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.

252409 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. #endif
  476. #include <sys/socket.h>
  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. static_jassert (sizeof (int8) == 1);
  1148. static_jassert (sizeof (uint8) == 1);
  1149. static_jassert (sizeof (int16) == 2);
  1150. static_jassert (sizeof (uint16) == 2);
  1151. static_jassert (sizeof (int32) == 4);
  1152. static_jassert (sizeof (uint32) == 4);
  1153. static_jassert (sizeof (int64) == 8);
  1154. static_jassert (sizeof (uint64) == 8);
  1155. char a1[7];
  1156. jassert (numElementsInArray(a1) == 7);
  1157. int a2[3];
  1158. jassert (numElementsInArray(a2) == 3);
  1159. int n = 1;
  1160. Atomic::increment (n);
  1161. jassert (Atomic::incrementAndReturn (n) == 3);
  1162. Atomic::decrement (n);
  1163. jassert (Atomic::decrementAndReturn (n) == 1);
  1164. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1165. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1166. // Some quick stream tests..
  1167. int randomInt = Random::getSystemRandom().nextInt();
  1168. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1169. double randomDouble = Random::getSystemRandom().nextDouble();
  1170. String randomString;
  1171. for (int i = 50; --i >= 0;)
  1172. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1173. MemoryOutputStream mo;
  1174. mo.writeInt (randomInt);
  1175. mo.writeIntBigEndian (randomInt);
  1176. mo.writeCompressedInt (randomInt);
  1177. mo.writeString (randomString);
  1178. mo.writeInt64 (randomInt64);
  1179. mo.writeInt64BigEndian (randomInt64);
  1180. mo.writeDouble (randomDouble);
  1181. mo.writeDoubleBigEndian (randomDouble);
  1182. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1183. jassert (mi.readInt() == randomInt);
  1184. jassert (mi.readIntBigEndian() == randomInt);
  1185. jassert (mi.readCompressedInt() == randomInt);
  1186. jassert (mi.readString() == randomString);
  1187. jassert (mi.readInt64() == randomInt64);
  1188. jassert (mi.readInt64BigEndian() == randomInt64);
  1189. jassert (mi.readDouble() == randomDouble);
  1190. jassert (mi.readDoubleBigEndian() == randomDouble);
  1191. }
  1192. #endif
  1193. // Now the real initialisation..
  1194. juceInitialisedNonGUI = true;
  1195. DBG (SystemStats::getJUCEVersion());
  1196. SystemStats::initialiseStats();
  1197. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1198. }
  1199. }
  1200. #if JUCE_WINDOWS
  1201. // This is imported from the sockets code..
  1202. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1203. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1204. #endif
  1205. #if JUCE_DEBUG
  1206. extern void juce_CheckForDanglingStreams();
  1207. #endif
  1208. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1209. {
  1210. if (juceInitialisedNonGUI)
  1211. {
  1212. #if JUCE_MAC || JUCE_IPHONE
  1213. const ScopedAutoReleasePool pool;
  1214. #endif
  1215. #if JUCE_WINDOWS
  1216. // need to shut down sockets if they were used..
  1217. if (juce_CloseWin32SocketLib != 0)
  1218. (*juce_CloseWin32SocketLib)();
  1219. #endif
  1220. LocalisedStrings::setCurrentMappings (0);
  1221. Thread::stopAllThreads (3000);
  1222. #if JUCE_DEBUG
  1223. juce_CheckForDanglingStreams();
  1224. #endif
  1225. juceInitialisedNonGUI = false;
  1226. }
  1227. }
  1228. #ifdef JUCE_DLL
  1229. void* juce_Malloc (const int size)
  1230. {
  1231. return malloc (size);
  1232. }
  1233. void* juce_Calloc (const int size)
  1234. {
  1235. return calloc (1, size);
  1236. }
  1237. void* juce_Realloc (void* const block, const int size)
  1238. {
  1239. return realloc (block, size);
  1240. }
  1241. void juce_Free (void* const block)
  1242. {
  1243. free (block);
  1244. }
  1245. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1246. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1247. {
  1248. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1249. }
  1250. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1251. {
  1252. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1253. }
  1254. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1255. {
  1256. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1257. }
  1258. void juce_DebugFree (void* const block)
  1259. {
  1260. _free_dbg (block, _NORMAL_BLOCK);
  1261. }
  1262. #endif
  1263. #endif
  1264. END_JUCE_NAMESPACE
  1265. /*** End of inlined file: juce_SystemStats.cpp ***/
  1266. /*** Start of inlined file: juce_Time.cpp ***/
  1267. #ifdef _MSC_VER
  1268. #pragma warning (disable: 4514)
  1269. #pragma warning (push)
  1270. #endif
  1271. #ifndef JUCE_WINDOWS
  1272. #include <sys/time.h>
  1273. #else
  1274. #include <ctime>
  1275. #endif
  1276. #include <sys/timeb.h>
  1277. BEGIN_JUCE_NAMESPACE
  1278. #ifdef _MSC_VER
  1279. #pragma warning (pop)
  1280. #ifdef _INC_TIME_INL
  1281. #define USE_NEW_SECURE_TIME_FNS
  1282. #endif
  1283. #endif
  1284. namespace TimeHelpers
  1285. {
  1286. static struct tm millisToLocal (const int64 millis) throw()
  1287. {
  1288. struct tm result;
  1289. const int64 seconds = millis / 1000;
  1290. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1291. {
  1292. // use extended maths for dates beyond 1970 to 2037..
  1293. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1294. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1295. const int days = (int) (jdm / literal64bit (86400));
  1296. const int a = 32044 + days;
  1297. const int b = (4 * a + 3) / 146097;
  1298. const int c = a - (b * 146097) / 4;
  1299. const int d = (4 * c + 3) / 1461;
  1300. const int e = c - (d * 1461) / 4;
  1301. const int m = (5 * e + 2) / 153;
  1302. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1303. result.tm_mon = m + 2 - 12 * (m / 10);
  1304. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1305. result.tm_wday = (days + 1) % 7;
  1306. result.tm_yday = -1;
  1307. int t = (int) (jdm % literal64bit (86400));
  1308. result.tm_hour = t / 3600;
  1309. t %= 3600;
  1310. result.tm_min = t / 60;
  1311. result.tm_sec = t % 60;
  1312. result.tm_isdst = -1;
  1313. }
  1314. else
  1315. {
  1316. time_t now = static_cast <time_t> (seconds);
  1317. #if JUCE_WINDOWS
  1318. #ifdef USE_NEW_SECURE_TIME_FNS
  1319. if (now >= 0 && now <= 0x793406fff)
  1320. localtime_s (&result, &now);
  1321. else
  1322. zeromem (&result, sizeof (result));
  1323. #else
  1324. result = *localtime (&now);
  1325. #endif
  1326. #else
  1327. // more thread-safe
  1328. localtime_r (&now, &result);
  1329. #endif
  1330. }
  1331. return result;
  1332. }
  1333. static int extendedModulo (const int64 value, const int modulo) throw()
  1334. {
  1335. return (int) (value >= 0 ? (value % modulo)
  1336. : (value - ((value / modulo) + 1) * modulo));
  1337. }
  1338. static uint32 lastMSCounterValue = 0;
  1339. }
  1340. Time::Time() throw()
  1341. : millisSinceEpoch (0)
  1342. {
  1343. }
  1344. Time::Time (const Time& other) throw()
  1345. : millisSinceEpoch (other.millisSinceEpoch)
  1346. {
  1347. }
  1348. Time::Time (const int64 ms) throw()
  1349. : millisSinceEpoch (ms)
  1350. {
  1351. }
  1352. Time::Time (const int year,
  1353. const int month,
  1354. const int day,
  1355. const int hours,
  1356. const int minutes,
  1357. const int seconds,
  1358. const int milliseconds,
  1359. const bool useLocalTime) throw()
  1360. {
  1361. jassert (year > 100); // year must be a 4-digit version
  1362. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1363. {
  1364. // use extended maths for dates beyond 1970 to 2037..
  1365. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1366. : 0;
  1367. const int a = (13 - month) / 12;
  1368. const int y = year + 4800 - a;
  1369. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1370. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1371. - 32045;
  1372. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1373. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1374. + milliseconds;
  1375. }
  1376. else
  1377. {
  1378. struct tm t;
  1379. t.tm_year = year - 1900;
  1380. t.tm_mon = month;
  1381. t.tm_mday = day;
  1382. t.tm_hour = hours;
  1383. t.tm_min = minutes;
  1384. t.tm_sec = seconds;
  1385. t.tm_isdst = -1;
  1386. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1387. if (millisSinceEpoch < 0)
  1388. millisSinceEpoch = 0;
  1389. else
  1390. millisSinceEpoch += milliseconds;
  1391. }
  1392. }
  1393. Time::~Time() throw()
  1394. {
  1395. }
  1396. Time& Time::operator= (const Time& other) throw()
  1397. {
  1398. millisSinceEpoch = other.millisSinceEpoch;
  1399. return *this;
  1400. }
  1401. int64 Time::currentTimeMillis() throw()
  1402. {
  1403. static uint32 lastCounterResult = 0xffffffff;
  1404. static int64 correction = 0;
  1405. const uint32 now = getMillisecondCounter();
  1406. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1407. if (now < lastCounterResult)
  1408. {
  1409. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1410. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1411. {
  1412. // get the time once using normal library calls, and store the difference needed to
  1413. // turn the millisecond counter into a real time.
  1414. #if JUCE_WINDOWS
  1415. struct _timeb t;
  1416. #ifdef USE_NEW_SECURE_TIME_FNS
  1417. _ftime_s (&t);
  1418. #else
  1419. _ftime (&t);
  1420. #endif
  1421. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1422. #else
  1423. struct timeval tv;
  1424. struct timezone tz;
  1425. gettimeofday (&tv, &tz);
  1426. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1427. #endif
  1428. }
  1429. }
  1430. lastCounterResult = now;
  1431. return correction + now;
  1432. }
  1433. uint32 juce_millisecondsSinceStartup() throw();
  1434. uint32 Time::getMillisecondCounter() throw()
  1435. {
  1436. const uint32 now = juce_millisecondsSinceStartup();
  1437. if (now < TimeHelpers::lastMSCounterValue)
  1438. {
  1439. // in multi-threaded apps this might be called concurrently, so
  1440. // make sure that our last counter value only increases and doesn't
  1441. // go backwards..
  1442. if (now < TimeHelpers::lastMSCounterValue - 1000)
  1443. TimeHelpers::lastMSCounterValue = now;
  1444. }
  1445. else
  1446. {
  1447. TimeHelpers::lastMSCounterValue = now;
  1448. }
  1449. return now;
  1450. }
  1451. uint32 Time::getApproximateMillisecondCounter() throw()
  1452. {
  1453. jassert (TimeHelpers::lastMSCounterValue != 0);
  1454. return TimeHelpers::lastMSCounterValue;
  1455. }
  1456. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1457. {
  1458. for (;;)
  1459. {
  1460. const uint32 now = getMillisecondCounter();
  1461. if (now >= targetTime)
  1462. break;
  1463. const int toWait = targetTime - now;
  1464. if (toWait > 2)
  1465. {
  1466. Thread::sleep (jmin (20, toWait >> 1));
  1467. }
  1468. else
  1469. {
  1470. // xxx should consider using mutex_pause on the mac as it apparently
  1471. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1472. for (int i = 10; --i >= 0;)
  1473. Thread::yield();
  1474. }
  1475. }
  1476. }
  1477. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1478. {
  1479. return ticks / (double) getHighResolutionTicksPerSecond();
  1480. }
  1481. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1482. {
  1483. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1484. }
  1485. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1486. {
  1487. return Time (currentTimeMillis());
  1488. }
  1489. const String Time::toString (const bool includeDate,
  1490. const bool includeTime,
  1491. const bool includeSeconds,
  1492. const bool use24HourClock) const throw()
  1493. {
  1494. String result;
  1495. if (includeDate)
  1496. {
  1497. result << getDayOfMonth() << ' '
  1498. << getMonthName (true) << ' '
  1499. << getYear();
  1500. if (includeTime)
  1501. result << ' ';
  1502. }
  1503. if (includeTime)
  1504. {
  1505. const int mins = getMinutes();
  1506. result << (use24HourClock ? getHours() : getHoursInAmPmFormat())
  1507. << (mins < 10 ? ":0" : ":") << mins;
  1508. if (includeSeconds)
  1509. {
  1510. const int secs = getSeconds();
  1511. result << (secs < 10 ? ":0" : ":") << secs;
  1512. }
  1513. if (! use24HourClock)
  1514. result << (isAfternoon() ? "pm" : "am");
  1515. }
  1516. return result.trimEnd();
  1517. }
  1518. const String Time::formatted (const juce_wchar* const format) const throw()
  1519. {
  1520. String buffer;
  1521. int bufferSize = 128;
  1522. buffer.preallocateStorage (bufferSize);
  1523. struct tm t (TimeHelpers::millisToLocal (millisSinceEpoch));
  1524. while (CharacterFunctions::ftime (static_cast <juce_wchar*> (buffer), bufferSize, format, &t) <= 0)
  1525. {
  1526. bufferSize += 128;
  1527. buffer.preallocateStorage (bufferSize);
  1528. }
  1529. return buffer;
  1530. }
  1531. int Time::getYear() const throw()
  1532. {
  1533. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_year + 1900;
  1534. }
  1535. int Time::getMonth() const throw()
  1536. {
  1537. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mon;
  1538. }
  1539. int Time::getDayOfMonth() const throw()
  1540. {
  1541. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_mday;
  1542. }
  1543. int Time::getDayOfWeek() const throw()
  1544. {
  1545. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_wday;
  1546. }
  1547. int Time::getHours() const throw()
  1548. {
  1549. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_hour;
  1550. }
  1551. int Time::getHoursInAmPmFormat() const throw()
  1552. {
  1553. const int hours = getHours();
  1554. if (hours == 0)
  1555. return 12;
  1556. else if (hours <= 12)
  1557. return hours;
  1558. else
  1559. return hours - 12;
  1560. }
  1561. bool Time::isAfternoon() const throw()
  1562. {
  1563. return getHours() >= 12;
  1564. }
  1565. int Time::getMinutes() const throw()
  1566. {
  1567. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_min;
  1568. }
  1569. int Time::getSeconds() const throw()
  1570. {
  1571. return TimeHelpers::extendedModulo (millisSinceEpoch / 1000, 60);
  1572. }
  1573. int Time::getMilliseconds() const throw()
  1574. {
  1575. return TimeHelpers::extendedModulo (millisSinceEpoch, 1000);
  1576. }
  1577. bool Time::isDaylightSavingTime() const throw()
  1578. {
  1579. return TimeHelpers::millisToLocal (millisSinceEpoch).tm_isdst != 0;
  1580. }
  1581. const String Time::getTimeZone() const throw()
  1582. {
  1583. String zone[2];
  1584. #if JUCE_WINDOWS
  1585. _tzset();
  1586. #ifdef USE_NEW_SECURE_TIME_FNS
  1587. {
  1588. char name [128];
  1589. size_t length;
  1590. for (int i = 0; i < 2; ++i)
  1591. {
  1592. zeromem (name, sizeof (name));
  1593. _get_tzname (&length, name, 127, i);
  1594. zone[i] = name;
  1595. }
  1596. }
  1597. #else
  1598. const char** const zonePtr = (const char**) _tzname;
  1599. zone[0] = zonePtr[0];
  1600. zone[1] = zonePtr[1];
  1601. #endif
  1602. #else
  1603. tzset();
  1604. const char** const zonePtr = (const char**) tzname;
  1605. zone[0] = zonePtr[0];
  1606. zone[1] = zonePtr[1];
  1607. #endif
  1608. if (isDaylightSavingTime())
  1609. {
  1610. zone[0] = zone[1];
  1611. if (zone[0].length() > 3
  1612. && zone[0].containsIgnoreCase ("daylight")
  1613. && zone[0].contains ("GMT"))
  1614. zone[0] = "BST";
  1615. }
  1616. return zone[0].substring (0, 3);
  1617. }
  1618. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1619. {
  1620. return getMonthName (getMonth(), threeLetterVersion);
  1621. }
  1622. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1623. {
  1624. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1625. }
  1626. const String Time::getMonthName (int monthNumber, const bool threeLetterVersion) throw()
  1627. {
  1628. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1629. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1630. monthNumber %= 12;
  1631. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1632. : longMonthNames [monthNumber]);
  1633. }
  1634. const String Time::getWeekdayName (int day, const bool threeLetterVersion) throw()
  1635. {
  1636. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1637. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1638. day %= 7;
  1639. return TRANS (threeLetterVersion ? shortDayNames [day]
  1640. : longDayNames [day]);
  1641. }
  1642. END_JUCE_NAMESPACE
  1643. /*** End of inlined file: juce_Time.cpp ***/
  1644. /*** Start of inlined file: juce_BitArray.cpp ***/
  1645. BEGIN_JUCE_NAMESPACE
  1646. BigInteger::BigInteger()
  1647. : numValues (4),
  1648. highestBit (-1),
  1649. negative (false)
  1650. {
  1651. values.calloc (numValues + 1);
  1652. }
  1653. BigInteger::BigInteger (const int value)
  1654. : numValues (4),
  1655. highestBit (31),
  1656. negative (value < 0)
  1657. {
  1658. values.calloc (numValues + 1);
  1659. values[0] = abs (value);
  1660. highestBit = getHighestBit();
  1661. }
  1662. BigInteger::BigInteger (int64 value)
  1663. : numValues (4),
  1664. highestBit (63),
  1665. negative (value < 0)
  1666. {
  1667. values.calloc (numValues + 1);
  1668. if (value < 0)
  1669. value = -value;
  1670. values[0] = (unsigned int) value;
  1671. values[1] = (unsigned int) (value >> 32);
  1672. highestBit = getHighestBit();
  1673. }
  1674. BigInteger::BigInteger (const unsigned int value)
  1675. : numValues (4),
  1676. highestBit (31),
  1677. negative (false)
  1678. {
  1679. values.calloc (numValues + 1);
  1680. values[0] = value;
  1681. highestBit = getHighestBit();
  1682. }
  1683. BigInteger::BigInteger (const BigInteger& other)
  1684. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1685. highestBit (other.getHighestBit()),
  1686. negative (other.negative)
  1687. {
  1688. values.malloc (numValues + 1);
  1689. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1690. }
  1691. BigInteger::~BigInteger()
  1692. {
  1693. }
  1694. void BigInteger::swapWith (BigInteger& other) throw()
  1695. {
  1696. values.swapWith (other.values);
  1697. swapVariables (numValues, other.numValues);
  1698. swapVariables (highestBit, other.highestBit);
  1699. swapVariables (negative, other.negative);
  1700. }
  1701. BigInteger& BigInteger::operator= (const BigInteger& other)
  1702. {
  1703. if (this != &other)
  1704. {
  1705. highestBit = other.getHighestBit();
  1706. numValues = jmax (4, (highestBit >> 5) + 1);
  1707. negative = other.negative;
  1708. values.malloc (numValues + 1);
  1709. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1710. }
  1711. return *this;
  1712. }
  1713. void BigInteger::ensureSize (const int numVals)
  1714. {
  1715. if (numVals + 2 >= numValues)
  1716. {
  1717. int oldSize = numValues;
  1718. numValues = ((numVals + 2) * 3) / 2;
  1719. values.realloc (numValues + 1);
  1720. while (oldSize < numValues)
  1721. values [oldSize++] = 0;
  1722. }
  1723. }
  1724. bool BigInteger::operator[] (const int bit) const throw()
  1725. {
  1726. return bit <= highestBit && bit >= 0
  1727. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1728. }
  1729. int BigInteger::toInteger() const throw()
  1730. {
  1731. const int n = (int) (values[0] & 0x7fffffff);
  1732. return negative ? -n : n;
  1733. }
  1734. const BigInteger BigInteger::getBitRange (int startBit, int numBits) const
  1735. {
  1736. BigInteger r;
  1737. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  1738. r.ensureSize (numBits >> 5);
  1739. r.highestBit = numBits;
  1740. int i = 0;
  1741. while (numBits > 0)
  1742. {
  1743. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  1744. numBits -= 32;
  1745. startBit += 32;
  1746. }
  1747. r.highestBit = r.getHighestBit();
  1748. return r;
  1749. }
  1750. int BigInteger::getBitRangeAsInt (const int startBit, int numBits) const throw()
  1751. {
  1752. if (numBits > 32)
  1753. {
  1754. jassertfalse // use getBitRange() if you need more than 32 bits..
  1755. numBits = 32;
  1756. }
  1757. numBits = jmin (numBits, highestBit + 1 - startBit);
  1758. if (numBits <= 0)
  1759. return 0;
  1760. const int pos = startBit >> 5;
  1761. const int offset = startBit & 31;
  1762. const int endSpace = 32 - numBits;
  1763. uint32 n = ((uint32) values [pos]) >> offset;
  1764. if (offset > endSpace)
  1765. n |= ((uint32) values [pos + 1]) << (32 - offset);
  1766. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  1767. }
  1768. void BigInteger::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet)
  1769. {
  1770. if (numBits > 32)
  1771. {
  1772. jassertfalse
  1773. numBits = 32;
  1774. }
  1775. for (int i = 0; i < numBits; ++i)
  1776. {
  1777. setBit (startBit + i, (valueToSet & 1) != 0);
  1778. valueToSet >>= 1;
  1779. }
  1780. }
  1781. void BigInteger::clear()
  1782. {
  1783. if (numValues > 16)
  1784. {
  1785. numValues = 4;
  1786. values.calloc (numValues + 1);
  1787. }
  1788. else
  1789. {
  1790. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1791. }
  1792. highestBit = -1;
  1793. negative = false;
  1794. }
  1795. void BigInteger::setBit (const int bit)
  1796. {
  1797. if (bit >= 0)
  1798. {
  1799. if (bit > highestBit)
  1800. {
  1801. ensureSize (bit >> 5);
  1802. highestBit = bit;
  1803. }
  1804. values [bit >> 5] |= (1 << (bit & 31));
  1805. }
  1806. }
  1807. void BigInteger::setBit (const int bit, const bool shouldBeSet)
  1808. {
  1809. if (shouldBeSet)
  1810. setBit (bit);
  1811. else
  1812. clearBit (bit);
  1813. }
  1814. void BigInteger::clearBit (const int bit) throw()
  1815. {
  1816. if (bit >= 0 && bit <= highestBit)
  1817. values [bit >> 5] &= ~(1 << (bit & 31));
  1818. }
  1819. void BigInteger::setRange (int startBit, int numBits, const bool shouldBeSet)
  1820. {
  1821. while (--numBits >= 0)
  1822. setBit (startBit++, shouldBeSet);
  1823. }
  1824. void BigInteger::insertBit (const int bit, const bool shouldBeSet)
  1825. {
  1826. if (bit >= 0)
  1827. shiftBits (1, bit);
  1828. setBit (bit, shouldBeSet);
  1829. }
  1830. bool BigInteger::isZero() const throw()
  1831. {
  1832. return getHighestBit() < 0;
  1833. }
  1834. bool BigInteger::isOne() const throw()
  1835. {
  1836. return getHighestBit() == 0 && ! negative;
  1837. }
  1838. bool BigInteger::isNegative() const throw()
  1839. {
  1840. return negative && ! isZero();
  1841. }
  1842. void BigInteger::setNegative (const bool neg) throw()
  1843. {
  1844. negative = neg;
  1845. }
  1846. void BigInteger::negate() throw()
  1847. {
  1848. negative = (! negative) && ! isZero();
  1849. }
  1850. int BigInteger::countNumberOfSetBits() const throw()
  1851. {
  1852. int total = 0;
  1853. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  1854. {
  1855. unsigned int n = values[i];
  1856. if (n == 0xffffffff)
  1857. {
  1858. total += 32;
  1859. }
  1860. else
  1861. {
  1862. while (n != 0)
  1863. {
  1864. total += (n & 1);
  1865. n >>= 1;
  1866. }
  1867. }
  1868. }
  1869. return total;
  1870. }
  1871. int BigInteger::getHighestBit() const throw()
  1872. {
  1873. for (int i = highestBit + 1; --i >= 0;)
  1874. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1875. return i;
  1876. return -1;
  1877. }
  1878. int BigInteger::findNextSetBit (int i) const throw()
  1879. {
  1880. for (; i <= highestBit; ++i)
  1881. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  1882. return i;
  1883. return -1;
  1884. }
  1885. int BigInteger::findNextClearBit (int i) const throw()
  1886. {
  1887. for (; i <= highestBit; ++i)
  1888. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  1889. break;
  1890. return i;
  1891. }
  1892. BigInteger& BigInteger::operator+= (const BigInteger& other)
  1893. {
  1894. if (other.isNegative())
  1895. return operator-= (-other);
  1896. if (isNegative())
  1897. {
  1898. if (compareAbsolute (other) < 0)
  1899. {
  1900. BigInteger temp (*this);
  1901. temp.negate();
  1902. *this = other;
  1903. operator-= (temp);
  1904. }
  1905. else
  1906. {
  1907. negate();
  1908. operator-= (other);
  1909. negate();
  1910. }
  1911. }
  1912. else
  1913. {
  1914. if (other.highestBit > highestBit)
  1915. highestBit = other.highestBit;
  1916. ++highestBit;
  1917. const int numInts = (highestBit >> 5) + 1;
  1918. ensureSize (numInts);
  1919. int64 remainder = 0;
  1920. for (int i = 0; i <= numInts; ++i)
  1921. {
  1922. if (i < numValues)
  1923. remainder += values[i];
  1924. if (i < other.numValues)
  1925. remainder += other.values[i];
  1926. values[i] = (unsigned int) remainder;
  1927. remainder >>= 32;
  1928. }
  1929. jassert (remainder == 0);
  1930. highestBit = getHighestBit();
  1931. }
  1932. return *this;
  1933. }
  1934. BigInteger& BigInteger::operator-= (const BigInteger& other)
  1935. {
  1936. if (other.isNegative())
  1937. return operator+= (-other);
  1938. if (! isNegative())
  1939. {
  1940. if (compareAbsolute (other) < 0)
  1941. {
  1942. BigInteger temp (other);
  1943. swapWith (temp);
  1944. operator-= (temp);
  1945. negate();
  1946. return *this;
  1947. }
  1948. }
  1949. else
  1950. {
  1951. negate();
  1952. operator+= (other);
  1953. negate();
  1954. return *this;
  1955. }
  1956. const int numInts = (highestBit >> 5) + 1;
  1957. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1958. int64 amountToSubtract = 0;
  1959. for (int i = 0; i <= numInts; ++i)
  1960. {
  1961. if (i <= maxOtherInts)
  1962. amountToSubtract += (int64) other.values[i];
  1963. if (values[i] >= amountToSubtract)
  1964. {
  1965. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1966. amountToSubtract = 0;
  1967. }
  1968. else
  1969. {
  1970. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1971. values[i] = (unsigned int) n;
  1972. amountToSubtract = 1;
  1973. }
  1974. }
  1975. return *this;
  1976. }
  1977. BigInteger& BigInteger::operator*= (const BigInteger& other)
  1978. {
  1979. BigInteger total;
  1980. highestBit = getHighestBit();
  1981. const bool wasNegative = isNegative();
  1982. setNegative (false);
  1983. for (int i = 0; i <= highestBit; ++i)
  1984. {
  1985. if (operator[](i))
  1986. {
  1987. BigInteger n (other);
  1988. n.setNegative (false);
  1989. n <<= i;
  1990. total += n;
  1991. }
  1992. }
  1993. total.setNegative (wasNegative ^ other.isNegative());
  1994. swapWith (total);
  1995. return *this;
  1996. }
  1997. void BigInteger::divideBy (const BigInteger& divisor, BigInteger& remainder)
  1998. {
  1999. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  2000. const int divHB = divisor.getHighestBit();
  2001. const int ourHB = getHighestBit();
  2002. if (divHB < 0 || ourHB < 0)
  2003. {
  2004. // division by zero
  2005. remainder.clear();
  2006. clear();
  2007. }
  2008. else
  2009. {
  2010. const bool wasNegative = isNegative();
  2011. swapWith (remainder);
  2012. remainder.setNegative (false);
  2013. clear();
  2014. BigInteger temp (divisor);
  2015. temp.setNegative (false);
  2016. int leftShift = ourHB - divHB;
  2017. temp <<= leftShift;
  2018. while (leftShift >= 0)
  2019. {
  2020. if (remainder.compareAbsolute (temp) >= 0)
  2021. {
  2022. remainder -= temp;
  2023. setBit (leftShift);
  2024. }
  2025. if (--leftShift >= 0)
  2026. temp >>= 1;
  2027. }
  2028. negative = wasNegative ^ divisor.isNegative();
  2029. remainder.setNegative (wasNegative);
  2030. }
  2031. }
  2032. BigInteger& BigInteger::operator/= (const BigInteger& other)
  2033. {
  2034. BigInteger remainder;
  2035. divideBy (other, remainder);
  2036. return *this;
  2037. }
  2038. BigInteger& BigInteger::operator|= (const BigInteger& other)
  2039. {
  2040. // this operation doesn't take into account negative values..
  2041. jassert (isNegative() == other.isNegative());
  2042. if (other.highestBit >= 0)
  2043. {
  2044. ensureSize (other.highestBit >> 5);
  2045. int n = (other.highestBit >> 5) + 1;
  2046. while (--n >= 0)
  2047. values[n] |= other.values[n];
  2048. if (other.highestBit > highestBit)
  2049. highestBit = other.highestBit;
  2050. highestBit = getHighestBit();
  2051. }
  2052. return *this;
  2053. }
  2054. BigInteger& BigInteger::operator&= (const BigInteger& other)
  2055. {
  2056. // this operation doesn't take into account negative values..
  2057. jassert (isNegative() == other.isNegative());
  2058. int n = numValues;
  2059. while (n > other.numValues)
  2060. values[--n] = 0;
  2061. while (--n >= 0)
  2062. values[n] &= other.values[n];
  2063. if (other.highestBit < highestBit)
  2064. highestBit = other.highestBit;
  2065. highestBit = getHighestBit();
  2066. return *this;
  2067. }
  2068. BigInteger& BigInteger::operator^= (const BigInteger& other)
  2069. {
  2070. // this operation will only work with the absolute values
  2071. jassert (isNegative() == other.isNegative());
  2072. if (other.highestBit >= 0)
  2073. {
  2074. ensureSize (other.highestBit >> 5);
  2075. int n = (other.highestBit >> 5) + 1;
  2076. while (--n >= 0)
  2077. values[n] ^= other.values[n];
  2078. if (other.highestBit > highestBit)
  2079. highestBit = other.highestBit;
  2080. highestBit = getHighestBit();
  2081. }
  2082. return *this;
  2083. }
  2084. BigInteger& BigInteger::operator%= (const BigInteger& divisor)
  2085. {
  2086. BigInteger remainder;
  2087. divideBy (divisor, remainder);
  2088. swapWith (remainder);
  2089. return *this;
  2090. }
  2091. BigInteger& BigInteger::operator<<= (int numBitsToShift)
  2092. {
  2093. shiftBits (numBitsToShift, 0);
  2094. return *this;
  2095. }
  2096. BigInteger& BigInteger::operator>>= (int numBitsToShift)
  2097. {
  2098. return operator<<= (-numBitsToShift);
  2099. }
  2100. BigInteger& BigInteger::operator++() { return operator+= (1); }
  2101. BigInteger& BigInteger::operator--() { return operator-= (1); }
  2102. const BigInteger BigInteger::operator++ (int) { const BigInteger old (*this); operator+= (1); return old; }
  2103. const BigInteger BigInteger::operator-- (int) { const BigInteger old (*this); operator-= (1); return old; }
  2104. const BigInteger BigInteger::operator+ (const BigInteger& other) const { BigInteger b (*this); return b += other; }
  2105. const BigInteger BigInteger::operator- (const BigInteger& other) const { BigInteger b (*this); return b -= other; }
  2106. const BigInteger BigInteger::operator* (const BigInteger& other) const { BigInteger b (*this); return b *= other; }
  2107. const BigInteger BigInteger::operator/ (const BigInteger& other) const { BigInteger b (*this); return b /= other; }
  2108. const BigInteger BigInteger::operator| (const BigInteger& other) const { BigInteger b (*this); return b |= other; }
  2109. const BigInteger BigInteger::operator& (const BigInteger& other) const { BigInteger b (*this); return b &= other; }
  2110. const BigInteger BigInteger::operator^ (const BigInteger& other) const { BigInteger b (*this); return b ^= other; }
  2111. const BigInteger BigInteger::operator% (const BigInteger& other) const { BigInteger b (*this); return b %= other; }
  2112. const BigInteger BigInteger::operator<< (const int numBits) const { BigInteger b (*this); return b <<= numBits; }
  2113. const BigInteger BigInteger::operator>> (const int numBits) const { BigInteger b (*this); return b >>= numBits; }
  2114. const BigInteger BigInteger::operator-() const { BigInteger b (*this); b.negate(); return b; }
  2115. int BigInteger::compare (const BigInteger& other) const throw()
  2116. {
  2117. if (isNegative() == other.isNegative())
  2118. {
  2119. const int absComp = compareAbsolute (other);
  2120. return isNegative() ? -absComp : absComp;
  2121. }
  2122. else
  2123. {
  2124. return isNegative() ? -1 : 1;
  2125. }
  2126. }
  2127. int BigInteger::compareAbsolute (const BigInteger& other) const throw()
  2128. {
  2129. const int h1 = getHighestBit();
  2130. const int h2 = other.getHighestBit();
  2131. if (h1 > h2)
  2132. return 1;
  2133. else if (h1 < h2)
  2134. return -1;
  2135. for (int i = (h1 >> 5) + 1; --i >= 0;)
  2136. if (values[i] != other.values[i])
  2137. return (values[i] > other.values[i]) ? 1 : -1;
  2138. return 0;
  2139. }
  2140. bool BigInteger::operator== (const BigInteger& other) const throw() { return compare (other) == 0; }
  2141. bool BigInteger::operator!= (const BigInteger& other) const throw() { return compare (other) != 0; }
  2142. bool BigInteger::operator< (const BigInteger& other) const throw() { return compare (other) < 0; }
  2143. bool BigInteger::operator<= (const BigInteger& other) const throw() { return compare (other) <= 0; }
  2144. bool BigInteger::operator> (const BigInteger& other) const throw() { return compare (other) > 0; }
  2145. bool BigInteger::operator>= (const BigInteger& other) const throw() { return compare (other) >= 0; }
  2146. void BigInteger::shiftBits (int bits, const int startBit)
  2147. {
  2148. if (highestBit < 0)
  2149. return;
  2150. if (startBit > 0)
  2151. {
  2152. if (bits < 0)
  2153. {
  2154. // right shift
  2155. for (int i = startBit; i <= highestBit; ++i)
  2156. setBit (i, operator[] (i - bits));
  2157. highestBit = getHighestBit();
  2158. }
  2159. else if (bits > 0)
  2160. {
  2161. // left shift
  2162. for (int i = highestBit + 1; --i >= startBit;)
  2163. setBit (i + bits, operator[] (i));
  2164. while (--bits >= 0)
  2165. clearBit (bits + startBit);
  2166. }
  2167. }
  2168. else
  2169. {
  2170. if (bits < 0)
  2171. {
  2172. // right shift
  2173. bits = -bits;
  2174. if (bits > highestBit)
  2175. {
  2176. clear();
  2177. }
  2178. else
  2179. {
  2180. const int wordsToMove = bits >> 5;
  2181. int top = 1 + (highestBit >> 5) - wordsToMove;
  2182. highestBit -= bits;
  2183. if (wordsToMove > 0)
  2184. {
  2185. int i;
  2186. for (i = 0; i < top; ++i)
  2187. values [i] = values [i + wordsToMove];
  2188. for (i = 0; i < wordsToMove; ++i)
  2189. values [top + i] = 0;
  2190. bits &= 31;
  2191. }
  2192. if (bits != 0)
  2193. {
  2194. const int invBits = 32 - bits;
  2195. --top;
  2196. for (int i = 0; i < top; ++i)
  2197. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2198. values[top] = (values[top] >> bits);
  2199. }
  2200. highestBit = getHighestBit();
  2201. }
  2202. }
  2203. else if (bits > 0)
  2204. {
  2205. // left shift
  2206. ensureSize (((highestBit + bits) >> 5) + 1);
  2207. const int wordsToMove = bits >> 5;
  2208. int top = 1 + (highestBit >> 5);
  2209. highestBit += bits;
  2210. if (wordsToMove > 0)
  2211. {
  2212. int i;
  2213. for (i = top; --i >= 0;)
  2214. values [i + wordsToMove] = values [i];
  2215. for (i = 0; i < wordsToMove; ++i)
  2216. values [i] = 0;
  2217. bits &= 31;
  2218. }
  2219. if (bits != 0)
  2220. {
  2221. const int invBits = 32 - bits;
  2222. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2223. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2224. values [wordsToMove] = values [wordsToMove] << bits;
  2225. }
  2226. highestBit = getHighestBit();
  2227. }
  2228. }
  2229. }
  2230. const BigInteger BigInteger::simpleGCD (BigInteger* m, BigInteger* n)
  2231. {
  2232. while (! m->isZero())
  2233. {
  2234. if (n->compareAbsolute (*m) > 0)
  2235. swapVariables (m, n);
  2236. *m -= *n;
  2237. }
  2238. return *n;
  2239. }
  2240. const BigInteger BigInteger::findGreatestCommonDivisor (BigInteger n) const
  2241. {
  2242. BigInteger m (*this);
  2243. while (! n.isZero())
  2244. {
  2245. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  2246. return simpleGCD (&m, &n);
  2247. BigInteger temp1 (m), temp2;
  2248. temp1.divideBy (n, temp2);
  2249. m = n;
  2250. n = temp2;
  2251. }
  2252. return m;
  2253. }
  2254. void BigInteger::exponentModulo (const BigInteger& exponent, const BigInteger& modulus)
  2255. {
  2256. BigInteger exp (exponent);
  2257. exp %= modulus;
  2258. BigInteger value (1);
  2259. swapWith (value);
  2260. value %= modulus;
  2261. while (! exp.isZero())
  2262. {
  2263. if (exp [0])
  2264. {
  2265. operator*= (value);
  2266. operator%= (modulus);
  2267. }
  2268. value *= value;
  2269. value %= modulus;
  2270. exp >>= 1;
  2271. }
  2272. }
  2273. void BigInteger::inverseModulo (const BigInteger& modulus)
  2274. {
  2275. if (modulus.isOne() || modulus.isNegative())
  2276. {
  2277. clear();
  2278. return;
  2279. }
  2280. if (isNegative() || compareAbsolute (modulus) >= 0)
  2281. operator%= (modulus);
  2282. if (isOne())
  2283. return;
  2284. if (! (*this)[0])
  2285. {
  2286. // not invertible
  2287. clear();
  2288. return;
  2289. }
  2290. BigInteger a1 (modulus);
  2291. BigInteger a2 (*this);
  2292. BigInteger b1 (modulus);
  2293. BigInteger b2 (1);
  2294. while (! a2.isOne())
  2295. {
  2296. BigInteger temp1, temp2, multiplier (a1);
  2297. multiplier.divideBy (a2, temp1);
  2298. temp1 = a2;
  2299. temp1 *= multiplier;
  2300. temp2 = a1;
  2301. temp2 -= temp1;
  2302. a1 = a2;
  2303. a2 = temp2;
  2304. temp1 = b2;
  2305. temp1 *= multiplier;
  2306. temp2 = b1;
  2307. temp2 -= temp1;
  2308. b1 = b2;
  2309. b2 = temp2;
  2310. }
  2311. while (b2.isNegative())
  2312. b2 += modulus;
  2313. b2 %= modulus;
  2314. swapWith (b2);
  2315. }
  2316. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const BigInteger& value)
  2317. {
  2318. return stream << value.toString (10);
  2319. }
  2320. const String BigInteger::toString (const int base, const int minimumNumCharacters) const
  2321. {
  2322. String s;
  2323. BigInteger v (*this);
  2324. if (base == 2 || base == 8 || base == 16)
  2325. {
  2326. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2327. static const char* const hexDigits = "0123456789abcdef";
  2328. for (;;)
  2329. {
  2330. const int remainder = v.getBitRangeAsInt (0, bits);
  2331. v >>= bits;
  2332. if (remainder == 0 && v.isZero())
  2333. break;
  2334. s = String::charToString (hexDigits [remainder]) + s;
  2335. }
  2336. }
  2337. else if (base == 10)
  2338. {
  2339. const BigInteger ten (10);
  2340. BigInteger remainder;
  2341. for (;;)
  2342. {
  2343. v.divideBy (ten, remainder);
  2344. if (remainder.isZero() && v.isZero())
  2345. break;
  2346. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2347. }
  2348. }
  2349. else
  2350. {
  2351. jassertfalse // can't do the specified base!
  2352. return String::empty;
  2353. }
  2354. s = s.paddedLeft ('0', minimumNumCharacters);
  2355. return isNegative() ? "-" + s : s;
  2356. }
  2357. void BigInteger::parseString (const String& text, const int base)
  2358. {
  2359. clear();
  2360. const juce_wchar* t = text;
  2361. if (base == 2 || base == 8 || base == 16)
  2362. {
  2363. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2364. for (;;)
  2365. {
  2366. const juce_wchar c = *t++;
  2367. const int digit = CharacterFunctions::getHexDigitValue (c);
  2368. if (((unsigned int) digit) < (unsigned int) base)
  2369. {
  2370. operator<<= (bits);
  2371. operator+= (digit);
  2372. }
  2373. else if (c == 0)
  2374. {
  2375. break;
  2376. }
  2377. }
  2378. }
  2379. else if (base == 10)
  2380. {
  2381. const BigInteger ten ((unsigned int) 10);
  2382. for (;;)
  2383. {
  2384. const juce_wchar c = *t++;
  2385. if (c >= '0' && c <= '9')
  2386. {
  2387. operator*= (ten);
  2388. operator+= ((int) (c - '0'));
  2389. }
  2390. else if (c == 0)
  2391. {
  2392. break;
  2393. }
  2394. }
  2395. }
  2396. setNegative (text.trimStart().startsWithChar ('-'));
  2397. }
  2398. const MemoryBlock BigInteger::toMemoryBlock() const
  2399. {
  2400. const int numBytes = (getHighestBit() + 8) >> 3;
  2401. MemoryBlock mb ((size_t) numBytes);
  2402. for (int i = 0; i < numBytes; ++i)
  2403. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2404. return mb;
  2405. }
  2406. void BigInteger::loadFromMemoryBlock (const MemoryBlock& data)
  2407. {
  2408. clear();
  2409. for (int i = (int) data.getSize(); --i >= 0;)
  2410. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2411. }
  2412. END_JUCE_NAMESPACE
  2413. /*** End of inlined file: juce_BitArray.cpp ***/
  2414. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2415. BEGIN_JUCE_NAMESPACE
  2416. MemoryBlock::MemoryBlock() throw()
  2417. : size (0)
  2418. {
  2419. }
  2420. MemoryBlock::MemoryBlock (const size_t initialSize,
  2421. const bool initialiseToZero) throw()
  2422. {
  2423. if (initialSize > 0)
  2424. {
  2425. size = initialSize;
  2426. data.allocate (initialSize, initialiseToZero);
  2427. }
  2428. else
  2429. {
  2430. size = 0;
  2431. }
  2432. }
  2433. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2434. : size (other.size)
  2435. {
  2436. if (size > 0)
  2437. {
  2438. jassert (other.data != 0);
  2439. data.malloc (size);
  2440. memcpy (data, other.data, size);
  2441. }
  2442. }
  2443. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2444. const size_t sizeInBytes) throw()
  2445. : size (jmax ((size_t) 0, sizeInBytes))
  2446. {
  2447. jassert (sizeInBytes >= 0);
  2448. if (size > 0)
  2449. {
  2450. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2451. data.malloc (size);
  2452. if (dataToInitialiseFrom != 0)
  2453. memcpy (data, dataToInitialiseFrom, size);
  2454. }
  2455. }
  2456. MemoryBlock::~MemoryBlock() throw()
  2457. {
  2458. jassert (size >= 0); // should never happen
  2459. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2460. }
  2461. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2462. {
  2463. if (this != &other)
  2464. {
  2465. setSize (other.size, false);
  2466. memcpy (data, other.data, size);
  2467. }
  2468. return *this;
  2469. }
  2470. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2471. {
  2472. return matches (other.data, other.size);
  2473. }
  2474. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2475. {
  2476. return ! operator== (other);
  2477. }
  2478. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2479. {
  2480. return size == dataSize
  2481. && memcmp (data, dataToCompare, size) == 0;
  2482. }
  2483. // this will resize the block to this size
  2484. void MemoryBlock::setSize (const size_t newSize,
  2485. const bool initialiseToZero) throw()
  2486. {
  2487. if (size != newSize)
  2488. {
  2489. if (newSize <= 0)
  2490. {
  2491. data.free();
  2492. size = 0;
  2493. }
  2494. else
  2495. {
  2496. if (data != 0)
  2497. {
  2498. data.realloc (newSize);
  2499. if (initialiseToZero && (newSize > size))
  2500. zeromem (data + size, newSize - size);
  2501. }
  2502. else
  2503. {
  2504. data.allocate (newSize, initialiseToZero);
  2505. }
  2506. size = newSize;
  2507. }
  2508. }
  2509. }
  2510. void MemoryBlock::ensureSize (const size_t minimumSize,
  2511. const bool initialiseToZero) throw()
  2512. {
  2513. if (size < minimumSize)
  2514. setSize (minimumSize, initialiseToZero);
  2515. }
  2516. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2517. {
  2518. swapVariables (size, other.size);
  2519. data.swapWith (other.data);
  2520. }
  2521. void MemoryBlock::fillWith (const uint8 value) throw()
  2522. {
  2523. memset (data, (int) value, size);
  2524. }
  2525. void MemoryBlock::append (const void* const srcData,
  2526. const size_t numBytes) throw()
  2527. {
  2528. if (numBytes > 0)
  2529. {
  2530. const size_t oldSize = size;
  2531. setSize (size + numBytes);
  2532. memcpy (data + oldSize, srcData, numBytes);
  2533. }
  2534. }
  2535. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2536. {
  2537. const char* d = static_cast<const char*> (src);
  2538. if (offset < 0)
  2539. {
  2540. d -= offset;
  2541. num -= offset;
  2542. offset = 0;
  2543. }
  2544. if (offset + num > size)
  2545. num = size - offset;
  2546. if (num > 0)
  2547. memcpy (data + offset, d, num);
  2548. }
  2549. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2550. {
  2551. char* d = static_cast<char*> (dst);
  2552. if (offset < 0)
  2553. {
  2554. zeromem (d, -offset);
  2555. d -= offset;
  2556. num += offset;
  2557. offset = 0;
  2558. }
  2559. if (offset + num > size)
  2560. {
  2561. const size_t newNum = size - offset;
  2562. zeromem (d + newNum, num - newNum);
  2563. num = newNum;
  2564. }
  2565. if (num > 0)
  2566. memcpy (d, data + offset, num);
  2567. }
  2568. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2569. {
  2570. if (startByte < 0)
  2571. {
  2572. numBytesToRemove += startByte;
  2573. startByte = 0;
  2574. }
  2575. if (startByte + numBytesToRemove >= size)
  2576. {
  2577. setSize (startByte);
  2578. }
  2579. else if (numBytesToRemove > 0)
  2580. {
  2581. memmove (data + startByte,
  2582. data + startByte + numBytesToRemove,
  2583. size - (startByte + numBytesToRemove));
  2584. setSize (size - numBytesToRemove);
  2585. }
  2586. }
  2587. const String MemoryBlock::toString() const throw()
  2588. {
  2589. return String (static_cast <const char*> (getData()), size);
  2590. }
  2591. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2592. {
  2593. int res = 0;
  2594. size_t byte = bitRangeStart >> 3;
  2595. int offsetInByte = (int) bitRangeStart & 7;
  2596. size_t bitsSoFar = 0;
  2597. while (numBits > 0 && (size_t) byte < size)
  2598. {
  2599. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2600. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2601. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2602. bitsSoFar += bitsThisTime;
  2603. numBits -= bitsThisTime;
  2604. ++byte;
  2605. offsetInByte = 0;
  2606. }
  2607. return res;
  2608. }
  2609. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2610. {
  2611. size_t byte = bitRangeStart >> 3;
  2612. int offsetInByte = (int) bitRangeStart & 7;
  2613. unsigned int mask = ~((((unsigned int) 0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2614. while (numBits > 0 && (size_t) byte < size)
  2615. {
  2616. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2617. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int) 0xffffffff) >> offsetInByte) << offsetInByte);
  2618. const unsigned int tempBits = bitsToSet << offsetInByte;
  2619. data[byte] = (char) ((data[byte] & tempMask) | tempBits);
  2620. ++byte;
  2621. numBits -= bitsThisTime;
  2622. bitsToSet >>= bitsThisTime;
  2623. mask >>= bitsThisTime;
  2624. offsetInByte = 0;
  2625. }
  2626. }
  2627. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2628. {
  2629. ensureSize (hex.length() >> 1);
  2630. char* dest = data;
  2631. int i = 0;
  2632. for (;;)
  2633. {
  2634. int byte = 0;
  2635. for (int loop = 2; --loop >= 0;)
  2636. {
  2637. byte <<= 4;
  2638. for (;;)
  2639. {
  2640. const juce_wchar c = hex [i++];
  2641. if (c >= '0' && c <= '9')
  2642. {
  2643. byte |= c - '0';
  2644. break;
  2645. }
  2646. else if (c >= 'a' && c <= 'z')
  2647. {
  2648. byte |= c - ('a' - 10);
  2649. break;
  2650. }
  2651. else if (c >= 'A' && c <= 'Z')
  2652. {
  2653. byte |= c - ('A' - 10);
  2654. break;
  2655. }
  2656. else if (c == 0)
  2657. {
  2658. setSize (static_cast <size_t> (dest - data));
  2659. return;
  2660. }
  2661. }
  2662. }
  2663. *dest++ = (char) byte;
  2664. }
  2665. }
  2666. static const char* const encodingTable
  2667. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2668. const String MemoryBlock::toBase64Encoding() const throw()
  2669. {
  2670. const size_t numChars = ((size << 3) + 5) / 6;
  2671. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2672. const int initialLen = destString.length();
  2673. destString.preallocateStorage (initialLen + 2 + numChars);
  2674. juce_wchar* d = destString;
  2675. d += initialLen;
  2676. *d++ = '.';
  2677. for (size_t i = 0; i < numChars; ++i)
  2678. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2679. *d++ = 0;
  2680. return destString;
  2681. }
  2682. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2683. {
  2684. const int startPos = s.indexOfChar ('.') + 1;
  2685. if (startPos <= 0)
  2686. return false;
  2687. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2688. setSize (numBytesNeeded, true);
  2689. const int numChars = s.length() - startPos;
  2690. const juce_wchar* srcChars = s;
  2691. srcChars += startPos;
  2692. int pos = 0;
  2693. for (int i = 0; i < numChars; ++i)
  2694. {
  2695. const char c = (char) srcChars[i];
  2696. for (int j = 0; j < 64; ++j)
  2697. {
  2698. if (encodingTable[j] == c)
  2699. {
  2700. setBitRange (pos, 6, j);
  2701. pos += 6;
  2702. break;
  2703. }
  2704. }
  2705. }
  2706. return true;
  2707. }
  2708. END_JUCE_NAMESPACE
  2709. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2710. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2711. BEGIN_JUCE_NAMESPACE
  2712. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2713. : properties (ignoreCaseOfKeyNames),
  2714. fallbackProperties (0),
  2715. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2716. {
  2717. }
  2718. PropertySet::PropertySet (const PropertySet& other) throw()
  2719. : properties (other.properties),
  2720. fallbackProperties (other.fallbackProperties),
  2721. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2722. {
  2723. }
  2724. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2725. {
  2726. properties = other.properties;
  2727. fallbackProperties = other.fallbackProperties;
  2728. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2729. propertyChanged();
  2730. return *this;
  2731. }
  2732. PropertySet::~PropertySet()
  2733. {
  2734. }
  2735. void PropertySet::clear()
  2736. {
  2737. const ScopedLock sl (lock);
  2738. if (properties.size() > 0)
  2739. {
  2740. properties.clear();
  2741. propertyChanged();
  2742. }
  2743. }
  2744. const String PropertySet::getValue (const String& keyName,
  2745. const String& defaultValue) const throw()
  2746. {
  2747. const ScopedLock sl (lock);
  2748. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2749. if (index >= 0)
  2750. return properties.getAllValues() [index];
  2751. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2752. : defaultValue;
  2753. }
  2754. int PropertySet::getIntValue (const String& keyName,
  2755. const int defaultValue) const throw()
  2756. {
  2757. const ScopedLock sl (lock);
  2758. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2759. if (index >= 0)
  2760. return properties.getAllValues() [index].getIntValue();
  2761. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2762. : defaultValue;
  2763. }
  2764. double PropertySet::getDoubleValue (const String& keyName,
  2765. const double defaultValue) const throw()
  2766. {
  2767. const ScopedLock sl (lock);
  2768. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2769. if (index >= 0)
  2770. return properties.getAllValues()[index].getDoubleValue();
  2771. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2772. : defaultValue;
  2773. }
  2774. bool PropertySet::getBoolValue (const String& keyName,
  2775. const bool defaultValue) const throw()
  2776. {
  2777. const ScopedLock sl (lock);
  2778. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2779. if (index >= 0)
  2780. return properties.getAllValues() [index].getIntValue() != 0;
  2781. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2782. : defaultValue;
  2783. }
  2784. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2785. {
  2786. XmlDocument doc (getValue (keyName));
  2787. return doc.getDocumentElement();
  2788. }
  2789. void PropertySet::setValue (const String& keyName,
  2790. const String& value) throw()
  2791. {
  2792. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2793. if (keyName.isNotEmpty())
  2794. {
  2795. const ScopedLock sl (lock);
  2796. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2797. if (index < 0 || properties.getAllValues() [index] != value)
  2798. {
  2799. properties.set (keyName, value);
  2800. propertyChanged();
  2801. }
  2802. }
  2803. }
  2804. void PropertySet::removeValue (const String& keyName) throw()
  2805. {
  2806. if (keyName.isNotEmpty())
  2807. {
  2808. const ScopedLock sl (lock);
  2809. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2810. if (index >= 0)
  2811. {
  2812. properties.remove (keyName);
  2813. propertyChanged();
  2814. }
  2815. }
  2816. }
  2817. void PropertySet::setValue (const String& keyName, const int value) throw()
  2818. {
  2819. setValue (keyName, String (value));
  2820. }
  2821. void PropertySet::setValue (const String& keyName, const double value) throw()
  2822. {
  2823. setValue (keyName, String (value));
  2824. }
  2825. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2826. {
  2827. setValue (keyName, String (value ? "1" : "0"));
  2828. }
  2829. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2830. {
  2831. setValue (keyName, (xml == 0) ? String::empty
  2832. : xml->createDocument (String::empty, true));
  2833. }
  2834. bool PropertySet::containsKey (const String& keyName) const throw()
  2835. {
  2836. const ScopedLock sl (lock);
  2837. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2838. }
  2839. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2840. {
  2841. const ScopedLock sl (lock);
  2842. fallbackProperties = fallbackProperties_;
  2843. }
  2844. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2845. {
  2846. const ScopedLock sl (lock);
  2847. XmlElement* const xml = new XmlElement (nodeName);
  2848. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2849. {
  2850. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2851. e->setAttribute ("name", properties.getAllKeys()[i]);
  2852. e->setAttribute ("val", properties.getAllValues()[i]);
  2853. }
  2854. return xml;
  2855. }
  2856. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2857. {
  2858. const ScopedLock sl (lock);
  2859. clear();
  2860. forEachXmlChildElementWithTagName (xml, e, "VALUE")
  2861. {
  2862. if (e->hasAttribute ("name")
  2863. && e->hasAttribute ("val"))
  2864. {
  2865. properties.set (e->getStringAttribute ("name"),
  2866. e->getStringAttribute ("val"));
  2867. }
  2868. }
  2869. if (properties.size() > 0)
  2870. propertyChanged();
  2871. }
  2872. void PropertySet::propertyChanged()
  2873. {
  2874. }
  2875. END_JUCE_NAMESPACE
  2876. /*** End of inlined file: juce_PropertySet.cpp ***/
  2877. /*** Start of inlined file: juce_Variant.cpp ***/
  2878. BEGIN_JUCE_NAMESPACE
  2879. var::var() throw()
  2880. : type (voidType)
  2881. {
  2882. value.doubleValue = 0;
  2883. }
  2884. var::~var() throw()
  2885. {
  2886. if (type == stringType)
  2887. delete value.stringValue;
  2888. else if (type == objectType && value.objectValue != 0)
  2889. value.objectValue->decReferenceCount();
  2890. }
  2891. const var var::null;
  2892. var::var (const var& valueToCopy)
  2893. : type (valueToCopy.type),
  2894. value (valueToCopy.value)
  2895. {
  2896. if (type == stringType)
  2897. value.stringValue = new String (*(value.stringValue));
  2898. else if (type == objectType && value.objectValue != 0)
  2899. value.objectValue->incReferenceCount();
  2900. }
  2901. var::var (const int value_) throw()
  2902. : type (intType)
  2903. {
  2904. value.intValue = value_;
  2905. }
  2906. var::var (const bool value_) throw()
  2907. : type (boolType)
  2908. {
  2909. value.boolValue = value_;
  2910. }
  2911. var::var (const double value_) throw()
  2912. : type (doubleType)
  2913. {
  2914. value.doubleValue = value_;
  2915. }
  2916. var::var (const String& value_)
  2917. : type (stringType)
  2918. {
  2919. value.stringValue = new String (value_);
  2920. }
  2921. var::var (const char* const value_)
  2922. : type (stringType)
  2923. {
  2924. value.stringValue = new String (value_);
  2925. }
  2926. var::var (const juce_wchar* const value_)
  2927. : type (stringType)
  2928. {
  2929. value.stringValue = new String (value_);
  2930. }
  2931. var::var (DynamicObject* const object)
  2932. : type (objectType)
  2933. {
  2934. value.objectValue = object;
  2935. if (object != 0)
  2936. object->incReferenceCount();
  2937. }
  2938. var::var (MethodFunction method_) throw()
  2939. : type (methodType)
  2940. {
  2941. value.methodValue = method_;
  2942. }
  2943. void var::swapWith (var& other) throw()
  2944. {
  2945. swapVariables (type, other.type);
  2946. swapVariables (value, other.value);
  2947. }
  2948. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2949. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2950. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2951. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2952. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2953. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2954. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2955. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2956. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2957. var::operator int() const
  2958. {
  2959. switch (type)
  2960. {
  2961. case voidType: break;
  2962. case intType: return value.intValue;
  2963. case boolType: return value.boolValue ? 1 : 0;
  2964. case doubleType: return static_cast <int> (value.doubleValue);
  2965. case stringType: return value.stringValue->getIntValue();
  2966. case objectType: break;
  2967. default: jassertfalse; break;
  2968. }
  2969. return 0;
  2970. }
  2971. var::operator bool() const
  2972. {
  2973. switch (type)
  2974. {
  2975. case voidType: break;
  2976. case intType: return value.intValue != 0;
  2977. case boolType: return value.boolValue;
  2978. case doubleType: return value.doubleValue != 0;
  2979. case stringType: return value.stringValue->getIntValue() != 0
  2980. || value.stringValue->trim().equalsIgnoreCase ("true")
  2981. || value.stringValue->trim().equalsIgnoreCase ("yes");
  2982. case objectType: return value.objectValue != 0;
  2983. default: jassertfalse; break;
  2984. }
  2985. return false;
  2986. }
  2987. var::operator float() const
  2988. {
  2989. return (float) operator double();
  2990. }
  2991. var::operator double() const
  2992. {
  2993. switch (type)
  2994. {
  2995. case voidType: break;
  2996. case intType: return value.intValue;
  2997. case boolType: return value.boolValue ? 1.0 : 0.0;
  2998. case doubleType: return value.doubleValue;
  2999. case stringType: return value.stringValue->getDoubleValue();
  3000. case objectType: break;
  3001. default: jassertfalse; break;
  3002. }
  3003. return 0.0;
  3004. }
  3005. const String var::toString() const
  3006. {
  3007. switch (type)
  3008. {
  3009. case voidType: return String::empty;
  3010. case intType: return String (value.intValue);
  3011. case boolType: return String::charToString (value.boolValue ? '1' : '0');
  3012. case doubleType: return String (value.doubleValue);
  3013. case stringType: return *(value.stringValue);
  3014. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  3015. case methodType: return "Method";
  3016. default: jassertfalse; break;
  3017. }
  3018. return String::empty;
  3019. }
  3020. var::operator const String() const
  3021. {
  3022. return toString();
  3023. }
  3024. DynamicObject* var::getObject() const
  3025. {
  3026. return type == objectType ? value.objectValue : 0;
  3027. }
  3028. bool var::equals (const var& other) const throw()
  3029. {
  3030. switch (type)
  3031. {
  3032. case voidType: return other.isVoid();
  3033. case intType: return value.intValue == static_cast <int> (other);
  3034. case boolType: return value.boolValue == static_cast <bool> (other);
  3035. case doubleType: return value.doubleValue == static_cast <double> (other);
  3036. case stringType: return (*(value.stringValue)) == other.toString();
  3037. case objectType: return value.objectValue == other.getObject();
  3038. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  3039. default: jassertfalse; break;
  3040. }
  3041. return false;
  3042. }
  3043. bool operator== (const var& v1, const var& v2) throw() { return v1.equals (v2); }
  3044. bool operator!= (const var& v1, const var& v2) throw() { return ! v1.equals (v2); }
  3045. bool operator== (const var& v1, const String& v2) throw() { return v1.toString() == v2; }
  3046. bool operator!= (const var& v1, const String& v2) throw() { return v1.toString() != v2; }
  3047. void var::writeToStream (OutputStream& output) const
  3048. {
  3049. switch (type)
  3050. {
  3051. case voidType: output.writeCompressedInt (0); break;
  3052. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  3053. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  3054. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  3055. case stringType:
  3056. {
  3057. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  3058. output.writeCompressedInt (len + 1);
  3059. output.writeByte (5);
  3060. HeapBlock<char> temp (len);
  3061. value.stringValue->copyToUTF8 (temp, len);
  3062. output.write (temp, len);
  3063. break;
  3064. }
  3065. case objectType:
  3066. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3067. default: jassertfalse; break; // Is this a corrupted object?
  3068. }
  3069. }
  3070. const var var::readFromStream (InputStream& input)
  3071. {
  3072. const int numBytes = input.readCompressedInt();
  3073. if (numBytes > 0)
  3074. {
  3075. switch (input.readByte())
  3076. {
  3077. case 1: return var (input.readInt());
  3078. case 2: return var (true);
  3079. case 3: return var (false);
  3080. case 4: return var (input.readDouble());
  3081. case 5:
  3082. {
  3083. MemoryBlock mb;
  3084. input.readIntoMemoryBlock (mb, numBytes - 1);
  3085. return var (String::fromUTF8 (static_cast <const char*> (mb.getData()), (int) mb.getSize()));
  3086. }
  3087. default: input.skipNextBytes (numBytes - 1); break;
  3088. }
  3089. }
  3090. return var::null;
  3091. }
  3092. const var var::operator[] (const var::identifier& propertyName) const
  3093. {
  3094. if (type == objectType && value.objectValue != 0)
  3095. return value.objectValue->getProperty (propertyName);
  3096. return var::null;
  3097. }
  3098. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3099. {
  3100. if (type == objectType && value.objectValue != 0)
  3101. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3102. return var::null;
  3103. }
  3104. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3105. {
  3106. if (isMethod())
  3107. {
  3108. DynamicObject* const target = targetObject.getObject();
  3109. if (target != 0)
  3110. return (target->*(value.methodValue)) (arguments, numArguments);
  3111. }
  3112. return var::null;
  3113. }
  3114. const var var::call (const var::identifier& method) const
  3115. {
  3116. return invoke (method, 0, 0);
  3117. }
  3118. const var var::call (const var::identifier& method, const var& arg1) const
  3119. {
  3120. return invoke (method, &arg1, 1);
  3121. }
  3122. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3123. {
  3124. var args[] = { arg1, arg2 };
  3125. return invoke (method, args, 2);
  3126. }
  3127. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3128. {
  3129. var args[] = { arg1, arg2, arg3 };
  3130. return invoke (method, args, 3);
  3131. }
  3132. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3133. {
  3134. var args[] = { arg1, arg2, arg3, arg4 };
  3135. return invoke (method, args, 4);
  3136. }
  3137. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3138. {
  3139. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3140. return invoke (method, args, 5);
  3141. }
  3142. var::identifier::identifier() throw()
  3143. : hashCode (0)
  3144. {
  3145. }
  3146. var::identifier::identifier (const String& name_)
  3147. : name (name_),
  3148. hashCode (name_.hashCode())
  3149. {
  3150. /* An identifier string must be suitable for use as a script variable or XML
  3151. attribute, so it can only contain this limited set of characters.. */
  3152. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3153. }
  3154. var::identifier::identifier (const char* const name_)
  3155. : name (name_),
  3156. hashCode (name.hashCode())
  3157. {
  3158. /* An identifier string must be suitable for use as a script variable or XML
  3159. attribute, so it can only contain this limited set of characters.. */
  3160. jassert (name.containsOnly ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_") && name.isNotEmpty());
  3161. }
  3162. var::identifier::~identifier()
  3163. {
  3164. }
  3165. END_JUCE_NAMESPACE
  3166. /*** End of inlined file: juce_Variant.cpp ***/
  3167. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3168. BEGIN_JUCE_NAMESPACE
  3169. NamedValueSet::NamedValue::NamedValue() throw()
  3170. {
  3171. }
  3172. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3173. : name (name_), value (value_)
  3174. {
  3175. }
  3176. NamedValueSet::NamedValueSet() throw()
  3177. {
  3178. }
  3179. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3180. : values (other.values)
  3181. {
  3182. }
  3183. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3184. {
  3185. values = other.values;
  3186. return *this;
  3187. }
  3188. NamedValueSet::~NamedValueSet()
  3189. {
  3190. }
  3191. int NamedValueSet::size() const throw()
  3192. {
  3193. return values.size();
  3194. }
  3195. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3196. {
  3197. for (int i = values.size(); --i >= 0;)
  3198. {
  3199. const NamedValue& v = values.getReference(i);
  3200. if (v.name == name)
  3201. return v.value;
  3202. }
  3203. return var::null;
  3204. }
  3205. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3206. {
  3207. const var* v = getItem (name);
  3208. return v != 0 ? *v : defaultReturnValue;
  3209. }
  3210. var* NamedValueSet::getItem (const var::identifier& name) const
  3211. {
  3212. for (int i = values.size(); --i >= 0;)
  3213. {
  3214. NamedValue& v = values.getReference(i);
  3215. if (v.name == name)
  3216. return &(v.value);
  3217. }
  3218. return 0;
  3219. }
  3220. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3221. {
  3222. for (int i = values.size(); --i >= 0;)
  3223. {
  3224. NamedValue& v = values.getReference(i);
  3225. if (v.name == name)
  3226. {
  3227. if (v.value == newValue)
  3228. return false;
  3229. v.value = newValue;
  3230. return true;
  3231. }
  3232. }
  3233. values.add (NamedValue (name, newValue));
  3234. return true;
  3235. }
  3236. bool NamedValueSet::contains (const var::identifier& name) const
  3237. {
  3238. return getItem (name) != 0;
  3239. }
  3240. bool NamedValueSet::remove (const var::identifier& name)
  3241. {
  3242. for (int i = values.size(); --i >= 0;)
  3243. {
  3244. if (values.getReference(i).name == name)
  3245. {
  3246. values.remove (i);
  3247. return true;
  3248. }
  3249. }
  3250. return false;
  3251. }
  3252. const var::identifier NamedValueSet::getName (int index) const
  3253. {
  3254. jassert (((unsigned int) index) < (unsigned int) values.size());
  3255. return values [index].name;
  3256. }
  3257. void NamedValueSet::clear()
  3258. {
  3259. values.clear();
  3260. }
  3261. END_JUCE_NAMESPACE
  3262. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3263. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3264. BEGIN_JUCE_NAMESPACE
  3265. DynamicObject::DynamicObject()
  3266. {
  3267. }
  3268. DynamicObject::~DynamicObject()
  3269. {
  3270. }
  3271. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3272. {
  3273. var* const v = properties.getItem (propertyName);
  3274. return v != 0 && ! v->isMethod();
  3275. }
  3276. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3277. {
  3278. return properties [propertyName];
  3279. }
  3280. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3281. {
  3282. properties.set (propertyName, newValue);
  3283. }
  3284. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3285. {
  3286. properties.remove (propertyName);
  3287. }
  3288. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3289. {
  3290. return getProperty (methodName).isMethod();
  3291. }
  3292. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3293. const var* parameters,
  3294. int numParameters)
  3295. {
  3296. return properties [methodName].invoke (var (this), parameters, numParameters);
  3297. }
  3298. void DynamicObject::setMethod (const var::identifier& name,
  3299. var::MethodFunction methodFunction)
  3300. {
  3301. properties.set (name, var (methodFunction));
  3302. }
  3303. void DynamicObject::clear()
  3304. {
  3305. properties.clear();
  3306. }
  3307. END_JUCE_NAMESPACE
  3308. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3309. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3310. BEGIN_JUCE_NAMESPACE
  3311. BlowFish::BlowFish (const void* const keyData, const int keyBytes)
  3312. {
  3313. jassert (keyData != 0);
  3314. jassert (keyBytes > 0);
  3315. static const uint32 initialPValues [18] =
  3316. {
  3317. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3318. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3319. 0x9216d5d9, 0x8979fb1b
  3320. };
  3321. static const uint32 initialSValues [4 * 256] =
  3322. {
  3323. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3324. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3325. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3326. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3327. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3328. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3329. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3330. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3331. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3332. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3333. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3334. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3335. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3336. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3337. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3338. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3339. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3340. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3341. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3342. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3343. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3344. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3345. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3346. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3347. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3348. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3349. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3350. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3351. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3352. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3353. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3354. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3355. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3356. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3357. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3358. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3359. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3360. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3361. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3362. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3363. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3364. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3365. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3366. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3367. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3368. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3369. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3370. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3371. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3372. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3373. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3374. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3375. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3376. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3377. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3378. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3379. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3380. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3381. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3382. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3383. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3384. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3385. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3386. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3387. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3388. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3389. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3390. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3391. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3392. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3393. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3394. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3395. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3396. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3397. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3398. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3399. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3400. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3401. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3402. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3403. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3404. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3405. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3406. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3407. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3408. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3409. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3410. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3411. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3412. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3413. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3414. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3415. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3416. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3417. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3418. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3419. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3420. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3421. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3422. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3423. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3424. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3425. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3426. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3427. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3428. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3429. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3430. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3431. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3432. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3433. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3434. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3435. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3436. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3437. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3438. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3439. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3440. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3441. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3442. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3443. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3444. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3445. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3446. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3447. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3448. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3449. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3450. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3451. };
  3452. memcpy (p, initialPValues, sizeof (p));
  3453. int i, j = 0;
  3454. for (i = 4; --i >= 0;)
  3455. {
  3456. s[i].malloc (256);
  3457. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3458. }
  3459. for (i = 0; i < 18; ++i)
  3460. {
  3461. uint32 d = 0;
  3462. for (int k = 0; k < 4; ++k)
  3463. {
  3464. d = (d << 8) | static_cast <const uint8*> (keyData)[j];
  3465. if (++j >= keyBytes)
  3466. j = 0;
  3467. }
  3468. p[i] = initialPValues[i] ^ d;
  3469. }
  3470. uint32 l = 0, r = 0;
  3471. for (i = 0; i < 18; i += 2)
  3472. {
  3473. encrypt (l, r);
  3474. p[i] = l;
  3475. p[i + 1] = r;
  3476. }
  3477. for (i = 0; i < 4; ++i)
  3478. {
  3479. for (j = 0; j < 256; j += 2)
  3480. {
  3481. encrypt (l, r);
  3482. s[i][j] = l;
  3483. s[i][j + 1] = r;
  3484. }
  3485. }
  3486. }
  3487. BlowFish::BlowFish (const BlowFish& other)
  3488. {
  3489. for (int i = 4; --i >= 0;)
  3490. s[i].malloc (256);
  3491. operator= (other);
  3492. }
  3493. BlowFish& BlowFish::operator= (const BlowFish& other)
  3494. {
  3495. memcpy (p, other.p, sizeof (p));
  3496. for (int i = 4; --i >= 0;)
  3497. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3498. return *this;
  3499. }
  3500. BlowFish::~BlowFish()
  3501. {
  3502. }
  3503. uint32 BlowFish::F (const uint32 x) const throw()
  3504. {
  3505. return ((s[0][(x >> 24) & 0xff] + s[1][(x >> 16) & 0xff])
  3506. ^ s[2][(x >> 8) & 0xff]) + s[3][x & 0xff];
  3507. }
  3508. void BlowFish::encrypt (uint32& data1, uint32& data2) const throw()
  3509. {
  3510. uint32 l = data1;
  3511. uint32 r = data2;
  3512. for (int i = 0; i < 16; ++i)
  3513. {
  3514. l ^= p[i];
  3515. r ^= F(l);
  3516. swapVariables (l, r);
  3517. }
  3518. data1 = r ^ p[17];
  3519. data2 = l ^ p[16];
  3520. }
  3521. void BlowFish::decrypt (uint32& data1, uint32& data2) const throw()
  3522. {
  3523. uint32 l = data1;
  3524. uint32 r = data2;
  3525. for (int i = 17; i > 1; --i)
  3526. {
  3527. l ^= p[i];
  3528. r ^= F(l);
  3529. swapVariables (l, r);
  3530. }
  3531. data1 = r ^ p[0];
  3532. data2 = l ^ p[1];
  3533. }
  3534. END_JUCE_NAMESPACE
  3535. /*** End of inlined file: juce_BlowFish.cpp ***/
  3536. /*** Start of inlined file: juce_MD5.cpp ***/
  3537. BEGIN_JUCE_NAMESPACE
  3538. MD5::MD5()
  3539. {
  3540. zerostruct (result);
  3541. }
  3542. MD5::MD5 (const MD5& other)
  3543. {
  3544. memcpy (result, other.result, sizeof (result));
  3545. }
  3546. MD5& MD5::operator= (const MD5& other)
  3547. {
  3548. memcpy (result, other.result, sizeof (result));
  3549. return *this;
  3550. }
  3551. MD5::MD5 (const MemoryBlock& data)
  3552. {
  3553. ProcessContext context;
  3554. context.processBlock (data.getData(), data.getSize());
  3555. context.finish (result);
  3556. }
  3557. MD5::MD5 (const void* data, const size_t numBytes)
  3558. {
  3559. ProcessContext context;
  3560. context.processBlock (data, numBytes);
  3561. context.finish (result);
  3562. }
  3563. MD5::MD5 (const String& text)
  3564. {
  3565. ProcessContext context;
  3566. const int len = text.length();
  3567. const juce_wchar* const t = text;
  3568. for (int i = 0; i < len; ++i)
  3569. {
  3570. // force the string into integer-sized unicode characters, to try to make it
  3571. // get the same results on all platforms + compilers.
  3572. uint32 unicodeChar = ByteOrder::swapIfBigEndian ((uint32) t[i]);
  3573. context.processBlock (&unicodeChar, sizeof (unicodeChar));
  3574. }
  3575. context.finish (result);
  3576. }
  3577. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3578. {
  3579. ProcessContext context;
  3580. if (numBytesToRead < 0)
  3581. numBytesToRead = std::numeric_limits<int64>::max();
  3582. while (numBytesToRead > 0)
  3583. {
  3584. uint8 tempBuffer [512];
  3585. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3586. if (bytesRead <= 0)
  3587. break;
  3588. numBytesToRead -= bytesRead;
  3589. context.processBlock (tempBuffer, bytesRead);
  3590. }
  3591. context.finish (result);
  3592. }
  3593. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3594. {
  3595. processStream (input, numBytesToRead);
  3596. }
  3597. MD5::MD5 (const File& file)
  3598. {
  3599. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3600. if (fin != 0)
  3601. processStream (*fin, -1);
  3602. else
  3603. zerostruct (result);
  3604. }
  3605. MD5::~MD5()
  3606. {
  3607. }
  3608. namespace MD5Functions
  3609. {
  3610. static void encode (void* const output, const void* const input, const int numBytes) throw()
  3611. {
  3612. for (int i = 0; i < (numBytes >> 2); ++i)
  3613. static_cast<uint32*> (output)[i] = ByteOrder::swapIfBigEndian (static_cast<const uint32*> (input) [i]);
  3614. }
  3615. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3616. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3617. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3618. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3619. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3620. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3621. {
  3622. a += F (b, c, d) + x + ac;
  3623. a = rotateLeft (a, s) + b;
  3624. }
  3625. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3626. {
  3627. a += G (b, c, d) + x + ac;
  3628. a = rotateLeft (a, s) + b;
  3629. }
  3630. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3631. {
  3632. a += H (b, c, d) + x + ac;
  3633. a = rotateLeft (a, s) + b;
  3634. }
  3635. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3636. {
  3637. a += I (b, c, d) + x + ac;
  3638. a = rotateLeft (a, s) + b;
  3639. }
  3640. }
  3641. MD5::ProcessContext::ProcessContext()
  3642. {
  3643. state[0] = 0x67452301;
  3644. state[1] = 0xefcdab89;
  3645. state[2] = 0x98badcfe;
  3646. state[3] = 0x10325476;
  3647. count[0] = 0;
  3648. count[1] = 0;
  3649. }
  3650. void MD5::ProcessContext::processBlock (const void* const data, const size_t dataSize)
  3651. {
  3652. int bufferPos = ((count[0] >> 3) & 0x3F);
  3653. count[0] += (uint32) (dataSize << 3);
  3654. if (count[0] < ((uint32) dataSize << 3))
  3655. count[1]++;
  3656. count[1] += (uint32) (dataSize >> 29);
  3657. const size_t spaceLeft = 64 - bufferPos;
  3658. size_t i = 0;
  3659. if (dataSize >= spaceLeft)
  3660. {
  3661. memcpy (buffer + bufferPos, data, spaceLeft);
  3662. transform (buffer);
  3663. for (i = spaceLeft; i + 64 <= dataSize; i += 64)
  3664. transform (static_cast <const char*> (data) + i);
  3665. bufferPos = 0;
  3666. }
  3667. memcpy (buffer + bufferPos, static_cast <const char*> (data) + i, dataSize - i);
  3668. }
  3669. void MD5::ProcessContext::finish (void* const result)
  3670. {
  3671. unsigned char encodedLength[8];
  3672. MD5Functions::encode (encodedLength, count, 8);
  3673. // Pad out to 56 mod 64.
  3674. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3675. const int paddingLength = (index < 56) ? (56 - index)
  3676. : (120 - index);
  3677. uint8 paddingBuffer [64];
  3678. zeromem (paddingBuffer, paddingLength);
  3679. paddingBuffer [0] = 0x80;
  3680. processBlock (paddingBuffer, paddingLength);
  3681. processBlock (encodedLength, 8);
  3682. MD5Functions::encode (result, state, 16);
  3683. zerostruct (buffer);
  3684. }
  3685. void MD5::ProcessContext::transform (const void* const bufferToTransform)
  3686. {
  3687. using namespace MD5Functions;
  3688. uint32 a = state[0];
  3689. uint32 b = state[1];
  3690. uint32 c = state[2];
  3691. uint32 d = state[3];
  3692. uint32 x[16];
  3693. encode (x, bufferToTransform, 64);
  3694. enum Constants
  3695. {
  3696. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3697. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3698. };
  3699. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); FF (d, a, b, c, x[ 1], S12, 0xe8c7b756);
  3700. FF (c, d, a, b, x[ 2], S13, 0x242070db); FF (b, c, d, a, x[ 3], S14, 0xc1bdceee);
  3701. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); FF (d, a, b, c, x[ 5], S12, 0x4787c62a);
  3702. FF (c, d, a, b, x[ 6], S13, 0xa8304613); FF (b, c, d, a, x[ 7], S14, 0xfd469501);
  3703. FF (a, b, c, d, x[ 8], S11, 0x698098d8); FF (d, a, b, c, x[ 9], S12, 0x8b44f7af);
  3704. FF (c, d, a, b, x[10], S13, 0xffff5bb1); FF (b, c, d, a, x[11], S14, 0x895cd7be);
  3705. FF (a, b, c, d, x[12], S11, 0x6b901122); FF (d, a, b, c, x[13], S12, 0xfd987193);
  3706. FF (c, d, a, b, x[14], S13, 0xa679438e); FF (b, c, d, a, x[15], S14, 0x49b40821);
  3707. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); GG (d, a, b, c, x[ 6], S22, 0xc040b340);
  3708. GG (c, d, a, b, x[11], S23, 0x265e5a51); GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa);
  3709. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); GG (d, a, b, c, x[10], S22, 0x02441453);
  3710. GG (c, d, a, b, x[15], S23, 0xd8a1e681); GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8);
  3711. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); GG (d, a, b, c, x[14], S22, 0xc33707d6);
  3712. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); GG (b, c, d, a, x[ 8], S24, 0x455a14ed);
  3713. GG (a, b, c, d, x[13], S21, 0xa9e3e905); GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8);
  3714. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); GG (b, c, d, a, x[12], S24, 0x8d2a4c8a);
  3715. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); HH (d, a, b, c, x[ 8], S32, 0x8771f681);
  3716. HH (c, d, a, b, x[11], S33, 0x6d9d6122); HH (b, c, d, a, x[14], S34, 0xfde5380c);
  3717. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9);
  3718. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); HH (b, c, d, a, x[10], S34, 0xbebfbc70);
  3719. HH (a, b, c, d, x[13], S31, 0x289b7ec6); HH (d, a, b, c, x[ 0], S32, 0xeaa127fa);
  3720. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); HH (b, c, d, a, x[ 6], S34, 0x04881d05);
  3721. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); HH (d, a, b, c, x[12], S32, 0xe6db99e5);
  3722. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); HH (b, c, d, a, x[ 2], S34, 0xc4ac5665);
  3723. II (a, b, c, d, x[ 0], S41, 0xf4292244); II (d, a, b, c, x[ 7], S42, 0x432aff97);
  3724. II (c, d, a, b, x[14], S43, 0xab9423a7); II (b, c, d, a, x[ 5], S44, 0xfc93a039);
  3725. II (a, b, c, d, x[12], S41, 0x655b59c3); II (d, a, b, c, x[ 3], S42, 0x8f0ccc92);
  3726. II (c, d, a, b, x[10], S43, 0xffeff47d); II (b, c, d, a, x[ 1], S44, 0x85845dd1);
  3727. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); II (d, a, b, c, x[15], S42, 0xfe2ce6e0);
  3728. II (c, d, a, b, x[ 6], S43, 0xa3014314); II (b, c, d, a, x[13], S44, 0x4e0811a1);
  3729. II (a, b, c, d, x[ 4], S41, 0xf7537e82); II (d, a, b, c, x[11], S42, 0xbd3af235);
  3730. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); II (b, c, d, a, x[ 9], S44, 0xeb86d391);
  3731. state[0] += a;
  3732. state[1] += b;
  3733. state[2] += c;
  3734. state[3] += d;
  3735. zerostruct (x);
  3736. }
  3737. const MemoryBlock MD5::getRawChecksumData() const
  3738. {
  3739. return MemoryBlock (result, sizeof (result));
  3740. }
  3741. const String MD5::toHexString() const
  3742. {
  3743. return String::toHexString (result, sizeof (result), 0);
  3744. }
  3745. bool MD5::operator== (const MD5& other) const
  3746. {
  3747. return memcmp (result, other.result, sizeof (result)) == 0;
  3748. }
  3749. bool MD5::operator!= (const MD5& other) const
  3750. {
  3751. return ! operator== (other);
  3752. }
  3753. END_JUCE_NAMESPACE
  3754. /*** End of inlined file: juce_MD5.cpp ***/
  3755. /*** Start of inlined file: juce_Primes.cpp ***/
  3756. BEGIN_JUCE_NAMESPACE
  3757. namespace PrimesHelpers
  3758. {
  3759. static void createSmallSieve (const int numBits, BigInteger& result)
  3760. {
  3761. result.setBit (numBits);
  3762. result.clearBit (numBits); // to enlarge the array
  3763. result.setBit (0);
  3764. int n = 2;
  3765. do
  3766. {
  3767. for (int i = n + n; i < numBits; i += n)
  3768. result.setBit (i);
  3769. n = result.findNextClearBit (n + 1);
  3770. }
  3771. while (n <= (numBits >> 1));
  3772. }
  3773. static void bigSieve (const BigInteger& base, const int numBits, BigInteger& result,
  3774. const BigInteger& smallSieve, const int smallSieveSize)
  3775. {
  3776. jassert (! base[0]); // must be even!
  3777. result.setBit (numBits);
  3778. result.clearBit (numBits); // to enlarge the array
  3779. int index = smallSieve.findNextClearBit (0);
  3780. do
  3781. {
  3782. const int prime = (index << 1) + 1;
  3783. BigInteger r (base), remainder;
  3784. r.divideBy (prime, remainder);
  3785. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3786. if (r.isZero())
  3787. i += prime;
  3788. if ((i & 1) == 0)
  3789. i += prime;
  3790. i = (i - 1) >> 1;
  3791. while (i < numBits)
  3792. {
  3793. result.setBit (i);
  3794. i += prime;
  3795. }
  3796. index = smallSieve.findNextClearBit (index + 1);
  3797. }
  3798. while (index < smallSieveSize);
  3799. }
  3800. static bool findCandidate (const BigInteger& base, const BigInteger& sieve,
  3801. const int numBits, BigInteger& result, const int certainty)
  3802. {
  3803. for (int i = 0; i < numBits; ++i)
  3804. {
  3805. if (! sieve[i])
  3806. {
  3807. result = base + (unsigned int) ((i << 1) + 1);
  3808. if (Primes::isProbablyPrime (result, certainty))
  3809. return true;
  3810. }
  3811. }
  3812. return false;
  3813. }
  3814. static bool passesMillerRabin (const BigInteger& n, int iterations)
  3815. {
  3816. const BigInteger one (1), two (2);
  3817. const BigInteger nMinusOne (n - one);
  3818. BigInteger d (nMinusOne);
  3819. const int s = d.findNextSetBit (0);
  3820. d >>= s;
  3821. BigInteger smallPrimes;
  3822. int numBitsInSmallPrimes = 0;
  3823. for (;;)
  3824. {
  3825. numBitsInSmallPrimes += 256;
  3826. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  3827. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  3828. if (numPrimesFound > iterations + 1)
  3829. break;
  3830. }
  3831. int smallPrime = 2;
  3832. while (--iterations >= 0)
  3833. {
  3834. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  3835. BigInteger r (smallPrime);
  3836. r.exponentModulo (d, n);
  3837. if (r != one && r != nMinusOne)
  3838. {
  3839. for (int j = 0; j < s; ++j)
  3840. {
  3841. r.exponentModulo (two, n);
  3842. if (r == nMinusOne)
  3843. break;
  3844. }
  3845. if (r != nMinusOne)
  3846. return false;
  3847. }
  3848. }
  3849. return true;
  3850. }
  3851. }
  3852. const BigInteger Primes::createProbablePrime (const int bitLength,
  3853. const int certainty,
  3854. const int* randomSeeds,
  3855. int numRandomSeeds)
  3856. {
  3857. using namespace PrimesHelpers;
  3858. int defaultSeeds [16];
  3859. if (numRandomSeeds <= 0)
  3860. {
  3861. randomSeeds = defaultSeeds;
  3862. numRandomSeeds = numElementsInArray (defaultSeeds);
  3863. Random r (0);
  3864. for (int j = 10; --j >= 0;)
  3865. {
  3866. r.setSeedRandomly();
  3867. for (int i = numRandomSeeds; --i >= 0;)
  3868. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3869. }
  3870. }
  3871. BigInteger smallSieve;
  3872. const int smallSieveSize = 15000;
  3873. createSmallSieve (smallSieveSize, smallSieve);
  3874. BigInteger p;
  3875. for (int i = numRandomSeeds; --i >= 0;)
  3876. {
  3877. BigInteger p2;
  3878. Random r (randomSeeds[i]);
  3879. r.fillBitsRandomly (p2, 0, bitLength);
  3880. p ^= p2;
  3881. }
  3882. p.setBit (bitLength - 1);
  3883. p.clearBit (0);
  3884. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3885. while (p.getHighestBit() < bitLength)
  3886. {
  3887. p += 2 * searchLen;
  3888. BigInteger sieve;
  3889. bigSieve (p, searchLen, sieve,
  3890. smallSieve, smallSieveSize);
  3891. BigInteger candidate;
  3892. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  3893. return candidate;
  3894. }
  3895. jassertfalse
  3896. return BigInteger();
  3897. }
  3898. bool Primes::isProbablyPrime (const BigInteger& number, const int certainty)
  3899. {
  3900. using namespace PrimesHelpers;
  3901. if (! number[0])
  3902. return false;
  3903. if (number.getHighestBit() <= 10)
  3904. {
  3905. const int num = number.getBitRangeAsInt (0, 10);
  3906. for (int i = num / 2; --i > 1;)
  3907. if (num % i == 0)
  3908. return false;
  3909. return true;
  3910. }
  3911. else
  3912. {
  3913. if (number.findGreatestCommonDivisor (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23) != 1)
  3914. return false;
  3915. return passesMillerRabin (number, certainty);
  3916. }
  3917. }
  3918. END_JUCE_NAMESPACE
  3919. /*** End of inlined file: juce_Primes.cpp ***/
  3920. /*** Start of inlined file: juce_RSAKey.cpp ***/
  3921. BEGIN_JUCE_NAMESPACE
  3922. RSAKey::RSAKey()
  3923. {
  3924. }
  3925. RSAKey::RSAKey (const String& s)
  3926. {
  3927. if (s.containsChar (','))
  3928. {
  3929. part1.parseString (s.upToFirstOccurrenceOf (",", false, false), 16);
  3930. part2.parseString (s.fromFirstOccurrenceOf (",", false, false), 16);
  3931. }
  3932. else
  3933. {
  3934. // the string needs to be two hex numbers, comma-separated..
  3935. jassertfalse;
  3936. }
  3937. }
  3938. RSAKey::~RSAKey()
  3939. {
  3940. }
  3941. const String RSAKey::toString() const
  3942. {
  3943. return part1.toString (16) + "," + part2.toString (16);
  3944. }
  3945. bool RSAKey::applyToValue (BigInteger& value) const
  3946. {
  3947. if (part1.isZero() || part2.isZero() || value <= 0)
  3948. {
  3949. jassertfalse // using an uninitialised key
  3950. value.clear();
  3951. return false;
  3952. }
  3953. BigInteger result;
  3954. while (! value.isZero())
  3955. {
  3956. result *= part2;
  3957. BigInteger remainder;
  3958. value.divideBy (part2, remainder);
  3959. remainder.exponentModulo (part1, part2);
  3960. result += remainder;
  3961. }
  3962. value.swapWith (result);
  3963. return true;
  3964. }
  3965. static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q)
  3966. {
  3967. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  3968. // are fast to divide + multiply
  3969. for (int i = 2; i <= 65536; i *= 2)
  3970. {
  3971. const BigInteger e (1 + i);
  3972. if (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne())
  3973. return e;
  3974. }
  3975. BigInteger e (4);
  3976. while (! (e.findGreatestCommonDivisor (p).isOne() && e.findGreatestCommonDivisor (q).isOne()))
  3977. ++e;
  3978. return e;
  3979. }
  3980. void RSAKey::createKeyPair (RSAKey& publicKey, RSAKey& privateKey,
  3981. const int numBits, const int* randomSeeds, const int numRandomSeeds)
  3982. {
  3983. jassert (numBits > 16); // not much point using less than this..
  3984. BigInteger p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  3985. BigInteger q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  3986. const BigInteger n (p * q);
  3987. const BigInteger m (--p * --q);
  3988. const BigInteger e (findBestCommonDivisor (p, q));
  3989. BigInteger d (e);
  3990. d.inverseModulo (m);
  3991. publicKey.part1 = e;
  3992. publicKey.part2 = n;
  3993. privateKey.part1 = d;
  3994. privateKey.part2 = n;
  3995. }
  3996. END_JUCE_NAMESPACE
  3997. /*** End of inlined file: juce_RSAKey.cpp ***/
  3998. /*** Start of inlined file: juce_InputStream.cpp ***/
  3999. BEGIN_JUCE_NAMESPACE
  4000. char InputStream::readByte()
  4001. {
  4002. char temp = 0;
  4003. read (&temp, 1);
  4004. return temp;
  4005. }
  4006. bool InputStream::readBool()
  4007. {
  4008. return readByte() != 0;
  4009. }
  4010. short InputStream::readShort()
  4011. {
  4012. char temp[2];
  4013. if (read (temp, 2) == 2)
  4014. return (short) ByteOrder::littleEndianShort (temp);
  4015. return 0;
  4016. }
  4017. short InputStream::readShortBigEndian()
  4018. {
  4019. char temp[2];
  4020. if (read (temp, 2) == 2)
  4021. return (short) ByteOrder::bigEndianShort (temp);
  4022. return 0;
  4023. }
  4024. int InputStream::readInt()
  4025. {
  4026. char temp[4];
  4027. if (read (temp, 4) == 4)
  4028. return (int) ByteOrder::littleEndianInt (temp);
  4029. return 0;
  4030. }
  4031. int InputStream::readIntBigEndian()
  4032. {
  4033. char temp[4];
  4034. if (read (temp, 4) == 4)
  4035. return (int) ByteOrder::bigEndianInt (temp);
  4036. return 0;
  4037. }
  4038. int InputStream::readCompressedInt()
  4039. {
  4040. const unsigned char sizeByte = readByte();
  4041. if (sizeByte == 0)
  4042. return 0;
  4043. const int numBytes = (sizeByte & 0x7f);
  4044. if (numBytes > 4)
  4045. {
  4046. jassertfalse // trying to read corrupt data - this method must only be used
  4047. // to read data that was written by OutputStream::writeCompressedInt()
  4048. return 0;
  4049. }
  4050. char bytes[4] = { 0, 0, 0, 0 };
  4051. if (read (bytes, numBytes) != numBytes)
  4052. return 0;
  4053. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4054. return (sizeByte >> 7) ? -num : num;
  4055. }
  4056. int64 InputStream::readInt64()
  4057. {
  4058. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4059. if (read (n.asBytes, 8) == 8)
  4060. return (int64) ByteOrder::swapIfBigEndian (n.asInt64);
  4061. return 0;
  4062. }
  4063. int64 InputStream::readInt64BigEndian()
  4064. {
  4065. union { uint8 asBytes[8]; uint64 asInt64; } n;
  4066. if (read (n.asBytes, 8) == 8)
  4067. return (int64) ByteOrder::swapIfLittleEndian (n.asInt64);
  4068. return 0;
  4069. }
  4070. float InputStream::readFloat()
  4071. {
  4072. // the union below relies on these types being the same size...
  4073. static_jassert (sizeof (int32) == sizeof (float));
  4074. union { int32 asInt; float asFloat; } n;
  4075. n.asInt = (int32) readInt();
  4076. return n.asFloat;
  4077. }
  4078. float InputStream::readFloatBigEndian()
  4079. {
  4080. union { int32 asInt; float asFloat; } n;
  4081. n.asInt = (int32) readIntBigEndian();
  4082. return n.asFloat;
  4083. }
  4084. double InputStream::readDouble()
  4085. {
  4086. union { int64 asInt; double asDouble; } n;
  4087. n.asInt = readInt64();
  4088. return n.asDouble;
  4089. }
  4090. double InputStream::readDoubleBigEndian()
  4091. {
  4092. union { int64 asInt; double asDouble; } n;
  4093. n.asInt = readInt64BigEndian();
  4094. return n.asDouble;
  4095. }
  4096. const String InputStream::readString()
  4097. {
  4098. MemoryBlock buffer (256);
  4099. char* data = static_cast<char*> (buffer.getData());
  4100. size_t i = 0;
  4101. while ((data[i] = readByte()) != 0)
  4102. {
  4103. if (++i >= buffer.getSize())
  4104. {
  4105. buffer.setSize (buffer.getSize() + 512);
  4106. data = static_cast<char*> (buffer.getData());
  4107. }
  4108. }
  4109. return String::fromUTF8 (data, (int) i);
  4110. }
  4111. const String InputStream::readNextLine()
  4112. {
  4113. MemoryBlock buffer (256);
  4114. char* data = static_cast<char*> (buffer.getData());
  4115. size_t i = 0;
  4116. while ((data[i] = readByte()) != 0)
  4117. {
  4118. if (data[i] == '\n')
  4119. break;
  4120. if (data[i] == '\r')
  4121. {
  4122. const int64 lastPos = getPosition();
  4123. if (readByte() != '\n')
  4124. setPosition (lastPos);
  4125. break;
  4126. }
  4127. if (++i >= buffer.getSize())
  4128. {
  4129. buffer.setSize (buffer.getSize() + 512);
  4130. data = static_cast<char*> (buffer.getData());
  4131. }
  4132. }
  4133. return String::fromUTF8 (data, (int) i);
  4134. }
  4135. int InputStream::readIntoMemoryBlock (MemoryBlock& block, int numBytes)
  4136. {
  4137. const int64 totalLength = getTotalLength();
  4138. if (totalLength >= 0)
  4139. {
  4140. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4141. totalLength - getPosition());
  4142. if (numBytes < 0)
  4143. numBytes = totalBytesRemaining;
  4144. else if (numBytes > 0)
  4145. numBytes = jmin (numBytes, totalBytesRemaining);
  4146. else
  4147. return 0;
  4148. }
  4149. const size_t originalBlockSize = block.getSize();
  4150. int totalBytesRead = 0;
  4151. if (numBytes > 0)
  4152. {
  4153. // know how many bytes we want, so we can resize the block first..
  4154. block.setSize (originalBlockSize + numBytes, false);
  4155. totalBytesRead = read (static_cast<char*> (block.getData()) + originalBlockSize, numBytes);
  4156. }
  4157. else
  4158. {
  4159. // read until end of stram..
  4160. const int chunkSize = 32768;
  4161. for (;;)
  4162. {
  4163. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4164. const int bytesJustIn = read (static_cast<char*> (block.getData())
  4165. + originalBlockSize
  4166. + totalBytesRead,
  4167. chunkSize);
  4168. if (bytesJustIn == 0)
  4169. break;
  4170. totalBytesRead += bytesJustIn;
  4171. }
  4172. }
  4173. // trim off any excess left at the end
  4174. block.setSize (originalBlockSize + totalBytesRead, false);
  4175. return totalBytesRead;
  4176. }
  4177. const String InputStream::readEntireStreamAsString()
  4178. {
  4179. MemoryBlock mb;
  4180. const int size = readIntoMemoryBlock (mb);
  4181. return String::createStringFromData (static_cast<const char*> (mb.getData()), size);
  4182. }
  4183. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4184. {
  4185. if (numBytesToSkip > 0)
  4186. {
  4187. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4188. HeapBlock<char> temp (skipBufferSize);
  4189. while (numBytesToSkip > 0 && ! isExhausted())
  4190. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4191. }
  4192. }
  4193. END_JUCE_NAMESPACE
  4194. /*** End of inlined file: juce_InputStream.cpp ***/
  4195. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4196. BEGIN_JUCE_NAMESPACE
  4197. #if JUCE_DEBUG
  4198. static CriticalSection activeStreamLock;
  4199. static VoidArray activeStreams;
  4200. void juce_CheckForDanglingStreams()
  4201. {
  4202. /*
  4203. It's always a bad idea to leak any object, but if you're leaking output
  4204. streams, then there's a good chance that you're failing to flush a file
  4205. to disk properly, which could result in corrupted data and other similar
  4206. nastiness..
  4207. */
  4208. jassert (activeStreams.size() == 0);
  4209. };
  4210. #endif
  4211. OutputStream::OutputStream()
  4212. {
  4213. #if JUCE_DEBUG
  4214. const ScopedLock sl (activeStreamLock);
  4215. activeStreams.add (this);
  4216. #endif
  4217. }
  4218. OutputStream::~OutputStream()
  4219. {
  4220. #if JUCE_DEBUG
  4221. const ScopedLock sl (activeStreamLock);
  4222. activeStreams.removeValue (this);
  4223. #endif
  4224. }
  4225. void OutputStream::writeBool (const bool b)
  4226. {
  4227. writeByte (b ? (char) 1
  4228. : (char) 0);
  4229. }
  4230. void OutputStream::writeByte (char byte)
  4231. {
  4232. write (&byte, 1);
  4233. }
  4234. void OutputStream::writeShort (short value)
  4235. {
  4236. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4237. write (&v, 2);
  4238. }
  4239. void OutputStream::writeShortBigEndian (short value)
  4240. {
  4241. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4242. write (&v, 2);
  4243. }
  4244. void OutputStream::writeInt (int value)
  4245. {
  4246. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4247. write (&v, 4);
  4248. }
  4249. void OutputStream::writeIntBigEndian (int value)
  4250. {
  4251. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4252. write (&v, 4);
  4253. }
  4254. void OutputStream::writeCompressedInt (int value)
  4255. {
  4256. unsigned int un = (value < 0) ? (unsigned int) -value
  4257. : (unsigned int) value;
  4258. uint8 data[5];
  4259. int num = 0;
  4260. while (un > 0)
  4261. {
  4262. data[++num] = (uint8) un;
  4263. un >>= 8;
  4264. }
  4265. data[0] = (uint8) num;
  4266. if (value < 0)
  4267. data[0] |= 0x80;
  4268. write (data, num + 1);
  4269. }
  4270. void OutputStream::writeInt64 (int64 value)
  4271. {
  4272. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4273. write (&v, 8);
  4274. }
  4275. void OutputStream::writeInt64BigEndian (int64 value)
  4276. {
  4277. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4278. write (&v, 8);
  4279. }
  4280. void OutputStream::writeFloat (float value)
  4281. {
  4282. union { int asInt; float asFloat; } n;
  4283. n.asFloat = value;
  4284. writeInt (n.asInt);
  4285. }
  4286. void OutputStream::writeFloatBigEndian (float value)
  4287. {
  4288. union { int asInt; float asFloat; } n;
  4289. n.asFloat = value;
  4290. writeIntBigEndian (n.asInt);
  4291. }
  4292. void OutputStream::writeDouble (double value)
  4293. {
  4294. union { int64 asInt; double asDouble; } n;
  4295. n.asDouble = value;
  4296. writeInt64 (n.asInt);
  4297. }
  4298. void OutputStream::writeDoubleBigEndian (double value)
  4299. {
  4300. union { int64 asInt; double asDouble; } n;
  4301. n.asDouble = value;
  4302. writeInt64BigEndian (n.asInt);
  4303. }
  4304. void OutputStream::writeString (const String& text)
  4305. {
  4306. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4307. // if lots of large, persistent strings were to be written to streams).
  4308. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4309. HeapBlock<char> temp (numBytes);
  4310. text.copyToUTF8 (temp, numBytes);
  4311. write (temp, numBytes);
  4312. }
  4313. void OutputStream::writeText (const String& text, const bool asUnicode,
  4314. const bool writeUnicodeHeaderBytes)
  4315. {
  4316. if (asUnicode)
  4317. {
  4318. if (writeUnicodeHeaderBytes)
  4319. write ("\x0ff\x0fe", 2);
  4320. const juce_wchar* src = text;
  4321. bool lastCharWasReturn = false;
  4322. while (*src != 0)
  4323. {
  4324. if (*src == L'\n' && ! lastCharWasReturn)
  4325. writeShort ((short) L'\r');
  4326. lastCharWasReturn = (*src == L'\r');
  4327. writeShort ((short) *src++);
  4328. }
  4329. }
  4330. else
  4331. {
  4332. const char* src = text.toUTF8();
  4333. const char* t = src;
  4334. for (;;)
  4335. {
  4336. if (*t == '\n')
  4337. {
  4338. if (t > src)
  4339. write (src, (int) (t - src));
  4340. write ("\r\n", 2);
  4341. src = t + 1;
  4342. }
  4343. else if (*t == '\r')
  4344. {
  4345. if (t[1] == '\n')
  4346. ++t;
  4347. }
  4348. else if (*t == 0)
  4349. {
  4350. if (t > src)
  4351. write (src, (int) (t - src));
  4352. break;
  4353. }
  4354. ++t;
  4355. }
  4356. }
  4357. }
  4358. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4359. {
  4360. if (numBytesToWrite < 0)
  4361. numBytesToWrite = 0x7fffffff;
  4362. int numWritten = 0;
  4363. while (numBytesToWrite > 0 && ! source.isExhausted())
  4364. {
  4365. char buffer [8192];
  4366. const int num = (int) source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4367. if (num == 0)
  4368. break;
  4369. write (buffer, num);
  4370. numBytesToWrite -= num;
  4371. numWritten += num;
  4372. }
  4373. return numWritten;
  4374. }
  4375. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const int number)
  4376. {
  4377. return stream << String (number);
  4378. }
  4379. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const double number)
  4380. {
  4381. return stream << String (number);
  4382. }
  4383. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char character)
  4384. {
  4385. stream.writeByte (character);
  4386. return stream;
  4387. }
  4388. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const char* const text)
  4389. {
  4390. stream.write (text, (int) strlen (text));
  4391. return stream;
  4392. }
  4393. END_JUCE_NAMESPACE
  4394. /*** End of inlined file: juce_OutputStream.cpp ***/
  4395. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4396. BEGIN_JUCE_NAMESPACE
  4397. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4398. bool* isDirectory, bool* isHidden, int64* fileSize,
  4399. Time* modTime, Time* creationTime, bool* isReadOnly);
  4400. bool juce_findFileNext (void* handle, String& resultFile,
  4401. bool* isDirectory, bool* isHidden, int64* fileSize,
  4402. Time* modTime, Time* creationTime, bool* isReadOnly);
  4403. void juce_findFileClose (void* handle);
  4404. DirectoryIterator::DirectoryIterator (const File& directory,
  4405. bool isRecursive,
  4406. const String& wc,
  4407. const int whatToLookFor_)
  4408. : wildCard (wc),
  4409. index (-1),
  4410. whatToLookFor (whatToLookFor_)
  4411. {
  4412. // you have to specify the type of files you're looking for!
  4413. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4414. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4415. String path (directory.getFullPathName());
  4416. if (! path.endsWithChar (File::separator))
  4417. path += File::separator;
  4418. String filename;
  4419. bool isDirectory, isHidden;
  4420. void* const handle = juce_findFileStart (path,
  4421. isRecursive ? "*" : wc,
  4422. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4423. if (handle != 0)
  4424. {
  4425. do
  4426. {
  4427. if (! filename.containsOnly ("."))
  4428. {
  4429. bool addToList = false;
  4430. if (isDirectory)
  4431. {
  4432. if (isRecursive
  4433. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4434. || ! isHidden))
  4435. {
  4436. dirsFound.add (File (path + filename, 0));
  4437. }
  4438. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4439. }
  4440. else
  4441. {
  4442. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4443. }
  4444. // if it's recursive, we're not relying on the OS iterator
  4445. // to do the wildcard match, so do it now..
  4446. if (isRecursive && addToList)
  4447. addToList = filename.matchesWildcard (wc, true);
  4448. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4449. addToList = ! isHidden;
  4450. if (addToList)
  4451. filesFound.add (File (path + filename, 0));
  4452. }
  4453. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4454. juce_findFileClose (handle);
  4455. }
  4456. }
  4457. DirectoryIterator::~DirectoryIterator()
  4458. {
  4459. }
  4460. bool DirectoryIterator::next()
  4461. {
  4462. if (subIterator != 0)
  4463. {
  4464. if (subIterator->next())
  4465. return true;
  4466. subIterator = 0;
  4467. }
  4468. if (index >= filesFound.size() + dirsFound.size() - 1)
  4469. return false;
  4470. ++index;
  4471. if (index >= filesFound.size())
  4472. {
  4473. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4474. true, wildCard, whatToLookFor);
  4475. return next();
  4476. }
  4477. return true;
  4478. }
  4479. const File DirectoryIterator::getFile() const
  4480. {
  4481. if (subIterator != 0)
  4482. return subIterator->getFile();
  4483. return filesFound [index];
  4484. }
  4485. float DirectoryIterator::getEstimatedProgress() const
  4486. {
  4487. if (filesFound.size() + dirsFound.size() == 0)
  4488. {
  4489. return 0.0f;
  4490. }
  4491. else
  4492. {
  4493. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4494. : (float) index;
  4495. return detailedIndex / (filesFound.size() + dirsFound.size());
  4496. }
  4497. }
  4498. END_JUCE_NAMESPACE
  4499. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4500. /*** Start of inlined file: juce_File.cpp ***/
  4501. #ifdef _MSC_VER
  4502. #pragma warning (disable: 4514)
  4503. #pragma warning (push)
  4504. #endif
  4505. #if ! JUCE_WINDOWS
  4506. #include <pwd.h>
  4507. #endif
  4508. BEGIN_JUCE_NAMESPACE
  4509. #ifdef _MSC_VER
  4510. #pragma warning (pop)
  4511. #endif
  4512. void* juce_fileOpen (const String& path, bool forWriting);
  4513. void juce_fileClose (void* handle);
  4514. int juce_fileWrite (void* handle, const void* buffer, int size);
  4515. int64 juce_fileGetPosition (void* handle);
  4516. int64 juce_fileSetPosition (void* handle, int64 pos);
  4517. void juce_fileFlush (void* handle);
  4518. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4519. bool juce_isDirectory (const String& fileName);
  4520. int64 juce_getFileSize (const String& fileName);
  4521. bool juce_canWriteToFile (const String& fileName);
  4522. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4523. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4524. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4525. bool juce_deleteFile (const String& fileName);
  4526. bool juce_copyFile (const String& source, const String& dest);
  4527. bool juce_moveFile (const String& source, const String& dest);
  4528. // this must also create all paths involved in the directory.
  4529. void juce_createDirectory (const String& fileName);
  4530. bool juce_launchFile (const String& fileName, const String& parameters);
  4531. const StringArray juce_getFileSystemRoots();
  4532. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4533. // starts a directory search operation with a wildcard, returning a handle for
  4534. // use in calls to juce_findFileNext.
  4535. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4536. // the other pointers, if non-null, are set based on the properties of the file.
  4537. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4538. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4539. Time* creationTime, bool* isReadOnly);
  4540. // returns false when no more files are found
  4541. bool juce_findFileNext (void* handle, String& resultFile,
  4542. bool* isDirectory, bool* isHidden, int64* fileSize,
  4543. Time* modTime, Time* creationTime, bool* isReadOnly);
  4544. void juce_findFileClose (void* handle);
  4545. static const String juce_addTrailingSeparator (const String& path)
  4546. {
  4547. return path.endsWithChar (File::separator) ? path
  4548. : path + File::separator;
  4549. }
  4550. static const String parseAbsolutePath (String path)
  4551. {
  4552. if (path.isEmpty())
  4553. return String::empty;
  4554. #if JUCE_WINDOWS
  4555. // Windows..
  4556. path = path.replaceCharacter ('/', '\\');
  4557. if (path.startsWithChar (File::separator))
  4558. {
  4559. if (path[1] != File::separator)
  4560. {
  4561. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4562. If you're trying to parse a string that may be either a relative path or an absolute path,
  4563. you MUST provide a context against which the partial path can be evaluated - you can do
  4564. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4565. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4566. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4567. */
  4568. jassertfalse
  4569. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4570. }
  4571. }
  4572. else if (path.indexOfChar (':') < 0)
  4573. {
  4574. if (path.isEmpty())
  4575. return String::empty;
  4576. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4577. If you're trying to parse a string that may be either a relative path or an absolute path,
  4578. you MUST provide a context against which the partial path can be evaluated - you can do
  4579. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4580. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4581. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4582. */
  4583. jassertfalse
  4584. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4585. }
  4586. #else
  4587. // Mac or Linux..
  4588. path = path.replaceCharacter ('\\', '/');
  4589. if (path.startsWithChar ('~'))
  4590. {
  4591. const char* homeDir = 0;
  4592. if (path[1] == File::separator || path[1] == 0)
  4593. {
  4594. // expand a name of the form "~/abc"
  4595. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4596. + path.substring (1);
  4597. }
  4598. else
  4599. {
  4600. // expand a name of type "~dave/abc"
  4601. const String userName (path.substring (1).upToFirstOccurrenceOf ("/", false, false));
  4602. struct passwd* const pw = getpwnam (userName.toUTF8());
  4603. if (pw != 0)
  4604. {
  4605. String home (homeDir);
  4606. if (home.endsWithChar (File::separator))
  4607. home [home.length() - 1] = 0;
  4608. path = String (pw->pw_dir)
  4609. + path.substring (userName.length());
  4610. }
  4611. }
  4612. }
  4613. else if (! path.startsWithChar (File::separator))
  4614. {
  4615. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4616. If you're trying to parse a string that may be either a relative path or an absolute path,
  4617. you MUST provide a context against which the partial path can be evaluated - you can do
  4618. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4619. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4620. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4621. */
  4622. jassert (path.startsWith ("./") || path.startsWith ("../")); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4623. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4624. }
  4625. #endif
  4626. int len = path.length();
  4627. while (--len > 0 && path [len] == File::separator)
  4628. path [len] = 0;
  4629. return path;
  4630. }
  4631. const File File::nonexistent;
  4632. File::File (const String& fullPathName)
  4633. : fullPath (parseAbsolutePath (fullPathName))
  4634. {
  4635. }
  4636. File::File (const String& path, int)
  4637. : fullPath (path)
  4638. {
  4639. }
  4640. const File File::createFileWithoutCheckingPath (const String& path)
  4641. {
  4642. return File (path, 0);
  4643. }
  4644. File::File (const File& other)
  4645. : fullPath (other.fullPath)
  4646. {
  4647. }
  4648. File& File::operator= (const String& newPath)
  4649. {
  4650. fullPath = parseAbsolutePath (newPath);
  4651. return *this;
  4652. }
  4653. File& File::operator= (const File& other)
  4654. {
  4655. fullPath = other.fullPath;
  4656. return *this;
  4657. }
  4658. #if JUCE_LINUX
  4659. #define NAMES_ARE_CASE_SENSITIVE 1
  4660. #endif
  4661. bool File::areFileNamesCaseSensitive()
  4662. {
  4663. #if NAMES_ARE_CASE_SENSITIVE
  4664. return true;
  4665. #else
  4666. return false;
  4667. #endif
  4668. }
  4669. bool File::operator== (const File& other) const
  4670. {
  4671. // case-insensitive on Windows, but not on linux.
  4672. #if NAMES_ARE_CASE_SENSITIVE
  4673. return fullPath == other.fullPath;
  4674. #else
  4675. return fullPath.equalsIgnoreCase (other.fullPath);
  4676. #endif
  4677. }
  4678. bool File::operator!= (const File& other) const
  4679. {
  4680. return ! operator== (other);
  4681. }
  4682. bool File::exists() const
  4683. {
  4684. return juce_fileExists (fullPath, false);
  4685. }
  4686. bool File::existsAsFile() const
  4687. {
  4688. return juce_fileExists (fullPath, true);
  4689. }
  4690. bool File::isDirectory() const
  4691. {
  4692. return juce_isDirectory (fullPath);
  4693. }
  4694. bool File::hasWriteAccess() const
  4695. {
  4696. if (exists())
  4697. return juce_canWriteToFile (fullPath);
  4698. #if ! JUCE_WINDOWS
  4699. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4700. return getParentDirectory().hasWriteAccess();
  4701. else
  4702. return false;
  4703. #else
  4704. // on windows, it seems that even read-only directories can still be written into,
  4705. // so checking the parent directory's permissions would return the wrong result..
  4706. else
  4707. return true;
  4708. #endif
  4709. }
  4710. bool File::setReadOnly (const bool shouldBeReadOnly,
  4711. const bool applyRecursively) const
  4712. {
  4713. bool worked = true;
  4714. if (applyRecursively && isDirectory())
  4715. {
  4716. Array <File> subFiles;
  4717. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4718. for (int i = subFiles.size(); --i >= 0;)
  4719. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4720. }
  4721. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4722. }
  4723. bool File::deleteFile() const
  4724. {
  4725. return (! exists())
  4726. || juce_deleteFile (fullPath);
  4727. }
  4728. bool File::deleteRecursively() const
  4729. {
  4730. bool worked = true;
  4731. if (isDirectory())
  4732. {
  4733. Array<File> subFiles;
  4734. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4735. for (int i = subFiles.size(); --i >= 0;)
  4736. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4737. }
  4738. return deleteFile() && worked;
  4739. }
  4740. bool File::moveFileTo (const File& newFile) const
  4741. {
  4742. if (newFile.fullPath == fullPath)
  4743. return true;
  4744. #if ! NAMES_ARE_CASE_SENSITIVE
  4745. if (*this != newFile)
  4746. #endif
  4747. if (! newFile.deleteFile())
  4748. return false;
  4749. return juce_moveFile (fullPath, newFile.fullPath);
  4750. }
  4751. bool File::copyFileTo (const File& newFile) const
  4752. {
  4753. if (*this == newFile)
  4754. return true;
  4755. if (! newFile.deleteFile())
  4756. return false;
  4757. return juce_copyFile (fullPath, newFile.fullPath);
  4758. }
  4759. bool File::copyDirectoryTo (const File& newDirectory) const
  4760. {
  4761. if (isDirectory() && newDirectory.createDirectory())
  4762. {
  4763. Array<File> subFiles;
  4764. findChildFiles (subFiles, File::findFiles, false);
  4765. int i;
  4766. for (i = 0; i < subFiles.size(); ++i)
  4767. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4768. return false;
  4769. subFiles.clear();
  4770. findChildFiles (subFiles, File::findDirectories, false);
  4771. for (i = 0; i < subFiles.size(); ++i)
  4772. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4773. return false;
  4774. return true;
  4775. }
  4776. return false;
  4777. }
  4778. const String File::getPathUpToLastSlash() const
  4779. {
  4780. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4781. if (lastSlash > 0)
  4782. return fullPath.substring (0, lastSlash);
  4783. else if (lastSlash == 0)
  4784. return separatorString;
  4785. else
  4786. return fullPath;
  4787. }
  4788. const File File::getParentDirectory() const
  4789. {
  4790. return File (getPathUpToLastSlash());
  4791. }
  4792. const String File::getFileName() const
  4793. {
  4794. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4795. }
  4796. int File::hashCode() const
  4797. {
  4798. return fullPath.hashCode();
  4799. }
  4800. int64 File::hashCode64() const
  4801. {
  4802. return fullPath.hashCode64();
  4803. }
  4804. const String File::getFileNameWithoutExtension() const
  4805. {
  4806. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4807. const int lastDot = fullPath.lastIndexOfChar ('.');
  4808. if (lastDot > lastSlash)
  4809. return fullPath.substring (lastSlash, lastDot);
  4810. else
  4811. return fullPath.substring (lastSlash);
  4812. }
  4813. bool File::isAChildOf (const File& potentialParent) const
  4814. {
  4815. if (potentialParent == File::nonexistent)
  4816. return false;
  4817. const String ourPath (getPathUpToLastSlash());
  4818. #if NAMES_ARE_CASE_SENSITIVE
  4819. if (potentialParent.fullPath == ourPath)
  4820. #else
  4821. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4822. #endif
  4823. {
  4824. return true;
  4825. }
  4826. else if (potentialParent.fullPath.length() >= ourPath.length())
  4827. {
  4828. return false;
  4829. }
  4830. else
  4831. {
  4832. return getParentDirectory().isAChildOf (potentialParent);
  4833. }
  4834. }
  4835. bool File::isAbsolutePath (const String& path)
  4836. {
  4837. return path.startsWithChar ('/') || path.startsWithChar ('\\')
  4838. #if JUCE_WINDOWS
  4839. || (path.isNotEmpty() && path[1] == ':');
  4840. #else
  4841. || path.startsWithChar ('~');
  4842. #endif
  4843. }
  4844. const File File::getChildFile (String relativePath) const
  4845. {
  4846. if (isAbsolutePath (relativePath))
  4847. {
  4848. // the path is really absolute..
  4849. return File (relativePath);
  4850. }
  4851. else
  4852. {
  4853. // it's relative, so remove any ../ or ./ bits at the start.
  4854. String path (fullPath);
  4855. if (relativePath[0] == '.')
  4856. {
  4857. #if JUCE_WINDOWS
  4858. relativePath = relativePath.replaceCharacter ('/', '\\').trimStart();
  4859. #else
  4860. relativePath = relativePath.replaceCharacter ('\\', '/').trimStart();
  4861. #endif
  4862. while (relativePath[0] == '.')
  4863. {
  4864. if (relativePath[1] == '.')
  4865. {
  4866. if (relativePath [2] == 0 || relativePath[2] == separator)
  4867. {
  4868. const int lastSlash = path.lastIndexOfChar (separator);
  4869. if (lastSlash >= 0)
  4870. path = path.substring (0, lastSlash);
  4871. relativePath = relativePath.substring (3);
  4872. }
  4873. else
  4874. {
  4875. break;
  4876. }
  4877. }
  4878. else if (relativePath[1] == separator)
  4879. {
  4880. relativePath = relativePath.substring (2);
  4881. }
  4882. else
  4883. {
  4884. break;
  4885. }
  4886. }
  4887. }
  4888. return File (juce_addTrailingSeparator (path) + relativePath);
  4889. }
  4890. }
  4891. const File File::getSiblingFile (const String& fileName) const
  4892. {
  4893. return getParentDirectory().getChildFile (fileName);
  4894. }
  4895. int64 File::getSize() const
  4896. {
  4897. return juce_getFileSize (fullPath);
  4898. }
  4899. const String File::descriptionOfSizeInBytes (const int64 bytes)
  4900. {
  4901. if (bytes == 1)
  4902. {
  4903. return "1 byte";
  4904. }
  4905. else if (bytes < 1024)
  4906. {
  4907. return String ((int) bytes) + " bytes";
  4908. }
  4909. else if (bytes < 1024 * 1024)
  4910. {
  4911. return String (bytes / 1024.0, 1) + " KB";
  4912. }
  4913. else if (bytes < 1024 * 1024 * 1024)
  4914. {
  4915. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  4916. }
  4917. else
  4918. {
  4919. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  4920. }
  4921. }
  4922. bool File::create() const
  4923. {
  4924. if (! exists())
  4925. {
  4926. const File parentDir (getParentDirectory());
  4927. if (parentDir == *this || ! parentDir.createDirectory())
  4928. return false;
  4929. void* const fh = juce_fileOpen (fullPath, true);
  4930. if (fh == 0)
  4931. return false;
  4932. juce_fileClose (fh);
  4933. }
  4934. return true;
  4935. }
  4936. bool File::createDirectory() const
  4937. {
  4938. if (! isDirectory())
  4939. {
  4940. const File parentDir (getParentDirectory());
  4941. if (parentDir == *this || ! parentDir.createDirectory())
  4942. return false;
  4943. String dir (fullPath);
  4944. while (dir.endsWithChar (separator))
  4945. dir [dir.length() - 1] = 0;
  4946. juce_createDirectory (dir);
  4947. return isDirectory();
  4948. }
  4949. return true;
  4950. }
  4951. const Time File::getCreationTime() const
  4952. {
  4953. int64 m, a, c;
  4954. juce_getFileTimes (fullPath, m, a, c);
  4955. return Time (c);
  4956. }
  4957. bool File::setCreationTime (const Time& t) const
  4958. {
  4959. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  4960. }
  4961. const Time File::getLastModificationTime() const
  4962. {
  4963. int64 m, a, c;
  4964. juce_getFileTimes (fullPath, m, a, c);
  4965. return Time (m);
  4966. }
  4967. bool File::setLastModificationTime (const Time& t) const
  4968. {
  4969. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  4970. }
  4971. const Time File::getLastAccessTime() const
  4972. {
  4973. int64 m, a, c;
  4974. juce_getFileTimes (fullPath, m, a, c);
  4975. return Time (a);
  4976. }
  4977. bool File::setLastAccessTime (const Time& t) const
  4978. {
  4979. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  4980. }
  4981. bool File::loadFileAsData (MemoryBlock& destBlock) const
  4982. {
  4983. if (! existsAsFile())
  4984. return false;
  4985. FileInputStream in (*this);
  4986. return getSize() == in.readIntoMemoryBlock (destBlock);
  4987. }
  4988. const String File::loadFileAsString() const
  4989. {
  4990. if (! existsAsFile())
  4991. return String::empty;
  4992. FileInputStream in (*this);
  4993. return in.readEntireStreamAsString();
  4994. }
  4995. static inline bool fileTypeMatches (const int whatToLookFor,
  4996. const bool isDir,
  4997. const bool isHidden)
  4998. {
  4999. return (whatToLookFor & (isDir ? File::findDirectories
  5000. : File::findFiles)) != 0
  5001. && ((! isHidden)
  5002. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5003. }
  5004. int File::findChildFiles (Array<File>& results,
  5005. const int whatToLookFor,
  5006. const bool searchRecursively,
  5007. const String& wildCardPattern) const
  5008. {
  5009. // you have to specify the type of files you're looking for!
  5010. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5011. int total = 0;
  5012. // find child files or directories in this directory first..
  5013. if (isDirectory())
  5014. {
  5015. const String path (juce_addTrailingSeparator (fullPath));
  5016. String filename;
  5017. bool itemIsDirectory, itemIsHidden;
  5018. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5019. &itemIsDirectory, &itemIsHidden,
  5020. 0, 0, 0, 0);
  5021. if (handle != 0)
  5022. {
  5023. do
  5024. {
  5025. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5026. && ! filename.containsOnly ("."))
  5027. {
  5028. results.add (File (path + filename, 0));
  5029. ++total;
  5030. }
  5031. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5032. juce_findFileClose (handle);
  5033. }
  5034. }
  5035. else
  5036. {
  5037. // trying to search for files inside a non-directory?
  5038. //jassertfalse
  5039. }
  5040. // and recurse down if required.
  5041. if (searchRecursively)
  5042. {
  5043. Array<File> subDirectories;
  5044. findChildFiles (subDirectories, File::findDirectories, false);
  5045. for (int i = 0; i < subDirectories.size(); ++i)
  5046. {
  5047. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5048. true, wildCardPattern);
  5049. }
  5050. }
  5051. return total;
  5052. }
  5053. int File::getNumberOfChildFiles (const int whatToLookFor,
  5054. const String& wildCardPattern) const
  5055. {
  5056. // you have to specify the type of files you're looking for!
  5057. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5058. int count = 0;
  5059. if (isDirectory())
  5060. {
  5061. String filename;
  5062. bool itemIsDirectory, itemIsHidden;
  5063. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5064. &itemIsDirectory, &itemIsHidden,
  5065. 0, 0, 0, 0);
  5066. if (handle != 0)
  5067. {
  5068. do
  5069. {
  5070. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5071. && ! filename.containsOnly ("."))
  5072. {
  5073. ++count;
  5074. }
  5075. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5076. juce_findFileClose (handle);
  5077. }
  5078. }
  5079. else
  5080. {
  5081. // trying to search for files inside a non-directory?
  5082. jassertfalse
  5083. }
  5084. return count;
  5085. }
  5086. bool File::containsSubDirectories() const
  5087. {
  5088. bool result = false;
  5089. if (isDirectory())
  5090. {
  5091. String filename;
  5092. bool itemIsDirectory, itemIsHidden;
  5093. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5094. "*", filename,
  5095. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5096. if (handle != 0)
  5097. {
  5098. do
  5099. {
  5100. if (itemIsDirectory)
  5101. {
  5102. result = true;
  5103. break;
  5104. }
  5105. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5106. juce_findFileClose (handle);
  5107. }
  5108. }
  5109. return result;
  5110. }
  5111. const File File::getNonexistentChildFile (const String& prefix_,
  5112. const String& suffix,
  5113. bool putNumbersInBrackets) const
  5114. {
  5115. File f (getChildFile (prefix_ + suffix));
  5116. if (f.exists())
  5117. {
  5118. int num = 2;
  5119. String prefix (prefix_);
  5120. // remove any bracketed numbers that may already be on the end..
  5121. if (prefix.trim().endsWithChar (')'))
  5122. {
  5123. putNumbersInBrackets = true;
  5124. const int openBracks = prefix.lastIndexOfChar ('(');
  5125. const int closeBracks = prefix.lastIndexOfChar (')');
  5126. if (openBracks > 0
  5127. && closeBracks > openBracks
  5128. && prefix.substring (openBracks + 1, closeBracks).containsOnly ("0123456789"))
  5129. {
  5130. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5131. prefix = prefix.substring (0, openBracks);
  5132. }
  5133. }
  5134. // also use brackets if it ends in a digit.
  5135. putNumbersInBrackets = putNumbersInBrackets
  5136. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5137. do
  5138. {
  5139. if (putNumbersInBrackets)
  5140. f = getChildFile (prefix + '(' + String (num++) + ')' + suffix);
  5141. else
  5142. f = getChildFile (prefix + String (num++) + suffix);
  5143. } while (f.exists());
  5144. }
  5145. return f;
  5146. }
  5147. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5148. {
  5149. if (exists())
  5150. {
  5151. return getParentDirectory()
  5152. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5153. getFileExtension(),
  5154. putNumbersInBrackets);
  5155. }
  5156. else
  5157. {
  5158. return *this;
  5159. }
  5160. }
  5161. const String File::getFileExtension() const
  5162. {
  5163. String ext;
  5164. if (! isDirectory())
  5165. {
  5166. const int indexOfDot = fullPath.lastIndexOfChar ('.');
  5167. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5168. ext = fullPath.substring (indexOfDot);
  5169. }
  5170. return ext;
  5171. }
  5172. bool File::hasFileExtension (const String& possibleSuffix) const
  5173. {
  5174. if (possibleSuffix.isEmpty())
  5175. return fullPath.lastIndexOfChar ('.') <= fullPath.lastIndexOfChar (separator);
  5176. const int semicolon = possibleSuffix.indexOfChar (0, ';');
  5177. if (semicolon >= 0)
  5178. {
  5179. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5180. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5181. }
  5182. else
  5183. {
  5184. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5185. {
  5186. if (possibleSuffix.startsWithChar ('.'))
  5187. return true;
  5188. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5189. if (dotPos >= 0)
  5190. return fullPath [dotPos] == '.';
  5191. }
  5192. }
  5193. return false;
  5194. }
  5195. const File File::withFileExtension (const String& newExtension) const
  5196. {
  5197. if (fullPath.isEmpty())
  5198. return File::nonexistent;
  5199. String filePart (getFileName());
  5200. int i = filePart.lastIndexOfChar ('.');
  5201. if (i >= 0)
  5202. filePart = filePart.substring (0, i);
  5203. if (newExtension.isNotEmpty() && ! newExtension.startsWithChar ('.'))
  5204. filePart << '.';
  5205. return getSiblingFile (filePart + newExtension);
  5206. }
  5207. bool File::startAsProcess (const String& parameters) const
  5208. {
  5209. return exists() && juce_launchFile (fullPath, parameters);
  5210. }
  5211. FileInputStream* File::createInputStream() const
  5212. {
  5213. if (existsAsFile())
  5214. return new FileInputStream (*this);
  5215. return 0;
  5216. }
  5217. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5218. {
  5219. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5220. if (out->failedToOpen())
  5221. return 0;
  5222. return out.release();
  5223. }
  5224. bool File::appendData (const void* const dataToAppend,
  5225. const int numberOfBytes) const
  5226. {
  5227. if (numberOfBytes > 0)
  5228. {
  5229. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5230. if (out == 0)
  5231. return false;
  5232. out->write (dataToAppend, numberOfBytes);
  5233. }
  5234. return true;
  5235. }
  5236. bool File::replaceWithData (const void* const dataToWrite,
  5237. const int numberOfBytes) const
  5238. {
  5239. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5240. if (numberOfBytes <= 0)
  5241. return deleteFile();
  5242. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5243. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5244. return tempFile.overwriteTargetFileWithTemporary();
  5245. }
  5246. bool File::appendText (const String& text,
  5247. const bool asUnicode,
  5248. const bool writeUnicodeHeaderBytes) const
  5249. {
  5250. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5251. if (out != 0)
  5252. {
  5253. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5254. return true;
  5255. }
  5256. return false;
  5257. }
  5258. bool File::replaceWithText (const String& textToWrite,
  5259. const bool asUnicode,
  5260. const bool writeUnicodeHeaderBytes) const
  5261. {
  5262. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5263. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5264. return tempFile.overwriteTargetFileWithTemporary();
  5265. }
  5266. const String File::createLegalPathName (const String& original)
  5267. {
  5268. String s (original);
  5269. String start;
  5270. if (s[1] == ':')
  5271. {
  5272. start = s.substring (0, 2);
  5273. s = s.substring (2);
  5274. }
  5275. return start + s.removeCharacters ("\"#@,;:<>*^|?")
  5276. .substring (0, 1024);
  5277. }
  5278. const String File::createLegalFileName (const String& original)
  5279. {
  5280. String s (original.removeCharacters ("\"#@,;:<>*^|?\\/"));
  5281. const int maxLength = 128; // only the length of the filename, not the whole path
  5282. const int len = s.length();
  5283. if (len > maxLength)
  5284. {
  5285. const int lastDot = s.lastIndexOfChar ('.');
  5286. if (lastDot > jmax (0, len - 12))
  5287. {
  5288. s = s.substring (0, maxLength - (len - lastDot))
  5289. + s.substring (lastDot);
  5290. }
  5291. else
  5292. {
  5293. s = s.substring (0, maxLength);
  5294. }
  5295. }
  5296. return s;
  5297. }
  5298. const String File::getRelativePathFrom (const File& dir) const
  5299. {
  5300. String thisPath (fullPath);
  5301. {
  5302. int len = thisPath.length();
  5303. while (--len >= 0 && thisPath [len] == File::separator)
  5304. thisPath [len] = 0;
  5305. }
  5306. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5307. : dir.fullPath));
  5308. const int len = jmin (thisPath.length(), dirPath.length());
  5309. int commonBitLength = 0;
  5310. for (int i = 0; i < len; ++i)
  5311. {
  5312. #if NAMES_ARE_CASE_SENSITIVE
  5313. if (thisPath[i] != dirPath[i])
  5314. #else
  5315. if (CharacterFunctions::toLowerCase (thisPath[i])
  5316. != CharacterFunctions::toLowerCase (dirPath[i]))
  5317. #endif
  5318. {
  5319. break;
  5320. }
  5321. ++commonBitLength;
  5322. }
  5323. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5324. --commonBitLength;
  5325. // if the only common bit is the root, then just return the full path..
  5326. if (commonBitLength <= 0
  5327. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5328. return fullPath;
  5329. thisPath = thisPath.substring (commonBitLength);
  5330. dirPath = dirPath.substring (commonBitLength);
  5331. while (dirPath.isNotEmpty())
  5332. {
  5333. #if JUCE_WINDOWS
  5334. thisPath = "..\\" + thisPath;
  5335. #else
  5336. thisPath = "../" + thisPath;
  5337. #endif
  5338. const int sep = dirPath.indexOfChar (separator);
  5339. if (sep >= 0)
  5340. dirPath = dirPath.substring (sep + 1);
  5341. else
  5342. dirPath = String::empty;
  5343. }
  5344. return thisPath;
  5345. }
  5346. void File::findFileSystemRoots (Array<File>& destArray)
  5347. {
  5348. const StringArray roots (juce_getFileSystemRoots());
  5349. for (int i = 0; i < roots.size(); ++i)
  5350. destArray.add (File (roots[i]));
  5351. }
  5352. const String File::getVolumeLabel() const
  5353. {
  5354. int serialNum;
  5355. return juce_getVolumeLabel (fullPath, serialNum);
  5356. }
  5357. int File::getVolumeSerialNumber() const
  5358. {
  5359. int serialNum;
  5360. juce_getVolumeLabel (fullPath, serialNum);
  5361. return serialNum;
  5362. }
  5363. const File File::createTempFile (const String& fileNameEnding)
  5364. {
  5365. const File tempFile (getSpecialLocation (tempDirectory)
  5366. .getChildFile ("temp_" + String (Random::getSystemRandom().nextInt()))
  5367. .withFileExtension (fileNameEnding));
  5368. if (tempFile.exists())
  5369. return createTempFile (fileNameEnding);
  5370. else
  5371. return tempFile;
  5372. }
  5373. END_JUCE_NAMESPACE
  5374. /*** End of inlined file: juce_File.cpp ***/
  5375. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5376. BEGIN_JUCE_NAMESPACE
  5377. void* juce_fileOpen (const String& path, bool forWriting);
  5378. void juce_fileClose (void* handle);
  5379. int juce_fileRead (void* handle, void* buffer, int size);
  5380. int64 juce_fileSetPosition (void* handle, int64 pos);
  5381. FileInputStream::FileInputStream (const File& f)
  5382. : file (f),
  5383. currentPosition (0),
  5384. needToSeek (true)
  5385. {
  5386. totalSize = f.getSize();
  5387. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5388. }
  5389. FileInputStream::~FileInputStream()
  5390. {
  5391. juce_fileClose (fileHandle);
  5392. }
  5393. int64 FileInputStream::getTotalLength()
  5394. {
  5395. return totalSize;
  5396. }
  5397. int FileInputStream::read (void* buffer, int bytesToRead)
  5398. {
  5399. int num = 0;
  5400. if (needToSeek)
  5401. {
  5402. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5403. return 0;
  5404. needToSeek = false;
  5405. }
  5406. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5407. currentPosition += num;
  5408. return num;
  5409. }
  5410. bool FileInputStream::isExhausted()
  5411. {
  5412. return currentPosition >= totalSize;
  5413. }
  5414. int64 FileInputStream::getPosition()
  5415. {
  5416. return currentPosition;
  5417. }
  5418. bool FileInputStream::setPosition (int64 pos)
  5419. {
  5420. pos = jlimit ((int64) 0, totalSize, pos);
  5421. needToSeek |= (currentPosition != pos);
  5422. currentPosition = pos;
  5423. return true;
  5424. }
  5425. END_JUCE_NAMESPACE
  5426. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5427. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5428. BEGIN_JUCE_NAMESPACE
  5429. void* juce_fileOpen (const String& path, bool forWriting);
  5430. void juce_fileClose (void* handle);
  5431. int juce_fileWrite (void* handle, const void* buffer, int size);
  5432. void juce_fileFlush (void* handle);
  5433. int64 juce_fileGetPosition (void* handle);
  5434. int64 juce_fileSetPosition (void* handle, int64 pos);
  5435. FileOutputStream::FileOutputStream (const File& f,
  5436. const int bufferSize_)
  5437. : file (f),
  5438. bufferSize (bufferSize_),
  5439. bytesInBuffer (0)
  5440. {
  5441. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5442. if (fileHandle != 0)
  5443. {
  5444. currentPosition = juce_fileGetPosition (fileHandle);
  5445. if (currentPosition < 0)
  5446. {
  5447. jassertfalse
  5448. juce_fileClose (fileHandle);
  5449. fileHandle = 0;
  5450. }
  5451. }
  5452. buffer.malloc (jmax (bufferSize_, 16));
  5453. }
  5454. FileOutputStream::~FileOutputStream()
  5455. {
  5456. flush();
  5457. juce_fileClose (fileHandle);
  5458. }
  5459. int64 FileOutputStream::getPosition()
  5460. {
  5461. return currentPosition;
  5462. }
  5463. bool FileOutputStream::setPosition (int64 newPosition)
  5464. {
  5465. if (newPosition != currentPosition)
  5466. {
  5467. flush();
  5468. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5469. }
  5470. return newPosition == currentPosition;
  5471. }
  5472. void FileOutputStream::flush()
  5473. {
  5474. if (bytesInBuffer > 0)
  5475. {
  5476. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5477. bytesInBuffer = 0;
  5478. }
  5479. juce_fileFlush (fileHandle);
  5480. }
  5481. bool FileOutputStream::write (const void* const src, const int numBytes)
  5482. {
  5483. if (bytesInBuffer + numBytes < bufferSize)
  5484. {
  5485. memcpy (buffer + bytesInBuffer, src, numBytes);
  5486. bytesInBuffer += numBytes;
  5487. currentPosition += numBytes;
  5488. }
  5489. else
  5490. {
  5491. if (bytesInBuffer > 0)
  5492. {
  5493. // flush the reservoir
  5494. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5495. bytesInBuffer = 0;
  5496. if (! wroteOk)
  5497. return false;
  5498. }
  5499. if (numBytes < bufferSize)
  5500. {
  5501. memcpy (buffer + bytesInBuffer, src, numBytes);
  5502. bytesInBuffer += numBytes;
  5503. currentPosition += numBytes;
  5504. }
  5505. else
  5506. {
  5507. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5508. currentPosition += bytesWritten;
  5509. return bytesWritten == numBytes;
  5510. }
  5511. }
  5512. return true;
  5513. }
  5514. END_JUCE_NAMESPACE
  5515. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5516. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5517. BEGIN_JUCE_NAMESPACE
  5518. FileSearchPath::FileSearchPath()
  5519. {
  5520. }
  5521. FileSearchPath::FileSearchPath (const String& path)
  5522. {
  5523. init (path);
  5524. }
  5525. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5526. : directories (other.directories)
  5527. {
  5528. }
  5529. FileSearchPath::~FileSearchPath()
  5530. {
  5531. }
  5532. FileSearchPath& FileSearchPath::operator= (const String& path)
  5533. {
  5534. init (path);
  5535. return *this;
  5536. }
  5537. void FileSearchPath::init (const String& path)
  5538. {
  5539. directories.clear();
  5540. directories.addTokens (path, ";", "\"");
  5541. directories.trim();
  5542. directories.removeEmptyStrings();
  5543. for (int i = directories.size(); --i >= 0;)
  5544. directories.set (i, directories[i].unquoted());
  5545. }
  5546. int FileSearchPath::getNumPaths() const
  5547. {
  5548. return directories.size();
  5549. }
  5550. const File FileSearchPath::operator[] (const int index) const
  5551. {
  5552. return File (directories [index]);
  5553. }
  5554. const String FileSearchPath::toString() const
  5555. {
  5556. StringArray directories2 (directories);
  5557. for (int i = directories2.size(); --i >= 0;)
  5558. if (directories2[i].containsChar (';'))
  5559. directories2.set (i, directories2[i].quoted());
  5560. return directories2.joinIntoString (";");
  5561. }
  5562. void FileSearchPath::add (const File& dir, const int insertIndex)
  5563. {
  5564. directories.insert (insertIndex, dir.getFullPathName());
  5565. }
  5566. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5567. {
  5568. for (int i = 0; i < directories.size(); ++i)
  5569. if (File (directories[i]) == dir)
  5570. return;
  5571. add (dir);
  5572. }
  5573. void FileSearchPath::remove (const int index)
  5574. {
  5575. directories.remove (index);
  5576. }
  5577. void FileSearchPath::addPath (const FileSearchPath& other)
  5578. {
  5579. for (int i = 0; i < other.getNumPaths(); ++i)
  5580. addIfNotAlreadyThere (other[i]);
  5581. }
  5582. void FileSearchPath::removeRedundantPaths()
  5583. {
  5584. for (int i = directories.size(); --i >= 0;)
  5585. {
  5586. const File d1 (directories[i]);
  5587. for (int j = directories.size(); --j >= 0;)
  5588. {
  5589. const File d2 (directories[j]);
  5590. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5591. {
  5592. directories.remove (i);
  5593. break;
  5594. }
  5595. }
  5596. }
  5597. }
  5598. void FileSearchPath::removeNonExistentPaths()
  5599. {
  5600. for (int i = directories.size(); --i >= 0;)
  5601. if (! File (directories[i]).isDirectory())
  5602. directories.remove (i);
  5603. }
  5604. int FileSearchPath::findChildFiles (Array<File>& results,
  5605. const int whatToLookFor,
  5606. const bool searchRecursively,
  5607. const String& wildCardPattern) const
  5608. {
  5609. int total = 0;
  5610. for (int i = 0; i < directories.size(); ++i)
  5611. total += operator[] (i).findChildFiles (results,
  5612. whatToLookFor,
  5613. searchRecursively,
  5614. wildCardPattern);
  5615. return total;
  5616. }
  5617. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5618. const bool checkRecursively) const
  5619. {
  5620. for (int i = directories.size(); --i >= 0;)
  5621. {
  5622. const File d (directories[i]);
  5623. if (checkRecursively)
  5624. {
  5625. if (fileToCheck.isAChildOf (d))
  5626. return true;
  5627. }
  5628. else
  5629. {
  5630. if (fileToCheck.getParentDirectory() == d)
  5631. return true;
  5632. }
  5633. }
  5634. return false;
  5635. }
  5636. END_JUCE_NAMESPACE
  5637. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5638. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5639. BEGIN_JUCE_NAMESPACE
  5640. NamedPipe::NamedPipe()
  5641. : internal (0)
  5642. {
  5643. }
  5644. NamedPipe::~NamedPipe()
  5645. {
  5646. close();
  5647. }
  5648. bool NamedPipe::openExisting (const String& pipeName)
  5649. {
  5650. currentPipeName = pipeName;
  5651. return openInternal (pipeName, false);
  5652. }
  5653. bool NamedPipe::createNewPipe (const String& pipeName)
  5654. {
  5655. currentPipeName = pipeName;
  5656. return openInternal (pipeName, true);
  5657. }
  5658. bool NamedPipe::isOpen() const
  5659. {
  5660. return internal != 0;
  5661. }
  5662. const String NamedPipe::getName() const
  5663. {
  5664. return currentPipeName;
  5665. }
  5666. // other methods for this class are implemented in the platform-specific files
  5667. END_JUCE_NAMESPACE
  5668. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5669. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5670. BEGIN_JUCE_NAMESPACE
  5671. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5672. {
  5673. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5674. "temp_" + String (Random::getSystemRandom().nextInt()),
  5675. suffix,
  5676. optionFlags);
  5677. }
  5678. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5679. : targetFile (targetFile_)
  5680. {
  5681. // If you use this constructor, you need to give it a valid target file!
  5682. jassert (targetFile != File::nonexistent);
  5683. createTempFile (targetFile.getParentDirectory(),
  5684. targetFile.getFileNameWithoutExtension() + "_temp" + String (Random::getSystemRandom().nextInt()),
  5685. targetFile.getFileExtension(),
  5686. optionFlags);
  5687. }
  5688. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5689. const String& suffix, const int optionFlags)
  5690. {
  5691. if ((optionFlags & useHiddenFile) != 0)
  5692. name = "." + name;
  5693. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5694. }
  5695. TemporaryFile::~TemporaryFile()
  5696. {
  5697. // Have a few attempts at deleting the file before giving up..
  5698. for (int i = 5; --i >= 0;)
  5699. {
  5700. if (temporaryFile.deleteFile())
  5701. return;
  5702. Thread::sleep (50);
  5703. }
  5704. // Failed to delete our temporary file! Check that you've deleted all the
  5705. // file output streams that were using it!
  5706. jassertfalse;
  5707. }
  5708. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5709. {
  5710. // This method only works if you created this object with the constructor
  5711. // that takes a target file!
  5712. jassert (targetFile != File::nonexistent);
  5713. if (temporaryFile.exists())
  5714. {
  5715. // Have a few attempts at overwriting the file before giving up..
  5716. for (int i = 5; --i >= 0;)
  5717. {
  5718. if (temporaryFile.moveFileTo (targetFile))
  5719. return true;
  5720. Thread::sleep (100);
  5721. }
  5722. }
  5723. else
  5724. {
  5725. // There's no temporary file to use. If your write failed, you should
  5726. // probably check, and not bother calling this method.
  5727. jassertfalse
  5728. }
  5729. return false;
  5730. }
  5731. END_JUCE_NAMESPACE
  5732. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5733. /*** Start of inlined file: juce_Socket.cpp ***/
  5734. #if JUCE_WINDOWS
  5735. #include <winsock2.h>
  5736. #ifdef _MSC_VER
  5737. #pragma warning (disable : 4127 4389 4018)
  5738. #endif
  5739. #else
  5740. #if JUCE_LINUX
  5741. #include <sys/types.h>
  5742. #include <sys/socket.h>
  5743. #include <sys/errno.h>
  5744. #include <unistd.h>
  5745. #include <netinet/in.h>
  5746. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5747. #include <CoreServices/CoreServices.h>
  5748. #endif
  5749. #include <fcntl.h>
  5750. #include <netdb.h>
  5751. #include <arpa/inet.h>
  5752. #include <netinet/tcp.h>
  5753. #endif
  5754. BEGIN_JUCE_NAMESPACE
  5755. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5756. typedef socklen_t juce_socklen_t;
  5757. #else
  5758. typedef int juce_socklen_t;
  5759. #endif
  5760. #if JUCE_WINDOWS
  5761. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5762. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5763. static void initWin32Sockets()
  5764. {
  5765. static CriticalSection lock;
  5766. const ScopedLock sl (lock);
  5767. if (juce_CloseWin32SocketLib == 0)
  5768. {
  5769. WSADATA wsaData;
  5770. const WORD wVersionRequested = MAKEWORD (1, 1);
  5771. WSAStartup (wVersionRequested, &wsaData);
  5772. juce_CloseWin32SocketLib = &WSACleanup;
  5773. }
  5774. }
  5775. #endif
  5776. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5777. {
  5778. const int sndBufSize = 65536;
  5779. const int rcvBufSize = 65536;
  5780. const int one = 1;
  5781. return handle > 0
  5782. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5783. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5784. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5785. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5786. }
  5787. static bool bindSocketToPort (const int handle, const int port) throw()
  5788. {
  5789. if (handle <= 0 || port <= 0)
  5790. return false;
  5791. struct sockaddr_in servTmpAddr;
  5792. zerostruct (servTmpAddr);
  5793. servTmpAddr.sin_family = PF_INET;
  5794. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5795. servTmpAddr.sin_port = htons ((uint16) port);
  5796. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5797. }
  5798. static int readSocket (const int handle,
  5799. void* const destBuffer, const int maxBytesToRead,
  5800. bool volatile& connected,
  5801. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5802. {
  5803. int bytesRead = 0;
  5804. while (bytesRead < maxBytesToRead)
  5805. {
  5806. int bytesThisTime;
  5807. #if JUCE_WINDOWS
  5808. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5809. #else
  5810. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5811. && errno == EINTR
  5812. && connected)
  5813. {
  5814. }
  5815. #endif
  5816. if (bytesThisTime <= 0 || ! connected)
  5817. {
  5818. if (bytesRead == 0)
  5819. bytesRead = -1;
  5820. break;
  5821. }
  5822. bytesRead += bytesThisTime;
  5823. if (! blockUntilSpecifiedAmountHasArrived)
  5824. break;
  5825. }
  5826. return bytesRead;
  5827. }
  5828. static int waitForReadiness (const int handle, const bool forReading,
  5829. const int timeoutMsecs) throw()
  5830. {
  5831. struct timeval timeout;
  5832. struct timeval* timeoutp;
  5833. if (timeoutMsecs >= 0)
  5834. {
  5835. timeout.tv_sec = timeoutMsecs / 1000;
  5836. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  5837. timeoutp = &timeout;
  5838. }
  5839. else
  5840. {
  5841. timeoutp = 0;
  5842. }
  5843. fd_set rset, wset;
  5844. FD_ZERO (&rset);
  5845. FD_SET (handle, &rset);
  5846. FD_ZERO (&wset);
  5847. FD_SET (handle, &wset);
  5848. fd_set* const prset = forReading ? &rset : 0;
  5849. fd_set* const pwset = forReading ? 0 : &wset;
  5850. #if JUCE_WINDOWS
  5851. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  5852. return -1;
  5853. #else
  5854. {
  5855. int result;
  5856. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  5857. && errno == EINTR)
  5858. {
  5859. }
  5860. if (result < 0)
  5861. return -1;
  5862. }
  5863. #endif
  5864. {
  5865. int opt;
  5866. juce_socklen_t len = sizeof (opt);
  5867. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  5868. || opt != 0)
  5869. return -1;
  5870. }
  5871. if ((forReading && FD_ISSET (handle, &rset))
  5872. || ((! forReading) && FD_ISSET (handle, &wset)))
  5873. return 1;
  5874. return 0;
  5875. }
  5876. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  5877. {
  5878. #if JUCE_WINDOWS
  5879. u_long nonBlocking = shouldBlock ? 0 : 1;
  5880. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  5881. return false;
  5882. #else
  5883. int socketFlags = fcntl (handle, F_GETFL, 0);
  5884. if (socketFlags == -1)
  5885. return false;
  5886. if (shouldBlock)
  5887. socketFlags &= ~O_NONBLOCK;
  5888. else
  5889. socketFlags |= O_NONBLOCK;
  5890. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  5891. return false;
  5892. #endif
  5893. return true;
  5894. }
  5895. static bool connectSocket (int volatile& handle,
  5896. const bool isDatagram,
  5897. void** serverAddress,
  5898. const String& hostName,
  5899. const int portNumber,
  5900. const int timeOutMillisecs) throw()
  5901. {
  5902. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  5903. if (hostEnt == 0)
  5904. return false;
  5905. struct in_addr targetAddress;
  5906. memcpy (&targetAddress.s_addr,
  5907. *(hostEnt->h_addr_list),
  5908. sizeof (targetAddress.s_addr));
  5909. struct sockaddr_in servTmpAddr;
  5910. zerostruct (servTmpAddr);
  5911. servTmpAddr.sin_family = PF_INET;
  5912. servTmpAddr.sin_addr = targetAddress;
  5913. servTmpAddr.sin_port = htons ((uint16) portNumber);
  5914. if (handle < 0)
  5915. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  5916. if (handle < 0)
  5917. return false;
  5918. if (isDatagram)
  5919. {
  5920. *serverAddress = new struct sockaddr_in();
  5921. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  5922. return true;
  5923. }
  5924. setSocketBlockingState (handle, false);
  5925. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  5926. if (result < 0)
  5927. {
  5928. #if JUCE_WINDOWS
  5929. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  5930. #else
  5931. if (errno == EINPROGRESS)
  5932. #endif
  5933. {
  5934. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  5935. {
  5936. setSocketBlockingState (handle, true);
  5937. return false;
  5938. }
  5939. }
  5940. }
  5941. setSocketBlockingState (handle, true);
  5942. resetSocketOptions (handle, false, false);
  5943. return true;
  5944. }
  5945. StreamingSocket::StreamingSocket()
  5946. : portNumber (0),
  5947. handle (-1),
  5948. connected (false),
  5949. isListener (false)
  5950. {
  5951. #if JUCE_WINDOWS
  5952. initWin32Sockets();
  5953. #endif
  5954. }
  5955. StreamingSocket::StreamingSocket (const String& hostName_,
  5956. const int portNumber_,
  5957. const int handle_)
  5958. : hostName (hostName_),
  5959. portNumber (portNumber_),
  5960. handle (handle_),
  5961. connected (true),
  5962. isListener (false)
  5963. {
  5964. #if JUCE_WINDOWS
  5965. initWin32Sockets();
  5966. #endif
  5967. resetSocketOptions (handle_, false, false);
  5968. }
  5969. StreamingSocket::~StreamingSocket()
  5970. {
  5971. close();
  5972. }
  5973. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  5974. {
  5975. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  5976. : -1;
  5977. }
  5978. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  5979. {
  5980. if (isListener || ! connected)
  5981. return -1;
  5982. #if JUCE_WINDOWS
  5983. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  5984. #else
  5985. int result;
  5986. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  5987. && errno == EINTR)
  5988. {
  5989. }
  5990. return result;
  5991. #endif
  5992. }
  5993. int StreamingSocket::waitUntilReady (const bool readyForReading,
  5994. const int timeoutMsecs) const
  5995. {
  5996. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  5997. : -1;
  5998. }
  5999. bool StreamingSocket::bindToPort (const int port)
  6000. {
  6001. return bindSocketToPort (handle, port);
  6002. }
  6003. bool StreamingSocket::connect (const String& remoteHostName,
  6004. const int remotePortNumber,
  6005. const int timeOutMillisecs)
  6006. {
  6007. if (isListener)
  6008. {
  6009. jassertfalse // a listener socket can't connect to another one!
  6010. return false;
  6011. }
  6012. if (connected)
  6013. close();
  6014. hostName = remoteHostName;
  6015. portNumber = remotePortNumber;
  6016. isListener = false;
  6017. connected = connectSocket (handle, false, 0, remoteHostName,
  6018. remotePortNumber, timeOutMillisecs);
  6019. if (! (connected && resetSocketOptions (handle, false, false)))
  6020. {
  6021. close();
  6022. return false;
  6023. }
  6024. return true;
  6025. }
  6026. void StreamingSocket::close()
  6027. {
  6028. #if JUCE_WINDOWS
  6029. if (handle != SOCKET_ERROR || connected)
  6030. closesocket (handle);
  6031. connected = false;
  6032. #else
  6033. if (connected)
  6034. {
  6035. connected = false;
  6036. if (isListener)
  6037. {
  6038. // need to do this to interrupt the accept() function..
  6039. StreamingSocket temp;
  6040. temp.connect ("localhost", portNumber, 1000);
  6041. }
  6042. }
  6043. if (handle != -1)
  6044. ::close (handle);
  6045. #endif
  6046. hostName = String::empty;
  6047. portNumber = 0;
  6048. handle = -1;
  6049. isListener = false;
  6050. }
  6051. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6052. {
  6053. if (connected)
  6054. close();
  6055. hostName = "listener";
  6056. portNumber = newPortNumber;
  6057. isListener = true;
  6058. struct sockaddr_in servTmpAddr;
  6059. zerostruct (servTmpAddr);
  6060. servTmpAddr.sin_family = PF_INET;
  6061. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6062. if (localHostName.isNotEmpty())
  6063. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6064. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6065. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6066. if (handle < 0)
  6067. return false;
  6068. const int reuse = 1;
  6069. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6070. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6071. || listen (handle, SOMAXCONN) < 0)
  6072. {
  6073. close();
  6074. return false;
  6075. }
  6076. connected = true;
  6077. return true;
  6078. }
  6079. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6080. {
  6081. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6082. // prepare this socket as a listener.
  6083. if (connected && isListener)
  6084. {
  6085. struct sockaddr address;
  6086. juce_socklen_t len = sizeof (sockaddr);
  6087. const int newSocket = (int) accept (handle, &address, &len);
  6088. if (newSocket >= 0 && connected)
  6089. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6090. portNumber, newSocket);
  6091. }
  6092. return 0;
  6093. }
  6094. bool StreamingSocket::isLocal() const throw()
  6095. {
  6096. return hostName == "127.0.0.1";
  6097. }
  6098. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6099. : portNumber (0),
  6100. handle (-1),
  6101. connected (true),
  6102. allowBroadcast (allowBroadcast_),
  6103. serverAddress (0)
  6104. {
  6105. #if JUCE_WINDOWS
  6106. initWin32Sockets();
  6107. #endif
  6108. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6109. bindToPort (localPortNumber);
  6110. }
  6111. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6112. const int handle_, const int localPortNumber)
  6113. : hostName (hostName_),
  6114. portNumber (portNumber_),
  6115. handle (handle_),
  6116. connected (true),
  6117. allowBroadcast (false),
  6118. serverAddress (0)
  6119. {
  6120. #if JUCE_WINDOWS
  6121. initWin32Sockets();
  6122. #endif
  6123. resetSocketOptions (handle_, true, allowBroadcast);
  6124. bindToPort (localPortNumber);
  6125. }
  6126. DatagramSocket::~DatagramSocket()
  6127. {
  6128. close();
  6129. delete ((struct sockaddr_in*) serverAddress);
  6130. serverAddress = 0;
  6131. }
  6132. void DatagramSocket::close()
  6133. {
  6134. #if JUCE_WINDOWS
  6135. closesocket (handle);
  6136. connected = false;
  6137. #else
  6138. connected = false;
  6139. ::close (handle);
  6140. #endif
  6141. hostName = String::empty;
  6142. portNumber = 0;
  6143. handle = -1;
  6144. }
  6145. bool DatagramSocket::bindToPort (const int port)
  6146. {
  6147. return bindSocketToPort (handle, port);
  6148. }
  6149. bool DatagramSocket::connect (const String& remoteHostName,
  6150. const int remotePortNumber,
  6151. const int timeOutMillisecs)
  6152. {
  6153. if (connected)
  6154. close();
  6155. hostName = remoteHostName;
  6156. portNumber = remotePortNumber;
  6157. connected = connectSocket (handle, true, &serverAddress,
  6158. remoteHostName, remotePortNumber,
  6159. timeOutMillisecs);
  6160. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6161. {
  6162. close();
  6163. return false;
  6164. }
  6165. return true;
  6166. }
  6167. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6168. {
  6169. struct sockaddr address;
  6170. juce_socklen_t len = sizeof (sockaddr);
  6171. while (waitUntilReady (true, -1) == 1)
  6172. {
  6173. char buf[1];
  6174. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6175. {
  6176. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6177. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6178. -1, -1);
  6179. }
  6180. }
  6181. return 0;
  6182. }
  6183. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6184. const int timeoutMsecs) const
  6185. {
  6186. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6187. : -1;
  6188. }
  6189. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6190. {
  6191. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6192. : -1;
  6193. }
  6194. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6195. {
  6196. // You need to call connect() first to set the server address..
  6197. jassert (serverAddress != 0 && connected);
  6198. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6199. numBytesToWrite, 0,
  6200. (const struct sockaddr*) serverAddress,
  6201. sizeof (struct sockaddr_in))
  6202. : -1;
  6203. }
  6204. bool DatagramSocket::isLocal() const throw()
  6205. {
  6206. return hostName == "127.0.0.1";
  6207. }
  6208. END_JUCE_NAMESPACE
  6209. /*** End of inlined file: juce_Socket.cpp ***/
  6210. /*** Start of inlined file: juce_URL.cpp ***/
  6211. BEGIN_JUCE_NAMESPACE
  6212. URL::URL()
  6213. {
  6214. }
  6215. URL::URL (const String& url_)
  6216. : url (url_)
  6217. {
  6218. int i = url.indexOfChar ('?');
  6219. if (i >= 0)
  6220. {
  6221. do
  6222. {
  6223. const int nextAmp = url.indexOfChar (i + 1, '&');
  6224. const int equalsPos = url.indexOfChar (i + 1, '=');
  6225. if (equalsPos > i + 1)
  6226. {
  6227. if (nextAmp < 0)
  6228. {
  6229. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6230. removeEscapeChars (url.substring (equalsPos + 1)));
  6231. }
  6232. else if (nextAmp > 0 && equalsPos < nextAmp)
  6233. {
  6234. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6235. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6236. }
  6237. }
  6238. i = nextAmp;
  6239. }
  6240. while (i >= 0);
  6241. url = url.upToFirstOccurrenceOf ("?", false, false);
  6242. }
  6243. }
  6244. URL::URL (const URL& other)
  6245. : url (other.url),
  6246. postData (other.postData),
  6247. parameters (other.parameters),
  6248. filesToUpload (other.filesToUpload),
  6249. mimeTypes (other.mimeTypes)
  6250. {
  6251. }
  6252. URL& URL::operator= (const URL& other)
  6253. {
  6254. url = other.url;
  6255. postData = other.postData;
  6256. parameters = other.parameters;
  6257. filesToUpload = other.filesToUpload;
  6258. mimeTypes = other.mimeTypes;
  6259. return *this;
  6260. }
  6261. URL::~URL()
  6262. {
  6263. }
  6264. static const String getMangledParameters (const StringPairArray& parameters)
  6265. {
  6266. String p;
  6267. for (int i = 0; i < parameters.size(); ++i)
  6268. {
  6269. if (i > 0)
  6270. p += '&';
  6271. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6272. << '='
  6273. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6274. }
  6275. return p;
  6276. }
  6277. const String URL::toString (const bool includeGetParameters) const
  6278. {
  6279. if (includeGetParameters && parameters.size() > 0)
  6280. return url + "?" + getMangledParameters (parameters);
  6281. else
  6282. return url;
  6283. }
  6284. bool URL::isWellFormed() const
  6285. {
  6286. //xxx TODO
  6287. return url.isNotEmpty();
  6288. }
  6289. static int findStartOfDomain (const String& url)
  6290. {
  6291. int i = 0;
  6292. while (CharacterFunctions::isLetterOrDigit (url[i])
  6293. || CharacterFunctions::indexOfChar (L"+-.", url[i], false) >= 0)
  6294. ++i;
  6295. return url[i] == ':' ? i + 1 : 0;
  6296. }
  6297. const String URL::getDomain() const
  6298. {
  6299. int start = findStartOfDomain (url);
  6300. while (url[start] == '/')
  6301. ++start;
  6302. const int end1 = url.indexOfChar (start, '/');
  6303. const int end2 = url.indexOfChar (start, ':');
  6304. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6305. : jmin (end1, end2);
  6306. return url.substring (start, end);
  6307. }
  6308. const String URL::getSubPath() const
  6309. {
  6310. int start = findStartOfDomain (url);
  6311. while (url[start] == '/')
  6312. ++start;
  6313. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6314. return startOfPath <= 0 ? String::empty
  6315. : url.substring (startOfPath);
  6316. }
  6317. const String URL::getScheme() const
  6318. {
  6319. return url.substring (0, findStartOfDomain (url) - 1);
  6320. }
  6321. const URL URL::withNewSubPath (const String& newPath) const
  6322. {
  6323. int start = findStartOfDomain (url);
  6324. while (url[start] == '/')
  6325. ++start;
  6326. const int startOfPath = url.indexOfChar (start, '/') + 1;
  6327. URL u (*this);
  6328. if (startOfPath > 0)
  6329. u.url = url.substring (0, startOfPath);
  6330. if (! u.url.endsWithChar ('/'))
  6331. u.url << '/';
  6332. if (newPath.startsWithChar ('/'))
  6333. u.url << newPath.substring (1);
  6334. else
  6335. u.url << newPath;
  6336. return u;
  6337. }
  6338. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6339. {
  6340. if (possibleURL.startsWithIgnoreCase ("http:")
  6341. || possibleURL.startsWithIgnoreCase ("ftp:"))
  6342. return true;
  6343. if (possibleURL.startsWithIgnoreCase ("file:")
  6344. || possibleURL.containsChar ('@')
  6345. || possibleURL.endsWithChar ('.')
  6346. || (! possibleURL.containsChar ('.')))
  6347. return false;
  6348. if (possibleURL.startsWithIgnoreCase ("www.")
  6349. && possibleURL.substring (5).containsChar ('.'))
  6350. return true;
  6351. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6352. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6353. if ((possibleURL + "/").containsIgnoreCase ("." + String (commonTLDs[i]) + "/"))
  6354. return true;
  6355. return false;
  6356. }
  6357. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6358. {
  6359. const int atSign = possibleEmailAddress.indexOfChar ('@');
  6360. return atSign > 0
  6361. && possibleEmailAddress.lastIndexOfChar ('.') > (atSign + 1)
  6362. && (! possibleEmailAddress.endsWithChar ('.'));
  6363. }
  6364. void* juce_openInternetFile (const String& url,
  6365. const String& headers,
  6366. const MemoryBlock& optionalPostData,
  6367. const bool isPost,
  6368. URL::OpenStreamProgressCallback* callback,
  6369. void* callbackContext,
  6370. int timeOutMs);
  6371. void juce_closeInternetFile (void* handle);
  6372. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6373. int juce_seekInInternetFile (void* handle, int newPosition);
  6374. int64 juce_getInternetFileContentLength (void* handle);
  6375. class WebInputStream : public InputStream
  6376. {
  6377. public:
  6378. WebInputStream (const URL& url,
  6379. const bool isPost_,
  6380. URL::OpenStreamProgressCallback* const progressCallback_,
  6381. void* const progressCallbackContext_,
  6382. const String& extraHeaders,
  6383. int timeOutMs_)
  6384. : position (0),
  6385. finished (false),
  6386. isPost (isPost_),
  6387. progressCallback (progressCallback_),
  6388. progressCallbackContext (progressCallbackContext_),
  6389. timeOutMs (timeOutMs_)
  6390. {
  6391. server = url.toString (! isPost);
  6392. if (isPost_)
  6393. createHeadersAndPostData (url);
  6394. headers += extraHeaders;
  6395. if (! headers.endsWithChar ('\n'))
  6396. headers << "\r\n";
  6397. handle = juce_openInternetFile (server, headers, postData, isPost,
  6398. progressCallback_, progressCallbackContext_,
  6399. timeOutMs);
  6400. }
  6401. ~WebInputStream()
  6402. {
  6403. juce_closeInternetFile (handle);
  6404. }
  6405. bool isError() const
  6406. {
  6407. return handle == 0;
  6408. }
  6409. int64 getTotalLength()
  6410. {
  6411. return juce_getInternetFileContentLength (handle);
  6412. }
  6413. bool isExhausted()
  6414. {
  6415. return finished;
  6416. }
  6417. int read (void* dest, int bytes)
  6418. {
  6419. if (finished || isError())
  6420. {
  6421. return 0;
  6422. }
  6423. else
  6424. {
  6425. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6426. position += bytesRead;
  6427. if (bytesRead == 0)
  6428. finished = true;
  6429. return bytesRead;
  6430. }
  6431. }
  6432. int64 getPosition()
  6433. {
  6434. return position;
  6435. }
  6436. bool setPosition (int64 wantedPos)
  6437. {
  6438. if (wantedPos != position)
  6439. {
  6440. finished = false;
  6441. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6442. if (actualPos == wantedPos)
  6443. {
  6444. position = wantedPos;
  6445. }
  6446. else
  6447. {
  6448. if (wantedPos < position)
  6449. {
  6450. juce_closeInternetFile (handle);
  6451. position = 0;
  6452. finished = false;
  6453. handle = juce_openInternetFile (server, headers, postData, isPost,
  6454. progressCallback, progressCallbackContext,
  6455. timeOutMs);
  6456. }
  6457. skipNextBytes (wantedPos - position);
  6458. }
  6459. }
  6460. return true;
  6461. }
  6462. juce_UseDebuggingNewOperator
  6463. private:
  6464. String server, headers;
  6465. MemoryBlock postData;
  6466. int64 position;
  6467. bool finished;
  6468. const bool isPost;
  6469. void* handle;
  6470. URL::OpenStreamProgressCallback* const progressCallback;
  6471. void* const progressCallbackContext;
  6472. const int timeOutMs;
  6473. void createHeadersAndPostData (const URL& url)
  6474. {
  6475. if (url.getFilesToUpload().size() > 0)
  6476. {
  6477. // need to upload some files, so do it as multi-part...
  6478. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6479. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6480. appendUTF8ToPostData ("--" + boundary);
  6481. int i;
  6482. for (i = 0; i < url.getParameters().size(); ++i)
  6483. {
  6484. String s;
  6485. s << "\r\nContent-Disposition: form-data; name=\""
  6486. << url.getParameters().getAllKeys() [i]
  6487. << "\"\r\n\r\n"
  6488. << url.getParameters().getAllValues() [i]
  6489. << "\r\n--"
  6490. << boundary;
  6491. appendUTF8ToPostData (s);
  6492. }
  6493. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6494. {
  6495. const File f (url.getFilesToUpload().getAllValues() [i]);
  6496. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6497. String s;
  6498. s << "\r\nContent-Disposition: form-data; name=\""
  6499. << paramName
  6500. << "\"; filename=\""
  6501. << f.getFileName()
  6502. << "\"\r\n";
  6503. const String mimeType (url.getMimeTypesOfUploadFiles()
  6504. .getValue (paramName, String::empty));
  6505. if (mimeType.isNotEmpty())
  6506. s << "Content-Type: " << mimeType << "\r\n";
  6507. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6508. appendUTF8ToPostData (s);
  6509. f.loadFileAsData (postData);
  6510. s = "\r\n--" + boundary;
  6511. appendUTF8ToPostData (s);
  6512. }
  6513. appendUTF8ToPostData ("--\r\n");
  6514. }
  6515. else
  6516. {
  6517. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6518. appendUTF8ToPostData (url.getPostData());
  6519. // just a short text attachment, so use simple url encoding..
  6520. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6521. + String ((unsigned int) postData.getSize())
  6522. + "\r\n";
  6523. }
  6524. }
  6525. void appendUTF8ToPostData (const String& text)
  6526. {
  6527. postData.append (text.toUTF8(),
  6528. (int) strlen (text.toUTF8()));
  6529. }
  6530. WebInputStream (const WebInputStream&);
  6531. WebInputStream& operator= (const WebInputStream&);
  6532. };
  6533. InputStream* URL::createInputStream (const bool usePostCommand,
  6534. OpenStreamProgressCallback* const progressCallback,
  6535. void* const progressCallbackContext,
  6536. const String& extraHeaders,
  6537. const int timeOutMs) const
  6538. {
  6539. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6540. progressCallback, progressCallbackContext,
  6541. extraHeaders,
  6542. timeOutMs));
  6543. return wi->isError() ? 0 : wi.release();
  6544. }
  6545. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6546. const bool usePostCommand) const
  6547. {
  6548. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6549. if (in != 0)
  6550. {
  6551. in->readIntoMemoryBlock (destData, -1);
  6552. return true;
  6553. }
  6554. return false;
  6555. }
  6556. const String URL::readEntireTextStream (const bool usePostCommand) const
  6557. {
  6558. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6559. if (in != 0)
  6560. return in->readEntireStreamAsString();
  6561. return String::empty;
  6562. }
  6563. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6564. {
  6565. XmlDocument doc (readEntireTextStream (usePostCommand));
  6566. return doc.getDocumentElement();
  6567. }
  6568. const URL URL::withParameter (const String& parameterName,
  6569. const String& parameterValue) const
  6570. {
  6571. URL u (*this);
  6572. u.parameters.set (parameterName, parameterValue);
  6573. return u;
  6574. }
  6575. const URL URL::withFileToUpload (const String& parameterName,
  6576. const File& fileToUpload,
  6577. const String& mimeType) const
  6578. {
  6579. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6580. URL u (*this);
  6581. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6582. u.mimeTypes.set (parameterName, mimeType);
  6583. return u;
  6584. }
  6585. const URL URL::withPOSTData (const String& postData_) const
  6586. {
  6587. URL u (*this);
  6588. u.postData = postData_;
  6589. return u;
  6590. }
  6591. const StringPairArray& URL::getParameters() const
  6592. {
  6593. return parameters;
  6594. }
  6595. const StringPairArray& URL::getFilesToUpload() const
  6596. {
  6597. return filesToUpload;
  6598. }
  6599. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6600. {
  6601. return mimeTypes;
  6602. }
  6603. const String URL::removeEscapeChars (const String& s)
  6604. {
  6605. String result (s.replaceCharacter ('+', ' '));
  6606. int nextPercent = 0;
  6607. for (;;)
  6608. {
  6609. nextPercent = result.indexOfChar (nextPercent, '%');
  6610. if (nextPercent < 0)
  6611. break;
  6612. juce_wchar replacementChar = result.substring (nextPercent + 1, nextPercent + 3).getHexValue32();
  6613. result = result.replaceSection (nextPercent, 3, String::charToString (replacementChar));
  6614. ++nextPercent;
  6615. }
  6616. return result;
  6617. }
  6618. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6619. {
  6620. String result;
  6621. result.preallocateStorage (s.length() + 8);
  6622. const char* utf8 = s.toUTF8();
  6623. const char* legalChars = isParameter ? "_-.*!'()"
  6624. : "_-$.*!'(),";
  6625. while (*utf8 != 0)
  6626. {
  6627. const char c = *utf8++;
  6628. if (CharacterFunctions::isLetterOrDigit (c)
  6629. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6630. {
  6631. result << c;
  6632. }
  6633. else
  6634. {
  6635. const int v = (int) (uint8) c;
  6636. result << (v < 0x10 ? "%0" : "%") << String::toHexString (v);
  6637. }
  6638. }
  6639. return result;
  6640. }
  6641. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6642. bool URL::launchInDefaultBrowser() const
  6643. {
  6644. String u (toString (true));
  6645. if (u.containsChar ('@') && ! u.containsChar (':'))
  6646. u = "mailto:" + u;
  6647. return juce_launchFile (u, String::empty);
  6648. }
  6649. END_JUCE_NAMESPACE
  6650. /*** End of inlined file: juce_URL.cpp ***/
  6651. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6652. BEGIN_JUCE_NAMESPACE
  6653. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6654. const int bufferSize_,
  6655. const bool deleteSourceWhenDestroyed)
  6656. : source (source_),
  6657. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6658. bufferSize (jmax (256, bufferSize_)),
  6659. position (source_->getPosition()),
  6660. lastReadPos (0),
  6661. bufferOverlap (128)
  6662. {
  6663. const int sourceSize = (int) source_->getTotalLength();
  6664. if (sourceSize >= 0)
  6665. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6666. bufferStart = position;
  6667. buffer.malloc (bufferSize);
  6668. }
  6669. BufferedInputStream::~BufferedInputStream()
  6670. {
  6671. }
  6672. int64 BufferedInputStream::getTotalLength()
  6673. {
  6674. return source->getTotalLength();
  6675. }
  6676. int64 BufferedInputStream::getPosition()
  6677. {
  6678. return position;
  6679. }
  6680. bool BufferedInputStream::setPosition (int64 newPosition)
  6681. {
  6682. position = jmax ((int64) 0, newPosition);
  6683. return true;
  6684. }
  6685. bool BufferedInputStream::isExhausted()
  6686. {
  6687. return (position >= lastReadPos)
  6688. && source->isExhausted();
  6689. }
  6690. void BufferedInputStream::ensureBuffered()
  6691. {
  6692. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6693. if (position < bufferStart || position >= bufferEndOverlap)
  6694. {
  6695. int bytesRead;
  6696. if (position < lastReadPos
  6697. && position >= bufferEndOverlap
  6698. && position >= bufferStart)
  6699. {
  6700. const int bytesToKeep = (int) (lastReadPos - position);
  6701. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6702. bufferStart = position;
  6703. bytesRead = source->read (buffer + bytesToKeep,
  6704. bufferSize - bytesToKeep);
  6705. lastReadPos += bytesRead;
  6706. bytesRead += bytesToKeep;
  6707. }
  6708. else
  6709. {
  6710. bufferStart = position;
  6711. source->setPosition (bufferStart);
  6712. bytesRead = source->read (buffer, bufferSize);
  6713. lastReadPos = bufferStart + bytesRead;
  6714. }
  6715. while (bytesRead < bufferSize)
  6716. buffer [bytesRead++] = 0;
  6717. }
  6718. }
  6719. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6720. {
  6721. if (position >= bufferStart
  6722. && position + maxBytesToRead <= lastReadPos)
  6723. {
  6724. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6725. position += maxBytesToRead;
  6726. return maxBytesToRead;
  6727. }
  6728. else
  6729. {
  6730. if (position < bufferStart || position >= lastReadPos)
  6731. ensureBuffered();
  6732. int bytesRead = 0;
  6733. while (maxBytesToRead > 0)
  6734. {
  6735. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6736. if (bytesAvailable > 0)
  6737. {
  6738. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6739. maxBytesToRead -= bytesAvailable;
  6740. bytesRead += bytesAvailable;
  6741. position += bytesAvailable;
  6742. destBuffer = static_cast <char*> (destBuffer) + bytesAvailable;
  6743. }
  6744. const int64 oldLastReadPos = lastReadPos;
  6745. ensureBuffered();
  6746. if (oldLastReadPos == lastReadPos)
  6747. break; // if ensureBuffered() failed to read any more data, bail out
  6748. if (isExhausted())
  6749. break;
  6750. }
  6751. return bytesRead;
  6752. }
  6753. }
  6754. const String BufferedInputStream::readString()
  6755. {
  6756. if (position >= bufferStart
  6757. && position < lastReadPos)
  6758. {
  6759. const int maxChars = (int) (lastReadPos - position);
  6760. const char* const src = buffer + (int) (position - bufferStart);
  6761. for (int i = 0; i < maxChars; ++i)
  6762. {
  6763. if (src[i] == 0)
  6764. {
  6765. position += i + 1;
  6766. return String::fromUTF8 (src, i);
  6767. }
  6768. }
  6769. }
  6770. return InputStream::readString();
  6771. }
  6772. END_JUCE_NAMESPACE
  6773. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6774. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6775. BEGIN_JUCE_NAMESPACE
  6776. FileInputSource::FileInputSource (const File& file_)
  6777. : file (file_)
  6778. {
  6779. }
  6780. FileInputSource::~FileInputSource()
  6781. {
  6782. }
  6783. InputStream* FileInputSource::createInputStream()
  6784. {
  6785. return file.createInputStream();
  6786. }
  6787. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6788. {
  6789. return file.getSiblingFile (relatedItemPath).createInputStream();
  6790. }
  6791. int64 FileInputSource::hashCode() const
  6792. {
  6793. return file.hashCode();
  6794. }
  6795. END_JUCE_NAMESPACE
  6796. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6797. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6798. BEGIN_JUCE_NAMESPACE
  6799. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6800. const size_t sourceDataSize,
  6801. const bool keepInternalCopy)
  6802. : data (static_cast <const char*> (sourceData)),
  6803. dataSize (sourceDataSize),
  6804. position (0)
  6805. {
  6806. if (keepInternalCopy)
  6807. {
  6808. internalCopy.append (data, sourceDataSize);
  6809. data = static_cast <const char*> (internalCopy.getData());
  6810. }
  6811. }
  6812. MemoryInputStream::MemoryInputStream (const MemoryBlock& sourceData,
  6813. const bool keepInternalCopy)
  6814. : data (static_cast <const char*> (sourceData.getData())),
  6815. dataSize (sourceData.getSize()),
  6816. position (0)
  6817. {
  6818. if (keepInternalCopy)
  6819. {
  6820. internalCopy = sourceData;
  6821. data = static_cast <const char*> (internalCopy.getData());
  6822. }
  6823. }
  6824. MemoryInputStream::~MemoryInputStream()
  6825. {
  6826. }
  6827. int64 MemoryInputStream::getTotalLength()
  6828. {
  6829. return dataSize;
  6830. }
  6831. int MemoryInputStream::read (void* const buffer, const int howMany)
  6832. {
  6833. jassert (howMany >= 0);
  6834. const int num = jmin (howMany, (int) (dataSize - position));
  6835. memcpy (buffer, data + position, num);
  6836. position += num;
  6837. return (int) num;
  6838. }
  6839. bool MemoryInputStream::isExhausted()
  6840. {
  6841. return (position >= dataSize);
  6842. }
  6843. bool MemoryInputStream::setPosition (const int64 pos)
  6844. {
  6845. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  6846. return true;
  6847. }
  6848. int64 MemoryInputStream::getPosition()
  6849. {
  6850. return position;
  6851. }
  6852. END_JUCE_NAMESPACE
  6853. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  6854. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  6855. BEGIN_JUCE_NAMESPACE
  6856. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  6857. const size_t blockSizeToIncreaseBy,
  6858. MemoryBlock* const memoryBlockToWriteTo)
  6859. : data (memoryBlockToWriteTo),
  6860. position (0),
  6861. size (0),
  6862. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  6863. {
  6864. if (data == 0)
  6865. dataToDelete = data = new MemoryBlock (initialSize);
  6866. else
  6867. data->setSize (initialSize, false);
  6868. }
  6869. MemoryOutputStream::~MemoryOutputStream()
  6870. {
  6871. flush();
  6872. }
  6873. void MemoryOutputStream::flush()
  6874. {
  6875. if (dataToDelete == 0)
  6876. data->setSize (size, false);
  6877. }
  6878. void MemoryOutputStream::reset() throw()
  6879. {
  6880. position = 0;
  6881. size = 0;
  6882. }
  6883. bool MemoryOutputStream::write (const void* const buffer, int howMany)
  6884. {
  6885. if (howMany > 0)
  6886. {
  6887. size_t storageNeeded = position + howMany;
  6888. if (storageNeeded >= data->getSize())
  6889. {
  6890. // if we need more space, increase the block by at least 10%..
  6891. storageNeeded += jmax (blockSize, storageNeeded / 10);
  6892. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  6893. data->ensureSize (storageNeeded);
  6894. }
  6895. data->copyFrom (buffer, (int) position, howMany);
  6896. position += howMany;
  6897. size = jmax (size, position);
  6898. }
  6899. return true;
  6900. }
  6901. const char* MemoryOutputStream::getData() const throw()
  6902. {
  6903. char* const d = static_cast <char*> (data->getData());
  6904. if (data->getSize() > size)
  6905. d [size] = 0;
  6906. return d;
  6907. }
  6908. bool MemoryOutputStream::setPosition (int64 newPosition)
  6909. {
  6910. if (newPosition <= (int64) size)
  6911. {
  6912. // ok to seek backwards
  6913. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  6914. return true;
  6915. }
  6916. else
  6917. {
  6918. // trying to make it bigger isn't a good thing to do..
  6919. return false;
  6920. }
  6921. }
  6922. const String MemoryOutputStream::toUTF8() const
  6923. {
  6924. return String (getData(), getDataSize());
  6925. }
  6926. END_JUCE_NAMESPACE
  6927. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  6928. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  6929. BEGIN_JUCE_NAMESPACE
  6930. SubregionStream::SubregionStream (InputStream* const sourceStream,
  6931. const int64 startPositionInSourceStream_,
  6932. const int64 lengthOfSourceStream_,
  6933. const bool deleteSourceWhenDestroyed) throw()
  6934. : source (sourceStream),
  6935. startPositionInSourceStream (startPositionInSourceStream_),
  6936. lengthOfSourceStream (lengthOfSourceStream_)
  6937. {
  6938. if (deleteSourceWhenDestroyed)
  6939. sourceToDelete = source;
  6940. setPosition (0);
  6941. }
  6942. SubregionStream::~SubregionStream() throw()
  6943. {
  6944. }
  6945. int64 SubregionStream::getTotalLength()
  6946. {
  6947. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  6948. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  6949. : srcLen;
  6950. }
  6951. int64 SubregionStream::getPosition()
  6952. {
  6953. return source->getPosition() - startPositionInSourceStream;
  6954. }
  6955. bool SubregionStream::setPosition (int64 newPosition)
  6956. {
  6957. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  6958. }
  6959. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  6960. {
  6961. if (lengthOfSourceStream < 0)
  6962. {
  6963. return source->read (destBuffer, maxBytesToRead);
  6964. }
  6965. else
  6966. {
  6967. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  6968. if (maxBytesToRead <= 0)
  6969. return 0;
  6970. return source->read (destBuffer, maxBytesToRead);
  6971. }
  6972. }
  6973. bool SubregionStream::isExhausted()
  6974. {
  6975. if (lengthOfSourceStream >= 0)
  6976. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  6977. else
  6978. return source->isExhausted();
  6979. }
  6980. END_JUCE_NAMESPACE
  6981. /*** End of inlined file: juce_SubregionStream.cpp ***/
  6982. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  6983. BEGIN_JUCE_NAMESPACE
  6984. PerformanceCounter::PerformanceCounter (const String& name_,
  6985. int runsPerPrintout,
  6986. const File& loggingFile)
  6987. : name (name_),
  6988. numRuns (0),
  6989. runsPerPrint (runsPerPrintout),
  6990. totalTime (0),
  6991. outputFile (loggingFile)
  6992. {
  6993. if (outputFile != File::nonexistent)
  6994. {
  6995. String s ("**** Counter for \"");
  6996. s << name_ << "\" started at: "
  6997. << Time::getCurrentTime().toString (true, true)
  6998. << "\r\n";
  6999. outputFile.appendText (s, false, false);
  7000. }
  7001. }
  7002. PerformanceCounter::~PerformanceCounter()
  7003. {
  7004. printStatistics();
  7005. }
  7006. void PerformanceCounter::start()
  7007. {
  7008. started = Time::getHighResolutionTicks();
  7009. }
  7010. void PerformanceCounter::stop()
  7011. {
  7012. const int64 now = Time::getHighResolutionTicks();
  7013. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7014. if (++numRuns == runsPerPrint)
  7015. printStatistics();
  7016. }
  7017. void PerformanceCounter::printStatistics()
  7018. {
  7019. if (numRuns > 0)
  7020. {
  7021. String s ("Performance count for \"");
  7022. s << name << "\" - average over " << numRuns << " run(s) = ";
  7023. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7024. if (micros > 10000)
  7025. s << (micros/1000) << " millisecs";
  7026. else
  7027. s << micros << " microsecs";
  7028. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7029. Logger::outputDebugString (s);
  7030. s << "\r\n";
  7031. if (outputFile != File::nonexistent)
  7032. outputFile.appendText (s, false, false);
  7033. numRuns = 0;
  7034. totalTime = 0;
  7035. }
  7036. }
  7037. END_JUCE_NAMESPACE
  7038. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7039. /*** Start of inlined file: juce_Uuid.cpp ***/
  7040. BEGIN_JUCE_NAMESPACE
  7041. Uuid::Uuid()
  7042. {
  7043. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7044. // to make it very very unlikely that two UUIDs will ever be the same..
  7045. static int64 macAddresses[2];
  7046. static bool hasCheckedMacAddresses = false;
  7047. if (! hasCheckedMacAddresses)
  7048. {
  7049. hasCheckedMacAddresses = true;
  7050. SystemStats::getMACAddresses (macAddresses, 2);
  7051. }
  7052. value.asInt64[0] = macAddresses[0];
  7053. value.asInt64[1] = macAddresses[1];
  7054. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7055. // whose seed will carry over between calls to this method.
  7056. Random r (macAddresses[0] ^ macAddresses[1]
  7057. ^ Random::getSystemRandom().nextInt64());
  7058. for (int i = 4; --i >= 0;)
  7059. {
  7060. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7061. value.asInt[i] ^= r.nextInt();
  7062. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7063. }
  7064. }
  7065. Uuid::~Uuid() throw()
  7066. {
  7067. }
  7068. Uuid::Uuid (const Uuid& other)
  7069. : value (other.value)
  7070. {
  7071. }
  7072. Uuid& Uuid::operator= (const Uuid& other)
  7073. {
  7074. value = other.value;
  7075. return *this;
  7076. }
  7077. bool Uuid::operator== (const Uuid& other) const
  7078. {
  7079. return value.asInt64[0] == other.value.asInt64[0]
  7080. && value.asInt64[1] == other.value.asInt64[1];
  7081. }
  7082. bool Uuid::operator!= (const Uuid& other) const
  7083. {
  7084. return ! operator== (other);
  7085. }
  7086. bool Uuid::isNull() const throw()
  7087. {
  7088. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7089. }
  7090. const String Uuid::toString() const
  7091. {
  7092. return String::toHexString (value.asBytes, sizeof (value.asBytes), 0);
  7093. }
  7094. Uuid::Uuid (const String& uuidString)
  7095. {
  7096. operator= (uuidString);
  7097. }
  7098. Uuid& Uuid::operator= (const String& uuidString)
  7099. {
  7100. MemoryBlock mb;
  7101. mb.loadFromHexString (uuidString);
  7102. mb.ensureSize (sizeof (value.asBytes), true);
  7103. mb.copyTo (value.asBytes, 0, sizeof (value.asBytes));
  7104. return *this;
  7105. }
  7106. Uuid::Uuid (const uint8* const rawData)
  7107. {
  7108. operator= (rawData);
  7109. }
  7110. Uuid& Uuid::operator= (const uint8* const rawData)
  7111. {
  7112. if (rawData != 0)
  7113. memcpy (value.asBytes, rawData, sizeof (value.asBytes));
  7114. else
  7115. zeromem (value.asBytes, sizeof (value.asBytes));
  7116. return *this;
  7117. }
  7118. END_JUCE_NAMESPACE
  7119. /*** End of inlined file: juce_Uuid.cpp ***/
  7120. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7121. BEGIN_JUCE_NAMESPACE
  7122. class ZipFile::ZipEntryInfo
  7123. {
  7124. public:
  7125. ZipFile::ZipEntry entry;
  7126. int streamOffset;
  7127. int compressedSize;
  7128. bool compressed;
  7129. };
  7130. class ZipFile::ZipInputStream : public InputStream
  7131. {
  7132. public:
  7133. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7134. : file (file_),
  7135. zipEntryInfo (zei),
  7136. pos (0),
  7137. headerSize (0),
  7138. inputStream (0)
  7139. {
  7140. inputStream = file_.inputStream;
  7141. if (file_.inputSource != 0)
  7142. {
  7143. inputStream = file.inputSource->createInputStream();
  7144. }
  7145. else
  7146. {
  7147. #ifdef JUCE_DEBUG
  7148. file_.numOpenStreams++;
  7149. #endif
  7150. }
  7151. char buffer [30];
  7152. if (inputStream != 0
  7153. && inputStream->setPosition (zei.streamOffset)
  7154. && inputStream->read (buffer, 30) == 30
  7155. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7156. {
  7157. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7158. + ByteOrder::littleEndianShort (buffer + 28);
  7159. }
  7160. }
  7161. ~ZipInputStream() throw()
  7162. {
  7163. #ifdef JUCE_DEBUG
  7164. if (inputStream != 0 && inputStream == file.inputStream)
  7165. file.numOpenStreams--;
  7166. #endif
  7167. if (inputStream != file.inputStream)
  7168. delete inputStream;
  7169. }
  7170. int64 getTotalLength() throw()
  7171. {
  7172. return zipEntryInfo.compressedSize;
  7173. }
  7174. int read (void* buffer, int howMany) throw()
  7175. {
  7176. if (headerSize <= 0)
  7177. return 0;
  7178. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7179. if (inputStream == 0)
  7180. return 0;
  7181. int num;
  7182. if (inputStream == file.inputStream)
  7183. {
  7184. const ScopedLock sl (file.lock);
  7185. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7186. num = inputStream->read (buffer, howMany);
  7187. }
  7188. else
  7189. {
  7190. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7191. num = inputStream->read (buffer, howMany);
  7192. }
  7193. pos += num;
  7194. return num;
  7195. }
  7196. bool isExhausted() throw()
  7197. {
  7198. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7199. }
  7200. int64 getPosition() throw()
  7201. {
  7202. return pos;
  7203. }
  7204. bool setPosition (int64 newPos) throw()
  7205. {
  7206. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7207. return true;
  7208. }
  7209. private:
  7210. ZipFile& file;
  7211. ZipEntryInfo zipEntryInfo;
  7212. int64 pos;
  7213. int headerSize;
  7214. InputStream* inputStream;
  7215. ZipInputStream (const ZipInputStream&);
  7216. ZipInputStream& operator= (const ZipInputStream&);
  7217. };
  7218. ZipFile::ZipFile (InputStream* const source_,
  7219. const bool deleteStreamWhenDestroyed) throw()
  7220. : inputStream (source_)
  7221. #ifdef JUCE_DEBUG
  7222. , numOpenStreams (0)
  7223. #endif
  7224. {
  7225. if (deleteStreamWhenDestroyed)
  7226. streamToDelete = inputStream;
  7227. init();
  7228. }
  7229. ZipFile::ZipFile (const File& file)
  7230. : inputStream (0)
  7231. #ifdef JUCE_DEBUG
  7232. , numOpenStreams (0)
  7233. #endif
  7234. {
  7235. inputSource = new FileInputSource (file);
  7236. init();
  7237. }
  7238. ZipFile::ZipFile (InputSource* const inputSource_)
  7239. : inputStream (0),
  7240. inputSource (inputSource_)
  7241. #ifdef JUCE_DEBUG
  7242. , numOpenStreams (0)
  7243. #endif
  7244. {
  7245. init();
  7246. }
  7247. ZipFile::~ZipFile() throw()
  7248. {
  7249. #ifdef JUCE_DEBUG
  7250. entries.clear();
  7251. // If you hit this assertion, it means you've created a stream to read
  7252. // one of the items in the zipfile, but you've forgotten to delete that
  7253. // stream object before deleting the file.. Streams can't be kept open
  7254. // after the file is deleted because they need to share the input
  7255. // stream that the file uses to read itself.
  7256. jassert (numOpenStreams == 0);
  7257. #endif
  7258. }
  7259. int ZipFile::getNumEntries() const throw()
  7260. {
  7261. return entries.size();
  7262. }
  7263. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7264. {
  7265. ZipEntryInfo* const zei = entries [index];
  7266. return zei != 0 ? &(zei->entry) : 0;
  7267. }
  7268. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7269. {
  7270. for (int i = 0; i < entries.size(); ++i)
  7271. if (entries.getUnchecked (i)->entry.filename == fileName)
  7272. return i;
  7273. return -1;
  7274. }
  7275. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7276. {
  7277. return getEntry (getIndexOfFileName (fileName));
  7278. }
  7279. InputStream* ZipFile::createStreamForEntry (const int index)
  7280. {
  7281. ZipEntryInfo* const zei = entries[index];
  7282. InputStream* stream = 0;
  7283. if (zei != 0)
  7284. {
  7285. stream = new ZipInputStream (*this, *zei);
  7286. if (zei->compressed)
  7287. {
  7288. stream = new GZIPDecompressorInputStream (stream, true, true,
  7289. zei->entry.uncompressedSize);
  7290. // (much faster to unzip in big blocks using a buffer..)
  7291. stream = new BufferedInputStream (stream, 32768, true);
  7292. }
  7293. }
  7294. return stream;
  7295. }
  7296. class ZipFile::ZipFilenameComparator
  7297. {
  7298. public:
  7299. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7300. {
  7301. return first->entry.filename.compare (second->entry.filename);
  7302. }
  7303. };
  7304. void ZipFile::sortEntriesByFilename()
  7305. {
  7306. ZipFilenameComparator sorter;
  7307. entries.sort (sorter);
  7308. }
  7309. void ZipFile::init()
  7310. {
  7311. ScopedPointer <InputStream> toDelete;
  7312. InputStream* in = inputStream;
  7313. if (inputSource != 0)
  7314. {
  7315. in = inputSource->createInputStream();
  7316. toDelete = in;
  7317. }
  7318. if (in != 0)
  7319. {
  7320. int numEntries = 0;
  7321. int pos = findEndOfZipEntryTable (in, numEntries);
  7322. if (pos >= 0 && pos < in->getTotalLength())
  7323. {
  7324. const int size = (int) (in->getTotalLength() - pos);
  7325. in->setPosition (pos);
  7326. MemoryBlock headerData;
  7327. if (in->readIntoMemoryBlock (headerData, size) == size)
  7328. {
  7329. pos = 0;
  7330. for (int i = 0; i < numEntries; ++i)
  7331. {
  7332. if (pos + 46 > size)
  7333. break;
  7334. const char* const buffer = static_cast <const char*> (headerData.getData()) + pos;
  7335. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7336. if (pos + 46 + fileNameLen > size)
  7337. break;
  7338. ZipEntryInfo* const zei = new ZipEntryInfo();
  7339. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7340. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7341. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7342. const int year = 1980 + (date >> 9);
  7343. const int month = ((date >> 5) & 15) - 1;
  7344. const int day = date & 31;
  7345. const int hours = time >> 11;
  7346. const int minutes = (time >> 5) & 63;
  7347. const int seconds = (time & 31) << 1;
  7348. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7349. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7350. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7351. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7352. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7353. entries.add (zei);
  7354. pos += 46 + fileNameLen
  7355. + ByteOrder::littleEndianShort (buffer + 30)
  7356. + ByteOrder::littleEndianShort (buffer + 32);
  7357. }
  7358. }
  7359. }
  7360. }
  7361. }
  7362. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7363. {
  7364. BufferedInputStream in (input, 8192, false);
  7365. in.setPosition (in.getTotalLength());
  7366. int64 pos = in.getPosition();
  7367. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7368. char buffer [32];
  7369. zeromem (buffer, sizeof (buffer));
  7370. while (pos > lowestPos)
  7371. {
  7372. in.setPosition (pos - 22);
  7373. pos = in.getPosition();
  7374. memcpy (buffer + 22, buffer, 4);
  7375. if (in.read (buffer, 22) != 22)
  7376. return 0;
  7377. for (int i = 0; i < 22; ++i)
  7378. {
  7379. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7380. {
  7381. in.setPosition (pos + i);
  7382. in.read (buffer, 22);
  7383. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7384. return ByteOrder::littleEndianInt (buffer + 16);
  7385. }
  7386. }
  7387. }
  7388. return 0;
  7389. }
  7390. void ZipFile::uncompressTo (const File& targetDirectory,
  7391. const bool shouldOverwriteFiles)
  7392. {
  7393. for (int i = 0; i < entries.size(); ++i)
  7394. {
  7395. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7396. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7397. if (zei.filename.endsWithChar ('/'))
  7398. {
  7399. targetFile.createDirectory(); // (entry is a directory, not a file)
  7400. }
  7401. else
  7402. {
  7403. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7404. if (in != 0)
  7405. {
  7406. if (shouldOverwriteFiles)
  7407. targetFile.deleteFile();
  7408. if ((! targetFile.exists())
  7409. && targetFile.getParentDirectory().createDirectory())
  7410. {
  7411. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7412. if (out != 0)
  7413. {
  7414. out->writeFromInputStream (*in, -1);
  7415. out = 0;
  7416. targetFile.setCreationTime (zei.fileTime);
  7417. targetFile.setLastModificationTime (zei.fileTime);
  7418. targetFile.setLastAccessTime (zei.fileTime);
  7419. }
  7420. }
  7421. }
  7422. }
  7423. }
  7424. }
  7425. END_JUCE_NAMESPACE
  7426. /*** End of inlined file: juce_ZipFile.cpp ***/
  7427. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7428. #ifdef _MSC_VER
  7429. #pragma warning (disable: 4514 4996)
  7430. #pragma warning (push)
  7431. #endif
  7432. #include <cwctype>
  7433. #include <cctype>
  7434. #include <ctime>
  7435. #ifdef _MSC_VER
  7436. #pragma warning (pop)
  7437. #endif
  7438. BEGIN_JUCE_NAMESPACE
  7439. int CharacterFunctions::length (const char* const s) throw()
  7440. {
  7441. return (int) strlen (s);
  7442. }
  7443. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7444. {
  7445. return (int) wcslen (s);
  7446. }
  7447. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7448. {
  7449. strncpy (dest, src, maxChars);
  7450. }
  7451. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7452. {
  7453. wcsncpy (dest, src, maxChars);
  7454. }
  7455. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7456. {
  7457. mbstowcs (dest, src, maxChars);
  7458. }
  7459. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7460. {
  7461. wcstombs (dest, src, maxChars);
  7462. }
  7463. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7464. {
  7465. return (int) wcstombs (0, src, 0);
  7466. }
  7467. void CharacterFunctions::append (char* dest, const char* src) throw()
  7468. {
  7469. strcat (dest, src);
  7470. }
  7471. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7472. {
  7473. wcscat (dest, src);
  7474. }
  7475. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7476. {
  7477. return strcmp (s1, s2);
  7478. }
  7479. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7480. {
  7481. jassert (s1 != 0 && s2 != 0);
  7482. return wcscmp (s1, s2);
  7483. }
  7484. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7485. {
  7486. jassert (s1 != 0 && s2 != 0);
  7487. return strncmp (s1, s2, maxChars);
  7488. }
  7489. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7490. {
  7491. jassert (s1 != 0 && s2 != 0);
  7492. return wcsncmp (s1, s2, maxChars);
  7493. }
  7494. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7495. {
  7496. jassert (s1 != 0 && s2 != 0);
  7497. for (;;)
  7498. {
  7499. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7500. if (diff != 0)
  7501. return diff;
  7502. else if (*s1 == 0)
  7503. break;
  7504. ++s1;
  7505. ++s2;
  7506. }
  7507. return 0;
  7508. }
  7509. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7510. {
  7511. return -compare (s2, s1);
  7512. }
  7513. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7514. {
  7515. jassert (s1 != 0 && s2 != 0);
  7516. #if JUCE_WIN32
  7517. return stricmp (s1, s2);
  7518. #else
  7519. return strcasecmp (s1, s2);
  7520. #endif
  7521. }
  7522. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7523. {
  7524. jassert (s1 != 0 && s2 != 0);
  7525. #if JUCE_WIN32
  7526. return _wcsicmp (s1, s2);
  7527. #else
  7528. for (;;)
  7529. {
  7530. if (*s1 != *s2)
  7531. {
  7532. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7533. if (diff != 0)
  7534. return diff < 0 ? -1 : 1;
  7535. }
  7536. else if (*s1 == 0)
  7537. break;
  7538. ++s1;
  7539. ++s2;
  7540. }
  7541. return 0;
  7542. #endif
  7543. }
  7544. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const char* s2) throw()
  7545. {
  7546. jassert (s1 != 0 && s2 != 0);
  7547. for (;;)
  7548. {
  7549. if (*s1 != *s2)
  7550. {
  7551. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7552. if (diff != 0)
  7553. return diff < 0 ? -1 : 1;
  7554. }
  7555. else if (*s1 == 0)
  7556. break;
  7557. ++s1;
  7558. ++s2;
  7559. }
  7560. return 0;
  7561. }
  7562. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7563. {
  7564. jassert (s1 != 0 && s2 != 0);
  7565. #if JUCE_WIN32
  7566. return strnicmp (s1, s2, maxChars);
  7567. #else
  7568. return strncasecmp (s1, s2, maxChars);
  7569. #endif
  7570. }
  7571. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7572. {
  7573. jassert (s1 != 0 && s2 != 0);
  7574. #if JUCE_WIN32
  7575. return _wcsnicmp (s1, s2, maxChars);
  7576. #else
  7577. while (--maxChars >= 0)
  7578. {
  7579. if (*s1 != *s2)
  7580. {
  7581. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7582. if (diff != 0)
  7583. return diff < 0 ? -1 : 1;
  7584. }
  7585. else if (*s1 == 0)
  7586. break;
  7587. ++s1;
  7588. ++s2;
  7589. }
  7590. return 0;
  7591. #endif
  7592. }
  7593. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7594. {
  7595. return strstr (haystack, needle);
  7596. }
  7597. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7598. {
  7599. return wcsstr (haystack, needle);
  7600. }
  7601. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7602. {
  7603. if (haystack != 0)
  7604. {
  7605. int i = 0;
  7606. if (ignoreCase)
  7607. {
  7608. const char n1 = toLowerCase (needle);
  7609. const char n2 = toUpperCase (needle);
  7610. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7611. {
  7612. while (haystack[i] != 0)
  7613. {
  7614. if (haystack[i] == n1 || haystack[i] == n2)
  7615. return i;
  7616. ++i;
  7617. }
  7618. return -1;
  7619. }
  7620. jassert (n1 == needle);
  7621. }
  7622. while (haystack[i] != 0)
  7623. {
  7624. if (haystack[i] == needle)
  7625. return i;
  7626. ++i;
  7627. }
  7628. }
  7629. return -1;
  7630. }
  7631. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7632. {
  7633. if (haystack != 0)
  7634. {
  7635. int i = 0;
  7636. if (ignoreCase)
  7637. {
  7638. const juce_wchar n1 = toLowerCase (needle);
  7639. const juce_wchar n2 = toUpperCase (needle);
  7640. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7641. {
  7642. while (haystack[i] != 0)
  7643. {
  7644. if (haystack[i] == n1 || haystack[i] == n2)
  7645. return i;
  7646. ++i;
  7647. }
  7648. return -1;
  7649. }
  7650. jassert (n1 == needle);
  7651. }
  7652. while (haystack[i] != 0)
  7653. {
  7654. if (haystack[i] == needle)
  7655. return i;
  7656. ++i;
  7657. }
  7658. }
  7659. return -1;
  7660. }
  7661. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7662. {
  7663. jassert (haystack != 0);
  7664. int i = 0;
  7665. while (haystack[i] != 0)
  7666. {
  7667. if (haystack[i] == needle)
  7668. return i;
  7669. ++i;
  7670. }
  7671. return -1;
  7672. }
  7673. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7674. {
  7675. jassert (haystack != 0);
  7676. int i = 0;
  7677. while (haystack[i] != 0)
  7678. {
  7679. if (haystack[i] == needle)
  7680. return i;
  7681. ++i;
  7682. }
  7683. return -1;
  7684. }
  7685. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7686. {
  7687. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7688. }
  7689. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7690. {
  7691. if (allowedChars == 0)
  7692. return 0;
  7693. int i = 0;
  7694. for (;;)
  7695. {
  7696. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7697. break;
  7698. ++i;
  7699. }
  7700. return i;
  7701. }
  7702. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7703. {
  7704. return (int) strftime (dest, maxChars, format, tm);
  7705. }
  7706. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7707. {
  7708. return (int) wcsftime (dest, maxChars, format, tm);
  7709. }
  7710. int CharacterFunctions::getIntValue (const char* const s) throw()
  7711. {
  7712. return atoi (s);
  7713. }
  7714. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7715. {
  7716. #if JUCE_WIN32
  7717. return _wtoi (s);
  7718. #else
  7719. int v = 0;
  7720. while (isWhitespace (*s))
  7721. ++s;
  7722. const bool isNeg = *s == '-';
  7723. if (isNeg)
  7724. ++s;
  7725. for (;;)
  7726. {
  7727. const wchar_t c = *s++;
  7728. if (c >= '0' && c <= '9')
  7729. v = v * 10 + (int) (c - '0');
  7730. else
  7731. break;
  7732. }
  7733. return isNeg ? -v : v;
  7734. #endif
  7735. }
  7736. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7737. {
  7738. #if JUCE_LINUX
  7739. return atoll (s);
  7740. #elif defined (JUCE_WIN32)
  7741. return _atoi64 (s);
  7742. #else
  7743. int64 v = 0;
  7744. while (isWhitespace (*s))
  7745. ++s;
  7746. const bool isNeg = *s == '-';
  7747. if (isNeg)
  7748. ++s;
  7749. for (;;)
  7750. {
  7751. const char c = *s++;
  7752. if (c >= '0' && c <= '9')
  7753. v = v * 10 + (int64) (c - '0');
  7754. else
  7755. break;
  7756. }
  7757. return isNeg ? -v : v;
  7758. #endif
  7759. }
  7760. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7761. {
  7762. #if JUCE_WIN32
  7763. return _wtoi64 (s);
  7764. #else
  7765. int64 v = 0;
  7766. while (isWhitespace (*s))
  7767. ++s;
  7768. const bool isNeg = *s == '-';
  7769. if (isNeg)
  7770. ++s;
  7771. for (;;)
  7772. {
  7773. const juce_wchar c = *s++;
  7774. if (c >= '0' && c <= '9')
  7775. v = v * 10 + (int64) (c - '0');
  7776. else
  7777. break;
  7778. }
  7779. return isNeg ? -v : v;
  7780. #endif
  7781. }
  7782. static double juce_mulexp10 (const double value, int exponent) throw()
  7783. {
  7784. if (exponent == 0)
  7785. return value;
  7786. if (value == 0)
  7787. return 0;
  7788. const bool negative = (exponent < 0);
  7789. if (negative)
  7790. exponent = -exponent;
  7791. double result = 1.0, power = 10.0;
  7792. for (int bit = 1; exponent != 0; bit <<= 1)
  7793. {
  7794. if ((exponent & bit) != 0)
  7795. {
  7796. exponent ^= bit;
  7797. result *= power;
  7798. if (exponent == 0)
  7799. break;
  7800. }
  7801. power *= power;
  7802. }
  7803. return negative ? (value / result) : (value * result);
  7804. }
  7805. template <class CharType>
  7806. double juce_atof (const CharType* const original) throw()
  7807. {
  7808. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  7809. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  7810. int exponent = 0, decPointIndex = 0, digit = 0;
  7811. int lastDigit = 0, numSignificantDigits = 0;
  7812. bool isNegative = false, digitsFound = false;
  7813. const int maxSignificantDigits = 15 + 2;
  7814. const CharType* s = original;
  7815. while (CharacterFunctions::isWhitespace (*s))
  7816. ++s;
  7817. switch (*s)
  7818. {
  7819. case '-': isNegative = true; // fall-through..
  7820. case '+': ++s;
  7821. }
  7822. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  7823. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  7824. for (;;)
  7825. {
  7826. if (CharacterFunctions::isDigit (*s))
  7827. {
  7828. lastDigit = digit;
  7829. digit = *s++ - '0';
  7830. digitsFound = true;
  7831. if (decPointIndex != 0)
  7832. exponentAdjustment[1]++;
  7833. if (numSignificantDigits == 0 && digit == 0)
  7834. continue;
  7835. if (++numSignificantDigits > maxSignificantDigits)
  7836. {
  7837. if (digit > 5)
  7838. ++accumulator [decPointIndex];
  7839. else if (digit == 5 && (lastDigit & 1) != 0)
  7840. ++accumulator [decPointIndex];
  7841. if (decPointIndex > 0)
  7842. exponentAdjustment[1]--;
  7843. else
  7844. exponentAdjustment[0]++;
  7845. while (CharacterFunctions::isDigit (*s))
  7846. {
  7847. ++s;
  7848. if (decPointIndex == 0)
  7849. exponentAdjustment[0]++;
  7850. }
  7851. }
  7852. else
  7853. {
  7854. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  7855. if (accumulator [decPointIndex] > maxAccumulatorValue)
  7856. {
  7857. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  7858. + accumulator [decPointIndex];
  7859. accumulator [decPointIndex] = 0;
  7860. exponentAccumulator [decPointIndex] = 0;
  7861. }
  7862. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  7863. exponentAccumulator [decPointIndex]++;
  7864. }
  7865. }
  7866. else if (decPointIndex == 0 && *s == '.')
  7867. {
  7868. ++s;
  7869. decPointIndex = 1;
  7870. if (numSignificantDigits > maxSignificantDigits)
  7871. {
  7872. while (CharacterFunctions::isDigit (*s))
  7873. ++s;
  7874. break;
  7875. }
  7876. }
  7877. else
  7878. {
  7879. break;
  7880. }
  7881. }
  7882. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  7883. if (decPointIndex != 0)
  7884. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  7885. if ((*s == 'e' || *s == 'E') && digitsFound)
  7886. {
  7887. bool negativeExponent = false;
  7888. switch (*++s)
  7889. {
  7890. case '-': negativeExponent = true; // fall-through..
  7891. case '+': ++s;
  7892. }
  7893. while (CharacterFunctions::isDigit (*s))
  7894. exponent = (exponent * 10) + (*s++ - '0');
  7895. if (negativeExponent)
  7896. exponent = -exponent;
  7897. }
  7898. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  7899. if (decPointIndex != 0)
  7900. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  7901. return isNegative ? -r : r;
  7902. }
  7903. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  7904. {
  7905. return juce_atof <char> (s);
  7906. }
  7907. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  7908. {
  7909. return juce_atof <juce_wchar> (s);
  7910. }
  7911. char CharacterFunctions::toUpperCase (const char character) throw()
  7912. {
  7913. return (char) toupper (character);
  7914. }
  7915. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  7916. {
  7917. return towupper (character);
  7918. }
  7919. void CharacterFunctions::toUpperCase (char* s) throw()
  7920. {
  7921. #if JUCE_WIN32
  7922. strupr (s);
  7923. #else
  7924. while (*s != 0)
  7925. {
  7926. *s = toUpperCase (*s);
  7927. ++s;
  7928. }
  7929. #endif
  7930. }
  7931. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  7932. {
  7933. #if JUCE_WIN32
  7934. _wcsupr (s);
  7935. #else
  7936. while (*s != 0)
  7937. {
  7938. *s = toUpperCase (*s);
  7939. ++s;
  7940. }
  7941. #endif
  7942. }
  7943. bool CharacterFunctions::isUpperCase (const char character) throw()
  7944. {
  7945. return isupper (character) != 0;
  7946. }
  7947. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  7948. {
  7949. #if JUCE_WIN32
  7950. return iswupper (character) != 0;
  7951. #else
  7952. return toLowerCase (character) != character;
  7953. #endif
  7954. }
  7955. char CharacterFunctions::toLowerCase (const char character) throw()
  7956. {
  7957. return (char) tolower (character);
  7958. }
  7959. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  7960. {
  7961. return towlower (character);
  7962. }
  7963. void CharacterFunctions::toLowerCase (char* s) throw()
  7964. {
  7965. #if JUCE_WIN32
  7966. strlwr (s);
  7967. #else
  7968. while (*s != 0)
  7969. {
  7970. *s = toLowerCase (*s);
  7971. ++s;
  7972. }
  7973. #endif
  7974. }
  7975. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  7976. {
  7977. #if JUCE_WIN32
  7978. _wcslwr (s);
  7979. #else
  7980. while (*s != 0)
  7981. {
  7982. *s = toLowerCase (*s);
  7983. ++s;
  7984. }
  7985. #endif
  7986. }
  7987. bool CharacterFunctions::isLowerCase (const char character) throw()
  7988. {
  7989. return islower (character) != 0;
  7990. }
  7991. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  7992. {
  7993. #if JUCE_WIN32
  7994. return iswlower (character) != 0;
  7995. #else
  7996. return toUpperCase (character) != character;
  7997. #endif
  7998. }
  7999. bool CharacterFunctions::isWhitespace (const char character) throw()
  8000. {
  8001. return character == ' ' || (character <= 13 && character >= 9);
  8002. }
  8003. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8004. {
  8005. return iswspace (character) != 0;
  8006. }
  8007. bool CharacterFunctions::isDigit (const char character) throw()
  8008. {
  8009. return (character >= '0' && character <= '9');
  8010. }
  8011. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8012. {
  8013. return iswdigit (character) != 0;
  8014. }
  8015. bool CharacterFunctions::isLetter (const char character) throw()
  8016. {
  8017. return (character >= 'a' && character <= 'z')
  8018. || (character >= 'A' && character <= 'Z');
  8019. }
  8020. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8021. {
  8022. return iswalpha (character) != 0;
  8023. }
  8024. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8025. {
  8026. return (character >= 'a' && character <= 'z')
  8027. || (character >= 'A' && character <= 'Z')
  8028. || (character >= '0' && character <= '9');
  8029. }
  8030. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8031. {
  8032. return iswalnum (character) != 0;
  8033. }
  8034. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8035. {
  8036. if (digit >= '0' && digit <= '9')
  8037. return digit - '0';
  8038. else if (digit >= 'a' && digit <= 'f')
  8039. return digit - ('a' - 10);
  8040. else if (digit >= 'A' && digit <= 'F')
  8041. return digit - ('A' - 10);
  8042. return -1;
  8043. }
  8044. END_JUCE_NAMESPACE
  8045. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8046. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8047. BEGIN_JUCE_NAMESPACE
  8048. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8049. {
  8050. loadFromText (fileContents);
  8051. }
  8052. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8053. {
  8054. loadFromText (fileToLoad.loadFileAsString());
  8055. }
  8056. LocalisedStrings::~LocalisedStrings()
  8057. {
  8058. }
  8059. const String LocalisedStrings::translate (const String& text) const
  8060. {
  8061. return translations.getValue (text, text);
  8062. }
  8063. static int findCloseQuote (const String& text, int startPos)
  8064. {
  8065. juce_wchar lastChar = 0;
  8066. for (;;)
  8067. {
  8068. const juce_wchar c = text [startPos];
  8069. if (c == 0 || (c == '"' && lastChar != '\\'))
  8070. break;
  8071. lastChar = c;
  8072. ++startPos;
  8073. }
  8074. return startPos;
  8075. }
  8076. static const String unescapeString (const String& s)
  8077. {
  8078. return s.replace ("\\\"", "\"")
  8079. .replace ("\\\'", "\'")
  8080. .replace ("\\t", "\t")
  8081. .replace ("\\r", "\r")
  8082. .replace ("\\n", "\n");
  8083. }
  8084. void LocalisedStrings::loadFromText (const String& fileContents)
  8085. {
  8086. StringArray lines;
  8087. lines.addLines (fileContents);
  8088. for (int i = 0; i < lines.size(); ++i)
  8089. {
  8090. String line (lines[i].trim());
  8091. if (line.startsWithChar ('"'))
  8092. {
  8093. int closeQuote = findCloseQuote (line, 1);
  8094. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8095. if (originalText.isNotEmpty())
  8096. {
  8097. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8098. closeQuote = findCloseQuote (line, openingQuote + 1);
  8099. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8100. if (newText.isNotEmpty())
  8101. translations.set (originalText, newText);
  8102. }
  8103. }
  8104. else if (line.startsWithIgnoreCase ("language:"))
  8105. {
  8106. languageName = line.substring (9).trim();
  8107. }
  8108. else if (line.startsWithIgnoreCase ("countries:"))
  8109. {
  8110. countryCodes.addTokens (line.substring (10).trim(), true);
  8111. countryCodes.trim();
  8112. countryCodes.removeEmptyStrings();
  8113. }
  8114. }
  8115. }
  8116. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8117. {
  8118. translations.setIgnoresCase (shouldIgnoreCase);
  8119. }
  8120. static CriticalSection currentMappingsLock;
  8121. static LocalisedStrings* currentMappings = 0;
  8122. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8123. {
  8124. const ScopedLock sl (currentMappingsLock);
  8125. delete currentMappings;
  8126. currentMappings = newTranslations;
  8127. }
  8128. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8129. {
  8130. return currentMappings;
  8131. }
  8132. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8133. {
  8134. const ScopedLock sl (currentMappingsLock);
  8135. if (currentMappings != 0)
  8136. return currentMappings->translate (text);
  8137. return text;
  8138. }
  8139. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8140. {
  8141. return translateWithCurrentMappings (String (text));
  8142. }
  8143. END_JUCE_NAMESPACE
  8144. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8145. /*** Start of inlined file: juce_String.cpp ***/
  8146. #ifdef _MSC_VER
  8147. #pragma warning (push)
  8148. #pragma warning (disable: 4514)
  8149. #endif
  8150. #include <locale>
  8151. #if JUCE_MSVC
  8152. #include <float.h>
  8153. #endif
  8154. BEGIN_JUCE_NAMESPACE
  8155. #ifdef _MSC_VER
  8156. #pragma warning (pop)
  8157. #endif
  8158. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8159. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8160. #endif
  8161. class StringHolder
  8162. {
  8163. public:
  8164. StringHolder()
  8165. : refCount (0x3fffffff), allocatedNumChars (0)
  8166. {
  8167. text[0] = 0;
  8168. }
  8169. static juce_wchar* createUninitialised (const size_t numChars)
  8170. {
  8171. StringHolder* const s = reinterpret_cast <StringHolder*> (new char [sizeof (StringHolder) + numChars * sizeof (juce_wchar)]);
  8172. s->refCount = 0;
  8173. s->allocatedNumChars = numChars;
  8174. return &(s->text[0]);
  8175. }
  8176. static juce_wchar* createCopy (const juce_wchar* const src, const size_t numChars)
  8177. {
  8178. juce_wchar* const dest = createUninitialised (numChars);
  8179. copyChars (dest, src, numChars);
  8180. return dest;
  8181. }
  8182. static juce_wchar* createCopy (const char* const src, const size_t numChars)
  8183. {
  8184. juce_wchar* const dest = createUninitialised (numChars);
  8185. CharacterFunctions::copy (dest, src, numChars);
  8186. dest [numChars] = 0;
  8187. return dest;
  8188. }
  8189. static inline juce_wchar* getEmpty() throw()
  8190. {
  8191. return &(empty.text[0]);
  8192. }
  8193. static void retain (juce_wchar* const text) throw()
  8194. {
  8195. Atomic::increment (bufferFromText (text)->refCount);
  8196. }
  8197. static inline void release (StringHolder* const b) throw()
  8198. {
  8199. if (Atomic::decrementAndReturn (b->refCount) == -1 && b != &empty)
  8200. delete[] reinterpret_cast <char*> (b);
  8201. }
  8202. static void release (juce_wchar* const text) throw()
  8203. {
  8204. release (bufferFromText (text));
  8205. }
  8206. static juce_wchar* makeUnique (juce_wchar* const text)
  8207. {
  8208. StringHolder* const b = bufferFromText (text);
  8209. if (b->refCount <= 0)
  8210. return text;
  8211. juce_wchar* const newText = createCopy (text, b->allocatedNumChars);
  8212. release (b);
  8213. return newText;
  8214. }
  8215. static juce_wchar* makeUniqueWithSize (juce_wchar* const text, size_t numChars)
  8216. {
  8217. StringHolder* const b = bufferFromText (text);
  8218. if (b->refCount <= 0 && b->allocatedNumChars >= numChars)
  8219. return text;
  8220. juce_wchar* const newText = createUninitialised (jmax (b->allocatedNumChars, numChars));
  8221. copyChars (newText, text, b->allocatedNumChars);
  8222. release (b);
  8223. return newText;
  8224. }
  8225. static size_t getAllocatedNumChars (juce_wchar* const text) throw()
  8226. {
  8227. return bufferFromText (text)->allocatedNumChars;
  8228. }
  8229. static void copyChars (juce_wchar* const dest, const juce_wchar* const src, const size_t numChars) throw()
  8230. {
  8231. memcpy (dest, src, numChars * sizeof (juce_wchar));
  8232. dest [numChars] = 0;
  8233. }
  8234. int refCount;
  8235. size_t allocatedNumChars;
  8236. juce_wchar text[1];
  8237. static StringHolder empty;
  8238. private:
  8239. static inline StringHolder* bufferFromText (void* const text) throw()
  8240. {
  8241. // (Can't use offsetof() here because of warnings about this not being a POD)
  8242. return reinterpret_cast <StringHolder*> (static_cast <char*> (text)
  8243. - (reinterpret_cast <size_t> (reinterpret_cast <StringHolder*> (1)->text) - 1));
  8244. }
  8245. };
  8246. StringHolder StringHolder::empty;
  8247. const String String::empty;
  8248. void String::createInternal (const juce_wchar* const t, const size_t numChars)
  8249. {
  8250. jassert (t[numChars] == 0); // must have a null terminator
  8251. text = StringHolder::createCopy (t, numChars);
  8252. }
  8253. void String::appendInternal (const juce_wchar* const newText, const int numExtraChars)
  8254. {
  8255. if (numExtraChars > 0)
  8256. {
  8257. const int oldLen = length();
  8258. const int newTotalLen = oldLen + numExtraChars;
  8259. text = StringHolder::makeUniqueWithSize (text, newTotalLen);
  8260. StringHolder::copyChars (text + oldLen, newText, numExtraChars);
  8261. }
  8262. }
  8263. void String::preallocateStorage (const size_t numChars)
  8264. {
  8265. text = StringHolder::makeUniqueWithSize (text, numChars);
  8266. }
  8267. String::String() throw()
  8268. : text (StringHolder::getEmpty())
  8269. {
  8270. }
  8271. String::~String() throw()
  8272. {
  8273. StringHolder::release (text);
  8274. }
  8275. String::String (const String& other) throw()
  8276. : text (other.text)
  8277. {
  8278. StringHolder::retain (text);
  8279. }
  8280. void String::swapWith (String& other) throw()
  8281. {
  8282. swapVariables (text, other.text);
  8283. }
  8284. String& String::operator= (const String& other) throw()
  8285. {
  8286. juce_wchar* const newText = other.text;
  8287. StringHolder::retain (newText);
  8288. StringHolder::release (static_cast <juce_wchar*> (Atomic::swapPointers ((void* volatile*) &text, newText)));
  8289. return *this;
  8290. }
  8291. String::String (const size_t numChars, const int /*dummyVariable*/)
  8292. : text (StringHolder::createUninitialised (numChars))
  8293. {
  8294. }
  8295. String::String (const String& stringToCopy, const size_t charsToAllocate)
  8296. {
  8297. const size_t otherSize = StringHolder::getAllocatedNumChars (stringToCopy.text);
  8298. text = StringHolder::createUninitialised (jmax (charsToAllocate, otherSize));
  8299. StringHolder::copyChars (text, stringToCopy.text, otherSize);
  8300. }
  8301. String::String (const char* const t)
  8302. {
  8303. if (t != 0 && *t != 0)
  8304. text = StringHolder::createCopy (t, CharacterFunctions::length (t));
  8305. else
  8306. text = StringHolder::getEmpty();
  8307. }
  8308. String::String (const juce_wchar* const t)
  8309. {
  8310. if (t != 0 && *t != 0)
  8311. text = StringHolder::createCopy (t, CharacterFunctions::length (t));
  8312. else
  8313. text = StringHolder::getEmpty();
  8314. }
  8315. String::String (const char* const t, const size_t maxChars)
  8316. {
  8317. int i;
  8318. for (i = 0; (size_t) i < maxChars; ++i)
  8319. if (t[i] == 0)
  8320. break;
  8321. if (i > 0)
  8322. text = StringHolder::createCopy (t, i);
  8323. else
  8324. text = StringHolder::getEmpty();
  8325. }
  8326. String::String (const juce_wchar* const t, const size_t maxChars)
  8327. {
  8328. int i;
  8329. for (i = 0; (size_t) i < maxChars; ++i)
  8330. if (t[i] == 0)
  8331. break;
  8332. if (i > 0)
  8333. text = StringHolder::createCopy (t, i);
  8334. else
  8335. text = StringHolder::getEmpty();
  8336. }
  8337. const String String::charToString (const juce_wchar character)
  8338. {
  8339. String result ((size_t) 1, (int) 0);
  8340. result.text[0] = character;
  8341. result.text[1] = 0;
  8342. return result;
  8343. }
  8344. namespace NumberToStringConverters
  8345. {
  8346. // pass in a pointer to the END of a buffer..
  8347. static juce_wchar* int64ToString (juce_wchar* t, const int64 n) throw()
  8348. {
  8349. *--t = 0;
  8350. int64 v = (n >= 0) ? n : -n;
  8351. do
  8352. {
  8353. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8354. v /= 10;
  8355. } while (v > 0);
  8356. if (n < 0)
  8357. *--t = '-';
  8358. return t;
  8359. }
  8360. static juce_wchar* uint64ToString (juce_wchar* t, int64 v) throw()
  8361. {
  8362. *--t = 0;
  8363. do
  8364. {
  8365. *--t = (juce_wchar) ('0' + (int) (v % 10));
  8366. v /= 10;
  8367. } while (v > 0);
  8368. return t;
  8369. }
  8370. static juce_wchar* intToString (juce_wchar* t, const int n) throw()
  8371. {
  8372. if (n == (int) 0x80000000) // (would cause an overflow)
  8373. return int64ToString (t, n);
  8374. *--t = 0;
  8375. int v = abs (n);
  8376. do
  8377. {
  8378. *--t = (juce_wchar) ('0' + (v % 10));
  8379. v /= 10;
  8380. } while (v > 0);
  8381. if (n < 0)
  8382. *--t = '-';
  8383. return t;
  8384. }
  8385. static juce_wchar* uintToString (juce_wchar* t, unsigned int v) throw()
  8386. {
  8387. *--t = 0;
  8388. do
  8389. {
  8390. *--t = (juce_wchar) ('0' + (v % 10));
  8391. v /= 10;
  8392. } while (v > 0);
  8393. return t;
  8394. }
  8395. static juce_wchar getDecimalPoint()
  8396. {
  8397. #if JUCE_WINDOWS && _MSC_VER < 1400
  8398. static juce_wchar dp = std::_USE (std::locale(), std::numpunct <wchar_t>).decimal_point();
  8399. #else
  8400. static juce_wchar dp = std::use_facet <std::numpunct <wchar_t> > (std::locale()).decimal_point();
  8401. #endif
  8402. return dp;
  8403. }
  8404. static juce_wchar* doubleToString (juce_wchar* buffer, int numChars, double n, int numDecPlaces, size_t& len) throw()
  8405. {
  8406. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8407. {
  8408. juce_wchar* const end = buffer + numChars;
  8409. juce_wchar* t = end;
  8410. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8411. *--t = (juce_wchar) 0;
  8412. while (numDecPlaces >= 0 || v > 0)
  8413. {
  8414. if (numDecPlaces == 0)
  8415. *--t = getDecimalPoint();
  8416. *--t = (juce_wchar) ('0' + (v % 10));
  8417. v /= 10;
  8418. --numDecPlaces;
  8419. }
  8420. if (n < 0)
  8421. *--t = '-';
  8422. len = end - t - 1;
  8423. return t;
  8424. }
  8425. else
  8426. {
  8427. #if JUCE_WIN32
  8428. #if _MSC_VER <= 1400
  8429. len = _snwprintf (buffer, numChars, L"%.9g", n);
  8430. #else
  8431. len = _snwprintf_s (buffer, numChars, _TRUNCATE, L"%.9g", n);
  8432. #endif
  8433. #else
  8434. len = swprintf (buffer, numChars, L"%.9g", n);
  8435. #endif
  8436. return buffer;
  8437. }
  8438. }
  8439. }
  8440. String::String (const int number)
  8441. {
  8442. juce_wchar buffer [16];
  8443. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8444. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8445. createInternal (start, end - start - 1);
  8446. }
  8447. String::String (const unsigned int number)
  8448. {
  8449. juce_wchar buffer [16];
  8450. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8451. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8452. createInternal (start, end - start - 1);
  8453. }
  8454. String::String (const short number)
  8455. {
  8456. juce_wchar buffer [16];
  8457. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8458. juce_wchar* const start = NumberToStringConverters::intToString (end, (int) number);
  8459. createInternal (start, end - start - 1);
  8460. }
  8461. String::String (const unsigned short number)
  8462. {
  8463. juce_wchar buffer [16];
  8464. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8465. juce_wchar* const start = NumberToStringConverters::uintToString (end, (unsigned int) number);
  8466. createInternal (start, end - start - 1);
  8467. }
  8468. String::String (const int64 number)
  8469. {
  8470. juce_wchar buffer [32];
  8471. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8472. juce_wchar* const start = NumberToStringConverters::int64ToString (end, number);
  8473. createInternal (start, end - start - 1);
  8474. }
  8475. String::String (const uint64 number)
  8476. {
  8477. juce_wchar buffer [32];
  8478. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8479. juce_wchar* const start = NumberToStringConverters::uint64ToString (end, number);
  8480. createInternal (start, end - start - 1);
  8481. }
  8482. String::String (const float number, const int numberOfDecimalPlaces)
  8483. {
  8484. juce_wchar buffer [48];
  8485. size_t len;
  8486. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), (double) number, numberOfDecimalPlaces, len);
  8487. createInternal (start, len);
  8488. }
  8489. String::String (const double number, const int numberOfDecimalPlaces)
  8490. {
  8491. juce_wchar buffer [48];
  8492. size_t len;
  8493. juce_wchar* start = NumberToStringConverters::doubleToString (buffer, numElementsInArray (buffer), number, numberOfDecimalPlaces, len);
  8494. createInternal (start, len);
  8495. }
  8496. int String::length() const throw()
  8497. {
  8498. return CharacterFunctions::length (text);
  8499. }
  8500. int String::hashCode() const throw()
  8501. {
  8502. const juce_wchar* t = text;
  8503. int result = 0;
  8504. while (*t != (juce_wchar) 0)
  8505. result = 31 * result + *t++;
  8506. return result;
  8507. }
  8508. int64 String::hashCode64() const throw()
  8509. {
  8510. const juce_wchar* t = text;
  8511. int64 result = 0;
  8512. while (*t != (juce_wchar) 0)
  8513. result = 101 * result + *t++;
  8514. return result;
  8515. }
  8516. bool JUCE_CALLTYPE operator== (const String& string1, const String& string2) throw()
  8517. {
  8518. return string1.compare (string2) == 0;
  8519. }
  8520. bool JUCE_CALLTYPE operator== (const String& string1, const char* string2) throw()
  8521. {
  8522. return string1.compare (string2) == 0;
  8523. }
  8524. bool JUCE_CALLTYPE operator== (const String& string1, const juce_wchar* string2) throw()
  8525. {
  8526. return string1.compare (string2) == 0;
  8527. }
  8528. bool JUCE_CALLTYPE operator!= (const String& string1, const String& string2) throw()
  8529. {
  8530. return string1.compare (string2) != 0;
  8531. }
  8532. bool JUCE_CALLTYPE operator!= (const String& string1, const char* string2) throw()
  8533. {
  8534. return string1.compare (string2) != 0;
  8535. }
  8536. bool JUCE_CALLTYPE operator!= (const String& string1, const juce_wchar* string2) throw()
  8537. {
  8538. return string1.compare (string2) != 0;
  8539. }
  8540. bool JUCE_CALLTYPE operator> (const String& string1, const String& string2) throw()
  8541. {
  8542. return string1.compare (string2) > 0;
  8543. }
  8544. bool JUCE_CALLTYPE operator< (const String& string1, const String& string2) throw()
  8545. {
  8546. return string1.compare (string2) < 0;
  8547. }
  8548. bool JUCE_CALLTYPE operator>= (const String& string1, const String& string2) throw()
  8549. {
  8550. return string1.compare (string2) >= 0;
  8551. }
  8552. bool JUCE_CALLTYPE operator<= (const String& string1, const String& string2) throw()
  8553. {
  8554. return string1.compare (string2) <= 0;
  8555. }
  8556. bool String::equalsIgnoreCase (const juce_wchar* t) const throw()
  8557. {
  8558. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8559. : isEmpty();
  8560. }
  8561. bool String::equalsIgnoreCase (const char* t) const throw()
  8562. {
  8563. return t != 0 ? CharacterFunctions::compareIgnoreCase (text, t) == 0
  8564. : isEmpty();
  8565. }
  8566. bool String::equalsIgnoreCase (const String& other) const throw()
  8567. {
  8568. return text == other.text
  8569. || CharacterFunctions::compareIgnoreCase (text, other.text) == 0;
  8570. }
  8571. int String::compare (const String& other) const throw()
  8572. {
  8573. return (text == other.text) ? 0 : CharacterFunctions::compare (text, other.text);
  8574. }
  8575. int String::compare (const char* other) const throw()
  8576. {
  8577. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8578. }
  8579. int String::compare (const juce_wchar* other) const throw()
  8580. {
  8581. return other == 0 ? isEmpty() : CharacterFunctions::compare (text, other);
  8582. }
  8583. int String::compareIgnoreCase (const String& other) const throw()
  8584. {
  8585. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text, other.text);
  8586. }
  8587. int String::compareLexicographically (const String& other) const throw()
  8588. {
  8589. const juce_wchar* s1 = text;
  8590. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8591. ++s1;
  8592. const juce_wchar* s2 = other.text;
  8593. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8594. ++s2;
  8595. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8596. }
  8597. String& String::operator+= (const juce_wchar* const t)
  8598. {
  8599. if (t != 0)
  8600. appendInternal (t, CharacterFunctions::length (t));
  8601. return *this;
  8602. }
  8603. String& String::operator+= (const String& other)
  8604. {
  8605. if (isEmpty())
  8606. operator= (other);
  8607. else
  8608. appendInternal (other.text, other.length());
  8609. return *this;
  8610. }
  8611. String& String::operator+= (const char ch)
  8612. {
  8613. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8614. return operator+= (static_cast <const juce_wchar*> (asString));
  8615. }
  8616. String& String::operator+= (const juce_wchar ch)
  8617. {
  8618. const juce_wchar asString[] = { (juce_wchar) ch, 0 };
  8619. return operator+= (static_cast <const juce_wchar*> (asString));
  8620. }
  8621. String& String::operator+= (const int number)
  8622. {
  8623. juce_wchar buffer [16];
  8624. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8625. juce_wchar* const start = NumberToStringConverters::intToString (end, number);
  8626. appendInternal (start, (int) (end - start));
  8627. return *this;
  8628. }
  8629. String& String::operator+= (const unsigned int number)
  8630. {
  8631. juce_wchar buffer [16];
  8632. juce_wchar* const end = buffer + numElementsInArray (buffer);
  8633. juce_wchar* const start = NumberToStringConverters::uintToString (end, number);
  8634. appendInternal (start, (int) (end - start));
  8635. return *this;
  8636. }
  8637. void String::append (const juce_wchar* const other, const int howMany)
  8638. {
  8639. if (howMany > 0)
  8640. {
  8641. int i;
  8642. for (i = 0; i < howMany; ++i)
  8643. if (other[i] == 0)
  8644. break;
  8645. appendInternal (other, i);
  8646. }
  8647. }
  8648. const String JUCE_CALLTYPE operator+ (const char* const string1, const String& string2)
  8649. {
  8650. String s (string1);
  8651. return s += string2;
  8652. }
  8653. const String JUCE_CALLTYPE operator+ (const juce_wchar* const string1, const String& string2)
  8654. {
  8655. String s (string1);
  8656. return s += string2;
  8657. }
  8658. const String JUCE_CALLTYPE operator+ (const char string1, const String& string2)
  8659. {
  8660. return String::charToString (string1) + string2;
  8661. }
  8662. const String JUCE_CALLTYPE operator+ (const juce_wchar string1, const String& string2)
  8663. {
  8664. return String::charToString (string1) + string2;
  8665. }
  8666. const String JUCE_CALLTYPE operator+ (String string1, const String& string2)
  8667. {
  8668. return string1 += string2;
  8669. }
  8670. const String JUCE_CALLTYPE operator+ (String string1, const char* const string2)
  8671. {
  8672. return string1 += string2;
  8673. }
  8674. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar* const string2)
  8675. {
  8676. return string1 += string2;
  8677. }
  8678. const String JUCE_CALLTYPE operator+ (String string1, const char string2)
  8679. {
  8680. return string1 += string2;
  8681. }
  8682. const String JUCE_CALLTYPE operator+ (String string1, const juce_wchar string2)
  8683. {
  8684. return string1 += string2;
  8685. }
  8686. String& JUCE_CALLTYPE operator<< (String& string1, const char characterToAppend)
  8687. {
  8688. return string1 += characterToAppend;
  8689. }
  8690. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar characterToAppend)
  8691. {
  8692. return string1 += characterToAppend;
  8693. }
  8694. String& JUCE_CALLTYPE operator<< (String& string1, const char* const string2)
  8695. {
  8696. return string1 += string2;
  8697. }
  8698. String& JUCE_CALLTYPE operator<< (String& string1, const juce_wchar* const string2)
  8699. {
  8700. return string1 += string2;
  8701. }
  8702. String& JUCE_CALLTYPE operator<< (String& string1, const String& string2)
  8703. {
  8704. return string1 += string2;
  8705. }
  8706. String& JUCE_CALLTYPE operator<< (String& string1, const short number)
  8707. {
  8708. return string1 += (int) number;
  8709. }
  8710. String& JUCE_CALLTYPE operator<< (String& string1, const int number)
  8711. {
  8712. return string1 += number;
  8713. }
  8714. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned int number)
  8715. {
  8716. return string1 += number;
  8717. }
  8718. String& JUCE_CALLTYPE operator<< (String& string1, const long number)
  8719. {
  8720. return string1 += (int) number;
  8721. }
  8722. String& JUCE_CALLTYPE operator<< (String& string1, const unsigned long number)
  8723. {
  8724. return string1 += (unsigned int) number;
  8725. }
  8726. String& JUCE_CALLTYPE operator<< (String& string1, const float number)
  8727. {
  8728. return string1 += String (number);
  8729. }
  8730. String& JUCE_CALLTYPE operator<< (String& string1, const double number)
  8731. {
  8732. return string1 += String (number);
  8733. }
  8734. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const String& text)
  8735. {
  8736. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8737. // if lots of large, persistent strings were to be written to streams).
  8738. const int numBytes = text.getNumBytesAsUTF8();
  8739. HeapBlock<char> temp (numBytes + 1);
  8740. text.copyToUTF8 (temp, numBytes + 1);
  8741. stream.write (temp, numBytes);
  8742. return stream;
  8743. }
  8744. int String::indexOfChar (const juce_wchar character) const throw()
  8745. {
  8746. const juce_wchar* t = text;
  8747. for (;;)
  8748. {
  8749. if (*t == character)
  8750. return (int) (t - text);
  8751. if (*t++ == 0)
  8752. return -1;
  8753. }
  8754. }
  8755. int String::lastIndexOfChar (const juce_wchar character) const throw()
  8756. {
  8757. for (int i = length(); --i >= 0;)
  8758. if (text[i] == character)
  8759. return i;
  8760. return -1;
  8761. }
  8762. int String::indexOf (const String& t) const throw()
  8763. {
  8764. const juce_wchar* const r = CharacterFunctions::find (text, t.text);
  8765. return r == 0 ? -1 : (int) (r - text);
  8766. }
  8767. int String::indexOfChar (const int startIndex,
  8768. const juce_wchar character) const throw()
  8769. {
  8770. if (startIndex > 0 && startIndex >= length())
  8771. return -1;
  8772. const juce_wchar* t = text + jmax (0, startIndex);
  8773. for (;;)
  8774. {
  8775. if (*t == character)
  8776. return (int) (t - text);
  8777. if (*t == 0)
  8778. return -1;
  8779. ++t;
  8780. }
  8781. }
  8782. int String::indexOfAnyOf (const String& charactersToLookFor,
  8783. const int startIndex,
  8784. const bool ignoreCase) const throw()
  8785. {
  8786. if (startIndex > 0 && startIndex >= length())
  8787. return -1;
  8788. const juce_wchar* t = text + jmax (0, startIndex);
  8789. while (*t != 0)
  8790. {
  8791. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, *t, ignoreCase) >= 0)
  8792. return (int) (t - text);
  8793. ++t;
  8794. }
  8795. return -1;
  8796. }
  8797. int String::indexOf (const int startIndex, const String& other) const throw()
  8798. {
  8799. if (startIndex > 0 && startIndex >= length())
  8800. return -1;
  8801. const juce_wchar* const found = CharacterFunctions::find (text + jmax (0, startIndex), other.text);
  8802. return found == 0 ? -1 : (int) (found - text);
  8803. }
  8804. int String::indexOfIgnoreCase (const String& other) const throw()
  8805. {
  8806. if (other.isNotEmpty())
  8807. {
  8808. const int len = other.length();
  8809. const int end = length() - len;
  8810. for (int i = 0; i <= end; ++i)
  8811. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8812. return i;
  8813. }
  8814. return -1;
  8815. }
  8816. int String::indexOfIgnoreCase (const int startIndex, const String& other) const throw()
  8817. {
  8818. if (other.isNotEmpty())
  8819. {
  8820. const int len = other.length();
  8821. const int end = length() - len;
  8822. for (int i = jmax (0, startIndex); i <= end; ++i)
  8823. if (CharacterFunctions::compareIgnoreCase (text + i, other.text, len) == 0)
  8824. return i;
  8825. }
  8826. return -1;
  8827. }
  8828. int String::lastIndexOf (const String& other) const throw()
  8829. {
  8830. if (other.isNotEmpty())
  8831. {
  8832. const int len = other.length();
  8833. int i = length() - len;
  8834. if (i >= 0)
  8835. {
  8836. const juce_wchar* n = text + i;
  8837. while (i >= 0)
  8838. {
  8839. if (CharacterFunctions::compare (n--, other.text, len) == 0)
  8840. return i;
  8841. --i;
  8842. }
  8843. }
  8844. }
  8845. return -1;
  8846. }
  8847. int String::lastIndexOfIgnoreCase (const String& other) const throw()
  8848. {
  8849. if (other.isNotEmpty())
  8850. {
  8851. const int len = other.length();
  8852. int i = length() - len;
  8853. if (i >= 0)
  8854. {
  8855. const juce_wchar* n = text + i;
  8856. while (i >= 0)
  8857. {
  8858. if (CharacterFunctions::compareIgnoreCase (n--, other.text, len) == 0)
  8859. return i;
  8860. --i;
  8861. }
  8862. }
  8863. }
  8864. return -1;
  8865. }
  8866. int String::lastIndexOfAnyOf (const String& charactersToLookFor, const bool ignoreCase) const throw()
  8867. {
  8868. for (int i = length(); --i >= 0;)
  8869. if (CharacterFunctions::indexOfChar (charactersToLookFor.text, text[i], ignoreCase) >= 0)
  8870. return i;
  8871. return -1;
  8872. }
  8873. bool String::contains (const String& other) const throw()
  8874. {
  8875. return indexOf (other) >= 0;
  8876. }
  8877. bool String::containsChar (const juce_wchar character) const throw()
  8878. {
  8879. const juce_wchar* t = text;
  8880. for (;;)
  8881. {
  8882. if (*t == 0)
  8883. return false;
  8884. if (*t == character)
  8885. return true;
  8886. ++t;
  8887. }
  8888. }
  8889. bool String::containsIgnoreCase (const String& t) const throw()
  8890. {
  8891. return indexOfIgnoreCase (t) >= 0;
  8892. }
  8893. int String::indexOfWholeWord (const String& word) const throw()
  8894. {
  8895. if (word.isNotEmpty())
  8896. {
  8897. const int wordLen = word.length();
  8898. const int end = length() - wordLen;
  8899. const juce_wchar* t = text;
  8900. for (int i = 0; i <= end; ++i)
  8901. {
  8902. if (CharacterFunctions::compare (t, word.text, wordLen) == 0
  8903. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8904. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8905. {
  8906. return i;
  8907. }
  8908. ++t;
  8909. }
  8910. }
  8911. return -1;
  8912. }
  8913. int String::indexOfWholeWordIgnoreCase (const String& word) const throw()
  8914. {
  8915. if (word.isNotEmpty())
  8916. {
  8917. const int wordLen = word.length();
  8918. const int end = length() - wordLen;
  8919. const juce_wchar* t = text;
  8920. for (int i = 0; i <= end; ++i)
  8921. {
  8922. if (CharacterFunctions::compareIgnoreCase (t, word.text, wordLen) == 0
  8923. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  8924. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  8925. {
  8926. return i;
  8927. }
  8928. ++t;
  8929. }
  8930. }
  8931. return -1;
  8932. }
  8933. bool String::containsWholeWord (const String& wordToLookFor) const throw()
  8934. {
  8935. return indexOfWholeWord (wordToLookFor) >= 0;
  8936. }
  8937. bool String::containsWholeWordIgnoreCase (const String& wordToLookFor) const throw()
  8938. {
  8939. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  8940. }
  8941. static int indexOfMatch (const juce_wchar* const wildcard,
  8942. const juce_wchar* const test,
  8943. const bool ignoreCase) throw()
  8944. {
  8945. int start = 0;
  8946. while (test [start] != 0)
  8947. {
  8948. int i = 0;
  8949. for (;;)
  8950. {
  8951. const juce_wchar wc = wildcard [i];
  8952. const juce_wchar c = test [i + start];
  8953. if (wc == c
  8954. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  8955. || (wc == '?' && c != 0))
  8956. {
  8957. if (wc == 0)
  8958. return start;
  8959. ++i;
  8960. }
  8961. else
  8962. {
  8963. if (wc == '*' && (wildcard [i + 1] == 0
  8964. || indexOfMatch (wildcard + i + 1,
  8965. test + start + i,
  8966. ignoreCase) >= 0))
  8967. {
  8968. return start;
  8969. }
  8970. break;
  8971. }
  8972. }
  8973. ++start;
  8974. }
  8975. return -1;
  8976. }
  8977. bool String::matchesWildcard (const String& wildcard, const bool ignoreCase) const throw()
  8978. {
  8979. int i = 0;
  8980. for (;;)
  8981. {
  8982. const juce_wchar wc = wildcard.text [i];
  8983. const juce_wchar c = text [i];
  8984. if (wc == c
  8985. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  8986. || (wc == '?' && c != 0))
  8987. {
  8988. if (wc == 0)
  8989. return true;
  8990. ++i;
  8991. }
  8992. else
  8993. {
  8994. return wc == '*' && (wildcard [i + 1] == 0
  8995. || indexOfMatch (wildcard.text + i + 1,
  8996. text + i,
  8997. ignoreCase) >= 0);
  8998. }
  8999. }
  9000. }
  9001. const String String::repeatedString (const String& stringToRepeat, int numberOfTimesToRepeat)
  9002. {
  9003. const int len = stringToRepeat.length();
  9004. String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
  9005. juce_wchar* n = result.text;
  9006. *n = 0;
  9007. while (--numberOfTimesToRepeat >= 0)
  9008. {
  9009. StringHolder::copyChars (n, stringToRepeat.text, len);
  9010. n += len;
  9011. }
  9012. return result;
  9013. }
  9014. const String String::paddedLeft (const juce_wchar padCharacter, int minimumLength) const
  9015. {
  9016. jassert (padCharacter != 0);
  9017. const int len = length();
  9018. if (len >= minimumLength || padCharacter == 0)
  9019. return *this;
  9020. String result ((size_t) minimumLength + 1, (int) 0);
  9021. juce_wchar* n = result.text;
  9022. minimumLength -= len;
  9023. while (--minimumLength >= 0)
  9024. *n++ = padCharacter;
  9025. StringHolder::copyChars (n, text, len);
  9026. return result;
  9027. }
  9028. const String String::paddedRight (const juce_wchar padCharacter, int minimumLength) const
  9029. {
  9030. jassert (padCharacter != 0);
  9031. const int len = length();
  9032. if (len >= minimumLength || padCharacter == 0)
  9033. return *this;
  9034. String result (*this, (size_t) minimumLength);
  9035. juce_wchar* n = result.text + len;
  9036. minimumLength -= len;
  9037. while (--minimumLength >= 0)
  9038. *n++ = padCharacter;
  9039. *n = 0;
  9040. return result;
  9041. }
  9042. const String String::replaceSection (int index, int numCharsToReplace, const String& stringToInsert) const
  9043. {
  9044. if (index < 0)
  9045. {
  9046. // a negative index to replace from?
  9047. jassertfalse
  9048. index = 0;
  9049. }
  9050. if (numCharsToReplace < 0)
  9051. {
  9052. // replacing a negative number of characters?
  9053. numCharsToReplace = 0;
  9054. jassertfalse;
  9055. }
  9056. const int len = length();
  9057. if (index + numCharsToReplace > len)
  9058. {
  9059. if (index > len)
  9060. {
  9061. // replacing beyond the end of the string?
  9062. index = len;
  9063. jassertfalse
  9064. }
  9065. numCharsToReplace = len - index;
  9066. }
  9067. const int newStringLen = stringToInsert.length();
  9068. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9069. if (newTotalLen <= 0)
  9070. return String::empty;
  9071. String result ((size_t) newTotalLen, (int) 0);
  9072. StringHolder::copyChars (result.text, text, index);
  9073. if (newStringLen > 0)
  9074. StringHolder::copyChars (result.text + index, stringToInsert.text, newStringLen);
  9075. const int endStringLen = newTotalLen - (index + newStringLen);
  9076. if (endStringLen > 0)
  9077. StringHolder::copyChars (result.text + (index + newStringLen),
  9078. text + (index + numCharsToReplace),
  9079. endStringLen);
  9080. return result;
  9081. }
  9082. const String String::replace (const String& stringToReplace, const String& stringToInsert, const bool ignoreCase) const
  9083. {
  9084. const int stringToReplaceLen = stringToReplace.length();
  9085. const int stringToInsertLen = stringToInsert.length();
  9086. int i = 0;
  9087. String result (*this);
  9088. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9089. : result.indexOf (i, stringToReplace))) >= 0)
  9090. {
  9091. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9092. i += stringToInsertLen;
  9093. }
  9094. return result;
  9095. }
  9096. const String String::replaceCharacter (const juce_wchar charToReplace, const juce_wchar charToInsert) const
  9097. {
  9098. const int index = indexOfChar (charToReplace);
  9099. if (index < 0)
  9100. return *this;
  9101. String result (*this, size_t());
  9102. juce_wchar* t = result.text + index;
  9103. while (*t != 0)
  9104. {
  9105. if (*t == charToReplace)
  9106. *t = charToInsert;
  9107. ++t;
  9108. }
  9109. return result;
  9110. }
  9111. const String String::replaceCharacters (const String& charactersToReplace,
  9112. const String& charactersToInsertInstead) const
  9113. {
  9114. String result (*this, size_t());
  9115. juce_wchar* t = result.text;
  9116. const int len2 = charactersToInsertInstead.length();
  9117. // the two strings passed in are supposed to be the same length!
  9118. jassert (len2 == charactersToReplace.length());
  9119. while (*t != 0)
  9120. {
  9121. const int index = charactersToReplace.indexOfChar (*t);
  9122. if (((unsigned int) index) < (unsigned int) len2)
  9123. *t = charactersToInsertInstead [index];
  9124. ++t;
  9125. }
  9126. return result;
  9127. }
  9128. bool String::startsWith (const String& other) const throw()
  9129. {
  9130. return CharacterFunctions::compare (text, other.text, other.length()) == 0;
  9131. }
  9132. bool String::startsWithIgnoreCase (const String& other) const throw()
  9133. {
  9134. return CharacterFunctions::compareIgnoreCase (text, other.text, other.length()) == 0;
  9135. }
  9136. bool String::startsWithChar (const juce_wchar character) const throw()
  9137. {
  9138. jassert (character != 0); // strings can't contain a null character!
  9139. return text[0] == character;
  9140. }
  9141. bool String::endsWithChar (const juce_wchar character) const throw()
  9142. {
  9143. jassert (character != 0); // strings can't contain a null character!
  9144. return text[0] != 0
  9145. && text [length() - 1] == character;
  9146. }
  9147. bool String::endsWith (const String& other) const throw()
  9148. {
  9149. const int thisLen = length();
  9150. const int otherLen = other.length();
  9151. return thisLen >= otherLen
  9152. && CharacterFunctions::compare (text + thisLen - otherLen, other.text) == 0;
  9153. }
  9154. bool String::endsWithIgnoreCase (const String& other) const throw()
  9155. {
  9156. const int thisLen = length();
  9157. const int otherLen = other.length();
  9158. return thisLen >= otherLen
  9159. && CharacterFunctions::compareIgnoreCase (text + thisLen - otherLen, other.text) == 0;
  9160. }
  9161. const String String::toUpperCase() const
  9162. {
  9163. String result (*this, size_t());
  9164. CharacterFunctions::toUpperCase (result.text);
  9165. return result;
  9166. }
  9167. const String String::toLowerCase() const
  9168. {
  9169. String result (*this, size_t());
  9170. CharacterFunctions::toLowerCase (result.text);
  9171. return result;
  9172. }
  9173. juce_wchar& String::operator[] (const int index)
  9174. {
  9175. jassert (((unsigned int) index) <= (unsigned int) length());
  9176. text = StringHolder::makeUnique (text);
  9177. return text [index];
  9178. }
  9179. juce_wchar String::getLastCharacter() const throw()
  9180. {
  9181. return isEmpty() ? juce_wchar() : text [length() - 1];
  9182. }
  9183. const String String::substring (int start, int end) const
  9184. {
  9185. if (start < 0)
  9186. start = 0;
  9187. else if (end <= start)
  9188. return empty;
  9189. int len = 0;
  9190. while (len <= end && text [len] != 0)
  9191. ++len;
  9192. if (end >= len)
  9193. {
  9194. if (start == 0)
  9195. return *this;
  9196. end = len;
  9197. }
  9198. return String (text + start, end - start);
  9199. }
  9200. const String String::substring (const int start) const
  9201. {
  9202. if (start <= 0)
  9203. return *this;
  9204. const int len = length();
  9205. if (start >= len)
  9206. return empty;
  9207. return String (text + start, len - start);
  9208. }
  9209. const String String::dropLastCharacters (const int numberToDrop) const
  9210. {
  9211. return String (text, jmax (0, length() - numberToDrop));
  9212. }
  9213. const String String::getLastCharacters (const int numCharacters) const
  9214. {
  9215. return String (text + jmax (0, length() - jmax (0, numCharacters)));
  9216. }
  9217. const String String::fromFirstOccurrenceOf (const String& sub,
  9218. const bool includeSubString,
  9219. const bool ignoreCase) const
  9220. {
  9221. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9222. : indexOf (sub);
  9223. if (i < 0)
  9224. return empty;
  9225. return substring (includeSubString ? i : i + sub.length());
  9226. }
  9227. const String String::fromLastOccurrenceOf (const String& sub,
  9228. const bool includeSubString,
  9229. const bool ignoreCase) const
  9230. {
  9231. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9232. : lastIndexOf (sub);
  9233. if (i < 0)
  9234. return *this;
  9235. return substring (includeSubString ? i : i + sub.length());
  9236. }
  9237. const String String::upToFirstOccurrenceOf (const String& sub,
  9238. const bool includeSubString,
  9239. const bool ignoreCase) const
  9240. {
  9241. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9242. : indexOf (sub);
  9243. if (i < 0)
  9244. return *this;
  9245. return substring (0, includeSubString ? i + sub.length() : i);
  9246. }
  9247. const String String::upToLastOccurrenceOf (const String& sub,
  9248. const bool includeSubString,
  9249. const bool ignoreCase) const
  9250. {
  9251. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9252. : lastIndexOf (sub);
  9253. if (i < 0)
  9254. return *this;
  9255. return substring (0, includeSubString ? i + sub.length() : i);
  9256. }
  9257. bool String::isQuotedString() const
  9258. {
  9259. const String trimmed (trimStart());
  9260. return trimmed[0] == '"'
  9261. || trimmed[0] == '\'';
  9262. }
  9263. const String String::unquoted() const
  9264. {
  9265. String s (*this);
  9266. if (s.text[0] == '"' || s.text[0] == '\'')
  9267. s = s.substring (1);
  9268. const int lastCharIndex = s.length() - 1;
  9269. if (lastCharIndex >= 0
  9270. && (s [lastCharIndex] == '"' || s[lastCharIndex] == '\''))
  9271. s [lastCharIndex] = 0;
  9272. return s;
  9273. }
  9274. const String String::quoted (const juce_wchar quoteCharacter) const
  9275. {
  9276. if (isEmpty())
  9277. return charToString (quoteCharacter) + quoteCharacter;
  9278. String t (*this);
  9279. if (! t.startsWithChar (quoteCharacter))
  9280. t = charToString (quoteCharacter) + t;
  9281. if (! t.endsWithChar (quoteCharacter))
  9282. t += quoteCharacter;
  9283. return t;
  9284. }
  9285. const String String::trim() const
  9286. {
  9287. if (isEmpty())
  9288. return empty;
  9289. int start = 0;
  9290. while (CharacterFunctions::isWhitespace (text [start]))
  9291. ++start;
  9292. const int len = length();
  9293. int end = len - 1;
  9294. while ((end >= start) && CharacterFunctions::isWhitespace (text [end]))
  9295. --end;
  9296. ++end;
  9297. if (end <= start)
  9298. return empty;
  9299. else if (start > 0 || end < len)
  9300. return String (text + start, end - start);
  9301. return *this;
  9302. }
  9303. const String String::trimStart() const
  9304. {
  9305. if (isEmpty())
  9306. return empty;
  9307. const juce_wchar* t = text;
  9308. while (CharacterFunctions::isWhitespace (*t))
  9309. ++t;
  9310. if (t == text)
  9311. return *this;
  9312. return String (t);
  9313. }
  9314. const String String::trimEnd() const
  9315. {
  9316. if (isEmpty())
  9317. return empty;
  9318. const juce_wchar* endT = text + (length() - 1);
  9319. while ((endT >= text) && CharacterFunctions::isWhitespace (*endT))
  9320. --endT;
  9321. return String (text, (int) (++endT - text));
  9322. }
  9323. const String String::trimCharactersAtStart (const String& charactersToTrim) const
  9324. {
  9325. const juce_wchar* t = text;
  9326. while (charactersToTrim.containsChar (*t))
  9327. ++t;
  9328. if (t == text)
  9329. return *this;
  9330. return String (t);
  9331. }
  9332. const String String::trimCharactersAtEnd (const String& charactersToTrim) const
  9333. {
  9334. if (isEmpty())
  9335. return empty;
  9336. const juce_wchar* endT = text + (length() - 1);
  9337. while (endT >= text && charactersToTrim.containsChar (*endT))
  9338. --endT;
  9339. return String (text, (int) (++endT - text));
  9340. }
  9341. const String String::retainCharacters (const String& charactersToRetain) const
  9342. {
  9343. if (isEmpty())
  9344. return empty;
  9345. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9346. juce_wchar* dst = result.text;
  9347. const juce_wchar* src = text;
  9348. while (*src != 0)
  9349. {
  9350. if (charactersToRetain.containsChar (*src))
  9351. *dst++ = *src;
  9352. ++src;
  9353. }
  9354. *dst = 0;
  9355. return result;
  9356. }
  9357. const String String::removeCharacters (const String& charactersToRemove) const
  9358. {
  9359. if (isEmpty())
  9360. return empty;
  9361. String result (StringHolder::getAllocatedNumChars (text), (int) 0);
  9362. juce_wchar* dst = result.text;
  9363. const juce_wchar* src = text;
  9364. while (*src != 0)
  9365. {
  9366. if (! charactersToRemove.containsChar (*src))
  9367. *dst++ = *src;
  9368. ++src;
  9369. }
  9370. *dst = 0;
  9371. return result;
  9372. }
  9373. const String String::initialSectionContainingOnly (const String& permittedCharacters) const
  9374. {
  9375. int i = 0;
  9376. for (;;)
  9377. {
  9378. if (! permittedCharacters.containsChar (text[i]))
  9379. break;
  9380. ++i;
  9381. }
  9382. return substring (0, i);
  9383. }
  9384. const String String::initialSectionNotContaining (const String& charactersToStopAt) const
  9385. {
  9386. const juce_wchar* const t = text;
  9387. int i = 0;
  9388. while (t[i] != 0)
  9389. {
  9390. if (charactersToStopAt.containsChar (t[i]))
  9391. return String (text, i);
  9392. ++i;
  9393. }
  9394. return empty;
  9395. }
  9396. bool String::containsOnly (const String& chars) const throw()
  9397. {
  9398. const juce_wchar* t = text;
  9399. while (*t != 0)
  9400. if (! chars.containsChar (*t++))
  9401. return false;
  9402. return true;
  9403. }
  9404. bool String::containsAnyOf (const String& chars) const throw()
  9405. {
  9406. const juce_wchar* t = text;
  9407. while (*t != 0)
  9408. if (chars.containsChar (*t++))
  9409. return true;
  9410. return false;
  9411. }
  9412. bool String::containsNonWhitespaceChars() const throw()
  9413. {
  9414. const juce_wchar* t = text;
  9415. while (*t != 0)
  9416. if (! CharacterFunctions::isWhitespace (*t++))
  9417. return true;
  9418. return false;
  9419. }
  9420. const String String::formatted (const juce_wchar* const pf, ... )
  9421. {
  9422. jassert (pf != 0);
  9423. va_list args;
  9424. va_start (args, pf);
  9425. size_t bufferSize = 256;
  9426. String result (bufferSize, (int) 0);
  9427. result.text[0] = 0;
  9428. for (;;)
  9429. {
  9430. #if JUCE_LINUX && JUCE_64BIT
  9431. va_list tempArgs;
  9432. va_copy (tempArgs, args);
  9433. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, tempArgs);
  9434. va_end (tempArgs);
  9435. #elif JUCE_WINDOWS
  9436. #ifdef _MSC_VER
  9437. #pragma warning (push)
  9438. #pragma warning (disable: 4996)
  9439. #endif
  9440. const int num = (int) _vsnwprintf (result.text, bufferSize - 1, pf, args);
  9441. #ifdef _MSC_VER
  9442. #pragma warning (pop)
  9443. #endif
  9444. #else
  9445. const int num = (int) vswprintf (result.text, bufferSize - 1, pf, args);
  9446. #endif
  9447. if (num > 0)
  9448. return result;
  9449. bufferSize += 256;
  9450. if (num == 0 || bufferSize > 65536) // the upper limit is a sanity check to avoid situations where vprintf repeatedly
  9451. break; // returns -1 because of an error rather than because it needs more space.
  9452. result.preallocateStorage (bufferSize);
  9453. }
  9454. return empty;
  9455. }
  9456. int String::getIntValue() const throw()
  9457. {
  9458. return CharacterFunctions::getIntValue (text);
  9459. }
  9460. int String::getTrailingIntValue() const throw()
  9461. {
  9462. int n = 0;
  9463. int mult = 1;
  9464. const juce_wchar* t = text + length();
  9465. while (--t >= text)
  9466. {
  9467. const juce_wchar c = *t;
  9468. if (! CharacterFunctions::isDigit (c))
  9469. {
  9470. if (c == '-')
  9471. n = -n;
  9472. break;
  9473. }
  9474. n += mult * (c - '0');
  9475. mult *= 10;
  9476. }
  9477. return n;
  9478. }
  9479. int64 String::getLargeIntValue() const throw()
  9480. {
  9481. return CharacterFunctions::getInt64Value (text);
  9482. }
  9483. float String::getFloatValue() const throw()
  9484. {
  9485. return (float) CharacterFunctions::getDoubleValue (text);
  9486. }
  9487. double String::getDoubleValue() const throw()
  9488. {
  9489. return CharacterFunctions::getDoubleValue (text);
  9490. }
  9491. static const juce_wchar* const hexDigits = T("0123456789abcdef");
  9492. const String String::toHexString (const int number)
  9493. {
  9494. juce_wchar buffer[32];
  9495. juce_wchar* const end = buffer + 32;
  9496. juce_wchar* t = end;
  9497. *--t = 0;
  9498. unsigned int v = (unsigned int) number;
  9499. do
  9500. {
  9501. *--t = hexDigits [v & 15];
  9502. v >>= 4;
  9503. } while (v != 0);
  9504. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9505. }
  9506. const String String::toHexString (const int64 number)
  9507. {
  9508. juce_wchar buffer[32];
  9509. juce_wchar* const end = buffer + 32;
  9510. juce_wchar* t = end;
  9511. *--t = 0;
  9512. uint64 v = (uint64) number;
  9513. do
  9514. {
  9515. *--t = hexDigits [(int) (v & 15)];
  9516. v >>= 4;
  9517. } while (v != 0);
  9518. return String (t, (int) (((char*) end) - (char*) t));
  9519. }
  9520. const String String::toHexString (const short number)
  9521. {
  9522. return toHexString ((int) (unsigned short) number);
  9523. }
  9524. const String String::toHexString (const unsigned char* data,
  9525. const int size,
  9526. const int groupSize)
  9527. {
  9528. if (size <= 0)
  9529. return empty;
  9530. int numChars = (size * 2) + 2;
  9531. if (groupSize > 0)
  9532. numChars += size / groupSize;
  9533. String s ((size_t) numChars, (int) 0);
  9534. juce_wchar* d = s.text;
  9535. for (int i = 0; i < size; ++i)
  9536. {
  9537. *d++ = hexDigits [(*data) >> 4];
  9538. *d++ = hexDigits [(*data) & 0xf];
  9539. ++data;
  9540. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9541. *d++ = ' ';
  9542. }
  9543. *d = 0;
  9544. return s;
  9545. }
  9546. int String::getHexValue32() const throw()
  9547. {
  9548. int result = 0;
  9549. const juce_wchar* c = text;
  9550. for (;;)
  9551. {
  9552. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9553. if (hexValue >= 0)
  9554. result = (result << 4) | hexValue;
  9555. else if (*c == 0)
  9556. break;
  9557. ++c;
  9558. }
  9559. return result;
  9560. }
  9561. int64 String::getHexValue64() const throw()
  9562. {
  9563. int64 result = 0;
  9564. const juce_wchar* c = text;
  9565. for (;;)
  9566. {
  9567. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9568. if (hexValue >= 0)
  9569. result = (result << 4) | hexValue;
  9570. else if (*c == 0)
  9571. break;
  9572. ++c;
  9573. }
  9574. return result;
  9575. }
  9576. const String String::createStringFromData (const void* const data_, const int size)
  9577. {
  9578. const char* const data = static_cast <const char*> (data_);
  9579. if (size <= 0 || data == 0)
  9580. {
  9581. return empty;
  9582. }
  9583. else if (size < 2)
  9584. {
  9585. return charToString (data[0]);
  9586. }
  9587. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9588. || (data[0] == (char)-1 && data[1] == (char)-2))
  9589. {
  9590. // assume it's 16-bit unicode
  9591. const bool bigEndian = (data[0] == (char)-2);
  9592. const int numChars = size / 2 - 1;
  9593. String result;
  9594. result.preallocateStorage (numChars + 2);
  9595. const uint16* const src = (const uint16*) (data + 2);
  9596. juce_wchar* const dst = const_cast <juce_wchar*> (static_cast <const juce_wchar*> (result));
  9597. if (bigEndian)
  9598. {
  9599. for (int i = 0; i < numChars; ++i)
  9600. dst[i] = (juce_wchar) ByteOrder::swapIfLittleEndian (src[i]);
  9601. }
  9602. else
  9603. {
  9604. for (int i = 0; i < numChars; ++i)
  9605. dst[i] = (juce_wchar) ByteOrder::swapIfBigEndian (src[i]);
  9606. }
  9607. dst [numChars] = 0;
  9608. return result;
  9609. }
  9610. else
  9611. {
  9612. return String::fromUTF8 (data, size);
  9613. }
  9614. }
  9615. const char* String::toUTF8() const
  9616. {
  9617. if (isEmpty())
  9618. {
  9619. return reinterpret_cast <const char*> (text);
  9620. }
  9621. else
  9622. {
  9623. const int currentLen = length() + 1;
  9624. const int utf8BytesNeeded = getNumBytesAsUTF8();
  9625. String* const mutableThis = const_cast <String*> (this);
  9626. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, currentLen + 1 + utf8BytesNeeded / sizeof (juce_wchar));
  9627. char* const otherCopy = reinterpret_cast <char*> (mutableThis->text + currentLen);
  9628. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9629. return otherCopy;
  9630. }
  9631. }
  9632. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9633. {
  9634. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9635. int num = 0, index = 0;
  9636. for (;;)
  9637. {
  9638. const uint32 c = (uint32) text [index++];
  9639. if (c >= 0x80)
  9640. {
  9641. int numExtraBytes = 1;
  9642. if (c >= 0x800)
  9643. {
  9644. ++numExtraBytes;
  9645. if (c >= 0x10000)
  9646. {
  9647. ++numExtraBytes;
  9648. if (c >= 0x200000)
  9649. {
  9650. ++numExtraBytes;
  9651. if (c >= 0x4000000)
  9652. ++numExtraBytes;
  9653. }
  9654. }
  9655. }
  9656. if (buffer != 0)
  9657. {
  9658. if (num + numExtraBytes >= maxBufferSizeBytes)
  9659. {
  9660. buffer [num++] = 0;
  9661. break;
  9662. }
  9663. else
  9664. {
  9665. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9666. while (--numExtraBytes >= 0)
  9667. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9668. }
  9669. }
  9670. else
  9671. {
  9672. num += numExtraBytes + 1;
  9673. }
  9674. }
  9675. else
  9676. {
  9677. if (buffer != 0)
  9678. {
  9679. if (num + 1 >= maxBufferSizeBytes)
  9680. {
  9681. buffer [num++] = 0;
  9682. break;
  9683. }
  9684. buffer [num] = (uint8) c;
  9685. }
  9686. ++num;
  9687. }
  9688. if (c == 0)
  9689. break;
  9690. }
  9691. return num;
  9692. }
  9693. int String::getNumBytesAsUTF8() const throw()
  9694. {
  9695. int num = 0;
  9696. const juce_wchar* t = text;
  9697. for (;;)
  9698. {
  9699. const uint32 c = (uint32) *t;
  9700. if (c >= 0x80)
  9701. {
  9702. ++num;
  9703. if (c >= 0x800)
  9704. {
  9705. ++num;
  9706. if (c >= 0x10000)
  9707. {
  9708. ++num;
  9709. if (c >= 0x200000)
  9710. {
  9711. ++num;
  9712. if (c >= 0x4000000)
  9713. ++num;
  9714. }
  9715. }
  9716. }
  9717. }
  9718. else if (c == 0)
  9719. break;
  9720. ++num;
  9721. ++t;
  9722. }
  9723. return num;
  9724. }
  9725. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9726. {
  9727. if (buffer == 0)
  9728. return empty;
  9729. if (bufferSizeBytes < 0)
  9730. bufferSizeBytes = std::numeric_limits<int>::max();
  9731. size_t numBytes;
  9732. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9733. if (buffer [numBytes] == 0)
  9734. break;
  9735. String result ((size_t) numBytes + 1, (int) 0);
  9736. juce_wchar* dest = result.text;
  9737. size_t i = 0;
  9738. while (i < numBytes)
  9739. {
  9740. const char c = buffer [i++];
  9741. if (c < 0)
  9742. {
  9743. unsigned int mask = 0x7f;
  9744. int bit = 0x40;
  9745. int numExtraValues = 0;
  9746. while (bit != 0 && (c & bit) != 0)
  9747. {
  9748. bit >>= 1;
  9749. mask >>= 1;
  9750. ++numExtraValues;
  9751. }
  9752. int n = (mask & (unsigned char) c);
  9753. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9754. {
  9755. const char nextByte = buffer[i];
  9756. if ((nextByte & 0xc0) != 0x80)
  9757. break;
  9758. n <<= 6;
  9759. n |= (nextByte & 0x3f);
  9760. ++i;
  9761. }
  9762. *dest++ = (juce_wchar) n;
  9763. }
  9764. else
  9765. {
  9766. *dest++ = (juce_wchar) c;
  9767. }
  9768. }
  9769. *dest = 0;
  9770. return result;
  9771. }
  9772. const char* String::toCString() const
  9773. {
  9774. if (isEmpty())
  9775. {
  9776. return reinterpret_cast <const char*> (text);
  9777. }
  9778. else
  9779. {
  9780. const int len = length();
  9781. String* const mutableThis = const_cast <String*> (this);
  9782. mutableThis->text = StringHolder::makeUniqueWithSize (mutableThis->text, (len + 1) * 2);
  9783. char* otherCopy = reinterpret_cast <char*> (mutableThis->text + len + 1);
  9784. CharacterFunctions::copy (otherCopy, text, len);
  9785. otherCopy [len] = 0;
  9786. return otherCopy;
  9787. }
  9788. }
  9789. #ifdef _MSC_VER
  9790. #pragma warning (disable: 4514 4996)
  9791. #pragma warning (push)
  9792. #endif
  9793. int String::getNumBytesAsCString() const throw()
  9794. {
  9795. return (int) wcstombs (0, text, 0);
  9796. }
  9797. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  9798. {
  9799. const int numBytes = (int) wcstombs (destBuffer, text, maxBufferSizeBytes);
  9800. if (destBuffer != 0 && numBytes >= 0)
  9801. destBuffer [numBytes] = 0;
  9802. return numBytes;
  9803. }
  9804. #ifdef _MSC_VER
  9805. #pragma warning (pop)
  9806. #endif
  9807. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  9808. {
  9809. StringHolder::copyChars (destBuffer, text, jmin (maxCharsToCopy, length()));
  9810. }
  9811. String::Concatenator::Concatenator (String& stringToAppendTo)
  9812. : result (stringToAppendTo),
  9813. nextIndex (stringToAppendTo.length())
  9814. {
  9815. }
  9816. String::Concatenator::~Concatenator()
  9817. {
  9818. }
  9819. void String::Concatenator::append (const String& s)
  9820. {
  9821. const int len = s.length();
  9822. if (len > 0)
  9823. {
  9824. result.preallocateStorage (nextIndex + len);
  9825. s.copyToUnicode (static_cast <juce_wchar*> (result) + nextIndex, len);
  9826. nextIndex += len;
  9827. }
  9828. }
  9829. END_JUCE_NAMESPACE
  9830. /*** End of inlined file: juce_String.cpp ***/
  9831. /*** Start of inlined file: juce_StringArray.cpp ***/
  9832. BEGIN_JUCE_NAMESPACE
  9833. StringArray::StringArray() throw()
  9834. {
  9835. }
  9836. StringArray::StringArray (const StringArray& other)
  9837. : strings (other.strings)
  9838. {
  9839. }
  9840. StringArray::StringArray (const String& firstValue)
  9841. {
  9842. strings.add (firstValue);
  9843. }
  9844. StringArray::StringArray (const juce_wchar** const initialStrings,
  9845. const int numberOfStrings)
  9846. {
  9847. for (int i = 0; i < numberOfStrings; ++i)
  9848. strings.add (initialStrings [i]);
  9849. }
  9850. StringArray::StringArray (const char** 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 juce_wchar** const initialStrings)
  9857. {
  9858. int i = 0;
  9859. while (initialStrings[i] != 0)
  9860. strings.add (initialStrings [i++]);
  9861. }
  9862. StringArray::StringArray (const char** const initialStrings)
  9863. {
  9864. int i = 0;
  9865. while (initialStrings[i] != 0)
  9866. strings.add (initialStrings [i++]);
  9867. }
  9868. StringArray& StringArray::operator= (const StringArray& other)
  9869. {
  9870. strings = other.strings;
  9871. return *this;
  9872. }
  9873. StringArray::~StringArray()
  9874. {
  9875. }
  9876. bool StringArray::operator== (const StringArray& other) const throw()
  9877. {
  9878. if (other.size() != size())
  9879. return false;
  9880. for (int i = size(); --i >= 0;)
  9881. if (other.strings.getReference(i) != strings.getReference(i))
  9882. return false;
  9883. return true;
  9884. }
  9885. bool StringArray::operator!= (const StringArray& other) const throw()
  9886. {
  9887. return ! operator== (other);
  9888. }
  9889. void StringArray::clear()
  9890. {
  9891. strings.clear();
  9892. }
  9893. const String& StringArray::operator[] (const int index) const throw()
  9894. {
  9895. if (((unsigned int) index) < (unsigned int) strings.size())
  9896. return strings.getReference (index);
  9897. return String::empty;
  9898. }
  9899. void StringArray::add (const String& newString)
  9900. {
  9901. strings.add (newString);
  9902. }
  9903. void StringArray::insert (const int index, const String& newString)
  9904. {
  9905. strings.insert (index, newString);
  9906. }
  9907. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  9908. {
  9909. if (! contains (newString, ignoreCase))
  9910. add (newString);
  9911. }
  9912. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  9913. {
  9914. if (startIndex < 0)
  9915. {
  9916. jassertfalse
  9917. startIndex = 0;
  9918. }
  9919. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  9920. numElementsToAdd = otherArray.size() - startIndex;
  9921. while (--numElementsToAdd >= 0)
  9922. strings.add (otherArray.strings.getReference (startIndex++));
  9923. }
  9924. void StringArray::set (const int index, const String& newString)
  9925. {
  9926. strings.set (index, newString);
  9927. }
  9928. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  9929. {
  9930. if (ignoreCase)
  9931. {
  9932. for (int i = size(); --i >= 0;)
  9933. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  9934. return true;
  9935. }
  9936. else
  9937. {
  9938. for (int i = size(); --i >= 0;)
  9939. if (stringToLookFor == strings.getReference(i))
  9940. return true;
  9941. }
  9942. return false;
  9943. }
  9944. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  9945. {
  9946. if (i < 0)
  9947. i = 0;
  9948. const int numElements = size();
  9949. if (ignoreCase)
  9950. {
  9951. while (i < numElements)
  9952. {
  9953. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  9954. return i;
  9955. ++i;
  9956. }
  9957. }
  9958. else
  9959. {
  9960. while (i < numElements)
  9961. {
  9962. if (stringToLookFor == strings.getReference (i))
  9963. return i;
  9964. ++i;
  9965. }
  9966. }
  9967. return -1;
  9968. }
  9969. void StringArray::remove (const int index)
  9970. {
  9971. strings.remove (index);
  9972. }
  9973. void StringArray::removeString (const String& stringToRemove,
  9974. const bool ignoreCase)
  9975. {
  9976. if (ignoreCase)
  9977. {
  9978. for (int i = size(); --i >= 0;)
  9979. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  9980. strings.remove (i);
  9981. }
  9982. else
  9983. {
  9984. for (int i = size(); --i >= 0;)
  9985. if (stringToRemove == strings.getReference (i))
  9986. strings.remove (i);
  9987. }
  9988. }
  9989. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  9990. {
  9991. if (removeWhitespaceStrings)
  9992. {
  9993. for (int i = size(); --i >= 0;)
  9994. if (! strings.getReference(i).containsNonWhitespaceChars())
  9995. strings.remove (i);
  9996. }
  9997. else
  9998. {
  9999. for (int i = size(); --i >= 0;)
  10000. if (strings.getReference(i).isEmpty())
  10001. strings.remove (i);
  10002. }
  10003. }
  10004. void StringArray::trim()
  10005. {
  10006. for (int i = size(); --i >= 0;)
  10007. {
  10008. String& s = strings.getReference(i);
  10009. s = s.trim();
  10010. }
  10011. }
  10012. class InternalStringArrayComparator_CaseSensitive
  10013. {
  10014. public:
  10015. static int compareElements (String& first, String& second) { return first.compare (second); }
  10016. };
  10017. class InternalStringArrayComparator_CaseInsensitive
  10018. {
  10019. public:
  10020. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10021. };
  10022. void StringArray::sort (const bool ignoreCase)
  10023. {
  10024. if (ignoreCase)
  10025. {
  10026. InternalStringArrayComparator_CaseInsensitive comp;
  10027. strings.sort (comp);
  10028. }
  10029. else
  10030. {
  10031. InternalStringArrayComparator_CaseSensitive comp;
  10032. strings.sort (comp);
  10033. }
  10034. }
  10035. void StringArray::move (const int currentIndex, int newIndex) throw()
  10036. {
  10037. strings.move (currentIndex, newIndex);
  10038. }
  10039. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10040. {
  10041. const int last = (numberToJoin < 0) ? size()
  10042. : jmin (size(), start + numberToJoin);
  10043. if (start < 0)
  10044. start = 0;
  10045. if (start >= last)
  10046. return String::empty;
  10047. if (start == last - 1)
  10048. return strings.getReference (start);
  10049. const int separatorLen = separator.length();
  10050. int charsNeeded = separatorLen * (last - start - 1);
  10051. for (int i = start; i < last; ++i)
  10052. charsNeeded += strings.getReference(i).length();
  10053. String result;
  10054. result.preallocateStorage (charsNeeded);
  10055. juce_wchar* dest = result;
  10056. while (start < last)
  10057. {
  10058. const String& s = strings.getReference (start);
  10059. const int len = s.length();
  10060. if (len > 0)
  10061. {
  10062. s.copyToUnicode (dest, len);
  10063. dest += len;
  10064. }
  10065. if (++start < last && separatorLen > 0)
  10066. {
  10067. separator.copyToUnicode (dest, separatorLen);
  10068. dest += separatorLen;
  10069. }
  10070. }
  10071. *dest = 0;
  10072. return result;
  10073. }
  10074. int StringArray::addTokens (const String& text, const bool preserveQuotedStrings)
  10075. {
  10076. return addTokens (text, " \n\r\t", preserveQuotedStrings ? "\"" : "");
  10077. }
  10078. int StringArray::addTokens (const String& text, const String& breakCharacters, const String& quoteCharacters)
  10079. {
  10080. int num = 0;
  10081. if (text.isNotEmpty())
  10082. {
  10083. bool insideQuotes = false;
  10084. juce_wchar currentQuoteChar = 0;
  10085. int i = 0;
  10086. int tokenStart = 0;
  10087. for (;;)
  10088. {
  10089. const juce_wchar c = text[i];
  10090. const bool isBreak = (c == 0) || ((! insideQuotes) && breakCharacters.containsChar (c));
  10091. if (! isBreak)
  10092. {
  10093. if (quoteCharacters.containsChar (c))
  10094. {
  10095. if (insideQuotes)
  10096. {
  10097. // only break out of quotes-mode if we find a matching quote to the
  10098. // one that we opened with..
  10099. if (currentQuoteChar == c)
  10100. insideQuotes = false;
  10101. }
  10102. else
  10103. {
  10104. insideQuotes = true;
  10105. currentQuoteChar = c;
  10106. }
  10107. }
  10108. }
  10109. else
  10110. {
  10111. add (String (static_cast <const juce_wchar*> (text) + tokenStart, i - tokenStart));
  10112. ++num;
  10113. tokenStart = i + 1;
  10114. }
  10115. if (c == 0)
  10116. break;
  10117. ++i;
  10118. }
  10119. }
  10120. return num;
  10121. }
  10122. int StringArray::addLines (const String& sourceText)
  10123. {
  10124. int numLines = 0;
  10125. const juce_wchar* text = sourceText;
  10126. while (*text != 0)
  10127. {
  10128. const juce_wchar* const startOfLine = text;
  10129. while (*text != 0)
  10130. {
  10131. if (*text == '\r')
  10132. {
  10133. ++text;
  10134. if (*text == '\n')
  10135. ++text;
  10136. break;
  10137. }
  10138. if (*text == '\n')
  10139. {
  10140. ++text;
  10141. break;
  10142. }
  10143. ++text;
  10144. }
  10145. const juce_wchar* endOfLine = text;
  10146. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10147. --endOfLine;
  10148. if (endOfLine > startOfLine && (*(endOfLine - 1) == '\r' || *(endOfLine - 1) == '\n'))
  10149. --endOfLine;
  10150. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10151. ++numLines;
  10152. }
  10153. return numLines;
  10154. }
  10155. void StringArray::removeDuplicates (const bool ignoreCase)
  10156. {
  10157. for (int i = 0; i < size() - 1; ++i)
  10158. {
  10159. const String s (strings.getReference(i));
  10160. int nextIndex = i + 1;
  10161. for (;;)
  10162. {
  10163. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10164. if (nextIndex < 0)
  10165. break;
  10166. strings.remove (nextIndex);
  10167. }
  10168. }
  10169. }
  10170. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10171. const bool appendNumberToFirstInstance,
  10172. const juce_wchar* preNumberString,
  10173. const juce_wchar* postNumberString)
  10174. {
  10175. if (preNumberString == 0)
  10176. preNumberString = T(" (");
  10177. if (postNumberString == 0)
  10178. postNumberString = T(")");
  10179. for (int i = 0; i < size() - 1; ++i)
  10180. {
  10181. String& s = strings.getReference(i);
  10182. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10183. if (nextIndex >= 0)
  10184. {
  10185. const String original (s);
  10186. int number = 0;
  10187. if (appendNumberToFirstInstance)
  10188. s = original + preNumberString + String (++number) + postNumberString;
  10189. else
  10190. ++number;
  10191. while (nextIndex >= 0)
  10192. {
  10193. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10194. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10195. }
  10196. }
  10197. }
  10198. }
  10199. void StringArray::minimiseStorageOverheads()
  10200. {
  10201. strings.minimiseStorageOverheads();
  10202. }
  10203. END_JUCE_NAMESPACE
  10204. /*** End of inlined file: juce_StringArray.cpp ***/
  10205. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10206. BEGIN_JUCE_NAMESPACE
  10207. StringPairArray::StringPairArray (const bool ignoreCase_)
  10208. : ignoreCase (ignoreCase_)
  10209. {
  10210. }
  10211. StringPairArray::StringPairArray (const StringPairArray& other)
  10212. : keys (other.keys),
  10213. values (other.values),
  10214. ignoreCase (other.ignoreCase)
  10215. {
  10216. }
  10217. StringPairArray::~StringPairArray()
  10218. {
  10219. }
  10220. StringPairArray& StringPairArray::operator= (const StringPairArray& other)
  10221. {
  10222. keys = other.keys;
  10223. values = other.values;
  10224. return *this;
  10225. }
  10226. bool StringPairArray::operator== (const StringPairArray& other) const
  10227. {
  10228. for (int i = keys.size(); --i >= 0;)
  10229. if (other [keys[i]] != values[i])
  10230. return false;
  10231. return true;
  10232. }
  10233. bool StringPairArray::operator!= (const StringPairArray& other) const
  10234. {
  10235. return ! operator== (other);
  10236. }
  10237. const String& StringPairArray::operator[] (const String& key) const
  10238. {
  10239. return values [keys.indexOf (key, ignoreCase)];
  10240. }
  10241. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10242. {
  10243. const int i = keys.indexOf (key, ignoreCase);
  10244. if (i >= 0)
  10245. return values[i];
  10246. return defaultReturnValue;
  10247. }
  10248. void StringPairArray::set (const String& key, const String& value)
  10249. {
  10250. const int i = keys.indexOf (key, ignoreCase);
  10251. if (i >= 0)
  10252. {
  10253. values.set (i, value);
  10254. }
  10255. else
  10256. {
  10257. keys.add (key);
  10258. values.add (value);
  10259. }
  10260. }
  10261. void StringPairArray::addArray (const StringPairArray& other)
  10262. {
  10263. for (int i = 0; i < other.size(); ++i)
  10264. set (other.keys[i], other.values[i]);
  10265. }
  10266. void StringPairArray::clear()
  10267. {
  10268. keys.clear();
  10269. values.clear();
  10270. }
  10271. void StringPairArray::remove (const String& key)
  10272. {
  10273. remove (keys.indexOf (key, ignoreCase));
  10274. }
  10275. void StringPairArray::remove (const int index)
  10276. {
  10277. keys.remove (index);
  10278. values.remove (index);
  10279. }
  10280. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase)
  10281. {
  10282. ignoreCase = shouldIgnoreCase;
  10283. }
  10284. const String StringPairArray::getDescription() const
  10285. {
  10286. String s;
  10287. for (int i = 0; i < keys.size(); ++i)
  10288. {
  10289. s << keys[i] << " = " << values[i];
  10290. if (i < keys.size())
  10291. s << ", ";
  10292. }
  10293. return s;
  10294. }
  10295. void StringPairArray::minimiseStorageOverheads()
  10296. {
  10297. keys.minimiseStorageOverheads();
  10298. values.minimiseStorageOverheads();
  10299. }
  10300. END_JUCE_NAMESPACE
  10301. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10302. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10303. BEGIN_JUCE_NAMESPACE
  10304. XmlDocument::XmlDocument (const String& documentText)
  10305. : originalText (documentText),
  10306. ignoreEmptyTextElements (true)
  10307. {
  10308. }
  10309. XmlDocument::XmlDocument (const File& file)
  10310. : ignoreEmptyTextElements (true)
  10311. {
  10312. inputSource = new FileInputSource (file);
  10313. }
  10314. XmlDocument::~XmlDocument()
  10315. {
  10316. }
  10317. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10318. {
  10319. inputSource = newSource;
  10320. }
  10321. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10322. {
  10323. ignoreEmptyTextElements = shouldBeIgnored;
  10324. }
  10325. bool XmlDocument::isXmlIdentifierCharSlow (const juce_wchar c) throw()
  10326. {
  10327. return CharacterFunctions::isLetterOrDigit (c)
  10328. || c == '_' || c == '-' || c == ':' || c == '.';
  10329. }
  10330. inline bool XmlDocument::isXmlIdentifierChar (const juce_wchar c) const throw()
  10331. {
  10332. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10333. : isXmlIdentifierCharSlow (c);
  10334. }
  10335. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10336. {
  10337. String textToParse (originalText);
  10338. if (textToParse.isEmpty() && inputSource != 0)
  10339. {
  10340. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10341. if (in != 0)
  10342. {
  10343. MemoryBlock data;
  10344. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10345. if (data.getSize() >= 2
  10346. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10347. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10348. {
  10349. textToParse = String::createStringFromData (static_cast <const char*> (data.getData()), (int) data.getSize());
  10350. }
  10351. else
  10352. {
  10353. textToParse = String::fromUTF8 (static_cast <const char*> (data.getData()), (int) data.getSize());
  10354. }
  10355. if (! onlyReadOuterDocumentElement)
  10356. originalText = textToParse;
  10357. }
  10358. }
  10359. input = textToParse;
  10360. lastError = String::empty;
  10361. errorOccurred = false;
  10362. outOfData = false;
  10363. needToLoadDTD = true;
  10364. for (int i = 0; i < 128; ++i)
  10365. identifierLookupTable[i] = isXmlIdentifierCharSlow ((juce_wchar) i);
  10366. if (textToParse.isEmpty())
  10367. {
  10368. lastError = "not enough input";
  10369. }
  10370. else
  10371. {
  10372. skipHeader();
  10373. if (input != 0)
  10374. {
  10375. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10376. if (! errorOccurred)
  10377. return result.release();
  10378. }
  10379. else
  10380. {
  10381. lastError = "incorrect xml header";
  10382. }
  10383. }
  10384. return 0;
  10385. }
  10386. const String& XmlDocument::getLastParseError() const throw()
  10387. {
  10388. return lastError;
  10389. }
  10390. void XmlDocument::setLastError (const String& desc, const bool carryOn)
  10391. {
  10392. lastError = desc;
  10393. errorOccurred = ! carryOn;
  10394. }
  10395. const String XmlDocument::getFileContents (const String& filename) const
  10396. {
  10397. if (inputSource != 0)
  10398. {
  10399. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10400. if (in != 0)
  10401. return in->readEntireStreamAsString();
  10402. }
  10403. return String::empty;
  10404. }
  10405. juce_wchar XmlDocument::readNextChar() throw()
  10406. {
  10407. if (*input != 0)
  10408. {
  10409. return *input++;
  10410. }
  10411. else
  10412. {
  10413. outOfData = true;
  10414. return 0;
  10415. }
  10416. }
  10417. int XmlDocument::findNextTokenLength() throw()
  10418. {
  10419. int len = 0;
  10420. juce_wchar c = *input;
  10421. while (isXmlIdentifierChar (c))
  10422. c = input [++len];
  10423. return len;
  10424. }
  10425. void XmlDocument::skipHeader()
  10426. {
  10427. const juce_wchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10428. if (found != 0)
  10429. {
  10430. input = found;
  10431. input = CharacterFunctions::find (input, T("?>"));
  10432. if (input == 0)
  10433. return;
  10434. input += 2;
  10435. }
  10436. skipNextWhiteSpace();
  10437. const juce_wchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10438. if (docType == 0)
  10439. return;
  10440. input = docType + 9;
  10441. int n = 1;
  10442. while (n > 0)
  10443. {
  10444. const juce_wchar c = readNextChar();
  10445. if (outOfData)
  10446. return;
  10447. if (c == '<')
  10448. ++n;
  10449. else if (c == '>')
  10450. --n;
  10451. }
  10452. docType += 9;
  10453. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10454. }
  10455. void XmlDocument::skipNextWhiteSpace()
  10456. {
  10457. for (;;)
  10458. {
  10459. juce_wchar c = *input;
  10460. while (CharacterFunctions::isWhitespace (c))
  10461. c = *++input;
  10462. if (c == 0)
  10463. {
  10464. outOfData = true;
  10465. break;
  10466. }
  10467. else if (c == '<')
  10468. {
  10469. if (input[1] == '!'
  10470. && input[2] == '-'
  10471. && input[3] == '-')
  10472. {
  10473. const juce_wchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10474. if (closeComment == 0)
  10475. {
  10476. outOfData = true;
  10477. break;
  10478. }
  10479. input = closeComment + 3;
  10480. continue;
  10481. }
  10482. else if (input[1] == '?')
  10483. {
  10484. const juce_wchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10485. if (closeBracket == 0)
  10486. {
  10487. outOfData = true;
  10488. break;
  10489. }
  10490. input = closeBracket + 2;
  10491. continue;
  10492. }
  10493. }
  10494. break;
  10495. }
  10496. }
  10497. void XmlDocument::readQuotedString (String& result)
  10498. {
  10499. const juce_wchar quote = readNextChar();
  10500. while (! outOfData)
  10501. {
  10502. const juce_wchar c = readNextChar();
  10503. if (c == quote)
  10504. break;
  10505. if (c == '&')
  10506. {
  10507. --input;
  10508. readEntity (result);
  10509. }
  10510. else
  10511. {
  10512. --input;
  10513. const juce_wchar* const start = input;
  10514. for (;;)
  10515. {
  10516. const juce_wchar character = *input;
  10517. if (character == quote)
  10518. {
  10519. result.append (start, (int) (input - start));
  10520. ++input;
  10521. return;
  10522. }
  10523. else if (character == '&')
  10524. {
  10525. result.append (start, (int) (input - start));
  10526. break;
  10527. }
  10528. else if (character == 0)
  10529. {
  10530. outOfData = true;
  10531. setLastError ("unmatched quotes", false);
  10532. break;
  10533. }
  10534. ++input;
  10535. }
  10536. }
  10537. }
  10538. }
  10539. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements)
  10540. {
  10541. XmlElement* node = 0;
  10542. skipNextWhiteSpace();
  10543. if (outOfData)
  10544. return 0;
  10545. input = CharacterFunctions::find (input, T("<"));
  10546. if (input != 0)
  10547. {
  10548. ++input;
  10549. int tagLen = findNextTokenLength();
  10550. if (tagLen == 0)
  10551. {
  10552. // no tag name - but allow for a gap after the '<' before giving an error
  10553. skipNextWhiteSpace();
  10554. tagLen = findNextTokenLength();
  10555. if (tagLen == 0)
  10556. {
  10557. setLastError ("tag name missing", false);
  10558. return node;
  10559. }
  10560. }
  10561. node = new XmlElement (String (input, tagLen));
  10562. input += tagLen;
  10563. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10564. // look for attributes
  10565. for (;;)
  10566. {
  10567. skipNextWhiteSpace();
  10568. const juce_wchar c = *input;
  10569. // empty tag..
  10570. if (c == '/' && input[1] == '>')
  10571. {
  10572. input += 2;
  10573. break;
  10574. }
  10575. // parse the guts of the element..
  10576. if (c == '>')
  10577. {
  10578. ++input;
  10579. skipNextWhiteSpace();
  10580. if (alsoParseSubElements)
  10581. readChildElements (node);
  10582. break;
  10583. }
  10584. // get an attribute..
  10585. if (isXmlIdentifierChar (c))
  10586. {
  10587. const int attNameLen = findNextTokenLength();
  10588. if (attNameLen > 0)
  10589. {
  10590. const juce_wchar* attNameStart = input;
  10591. input += attNameLen;
  10592. skipNextWhiteSpace();
  10593. if (readNextChar() == '=')
  10594. {
  10595. skipNextWhiteSpace();
  10596. const juce_wchar nextChar = *input;
  10597. if (nextChar == '"' || nextChar == '\'')
  10598. {
  10599. XmlElement::XmlAttributeNode* const newAtt
  10600. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10601. String::empty);
  10602. readQuotedString (newAtt->value);
  10603. if (lastAttribute == 0)
  10604. node->attributes = newAtt;
  10605. else
  10606. lastAttribute->next = newAtt;
  10607. lastAttribute = newAtt;
  10608. continue;
  10609. }
  10610. }
  10611. }
  10612. }
  10613. else
  10614. {
  10615. if (! outOfData)
  10616. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10617. }
  10618. break;
  10619. }
  10620. }
  10621. return node;
  10622. }
  10623. void XmlDocument::readChildElements (XmlElement* parent)
  10624. {
  10625. XmlElement* lastChildNode = 0;
  10626. for (;;)
  10627. {
  10628. skipNextWhiteSpace();
  10629. if (outOfData)
  10630. {
  10631. setLastError ("unmatched tags", false);
  10632. break;
  10633. }
  10634. if (*input == '<')
  10635. {
  10636. if (input[1] == '/')
  10637. {
  10638. // our close tag..
  10639. input = CharacterFunctions::find (input, T(">"));
  10640. ++input;
  10641. break;
  10642. }
  10643. else if (input[1] == '!'
  10644. && input[2] == '['
  10645. && input[3] == 'C'
  10646. && input[4] == 'D'
  10647. && input[5] == 'A'
  10648. && input[6] == 'T'
  10649. && input[7] == 'A'
  10650. && input[8] == '[')
  10651. {
  10652. input += 9;
  10653. const juce_wchar* const inputStart = input;
  10654. int len = 0;
  10655. for (;;)
  10656. {
  10657. if (*input == 0)
  10658. {
  10659. setLastError ("unterminated CDATA section", false);
  10660. outOfData = true;
  10661. break;
  10662. }
  10663. else if (input[0] == ']'
  10664. && input[1] == ']'
  10665. && input[2] == '>')
  10666. {
  10667. input += 3;
  10668. break;
  10669. }
  10670. ++input;
  10671. ++len;
  10672. }
  10673. XmlElement* const e = new XmlElement ((int) 0);
  10674. e->setText (String (inputStart, len));
  10675. if (lastChildNode != 0)
  10676. lastChildNode->nextElement = e;
  10677. else
  10678. parent->addChildElement (e);
  10679. lastChildNode = e;
  10680. }
  10681. else
  10682. {
  10683. // this is some other element, so parse and add it..
  10684. XmlElement* const n = readNextElement (true);
  10685. if (n != 0)
  10686. {
  10687. if (lastChildNode == 0)
  10688. parent->addChildElement (n);
  10689. else
  10690. lastChildNode->nextElement = n;
  10691. lastChildNode = n;
  10692. }
  10693. else
  10694. {
  10695. return;
  10696. }
  10697. }
  10698. }
  10699. else
  10700. {
  10701. // read character block..
  10702. XmlElement* const e = new XmlElement ((int)0);
  10703. if (lastChildNode != 0)
  10704. lastChildNode->nextElement = e;
  10705. else
  10706. parent->addChildElement (e);
  10707. lastChildNode = e;
  10708. String textElementContent;
  10709. for (;;)
  10710. {
  10711. const juce_wchar c = *input;
  10712. if (c == '<')
  10713. break;
  10714. if (c == 0)
  10715. {
  10716. setLastError ("unmatched tags", false);
  10717. outOfData = true;
  10718. return;
  10719. }
  10720. if (c == '&')
  10721. {
  10722. String entity;
  10723. readEntity (entity);
  10724. if (entity.startsWithChar ('<') && entity [1] != 0)
  10725. {
  10726. const juce_wchar* const oldInput = input;
  10727. const bool oldOutOfData = outOfData;
  10728. input = entity;
  10729. outOfData = false;
  10730. for (;;)
  10731. {
  10732. XmlElement* const n = readNextElement (true);
  10733. if (n == 0)
  10734. break;
  10735. if (lastChildNode == 0)
  10736. parent->addChildElement (n);
  10737. else
  10738. lastChildNode->nextElement = n;
  10739. lastChildNode = n;
  10740. }
  10741. input = oldInput;
  10742. outOfData = oldOutOfData;
  10743. }
  10744. else
  10745. {
  10746. textElementContent += entity;
  10747. }
  10748. }
  10749. else
  10750. {
  10751. const juce_wchar* start = input;
  10752. int len = 0;
  10753. for (;;)
  10754. {
  10755. const juce_wchar nextChar = *input;
  10756. if (nextChar == '<' || nextChar == '&')
  10757. {
  10758. break;
  10759. }
  10760. else if (nextChar == 0)
  10761. {
  10762. setLastError ("unmatched tags", false);
  10763. outOfData = true;
  10764. return;
  10765. }
  10766. ++input;
  10767. ++len;
  10768. }
  10769. textElementContent.append (start, len);
  10770. }
  10771. }
  10772. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  10773. : textElementContent.isNotEmpty())
  10774. e->setText (textElementContent);
  10775. }
  10776. }
  10777. }
  10778. void XmlDocument::readEntity (String& result)
  10779. {
  10780. // skip over the ampersand
  10781. ++input;
  10782. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  10783. {
  10784. input += 4;
  10785. result += '&';
  10786. }
  10787. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  10788. {
  10789. input += 5;
  10790. result += '"';
  10791. }
  10792. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  10793. {
  10794. input += 5;
  10795. result += '\'';
  10796. }
  10797. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  10798. {
  10799. input += 3;
  10800. result += '<';
  10801. }
  10802. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  10803. {
  10804. input += 3;
  10805. result += '>';
  10806. }
  10807. else if (*input == '#')
  10808. {
  10809. int charCode = 0;
  10810. ++input;
  10811. if (*input == 'x' || *input == 'X')
  10812. {
  10813. ++input;
  10814. int numChars = 0;
  10815. while (input[0] != ';')
  10816. {
  10817. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  10818. if (hexValue < 0 || ++numChars > 8)
  10819. {
  10820. setLastError ("illegal escape sequence", true);
  10821. break;
  10822. }
  10823. charCode = (charCode << 4) | hexValue;
  10824. ++input;
  10825. }
  10826. ++input;
  10827. }
  10828. else if (input[0] >= '0' && input[0] <= '9')
  10829. {
  10830. int numChars = 0;
  10831. while (input[0] != ';')
  10832. {
  10833. if (++numChars > 12)
  10834. {
  10835. setLastError ("illegal escape sequence", true);
  10836. break;
  10837. }
  10838. charCode = charCode * 10 + (input[0] - '0');
  10839. ++input;
  10840. }
  10841. ++input;
  10842. }
  10843. else
  10844. {
  10845. setLastError ("illegal escape sequence", true);
  10846. result += '&';
  10847. return;
  10848. }
  10849. result << (juce_wchar) charCode;
  10850. }
  10851. else
  10852. {
  10853. const juce_wchar* const entityNameStart = input;
  10854. const juce_wchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  10855. if (closingSemiColon == 0)
  10856. {
  10857. outOfData = true;
  10858. result += '&';
  10859. }
  10860. else
  10861. {
  10862. input = closingSemiColon + 1;
  10863. result += expandExternalEntity (String (entityNameStart,
  10864. (int) (closingSemiColon - entityNameStart)));
  10865. }
  10866. }
  10867. }
  10868. const String XmlDocument::expandEntity (const String& ent)
  10869. {
  10870. if (ent.equalsIgnoreCase ("amp"))
  10871. return String::charToString ('&');
  10872. if (ent.equalsIgnoreCase ("quot"))
  10873. return String::charToString ('"');
  10874. if (ent.equalsIgnoreCase ("apos"))
  10875. return String::charToString ('\'');
  10876. if (ent.equalsIgnoreCase ("lt"))
  10877. return String::charToString ('<');
  10878. if (ent.equalsIgnoreCase ("gt"))
  10879. return String::charToString ('>');
  10880. if (ent[0] == '#')
  10881. {
  10882. if (ent[1] == 'x' || ent[1] == 'X')
  10883. return String::charToString (static_cast <juce_wchar> (ent.substring (2).getHexValue32()));
  10884. if (ent[1] >= '0' && ent[1] <= '9')
  10885. return String::charToString (static_cast <juce_wchar> (ent.substring (1).getIntValue()));
  10886. setLastError ("illegal escape sequence", false);
  10887. return String::charToString ('&');
  10888. }
  10889. return expandExternalEntity (ent);
  10890. }
  10891. const String XmlDocument::expandExternalEntity (const String& entity)
  10892. {
  10893. if (needToLoadDTD)
  10894. {
  10895. if (dtdText.isNotEmpty())
  10896. {
  10897. while (dtdText.endsWithChar ('>'))
  10898. dtdText = dtdText.dropLastCharacters (1);
  10899. tokenisedDTD.addTokens (dtdText, true);
  10900. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase ("system")
  10901. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  10902. {
  10903. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  10904. tokenisedDTD.clear();
  10905. tokenisedDTD.addTokens (getFileContents (fn), true);
  10906. }
  10907. else
  10908. {
  10909. tokenisedDTD.clear();
  10910. const int openBracket = dtdText.indexOfChar ('[');
  10911. if (openBracket > 0)
  10912. {
  10913. const int closeBracket = dtdText.lastIndexOfChar (']');
  10914. if (closeBracket > openBracket)
  10915. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  10916. closeBracket), true);
  10917. }
  10918. }
  10919. for (int i = tokenisedDTD.size(); --i >= 0;)
  10920. {
  10921. if (tokenisedDTD[i].startsWithChar ('%')
  10922. && tokenisedDTD[i].endsWithChar (';'))
  10923. {
  10924. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  10925. StringArray newToks;
  10926. newToks.addTokens (parsed, true);
  10927. tokenisedDTD.remove (i);
  10928. for (int j = newToks.size(); --j >= 0;)
  10929. tokenisedDTD.insert (i, newToks[j]);
  10930. }
  10931. }
  10932. }
  10933. needToLoadDTD = false;
  10934. }
  10935. for (int i = 0; i < tokenisedDTD.size(); ++i)
  10936. {
  10937. if (tokenisedDTD[i] == entity)
  10938. {
  10939. if (tokenisedDTD[i - 1].equalsIgnoreCase ("<!entity"))
  10940. {
  10941. String ent (tokenisedDTD [i + 1]);
  10942. while (ent.endsWithChar ('>'))
  10943. ent = ent.dropLastCharacters (1);
  10944. ent = ent.trim().unquoted();
  10945. // check for sub-entities..
  10946. int ampersand = ent.indexOfChar ('&');
  10947. while (ampersand >= 0)
  10948. {
  10949. const int semiColon = ent.indexOf (i + 1, ";");
  10950. if (semiColon < 0)
  10951. {
  10952. setLastError ("entity without terminating semi-colon", false);
  10953. break;
  10954. }
  10955. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  10956. ent = ent.substring (0, ampersand)
  10957. + resolved
  10958. + ent.substring (semiColon + 1);
  10959. ampersand = ent.indexOfChar (semiColon + 1, '&');
  10960. }
  10961. return ent;
  10962. }
  10963. }
  10964. }
  10965. setLastError ("unknown entity", true);
  10966. return entity;
  10967. }
  10968. const String XmlDocument::getParameterEntity (const String& entity)
  10969. {
  10970. for (int i = 0; i < tokenisedDTD.size(); ++i)
  10971. {
  10972. if (tokenisedDTD[i] == entity)
  10973. {
  10974. if (tokenisedDTD [i - 1] == "%"
  10975. && tokenisedDTD [i - 2].equalsIgnoreCase ("<!entity"))
  10976. {
  10977. String ent (tokenisedDTD [i + 1]);
  10978. while (ent.endsWithChar ('>'))
  10979. ent = ent.dropLastCharacters (1);
  10980. if (ent.equalsIgnoreCase ("system"))
  10981. {
  10982. String filename (tokenisedDTD [i + 2]);
  10983. while (filename.endsWithChar ('>'))
  10984. filename = filename.dropLastCharacters (1);
  10985. return getFileContents (filename);
  10986. }
  10987. else
  10988. {
  10989. return ent.trim().unquoted();
  10990. }
  10991. }
  10992. }
  10993. }
  10994. return entity;
  10995. }
  10996. END_JUCE_NAMESPACE
  10997. /*** End of inlined file: juce_XmlDocument.cpp ***/
  10998. /*** Start of inlined file: juce_XmlElement.cpp ***/
  10999. BEGIN_JUCE_NAMESPACE
  11000. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11001. : name (other.name),
  11002. value (other.value),
  11003. next (0)
  11004. {
  11005. }
  11006. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_, const String& value_) throw()
  11007. : name (name_),
  11008. value (value_),
  11009. next (0)
  11010. {
  11011. }
  11012. XmlElement::XmlElement (const String& tagName_) throw()
  11013. : tagName (tagName_),
  11014. firstChildElement (0),
  11015. nextElement (0),
  11016. attributes (0)
  11017. {
  11018. // the tag name mustn't be empty, or it'll look like a text element!
  11019. jassert (tagName_.containsNonWhitespaceChars())
  11020. // The tag can't contain spaces or other characters that would create invalid XML!
  11021. jassert (! tagName_.containsAnyOf (" <>/&"));
  11022. }
  11023. XmlElement::XmlElement (int /*dummy*/) throw()
  11024. : firstChildElement (0),
  11025. nextElement (0),
  11026. attributes (0)
  11027. {
  11028. }
  11029. XmlElement::XmlElement (const XmlElement& other) throw()
  11030. : tagName (other.tagName),
  11031. firstChildElement (0),
  11032. nextElement (0),
  11033. attributes (0)
  11034. {
  11035. copyChildrenAndAttributesFrom (other);
  11036. }
  11037. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11038. {
  11039. if (this != &other)
  11040. {
  11041. removeAllAttributes();
  11042. deleteAllChildElements();
  11043. tagName = other.tagName;
  11044. copyChildrenAndAttributesFrom (other);
  11045. }
  11046. return *this;
  11047. }
  11048. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11049. {
  11050. XmlElement* child = other.firstChildElement;
  11051. XmlElement* lastChild = 0;
  11052. while (child != 0)
  11053. {
  11054. XmlElement* const copiedChild = new XmlElement (*child);
  11055. if (lastChild != 0)
  11056. lastChild->nextElement = copiedChild;
  11057. else
  11058. firstChildElement = copiedChild;
  11059. lastChild = copiedChild;
  11060. child = child->nextElement;
  11061. }
  11062. const XmlAttributeNode* att = other.attributes;
  11063. XmlAttributeNode* lastAtt = 0;
  11064. while (att != 0)
  11065. {
  11066. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11067. if (lastAtt != 0)
  11068. lastAtt->next = newAtt;
  11069. else
  11070. attributes = newAtt;
  11071. lastAtt = newAtt;
  11072. att = att->next;
  11073. }
  11074. }
  11075. XmlElement::~XmlElement() throw()
  11076. {
  11077. XmlElement* child = firstChildElement;
  11078. while (child != 0)
  11079. {
  11080. XmlElement* const nextChild = child->nextElement;
  11081. delete child;
  11082. child = nextChild;
  11083. }
  11084. XmlAttributeNode* att = attributes;
  11085. while (att != 0)
  11086. {
  11087. XmlAttributeNode* const nextAtt = att->next;
  11088. delete att;
  11089. att = nextAtt;
  11090. }
  11091. }
  11092. namespace XmlOutputFunctions
  11093. {
  11094. static bool isLegalXmlChar (const uint32 c) throw()
  11095. {
  11096. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11097. return c < sizeof (legalChars) * 8
  11098. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11099. }
  11100. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11101. {
  11102. const juce_wchar* t = text;
  11103. for (;;)
  11104. {
  11105. const juce_wchar character = *t++;
  11106. if (character == 0)
  11107. {
  11108. break;
  11109. }
  11110. else if (isLegalXmlChar ((uint32) character))
  11111. {
  11112. outputStream << (char) character;
  11113. }
  11114. else
  11115. {
  11116. switch (character)
  11117. {
  11118. case '&': outputStream << "&amp;"; break;
  11119. case '"': outputStream << "&quot;"; break;
  11120. case '>': outputStream << "&gt;"; break;
  11121. case '<': outputStream << "&lt;"; break;
  11122. case '\n':
  11123. if (changeNewLines)
  11124. outputStream << "&#10;";
  11125. else
  11126. outputStream << (char) character;
  11127. break;
  11128. case '\r':
  11129. if (changeNewLines)
  11130. outputStream << "&#13;";
  11131. else
  11132. outputStream << (char) character;
  11133. break;
  11134. default:
  11135. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11136. break;
  11137. }
  11138. }
  11139. }
  11140. }
  11141. static void writeSpaces (OutputStream& out, int numSpaces)
  11142. {
  11143. if (numSpaces > 0)
  11144. {
  11145. const char* const blanks = " ";
  11146. const int blankSize = (int) sizeof (blanks) - 1;
  11147. while (numSpaces > blankSize)
  11148. {
  11149. out.write (blanks, blankSize);
  11150. numSpaces -= blankSize;
  11151. }
  11152. out.write (blanks, numSpaces);
  11153. }
  11154. }
  11155. }
  11156. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11157. const int indentationLevel,
  11158. const int lineWrapLength) const
  11159. {
  11160. using namespace XmlOutputFunctions;
  11161. writeSpaces (outputStream, indentationLevel);
  11162. if (! isTextElement())
  11163. {
  11164. outputStream.writeByte ('<');
  11165. outputStream << tagName;
  11166. const int attIndent = indentationLevel + tagName.length() + 1;
  11167. int lineLen = 0;
  11168. const XmlAttributeNode* att = attributes;
  11169. while (att != 0)
  11170. {
  11171. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11172. {
  11173. outputStream.write ("\r\n", 2);
  11174. writeSpaces (outputStream, attIndent);
  11175. lineLen = 0;
  11176. }
  11177. const int64 startPos = outputStream.getPosition();
  11178. outputStream.writeByte (' ');
  11179. outputStream << att->name;
  11180. outputStream.write ("=\"", 2);
  11181. escapeIllegalXmlChars (outputStream, att->value, true);
  11182. outputStream.writeByte ('"');
  11183. lineLen += (int) (outputStream.getPosition() - startPos);
  11184. att = att->next;
  11185. }
  11186. if (firstChildElement != 0)
  11187. {
  11188. XmlElement* child = firstChildElement;
  11189. if (child->nextElement == 0 && child->isTextElement())
  11190. {
  11191. outputStream.writeByte ('>');
  11192. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11193. }
  11194. else
  11195. {
  11196. if (indentationLevel >= 0)
  11197. outputStream.write (">\r\n", 3);
  11198. else
  11199. outputStream.writeByte ('>');
  11200. bool lastWasTextNode = false;
  11201. while (child != 0)
  11202. {
  11203. if (child->isTextElement())
  11204. {
  11205. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11206. writeSpaces (outputStream, indentationLevel + 2);
  11207. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11208. lastWasTextNode = true;
  11209. }
  11210. else
  11211. {
  11212. if (indentationLevel >= 0)
  11213. {
  11214. if (lastWasTextNode)
  11215. outputStream.write ("\r\n", 2);
  11216. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11217. }
  11218. else
  11219. {
  11220. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11221. }
  11222. lastWasTextNode = false;
  11223. }
  11224. child = child->nextElement;
  11225. }
  11226. if (indentationLevel >= 0)
  11227. {
  11228. if (lastWasTextNode)
  11229. outputStream.write ("\r\n", 2);
  11230. writeSpaces (outputStream, indentationLevel);
  11231. }
  11232. }
  11233. outputStream.write ("</", 2);
  11234. outputStream << tagName;
  11235. if (indentationLevel >= 0)
  11236. outputStream.write (">\r\n", 3);
  11237. else
  11238. outputStream.writeByte ('>');
  11239. }
  11240. else
  11241. {
  11242. if (indentationLevel >= 0)
  11243. outputStream.write ("/>\r\n", 4);
  11244. else
  11245. outputStream.write ("/>", 2);
  11246. }
  11247. }
  11248. else
  11249. {
  11250. if (indentationLevel >= 0)
  11251. writeSpaces (outputStream, indentationLevel + 2);
  11252. escapeIllegalXmlChars (outputStream, getText(), false);
  11253. }
  11254. }
  11255. const String XmlElement::createDocument (const String& dtdToUse,
  11256. const bool allOnOneLine,
  11257. const bool includeXmlHeader,
  11258. const String& encodingType,
  11259. const int lineWrapLength) const
  11260. {
  11261. MemoryOutputStream mem (2048, 4096);
  11262. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11263. return mem.toUTF8();
  11264. }
  11265. void XmlElement::writeToStream (OutputStream& output,
  11266. const String& dtdToUse,
  11267. const bool allOnOneLine,
  11268. const bool includeXmlHeader,
  11269. const String& encodingType,
  11270. const int lineWrapLength) const
  11271. {
  11272. if (includeXmlHeader)
  11273. output << "<?xml version=\"1.0\" encoding=\"" << encodingType
  11274. << (allOnOneLine ? "\"?> " : "\"?>\r\n\r\n");
  11275. if (dtdToUse.isNotEmpty())
  11276. output << dtdToUse << (allOnOneLine ? " " : "\r\n");
  11277. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11278. }
  11279. bool XmlElement::writeToFile (const File& file,
  11280. const String& dtdToUse,
  11281. const String& encodingType,
  11282. const int lineWrapLength) const
  11283. {
  11284. if (file.hasWriteAccess())
  11285. {
  11286. TemporaryFile tempFile (file);
  11287. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11288. if (out != 0)
  11289. {
  11290. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11291. out = 0;
  11292. return tempFile.overwriteTargetFileWithTemporary();
  11293. }
  11294. }
  11295. return false;
  11296. }
  11297. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11298. {
  11299. #ifdef JUCE_DEBUG
  11300. // if debugging, check that the case is actually the same, because
  11301. // valid xml is case-sensitive, and although this lets it pass, it's
  11302. // better not to..
  11303. if (tagName.equalsIgnoreCase (tagNameWanted))
  11304. {
  11305. jassert (tagName == tagNameWanted);
  11306. return true;
  11307. }
  11308. else
  11309. {
  11310. return false;
  11311. }
  11312. #else
  11313. return tagName.equalsIgnoreCase (tagNameWanted);
  11314. #endif
  11315. }
  11316. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11317. {
  11318. XmlElement* e = nextElement;
  11319. while (e != 0 && ! e->hasTagName (requiredTagName))
  11320. e = e->nextElement;
  11321. return e;
  11322. }
  11323. int XmlElement::getNumAttributes() const throw()
  11324. {
  11325. const XmlAttributeNode* att = attributes;
  11326. int count = 0;
  11327. while (att != 0)
  11328. {
  11329. att = att->next;
  11330. ++count;
  11331. }
  11332. return count;
  11333. }
  11334. const String& XmlElement::getAttributeName (const int index) const throw()
  11335. {
  11336. const XmlAttributeNode* att = attributes;
  11337. int count = 0;
  11338. while (att != 0)
  11339. {
  11340. if (count == index)
  11341. return att->name;
  11342. att = att->next;
  11343. ++count;
  11344. }
  11345. return String::empty;
  11346. }
  11347. const String& XmlElement::getAttributeValue (const int index) const throw()
  11348. {
  11349. const XmlAttributeNode* att = attributes;
  11350. int count = 0;
  11351. while (att != 0)
  11352. {
  11353. if (count == index)
  11354. return att->value;
  11355. att = att->next;
  11356. ++count;
  11357. }
  11358. return String::empty;
  11359. }
  11360. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11361. {
  11362. const XmlAttributeNode* att = attributes;
  11363. while (att != 0)
  11364. {
  11365. if (att->name.equalsIgnoreCase (attributeName))
  11366. return true;
  11367. att = att->next;
  11368. }
  11369. return false;
  11370. }
  11371. const String& XmlElement::getStringAttribute (const String& attributeName) const throw()
  11372. {
  11373. const XmlAttributeNode* att = attributes;
  11374. while (att != 0)
  11375. {
  11376. if (att->name.equalsIgnoreCase (attributeName))
  11377. return att->value;
  11378. att = att->next;
  11379. }
  11380. return String::empty;
  11381. }
  11382. const String XmlElement::getStringAttribute (const String& attributeName, const String& defaultReturnValue) const
  11383. {
  11384. const XmlAttributeNode* att = attributes;
  11385. while (att != 0)
  11386. {
  11387. if (att->name.equalsIgnoreCase (attributeName))
  11388. return att->value;
  11389. att = att->next;
  11390. }
  11391. return defaultReturnValue;
  11392. }
  11393. int XmlElement::getIntAttribute (const String& attributeName, const int defaultReturnValue) const
  11394. {
  11395. const XmlAttributeNode* att = attributes;
  11396. while (att != 0)
  11397. {
  11398. if (att->name.equalsIgnoreCase (attributeName))
  11399. return att->value.getIntValue();
  11400. att = att->next;
  11401. }
  11402. return defaultReturnValue;
  11403. }
  11404. double XmlElement::getDoubleAttribute (const String& attributeName, const double defaultReturnValue) const
  11405. {
  11406. const XmlAttributeNode* att = attributes;
  11407. while (att != 0)
  11408. {
  11409. if (att->name.equalsIgnoreCase (attributeName))
  11410. return att->value.getDoubleValue();
  11411. att = att->next;
  11412. }
  11413. return defaultReturnValue;
  11414. }
  11415. bool XmlElement::getBoolAttribute (const String& attributeName, const bool defaultReturnValue) const
  11416. {
  11417. const XmlAttributeNode* att = attributes;
  11418. while (att != 0)
  11419. {
  11420. if (att->name.equalsIgnoreCase (attributeName))
  11421. {
  11422. juce_wchar firstChar = att->value[0];
  11423. if (CharacterFunctions::isWhitespace (firstChar))
  11424. firstChar = att->value.trimStart() [0];
  11425. return firstChar == '1'
  11426. || firstChar == 't'
  11427. || firstChar == 'y'
  11428. || firstChar == 'T'
  11429. || firstChar == 'Y';
  11430. }
  11431. att = att->next;
  11432. }
  11433. return defaultReturnValue;
  11434. }
  11435. bool XmlElement::compareAttribute (const String& attributeName,
  11436. const String& stringToCompareAgainst,
  11437. const bool ignoreCase) const throw()
  11438. {
  11439. const XmlAttributeNode* att = attributes;
  11440. while (att != 0)
  11441. {
  11442. if (att->name.equalsIgnoreCase (attributeName))
  11443. {
  11444. if (ignoreCase)
  11445. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11446. else
  11447. return att->value == stringToCompareAgainst;
  11448. }
  11449. att = att->next;
  11450. }
  11451. return false;
  11452. }
  11453. void XmlElement::setAttribute (const String& attributeName, const String& value)
  11454. {
  11455. #ifdef JUCE_DEBUG
  11456. // check the identifier being passed in is legal..
  11457. const juce_wchar* t = attributeName;
  11458. while (*t != 0)
  11459. {
  11460. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11461. || *t == '_'
  11462. || *t == '-'
  11463. || *t == ':');
  11464. ++t;
  11465. }
  11466. #endif
  11467. if (attributes == 0)
  11468. {
  11469. attributes = new XmlAttributeNode (attributeName, value);
  11470. }
  11471. else
  11472. {
  11473. XmlAttributeNode* att = attributes;
  11474. for (;;)
  11475. {
  11476. if (att->name.equalsIgnoreCase (attributeName))
  11477. {
  11478. att->value = value;
  11479. break;
  11480. }
  11481. else if (att->next == 0)
  11482. {
  11483. att->next = new XmlAttributeNode (attributeName, value);
  11484. break;
  11485. }
  11486. att = att->next;
  11487. }
  11488. }
  11489. }
  11490. void XmlElement::setAttribute (const String& attributeName, const int number)
  11491. {
  11492. setAttribute (attributeName, String (number));
  11493. }
  11494. void XmlElement::setAttribute (const String& attributeName, const double number)
  11495. {
  11496. setAttribute (attributeName, String (number));
  11497. }
  11498. void XmlElement::removeAttribute (const String& attributeName) throw()
  11499. {
  11500. XmlAttributeNode* att = attributes;
  11501. XmlAttributeNode* lastAtt = 0;
  11502. while (att != 0)
  11503. {
  11504. if (att->name.equalsIgnoreCase (attributeName))
  11505. {
  11506. if (lastAtt == 0)
  11507. attributes = att->next;
  11508. else
  11509. lastAtt->next = att->next;
  11510. delete att;
  11511. break;
  11512. }
  11513. lastAtt = att;
  11514. att = att->next;
  11515. }
  11516. }
  11517. void XmlElement::removeAllAttributes() throw()
  11518. {
  11519. while (attributes != 0)
  11520. {
  11521. XmlAttributeNode* const nextAtt = attributes->next;
  11522. delete attributes;
  11523. attributes = nextAtt;
  11524. }
  11525. }
  11526. int XmlElement::getNumChildElements() const throw()
  11527. {
  11528. int count = 0;
  11529. const XmlElement* child = firstChildElement;
  11530. while (child != 0)
  11531. {
  11532. ++count;
  11533. child = child->nextElement;
  11534. }
  11535. return count;
  11536. }
  11537. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11538. {
  11539. int count = 0;
  11540. XmlElement* child = firstChildElement;
  11541. while (child != 0 && count < index)
  11542. {
  11543. child = child->nextElement;
  11544. ++count;
  11545. }
  11546. return child;
  11547. }
  11548. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11549. {
  11550. XmlElement* child = firstChildElement;
  11551. while (child != 0)
  11552. {
  11553. if (child->hasTagName (childName))
  11554. break;
  11555. child = child->nextElement;
  11556. }
  11557. return child;
  11558. }
  11559. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11560. {
  11561. if (newNode != 0)
  11562. {
  11563. if (firstChildElement == 0)
  11564. {
  11565. firstChildElement = newNode;
  11566. }
  11567. else
  11568. {
  11569. XmlElement* child = firstChildElement;
  11570. while (child->nextElement != 0)
  11571. child = child->nextElement;
  11572. child->nextElement = newNode;
  11573. // if this is non-zero, then something's probably
  11574. // gone wrong..
  11575. jassert (newNode->nextElement == 0);
  11576. }
  11577. }
  11578. }
  11579. void XmlElement::insertChildElement (XmlElement* const newNode,
  11580. int indexToInsertAt) throw()
  11581. {
  11582. if (newNode != 0)
  11583. {
  11584. removeChildElement (newNode, false);
  11585. if (indexToInsertAt == 0)
  11586. {
  11587. newNode->nextElement = firstChildElement;
  11588. firstChildElement = newNode;
  11589. }
  11590. else
  11591. {
  11592. if (firstChildElement == 0)
  11593. {
  11594. firstChildElement = newNode;
  11595. }
  11596. else
  11597. {
  11598. if (indexToInsertAt < 0)
  11599. indexToInsertAt = std::numeric_limits<int>::max();
  11600. XmlElement* child = firstChildElement;
  11601. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11602. child = child->nextElement;
  11603. newNode->nextElement = child->nextElement;
  11604. child->nextElement = newNode;
  11605. }
  11606. }
  11607. }
  11608. }
  11609. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11610. {
  11611. XmlElement* const newElement = new XmlElement (tagName);
  11612. addChildElement (newElement);
  11613. return newElement;
  11614. }
  11615. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11616. XmlElement* const newNode) throw()
  11617. {
  11618. if (newNode != 0)
  11619. {
  11620. XmlElement* child = firstChildElement;
  11621. XmlElement* previousNode = 0;
  11622. while (child != 0)
  11623. {
  11624. if (child == currentChildElement)
  11625. {
  11626. if (child != newNode)
  11627. {
  11628. if (previousNode == 0)
  11629. firstChildElement = newNode;
  11630. else
  11631. previousNode->nextElement = newNode;
  11632. newNode->nextElement = child->nextElement;
  11633. delete child;
  11634. }
  11635. return true;
  11636. }
  11637. previousNode = child;
  11638. child = child->nextElement;
  11639. }
  11640. }
  11641. return false;
  11642. }
  11643. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11644. const bool shouldDeleteTheChild) throw()
  11645. {
  11646. if (childToRemove != 0)
  11647. {
  11648. if (firstChildElement == childToRemove)
  11649. {
  11650. firstChildElement = childToRemove->nextElement;
  11651. childToRemove->nextElement = 0;
  11652. }
  11653. else
  11654. {
  11655. XmlElement* child = firstChildElement;
  11656. XmlElement* last = 0;
  11657. while (child != 0)
  11658. {
  11659. if (child == childToRemove)
  11660. {
  11661. if (last == 0)
  11662. firstChildElement = child->nextElement;
  11663. else
  11664. last->nextElement = child->nextElement;
  11665. childToRemove->nextElement = 0;
  11666. break;
  11667. }
  11668. last = child;
  11669. child = child->nextElement;
  11670. }
  11671. }
  11672. if (shouldDeleteTheChild)
  11673. delete childToRemove;
  11674. }
  11675. }
  11676. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11677. const bool ignoreOrderOfAttributes) const throw()
  11678. {
  11679. if (this != other)
  11680. {
  11681. if (other == 0 || tagName != other->tagName)
  11682. {
  11683. return false;
  11684. }
  11685. if (ignoreOrderOfAttributes)
  11686. {
  11687. int totalAtts = 0;
  11688. const XmlAttributeNode* att = attributes;
  11689. while (att != 0)
  11690. {
  11691. if (! other->compareAttribute (att->name, att->value))
  11692. return false;
  11693. att = att->next;
  11694. ++totalAtts;
  11695. }
  11696. if (totalAtts != other->getNumAttributes())
  11697. return false;
  11698. }
  11699. else
  11700. {
  11701. const XmlAttributeNode* thisAtt = attributes;
  11702. const XmlAttributeNode* otherAtt = other->attributes;
  11703. for (;;)
  11704. {
  11705. if (thisAtt == 0 || otherAtt == 0)
  11706. {
  11707. if (thisAtt == otherAtt) // both 0, so it's a match
  11708. break;
  11709. return false;
  11710. }
  11711. if (thisAtt->name != otherAtt->name
  11712. || thisAtt->value != otherAtt->value)
  11713. {
  11714. return false;
  11715. }
  11716. thisAtt = thisAtt->next;
  11717. otherAtt = otherAtt->next;
  11718. }
  11719. }
  11720. const XmlElement* thisChild = firstChildElement;
  11721. const XmlElement* otherChild = other->firstChildElement;
  11722. for (;;)
  11723. {
  11724. if (thisChild == 0 || otherChild == 0)
  11725. {
  11726. if (thisChild == otherChild) // both 0, so it's a match
  11727. break;
  11728. return false;
  11729. }
  11730. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  11731. return false;
  11732. thisChild = thisChild->nextElement;
  11733. otherChild = otherChild->nextElement;
  11734. }
  11735. }
  11736. return true;
  11737. }
  11738. void XmlElement::deleteAllChildElements() throw()
  11739. {
  11740. while (firstChildElement != 0)
  11741. {
  11742. XmlElement* const nextChild = firstChildElement->nextElement;
  11743. delete firstChildElement;
  11744. firstChildElement = nextChild;
  11745. }
  11746. }
  11747. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  11748. {
  11749. XmlElement* child = firstChildElement;
  11750. while (child != 0)
  11751. {
  11752. if (child->hasTagName (name))
  11753. {
  11754. XmlElement* const nextChild = child->nextElement;
  11755. removeChildElement (child, true);
  11756. child = nextChild;
  11757. }
  11758. else
  11759. {
  11760. child = child->nextElement;
  11761. }
  11762. }
  11763. }
  11764. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  11765. {
  11766. const XmlElement* child = firstChildElement;
  11767. while (child != 0)
  11768. {
  11769. if (child == possibleChild)
  11770. return true;
  11771. child = child->nextElement;
  11772. }
  11773. return false;
  11774. }
  11775. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  11776. {
  11777. if (this == elementToLookFor || elementToLookFor == 0)
  11778. return 0;
  11779. XmlElement* child = firstChildElement;
  11780. while (child != 0)
  11781. {
  11782. if (elementToLookFor == child)
  11783. return this;
  11784. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  11785. if (found != 0)
  11786. return found;
  11787. child = child->nextElement;
  11788. }
  11789. return 0;
  11790. }
  11791. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  11792. {
  11793. XmlElement* e = firstChildElement;
  11794. while (e != 0)
  11795. {
  11796. *elems++ = e;
  11797. e = e->nextElement;
  11798. }
  11799. }
  11800. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  11801. {
  11802. XmlElement* e = firstChildElement = elems[0];
  11803. for (int i = 1; i < num; ++i)
  11804. {
  11805. e->nextElement = elems[i];
  11806. e = e->nextElement;
  11807. }
  11808. e->nextElement = 0;
  11809. }
  11810. bool XmlElement::isTextElement() const throw()
  11811. {
  11812. return tagName.isEmpty();
  11813. }
  11814. static const juce_wchar* const juce_xmltextContentAttributeName = T("text");
  11815. const String XmlElement::getText() const throw()
  11816. {
  11817. jassert (isTextElement()); // you're trying to get the text from an element that
  11818. // isn't actually a text element.. If this contains text sub-nodes, you
  11819. // probably want to use getAllSubText instead.
  11820. return getStringAttribute (juce_xmltextContentAttributeName);
  11821. }
  11822. void XmlElement::setText (const String& newText) throw()
  11823. {
  11824. if (isTextElement())
  11825. {
  11826. setAttribute (juce_xmltextContentAttributeName, newText);
  11827. }
  11828. else
  11829. {
  11830. jassertfalse // you can only change the text in a text element, not a normal one.
  11831. }
  11832. }
  11833. const String XmlElement::getAllSubText() const throw()
  11834. {
  11835. String result;
  11836. String::Concatenator concatenator (result);
  11837. const XmlElement* child = firstChildElement;
  11838. while (child != 0)
  11839. {
  11840. if (child->isTextElement())
  11841. concatenator.append (child->getText());
  11842. child = child->nextElement;
  11843. }
  11844. return result;
  11845. }
  11846. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  11847. const String& defaultReturnValue) const throw()
  11848. {
  11849. const XmlElement* const child = getChildByName (childTagName);
  11850. if (child != 0)
  11851. return child->getAllSubText();
  11852. return defaultReturnValue;
  11853. }
  11854. XmlElement* XmlElement::createTextElement (const String& text) throw()
  11855. {
  11856. XmlElement* const e = new XmlElement ((int) 0);
  11857. e->setAttribute (juce_xmltextContentAttributeName, text);
  11858. return e;
  11859. }
  11860. void XmlElement::addTextElement (const String& text) throw()
  11861. {
  11862. addChildElement (createTextElement (text));
  11863. }
  11864. void XmlElement::deleteAllTextElements() throw()
  11865. {
  11866. XmlElement* child = firstChildElement;
  11867. while (child != 0)
  11868. {
  11869. XmlElement* const next = child->nextElement;
  11870. if (child->isTextElement())
  11871. removeChildElement (child, true);
  11872. child = next;
  11873. }
  11874. }
  11875. END_JUCE_NAMESPACE
  11876. /*** End of inlined file: juce_XmlElement.cpp ***/
  11877. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  11878. BEGIN_JUCE_NAMESPACE
  11879. ReadWriteLock::ReadWriteLock() throw()
  11880. : numWaitingWriters (0),
  11881. numWriters (0),
  11882. writerThreadId (0)
  11883. {
  11884. }
  11885. ReadWriteLock::~ReadWriteLock() throw()
  11886. {
  11887. jassert (readerThreads.size() == 0);
  11888. jassert (numWriters == 0);
  11889. }
  11890. void ReadWriteLock::enterRead() const throw()
  11891. {
  11892. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11893. const ScopedLock sl (accessLock);
  11894. for (;;)
  11895. {
  11896. jassert (readerThreads.size() % 2 == 0);
  11897. int i;
  11898. for (i = 0; i < readerThreads.size(); i += 2)
  11899. if (readerThreads.getUnchecked(i) == threadId)
  11900. break;
  11901. if (i < readerThreads.size()
  11902. || numWriters + numWaitingWriters == 0
  11903. || (threadId == writerThreadId && numWriters > 0))
  11904. {
  11905. if (i < readerThreads.size())
  11906. {
  11907. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  11908. }
  11909. else
  11910. {
  11911. readerThreads.add (threadId);
  11912. readerThreads.add ((Thread::ThreadID) 1);
  11913. }
  11914. return;
  11915. }
  11916. const ScopedUnlock ul (accessLock);
  11917. waitEvent.wait (100);
  11918. }
  11919. }
  11920. void ReadWriteLock::exitRead() const throw()
  11921. {
  11922. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11923. const ScopedLock sl (accessLock);
  11924. for (int i = 0; i < readerThreads.size(); i += 2)
  11925. {
  11926. if (readerThreads.getUnchecked(i) == threadId)
  11927. {
  11928. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  11929. if (newCount == 0)
  11930. {
  11931. readerThreads.removeRange (i, 2);
  11932. waitEvent.signal();
  11933. }
  11934. else
  11935. {
  11936. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  11937. }
  11938. return;
  11939. }
  11940. }
  11941. jassertfalse // unlocking a lock that wasn't locked..
  11942. }
  11943. void ReadWriteLock::enterWrite() const throw()
  11944. {
  11945. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11946. const ScopedLock sl (accessLock);
  11947. for (;;)
  11948. {
  11949. if (readerThreads.size() + numWriters == 0
  11950. || threadId == writerThreadId
  11951. || (readerThreads.size() == 2
  11952. && readerThreads.getUnchecked(0) == threadId))
  11953. {
  11954. writerThreadId = threadId;
  11955. ++numWriters;
  11956. break;
  11957. }
  11958. ++numWaitingWriters;
  11959. accessLock.exit();
  11960. waitEvent.wait (100);
  11961. accessLock.enter();
  11962. --numWaitingWriters;
  11963. }
  11964. }
  11965. bool ReadWriteLock::tryEnterWrite() const throw()
  11966. {
  11967. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  11968. const ScopedLock sl (accessLock);
  11969. if (readerThreads.size() + numWriters == 0
  11970. || threadId == writerThreadId
  11971. || (readerThreads.size() == 2
  11972. && readerThreads.getUnchecked(0) == threadId))
  11973. {
  11974. writerThreadId = threadId;
  11975. ++numWriters;
  11976. return true;
  11977. }
  11978. return false;
  11979. }
  11980. void ReadWriteLock::exitWrite() const throw()
  11981. {
  11982. const ScopedLock sl (accessLock);
  11983. // check this thread actually had the lock..
  11984. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  11985. if (--numWriters == 0)
  11986. {
  11987. writerThreadId = 0;
  11988. waitEvent.signal();
  11989. }
  11990. }
  11991. END_JUCE_NAMESPACE
  11992. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  11993. /*** Start of inlined file: juce_Thread.cpp ***/
  11994. BEGIN_JUCE_NAMESPACE
  11995. // these functions are implemented in the platform-specific code.
  11996. void* juce_createThread (void* userData);
  11997. void juce_killThread (void* handle);
  11998. bool juce_setThreadPriority (void* handle, int priority);
  11999. void juce_setCurrentThreadName (const String& name);
  12000. #if JUCE_WIN32
  12001. void juce_CloseThreadHandle (void* handle);
  12002. #endif
  12003. void Thread::threadEntryPoint (Thread* const thread)
  12004. {
  12005. {
  12006. const ScopedLock sl (runningThreadsLock);
  12007. runningThreads.add (thread);
  12008. }
  12009. JUCE_TRY
  12010. {
  12011. thread->threadId_ = Thread::getCurrentThreadId();
  12012. if (thread->threadName_.isNotEmpty())
  12013. juce_setCurrentThreadName (thread->threadName_);
  12014. if (thread->startSuspensionEvent_.wait (10000))
  12015. {
  12016. if (thread->affinityMask_ != 0)
  12017. setCurrentThreadAffinityMask (thread->affinityMask_);
  12018. thread->run();
  12019. }
  12020. }
  12021. JUCE_CATCH_ALL_ASSERT
  12022. {
  12023. const ScopedLock sl (runningThreadsLock);
  12024. jassert (runningThreads.contains (thread));
  12025. runningThreads.removeValue (thread);
  12026. }
  12027. #if JUCE_WIN32
  12028. juce_CloseThreadHandle (thread->threadHandle_);
  12029. #endif
  12030. thread->threadHandle_ = 0;
  12031. thread->threadId_ = 0;
  12032. }
  12033. // used to wrap the incoming call from the platform-specific code
  12034. void JUCE_API juce_threadEntryPoint (void* userData)
  12035. {
  12036. Thread::threadEntryPoint (static_cast <Thread*> (userData));
  12037. }
  12038. Thread::Thread (const String& threadName)
  12039. : threadName_ (threadName),
  12040. threadHandle_ (0),
  12041. threadPriority_ (5),
  12042. threadId_ (0),
  12043. affinityMask_ (0),
  12044. threadShouldExit_ (false)
  12045. {
  12046. }
  12047. Thread::~Thread()
  12048. {
  12049. stopThread (100);
  12050. }
  12051. void Thread::startThread()
  12052. {
  12053. const ScopedLock sl (startStopLock);
  12054. threadShouldExit_ = false;
  12055. if (threadHandle_ == 0)
  12056. {
  12057. threadHandle_ = juce_createThread (this);
  12058. juce_setThreadPriority (threadHandle_, threadPriority_);
  12059. startSuspensionEvent_.signal();
  12060. }
  12061. }
  12062. void Thread::startThread (const int priority)
  12063. {
  12064. const ScopedLock sl (startStopLock);
  12065. if (threadHandle_ == 0)
  12066. {
  12067. threadPriority_ = priority;
  12068. startThread();
  12069. }
  12070. else
  12071. {
  12072. setPriority (priority);
  12073. }
  12074. }
  12075. bool Thread::isThreadRunning() const
  12076. {
  12077. return threadHandle_ != 0;
  12078. }
  12079. void Thread::signalThreadShouldExit()
  12080. {
  12081. threadShouldExit_ = true;
  12082. }
  12083. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12084. {
  12085. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12086. jassert (getThreadId() != getCurrentThreadId());
  12087. const int sleepMsPerIteration = 5;
  12088. int count = timeOutMilliseconds / sleepMsPerIteration;
  12089. while (isThreadRunning())
  12090. {
  12091. if (timeOutMilliseconds > 0 && --count < 0)
  12092. return false;
  12093. sleep (sleepMsPerIteration);
  12094. }
  12095. return true;
  12096. }
  12097. void Thread::stopThread (const int timeOutMilliseconds)
  12098. {
  12099. // agh! You can't stop the thread that's calling this method! How on earth
  12100. // would that work??
  12101. jassert (getCurrentThreadId() != getThreadId());
  12102. const ScopedLock sl (startStopLock);
  12103. if (isThreadRunning())
  12104. {
  12105. signalThreadShouldExit();
  12106. notify();
  12107. if (timeOutMilliseconds != 0)
  12108. waitForThreadToExit (timeOutMilliseconds);
  12109. if (isThreadRunning())
  12110. {
  12111. // very bad karma if this point is reached, as
  12112. // there are bound to be locks and events left in
  12113. // silly states when a thread is killed by force..
  12114. jassertfalse
  12115. Logger::writeToLog ("!! killing thread by force !!");
  12116. juce_killThread (threadHandle_);
  12117. threadHandle_ = 0;
  12118. threadId_ = 0;
  12119. const ScopedLock sl2 (runningThreadsLock);
  12120. runningThreads.removeValue (this);
  12121. }
  12122. }
  12123. }
  12124. bool Thread::setPriority (const int priority)
  12125. {
  12126. const ScopedLock sl (startStopLock);
  12127. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12128. if (worked)
  12129. threadPriority_ = priority;
  12130. return worked;
  12131. }
  12132. bool Thread::setCurrentThreadPriority (const int priority)
  12133. {
  12134. return juce_setThreadPriority (0, priority);
  12135. }
  12136. void Thread::setAffinityMask (const uint32 affinityMask)
  12137. {
  12138. affinityMask_ = affinityMask;
  12139. }
  12140. bool Thread::wait (const int timeOutMilliseconds) const
  12141. {
  12142. return defaultEvent_.wait (timeOutMilliseconds);
  12143. }
  12144. void Thread::notify() const
  12145. {
  12146. defaultEvent_.signal();
  12147. }
  12148. int Thread::getNumRunningThreads()
  12149. {
  12150. return runningThreads.size();
  12151. }
  12152. Thread* Thread::getCurrentThread()
  12153. {
  12154. const ThreadID thisId = getCurrentThreadId();
  12155. const ScopedLock sl (runningThreadsLock);
  12156. for (int i = runningThreads.size(); --i >= 0;)
  12157. {
  12158. Thread* const t = runningThreads.getUnchecked(i);
  12159. if (t->threadId_ == thisId)
  12160. return t;
  12161. }
  12162. return 0;
  12163. }
  12164. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12165. {
  12166. {
  12167. const ScopedLock sl (runningThreadsLock);
  12168. for (int i = runningThreads.size(); --i >= 0;)
  12169. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12170. }
  12171. for (;;)
  12172. {
  12173. Thread* firstThread;
  12174. {
  12175. const ScopedLock sl (runningThreadsLock);
  12176. firstThread = runningThreads.getFirst();
  12177. }
  12178. if (firstThread == 0)
  12179. break;
  12180. firstThread->stopThread (timeOutMilliseconds);
  12181. }
  12182. }
  12183. Array<Thread*> Thread::runningThreads;
  12184. CriticalSection Thread::runningThreadsLock;
  12185. END_JUCE_NAMESPACE
  12186. /*** End of inlined file: juce_Thread.cpp ***/
  12187. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12188. BEGIN_JUCE_NAMESPACE
  12189. ThreadPoolJob::ThreadPoolJob (const String& name)
  12190. : jobName (name),
  12191. pool (0),
  12192. shouldStop (false),
  12193. isActive (false),
  12194. shouldBeDeleted (false)
  12195. {
  12196. }
  12197. ThreadPoolJob::~ThreadPoolJob()
  12198. {
  12199. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12200. // to remove it first!
  12201. jassert (pool == 0 || ! pool->contains (this));
  12202. }
  12203. const String ThreadPoolJob::getJobName() const
  12204. {
  12205. return jobName;
  12206. }
  12207. void ThreadPoolJob::setJobName (const String& newName)
  12208. {
  12209. jobName = newName;
  12210. }
  12211. void ThreadPoolJob::signalJobShouldExit()
  12212. {
  12213. shouldStop = true;
  12214. }
  12215. class ThreadPool::ThreadPoolThread : public Thread
  12216. {
  12217. public:
  12218. ThreadPoolThread (ThreadPool& pool_)
  12219. : Thread ("Pool"),
  12220. pool (pool_),
  12221. busy (false)
  12222. {
  12223. }
  12224. ~ThreadPoolThread()
  12225. {
  12226. }
  12227. void run()
  12228. {
  12229. while (! threadShouldExit())
  12230. {
  12231. if (! pool.runNextJob())
  12232. wait (500);
  12233. }
  12234. }
  12235. private:
  12236. ThreadPool& pool;
  12237. bool volatile busy;
  12238. ThreadPoolThread (const ThreadPoolThread&);
  12239. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12240. };
  12241. ThreadPool::ThreadPool (const int numThreads,
  12242. const bool startThreadsOnlyWhenNeeded,
  12243. const int stopThreadsWhenNotUsedTimeoutMs)
  12244. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12245. priority (5)
  12246. {
  12247. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12248. for (int i = jmax (1, numThreads); --i >= 0;)
  12249. threads.add (new ThreadPoolThread (*this));
  12250. if (! startThreadsOnlyWhenNeeded)
  12251. for (int i = threads.size(); --i >= 0;)
  12252. threads.getUnchecked(i)->startThread (priority);
  12253. }
  12254. ThreadPool::~ThreadPool()
  12255. {
  12256. removeAllJobs (true, 4000);
  12257. int i;
  12258. for (i = threads.size(); --i >= 0;)
  12259. threads.getUnchecked(i)->signalThreadShouldExit();
  12260. for (i = threads.size(); --i >= 0;)
  12261. threads.getUnchecked(i)->stopThread (500);
  12262. }
  12263. void ThreadPool::addJob (ThreadPoolJob* const job)
  12264. {
  12265. jassert (job != 0);
  12266. jassert (job->pool == 0);
  12267. if (job->pool == 0)
  12268. {
  12269. job->pool = this;
  12270. job->shouldStop = false;
  12271. job->isActive = false;
  12272. {
  12273. const ScopedLock sl (lock);
  12274. jobs.add (job);
  12275. int numRunning = 0;
  12276. for (int i = threads.size(); --i >= 0;)
  12277. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12278. ++numRunning;
  12279. if (numRunning < threads.size())
  12280. {
  12281. bool startedOne = false;
  12282. int n = 1000;
  12283. while (--n >= 0 && ! startedOne)
  12284. {
  12285. for (int i = threads.size(); --i >= 0;)
  12286. {
  12287. if (! threads.getUnchecked(i)->isThreadRunning())
  12288. {
  12289. threads.getUnchecked(i)->startThread (priority);
  12290. startedOne = true;
  12291. break;
  12292. }
  12293. }
  12294. if (! startedOne)
  12295. Thread::sleep (2);
  12296. }
  12297. }
  12298. }
  12299. for (int i = threads.size(); --i >= 0;)
  12300. threads.getUnchecked(i)->notify();
  12301. }
  12302. }
  12303. int ThreadPool::getNumJobs() const
  12304. {
  12305. return jobs.size();
  12306. }
  12307. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12308. {
  12309. const ScopedLock sl (lock);
  12310. return jobs [index];
  12311. }
  12312. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12313. {
  12314. const ScopedLock sl (lock);
  12315. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12316. }
  12317. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12318. {
  12319. const ScopedLock sl (lock);
  12320. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12321. }
  12322. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12323. const int timeOutMs) const
  12324. {
  12325. if (job != 0)
  12326. {
  12327. const uint32 start = Time::getMillisecondCounter();
  12328. while (contains (job))
  12329. {
  12330. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12331. return false;
  12332. jobFinishedSignal.wait (2);
  12333. }
  12334. }
  12335. return true;
  12336. }
  12337. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12338. const bool interruptIfRunning,
  12339. const int timeOutMs)
  12340. {
  12341. bool dontWait = true;
  12342. if (job != 0)
  12343. {
  12344. const ScopedLock sl (lock);
  12345. if (jobs.contains (job))
  12346. {
  12347. if (job->isActive)
  12348. {
  12349. if (interruptIfRunning)
  12350. job->signalJobShouldExit();
  12351. dontWait = false;
  12352. }
  12353. else
  12354. {
  12355. jobs.removeValue (job);
  12356. }
  12357. }
  12358. }
  12359. return dontWait || waitForJobToFinish (job, timeOutMs);
  12360. }
  12361. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12362. const int timeOutMs,
  12363. const bool deleteInactiveJobs,
  12364. ThreadPool::JobSelector* selectedJobsToRemove)
  12365. {
  12366. Array <ThreadPoolJob*> jobsToWaitFor;
  12367. {
  12368. const ScopedLock sl (lock);
  12369. for (int i = jobs.size(); --i >= 0;)
  12370. {
  12371. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12372. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12373. {
  12374. if (job->isActive)
  12375. {
  12376. jobsToWaitFor.add (job);
  12377. if (interruptRunningJobs)
  12378. job->signalJobShouldExit();
  12379. }
  12380. else
  12381. {
  12382. jobs.remove (i);
  12383. if (deleteInactiveJobs)
  12384. delete job;
  12385. }
  12386. }
  12387. }
  12388. }
  12389. const uint32 start = Time::getMillisecondCounter();
  12390. for (;;)
  12391. {
  12392. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12393. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12394. jobsToWaitFor.remove (i);
  12395. if (jobsToWaitFor.size() == 0)
  12396. break;
  12397. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12398. return false;
  12399. jobFinishedSignal.wait (20);
  12400. }
  12401. return true;
  12402. }
  12403. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12404. {
  12405. StringArray s;
  12406. const ScopedLock sl (lock);
  12407. for (int i = 0; i < jobs.size(); ++i)
  12408. {
  12409. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12410. if (job->isActive || ! onlyReturnActiveJobs)
  12411. s.add (job->getJobName());
  12412. }
  12413. return s;
  12414. }
  12415. bool ThreadPool::setThreadPriorities (const int newPriority)
  12416. {
  12417. bool ok = true;
  12418. if (priority != newPriority)
  12419. {
  12420. priority = newPriority;
  12421. for (int i = threads.size(); --i >= 0;)
  12422. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12423. ok = false;
  12424. }
  12425. return ok;
  12426. }
  12427. bool ThreadPool::runNextJob()
  12428. {
  12429. ThreadPoolJob* job = 0;
  12430. {
  12431. const ScopedLock sl (lock);
  12432. for (int i = 0; i < jobs.size(); ++i)
  12433. {
  12434. job = jobs[i];
  12435. if (job != 0 && ! (job->isActive || job->shouldStop))
  12436. break;
  12437. job = 0;
  12438. }
  12439. if (job != 0)
  12440. job->isActive = true;
  12441. }
  12442. if (job != 0)
  12443. {
  12444. JUCE_TRY
  12445. {
  12446. ThreadPoolJob::JobStatus result = job->runJob();
  12447. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12448. const ScopedLock sl (lock);
  12449. if (jobs.contains (job))
  12450. {
  12451. job->isActive = false;
  12452. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12453. {
  12454. job->pool = 0;
  12455. job->shouldStop = true;
  12456. jobs.removeValue (job);
  12457. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12458. delete job;
  12459. jobFinishedSignal.signal();
  12460. }
  12461. else
  12462. {
  12463. // move the job to the end of the queue if it wants another go
  12464. jobs.move (jobs.indexOf (job), -1);
  12465. }
  12466. }
  12467. }
  12468. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12469. catch (...)
  12470. {
  12471. const ScopedLock sl (lock);
  12472. jobs.removeValue (job);
  12473. }
  12474. #endif
  12475. }
  12476. else
  12477. {
  12478. if (threadStopTimeout > 0
  12479. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12480. {
  12481. const ScopedLock sl (lock);
  12482. if (jobs.size() == 0)
  12483. for (int i = threads.size(); --i >= 0;)
  12484. threads.getUnchecked(i)->signalThreadShouldExit();
  12485. }
  12486. else
  12487. {
  12488. return false;
  12489. }
  12490. }
  12491. return true;
  12492. }
  12493. END_JUCE_NAMESPACE
  12494. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12495. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12496. BEGIN_JUCE_NAMESPACE
  12497. TimeSliceThread::TimeSliceThread (const String& threadName)
  12498. : Thread (threadName),
  12499. index (0),
  12500. clientBeingCalled (0),
  12501. clientsChanged (false)
  12502. {
  12503. }
  12504. TimeSliceThread::~TimeSliceThread()
  12505. {
  12506. stopThread (2000);
  12507. }
  12508. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12509. {
  12510. const ScopedLock sl (listLock);
  12511. clients.addIfNotAlreadyThere (client);
  12512. clientsChanged = true;
  12513. notify();
  12514. }
  12515. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12516. {
  12517. const ScopedLock sl1 (listLock);
  12518. clientsChanged = true;
  12519. // if there's a chance we're in the middle of calling this client, we need to
  12520. // also lock the outer lock..
  12521. if (clientBeingCalled == client)
  12522. {
  12523. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12524. const ScopedLock sl2 (callbackLock);
  12525. const ScopedLock sl3 (listLock);
  12526. clients.removeValue (client);
  12527. }
  12528. else
  12529. {
  12530. clients.removeValue (client);
  12531. }
  12532. }
  12533. int TimeSliceThread::getNumClients() const
  12534. {
  12535. return clients.size();
  12536. }
  12537. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12538. {
  12539. const ScopedLock sl (listLock);
  12540. return clients [i];
  12541. }
  12542. void TimeSliceThread::run()
  12543. {
  12544. int numCallsSinceBusy = 0;
  12545. while (! threadShouldExit())
  12546. {
  12547. int timeToWait = 500;
  12548. {
  12549. const ScopedLock sl (callbackLock);
  12550. {
  12551. const ScopedLock sl2 (listLock);
  12552. if (clients.size() > 0)
  12553. {
  12554. index = (index + 1) % clients.size();
  12555. clientBeingCalled = clients [index];
  12556. }
  12557. else
  12558. {
  12559. index = 0;
  12560. clientBeingCalled = 0;
  12561. }
  12562. if (clientsChanged)
  12563. {
  12564. clientsChanged = false;
  12565. numCallsSinceBusy = 0;
  12566. }
  12567. }
  12568. if (clientBeingCalled != 0)
  12569. {
  12570. if (clientBeingCalled->useTimeSlice())
  12571. numCallsSinceBusy = 0;
  12572. else
  12573. ++numCallsSinceBusy;
  12574. if (numCallsSinceBusy >= clients.size())
  12575. timeToWait = 500;
  12576. else if (index == 0)
  12577. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12578. else
  12579. timeToWait = 0;
  12580. }
  12581. }
  12582. if (timeToWait > 0)
  12583. wait (timeToWait);
  12584. }
  12585. }
  12586. END_JUCE_NAMESPACE
  12587. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12588. #endif
  12589. #if JUCE_BUILD_MISC
  12590. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12591. BEGIN_JUCE_NAMESPACE
  12592. class ValueTreeSetPropertyAction : public UndoableAction
  12593. {
  12594. public:
  12595. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12596. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12597. : target (target_), name (name_), newValue (newValue_),
  12598. isAddingNewProperty (isAddingNewProperty_),
  12599. isDeletingProperty (isDeletingProperty_)
  12600. {
  12601. if (! isAddingNewProperty)
  12602. oldValue = target_->getProperty (name_);
  12603. }
  12604. ~ValueTreeSetPropertyAction() {}
  12605. bool perform()
  12606. {
  12607. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12608. if (isDeletingProperty)
  12609. target->removeProperty (name, 0);
  12610. else
  12611. target->setProperty (name, newValue, 0);
  12612. return true;
  12613. }
  12614. bool undo()
  12615. {
  12616. if (isAddingNewProperty)
  12617. target->removeProperty (name, 0);
  12618. else
  12619. target->setProperty (name, oldValue, 0);
  12620. return true;
  12621. }
  12622. int getSizeInUnits()
  12623. {
  12624. return (int) sizeof (*this); //xxx should be more accurate
  12625. }
  12626. private:
  12627. const ValueTree::SharedObjectPtr target;
  12628. const var::identifier name;
  12629. const var newValue;
  12630. var oldValue;
  12631. const bool isAddingNewProperty, isDeletingProperty;
  12632. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12633. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12634. };
  12635. class ValueTreeChildChangeAction : public UndoableAction
  12636. {
  12637. public:
  12638. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12639. const ValueTree::SharedObjectPtr& newChild_)
  12640. : target (target_),
  12641. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12642. childIndex (childIndex_),
  12643. isDeleting (newChild_ == 0)
  12644. {
  12645. jassert (child != 0);
  12646. }
  12647. ~ValueTreeChildChangeAction() {}
  12648. bool perform()
  12649. {
  12650. if (isDeleting)
  12651. target->removeChild (childIndex, 0);
  12652. else
  12653. target->addChild (child, childIndex, 0);
  12654. return true;
  12655. }
  12656. bool undo()
  12657. {
  12658. if (isDeleting)
  12659. target->addChild (child, childIndex, 0);
  12660. else
  12661. target->removeChild (childIndex, 0);
  12662. return true;
  12663. }
  12664. int getSizeInUnits()
  12665. {
  12666. return (int) sizeof (*this); //xxx should be more accurate
  12667. }
  12668. private:
  12669. const ValueTree::SharedObjectPtr target, child;
  12670. const int childIndex;
  12671. const bool isDeleting;
  12672. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12673. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12674. };
  12675. ValueTree::SharedObject::SharedObject (const String& type_)
  12676. : type (type_), parent (0)
  12677. {
  12678. }
  12679. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12680. : type (other.type), properties (other.properties), parent (0)
  12681. {
  12682. for (int i = 0; i < other.children.size(); ++i)
  12683. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12684. }
  12685. ValueTree::SharedObject::~SharedObject()
  12686. {
  12687. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12688. for (int i = children.size(); --i >= 0;)
  12689. {
  12690. const SharedObjectPtr c (children.getUnchecked(i));
  12691. c->parent = 0;
  12692. children.remove (i);
  12693. c->sendParentChangeMessage();
  12694. }
  12695. }
  12696. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12697. {
  12698. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12699. {
  12700. ValueTree* const v = valueTreesWithListeners[i];
  12701. if (v != 0)
  12702. v->listeners.call (&ValueTree::Listener::valueTreePropertyChanged, tree, property);
  12703. }
  12704. }
  12705. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  12706. {
  12707. ValueTree tree (this);
  12708. ValueTree::SharedObject* t = this;
  12709. while (t != 0)
  12710. {
  12711. t->sendPropertyChangeMessage (tree, property);
  12712. t = t->parent;
  12713. }
  12714. }
  12715. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  12716. {
  12717. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12718. {
  12719. ValueTree* const v = valueTreesWithListeners[i];
  12720. if (v != 0)
  12721. v->listeners.call (&ValueTree::Listener::valueTreeChildrenChanged, tree);
  12722. }
  12723. }
  12724. void ValueTree::SharedObject::sendChildChangeMessage()
  12725. {
  12726. ValueTree tree (this);
  12727. ValueTree::SharedObject* t = this;
  12728. while (t != 0)
  12729. {
  12730. t->sendChildChangeMessage (tree);
  12731. t = t->parent;
  12732. }
  12733. }
  12734. void ValueTree::SharedObject::sendParentChangeMessage()
  12735. {
  12736. ValueTree tree (this);
  12737. int i;
  12738. for (i = children.size(); --i >= 0;)
  12739. {
  12740. SharedObject* const t = children[i];
  12741. if (t != 0)
  12742. t->sendParentChangeMessage();
  12743. }
  12744. for (i = valueTreesWithListeners.size(); --i >= 0;)
  12745. {
  12746. ValueTree* const v = valueTreesWithListeners[i];
  12747. if (v != 0)
  12748. v->listeners.call (&ValueTree::Listener::valueTreeParentChanged, tree);
  12749. }
  12750. }
  12751. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  12752. {
  12753. return properties [name];
  12754. }
  12755. const var ValueTree::SharedObject::getProperty (const var::identifier& name, const var& defaultReturnValue) const
  12756. {
  12757. return properties.getWithDefault (name, defaultReturnValue);
  12758. }
  12759. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12760. {
  12761. if (undoManager == 0)
  12762. {
  12763. if (properties.set (name, newValue))
  12764. sendPropertyChangeMessage (name);
  12765. }
  12766. else
  12767. {
  12768. var* const existingValue = properties.getItem (name);
  12769. if (existingValue != 0)
  12770. {
  12771. if (*existingValue != newValue)
  12772. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  12773. }
  12774. else
  12775. {
  12776. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  12777. }
  12778. }
  12779. }
  12780. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  12781. {
  12782. return properties.contains (name);
  12783. }
  12784. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12785. {
  12786. if (undoManager == 0)
  12787. {
  12788. if (properties.remove (name))
  12789. sendPropertyChangeMessage (name);
  12790. }
  12791. else
  12792. {
  12793. if (properties.contains (name))
  12794. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  12795. }
  12796. }
  12797. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  12798. {
  12799. if (undoManager == 0)
  12800. {
  12801. while (properties.size() > 0)
  12802. {
  12803. const var::identifier name (properties.getName (properties.size() - 1));
  12804. properties.remove (name);
  12805. sendPropertyChangeMessage (name);
  12806. }
  12807. }
  12808. else
  12809. {
  12810. for (int i = properties.size(); --i >= 0;)
  12811. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  12812. }
  12813. }
  12814. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  12815. {
  12816. for (int i = 0; i < children.size(); ++i)
  12817. if (children.getUnchecked(i)->type == typeToMatch)
  12818. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12819. return ValueTree::invalid;
  12820. }
  12821. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  12822. {
  12823. for (int i = 0; i < children.size(); ++i)
  12824. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  12825. return ValueTree (static_cast <SharedObject*> (children.getUnchecked(i)));
  12826. return ValueTree::invalid;
  12827. }
  12828. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  12829. {
  12830. const SharedObject* p = parent;
  12831. while (p != 0)
  12832. {
  12833. if (p == possibleParent)
  12834. return true;
  12835. p = p->parent;
  12836. }
  12837. return false;
  12838. }
  12839. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  12840. {
  12841. if (child != 0 && child->parent != this)
  12842. {
  12843. if (child != this && ! isAChildOf (child))
  12844. {
  12845. // You should always make sure that a child is removed from its previous parent before
  12846. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  12847. // undomanager should be used when removing it from its current parent..
  12848. jassert (child->parent == 0);
  12849. if (child->parent != 0)
  12850. {
  12851. jassert (child->parent->children.indexOf (child) >= 0);
  12852. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  12853. }
  12854. if (undoManager == 0)
  12855. {
  12856. children.insert (index, child);
  12857. child->parent = this;
  12858. sendChildChangeMessage();
  12859. child->sendParentChangeMessage();
  12860. }
  12861. else
  12862. {
  12863. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  12864. }
  12865. }
  12866. else
  12867. {
  12868. // You're attempting to create a recursive loop! A node
  12869. // can't be a child of one of its own children!
  12870. jassertfalse
  12871. }
  12872. }
  12873. }
  12874. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  12875. {
  12876. const SharedObjectPtr child (children [childIndex]);
  12877. if (child != 0)
  12878. {
  12879. if (undoManager == 0)
  12880. {
  12881. children.remove (childIndex);
  12882. child->parent = 0;
  12883. sendChildChangeMessage();
  12884. child->sendParentChangeMessage();
  12885. }
  12886. else
  12887. {
  12888. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  12889. }
  12890. }
  12891. }
  12892. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  12893. {
  12894. while (children.size() > 0)
  12895. removeChild (children.size() - 1, undoManager);
  12896. }
  12897. ValueTree ValueTree::invalid (static_cast <ValueTree::SharedObject*> (0));
  12898. ValueTree::ValueTree (const String& type_)
  12899. : object (new ValueTree::SharedObject (type_))
  12900. {
  12901. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  12902. }
  12903. ValueTree::ValueTree (SharedObject* const object_)
  12904. : object (object_)
  12905. {
  12906. }
  12907. ValueTree::ValueTree (const ValueTree& other)
  12908. : object (other.object)
  12909. {
  12910. }
  12911. ValueTree& ValueTree::operator= (const ValueTree& other)
  12912. {
  12913. if (listeners.size() > 0)
  12914. {
  12915. if (object != 0)
  12916. object->valueTreesWithListeners.removeValue (this);
  12917. if (other.object != 0)
  12918. other.object->valueTreesWithListeners.add (this);
  12919. }
  12920. object = other.object;
  12921. return *this;
  12922. }
  12923. ValueTree::~ValueTree()
  12924. {
  12925. if (listeners.size() > 0 && object != 0)
  12926. object->valueTreesWithListeners.removeValue (this);
  12927. }
  12928. bool ValueTree::operator== (const ValueTree& other) const
  12929. {
  12930. return object == other.object;
  12931. }
  12932. bool ValueTree::operator!= (const ValueTree& other) const
  12933. {
  12934. return object != other.object;
  12935. }
  12936. ValueTree ValueTree::createCopy() const
  12937. {
  12938. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  12939. }
  12940. bool ValueTree::hasType (const String& typeName) const
  12941. {
  12942. return object != 0 && object->type == typeName;
  12943. }
  12944. const String ValueTree::getType() const
  12945. {
  12946. return object != 0 ? object->type : String::empty;
  12947. }
  12948. ValueTree ValueTree::getParent() const
  12949. {
  12950. return ValueTree (object != 0 ? object->parent : (SharedObject*) 0);
  12951. }
  12952. const var& ValueTree::operator[] (const var::identifier& name) const
  12953. {
  12954. return object == 0 ? var::null : object->getProperty (name);
  12955. }
  12956. const var& ValueTree::getProperty (const var::identifier& name) const
  12957. {
  12958. return object == 0 ? var::null : object->getProperty (name);
  12959. }
  12960. const var ValueTree::getProperty (const var::identifier& name, const var& defaultReturnValue) const
  12961. {
  12962. return object == 0 ? defaultReturnValue : object->getProperty (name, defaultReturnValue);
  12963. }
  12964. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  12965. {
  12966. jassert (name.name.isNotEmpty());
  12967. if (object != 0 && name.name.isNotEmpty())
  12968. object->setProperty (name, newValue, undoManager);
  12969. }
  12970. bool ValueTree::hasProperty (const var::identifier& name) const
  12971. {
  12972. return object != 0 && object->hasProperty (name);
  12973. }
  12974. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  12975. {
  12976. if (object != 0)
  12977. object->removeProperty (name, undoManager);
  12978. }
  12979. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  12980. {
  12981. if (object != 0)
  12982. object->removeAllProperties (undoManager);
  12983. }
  12984. int ValueTree::getNumProperties() const
  12985. {
  12986. return object == 0 ? 0 : object->properties.size();
  12987. }
  12988. const var::identifier ValueTree::getPropertyName (const int index) const
  12989. {
  12990. return object == 0 ? var::identifier()
  12991. : object->properties.getName (index);
  12992. }
  12993. class ValueTreePropertyValueSource : public Value::ValueSource,
  12994. public ValueTree::Listener
  12995. {
  12996. public:
  12997. ValueTreePropertyValueSource (const ValueTree& tree_,
  12998. const var::identifier& property_,
  12999. UndoManager* const undoManager_)
  13000. : tree (tree_),
  13001. property (property_),
  13002. undoManager (undoManager_)
  13003. {
  13004. tree.addListener (this);
  13005. }
  13006. ~ValueTreePropertyValueSource()
  13007. {
  13008. tree.removeListener (this);
  13009. }
  13010. const var getValue() const
  13011. {
  13012. return tree [property];
  13013. }
  13014. void setValue (const var& newValue)
  13015. {
  13016. tree.setProperty (property, newValue, undoManager);
  13017. }
  13018. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13019. {
  13020. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13021. sendChangeMessage (false);
  13022. }
  13023. void valueTreeChildrenChanged (ValueTree&) {}
  13024. void valueTreeParentChanged (ValueTree&) {}
  13025. private:
  13026. ValueTree tree;
  13027. const var::identifier property;
  13028. UndoManager* const undoManager;
  13029. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13030. };
  13031. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13032. {
  13033. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13034. }
  13035. int ValueTree::getNumChildren() const
  13036. {
  13037. return object == 0 ? 0 : object->children.size();
  13038. }
  13039. ValueTree ValueTree::getChild (int index) const
  13040. {
  13041. return ValueTree (object != 0 ? (SharedObject*) object->children [index] : (SharedObject*) 0);
  13042. }
  13043. ValueTree ValueTree::getChildWithName (const String& type) const
  13044. {
  13045. return object != 0 ? object->getChildWithName (type) : ValueTree::invalid;
  13046. }
  13047. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13048. {
  13049. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree::invalid;
  13050. }
  13051. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13052. {
  13053. return object != 0 && object->isAChildOf (possibleParent.object);
  13054. }
  13055. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13056. {
  13057. if (object != 0)
  13058. object->addChild (child.object, index, undoManager);
  13059. }
  13060. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13061. {
  13062. if (object != 0)
  13063. object->removeChild (childIndex, undoManager);
  13064. }
  13065. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13066. {
  13067. if (object != 0)
  13068. object->removeChild (object->children.indexOf (child.object), undoManager);
  13069. }
  13070. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13071. {
  13072. if (object != 0)
  13073. object->removeAllChildren (undoManager);
  13074. }
  13075. void ValueTree::addListener (Listener* listener)
  13076. {
  13077. if (listener != 0)
  13078. {
  13079. if (listeners.size() == 0 && object != 0)
  13080. object->valueTreesWithListeners.add (this);
  13081. listeners.add (listener);
  13082. }
  13083. }
  13084. void ValueTree::removeListener (Listener* listener)
  13085. {
  13086. listeners.remove (listener);
  13087. if (listeners.size() == 0 && object != 0)
  13088. object->valueTreesWithListeners.removeValue (this);
  13089. }
  13090. XmlElement* ValueTree::SharedObject::createXml() const
  13091. {
  13092. XmlElement* xml = new XmlElement (type);
  13093. int i;
  13094. for (i = 0; i < properties.size(); ++i)
  13095. {
  13096. var::identifier name (properties.getName(i));
  13097. const var& v = properties [name];
  13098. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13099. xml->setAttribute (name.name, v.toString());
  13100. }
  13101. for (i = 0; i < children.size(); ++i)
  13102. xml->addChildElement (children.getUnchecked(i)->createXml());
  13103. return xml;
  13104. }
  13105. XmlElement* ValueTree::createXml() const
  13106. {
  13107. return object != 0 ? object->createXml() : 0;
  13108. }
  13109. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13110. {
  13111. ValueTree v (xml.getTagName());
  13112. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13113. for (int i = 0; i < numAtts; ++i)
  13114. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13115. forEachXmlChildElement (xml, e)
  13116. {
  13117. v.addChild (fromXml (*e), -1, 0);
  13118. }
  13119. return v;
  13120. }
  13121. void ValueTree::writeToStream (OutputStream& output)
  13122. {
  13123. output.writeString (getType());
  13124. const int numProps = getNumProperties();
  13125. output.writeCompressedInt (numProps);
  13126. int i;
  13127. for (i = 0; i < numProps; ++i)
  13128. {
  13129. const var::identifier name (getPropertyName(i));
  13130. output.writeString (name.name);
  13131. getProperty(name).writeToStream (output);
  13132. }
  13133. const int numChildren = getNumChildren();
  13134. output.writeCompressedInt (numChildren);
  13135. for (i = 0; i < numChildren; ++i)
  13136. getChild (i).writeToStream (output);
  13137. }
  13138. ValueTree ValueTree::readFromStream (InputStream& input)
  13139. {
  13140. String type (input.readString());
  13141. if (type.isEmpty())
  13142. return ValueTree::invalid;
  13143. ValueTree v (type);
  13144. const int numProps = input.readCompressedInt();
  13145. if (numProps < 0)
  13146. {
  13147. jassertfalse // trying to read corrupted data!
  13148. return v;
  13149. }
  13150. int i;
  13151. for (i = 0; i < numProps; ++i)
  13152. {
  13153. const String name (input.readString());
  13154. jassert (name.isNotEmpty());
  13155. const var value (var::readFromStream (input));
  13156. v.setProperty (name, value, 0);
  13157. }
  13158. const int numChildren = input.readCompressedInt();
  13159. for (i = 0; i < numChildren; ++i)
  13160. v.addChild (readFromStream (input), -1, 0);
  13161. return v;
  13162. }
  13163. END_JUCE_NAMESPACE
  13164. /*** End of inlined file: juce_ValueTree.cpp ***/
  13165. /*** Start of inlined file: juce_Value.cpp ***/
  13166. BEGIN_JUCE_NAMESPACE
  13167. Value::ValueSource::ValueSource()
  13168. {
  13169. }
  13170. Value::ValueSource::~ValueSource()
  13171. {
  13172. }
  13173. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13174. {
  13175. if (synchronous)
  13176. {
  13177. for (int i = valuesWithListeners.size(); --i >= 0;)
  13178. {
  13179. Value* const v = valuesWithListeners[i];
  13180. if (v != 0)
  13181. v->callListeners();
  13182. }
  13183. }
  13184. else
  13185. {
  13186. triggerAsyncUpdate();
  13187. }
  13188. }
  13189. void Value::ValueSource::handleAsyncUpdate()
  13190. {
  13191. sendChangeMessage (true);
  13192. }
  13193. class SimpleValueSource : public Value::ValueSource
  13194. {
  13195. public:
  13196. SimpleValueSource()
  13197. {
  13198. }
  13199. SimpleValueSource (const var& initialValue)
  13200. : value (initialValue)
  13201. {
  13202. }
  13203. ~SimpleValueSource()
  13204. {
  13205. }
  13206. const var getValue() const
  13207. {
  13208. return value;
  13209. }
  13210. void setValue (const var& newValue)
  13211. {
  13212. if (newValue != value)
  13213. {
  13214. value = newValue;
  13215. sendChangeMessage (false);
  13216. }
  13217. }
  13218. private:
  13219. var value;
  13220. SimpleValueSource (const SimpleValueSource&);
  13221. SimpleValueSource& operator= (const SimpleValueSource&);
  13222. };
  13223. Value::Value()
  13224. : value (new SimpleValueSource())
  13225. {
  13226. }
  13227. Value::Value (ValueSource* const value_)
  13228. : value (value_)
  13229. {
  13230. jassert (value_ != 0);
  13231. }
  13232. Value::Value (const var& initialValue)
  13233. : value (new SimpleValueSource (initialValue))
  13234. {
  13235. }
  13236. Value::Value (const Value& other)
  13237. : value (other.value)
  13238. {
  13239. }
  13240. Value& Value::operator= (const Value& other)
  13241. {
  13242. value = other.value;
  13243. return *this;
  13244. }
  13245. Value::~Value()
  13246. {
  13247. if (listeners.size() > 0)
  13248. value->valuesWithListeners.removeValue (this);
  13249. }
  13250. const var Value::getValue() const
  13251. {
  13252. return value->getValue();
  13253. }
  13254. Value::operator const var() const
  13255. {
  13256. return getValue();
  13257. }
  13258. void Value::setValue (const var& newValue)
  13259. {
  13260. value->setValue (newValue);
  13261. }
  13262. const String Value::toString() const
  13263. {
  13264. return value->getValue().toString();
  13265. }
  13266. Value& Value::operator= (const var& newValue)
  13267. {
  13268. value->setValue (newValue);
  13269. return *this;
  13270. }
  13271. void Value::referTo (const Value& valueToReferTo)
  13272. {
  13273. if (valueToReferTo.value != value)
  13274. {
  13275. if (listeners.size() > 0)
  13276. {
  13277. value->valuesWithListeners.removeValue (this);
  13278. valueToReferTo.value->valuesWithListeners.add (this);
  13279. }
  13280. value = valueToReferTo.value;
  13281. callListeners();
  13282. }
  13283. }
  13284. bool Value::refersToSameSourceAs (const Value& other) const
  13285. {
  13286. return value == other.value;
  13287. }
  13288. bool Value::operator== (const Value& other) const
  13289. {
  13290. return value == other.value || value->getValue() == other.getValue();
  13291. }
  13292. bool Value::operator!= (const Value& other) const
  13293. {
  13294. return value != other.value && value->getValue() != other.getValue();
  13295. }
  13296. void Value::addListener (Listener* const listener)
  13297. {
  13298. if (listener != 0)
  13299. {
  13300. if (listeners.size() == 0)
  13301. value->valuesWithListeners.add (this);
  13302. listeners.add (listener);
  13303. }
  13304. }
  13305. void Value::removeListener (Listener* const listener)
  13306. {
  13307. listeners.remove (listener);
  13308. if (listeners.size() == 0)
  13309. value->valuesWithListeners.removeValue (this);
  13310. }
  13311. void Value::callListeners()
  13312. {
  13313. Value v (*this); // (create a copy in case this gets deleted by a callback)
  13314. listeners.call (&Listener::valueChanged, v);
  13315. }
  13316. OutputStream& JUCE_CALLTYPE operator<< (OutputStream& stream, const Value& value)
  13317. {
  13318. return stream << value.toString();
  13319. }
  13320. END_JUCE_NAMESPACE
  13321. /*** End of inlined file: juce_Value.cpp ***/
  13322. /*** Start of inlined file: juce_Application.cpp ***/
  13323. #if JUCE_MSVC
  13324. #pragma warning (push)
  13325. #pragma warning (disable: 4245 4514 4100)
  13326. #include <crtdbg.h>
  13327. #pragma warning (pop)
  13328. #endif
  13329. BEGIN_JUCE_NAMESPACE
  13330. void juce_setCurrentThreadName (const String& name);
  13331. static JUCEApplication* appInstance = 0;
  13332. JUCEApplication::JUCEApplication()
  13333. : appReturnValue (0),
  13334. stillInitialising (true)
  13335. {
  13336. }
  13337. JUCEApplication::~JUCEApplication()
  13338. {
  13339. if (appLock != 0)
  13340. {
  13341. appLock->exit();
  13342. appLock = 0;
  13343. }
  13344. }
  13345. JUCEApplication* JUCEApplication::getInstance() throw()
  13346. {
  13347. return appInstance;
  13348. }
  13349. bool JUCEApplication::isInitialising() const throw()
  13350. {
  13351. return stillInitialising;
  13352. }
  13353. const String JUCEApplication::getApplicationVersion()
  13354. {
  13355. return String::empty;
  13356. }
  13357. bool JUCEApplication::moreThanOneInstanceAllowed()
  13358. {
  13359. return true;
  13360. }
  13361. void JUCEApplication::anotherInstanceStarted (const String&)
  13362. {
  13363. }
  13364. void JUCEApplication::systemRequestedQuit()
  13365. {
  13366. quit();
  13367. }
  13368. void JUCEApplication::quit()
  13369. {
  13370. MessageManager::getInstance()->stopDispatchLoop();
  13371. }
  13372. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13373. {
  13374. appReturnValue = newReturnValue;
  13375. }
  13376. void JUCEApplication::unhandledException (const std::exception*,
  13377. const String&,
  13378. const int)
  13379. {
  13380. jassertfalse
  13381. }
  13382. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13383. const char* const sourceFile,
  13384. const int lineNumber)
  13385. {
  13386. if (appInstance != 0)
  13387. appInstance->unhandledException (e, sourceFile, lineNumber);
  13388. }
  13389. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13390. {
  13391. return 0;
  13392. }
  13393. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13394. {
  13395. commands.add (StandardApplicationCommandIDs::quit);
  13396. }
  13397. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13398. {
  13399. if (commandID == StandardApplicationCommandIDs::quit)
  13400. {
  13401. result.setInfo (TRANS("Quit"),
  13402. TRANS("Quits the application"),
  13403. "Application",
  13404. 0);
  13405. result.defaultKeypresses.add (KeyPress ('q', ModifierKeys::commandModifier, 0));
  13406. }
  13407. }
  13408. bool JUCEApplication::perform (const InvocationInfo& info)
  13409. {
  13410. if (info.commandID == StandardApplicationCommandIDs::quit)
  13411. {
  13412. systemRequestedQuit();
  13413. return true;
  13414. }
  13415. return false;
  13416. }
  13417. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13418. {
  13419. if (! app->initialiseApp (commandLine))
  13420. return 0;
  13421. // now loop until a quit message is received..
  13422. JUCE_TRY
  13423. {
  13424. MessageManager::getInstance()->runDispatchLoop();
  13425. }
  13426. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13427. catch (const std::exception& e)
  13428. {
  13429. app->unhandledException (&e, __FILE__, __LINE__);
  13430. }
  13431. catch (...)
  13432. {
  13433. app->unhandledException (0, __FILE__, __LINE__);
  13434. }
  13435. #endif
  13436. return shutdownAppAndClearUp();
  13437. }
  13438. bool JUCEApplication::initialiseApp (String& commandLine)
  13439. {
  13440. jassert (appInstance == 0);
  13441. appInstance = this;
  13442. commandLineParameters = commandLine.trim();
  13443. commandLine = String::empty;
  13444. initialiseJuce_GUI();
  13445. #if ! JUCE_IPHONE
  13446. jassert (appLock == 0); // initialiseApp must only be called once!
  13447. if (! moreThanOneInstanceAllowed())
  13448. {
  13449. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13450. if (! appLock->enter(0))
  13451. {
  13452. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13453. delete appInstance;
  13454. appInstance = 0;
  13455. DBG ("Another instance is running - quitting...");
  13456. return false;
  13457. }
  13458. }
  13459. #endif
  13460. // let the app do its setting-up..
  13461. initialise (commandLineParameters);
  13462. // register for broadcast new app messages
  13463. MessageManager::getInstance()->registerBroadcastListener (this);
  13464. stillInitialising = false;
  13465. return true;
  13466. }
  13467. int JUCEApplication::shutdownAppAndClearUp()
  13468. {
  13469. jassert (appInstance != 0);
  13470. ScopedPointer<JUCEApplication> app (appInstance);
  13471. int returnValue = 0;
  13472. MessageManager::getInstance()->deregisterBroadcastListener (static_cast <JUCEApplication*> (app));
  13473. static bool reentrancyCheck = false;
  13474. if (! reentrancyCheck)
  13475. {
  13476. reentrancyCheck = true;
  13477. JUCE_TRY
  13478. {
  13479. // give the app a chance to clean up..
  13480. app->shutdown();
  13481. }
  13482. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13483. catch (const std::exception& e)
  13484. {
  13485. app->unhandledException (&e, __FILE__, __LINE__);
  13486. }
  13487. catch (...)
  13488. {
  13489. app->unhandledException (0, __FILE__, __LINE__);
  13490. }
  13491. #endif
  13492. JUCE_TRY
  13493. {
  13494. shutdownJuce_GUI();
  13495. returnValue = app->getApplicationReturnValue();
  13496. appInstance = 0;
  13497. app = 0;
  13498. }
  13499. JUCE_CATCH_ALL_ASSERT
  13500. reentrancyCheck = false;
  13501. }
  13502. return returnValue;
  13503. }
  13504. #if JUCE_IPHONE
  13505. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13506. #endif
  13507. #if ! JUCE_WINDOWS
  13508. extern const char* juce_Argv0;
  13509. #endif
  13510. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13511. {
  13512. #if ! JUCE_WINDOWS
  13513. juce_Argv0 = argv[0];
  13514. #endif
  13515. #if JUCE_IPHONE
  13516. const ScopedAutoReleasePool pool;
  13517. return juce_IPhoneMain (argc, argv, newApp);
  13518. #else
  13519. #if JUCE_MAC
  13520. const ScopedAutoReleasePool pool;
  13521. #endif
  13522. String cmd;
  13523. for (int i = 1; i < argc; ++i)
  13524. cmd << argv[i] << ' ';
  13525. return JUCEApplication::main (cmd, newApp);
  13526. #endif
  13527. }
  13528. void JUCEApplication::actionListenerCallback (const String& message)
  13529. {
  13530. if (message.startsWith (getApplicationName() + "/"))
  13531. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13532. }
  13533. static bool juceInitialisedGUI = false;
  13534. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13535. {
  13536. if (! juceInitialisedGUI)
  13537. {
  13538. #if JUCE_MAC || JUCE_IPHONE
  13539. const ScopedAutoReleasePool pool;
  13540. #endif
  13541. juceInitialisedGUI = true;
  13542. initialiseJuce_NonGUI();
  13543. MessageManager::getInstance();
  13544. LookAndFeel::setDefaultLookAndFeel (0);
  13545. juce_setCurrentThreadName ("Juce Message Thread");
  13546. #if JUCE_WINDOWS && JUCE_DEBUG
  13547. // This section is just for catching people who mess up their project settings and
  13548. // turn RTTI off..
  13549. try
  13550. {
  13551. TextButton tb (String::empty);
  13552. Component* c = &tb;
  13553. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13554. c = dynamic_cast <Button*> (c);
  13555. }
  13556. catch (...)
  13557. {
  13558. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13559. // got as far as this catch statement, then why haven't you got exception catching
  13560. // turned on in the debugger???
  13561. jassertfalse
  13562. }
  13563. #endif
  13564. }
  13565. }
  13566. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13567. {
  13568. if (juceInitialisedGUI)
  13569. {
  13570. #if JUCE_MAC
  13571. const ScopedAutoReleasePool pool;
  13572. #endif
  13573. {
  13574. DeletedAtShutdown::deleteAll();
  13575. LookAndFeel::clearDefaultLookAndFeel();
  13576. }
  13577. delete MessageManager::getInstance();
  13578. shutdownJuce_NonGUI();
  13579. juceInitialisedGUI = false;
  13580. }
  13581. }
  13582. END_JUCE_NAMESPACE
  13583. /*** End of inlined file: juce_Application.cpp ***/
  13584. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13585. BEGIN_JUCE_NAMESPACE
  13586. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13587. : commandID (commandID_),
  13588. flags (0)
  13589. {
  13590. }
  13591. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13592. const String& description_,
  13593. const String& categoryName_,
  13594. const int flags_) throw()
  13595. {
  13596. shortName = shortName_;
  13597. description = description_;
  13598. categoryName = categoryName_;
  13599. flags = flags_;
  13600. }
  13601. void ApplicationCommandInfo::setActive (const bool b) throw()
  13602. {
  13603. if (b)
  13604. flags &= ~isDisabled;
  13605. else
  13606. flags |= isDisabled;
  13607. }
  13608. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13609. {
  13610. if (b)
  13611. flags |= isTicked;
  13612. else
  13613. flags &= ~isTicked;
  13614. }
  13615. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13616. {
  13617. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13618. }
  13619. END_JUCE_NAMESPACE
  13620. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13621. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13622. BEGIN_JUCE_NAMESPACE
  13623. ApplicationCommandManager::ApplicationCommandManager()
  13624. : firstTarget (0)
  13625. {
  13626. keyMappings = new KeyPressMappingSet (this);
  13627. Desktop::getInstance().addFocusChangeListener (this);
  13628. }
  13629. ApplicationCommandManager::~ApplicationCommandManager()
  13630. {
  13631. Desktop::getInstance().removeFocusChangeListener (this);
  13632. keyMappings = 0;
  13633. }
  13634. void ApplicationCommandManager::clearCommands()
  13635. {
  13636. commands.clear();
  13637. keyMappings->clearAllKeyPresses();
  13638. triggerAsyncUpdate();
  13639. }
  13640. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13641. {
  13642. // zero isn't a valid command ID!
  13643. jassert (newCommand.commandID != 0);
  13644. // the name isn't optional!
  13645. jassert (newCommand.shortName.isNotEmpty());
  13646. if (getCommandForID (newCommand.commandID) == 0)
  13647. {
  13648. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13649. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13650. commands.add (newInfo);
  13651. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13652. triggerAsyncUpdate();
  13653. }
  13654. else
  13655. {
  13656. // trying to re-register the same command with different parameters?
  13657. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13658. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13659. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13660. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13661. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13662. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13663. }
  13664. }
  13665. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13666. {
  13667. if (target != 0)
  13668. {
  13669. Array <CommandID> commandIDs;
  13670. target->getAllCommands (commandIDs);
  13671. for (int i = 0; i < commandIDs.size(); ++i)
  13672. {
  13673. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13674. target->getCommandInfo (info.commandID, info);
  13675. registerCommand (info);
  13676. }
  13677. }
  13678. }
  13679. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13680. {
  13681. for (int i = commands.size(); --i >= 0;)
  13682. {
  13683. if (commands.getUnchecked (i)->commandID == commandID)
  13684. {
  13685. commands.remove (i);
  13686. triggerAsyncUpdate();
  13687. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13688. for (int j = keys.size(); --j >= 0;)
  13689. keyMappings->removeKeyPress (keys.getReference (j));
  13690. }
  13691. }
  13692. }
  13693. void ApplicationCommandManager::commandStatusChanged()
  13694. {
  13695. triggerAsyncUpdate();
  13696. }
  13697. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  13698. {
  13699. for (int i = commands.size(); --i >= 0;)
  13700. if (commands.getUnchecked(i)->commandID == commandID)
  13701. return commands.getUnchecked(i);
  13702. return 0;
  13703. }
  13704. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  13705. {
  13706. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13707. return (ci != 0) ? ci->shortName : String::empty;
  13708. }
  13709. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  13710. {
  13711. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  13712. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  13713. : String::empty;
  13714. }
  13715. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  13716. {
  13717. StringArray s;
  13718. for (int i = 0; i < commands.size(); ++i)
  13719. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  13720. return s;
  13721. }
  13722. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  13723. {
  13724. Array <CommandID> results;
  13725. for (int i = 0; i < commands.size(); ++i)
  13726. if (commands.getUnchecked(i)->categoryName == categoryName)
  13727. results.add (commands.getUnchecked(i)->commandID);
  13728. return results;
  13729. }
  13730. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13731. {
  13732. ApplicationCommandTarget::InvocationInfo info (commandID);
  13733. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13734. return invoke (info, asynchronously);
  13735. }
  13736. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  13737. {
  13738. // This call isn't thread-safe for use from a non-UI thread without locking the message
  13739. // manager first..
  13740. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  13741. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  13742. if (target == 0)
  13743. return false;
  13744. ApplicationCommandInfo commandInfo (0);
  13745. target->getCommandInfo (info_.commandID, commandInfo);
  13746. ApplicationCommandTarget::InvocationInfo info (info_);
  13747. info.commandFlags = commandInfo.flags;
  13748. sendListenerInvokeCallback (info);
  13749. const bool ok = target->invoke (info, asynchronously);
  13750. commandStatusChanged();
  13751. return ok;
  13752. }
  13753. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  13754. {
  13755. return firstTarget != 0 ? firstTarget
  13756. : findDefaultComponentTarget();
  13757. }
  13758. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  13759. {
  13760. firstTarget = newTarget;
  13761. }
  13762. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  13763. ApplicationCommandInfo& upToDateInfo)
  13764. {
  13765. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  13766. if (target == 0)
  13767. target = JUCEApplication::getInstance();
  13768. if (target != 0)
  13769. target = target->getTargetForCommand (commandID);
  13770. if (target != 0)
  13771. target->getCommandInfo (commandID, upToDateInfo);
  13772. return target;
  13773. }
  13774. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  13775. {
  13776. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  13777. if (target == 0 && c != 0)
  13778. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13779. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13780. return target;
  13781. }
  13782. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  13783. {
  13784. Component* c = Component::getCurrentlyFocusedComponent();
  13785. if (c == 0)
  13786. {
  13787. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  13788. if (activeWindow != 0)
  13789. {
  13790. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  13791. if (c == 0)
  13792. c = activeWindow;
  13793. }
  13794. }
  13795. if (c == 0 && Process::isForegroundProcess())
  13796. {
  13797. // getting a bit desperate now - try all desktop comps..
  13798. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  13799. {
  13800. ApplicationCommandTarget* const target
  13801. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  13802. ->getPeer()->getLastFocusedSubcomponent());
  13803. if (target != 0)
  13804. return target;
  13805. }
  13806. }
  13807. if (c != 0)
  13808. {
  13809. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  13810. // if we're focused on a ResizableWindow, chances are that it's the content
  13811. // component that really should get the event. And if not, the event will
  13812. // still be passed up to the top level window anyway, so let's send it to the
  13813. // content comp.
  13814. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  13815. c = resizableWindow->getContentComponent();
  13816. ApplicationCommandTarget* const target = findTargetForComponent (c);
  13817. if (target != 0)
  13818. return target;
  13819. }
  13820. return JUCEApplication::getInstance();
  13821. }
  13822. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  13823. {
  13824. listeners.add (listener);
  13825. }
  13826. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  13827. {
  13828. listeners.remove (listener);
  13829. }
  13830. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info)
  13831. {
  13832. listeners.call (&ApplicationCommandManagerListener::applicationCommandInvoked, info);
  13833. }
  13834. void ApplicationCommandManager::handleAsyncUpdate()
  13835. {
  13836. listeners.call (&ApplicationCommandManagerListener::applicationCommandListChanged);
  13837. }
  13838. void ApplicationCommandManager::globalFocusChanged (Component*)
  13839. {
  13840. commandStatusChanged();
  13841. }
  13842. END_JUCE_NAMESPACE
  13843. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  13844. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13845. BEGIN_JUCE_NAMESPACE
  13846. ApplicationCommandTarget::ApplicationCommandTarget()
  13847. {
  13848. }
  13849. ApplicationCommandTarget::~ApplicationCommandTarget()
  13850. {
  13851. messageInvoker = 0;
  13852. }
  13853. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  13854. {
  13855. if (isCommandActive (info.commandID))
  13856. {
  13857. if (async)
  13858. {
  13859. if (messageInvoker == 0)
  13860. messageInvoker = new CommandTargetMessageInvoker (this);
  13861. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  13862. return true;
  13863. }
  13864. else
  13865. {
  13866. const bool success = perform (info);
  13867. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  13868. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  13869. // returns the command's info.
  13870. return success;
  13871. }
  13872. }
  13873. return false;
  13874. }
  13875. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  13876. {
  13877. Component* c = dynamic_cast <Component*> (this);
  13878. if (c != 0)
  13879. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  13880. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  13881. return 0;
  13882. }
  13883. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  13884. {
  13885. ApplicationCommandTarget* target = this;
  13886. int depth = 0;
  13887. while (target != 0)
  13888. {
  13889. Array <CommandID> commandIDs;
  13890. target->getAllCommands (commandIDs);
  13891. if (commandIDs.contains (commandID))
  13892. return target;
  13893. target = target->getNextCommandTarget();
  13894. ++depth;
  13895. jassert (depth < 100); // could be a recursive command chain??
  13896. jassert (target != this); // definitely a recursive command chain!
  13897. if (depth > 100 || target == this)
  13898. break;
  13899. }
  13900. if (target == 0)
  13901. {
  13902. target = JUCEApplication::getInstance();
  13903. if (target != 0)
  13904. {
  13905. Array <CommandID> commandIDs;
  13906. target->getAllCommands (commandIDs);
  13907. if (commandIDs.contains (commandID))
  13908. return target;
  13909. }
  13910. }
  13911. return 0;
  13912. }
  13913. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  13914. {
  13915. ApplicationCommandInfo info (commandID);
  13916. info.flags = ApplicationCommandInfo::isDisabled;
  13917. getCommandInfo (commandID, info);
  13918. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  13919. }
  13920. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  13921. {
  13922. ApplicationCommandTarget* target = this;
  13923. int depth = 0;
  13924. while (target != 0)
  13925. {
  13926. if (target->tryToInvoke (info, async))
  13927. return true;
  13928. target = target->getNextCommandTarget();
  13929. ++depth;
  13930. jassert (depth < 100); // could be a recursive command chain??
  13931. jassert (target != this); // definitely a recursive command chain!
  13932. if (depth > 100 || target == this)
  13933. break;
  13934. }
  13935. if (target == 0)
  13936. {
  13937. target = JUCEApplication::getInstance();
  13938. if (target != 0)
  13939. return target->tryToInvoke (info, async);
  13940. }
  13941. return false;
  13942. }
  13943. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  13944. {
  13945. ApplicationCommandTarget::InvocationInfo info (commandID);
  13946. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  13947. return invoke (info, asynchronously);
  13948. }
  13949. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  13950. : commandID (commandID_),
  13951. commandFlags (0),
  13952. invocationMethod (direct),
  13953. originatingComponent (0),
  13954. isKeyDown (false),
  13955. millisecsSinceKeyPressed (0)
  13956. {
  13957. }
  13958. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  13959. : owner (owner_)
  13960. {
  13961. }
  13962. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  13963. {
  13964. }
  13965. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  13966. {
  13967. const ScopedPointer <InvocationInfo> info (static_cast <InvocationInfo*> (message.pointerParameter));
  13968. owner->tryToInvoke (*info, false);
  13969. }
  13970. END_JUCE_NAMESPACE
  13971. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  13972. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  13973. BEGIN_JUCE_NAMESPACE
  13974. juce_ImplementSingleton (ApplicationProperties)
  13975. ApplicationProperties::ApplicationProperties() throw()
  13976. : msBeforeSaving (3000),
  13977. options (PropertiesFile::storeAsBinary),
  13978. commonSettingsAreReadOnly (0)
  13979. {
  13980. }
  13981. ApplicationProperties::~ApplicationProperties()
  13982. {
  13983. closeFiles();
  13984. clearSingletonInstance();
  13985. }
  13986. void ApplicationProperties::setStorageParameters (const String& applicationName,
  13987. const String& fileNameSuffix,
  13988. const String& folderName_,
  13989. const int millisecondsBeforeSaving,
  13990. const int propertiesFileOptions) throw()
  13991. {
  13992. appName = applicationName;
  13993. fileSuffix = fileNameSuffix;
  13994. folderName = folderName_;
  13995. msBeforeSaving = millisecondsBeforeSaving;
  13996. options = propertiesFileOptions;
  13997. }
  13998. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  13999. const bool testCommonSettings,
  14000. const bool showWarningDialogOnFailure)
  14001. {
  14002. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14003. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14004. if (! (userOk && commonOk))
  14005. {
  14006. if (showWarningDialogOnFailure)
  14007. {
  14008. String filenames;
  14009. if (userProps != 0 && ! userOk)
  14010. filenames << '\n' << userProps->getFile().getFullPathName();
  14011. if (commonProps != 0 && ! commonOk)
  14012. filenames << '\n' << commonProps->getFile().getFullPathName();
  14013. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14014. appName + TRANS(" - Unable to save settings"),
  14015. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14016. + appName + TRANS(" needs to be able to write to the following files:\n")
  14017. + filenames
  14018. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14019. }
  14020. return false;
  14021. }
  14022. return true;
  14023. }
  14024. void ApplicationProperties::openFiles() throw()
  14025. {
  14026. // You need to call setStorageParameters() before trying to get hold of the
  14027. // properties!
  14028. jassert (appName.isNotEmpty());
  14029. if (appName.isNotEmpty())
  14030. {
  14031. if (userProps == 0)
  14032. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14033. false, msBeforeSaving, options);
  14034. if (commonProps == 0)
  14035. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14036. true, msBeforeSaving, options);
  14037. userProps->setFallbackPropertySet (commonProps);
  14038. }
  14039. }
  14040. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14041. {
  14042. if (userProps == 0)
  14043. openFiles();
  14044. return userProps;
  14045. }
  14046. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14047. {
  14048. if (commonProps == 0)
  14049. openFiles();
  14050. if (returnUserPropsIfReadOnly)
  14051. {
  14052. if (commonSettingsAreReadOnly == 0)
  14053. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14054. if (commonSettingsAreReadOnly > 0)
  14055. return userProps;
  14056. }
  14057. return commonProps;
  14058. }
  14059. bool ApplicationProperties::saveIfNeeded()
  14060. {
  14061. return (userProps == 0 || userProps->saveIfNeeded())
  14062. && (commonProps == 0 || commonProps->saveIfNeeded());
  14063. }
  14064. void ApplicationProperties::closeFiles()
  14065. {
  14066. userProps = 0;
  14067. commonProps = 0;
  14068. }
  14069. END_JUCE_NAMESPACE
  14070. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14071. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14072. BEGIN_JUCE_NAMESPACE
  14073. static VoidArray objectsToDelete;
  14074. static CriticalSection lock;
  14075. DeletedAtShutdown::DeletedAtShutdown()
  14076. {
  14077. const ScopedLock sl (lock);
  14078. objectsToDelete.add (this);
  14079. }
  14080. DeletedAtShutdown::~DeletedAtShutdown()
  14081. {
  14082. const ScopedLock sl (lock);
  14083. objectsToDelete.removeValue (this);
  14084. }
  14085. void DeletedAtShutdown::deleteAll()
  14086. {
  14087. // make a local copy of the array, so it can't get into a loop if something
  14088. // creates another DeletedAtShutdown object during its destructor.
  14089. VoidArray localCopy;
  14090. {
  14091. const ScopedLock sl (lock);
  14092. localCopy = objectsToDelete;
  14093. }
  14094. for (int i = localCopy.size(); --i >= 0;)
  14095. {
  14096. JUCE_TRY
  14097. {
  14098. DeletedAtShutdown* deletee = static_cast <DeletedAtShutdown*> (localCopy.getUnchecked(i));
  14099. // double-check that it's not already been deleted during another object's destructor.
  14100. {
  14101. const ScopedLock sl (lock);
  14102. if (! objectsToDelete.contains (deletee))
  14103. deletee = 0;
  14104. }
  14105. delete deletee;
  14106. }
  14107. JUCE_CATCH_EXCEPTION
  14108. }
  14109. // if no objects got re-created during shutdown, this should have been emptied by their
  14110. // destructors
  14111. jassert (objectsToDelete.size() == 0);
  14112. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14113. }
  14114. END_JUCE_NAMESPACE
  14115. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14116. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14117. BEGIN_JUCE_NAMESPACE
  14118. namespace PropertyFileConstants
  14119. {
  14120. static const int magicNumber = (int) ByteOrder::littleEndianInt ("PROP");
  14121. static const int magicNumberCompressed = (int) ByteOrder::littleEndianInt ("CPRP");
  14122. static const char* const fileTag = "PROPERTIES";
  14123. static const char* const valueTag = "VALUE";
  14124. static const char* const nameAttribute = "name";
  14125. static const char* const valueAttribute = "val";
  14126. }
  14127. PropertiesFile::PropertiesFile (const File& f, const int millisecondsBeforeSaving,
  14128. const int options_, InterProcessLock* const processLock_)
  14129. : PropertySet (ignoreCaseOfKeyNames),
  14130. file (f),
  14131. timerInterval (millisecondsBeforeSaving),
  14132. options (options_),
  14133. loadedOk (false),
  14134. needsWriting (false),
  14135. processLock (processLock_)
  14136. {
  14137. // You need to correctly specify just one storage format for the file
  14138. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14139. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14140. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14141. ProcessScopedLock pl (createProcessLock());
  14142. ScopedPointer<InputStream> fileStream (f.createInputStream());
  14143. if (fileStream != 0)
  14144. {
  14145. int magicNumber = fileStream->readInt();
  14146. if (magicNumber == PropertyFileConstants::magicNumberCompressed)
  14147. {
  14148. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true), true);
  14149. magicNumber = PropertyFileConstants::magicNumber;
  14150. }
  14151. if (magicNumber == PropertyFileConstants::magicNumber)
  14152. {
  14153. loadedOk = true;
  14154. BufferedInputStream in (fileStream.release(), 2048, true);
  14155. int numValues = in.readInt();
  14156. while (--numValues >= 0 && ! in.isExhausted())
  14157. {
  14158. const String key (in.readString());
  14159. const String value (in.readString());
  14160. jassert (key.isNotEmpty());
  14161. if (key.isNotEmpty())
  14162. getAllProperties().set (key, value);
  14163. }
  14164. }
  14165. else
  14166. {
  14167. // Not a binary props file - let's see if it's XML..
  14168. fileStream = 0;
  14169. XmlDocument parser (f);
  14170. ScopedPointer<XmlElement> doc (parser.getDocumentElement (true));
  14171. if (doc != 0 && doc->hasTagName (PropertyFileConstants::fileTag))
  14172. {
  14173. doc = parser.getDocumentElement();
  14174. if (doc != 0)
  14175. {
  14176. loadedOk = true;
  14177. forEachXmlChildElementWithTagName (*doc, e, PropertyFileConstants::valueTag)
  14178. {
  14179. const String name (e->getStringAttribute (PropertyFileConstants::nameAttribute));
  14180. if (name.isNotEmpty())
  14181. {
  14182. getAllProperties().set (name,
  14183. e->getFirstChildElement() != 0
  14184. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14185. : e->getStringAttribute (PropertyFileConstants::valueAttribute));
  14186. }
  14187. }
  14188. }
  14189. else
  14190. {
  14191. // must be a pretty broken XML file we're trying to parse here,
  14192. // or a sign that this object needs an InterProcessLock,
  14193. // or just a failure reading the file. This last reason is why
  14194. // we don't jassertfalse here.
  14195. }
  14196. }
  14197. }
  14198. }
  14199. else
  14200. {
  14201. loadedOk = ! f.exists();
  14202. }
  14203. }
  14204. PropertiesFile::~PropertiesFile()
  14205. {
  14206. if (! saveIfNeeded())
  14207. jassertfalse;
  14208. }
  14209. InterProcessLock::ScopedLockType* PropertiesFile::createProcessLock() const
  14210. {
  14211. return processLock != 0 ? new InterProcessLock::ScopedLockType (*processLock) : 0;
  14212. }
  14213. bool PropertiesFile::saveIfNeeded()
  14214. {
  14215. const ScopedLock sl (getLock());
  14216. return (! needsWriting) || save();
  14217. }
  14218. bool PropertiesFile::needsToBeSaved() const
  14219. {
  14220. const ScopedLock sl (getLock());
  14221. return needsWriting;
  14222. }
  14223. void PropertiesFile::setNeedsToBeSaved (const bool needsToBeSaved)
  14224. {
  14225. const ScopedLock sl (getLock());
  14226. needsWriting = needsToBeSaved;
  14227. }
  14228. bool PropertiesFile::save()
  14229. {
  14230. const ScopedLock sl (getLock());
  14231. stopTimer();
  14232. if (file == File::nonexistent
  14233. || file.isDirectory()
  14234. || ! file.getParentDirectory().createDirectory())
  14235. return false;
  14236. if ((options & storeAsXML) != 0)
  14237. {
  14238. XmlElement doc (PropertyFileConstants::fileTag);
  14239. for (int i = 0; i < getAllProperties().size(); ++i)
  14240. {
  14241. XmlElement* const e = doc.createNewChildElement (PropertyFileConstants::valueTag);
  14242. e->setAttribute (PropertyFileConstants::nameAttribute, getAllProperties().getAllKeys() [i]);
  14243. // if the value seems to contain xml, store it as such..
  14244. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14245. XmlElement* const childElement = xmlContent.getDocumentElement();
  14246. if (childElement != 0)
  14247. e->addChildElement (childElement);
  14248. else
  14249. e->setAttribute (PropertyFileConstants::valueAttribute,
  14250. getAllProperties().getAllValues() [i]);
  14251. }
  14252. ProcessScopedLock pl (createProcessLock());
  14253. if (doc.writeToFile (file, String::empty))
  14254. {
  14255. needsWriting = false;
  14256. return true;
  14257. }
  14258. }
  14259. else
  14260. {
  14261. ProcessScopedLock pl (createProcessLock());
  14262. TemporaryFile tempFile (file);
  14263. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14264. if (out != 0)
  14265. {
  14266. if ((options & storeAsCompressedBinary) != 0)
  14267. {
  14268. out->writeInt (PropertyFileConstants::magicNumberCompressed);
  14269. out->flush();
  14270. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14271. }
  14272. else
  14273. {
  14274. // have you set up the storage option flags correctly?
  14275. jassert ((options & storeAsBinary) != 0);
  14276. out->writeInt (PropertyFileConstants::magicNumber);
  14277. }
  14278. const int numProperties = getAllProperties().size();
  14279. out->writeInt (numProperties);
  14280. for (int i = 0; i < numProperties; ++i)
  14281. {
  14282. out->writeString (getAllProperties().getAllKeys() [i]);
  14283. out->writeString (getAllProperties().getAllValues() [i]);
  14284. }
  14285. out = 0;
  14286. if (tempFile.overwriteTargetFileWithTemporary())
  14287. {
  14288. needsWriting = false;
  14289. return true;
  14290. }
  14291. }
  14292. }
  14293. return false;
  14294. }
  14295. void PropertiesFile::timerCallback()
  14296. {
  14297. saveIfNeeded();
  14298. }
  14299. void PropertiesFile::propertyChanged()
  14300. {
  14301. sendChangeMessage (this);
  14302. needsWriting = true;
  14303. if (timerInterval > 0)
  14304. startTimer (timerInterval);
  14305. else if (timerInterval == 0)
  14306. saveIfNeeded();
  14307. }
  14308. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14309. const String& fileNameSuffix,
  14310. const String& folderName,
  14311. const bool commonToAllUsers)
  14312. {
  14313. // mustn't have illegal characters in this name..
  14314. jassert (applicationName == File::createLegalFileName (applicationName));
  14315. #if JUCE_MAC || JUCE_IPHONE
  14316. File dir (commonToAllUsers ? "/Library/Preferences"
  14317. : "~/Library/Preferences");
  14318. if (folderName.isNotEmpty())
  14319. dir = dir.getChildFile (folderName);
  14320. #endif
  14321. #ifdef JUCE_LINUX
  14322. const File dir ((commonToAllUsers ? "/var/" : "~/")
  14323. + (folderName.isNotEmpty() ? folderName
  14324. : ("." + applicationName)));
  14325. #endif
  14326. #if JUCE_WIN32
  14327. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14328. : File::userApplicationDataDirectory));
  14329. if (dir == File::nonexistent)
  14330. return File::nonexistent;
  14331. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14332. : applicationName);
  14333. #endif
  14334. return dir.getChildFile (applicationName)
  14335. .withFileExtension (fileNameSuffix);
  14336. }
  14337. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14338. const String& fileNameSuffix,
  14339. const String& folderName,
  14340. const bool commonToAllUsers,
  14341. const int millisecondsBeforeSaving,
  14342. const int propertiesFileOptions,
  14343. InterProcessLock* processLock_)
  14344. {
  14345. const File file (getDefaultAppSettingsFile (applicationName,
  14346. fileNameSuffix,
  14347. folderName,
  14348. commonToAllUsers));
  14349. jassert (file != File::nonexistent);
  14350. if (file == File::nonexistent)
  14351. return 0;
  14352. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions,processLock_);
  14353. }
  14354. END_JUCE_NAMESPACE
  14355. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14356. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14357. BEGIN_JUCE_NAMESPACE
  14358. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14359. const String& fileWildcard_,
  14360. const String& openFileDialogTitle_,
  14361. const String& saveFileDialogTitle_)
  14362. : changedSinceSave (false),
  14363. fileExtension (fileExtension_),
  14364. fileWildcard (fileWildcard_),
  14365. openFileDialogTitle (openFileDialogTitle_),
  14366. saveFileDialogTitle (saveFileDialogTitle_)
  14367. {
  14368. }
  14369. FileBasedDocument::~FileBasedDocument()
  14370. {
  14371. }
  14372. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14373. {
  14374. if (changedSinceSave != hasChanged)
  14375. {
  14376. changedSinceSave = hasChanged;
  14377. sendChangeMessage (this);
  14378. }
  14379. }
  14380. void FileBasedDocument::changed()
  14381. {
  14382. changedSinceSave = true;
  14383. sendChangeMessage (this);
  14384. }
  14385. void FileBasedDocument::setFile (const File& newFile)
  14386. {
  14387. if (documentFile != newFile)
  14388. {
  14389. documentFile = newFile;
  14390. changed();
  14391. }
  14392. }
  14393. bool FileBasedDocument::loadFrom (const File& newFile,
  14394. const bool showMessageOnFailure)
  14395. {
  14396. MouseCursor::showWaitCursor();
  14397. const File oldFile (documentFile);
  14398. documentFile = newFile;
  14399. String error;
  14400. if (newFile.existsAsFile())
  14401. {
  14402. error = loadDocument (newFile);
  14403. if (error.isEmpty())
  14404. {
  14405. setChangedFlag (false);
  14406. MouseCursor::hideWaitCursor();
  14407. setLastDocumentOpened (newFile);
  14408. return true;
  14409. }
  14410. }
  14411. else
  14412. {
  14413. error = "The file doesn't exist";
  14414. }
  14415. documentFile = oldFile;
  14416. MouseCursor::hideWaitCursor();
  14417. if (showMessageOnFailure)
  14418. {
  14419. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14420. TRANS("Failed to open file..."),
  14421. TRANS("There was an error while trying to load the file:\n\n")
  14422. + newFile.getFullPathName()
  14423. + "\n\n"
  14424. + error);
  14425. }
  14426. return false;
  14427. }
  14428. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14429. {
  14430. FileChooser fc (openFileDialogTitle,
  14431. getLastDocumentOpened(),
  14432. fileWildcard);
  14433. if (fc.browseForFileToOpen())
  14434. return loadFrom (fc.getResult(), showMessageOnFailure);
  14435. return false;
  14436. }
  14437. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14438. const bool showMessageOnFailure)
  14439. {
  14440. return saveAs (documentFile,
  14441. false,
  14442. askUserForFileIfNotSpecified,
  14443. showMessageOnFailure);
  14444. }
  14445. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14446. const bool warnAboutOverwritingExistingFiles,
  14447. const bool askUserForFileIfNotSpecified,
  14448. const bool showMessageOnFailure)
  14449. {
  14450. if (newFile == File::nonexistent)
  14451. {
  14452. if (askUserForFileIfNotSpecified)
  14453. {
  14454. return saveAsInteractive (true);
  14455. }
  14456. else
  14457. {
  14458. // can't save to an unspecified file
  14459. jassertfalse
  14460. return failedToWriteToFile;
  14461. }
  14462. }
  14463. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14464. {
  14465. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14466. TRANS("File already exists"),
  14467. TRANS("There's already a file called:\n\n")
  14468. + newFile.getFullPathName()
  14469. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14470. TRANS("overwrite"),
  14471. TRANS("cancel")))
  14472. {
  14473. return userCancelledSave;
  14474. }
  14475. }
  14476. MouseCursor::showWaitCursor();
  14477. const File oldFile (documentFile);
  14478. documentFile = newFile;
  14479. String error (saveDocument (newFile));
  14480. if (error.isEmpty())
  14481. {
  14482. setChangedFlag (false);
  14483. MouseCursor::hideWaitCursor();
  14484. return savedOk;
  14485. }
  14486. documentFile = oldFile;
  14487. MouseCursor::hideWaitCursor();
  14488. if (showMessageOnFailure)
  14489. {
  14490. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14491. TRANS("Error writing to file..."),
  14492. TRANS("An error occurred while trying to save \"")
  14493. + getDocumentTitle()
  14494. + TRANS("\" to the file:\n\n")
  14495. + newFile.getFullPathName()
  14496. + "\n\n"
  14497. + error);
  14498. }
  14499. return failedToWriteToFile;
  14500. }
  14501. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14502. {
  14503. if (! hasChangedSinceSaved())
  14504. return savedOk;
  14505. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14506. TRANS("Closing document..."),
  14507. TRANS("Do you want to save the changes to \"")
  14508. + getDocumentTitle() + "\"?",
  14509. TRANS("save"),
  14510. TRANS("discard changes"),
  14511. TRANS("cancel"));
  14512. if (r == 1)
  14513. {
  14514. // save changes
  14515. return save (true, true);
  14516. }
  14517. else if (r == 2)
  14518. {
  14519. // discard changes
  14520. return savedOk;
  14521. }
  14522. return userCancelledSave;
  14523. }
  14524. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14525. {
  14526. File f;
  14527. if (documentFile.existsAsFile())
  14528. f = documentFile;
  14529. else
  14530. f = getLastDocumentOpened();
  14531. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14532. if (legalFilename.isEmpty())
  14533. legalFilename = "unnamed";
  14534. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14535. f = f.getSiblingFile (legalFilename);
  14536. else
  14537. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14538. f = f.withFileExtension (fileExtension)
  14539. .getNonexistentSibling (true);
  14540. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14541. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14542. {
  14543. setLastDocumentOpened (fc.getResult());
  14544. File chosen (fc.getResult());
  14545. if (chosen.getFileExtension().isEmpty())
  14546. {
  14547. chosen = chosen.withFileExtension (fileExtension);
  14548. if (chosen.exists())
  14549. {
  14550. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14551. TRANS("File already exists"),
  14552. TRANS("There's already a file called:")
  14553. + "\n\n" + chosen.getFullPathName()
  14554. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  14555. TRANS("overwrite"),
  14556. TRANS("cancel")))
  14557. {
  14558. return userCancelledSave;
  14559. }
  14560. }
  14561. }
  14562. return saveAs (chosen, false, false, true);
  14563. }
  14564. return userCancelledSave;
  14565. }
  14566. END_JUCE_NAMESPACE
  14567. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14568. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14569. BEGIN_JUCE_NAMESPACE
  14570. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14571. : maxNumberOfItems (10)
  14572. {
  14573. }
  14574. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14575. {
  14576. }
  14577. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14578. {
  14579. maxNumberOfItems = jmax (1, newMaxNumber);
  14580. while (getNumFiles() > maxNumberOfItems)
  14581. files.remove (getNumFiles() - 1);
  14582. }
  14583. int RecentlyOpenedFilesList::getNumFiles() const
  14584. {
  14585. return files.size();
  14586. }
  14587. const File RecentlyOpenedFilesList::getFile (const int index) const
  14588. {
  14589. return File (files [index]);
  14590. }
  14591. void RecentlyOpenedFilesList::clear()
  14592. {
  14593. files.clear();
  14594. }
  14595. void RecentlyOpenedFilesList::addFile (const File& file)
  14596. {
  14597. const String path (file.getFullPathName());
  14598. files.removeString (path, true);
  14599. files.insert (0, path);
  14600. setMaxNumberOfItems (maxNumberOfItems);
  14601. }
  14602. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14603. {
  14604. for (int i = getNumFiles(); --i >= 0;)
  14605. if (! getFile(i).exists())
  14606. files.remove (i);
  14607. }
  14608. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14609. const int baseItemId,
  14610. const bool showFullPaths,
  14611. const bool dontAddNonExistentFiles,
  14612. const File** filesToAvoid)
  14613. {
  14614. int num = 0;
  14615. for (int i = 0; i < getNumFiles(); ++i)
  14616. {
  14617. const File f (getFile(i));
  14618. if ((! dontAddNonExistentFiles) || f.exists())
  14619. {
  14620. bool needsAvoiding = false;
  14621. if (filesToAvoid != 0)
  14622. {
  14623. const File** avoid = filesToAvoid;
  14624. while (*avoid != 0)
  14625. {
  14626. if (f == **avoid)
  14627. {
  14628. needsAvoiding = true;
  14629. break;
  14630. }
  14631. ++avoid;
  14632. }
  14633. }
  14634. if (! needsAvoiding)
  14635. {
  14636. menuToAddTo.addItem (baseItemId + i,
  14637. showFullPaths ? f.getFullPathName()
  14638. : f.getFileName());
  14639. ++num;
  14640. }
  14641. }
  14642. }
  14643. return num;
  14644. }
  14645. const String RecentlyOpenedFilesList::toString() const
  14646. {
  14647. return files.joinIntoString ("\n");
  14648. }
  14649. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14650. {
  14651. clear();
  14652. files.addLines (stringifiedVersion);
  14653. setMaxNumberOfItems (maxNumberOfItems);
  14654. }
  14655. END_JUCE_NAMESPACE
  14656. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14657. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14658. BEGIN_JUCE_NAMESPACE
  14659. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14660. const int minimumTransactions)
  14661. : totalUnitsStored (0),
  14662. nextIndex (0),
  14663. newTransaction (true),
  14664. reentrancyCheck (false)
  14665. {
  14666. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14667. minimumTransactions);
  14668. }
  14669. UndoManager::~UndoManager()
  14670. {
  14671. clearUndoHistory();
  14672. }
  14673. void UndoManager::clearUndoHistory()
  14674. {
  14675. transactions.clear();
  14676. transactionNames.clear();
  14677. totalUnitsStored = 0;
  14678. nextIndex = 0;
  14679. sendChangeMessage (this);
  14680. }
  14681. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14682. {
  14683. return totalUnitsStored;
  14684. }
  14685. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14686. const int minimumTransactions)
  14687. {
  14688. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14689. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14690. }
  14691. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14692. {
  14693. if (command != 0)
  14694. {
  14695. if (actionName.isNotEmpty())
  14696. currentTransactionName = actionName;
  14697. if (reentrancyCheck)
  14698. {
  14699. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14700. // undo() methods, or else these actions won't actually get done.
  14701. return false;
  14702. }
  14703. else
  14704. {
  14705. bool success = false;
  14706. JUCE_TRY
  14707. {
  14708. success = command->perform();
  14709. }
  14710. JUCE_CATCH_EXCEPTION
  14711. jassert (success);
  14712. if (success)
  14713. {
  14714. if (nextIndex > 0 && ! newTransaction)
  14715. {
  14716. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14717. jassert (commandSet != 0);
  14718. if (commandSet == 0)
  14719. return false;
  14720. commandSet->add (command);
  14721. }
  14722. else
  14723. {
  14724. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  14725. commandSet->add (command);
  14726. transactions.insert (nextIndex, commandSet);
  14727. transactionNames.insert (nextIndex, currentTransactionName);
  14728. ++nextIndex;
  14729. }
  14730. totalUnitsStored += command->getSizeInUnits();
  14731. newTransaction = false;
  14732. }
  14733. while (nextIndex < transactions.size())
  14734. {
  14735. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  14736. for (int i = lastSet->size(); --i >= 0;)
  14737. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  14738. transactions.removeLast();
  14739. transactionNames.remove (transactionNames.size() - 1);
  14740. }
  14741. while (nextIndex > 0
  14742. && totalUnitsStored > maxNumUnitsToKeep
  14743. && transactions.size() > minimumTransactionsToKeep)
  14744. {
  14745. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  14746. for (int i = firstSet->size(); --i >= 0;)
  14747. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  14748. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  14749. transactions.remove (0);
  14750. transactionNames.remove (0);
  14751. --nextIndex;
  14752. }
  14753. sendChangeMessage (this);
  14754. return success;
  14755. }
  14756. }
  14757. return false;
  14758. }
  14759. void UndoManager::beginNewTransaction (const String& actionName)
  14760. {
  14761. newTransaction = true;
  14762. currentTransactionName = actionName;
  14763. }
  14764. void UndoManager::setCurrentTransactionName (const String& newName)
  14765. {
  14766. currentTransactionName = newName;
  14767. }
  14768. bool UndoManager::canUndo() const
  14769. {
  14770. return nextIndex > 0;
  14771. }
  14772. bool UndoManager::canRedo() const
  14773. {
  14774. return nextIndex < transactions.size();
  14775. }
  14776. const String UndoManager::getUndoDescription() const
  14777. {
  14778. return transactionNames [nextIndex - 1];
  14779. }
  14780. const String UndoManager::getRedoDescription() const
  14781. {
  14782. return transactionNames [nextIndex];
  14783. }
  14784. bool UndoManager::undo()
  14785. {
  14786. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14787. if (commandSet == 0)
  14788. return false;
  14789. reentrancyCheck = true;
  14790. bool failed = false;
  14791. for (int i = commandSet->size(); --i >= 0;)
  14792. {
  14793. if (! commandSet->getUnchecked(i)->undo())
  14794. {
  14795. jassertfalse
  14796. failed = true;
  14797. break;
  14798. }
  14799. }
  14800. reentrancyCheck = false;
  14801. if (failed)
  14802. {
  14803. clearUndoHistory();
  14804. }
  14805. else
  14806. {
  14807. --nextIndex;
  14808. }
  14809. beginNewTransaction();
  14810. sendChangeMessage (this);
  14811. return true;
  14812. }
  14813. bool UndoManager::redo()
  14814. {
  14815. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  14816. if (commandSet == 0)
  14817. return false;
  14818. reentrancyCheck = true;
  14819. bool failed = false;
  14820. for (int i = 0; i < commandSet->size(); ++i)
  14821. {
  14822. if (! commandSet->getUnchecked(i)->perform())
  14823. {
  14824. jassertfalse
  14825. failed = true;
  14826. break;
  14827. }
  14828. }
  14829. reentrancyCheck = false;
  14830. if (failed)
  14831. {
  14832. clearUndoHistory();
  14833. }
  14834. else
  14835. {
  14836. ++nextIndex;
  14837. }
  14838. beginNewTransaction();
  14839. sendChangeMessage (this);
  14840. return true;
  14841. }
  14842. bool UndoManager::undoCurrentTransactionOnly()
  14843. {
  14844. return newTransaction ? false
  14845. : undo();
  14846. }
  14847. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  14848. {
  14849. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14850. if (commandSet != 0 && ! newTransaction)
  14851. {
  14852. for (int i = 0; i < commandSet->size(); ++i)
  14853. actionsFound.add (commandSet->getUnchecked(i));
  14854. }
  14855. }
  14856. int UndoManager::getNumActionsInCurrentTransaction() const
  14857. {
  14858. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  14859. if (commandSet != 0 && ! newTransaction)
  14860. return commandSet->size();
  14861. return 0;
  14862. }
  14863. END_JUCE_NAMESPACE
  14864. /*** End of inlined file: juce_UndoManager.cpp ***/
  14865. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  14866. BEGIN_JUCE_NAMESPACE
  14867. static const char* const aiffFormatName = "AIFF file";
  14868. static const juce_wchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  14869. class AiffAudioFormatReader : public AudioFormatReader
  14870. {
  14871. public:
  14872. int bytesPerFrame;
  14873. int64 dataChunkStart;
  14874. bool littleEndian;
  14875. AiffAudioFormatReader (InputStream* in)
  14876. : AudioFormatReader (in, TRANS (aiffFormatName))
  14877. {
  14878. if (input->readInt() == chunkName ("FORM"))
  14879. {
  14880. const int len = input->readIntBigEndian();
  14881. const int64 end = input->getPosition() + len;
  14882. const int nextType = input->readInt();
  14883. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  14884. {
  14885. bool hasGotVer = false;
  14886. bool hasGotData = false;
  14887. bool hasGotType = false;
  14888. while (input->getPosition() < end)
  14889. {
  14890. const int type = input->readInt();
  14891. const uint32 length = (uint32) input->readIntBigEndian();
  14892. const int64 chunkEnd = input->getPosition() + length;
  14893. if (type == chunkName ("FVER"))
  14894. {
  14895. hasGotVer = true;
  14896. const int ver = input->readIntBigEndian();
  14897. if (ver != 0 && ver != (int)0xa2805140)
  14898. break;
  14899. }
  14900. else if (type == chunkName ("COMM"))
  14901. {
  14902. hasGotType = true;
  14903. numChannels = (unsigned int)input->readShortBigEndian();
  14904. lengthInSamples = input->readIntBigEndian();
  14905. bitsPerSample = input->readShortBigEndian();
  14906. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  14907. unsigned char sampleRateBytes[10];
  14908. input->read (sampleRateBytes, 10);
  14909. const int byte0 = sampleRateBytes[0];
  14910. if ((byte0 & 0x80) != 0
  14911. || byte0 <= 0x3F || byte0 > 0x40
  14912. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  14913. break;
  14914. unsigned int sampRate = ByteOrder::bigEndianInt (sampleRateBytes + 2);
  14915. sampRate >>= (16414 - ByteOrder::bigEndianShort (sampleRateBytes));
  14916. sampleRate = (int) sampRate;
  14917. if (length <= 18)
  14918. {
  14919. // some types don't have a chunk large enough to include a compression
  14920. // type, so assume it's just big-endian pcm
  14921. littleEndian = false;
  14922. }
  14923. else
  14924. {
  14925. const int compType = input->readInt();
  14926. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  14927. {
  14928. littleEndian = false;
  14929. }
  14930. else if (compType == chunkName ("sowt"))
  14931. {
  14932. littleEndian = true;
  14933. }
  14934. else
  14935. {
  14936. sampleRate = 0;
  14937. break;
  14938. }
  14939. }
  14940. }
  14941. else if (type == chunkName ("SSND"))
  14942. {
  14943. hasGotData = true;
  14944. const int offset = input->readIntBigEndian();
  14945. dataChunkStart = input->getPosition() + 4 + offset;
  14946. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  14947. }
  14948. else if ((hasGotVer && hasGotData && hasGotType)
  14949. || chunkEnd < input->getPosition()
  14950. || input->isExhausted())
  14951. {
  14952. break;
  14953. }
  14954. input->setPosition (chunkEnd);
  14955. }
  14956. }
  14957. }
  14958. }
  14959. ~AiffAudioFormatReader()
  14960. {
  14961. }
  14962. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  14963. int64 startSampleInFile, int numSamples)
  14964. {
  14965. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  14966. if (samplesAvailable < numSamples)
  14967. {
  14968. for (int i = numDestChannels; --i >= 0;)
  14969. if (destSamples[i] != 0)
  14970. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  14971. numSamples = (int) samplesAvailable;
  14972. }
  14973. if (numSamples <= 0)
  14974. return true;
  14975. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  14976. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  14977. char tempBuffer [tempBufSize];
  14978. while (numSamples > 0)
  14979. {
  14980. int* left = destSamples[0];
  14981. if (left != 0)
  14982. left += startOffsetInDestBuffer;
  14983. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  14984. if (right != 0)
  14985. right += startOffsetInDestBuffer;
  14986. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  14987. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  14988. if (bytesRead < numThisTime * bytesPerFrame)
  14989. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  14990. if (bitsPerSample == 16)
  14991. {
  14992. if (littleEndian)
  14993. {
  14994. const short* src = reinterpret_cast <const short*> (tempBuffer);
  14995. if (numChannels > 1)
  14996. {
  14997. if (left == 0)
  14998. {
  14999. for (int i = numThisTime; --i >= 0;)
  15000. {
  15001. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15002. ++src;
  15003. }
  15004. }
  15005. else if (right == 0)
  15006. {
  15007. for (int i = numThisTime; --i >= 0;)
  15008. {
  15009. ++src;
  15010. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15011. }
  15012. }
  15013. else
  15014. {
  15015. for (int i = numThisTime; --i >= 0;)
  15016. {
  15017. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15018. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15019. }
  15020. }
  15021. }
  15022. else
  15023. {
  15024. for (int i = numThisTime; --i >= 0;)
  15025. {
  15026. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15027. }
  15028. }
  15029. }
  15030. else
  15031. {
  15032. const char* src = tempBuffer;
  15033. if (numChannels > 1)
  15034. {
  15035. if (left == 0)
  15036. {
  15037. for (int i = numThisTime; --i >= 0;)
  15038. {
  15039. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15040. src += 4;
  15041. }
  15042. }
  15043. else if (right == 0)
  15044. {
  15045. for (int i = numThisTime; --i >= 0;)
  15046. {
  15047. src += 2;
  15048. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15049. src += 2;
  15050. }
  15051. }
  15052. else
  15053. {
  15054. for (int i = numThisTime; --i >= 0;)
  15055. {
  15056. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15057. src += 2;
  15058. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15059. src += 2;
  15060. }
  15061. }
  15062. }
  15063. else
  15064. {
  15065. for (int i = numThisTime; --i >= 0;)
  15066. {
  15067. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15068. src += 2;
  15069. }
  15070. }
  15071. }
  15072. }
  15073. else if (bitsPerSample == 24)
  15074. {
  15075. const char* src = (const char*)tempBuffer;
  15076. if (littleEndian)
  15077. {
  15078. if (numChannels > 1)
  15079. {
  15080. if (left == 0)
  15081. {
  15082. for (int i = numThisTime; --i >= 0;)
  15083. {
  15084. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15085. src += 6;
  15086. }
  15087. }
  15088. else if (right == 0)
  15089. {
  15090. for (int i = numThisTime; --i >= 0;)
  15091. {
  15092. src += 3;
  15093. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15094. src += 3;
  15095. }
  15096. }
  15097. else
  15098. {
  15099. for (int i = numThisTime; --i >= 0;)
  15100. {
  15101. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15102. src += 3;
  15103. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15104. src += 3;
  15105. }
  15106. }
  15107. }
  15108. else
  15109. {
  15110. for (int i = numThisTime; --i >= 0;)
  15111. {
  15112. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15113. src += 3;
  15114. }
  15115. }
  15116. }
  15117. else
  15118. {
  15119. if (numChannels > 1)
  15120. {
  15121. if (left == 0)
  15122. {
  15123. for (int i = numThisTime; --i >= 0;)
  15124. {
  15125. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15126. src += 6;
  15127. }
  15128. }
  15129. else if (right == 0)
  15130. {
  15131. for (int i = numThisTime; --i >= 0;)
  15132. {
  15133. src += 3;
  15134. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15135. src += 3;
  15136. }
  15137. }
  15138. else
  15139. {
  15140. for (int i = numThisTime; --i >= 0;)
  15141. {
  15142. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15143. src += 3;
  15144. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15145. src += 3;
  15146. }
  15147. }
  15148. }
  15149. else
  15150. {
  15151. for (int i = numThisTime; --i >= 0;)
  15152. {
  15153. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15154. src += 3;
  15155. }
  15156. }
  15157. }
  15158. }
  15159. else if (bitsPerSample == 32)
  15160. {
  15161. const unsigned int* src = reinterpret_cast <const unsigned int*> (tempBuffer);
  15162. unsigned int* l = reinterpret_cast <unsigned int*> (left);
  15163. unsigned int* r = reinterpret_cast <unsigned int*> (right);
  15164. if (littleEndian)
  15165. {
  15166. if (numChannels > 1)
  15167. {
  15168. if (l == 0)
  15169. {
  15170. for (int i = numThisTime; --i >= 0;)
  15171. {
  15172. ++src;
  15173. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15174. }
  15175. }
  15176. else if (r == 0)
  15177. {
  15178. for (int i = numThisTime; --i >= 0;)
  15179. {
  15180. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15181. ++src;
  15182. }
  15183. }
  15184. else
  15185. {
  15186. for (int i = numThisTime; --i >= 0;)
  15187. {
  15188. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15189. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15190. }
  15191. }
  15192. }
  15193. else
  15194. {
  15195. for (int i = numThisTime; --i >= 0;)
  15196. {
  15197. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15198. }
  15199. }
  15200. }
  15201. else
  15202. {
  15203. if (numChannels > 1)
  15204. {
  15205. if (l == 0)
  15206. {
  15207. for (int i = numThisTime; --i >= 0;)
  15208. {
  15209. ++src;
  15210. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15211. }
  15212. }
  15213. else if (r == 0)
  15214. {
  15215. for (int i = numThisTime; --i >= 0;)
  15216. {
  15217. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15218. ++src;
  15219. }
  15220. }
  15221. else
  15222. {
  15223. for (int i = numThisTime; --i >= 0;)
  15224. {
  15225. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15226. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15227. }
  15228. }
  15229. }
  15230. else
  15231. {
  15232. for (int i = numThisTime; --i >= 0;)
  15233. {
  15234. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15235. }
  15236. }
  15237. }
  15238. left = reinterpret_cast <int*> (l);
  15239. right = reinterpret_cast <int*> (r);
  15240. }
  15241. else if (bitsPerSample == 8)
  15242. {
  15243. const char* src = tempBuffer;
  15244. if (numChannels > 1)
  15245. {
  15246. if (left == 0)
  15247. {
  15248. for (int i = numThisTime; --i >= 0;)
  15249. {
  15250. *right++ = ((int) *src++) << 24;
  15251. ++src;
  15252. }
  15253. }
  15254. else if (right == 0)
  15255. {
  15256. for (int i = numThisTime; --i >= 0;)
  15257. {
  15258. ++src;
  15259. *left++ = ((int) *src++) << 24;
  15260. }
  15261. }
  15262. else
  15263. {
  15264. for (int i = numThisTime; --i >= 0;)
  15265. {
  15266. *left++ = ((int) *src++) << 24;
  15267. *right++ = ((int) *src++) << 24;
  15268. }
  15269. }
  15270. }
  15271. else
  15272. {
  15273. for (int i = numThisTime; --i >= 0;)
  15274. {
  15275. *left++ = ((int) *src++) << 24;
  15276. }
  15277. }
  15278. }
  15279. startOffsetInDestBuffer += numThisTime;
  15280. numSamples -= numThisTime;
  15281. }
  15282. if (numSamples > 0)
  15283. {
  15284. for (int i = numDestChannels; --i >= 0;)
  15285. if (destSamples[i] != 0)
  15286. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15287. sizeof (int) * numSamples);
  15288. }
  15289. return true;
  15290. }
  15291. juce_UseDebuggingNewOperator
  15292. private:
  15293. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15294. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15295. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15296. };
  15297. class AiffAudioFormatWriter : public AudioFormatWriter
  15298. {
  15299. MemoryBlock tempBlock;
  15300. uint32 lengthInSamples, bytesWritten;
  15301. int64 headerPosition;
  15302. bool writeFailed;
  15303. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15304. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15305. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15306. void writeHeader()
  15307. {
  15308. const bool couldSeekOk = output->setPosition (headerPosition);
  15309. (void) couldSeekOk;
  15310. // if this fails, you've given it an output stream that can't seek! It needs
  15311. // to be able to seek back to write the header
  15312. jassert (couldSeekOk);
  15313. const int headerLen = 54;
  15314. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15315. audioBytes += (audioBytes & 1);
  15316. output->writeInt (chunkName ("FORM"));
  15317. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15318. output->writeInt (chunkName ("AIFF"));
  15319. output->writeInt (chunkName ("COMM"));
  15320. output->writeIntBigEndian (18);
  15321. output->writeShortBigEndian ((short) numChannels);
  15322. output->writeIntBigEndian (lengthInSamples);
  15323. output->writeShortBigEndian ((short) bitsPerSample);
  15324. uint8 sampleRateBytes[10];
  15325. zeromem (sampleRateBytes, 10);
  15326. if (sampleRate <= 1)
  15327. {
  15328. sampleRateBytes[0] = 0x3f;
  15329. sampleRateBytes[1] = 0xff;
  15330. sampleRateBytes[2] = 0x80;
  15331. }
  15332. else
  15333. {
  15334. int mask = 0x40000000;
  15335. sampleRateBytes[0] = 0x40;
  15336. if (sampleRate >= mask)
  15337. {
  15338. jassertfalse
  15339. sampleRateBytes[1] = 0x1d;
  15340. }
  15341. else
  15342. {
  15343. int n = (int) sampleRate;
  15344. int i;
  15345. for (i = 0; i <= 32 ; ++i)
  15346. {
  15347. if ((n & mask) != 0)
  15348. break;
  15349. mask >>= 1;
  15350. }
  15351. n = n << (i + 1);
  15352. sampleRateBytes[1] = (uint8) (29 - i);
  15353. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15354. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15355. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15356. sampleRateBytes[5] = (uint8) (n & 0xff);
  15357. }
  15358. }
  15359. output->write (sampleRateBytes, 10);
  15360. output->writeInt (chunkName ("SSND"));
  15361. output->writeIntBigEndian (audioBytes + 8);
  15362. output->writeInt (0);
  15363. output->writeInt (0);
  15364. jassert (output->getPosition() == headerLen);
  15365. }
  15366. public:
  15367. AiffAudioFormatWriter (OutputStream* out,
  15368. const double sampleRate_,
  15369. const unsigned int chans,
  15370. const int bits)
  15371. : AudioFormatWriter (out,
  15372. TRANS (aiffFormatName),
  15373. sampleRate_,
  15374. chans,
  15375. bits),
  15376. lengthInSamples (0),
  15377. bytesWritten (0),
  15378. writeFailed (false)
  15379. {
  15380. headerPosition = out->getPosition();
  15381. writeHeader();
  15382. }
  15383. ~AiffAudioFormatWriter()
  15384. {
  15385. if ((bytesWritten & 1) != 0)
  15386. output->writeByte (0);
  15387. writeHeader();
  15388. }
  15389. bool write (const int** data, int numSamples)
  15390. {
  15391. if (writeFailed)
  15392. return false;
  15393. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15394. tempBlock.ensureSize (bytes, false);
  15395. char* buffer = static_cast <char*> (tempBlock.getData());
  15396. const int* left = data[0];
  15397. const int* right = data[1];
  15398. if (right == 0)
  15399. right = left;
  15400. if (bitsPerSample == 16)
  15401. {
  15402. short* b = reinterpret_cast <short*> (buffer);
  15403. if (numChannels > 1)
  15404. {
  15405. for (int i = numSamples; --i >= 0;)
  15406. {
  15407. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15408. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15409. }
  15410. }
  15411. else
  15412. {
  15413. for (int i = numSamples; --i >= 0;)
  15414. {
  15415. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15416. }
  15417. }
  15418. }
  15419. else if (bitsPerSample == 24)
  15420. {
  15421. char* b = buffer;
  15422. if (numChannels > 1)
  15423. {
  15424. for (int i = numSamples; --i >= 0;)
  15425. {
  15426. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15427. b += 3;
  15428. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15429. b += 3;
  15430. }
  15431. }
  15432. else
  15433. {
  15434. for (int i = numSamples; --i >= 0;)
  15435. {
  15436. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15437. b += 3;
  15438. }
  15439. }
  15440. }
  15441. else if (bitsPerSample == 32)
  15442. {
  15443. uint32* b = reinterpret_cast <uint32*> (buffer);
  15444. if (numChannels > 1)
  15445. {
  15446. for (int i = numSamples; --i >= 0;)
  15447. {
  15448. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15449. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15450. }
  15451. }
  15452. else
  15453. {
  15454. for (int i = numSamples; --i >= 0;)
  15455. {
  15456. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15457. }
  15458. }
  15459. }
  15460. else if (bitsPerSample == 8)
  15461. {
  15462. char* b = buffer;
  15463. if (numChannels > 1)
  15464. {
  15465. for (int i = numSamples; --i >= 0;)
  15466. {
  15467. *b++ = (char) (*left++ >> 24);
  15468. *b++ = (char) (*right++ >> 24);
  15469. }
  15470. }
  15471. else
  15472. {
  15473. for (int i = numSamples; --i >= 0;)
  15474. {
  15475. *b++ = (char) (*left++ >> 24);
  15476. }
  15477. }
  15478. }
  15479. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15480. || ! output->write (buffer, bytes))
  15481. {
  15482. // failed to write to disk, so let's try writing the header.
  15483. // If it's just run out of disk space, then if it does manage
  15484. // to write the header, we'll still have a useable file..
  15485. writeHeader();
  15486. writeFailed = true;
  15487. return false;
  15488. }
  15489. else
  15490. {
  15491. bytesWritten += bytes;
  15492. lengthInSamples += numSamples;
  15493. return true;
  15494. }
  15495. }
  15496. juce_UseDebuggingNewOperator
  15497. };
  15498. AiffAudioFormat::AiffAudioFormat()
  15499. : AudioFormat (TRANS (aiffFormatName), (const juce_wchar**) aiffExtensions)
  15500. {
  15501. }
  15502. AiffAudioFormat::~AiffAudioFormat()
  15503. {
  15504. }
  15505. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15506. {
  15507. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15508. return Array <int> (rates);
  15509. }
  15510. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15511. {
  15512. const int depths[] = { 8, 16, 24, 0 };
  15513. return Array <int> (depths);
  15514. }
  15515. bool AiffAudioFormat::canDoStereo()
  15516. {
  15517. return true;
  15518. }
  15519. bool AiffAudioFormat::canDoMono()
  15520. {
  15521. return true;
  15522. }
  15523. #if JUCE_MAC
  15524. bool AiffAudioFormat::canHandleFile (const File& f)
  15525. {
  15526. if (AudioFormat::canHandleFile (f))
  15527. return true;
  15528. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15529. return type == 'AIFF' || type == 'AIFC'
  15530. || type == 'aiff' || type == 'aifc';
  15531. }
  15532. #endif
  15533. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15534. const bool deleteStreamIfOpeningFails)
  15535. {
  15536. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15537. if (w->sampleRate != 0)
  15538. return w.release();
  15539. if (! deleteStreamIfOpeningFails)
  15540. w->input = 0;
  15541. return 0;
  15542. }
  15543. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15544. double sampleRate,
  15545. unsigned int chans,
  15546. int bitsPerSample,
  15547. const StringPairArray& /*metadataValues*/,
  15548. int /*qualityOptionIndex*/)
  15549. {
  15550. if (getPossibleBitDepths().contains (bitsPerSample))
  15551. {
  15552. return new AiffAudioFormatWriter (out,
  15553. sampleRate,
  15554. chans,
  15555. bitsPerSample);
  15556. }
  15557. return 0;
  15558. }
  15559. END_JUCE_NAMESPACE
  15560. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15561. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15562. BEGIN_JUCE_NAMESPACE
  15563. #if JUCE_MAC && JUCE_USE_CDREADER
  15564. // Mac version doesn't need any native code because it's all done with files..
  15565. // Windows + Linux versions are in the platform-dependent code sections.
  15566. static void findCDs (Array<File>& cds)
  15567. {
  15568. File volumes ("/Volumes");
  15569. volumes.findChildFiles (cds, File::findDirectories, false);
  15570. for (int i = cds.size(); --i >= 0;)
  15571. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15572. cds.remove (i);
  15573. }
  15574. const StringArray AudioCDReader::getAvailableCDNames()
  15575. {
  15576. Array<File> cds;
  15577. findCDs (cds);
  15578. StringArray names;
  15579. for (int i = 0; i < cds.size(); ++i)
  15580. names.add (cds.getReference(i).getFileName());
  15581. return names;
  15582. }
  15583. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15584. {
  15585. Array<File> cds;
  15586. findCDs (cds);
  15587. if (cds[index] != File::nonexistent)
  15588. return new AudioCDReader (cds[index]);
  15589. else
  15590. return 0;
  15591. }
  15592. AudioCDReader::AudioCDReader (const File& volume)
  15593. : AudioFormatReader (0, "CD Audio"),
  15594. volumeDir (volume),
  15595. currentReaderTrack (-1),
  15596. reader (0)
  15597. {
  15598. sampleRate = 44100.0;
  15599. bitsPerSample = 16;
  15600. numChannels = 2;
  15601. usesFloatingPointData = false;
  15602. refreshTrackLengths();
  15603. }
  15604. AudioCDReader::~AudioCDReader()
  15605. {
  15606. }
  15607. static int getTrackNumber (const File& file)
  15608. {
  15609. return file.getFileName()
  15610. .initialSectionContainingOnly ("0123456789")
  15611. .getIntValue();
  15612. }
  15613. int AudioCDReader::compareElements (const File& first, const File& second)
  15614. {
  15615. const int firstTrack = getTrackNumber (first);
  15616. const int secondTrack = getTrackNumber (second);
  15617. jassert (firstTrack > 0 && secondTrack > 0);
  15618. return firstTrack - secondTrack;
  15619. }
  15620. void AudioCDReader::refreshTrackLengths()
  15621. {
  15622. tracks.clear();
  15623. trackStartSamples.clear();
  15624. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, "*.aiff");
  15625. tracks.sort (*this);
  15626. AiffAudioFormat format;
  15627. int sample = 0;
  15628. for (int i = 0; i < tracks.size(); ++i)
  15629. {
  15630. trackStartSamples.add (sample);
  15631. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15632. if (in != 0)
  15633. {
  15634. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15635. if (r != 0)
  15636. sample += (int) r->lengthInSamples;
  15637. }
  15638. }
  15639. trackStartSamples.add (sample);
  15640. lengthInSamples = sample;
  15641. }
  15642. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15643. int64 startSampleInFile, int numSamples)
  15644. {
  15645. while (numSamples > 0)
  15646. {
  15647. int track = -1;
  15648. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15649. {
  15650. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15651. {
  15652. track = i;
  15653. break;
  15654. }
  15655. }
  15656. if (track < 0)
  15657. return false;
  15658. if (track != currentReaderTrack)
  15659. {
  15660. reader = 0;
  15661. FileInputStream* const in = tracks [track].createInputStream();
  15662. if (in != 0)
  15663. {
  15664. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15665. AiffAudioFormat format;
  15666. reader = format.createReaderFor (bin, true);
  15667. if (reader == 0)
  15668. currentReaderTrack = -1;
  15669. else
  15670. currentReaderTrack = track;
  15671. }
  15672. }
  15673. if (reader == 0)
  15674. return false;
  15675. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15676. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15677. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15678. numSamples -= numAvailable;
  15679. startSampleInFile += numAvailable;
  15680. }
  15681. return true;
  15682. }
  15683. bool AudioCDReader::isCDStillPresent() const
  15684. {
  15685. return volumeDir.exists();
  15686. }
  15687. int AudioCDReader::getNumTracks() const
  15688. {
  15689. return tracks.size();
  15690. }
  15691. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15692. {
  15693. return trackStartSamples [trackNum];
  15694. }
  15695. bool AudioCDReader::isTrackAudio (int trackNum) const
  15696. {
  15697. return tracks [trackNum] != File::nonexistent;
  15698. }
  15699. void AudioCDReader::enableIndexScanning (bool b)
  15700. {
  15701. // any way to do this on a Mac??
  15702. }
  15703. int AudioCDReader::getLastIndex() const
  15704. {
  15705. return 0;
  15706. }
  15707. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15708. {
  15709. return Array <int>();
  15710. }
  15711. int AudioCDReader::getCDDBId()
  15712. {
  15713. return 0; //xxx
  15714. }
  15715. #endif
  15716. END_JUCE_NAMESPACE
  15717. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15718. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15719. BEGIN_JUCE_NAMESPACE
  15720. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15721. const String& formatName_)
  15722. : sampleRate (0),
  15723. bitsPerSample (0),
  15724. lengthInSamples (0),
  15725. numChannels (0),
  15726. usesFloatingPointData (false),
  15727. input (in),
  15728. formatName (formatName_)
  15729. {
  15730. }
  15731. AudioFormatReader::~AudioFormatReader()
  15732. {
  15733. delete input;
  15734. }
  15735. bool AudioFormatReader::read (int** destSamples,
  15736. int numDestChannels,
  15737. int64 startSampleInSource,
  15738. int numSamplesToRead,
  15739. const bool fillLeftoverChannelsWithCopies)
  15740. {
  15741. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  15742. int startOffsetInDestBuffer = 0;
  15743. if (startSampleInSource < 0)
  15744. {
  15745. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  15746. for (int i = numDestChannels; --i >= 0;)
  15747. if (destSamples[i] != 0)
  15748. zeromem (destSamples[i], sizeof (int) * silence);
  15749. startOffsetInDestBuffer += silence;
  15750. numSamplesToRead -= silence;
  15751. startSampleInSource = 0;
  15752. }
  15753. if (numSamplesToRead <= 0)
  15754. return true;
  15755. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  15756. startSampleInSource, numSamplesToRead))
  15757. return false;
  15758. if (numDestChannels > (int) numChannels)
  15759. {
  15760. if (fillLeftoverChannelsWithCopies)
  15761. {
  15762. int* lastFullChannel = destSamples[0];
  15763. for (int i = numDestChannels; --i > 0;)
  15764. {
  15765. if (destSamples[i] != 0)
  15766. {
  15767. lastFullChannel = destSamples[i];
  15768. break;
  15769. }
  15770. }
  15771. if (lastFullChannel != 0)
  15772. for (int i = numChannels; i < numDestChannels; ++i)
  15773. if (destSamples[i] != 0)
  15774. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  15775. }
  15776. else
  15777. {
  15778. for (int i = numChannels; i < numDestChannels; ++i)
  15779. if (destSamples[i] != 0)
  15780. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  15781. }
  15782. }
  15783. return true;
  15784. }
  15785. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  15786. {
  15787. float mn = buffer[0];
  15788. float mx = mn;
  15789. for (int i = 1; i < num; ++i)
  15790. {
  15791. const float s = buffer[i];
  15792. if (s > mx) mx = s;
  15793. if (s < mn) mn = s;
  15794. }
  15795. maxVal = mx;
  15796. minVal = mn;
  15797. }
  15798. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  15799. int64 numSamples,
  15800. float& lowestLeft, float& highestLeft,
  15801. float& lowestRight, float& highestRight)
  15802. {
  15803. if (numSamples <= 0)
  15804. {
  15805. lowestLeft = 0;
  15806. lowestRight = 0;
  15807. highestLeft = 0;
  15808. highestRight = 0;
  15809. return;
  15810. }
  15811. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  15812. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15813. int* tempBuffer[3];
  15814. tempBuffer[0] = (int*) tempSpace.getData();
  15815. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15816. tempBuffer[2] = 0;
  15817. if (usesFloatingPointData)
  15818. {
  15819. float lmin = 1.0e6f;
  15820. float lmax = -lmin;
  15821. float rmin = lmin;
  15822. float rmax = lmax;
  15823. while (numSamples > 0)
  15824. {
  15825. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15826. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15827. numSamples -= numToDo;
  15828. startSampleInFile += numToDo;
  15829. float bufmin, bufmax;
  15830. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  15831. lmin = jmin (lmin, bufmin);
  15832. lmax = jmax (lmax, bufmax);
  15833. if (numChannels > 1)
  15834. {
  15835. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  15836. rmin = jmin (rmin, bufmin);
  15837. rmax = jmax (rmax, bufmax);
  15838. }
  15839. }
  15840. if (numChannels <= 1)
  15841. {
  15842. rmax = lmax;
  15843. rmin = lmin;
  15844. }
  15845. lowestLeft = lmin;
  15846. highestLeft = lmax;
  15847. lowestRight = rmin;
  15848. highestRight = rmax;
  15849. }
  15850. else
  15851. {
  15852. int lmax = std::numeric_limits<int>::min();
  15853. int lmin = std::numeric_limits<int>::max();
  15854. int rmax = std::numeric_limits<int>::min();
  15855. int rmin = std::numeric_limits<int>::max();
  15856. while (numSamples > 0)
  15857. {
  15858. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  15859. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  15860. numSamples -= numToDo;
  15861. startSampleInFile += numToDo;
  15862. for (int j = numChannels; --j >= 0;)
  15863. {
  15864. int bufMax = std::numeric_limits<int>::min();
  15865. int bufMin = std::numeric_limits<int>::max();
  15866. const int* const b = tempBuffer[j];
  15867. for (int i = 0; i < numToDo; ++i)
  15868. {
  15869. const int samp = b[i];
  15870. if (samp < bufMin)
  15871. bufMin = samp;
  15872. if (samp > bufMax)
  15873. bufMax = samp;
  15874. }
  15875. if (j == 0)
  15876. {
  15877. lmax = jmax (lmax, bufMax);
  15878. lmin = jmin (lmin, bufMin);
  15879. }
  15880. else
  15881. {
  15882. rmax = jmax (rmax, bufMax);
  15883. rmin = jmin (rmin, bufMin);
  15884. }
  15885. }
  15886. }
  15887. if (numChannels <= 1)
  15888. {
  15889. rmax = lmax;
  15890. rmin = lmin;
  15891. }
  15892. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  15893. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  15894. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  15895. highestRight = rmax / (float) std::numeric_limits<int>::max();
  15896. }
  15897. }
  15898. int64 AudioFormatReader::searchForLevel (int64 startSample,
  15899. int64 numSamplesToSearch,
  15900. const double magnitudeRangeMinimum,
  15901. const double magnitudeRangeMaximum,
  15902. const int minimumConsecutiveSamples)
  15903. {
  15904. if (numSamplesToSearch == 0)
  15905. return -1;
  15906. const int bufferSize = 4096;
  15907. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  15908. int* tempBuffer[3];
  15909. tempBuffer[0] = (int*) tempSpace.getData();
  15910. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  15911. tempBuffer[2] = 0;
  15912. int consecutive = 0;
  15913. int64 firstMatchPos = -1;
  15914. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  15915. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  15916. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  15917. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  15918. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  15919. while (numSamplesToSearch != 0)
  15920. {
  15921. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  15922. int64 bufferStart = startSample;
  15923. if (numSamplesToSearch < 0)
  15924. bufferStart -= numThisTime;
  15925. if (bufferStart >= (int) lengthInSamples)
  15926. break;
  15927. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  15928. int num = numThisTime;
  15929. while (--num >= 0)
  15930. {
  15931. if (numSamplesToSearch < 0)
  15932. --startSample;
  15933. bool matches = false;
  15934. const int index = (int) (startSample - bufferStart);
  15935. if (usesFloatingPointData)
  15936. {
  15937. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  15938. if (sample1 >= magnitudeRangeMinimum
  15939. && sample1 <= magnitudeRangeMaximum)
  15940. {
  15941. matches = true;
  15942. }
  15943. else if (numChannels > 1)
  15944. {
  15945. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  15946. matches = (sample2 >= magnitudeRangeMinimum
  15947. && sample2 <= magnitudeRangeMaximum);
  15948. }
  15949. }
  15950. else
  15951. {
  15952. const int sample1 = abs (tempBuffer[0] [index]);
  15953. if (sample1 >= intMagnitudeRangeMinimum
  15954. && sample1 <= intMagnitudeRangeMaximum)
  15955. {
  15956. matches = true;
  15957. }
  15958. else if (numChannels > 1)
  15959. {
  15960. const int sample2 = abs (tempBuffer[1][index]);
  15961. matches = (sample2 >= intMagnitudeRangeMinimum
  15962. && sample2 <= intMagnitudeRangeMaximum);
  15963. }
  15964. }
  15965. if (matches)
  15966. {
  15967. if (firstMatchPos < 0)
  15968. firstMatchPos = startSample;
  15969. if (++consecutive >= minimumConsecutiveSamples)
  15970. {
  15971. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  15972. return -1;
  15973. return firstMatchPos;
  15974. }
  15975. }
  15976. else
  15977. {
  15978. consecutive = 0;
  15979. firstMatchPos = -1;
  15980. }
  15981. if (numSamplesToSearch > 0)
  15982. ++startSample;
  15983. }
  15984. if (numSamplesToSearch > 0)
  15985. numSamplesToSearch -= numThisTime;
  15986. else
  15987. numSamplesToSearch += numThisTime;
  15988. }
  15989. return -1;
  15990. }
  15991. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  15992. const String& formatName_,
  15993. const double rate,
  15994. const unsigned int numChannels_,
  15995. const unsigned int bitsPerSample_)
  15996. : sampleRate (rate),
  15997. numChannels (numChannels_),
  15998. bitsPerSample (bitsPerSample_),
  15999. usesFloatingPointData (false),
  16000. output (out),
  16001. formatName (formatName_)
  16002. {
  16003. }
  16004. AudioFormatWriter::~AudioFormatWriter()
  16005. {
  16006. delete output;
  16007. }
  16008. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16009. int64 startSample,
  16010. int64 numSamplesToRead)
  16011. {
  16012. const int bufferSize = 16384;
  16013. const int maxChans = 128;
  16014. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16015. int* buffers [maxChans];
  16016. for (int i = maxChans; --i >= 0;)
  16017. buffers[i] = 0;
  16018. if (numSamplesToRead < 0)
  16019. numSamplesToRead = reader.lengthInSamples;
  16020. while (numSamplesToRead > 0)
  16021. {
  16022. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16023. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16024. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16025. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16026. return false;
  16027. if (reader.usesFloatingPointData != isFloatingPoint())
  16028. {
  16029. int** bufferChan = buffers;
  16030. while (*bufferChan != 0)
  16031. {
  16032. int* b = *bufferChan++;
  16033. if (isFloatingPoint())
  16034. {
  16035. // int -> float
  16036. const double factor = 1.0 / std::numeric_limits<int>::max();
  16037. for (int i = 0; i < numToDo; ++i)
  16038. ((float*) b)[i] = (float) (factor * b[i]);
  16039. }
  16040. else
  16041. {
  16042. // float -> int
  16043. for (int i = 0; i < numToDo; ++i)
  16044. {
  16045. const double samp = *(const float*) b;
  16046. if (samp <= -1.0)
  16047. *b++ = std::numeric_limits<int>::min();
  16048. else if (samp >= 1.0)
  16049. *b++ = std::numeric_limits<int>::max();
  16050. else
  16051. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16052. }
  16053. }
  16054. }
  16055. }
  16056. if (! write ((const int**) buffers, numToDo))
  16057. return false;
  16058. numSamplesToRead -= numToDo;
  16059. startSample += numToDo;
  16060. }
  16061. return true;
  16062. }
  16063. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16064. int numSamplesToRead,
  16065. const int samplesPerBlock)
  16066. {
  16067. const int maxChans = 128;
  16068. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16069. int* buffers [maxChans];
  16070. while (numSamplesToRead > 0)
  16071. {
  16072. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16073. AudioSourceChannelInfo info;
  16074. info.buffer = &tempBuffer;
  16075. info.startSample = 0;
  16076. info.numSamples = numToDo;
  16077. info.clearActiveBufferRegion();
  16078. source.getNextAudioBlock (info);
  16079. int i;
  16080. for (i = maxChans; --i >= 0;)
  16081. buffers[i] = 0;
  16082. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16083. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16084. if (! isFloatingPoint())
  16085. {
  16086. int** bufferChan = buffers;
  16087. while (*bufferChan != 0)
  16088. {
  16089. int* b = *bufferChan++;
  16090. // float -> int
  16091. for (int j = numToDo; --j >= 0;)
  16092. {
  16093. const double samp = *(const float*) b;
  16094. if (samp <= -1.0)
  16095. *b++ = std::numeric_limits<int>::min();
  16096. else if (samp >= 1.0)
  16097. *b++ = std::numeric_limits<int>::max();
  16098. else
  16099. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16100. }
  16101. }
  16102. }
  16103. if (! write ((const int**) buffers, numToDo))
  16104. return false;
  16105. numSamplesToRead -= numToDo;
  16106. }
  16107. return true;
  16108. }
  16109. AudioFormat::AudioFormat (const String& name,
  16110. const juce_wchar** const extensions)
  16111. : formatName (name),
  16112. fileExtensions (extensions)
  16113. {
  16114. }
  16115. AudioFormat::~AudioFormat()
  16116. {
  16117. }
  16118. const String& AudioFormat::getFormatName() const
  16119. {
  16120. return formatName;
  16121. }
  16122. const StringArray& AudioFormat::getFileExtensions() const
  16123. {
  16124. return fileExtensions;
  16125. }
  16126. bool AudioFormat::canHandleFile (const File& f)
  16127. {
  16128. for (int i = 0; i < fileExtensions.size(); ++i)
  16129. if (f.hasFileExtension (fileExtensions[i]))
  16130. return true;
  16131. return false;
  16132. }
  16133. bool AudioFormat::isCompressed()
  16134. {
  16135. return false;
  16136. }
  16137. const StringArray AudioFormat::getQualityOptions()
  16138. {
  16139. return StringArray();
  16140. }
  16141. END_JUCE_NAMESPACE
  16142. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16143. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16144. BEGIN_JUCE_NAMESPACE
  16145. AudioFormatManager::AudioFormatManager()
  16146. : defaultFormatIndex (0)
  16147. {
  16148. }
  16149. AudioFormatManager::~AudioFormatManager()
  16150. {
  16151. clearFormats();
  16152. clearSingletonInstance();
  16153. }
  16154. juce_ImplementSingleton (AudioFormatManager);
  16155. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16156. const bool makeThisTheDefaultFormat)
  16157. {
  16158. jassert (newFormat != 0);
  16159. if (newFormat != 0)
  16160. {
  16161. #ifdef JUCE_DEBUG
  16162. for (int i = getNumKnownFormats(); --i >= 0;)
  16163. {
  16164. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16165. {
  16166. jassertfalse // trying to add the same format twice!
  16167. }
  16168. }
  16169. #endif
  16170. if (makeThisTheDefaultFormat)
  16171. defaultFormatIndex = knownFormats.size();
  16172. knownFormats.add (newFormat);
  16173. }
  16174. }
  16175. void AudioFormatManager::registerBasicFormats()
  16176. {
  16177. #if JUCE_MAC
  16178. registerFormat (new AiffAudioFormat(), true);
  16179. registerFormat (new WavAudioFormat(), false);
  16180. #else
  16181. registerFormat (new WavAudioFormat(), true);
  16182. registerFormat (new AiffAudioFormat(), false);
  16183. #endif
  16184. #if JUCE_USE_FLAC
  16185. registerFormat (new FlacAudioFormat(), false);
  16186. #endif
  16187. #if JUCE_USE_OGGVORBIS
  16188. registerFormat (new OggVorbisAudioFormat(), false);
  16189. #endif
  16190. }
  16191. void AudioFormatManager::clearFormats()
  16192. {
  16193. for (int i = getNumKnownFormats(); --i >= 0;)
  16194. delete getKnownFormat(i);
  16195. knownFormats.clear();
  16196. defaultFormatIndex = 0;
  16197. }
  16198. int AudioFormatManager::getNumKnownFormats() const
  16199. {
  16200. return knownFormats.size();
  16201. }
  16202. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16203. {
  16204. return (AudioFormat*) knownFormats [index];
  16205. }
  16206. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16207. {
  16208. return getKnownFormat (defaultFormatIndex);
  16209. }
  16210. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16211. {
  16212. String e (fileExtension);
  16213. if (! e.startsWithChar ('.'))
  16214. e = "." + e;
  16215. for (int i = 0; i < getNumKnownFormats(); ++i)
  16216. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16217. return getKnownFormat(i);
  16218. return 0;
  16219. }
  16220. const String AudioFormatManager::getWildcardForAllFormats() const
  16221. {
  16222. StringArray allExtensions;
  16223. int i;
  16224. for (i = 0; i < getNumKnownFormats(); ++i)
  16225. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16226. allExtensions.trim();
  16227. allExtensions.removeEmptyStrings();
  16228. String s;
  16229. for (i = 0; i < allExtensions.size(); ++i)
  16230. {
  16231. s << '*';
  16232. if (! allExtensions[i].startsWithChar ('.'))
  16233. s << '.';
  16234. s << allExtensions[i];
  16235. if (i < allExtensions.size() - 1)
  16236. s << ';';
  16237. }
  16238. return s;
  16239. }
  16240. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16241. {
  16242. // you need to actually register some formats before the manager can
  16243. // use them to open a file!
  16244. jassert (knownFormats.size() > 0);
  16245. for (int i = 0; i < getNumKnownFormats(); ++i)
  16246. {
  16247. AudioFormat* const af = getKnownFormat(i);
  16248. if (af->canHandleFile (file))
  16249. {
  16250. InputStream* const in = file.createInputStream();
  16251. if (in != 0)
  16252. {
  16253. AudioFormatReader* const r = af->createReaderFor (in, true);
  16254. if (r != 0)
  16255. return r;
  16256. }
  16257. }
  16258. }
  16259. return 0;
  16260. }
  16261. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16262. {
  16263. // you need to actually register some formats before the manager can
  16264. // use them to open a file!
  16265. jassert (knownFormats.size() > 0);
  16266. ScopedPointer <InputStream> in (audioFileStream);
  16267. if (in != 0)
  16268. {
  16269. const int64 originalStreamPos = in->getPosition();
  16270. for (int i = 0; i < getNumKnownFormats(); ++i)
  16271. {
  16272. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16273. if (r != 0)
  16274. {
  16275. in.release();
  16276. return r;
  16277. }
  16278. in->setPosition (originalStreamPos);
  16279. // the stream that is passed-in must be capable of being repositioned so
  16280. // that all the formats can have a go at opening it.
  16281. jassert (in->getPosition() == originalStreamPos);
  16282. }
  16283. }
  16284. return 0;
  16285. }
  16286. END_JUCE_NAMESPACE
  16287. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16288. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16289. BEGIN_JUCE_NAMESPACE
  16290. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16291. const int64 startSample_,
  16292. const int64 length_,
  16293. const bool deleteSourceWhenDeleted_)
  16294. : AudioFormatReader (0, source_->getFormatName()),
  16295. source (source_),
  16296. startSample (startSample_),
  16297. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16298. {
  16299. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16300. sampleRate = source->sampleRate;
  16301. bitsPerSample = source->bitsPerSample;
  16302. lengthInSamples = length;
  16303. numChannels = source->numChannels;
  16304. usesFloatingPointData = source->usesFloatingPointData;
  16305. }
  16306. AudioSubsectionReader::~AudioSubsectionReader()
  16307. {
  16308. if (deleteSourceWhenDeleted)
  16309. delete source;
  16310. }
  16311. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16312. int64 startSampleInFile, int numSamples)
  16313. {
  16314. if (startSampleInFile + numSamples > length)
  16315. {
  16316. for (int i = numDestChannels; --i >= 0;)
  16317. if (destSamples[i] != 0)
  16318. zeromem (destSamples[i], sizeof (int) * numSamples);
  16319. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16320. if (numSamples <= 0)
  16321. return true;
  16322. }
  16323. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16324. startSampleInFile + startSample, numSamples);
  16325. }
  16326. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16327. int64 numSamples,
  16328. float& lowestLeft,
  16329. float& highestLeft,
  16330. float& lowestRight,
  16331. float& highestRight)
  16332. {
  16333. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16334. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16335. source->readMaxLevels (startSampleInFile + startSample,
  16336. numSamples,
  16337. lowestLeft,
  16338. highestLeft,
  16339. lowestRight,
  16340. highestRight);
  16341. }
  16342. END_JUCE_NAMESPACE
  16343. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16344. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16345. BEGIN_JUCE_NAMESPACE
  16346. const int timeBeforeDeletingReader = 2000;
  16347. struct AudioThumbnailDataFormat
  16348. {
  16349. char thumbnailMagic[4];
  16350. int samplesPerThumbSample;
  16351. int64 totalSamples; // source samples
  16352. int64 numFinishedSamples; // source samples
  16353. int numThumbnailSamples;
  16354. int numChannels;
  16355. int sampleRate;
  16356. char future[16];
  16357. char data[1];
  16358. void swapEndiannessIfNeeded() throw()
  16359. {
  16360. #if JUCE_BIG_ENDIAN
  16361. flip (samplesPerThumbSample);
  16362. flip (totalSamples);
  16363. flip (numFinishedSamples);
  16364. flip (numThumbnailSamples);
  16365. flip (numChannels);
  16366. flip (sampleRate);
  16367. #endif
  16368. }
  16369. private:
  16370. #if JUCE_BIG_ENDIAN
  16371. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16372. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16373. #endif
  16374. };
  16375. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16376. AudioFormatManager& formatManagerToUse_,
  16377. AudioThumbnailCache& cacheToUse)
  16378. : formatManagerToUse (formatManagerToUse_),
  16379. cache (cacheToUse),
  16380. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16381. {
  16382. clear();
  16383. }
  16384. AudioThumbnail::~AudioThumbnail()
  16385. {
  16386. cache.removeThumbnail (this);
  16387. const ScopedLock sl (readerLock);
  16388. reader = 0;
  16389. }
  16390. void AudioThumbnail::setSource (InputSource* const newSource)
  16391. {
  16392. cache.removeThumbnail (this);
  16393. timerCallback(); // stops the timer and deletes the reader
  16394. source = newSource;
  16395. clear();
  16396. if (newSource != 0
  16397. && ! (cache.loadThumb (*this, newSource->hashCode())
  16398. && isFullyLoaded()))
  16399. {
  16400. {
  16401. const ScopedLock sl (readerLock);
  16402. reader = createReader();
  16403. }
  16404. if (reader != 0)
  16405. {
  16406. initialiseFromAudioFile (*reader);
  16407. cache.addThumbnail (this);
  16408. }
  16409. }
  16410. sendChangeMessage (this);
  16411. }
  16412. bool AudioThumbnail::useTimeSlice()
  16413. {
  16414. const ScopedLock sl (readerLock);
  16415. if (isFullyLoaded())
  16416. {
  16417. if (reader != 0)
  16418. startTimer (timeBeforeDeletingReader);
  16419. cache.removeThumbnail (this);
  16420. return false;
  16421. }
  16422. if (reader == 0)
  16423. reader = createReader();
  16424. if (reader != 0)
  16425. {
  16426. readNextBlockFromAudioFile (*reader);
  16427. stopTimer();
  16428. sendChangeMessage (this);
  16429. const bool justFinished = isFullyLoaded();
  16430. if (justFinished)
  16431. cache.storeThumb (*this, source->hashCode());
  16432. return ! justFinished;
  16433. }
  16434. return false;
  16435. }
  16436. AudioFormatReader* AudioThumbnail::createReader() const
  16437. {
  16438. if (source != 0)
  16439. {
  16440. InputStream* const audioFileStream = source->createInputStream();
  16441. if (audioFileStream != 0)
  16442. return formatManagerToUse.createReaderFor (audioFileStream);
  16443. }
  16444. return 0;
  16445. }
  16446. void AudioThumbnail::timerCallback()
  16447. {
  16448. stopTimer();
  16449. const ScopedLock sl (readerLock);
  16450. reader = 0;
  16451. }
  16452. void AudioThumbnail::clear()
  16453. {
  16454. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16455. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16456. d->thumbnailMagic[0] = 'j';
  16457. d->thumbnailMagic[1] = 'a';
  16458. d->thumbnailMagic[2] = 't';
  16459. d->thumbnailMagic[3] = 'm';
  16460. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16461. d->totalSamples = 0;
  16462. d->numFinishedSamples = 0;
  16463. d->numThumbnailSamples = 0;
  16464. d->numChannels = 0;
  16465. d->sampleRate = 0;
  16466. numSamplesCached = 0;
  16467. cacheNeedsRefilling = true;
  16468. }
  16469. void AudioThumbnail::loadFrom (InputStream& input)
  16470. {
  16471. const ScopedLock sl (readerLock);
  16472. data.setSize (0);
  16473. input.readIntoMemoryBlock (data);
  16474. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16475. d->swapEndiannessIfNeeded();
  16476. if (! (d->thumbnailMagic[0] == 'j'
  16477. && d->thumbnailMagic[1] == 'a'
  16478. && d->thumbnailMagic[2] == 't'
  16479. && d->thumbnailMagic[3] == 'm'))
  16480. {
  16481. clear();
  16482. }
  16483. numSamplesCached = 0;
  16484. cacheNeedsRefilling = true;
  16485. }
  16486. void AudioThumbnail::saveTo (OutputStream& output) const
  16487. {
  16488. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16489. d->swapEndiannessIfNeeded();
  16490. output.write (data.getData(), (int) data.getSize());
  16491. d->swapEndiannessIfNeeded();
  16492. }
  16493. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16494. {
  16495. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16496. d->totalSamples = fileReader.lengthInSamples;
  16497. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16498. d->numFinishedSamples = 0;
  16499. d->sampleRate = roundToInt (fileReader.sampleRate);
  16500. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16501. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16502. d = (AudioThumbnailDataFormat*) data.getData();
  16503. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16504. return d->totalSamples > 0;
  16505. }
  16506. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16507. {
  16508. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16509. if (d->numFinishedSamples < d->totalSamples)
  16510. {
  16511. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16512. generateSection (fileReader,
  16513. d->numFinishedSamples,
  16514. numToDo);
  16515. d->numFinishedSamples += numToDo;
  16516. }
  16517. cacheNeedsRefilling = true;
  16518. return (d->numFinishedSamples < d->totalSamples);
  16519. }
  16520. int AudioThumbnail::getNumChannels() const throw()
  16521. {
  16522. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16523. jassert (d != 0);
  16524. return d->numChannels;
  16525. }
  16526. double AudioThumbnail::getTotalLength() const throw()
  16527. {
  16528. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16529. jassert (d != 0);
  16530. if (d->sampleRate > 0)
  16531. return d->totalSamples / (double)d->sampleRate;
  16532. else
  16533. return 0.0;
  16534. }
  16535. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16536. int64 startSample,
  16537. int numSamples)
  16538. {
  16539. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16540. jassert (d != 0);
  16541. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16542. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16543. char* l = getChannelData (0);
  16544. char* r = getChannelData (1);
  16545. for (int i = firstDataPos; i < lastDataPos; ++i)
  16546. {
  16547. const int sourceStart = i * d->samplesPerThumbSample;
  16548. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16549. float lowestLeft, highestLeft, lowestRight, highestRight;
  16550. fileReader.readMaxLevels (sourceStart,
  16551. sourceEnd - sourceStart,
  16552. lowestLeft,
  16553. highestLeft,
  16554. lowestRight,
  16555. highestRight);
  16556. int n = i * 2;
  16557. if (r != 0)
  16558. {
  16559. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16560. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16561. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16562. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16563. }
  16564. else
  16565. {
  16566. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16567. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16568. }
  16569. }
  16570. }
  16571. char* AudioThumbnail::getChannelData (int channel) const
  16572. {
  16573. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16574. jassert (d != 0);
  16575. if (channel >= 0 && channel < d->numChannels)
  16576. return d->data + (channel * 2 * d->numThumbnailSamples);
  16577. return 0;
  16578. }
  16579. bool AudioThumbnail::isFullyLoaded() const throw()
  16580. {
  16581. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16582. jassert (d != 0);
  16583. return d->numFinishedSamples >= d->totalSamples;
  16584. }
  16585. void AudioThumbnail::refillCache (const int numSamples,
  16586. double startTime,
  16587. const double timePerPixel)
  16588. {
  16589. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16590. jassert (d != 0);
  16591. if (numSamples <= 0
  16592. || timePerPixel <= 0.0
  16593. || d->sampleRate <= 0)
  16594. {
  16595. numSamplesCached = 0;
  16596. cacheNeedsRefilling = true;
  16597. return;
  16598. }
  16599. if (numSamples == numSamplesCached
  16600. && numChannelsCached == d->numChannels
  16601. && startTime == cachedStart
  16602. && timePerPixel == cachedTimePerPixel
  16603. && ! cacheNeedsRefilling)
  16604. {
  16605. return;
  16606. }
  16607. numSamplesCached = numSamples;
  16608. numChannelsCached = d->numChannels;
  16609. cachedStart = startTime;
  16610. cachedTimePerPixel = timePerPixel;
  16611. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16612. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16613. const ScopedLock sl (readerLock);
  16614. cacheNeedsRefilling = false;
  16615. if (needExtraDetail && reader == 0)
  16616. reader = createReader();
  16617. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16618. {
  16619. startTimer (timeBeforeDeletingReader);
  16620. char* cacheData = static_cast <char*> (cachedLevels.getData());
  16621. int sample = roundToInt (startTime * d->sampleRate);
  16622. for (int i = numSamples; --i >= 0;)
  16623. {
  16624. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16625. if (sample >= 0)
  16626. {
  16627. if (sample >= reader->lengthInSamples)
  16628. break;
  16629. float lmin, lmax, rmin, rmax;
  16630. reader->readMaxLevels (sample,
  16631. jmax (1, nextSample - sample),
  16632. lmin, lmax, rmin, rmax);
  16633. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16634. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16635. if (numChannelsCached > 1)
  16636. {
  16637. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16638. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16639. }
  16640. cacheData += 2 * numChannelsCached;
  16641. }
  16642. startTime += timePerPixel;
  16643. sample = nextSample;
  16644. }
  16645. }
  16646. else
  16647. {
  16648. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16649. {
  16650. char* const channelData = getChannelData (channelNum);
  16651. char* cacheData = static_cast <char*> (cachedLevels.getData()) + channelNum * 2;
  16652. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16653. startTime = cachedStart;
  16654. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16655. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16656. for (int i = numSamples; --i >= 0;)
  16657. {
  16658. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16659. if (sample >= 0 && channelData != 0)
  16660. {
  16661. char mx = -128;
  16662. char mn = 127;
  16663. while (sample <= nextSample)
  16664. {
  16665. if (sample >= numFinished)
  16666. break;
  16667. const int n = sample << 1;
  16668. const char sampMin = channelData [n];
  16669. const char sampMax = channelData [n + 1];
  16670. if (sampMin < mn)
  16671. mn = sampMin;
  16672. if (sampMax > mx)
  16673. mx = sampMax;
  16674. ++sample;
  16675. }
  16676. if (mn <= mx)
  16677. {
  16678. cacheData[0] = mn;
  16679. cacheData[1] = mx;
  16680. }
  16681. else
  16682. {
  16683. cacheData[0] = 1;
  16684. cacheData[1] = 0;
  16685. }
  16686. }
  16687. else
  16688. {
  16689. cacheData[0] = 1;
  16690. cacheData[1] = 0;
  16691. }
  16692. cacheData += numChannelsCached * 2;
  16693. startTime += timePerPixel;
  16694. sample = nextSample;
  16695. }
  16696. }
  16697. }
  16698. }
  16699. void AudioThumbnail::drawChannel (Graphics& g,
  16700. int x, int y, int w, int h,
  16701. double startTime,
  16702. double endTime,
  16703. int channelNum,
  16704. const float verticalZoomFactor)
  16705. {
  16706. refillCache (w, startTime, (endTime - startTime) / w);
  16707. if (numSamplesCached >= w
  16708. && channelNum >= 0
  16709. && channelNum < numChannelsCached)
  16710. {
  16711. const float topY = (float) y;
  16712. const float bottomY = topY + h;
  16713. const float midY = topY + h * 0.5f;
  16714. const float vscale = verticalZoomFactor * h / 256.0f;
  16715. const Rectangle<int> clip (g.getClipBounds());
  16716. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16717. w -= skipLeft;
  16718. x += skipLeft;
  16719. const char* cacheData = static_cast <const char*> (cachedLevels.getData())
  16720. + (channelNum << 1)
  16721. + skipLeft * (numChannelsCached << 1);
  16722. while (--w >= 0)
  16723. {
  16724. const char mn = cacheData[0];
  16725. const char mx = cacheData[1];
  16726. cacheData += numChannelsCached << 1;
  16727. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  16728. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  16729. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  16730. ++x;
  16731. if (x >= clip.getRight())
  16732. break;
  16733. }
  16734. }
  16735. }
  16736. END_JUCE_NAMESPACE
  16737. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  16738. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  16739. BEGIN_JUCE_NAMESPACE
  16740. struct ThumbnailCacheEntry
  16741. {
  16742. int64 hash;
  16743. uint32 lastUsed;
  16744. MemoryBlock data;
  16745. juce_UseDebuggingNewOperator
  16746. };
  16747. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  16748. : TimeSliceThread ("thumb cache"),
  16749. maxNumThumbsToStore (maxNumThumbsToStore_)
  16750. {
  16751. startThread (2);
  16752. }
  16753. AudioThumbnailCache::~AudioThumbnailCache()
  16754. {
  16755. }
  16756. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  16757. {
  16758. for (int i = thumbs.size(); --i >= 0;)
  16759. {
  16760. if (thumbs[i]->hash == hashCode)
  16761. {
  16762. MemoryInputStream in (thumbs[i]->data, false);
  16763. thumb.loadFrom (in);
  16764. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  16765. return true;
  16766. }
  16767. }
  16768. return false;
  16769. }
  16770. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  16771. const int64 hashCode)
  16772. {
  16773. MemoryOutputStream out;
  16774. thumb.saveTo (out);
  16775. ThumbnailCacheEntry* te = 0;
  16776. for (int i = thumbs.size(); --i >= 0;)
  16777. {
  16778. if (thumbs[i]->hash == hashCode)
  16779. {
  16780. te = thumbs[i];
  16781. break;
  16782. }
  16783. }
  16784. if (te == 0)
  16785. {
  16786. te = new ThumbnailCacheEntry();
  16787. te->hash = hashCode;
  16788. if (thumbs.size() < maxNumThumbsToStore)
  16789. {
  16790. thumbs.add (te);
  16791. }
  16792. else
  16793. {
  16794. int oldest = 0;
  16795. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  16796. int i;
  16797. for (i = thumbs.size(); --i >= 0;)
  16798. if (thumbs[i]->lastUsed < oldestTime)
  16799. oldest = i;
  16800. thumbs.set (i, te);
  16801. }
  16802. }
  16803. te->lastUsed = Time::getMillisecondCounter();
  16804. te->data.setSize (0);
  16805. te->data.append (out.getData(), out.getDataSize());
  16806. }
  16807. void AudioThumbnailCache::clear()
  16808. {
  16809. thumbs.clear();
  16810. }
  16811. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  16812. {
  16813. addTimeSliceClient (thumb);
  16814. }
  16815. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  16816. {
  16817. removeTimeSliceClient (thumb);
  16818. }
  16819. END_JUCE_NAMESPACE
  16820. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  16821. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  16822. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  16823. #if ! JUCE_WINDOWS
  16824. #include <QuickTime/Movies.h>
  16825. #include <QuickTime/QTML.h>
  16826. #include <QuickTime/QuickTimeComponents.h>
  16827. #include <QuickTime/MediaHandlers.h>
  16828. #include <QuickTime/ImageCodec.h>
  16829. #else
  16830. #if JUCE_MSVC
  16831. #pragma warning (push)
  16832. #pragma warning (disable : 4100)
  16833. #endif
  16834. #include <Movies.h>
  16835. #include <QTML.h>
  16836. #include <QuickTimeComponents.h>
  16837. #include <MediaHandlers.h>
  16838. #include <ImageCodec.h>
  16839. #if JUCE_MSVC
  16840. #pragma warning (pop)
  16841. #endif
  16842. #endif
  16843. BEGIN_JUCE_NAMESPACE
  16844. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  16845. static const char* const quickTimeFormatName = "QuickTime file";
  16846. static const juce_wchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  16847. class QTAudioReader : public AudioFormatReader
  16848. {
  16849. public:
  16850. QTAudioReader (InputStream* const input_, const int trackNum_)
  16851. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  16852. ok (false),
  16853. movie (0),
  16854. trackNum (trackNum_),
  16855. lastSampleRead (0),
  16856. lastThreadId (0),
  16857. extractor (0),
  16858. dataHandle (0)
  16859. {
  16860. bufferList.calloc (256, 1);
  16861. #ifdef WIN32
  16862. if (InitializeQTML (0) != noErr)
  16863. return;
  16864. #endif
  16865. if (EnterMovies() != noErr)
  16866. return;
  16867. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  16868. if (! opened)
  16869. return;
  16870. {
  16871. const int numTracks = GetMovieTrackCount (movie);
  16872. int trackCount = 0;
  16873. for (int i = 1; i <= numTracks; ++i)
  16874. {
  16875. track = GetMovieIndTrack (movie, i);
  16876. media = GetTrackMedia (track);
  16877. OSType mediaType;
  16878. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  16879. if (mediaType == SoundMediaType
  16880. && trackCount++ == trackNum_)
  16881. {
  16882. ok = true;
  16883. break;
  16884. }
  16885. }
  16886. }
  16887. if (! ok)
  16888. return;
  16889. ok = false;
  16890. lengthInSamples = GetMediaDecodeDuration (media);
  16891. usesFloatingPointData = false;
  16892. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  16893. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  16894. / GetMediaTimeScale (media);
  16895. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  16896. unsigned long output_layout_size;
  16897. err = MovieAudioExtractionGetPropertyInfo (extractor,
  16898. kQTPropertyClass_MovieAudioExtraction_Audio,
  16899. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16900. 0, &output_layout_size, 0);
  16901. if (err != noErr)
  16902. return;
  16903. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  16904. qt_audio_channel_layout.calloc (output_layout_size, 1);
  16905. err = MovieAudioExtractionGetProperty (extractor,
  16906. kQTPropertyClass_MovieAudioExtraction_Audio,
  16907. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16908. output_layout_size, qt_audio_channel_layout, 0);
  16909. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  16910. err = MovieAudioExtractionSetProperty (extractor,
  16911. kQTPropertyClass_MovieAudioExtraction_Audio,
  16912. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  16913. output_layout_size,
  16914. qt_audio_channel_layout);
  16915. err = MovieAudioExtractionGetProperty (extractor,
  16916. kQTPropertyClass_MovieAudioExtraction_Audio,
  16917. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16918. sizeof (inputStreamDesc),
  16919. &inputStreamDesc, 0);
  16920. if (err != noErr)
  16921. return;
  16922. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  16923. | kAudioFormatFlagIsPacked
  16924. | kAudioFormatFlagsNativeEndian;
  16925. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  16926. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  16927. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  16928. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  16929. err = MovieAudioExtractionSetProperty (extractor,
  16930. kQTPropertyClass_MovieAudioExtraction_Audio,
  16931. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  16932. sizeof (inputStreamDesc),
  16933. &inputStreamDesc);
  16934. if (err != noErr)
  16935. return;
  16936. Boolean allChannelsDiscrete = false;
  16937. err = MovieAudioExtractionSetProperty (extractor,
  16938. kQTPropertyClass_MovieAudioExtraction_Movie,
  16939. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  16940. sizeof (allChannelsDiscrete),
  16941. &allChannelsDiscrete);
  16942. if (err != noErr)
  16943. return;
  16944. bufferList->mNumberBuffers = 1;
  16945. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  16946. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  16947. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  16948. sampleRate = inputStreamDesc.mSampleRate;
  16949. bitsPerSample = 16;
  16950. numChannels = inputStreamDesc.mChannelsPerFrame;
  16951. detachThread();
  16952. ok = true;
  16953. }
  16954. ~QTAudioReader()
  16955. {
  16956. if (dataHandle != 0)
  16957. DisposeHandle (dataHandle);
  16958. if (extractor != 0)
  16959. {
  16960. MovieAudioExtractionEnd (extractor);
  16961. extractor = 0;
  16962. }
  16963. checkThreadIsAttached();
  16964. DisposeMovie (movie);
  16965. juce_free (bufferList->mBuffers[0].mData);
  16966. #if JUCE_MAC
  16967. ExitMoviesOnThread ();
  16968. #endif
  16969. }
  16970. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16971. int64 startSampleInFile, int numSamples)
  16972. {
  16973. checkThreadIsAttached();
  16974. while (numSamples > 0)
  16975. {
  16976. if (! loadFrame ((int) startSampleInFile))
  16977. return false;
  16978. const int numToDo = jmin (numSamples, samplesPerFrame);
  16979. for (int j = numDestChannels; --j >= 0;)
  16980. {
  16981. if (destSamples[j] != 0)
  16982. {
  16983. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  16984. for (int i = 0; i < numToDo; ++i)
  16985. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  16986. }
  16987. }
  16988. startOffsetInDestBuffer += numToDo;
  16989. startSampleInFile += numToDo;
  16990. numSamples -= numToDo;
  16991. }
  16992. detachThread();
  16993. return true;
  16994. }
  16995. bool loadFrame (const int sampleNum)
  16996. {
  16997. if (lastSampleRead != sampleNum)
  16998. {
  16999. TimeRecord time;
  17000. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17001. time.base = 0;
  17002. time.value.hi = 0;
  17003. time.value.lo = (UInt32) sampleNum;
  17004. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17005. kQTPropertyClass_MovieAudioExtraction_Movie,
  17006. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17007. sizeof (time), &time);
  17008. if (err != noErr)
  17009. return false;
  17010. }
  17011. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17012. UInt32 outFlags = 0;
  17013. UInt32 actualNumSamples = samplesPerFrame;
  17014. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17015. bufferList, &outFlags);
  17016. lastSampleRead = sampleNum + samplesPerFrame;
  17017. return err == noErr;
  17018. }
  17019. juce_UseDebuggingNewOperator
  17020. bool ok;
  17021. private:
  17022. Movie movie;
  17023. Media media;
  17024. Track track;
  17025. const int trackNum;
  17026. double trackUnitsPerFrame;
  17027. int samplesPerFrame;
  17028. int lastSampleRead;
  17029. Thread::ThreadID lastThreadId;
  17030. MovieAudioExtractionRef extractor;
  17031. AudioStreamBasicDescription inputStreamDesc;
  17032. HeapBlock <AudioBufferList> bufferList;
  17033. Handle dataHandle;
  17034. void checkThreadIsAttached()
  17035. {
  17036. #if JUCE_MAC
  17037. if (Thread::getCurrentThreadId() != lastThreadId)
  17038. EnterMoviesOnThread (0);
  17039. AttachMovieToCurrentThread (movie);
  17040. #endif
  17041. }
  17042. void detachThread()
  17043. {
  17044. #if JUCE_MAC
  17045. DetachMovieFromCurrentThread (movie);
  17046. #endif
  17047. }
  17048. QTAudioReader (const QTAudioReader&);
  17049. QTAudioReader& operator= (const QTAudioReader&);
  17050. };
  17051. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17052. : AudioFormat (TRANS (quickTimeFormatName), (const juce_wchar**) quickTimeExtensions)
  17053. {
  17054. }
  17055. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17056. {
  17057. }
  17058. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17059. {
  17060. return Array<int>();
  17061. }
  17062. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17063. {
  17064. return Array<int>();
  17065. }
  17066. bool QuickTimeAudioFormat::canDoStereo()
  17067. {
  17068. return true;
  17069. }
  17070. bool QuickTimeAudioFormat::canDoMono()
  17071. {
  17072. return true;
  17073. }
  17074. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17075. const bool deleteStreamIfOpeningFails)
  17076. {
  17077. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17078. if (r->ok)
  17079. return r.release();
  17080. if (! deleteStreamIfOpeningFails)
  17081. r->input = 0;
  17082. return 0;
  17083. }
  17084. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17085. double /*sampleRateToUse*/,
  17086. unsigned int /*numberOfChannels*/,
  17087. int /*bitsPerSample*/,
  17088. const StringPairArray& /*metadataValues*/,
  17089. int /*qualityOptionIndex*/)
  17090. {
  17091. jassertfalse // not yet implemented!
  17092. return 0;
  17093. }
  17094. END_JUCE_NAMESPACE
  17095. #endif
  17096. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17097. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17098. BEGIN_JUCE_NAMESPACE
  17099. static const char* const wavFormatName = "WAV file";
  17100. static const juce_wchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17101. const char* const WavAudioFormat::bwavDescription = "bwav description";
  17102. const char* const WavAudioFormat::bwavOriginator = "bwav originator";
  17103. const char* const WavAudioFormat::bwavOriginatorRef = "bwav originator ref";
  17104. const char* const WavAudioFormat::bwavOriginationDate = "bwav origination date";
  17105. const char* const WavAudioFormat::bwavOriginationTime = "bwav origination time";
  17106. const char* const WavAudioFormat::bwavTimeReference = "bwav time reference";
  17107. const char* const WavAudioFormat::bwavCodingHistory = "bwav coding history";
  17108. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17109. const String& originator,
  17110. const String& originatorRef,
  17111. const Time& date,
  17112. const int64 timeReferenceSamples,
  17113. const String& codingHistory)
  17114. {
  17115. StringPairArray m;
  17116. m.set (bwavDescription, description);
  17117. m.set (bwavOriginator, originator);
  17118. m.set (bwavOriginatorRef, originatorRef);
  17119. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17120. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17121. m.set (bwavTimeReference, String (timeReferenceSamples));
  17122. m.set (bwavCodingHistory, codingHistory);
  17123. return m;
  17124. }
  17125. #if JUCE_MSVC
  17126. #pragma pack (push, 1)
  17127. #define PACKED
  17128. #elif JUCE_GCC
  17129. #define PACKED __attribute__((packed))
  17130. #else
  17131. #define PACKED
  17132. #endif
  17133. struct BWAVChunk
  17134. {
  17135. char description [256];
  17136. char originator [32];
  17137. char originatorRef [32];
  17138. char originationDate [10];
  17139. char originationTime [8];
  17140. uint32 timeRefLow;
  17141. uint32 timeRefHigh;
  17142. uint16 version;
  17143. uint8 umid[64];
  17144. uint8 reserved[190];
  17145. char codingHistory[1];
  17146. void copyTo (StringPairArray& values) const
  17147. {
  17148. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17149. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17150. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17151. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17152. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17153. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17154. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17155. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17156. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17157. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17158. }
  17159. static MemoryBlock createFrom (const StringPairArray& values)
  17160. {
  17161. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17162. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17163. data.fillWith (0);
  17164. BWAVChunk* b = (BWAVChunk*) data.getData();
  17165. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17166. // as they get called in the right order..
  17167. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17168. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17169. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17170. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17171. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17172. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17173. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17174. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17175. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17176. if (b->description[0] != 0
  17177. || b->originator[0] != 0
  17178. || b->originationDate[0] != 0
  17179. || b->originationTime[0] != 0
  17180. || b->codingHistory[0] != 0
  17181. || time != 0)
  17182. {
  17183. return data;
  17184. }
  17185. return MemoryBlock();
  17186. }
  17187. } PACKED;
  17188. struct SMPLChunk
  17189. {
  17190. struct SampleLoop
  17191. {
  17192. uint32 identifier;
  17193. uint32 type;
  17194. uint32 start;
  17195. uint32 end;
  17196. uint32 fraction;
  17197. uint32 playCount;
  17198. } PACKED;
  17199. uint32 manufacturer;
  17200. uint32 product;
  17201. uint32 samplePeriod;
  17202. uint32 midiUnityNote;
  17203. uint32 midiPitchFraction;
  17204. uint32 smpteFormat;
  17205. uint32 smpteOffset;
  17206. uint32 numSampleLoops;
  17207. uint32 samplerData;
  17208. SampleLoop loops[1];
  17209. void copyTo (StringPairArray& values, const int totalSize) const
  17210. {
  17211. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17212. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17213. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17214. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17215. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17216. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17217. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17218. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17219. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17220. for (uint32 i = 0; i < numSampleLoops; ++i)
  17221. {
  17222. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17223. break;
  17224. const String prefix ("Loop" + String(i));
  17225. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17226. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17227. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17228. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17229. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17230. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17231. }
  17232. }
  17233. static MemoryBlock createFrom (const StringPairArray& values)
  17234. {
  17235. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17236. if (numLoops <= 0)
  17237. return MemoryBlock();
  17238. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17239. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17240. data.fillWith (0);
  17241. SMPLChunk* s = (SMPLChunk*) data.getData();
  17242. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17243. // as they get called in the right order..
  17244. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17245. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17246. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17247. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17248. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17249. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17250. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17251. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17252. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17253. for (int i = 0; i < numLoops; ++i)
  17254. {
  17255. const String prefix ("Loop" + String(i));
  17256. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17257. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17258. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17259. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17260. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17261. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17262. }
  17263. return data;
  17264. }
  17265. } PACKED;
  17266. struct ExtensibleWavSubFormat
  17267. {
  17268. uint32 data1;
  17269. uint16 data2;
  17270. uint16 data3;
  17271. uint8 data4[8];
  17272. } PACKED;
  17273. #if JUCE_MSVC
  17274. #pragma pack (pop)
  17275. #endif
  17276. #undef PACKED
  17277. class WavAudioFormatReader : public AudioFormatReader
  17278. {
  17279. int bytesPerFrame;
  17280. int64 dataChunkStart, dataLength;
  17281. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17282. WavAudioFormatReader (const WavAudioFormatReader&);
  17283. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17284. public:
  17285. int64 bwavChunkStart, bwavSize;
  17286. WavAudioFormatReader (InputStream* const in)
  17287. : AudioFormatReader (in, TRANS (wavFormatName)),
  17288. dataLength (0),
  17289. bwavChunkStart (0),
  17290. bwavSize (0)
  17291. {
  17292. if (input->readInt() == chunkName ("RIFF"))
  17293. {
  17294. const uint32 len = (uint32) input->readInt();
  17295. const int64 end = input->getPosition() + len;
  17296. bool hasGotType = false;
  17297. bool hasGotData = false;
  17298. if (input->readInt() == chunkName ("WAVE"))
  17299. {
  17300. while (input->getPosition() < end
  17301. && ! input->isExhausted())
  17302. {
  17303. const int chunkType = input->readInt();
  17304. uint32 length = (uint32) input->readInt();
  17305. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17306. if (chunkType == chunkName ("fmt "))
  17307. {
  17308. // read the format chunk
  17309. const unsigned short format = input->readShort();
  17310. const short numChans = input->readShort();
  17311. sampleRate = input->readInt();
  17312. const int bytesPerSec = input->readInt();
  17313. numChannels = numChans;
  17314. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17315. bitsPerSample = 8 * bytesPerFrame / numChans;
  17316. if (format == 3)
  17317. {
  17318. usesFloatingPointData = true;
  17319. }
  17320. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17321. {
  17322. if (length < 40) // too short
  17323. {
  17324. bytesPerFrame = 0;
  17325. }
  17326. else
  17327. {
  17328. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17329. ExtensibleWavSubFormat subFormat;
  17330. subFormat.data1 = input->readInt();
  17331. subFormat.data2 = input->readShort();
  17332. subFormat.data3 = input->readShort();
  17333. input->read (subFormat.data4, sizeof (subFormat.data4));
  17334. const ExtensibleWavSubFormat pcmFormat
  17335. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17336. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17337. {
  17338. const ExtensibleWavSubFormat ambisonicFormat
  17339. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17340. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17341. bytesPerFrame = 0;
  17342. }
  17343. }
  17344. }
  17345. else if (format != 1)
  17346. {
  17347. bytesPerFrame = 0;
  17348. }
  17349. hasGotType = true;
  17350. }
  17351. else if (chunkType == chunkName ("data"))
  17352. {
  17353. // get the data chunk's position
  17354. dataLength = length;
  17355. dataChunkStart = input->getPosition();
  17356. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17357. hasGotData = true;
  17358. }
  17359. else if (chunkType == chunkName ("bext"))
  17360. {
  17361. bwavChunkStart = input->getPosition();
  17362. bwavSize = length;
  17363. // Broadcast-wav extension chunk..
  17364. HeapBlock <BWAVChunk> bwav;
  17365. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17366. input->read (bwav, length);
  17367. bwav->copyTo (metadataValues);
  17368. }
  17369. else if (chunkType == chunkName ("smpl"))
  17370. {
  17371. HeapBlock <SMPLChunk> smpl;
  17372. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17373. input->read (smpl, length);
  17374. smpl->copyTo (metadataValues, length);
  17375. }
  17376. else if (chunkEnd <= input->getPosition())
  17377. {
  17378. break;
  17379. }
  17380. input->setPosition (chunkEnd);
  17381. }
  17382. }
  17383. }
  17384. }
  17385. ~WavAudioFormatReader()
  17386. {
  17387. }
  17388. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17389. int64 startSampleInFile, int numSamples)
  17390. {
  17391. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17392. if (samplesAvailable < numSamples)
  17393. {
  17394. for (int i = numDestChannels; --i >= 0;)
  17395. if (destSamples[i] != 0)
  17396. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17397. numSamples = (int) samplesAvailable;
  17398. }
  17399. if (numSamples <= 0)
  17400. return true;
  17401. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17402. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17403. char tempBuffer [tempBufSize];
  17404. while (numSamples > 0)
  17405. {
  17406. int* left = destSamples[0];
  17407. if (left != 0)
  17408. left += startOffsetInDestBuffer;
  17409. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17410. if (right != 0)
  17411. right += startOffsetInDestBuffer;
  17412. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17413. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17414. if (bytesRead < numThisTime * bytesPerFrame)
  17415. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17416. if (bitsPerSample == 16)
  17417. {
  17418. const short* src = reinterpret_cast <const short*> (tempBuffer);
  17419. if (numChannels > 1)
  17420. {
  17421. if (left == 0)
  17422. {
  17423. for (int i = numThisTime; --i >= 0;)
  17424. {
  17425. ++src;
  17426. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17427. }
  17428. }
  17429. else if (right == 0)
  17430. {
  17431. for (int i = numThisTime; --i >= 0;)
  17432. {
  17433. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17434. ++src;
  17435. }
  17436. }
  17437. else
  17438. {
  17439. for (int i = numThisTime; --i >= 0;)
  17440. {
  17441. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17442. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17443. }
  17444. }
  17445. }
  17446. else
  17447. {
  17448. for (int i = numThisTime; --i >= 0;)
  17449. {
  17450. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17451. }
  17452. }
  17453. }
  17454. else if (bitsPerSample == 24)
  17455. {
  17456. const char* src = tempBuffer;
  17457. if (numChannels > 1)
  17458. {
  17459. if (left == 0)
  17460. {
  17461. for (int i = numThisTime; --i >= 0;)
  17462. {
  17463. src += 3;
  17464. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17465. src += 3;
  17466. }
  17467. }
  17468. else if (right == 0)
  17469. {
  17470. for (int i = numThisTime; --i >= 0;)
  17471. {
  17472. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17473. src += 6;
  17474. }
  17475. }
  17476. else
  17477. {
  17478. for (int i = 0; i < numThisTime; ++i)
  17479. {
  17480. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17481. src += 3;
  17482. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17483. src += 3;
  17484. }
  17485. }
  17486. }
  17487. else
  17488. {
  17489. for (int i = 0; i < numThisTime; ++i)
  17490. {
  17491. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17492. src += 3;
  17493. }
  17494. }
  17495. }
  17496. else if (bitsPerSample == 32)
  17497. {
  17498. const unsigned int* src = (const unsigned int*) tempBuffer;
  17499. unsigned int* l = (unsigned int*) left;
  17500. unsigned int* r = (unsigned int*) right;
  17501. if (numChannels > 1)
  17502. {
  17503. if (l == 0)
  17504. {
  17505. for (int i = numThisTime; --i >= 0;)
  17506. {
  17507. ++src;
  17508. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17509. }
  17510. }
  17511. else if (r == 0)
  17512. {
  17513. for (int i = numThisTime; --i >= 0;)
  17514. {
  17515. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17516. ++src;
  17517. }
  17518. }
  17519. else
  17520. {
  17521. for (int i = numThisTime; --i >= 0;)
  17522. {
  17523. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17524. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17525. }
  17526. }
  17527. }
  17528. else
  17529. {
  17530. for (int i = numThisTime; --i >= 0;)
  17531. {
  17532. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17533. }
  17534. }
  17535. left = (int*)l;
  17536. right = (int*)r;
  17537. }
  17538. else if (bitsPerSample == 8)
  17539. {
  17540. const unsigned char* src = (const unsigned char*) tempBuffer;
  17541. if (numChannels > 1)
  17542. {
  17543. if (left == 0)
  17544. {
  17545. for (int i = numThisTime; --i >= 0;)
  17546. {
  17547. ++src;
  17548. *right++ = ((int) *src++ - 128) << 24;
  17549. }
  17550. }
  17551. else if (right == 0)
  17552. {
  17553. for (int i = numThisTime; --i >= 0;)
  17554. {
  17555. *left++ = ((int) *src++ - 128) << 24;
  17556. ++src;
  17557. }
  17558. }
  17559. else
  17560. {
  17561. for (int i = numThisTime; --i >= 0;)
  17562. {
  17563. *left++ = ((int) *src++ - 128) << 24;
  17564. *right++ = ((int) *src++ - 128) << 24;
  17565. }
  17566. }
  17567. }
  17568. else
  17569. {
  17570. for (int i = numThisTime; --i >= 0;)
  17571. {
  17572. *left++ = ((int)*src++ - 128) << 24;
  17573. }
  17574. }
  17575. }
  17576. startOffsetInDestBuffer += numThisTime;
  17577. numSamples -= numThisTime;
  17578. }
  17579. if (numSamples > 0)
  17580. {
  17581. for (int i = numDestChannels; --i >= 0;)
  17582. if (destSamples[i] != 0)
  17583. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17584. sizeof (int) * numSamples);
  17585. }
  17586. return true;
  17587. }
  17588. juce_UseDebuggingNewOperator
  17589. };
  17590. class WavAudioFormatWriter : public AudioFormatWriter
  17591. {
  17592. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17593. uint32 lengthInSamples, bytesWritten;
  17594. int64 headerPosition;
  17595. bool writeFailed;
  17596. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17597. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17598. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17599. void writeHeader()
  17600. {
  17601. const bool seekedOk = output->setPosition (headerPosition);
  17602. (void) seekedOk;
  17603. // if this fails, you've given it an output stream that can't seek! It needs
  17604. // to be able to seek back to write the header
  17605. jassert (seekedOk);
  17606. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17607. output->writeInt (chunkName ("RIFF"));
  17608. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17609. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17610. output->writeInt (chunkName ("WAVE"));
  17611. output->writeInt (chunkName ("fmt "));
  17612. output->writeInt (16);
  17613. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17614. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17615. output->writeShort ((short) numChannels);
  17616. output->writeInt ((int) sampleRate);
  17617. output->writeInt (bytesPerFrame * (int) sampleRate);
  17618. output->writeShort ((short) bytesPerFrame);
  17619. output->writeShort ((short) bitsPerSample);
  17620. if (bwavChunk.getSize() > 0)
  17621. {
  17622. output->writeInt (chunkName ("bext"));
  17623. output->writeInt ((int) bwavChunk.getSize());
  17624. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17625. }
  17626. if (smplChunk.getSize() > 0)
  17627. {
  17628. output->writeInt (chunkName ("smpl"));
  17629. output->writeInt ((int) smplChunk.getSize());
  17630. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17631. }
  17632. output->writeInt (chunkName ("data"));
  17633. output->writeInt (lengthInSamples * bytesPerFrame);
  17634. usesFloatingPointData = (bitsPerSample == 32);
  17635. }
  17636. public:
  17637. WavAudioFormatWriter (OutputStream* const out,
  17638. const double sampleRate_,
  17639. const unsigned int numChannels_,
  17640. const int bits,
  17641. const StringPairArray& metadataValues)
  17642. : AudioFormatWriter (out,
  17643. TRANS (wavFormatName),
  17644. sampleRate_,
  17645. numChannels_,
  17646. bits),
  17647. lengthInSamples (0),
  17648. bytesWritten (0),
  17649. writeFailed (false)
  17650. {
  17651. if (metadataValues.size() > 0)
  17652. {
  17653. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17654. smplChunk = SMPLChunk::createFrom (metadataValues);
  17655. }
  17656. headerPosition = out->getPosition();
  17657. writeHeader();
  17658. }
  17659. ~WavAudioFormatWriter()
  17660. {
  17661. writeHeader();
  17662. }
  17663. bool write (const int** data, int numSamples)
  17664. {
  17665. if (writeFailed)
  17666. return false;
  17667. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17668. tempBlock.ensureSize (bytes, false);
  17669. char* buffer = static_cast <char*> (tempBlock.getData());
  17670. const int* left = data[0];
  17671. const int* right = data[1];
  17672. if (right == 0)
  17673. right = left;
  17674. if (bitsPerSample == 16)
  17675. {
  17676. short* b = (short*) buffer;
  17677. if (numChannels > 1)
  17678. {
  17679. for (int i = numSamples; --i >= 0;)
  17680. {
  17681. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17682. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17683. }
  17684. }
  17685. else
  17686. {
  17687. for (int i = numSamples; --i >= 0;)
  17688. {
  17689. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17690. }
  17691. }
  17692. }
  17693. else if (bitsPerSample == 24)
  17694. {
  17695. char* b = buffer;
  17696. if (numChannels > 1)
  17697. {
  17698. for (int i = numSamples; --i >= 0;)
  17699. {
  17700. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17701. b += 3;
  17702. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17703. b += 3;
  17704. }
  17705. }
  17706. else
  17707. {
  17708. for (int i = numSamples; --i >= 0;)
  17709. {
  17710. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17711. b += 3;
  17712. }
  17713. }
  17714. }
  17715. else if (bitsPerSample == 32)
  17716. {
  17717. unsigned int* b = (unsigned int*) buffer;
  17718. if (numChannels > 1)
  17719. {
  17720. for (int i = numSamples; --i >= 0;)
  17721. {
  17722. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17723. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  17724. }
  17725. }
  17726. else
  17727. {
  17728. for (int i = numSamples; --i >= 0;)
  17729. {
  17730. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  17731. }
  17732. }
  17733. }
  17734. else if (bitsPerSample == 8)
  17735. {
  17736. unsigned char* b = (unsigned char*) buffer;
  17737. if (numChannels > 1)
  17738. {
  17739. for (int i = numSamples; --i >= 0;)
  17740. {
  17741. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17742. *b++ = (unsigned char) (128 + (*right++ >> 24));
  17743. }
  17744. }
  17745. else
  17746. {
  17747. for (int i = numSamples; --i >= 0;)
  17748. {
  17749. *b++ = (unsigned char) (128 + (*left++ >> 24));
  17750. }
  17751. }
  17752. }
  17753. if (bytesWritten + bytes >= (uint32) 0xfff00000
  17754. || ! output->write (buffer, bytes))
  17755. {
  17756. // failed to write to disk, so let's try writing the header.
  17757. // If it's just run out of disk space, then if it does manage
  17758. // to write the header, we'll still have a useable file..
  17759. writeHeader();
  17760. writeFailed = true;
  17761. return false;
  17762. }
  17763. else
  17764. {
  17765. bytesWritten += bytes;
  17766. lengthInSamples += numSamples;
  17767. return true;
  17768. }
  17769. }
  17770. juce_UseDebuggingNewOperator
  17771. };
  17772. WavAudioFormat::WavAudioFormat()
  17773. : AudioFormat (TRANS (wavFormatName), (const juce_wchar**) wavExtensions)
  17774. {
  17775. }
  17776. WavAudioFormat::~WavAudioFormat()
  17777. {
  17778. }
  17779. const Array <int> WavAudioFormat::getPossibleSampleRates()
  17780. {
  17781. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  17782. return Array <int> (rates);
  17783. }
  17784. const Array <int> WavAudioFormat::getPossibleBitDepths()
  17785. {
  17786. const int depths[] = { 8, 16, 24, 32, 0 };
  17787. return Array <int> (depths);
  17788. }
  17789. bool WavAudioFormat::canDoStereo()
  17790. {
  17791. return true;
  17792. }
  17793. bool WavAudioFormat::canDoMono()
  17794. {
  17795. return true;
  17796. }
  17797. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  17798. const bool deleteStreamIfOpeningFails)
  17799. {
  17800. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  17801. if (r->sampleRate != 0)
  17802. return r.release();
  17803. if (! deleteStreamIfOpeningFails)
  17804. r->input = 0;
  17805. return 0;
  17806. }
  17807. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  17808. double sampleRate,
  17809. unsigned int numChannels,
  17810. int bitsPerSample,
  17811. const StringPairArray& metadataValues,
  17812. int /*qualityOptionIndex*/)
  17813. {
  17814. if (getPossibleBitDepths().contains (bitsPerSample))
  17815. {
  17816. return new WavAudioFormatWriter (out,
  17817. sampleRate,
  17818. numChannels,
  17819. bitsPerSample,
  17820. metadataValues);
  17821. }
  17822. return 0;
  17823. }
  17824. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  17825. {
  17826. TemporaryFile tempFile (file);
  17827. WavAudioFormat wav;
  17828. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  17829. if (reader != 0)
  17830. {
  17831. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  17832. if (outStream != 0)
  17833. {
  17834. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  17835. reader->numChannels, reader->bitsPerSample,
  17836. metadata, 0));
  17837. if (writer != 0)
  17838. {
  17839. outStream.release();
  17840. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  17841. writer = 0;
  17842. reader = 0;
  17843. return ok && tempFile.overwriteTargetFileWithTemporary();
  17844. }
  17845. }
  17846. }
  17847. return false;
  17848. }
  17849. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  17850. {
  17851. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  17852. if (reader != 0)
  17853. {
  17854. const int64 bwavPos = reader->bwavChunkStart;
  17855. const int64 bwavSize = reader->bwavSize;
  17856. reader = 0;
  17857. if (bwavSize > 0)
  17858. {
  17859. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  17860. if (chunk.getSize() <= (size_t) bwavSize)
  17861. {
  17862. // the new one will fit in the space available, so write it directly..
  17863. const int64 oldSize = wavFile.getSize();
  17864. {
  17865. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  17866. out->setPosition (bwavPos);
  17867. out->write (chunk.getData(), (int) chunk.getSize());
  17868. out->setPosition (oldSize);
  17869. }
  17870. jassert (wavFile.getSize() == oldSize);
  17871. return true;
  17872. }
  17873. }
  17874. }
  17875. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  17876. }
  17877. END_JUCE_NAMESPACE
  17878. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  17879. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17880. BEGIN_JUCE_NAMESPACE
  17881. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  17882. const bool deleteReaderWhenThisIsDeleted)
  17883. : reader (reader_),
  17884. deleteReader (deleteReaderWhenThisIsDeleted),
  17885. nextPlayPos (0),
  17886. looping (false)
  17887. {
  17888. jassert (reader != 0);
  17889. }
  17890. AudioFormatReaderSource::~AudioFormatReaderSource()
  17891. {
  17892. releaseResources();
  17893. if (deleteReader)
  17894. delete reader;
  17895. }
  17896. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  17897. {
  17898. nextPlayPos = newPosition;
  17899. }
  17900. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  17901. {
  17902. looping = shouldLoop;
  17903. }
  17904. int AudioFormatReaderSource::getNextReadPosition() const
  17905. {
  17906. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  17907. : nextPlayPos;
  17908. }
  17909. int AudioFormatReaderSource::getTotalLength() const
  17910. {
  17911. return (int) reader->lengthInSamples;
  17912. }
  17913. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  17914. double /*sampleRate*/)
  17915. {
  17916. }
  17917. void AudioFormatReaderSource::releaseResources()
  17918. {
  17919. }
  17920. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  17921. {
  17922. if (info.numSamples > 0)
  17923. {
  17924. const int start = nextPlayPos;
  17925. if (looping)
  17926. {
  17927. const int newStart = start % (int) reader->lengthInSamples;
  17928. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  17929. if (newEnd > newStart)
  17930. {
  17931. info.buffer->readFromAudioReader (reader,
  17932. info.startSample,
  17933. newEnd - newStart,
  17934. newStart,
  17935. true, true);
  17936. }
  17937. else
  17938. {
  17939. const int endSamps = (int) reader->lengthInSamples - newStart;
  17940. info.buffer->readFromAudioReader (reader,
  17941. info.startSample,
  17942. endSamps,
  17943. newStart,
  17944. true, true);
  17945. info.buffer->readFromAudioReader (reader,
  17946. info.startSample + endSamps,
  17947. newEnd,
  17948. 0,
  17949. true, true);
  17950. }
  17951. nextPlayPos = newEnd;
  17952. }
  17953. else
  17954. {
  17955. info.buffer->readFromAudioReader (reader,
  17956. info.startSample,
  17957. info.numSamples,
  17958. start,
  17959. true, true);
  17960. nextPlayPos += info.numSamples;
  17961. }
  17962. }
  17963. }
  17964. END_JUCE_NAMESPACE
  17965. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  17966. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  17967. BEGIN_JUCE_NAMESPACE
  17968. AudioSourcePlayer::AudioSourcePlayer()
  17969. : source (0),
  17970. sampleRate (0),
  17971. bufferSize (0),
  17972. tempBuffer (2, 8),
  17973. lastGain (1.0f),
  17974. gain (1.0f)
  17975. {
  17976. }
  17977. AudioSourcePlayer::~AudioSourcePlayer()
  17978. {
  17979. setSource (0);
  17980. }
  17981. void AudioSourcePlayer::setSource (AudioSource* newSource)
  17982. {
  17983. if (source != newSource)
  17984. {
  17985. AudioSource* const oldSource = source;
  17986. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  17987. newSource->prepareToPlay (bufferSize, sampleRate);
  17988. {
  17989. const ScopedLock sl (readLock);
  17990. source = newSource;
  17991. }
  17992. if (oldSource != 0)
  17993. oldSource->releaseResources();
  17994. }
  17995. }
  17996. void AudioSourcePlayer::setGain (const float newGain) throw()
  17997. {
  17998. gain = newGain;
  17999. }
  18000. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18001. int totalNumInputChannels,
  18002. float** outputChannelData,
  18003. int totalNumOutputChannels,
  18004. int numSamples)
  18005. {
  18006. // these should have been prepared by audioDeviceAboutToStart()...
  18007. jassert (sampleRate > 0 && bufferSize > 0);
  18008. const ScopedLock sl (readLock);
  18009. if (source != 0)
  18010. {
  18011. AudioSourceChannelInfo info;
  18012. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18013. // messy stuff needed to compact the channels down into an array
  18014. // of non-zero pointers..
  18015. for (i = 0; i < totalNumInputChannels; ++i)
  18016. {
  18017. if (inputChannelData[i] != 0)
  18018. {
  18019. inputChans [numInputs++] = inputChannelData[i];
  18020. if (numInputs >= numElementsInArray (inputChans))
  18021. break;
  18022. }
  18023. }
  18024. for (i = 0; i < totalNumOutputChannels; ++i)
  18025. {
  18026. if (outputChannelData[i] != 0)
  18027. {
  18028. outputChans [numOutputs++] = outputChannelData[i];
  18029. if (numOutputs >= numElementsInArray (outputChans))
  18030. break;
  18031. }
  18032. }
  18033. if (numInputs > numOutputs)
  18034. {
  18035. // if there aren't enough output channels for the number of
  18036. // inputs, we need to create some temporary extra ones (can't
  18037. // use the input data in case it gets written to)
  18038. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18039. false, false, true);
  18040. for (i = 0; i < numOutputs; ++i)
  18041. {
  18042. channels[numActiveChans] = outputChans[i];
  18043. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18044. ++numActiveChans;
  18045. }
  18046. for (i = numOutputs; i < numInputs; ++i)
  18047. {
  18048. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18049. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18050. ++numActiveChans;
  18051. }
  18052. }
  18053. else
  18054. {
  18055. for (i = 0; i < numInputs; ++i)
  18056. {
  18057. channels[numActiveChans] = outputChans[i];
  18058. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18059. ++numActiveChans;
  18060. }
  18061. for (i = numInputs; i < numOutputs; ++i)
  18062. {
  18063. channels[numActiveChans] = outputChans[i];
  18064. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18065. ++numActiveChans;
  18066. }
  18067. }
  18068. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18069. info.buffer = &buffer;
  18070. info.startSample = 0;
  18071. info.numSamples = numSamples;
  18072. source->getNextAudioBlock (info);
  18073. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18074. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18075. lastGain = gain;
  18076. }
  18077. else
  18078. {
  18079. for (int i = 0; i < totalNumOutputChannels; ++i)
  18080. if (outputChannelData[i] != 0)
  18081. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18082. }
  18083. }
  18084. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18085. {
  18086. sampleRate = device->getCurrentSampleRate();
  18087. bufferSize = device->getCurrentBufferSizeSamples();
  18088. zeromem (channels, sizeof (channels));
  18089. if (source != 0)
  18090. source->prepareToPlay (bufferSize, sampleRate);
  18091. }
  18092. void AudioSourcePlayer::audioDeviceStopped()
  18093. {
  18094. if (source != 0)
  18095. source->releaseResources();
  18096. sampleRate = 0.0;
  18097. bufferSize = 0;
  18098. tempBuffer.setSize (2, 8);
  18099. }
  18100. END_JUCE_NAMESPACE
  18101. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18102. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18103. BEGIN_JUCE_NAMESPACE
  18104. AudioTransportSource::AudioTransportSource()
  18105. : source (0),
  18106. resamplerSource (0),
  18107. bufferingSource (0),
  18108. positionableSource (0),
  18109. masterSource (0),
  18110. gain (1.0f),
  18111. lastGain (1.0f),
  18112. playing (false),
  18113. stopped (true),
  18114. sampleRate (44100.0),
  18115. sourceSampleRate (0.0),
  18116. blockSize (128),
  18117. readAheadBufferSize (0),
  18118. isPrepared (false),
  18119. inputStreamEOF (false)
  18120. {
  18121. }
  18122. AudioTransportSource::~AudioTransportSource()
  18123. {
  18124. setSource (0);
  18125. releaseResources();
  18126. }
  18127. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18128. int readAheadBufferSize_,
  18129. double sourceSampleRateToCorrectFor)
  18130. {
  18131. if (source == newSource)
  18132. {
  18133. if (source == 0)
  18134. return;
  18135. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18136. }
  18137. readAheadBufferSize = readAheadBufferSize_;
  18138. sourceSampleRate = sourceSampleRateToCorrectFor;
  18139. ResamplingAudioSource* newResamplerSource = 0;
  18140. BufferingAudioSource* newBufferingSource = 0;
  18141. PositionableAudioSource* newPositionableSource = 0;
  18142. AudioSource* newMasterSource = 0;
  18143. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18144. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18145. AudioSource* oldMasterSource = masterSource;
  18146. if (newSource != 0)
  18147. {
  18148. newPositionableSource = newSource;
  18149. if (readAheadBufferSize_ > 0)
  18150. newPositionableSource = newBufferingSource
  18151. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18152. newPositionableSource->setNextReadPosition (0);
  18153. if (sourceSampleRateToCorrectFor != 0)
  18154. newMasterSource = newResamplerSource
  18155. = new ResamplingAudioSource (newPositionableSource, false);
  18156. else
  18157. newMasterSource = newPositionableSource;
  18158. if (isPrepared)
  18159. {
  18160. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18161. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18162. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18163. }
  18164. }
  18165. {
  18166. const ScopedLock sl (callbackLock);
  18167. source = newSource;
  18168. resamplerSource = newResamplerSource;
  18169. bufferingSource = newBufferingSource;
  18170. masterSource = newMasterSource;
  18171. positionableSource = newPositionableSource;
  18172. playing = false;
  18173. }
  18174. if (oldMasterSource != 0)
  18175. oldMasterSource->releaseResources();
  18176. }
  18177. void AudioTransportSource::start()
  18178. {
  18179. if ((! playing) && masterSource != 0)
  18180. {
  18181. {
  18182. const ScopedLock sl (callbackLock);
  18183. playing = true;
  18184. stopped = false;
  18185. inputStreamEOF = false;
  18186. }
  18187. sendChangeMessage (this);
  18188. }
  18189. }
  18190. void AudioTransportSource::stop()
  18191. {
  18192. if (playing)
  18193. {
  18194. {
  18195. const ScopedLock sl (callbackLock);
  18196. playing = false;
  18197. }
  18198. int n = 500;
  18199. while (--n >= 0 && ! stopped)
  18200. Thread::sleep (2);
  18201. sendChangeMessage (this);
  18202. }
  18203. }
  18204. void AudioTransportSource::setPosition (double newPosition)
  18205. {
  18206. if (sampleRate > 0.0)
  18207. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18208. }
  18209. double AudioTransportSource::getCurrentPosition() const
  18210. {
  18211. if (sampleRate > 0.0)
  18212. return getNextReadPosition() / sampleRate;
  18213. else
  18214. return 0.0;
  18215. }
  18216. void AudioTransportSource::setNextReadPosition (int newPosition)
  18217. {
  18218. if (positionableSource != 0)
  18219. {
  18220. if (sampleRate > 0 && sourceSampleRate > 0)
  18221. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18222. positionableSource->setNextReadPosition (newPosition);
  18223. }
  18224. }
  18225. int AudioTransportSource::getNextReadPosition() const
  18226. {
  18227. if (positionableSource != 0)
  18228. {
  18229. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18230. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18231. }
  18232. return 0;
  18233. }
  18234. int AudioTransportSource::getTotalLength() const
  18235. {
  18236. const ScopedLock sl (callbackLock);
  18237. if (positionableSource != 0)
  18238. {
  18239. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18240. return roundToInt (positionableSource->getTotalLength() * ratio);
  18241. }
  18242. return 0;
  18243. }
  18244. bool AudioTransportSource::isLooping() const
  18245. {
  18246. const ScopedLock sl (callbackLock);
  18247. return positionableSource != 0
  18248. && positionableSource->isLooping();
  18249. }
  18250. void AudioTransportSource::setGain (const float newGain) throw()
  18251. {
  18252. gain = newGain;
  18253. }
  18254. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18255. double sampleRate_)
  18256. {
  18257. const ScopedLock sl (callbackLock);
  18258. sampleRate = sampleRate_;
  18259. blockSize = samplesPerBlockExpected;
  18260. if (masterSource != 0)
  18261. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18262. if (resamplerSource != 0 && sourceSampleRate != 0)
  18263. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18264. isPrepared = true;
  18265. }
  18266. void AudioTransportSource::releaseResources()
  18267. {
  18268. const ScopedLock sl (callbackLock);
  18269. if (masterSource != 0)
  18270. masterSource->releaseResources();
  18271. isPrepared = false;
  18272. }
  18273. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18274. {
  18275. const ScopedLock sl (callbackLock);
  18276. inputStreamEOF = false;
  18277. if (masterSource != 0 && ! stopped)
  18278. {
  18279. masterSource->getNextAudioBlock (info);
  18280. if (! playing)
  18281. {
  18282. // just stopped playing, so fade out the last block..
  18283. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18284. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18285. if (info.numSamples > 256)
  18286. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18287. }
  18288. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18289. && ! positionableSource->isLooping())
  18290. {
  18291. playing = false;
  18292. inputStreamEOF = true;
  18293. sendChangeMessage (this);
  18294. }
  18295. stopped = ! playing;
  18296. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18297. {
  18298. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18299. lastGain, gain);
  18300. }
  18301. }
  18302. else
  18303. {
  18304. info.clearActiveBufferRegion();
  18305. stopped = true;
  18306. }
  18307. lastGain = gain;
  18308. }
  18309. END_JUCE_NAMESPACE
  18310. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18311. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18312. BEGIN_JUCE_NAMESPACE
  18313. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18314. public Thread,
  18315. private Timer
  18316. {
  18317. public:
  18318. SharedBufferingAudioSourceThread()
  18319. : Thread ("Audio Buffer")
  18320. {
  18321. }
  18322. ~SharedBufferingAudioSourceThread()
  18323. {
  18324. stopThread (10000);
  18325. clearSingletonInstance();
  18326. }
  18327. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18328. void addSource (BufferingAudioSource* source)
  18329. {
  18330. const ScopedLock sl (lock);
  18331. if (! sources.contains (source))
  18332. {
  18333. sources.add (source);
  18334. startThread();
  18335. stopTimer();
  18336. }
  18337. notify();
  18338. }
  18339. void removeSource (BufferingAudioSource* source)
  18340. {
  18341. const ScopedLock sl (lock);
  18342. sources.removeValue (source);
  18343. if (sources.size() == 0)
  18344. startTimer (5000);
  18345. }
  18346. private:
  18347. Array <BufferingAudioSource*> sources;
  18348. CriticalSection lock;
  18349. void run()
  18350. {
  18351. while (! threadShouldExit())
  18352. {
  18353. bool busy = false;
  18354. for (int i = sources.size(); --i >= 0;)
  18355. {
  18356. if (threadShouldExit())
  18357. return;
  18358. const ScopedLock sl (lock);
  18359. BufferingAudioSource* const b = sources[i];
  18360. if (b != 0 && b->readNextBufferChunk())
  18361. busy = true;
  18362. }
  18363. if (! busy)
  18364. wait (500);
  18365. }
  18366. }
  18367. void timerCallback()
  18368. {
  18369. stopTimer();
  18370. if (sources.size() == 0)
  18371. deleteInstance();
  18372. }
  18373. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18374. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18375. };
  18376. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18377. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18378. const bool deleteSourceWhenDeleted_,
  18379. int numberOfSamplesToBuffer_)
  18380. : source (source_),
  18381. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18382. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18383. buffer (2, 0),
  18384. bufferValidStart (0),
  18385. bufferValidEnd (0),
  18386. nextPlayPos (0),
  18387. wasSourceLooping (false)
  18388. {
  18389. jassert (source_ != 0);
  18390. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18391. // not using a larger buffer..
  18392. }
  18393. BufferingAudioSource::~BufferingAudioSource()
  18394. {
  18395. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18396. if (thread != 0)
  18397. thread->removeSource (this);
  18398. if (deleteSourceWhenDeleted)
  18399. delete source;
  18400. }
  18401. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18402. {
  18403. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18404. sampleRate = sampleRate_;
  18405. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18406. buffer.clear();
  18407. bufferValidStart = 0;
  18408. bufferValidEnd = 0;
  18409. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18410. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18411. buffer.getNumSamples() / 2))
  18412. {
  18413. SharedBufferingAudioSourceThread::getInstance()->notify();
  18414. Thread::sleep (5);
  18415. }
  18416. }
  18417. void BufferingAudioSource::releaseResources()
  18418. {
  18419. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18420. if (thread != 0)
  18421. thread->removeSource (this);
  18422. buffer.setSize (2, 0);
  18423. source->releaseResources();
  18424. }
  18425. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18426. {
  18427. const ScopedLock sl (bufferStartPosLock);
  18428. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18429. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18430. if (validStart == validEnd)
  18431. {
  18432. // total cache miss
  18433. info.clearActiveBufferRegion();
  18434. }
  18435. else
  18436. {
  18437. if (validStart > 0)
  18438. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18439. if (validEnd < info.numSamples)
  18440. info.buffer->clear (info.startSample + validEnd,
  18441. info.numSamples - validEnd); // partial cache miss at end
  18442. if (validStart < validEnd)
  18443. {
  18444. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18445. {
  18446. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18447. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18448. if (startBufferIndex < endBufferIndex)
  18449. {
  18450. info.buffer->copyFrom (chan, info.startSample + validStart,
  18451. buffer,
  18452. chan, startBufferIndex,
  18453. validEnd - validStart);
  18454. }
  18455. else
  18456. {
  18457. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18458. info.buffer->copyFrom (chan, info.startSample + validStart,
  18459. buffer,
  18460. chan, startBufferIndex,
  18461. initialSize);
  18462. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18463. buffer,
  18464. chan, 0,
  18465. (validEnd - validStart) - initialSize);
  18466. }
  18467. }
  18468. }
  18469. nextPlayPos += info.numSamples;
  18470. if (source->isLooping() && nextPlayPos > 0)
  18471. nextPlayPos %= source->getTotalLength();
  18472. }
  18473. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18474. if (thread != 0)
  18475. thread->notify();
  18476. }
  18477. int BufferingAudioSource::getNextReadPosition() const
  18478. {
  18479. return (source->isLooping() && nextPlayPos > 0)
  18480. ? nextPlayPos % source->getTotalLength()
  18481. : nextPlayPos;
  18482. }
  18483. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18484. {
  18485. const ScopedLock sl (bufferStartPosLock);
  18486. nextPlayPos = newPosition;
  18487. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18488. if (thread != 0)
  18489. thread->notify();
  18490. }
  18491. bool BufferingAudioSource::readNextBufferChunk()
  18492. {
  18493. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18494. {
  18495. const ScopedLock sl (bufferStartPosLock);
  18496. if (wasSourceLooping != isLooping())
  18497. {
  18498. wasSourceLooping = isLooping();
  18499. bufferValidStart = 0;
  18500. bufferValidEnd = 0;
  18501. }
  18502. newBVS = jmax (0, nextPlayPos);
  18503. newBVE = newBVS + buffer.getNumSamples() - 4;
  18504. sectionToReadStart = 0;
  18505. sectionToReadEnd = 0;
  18506. const int maxChunkSize = 2048;
  18507. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18508. {
  18509. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18510. sectionToReadStart = newBVS;
  18511. sectionToReadEnd = newBVE;
  18512. bufferValidStart = 0;
  18513. bufferValidEnd = 0;
  18514. }
  18515. else if (abs (newBVS - bufferValidStart) > 512
  18516. || abs (newBVE - bufferValidEnd) > 512)
  18517. {
  18518. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18519. sectionToReadStart = bufferValidEnd;
  18520. sectionToReadEnd = newBVE;
  18521. bufferValidStart = newBVS;
  18522. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18523. }
  18524. }
  18525. if (sectionToReadStart != sectionToReadEnd)
  18526. {
  18527. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18528. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18529. if (bufferIndexStart < bufferIndexEnd)
  18530. {
  18531. readBufferSection (sectionToReadStart,
  18532. sectionToReadEnd - sectionToReadStart,
  18533. bufferIndexStart);
  18534. }
  18535. else
  18536. {
  18537. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18538. readBufferSection (sectionToReadStart,
  18539. initialSize,
  18540. bufferIndexStart);
  18541. readBufferSection (sectionToReadStart + initialSize,
  18542. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18543. 0);
  18544. }
  18545. const ScopedLock sl2 (bufferStartPosLock);
  18546. bufferValidStart = newBVS;
  18547. bufferValidEnd = newBVE;
  18548. return true;
  18549. }
  18550. else
  18551. {
  18552. return false;
  18553. }
  18554. }
  18555. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18556. {
  18557. if (source->getNextReadPosition() != start)
  18558. source->setNextReadPosition (start);
  18559. AudioSourceChannelInfo info;
  18560. info.buffer = &buffer;
  18561. info.startSample = bufferOffset;
  18562. info.numSamples = length;
  18563. source->getNextAudioBlock (info);
  18564. }
  18565. END_JUCE_NAMESPACE
  18566. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18567. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18568. BEGIN_JUCE_NAMESPACE
  18569. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18570. const bool deleteSourceWhenDeleted_)
  18571. : requiredNumberOfChannels (2),
  18572. source (source_),
  18573. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18574. buffer (2, 16)
  18575. {
  18576. remappedInfo.buffer = &buffer;
  18577. remappedInfo.startSample = 0;
  18578. }
  18579. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18580. {
  18581. if (deleteSourceWhenDeleted)
  18582. delete source;
  18583. }
  18584. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18585. {
  18586. const ScopedLock sl (lock);
  18587. requiredNumberOfChannels = requiredNumberOfChannels_;
  18588. }
  18589. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18590. {
  18591. const ScopedLock sl (lock);
  18592. remappedInputs.clear();
  18593. remappedOutputs.clear();
  18594. }
  18595. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18596. {
  18597. const ScopedLock sl (lock);
  18598. while (remappedInputs.size() < destIndex)
  18599. remappedInputs.add (-1);
  18600. remappedInputs.set (destIndex, sourceIndex);
  18601. }
  18602. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18603. {
  18604. const ScopedLock sl (lock);
  18605. while (remappedOutputs.size() < sourceIndex)
  18606. remappedOutputs.add (-1);
  18607. remappedOutputs.set (sourceIndex, destIndex);
  18608. }
  18609. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18610. {
  18611. const ScopedLock sl (lock);
  18612. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18613. return remappedInputs.getUnchecked (inputChannelIndex);
  18614. return -1;
  18615. }
  18616. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18617. {
  18618. const ScopedLock sl (lock);
  18619. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18620. return remappedOutputs .getUnchecked (outputChannelIndex);
  18621. return -1;
  18622. }
  18623. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18624. {
  18625. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18626. }
  18627. void ChannelRemappingAudioSource::releaseResources()
  18628. {
  18629. source->releaseResources();
  18630. }
  18631. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18632. {
  18633. const ScopedLock sl (lock);
  18634. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18635. const int numChans = bufferToFill.buffer->getNumChannels();
  18636. int i;
  18637. for (i = 0; i < buffer.getNumChannels(); ++i)
  18638. {
  18639. const int remappedChan = getRemappedInputChannel (i);
  18640. if (remappedChan >= 0 && remappedChan < numChans)
  18641. {
  18642. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18643. remappedChan,
  18644. bufferToFill.startSample,
  18645. bufferToFill.numSamples);
  18646. }
  18647. else
  18648. {
  18649. buffer.clear (i, 0, bufferToFill.numSamples);
  18650. }
  18651. }
  18652. remappedInfo.numSamples = bufferToFill.numSamples;
  18653. source->getNextAudioBlock (remappedInfo);
  18654. bufferToFill.clearActiveBufferRegion();
  18655. for (i = 0; i < requiredNumberOfChannels; ++i)
  18656. {
  18657. const int remappedChan = getRemappedOutputChannel (i);
  18658. if (remappedChan >= 0 && remappedChan < numChans)
  18659. {
  18660. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18661. buffer, i, 0, bufferToFill.numSamples);
  18662. }
  18663. }
  18664. }
  18665. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18666. {
  18667. XmlElement* e = new XmlElement ("MAPPINGS");
  18668. String ins, outs;
  18669. int i;
  18670. const ScopedLock sl (lock);
  18671. for (i = 0; i < remappedInputs.size(); ++i)
  18672. ins << remappedInputs.getUnchecked(i) << ' ';
  18673. for (i = 0; i < remappedOutputs.size(); ++i)
  18674. outs << remappedOutputs.getUnchecked(i) << ' ';
  18675. e->setAttribute ("inputs", ins.trimEnd());
  18676. e->setAttribute ("outputs", outs.trimEnd());
  18677. return e;
  18678. }
  18679. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18680. {
  18681. if (e.hasTagName ("MAPPINGS"))
  18682. {
  18683. const ScopedLock sl (lock);
  18684. clearAllMappings();
  18685. StringArray ins, outs;
  18686. ins.addTokens (e.getStringAttribute ("inputs"), false);
  18687. outs.addTokens (e.getStringAttribute ("outputs"), false);
  18688. int i;
  18689. for (i = 0; i < ins.size(); ++i)
  18690. remappedInputs.add (ins[i].getIntValue());
  18691. for (i = 0; i < outs.size(); ++i)
  18692. remappedOutputs.add (outs[i].getIntValue());
  18693. }
  18694. }
  18695. END_JUCE_NAMESPACE
  18696. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18697. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18698. BEGIN_JUCE_NAMESPACE
  18699. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18700. const bool deleteInputWhenDeleted_)
  18701. : input (inputSource),
  18702. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18703. {
  18704. jassert (inputSource != 0);
  18705. for (int i = 2; --i >= 0;)
  18706. iirFilters.add (new IIRFilter());
  18707. }
  18708. IIRFilterAudioSource::~IIRFilterAudioSource()
  18709. {
  18710. if (deleteInputWhenDeleted)
  18711. delete input;
  18712. }
  18713. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18714. {
  18715. for (int i = iirFilters.size(); --i >= 0;)
  18716. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18717. }
  18718. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18719. {
  18720. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18721. for (int i = iirFilters.size(); --i >= 0;)
  18722. iirFilters.getUnchecked(i)->reset();
  18723. }
  18724. void IIRFilterAudioSource::releaseResources()
  18725. {
  18726. input->releaseResources();
  18727. }
  18728. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18729. {
  18730. input->getNextAudioBlock (bufferToFill);
  18731. const int numChannels = bufferToFill.buffer->getNumChannels();
  18732. while (numChannels > iirFilters.size())
  18733. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  18734. for (int i = 0; i < numChannels; ++i)
  18735. iirFilters.getUnchecked(i)
  18736. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  18737. bufferToFill.numSamples);
  18738. }
  18739. END_JUCE_NAMESPACE
  18740. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18741. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  18742. BEGIN_JUCE_NAMESPACE
  18743. MixerAudioSource::MixerAudioSource()
  18744. : tempBuffer (2, 0),
  18745. currentSampleRate (0.0),
  18746. bufferSizeExpected (0)
  18747. {
  18748. }
  18749. MixerAudioSource::~MixerAudioSource()
  18750. {
  18751. removeAllInputs();
  18752. }
  18753. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  18754. {
  18755. if (input != 0 && ! inputs.contains (input))
  18756. {
  18757. double localRate;
  18758. int localBufferSize;
  18759. {
  18760. const ScopedLock sl (lock);
  18761. localRate = currentSampleRate;
  18762. localBufferSize = bufferSizeExpected;
  18763. }
  18764. if (localRate != 0.0)
  18765. input->prepareToPlay (localBufferSize, localRate);
  18766. const ScopedLock sl (lock);
  18767. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  18768. inputs.add (input);
  18769. }
  18770. }
  18771. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  18772. {
  18773. if (input != 0)
  18774. {
  18775. int index;
  18776. {
  18777. const ScopedLock sl (lock);
  18778. index = inputs.indexOf (input);
  18779. if (index >= 0)
  18780. {
  18781. inputsToDelete.shiftBits (index, 1);
  18782. inputs.remove (index);
  18783. }
  18784. }
  18785. if (index >= 0)
  18786. {
  18787. input->releaseResources();
  18788. if (deleteInput)
  18789. delete input;
  18790. }
  18791. }
  18792. }
  18793. void MixerAudioSource::removeAllInputs()
  18794. {
  18795. VoidArray inputsCopy;
  18796. BigInteger inputsToDeleteCopy;
  18797. {
  18798. const ScopedLock sl (lock);
  18799. inputsCopy = inputs;
  18800. inputsToDeleteCopy = inputsToDelete;
  18801. }
  18802. for (int i = inputsCopy.size(); --i >= 0;)
  18803. if (inputsToDeleteCopy[i])
  18804. delete (AudioSource*) inputsCopy[i];
  18805. }
  18806. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18807. {
  18808. tempBuffer.setSize (2, samplesPerBlockExpected);
  18809. const ScopedLock sl (lock);
  18810. currentSampleRate = sampleRate;
  18811. bufferSizeExpected = samplesPerBlockExpected;
  18812. for (int i = inputs.size(); --i >= 0;)
  18813. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  18814. sampleRate);
  18815. }
  18816. void MixerAudioSource::releaseResources()
  18817. {
  18818. const ScopedLock sl (lock);
  18819. for (int i = inputs.size(); --i >= 0;)
  18820. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  18821. tempBuffer.setSize (2, 0);
  18822. currentSampleRate = 0;
  18823. bufferSizeExpected = 0;
  18824. }
  18825. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18826. {
  18827. const ScopedLock sl (lock);
  18828. if (inputs.size() > 0)
  18829. {
  18830. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  18831. if (inputs.size() > 1)
  18832. {
  18833. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  18834. info.buffer->getNumSamples());
  18835. AudioSourceChannelInfo info2;
  18836. info2.buffer = &tempBuffer;
  18837. info2.numSamples = info.numSamples;
  18838. info2.startSample = 0;
  18839. for (int i = 1; i < inputs.size(); ++i)
  18840. {
  18841. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  18842. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  18843. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  18844. }
  18845. }
  18846. }
  18847. else
  18848. {
  18849. info.clearActiveBufferRegion();
  18850. }
  18851. }
  18852. END_JUCE_NAMESPACE
  18853. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  18854. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  18855. BEGIN_JUCE_NAMESPACE
  18856. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  18857. const bool deleteInputWhenDeleted_)
  18858. : input (inputSource),
  18859. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  18860. ratio (1.0),
  18861. lastRatio (1.0),
  18862. buffer (2, 0),
  18863. sampsInBuffer (0)
  18864. {
  18865. jassert (input != 0);
  18866. }
  18867. ResamplingAudioSource::~ResamplingAudioSource()
  18868. {
  18869. if (deleteInputWhenDeleted)
  18870. delete input;
  18871. }
  18872. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  18873. {
  18874. jassert (samplesInPerOutputSample > 0);
  18875. const ScopedLock sl (ratioLock);
  18876. ratio = jmax (0.0, samplesInPerOutputSample);
  18877. }
  18878. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  18879. double sampleRate)
  18880. {
  18881. const ScopedLock sl (ratioLock);
  18882. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18883. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  18884. buffer.clear();
  18885. sampsInBuffer = 0;
  18886. bufferPos = 0;
  18887. subSampleOffset = 0.0;
  18888. createLowPass (ratio);
  18889. resetFilters();
  18890. }
  18891. void ResamplingAudioSource::releaseResources()
  18892. {
  18893. input->releaseResources();
  18894. buffer.setSize (2, 0);
  18895. }
  18896. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18897. {
  18898. const ScopedLock sl (ratioLock);
  18899. if (lastRatio != ratio)
  18900. {
  18901. createLowPass (ratio);
  18902. lastRatio = ratio;
  18903. }
  18904. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  18905. int bufferSize = buffer.getNumSamples();
  18906. if (bufferSize < sampsNeeded + 8)
  18907. {
  18908. bufferPos %= bufferSize;
  18909. bufferSize = sampsNeeded + 32;
  18910. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  18911. }
  18912. bufferPos %= bufferSize;
  18913. int endOfBufferPos = bufferPos + sampsInBuffer;
  18914. while (sampsNeeded > sampsInBuffer)
  18915. {
  18916. endOfBufferPos %= bufferSize;
  18917. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  18918. bufferSize - endOfBufferPos);
  18919. AudioSourceChannelInfo readInfo;
  18920. readInfo.buffer = &buffer;
  18921. readInfo.numSamples = numToDo;
  18922. readInfo.startSample = endOfBufferPos;
  18923. input->getNextAudioBlock (readInfo);
  18924. if (ratio > 1.0001)
  18925. {
  18926. // for down-sampling, pre-apply the filter..
  18927. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18928. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  18929. }
  18930. sampsInBuffer += numToDo;
  18931. endOfBufferPos += numToDo;
  18932. }
  18933. float* dl = info.buffer->getSampleData (0, info.startSample);
  18934. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  18935. const float* const bl = buffer.getSampleData (0, 0);
  18936. const float* const br = buffer.getSampleData (1, 0);
  18937. int nextPos = (bufferPos + 1) % bufferSize;
  18938. for (int m = info.numSamples; --m >= 0;)
  18939. {
  18940. const float alpha = (float) subSampleOffset;
  18941. const float invAlpha = 1.0f - alpha;
  18942. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  18943. if (dr != 0)
  18944. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  18945. subSampleOffset += ratio;
  18946. jassert (sampsInBuffer > 0);
  18947. while (subSampleOffset >= 1.0)
  18948. {
  18949. if (++bufferPos >= bufferSize)
  18950. bufferPos = 0;
  18951. --sampsInBuffer;
  18952. nextPos = (bufferPos + 1) % bufferSize;
  18953. subSampleOffset -= 1.0;
  18954. }
  18955. }
  18956. if (ratio < 0.9999)
  18957. {
  18958. // for up-sampling, apply the filter after transposing..
  18959. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18960. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  18961. }
  18962. else if (ratio <= 1.0001)
  18963. {
  18964. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  18965. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  18966. {
  18967. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  18968. FilterState& fs = filterStates[i];
  18969. if (info.numSamples > 1)
  18970. {
  18971. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  18972. }
  18973. else
  18974. {
  18975. fs.y2 = fs.y1;
  18976. fs.x2 = fs.x1;
  18977. }
  18978. fs.y1 = fs.x1 = *endOfBuffer;
  18979. }
  18980. }
  18981. jassert (sampsInBuffer >= 0);
  18982. }
  18983. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  18984. {
  18985. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  18986. : 0.5 * frequencyRatio;
  18987. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  18988. const double nSquared = n * n;
  18989. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  18990. setFilterCoefficients (c1,
  18991. c1 * 2.0f,
  18992. c1,
  18993. 1.0,
  18994. c1 * 2.0 * (1.0 - nSquared),
  18995. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  18996. }
  18997. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  18998. {
  18999. const double a = 1.0 / c4;
  19000. c1 *= a;
  19001. c2 *= a;
  19002. c3 *= a;
  19003. c5 *= a;
  19004. c6 *= a;
  19005. coefficients[0] = c1;
  19006. coefficients[1] = c2;
  19007. coefficients[2] = c3;
  19008. coefficients[3] = c4;
  19009. coefficients[4] = c5;
  19010. coefficients[5] = c6;
  19011. }
  19012. void ResamplingAudioSource::resetFilters()
  19013. {
  19014. zeromem (filterStates, sizeof (filterStates));
  19015. }
  19016. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19017. {
  19018. while (--num >= 0)
  19019. {
  19020. const double in = *samples;
  19021. double out = coefficients[0] * in
  19022. + coefficients[1] * fs.x1
  19023. + coefficients[2] * fs.x2
  19024. - coefficients[4] * fs.y1
  19025. - coefficients[5] * fs.y2;
  19026. #if JUCE_INTEL
  19027. if (! (out < -1.0e-8 || out > 1.0e-8))
  19028. out = 0;
  19029. #endif
  19030. fs.x2 = fs.x1;
  19031. fs.x1 = in;
  19032. fs.y2 = fs.y1;
  19033. fs.y1 = out;
  19034. *samples++ = (float) out;
  19035. }
  19036. }
  19037. END_JUCE_NAMESPACE
  19038. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19039. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19040. BEGIN_JUCE_NAMESPACE
  19041. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19042. : frequency (1000.0),
  19043. sampleRate (44100.0),
  19044. currentPhase (0.0),
  19045. phasePerSample (0.0),
  19046. amplitude (0.5f)
  19047. {
  19048. }
  19049. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19050. {
  19051. }
  19052. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19053. {
  19054. amplitude = newAmplitude;
  19055. }
  19056. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19057. {
  19058. frequency = newFrequencyHz;
  19059. phasePerSample = 0.0;
  19060. }
  19061. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19062. double sampleRate_)
  19063. {
  19064. currentPhase = 0.0;
  19065. phasePerSample = 0.0;
  19066. sampleRate = sampleRate_;
  19067. }
  19068. void ToneGeneratorAudioSource::releaseResources()
  19069. {
  19070. }
  19071. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19072. {
  19073. if (phasePerSample == 0.0)
  19074. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19075. for (int i = 0; i < info.numSamples; ++i)
  19076. {
  19077. const float sample = amplitude * (float) sin (currentPhase);
  19078. currentPhase += phasePerSample;
  19079. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19080. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19081. }
  19082. }
  19083. END_JUCE_NAMESPACE
  19084. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19085. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19086. BEGIN_JUCE_NAMESPACE
  19087. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19088. : sampleRate (0),
  19089. bufferSize (0),
  19090. useDefaultInputChannels (true),
  19091. useDefaultOutputChannels (true)
  19092. {
  19093. }
  19094. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19095. {
  19096. return outputDeviceName == other.outputDeviceName
  19097. && inputDeviceName == other.inputDeviceName
  19098. && sampleRate == other.sampleRate
  19099. && bufferSize == other.bufferSize
  19100. && inputChannels == other.inputChannels
  19101. && useDefaultInputChannels == other.useDefaultInputChannels
  19102. && outputChannels == other.outputChannels
  19103. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19104. }
  19105. AudioDeviceManager::AudioDeviceManager()
  19106. : currentAudioDevice (0),
  19107. numInputChansNeeded (0),
  19108. numOutputChansNeeded (2),
  19109. listNeedsScanning (true),
  19110. useInputNames (false),
  19111. inputLevelMeasurementEnabledCount (0),
  19112. inputLevel (0),
  19113. tempBuffer (2, 2),
  19114. defaultMidiOutput (0),
  19115. cpuUsageMs (0),
  19116. timeToCpuScale (0)
  19117. {
  19118. callbackHandler.owner = this;
  19119. }
  19120. AudioDeviceManager::~AudioDeviceManager()
  19121. {
  19122. currentAudioDevice = 0;
  19123. defaultMidiOutput = 0;
  19124. }
  19125. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19126. {
  19127. if (availableDeviceTypes.size() == 0)
  19128. {
  19129. createAudioDeviceTypes (availableDeviceTypes);
  19130. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19131. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19132. if (availableDeviceTypes.size() > 0)
  19133. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19134. }
  19135. }
  19136. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19137. {
  19138. scanDevicesIfNeeded();
  19139. return availableDeviceTypes;
  19140. }
  19141. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19142. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19143. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19144. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19145. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19146. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19147. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19148. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19149. {
  19150. #if JUCE_WINDOWS
  19151. #if JUCE_WASAPI
  19152. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19153. list.add (juce_createAudioIODeviceType_WASAPI());
  19154. #endif
  19155. #if JUCE_DIRECTSOUND
  19156. list.add (juce_createAudioIODeviceType_DirectSound());
  19157. #endif
  19158. #if JUCE_ASIO
  19159. list.add (juce_createAudioIODeviceType_ASIO());
  19160. #endif
  19161. #endif
  19162. #if JUCE_MAC
  19163. list.add (juce_createAudioIODeviceType_CoreAudio());
  19164. #endif
  19165. #if JUCE_IPHONE
  19166. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19167. #endif
  19168. #if JUCE_LINUX && JUCE_ALSA
  19169. list.add (juce_createAudioIODeviceType_ALSA());
  19170. #endif
  19171. #if JUCE_LINUX && JUCE_JACK
  19172. list.add (juce_createAudioIODeviceType_JACK());
  19173. #endif
  19174. }
  19175. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19176. const int numOutputChannelsNeeded,
  19177. const XmlElement* const e,
  19178. const bool selectDefaultDeviceOnFailure,
  19179. const String& preferredDefaultDeviceName,
  19180. const AudioDeviceSetup* preferredSetupOptions)
  19181. {
  19182. scanDevicesIfNeeded();
  19183. numInputChansNeeded = numInputChannelsNeeded;
  19184. numOutputChansNeeded = numOutputChannelsNeeded;
  19185. if (e != 0 && e->hasTagName ("DEVICESETUP"))
  19186. {
  19187. lastExplicitSettings = new XmlElement (*e);
  19188. String error;
  19189. AudioDeviceSetup setup;
  19190. if (preferredSetupOptions != 0)
  19191. setup = *preferredSetupOptions;
  19192. if (e->getStringAttribute ("audioDeviceName").isNotEmpty())
  19193. {
  19194. setup.inputDeviceName = setup.outputDeviceName
  19195. = e->getStringAttribute ("audioDeviceName");
  19196. }
  19197. else
  19198. {
  19199. setup.inputDeviceName = e->getStringAttribute ("audioInputDeviceName");
  19200. setup.outputDeviceName = e->getStringAttribute ("audioOutputDeviceName");
  19201. }
  19202. currentDeviceType = e->getStringAttribute ("deviceType");
  19203. if (currentDeviceType.isEmpty())
  19204. {
  19205. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19206. if (type != 0)
  19207. currentDeviceType = type->getTypeName();
  19208. else if (availableDeviceTypes.size() > 0)
  19209. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19210. }
  19211. setup.bufferSize = e->getIntAttribute ("audioDeviceBufferSize");
  19212. setup.sampleRate = e->getDoubleAttribute ("audioDeviceRate");
  19213. setup.inputChannels.parseString (e->getStringAttribute ("audioDeviceInChans", "11"), 2);
  19214. setup.outputChannels.parseString (e->getStringAttribute ("audioDeviceOutChans", "11"), 2);
  19215. setup.useDefaultInputChannels = ! e->hasAttribute ("audioDeviceInChans");
  19216. setup.useDefaultOutputChannels = ! e->hasAttribute ("audioDeviceOutChans");
  19217. error = setAudioDeviceSetup (setup, true);
  19218. midiInsFromXml.clear();
  19219. forEachXmlChildElementWithTagName (*e, c, "MIDIINPUT")
  19220. midiInsFromXml.add (c->getStringAttribute ("name"));
  19221. const StringArray allMidiIns (MidiInput::getDevices());
  19222. for (int i = allMidiIns.size(); --i >= 0;)
  19223. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19224. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19225. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19226. false, preferredDefaultDeviceName);
  19227. setDefaultMidiOutput (e->getStringAttribute ("defaultMidiOutput"));
  19228. return error;
  19229. }
  19230. else
  19231. {
  19232. AudioDeviceSetup setup;
  19233. if (preferredSetupOptions != 0)
  19234. {
  19235. setup = *preferredSetupOptions;
  19236. }
  19237. else if (preferredDefaultDeviceName.isNotEmpty())
  19238. {
  19239. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19240. {
  19241. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19242. StringArray outs (type->getDeviceNames (false));
  19243. int i;
  19244. for (i = 0; i < outs.size(); ++i)
  19245. {
  19246. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19247. {
  19248. setup.outputDeviceName = outs[i];
  19249. break;
  19250. }
  19251. }
  19252. StringArray ins (type->getDeviceNames (true));
  19253. for (i = 0; i < ins.size(); ++i)
  19254. {
  19255. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19256. {
  19257. setup.inputDeviceName = ins[i];
  19258. break;
  19259. }
  19260. }
  19261. }
  19262. }
  19263. insertDefaultDeviceNames (setup);
  19264. return setAudioDeviceSetup (setup, false);
  19265. }
  19266. }
  19267. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19268. {
  19269. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19270. if (type != 0)
  19271. {
  19272. if (setup.outputDeviceName.isEmpty())
  19273. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19274. if (setup.inputDeviceName.isEmpty())
  19275. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19276. }
  19277. }
  19278. XmlElement* AudioDeviceManager::createStateXml() const
  19279. {
  19280. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19281. }
  19282. void AudioDeviceManager::scanDevicesIfNeeded()
  19283. {
  19284. if (listNeedsScanning)
  19285. {
  19286. listNeedsScanning = false;
  19287. createDeviceTypesIfNeeded();
  19288. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19289. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19290. }
  19291. }
  19292. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19293. {
  19294. scanDevicesIfNeeded();
  19295. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19296. {
  19297. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19298. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19299. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19300. {
  19301. return type;
  19302. }
  19303. }
  19304. return 0;
  19305. }
  19306. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19307. {
  19308. setup = currentSetup;
  19309. }
  19310. void AudioDeviceManager::deleteCurrentDevice()
  19311. {
  19312. currentAudioDevice = 0;
  19313. currentSetup.inputDeviceName = String::empty;
  19314. currentSetup.outputDeviceName = String::empty;
  19315. }
  19316. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19317. const bool treatAsChosenDevice)
  19318. {
  19319. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19320. {
  19321. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19322. && currentDeviceType != type)
  19323. {
  19324. currentDeviceType = type;
  19325. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19326. insertDefaultDeviceNames (s);
  19327. setAudioDeviceSetup (s, treatAsChosenDevice);
  19328. sendChangeMessage (this);
  19329. break;
  19330. }
  19331. }
  19332. }
  19333. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19334. {
  19335. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19336. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19337. return availableDeviceTypes[i];
  19338. return availableDeviceTypes[0];
  19339. }
  19340. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19341. const bool treatAsChosenDevice)
  19342. {
  19343. jassert (&newSetup != &currentSetup); // this will have no effect
  19344. if (newSetup == currentSetup && currentAudioDevice != 0)
  19345. return String::empty;
  19346. if (! (newSetup == currentSetup))
  19347. sendChangeMessage (this);
  19348. stopDevice();
  19349. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19350. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19351. String error;
  19352. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19353. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19354. {
  19355. deleteCurrentDevice();
  19356. if (treatAsChosenDevice)
  19357. updateXml();
  19358. return String::empty;
  19359. }
  19360. if (currentSetup.inputDeviceName != newInputDeviceName
  19361. || currentSetup.outputDeviceName != newOutputDeviceName
  19362. || currentAudioDevice == 0)
  19363. {
  19364. deleteCurrentDevice();
  19365. scanDevicesIfNeeded();
  19366. if (newOutputDeviceName.isNotEmpty()
  19367. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19368. {
  19369. return "No such device: " + newOutputDeviceName;
  19370. }
  19371. if (newInputDeviceName.isNotEmpty()
  19372. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19373. {
  19374. return "No such device: " + newInputDeviceName;
  19375. }
  19376. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19377. if (currentAudioDevice == 0)
  19378. 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!";
  19379. else
  19380. error = currentAudioDevice->getLastError();
  19381. if (error.isNotEmpty())
  19382. {
  19383. deleteCurrentDevice();
  19384. return error;
  19385. }
  19386. if (newSetup.useDefaultInputChannels)
  19387. {
  19388. inputChannels.clear();
  19389. inputChannels.setRange (0, numInputChansNeeded, true);
  19390. }
  19391. if (newSetup.useDefaultOutputChannels)
  19392. {
  19393. outputChannels.clear();
  19394. outputChannels.setRange (0, numOutputChansNeeded, true);
  19395. }
  19396. if (newInputDeviceName.isEmpty())
  19397. inputChannels.clear();
  19398. if (newOutputDeviceName.isEmpty())
  19399. outputChannels.clear();
  19400. }
  19401. if (! newSetup.useDefaultInputChannels)
  19402. inputChannels = newSetup.inputChannels;
  19403. if (! newSetup.useDefaultOutputChannels)
  19404. outputChannels = newSetup.outputChannels;
  19405. currentSetup = newSetup;
  19406. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19407. error = currentAudioDevice->open (inputChannels,
  19408. outputChannels,
  19409. currentSetup.sampleRate,
  19410. currentSetup.bufferSize);
  19411. if (error.isEmpty())
  19412. {
  19413. currentDeviceType = currentAudioDevice->getTypeName();
  19414. currentAudioDevice->start (&callbackHandler);
  19415. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19416. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19417. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19418. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19419. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19420. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19421. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19422. if (treatAsChosenDevice)
  19423. updateXml();
  19424. }
  19425. else
  19426. {
  19427. deleteCurrentDevice();
  19428. }
  19429. return error;
  19430. }
  19431. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19432. {
  19433. jassert (currentAudioDevice != 0);
  19434. if (rate > 0)
  19435. {
  19436. bool ok = false;
  19437. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19438. {
  19439. const double sr = currentAudioDevice->getSampleRate (i);
  19440. if (sr == rate)
  19441. ok = true;
  19442. }
  19443. if (! ok)
  19444. rate = 0;
  19445. }
  19446. if (rate == 0)
  19447. {
  19448. double lowestAbove44 = 0.0;
  19449. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19450. {
  19451. const double sr = currentAudioDevice->getSampleRate (i);
  19452. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19453. lowestAbove44 = sr;
  19454. }
  19455. if (lowestAbove44 == 0.0)
  19456. rate = currentAudioDevice->getSampleRate (0);
  19457. else
  19458. rate = lowestAbove44;
  19459. }
  19460. return rate;
  19461. }
  19462. void AudioDeviceManager::stopDevice()
  19463. {
  19464. if (currentAudioDevice != 0)
  19465. currentAudioDevice->stop();
  19466. testSound = 0;
  19467. }
  19468. void AudioDeviceManager::closeAudioDevice()
  19469. {
  19470. stopDevice();
  19471. currentAudioDevice = 0;
  19472. }
  19473. void AudioDeviceManager::restartLastAudioDevice()
  19474. {
  19475. if (currentAudioDevice == 0)
  19476. {
  19477. if (currentSetup.inputDeviceName.isEmpty()
  19478. && currentSetup.outputDeviceName.isEmpty())
  19479. {
  19480. // This method will only reload the last device that was running
  19481. // before closeAudioDevice() was called - you need to actually open
  19482. // one first, with setAudioDevice().
  19483. jassertfalse
  19484. return;
  19485. }
  19486. AudioDeviceSetup s (currentSetup);
  19487. setAudioDeviceSetup (s, false);
  19488. }
  19489. }
  19490. void AudioDeviceManager::updateXml()
  19491. {
  19492. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19493. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19494. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19495. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19496. if (currentAudioDevice != 0)
  19497. {
  19498. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19499. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19500. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19501. if (! currentSetup.useDefaultInputChannels)
  19502. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19503. if (! currentSetup.useDefaultOutputChannels)
  19504. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19505. }
  19506. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19507. {
  19508. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19509. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19510. }
  19511. if (midiInsFromXml.size() > 0)
  19512. {
  19513. // Add any midi devices that have been enabled before, but which aren't currently
  19514. // open because the device has been disconnected.
  19515. const StringArray availableMidiDevices (MidiInput::getDevices());
  19516. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19517. {
  19518. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19519. {
  19520. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19521. m->setAttribute ("name", midiInsFromXml[i]);
  19522. }
  19523. }
  19524. }
  19525. if (defaultMidiOutputName.isNotEmpty())
  19526. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19527. }
  19528. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19529. {
  19530. {
  19531. const ScopedLock sl (audioCallbackLock);
  19532. if (callbacks.contains (newCallback))
  19533. return;
  19534. }
  19535. if (currentAudioDevice != 0 && newCallback != 0)
  19536. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19537. const ScopedLock sl (audioCallbackLock);
  19538. callbacks.add (newCallback);
  19539. }
  19540. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19541. {
  19542. if (callback != 0)
  19543. {
  19544. bool needsDeinitialising = currentAudioDevice != 0;
  19545. {
  19546. const ScopedLock sl (audioCallbackLock);
  19547. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19548. callbacks.removeValue (callback);
  19549. }
  19550. if (needsDeinitialising)
  19551. callback->audioDeviceStopped();
  19552. }
  19553. }
  19554. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19555. int numInputChannels,
  19556. float** outputChannelData,
  19557. int numOutputChannels,
  19558. int numSamples)
  19559. {
  19560. const ScopedLock sl (audioCallbackLock);
  19561. if (inputLevelMeasurementEnabledCount > 0)
  19562. {
  19563. for (int j = 0; j < numSamples; ++j)
  19564. {
  19565. float s = 0;
  19566. for (int i = 0; i < numInputChannels; ++i)
  19567. s += fabsf (inputChannelData[i][j]);
  19568. s /= numInputChannels;
  19569. const double decayFactor = 0.99992;
  19570. if (s > inputLevel)
  19571. inputLevel = s;
  19572. else if (inputLevel > 0.001f)
  19573. inputLevel *= decayFactor;
  19574. else
  19575. inputLevel = 0;
  19576. }
  19577. }
  19578. if (callbacks.size() > 0)
  19579. {
  19580. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19581. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19582. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19583. outputChannelData, numOutputChannels, numSamples);
  19584. float** const tempChans = tempBuffer.getArrayOfChannels();
  19585. for (int i = callbacks.size(); --i > 0;)
  19586. {
  19587. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19588. tempChans, numOutputChannels, numSamples);
  19589. for (int chan = 0; chan < numOutputChannels; ++chan)
  19590. {
  19591. const float* const src = tempChans [chan];
  19592. float* const dst = outputChannelData [chan];
  19593. if (src != 0 && dst != 0)
  19594. for (int j = 0; j < numSamples; ++j)
  19595. dst[j] += src[j];
  19596. }
  19597. }
  19598. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19599. const double filterAmount = 0.2;
  19600. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19601. }
  19602. else
  19603. {
  19604. for (int i = 0; i < numOutputChannels; ++i)
  19605. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19606. }
  19607. if (testSound != 0)
  19608. {
  19609. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19610. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19611. for (int i = 0; i < numOutputChannels; ++i)
  19612. for (int j = 0; j < numSamps; ++j)
  19613. outputChannelData [i][j] += src[j];
  19614. testSoundPosition += numSamps;
  19615. if (testSoundPosition >= testSound->getNumSamples())
  19616. testSound = 0;
  19617. }
  19618. }
  19619. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19620. {
  19621. cpuUsageMs = 0;
  19622. const double sampleRate = device->getCurrentSampleRate();
  19623. const int blockSize = device->getCurrentBufferSizeSamples();
  19624. if (sampleRate > 0.0 && blockSize > 0)
  19625. {
  19626. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19627. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19628. }
  19629. {
  19630. const ScopedLock sl (audioCallbackLock);
  19631. for (int i = callbacks.size(); --i >= 0;)
  19632. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19633. }
  19634. sendChangeMessage (this);
  19635. }
  19636. void AudioDeviceManager::audioDeviceStoppedInt()
  19637. {
  19638. cpuUsageMs = 0;
  19639. timeToCpuScale = 0;
  19640. sendChangeMessage (this);
  19641. const ScopedLock sl (audioCallbackLock);
  19642. for (int i = callbacks.size(); --i >= 0;)
  19643. callbacks.getUnchecked(i)->audioDeviceStopped();
  19644. }
  19645. double AudioDeviceManager::getCpuUsage() const
  19646. {
  19647. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19648. }
  19649. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19650. const bool enabled)
  19651. {
  19652. if (enabled != isMidiInputEnabled (name))
  19653. {
  19654. if (enabled)
  19655. {
  19656. const int index = MidiInput::getDevices().indexOf (name);
  19657. if (index >= 0)
  19658. {
  19659. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19660. if (min != 0)
  19661. {
  19662. enabledMidiInputs.add (min);
  19663. min->start();
  19664. }
  19665. }
  19666. }
  19667. else
  19668. {
  19669. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19670. if (enabledMidiInputs[i]->getName() == name)
  19671. enabledMidiInputs.remove (i);
  19672. }
  19673. updateXml();
  19674. sendChangeMessage (this);
  19675. }
  19676. }
  19677. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19678. {
  19679. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19680. if (enabledMidiInputs[i]->getName() == name)
  19681. return true;
  19682. return false;
  19683. }
  19684. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19685. MidiInputCallback* callback)
  19686. {
  19687. removeMidiInputCallback (name, callback);
  19688. if (name.isEmpty())
  19689. {
  19690. midiCallbacks.add (callback);
  19691. midiCallbackDevices.add (0);
  19692. }
  19693. else
  19694. {
  19695. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19696. {
  19697. if (enabledMidiInputs[i]->getName() == name)
  19698. {
  19699. const ScopedLock sl (midiCallbackLock);
  19700. midiCallbacks.add (callback);
  19701. midiCallbackDevices.add (enabledMidiInputs[i]);
  19702. break;
  19703. }
  19704. }
  19705. }
  19706. }
  19707. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19708. MidiInputCallback* /*callback*/)
  19709. {
  19710. const ScopedLock sl (midiCallbackLock);
  19711. for (int i = midiCallbacks.size(); --i >= 0;)
  19712. {
  19713. String devName;
  19714. if (midiCallbackDevices.getUnchecked(i) != 0)
  19715. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19716. if (devName == name)
  19717. {
  19718. midiCallbacks.remove (i);
  19719. midiCallbackDevices.remove (i);
  19720. }
  19721. }
  19722. }
  19723. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  19724. const MidiMessage& message)
  19725. {
  19726. if (! message.isActiveSense())
  19727. {
  19728. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  19729. const ScopedLock sl (midiCallbackLock);
  19730. for (int i = midiCallbackDevices.size(); --i >= 0;)
  19731. {
  19732. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  19733. if (md == source || (md == 0 && isDefaultSource))
  19734. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  19735. }
  19736. }
  19737. }
  19738. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  19739. {
  19740. if (defaultMidiOutputName != deviceName)
  19741. {
  19742. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  19743. {
  19744. const ScopedLock sl (audioCallbackLock);
  19745. oldCallbacks = callbacks;
  19746. callbacks.clear();
  19747. }
  19748. if (currentAudioDevice != 0)
  19749. for (int i = oldCallbacks.size(); --i >= 0;)
  19750. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  19751. defaultMidiOutput = 0;
  19752. defaultMidiOutputName = deviceName;
  19753. if (deviceName.isNotEmpty())
  19754. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  19755. if (currentAudioDevice != 0)
  19756. for (int i = oldCallbacks.size(); --i >= 0;)
  19757. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  19758. {
  19759. const ScopedLock sl (audioCallbackLock);
  19760. callbacks = oldCallbacks;
  19761. }
  19762. updateXml();
  19763. sendChangeMessage (this);
  19764. }
  19765. }
  19766. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  19767. int numInputChannels,
  19768. float** outputChannelData,
  19769. int numOutputChannels,
  19770. int numSamples)
  19771. {
  19772. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  19773. }
  19774. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  19775. {
  19776. owner->audioDeviceAboutToStartInt (device);
  19777. }
  19778. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  19779. {
  19780. owner->audioDeviceStoppedInt();
  19781. }
  19782. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  19783. {
  19784. owner->handleIncomingMidiMessageInt (source, message);
  19785. }
  19786. void AudioDeviceManager::playTestSound()
  19787. {
  19788. { // cunningly nested to swap, unlock and delete in that order.
  19789. ScopedPointer <AudioSampleBuffer> oldSound;
  19790. {
  19791. const ScopedLock sl (audioCallbackLock);
  19792. oldSound = testSound;
  19793. }
  19794. }
  19795. testSoundPosition = 0;
  19796. if (currentAudioDevice != 0)
  19797. {
  19798. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  19799. const int soundLength = (int) sampleRate;
  19800. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  19801. float* samples = newSound->getSampleData (0);
  19802. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  19803. const float amplitude = 0.5f;
  19804. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19805. for (int i = 0; i < soundLength; ++i)
  19806. samples[i] = amplitude * (float) sin (i * phasePerSample);
  19807. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  19808. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  19809. const ScopedLock sl (audioCallbackLock);
  19810. testSound = newSound;
  19811. }
  19812. }
  19813. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  19814. {
  19815. const ScopedLock sl (audioCallbackLock);
  19816. if (enableMeasurement)
  19817. ++inputLevelMeasurementEnabledCount;
  19818. else
  19819. --inputLevelMeasurementEnabledCount;
  19820. inputLevel = 0;
  19821. }
  19822. double AudioDeviceManager::getCurrentInputLevel() const
  19823. {
  19824. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  19825. return inputLevel;
  19826. }
  19827. END_JUCE_NAMESPACE
  19828. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  19829. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  19830. BEGIN_JUCE_NAMESPACE
  19831. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  19832. : name (deviceName),
  19833. typeName (typeName_)
  19834. {
  19835. }
  19836. AudioIODevice::~AudioIODevice()
  19837. {
  19838. }
  19839. bool AudioIODevice::hasControlPanel() const
  19840. {
  19841. return false;
  19842. }
  19843. bool AudioIODevice::showControlPanel()
  19844. {
  19845. jassertfalse // this should only be called for devices which return true from
  19846. // their hasControlPanel() method.
  19847. return false;
  19848. }
  19849. END_JUCE_NAMESPACE
  19850. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  19851. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  19852. BEGIN_JUCE_NAMESPACE
  19853. AudioIODeviceType::AudioIODeviceType (const String& name)
  19854. : typeName (name)
  19855. {
  19856. }
  19857. AudioIODeviceType::~AudioIODeviceType()
  19858. {
  19859. }
  19860. END_JUCE_NAMESPACE
  19861. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  19862. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  19863. BEGIN_JUCE_NAMESPACE
  19864. MidiOutput::MidiOutput()
  19865. : Thread ("midi out"),
  19866. internal (0),
  19867. firstMessage (0)
  19868. {
  19869. }
  19870. MidiOutput::PendingMessage::PendingMessage (const uint8* const data, const int len,
  19871. const double sampleNumber)
  19872. : message (data, len, sampleNumber)
  19873. {
  19874. }
  19875. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  19876. const double millisecondCounterToStartAt,
  19877. double samplesPerSecondForBuffer)
  19878. {
  19879. // You've got to call startBackgroundThread() for this to actually work..
  19880. jassert (isThreadRunning());
  19881. // this needs to be a value in the future - RTFM for this method!
  19882. jassert (millisecondCounterToStartAt > 0);
  19883. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  19884. MidiBuffer::Iterator i (buffer);
  19885. const uint8* data;
  19886. int len, time;
  19887. while (i.getNextEvent (data, len, time))
  19888. {
  19889. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  19890. PendingMessage* const m
  19891. = new PendingMessage (data, len, eventTime);
  19892. const ScopedLock sl (lock);
  19893. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  19894. {
  19895. m->next = firstMessage;
  19896. firstMessage = m;
  19897. }
  19898. else
  19899. {
  19900. PendingMessage* mm = firstMessage;
  19901. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  19902. mm = mm->next;
  19903. m->next = mm->next;
  19904. mm->next = m;
  19905. }
  19906. }
  19907. notify();
  19908. }
  19909. void MidiOutput::clearAllPendingMessages()
  19910. {
  19911. const ScopedLock sl (lock);
  19912. while (firstMessage != 0)
  19913. {
  19914. PendingMessage* const m = firstMessage;
  19915. firstMessage = firstMessage->next;
  19916. delete m;
  19917. }
  19918. }
  19919. void MidiOutput::startBackgroundThread()
  19920. {
  19921. startThread (9);
  19922. }
  19923. void MidiOutput::stopBackgroundThread()
  19924. {
  19925. stopThread (5000);
  19926. }
  19927. void MidiOutput::run()
  19928. {
  19929. while (! threadShouldExit())
  19930. {
  19931. uint32 now = Time::getMillisecondCounter();
  19932. uint32 eventTime = 0;
  19933. uint32 timeToWait = 500;
  19934. PendingMessage* message;
  19935. {
  19936. const ScopedLock sl (lock);
  19937. message = firstMessage;
  19938. if (message != 0)
  19939. {
  19940. eventTime = roundToInt (message->message.getTimeStamp());
  19941. if (eventTime > now + 20)
  19942. {
  19943. timeToWait = eventTime - (now + 20);
  19944. message = 0;
  19945. }
  19946. else
  19947. {
  19948. firstMessage = message->next;
  19949. }
  19950. }
  19951. }
  19952. if (message != 0)
  19953. {
  19954. if (eventTime > now)
  19955. {
  19956. Time::waitForMillisecondCounter (eventTime);
  19957. if (threadShouldExit())
  19958. break;
  19959. }
  19960. if (eventTime > now - 200)
  19961. sendMessageNow (message->message);
  19962. delete message;
  19963. }
  19964. else
  19965. {
  19966. jassert (timeToWait < 1000 * 30);
  19967. wait (timeToWait);
  19968. }
  19969. }
  19970. clearAllPendingMessages();
  19971. }
  19972. END_JUCE_NAMESPACE
  19973. /*** End of inlined file: juce_MidiOutput.cpp ***/
  19974. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  19975. BEGIN_JUCE_NAMESPACE
  19976. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19977. {
  19978. const double maxVal = (double) 0x7fff;
  19979. char* intData = static_cast <char*> (dest);
  19980. if (dest != (void*) source || destBytesPerSample <= 4)
  19981. {
  19982. for (int i = 0; i < numSamples; ++i)
  19983. {
  19984. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19985. intData += destBytesPerSample;
  19986. }
  19987. }
  19988. else
  19989. {
  19990. intData += destBytesPerSample * numSamples;
  19991. for (int i = numSamples; --i >= 0;)
  19992. {
  19993. intData -= destBytesPerSample;
  19994. *(uint16*) intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  19995. }
  19996. }
  19997. }
  19998. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  19999. {
  20000. const double maxVal = (double) 0x7fff;
  20001. char* intData = static_cast <char*> (dest);
  20002. if (dest != (void*) source || destBytesPerSample <= 4)
  20003. {
  20004. for (int i = 0; i < numSamples; ++i)
  20005. {
  20006. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20007. intData += destBytesPerSample;
  20008. }
  20009. }
  20010. else
  20011. {
  20012. intData += destBytesPerSample * numSamples;
  20013. for (int i = numSamples; --i >= 0;)
  20014. {
  20015. intData -= destBytesPerSample;
  20016. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20017. }
  20018. }
  20019. }
  20020. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20021. {
  20022. const double maxVal = (double) 0x7fffff;
  20023. char* intData = static_cast <char*> (dest);
  20024. if (dest != (void*) source || destBytesPerSample <= 4)
  20025. {
  20026. for (int i = 0; i < numSamples; ++i)
  20027. {
  20028. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20029. intData += destBytesPerSample;
  20030. }
  20031. }
  20032. else
  20033. {
  20034. intData += destBytesPerSample * numSamples;
  20035. for (int i = numSamples; --i >= 0;)
  20036. {
  20037. intData -= destBytesPerSample;
  20038. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20039. }
  20040. }
  20041. }
  20042. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20043. {
  20044. const double maxVal = (double) 0x7fffff;
  20045. char* intData = static_cast <char*> (dest);
  20046. if (dest != (void*) source || destBytesPerSample <= 4)
  20047. {
  20048. for (int i = 0; i < numSamples; ++i)
  20049. {
  20050. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20051. intData += destBytesPerSample;
  20052. }
  20053. }
  20054. else
  20055. {
  20056. intData += destBytesPerSample * numSamples;
  20057. for (int i = numSamples; --i >= 0;)
  20058. {
  20059. intData -= destBytesPerSample;
  20060. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20061. }
  20062. }
  20063. }
  20064. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20065. {
  20066. const double maxVal = (double) 0x7fffffff;
  20067. char* intData = static_cast <char*> (dest);
  20068. if (dest != (void*) source || destBytesPerSample <= 4)
  20069. {
  20070. for (int i = 0; i < numSamples; ++i)
  20071. {
  20072. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20073. intData += destBytesPerSample;
  20074. }
  20075. }
  20076. else
  20077. {
  20078. intData += destBytesPerSample * numSamples;
  20079. for (int i = numSamples; --i >= 0;)
  20080. {
  20081. intData -= destBytesPerSample;
  20082. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20083. }
  20084. }
  20085. }
  20086. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20087. {
  20088. const double maxVal = (double) 0x7fffffff;
  20089. char* intData = static_cast <char*> (dest);
  20090. if (dest != (void*) source || destBytesPerSample <= 4)
  20091. {
  20092. for (int i = 0; i < numSamples; ++i)
  20093. {
  20094. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20095. intData += destBytesPerSample;
  20096. }
  20097. }
  20098. else
  20099. {
  20100. intData += destBytesPerSample * numSamples;
  20101. for (int i = numSamples; --i >= 0;)
  20102. {
  20103. intData -= destBytesPerSample;
  20104. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20105. }
  20106. }
  20107. }
  20108. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20109. {
  20110. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20111. char* d = static_cast <char*> (dest);
  20112. for (int i = 0; i < numSamples; ++i)
  20113. {
  20114. *(float*) d = source[i];
  20115. #if JUCE_BIG_ENDIAN
  20116. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20117. #endif
  20118. d += destBytesPerSample;
  20119. }
  20120. }
  20121. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20122. {
  20123. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20124. char* d = static_cast <char*> (dest);
  20125. for (int i = 0; i < numSamples; ++i)
  20126. {
  20127. *(float*) d = source[i];
  20128. #if JUCE_LITTLE_ENDIAN
  20129. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20130. #endif
  20131. d += destBytesPerSample;
  20132. }
  20133. }
  20134. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20135. {
  20136. const float scale = 1.0f / 0x7fff;
  20137. const char* intData = static_cast <const char*> (source);
  20138. if (source != (void*) dest || srcBytesPerSample >= 4)
  20139. {
  20140. for (int i = 0; i < numSamples; ++i)
  20141. {
  20142. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20143. intData += srcBytesPerSample;
  20144. }
  20145. }
  20146. else
  20147. {
  20148. intData += srcBytesPerSample * numSamples;
  20149. for (int i = numSamples; --i >= 0;)
  20150. {
  20151. intData -= srcBytesPerSample;
  20152. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20153. }
  20154. }
  20155. }
  20156. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20157. {
  20158. const float scale = 1.0f / 0x7fff;
  20159. const char* intData = static_cast <const char*> (source);
  20160. if (source != (void*) dest || srcBytesPerSample >= 4)
  20161. {
  20162. for (int i = 0; i < numSamples; ++i)
  20163. {
  20164. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20165. intData += srcBytesPerSample;
  20166. }
  20167. }
  20168. else
  20169. {
  20170. intData += srcBytesPerSample * numSamples;
  20171. for (int i = numSamples; --i >= 0;)
  20172. {
  20173. intData -= srcBytesPerSample;
  20174. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20175. }
  20176. }
  20177. }
  20178. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20179. {
  20180. const float scale = 1.0f / 0x7fffff;
  20181. const char* intData = static_cast <const char*> (source);
  20182. if (source != (void*) dest || srcBytesPerSample >= 4)
  20183. {
  20184. for (int i = 0; i < numSamples; ++i)
  20185. {
  20186. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20187. intData += srcBytesPerSample;
  20188. }
  20189. }
  20190. else
  20191. {
  20192. intData += srcBytesPerSample * numSamples;
  20193. for (int i = numSamples; --i >= 0;)
  20194. {
  20195. intData -= srcBytesPerSample;
  20196. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20197. }
  20198. }
  20199. }
  20200. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20201. {
  20202. const float scale = 1.0f / 0x7fffff;
  20203. const char* intData = static_cast <const char*> (source);
  20204. if (source != (void*) dest || srcBytesPerSample >= 4)
  20205. {
  20206. for (int i = 0; i < numSamples; ++i)
  20207. {
  20208. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20209. intData += srcBytesPerSample;
  20210. }
  20211. }
  20212. else
  20213. {
  20214. intData += srcBytesPerSample * numSamples;
  20215. for (int i = numSamples; --i >= 0;)
  20216. {
  20217. intData -= srcBytesPerSample;
  20218. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20219. }
  20220. }
  20221. }
  20222. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20223. {
  20224. const float scale = 1.0f / 0x7fffffff;
  20225. const char* intData = static_cast <const char*> (source);
  20226. if (source != (void*) dest || srcBytesPerSample >= 4)
  20227. {
  20228. for (int i = 0; i < numSamples; ++i)
  20229. {
  20230. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20231. intData += srcBytesPerSample;
  20232. }
  20233. }
  20234. else
  20235. {
  20236. intData += srcBytesPerSample * numSamples;
  20237. for (int i = numSamples; --i >= 0;)
  20238. {
  20239. intData -= srcBytesPerSample;
  20240. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20241. }
  20242. }
  20243. }
  20244. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20245. {
  20246. const float scale = 1.0f / 0x7fffffff;
  20247. const char* intData = static_cast <const char*> (source);
  20248. if (source != (void*) dest || srcBytesPerSample >= 4)
  20249. {
  20250. for (int i = 0; i < numSamples; ++i)
  20251. {
  20252. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20253. intData += srcBytesPerSample;
  20254. }
  20255. }
  20256. else
  20257. {
  20258. intData += srcBytesPerSample * numSamples;
  20259. for (int i = numSamples; --i >= 0;)
  20260. {
  20261. intData -= srcBytesPerSample;
  20262. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20263. }
  20264. }
  20265. }
  20266. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20267. {
  20268. const char* s = static_cast <const char*> (source);
  20269. for (int i = 0; i < numSamples; ++i)
  20270. {
  20271. dest[i] = *(float*)s;
  20272. #if JUCE_BIG_ENDIAN
  20273. uint32* const d = (uint32*) (dest + i);
  20274. *d = ByteOrder::swap (*d);
  20275. #endif
  20276. s += srcBytesPerSample;
  20277. }
  20278. }
  20279. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20280. {
  20281. const char* s = static_cast <const char*> (source);
  20282. for (int i = 0; i < numSamples; ++i)
  20283. {
  20284. dest[i] = *(float*)s;
  20285. #if JUCE_LITTLE_ENDIAN
  20286. uint32* const d = (uint32*) (dest + i);
  20287. *d = ByteOrder::swap (*d);
  20288. #endif
  20289. s += srcBytesPerSample;
  20290. }
  20291. }
  20292. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20293. const float* const source,
  20294. void* const dest,
  20295. const int numSamples)
  20296. {
  20297. switch (destFormat)
  20298. {
  20299. case int16LE:
  20300. convertFloatToInt16LE (source, dest, numSamples);
  20301. break;
  20302. case int16BE:
  20303. convertFloatToInt16BE (source, dest, numSamples);
  20304. break;
  20305. case int24LE:
  20306. convertFloatToInt24LE (source, dest, numSamples);
  20307. break;
  20308. case int24BE:
  20309. convertFloatToInt24BE (source, dest, numSamples);
  20310. break;
  20311. case int32LE:
  20312. convertFloatToInt32LE (source, dest, numSamples);
  20313. break;
  20314. case int32BE:
  20315. convertFloatToInt32BE (source, dest, numSamples);
  20316. break;
  20317. case float32LE:
  20318. convertFloatToFloat32LE (source, dest, numSamples);
  20319. break;
  20320. case float32BE:
  20321. convertFloatToFloat32BE (source, dest, numSamples);
  20322. break;
  20323. default:
  20324. jassertfalse
  20325. break;
  20326. }
  20327. }
  20328. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20329. const void* const source,
  20330. float* const dest,
  20331. const int numSamples)
  20332. {
  20333. switch (sourceFormat)
  20334. {
  20335. case int16LE:
  20336. convertInt16LEToFloat (source, dest, numSamples);
  20337. break;
  20338. case int16BE:
  20339. convertInt16BEToFloat (source, dest, numSamples);
  20340. break;
  20341. case int24LE:
  20342. convertInt24LEToFloat (source, dest, numSamples);
  20343. break;
  20344. case int24BE:
  20345. convertInt24BEToFloat (source, dest, numSamples);
  20346. break;
  20347. case int32LE:
  20348. convertInt32LEToFloat (source, dest, numSamples);
  20349. break;
  20350. case int32BE:
  20351. convertInt32BEToFloat (source, dest, numSamples);
  20352. break;
  20353. case float32LE:
  20354. convertFloat32LEToFloat (source, dest, numSamples);
  20355. break;
  20356. case float32BE:
  20357. convertFloat32BEToFloat (source, dest, numSamples);
  20358. break;
  20359. default:
  20360. jassertfalse
  20361. break;
  20362. }
  20363. }
  20364. void AudioDataConverters::interleaveSamples (const float** const source,
  20365. float* const dest,
  20366. const int numSamples,
  20367. const int numChannels)
  20368. {
  20369. for (int chan = 0; chan < numChannels; ++chan)
  20370. {
  20371. int i = chan;
  20372. const float* src = source [chan];
  20373. for (int j = 0; j < numSamples; ++j)
  20374. {
  20375. dest [i] = src [j];
  20376. i += numChannels;
  20377. }
  20378. }
  20379. }
  20380. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20381. float** const dest,
  20382. const int numSamples,
  20383. const int numChannels)
  20384. {
  20385. for (int chan = 0; chan < numChannels; ++chan)
  20386. {
  20387. int i = chan;
  20388. float* dst = dest [chan];
  20389. for (int j = 0; j < numSamples; ++j)
  20390. {
  20391. dst [j] = source [i];
  20392. i += numChannels;
  20393. }
  20394. }
  20395. }
  20396. END_JUCE_NAMESPACE
  20397. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20398. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20399. BEGIN_JUCE_NAMESPACE
  20400. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20401. const int numSamples) throw()
  20402. : numChannels (numChannels_),
  20403. size (numSamples)
  20404. {
  20405. jassert (numSamples >= 0);
  20406. jassert (numChannels_ > 0);
  20407. allocateData();
  20408. }
  20409. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20410. : numChannels (other.numChannels),
  20411. size (other.size)
  20412. {
  20413. allocateData();
  20414. const size_t numBytes = size * sizeof (float);
  20415. for (int i = 0; i < numChannels; ++i)
  20416. memcpy (channels[i], other.channels[i], numBytes);
  20417. }
  20418. void AudioSampleBuffer::allocateData()
  20419. {
  20420. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20421. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20422. allocatedData.malloc (allocatedBytes);
  20423. channels = reinterpret_cast <float**> (allocatedData.getData());
  20424. float* chan = (float*) (allocatedData + channelListSize);
  20425. for (int i = 0; i < numChannels; ++i)
  20426. {
  20427. channels[i] = chan;
  20428. chan += size;
  20429. }
  20430. channels [numChannels] = 0;
  20431. }
  20432. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20433. const int numChannels_,
  20434. const int numSamples) throw()
  20435. : numChannels (numChannels_),
  20436. size (numSamples),
  20437. allocatedBytes (0)
  20438. {
  20439. jassert (numChannels_ > 0);
  20440. allocateChannels (dataToReferTo);
  20441. }
  20442. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20443. const int newNumChannels,
  20444. const int newNumSamples) throw()
  20445. {
  20446. jassert (newNumChannels > 0);
  20447. allocatedBytes = 0;
  20448. allocatedData.free();
  20449. numChannels = newNumChannels;
  20450. size = newNumSamples;
  20451. allocateChannels (dataToReferTo);
  20452. }
  20453. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20454. {
  20455. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20456. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20457. {
  20458. channels = static_cast <float**> (preallocatedChannelSpace);
  20459. }
  20460. else
  20461. {
  20462. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20463. channels = reinterpret_cast <float**> (allocatedData.getData());
  20464. }
  20465. for (int i = 0; i < numChannels; ++i)
  20466. {
  20467. // you have to pass in the same number of valid pointers as numChannels
  20468. jassert (dataToReferTo[i] != 0);
  20469. channels[i] = dataToReferTo[i];
  20470. }
  20471. channels [numChannels] = 0;
  20472. }
  20473. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20474. {
  20475. if (this != &other)
  20476. {
  20477. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20478. const size_t numBytes = size * sizeof (float);
  20479. for (int i = 0; i < numChannels; ++i)
  20480. memcpy (channels[i], other.channels[i], numBytes);
  20481. }
  20482. return *this;
  20483. }
  20484. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20485. {
  20486. }
  20487. void AudioSampleBuffer::setSize (const int newNumChannels,
  20488. const int newNumSamples,
  20489. const bool keepExistingContent,
  20490. const bool clearExtraSpace,
  20491. const bool avoidReallocating) throw()
  20492. {
  20493. jassert (newNumChannels > 0);
  20494. if (newNumSamples != size || newNumChannels != numChannels)
  20495. {
  20496. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20497. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20498. if (keepExistingContent)
  20499. {
  20500. HeapBlock <char> newData;
  20501. newData.allocate (newTotalBytes, clearExtraSpace);
  20502. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20503. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20504. float** const newChannels = reinterpret_cast <float**> (newData.getData());
  20505. float* newChan = reinterpret_cast <float*> (newData + channelListSize);
  20506. for (int i = 0; i < numChansToCopy; ++i)
  20507. {
  20508. memcpy (newChan, channels[i], numBytesToCopy);
  20509. newChannels[i] = newChan;
  20510. newChan += newNumSamples;
  20511. }
  20512. allocatedData.swapWith (newData);
  20513. allocatedBytes = (int) newTotalBytes;
  20514. channels = newChannels;
  20515. }
  20516. else
  20517. {
  20518. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20519. {
  20520. if (clearExtraSpace)
  20521. zeromem (allocatedData, newTotalBytes);
  20522. }
  20523. else
  20524. {
  20525. allocatedBytes = newTotalBytes;
  20526. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20527. channels = reinterpret_cast <float**> (allocatedData.getData());
  20528. }
  20529. float* chan = reinterpret_cast <float*> (allocatedData + channelListSize);
  20530. for (int i = 0; i < newNumChannels; ++i)
  20531. {
  20532. channels[i] = chan;
  20533. chan += newNumSamples;
  20534. }
  20535. }
  20536. channels [newNumChannels] = 0;
  20537. size = newNumSamples;
  20538. numChannels = newNumChannels;
  20539. }
  20540. }
  20541. void AudioSampleBuffer::clear() throw()
  20542. {
  20543. for (int i = 0; i < numChannels; ++i)
  20544. zeromem (channels[i], size * sizeof (float));
  20545. }
  20546. void AudioSampleBuffer::clear (const int startSample,
  20547. const int numSamples) throw()
  20548. {
  20549. jassert (startSample >= 0 && startSample + numSamples <= size);
  20550. for (int i = 0; i < numChannels; ++i)
  20551. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20552. }
  20553. void AudioSampleBuffer::clear (const int channel,
  20554. const int startSample,
  20555. const int numSamples) throw()
  20556. {
  20557. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20558. jassert (startSample >= 0 && startSample + numSamples <= size);
  20559. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20560. }
  20561. void AudioSampleBuffer::applyGain (const int channel,
  20562. const int startSample,
  20563. int numSamples,
  20564. const float gain) throw()
  20565. {
  20566. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20567. jassert (startSample >= 0 && startSample + numSamples <= size);
  20568. if (gain != 1.0f)
  20569. {
  20570. float* d = channels [channel] + startSample;
  20571. if (gain == 0.0f)
  20572. {
  20573. zeromem (d, sizeof (float) * numSamples);
  20574. }
  20575. else
  20576. {
  20577. while (--numSamples >= 0)
  20578. *d++ *= gain;
  20579. }
  20580. }
  20581. }
  20582. void AudioSampleBuffer::applyGainRamp (const int channel,
  20583. const int startSample,
  20584. int numSamples,
  20585. float startGain,
  20586. float endGain) throw()
  20587. {
  20588. if (startGain == endGain)
  20589. {
  20590. applyGain (channel, startSample, numSamples, startGain);
  20591. }
  20592. else
  20593. {
  20594. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20595. jassert (startSample >= 0 && startSample + numSamples <= size);
  20596. const float increment = (endGain - startGain) / numSamples;
  20597. float* d = channels [channel] + startSample;
  20598. while (--numSamples >= 0)
  20599. {
  20600. *d++ *= startGain;
  20601. startGain += increment;
  20602. }
  20603. }
  20604. }
  20605. void AudioSampleBuffer::applyGain (const int startSample,
  20606. const int numSamples,
  20607. const float gain) throw()
  20608. {
  20609. for (int i = 0; i < numChannels; ++i)
  20610. applyGain (i, startSample, numSamples, gain);
  20611. }
  20612. void AudioSampleBuffer::addFrom (const int destChannel,
  20613. const int destStartSample,
  20614. const AudioSampleBuffer& source,
  20615. const int sourceChannel,
  20616. const int sourceStartSample,
  20617. int numSamples,
  20618. const float gain) throw()
  20619. {
  20620. jassert (&source != this || sourceChannel != destChannel);
  20621. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20622. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20623. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20624. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20625. if (gain != 0.0f && numSamples > 0)
  20626. {
  20627. float* d = channels [destChannel] + destStartSample;
  20628. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20629. if (gain != 1.0f)
  20630. {
  20631. while (--numSamples >= 0)
  20632. *d++ += gain * *s++;
  20633. }
  20634. else
  20635. {
  20636. while (--numSamples >= 0)
  20637. *d++ += *s++;
  20638. }
  20639. }
  20640. }
  20641. void AudioSampleBuffer::addFrom (const int destChannel,
  20642. const int destStartSample,
  20643. const float* source,
  20644. int numSamples,
  20645. const float gain) throw()
  20646. {
  20647. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20648. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20649. jassert (source != 0);
  20650. if (gain != 0.0f && numSamples > 0)
  20651. {
  20652. float* d = channels [destChannel] + destStartSample;
  20653. if (gain != 1.0f)
  20654. {
  20655. while (--numSamples >= 0)
  20656. *d++ += gain * *source++;
  20657. }
  20658. else
  20659. {
  20660. while (--numSamples >= 0)
  20661. *d++ += *source++;
  20662. }
  20663. }
  20664. }
  20665. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20666. const int destStartSample,
  20667. const float* source,
  20668. int numSamples,
  20669. float startGain,
  20670. const float endGain) throw()
  20671. {
  20672. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20673. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20674. jassert (source != 0);
  20675. if (startGain == endGain)
  20676. {
  20677. addFrom (destChannel,
  20678. destStartSample,
  20679. source,
  20680. numSamples,
  20681. startGain);
  20682. }
  20683. else
  20684. {
  20685. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20686. {
  20687. const float increment = (endGain - startGain) / numSamples;
  20688. float* d = channels [destChannel] + destStartSample;
  20689. while (--numSamples >= 0)
  20690. {
  20691. *d++ += startGain * *source++;
  20692. startGain += increment;
  20693. }
  20694. }
  20695. }
  20696. }
  20697. void AudioSampleBuffer::copyFrom (const int destChannel,
  20698. const int destStartSample,
  20699. const AudioSampleBuffer& source,
  20700. const int sourceChannel,
  20701. const int sourceStartSample,
  20702. int numSamples) throw()
  20703. {
  20704. jassert (&source != this || sourceChannel != destChannel);
  20705. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20706. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20707. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20708. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20709. if (numSamples > 0)
  20710. {
  20711. memcpy (channels [destChannel] + destStartSample,
  20712. source.channels [sourceChannel] + sourceStartSample,
  20713. sizeof (float) * numSamples);
  20714. }
  20715. }
  20716. void AudioSampleBuffer::copyFrom (const int destChannel,
  20717. const int destStartSample,
  20718. const float* source,
  20719. int numSamples) throw()
  20720. {
  20721. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20722. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20723. jassert (source != 0);
  20724. if (numSamples > 0)
  20725. {
  20726. memcpy (channels [destChannel] + destStartSample,
  20727. source,
  20728. sizeof (float) * numSamples);
  20729. }
  20730. }
  20731. void AudioSampleBuffer::copyFrom (const int destChannel,
  20732. const int destStartSample,
  20733. const float* source,
  20734. int numSamples,
  20735. const float gain) throw()
  20736. {
  20737. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20738. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20739. jassert (source != 0);
  20740. if (numSamples > 0)
  20741. {
  20742. float* d = channels [destChannel] + destStartSample;
  20743. if (gain != 1.0f)
  20744. {
  20745. if (gain == 0)
  20746. {
  20747. zeromem (d, sizeof (float) * numSamples);
  20748. }
  20749. else
  20750. {
  20751. while (--numSamples >= 0)
  20752. *d++ = gain * *source++;
  20753. }
  20754. }
  20755. else
  20756. {
  20757. memcpy (d, source, sizeof (float) * numSamples);
  20758. }
  20759. }
  20760. }
  20761. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  20762. const int destStartSample,
  20763. const float* source,
  20764. int numSamples,
  20765. float startGain,
  20766. float endGain) throw()
  20767. {
  20768. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20769. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20770. jassert (source != 0);
  20771. if (startGain == endGain)
  20772. {
  20773. copyFrom (destChannel,
  20774. destStartSample,
  20775. source,
  20776. numSamples,
  20777. startGain);
  20778. }
  20779. else
  20780. {
  20781. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20782. {
  20783. const float increment = (endGain - startGain) / numSamples;
  20784. float* d = channels [destChannel] + destStartSample;
  20785. while (--numSamples >= 0)
  20786. {
  20787. *d++ = startGain * *source++;
  20788. startGain += increment;
  20789. }
  20790. }
  20791. }
  20792. }
  20793. void AudioSampleBuffer::findMinMax (const int channel,
  20794. const int startSample,
  20795. int numSamples,
  20796. float& minVal,
  20797. float& maxVal) const throw()
  20798. {
  20799. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20800. jassert (startSample >= 0 && startSample + numSamples <= size);
  20801. if (numSamples <= 0)
  20802. {
  20803. minVal = 0.0f;
  20804. maxVal = 0.0f;
  20805. }
  20806. else
  20807. {
  20808. const float* d = channels [channel] + startSample;
  20809. float mn = *d++;
  20810. float mx = mn;
  20811. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  20812. {
  20813. const float samp = *d++;
  20814. if (samp > mx)
  20815. mx = samp;
  20816. if (samp < mn)
  20817. mn = samp;
  20818. }
  20819. maxVal = mx;
  20820. minVal = mn;
  20821. }
  20822. }
  20823. float AudioSampleBuffer::getMagnitude (const int channel,
  20824. const int startSample,
  20825. const int numSamples) const throw()
  20826. {
  20827. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20828. jassert (startSample >= 0 && startSample + numSamples <= size);
  20829. float mn, mx;
  20830. findMinMax (channel, startSample, numSamples, mn, mx);
  20831. return jmax (mn, -mn, mx, -mx);
  20832. }
  20833. float AudioSampleBuffer::getMagnitude (const int startSample,
  20834. const int numSamples) const throw()
  20835. {
  20836. float mag = 0.0f;
  20837. for (int i = 0; i < numChannels; ++i)
  20838. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  20839. return mag;
  20840. }
  20841. float AudioSampleBuffer::getRMSLevel (const int channel,
  20842. const int startSample,
  20843. const int numSamples) const throw()
  20844. {
  20845. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20846. jassert (startSample >= 0 && startSample + numSamples <= size);
  20847. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  20848. return 0.0f;
  20849. const float* const data = channels [channel] + startSample;
  20850. double sum = 0.0;
  20851. for (int i = 0; i < numSamples; ++i)
  20852. {
  20853. const float sample = data [i];
  20854. sum += sample * sample;
  20855. }
  20856. return (float) sqrt (sum / numSamples);
  20857. }
  20858. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  20859. const int startSample,
  20860. const int numSamples,
  20861. const int readerStartSample,
  20862. const bool useLeftChan,
  20863. const bool useRightChan) throw()
  20864. {
  20865. jassert (reader != 0);
  20866. jassert (startSample >= 0 && startSample + numSamples <= size);
  20867. if (numSamples > 0)
  20868. {
  20869. int* chans[3];
  20870. if (useLeftChan == useRightChan)
  20871. {
  20872. chans[0] = (int*) getSampleData (0, startSample);
  20873. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  20874. }
  20875. else if (useLeftChan || (reader->numChannels == 1))
  20876. {
  20877. chans[0] = (int*) getSampleData (0, startSample);
  20878. chans[1] = 0;
  20879. }
  20880. else if (useRightChan)
  20881. {
  20882. chans[0] = 0;
  20883. chans[1] = (int*) getSampleData (0, startSample);
  20884. }
  20885. chans[2] = 0;
  20886. reader->read (chans, 2, readerStartSample, numSamples, true);
  20887. if (! reader->usesFloatingPointData)
  20888. {
  20889. for (int j = 0; j < 2; ++j)
  20890. {
  20891. float* const d = reinterpret_cast <float*> (chans[j]);
  20892. if (d != 0)
  20893. {
  20894. const float multiplier = 1.0f / 0x7fffffff;
  20895. for (int i = 0; i < numSamples; ++i)
  20896. d[i] = *(int*)(d + i) * multiplier;
  20897. }
  20898. }
  20899. }
  20900. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  20901. {
  20902. // if this is a stereo buffer and the source was mono, dupe the first channel..
  20903. memcpy (getSampleData (1, startSample),
  20904. getSampleData (0, startSample),
  20905. sizeof (float) * numSamples);
  20906. }
  20907. }
  20908. }
  20909. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  20910. const int startSample,
  20911. const int numSamples) const throw()
  20912. {
  20913. jassert (startSample >= 0 && startSample + numSamples <= size);
  20914. if (numSamples > 0)
  20915. {
  20916. int* chans [3];
  20917. if (writer->isFloatingPoint())
  20918. {
  20919. chans[0] = (int*) getSampleData (0, startSample);
  20920. if (numChannels > 1)
  20921. chans[1] = (int*) getSampleData (1, startSample);
  20922. else
  20923. chans[1] = 0;
  20924. chans[2] = 0;
  20925. writer->write ((const int**) chans, numSamples);
  20926. }
  20927. else
  20928. {
  20929. HeapBlock <int> tempBuffer (numSamples * 2);
  20930. chans[0] = tempBuffer;
  20931. if (numChannels > 1)
  20932. chans[1] = chans[0] + numSamples;
  20933. else
  20934. chans[1] = 0;
  20935. chans[2] = 0;
  20936. for (int j = 0; j < 2; ++j)
  20937. {
  20938. int* const dest = chans[j];
  20939. if (dest != 0)
  20940. {
  20941. const float* const src = channels [j] + startSample;
  20942. for (int i = 0; i < numSamples; ++i)
  20943. {
  20944. const double samp = src[i];
  20945. if (samp <= -1.0)
  20946. dest[i] = std::numeric_limits<int>::min();
  20947. else if (samp >= 1.0)
  20948. dest[i] = std::numeric_limits<int>::max();
  20949. else
  20950. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  20951. }
  20952. }
  20953. }
  20954. writer->write ((const int**) chans, numSamples);
  20955. }
  20956. }
  20957. }
  20958. END_JUCE_NAMESPACE
  20959. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  20960. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  20961. BEGIN_JUCE_NAMESPACE
  20962. IIRFilter::IIRFilter()
  20963. : active (false)
  20964. {
  20965. reset();
  20966. }
  20967. IIRFilter::IIRFilter (const IIRFilter& other)
  20968. : active (other.active)
  20969. {
  20970. const ScopedLock sl (other.processLock);
  20971. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  20972. reset();
  20973. }
  20974. IIRFilter::~IIRFilter()
  20975. {
  20976. }
  20977. void IIRFilter::reset() throw()
  20978. {
  20979. const ScopedLock sl (processLock);
  20980. x1 = 0;
  20981. x2 = 0;
  20982. y1 = 0;
  20983. y2 = 0;
  20984. }
  20985. float IIRFilter::processSingleSampleRaw (const float in) throw()
  20986. {
  20987. float out = coefficients[0] * in
  20988. + coefficients[1] * x1
  20989. + coefficients[2] * x2
  20990. - coefficients[4] * y1
  20991. - coefficients[5] * y2;
  20992. #if JUCE_INTEL
  20993. if (! (out < -1.0e-8 || out > 1.0e-8))
  20994. out = 0;
  20995. #endif
  20996. x2 = x1;
  20997. x1 = in;
  20998. y2 = y1;
  20999. y1 = out;
  21000. return out;
  21001. }
  21002. void IIRFilter::processSamples (float* const samples,
  21003. const int numSamples) throw()
  21004. {
  21005. const ScopedLock sl (processLock);
  21006. if (active)
  21007. {
  21008. for (int i = 0; i < numSamples; ++i)
  21009. {
  21010. const float in = samples[i];
  21011. float out = coefficients[0] * in
  21012. + coefficients[1] * x1
  21013. + coefficients[2] * x2
  21014. - coefficients[4] * y1
  21015. - coefficients[5] * y2;
  21016. #if JUCE_INTEL
  21017. if (! (out < -1.0e-8 || out > 1.0e-8))
  21018. out = 0;
  21019. #endif
  21020. x2 = x1;
  21021. x1 = in;
  21022. y2 = y1;
  21023. y1 = out;
  21024. samples[i] = out;
  21025. }
  21026. }
  21027. }
  21028. void IIRFilter::makeLowPass (const double sampleRate,
  21029. const double frequency) throw()
  21030. {
  21031. jassert (sampleRate > 0);
  21032. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21033. const double nSquared = n * n;
  21034. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21035. setCoefficients (c1,
  21036. c1 * 2.0f,
  21037. c1,
  21038. 1.0,
  21039. c1 * 2.0 * (1.0 - nSquared),
  21040. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21041. }
  21042. void IIRFilter::makeHighPass (const double sampleRate,
  21043. const double frequency) throw()
  21044. {
  21045. const double n = tan (double_Pi * frequency / sampleRate);
  21046. const double nSquared = n * n;
  21047. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21048. setCoefficients (c1,
  21049. c1 * -2.0f,
  21050. c1,
  21051. 1.0,
  21052. c1 * 2.0 * (nSquared - 1.0),
  21053. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21054. }
  21055. void IIRFilter::makeLowShelf (const double sampleRate,
  21056. const double cutOffFrequency,
  21057. const double Q,
  21058. const float gainFactor) throw()
  21059. {
  21060. jassert (sampleRate > 0);
  21061. jassert (Q > 0);
  21062. const double A = jmax (0.0f, gainFactor);
  21063. const double aminus1 = A - 1.0;
  21064. const double aplus1 = A + 1.0;
  21065. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21066. const double coso = cos (omega);
  21067. const double beta = sin (omega) * sqrt (A) / Q;
  21068. const double aminus1TimesCoso = aminus1 * coso;
  21069. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21070. A * 2.0 * (aminus1 - aplus1 * coso),
  21071. A * (aplus1 - aminus1TimesCoso - beta),
  21072. aplus1 + aminus1TimesCoso + beta,
  21073. -2.0 * (aminus1 + aplus1 * coso),
  21074. aplus1 + aminus1TimesCoso - beta);
  21075. }
  21076. void IIRFilter::makeHighShelf (const double sampleRate,
  21077. const double cutOffFrequency,
  21078. const double Q,
  21079. const float gainFactor) throw()
  21080. {
  21081. jassert (sampleRate > 0);
  21082. jassert (Q > 0);
  21083. const double A = jmax (0.0f, gainFactor);
  21084. const double aminus1 = A - 1.0;
  21085. const double aplus1 = A + 1.0;
  21086. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21087. const double coso = cos (omega);
  21088. const double beta = sin (omega) * sqrt (A) / Q;
  21089. const double aminus1TimesCoso = aminus1 * coso;
  21090. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21091. A * -2.0 * (aminus1 + aplus1 * coso),
  21092. A * (aplus1 + aminus1TimesCoso - beta),
  21093. aplus1 - aminus1TimesCoso + beta,
  21094. 2.0 * (aminus1 - aplus1 * coso),
  21095. aplus1 - aminus1TimesCoso - beta);
  21096. }
  21097. void IIRFilter::makeBandPass (const double sampleRate,
  21098. const double centreFrequency,
  21099. const double Q,
  21100. const float gainFactor) throw()
  21101. {
  21102. jassert (sampleRate > 0);
  21103. jassert (Q > 0);
  21104. const double A = jmax (0.0f, gainFactor);
  21105. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21106. const double alpha = 0.5 * sin (omega) / Q;
  21107. const double c2 = -2.0 * cos (omega);
  21108. const double alphaTimesA = alpha * A;
  21109. const double alphaOverA = alpha / A;
  21110. setCoefficients (1.0 + alphaTimesA,
  21111. c2,
  21112. 1.0 - alphaTimesA,
  21113. 1.0 + alphaOverA,
  21114. c2,
  21115. 1.0 - alphaOverA);
  21116. }
  21117. void IIRFilter::makeInactive() throw()
  21118. {
  21119. const ScopedLock sl (processLock);
  21120. active = false;
  21121. }
  21122. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21123. {
  21124. const ScopedLock sl (processLock);
  21125. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21126. active = other.active;
  21127. }
  21128. void IIRFilter::setCoefficients (double c1,
  21129. double c2,
  21130. double c3,
  21131. double c4,
  21132. double c5,
  21133. double c6) throw()
  21134. {
  21135. const double a = 1.0 / c4;
  21136. c1 *= a;
  21137. c2 *= a;
  21138. c3 *= a;
  21139. c5 *= a;
  21140. c6 *= a;
  21141. const ScopedLock sl (processLock);
  21142. coefficients[0] = (float) c1;
  21143. coefficients[1] = (float) c2;
  21144. coefficients[2] = (float) c3;
  21145. coefficients[3] = (float) c4;
  21146. coefficients[4] = (float) c5;
  21147. coefficients[5] = (float) c6;
  21148. active = true;
  21149. }
  21150. END_JUCE_NAMESPACE
  21151. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21152. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21153. BEGIN_JUCE_NAMESPACE
  21154. MidiBuffer::MidiBuffer() throw()
  21155. : bytesUsed (0)
  21156. {
  21157. }
  21158. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21159. : bytesUsed (0)
  21160. {
  21161. addEvent (message, 0);
  21162. }
  21163. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21164. : data (other.data),
  21165. bytesUsed (other.bytesUsed)
  21166. {
  21167. }
  21168. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21169. {
  21170. bytesUsed = other.bytesUsed;
  21171. data = other.data;
  21172. return *this;
  21173. }
  21174. void MidiBuffer::swapWith (MidiBuffer& other)
  21175. {
  21176. data.swapWith (other.data);
  21177. swapVariables <int> (bytesUsed, other.bytesUsed);
  21178. }
  21179. MidiBuffer::~MidiBuffer() throw()
  21180. {
  21181. }
  21182. inline uint8* MidiBuffer::getData() const throw()
  21183. {
  21184. return static_cast <uint8*> (data.getData());
  21185. }
  21186. inline int MidiBuffer::getEventTime (const void* const d) throw()
  21187. {
  21188. return *static_cast <const int*> (d);
  21189. }
  21190. inline uint16 MidiBuffer::getEventDataSize (const void* const d) throw()
  21191. {
  21192. return *reinterpret_cast <const uint16*> (static_cast <const char*> (d) + sizeof (int));
  21193. }
  21194. inline uint16 MidiBuffer::getEventTotalSize (const void* const d) throw()
  21195. {
  21196. return getEventDataSize (d) + sizeof (int) + sizeof (uint16);
  21197. }
  21198. void MidiBuffer::clear() throw()
  21199. {
  21200. bytesUsed = 0;
  21201. }
  21202. void MidiBuffer::clear (const int startSample,
  21203. const int numSamples) throw()
  21204. {
  21205. uint8* const start = findEventAfter (getData(), startSample - 1);
  21206. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21207. if (end > start)
  21208. {
  21209. const int bytesToMove = bytesUsed - (int) (end - getData());
  21210. if (bytesToMove > 0)
  21211. memmove (start, end, bytesToMove);
  21212. bytesUsed -= (int) (end - start);
  21213. }
  21214. }
  21215. void MidiBuffer::addEvent (const MidiMessage& m,
  21216. const int sampleNumber) throw()
  21217. {
  21218. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21219. }
  21220. static int findActualEventLength (const uint8* const data,
  21221. const int maxBytes) throw()
  21222. {
  21223. unsigned int byte = (unsigned int) *data;
  21224. int size = 0;
  21225. if (byte == 0xf0 || byte == 0xf7)
  21226. {
  21227. const uint8* d = data + 1;
  21228. while (d < data + maxBytes)
  21229. if (*d++ == 0xf7)
  21230. break;
  21231. size = (int) (d - data);
  21232. }
  21233. else if (byte == 0xff)
  21234. {
  21235. int n;
  21236. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21237. size = jmin (maxBytes, n + 2 + bytesLeft);
  21238. }
  21239. else if (byte >= 0x80)
  21240. {
  21241. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21242. }
  21243. return size;
  21244. }
  21245. void MidiBuffer::addEvent (const uint8* const newData,
  21246. const int maxBytes,
  21247. const int sampleNumber) throw()
  21248. {
  21249. const int numBytes = findActualEventLength (newData, maxBytes);
  21250. if (numBytes > 0)
  21251. {
  21252. int spaceNeeded = bytesUsed + numBytes + sizeof (int) + sizeof (uint16);
  21253. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21254. uint8* d = findEventAfter (getData(), sampleNumber);
  21255. const int bytesToMove = bytesUsed - (int) (d - getData());
  21256. if (bytesToMove > 0)
  21257. memmove (d + numBytes + sizeof (int) + sizeof (uint16), d, bytesToMove);
  21258. *reinterpret_cast <int*> (d) = sampleNumber;
  21259. d += sizeof (int);
  21260. *reinterpret_cast <uint16*> (d) = (uint16) numBytes;
  21261. d += sizeof (uint16);
  21262. memcpy (d, newData, numBytes);
  21263. bytesUsed += numBytes + sizeof (int) + sizeof (uint16);
  21264. }
  21265. }
  21266. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21267. const int startSample,
  21268. const int numSamples,
  21269. const int sampleDeltaToAdd) throw()
  21270. {
  21271. Iterator i (otherBuffer);
  21272. i.setNextSamplePosition (startSample);
  21273. const uint8* eventData;
  21274. int eventSize, position;
  21275. while (i.getNextEvent (eventData, eventSize, position)
  21276. && (position < startSample + numSamples || numSamples < 0))
  21277. {
  21278. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21279. }
  21280. }
  21281. bool MidiBuffer::isEmpty() const throw()
  21282. {
  21283. return bytesUsed == 0;
  21284. }
  21285. int MidiBuffer::getNumEvents() const throw()
  21286. {
  21287. int n = 0;
  21288. const uint8* d = getData();
  21289. const uint8* const end = d + bytesUsed;
  21290. while (d < end)
  21291. {
  21292. d += getEventTotalSize (d);
  21293. ++n;
  21294. }
  21295. return n;
  21296. }
  21297. int MidiBuffer::getFirstEventTime() const throw()
  21298. {
  21299. return bytesUsed > 0 ? getEventTime (data.getData()) : 0;
  21300. }
  21301. int MidiBuffer::getLastEventTime() const throw()
  21302. {
  21303. if (bytesUsed == 0)
  21304. return 0;
  21305. const uint8* d = getData();
  21306. const uint8* const endData = d + bytesUsed;
  21307. for (;;)
  21308. {
  21309. const uint8* const nextOne = d + getEventTotalSize (d);
  21310. if (nextOne >= endData)
  21311. return getEventTime (d);
  21312. d = nextOne;
  21313. }
  21314. }
  21315. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21316. {
  21317. const uint8* const endData = getData() + bytesUsed;
  21318. while (d < endData && getEventTime (d) <= samplePosition)
  21319. d += getEventTotalSize (d);
  21320. return d;
  21321. }
  21322. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21323. : buffer (buffer_),
  21324. data (buffer_.getData())
  21325. {
  21326. }
  21327. MidiBuffer::Iterator::~Iterator() throw()
  21328. {
  21329. }
  21330. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21331. {
  21332. data = buffer.getData();
  21333. const uint8* dataEnd = data + buffer.bytesUsed;
  21334. while (data < dataEnd && getEventTime (data) < samplePosition)
  21335. data += getEventTotalSize (data);
  21336. }
  21337. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, int& numBytes, int& samplePosition) throw()
  21338. {
  21339. if (data >= buffer.getData() + buffer.bytesUsed)
  21340. return false;
  21341. samplePosition = getEventTime (data);
  21342. numBytes = getEventDataSize (data);
  21343. data += sizeof (int) + sizeof (uint16);
  21344. midiData = data;
  21345. data += numBytes;
  21346. return true;
  21347. }
  21348. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, int& samplePosition) throw()
  21349. {
  21350. if (data >= buffer.getData() + buffer.bytesUsed)
  21351. return false;
  21352. samplePosition = getEventTime (data);
  21353. const int numBytes = getEventDataSize (data);
  21354. data += sizeof (int) + sizeof (uint16);
  21355. result = MidiMessage (data, numBytes, samplePosition);
  21356. data += numBytes;
  21357. return true;
  21358. }
  21359. END_JUCE_NAMESPACE
  21360. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21361. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21362. BEGIN_JUCE_NAMESPACE
  21363. namespace MidiFileHelpers
  21364. {
  21365. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21366. {
  21367. unsigned int buffer = v & 0x7F;
  21368. while ((v >>= 7) != 0)
  21369. {
  21370. buffer <<= 8;
  21371. buffer |= ((v & 0x7F) | 0x80);
  21372. }
  21373. for (;;)
  21374. {
  21375. out.writeByte ((char) buffer);
  21376. if (buffer & 0x80)
  21377. buffer >>= 8;
  21378. else
  21379. break;
  21380. }
  21381. }
  21382. static bool parseMidiHeader (const uint8* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21383. {
  21384. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21385. data += 4;
  21386. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21387. {
  21388. bool ok = false;
  21389. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21390. {
  21391. for (int i = 0; i < 8; ++i)
  21392. {
  21393. ch = ByteOrder::bigEndianInt (data);
  21394. data += 4;
  21395. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21396. {
  21397. ok = true;
  21398. break;
  21399. }
  21400. }
  21401. }
  21402. if (! ok)
  21403. return false;
  21404. }
  21405. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21406. data += 4;
  21407. fileType = (short) ByteOrder::bigEndianShort (data);
  21408. data += 2;
  21409. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21410. data += 2;
  21411. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21412. data += 2;
  21413. bytesRemaining -= 6;
  21414. data += bytesRemaining;
  21415. return true;
  21416. }
  21417. static double convertTicksToSeconds (const double time,
  21418. const MidiMessageSequence& tempoEvents,
  21419. const int timeFormat)
  21420. {
  21421. if (timeFormat > 0)
  21422. {
  21423. int numer = 4, denom = 4;
  21424. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21425. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21426. double secsPerTick = 0.5 * tickLen;
  21427. const int numEvents = tempoEvents.getNumEvents();
  21428. for (int i = 0; i < numEvents; ++i)
  21429. {
  21430. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21431. if (time <= m.getTimeStamp())
  21432. break;
  21433. if (timeFormat > 0)
  21434. {
  21435. correctedTempoTime = correctedTempoTime
  21436. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21437. }
  21438. else
  21439. {
  21440. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21441. }
  21442. tempoTime = m.getTimeStamp();
  21443. if (m.isTempoMetaEvent())
  21444. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21445. else if (m.isTimeSignatureMetaEvent())
  21446. m.getTimeSignatureInfo (numer, denom);
  21447. while (i + 1 < numEvents)
  21448. {
  21449. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21450. if (m2.getTimeStamp() == tempoTime)
  21451. {
  21452. ++i;
  21453. if (m2.isTempoMetaEvent())
  21454. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21455. else if (m2.isTimeSignatureMetaEvent())
  21456. m2.getTimeSignatureInfo (numer, denom);
  21457. }
  21458. else
  21459. {
  21460. break;
  21461. }
  21462. }
  21463. }
  21464. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21465. }
  21466. else
  21467. {
  21468. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21469. }
  21470. }
  21471. }
  21472. MidiFile::MidiFile()
  21473. : timeFormat ((short) (unsigned short) 0xe728)
  21474. {
  21475. }
  21476. MidiFile::~MidiFile()
  21477. {
  21478. clear();
  21479. }
  21480. void MidiFile::clear()
  21481. {
  21482. tracks.clear();
  21483. }
  21484. int MidiFile::getNumTracks() const throw()
  21485. {
  21486. return tracks.size();
  21487. }
  21488. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21489. {
  21490. return tracks [index];
  21491. }
  21492. void MidiFile::addTrack (const MidiMessageSequence& trackSequence)
  21493. {
  21494. tracks.add (new MidiMessageSequence (trackSequence));
  21495. }
  21496. short MidiFile::getTimeFormat() const throw()
  21497. {
  21498. return timeFormat;
  21499. }
  21500. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21501. {
  21502. timeFormat = (short) ticks;
  21503. }
  21504. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21505. const int subframeResolution) throw()
  21506. {
  21507. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21508. }
  21509. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21510. {
  21511. for (int i = tracks.size(); --i >= 0;)
  21512. {
  21513. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21514. for (int j = 0; j < numEvents; ++j)
  21515. {
  21516. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21517. if (m.isTempoMetaEvent())
  21518. tempoChangeEvents.addEvent (m);
  21519. }
  21520. }
  21521. }
  21522. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21523. {
  21524. for (int i = tracks.size(); --i >= 0;)
  21525. {
  21526. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21527. for (int j = 0; j < numEvents; ++j)
  21528. {
  21529. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21530. if (m.isTimeSignatureMetaEvent())
  21531. timeSigEvents.addEvent (m);
  21532. }
  21533. }
  21534. }
  21535. double MidiFile::getLastTimestamp() const
  21536. {
  21537. double t = 0.0;
  21538. for (int i = tracks.size(); --i >= 0;)
  21539. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21540. return t;
  21541. }
  21542. bool MidiFile::readFrom (InputStream& sourceStream)
  21543. {
  21544. clear();
  21545. MemoryBlock data;
  21546. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21547. // (put a sanity-check on the file size, as midi files are generally small)
  21548. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21549. {
  21550. size_t size = data.getSize();
  21551. const uint8* d = static_cast <const uint8*> (data.getData());
  21552. short fileType, expectedTracks;
  21553. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21554. {
  21555. size -= (int) (d - static_cast <const uint8*> (data.getData()));
  21556. int track = 0;
  21557. while (size > 0 && track < expectedTracks)
  21558. {
  21559. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21560. d += 4;
  21561. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21562. d += 4;
  21563. if (chunkSize <= 0)
  21564. break;
  21565. if (size < 0)
  21566. return false;
  21567. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21568. {
  21569. readNextTrack (d, chunkSize);
  21570. }
  21571. size -= chunkSize + 8;
  21572. d += chunkSize;
  21573. ++track;
  21574. }
  21575. return true;
  21576. }
  21577. }
  21578. return false;
  21579. }
  21580. // a comparator that puts all the note-offs before note-ons that have the same time
  21581. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21582. const MidiMessageSequence::MidiEventHolder* const second)
  21583. {
  21584. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21585. if (diff == 0)
  21586. {
  21587. if (first->message.isNoteOff() && second->message.isNoteOn())
  21588. return -1;
  21589. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21590. return 1;
  21591. else
  21592. return 0;
  21593. }
  21594. else
  21595. {
  21596. return (diff > 0) ? 1 : -1;
  21597. }
  21598. }
  21599. void MidiFile::readNextTrack (const uint8* data, int size)
  21600. {
  21601. double time = 0;
  21602. char lastStatusByte = 0;
  21603. MidiMessageSequence result;
  21604. while (size > 0)
  21605. {
  21606. int bytesUsed;
  21607. const int delay = MidiMessage::readVariableLengthVal (data, bytesUsed);
  21608. data += bytesUsed;
  21609. size -= bytesUsed;
  21610. time += delay;
  21611. int messSize = 0;
  21612. const MidiMessage mm (data, size, messSize, lastStatusByte, time);
  21613. if (messSize <= 0)
  21614. break;
  21615. size -= messSize;
  21616. data += messSize;
  21617. result.addEvent (mm);
  21618. const char firstByte = *(mm.getRawData());
  21619. if ((firstByte & 0xf0) != 0xf0)
  21620. lastStatusByte = firstByte;
  21621. }
  21622. // use a sort that puts all the note-offs before note-ons that have the same time
  21623. result.list.sort (*this, true);
  21624. result.updateMatchedPairs();
  21625. addTrack (result);
  21626. }
  21627. void MidiFile::convertTimestampTicksToSeconds()
  21628. {
  21629. MidiMessageSequence tempoEvents;
  21630. findAllTempoEvents (tempoEvents);
  21631. findAllTimeSigEvents (tempoEvents);
  21632. for (int i = 0; i < tracks.size(); ++i)
  21633. {
  21634. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21635. for (int j = ms.getNumEvents(); --j >= 0;)
  21636. {
  21637. MidiMessage& m = ms.getEventPointer(j)->message;
  21638. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21639. tempoEvents,
  21640. timeFormat));
  21641. }
  21642. }
  21643. }
  21644. bool MidiFile::writeTo (OutputStream& out)
  21645. {
  21646. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21647. out.writeIntBigEndian (6);
  21648. out.writeShortBigEndian (1); // type
  21649. out.writeShortBigEndian ((short) tracks.size());
  21650. out.writeShortBigEndian (timeFormat);
  21651. for (int i = 0; i < tracks.size(); ++i)
  21652. writeTrack (out, i);
  21653. out.flush();
  21654. return true;
  21655. }
  21656. void MidiFile::writeTrack (OutputStream& mainOut,
  21657. const int trackNum)
  21658. {
  21659. MemoryOutputStream out;
  21660. const MidiMessageSequence& ms = *tracks[trackNum];
  21661. int lastTick = 0;
  21662. char lastStatusByte = 0;
  21663. for (int i = 0; i < ms.getNumEvents(); ++i)
  21664. {
  21665. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21666. const int tick = roundToInt (mm.getTimeStamp());
  21667. const int delta = jmax (0, tick - lastTick);
  21668. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21669. lastTick = tick;
  21670. const char statusByte = *(mm.getRawData());
  21671. if ((statusByte == lastStatusByte)
  21672. && ((statusByte & 0xf0) != 0xf0)
  21673. && i > 0
  21674. && mm.getRawDataSize() > 1)
  21675. {
  21676. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21677. }
  21678. else
  21679. {
  21680. out.write (mm.getRawData(), mm.getRawDataSize());
  21681. }
  21682. lastStatusByte = statusByte;
  21683. }
  21684. out.writeByte (0);
  21685. const MidiMessage m (MidiMessage::endOfTrack());
  21686. out.write (m.getRawData(),
  21687. m.getRawDataSize());
  21688. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21689. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21690. mainOut.write (out.getData(), (int) out.getDataSize());
  21691. }
  21692. END_JUCE_NAMESPACE
  21693. /*** End of inlined file: juce_MidiFile.cpp ***/
  21694. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21695. BEGIN_JUCE_NAMESPACE
  21696. MidiKeyboardState::MidiKeyboardState()
  21697. {
  21698. zerostruct (noteStates);
  21699. }
  21700. MidiKeyboardState::~MidiKeyboardState()
  21701. {
  21702. }
  21703. void MidiKeyboardState::reset()
  21704. {
  21705. const ScopedLock sl (lock);
  21706. zerostruct (noteStates);
  21707. eventsToAdd.clear();
  21708. }
  21709. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21710. {
  21711. jassert (midiChannel >= 0 && midiChannel <= 16);
  21712. return ((unsigned int) n) < 128
  21713. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21714. }
  21715. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21716. {
  21717. return ((unsigned int) n) < 128
  21718. && (noteStates[n] & midiChannelMask) != 0;
  21719. }
  21720. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21721. {
  21722. jassert (midiChannel >= 0 && midiChannel <= 16);
  21723. jassert (((unsigned int) midiNoteNumber) < 128);
  21724. const ScopedLock sl (lock);
  21725. if (((unsigned int) midiNoteNumber) < 128)
  21726. {
  21727. const int timeNow = (int) Time::getMillisecondCounter();
  21728. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  21729. eventsToAdd.clear (0, timeNow - 500);
  21730. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  21731. }
  21732. }
  21733. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  21734. {
  21735. if (((unsigned int) midiNoteNumber) < 128)
  21736. {
  21737. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  21738. for (int i = listeners.size(); --i >= 0;)
  21739. listeners.getUnchecked(i)->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  21740. }
  21741. }
  21742. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  21743. {
  21744. const ScopedLock sl (lock);
  21745. if (isNoteOn (midiChannel, midiNoteNumber))
  21746. {
  21747. const int timeNow = (int) Time::getMillisecondCounter();
  21748. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  21749. eventsToAdd.clear (0, timeNow - 500);
  21750. noteOffInternal (midiChannel, midiNoteNumber);
  21751. }
  21752. }
  21753. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  21754. {
  21755. if (isNoteOn (midiChannel, midiNoteNumber))
  21756. {
  21757. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  21758. for (int i = listeners.size(); --i >= 0;)
  21759. listeners.getUnchecked(i)->handleNoteOff (this, midiChannel, midiNoteNumber);
  21760. }
  21761. }
  21762. void MidiKeyboardState::allNotesOff (const int midiChannel)
  21763. {
  21764. const ScopedLock sl (lock);
  21765. if (midiChannel <= 0)
  21766. {
  21767. for (int i = 1; i <= 16; ++i)
  21768. allNotesOff (i);
  21769. }
  21770. else
  21771. {
  21772. for (int i = 0; i < 128; ++i)
  21773. noteOff (midiChannel, i);
  21774. }
  21775. }
  21776. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  21777. {
  21778. if (message.isNoteOn())
  21779. {
  21780. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  21781. }
  21782. else if (message.isNoteOff())
  21783. {
  21784. noteOffInternal (message.getChannel(), message.getNoteNumber());
  21785. }
  21786. else if (message.isAllNotesOff())
  21787. {
  21788. for (int i = 0; i < 128; ++i)
  21789. noteOffInternal (message.getChannel(), i);
  21790. }
  21791. }
  21792. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  21793. const int startSample,
  21794. const int numSamples,
  21795. const bool injectIndirectEvents)
  21796. {
  21797. MidiBuffer::Iterator i (buffer);
  21798. MidiMessage message (0xf4, 0.0);
  21799. int time;
  21800. const ScopedLock sl (lock);
  21801. while (i.getNextEvent (message, time))
  21802. processNextMidiEvent (message);
  21803. if (injectIndirectEvents)
  21804. {
  21805. MidiBuffer::Iterator i2 (eventsToAdd);
  21806. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  21807. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  21808. while (i2.getNextEvent (message, time))
  21809. {
  21810. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  21811. buffer.addEvent (message, startSample + pos);
  21812. }
  21813. }
  21814. eventsToAdd.clear();
  21815. }
  21816. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  21817. {
  21818. const ScopedLock sl (lock);
  21819. listeners.addIfNotAlreadyThere (listener);
  21820. }
  21821. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  21822. {
  21823. const ScopedLock sl (lock);
  21824. listeners.removeValue (listener);
  21825. }
  21826. END_JUCE_NAMESPACE
  21827. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  21828. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  21829. BEGIN_JUCE_NAMESPACE
  21830. int MidiMessage::readVariableLengthVal (const uint8* data,
  21831. int& numBytesUsed) throw()
  21832. {
  21833. numBytesUsed = 0;
  21834. int v = 0;
  21835. int i;
  21836. do
  21837. {
  21838. i = (int) *data++;
  21839. if (++numBytesUsed > 6)
  21840. break;
  21841. v = (v << 7) + (i & 0x7f);
  21842. } while (i & 0x80);
  21843. return v;
  21844. }
  21845. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  21846. {
  21847. // this method only works for valid starting bytes of a short midi message
  21848. jassert (firstByte >= 0x80
  21849. && firstByte != 0xf0
  21850. && firstByte != 0xf7);
  21851. static const char messageLengths[] =
  21852. {
  21853. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21854. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21855. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21856. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21857. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21858. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  21859. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  21860. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  21861. };
  21862. return messageLengths [firstByte & 0x7f];
  21863. }
  21864. MidiMessage::MidiMessage (const void* const d, const int dataSize, const double t)
  21865. : timeStamp (t),
  21866. size (dataSize)
  21867. {
  21868. jassert (dataSize > 0);
  21869. if (dataSize <= 4)
  21870. data = static_cast<uint8*> (preallocatedData.asBytes);
  21871. else
  21872. data = static_cast<uint8*> (juce_malloc (dataSize));
  21873. memcpy (data, d, dataSize);
  21874. // check that the length matches the data..
  21875. jassert (size > 3 || data[0] >= 0xf0 || getMessageLengthFromFirstByte (data[0]) == size);
  21876. }
  21877. MidiMessage::MidiMessage (const int byte1, const double t) throw()
  21878. : timeStamp (t),
  21879. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21880. size (1)
  21881. {
  21882. data[0] = (uint8) byte1;
  21883. // check that the length matches the data..
  21884. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  21885. }
  21886. MidiMessage::MidiMessage (const int byte1, const int byte2, const double t) throw()
  21887. : timeStamp (t),
  21888. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21889. size (2)
  21890. {
  21891. data[0] = (uint8) byte1;
  21892. data[1] = (uint8) byte2;
  21893. // check that the length matches the data..
  21894. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  21895. }
  21896. MidiMessage::MidiMessage (const int byte1, const int byte2, const int byte3, const double t) throw()
  21897. : timeStamp (t),
  21898. data (static_cast<uint8*> (preallocatedData.asBytes)),
  21899. size (3)
  21900. {
  21901. data[0] = (uint8) byte1;
  21902. data[1] = (uint8) byte2;
  21903. data[2] = (uint8) byte3;
  21904. // check that the length matches the data..
  21905. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  21906. }
  21907. MidiMessage::MidiMessage (const MidiMessage& other)
  21908. : timeStamp (other.timeStamp),
  21909. size (other.size)
  21910. {
  21911. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21912. {
  21913. data = static_cast<uint8*> (juce_malloc (size));
  21914. memcpy (data, other.data, size);
  21915. }
  21916. else
  21917. {
  21918. data = static_cast<uint8*> (preallocatedData.asBytes);
  21919. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21920. }
  21921. }
  21922. MidiMessage::MidiMessage (const MidiMessage& other, const double newTimeStamp)
  21923. : timeStamp (newTimeStamp),
  21924. size (other.size)
  21925. {
  21926. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  21927. {
  21928. data = static_cast<uint8*> (juce_malloc (size));
  21929. memcpy (data, other.data, size);
  21930. }
  21931. else
  21932. {
  21933. data = static_cast<uint8*> (preallocatedData.asBytes);
  21934. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  21935. }
  21936. }
  21937. MidiMessage::MidiMessage (const void* src_, int sz, int& numBytesUsed, const uint8 lastStatusByte, double t)
  21938. : timeStamp (t),
  21939. data (static_cast<uint8*> (preallocatedData.asBytes))
  21940. {
  21941. const uint8* src = static_cast <const uint8*> (src_);
  21942. unsigned int byte = (unsigned int) *src;
  21943. if (byte < 0x80)
  21944. {
  21945. byte = (unsigned int) (uint8) lastStatusByte;
  21946. numBytesUsed = -1;
  21947. }
  21948. else
  21949. {
  21950. numBytesUsed = 0;
  21951. --sz;
  21952. ++src;
  21953. }
  21954. if (byte >= 0x80)
  21955. {
  21956. if (byte == 0xf0)
  21957. {
  21958. const uint8* d = src;
  21959. while (d < src + sz)
  21960. {
  21961. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  21962. {
  21963. if (*d == 0xf7) // include an 0xf7 if we hit one
  21964. ++d;
  21965. break;
  21966. }
  21967. ++d;
  21968. }
  21969. size = 1 + (int) (d - src);
  21970. data = static_cast<uint8*> (juce_malloc (size));
  21971. *data = (uint8) byte;
  21972. memcpy (data + 1, src, size - 1);
  21973. }
  21974. else if (byte == 0xff)
  21975. {
  21976. int n;
  21977. const int bytesLeft = readVariableLengthVal (src + 1, n);
  21978. size = jmin (sz + 1, n + 2 + bytesLeft);
  21979. data = static_cast<uint8*> (juce_malloc (size));
  21980. *data = (uint8) byte;
  21981. memcpy (data + 1, src, size - 1);
  21982. }
  21983. else
  21984. {
  21985. preallocatedData.asInt32 = 0;
  21986. size = getMessageLengthFromFirstByte ((uint8) byte);
  21987. data[0] = (uint8) byte;
  21988. if (size > 1)
  21989. {
  21990. data[1] = src[0];
  21991. if (size > 2)
  21992. data[2] = src[1];
  21993. }
  21994. }
  21995. numBytesUsed += size;
  21996. }
  21997. else
  21998. {
  21999. preallocatedData.asInt32 = 0;
  22000. size = 0;
  22001. }
  22002. }
  22003. MidiMessage& MidiMessage::operator= (const MidiMessage& other)
  22004. {
  22005. if (this != &other)
  22006. {
  22007. timeStamp = other.timeStamp;
  22008. size = other.size;
  22009. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22010. juce_free (data);
  22011. if (other.data != static_cast <const uint8*> (other.preallocatedData.asBytes))
  22012. {
  22013. data = static_cast<uint8*> (juce_malloc (size));
  22014. memcpy (data, other.data, size);
  22015. }
  22016. else
  22017. {
  22018. data = static_cast<uint8*> (preallocatedData.asBytes);
  22019. preallocatedData.asInt32 = other.preallocatedData.asInt32;
  22020. }
  22021. }
  22022. return *this;
  22023. }
  22024. MidiMessage::~MidiMessage()
  22025. {
  22026. if (data != static_cast <const uint8*> (preallocatedData.asBytes))
  22027. juce_free (data);
  22028. }
  22029. int MidiMessage::getChannel() const throw()
  22030. {
  22031. if ((data[0] & 0xf0) != 0xf0)
  22032. return (data[0] & 0xf) + 1;
  22033. else
  22034. return 0;
  22035. }
  22036. bool MidiMessage::isForChannel (const int channel) const throw()
  22037. {
  22038. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22039. return ((data[0] & 0xf) == channel - 1)
  22040. && ((data[0] & 0xf0) != 0xf0);
  22041. }
  22042. void MidiMessage::setChannel (const int channel) throw()
  22043. {
  22044. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22045. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22046. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22047. | (uint8)(channel - 1));
  22048. }
  22049. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22050. {
  22051. return ((data[0] & 0xf0) == 0x90)
  22052. && (returnTrueForVelocity0 || data[2] != 0);
  22053. }
  22054. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22055. {
  22056. return ((data[0] & 0xf0) == 0x80)
  22057. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22058. }
  22059. bool MidiMessage::isNoteOnOrOff() const throw()
  22060. {
  22061. const int d = data[0] & 0xf0;
  22062. return (d == 0x90) || (d == 0x80);
  22063. }
  22064. int MidiMessage::getNoteNumber() const throw()
  22065. {
  22066. return data[1];
  22067. }
  22068. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22069. {
  22070. if (isNoteOnOrOff())
  22071. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22072. }
  22073. uint8 MidiMessage::getVelocity() const throw()
  22074. {
  22075. if (isNoteOnOrOff())
  22076. return data[2];
  22077. else
  22078. return 0;
  22079. }
  22080. float MidiMessage::getFloatVelocity() const throw()
  22081. {
  22082. return getVelocity() * (1.0f / 127.0f);
  22083. }
  22084. void MidiMessage::setVelocity (const float newVelocity) throw()
  22085. {
  22086. if (isNoteOnOrOff())
  22087. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22088. }
  22089. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22090. {
  22091. if (isNoteOnOrOff())
  22092. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22093. }
  22094. bool MidiMessage::isAftertouch() const throw()
  22095. {
  22096. return (data[0] & 0xf0) == 0xa0;
  22097. }
  22098. int MidiMessage::getAfterTouchValue() const throw()
  22099. {
  22100. return data[2];
  22101. }
  22102. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22103. const int noteNum,
  22104. const int aftertouchValue) throw()
  22105. {
  22106. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22107. jassert (((unsigned int) noteNum) <= 127);
  22108. jassert (((unsigned int) aftertouchValue) <= 127);
  22109. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22110. noteNum & 0x7f,
  22111. aftertouchValue & 0x7f);
  22112. }
  22113. bool MidiMessage::isChannelPressure() const throw()
  22114. {
  22115. return (data[0] & 0xf0) == 0xd0;
  22116. }
  22117. int MidiMessage::getChannelPressureValue() const throw()
  22118. {
  22119. jassert (isChannelPressure());
  22120. return data[1];
  22121. }
  22122. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22123. const int pressure) throw()
  22124. {
  22125. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22126. jassert (((unsigned int) pressure) <= 127);
  22127. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22128. pressure & 0x7f);
  22129. }
  22130. bool MidiMessage::isProgramChange() const throw()
  22131. {
  22132. return (data[0] & 0xf0) == 0xc0;
  22133. }
  22134. int MidiMessage::getProgramChangeNumber() const throw()
  22135. {
  22136. return data[1];
  22137. }
  22138. const MidiMessage MidiMessage::programChange (const int channel,
  22139. const int programNumber) throw()
  22140. {
  22141. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22142. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22143. programNumber & 0x7f);
  22144. }
  22145. bool MidiMessage::isPitchWheel() const throw()
  22146. {
  22147. return (data[0] & 0xf0) == 0xe0;
  22148. }
  22149. int MidiMessage::getPitchWheelValue() const throw()
  22150. {
  22151. return data[1] | (data[2] << 7);
  22152. }
  22153. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22154. const int position) throw()
  22155. {
  22156. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22157. jassert (((unsigned int) position) <= 0x3fff);
  22158. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22159. position & 127,
  22160. (position >> 7) & 127);
  22161. }
  22162. bool MidiMessage::isController() const throw()
  22163. {
  22164. return (data[0] & 0xf0) == 0xb0;
  22165. }
  22166. int MidiMessage::getControllerNumber() const throw()
  22167. {
  22168. jassert (isController());
  22169. return data[1];
  22170. }
  22171. int MidiMessage::getControllerValue() const throw()
  22172. {
  22173. jassert (isController());
  22174. return data[2];
  22175. }
  22176. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22177. const int controllerType,
  22178. const int value) throw()
  22179. {
  22180. // the channel must be between 1 and 16 inclusive
  22181. jassert (channel > 0 && channel <= 16);
  22182. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22183. controllerType & 127,
  22184. value & 127);
  22185. }
  22186. const MidiMessage MidiMessage::noteOn (const int channel,
  22187. const int noteNumber,
  22188. const float velocity) throw()
  22189. {
  22190. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22191. }
  22192. const MidiMessage MidiMessage::noteOn (const int channel,
  22193. const int noteNumber,
  22194. const uint8 velocity) throw()
  22195. {
  22196. jassert (channel > 0 && channel <= 16);
  22197. jassert (((unsigned int) noteNumber) <= 127);
  22198. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22199. noteNumber & 127,
  22200. jlimit (0, 127, roundToInt (velocity)));
  22201. }
  22202. const MidiMessage MidiMessage::noteOff (const int channel,
  22203. const int noteNumber) throw()
  22204. {
  22205. jassert (channel > 0 && channel <= 16);
  22206. jassert (((unsigned int) noteNumber) <= 127);
  22207. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22208. }
  22209. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22210. {
  22211. jassert (channel > 0 && channel <= 16);
  22212. return controllerEvent (channel, 123, 0);
  22213. }
  22214. bool MidiMessage::isAllNotesOff() const throw()
  22215. {
  22216. return (data[0] & 0xf0) == 0xb0
  22217. && data[1] == 123;
  22218. }
  22219. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22220. {
  22221. return controllerEvent (channel, 120, 0);
  22222. }
  22223. bool MidiMessage::isAllSoundOff() const throw()
  22224. {
  22225. return (data[0] & 0xf0) == 0xb0
  22226. && data[1] == 120;
  22227. }
  22228. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22229. {
  22230. return controllerEvent (channel, 121, 0);
  22231. }
  22232. const MidiMessage MidiMessage::masterVolume (const float volume)
  22233. {
  22234. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22235. uint8 buf[8];
  22236. buf[0] = 0xf0;
  22237. buf[1] = 0x7f;
  22238. buf[2] = 0x7f;
  22239. buf[3] = 0x04;
  22240. buf[4] = 0x01;
  22241. buf[5] = (uint8) (vol & 0x7f);
  22242. buf[6] = (uint8) (vol >> 7);
  22243. buf[7] = 0xf7;
  22244. return MidiMessage (buf, 8);
  22245. }
  22246. bool MidiMessage::isSysEx() const throw()
  22247. {
  22248. return *data == 0xf0;
  22249. }
  22250. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData, const int dataSize)
  22251. {
  22252. MemoryBlock mm (dataSize + 2);
  22253. uint8* const m = static_cast <uint8*> (mm.getData());
  22254. m[0] = 0xf0;
  22255. memcpy (m + 1, sysexData, dataSize);
  22256. m[dataSize + 1] = 0xf7;
  22257. return MidiMessage (m, dataSize + 2);
  22258. }
  22259. const uint8* MidiMessage::getSysExData() const throw()
  22260. {
  22261. return (isSysEx()) ? getRawData() + 1 : 0;
  22262. }
  22263. int MidiMessage::getSysExDataSize() const throw()
  22264. {
  22265. return (isSysEx()) ? size - 2 : 0;
  22266. }
  22267. bool MidiMessage::isMetaEvent() const throw()
  22268. {
  22269. return *data == 0xff;
  22270. }
  22271. bool MidiMessage::isActiveSense() const throw()
  22272. {
  22273. return *data == 0xfe;
  22274. }
  22275. int MidiMessage::getMetaEventType() const throw()
  22276. {
  22277. if (*data != 0xff)
  22278. return -1;
  22279. else
  22280. return data[1];
  22281. }
  22282. int MidiMessage::getMetaEventLength() const throw()
  22283. {
  22284. if (*data == 0xff)
  22285. {
  22286. int n;
  22287. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22288. }
  22289. return 0;
  22290. }
  22291. const uint8* MidiMessage::getMetaEventData() const throw()
  22292. {
  22293. int n;
  22294. const uint8* d = data + 2;
  22295. readVariableLengthVal (d, n);
  22296. return d + n;
  22297. }
  22298. bool MidiMessage::isTrackMetaEvent() const throw()
  22299. {
  22300. return getMetaEventType() == 0;
  22301. }
  22302. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22303. {
  22304. return getMetaEventType() == 47;
  22305. }
  22306. bool MidiMessage::isTextMetaEvent() const throw()
  22307. {
  22308. const int t = getMetaEventType();
  22309. return t > 0 && t < 16;
  22310. }
  22311. const String MidiMessage::getTextFromTextMetaEvent() const
  22312. {
  22313. return String (reinterpret_cast <const char*> (getMetaEventData()), getMetaEventLength());
  22314. }
  22315. bool MidiMessage::isTrackNameEvent() const throw()
  22316. {
  22317. return (data[1] == 3)
  22318. && (*data == 0xff);
  22319. }
  22320. bool MidiMessage::isTempoMetaEvent() const throw()
  22321. {
  22322. return (data[1] == 81)
  22323. && (*data == 0xff);
  22324. }
  22325. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22326. {
  22327. return (data[1] == 0x20)
  22328. && (*data == 0xff)
  22329. && (data[2] == 1);
  22330. }
  22331. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22332. {
  22333. return data[3] + 1;
  22334. }
  22335. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22336. {
  22337. if (! isTempoMetaEvent())
  22338. return 0.0;
  22339. const uint8* const d = getMetaEventData();
  22340. return (((unsigned int) d[0] << 16)
  22341. | ((unsigned int) d[1] << 8)
  22342. | d[2])
  22343. / 1000000.0;
  22344. }
  22345. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22346. {
  22347. if (timeFormat > 0)
  22348. {
  22349. if (! isTempoMetaEvent())
  22350. return 0.5 / timeFormat;
  22351. return getTempoSecondsPerQuarterNote() / timeFormat;
  22352. }
  22353. else
  22354. {
  22355. const int frameCode = (-timeFormat) >> 8;
  22356. double framesPerSecond;
  22357. switch (frameCode)
  22358. {
  22359. case 24: framesPerSecond = 24.0; break;
  22360. case 25: framesPerSecond = 25.0; break;
  22361. case 29: framesPerSecond = 29.97; break;
  22362. case 30: framesPerSecond = 30.0; break;
  22363. default: framesPerSecond = 30.0; break;
  22364. }
  22365. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22366. }
  22367. }
  22368. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22369. {
  22370. uint8 d[8];
  22371. d[0] = 0xff;
  22372. d[1] = 81;
  22373. d[2] = 3;
  22374. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22375. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22376. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22377. return MidiMessage (d, 6, 0.0);
  22378. }
  22379. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22380. {
  22381. return (data[1] == 0x58)
  22382. && (*data == (uint8) 0xff);
  22383. }
  22384. void MidiMessage::getTimeSignatureInfo (int& numerator, int& denominator) const throw()
  22385. {
  22386. if (isTimeSignatureMetaEvent())
  22387. {
  22388. const uint8* const d = getMetaEventData();
  22389. numerator = d[0];
  22390. denominator = 1 << d[1];
  22391. }
  22392. else
  22393. {
  22394. numerator = 4;
  22395. denominator = 4;
  22396. }
  22397. }
  22398. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator, const int denominator)
  22399. {
  22400. uint8 d[8];
  22401. d[0] = 0xff;
  22402. d[1] = 0x58;
  22403. d[2] = 0x04;
  22404. d[3] = (uint8) numerator;
  22405. int n = 1;
  22406. int powerOfTwo = 0;
  22407. while (n < denominator)
  22408. {
  22409. n <<= 1;
  22410. ++powerOfTwo;
  22411. }
  22412. d[4] = (uint8) powerOfTwo;
  22413. d[5] = 0x01;
  22414. d[6] = 96;
  22415. return MidiMessage (d, 7, 0.0);
  22416. }
  22417. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22418. {
  22419. uint8 d[8];
  22420. d[0] = 0xff;
  22421. d[1] = 0x20;
  22422. d[2] = 0x01;
  22423. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22424. return MidiMessage (d, 4, 0.0);
  22425. }
  22426. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22427. {
  22428. return getMetaEventType() == 89;
  22429. }
  22430. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22431. {
  22432. return (int) *getMetaEventData();
  22433. }
  22434. const MidiMessage MidiMessage::endOfTrack() throw()
  22435. {
  22436. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22437. }
  22438. bool MidiMessage::isSongPositionPointer() const throw()
  22439. {
  22440. return *data == 0xf2;
  22441. }
  22442. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22443. {
  22444. return data[1] | (data[2] << 7);
  22445. }
  22446. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22447. {
  22448. return MidiMessage (0xf2,
  22449. positionInMidiBeats & 127,
  22450. (positionInMidiBeats >> 7) & 127);
  22451. }
  22452. bool MidiMessage::isMidiStart() const throw()
  22453. {
  22454. return *data == 0xfa;
  22455. }
  22456. const MidiMessage MidiMessage::midiStart() throw()
  22457. {
  22458. return MidiMessage (0xfa);
  22459. }
  22460. bool MidiMessage::isMidiContinue() const throw()
  22461. {
  22462. return *data == 0xfb;
  22463. }
  22464. const MidiMessage MidiMessage::midiContinue() throw()
  22465. {
  22466. return MidiMessage (0xfb);
  22467. }
  22468. bool MidiMessage::isMidiStop() const throw()
  22469. {
  22470. return *data == 0xfc;
  22471. }
  22472. const MidiMessage MidiMessage::midiStop() throw()
  22473. {
  22474. return MidiMessage (0xfc);
  22475. }
  22476. bool MidiMessage::isMidiClock() const throw()
  22477. {
  22478. return *data == 0xf8;
  22479. }
  22480. const MidiMessage MidiMessage::midiClock() throw()
  22481. {
  22482. return MidiMessage (0xf8);
  22483. }
  22484. bool MidiMessage::isQuarterFrame() const throw()
  22485. {
  22486. return *data == 0xf1;
  22487. }
  22488. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22489. {
  22490. return ((int) data[1]) >> 4;
  22491. }
  22492. int MidiMessage::getQuarterFrameValue() const throw()
  22493. {
  22494. return ((int) data[1]) & 0x0f;
  22495. }
  22496. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22497. const int value) throw()
  22498. {
  22499. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22500. }
  22501. bool MidiMessage::isFullFrame() const throw()
  22502. {
  22503. return data[0] == 0xf0
  22504. && data[1] == 0x7f
  22505. && size >= 10
  22506. && data[3] == 0x01
  22507. && data[4] == 0x01;
  22508. }
  22509. void MidiMessage::getFullFrameParameters (int& hours,
  22510. int& minutes,
  22511. int& seconds,
  22512. int& frames,
  22513. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22514. {
  22515. jassert (isFullFrame());
  22516. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22517. hours = data[5] & 0x1f;
  22518. minutes = data[6];
  22519. seconds = data[7];
  22520. frames = data[8];
  22521. }
  22522. const MidiMessage MidiMessage::fullFrame (const int hours,
  22523. const int minutes,
  22524. const int seconds,
  22525. const int frames,
  22526. MidiMessage::SmpteTimecodeType timecodeType)
  22527. {
  22528. uint8 d[10];
  22529. d[0] = 0xf0;
  22530. d[1] = 0x7f;
  22531. d[2] = 0x7f;
  22532. d[3] = 0x01;
  22533. d[4] = 0x01;
  22534. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22535. d[6] = (uint8) minutes;
  22536. d[7] = (uint8) seconds;
  22537. d[8] = (uint8) frames;
  22538. d[9] = 0xf7;
  22539. return MidiMessage (d, 10, 0.0);
  22540. }
  22541. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22542. {
  22543. return data[0] == 0xf0
  22544. && data[1] == 0x7f
  22545. && data[3] == 0x06
  22546. && size > 5;
  22547. }
  22548. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22549. {
  22550. jassert (isMidiMachineControlMessage());
  22551. return (MidiMachineControlCommand) data[4];
  22552. }
  22553. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22554. {
  22555. uint8 d[6];
  22556. d[0] = 0xf0;
  22557. d[1] = 0x7f;
  22558. d[2] = 0x00;
  22559. d[3] = 0x06;
  22560. d[4] = (uint8) command;
  22561. d[5] = 0xf7;
  22562. return MidiMessage (d, 6, 0.0);
  22563. }
  22564. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22565. int& minutes,
  22566. int& seconds,
  22567. int& frames) const throw()
  22568. {
  22569. if (size >= 12
  22570. && data[0] == 0xf0
  22571. && data[1] == 0x7f
  22572. && data[3] == 0x06
  22573. && data[4] == 0x44
  22574. && data[5] == 0x06
  22575. && data[6] == 0x01)
  22576. {
  22577. hours = data[7] % 24; // (that some machines send out hours > 24)
  22578. minutes = data[8];
  22579. seconds = data[9];
  22580. frames = data[10];
  22581. return true;
  22582. }
  22583. return false;
  22584. }
  22585. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22586. int minutes,
  22587. int seconds,
  22588. int frames)
  22589. {
  22590. uint8 d[12];
  22591. d[0] = 0xf0;
  22592. d[1] = 0x7f;
  22593. d[2] = 0x00;
  22594. d[3] = 0x06;
  22595. d[4] = 0x44;
  22596. d[5] = 0x06;
  22597. d[6] = 0x01;
  22598. d[7] = (uint8) hours;
  22599. d[8] = (uint8) minutes;
  22600. d[9] = (uint8) seconds;
  22601. d[10] = (uint8) frames;
  22602. d[11] = 0xf7;
  22603. return MidiMessage (d, 12, 0.0);
  22604. }
  22605. const String MidiMessage::getMidiNoteName (int note,
  22606. bool useSharps,
  22607. bool includeOctaveNumber,
  22608. int octaveNumForMiddleC) throw()
  22609. {
  22610. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22611. "F", "F#", "G", "G#", "A",
  22612. "A#", "B" };
  22613. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22614. "F", "Gb", "G", "Ab", "A",
  22615. "Bb", "B" };
  22616. if (((unsigned int) note) < 128)
  22617. {
  22618. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22619. : flatNoteNames [note % 12]);
  22620. if (includeOctaveNumber)
  22621. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22622. else
  22623. return s;
  22624. }
  22625. return String::empty;
  22626. }
  22627. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22628. {
  22629. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22630. return 440.0 * pow (2.0, noteNumber / 12.0);
  22631. }
  22632. const String MidiMessage::getGMInstrumentName (int n) throw()
  22633. {
  22634. const char *names[] =
  22635. {
  22636. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22637. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22638. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22639. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22640. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22641. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22642. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22643. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22644. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22645. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22646. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22647. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22648. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22649. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22650. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22651. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22652. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22653. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22654. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22655. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22656. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22657. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22658. "Applause", "Gunshot"
  22659. };
  22660. return (((unsigned int) n) < 128) ? names[n]
  22661. : (const char*)0;
  22662. }
  22663. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22664. {
  22665. const char* names[] =
  22666. {
  22667. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22668. "Bass", "Strings", "Ensemble", "Brass",
  22669. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22670. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22671. };
  22672. return (((unsigned int) n) <= 15) ? names[n]
  22673. : (const char*)0;
  22674. }
  22675. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22676. {
  22677. const char* names[] =
  22678. {
  22679. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22680. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22681. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22682. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22683. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22684. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22685. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22686. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22687. "Mute Triangle", "Open Triangle"
  22688. };
  22689. return (n >= 35 && n <= 81) ? names [n - 35]
  22690. : (const char*)0;
  22691. }
  22692. const String MidiMessage::getControllerName (int n) throw()
  22693. {
  22694. const char* names[] =
  22695. {
  22696. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22697. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22698. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22699. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22700. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22701. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  22702. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  22703. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  22704. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  22705. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  22706. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  22707. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  22708. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  22709. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  22710. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  22711. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  22712. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  22713. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  22714. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  22715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  22716. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  22717. "Poly Operation"
  22718. };
  22719. return (((unsigned int) n) < 128) ? names[n]
  22720. : (const char*)0;
  22721. }
  22722. END_JUCE_NAMESPACE
  22723. /*** End of inlined file: juce_MidiMessage.cpp ***/
  22724. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  22725. BEGIN_JUCE_NAMESPACE
  22726. MidiMessageCollector::MidiMessageCollector()
  22727. : lastCallbackTime (0),
  22728. sampleRate (44100.0001)
  22729. {
  22730. }
  22731. MidiMessageCollector::~MidiMessageCollector()
  22732. {
  22733. }
  22734. void MidiMessageCollector::reset (const double sampleRate_)
  22735. {
  22736. jassert (sampleRate_ > 0);
  22737. const ScopedLock sl (midiCallbackLock);
  22738. sampleRate = sampleRate_;
  22739. incomingMessages.clear();
  22740. lastCallbackTime = Time::getMillisecondCounterHiRes();
  22741. }
  22742. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  22743. {
  22744. // you need to call reset() to set the correct sample rate before using this object
  22745. jassert (sampleRate != 44100.0001);
  22746. // the messages that come in here need to be time-stamped correctly - see MidiInput
  22747. // for details of what the number should be.
  22748. jassert (message.getTimeStamp() != 0);
  22749. const ScopedLock sl (midiCallbackLock);
  22750. const int sampleNumber
  22751. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  22752. incomingMessages.addEvent (message, sampleNumber);
  22753. // if the messages don't get used for over a second, we'd better
  22754. // get rid of any old ones to avoid the queue getting too big
  22755. if (sampleNumber > sampleRate)
  22756. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  22757. }
  22758. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  22759. const int numSamples)
  22760. {
  22761. // you need to call reset() to set the correct sample rate before using this object
  22762. jassert (sampleRate != 44100.0001);
  22763. const double timeNow = Time::getMillisecondCounterHiRes();
  22764. const double msElapsed = timeNow - lastCallbackTime;
  22765. const ScopedLock sl (midiCallbackLock);
  22766. lastCallbackTime = timeNow;
  22767. if (! incomingMessages.isEmpty())
  22768. {
  22769. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  22770. int startSample = 0;
  22771. int scale = 1 << 16;
  22772. const uint8* midiData;
  22773. int numBytes, samplePosition;
  22774. MidiBuffer::Iterator iter (incomingMessages);
  22775. if (numSourceSamples > numSamples)
  22776. {
  22777. // if our list of events is longer than the buffer we're being
  22778. // asked for, scale them down to squeeze them all in..
  22779. const int maxBlockLengthToUse = numSamples << 5;
  22780. if (numSourceSamples > maxBlockLengthToUse)
  22781. {
  22782. startSample = numSourceSamples - maxBlockLengthToUse;
  22783. numSourceSamples = maxBlockLengthToUse;
  22784. iter.setNextSamplePosition (startSample);
  22785. }
  22786. scale = (numSamples << 10) / numSourceSamples;
  22787. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22788. {
  22789. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  22790. destBuffer.addEvent (midiData, numBytes,
  22791. jlimit (0, numSamples - 1, samplePosition));
  22792. }
  22793. }
  22794. else
  22795. {
  22796. // if our event list is shorter than the number we need, put them
  22797. // towards the end of the buffer
  22798. startSample = numSamples - numSourceSamples;
  22799. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  22800. {
  22801. destBuffer.addEvent (midiData, numBytes,
  22802. jlimit (0, numSamples - 1, samplePosition + startSample));
  22803. }
  22804. }
  22805. incomingMessages.clear();
  22806. }
  22807. }
  22808. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  22809. {
  22810. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  22811. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22812. addMessageToQueue (m);
  22813. }
  22814. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  22815. {
  22816. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  22817. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  22818. addMessageToQueue (m);
  22819. }
  22820. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  22821. {
  22822. addMessageToQueue (message);
  22823. }
  22824. END_JUCE_NAMESPACE
  22825. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  22826. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  22827. BEGIN_JUCE_NAMESPACE
  22828. MidiMessageSequence::MidiMessageSequence()
  22829. {
  22830. }
  22831. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  22832. {
  22833. list.ensureStorageAllocated (other.list.size());
  22834. for (int i = 0; i < other.list.size(); ++i)
  22835. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  22836. }
  22837. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  22838. {
  22839. MidiMessageSequence otherCopy (other);
  22840. swapWith (otherCopy);
  22841. return *this;
  22842. }
  22843. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  22844. {
  22845. list.swapWithArray (other.list);
  22846. }
  22847. MidiMessageSequence::~MidiMessageSequence()
  22848. {
  22849. }
  22850. void MidiMessageSequence::clear()
  22851. {
  22852. list.clear();
  22853. }
  22854. int MidiMessageSequence::getNumEvents() const
  22855. {
  22856. return list.size();
  22857. }
  22858. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  22859. {
  22860. return list [index];
  22861. }
  22862. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  22863. {
  22864. const MidiEventHolder* const meh = list [index];
  22865. if (meh != 0 && meh->noteOffObject != 0)
  22866. return meh->noteOffObject->message.getTimeStamp();
  22867. else
  22868. return 0.0;
  22869. }
  22870. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  22871. {
  22872. const MidiEventHolder* const meh = list [index];
  22873. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  22874. }
  22875. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  22876. {
  22877. return list.indexOf (event);
  22878. }
  22879. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  22880. {
  22881. const int numEvents = list.size();
  22882. int i;
  22883. for (i = 0; i < numEvents; ++i)
  22884. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  22885. break;
  22886. return i;
  22887. }
  22888. double MidiMessageSequence::getStartTime() const
  22889. {
  22890. if (list.size() > 0)
  22891. return list.getUnchecked(0)->message.getTimeStamp();
  22892. else
  22893. return 0;
  22894. }
  22895. double MidiMessageSequence::getEndTime() const
  22896. {
  22897. if (list.size() > 0)
  22898. return list.getLast()->message.getTimeStamp();
  22899. else
  22900. return 0;
  22901. }
  22902. double MidiMessageSequence::getEventTime (const int index) const
  22903. {
  22904. if (((unsigned int) index) < (unsigned int) list.size())
  22905. return list.getUnchecked (index)->message.getTimeStamp();
  22906. return 0.0;
  22907. }
  22908. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  22909. double timeAdjustment)
  22910. {
  22911. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  22912. timeAdjustment += newMessage.getTimeStamp();
  22913. newOne->message.setTimeStamp (timeAdjustment);
  22914. int i;
  22915. for (i = list.size(); --i >= 0;)
  22916. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  22917. break;
  22918. list.insert (i + 1, newOne);
  22919. }
  22920. void MidiMessageSequence::deleteEvent (const int index,
  22921. const bool deleteMatchingNoteUp)
  22922. {
  22923. if (((unsigned int) index) < (unsigned int) list.size())
  22924. {
  22925. if (deleteMatchingNoteUp)
  22926. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  22927. list.remove (index);
  22928. }
  22929. }
  22930. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  22931. double timeAdjustment,
  22932. double firstAllowableTime,
  22933. double endOfAllowableDestTimes)
  22934. {
  22935. firstAllowableTime -= timeAdjustment;
  22936. endOfAllowableDestTimes -= timeAdjustment;
  22937. for (int i = 0; i < other.list.size(); ++i)
  22938. {
  22939. const MidiMessage& m = other.list.getUnchecked(i)->message;
  22940. const double t = m.getTimeStamp();
  22941. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  22942. {
  22943. MidiEventHolder* const newOne = new MidiEventHolder (m);
  22944. newOne->message.setTimeStamp (timeAdjustment + t);
  22945. list.add (newOne);
  22946. }
  22947. }
  22948. sort();
  22949. }
  22950. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  22951. const MidiMessageSequence::MidiEventHolder* const second) throw()
  22952. {
  22953. const double diff = first->message.getTimeStamp()
  22954. - second->message.getTimeStamp();
  22955. return (diff > 0) - (diff < 0);
  22956. }
  22957. void MidiMessageSequence::sort()
  22958. {
  22959. list.sort (*this, true);
  22960. }
  22961. void MidiMessageSequence::updateMatchedPairs()
  22962. {
  22963. for (int i = 0; i < list.size(); ++i)
  22964. {
  22965. const MidiMessage& m1 = list.getUnchecked(i)->message;
  22966. if (m1.isNoteOn())
  22967. {
  22968. list.getUnchecked(i)->noteOffObject = 0;
  22969. const int note = m1.getNoteNumber();
  22970. const int chan = m1.getChannel();
  22971. const int len = list.size();
  22972. for (int j = i + 1; j < len; ++j)
  22973. {
  22974. const MidiMessage& m = list.getUnchecked(j)->message;
  22975. if (m.getNoteNumber() == note && m.getChannel() == chan)
  22976. {
  22977. if (m.isNoteOff())
  22978. {
  22979. list.getUnchecked(i)->noteOffObject = list[j];
  22980. break;
  22981. }
  22982. else if (m.isNoteOn())
  22983. {
  22984. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  22985. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  22986. list.getUnchecked(i)->noteOffObject = list[j];
  22987. break;
  22988. }
  22989. }
  22990. }
  22991. }
  22992. }
  22993. }
  22994. void MidiMessageSequence::addTimeToMessages (const double delta)
  22995. {
  22996. for (int i = list.size(); --i >= 0;)
  22997. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  22998. + delta);
  22999. }
  23000. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23001. MidiMessageSequence& destSequence,
  23002. const bool alsoIncludeMetaEvents) const
  23003. {
  23004. for (int i = 0; i < list.size(); ++i)
  23005. {
  23006. const MidiMessage& mm = list.getUnchecked(i)->message;
  23007. if (mm.isForChannel (channelNumberToExtract)
  23008. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23009. {
  23010. destSequence.addEvent (mm);
  23011. }
  23012. }
  23013. }
  23014. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23015. {
  23016. for (int i = 0; i < list.size(); ++i)
  23017. {
  23018. const MidiMessage& mm = list.getUnchecked(i)->message;
  23019. if (mm.isSysEx())
  23020. destSequence.addEvent (mm);
  23021. }
  23022. }
  23023. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23024. {
  23025. for (int i = list.size(); --i >= 0;)
  23026. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23027. list.remove(i);
  23028. }
  23029. void MidiMessageSequence::deleteSysExMessages()
  23030. {
  23031. for (int i = list.size(); --i >= 0;)
  23032. if (list.getUnchecked(i)->message.isSysEx())
  23033. list.remove(i);
  23034. }
  23035. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23036. const double time,
  23037. OwnedArray<MidiMessage>& dest)
  23038. {
  23039. bool doneProg = false;
  23040. bool donePitchWheel = false;
  23041. Array <int> doneControllers;
  23042. doneControllers.ensureStorageAllocated (32);
  23043. for (int i = list.size(); --i >= 0;)
  23044. {
  23045. const MidiMessage& mm = list.getUnchecked(i)->message;
  23046. if (mm.isForChannel (channelNumber)
  23047. && mm.getTimeStamp() <= time)
  23048. {
  23049. if (mm.isProgramChange())
  23050. {
  23051. if (! doneProg)
  23052. {
  23053. dest.add (new MidiMessage (mm, 0.0));
  23054. doneProg = true;
  23055. }
  23056. }
  23057. else if (mm.isController())
  23058. {
  23059. if (! doneControllers.contains (mm.getControllerNumber()))
  23060. {
  23061. dest.add (new MidiMessage (mm, 0.0));
  23062. doneControllers.add (mm.getControllerNumber());
  23063. }
  23064. }
  23065. else if (mm.isPitchWheel())
  23066. {
  23067. if (! donePitchWheel)
  23068. {
  23069. dest.add (new MidiMessage (mm, 0.0));
  23070. donePitchWheel = true;
  23071. }
  23072. }
  23073. }
  23074. }
  23075. }
  23076. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23077. : message (message_),
  23078. noteOffObject (0)
  23079. {
  23080. }
  23081. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23082. {
  23083. }
  23084. END_JUCE_NAMESPACE
  23085. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23086. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23087. BEGIN_JUCE_NAMESPACE
  23088. AudioPluginFormat::AudioPluginFormat() throw()
  23089. {
  23090. }
  23091. AudioPluginFormat::~AudioPluginFormat()
  23092. {
  23093. }
  23094. END_JUCE_NAMESPACE
  23095. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23096. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23097. BEGIN_JUCE_NAMESPACE
  23098. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23099. {
  23100. }
  23101. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23102. {
  23103. clearSingletonInstance();
  23104. }
  23105. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23106. void AudioPluginFormatManager::addDefaultFormats()
  23107. {
  23108. #ifdef JUCE_DEBUG
  23109. // you should only call this method once!
  23110. for (int i = formats.size(); --i >= 0;)
  23111. {
  23112. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23113. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23114. #endif
  23115. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23116. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23117. #endif
  23118. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23119. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23120. #endif
  23121. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23122. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23123. #endif
  23124. }
  23125. #endif
  23126. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23127. formats.add (new AudioUnitPluginFormat());
  23128. #endif
  23129. #if JUCE_PLUGINHOST_VST && ! (JUCE_MAC && JUCE_64BIT)
  23130. formats.add (new VSTPluginFormat());
  23131. #endif
  23132. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23133. formats.add (new DirectXPluginFormat());
  23134. #endif
  23135. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23136. formats.add (new LADSPAPluginFormat());
  23137. #endif
  23138. }
  23139. int AudioPluginFormatManager::getNumFormats() throw()
  23140. {
  23141. return formats.size();
  23142. }
  23143. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23144. {
  23145. return formats [index];
  23146. }
  23147. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23148. {
  23149. formats.add (format);
  23150. }
  23151. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23152. String& errorMessage) const
  23153. {
  23154. AudioPluginInstance* result = 0;
  23155. for (int i = 0; i < formats.size(); ++i)
  23156. {
  23157. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23158. if (result != 0)
  23159. break;
  23160. }
  23161. if (result == 0)
  23162. {
  23163. if (! doesPluginStillExist (description))
  23164. errorMessage = TRANS ("This plug-in file no longer exists");
  23165. else
  23166. errorMessage = TRANS ("This plug-in failed to load correctly");
  23167. }
  23168. return result;
  23169. }
  23170. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23171. {
  23172. for (int i = 0; i < formats.size(); ++i)
  23173. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23174. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23175. return false;
  23176. }
  23177. END_JUCE_NAMESPACE
  23178. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23179. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23180. #define JUCE_PLUGIN_HOST 1
  23181. BEGIN_JUCE_NAMESPACE
  23182. AudioPluginInstance::AudioPluginInstance()
  23183. {
  23184. }
  23185. AudioPluginInstance::~AudioPluginInstance()
  23186. {
  23187. }
  23188. END_JUCE_NAMESPACE
  23189. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23190. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23191. BEGIN_JUCE_NAMESPACE
  23192. KnownPluginList::KnownPluginList()
  23193. {
  23194. }
  23195. KnownPluginList::~KnownPluginList()
  23196. {
  23197. }
  23198. void KnownPluginList::clear()
  23199. {
  23200. if (types.size() > 0)
  23201. {
  23202. types.clear();
  23203. sendChangeMessage (this);
  23204. }
  23205. }
  23206. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23207. {
  23208. for (int i = 0; i < types.size(); ++i)
  23209. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23210. return types.getUnchecked(i);
  23211. return 0;
  23212. }
  23213. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23214. {
  23215. for (int i = 0; i < types.size(); ++i)
  23216. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23217. return types.getUnchecked(i);
  23218. return 0;
  23219. }
  23220. bool KnownPluginList::addType (const PluginDescription& type)
  23221. {
  23222. for (int i = types.size(); --i >= 0;)
  23223. {
  23224. if (types.getUnchecked(i)->isDuplicateOf (type))
  23225. {
  23226. // strange - found a duplicate plugin with different info..
  23227. jassert (types.getUnchecked(i)->name == type.name);
  23228. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23229. *types.getUnchecked(i) = type;
  23230. return false;
  23231. }
  23232. }
  23233. types.add (new PluginDescription (type));
  23234. sendChangeMessage (this);
  23235. return true;
  23236. }
  23237. void KnownPluginList::removeType (const int index) throw()
  23238. {
  23239. types.remove (index);
  23240. sendChangeMessage (this);
  23241. }
  23242. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23243. {
  23244. if (fileOrIdentifier.startsWithChar ('/')
  23245. || fileOrIdentifier[1] == ':')
  23246. {
  23247. return File (fileOrIdentifier).getLastModificationTime();
  23248. }
  23249. return Time (0);
  23250. }
  23251. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23252. {
  23253. return t1 != t2 || t1 == Time (0);
  23254. }
  23255. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23256. {
  23257. if (getTypeForFile (fileOrIdentifier) == 0)
  23258. return false;
  23259. for (int i = types.size(); --i >= 0;)
  23260. {
  23261. const PluginDescription* const d = types.getUnchecked(i);
  23262. if (d->fileOrIdentifier == fileOrIdentifier
  23263. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23264. {
  23265. return false;
  23266. }
  23267. }
  23268. return true;
  23269. }
  23270. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23271. const bool dontRescanIfAlreadyInList,
  23272. OwnedArray <PluginDescription>& typesFound,
  23273. AudioPluginFormat& format)
  23274. {
  23275. bool addedOne = false;
  23276. if (dontRescanIfAlreadyInList
  23277. && getTypeForFile (fileOrIdentifier) != 0)
  23278. {
  23279. bool needsRescanning = false;
  23280. for (int i = types.size(); --i >= 0;)
  23281. {
  23282. const PluginDescription* const d = types.getUnchecked(i);
  23283. if (d->fileOrIdentifier == fileOrIdentifier)
  23284. {
  23285. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23286. needsRescanning = true;
  23287. else
  23288. typesFound.add (new PluginDescription (*d));
  23289. }
  23290. }
  23291. if (! needsRescanning)
  23292. return false;
  23293. }
  23294. OwnedArray <PluginDescription> found;
  23295. format.findAllTypesForFile (found, fileOrIdentifier);
  23296. for (int i = 0; i < found.size(); ++i)
  23297. {
  23298. PluginDescription* const desc = found.getUnchecked(i);
  23299. jassert (desc != 0);
  23300. if (addType (*desc))
  23301. addedOne = true;
  23302. typesFound.add (new PluginDescription (*desc));
  23303. }
  23304. return addedOne;
  23305. }
  23306. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23307. OwnedArray <PluginDescription>& typesFound)
  23308. {
  23309. for (int i = 0; i < files.size(); ++i)
  23310. {
  23311. bool loaded = false;
  23312. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23313. {
  23314. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23315. if (scanAndAddFile (files[i], true, typesFound, *format))
  23316. loaded = true;
  23317. }
  23318. if (! loaded)
  23319. {
  23320. const File f (files[i]);
  23321. if (f.isDirectory())
  23322. {
  23323. StringArray s;
  23324. {
  23325. Array<File> subFiles;
  23326. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23327. for (int j = 0; j < subFiles.size(); ++j)
  23328. s.add (subFiles.getReference(j).getFullPathName());
  23329. }
  23330. scanAndAddDragAndDroppedFiles (s, typesFound);
  23331. }
  23332. }
  23333. }
  23334. }
  23335. class PluginSorter
  23336. {
  23337. public:
  23338. KnownPluginList::SortMethod method;
  23339. PluginSorter() throw() {}
  23340. int compareElements (const PluginDescription* const first,
  23341. const PluginDescription* const second) const throw()
  23342. {
  23343. int diff = 0;
  23344. if (method == KnownPluginList::sortByCategory)
  23345. diff = first->category.compareLexicographically (second->category);
  23346. else if (method == KnownPluginList::sortByManufacturer)
  23347. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23348. else if (method == KnownPluginList::sortByFileSystemLocation)
  23349. diff = first->fileOrIdentifier.replaceCharacter ('\\', '/')
  23350. .upToLastOccurrenceOf ("/", false, false)
  23351. .compare (second->fileOrIdentifier.replaceCharacter ('\\', '/')
  23352. .upToLastOccurrenceOf ("/", false, false));
  23353. if (diff == 0)
  23354. diff = first->name.compareLexicographically (second->name);
  23355. return diff;
  23356. }
  23357. };
  23358. void KnownPluginList::sort (const SortMethod method)
  23359. {
  23360. if (method != defaultOrder)
  23361. {
  23362. PluginSorter sorter;
  23363. sorter.method = method;
  23364. types.sort (sorter, true);
  23365. sendChangeMessage (this);
  23366. }
  23367. }
  23368. XmlElement* KnownPluginList::createXml() const
  23369. {
  23370. XmlElement* const e = new XmlElement ("KNOWNPLUGINS");
  23371. for (int i = 0; i < types.size(); ++i)
  23372. e->addChildElement (types.getUnchecked(i)->createXml());
  23373. return e;
  23374. }
  23375. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23376. {
  23377. clear();
  23378. if (xml.hasTagName ("KNOWNPLUGINS"))
  23379. {
  23380. forEachXmlChildElement (xml, e)
  23381. {
  23382. PluginDescription info;
  23383. if (info.loadFromXml (*e))
  23384. addType (info);
  23385. }
  23386. }
  23387. }
  23388. const int menuIdBase = 0x324503f4;
  23389. // This is used to turn a bunch of paths into a nested menu structure.
  23390. struct PluginFilesystemTree
  23391. {
  23392. private:
  23393. String folder;
  23394. OwnedArray <PluginFilesystemTree> subFolders;
  23395. Array <PluginDescription*> plugins;
  23396. void addPlugin (PluginDescription* const pd, const String& path)
  23397. {
  23398. if (path.isEmpty())
  23399. {
  23400. plugins.add (pd);
  23401. }
  23402. else
  23403. {
  23404. const String firstSubFolder (path.upToFirstOccurrenceOf ("/", false, false));
  23405. const String remainingPath (path.fromFirstOccurrenceOf ("/", false, false));
  23406. for (int i = subFolders.size(); --i >= 0;)
  23407. {
  23408. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23409. {
  23410. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23411. return;
  23412. }
  23413. }
  23414. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23415. newFolder->folder = firstSubFolder;
  23416. subFolders.add (newFolder);
  23417. newFolder->addPlugin (pd, remainingPath);
  23418. }
  23419. }
  23420. // removes any deeply nested folders that don't contain any actual plugins
  23421. void optimise()
  23422. {
  23423. for (int i = subFolders.size(); --i >= 0;)
  23424. {
  23425. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23426. sub->optimise();
  23427. if (sub->plugins.size() == 0)
  23428. {
  23429. for (int j = 0; j < sub->subFolders.size(); ++j)
  23430. subFolders.add (sub->subFolders.getUnchecked(j));
  23431. sub->subFolders.clear (false);
  23432. subFolders.remove (i);
  23433. }
  23434. }
  23435. }
  23436. public:
  23437. void buildTree (const Array <PluginDescription*>& allPlugins)
  23438. {
  23439. for (int i = 0; i < allPlugins.size(); ++i)
  23440. {
  23441. String path (allPlugins.getUnchecked(i)
  23442. ->fileOrIdentifier.replaceCharacter ('\\', '/')
  23443. .upToLastOccurrenceOf ("/", false, false));
  23444. if (path.substring (1, 2) == ":")
  23445. path = path.substring (2);
  23446. addPlugin (allPlugins.getUnchecked(i), path);
  23447. }
  23448. optimise();
  23449. }
  23450. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23451. {
  23452. int i;
  23453. for (i = 0; i < subFolders.size(); ++i)
  23454. {
  23455. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23456. PopupMenu subMenu;
  23457. sub->addToMenu (subMenu, allPlugins);
  23458. #if JUCE_MAC
  23459. // avoid the special AU formatting nonsense on Mac..
  23460. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (":", false, false), subMenu);
  23461. #else
  23462. m.addSubMenu (sub->folder, subMenu);
  23463. #endif
  23464. }
  23465. for (i = 0; i < plugins.size(); ++i)
  23466. {
  23467. PluginDescription* const plugin = plugins.getUnchecked(i);
  23468. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23469. plugin->name, true, false);
  23470. }
  23471. }
  23472. };
  23473. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23474. {
  23475. Array <PluginDescription*> sorted;
  23476. {
  23477. PluginSorter sorter;
  23478. sorter.method = sortMethod;
  23479. for (int i = 0; i < types.size(); ++i)
  23480. sorted.addSorted (sorter, types.getUnchecked(i));
  23481. }
  23482. if (sortMethod == sortByCategory
  23483. || sortMethod == sortByManufacturer)
  23484. {
  23485. String lastSubMenuName;
  23486. PopupMenu sub;
  23487. for (int i = 0; i < sorted.size(); ++i)
  23488. {
  23489. const PluginDescription* const pd = sorted.getUnchecked(i);
  23490. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23491. : pd->manufacturerName);
  23492. if (! thisSubMenuName.containsNonWhitespaceChars())
  23493. thisSubMenuName = "Other";
  23494. if (thisSubMenuName != lastSubMenuName)
  23495. {
  23496. if (sub.getNumItems() > 0)
  23497. {
  23498. menu.addSubMenu (lastSubMenuName, sub);
  23499. sub.clear();
  23500. }
  23501. lastSubMenuName = thisSubMenuName;
  23502. }
  23503. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23504. }
  23505. if (sub.getNumItems() > 0)
  23506. menu.addSubMenu (lastSubMenuName, sub);
  23507. }
  23508. else if (sortMethod == sortByFileSystemLocation)
  23509. {
  23510. PluginFilesystemTree root;
  23511. root.buildTree (sorted);
  23512. root.addToMenu (menu, types);
  23513. }
  23514. else
  23515. {
  23516. for (int i = 0; i < sorted.size(); ++i)
  23517. {
  23518. const PluginDescription* const pd = sorted.getUnchecked(i);
  23519. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23520. }
  23521. }
  23522. }
  23523. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23524. {
  23525. const int i = menuResultCode - menuIdBase;
  23526. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23527. }
  23528. END_JUCE_NAMESPACE
  23529. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23530. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23531. BEGIN_JUCE_NAMESPACE
  23532. PluginDescription::PluginDescription() throw()
  23533. : uid (0),
  23534. isInstrument (false),
  23535. numInputChannels (0),
  23536. numOutputChannels (0)
  23537. {
  23538. }
  23539. PluginDescription::~PluginDescription() throw()
  23540. {
  23541. }
  23542. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23543. : name (other.name),
  23544. pluginFormatName (other.pluginFormatName),
  23545. category (other.category),
  23546. manufacturerName (other.manufacturerName),
  23547. version (other.version),
  23548. fileOrIdentifier (other.fileOrIdentifier),
  23549. lastFileModTime (other.lastFileModTime),
  23550. uid (other.uid),
  23551. isInstrument (other.isInstrument),
  23552. numInputChannels (other.numInputChannels),
  23553. numOutputChannels (other.numOutputChannels)
  23554. {
  23555. }
  23556. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23557. {
  23558. name = other.name;
  23559. pluginFormatName = other.pluginFormatName;
  23560. category = other.category;
  23561. manufacturerName = other.manufacturerName;
  23562. version = other.version;
  23563. fileOrIdentifier = other.fileOrIdentifier;
  23564. uid = other.uid;
  23565. isInstrument = other.isInstrument;
  23566. lastFileModTime = other.lastFileModTime;
  23567. numInputChannels = other.numInputChannels;
  23568. numOutputChannels = other.numOutputChannels;
  23569. return *this;
  23570. }
  23571. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23572. {
  23573. return fileOrIdentifier == other.fileOrIdentifier
  23574. && uid == other.uid;
  23575. }
  23576. const String PluginDescription::createIdentifierString() const throw()
  23577. {
  23578. return pluginFormatName
  23579. + "-" + name
  23580. + "-" + String::toHexString (fileOrIdentifier.hashCode())
  23581. + "-" + String::toHexString (uid);
  23582. }
  23583. XmlElement* PluginDescription::createXml() const
  23584. {
  23585. XmlElement* const e = new XmlElement ("PLUGIN");
  23586. e->setAttribute ("name", name);
  23587. e->setAttribute ("format", pluginFormatName);
  23588. e->setAttribute ("category", category);
  23589. e->setAttribute ("manufacturer", manufacturerName);
  23590. e->setAttribute ("version", version);
  23591. e->setAttribute ("file", fileOrIdentifier);
  23592. e->setAttribute ("uid", String::toHexString (uid));
  23593. e->setAttribute ("isInstrument", isInstrument);
  23594. e->setAttribute ("fileTime", String::toHexString (lastFileModTime.toMilliseconds()));
  23595. e->setAttribute ("numInputs", numInputChannels);
  23596. e->setAttribute ("numOutputs", numOutputChannels);
  23597. return e;
  23598. }
  23599. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23600. {
  23601. if (xml.hasTagName ("PLUGIN"))
  23602. {
  23603. name = xml.getStringAttribute ("name");
  23604. pluginFormatName = xml.getStringAttribute ("format");
  23605. category = xml.getStringAttribute ("category");
  23606. manufacturerName = xml.getStringAttribute ("manufacturer");
  23607. version = xml.getStringAttribute ("version");
  23608. fileOrIdentifier = xml.getStringAttribute ("file");
  23609. uid = xml.getStringAttribute ("uid").getHexValue32();
  23610. isInstrument = xml.getBoolAttribute ("isInstrument", false);
  23611. lastFileModTime = Time (xml.getStringAttribute ("fileTime").getHexValue64());
  23612. numInputChannels = xml.getIntAttribute ("numInputs");
  23613. numOutputChannels = xml.getIntAttribute ("numOutputs");
  23614. return true;
  23615. }
  23616. return false;
  23617. }
  23618. END_JUCE_NAMESPACE
  23619. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23620. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23621. BEGIN_JUCE_NAMESPACE
  23622. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23623. AudioPluginFormat& formatToLookFor,
  23624. FileSearchPath directoriesToSearch,
  23625. const bool recursive,
  23626. const File& deadMansPedalFile_)
  23627. : list (listToAddTo),
  23628. format (formatToLookFor),
  23629. deadMansPedalFile (deadMansPedalFile_),
  23630. nextIndex (0),
  23631. progress (0)
  23632. {
  23633. directoriesToSearch.removeRedundantPaths();
  23634. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23635. // If any plugins have crashed recently when being loaded, move them to the
  23636. // end of the list to give the others a chance to load correctly..
  23637. const StringArray crashedPlugins (getDeadMansPedalFile());
  23638. for (int i = 0; i < crashedPlugins.size(); ++i)
  23639. {
  23640. const String f = crashedPlugins[i];
  23641. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23642. if (f == filesOrIdentifiersToScan[j])
  23643. filesOrIdentifiersToScan.move (j, -1);
  23644. }
  23645. }
  23646. PluginDirectoryScanner::~PluginDirectoryScanner()
  23647. {
  23648. }
  23649. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23650. {
  23651. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23652. }
  23653. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23654. {
  23655. String file (filesOrIdentifiersToScan [nextIndex]);
  23656. if (file.isNotEmpty())
  23657. {
  23658. if (! list.isListingUpToDate (file))
  23659. {
  23660. OwnedArray <PluginDescription> typesFound;
  23661. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23662. StringArray crashedPlugins (getDeadMansPedalFile());
  23663. crashedPlugins.removeString (file);
  23664. crashedPlugins.add (file);
  23665. setDeadMansPedalFile (crashedPlugins);
  23666. list.scanAndAddFile (file,
  23667. dontRescanIfAlreadyInList,
  23668. typesFound,
  23669. format);
  23670. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23671. crashedPlugins.removeString (file);
  23672. setDeadMansPedalFile (crashedPlugins);
  23673. if (typesFound.size() == 0)
  23674. failedFiles.add (file);
  23675. }
  23676. ++nextIndex;
  23677. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23678. }
  23679. return nextIndex < filesOrIdentifiersToScan.size();
  23680. }
  23681. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23682. {
  23683. StringArray lines;
  23684. if (deadMansPedalFile != File::nonexistent)
  23685. {
  23686. lines.addLines (deadMansPedalFile.loadFileAsString());
  23687. lines.removeEmptyStrings();
  23688. }
  23689. return lines;
  23690. }
  23691. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23692. {
  23693. if (deadMansPedalFile != File::nonexistent)
  23694. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23695. }
  23696. END_JUCE_NAMESPACE
  23697. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23698. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23699. BEGIN_JUCE_NAMESPACE
  23700. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23701. const File& deadMansPedalFile_,
  23702. PropertiesFile* const propertiesToUse_)
  23703. : list (listToEdit),
  23704. deadMansPedalFile (deadMansPedalFile_),
  23705. propertiesToUse (propertiesToUse_)
  23706. {
  23707. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  23708. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  23709. optionsButton->addButtonListener (this);
  23710. optionsButton->setTriggeredOnMouseDown (true);
  23711. setSize (400, 600);
  23712. list.addChangeListener (this);
  23713. }
  23714. PluginListComponent::~PluginListComponent()
  23715. {
  23716. list.removeChangeListener (this);
  23717. deleteAllChildren();
  23718. }
  23719. void PluginListComponent::resized()
  23720. {
  23721. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  23722. optionsButton->changeWidthToFitText (24);
  23723. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  23724. }
  23725. void PluginListComponent::changeListenerCallback (void*)
  23726. {
  23727. listBox->updateContent();
  23728. listBox->repaint();
  23729. }
  23730. int PluginListComponent::getNumRows()
  23731. {
  23732. return list.getNumTypes();
  23733. }
  23734. void PluginListComponent::paintListBoxItem (int row,
  23735. Graphics& g,
  23736. int width, int height,
  23737. bool rowIsSelected)
  23738. {
  23739. if (rowIsSelected)
  23740. g.fillAll (findColour (TextEditor::highlightColourId));
  23741. const PluginDescription* const pd = list.getType (row);
  23742. if (pd != 0)
  23743. {
  23744. GlyphArrangement ga;
  23745. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  23746. g.setColour (Colours::black);
  23747. ga.draw (g);
  23748. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  23749. String desc;
  23750. desc << pd->pluginFormatName
  23751. << (pd->isInstrument ? " instrument" : " effect")
  23752. << " - "
  23753. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  23754. << " / "
  23755. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  23756. if (pd->manufacturerName.isNotEmpty())
  23757. desc << " - " << pd->manufacturerName;
  23758. if (pd->version.isNotEmpty())
  23759. desc << " - " << pd->version;
  23760. if (pd->category.isNotEmpty())
  23761. desc << " - category: '" << pd->category << '\'';
  23762. g.setColour (Colours::grey);
  23763. ga.clear();
  23764. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, bb.getRight() + 10.0f, height * 0.8f, width - bb.getRight() - 12.0f, true);
  23765. ga.draw (g);
  23766. }
  23767. }
  23768. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  23769. {
  23770. list.removeType (lastRowSelected);
  23771. }
  23772. void PluginListComponent::buttonClicked (Button* b)
  23773. {
  23774. if (optionsButton == b)
  23775. {
  23776. PopupMenu menu;
  23777. menu.addItem (1, TRANS("Clear list"));
  23778. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  23779. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  23780. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  23781. menu.addSeparator();
  23782. menu.addItem (2, TRANS("Sort alphabetically"));
  23783. menu.addItem (3, TRANS("Sort by category"));
  23784. menu.addItem (4, TRANS("Sort by manufacturer"));
  23785. menu.addSeparator();
  23786. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  23787. {
  23788. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  23789. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  23790. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  23791. }
  23792. const int r = menu.showAt (optionsButton);
  23793. if (r == 1)
  23794. {
  23795. list.clear();
  23796. }
  23797. else if (r == 2)
  23798. {
  23799. list.sort (KnownPluginList::sortAlphabetically);
  23800. }
  23801. else if (r == 3)
  23802. {
  23803. list.sort (KnownPluginList::sortByCategory);
  23804. }
  23805. else if (r == 4)
  23806. {
  23807. list.sort (KnownPluginList::sortByManufacturer);
  23808. }
  23809. else if (r == 5)
  23810. {
  23811. const SparseSet <int> selected (listBox->getSelectedRows());
  23812. for (int i = list.getNumTypes(); --i >= 0;)
  23813. if (selected.contains (i))
  23814. list.removeType (i);
  23815. }
  23816. else if (r == 6)
  23817. {
  23818. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  23819. if (desc != 0)
  23820. {
  23821. if (File (desc->fileOrIdentifier).existsAsFile())
  23822. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  23823. }
  23824. }
  23825. else if (r == 7)
  23826. {
  23827. for (int i = list.getNumTypes(); --i >= 0;)
  23828. {
  23829. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  23830. {
  23831. list.removeType (i);
  23832. }
  23833. }
  23834. }
  23835. else if (r != 0)
  23836. {
  23837. typeToScan = r - 10;
  23838. startTimer (1);
  23839. }
  23840. }
  23841. }
  23842. void PluginListComponent::timerCallback()
  23843. {
  23844. stopTimer();
  23845. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  23846. }
  23847. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  23848. {
  23849. return true;
  23850. }
  23851. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  23852. {
  23853. OwnedArray <PluginDescription> typesFound;
  23854. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  23855. }
  23856. void PluginListComponent::scanFor (AudioPluginFormat* format)
  23857. {
  23858. if (format == 0)
  23859. return;
  23860. FileSearchPath path (format->getDefaultLocationsToSearch());
  23861. if (propertiesToUse != 0)
  23862. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23863. {
  23864. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  23865. FileSearchPathListComponent pathList;
  23866. pathList.setSize (500, 300);
  23867. pathList.setPath (path);
  23868. aw.addCustomComponent (&pathList);
  23869. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  23870. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23871. if (aw.runModalLoop() == 0)
  23872. return;
  23873. path = pathList.getPath();
  23874. }
  23875. if (propertiesToUse != 0)
  23876. {
  23877. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  23878. propertiesToUse->saveIfNeeded();
  23879. }
  23880. double progress = 0.0;
  23881. AlertWindow aw (TRANS("Scanning for plugins..."),
  23882. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  23883. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  23884. aw.addProgressBarComponent (progress);
  23885. aw.enterModalState();
  23886. MessageManager::getInstance()->runDispatchLoopUntil (300);
  23887. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  23888. for (;;)
  23889. {
  23890. aw.setMessage (TRANS("Testing:\n\n")
  23891. + scanner.getNextPluginFileThatWillBeScanned());
  23892. MessageManager::getInstance()->runDispatchLoopUntil (20);
  23893. if (! scanner.scanNextFile (true))
  23894. break;
  23895. if (! aw.isCurrentlyModal())
  23896. break;
  23897. progress = scanner.getProgress();
  23898. }
  23899. if (scanner.getFailedFiles().size() > 0)
  23900. {
  23901. StringArray shortNames;
  23902. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  23903. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  23904. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  23905. TRANS("Scan complete"),
  23906. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  23907. + shortNames.joinIntoString (", "));
  23908. }
  23909. }
  23910. END_JUCE_NAMESPACE
  23911. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  23912. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  23913. #if JUCE_PLUGINHOST_AU && ! (JUCE_LINUX || JUCE_WINDOWS)
  23914. #include <AudioUnit/AudioUnit.h>
  23915. #include <AudioUnit/AUCocoaUIView.h>
  23916. #include <CoreAudioKit/AUGenericView.h>
  23917. #if JUCE_SUPPORT_CARBON
  23918. #include <AudioToolbox/AudioUnitUtilities.h>
  23919. #include <AudioUnit/AudioUnitCarbonView.h>
  23920. #endif
  23921. BEGIN_JUCE_NAMESPACE
  23922. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  23923. #endif
  23924. #if JUCE_MAC
  23925. // Change this to disable logging of various activities
  23926. #ifndef AU_LOGGING
  23927. #define AU_LOGGING 1
  23928. #endif
  23929. #if AU_LOGGING
  23930. #define log(a) Logger::writeToLog(a);
  23931. #else
  23932. #define log(a)
  23933. #endif
  23934. static int insideCallback = 0;
  23935. static const String osTypeToString (OSType type)
  23936. {
  23937. char s[4];
  23938. s[0] = (char) (((uint32) type) >> 24);
  23939. s[1] = (char) (((uint32) type) >> 16);
  23940. s[2] = (char) (((uint32) type) >> 8);
  23941. s[3] = (char) ((uint32) type);
  23942. return String (s, 4);
  23943. }
  23944. static OSType stringToOSType (const String& s1)
  23945. {
  23946. const String s (s1 + " ");
  23947. return (((OSType) (unsigned char) s[0]) << 24)
  23948. | (((OSType) (unsigned char) s[1]) << 16)
  23949. | (((OSType) (unsigned char) s[2]) << 8)
  23950. | ((OSType) (unsigned char) s[3]);
  23951. }
  23952. static const char* auIdentifierPrefix = "AudioUnit:";
  23953. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  23954. {
  23955. jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong..
  23956. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  23957. String s (auIdentifierPrefix);
  23958. if (desc.componentType == kAudioUnitType_MusicDevice)
  23959. s << "Synths/";
  23960. else if (desc.componentType == kAudioUnitType_MusicEffect
  23961. || desc.componentType == kAudioUnitType_Effect)
  23962. s << "Effects/";
  23963. else if (desc.componentType == kAudioUnitType_Generator)
  23964. s << "Generators/";
  23965. else if (desc.componentType == kAudioUnitType_Panner)
  23966. s << "Panners/";
  23967. s << osTypeToString (desc.componentType) << ","
  23968. << osTypeToString (desc.componentSubType) << ","
  23969. << osTypeToString (desc.componentManufacturer);
  23970. return s;
  23971. }
  23972. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  23973. {
  23974. Handle componentNameHandle = NewHandle (sizeof (void*));
  23975. Handle componentInfoHandle = NewHandle (sizeof (void*));
  23976. if (componentNameHandle != 0 && componentInfoHandle != 0)
  23977. {
  23978. ComponentDescription desc;
  23979. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  23980. {
  23981. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  23982. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  23983. if (nameString != 0 && nameString[0] != 0)
  23984. {
  23985. const String all ((const char*) nameString + 1, nameString[0]);
  23986. DBG ("name: "+ all);
  23987. manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim();
  23988. name = all.fromFirstOccurrenceOf (":", false, false).trim();
  23989. }
  23990. if (infoString != 0 && infoString[0] != 0)
  23991. {
  23992. DBG ("info: " + String ((const char*) infoString + 1, infoString[0]));
  23993. }
  23994. if (name.isEmpty())
  23995. name = "<Unknown>";
  23996. }
  23997. DisposeHandle (componentNameHandle);
  23998. DisposeHandle (componentInfoHandle);
  23999. }
  24000. }
  24001. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24002. String& name, String& version, String& manufacturer)
  24003. {
  24004. zerostruct (desc);
  24005. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24006. {
  24007. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'),
  24008. fileOrIdentifier.lastIndexOfChar ('/')) + 1));
  24009. StringArray tokens;
  24010. tokens.addTokens (s, ",", String::empty);
  24011. tokens.trim();
  24012. tokens.removeEmptyStrings();
  24013. if (tokens.size() == 3)
  24014. {
  24015. desc.componentType = stringToOSType (tokens[0]);
  24016. desc.componentSubType = stringToOSType (tokens[1]);
  24017. desc.componentManufacturer = stringToOSType (tokens[2]);
  24018. ComponentRecord* comp = FindNextComponent (0, &desc);
  24019. if (comp != 0)
  24020. {
  24021. getAUDetails (comp, name, manufacturer);
  24022. return true;
  24023. }
  24024. }
  24025. }
  24026. return false;
  24027. }
  24028. class AudioUnitPluginWindowCarbon;
  24029. class AudioUnitPluginWindowCocoa;
  24030. class AudioUnitPluginInstance : public AudioPluginInstance
  24031. {
  24032. public:
  24033. ~AudioUnitPluginInstance();
  24034. // AudioPluginInstance methods:
  24035. void fillInPluginDescription (PluginDescription& desc) const
  24036. {
  24037. desc.name = pluginName;
  24038. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24039. desc.uid = ((int) componentDesc.componentType)
  24040. ^ ((int) componentDesc.componentSubType)
  24041. ^ ((int) componentDesc.componentManufacturer);
  24042. desc.lastFileModTime = 0;
  24043. desc.pluginFormatName = "AudioUnit";
  24044. desc.category = getCategory();
  24045. desc.manufacturerName = manufacturer;
  24046. desc.version = version;
  24047. desc.numInputChannels = getNumInputChannels();
  24048. desc.numOutputChannels = getNumOutputChannels();
  24049. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24050. }
  24051. const String getName() const { return pluginName; }
  24052. bool acceptsMidi() const { return wantsMidiMessages; }
  24053. bool producesMidi() const { return false; }
  24054. // AudioProcessor methods:
  24055. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24056. void releaseResources();
  24057. void processBlock (AudioSampleBuffer& buffer,
  24058. MidiBuffer& midiMessages);
  24059. AudioProcessorEditor* createEditor();
  24060. const String getInputChannelName (const int index) const;
  24061. bool isInputChannelStereoPair (int index) const;
  24062. const String getOutputChannelName (const int index) const;
  24063. bool isOutputChannelStereoPair (int index) const;
  24064. int getNumParameters();
  24065. float getParameter (int index);
  24066. void setParameter (int index, float newValue);
  24067. const String getParameterName (int index);
  24068. const String getParameterText (int index);
  24069. bool isParameterAutomatable (int index) const;
  24070. int getNumPrograms();
  24071. int getCurrentProgram();
  24072. void setCurrentProgram (int index);
  24073. const String getProgramName (int index);
  24074. void changeProgramName (int index, const String& newName);
  24075. void getStateInformation (MemoryBlock& destData);
  24076. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24077. void setStateInformation (const void* data, int sizeInBytes);
  24078. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24079. juce_UseDebuggingNewOperator
  24080. private:
  24081. friend class AudioUnitPluginWindowCarbon;
  24082. friend class AudioUnitPluginWindowCocoa;
  24083. friend class AudioUnitPluginFormat;
  24084. ComponentDescription componentDesc;
  24085. String pluginName, manufacturer, version;
  24086. String fileOrIdentifier;
  24087. CriticalSection lock;
  24088. bool initialised, wantsMidiMessages, wasPlaying;
  24089. HeapBlock <AudioBufferList> outputBufferList;
  24090. AudioTimeStamp timeStamp;
  24091. AudioSampleBuffer* currentBuffer;
  24092. AudioUnit audioUnit;
  24093. Array <int> parameterIds;
  24094. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24095. void initialise();
  24096. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24097. const AudioTimeStamp* inTimeStamp,
  24098. UInt32 inBusNumber,
  24099. UInt32 inNumberFrames,
  24100. AudioBufferList* ioData) const;
  24101. static OSStatus renderGetInputCallback (void* inRefCon,
  24102. AudioUnitRenderActionFlags* ioActionFlags,
  24103. const AudioTimeStamp* inTimeStamp,
  24104. UInt32 inBusNumber,
  24105. UInt32 inNumberFrames,
  24106. AudioBufferList* ioData)
  24107. {
  24108. return ((AudioUnitPluginInstance*) inRefCon)
  24109. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24110. }
  24111. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24112. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24113. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24114. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24115. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24116. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24117. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24118. {
  24119. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24120. }
  24121. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24122. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24123. Float64* outCurrentMeasureDownBeat)
  24124. {
  24125. return ((AudioUnitPluginInstance*) inHostUserData)
  24126. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24127. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24128. }
  24129. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24130. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24131. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24132. {
  24133. return ((AudioUnitPluginInstance*) inHostUserData)
  24134. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24135. outCurrentSampleInTimeLine, outIsCycling,
  24136. outCycleStartBeat, outCycleEndBeat);
  24137. }
  24138. void getNumChannels (int& numIns, int& numOuts)
  24139. {
  24140. numIns = 0;
  24141. numOuts = 0;
  24142. AUChannelInfo supportedChannels [128];
  24143. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24144. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24145. 0, supportedChannels, &supportedChannelsSize) == noErr
  24146. && supportedChannelsSize > 0)
  24147. {
  24148. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24149. {
  24150. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24151. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24152. }
  24153. }
  24154. else
  24155. {
  24156. // (this really means the plugin will take any number of ins/outs as long
  24157. // as they are the same)
  24158. numIns = numOuts = 2;
  24159. }
  24160. }
  24161. const String getCategory() const;
  24162. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24163. };
  24164. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24165. : fileOrIdentifier (fileOrIdentifier),
  24166. initialised (false),
  24167. wantsMidiMessages (false),
  24168. audioUnit (0),
  24169. currentBuffer (0)
  24170. {
  24171. try
  24172. {
  24173. ++insideCallback;
  24174. log ("Opening AU: " + fileOrIdentifier);
  24175. if (getComponentDescFromFile (fileOrIdentifier))
  24176. {
  24177. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24178. if (comp != 0)
  24179. {
  24180. audioUnit = (AudioUnit) OpenComponent (comp);
  24181. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24182. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24183. }
  24184. }
  24185. --insideCallback;
  24186. }
  24187. catch (...)
  24188. {
  24189. --insideCallback;
  24190. }
  24191. }
  24192. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24193. {
  24194. const ScopedLock sl (lock);
  24195. jassert (insideCallback == 0);
  24196. if (audioUnit != 0)
  24197. {
  24198. AudioUnitUninitialize (audioUnit);
  24199. CloseComponent (audioUnit);
  24200. audioUnit = 0;
  24201. }
  24202. }
  24203. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24204. {
  24205. zerostruct (componentDesc);
  24206. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24207. return true;
  24208. const File file (fileOrIdentifier);
  24209. if (! file.hasFileExtension (".component"))
  24210. return false;
  24211. const char* const utf8 = fileOrIdentifier.toUTF8();
  24212. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24213. strlen (utf8), file.isDirectory());
  24214. if (url != 0)
  24215. {
  24216. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24217. CFRelease (url);
  24218. if (bundleRef != 0)
  24219. {
  24220. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24221. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24222. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24223. if (pluginName.isEmpty())
  24224. pluginName = file.getFileNameWithoutExtension();
  24225. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24226. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24227. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24228. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24229. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24230. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24231. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24232. UseResFile (resFileId);
  24233. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24234. {
  24235. Handle h = Get1IndResource ('thng', i);
  24236. if (h != 0)
  24237. {
  24238. HLock (h);
  24239. const uint32* const types = (const uint32*) *h;
  24240. if (types[0] == kAudioUnitType_MusicDevice
  24241. || types[0] == kAudioUnitType_MusicEffect
  24242. || types[0] == kAudioUnitType_Effect
  24243. || types[0] == kAudioUnitType_Generator
  24244. || types[0] == kAudioUnitType_Panner)
  24245. {
  24246. componentDesc.componentType = types[0];
  24247. componentDesc.componentSubType = types[1];
  24248. componentDesc.componentManufacturer = types[2];
  24249. break;
  24250. }
  24251. HUnlock (h);
  24252. ReleaseResource (h);
  24253. }
  24254. }
  24255. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24256. CFRelease (bundleRef);
  24257. }
  24258. }
  24259. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24260. }
  24261. void AudioUnitPluginInstance::initialise()
  24262. {
  24263. if (initialised || audioUnit == 0)
  24264. return;
  24265. log ("Initialising AU: " + pluginName);
  24266. parameterIds.clear();
  24267. {
  24268. UInt32 paramListSize = 0;
  24269. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24270. 0, 0, &paramListSize);
  24271. if (paramListSize > 0)
  24272. {
  24273. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24274. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24275. 0, &parameterIds.getReference(0), &paramListSize);
  24276. }
  24277. }
  24278. {
  24279. AURenderCallbackStruct info;
  24280. zerostruct (info);
  24281. info.inputProcRefCon = this;
  24282. info.inputProc = renderGetInputCallback;
  24283. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24284. 0, &info, sizeof (info));
  24285. }
  24286. {
  24287. HostCallbackInfo info;
  24288. zerostruct (info);
  24289. info.hostUserData = this;
  24290. info.beatAndTempoProc = getBeatAndTempoCallback;
  24291. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24292. info.transportStateProc = getTransportStateCallback;
  24293. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24294. 0, &info, sizeof (info));
  24295. }
  24296. int numIns, numOuts;
  24297. getNumChannels (numIns, numOuts);
  24298. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24299. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24300. setLatencySamples (0);
  24301. }
  24302. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24303. int samplesPerBlockExpected)
  24304. {
  24305. initialise();
  24306. if (initialised)
  24307. {
  24308. int numIns, numOuts;
  24309. getNumChannels (numIns, numOuts);
  24310. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24311. Float64 latencySecs = 0.0;
  24312. UInt32 latencySize = sizeof (latencySecs);
  24313. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24314. 0, &latencySecs, &latencySize);
  24315. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24316. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24317. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24318. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24319. AudioStreamBasicDescription stream;
  24320. zerostruct (stream);
  24321. stream.mSampleRate = sampleRate_;
  24322. stream.mFormatID = kAudioFormatLinearPCM;
  24323. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24324. stream.mFramesPerPacket = 1;
  24325. stream.mBytesPerPacket = 4;
  24326. stream.mBytesPerFrame = 4;
  24327. stream.mBitsPerChannel = 32;
  24328. stream.mChannelsPerFrame = numIns;
  24329. OSStatus err = AudioUnitSetProperty (audioUnit,
  24330. kAudioUnitProperty_StreamFormat,
  24331. kAudioUnitScope_Input,
  24332. 0, &stream, sizeof (stream));
  24333. stream.mChannelsPerFrame = numOuts;
  24334. err = AudioUnitSetProperty (audioUnit,
  24335. kAudioUnitProperty_StreamFormat,
  24336. kAudioUnitScope_Output,
  24337. 0, &stream, sizeof (stream));
  24338. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24339. outputBufferList->mNumberBuffers = numOuts;
  24340. for (int i = numOuts; --i >= 0;)
  24341. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24342. zerostruct (timeStamp);
  24343. timeStamp.mSampleTime = 0;
  24344. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24345. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24346. currentBuffer = 0;
  24347. wasPlaying = false;
  24348. }
  24349. }
  24350. void AudioUnitPluginInstance::releaseResources()
  24351. {
  24352. if (initialised)
  24353. {
  24354. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24355. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24356. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24357. outputBufferList.free();
  24358. currentBuffer = 0;
  24359. }
  24360. }
  24361. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24362. const AudioTimeStamp* inTimeStamp,
  24363. UInt32 inBusNumber,
  24364. UInt32 inNumberFrames,
  24365. AudioBufferList* ioData) const
  24366. {
  24367. if (inBusNumber == 0
  24368. && currentBuffer != 0)
  24369. {
  24370. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24371. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24372. {
  24373. if (i < currentBuffer->getNumChannels())
  24374. {
  24375. memcpy (ioData->mBuffers[i].mData,
  24376. currentBuffer->getSampleData (i, 0),
  24377. sizeof (float) * inNumberFrames);
  24378. }
  24379. else
  24380. {
  24381. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24382. }
  24383. }
  24384. }
  24385. return noErr;
  24386. }
  24387. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24388. MidiBuffer& midiMessages)
  24389. {
  24390. const int numSamples = buffer.getNumSamples();
  24391. if (initialised)
  24392. {
  24393. AudioUnitRenderActionFlags flags = 0;
  24394. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24395. for (int i = getNumOutputChannels(); --i >= 0;)
  24396. {
  24397. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24398. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24399. }
  24400. currentBuffer = &buffer;
  24401. if (wantsMidiMessages)
  24402. {
  24403. const uint8* midiEventData;
  24404. int midiEventSize, midiEventPosition;
  24405. MidiBuffer::Iterator i (midiMessages);
  24406. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24407. {
  24408. if (midiEventSize <= 3)
  24409. MusicDeviceMIDIEvent (audioUnit,
  24410. midiEventData[0], midiEventData[1], midiEventData[2],
  24411. midiEventPosition);
  24412. else
  24413. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24414. }
  24415. midiMessages.clear();
  24416. }
  24417. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24418. 0, numSamples, outputBufferList);
  24419. timeStamp.mSampleTime += numSamples;
  24420. }
  24421. else
  24422. {
  24423. // Not initialised, so just bypass..
  24424. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24425. buffer.clear (i, 0, buffer.getNumSamples());
  24426. }
  24427. }
  24428. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24429. {
  24430. AudioPlayHead* const ph = getPlayHead();
  24431. AudioPlayHead::CurrentPositionInfo result;
  24432. if (ph != 0 && ph->getCurrentPosition (result))
  24433. {
  24434. if (outCurrentBeat != 0)
  24435. *outCurrentBeat = result.ppqPosition;
  24436. if (outCurrentTempo != 0)
  24437. *outCurrentTempo = result.bpm;
  24438. }
  24439. else
  24440. {
  24441. if (outCurrentBeat != 0)
  24442. *outCurrentBeat = 0;
  24443. if (outCurrentTempo != 0)
  24444. *outCurrentTempo = 120.0;
  24445. }
  24446. return noErr;
  24447. }
  24448. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24449. Float32* outTimeSig_Numerator,
  24450. UInt32* outTimeSig_Denominator,
  24451. Float64* outCurrentMeasureDownBeat) const
  24452. {
  24453. AudioPlayHead* const ph = getPlayHead();
  24454. AudioPlayHead::CurrentPositionInfo result;
  24455. if (ph != 0 && ph->getCurrentPosition (result))
  24456. {
  24457. if (outTimeSig_Numerator != 0)
  24458. *outTimeSig_Numerator = result.timeSigNumerator;
  24459. if (outTimeSig_Denominator != 0)
  24460. *outTimeSig_Denominator = result.timeSigDenominator;
  24461. if (outDeltaSampleOffsetToNextBeat != 0)
  24462. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24463. if (outCurrentMeasureDownBeat != 0)
  24464. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24465. }
  24466. else
  24467. {
  24468. if (outDeltaSampleOffsetToNextBeat != 0)
  24469. *outDeltaSampleOffsetToNextBeat = 0;
  24470. if (outTimeSig_Numerator != 0)
  24471. *outTimeSig_Numerator = 4;
  24472. if (outTimeSig_Denominator != 0)
  24473. *outTimeSig_Denominator = 4;
  24474. if (outCurrentMeasureDownBeat != 0)
  24475. *outCurrentMeasureDownBeat = 0;
  24476. }
  24477. return noErr;
  24478. }
  24479. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24480. Boolean* outTransportStateChanged,
  24481. Float64* outCurrentSampleInTimeLine,
  24482. Boolean* outIsCycling,
  24483. Float64* outCycleStartBeat,
  24484. Float64* outCycleEndBeat)
  24485. {
  24486. AudioPlayHead* const ph = getPlayHead();
  24487. AudioPlayHead::CurrentPositionInfo result;
  24488. if (ph != 0 && ph->getCurrentPosition (result))
  24489. {
  24490. if (outIsPlaying != 0)
  24491. *outIsPlaying = result.isPlaying;
  24492. if (outTransportStateChanged != 0)
  24493. {
  24494. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24495. wasPlaying = result.isPlaying;
  24496. }
  24497. if (outCurrentSampleInTimeLine != 0)
  24498. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24499. if (outIsCycling != 0)
  24500. *outIsCycling = false;
  24501. if (outCycleStartBeat != 0)
  24502. *outCycleStartBeat = 0;
  24503. if (outCycleEndBeat != 0)
  24504. *outCycleEndBeat = 0;
  24505. }
  24506. else
  24507. {
  24508. if (outIsPlaying != 0)
  24509. *outIsPlaying = false;
  24510. if (outTransportStateChanged != 0)
  24511. *outTransportStateChanged = false;
  24512. if (outCurrentSampleInTimeLine != 0)
  24513. *outCurrentSampleInTimeLine = 0;
  24514. if (outIsCycling != 0)
  24515. *outIsCycling = false;
  24516. if (outCycleStartBeat != 0)
  24517. *outCycleStartBeat = 0;
  24518. if (outCycleEndBeat != 0)
  24519. *outCycleEndBeat = 0;
  24520. }
  24521. return noErr;
  24522. }
  24523. static VoidArray activeWindows;
  24524. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24525. {
  24526. public:
  24527. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24528. : AudioProcessorEditor (&plugin_),
  24529. plugin (plugin_),
  24530. wrapper (0)
  24531. {
  24532. addAndMakeVisible (wrapper = new NSViewComponent());
  24533. activeWindows.add (this);
  24534. setOpaque (true);
  24535. setVisible (true);
  24536. setSize (100, 100);
  24537. createView (createGenericViewIfNeeded);
  24538. }
  24539. ~AudioUnitPluginWindowCocoa()
  24540. {
  24541. const bool wasValid = isValid();
  24542. wrapper->setView (0);
  24543. activeWindows.removeValue (this);
  24544. if (wasValid)
  24545. plugin.editorBeingDeleted (this);
  24546. delete wrapper;
  24547. }
  24548. bool isValid() const { return wrapper->getView() != 0; }
  24549. void paint (Graphics& g)
  24550. {
  24551. g.fillAll (Colours::white);
  24552. }
  24553. void resized()
  24554. {
  24555. wrapper->setSize (getWidth(), getHeight());
  24556. }
  24557. private:
  24558. AudioUnitPluginInstance& plugin;
  24559. NSViewComponent* wrapper;
  24560. bool createView (const bool createGenericViewIfNeeded)
  24561. {
  24562. NSView* pluginView = 0;
  24563. UInt32 dataSize = 0;
  24564. Boolean isWritable = false;
  24565. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24566. 0, &dataSize, &isWritable) == noErr
  24567. && dataSize != 0
  24568. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24569. 0, &dataSize, &isWritable) == noErr)
  24570. {
  24571. HeapBlock <AudioUnitCocoaViewInfo> info;
  24572. info.calloc (dataSize, 1);
  24573. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24574. 0, info, &dataSize) == noErr)
  24575. {
  24576. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24577. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24578. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24579. Class viewClass = [viewBundle classNamed: viewClassName];
  24580. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24581. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24582. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24583. {
  24584. id factory = [[[viewClass alloc] init] autorelease];
  24585. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24586. withSize: NSMakeSize (getWidth(), getHeight())];
  24587. }
  24588. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24589. {
  24590. CFRelease (info->mCocoaAUViewClass[i]);
  24591. CFRelease (info->mCocoaAUViewBundleLocation);
  24592. }
  24593. }
  24594. }
  24595. if (createGenericViewIfNeeded && (pluginView == 0))
  24596. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24597. wrapper->setView (pluginView);
  24598. if (pluginView != 0)
  24599. setSize ([pluginView frame].size.width,
  24600. [pluginView frame].size.height);
  24601. return pluginView != 0;
  24602. }
  24603. };
  24604. #if JUCE_SUPPORT_CARBON
  24605. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24606. {
  24607. public:
  24608. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24609. : AudioProcessorEditor (&plugin_),
  24610. plugin (plugin_),
  24611. viewComponent (0)
  24612. {
  24613. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24614. activeWindows.add (this);
  24615. setOpaque (true);
  24616. setVisible (true);
  24617. setSize (400, 300);
  24618. ComponentDescription viewList [16];
  24619. UInt32 viewListSize = sizeof (viewList);
  24620. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24621. 0, &viewList, &viewListSize);
  24622. componentRecord = FindNextComponent (0, &viewList[0]);
  24623. }
  24624. ~AudioUnitPluginWindowCarbon()
  24625. {
  24626. innerWrapper = 0;
  24627. activeWindows.removeValue (this);
  24628. if (isValid())
  24629. plugin.editorBeingDeleted (this);
  24630. }
  24631. bool isValid() const throw() { return componentRecord != 0; }
  24632. void paint (Graphics& g)
  24633. {
  24634. g.fillAll (Colours::black);
  24635. }
  24636. void resized()
  24637. {
  24638. innerWrapper->setSize (getWidth(), getHeight());
  24639. }
  24640. bool keyStateChanged (bool)
  24641. {
  24642. return false;
  24643. }
  24644. bool keyPressed (const KeyPress&)
  24645. {
  24646. return false;
  24647. }
  24648. void broughtToFront()
  24649. {
  24650. activeWindows.removeValue (this);
  24651. activeWindows.add (this);
  24652. }
  24653. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24654. AudioUnitCarbonView getViewComponent()
  24655. {
  24656. if (viewComponent == 0 && componentRecord != 0)
  24657. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24658. return viewComponent;
  24659. }
  24660. void closeViewComponent()
  24661. {
  24662. if (viewComponent != 0)
  24663. {
  24664. CloseComponent (viewComponent);
  24665. viewComponent = 0;
  24666. }
  24667. }
  24668. juce_UseDebuggingNewOperator
  24669. private:
  24670. AudioUnitPluginInstance& plugin;
  24671. ComponentRecord* componentRecord;
  24672. AudioUnitCarbonView viewComponent;
  24673. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24674. {
  24675. public:
  24676. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24677. : owner (owner_)
  24678. {
  24679. }
  24680. ~InnerWrapperComponent()
  24681. {
  24682. deleteWindow();
  24683. }
  24684. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24685. {
  24686. log ("Opening AU GUI: " + owner->plugin.getName());
  24687. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24688. if (viewComponent == 0)
  24689. return 0;
  24690. Float32Point pos = { 0, 0 };
  24691. Float32Point size = { 250, 200 };
  24692. HIViewRef pluginView = 0;
  24693. AudioUnitCarbonViewCreate (viewComponent,
  24694. owner->getAudioUnit(),
  24695. windowRef,
  24696. rootView,
  24697. &pos,
  24698. &size,
  24699. (ControlRef*) &pluginView);
  24700. return pluginView;
  24701. }
  24702. void removeView (HIViewRef)
  24703. {
  24704. log ("Closing AU GUI: " + owner->plugin.getName());
  24705. owner->closeViewComponent();
  24706. }
  24707. private:
  24708. AudioUnitPluginWindowCarbon* const owner;
  24709. };
  24710. friend class InnerWrapperComponent;
  24711. ScopedPointer<InnerWrapperComponent> innerWrapper;
  24712. };
  24713. #endif
  24714. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  24715. {
  24716. ScopedPointer<AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  24717. if (! static_cast <AudioUnitPluginWindowCocoa*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24718. w = 0;
  24719. #if JUCE_SUPPORT_CARBON
  24720. if (w == 0)
  24721. {
  24722. w = new AudioUnitPluginWindowCarbon (*this);
  24723. if (! static_cast <AudioUnitPluginWindowCarbon*> (static_cast <AudioProcessorEditor*> (w))->isValid())
  24724. w = 0;
  24725. }
  24726. #endif
  24727. if (w == 0)
  24728. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  24729. return w.release();
  24730. }
  24731. const String AudioUnitPluginInstance::getCategory() const
  24732. {
  24733. const char* result = 0;
  24734. switch (componentDesc.componentType)
  24735. {
  24736. case kAudioUnitType_Effect:
  24737. case kAudioUnitType_MusicEffect:
  24738. result = "Effect";
  24739. break;
  24740. case kAudioUnitType_MusicDevice:
  24741. result = "Synth";
  24742. break;
  24743. case kAudioUnitType_Generator:
  24744. result = "Generator";
  24745. break;
  24746. case kAudioUnitType_Panner:
  24747. result = "Panner";
  24748. break;
  24749. default:
  24750. break;
  24751. }
  24752. return result;
  24753. }
  24754. int AudioUnitPluginInstance::getNumParameters()
  24755. {
  24756. return parameterIds.size();
  24757. }
  24758. float AudioUnitPluginInstance::getParameter (int index)
  24759. {
  24760. const ScopedLock sl (lock);
  24761. Float32 value = 0.0f;
  24762. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24763. {
  24764. AudioUnitGetParameter (audioUnit,
  24765. (UInt32) parameterIds.getUnchecked (index),
  24766. kAudioUnitScope_Global, 0,
  24767. &value);
  24768. }
  24769. return value;
  24770. }
  24771. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  24772. {
  24773. const ScopedLock sl (lock);
  24774. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  24775. {
  24776. AudioUnitSetParameter (audioUnit,
  24777. (UInt32) parameterIds.getUnchecked (index),
  24778. kAudioUnitScope_Global, 0,
  24779. newValue, 0);
  24780. }
  24781. }
  24782. const String AudioUnitPluginInstance::getParameterName (int index)
  24783. {
  24784. AudioUnitParameterInfo info;
  24785. zerostruct (info);
  24786. UInt32 sz = sizeof (info);
  24787. String name;
  24788. if (AudioUnitGetProperty (audioUnit,
  24789. kAudioUnitProperty_ParameterInfo,
  24790. kAudioUnitScope_Global,
  24791. parameterIds [index], &info, &sz) == noErr)
  24792. {
  24793. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  24794. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  24795. else
  24796. name = String (info.name, sizeof (info.name));
  24797. }
  24798. return name;
  24799. }
  24800. const String AudioUnitPluginInstance::getParameterText (int index)
  24801. {
  24802. return String (getParameter (index));
  24803. }
  24804. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  24805. {
  24806. AudioUnitParameterInfo info;
  24807. UInt32 sz = sizeof (info);
  24808. if (AudioUnitGetProperty (audioUnit,
  24809. kAudioUnitProperty_ParameterInfo,
  24810. kAudioUnitScope_Global,
  24811. parameterIds [index], &info, &sz) == noErr)
  24812. {
  24813. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  24814. }
  24815. return true;
  24816. }
  24817. int AudioUnitPluginInstance::getNumPrograms()
  24818. {
  24819. CFArrayRef presets;
  24820. UInt32 sz = sizeof (CFArrayRef);
  24821. int num = 0;
  24822. if (AudioUnitGetProperty (audioUnit,
  24823. kAudioUnitProperty_FactoryPresets,
  24824. kAudioUnitScope_Global,
  24825. 0, &presets, &sz) == noErr)
  24826. {
  24827. num = (int) CFArrayGetCount (presets);
  24828. CFRelease (presets);
  24829. }
  24830. return num;
  24831. }
  24832. int AudioUnitPluginInstance::getCurrentProgram()
  24833. {
  24834. AUPreset current;
  24835. current.presetNumber = 0;
  24836. UInt32 sz = sizeof (AUPreset);
  24837. AudioUnitGetProperty (audioUnit,
  24838. kAudioUnitProperty_FactoryPresets,
  24839. kAudioUnitScope_Global,
  24840. 0, &current, &sz);
  24841. return current.presetNumber;
  24842. }
  24843. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  24844. {
  24845. AUPreset current;
  24846. current.presetNumber = newIndex;
  24847. current.presetName = 0;
  24848. AudioUnitSetProperty (audioUnit,
  24849. kAudioUnitProperty_FactoryPresets,
  24850. kAudioUnitScope_Global,
  24851. 0, &current, sizeof (AUPreset));
  24852. }
  24853. const String AudioUnitPluginInstance::getProgramName (int index)
  24854. {
  24855. String s;
  24856. CFArrayRef presets;
  24857. UInt32 sz = sizeof (CFArrayRef);
  24858. if (AudioUnitGetProperty (audioUnit,
  24859. kAudioUnitProperty_FactoryPresets,
  24860. kAudioUnitScope_Global,
  24861. 0, &presets, &sz) == noErr)
  24862. {
  24863. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  24864. {
  24865. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  24866. if (p != 0 && p->presetNumber == index)
  24867. {
  24868. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  24869. break;
  24870. }
  24871. }
  24872. CFRelease (presets);
  24873. }
  24874. return s;
  24875. }
  24876. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  24877. {
  24878. jassertfalse // xxx not implemented!
  24879. }
  24880. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  24881. {
  24882. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  24883. return "Input " + String (index + 1);
  24884. return String::empty;
  24885. }
  24886. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  24887. {
  24888. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  24889. return false;
  24890. return true;
  24891. }
  24892. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  24893. {
  24894. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  24895. return "Output " + String (index + 1);
  24896. return String::empty;
  24897. }
  24898. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  24899. {
  24900. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  24901. return false;
  24902. return true;
  24903. }
  24904. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  24905. {
  24906. getCurrentProgramStateInformation (destData);
  24907. }
  24908. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  24909. {
  24910. CFPropertyListRef propertyList = 0;
  24911. UInt32 sz = sizeof (CFPropertyListRef);
  24912. if (AudioUnitGetProperty (audioUnit,
  24913. kAudioUnitProperty_ClassInfo,
  24914. kAudioUnitScope_Global,
  24915. 0, &propertyList, &sz) == noErr)
  24916. {
  24917. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  24918. CFWriteStreamOpen (stream);
  24919. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  24920. CFWriteStreamClose (stream);
  24921. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  24922. destData.setSize (bytesWritten);
  24923. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  24924. CFRelease (data);
  24925. CFRelease (stream);
  24926. CFRelease (propertyList);
  24927. }
  24928. }
  24929. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  24930. {
  24931. setCurrentProgramStateInformation (data, sizeInBytes);
  24932. }
  24933. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  24934. {
  24935. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  24936. (const UInt8*) data,
  24937. sizeInBytes,
  24938. kCFAllocatorNull);
  24939. CFReadStreamOpen (stream);
  24940. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  24941. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  24942. stream,
  24943. 0,
  24944. kCFPropertyListImmutable,
  24945. &format,
  24946. 0);
  24947. CFRelease (stream);
  24948. if (propertyList != 0)
  24949. AudioUnitSetProperty (audioUnit,
  24950. kAudioUnitProperty_ClassInfo,
  24951. kAudioUnitScope_Global,
  24952. 0, &propertyList, sizeof (propertyList));
  24953. }
  24954. AudioUnitPluginFormat::AudioUnitPluginFormat()
  24955. {
  24956. }
  24957. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  24958. {
  24959. }
  24960. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  24961. const String& fileOrIdentifier)
  24962. {
  24963. if (! fileMightContainThisPluginType (fileOrIdentifier))
  24964. return;
  24965. PluginDescription desc;
  24966. desc.fileOrIdentifier = fileOrIdentifier;
  24967. desc.uid = 0;
  24968. try
  24969. {
  24970. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  24971. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  24972. if (auInstance != 0)
  24973. {
  24974. auInstance->fillInPluginDescription (desc);
  24975. results.add (new PluginDescription (desc));
  24976. }
  24977. }
  24978. catch (...)
  24979. {
  24980. // crashed while loading...
  24981. }
  24982. }
  24983. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  24984. {
  24985. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  24986. {
  24987. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  24988. if (result->audioUnit != 0)
  24989. {
  24990. result->initialise();
  24991. return result.release();
  24992. }
  24993. }
  24994. return 0;
  24995. }
  24996. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  24997. const bool /*recursive*/)
  24998. {
  24999. StringArray result;
  25000. ComponentRecord* comp = 0;
  25001. ComponentDescription desc;
  25002. zerostruct (desc);
  25003. for (;;)
  25004. {
  25005. zerostruct (desc);
  25006. comp = FindNextComponent (comp, &desc);
  25007. if (comp == 0)
  25008. break;
  25009. GetComponentInfo (comp, &desc, 0, 0, 0);
  25010. if (desc.componentType == kAudioUnitType_MusicDevice
  25011. || desc.componentType == kAudioUnitType_MusicEffect
  25012. || desc.componentType == kAudioUnitType_Effect
  25013. || desc.componentType == kAudioUnitType_Generator
  25014. || desc.componentType == kAudioUnitType_Panner)
  25015. {
  25016. const String s (createAUPluginIdentifier (desc));
  25017. DBG (s);
  25018. result.add (s);
  25019. }
  25020. }
  25021. return result;
  25022. }
  25023. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25024. {
  25025. ComponentDescription desc;
  25026. String name, version, manufacturer;
  25027. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25028. return FindNextComponent (0, &desc) != 0;
  25029. const File f (fileOrIdentifier);
  25030. return f.hasFileExtension (".component")
  25031. && f.isDirectory();
  25032. }
  25033. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25034. {
  25035. ComponentDescription desc;
  25036. String name, version, manufacturer;
  25037. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25038. if (name.isEmpty())
  25039. name = fileOrIdentifier;
  25040. return name;
  25041. }
  25042. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25043. {
  25044. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25045. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25046. else
  25047. return File (desc.fileOrIdentifier).exists();
  25048. }
  25049. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25050. {
  25051. return FileSearchPath ("/(Default AudioUnit locations)");
  25052. }
  25053. #endif
  25054. END_JUCE_NAMESPACE
  25055. #undef log
  25056. #endif
  25057. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25058. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25059. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25060. #define JUCE_MAC_VST_INCLUDED 1
  25061. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25062. #if JUCE_PLUGINHOST_VST
  25063. #if JUCE_WINDOWS
  25064. #undef _WIN32_WINNT
  25065. #define _WIN32_WINNT 0x500
  25066. #undef STRICT
  25067. #define STRICT
  25068. #include <windows.h>
  25069. #include <float.h>
  25070. #pragma warning (disable : 4312 4355)
  25071. #elif JUCE_LINUX
  25072. #include <float.h>
  25073. #include <sys/time.h>
  25074. #include <X11/Xlib.h>
  25075. #include <X11/Xutil.h>
  25076. #include <X11/Xatom.h>
  25077. #undef Font
  25078. #undef KeyPress
  25079. #undef Drawable
  25080. #undef Time
  25081. #else
  25082. #ifndef JUCE_MAC_VST_INCLUDED
  25083. // On the mac, this file needs to be compiled indirectly, by using
  25084. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25085. #error
  25086. #endif
  25087. #include <Cocoa/Cocoa.h>
  25088. #include <Carbon/Carbon.h>
  25089. #endif
  25090. #if ! (JUCE_MAC && JUCE_64BIT)
  25091. BEGIN_JUCE_NAMESPACE
  25092. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25093. #endif
  25094. #undef PRAGMA_ALIGN_SUPPORTED
  25095. #define VST_FORCE_DEPRECATED 0
  25096. #ifdef _MSC_VER
  25097. #pragma warning (push)
  25098. #pragma warning (disable: 4996)
  25099. #endif
  25100. #include "pluginterfaces/vst2.x/aeffectx.h"
  25101. #ifdef _MSC_VER
  25102. #pragma warning (pop)
  25103. #endif
  25104. #if JUCE_LINUX
  25105. #define Font JUCE_NAMESPACE::Font
  25106. #define KeyPress JUCE_NAMESPACE::KeyPress
  25107. #define Drawable JUCE_NAMESPACE::Drawable
  25108. #define Time JUCE_NAMESPACE::Time
  25109. #endif
  25110. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25111. #ifdef __aeffect__
  25112. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25113. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25114. class VSTMidiEventList
  25115. {
  25116. public:
  25117. VSTMidiEventList()
  25118. : numEventsUsed (0), numEventsAllocated (0)
  25119. {
  25120. }
  25121. ~VSTMidiEventList()
  25122. {
  25123. freeEvents();
  25124. }
  25125. void clear()
  25126. {
  25127. numEventsUsed = 0;
  25128. if (events != 0)
  25129. events->numEvents = 0;
  25130. }
  25131. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25132. {
  25133. ensureSize (numEventsUsed + 1);
  25134. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25135. events->numEvents = ++numEventsUsed;
  25136. if (numBytes <= 4)
  25137. {
  25138. if (e->type == kVstSysExType)
  25139. {
  25140. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25141. e->type = kVstMidiType;
  25142. e->byteSize = sizeof (VstMidiEvent);
  25143. e->noteLength = 0;
  25144. e->noteOffset = 0;
  25145. e->detune = 0;
  25146. e->noteOffVelocity = 0;
  25147. }
  25148. e->deltaFrames = frameOffset;
  25149. memcpy (e->midiData, midiData, numBytes);
  25150. }
  25151. else
  25152. {
  25153. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25154. if (se->type == kVstSysExType)
  25155. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25156. else
  25157. se->sysexDump = (char*) juce_malloc (numBytes);
  25158. memcpy (se->sysexDump, midiData, numBytes);
  25159. se->type = kVstSysExType;
  25160. se->byteSize = sizeof (VstMidiSysexEvent);
  25161. se->deltaFrames = frameOffset;
  25162. se->flags = 0;
  25163. se->dumpBytes = numBytes;
  25164. se->resvd1 = 0;
  25165. se->resvd2 = 0;
  25166. }
  25167. }
  25168. // Handy method to pull the events out of an event buffer supplied by the host
  25169. // or plugin.
  25170. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25171. {
  25172. for (int i = 0; i < events->numEvents; ++i)
  25173. {
  25174. const VstEvent* const e = events->events[i];
  25175. if (e != 0)
  25176. {
  25177. if (e->type == kVstMidiType)
  25178. {
  25179. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25180. 4, e->deltaFrames);
  25181. }
  25182. else if (e->type == kVstSysExType)
  25183. {
  25184. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25185. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25186. e->deltaFrames);
  25187. }
  25188. }
  25189. }
  25190. }
  25191. void ensureSize (int numEventsNeeded)
  25192. {
  25193. if (numEventsNeeded > numEventsAllocated)
  25194. {
  25195. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25196. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25197. if (events == 0)
  25198. events.calloc (size, 1);
  25199. else
  25200. events.realloc (size, 1);
  25201. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25202. {
  25203. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25204. (int) sizeof (VstMidiSysexEvent)));
  25205. e->type = kVstMidiType;
  25206. e->byteSize = sizeof (VstMidiEvent);
  25207. events->events[i] = (VstEvent*) e;
  25208. }
  25209. numEventsAllocated = numEventsNeeded;
  25210. }
  25211. }
  25212. void freeEvents()
  25213. {
  25214. if (events != 0)
  25215. {
  25216. for (int i = numEventsAllocated; --i >= 0;)
  25217. {
  25218. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25219. if (e->type == kVstSysExType)
  25220. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25221. juce_free (e);
  25222. }
  25223. events.free();
  25224. numEventsUsed = 0;
  25225. numEventsAllocated = 0;
  25226. }
  25227. }
  25228. HeapBlock <VstEvents> events;
  25229. private:
  25230. int numEventsUsed, numEventsAllocated;
  25231. };
  25232. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25233. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25234. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25235. #if ! JUCE_WIN32
  25236. static void _fpreset() {}
  25237. static void _clearfp() {}
  25238. #endif
  25239. extern void juce_callAnyTimersSynchronously();
  25240. const int fxbVersionNum = 1;
  25241. struct fxProgram
  25242. {
  25243. long chunkMagic; // 'CcnK'
  25244. long byteSize; // of this chunk, excl. magic + byteSize
  25245. long fxMagic; // 'FxCk'
  25246. long version;
  25247. long fxID; // fx unique id
  25248. long fxVersion;
  25249. long numParams;
  25250. char prgName[28];
  25251. float params[1]; // variable no. of parameters
  25252. };
  25253. struct fxSet
  25254. {
  25255. long chunkMagic; // 'CcnK'
  25256. long byteSize; // of this chunk, excl. magic + byteSize
  25257. long fxMagic; // 'FxBk'
  25258. long version;
  25259. long fxID; // fx unique id
  25260. long fxVersion;
  25261. long numPrograms;
  25262. char future[128];
  25263. fxProgram programs[1]; // variable no. of programs
  25264. };
  25265. struct fxChunkSet
  25266. {
  25267. long chunkMagic; // 'CcnK'
  25268. long byteSize; // of this chunk, excl. magic + byteSize
  25269. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25270. long version;
  25271. long fxID; // fx unique id
  25272. long fxVersion;
  25273. long numPrograms;
  25274. char future[128];
  25275. long chunkSize;
  25276. char chunk[8]; // variable
  25277. };
  25278. struct fxProgramSet
  25279. {
  25280. long chunkMagic; // 'CcnK'
  25281. long byteSize; // of this chunk, excl. magic + byteSize
  25282. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25283. long version;
  25284. long fxID; // fx unique id
  25285. long fxVersion;
  25286. long numPrograms;
  25287. char name[28];
  25288. long chunkSize;
  25289. char chunk[8]; // variable
  25290. };
  25291. static long vst_swap (const long x) throw()
  25292. {
  25293. #ifdef JUCE_LITTLE_ENDIAN
  25294. return (long) ByteOrder::swap ((uint32) x);
  25295. #else
  25296. return x;
  25297. #endif
  25298. }
  25299. static float vst_swapFloat (const float x) throw()
  25300. {
  25301. #ifdef JUCE_LITTLE_ENDIAN
  25302. union { uint32 asInt; float asFloat; } n;
  25303. n.asFloat = x;
  25304. n.asInt = ByteOrder::swap (n.asInt);
  25305. return n.asFloat;
  25306. #else
  25307. return x;
  25308. #endif
  25309. }
  25310. typedef AEffect* (*MainCall) (audioMasterCallback);
  25311. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25312. static int shellUIDToCreate = 0;
  25313. static int insideVSTCallback = 0;
  25314. class VSTPluginWindow;
  25315. // Change this to disable logging of various VST activities
  25316. #ifndef VST_LOGGING
  25317. #define VST_LOGGING 1
  25318. #endif
  25319. #if VST_LOGGING
  25320. #define log(a) Logger::writeToLog(a);
  25321. #else
  25322. #define log(a)
  25323. #endif
  25324. #if JUCE_MAC && JUCE_PPC
  25325. static void* NewCFMFromMachO (void* const machofp) throw()
  25326. {
  25327. void* result = juce_malloc (8);
  25328. ((void**) result)[0] = machofp;
  25329. ((void**) result)[1] = result;
  25330. return result;
  25331. }
  25332. #endif
  25333. #if JUCE_LINUX
  25334. extern Display* display;
  25335. extern XContext improbableNumber;
  25336. typedef void (*EventProcPtr) (XEvent* ev);
  25337. static bool xErrorTriggered;
  25338. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25339. {
  25340. xErrorTriggered = true;
  25341. return 0;
  25342. }
  25343. static int getPropertyFromXWindow (Window handle, Atom atom)
  25344. {
  25345. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25346. xErrorTriggered = false;
  25347. int userSize;
  25348. unsigned long bytes, userCount;
  25349. unsigned char* data;
  25350. Atom userType;
  25351. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25352. &userType, &userSize, &userCount, &bytes, &data);
  25353. XSetErrorHandler (oldErrorHandler);
  25354. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25355. : 0;
  25356. }
  25357. static Window getChildWindow (Window windowToCheck)
  25358. {
  25359. Window rootWindow, parentWindow;
  25360. Window* childWindows;
  25361. unsigned int numChildren;
  25362. XQueryTree (display,
  25363. windowToCheck,
  25364. &rootWindow,
  25365. &parentWindow,
  25366. &childWindows,
  25367. &numChildren);
  25368. if (numChildren > 0)
  25369. return childWindows [0];
  25370. return 0;
  25371. }
  25372. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25373. {
  25374. if (e.mods.isLeftButtonDown())
  25375. {
  25376. ev.xbutton.button = Button1;
  25377. ev.xbutton.state |= Button1Mask;
  25378. }
  25379. else if (e.mods.isRightButtonDown())
  25380. {
  25381. ev.xbutton.button = Button3;
  25382. ev.xbutton.state |= Button3Mask;
  25383. }
  25384. else if (e.mods.isMiddleButtonDown())
  25385. {
  25386. ev.xbutton.button = Button2;
  25387. ev.xbutton.state |= Button2Mask;
  25388. }
  25389. }
  25390. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25391. {
  25392. if (e.mods.isLeftButtonDown())
  25393. ev.xmotion.state |= Button1Mask;
  25394. else if (e.mods.isRightButtonDown())
  25395. ev.xmotion.state |= Button3Mask;
  25396. else if (e.mods.isMiddleButtonDown())
  25397. ev.xmotion.state |= Button2Mask;
  25398. }
  25399. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25400. {
  25401. if (e.mods.isLeftButtonDown())
  25402. ev.xcrossing.state |= Button1Mask;
  25403. else if (e.mods.isRightButtonDown())
  25404. ev.xcrossing.state |= Button3Mask;
  25405. else if (e.mods.isMiddleButtonDown())
  25406. ev.xcrossing.state |= Button2Mask;
  25407. }
  25408. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25409. {
  25410. if (increment < 0)
  25411. {
  25412. ev.xbutton.button = Button5;
  25413. ev.xbutton.state |= Button5Mask;
  25414. }
  25415. else if (increment > 0)
  25416. {
  25417. ev.xbutton.button = Button4;
  25418. ev.xbutton.state |= Button4Mask;
  25419. }
  25420. }
  25421. #endif
  25422. static VoidArray activeModules;
  25423. class ModuleHandle : public ReferenceCountedObject
  25424. {
  25425. public:
  25426. File file;
  25427. MainCall moduleMain;
  25428. String pluginName;
  25429. static ModuleHandle* findOrCreateModule (const File& file)
  25430. {
  25431. for (int i = activeModules.size(); --i >= 0;)
  25432. {
  25433. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25434. if (module->file == file)
  25435. return module;
  25436. }
  25437. _fpreset(); // (doesn't do any harm)
  25438. ++insideVSTCallback;
  25439. shellUIDToCreate = 0;
  25440. log ("Attempting to load VST: " + file.getFullPathName());
  25441. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25442. if (! m->open())
  25443. m = 0;
  25444. --insideVSTCallback;
  25445. _fpreset(); // (doesn't do any harm)
  25446. return m.release();
  25447. }
  25448. ModuleHandle (const File& file_)
  25449. : file (file_),
  25450. moduleMain (0),
  25451. #if JUCE_WIN32 || JUCE_LINUX
  25452. hModule (0)
  25453. #elif JUCE_MAC
  25454. fragId (0),
  25455. resHandle (0),
  25456. bundleRef (0),
  25457. resFileId (0)
  25458. #endif
  25459. {
  25460. activeModules.add (this);
  25461. #if JUCE_WIN32 || JUCE_LINUX
  25462. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25463. #elif JUCE_MAC
  25464. FSRef ref;
  25465. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25466. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25467. #endif
  25468. }
  25469. ~ModuleHandle()
  25470. {
  25471. activeModules.removeValue (this);
  25472. close();
  25473. }
  25474. juce_UseDebuggingNewOperator
  25475. #if JUCE_WIN32 || JUCE_LINUX
  25476. void* hModule;
  25477. String fullParentDirectoryPathName;
  25478. bool open()
  25479. {
  25480. #if JUCE_WIN32
  25481. static bool timePeriodSet = false;
  25482. if (! timePeriodSet)
  25483. {
  25484. timePeriodSet = true;
  25485. timeBeginPeriod (2);
  25486. }
  25487. #endif
  25488. pluginName = file.getFileNameWithoutExtension();
  25489. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25490. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25491. if (moduleMain == 0)
  25492. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25493. return moduleMain != 0;
  25494. }
  25495. void close()
  25496. {
  25497. _fpreset(); // (doesn't do any harm)
  25498. PlatformUtilities::freeDynamicLibrary (hModule);
  25499. }
  25500. void closeEffect (AEffect* eff)
  25501. {
  25502. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25503. }
  25504. #else
  25505. CFragConnectionID fragId;
  25506. Handle resHandle;
  25507. CFBundleRef bundleRef;
  25508. FSSpec parentDirFSSpec;
  25509. short resFileId;
  25510. bool open()
  25511. {
  25512. bool ok = false;
  25513. const String filename (file.getFullPathName());
  25514. if (file.hasFileExtension (".vst"))
  25515. {
  25516. const char* const utf8 = filename.toUTF8();
  25517. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25518. strlen (utf8), file.isDirectory());
  25519. if (url != 0)
  25520. {
  25521. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25522. CFRelease (url);
  25523. if (bundleRef != 0)
  25524. {
  25525. if (CFBundleLoadExecutable (bundleRef))
  25526. {
  25527. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25528. if (moduleMain == 0)
  25529. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25530. if (moduleMain != 0)
  25531. {
  25532. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25533. if (name != 0)
  25534. {
  25535. if (CFGetTypeID (name) == CFStringGetTypeID())
  25536. {
  25537. char buffer[1024];
  25538. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25539. pluginName = buffer;
  25540. }
  25541. }
  25542. if (pluginName.isEmpty())
  25543. pluginName = file.getFileNameWithoutExtension();
  25544. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25545. ok = true;
  25546. }
  25547. }
  25548. if (! ok)
  25549. {
  25550. CFBundleUnloadExecutable (bundleRef);
  25551. CFRelease (bundleRef);
  25552. bundleRef = 0;
  25553. }
  25554. }
  25555. }
  25556. }
  25557. #if JUCE_PPC
  25558. else
  25559. {
  25560. FSRef fn;
  25561. if (FSPathMakeRef ((UInt8*) filename.toUTF8(), &fn, 0) == noErr)
  25562. {
  25563. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25564. if (resFileId != -1)
  25565. {
  25566. const int numEffs = Count1Resources ('aEff');
  25567. for (int i = 0; i < numEffs; ++i)
  25568. {
  25569. resHandle = Get1IndResource ('aEff', i + 1);
  25570. if (resHandle != 0)
  25571. {
  25572. OSType type;
  25573. Str255 name;
  25574. SInt16 id;
  25575. GetResInfo (resHandle, &id, &type, name);
  25576. pluginName = String ((const char*) name + 1, name[0]);
  25577. DetachResource (resHandle);
  25578. HLock (resHandle);
  25579. Ptr ptr;
  25580. Str255 errorText;
  25581. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25582. name, kPrivateCFragCopy,
  25583. &fragId, &ptr, errorText);
  25584. if (err == noErr)
  25585. {
  25586. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25587. ok = true;
  25588. }
  25589. else
  25590. {
  25591. HUnlock (resHandle);
  25592. }
  25593. break;
  25594. }
  25595. }
  25596. if (! ok)
  25597. CloseResFile (resFileId);
  25598. }
  25599. }
  25600. }
  25601. #endif
  25602. return ok;
  25603. }
  25604. void close()
  25605. {
  25606. #if JUCE_PPC
  25607. if (fragId != 0)
  25608. {
  25609. if (moduleMain != 0)
  25610. disposeMachOFromCFM ((void*) moduleMain);
  25611. CloseConnection (&fragId);
  25612. HUnlock (resHandle);
  25613. if (resFileId != 0)
  25614. CloseResFile (resFileId);
  25615. }
  25616. else
  25617. #endif
  25618. if (bundleRef != 0)
  25619. {
  25620. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25621. if (CFGetRetainCount (bundleRef) == 1)
  25622. CFBundleUnloadExecutable (bundleRef);
  25623. if (CFGetRetainCount (bundleRef) > 0)
  25624. CFRelease (bundleRef);
  25625. }
  25626. }
  25627. void closeEffect (AEffect* eff)
  25628. {
  25629. #if JUCE_PPC
  25630. if (fragId != 0)
  25631. {
  25632. VoidArray thingsToDelete;
  25633. thingsToDelete.add ((void*) eff->dispatcher);
  25634. thingsToDelete.add ((void*) eff->process);
  25635. thingsToDelete.add ((void*) eff->setParameter);
  25636. thingsToDelete.add ((void*) eff->getParameter);
  25637. thingsToDelete.add ((void*) eff->processReplacing);
  25638. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25639. for (int i = thingsToDelete.size(); --i >= 0;)
  25640. disposeMachOFromCFM (thingsToDelete[i]);
  25641. }
  25642. else
  25643. #endif
  25644. {
  25645. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25646. }
  25647. }
  25648. #if JUCE_PPC
  25649. static void* newMachOFromCFM (void* cfmfp)
  25650. {
  25651. if (cfmfp == 0)
  25652. return 0;
  25653. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25654. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25655. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25656. mfp[2] = 0x800c0000;
  25657. mfp[3] = 0x804c0004;
  25658. mfp[4] = 0x7c0903a6;
  25659. mfp[5] = 0x4e800420;
  25660. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25661. return mfp;
  25662. }
  25663. static void disposeMachOFromCFM (void* ptr)
  25664. {
  25665. juce_free (ptr);
  25666. }
  25667. void coerceAEffectFunctionCalls (AEffect* eff)
  25668. {
  25669. if (fragId != 0)
  25670. {
  25671. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25672. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25673. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25674. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25675. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25676. }
  25677. }
  25678. #endif
  25679. #endif
  25680. };
  25681. class VSTPluginInstance : public AudioPluginInstance,
  25682. private Timer,
  25683. private AsyncUpdater
  25684. {
  25685. public:
  25686. ~VSTPluginInstance();
  25687. // AudioPluginInstance methods:
  25688. void fillInPluginDescription (PluginDescription& desc) const
  25689. {
  25690. desc.name = name;
  25691. desc.fileOrIdentifier = module->file.getFullPathName();
  25692. desc.uid = getUID();
  25693. desc.lastFileModTime = module->file.getLastModificationTime();
  25694. desc.pluginFormatName = "VST";
  25695. desc.category = getCategory();
  25696. {
  25697. char buffer [kVstMaxVendorStrLen + 8];
  25698. zerostruct (buffer);
  25699. dispatch (effGetVendorString, 0, 0, buffer, 0);
  25700. desc.manufacturerName = buffer;
  25701. }
  25702. desc.version = getVersion();
  25703. desc.numInputChannels = getNumInputChannels();
  25704. desc.numOutputChannels = getNumOutputChannels();
  25705. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  25706. }
  25707. const String getName() const { return name; }
  25708. int getUID() const throw();
  25709. bool acceptsMidi() const { return wantsMidiMessages; }
  25710. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  25711. // AudioProcessor methods:
  25712. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  25713. void releaseResources();
  25714. void processBlock (AudioSampleBuffer& buffer,
  25715. MidiBuffer& midiMessages);
  25716. AudioProcessorEditor* createEditor();
  25717. const String getInputChannelName (const int index) const;
  25718. bool isInputChannelStereoPair (int index) const;
  25719. const String getOutputChannelName (const int index) const;
  25720. bool isOutputChannelStereoPair (int index) const;
  25721. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  25722. float getParameter (int index);
  25723. void setParameter (int index, float newValue);
  25724. const String getParameterName (int index);
  25725. const String getParameterText (int index);
  25726. bool isParameterAutomatable (int index) const;
  25727. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  25728. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  25729. void setCurrentProgram (int index);
  25730. const String getProgramName (int index);
  25731. void changeProgramName (int index, const String& newName);
  25732. void getStateInformation (MemoryBlock& destData);
  25733. void getCurrentProgramStateInformation (MemoryBlock& destData);
  25734. void setStateInformation (const void* data, int sizeInBytes);
  25735. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  25736. void timerCallback();
  25737. void handleAsyncUpdate();
  25738. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  25739. juce_UseDebuggingNewOperator
  25740. private:
  25741. friend class VSTPluginWindow;
  25742. friend class VSTPluginFormat;
  25743. AEffect* effect;
  25744. String name;
  25745. CriticalSection lock;
  25746. bool wantsMidiMessages, initialised, isPowerOn;
  25747. mutable StringArray programNames;
  25748. AudioSampleBuffer tempBuffer;
  25749. CriticalSection midiInLock;
  25750. MidiBuffer incomingMidi;
  25751. VSTMidiEventList midiEventsToSend;
  25752. VstTimeInfo vstHostTime;
  25753. HeapBlock <float*> channels;
  25754. ReferenceCountedObjectPtr <ModuleHandle> module;
  25755. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  25756. bool restoreProgramSettings (const fxProgram* const prog);
  25757. const String getCurrentProgramName();
  25758. void setParamsInProgramBlock (fxProgram* const prog) throw();
  25759. void updateStoredProgramNames();
  25760. void initialise();
  25761. void handleMidiFromPlugin (const VstEvents* const events);
  25762. void createTempParameterStore (MemoryBlock& dest);
  25763. void restoreFromTempParameterStore (const MemoryBlock& mb);
  25764. const String getParameterLabel (int index) const;
  25765. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  25766. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  25767. void setChunkData (const char* data, int size, bool isPreset);
  25768. bool loadFromFXBFile (const void* data, int numBytes);
  25769. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  25770. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  25771. const String getVersion() const throw();
  25772. const String getCategory() const throw();
  25773. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  25774. void setPower (const bool on);
  25775. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  25776. };
  25777. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  25778. : effect (0),
  25779. wantsMidiMessages (false),
  25780. initialised (false),
  25781. isPowerOn (false),
  25782. tempBuffer (1, 1),
  25783. module (module_)
  25784. {
  25785. try
  25786. {
  25787. _fpreset();
  25788. ++insideVSTCallback;
  25789. name = module->pluginName;
  25790. log ("Creating VST instance: " + name);
  25791. #if JUCE_MAC
  25792. if (module->resFileId != 0)
  25793. UseResFile (module->resFileId);
  25794. #if JUCE_PPC
  25795. if (module->fragId != 0)
  25796. {
  25797. static void* audioMasterCoerced = 0;
  25798. if (audioMasterCoerced == 0)
  25799. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  25800. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  25801. }
  25802. else
  25803. #endif
  25804. #endif
  25805. {
  25806. effect = module->moduleMain (&audioMaster);
  25807. }
  25808. --insideVSTCallback;
  25809. if (effect != 0 && effect->magic == kEffectMagic)
  25810. {
  25811. #if JUCE_PPC
  25812. module->coerceAEffectFunctionCalls (effect);
  25813. #endif
  25814. jassert (effect->resvd2 == 0);
  25815. jassert (effect->object != 0);
  25816. _fpreset(); // some dodgy plugs fuck around with this
  25817. }
  25818. else
  25819. {
  25820. effect = 0;
  25821. }
  25822. }
  25823. catch (...)
  25824. {
  25825. --insideVSTCallback;
  25826. }
  25827. }
  25828. VSTPluginInstance::~VSTPluginInstance()
  25829. {
  25830. {
  25831. const ScopedLock sl (lock);
  25832. jassert (insideVSTCallback == 0);
  25833. if (effect != 0 && effect->magic == kEffectMagic)
  25834. {
  25835. try
  25836. {
  25837. #if JUCE_MAC
  25838. if (module->resFileId != 0)
  25839. UseResFile (module->resFileId);
  25840. #endif
  25841. // Must delete any editors before deleting the plugin instance!
  25842. jassert (getActiveEditor() == 0);
  25843. _fpreset(); // some dodgy plugs fuck around with this
  25844. module->closeEffect (effect);
  25845. }
  25846. catch (...)
  25847. {}
  25848. }
  25849. module = 0;
  25850. effect = 0;
  25851. }
  25852. }
  25853. void VSTPluginInstance::initialise()
  25854. {
  25855. if (initialised || effect == 0)
  25856. return;
  25857. log ("Initialising VST: " + module->pluginName);
  25858. initialised = true;
  25859. dispatch (effIdentify, 0, 0, 0, 0);
  25860. // this code would ask the plugin for its name, but so few plugins
  25861. // actually bother implementing this correctly, that it's better to
  25862. // just ignore it and use the file name instead.
  25863. if (getSampleRate() > 0)
  25864. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  25865. if (getBlockSize() > 0)
  25866. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  25867. dispatch (effOpen, 0, 0, 0, 0);
  25868. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25869. getSampleRate(), getBlockSize());
  25870. if (getNumPrograms() > 1)
  25871. setCurrentProgram (0);
  25872. else
  25873. dispatch (effSetProgram, 0, 0, 0, 0);
  25874. int i;
  25875. for (i = effect->numInputs; --i >= 0;)
  25876. dispatch (effConnectInput, i, 1, 0, 0);
  25877. for (i = effect->numOutputs; --i >= 0;)
  25878. dispatch (effConnectOutput, i, 1, 0, 0);
  25879. updateStoredProgramNames();
  25880. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  25881. setLatencySamples (effect->initialDelay);
  25882. }
  25883. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  25884. int samplesPerBlockExpected)
  25885. {
  25886. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  25887. sampleRate_, samplesPerBlockExpected);
  25888. setLatencySamples (effect->initialDelay);
  25889. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  25890. vstHostTime.tempo = 120.0;
  25891. vstHostTime.timeSigNumerator = 4;
  25892. vstHostTime.timeSigDenominator = 4;
  25893. vstHostTime.sampleRate = sampleRate_;
  25894. vstHostTime.samplePos = 0;
  25895. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  25896. initialise();
  25897. if (initialised)
  25898. {
  25899. wantsMidiMessages = wantsMidiMessages
  25900. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  25901. if (wantsMidiMessages)
  25902. midiEventsToSend.ensureSize (256);
  25903. else
  25904. midiEventsToSend.freeEvents();
  25905. incomingMidi.clear();
  25906. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  25907. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  25908. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  25909. if (! isPowerOn)
  25910. setPower (true);
  25911. // dodgy hack to force some plugins to initialise the sample rate..
  25912. if ((! hasEditor()) && getNumParameters() > 0)
  25913. {
  25914. const float old = getParameter (0);
  25915. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  25916. setParameter (0, old);
  25917. }
  25918. dispatch (effStartProcess, 0, 0, 0, 0);
  25919. }
  25920. }
  25921. void VSTPluginInstance::releaseResources()
  25922. {
  25923. if (initialised)
  25924. {
  25925. dispatch (effStopProcess, 0, 0, 0, 0);
  25926. setPower (false);
  25927. }
  25928. tempBuffer.setSize (1, 1);
  25929. incomingMidi.clear();
  25930. midiEventsToSend.freeEvents();
  25931. channels.free();
  25932. }
  25933. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  25934. MidiBuffer& midiMessages)
  25935. {
  25936. const int numSamples = buffer.getNumSamples();
  25937. if (initialised)
  25938. {
  25939. AudioPlayHead* playHead = getPlayHead();
  25940. if (playHead != 0)
  25941. {
  25942. AudioPlayHead::CurrentPositionInfo position;
  25943. playHead->getCurrentPosition (position);
  25944. vstHostTime.tempo = position.bpm;
  25945. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  25946. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  25947. vstHostTime.ppqPos = position.ppqPosition;
  25948. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  25949. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  25950. if (position.isPlaying)
  25951. vstHostTime.flags |= kVstTransportPlaying;
  25952. else
  25953. vstHostTime.flags &= ~kVstTransportPlaying;
  25954. }
  25955. #if JUCE_WIN32
  25956. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  25957. #elif JUCE_LINUX
  25958. timeval micro;
  25959. gettimeofday (&micro, 0);
  25960. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  25961. #elif JUCE_MAC
  25962. UnsignedWide micro;
  25963. Microseconds (&micro);
  25964. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  25965. #endif
  25966. if (wantsMidiMessages)
  25967. {
  25968. midiEventsToSend.clear();
  25969. midiEventsToSend.ensureSize (1);
  25970. MidiBuffer::Iterator iter (midiMessages);
  25971. const uint8* midiData;
  25972. int numBytesOfMidiData, samplePosition;
  25973. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  25974. {
  25975. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  25976. jlimit (0, numSamples - 1, samplePosition));
  25977. }
  25978. try
  25979. {
  25980. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  25981. }
  25982. catch (...)
  25983. {}
  25984. }
  25985. int i;
  25986. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  25987. for (i = 0; i < maxChans; ++i)
  25988. channels[i] = buffer.getSampleData (i);
  25989. channels [maxChans] = 0;
  25990. _clearfp();
  25991. if ((effect->flags & effFlagsCanReplacing) != 0)
  25992. {
  25993. try
  25994. {
  25995. effect->processReplacing (effect, channels, channels, numSamples);
  25996. }
  25997. catch (...)
  25998. {}
  25999. }
  26000. else
  26001. {
  26002. tempBuffer.setSize (effect->numOutputs, numSamples);
  26003. tempBuffer.clear();
  26004. float* outs [64];
  26005. for (i = effect->numOutputs; --i >= 0;)
  26006. outs[i] = tempBuffer.getSampleData (i);
  26007. outs [effect->numOutputs] = 0;
  26008. try
  26009. {
  26010. effect->process (effect, channels, outs, numSamples);
  26011. }
  26012. catch (...)
  26013. {}
  26014. for (i = effect->numOutputs; --i >= 0;)
  26015. buffer.copyFrom (i, 0, outs[i], numSamples);
  26016. }
  26017. }
  26018. else
  26019. {
  26020. // Not initialised, so just bypass..
  26021. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26022. buffer.clear (i, 0, buffer.getNumSamples());
  26023. }
  26024. {
  26025. // copy any incoming midi..
  26026. const ScopedLock sl (midiInLock);
  26027. midiMessages = incomingMidi;
  26028. incomingMidi.clear();
  26029. }
  26030. }
  26031. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26032. {
  26033. if (events != 0)
  26034. {
  26035. const ScopedLock sl (midiInLock);
  26036. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26037. }
  26038. }
  26039. static Array <VSTPluginWindow*> activeVSTWindows;
  26040. class VSTPluginWindow : public AudioProcessorEditor,
  26041. #if ! JUCE_MAC
  26042. public ComponentMovementWatcher,
  26043. #endif
  26044. public Timer
  26045. {
  26046. public:
  26047. VSTPluginWindow (VSTPluginInstance& plugin_)
  26048. : AudioProcessorEditor (&plugin_),
  26049. #if ! JUCE_MAC
  26050. ComponentMovementWatcher (this),
  26051. #endif
  26052. plugin (plugin_),
  26053. isOpen (false),
  26054. wasShowing (false),
  26055. pluginRefusesToResize (false),
  26056. pluginWantsKeys (false),
  26057. alreadyInside (false),
  26058. recursiveResize (false)
  26059. {
  26060. #if JUCE_WIN32
  26061. sizeCheckCount = 0;
  26062. pluginHWND = 0;
  26063. #elif JUCE_LINUX
  26064. pluginWindow = None;
  26065. pluginProc = None;
  26066. #else
  26067. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26068. #endif
  26069. activeVSTWindows.add (this);
  26070. setSize (1, 1);
  26071. setOpaque (true);
  26072. setVisible (true);
  26073. }
  26074. ~VSTPluginWindow()
  26075. {
  26076. #if JUCE_MAC
  26077. innerWrapper = 0;
  26078. #else
  26079. closePluginWindow();
  26080. #endif
  26081. activeVSTWindows.removeValue (this);
  26082. plugin.editorBeingDeleted (this);
  26083. }
  26084. #if ! JUCE_MAC
  26085. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26086. {
  26087. if (recursiveResize)
  26088. return;
  26089. Component* const topComp = getTopLevelComponent();
  26090. if (topComp->getPeer() != 0)
  26091. {
  26092. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26093. recursiveResize = true;
  26094. #if JUCE_WIN32
  26095. if (pluginHWND != 0)
  26096. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26097. #elif JUCE_LINUX
  26098. if (pluginWindow != 0)
  26099. {
  26100. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26101. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26102. XMapRaised (display, pluginWindow);
  26103. }
  26104. #endif
  26105. recursiveResize = false;
  26106. }
  26107. }
  26108. void componentVisibilityChanged (Component&)
  26109. {
  26110. const bool isShowingNow = isShowing();
  26111. if (wasShowing != isShowingNow)
  26112. {
  26113. wasShowing = isShowingNow;
  26114. if (isShowingNow)
  26115. openPluginWindow();
  26116. else
  26117. closePluginWindow();
  26118. }
  26119. componentMovedOrResized (true, true);
  26120. }
  26121. void componentPeerChanged()
  26122. {
  26123. closePluginWindow();
  26124. openPluginWindow();
  26125. }
  26126. #endif
  26127. bool keyStateChanged (bool)
  26128. {
  26129. return pluginWantsKeys;
  26130. }
  26131. bool keyPressed (const KeyPress&)
  26132. {
  26133. return pluginWantsKeys;
  26134. }
  26135. #if JUCE_MAC
  26136. void paint (Graphics& g)
  26137. {
  26138. g.fillAll (Colours::black);
  26139. }
  26140. #else
  26141. void paint (Graphics& g)
  26142. {
  26143. if (isOpen)
  26144. {
  26145. ComponentPeer* const peer = getPeer();
  26146. if (peer != 0)
  26147. {
  26148. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26149. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26150. #if JUCE_LINUX
  26151. if (pluginWindow != 0)
  26152. {
  26153. const Rectangle<int> clip (g.getClipBounds());
  26154. XEvent ev;
  26155. zerostruct (ev);
  26156. ev.xexpose.type = Expose;
  26157. ev.xexpose.display = display;
  26158. ev.xexpose.window = pluginWindow;
  26159. ev.xexpose.x = clip.getX();
  26160. ev.xexpose.y = clip.getY();
  26161. ev.xexpose.width = clip.getWidth();
  26162. ev.xexpose.height = clip.getHeight();
  26163. sendEventToChild (&ev);
  26164. }
  26165. #endif
  26166. }
  26167. }
  26168. else
  26169. {
  26170. g.fillAll (Colours::black);
  26171. }
  26172. }
  26173. #endif
  26174. void timerCallback()
  26175. {
  26176. #if JUCE_WIN32
  26177. if (--sizeCheckCount <= 0)
  26178. {
  26179. sizeCheckCount = 10;
  26180. checkPluginWindowSize();
  26181. }
  26182. #endif
  26183. try
  26184. {
  26185. static bool reentrant = false;
  26186. if (! reentrant)
  26187. {
  26188. reentrant = true;
  26189. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26190. reentrant = false;
  26191. }
  26192. }
  26193. catch (...)
  26194. {}
  26195. }
  26196. void mouseDown (const MouseEvent& e)
  26197. {
  26198. #if JUCE_LINUX
  26199. if (pluginWindow == 0)
  26200. return;
  26201. toFront (true);
  26202. XEvent ev;
  26203. zerostruct (ev);
  26204. ev.xbutton.display = display;
  26205. ev.xbutton.type = ButtonPress;
  26206. ev.xbutton.window = pluginWindow;
  26207. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26208. ev.xbutton.time = CurrentTime;
  26209. ev.xbutton.x = e.x;
  26210. ev.xbutton.y = e.y;
  26211. ev.xbutton.x_root = e.getScreenX();
  26212. ev.xbutton.y_root = e.getScreenY();
  26213. translateJuceToXButtonModifiers (e, ev);
  26214. sendEventToChild (&ev);
  26215. #elif JUCE_WIN32
  26216. (void) e;
  26217. toFront (true);
  26218. #endif
  26219. }
  26220. void broughtToFront()
  26221. {
  26222. activeVSTWindows.removeValue (this);
  26223. activeVSTWindows.add (this);
  26224. #if JUCE_MAC
  26225. dispatch (effEditTop, 0, 0, 0, 0);
  26226. #endif
  26227. }
  26228. juce_UseDebuggingNewOperator
  26229. private:
  26230. VSTPluginInstance& plugin;
  26231. bool isOpen, wasShowing, recursiveResize;
  26232. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26233. #if JUCE_WIN32
  26234. HWND pluginHWND;
  26235. void* originalWndProc;
  26236. int sizeCheckCount;
  26237. #elif JUCE_LINUX
  26238. Window pluginWindow;
  26239. EventProcPtr pluginProc;
  26240. #endif
  26241. #if JUCE_MAC
  26242. void openPluginWindow (WindowRef parentWindow)
  26243. {
  26244. if (isOpen || parentWindow == 0)
  26245. return;
  26246. isOpen = true;
  26247. ERect* rect = 0;
  26248. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26249. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26250. // do this before and after like in the steinberg example
  26251. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26252. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26253. // Install keyboard hooks
  26254. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26255. // double-check it's not too tiny
  26256. int w = 250, h = 150;
  26257. if (rect != 0)
  26258. {
  26259. w = rect->right - rect->left;
  26260. h = rect->bottom - rect->top;
  26261. if (w == 0 || h == 0)
  26262. {
  26263. w = 250;
  26264. h = 150;
  26265. }
  26266. }
  26267. w = jmax (w, 32);
  26268. h = jmax (h, 32);
  26269. setSize (w, h);
  26270. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26271. repaint();
  26272. }
  26273. #else
  26274. void openPluginWindow()
  26275. {
  26276. if (isOpen || getWindowHandle() == 0)
  26277. return;
  26278. log ("Opening VST UI: " + plugin.name);
  26279. isOpen = true;
  26280. ERect* rect = 0;
  26281. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26282. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26283. // do this before and after like in the steinberg example
  26284. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26285. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26286. // Install keyboard hooks
  26287. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26288. #if JUCE_WIN32
  26289. originalWndProc = 0;
  26290. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26291. if (pluginHWND == 0)
  26292. {
  26293. isOpen = false;
  26294. setSize (300, 150);
  26295. return;
  26296. }
  26297. #pragma warning (push)
  26298. #pragma warning (disable: 4244)
  26299. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26300. if (! pluginWantsKeys)
  26301. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) vstHookWndProc);
  26302. #pragma warning (pop)
  26303. int w, h;
  26304. RECT r;
  26305. GetWindowRect (pluginHWND, &r);
  26306. w = r.right - r.left;
  26307. h = r.bottom - r.top;
  26308. if (rect != 0)
  26309. {
  26310. const int rw = rect->right - rect->left;
  26311. const int rh = rect->bottom - rect->top;
  26312. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26313. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26314. {
  26315. // very dodgy logic to decide which size is right.
  26316. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26317. {
  26318. SetWindowPos (pluginHWND, 0,
  26319. 0, 0, rw, rh,
  26320. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26321. GetWindowRect (pluginHWND, &r);
  26322. w = r.right - r.left;
  26323. h = r.bottom - r.top;
  26324. pluginRefusesToResize = (w != rw) || (h != rh);
  26325. w = rw;
  26326. h = rh;
  26327. }
  26328. }
  26329. }
  26330. #elif JUCE_LINUX
  26331. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26332. if (pluginWindow != 0)
  26333. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26334. XInternAtom (display, "_XEventProc", False));
  26335. int w = 250, h = 150;
  26336. if (rect != 0)
  26337. {
  26338. w = rect->right - rect->left;
  26339. h = rect->bottom - rect->top;
  26340. if (w == 0 || h == 0)
  26341. {
  26342. w = 250;
  26343. h = 150;
  26344. }
  26345. }
  26346. if (pluginWindow != 0)
  26347. XMapRaised (display, pluginWindow);
  26348. #endif
  26349. // double-check it's not too tiny
  26350. w = jmax (w, 32);
  26351. h = jmax (h, 32);
  26352. setSize (w, h);
  26353. #if JUCE_WIN32
  26354. checkPluginWindowSize();
  26355. #endif
  26356. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26357. repaint();
  26358. }
  26359. #endif
  26360. #if ! JUCE_MAC
  26361. void closePluginWindow()
  26362. {
  26363. if (isOpen)
  26364. {
  26365. log ("Closing VST UI: " + plugin.getName());
  26366. isOpen = false;
  26367. dispatch (effEditClose, 0, 0, 0, 0);
  26368. #if JUCE_WIN32
  26369. #pragma warning (push)
  26370. #pragma warning (disable: 4244)
  26371. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26372. SetWindowLongPtr (pluginHWND, GWLP_WNDPROC, (LONG_PTR) originalWndProc);
  26373. #pragma warning (pop)
  26374. stopTimer();
  26375. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26376. DestroyWindow (pluginHWND);
  26377. pluginHWND = 0;
  26378. #elif JUCE_LINUX
  26379. stopTimer();
  26380. pluginWindow = 0;
  26381. pluginProc = 0;
  26382. #endif
  26383. }
  26384. }
  26385. #endif
  26386. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26387. {
  26388. return plugin.dispatch (opcode, index, value, ptr, opt);
  26389. }
  26390. #if JUCE_WIN32
  26391. void checkPluginWindowSize() throw()
  26392. {
  26393. RECT r;
  26394. GetWindowRect (pluginHWND, &r);
  26395. const int w = r.right - r.left;
  26396. const int h = r.bottom - r.top;
  26397. if (isShowing() && w > 0 && h > 0
  26398. && (w != getWidth() || h != getHeight())
  26399. && ! pluginRefusesToResize)
  26400. {
  26401. setSize (w, h);
  26402. sizeCheckCount = 0;
  26403. }
  26404. }
  26405. // hooks to get keyboard events from VST windows..
  26406. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26407. {
  26408. for (int i = activeVSTWindows.size(); --i >= 0;)
  26409. {
  26410. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26411. if (w->pluginHWND == hW)
  26412. {
  26413. if (message == WM_CHAR
  26414. || message == WM_KEYDOWN
  26415. || message == WM_SYSKEYDOWN
  26416. || message == WM_KEYUP
  26417. || message == WM_SYSKEYUP
  26418. || message == WM_APPCOMMAND)
  26419. {
  26420. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26421. message, wParam, lParam);
  26422. }
  26423. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26424. (HWND) w->pluginHWND,
  26425. message,
  26426. wParam,
  26427. lParam);
  26428. }
  26429. }
  26430. return DefWindowProc (hW, message, wParam, lParam);
  26431. }
  26432. #endif
  26433. #if JUCE_LINUX
  26434. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26435. void sendEventToChild (XEvent* event)
  26436. {
  26437. if (pluginProc != 0)
  26438. {
  26439. // if the plugin publishes an event procedure, pass the event directly..
  26440. pluginProc (event);
  26441. }
  26442. else if (pluginWindow != 0)
  26443. {
  26444. // if the plugin has a window, then send the event to the window so that
  26445. // its message thread will pick it up..
  26446. XSendEvent (display, pluginWindow, False, 0L, event);
  26447. XFlush (display);
  26448. }
  26449. }
  26450. void mouseEnter (const MouseEvent& e)
  26451. {
  26452. if (pluginWindow != 0)
  26453. {
  26454. XEvent ev;
  26455. zerostruct (ev);
  26456. ev.xcrossing.display = display;
  26457. ev.xcrossing.type = EnterNotify;
  26458. ev.xcrossing.window = pluginWindow;
  26459. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26460. ev.xcrossing.time = CurrentTime;
  26461. ev.xcrossing.x = e.x;
  26462. ev.xcrossing.y = e.y;
  26463. ev.xcrossing.x_root = e.getScreenX();
  26464. ev.xcrossing.y_root = e.getScreenY();
  26465. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26466. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26467. translateJuceToXCrossingModifiers (e, ev);
  26468. sendEventToChild (&ev);
  26469. }
  26470. }
  26471. void mouseExit (const MouseEvent& e)
  26472. {
  26473. if (pluginWindow != 0)
  26474. {
  26475. XEvent ev;
  26476. zerostruct (ev);
  26477. ev.xcrossing.display = display;
  26478. ev.xcrossing.type = LeaveNotify;
  26479. ev.xcrossing.window = pluginWindow;
  26480. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26481. ev.xcrossing.time = CurrentTime;
  26482. ev.xcrossing.x = e.x;
  26483. ev.xcrossing.y = e.y;
  26484. ev.xcrossing.x_root = e.getScreenX();
  26485. ev.xcrossing.y_root = e.getScreenY();
  26486. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26487. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26488. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26489. translateJuceToXCrossingModifiers (e, ev);
  26490. sendEventToChild (&ev);
  26491. }
  26492. }
  26493. void mouseMove (const MouseEvent& e)
  26494. {
  26495. if (pluginWindow != 0)
  26496. {
  26497. XEvent ev;
  26498. zerostruct (ev);
  26499. ev.xmotion.display = display;
  26500. ev.xmotion.type = MotionNotify;
  26501. ev.xmotion.window = pluginWindow;
  26502. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26503. ev.xmotion.time = CurrentTime;
  26504. ev.xmotion.is_hint = NotifyNormal;
  26505. ev.xmotion.x = e.x;
  26506. ev.xmotion.y = e.y;
  26507. ev.xmotion.x_root = e.getScreenX();
  26508. ev.xmotion.y_root = e.getScreenY();
  26509. sendEventToChild (&ev);
  26510. }
  26511. }
  26512. void mouseDrag (const MouseEvent& e)
  26513. {
  26514. if (pluginWindow != 0)
  26515. {
  26516. XEvent ev;
  26517. zerostruct (ev);
  26518. ev.xmotion.display = display;
  26519. ev.xmotion.type = MotionNotify;
  26520. ev.xmotion.window = pluginWindow;
  26521. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26522. ev.xmotion.time = CurrentTime;
  26523. ev.xmotion.x = e.x ;
  26524. ev.xmotion.y = e.y;
  26525. ev.xmotion.x_root = e.getScreenX();
  26526. ev.xmotion.y_root = e.getScreenY();
  26527. ev.xmotion.is_hint = NotifyNormal;
  26528. translateJuceToXMotionModifiers (e, ev);
  26529. sendEventToChild (&ev);
  26530. }
  26531. }
  26532. void mouseUp (const MouseEvent& e)
  26533. {
  26534. if (pluginWindow != 0)
  26535. {
  26536. XEvent ev;
  26537. zerostruct (ev);
  26538. ev.xbutton.display = display;
  26539. ev.xbutton.type = ButtonRelease;
  26540. ev.xbutton.window = pluginWindow;
  26541. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26542. ev.xbutton.time = CurrentTime;
  26543. ev.xbutton.x = e.x;
  26544. ev.xbutton.y = e.y;
  26545. ev.xbutton.x_root = e.getScreenX();
  26546. ev.xbutton.y_root = e.getScreenY();
  26547. translateJuceToXButtonModifiers (e, ev);
  26548. sendEventToChild (&ev);
  26549. }
  26550. }
  26551. void mouseWheelMove (const MouseEvent& e,
  26552. float incrementX,
  26553. float incrementY)
  26554. {
  26555. if (pluginWindow != 0)
  26556. {
  26557. XEvent ev;
  26558. zerostruct (ev);
  26559. ev.xbutton.display = display;
  26560. ev.xbutton.type = ButtonPress;
  26561. ev.xbutton.window = pluginWindow;
  26562. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26563. ev.xbutton.time = CurrentTime;
  26564. ev.xbutton.x = e.x;
  26565. ev.xbutton.y = e.y;
  26566. ev.xbutton.x_root = e.getScreenX();
  26567. ev.xbutton.y_root = e.getScreenY();
  26568. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26569. sendEventToChild (&ev);
  26570. // TODO - put a usleep here ?
  26571. ev.xbutton.type = ButtonRelease;
  26572. sendEventToChild (&ev);
  26573. }
  26574. }
  26575. #endif
  26576. #if JUCE_MAC
  26577. #if ! JUCE_SUPPORT_CARBON
  26578. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26579. #endif
  26580. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26581. {
  26582. public:
  26583. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26584. : owner (owner_),
  26585. alreadyInside (false)
  26586. {
  26587. }
  26588. ~InnerWrapperComponent()
  26589. {
  26590. deleteWindow();
  26591. }
  26592. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26593. {
  26594. owner->openPluginWindow (windowRef);
  26595. return 0;
  26596. }
  26597. void removeView (HIViewRef)
  26598. {
  26599. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26600. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26601. }
  26602. bool getEmbeddedViewSize (int& w, int& h)
  26603. {
  26604. ERect* rect = 0;
  26605. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26606. w = rect->right - rect->left;
  26607. h = rect->bottom - rect->top;
  26608. return true;
  26609. }
  26610. void mouseDown (int x, int y)
  26611. {
  26612. if (! alreadyInside)
  26613. {
  26614. alreadyInside = true;
  26615. getTopLevelComponent()->toFront (true);
  26616. owner->dispatch (effEditMouse, x, y, 0, 0);
  26617. alreadyInside = false;
  26618. }
  26619. else
  26620. {
  26621. PostEvent (::mouseDown, 0);
  26622. }
  26623. }
  26624. void paint()
  26625. {
  26626. ComponentPeer* const peer = getPeer();
  26627. if (peer != 0)
  26628. {
  26629. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26630. ERect r;
  26631. r.left = pos.getX();
  26632. r.right = r.left + getWidth();
  26633. r.top = pos.getY();
  26634. r.bottom = r.top + getHeight();
  26635. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26636. }
  26637. }
  26638. private:
  26639. VSTPluginWindow* const owner;
  26640. bool alreadyInside;
  26641. };
  26642. friend class InnerWrapperComponent;
  26643. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26644. void resized()
  26645. {
  26646. innerWrapper->setSize (getWidth(), getHeight());
  26647. }
  26648. #endif
  26649. };
  26650. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26651. {
  26652. if (hasEditor())
  26653. return new VSTPluginWindow (*this);
  26654. return 0;
  26655. }
  26656. void VSTPluginInstance::handleAsyncUpdate()
  26657. {
  26658. // indicates that something about the plugin has changed..
  26659. updateHostDisplay();
  26660. }
  26661. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26662. {
  26663. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26664. {
  26665. changeProgramName (getCurrentProgram(), prog->prgName);
  26666. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26667. setParameter (i, vst_swapFloat (prog->params[i]));
  26668. return true;
  26669. }
  26670. return false;
  26671. }
  26672. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26673. const int dataSize)
  26674. {
  26675. if (dataSize < 28)
  26676. return false;
  26677. const fxSet* const set = (const fxSet*) data;
  26678. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26679. || vst_swap (set->version) > fxbVersionNum)
  26680. return false;
  26681. if (vst_swap (set->fxMagic) == 'FxBk')
  26682. {
  26683. // bank of programs
  26684. if (vst_swap (set->numPrograms) >= 0)
  26685. {
  26686. const int oldProg = getCurrentProgram();
  26687. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26688. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26689. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26690. {
  26691. if (i != oldProg)
  26692. {
  26693. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26694. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26695. return false;
  26696. if (vst_swap (set->numPrograms) > 0)
  26697. setCurrentProgram (i);
  26698. if (! restoreProgramSettings (prog))
  26699. return false;
  26700. }
  26701. }
  26702. if (vst_swap (set->numPrograms) > 0)
  26703. setCurrentProgram (oldProg);
  26704. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  26705. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26706. return false;
  26707. if (! restoreProgramSettings (prog))
  26708. return false;
  26709. }
  26710. }
  26711. else if (vst_swap (set->fxMagic) == 'FxCk')
  26712. {
  26713. // single program
  26714. const fxProgram* const prog = (const fxProgram*) data;
  26715. if (vst_swap (prog->chunkMagic) != 'CcnK')
  26716. return false;
  26717. changeProgramName (getCurrentProgram(), prog->prgName);
  26718. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26719. setParameter (i, vst_swapFloat (prog->params[i]));
  26720. }
  26721. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  26722. {
  26723. // non-preset chunk
  26724. const fxChunkSet* const cset = (const fxChunkSet*) data;
  26725. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  26726. return false;
  26727. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  26728. }
  26729. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  26730. {
  26731. // preset chunk
  26732. const fxProgramSet* const cset = (const fxProgramSet*) data;
  26733. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  26734. return false;
  26735. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  26736. changeProgramName (getCurrentProgram(), cset->name);
  26737. }
  26738. else
  26739. {
  26740. return false;
  26741. }
  26742. return true;
  26743. }
  26744. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  26745. {
  26746. const int numParams = getNumParameters();
  26747. prog->chunkMagic = vst_swap ('CcnK');
  26748. prog->byteSize = 0;
  26749. prog->fxMagic = vst_swap ('FxCk');
  26750. prog->version = vst_swap (fxbVersionNum);
  26751. prog->fxID = vst_swap (getUID());
  26752. prog->fxVersion = vst_swap (getVersionNumber());
  26753. prog->numParams = vst_swap (numParams);
  26754. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  26755. for (int i = 0; i < numParams; ++i)
  26756. prog->params[i] = vst_swapFloat (getParameter (i));
  26757. }
  26758. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  26759. {
  26760. const int numPrograms = getNumPrograms();
  26761. const int numParams = getNumParameters();
  26762. if (usesChunks())
  26763. {
  26764. if (isFXB)
  26765. {
  26766. MemoryBlock chunk;
  26767. getChunkData (chunk, false, maxSizeMB);
  26768. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  26769. dest.setSize (totalLen, true);
  26770. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  26771. set->chunkMagic = vst_swap ('CcnK');
  26772. set->byteSize = 0;
  26773. set->fxMagic = vst_swap ('FBCh');
  26774. set->version = vst_swap (fxbVersionNum);
  26775. set->fxID = vst_swap (getUID());
  26776. set->fxVersion = vst_swap (getVersionNumber());
  26777. set->numPrograms = vst_swap (numPrograms);
  26778. set->chunkSize = vst_swap ((long) chunk.getSize());
  26779. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26780. }
  26781. else
  26782. {
  26783. MemoryBlock chunk;
  26784. getChunkData (chunk, true, maxSizeMB);
  26785. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  26786. dest.setSize (totalLen, true);
  26787. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  26788. set->chunkMagic = vst_swap ('CcnK');
  26789. set->byteSize = 0;
  26790. set->fxMagic = vst_swap ('FPCh');
  26791. set->version = vst_swap (fxbVersionNum);
  26792. set->fxID = vst_swap (getUID());
  26793. set->fxVersion = vst_swap (getVersionNumber());
  26794. set->numPrograms = vst_swap (numPrograms);
  26795. set->chunkSize = vst_swap ((long) chunk.getSize());
  26796. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  26797. chunk.copyTo (set->chunk, 0, chunk.getSize());
  26798. }
  26799. }
  26800. else
  26801. {
  26802. if (isFXB)
  26803. {
  26804. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26805. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  26806. dest.setSize (len, true);
  26807. fxSet* const set = (fxSet*) dest.getData();
  26808. set->chunkMagic = vst_swap ('CcnK');
  26809. set->byteSize = 0;
  26810. set->fxMagic = vst_swap ('FxBk');
  26811. set->version = vst_swap (fxbVersionNum);
  26812. set->fxID = vst_swap (getUID());
  26813. set->fxVersion = vst_swap (getVersionNumber());
  26814. set->numPrograms = vst_swap (numPrograms);
  26815. const int oldProgram = getCurrentProgram();
  26816. MemoryBlock oldSettings;
  26817. createTempParameterStore (oldSettings);
  26818. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  26819. for (int i = 0; i < numPrograms; ++i)
  26820. {
  26821. if (i != oldProgram)
  26822. {
  26823. setCurrentProgram (i);
  26824. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  26825. }
  26826. }
  26827. setCurrentProgram (oldProgram);
  26828. restoreFromTempParameterStore (oldSettings);
  26829. }
  26830. else
  26831. {
  26832. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26833. dest.setSize (totalLen, true);
  26834. setParamsInProgramBlock ((fxProgram*) dest.getData());
  26835. }
  26836. }
  26837. return true;
  26838. }
  26839. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  26840. {
  26841. if (usesChunks())
  26842. {
  26843. void* data = 0;
  26844. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  26845. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  26846. {
  26847. mb.setSize (bytes);
  26848. mb.copyFrom (data, 0, bytes);
  26849. }
  26850. }
  26851. }
  26852. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  26853. {
  26854. if (size > 0 && usesChunks())
  26855. {
  26856. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  26857. if (! isPreset)
  26858. updateStoredProgramNames();
  26859. }
  26860. }
  26861. void VSTPluginInstance::timerCallback()
  26862. {
  26863. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  26864. stopTimer();
  26865. }
  26866. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  26867. {
  26868. const ScopedLock sl (lock);
  26869. ++insideVSTCallback;
  26870. int result = 0;
  26871. try
  26872. {
  26873. if (effect != 0)
  26874. {
  26875. #if JUCE_MAC
  26876. if (module->resFileId != 0)
  26877. UseResFile (module->resFileId);
  26878. CGrafPtr oldPort;
  26879. if (getActiveEditor() != 0)
  26880. {
  26881. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  26882. GetPort (&oldPort);
  26883. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  26884. SetOrigin (-pos.getX(), -pos.getY());
  26885. }
  26886. #endif
  26887. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  26888. #if JUCE_MAC
  26889. if (getActiveEditor() != 0)
  26890. SetPort (oldPort);
  26891. module->resFileId = CurResFile();
  26892. #endif
  26893. --insideVSTCallback;
  26894. return result;
  26895. }
  26896. }
  26897. catch (...)
  26898. {
  26899. }
  26900. --insideVSTCallback;
  26901. return result;
  26902. }
  26903. // handles non plugin-specific callbacks..
  26904. static const int defaultVSTSampleRateValue = 16384;
  26905. static const int defaultVSTBlockSizeValue = 512;
  26906. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26907. {
  26908. (void) index;
  26909. (void) value;
  26910. (void) opt;
  26911. switch (opcode)
  26912. {
  26913. case audioMasterCanDo:
  26914. {
  26915. static const char* canDos[] = { "supplyIdle",
  26916. "sendVstEvents",
  26917. "sendVstMidiEvent",
  26918. "sendVstTimeInfo",
  26919. "receiveVstEvents",
  26920. "receiveVstMidiEvent",
  26921. "supportShell",
  26922. "shellCategory" };
  26923. for (int i = 0; i < numElementsInArray (canDos); ++i)
  26924. if (strcmp (canDos[i], (const char*) ptr) == 0)
  26925. return 1;
  26926. return 0;
  26927. }
  26928. case audioMasterVersion:
  26929. return 0x2400;
  26930. case audioMasterCurrentId:
  26931. return shellUIDToCreate;
  26932. case audioMasterGetNumAutomatableParameters:
  26933. return 0;
  26934. case audioMasterGetAutomationState:
  26935. return 1;
  26936. case audioMasterGetVendorVersion:
  26937. return 0x0101;
  26938. case audioMasterGetVendorString:
  26939. case audioMasterGetProductString:
  26940. {
  26941. String hostName ("Juce VST Host");
  26942. if (JUCEApplication::getInstance() != 0)
  26943. hostName = JUCEApplication::getInstance()->getApplicationName();
  26944. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  26945. }
  26946. break;
  26947. case audioMasterGetSampleRate:
  26948. return (VstIntPtr) defaultVSTSampleRateValue;
  26949. case audioMasterGetBlockSize:
  26950. return (VstIntPtr) defaultVSTBlockSizeValue;
  26951. case audioMasterSetOutputSampleRate:
  26952. return 0;
  26953. default:
  26954. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  26955. break;
  26956. }
  26957. return 0;
  26958. }
  26959. // handles callbacks for a specific plugin
  26960. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  26961. {
  26962. switch (opcode)
  26963. {
  26964. case audioMasterAutomate:
  26965. sendParamChangeMessageToListeners (index, opt);
  26966. break;
  26967. case audioMasterProcessEvents:
  26968. handleMidiFromPlugin ((const VstEvents*) ptr);
  26969. break;
  26970. case audioMasterGetTime:
  26971. #ifdef _MSC_VER
  26972. #pragma warning (push)
  26973. #pragma warning (disable: 4311)
  26974. #endif
  26975. return (VstIntPtr) &vstHostTime;
  26976. #ifdef _MSC_VER
  26977. #pragma warning (pop)
  26978. #endif
  26979. break;
  26980. case audioMasterIdle:
  26981. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  26982. {
  26983. ++insideVSTCallback;
  26984. #if JUCE_MAC
  26985. if (getActiveEditor() != 0)
  26986. dispatch (effEditIdle, 0, 0, 0, 0);
  26987. #endif
  26988. juce_callAnyTimersSynchronously();
  26989. handleUpdateNowIfNeeded();
  26990. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  26991. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  26992. --insideVSTCallback;
  26993. }
  26994. break;
  26995. case audioMasterUpdateDisplay:
  26996. triggerAsyncUpdate();
  26997. break;
  26998. case audioMasterTempoAt:
  26999. // returns (10000 * bpm)
  27000. break;
  27001. case audioMasterNeedIdle:
  27002. startTimer (50);
  27003. break;
  27004. case audioMasterSizeWindow:
  27005. if (getActiveEditor() != 0)
  27006. getActiveEditor()->setSize (index, value);
  27007. return 1;
  27008. case audioMasterGetSampleRate:
  27009. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27010. case audioMasterGetBlockSize:
  27011. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27012. case audioMasterWantMidi:
  27013. wantsMidiMessages = true;
  27014. break;
  27015. case audioMasterGetDirectory:
  27016. #if JUCE_MAC
  27017. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27018. #else
  27019. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27020. #endif
  27021. case audioMasterGetAutomationState:
  27022. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27023. break;
  27024. // none of these are handled (yet)..
  27025. case audioMasterBeginEdit:
  27026. case audioMasterEndEdit:
  27027. case audioMasterSetTime:
  27028. case audioMasterPinConnected:
  27029. case audioMasterGetParameterQuantization:
  27030. case audioMasterIOChanged:
  27031. case audioMasterGetInputLatency:
  27032. case audioMasterGetOutputLatency:
  27033. case audioMasterGetPreviousPlug:
  27034. case audioMasterGetNextPlug:
  27035. case audioMasterWillReplaceOrAccumulate:
  27036. case audioMasterGetCurrentProcessLevel:
  27037. case audioMasterOfflineStart:
  27038. case audioMasterOfflineRead:
  27039. case audioMasterOfflineWrite:
  27040. case audioMasterOfflineGetCurrentPass:
  27041. case audioMasterOfflineGetCurrentMetaPass:
  27042. case audioMasterVendorSpecific:
  27043. case audioMasterSetIcon:
  27044. case audioMasterGetLanguage:
  27045. case audioMasterOpenWindow:
  27046. case audioMasterCloseWindow:
  27047. break;
  27048. default:
  27049. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27050. }
  27051. return 0;
  27052. }
  27053. // entry point for all callbacks from the plugin
  27054. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27055. {
  27056. try
  27057. {
  27058. if (effect != 0 && effect->resvd2 != 0)
  27059. {
  27060. return ((VSTPluginInstance*)(effect->resvd2))
  27061. ->handleCallback (opcode, index, value, ptr, opt);
  27062. }
  27063. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27064. }
  27065. catch (...)
  27066. {
  27067. return 0;
  27068. }
  27069. }
  27070. const String VSTPluginInstance::getVersion() const throw()
  27071. {
  27072. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27073. String s;
  27074. if (v == 0 || v == -1)
  27075. v = getVersionNumber();
  27076. if (v != 0)
  27077. {
  27078. int versionBits[4];
  27079. int n = 0;
  27080. while (v != 0)
  27081. {
  27082. versionBits [n++] = (v & 0xff);
  27083. v >>= 8;
  27084. }
  27085. s << 'V';
  27086. while (n > 0)
  27087. {
  27088. s << versionBits [--n];
  27089. if (n > 0)
  27090. s << '.';
  27091. }
  27092. }
  27093. return s;
  27094. }
  27095. int VSTPluginInstance::getUID() const throw()
  27096. {
  27097. int uid = effect != 0 ? effect->uniqueID : 0;
  27098. if (uid == 0)
  27099. uid = module->file.hashCode();
  27100. return uid;
  27101. }
  27102. const String VSTPluginInstance::getCategory() const throw()
  27103. {
  27104. const char* result = 0;
  27105. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27106. {
  27107. case kPlugCategEffect:
  27108. result = "Effect";
  27109. break;
  27110. case kPlugCategSynth:
  27111. result = "Synth";
  27112. break;
  27113. case kPlugCategAnalysis:
  27114. result = "Anaylsis";
  27115. break;
  27116. case kPlugCategMastering:
  27117. result = "Mastering";
  27118. break;
  27119. case kPlugCategSpacializer:
  27120. result = "Spacial";
  27121. break;
  27122. case kPlugCategRoomFx:
  27123. result = "Reverb";
  27124. break;
  27125. case kPlugSurroundFx:
  27126. result = "Surround";
  27127. break;
  27128. case kPlugCategRestoration:
  27129. result = "Restoration";
  27130. break;
  27131. case kPlugCategGenerator:
  27132. result = "Tone generation";
  27133. break;
  27134. default:
  27135. break;
  27136. }
  27137. return result;
  27138. }
  27139. float VSTPluginInstance::getParameter (int index)
  27140. {
  27141. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27142. {
  27143. try
  27144. {
  27145. const ScopedLock sl (lock);
  27146. return effect->getParameter (effect, index);
  27147. }
  27148. catch (...)
  27149. {
  27150. }
  27151. }
  27152. return 0.0f;
  27153. }
  27154. void VSTPluginInstance::setParameter (int index, float newValue)
  27155. {
  27156. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27157. {
  27158. try
  27159. {
  27160. const ScopedLock sl (lock);
  27161. if (effect->getParameter (effect, index) != newValue)
  27162. effect->setParameter (effect, index, newValue);
  27163. }
  27164. catch (...)
  27165. {
  27166. }
  27167. }
  27168. }
  27169. const String VSTPluginInstance::getParameterName (int index)
  27170. {
  27171. if (effect != 0)
  27172. {
  27173. jassert (index >= 0 && index < effect->numParams);
  27174. char nm [256];
  27175. zerostruct (nm);
  27176. dispatch (effGetParamName, index, 0, nm, 0);
  27177. return String (nm).trim();
  27178. }
  27179. return String::empty;
  27180. }
  27181. const String VSTPluginInstance::getParameterLabel (int index) const
  27182. {
  27183. if (effect != 0)
  27184. {
  27185. jassert (index >= 0 && index < effect->numParams);
  27186. char nm [256];
  27187. zerostruct (nm);
  27188. dispatch (effGetParamLabel, index, 0, nm, 0);
  27189. return String (nm).trim();
  27190. }
  27191. return String::empty;
  27192. }
  27193. const String VSTPluginInstance::getParameterText (int index)
  27194. {
  27195. if (effect != 0)
  27196. {
  27197. jassert (index >= 0 && index < effect->numParams);
  27198. char nm [256];
  27199. zerostruct (nm);
  27200. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27201. return String (nm).trim();
  27202. }
  27203. return String::empty;
  27204. }
  27205. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27206. {
  27207. if (effect != 0)
  27208. {
  27209. jassert (index >= 0 && index < effect->numParams);
  27210. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27211. }
  27212. return false;
  27213. }
  27214. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27215. {
  27216. dest.setSize (64 + 4 * getNumParameters());
  27217. dest.fillWith (0);
  27218. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27219. float* const p = (float*) (((char*) dest.getData()) + 64);
  27220. for (int i = 0; i < getNumParameters(); ++i)
  27221. p[i] = getParameter(i);
  27222. }
  27223. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27224. {
  27225. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27226. float* p = (float*) (((char*) m.getData()) + 64);
  27227. for (int i = 0; i < getNumParameters(); ++i)
  27228. setParameter (i, p[i]);
  27229. }
  27230. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27231. {
  27232. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27233. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27234. }
  27235. const String VSTPluginInstance::getProgramName (int index)
  27236. {
  27237. if (index == getCurrentProgram())
  27238. {
  27239. return getCurrentProgramName();
  27240. }
  27241. else if (effect != 0)
  27242. {
  27243. char nm [256];
  27244. zerostruct (nm);
  27245. if (dispatch (effGetProgramNameIndexed,
  27246. jlimit (0, getNumPrograms(), index),
  27247. -1, nm, 0) != 0)
  27248. {
  27249. return String (nm).trim();
  27250. }
  27251. }
  27252. return programNames [index];
  27253. }
  27254. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27255. {
  27256. if (index == getCurrentProgram())
  27257. {
  27258. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27259. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27260. }
  27261. else
  27262. {
  27263. jassertfalse // xxx not implemented!
  27264. }
  27265. }
  27266. void VSTPluginInstance::updateStoredProgramNames()
  27267. {
  27268. if (effect != 0 && getNumPrograms() > 0)
  27269. {
  27270. char nm [256];
  27271. zerostruct (nm);
  27272. // only do this if the plugin can't use indexed names..
  27273. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27274. {
  27275. const int oldProgram = getCurrentProgram();
  27276. MemoryBlock oldSettings;
  27277. createTempParameterStore (oldSettings);
  27278. for (int i = 0; i < getNumPrograms(); ++i)
  27279. {
  27280. setCurrentProgram (i);
  27281. getCurrentProgramName(); // (this updates the list)
  27282. }
  27283. setCurrentProgram (oldProgram);
  27284. restoreFromTempParameterStore (oldSettings);
  27285. }
  27286. }
  27287. }
  27288. const String VSTPluginInstance::getCurrentProgramName()
  27289. {
  27290. if (effect != 0)
  27291. {
  27292. char nm [256];
  27293. zerostruct (nm);
  27294. dispatch (effGetProgramName, 0, 0, nm, 0);
  27295. const int index = getCurrentProgram();
  27296. if (programNames[index].isEmpty())
  27297. {
  27298. while (programNames.size() < index)
  27299. programNames.add (String::empty);
  27300. programNames.set (index, String (nm).trim());
  27301. }
  27302. return String (nm).trim();
  27303. }
  27304. return String::empty;
  27305. }
  27306. const String VSTPluginInstance::getInputChannelName (const int index) const
  27307. {
  27308. if (index >= 0 && index < getNumInputChannels())
  27309. {
  27310. VstPinProperties pinProps;
  27311. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27312. return String (pinProps.label, sizeof (pinProps.label));
  27313. }
  27314. return String::empty;
  27315. }
  27316. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27317. {
  27318. if (index < 0 || index >= getNumInputChannels())
  27319. return false;
  27320. VstPinProperties pinProps;
  27321. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27322. return (pinProps.flags & kVstPinIsStereo) != 0;
  27323. return true;
  27324. }
  27325. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27326. {
  27327. if (index >= 0 && index < getNumOutputChannels())
  27328. {
  27329. VstPinProperties pinProps;
  27330. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27331. return String (pinProps.label, sizeof (pinProps.label));
  27332. }
  27333. return String::empty;
  27334. }
  27335. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27336. {
  27337. if (index < 0 || index >= getNumOutputChannels())
  27338. return false;
  27339. VstPinProperties pinProps;
  27340. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27341. return (pinProps.flags & kVstPinIsStereo) != 0;
  27342. return true;
  27343. }
  27344. void VSTPluginInstance::setPower (const bool on)
  27345. {
  27346. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27347. isPowerOn = on;
  27348. }
  27349. const int defaultMaxSizeMB = 64;
  27350. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27351. {
  27352. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27353. }
  27354. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27355. {
  27356. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27357. }
  27358. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27359. {
  27360. loadFromFXBFile (data, sizeInBytes);
  27361. }
  27362. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27363. {
  27364. loadFromFXBFile (data, sizeInBytes);
  27365. }
  27366. VSTPluginFormat::VSTPluginFormat()
  27367. {
  27368. }
  27369. VSTPluginFormat::~VSTPluginFormat()
  27370. {
  27371. }
  27372. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27373. const String& fileOrIdentifier)
  27374. {
  27375. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27376. return;
  27377. PluginDescription desc;
  27378. desc.fileOrIdentifier = fileOrIdentifier;
  27379. desc.uid = 0;
  27380. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27381. if (instance == 0)
  27382. return;
  27383. try
  27384. {
  27385. #if JUCE_MAC
  27386. if (instance->module->resFileId != 0)
  27387. UseResFile (instance->module->resFileId);
  27388. #endif
  27389. instance->fillInPluginDescription (desc);
  27390. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27391. if (category != kPlugCategShell)
  27392. {
  27393. // Normal plugin...
  27394. results.add (new PluginDescription (desc));
  27395. ++insideVSTCallback;
  27396. instance->dispatch (effOpen, 0, 0, 0, 0);
  27397. --insideVSTCallback;
  27398. }
  27399. else
  27400. {
  27401. // It's a shell plugin, so iterate all the subtypes...
  27402. char shellEffectName [64];
  27403. for (;;)
  27404. {
  27405. zerostruct (shellEffectName);
  27406. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27407. if (uid == 0)
  27408. {
  27409. break;
  27410. }
  27411. else
  27412. {
  27413. desc.uid = uid;
  27414. desc.name = shellEffectName;
  27415. bool alreadyThere = false;
  27416. for (int i = results.size(); --i >= 0;)
  27417. {
  27418. PluginDescription* const d = results.getUnchecked(i);
  27419. if (d->isDuplicateOf (desc))
  27420. {
  27421. alreadyThere = true;
  27422. break;
  27423. }
  27424. }
  27425. if (! alreadyThere)
  27426. results.add (new PluginDescription (desc));
  27427. }
  27428. }
  27429. }
  27430. }
  27431. catch (...)
  27432. {
  27433. // crashed while loading...
  27434. }
  27435. }
  27436. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27437. {
  27438. ScopedPointer <VSTPluginInstance> result;
  27439. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27440. {
  27441. File file (desc.fileOrIdentifier);
  27442. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27443. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27444. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27445. if (module != 0)
  27446. {
  27447. shellUIDToCreate = desc.uid;
  27448. result = new VSTPluginInstance (module);
  27449. if (result->effect != 0)
  27450. {
  27451. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27452. result->initialise();
  27453. }
  27454. else
  27455. {
  27456. result = 0;
  27457. }
  27458. }
  27459. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27460. }
  27461. return result.release();
  27462. }
  27463. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27464. {
  27465. const File f (fileOrIdentifier);
  27466. #if JUCE_MAC
  27467. if (f.isDirectory() && f.hasFileExtension (".vst"))
  27468. return true;
  27469. #if JUCE_PPC
  27470. FSRef fileRef;
  27471. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27472. {
  27473. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27474. if (resFileId != -1)
  27475. {
  27476. const int numEffects = Count1Resources ('aEff');
  27477. CloseResFile (resFileId);
  27478. if (numEffects > 0)
  27479. return true;
  27480. }
  27481. }
  27482. #endif
  27483. return false;
  27484. #elif JUCE_WIN32
  27485. return f.existsAsFile()
  27486. && f.hasFileExtension (".dll");
  27487. #elif JUCE_LINUX
  27488. return f.existsAsFile()
  27489. && f.hasFileExtension (".so");
  27490. #endif
  27491. }
  27492. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27493. {
  27494. return fileOrIdentifier;
  27495. }
  27496. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27497. {
  27498. return File (desc.fileOrIdentifier).exists();
  27499. }
  27500. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27501. {
  27502. StringArray results;
  27503. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27504. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27505. return results;
  27506. }
  27507. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27508. {
  27509. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27510. // .component or .vst directories.
  27511. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27512. while (iter.next())
  27513. {
  27514. const File f (iter.getFile());
  27515. bool isPlugin = false;
  27516. if (fileMightContainThisPluginType (f.getFullPathName()))
  27517. {
  27518. isPlugin = true;
  27519. results.add (f.getFullPathName());
  27520. }
  27521. if (recursive && (! isPlugin) && f.isDirectory())
  27522. recursiveFileSearch (results, f, true);
  27523. }
  27524. }
  27525. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27526. {
  27527. #if JUCE_MAC
  27528. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27529. #elif JUCE_WIN32
  27530. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27531. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27532. #elif JUCE_LINUX
  27533. return FileSearchPath ("/usr/lib/vst");
  27534. #endif
  27535. }
  27536. END_JUCE_NAMESPACE
  27537. #endif
  27538. #undef log
  27539. #endif
  27540. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27541. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27542. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27543. BEGIN_JUCE_NAMESPACE
  27544. AudioProcessor::AudioProcessor()
  27545. : playHead (0),
  27546. activeEditor (0),
  27547. sampleRate (0),
  27548. blockSize (0),
  27549. numInputChannels (0),
  27550. numOutputChannels (0),
  27551. latencySamples (0),
  27552. suspended (false),
  27553. nonRealtime (false)
  27554. {
  27555. }
  27556. AudioProcessor::~AudioProcessor()
  27557. {
  27558. // ooh, nasty - the editor should have been deleted before the filter
  27559. // that it refers to is deleted..
  27560. jassert (activeEditor == 0);
  27561. #ifdef JUCE_DEBUG
  27562. // This will fail if you've called beginParameterChangeGesture() for one
  27563. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27564. jassert (changingParams.countNumberOfSetBits() == 0);
  27565. #endif
  27566. }
  27567. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27568. {
  27569. playHead = newPlayHead;
  27570. }
  27571. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27572. {
  27573. const ScopedLock sl (listenerLock);
  27574. listeners.addIfNotAlreadyThere (newListener);
  27575. }
  27576. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27577. {
  27578. const ScopedLock sl (listenerLock);
  27579. listeners.removeValue (listenerToRemove);
  27580. }
  27581. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27582. const int numOuts,
  27583. const double sampleRate_,
  27584. const int blockSize_) throw()
  27585. {
  27586. numInputChannels = numIns;
  27587. numOutputChannels = numOuts;
  27588. sampleRate = sampleRate_;
  27589. blockSize = blockSize_;
  27590. }
  27591. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27592. {
  27593. nonRealtime = nonRealtime_;
  27594. }
  27595. void AudioProcessor::setLatencySamples (const int newLatency)
  27596. {
  27597. if (latencySamples != newLatency)
  27598. {
  27599. latencySamples = newLatency;
  27600. updateHostDisplay();
  27601. }
  27602. }
  27603. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27604. const float newValue)
  27605. {
  27606. setParameter (parameterIndex, newValue);
  27607. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27608. }
  27609. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27610. {
  27611. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27612. for (int i = listeners.size(); --i >= 0;)
  27613. {
  27614. AudioProcessorListener* l;
  27615. {
  27616. const ScopedLock sl (listenerLock);
  27617. l = (AudioProcessorListener*) listeners [i];
  27618. }
  27619. if (l != 0)
  27620. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27621. }
  27622. }
  27623. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27624. {
  27625. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27626. #ifdef JUCE_DEBUG
  27627. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27628. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27629. jassert (! changingParams [parameterIndex]);
  27630. changingParams.setBit (parameterIndex);
  27631. #endif
  27632. for (int i = listeners.size(); --i >= 0;)
  27633. {
  27634. AudioProcessorListener* l;
  27635. {
  27636. const ScopedLock sl (listenerLock);
  27637. l = (AudioProcessorListener*) listeners [i];
  27638. }
  27639. if (l != 0)
  27640. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27641. }
  27642. }
  27643. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27644. {
  27645. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27646. #ifdef JUCE_DEBUG
  27647. // This means you've called endParameterChangeGesture without having previously called
  27648. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27649. // calls matched correctly.
  27650. jassert (changingParams [parameterIndex]);
  27651. changingParams.clearBit (parameterIndex);
  27652. #endif
  27653. for (int i = listeners.size(); --i >= 0;)
  27654. {
  27655. AudioProcessorListener* l;
  27656. {
  27657. const ScopedLock sl (listenerLock);
  27658. l = (AudioProcessorListener*) listeners [i];
  27659. }
  27660. if (l != 0)
  27661. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27662. }
  27663. }
  27664. void AudioProcessor::updateHostDisplay()
  27665. {
  27666. for (int i = listeners.size(); --i >= 0;)
  27667. {
  27668. AudioProcessorListener* l;
  27669. {
  27670. const ScopedLock sl (listenerLock);
  27671. l = (AudioProcessorListener*) listeners [i];
  27672. }
  27673. if (l != 0)
  27674. l->audioProcessorChanged (this);
  27675. }
  27676. }
  27677. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27678. {
  27679. return true;
  27680. }
  27681. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27682. {
  27683. return false;
  27684. }
  27685. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27686. {
  27687. const ScopedLock sl (callbackLock);
  27688. suspended = shouldBeSuspended;
  27689. }
  27690. void AudioProcessor::reset()
  27691. {
  27692. }
  27693. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27694. {
  27695. const ScopedLock sl (callbackLock);
  27696. jassert (activeEditor == editor);
  27697. if (activeEditor == editor)
  27698. activeEditor = 0;
  27699. }
  27700. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  27701. {
  27702. if (activeEditor != 0)
  27703. return activeEditor;
  27704. AudioProcessorEditor* const ed = createEditor();
  27705. if (ed != 0)
  27706. {
  27707. // you must give your editor comp a size before returning it..
  27708. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  27709. const ScopedLock sl (callbackLock);
  27710. activeEditor = ed;
  27711. }
  27712. return ed;
  27713. }
  27714. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  27715. {
  27716. getStateInformation (destData);
  27717. }
  27718. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27719. {
  27720. setStateInformation (data, sizeInBytes);
  27721. }
  27722. // magic number to identify memory blocks that we've stored as XML
  27723. const uint32 magicXmlNumber = 0x21324356;
  27724. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  27725. JUCE_NAMESPACE::MemoryBlock& destData)
  27726. {
  27727. const String xmlString (xml.createDocument (String::empty, true, false));
  27728. const int stringLength = xmlString.getNumBytesAsUTF8();
  27729. destData.setSize (stringLength + 10);
  27730. char* const d = (char*) destData.getData();
  27731. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  27732. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  27733. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  27734. }
  27735. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  27736. const int sizeInBytes)
  27737. {
  27738. if (sizeInBytes > 8
  27739. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  27740. {
  27741. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  27742. if (stringLength > 0)
  27743. {
  27744. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  27745. jmin ((sizeInBytes - 8), stringLength)));
  27746. return doc.getDocumentElement();
  27747. }
  27748. }
  27749. return 0;
  27750. }
  27751. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  27752. {
  27753. }
  27754. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  27755. {
  27756. }
  27757. bool AudioPlayHead::CurrentPositionInfo::operator== (const CurrentPositionInfo& other) const throw()
  27758. {
  27759. return timeInSeconds == other.timeInSeconds
  27760. && ppqPosition == other.ppqPosition
  27761. && editOriginTime == other.editOriginTime
  27762. && ppqPositionOfLastBarStart == other.ppqPositionOfLastBarStart
  27763. && frameRate == other.frameRate
  27764. && isPlaying == other.isPlaying
  27765. && isRecording == other.isRecording
  27766. && bpm == other.bpm
  27767. && timeSigNumerator == other.timeSigNumerator
  27768. && timeSigDenominator == other.timeSigDenominator;
  27769. }
  27770. bool AudioPlayHead::CurrentPositionInfo::operator!= (const CurrentPositionInfo& other) const throw()
  27771. {
  27772. return ! operator== (other);
  27773. }
  27774. void AudioPlayHead::CurrentPositionInfo::resetToDefault()
  27775. {
  27776. zerostruct (*this);
  27777. timeSigNumerator = 4;
  27778. timeSigDenominator = 4;
  27779. bpm = 120;
  27780. }
  27781. END_JUCE_NAMESPACE
  27782. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  27783. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  27784. BEGIN_JUCE_NAMESPACE
  27785. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  27786. : owner (owner_)
  27787. {
  27788. // the filter must be valid..
  27789. jassert (owner != 0);
  27790. }
  27791. AudioProcessorEditor::~AudioProcessorEditor()
  27792. {
  27793. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  27794. // filter for some reason..
  27795. jassert (owner->getActiveEditor() != this);
  27796. }
  27797. END_JUCE_NAMESPACE
  27798. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  27799. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  27800. BEGIN_JUCE_NAMESPACE
  27801. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  27802. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  27803. : id (id_),
  27804. processor (processor_),
  27805. isPrepared (false)
  27806. {
  27807. jassert (processor_ != 0);
  27808. }
  27809. AudioProcessorGraph::Node::~Node()
  27810. {
  27811. delete processor;
  27812. }
  27813. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  27814. AudioProcessorGraph* const graph)
  27815. {
  27816. if (! isPrepared)
  27817. {
  27818. isPrepared = true;
  27819. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27820. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  27821. if (ioProc != 0)
  27822. ioProc->setParentGraph (graph);
  27823. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  27824. processor->getNumOutputChannels(),
  27825. sampleRate, blockSize);
  27826. processor->prepareToPlay (sampleRate, blockSize);
  27827. }
  27828. }
  27829. void AudioProcessorGraph::Node::unprepare()
  27830. {
  27831. if (isPrepared)
  27832. {
  27833. isPrepared = false;
  27834. processor->releaseResources();
  27835. }
  27836. }
  27837. AudioProcessorGraph::AudioProcessorGraph()
  27838. : lastNodeId (0),
  27839. renderingBuffers (1, 1),
  27840. currentAudioOutputBuffer (1, 1)
  27841. {
  27842. }
  27843. AudioProcessorGraph::~AudioProcessorGraph()
  27844. {
  27845. clearRenderingSequence();
  27846. clear();
  27847. }
  27848. const String AudioProcessorGraph::getName() const
  27849. {
  27850. return "Audio Graph";
  27851. }
  27852. void AudioProcessorGraph::clear()
  27853. {
  27854. nodes.clear();
  27855. connections.clear();
  27856. triggerAsyncUpdate();
  27857. }
  27858. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  27859. {
  27860. for (int i = nodes.size(); --i >= 0;)
  27861. if (nodes.getUnchecked(i)->id == nodeId)
  27862. return nodes.getUnchecked(i);
  27863. return 0;
  27864. }
  27865. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  27866. uint32 nodeId)
  27867. {
  27868. if (newProcessor == 0)
  27869. {
  27870. jassertfalse
  27871. return 0;
  27872. }
  27873. if (nodeId == 0)
  27874. {
  27875. nodeId = ++lastNodeId;
  27876. }
  27877. else
  27878. {
  27879. // you can't add a node with an id that already exists in the graph..
  27880. jassert (getNodeForId (nodeId) == 0);
  27881. removeNode (nodeId);
  27882. }
  27883. lastNodeId = nodeId;
  27884. Node* const n = new Node (nodeId, newProcessor);
  27885. nodes.add (n);
  27886. triggerAsyncUpdate();
  27887. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27888. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  27889. if (ioProc != 0)
  27890. ioProc->setParentGraph (this);
  27891. return n;
  27892. }
  27893. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  27894. {
  27895. disconnectNode (nodeId);
  27896. for (int i = nodes.size(); --i >= 0;)
  27897. {
  27898. if (nodes.getUnchecked(i)->id == nodeId)
  27899. {
  27900. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  27901. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  27902. if (ioProc != 0)
  27903. ioProc->setParentGraph (0);
  27904. nodes.remove (i);
  27905. triggerAsyncUpdate();
  27906. return true;
  27907. }
  27908. }
  27909. return false;
  27910. }
  27911. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  27912. const int sourceChannelIndex,
  27913. const uint32 destNodeId,
  27914. const int destChannelIndex) const
  27915. {
  27916. for (int i = connections.size(); --i >= 0;)
  27917. {
  27918. const Connection* const c = connections.getUnchecked(i);
  27919. if (c->sourceNodeId == sourceNodeId
  27920. && c->destNodeId == destNodeId
  27921. && c->sourceChannelIndex == sourceChannelIndex
  27922. && c->destChannelIndex == destChannelIndex)
  27923. {
  27924. return c;
  27925. }
  27926. }
  27927. return 0;
  27928. }
  27929. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  27930. const uint32 possibleDestNodeId) const
  27931. {
  27932. for (int i = connections.size(); --i >= 0;)
  27933. {
  27934. const Connection* const c = connections.getUnchecked(i);
  27935. if (c->sourceNodeId == possibleSourceNodeId
  27936. && c->destNodeId == possibleDestNodeId)
  27937. {
  27938. return true;
  27939. }
  27940. }
  27941. return false;
  27942. }
  27943. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  27944. const int sourceChannelIndex,
  27945. const uint32 destNodeId,
  27946. const int destChannelIndex) const
  27947. {
  27948. if (sourceChannelIndex < 0
  27949. || destChannelIndex < 0
  27950. || sourceNodeId == destNodeId
  27951. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  27952. return false;
  27953. const Node* const source = getNodeForId (sourceNodeId);
  27954. if (source == 0
  27955. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  27956. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  27957. return false;
  27958. const Node* const dest = getNodeForId (destNodeId);
  27959. if (dest == 0
  27960. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  27961. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  27962. return false;
  27963. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  27964. destNodeId, destChannelIndex) == 0;
  27965. }
  27966. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  27967. const int sourceChannelIndex,
  27968. const uint32 destNodeId,
  27969. const int destChannelIndex)
  27970. {
  27971. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  27972. return false;
  27973. Connection* const c = new Connection();
  27974. c->sourceNodeId = sourceNodeId;
  27975. c->sourceChannelIndex = sourceChannelIndex;
  27976. c->destNodeId = destNodeId;
  27977. c->destChannelIndex = destChannelIndex;
  27978. connections.add (c);
  27979. triggerAsyncUpdate();
  27980. return true;
  27981. }
  27982. void AudioProcessorGraph::removeConnection (const int index)
  27983. {
  27984. connections.remove (index);
  27985. triggerAsyncUpdate();
  27986. }
  27987. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  27988. const uint32 destNodeId, const int destChannelIndex)
  27989. {
  27990. bool doneAnything = false;
  27991. for (int i = connections.size(); --i >= 0;)
  27992. {
  27993. const Connection* const c = connections.getUnchecked(i);
  27994. if (c->sourceNodeId == sourceNodeId
  27995. && c->destNodeId == destNodeId
  27996. && c->sourceChannelIndex == sourceChannelIndex
  27997. && c->destChannelIndex == destChannelIndex)
  27998. {
  27999. removeConnection (i);
  28000. doneAnything = true;
  28001. triggerAsyncUpdate();
  28002. }
  28003. }
  28004. return doneAnything;
  28005. }
  28006. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28007. {
  28008. bool doneAnything = false;
  28009. for (int i = connections.size(); --i >= 0;)
  28010. {
  28011. const Connection* const c = connections.getUnchecked(i);
  28012. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28013. {
  28014. removeConnection (i);
  28015. doneAnything = true;
  28016. triggerAsyncUpdate();
  28017. }
  28018. }
  28019. return doneAnything;
  28020. }
  28021. bool AudioProcessorGraph::removeIllegalConnections()
  28022. {
  28023. bool doneAnything = false;
  28024. for (int i = connections.size(); --i >= 0;)
  28025. {
  28026. const Connection* const c = connections.getUnchecked(i);
  28027. const Node* const source = getNodeForId (c->sourceNodeId);
  28028. const Node* const dest = getNodeForId (c->destNodeId);
  28029. if (source == 0 || dest == 0
  28030. || (c->sourceChannelIndex != midiChannelIndex
  28031. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28032. || (c->sourceChannelIndex == midiChannelIndex
  28033. && ! source->processor->producesMidi())
  28034. || (c->destChannelIndex != midiChannelIndex
  28035. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28036. || (c->destChannelIndex == midiChannelIndex
  28037. && ! dest->processor->acceptsMidi()))
  28038. {
  28039. removeConnection (i);
  28040. doneAnything = true;
  28041. triggerAsyncUpdate();
  28042. }
  28043. }
  28044. return doneAnything;
  28045. }
  28046. namespace GraphRenderingOps
  28047. {
  28048. class AudioGraphRenderingOp
  28049. {
  28050. public:
  28051. AudioGraphRenderingOp() {}
  28052. virtual ~AudioGraphRenderingOp() {}
  28053. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28054. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28055. const int numSamples) = 0;
  28056. juce_UseDebuggingNewOperator
  28057. };
  28058. class ClearChannelOp : public AudioGraphRenderingOp
  28059. {
  28060. public:
  28061. ClearChannelOp (const int channelNum_)
  28062. : channelNum (channelNum_)
  28063. {}
  28064. ~ClearChannelOp() {}
  28065. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28066. {
  28067. sharedBufferChans.clear (channelNum, 0, numSamples);
  28068. }
  28069. private:
  28070. const int channelNum;
  28071. ClearChannelOp (const ClearChannelOp&);
  28072. ClearChannelOp& operator= (const ClearChannelOp&);
  28073. };
  28074. class CopyChannelOp : public AudioGraphRenderingOp
  28075. {
  28076. public:
  28077. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28078. : srcChannelNum (srcChannelNum_),
  28079. dstChannelNum (dstChannelNum_)
  28080. {}
  28081. ~CopyChannelOp() {}
  28082. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28083. {
  28084. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28085. }
  28086. private:
  28087. const int srcChannelNum, dstChannelNum;
  28088. CopyChannelOp (const CopyChannelOp&);
  28089. CopyChannelOp& operator= (const CopyChannelOp&);
  28090. };
  28091. class AddChannelOp : public AudioGraphRenderingOp
  28092. {
  28093. public:
  28094. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28095. : srcChannelNum (srcChannelNum_),
  28096. dstChannelNum (dstChannelNum_)
  28097. {}
  28098. ~AddChannelOp() {}
  28099. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28100. {
  28101. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28102. }
  28103. private:
  28104. const int srcChannelNum, dstChannelNum;
  28105. AddChannelOp (const AddChannelOp&);
  28106. AddChannelOp& operator= (const AddChannelOp&);
  28107. };
  28108. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28109. {
  28110. public:
  28111. ClearMidiBufferOp (const int bufferNum_)
  28112. : bufferNum (bufferNum_)
  28113. {}
  28114. ~ClearMidiBufferOp() {}
  28115. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28116. {
  28117. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28118. }
  28119. private:
  28120. const int bufferNum;
  28121. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28122. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28123. };
  28124. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28125. {
  28126. public:
  28127. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28128. : srcBufferNum (srcBufferNum_),
  28129. dstBufferNum (dstBufferNum_)
  28130. {}
  28131. ~CopyMidiBufferOp() {}
  28132. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28133. {
  28134. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28135. }
  28136. private:
  28137. const int srcBufferNum, dstBufferNum;
  28138. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28139. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28140. };
  28141. class AddMidiBufferOp : public AudioGraphRenderingOp
  28142. {
  28143. public:
  28144. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28145. : srcBufferNum (srcBufferNum_),
  28146. dstBufferNum (dstBufferNum_)
  28147. {}
  28148. ~AddMidiBufferOp() {}
  28149. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28150. {
  28151. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28152. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28153. }
  28154. private:
  28155. const int srcBufferNum, dstBufferNum;
  28156. AddMidiBufferOp (const AddMidiBufferOp&);
  28157. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28158. };
  28159. class ProcessBufferOp : public AudioGraphRenderingOp
  28160. {
  28161. public:
  28162. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28163. const Array <int>& audioChannelsToUse_,
  28164. const int totalChans_,
  28165. const int midiBufferToUse_)
  28166. : node (node_),
  28167. processor (node_->processor),
  28168. audioChannelsToUse (audioChannelsToUse_),
  28169. totalChans (jmax (1, totalChans_)),
  28170. midiBufferToUse (midiBufferToUse_)
  28171. {
  28172. channels.calloc (totalChans);
  28173. while (audioChannelsToUse.size() < totalChans)
  28174. audioChannelsToUse.add (0);
  28175. }
  28176. ~ProcessBufferOp()
  28177. {
  28178. }
  28179. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28180. {
  28181. for (int i = totalChans; --i >= 0;)
  28182. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28183. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28184. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28185. }
  28186. const AudioProcessorGraph::Node::Ptr node;
  28187. AudioProcessor* const processor;
  28188. private:
  28189. Array <int> audioChannelsToUse;
  28190. HeapBlock <float*> channels;
  28191. int totalChans;
  28192. int midiBufferToUse;
  28193. ProcessBufferOp (const ProcessBufferOp&);
  28194. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28195. };
  28196. class RenderingOpSequenceCalculator
  28197. {
  28198. public:
  28199. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28200. const VoidArray& orderedNodes_,
  28201. VoidArray& renderingOps)
  28202. : graph (graph_),
  28203. orderedNodes (orderedNodes_)
  28204. {
  28205. nodeIds.add (-2); // first buffer is read-only zeros
  28206. channels.add (0);
  28207. midiNodeIds.add (-2);
  28208. for (int i = 0; i < orderedNodes.size(); ++i)
  28209. {
  28210. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28211. renderingOps, i);
  28212. markAnyUnusedBuffersAsFree (i);
  28213. }
  28214. }
  28215. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28216. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28217. juce_UseDebuggingNewOperator
  28218. private:
  28219. AudioProcessorGraph& graph;
  28220. const VoidArray& orderedNodes;
  28221. Array <int> nodeIds, channels, midiNodeIds;
  28222. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28223. VoidArray& renderingOps,
  28224. const int ourRenderingIndex)
  28225. {
  28226. const int numIns = node->processor->getNumInputChannels();
  28227. const int numOuts = node->processor->getNumOutputChannels();
  28228. const int totalChans = jmax (numIns, numOuts);
  28229. Array <int> audioChannelsToUse;
  28230. int midiBufferToUse = -1;
  28231. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28232. {
  28233. // get a list of all the inputs to this node
  28234. Array <int> sourceNodes, sourceOutputChans;
  28235. for (int i = graph.getNumConnections(); --i >= 0;)
  28236. {
  28237. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28238. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28239. {
  28240. sourceNodes.add (c->sourceNodeId);
  28241. sourceOutputChans.add (c->sourceChannelIndex);
  28242. }
  28243. }
  28244. int bufIndex = -1;
  28245. if (sourceNodes.size() == 0)
  28246. {
  28247. // unconnected input channel
  28248. if (inputChan >= numOuts)
  28249. {
  28250. bufIndex = getReadOnlyEmptyBuffer();
  28251. jassert (bufIndex >= 0);
  28252. }
  28253. else
  28254. {
  28255. bufIndex = getFreeBuffer (false);
  28256. renderingOps.add (new ClearChannelOp (bufIndex));
  28257. }
  28258. }
  28259. else if (sourceNodes.size() == 1)
  28260. {
  28261. // channel with a straightforward single input..
  28262. const int srcNode = sourceNodes.getUnchecked(0);
  28263. const int srcChan = sourceOutputChans.getUnchecked(0);
  28264. bufIndex = getBufferContaining (srcNode, srcChan);
  28265. if (bufIndex < 0)
  28266. {
  28267. // if not found, this is probably a feedback loop
  28268. bufIndex = getReadOnlyEmptyBuffer();
  28269. jassert (bufIndex >= 0);
  28270. }
  28271. if (inputChan < numOuts
  28272. && isBufferNeededLater (ourRenderingIndex,
  28273. inputChan,
  28274. srcNode, srcChan))
  28275. {
  28276. // can't mess up this channel because it's needed later by another node, so we
  28277. // need to use a copy of it..
  28278. const int newFreeBuffer = getFreeBuffer (false);
  28279. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28280. bufIndex = newFreeBuffer;
  28281. }
  28282. }
  28283. else
  28284. {
  28285. // channel with a mix of several inputs..
  28286. // try to find a re-usable channel from our inputs..
  28287. int reusableInputIndex = -1;
  28288. for (int i = 0; i < sourceNodes.size(); ++i)
  28289. {
  28290. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28291. sourceOutputChans.getUnchecked(i));
  28292. if (sourceBufIndex >= 0
  28293. && ! isBufferNeededLater (ourRenderingIndex,
  28294. inputChan,
  28295. sourceNodes.getUnchecked(i),
  28296. sourceOutputChans.getUnchecked(i)))
  28297. {
  28298. // we've found one of our input chans that can be re-used..
  28299. reusableInputIndex = i;
  28300. bufIndex = sourceBufIndex;
  28301. break;
  28302. }
  28303. }
  28304. if (reusableInputIndex < 0)
  28305. {
  28306. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28307. bufIndex = getFreeBuffer (false);
  28308. jassert (bufIndex != 0);
  28309. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28310. sourceOutputChans.getUnchecked (0));
  28311. if (srcIndex < 0)
  28312. {
  28313. // if not found, this is probably a feedback loop
  28314. renderingOps.add (new ClearChannelOp (bufIndex));
  28315. }
  28316. else
  28317. {
  28318. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28319. }
  28320. reusableInputIndex = 0;
  28321. }
  28322. for (int j = 0; j < sourceNodes.size(); ++j)
  28323. {
  28324. if (j != reusableInputIndex)
  28325. {
  28326. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28327. sourceOutputChans.getUnchecked(j));
  28328. if (srcIndex >= 0)
  28329. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28330. }
  28331. }
  28332. }
  28333. jassert (bufIndex >= 0);
  28334. audioChannelsToUse.add (bufIndex);
  28335. if (inputChan < numOuts)
  28336. markBufferAsContaining (bufIndex, node->id, inputChan);
  28337. }
  28338. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28339. {
  28340. const int bufIndex = getFreeBuffer (false);
  28341. jassert (bufIndex != 0);
  28342. audioChannelsToUse.add (bufIndex);
  28343. markBufferAsContaining (bufIndex, node->id, outputChan);
  28344. }
  28345. // Now the same thing for midi..
  28346. Array <int> midiSourceNodes;
  28347. for (int i = graph.getNumConnections(); --i >= 0;)
  28348. {
  28349. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28350. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28351. midiSourceNodes.add (c->sourceNodeId);
  28352. }
  28353. if (midiSourceNodes.size() == 0)
  28354. {
  28355. // No midi inputs..
  28356. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28357. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28358. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28359. }
  28360. else if (midiSourceNodes.size() == 1)
  28361. {
  28362. // One midi input..
  28363. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28364. AudioProcessorGraph::midiChannelIndex);
  28365. if (midiBufferToUse >= 0)
  28366. {
  28367. if (isBufferNeededLater (ourRenderingIndex,
  28368. AudioProcessorGraph::midiChannelIndex,
  28369. midiSourceNodes.getUnchecked(0),
  28370. AudioProcessorGraph::midiChannelIndex))
  28371. {
  28372. // can't mess up this channel because it's needed later by another node, so we
  28373. // need to use a copy of it..
  28374. const int newFreeBuffer = getFreeBuffer (true);
  28375. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28376. midiBufferToUse = newFreeBuffer;
  28377. }
  28378. }
  28379. else
  28380. {
  28381. // probably a feedback loop, so just use an empty one..
  28382. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28383. }
  28384. }
  28385. else
  28386. {
  28387. // More than one midi input being mixed..
  28388. int reusableInputIndex = -1;
  28389. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28390. {
  28391. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28392. AudioProcessorGraph::midiChannelIndex);
  28393. if (sourceBufIndex >= 0
  28394. && ! isBufferNeededLater (ourRenderingIndex,
  28395. AudioProcessorGraph::midiChannelIndex,
  28396. midiSourceNodes.getUnchecked(i),
  28397. AudioProcessorGraph::midiChannelIndex))
  28398. {
  28399. // we've found one of our input buffers that can be re-used..
  28400. reusableInputIndex = i;
  28401. midiBufferToUse = sourceBufIndex;
  28402. break;
  28403. }
  28404. }
  28405. if (reusableInputIndex < 0)
  28406. {
  28407. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28408. midiBufferToUse = getFreeBuffer (true);
  28409. jassert (midiBufferToUse >= 0);
  28410. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28411. AudioProcessorGraph::midiChannelIndex);
  28412. if (srcIndex >= 0)
  28413. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28414. else
  28415. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28416. reusableInputIndex = 0;
  28417. }
  28418. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28419. {
  28420. if (j != reusableInputIndex)
  28421. {
  28422. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28423. AudioProcessorGraph::midiChannelIndex);
  28424. if (srcIndex >= 0)
  28425. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28426. }
  28427. }
  28428. }
  28429. if (node->processor->producesMidi())
  28430. markBufferAsContaining (midiBufferToUse, node->id,
  28431. AudioProcessorGraph::midiChannelIndex);
  28432. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28433. totalChans, midiBufferToUse));
  28434. }
  28435. int getFreeBuffer (const bool forMidi)
  28436. {
  28437. if (forMidi)
  28438. {
  28439. for (int i = 1; i < midiNodeIds.size(); ++i)
  28440. if (midiNodeIds.getUnchecked(i) < 0)
  28441. return i;
  28442. midiNodeIds.add (-1);
  28443. return midiNodeIds.size() - 1;
  28444. }
  28445. else
  28446. {
  28447. for (int i = 1; i < nodeIds.size(); ++i)
  28448. if (nodeIds.getUnchecked(i) < 0)
  28449. return i;
  28450. nodeIds.add (-1);
  28451. channels.add (0);
  28452. return nodeIds.size() - 1;
  28453. }
  28454. }
  28455. int getReadOnlyEmptyBuffer() const
  28456. {
  28457. return 0;
  28458. }
  28459. int getBufferContaining (const int nodeId, const int outputChannel) const
  28460. {
  28461. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28462. {
  28463. for (int i = midiNodeIds.size(); --i >= 0;)
  28464. if (midiNodeIds.getUnchecked(i) == nodeId)
  28465. return i;
  28466. }
  28467. else
  28468. {
  28469. for (int i = nodeIds.size(); --i >= 0;)
  28470. if (nodeIds.getUnchecked(i) == nodeId
  28471. && channels.getUnchecked(i) == outputChannel)
  28472. return i;
  28473. }
  28474. return -1;
  28475. }
  28476. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28477. {
  28478. int i;
  28479. for (i = 0; i < nodeIds.size(); ++i)
  28480. {
  28481. if (nodeIds.getUnchecked(i) >= 0
  28482. && ! isBufferNeededLater (stepIndex, -1,
  28483. nodeIds.getUnchecked(i),
  28484. channels.getUnchecked(i)))
  28485. {
  28486. nodeIds.set (i, -1);
  28487. }
  28488. }
  28489. for (i = 0; i < midiNodeIds.size(); ++i)
  28490. {
  28491. if (midiNodeIds.getUnchecked(i) >= 0
  28492. && ! isBufferNeededLater (stepIndex, -1,
  28493. midiNodeIds.getUnchecked(i),
  28494. AudioProcessorGraph::midiChannelIndex))
  28495. {
  28496. midiNodeIds.set (i, -1);
  28497. }
  28498. }
  28499. }
  28500. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28501. int inputChannelOfIndexToIgnore,
  28502. const int nodeId,
  28503. const int outputChanIndex) const
  28504. {
  28505. while (stepIndexToSearchFrom < orderedNodes.size())
  28506. {
  28507. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28508. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28509. {
  28510. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28511. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28512. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28513. return true;
  28514. }
  28515. else
  28516. {
  28517. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28518. if (i != inputChannelOfIndexToIgnore
  28519. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28520. node->id, i) != 0)
  28521. return true;
  28522. }
  28523. inputChannelOfIndexToIgnore = -1;
  28524. ++stepIndexToSearchFrom;
  28525. }
  28526. return false;
  28527. }
  28528. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28529. {
  28530. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28531. {
  28532. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28533. midiNodeIds.set (bufferNum, nodeId);
  28534. }
  28535. else
  28536. {
  28537. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28538. nodeIds.set (bufferNum, nodeId);
  28539. channels.set (bufferNum, outputIndex);
  28540. }
  28541. }
  28542. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28543. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28544. };
  28545. }
  28546. void AudioProcessorGraph::clearRenderingSequence()
  28547. {
  28548. const ScopedLock sl (renderLock);
  28549. for (int i = renderingOps.size(); --i >= 0;)
  28550. {
  28551. GraphRenderingOps::AudioGraphRenderingOp* const r
  28552. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28553. renderingOps.remove (i);
  28554. delete r;
  28555. }
  28556. }
  28557. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28558. const uint32 possibleDestinationId,
  28559. const int recursionCheck) const
  28560. {
  28561. if (recursionCheck > 0)
  28562. {
  28563. for (int i = connections.size(); --i >= 0;)
  28564. {
  28565. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28566. if (c->destNodeId == possibleDestinationId
  28567. && (c->sourceNodeId == possibleInputId
  28568. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28569. return true;
  28570. }
  28571. }
  28572. return false;
  28573. }
  28574. void AudioProcessorGraph::buildRenderingSequence()
  28575. {
  28576. VoidArray newRenderingOps;
  28577. int numRenderingBuffersNeeded = 2;
  28578. int numMidiBuffersNeeded = 1;
  28579. {
  28580. MessageManagerLock mml;
  28581. VoidArray orderedNodes;
  28582. int i;
  28583. for (i = 0; i < nodes.size(); ++i)
  28584. {
  28585. Node* const node = nodes.getUnchecked(i);
  28586. node->prepare (getSampleRate(), getBlockSize(), this);
  28587. int j = 0;
  28588. for (; j < orderedNodes.size(); ++j)
  28589. if (isAnInputTo (node->id,
  28590. ((Node*) orderedNodes.getUnchecked (j))->id,
  28591. nodes.size() + 1))
  28592. break;
  28593. orderedNodes.insert (j, node);
  28594. }
  28595. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28596. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28597. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28598. }
  28599. VoidArray oldRenderingOps (renderingOps);
  28600. {
  28601. // swap over to the new rendering sequence..
  28602. const ScopedLock sl (renderLock);
  28603. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28604. renderingBuffers.clear();
  28605. for (int i = midiBuffers.size(); --i >= 0;)
  28606. midiBuffers.getUnchecked(i)->clear();
  28607. while (midiBuffers.size() < numMidiBuffersNeeded)
  28608. midiBuffers.add (new MidiBuffer());
  28609. renderingOps = newRenderingOps;
  28610. }
  28611. for (int i = oldRenderingOps.size(); --i >= 0;)
  28612. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28613. }
  28614. void AudioProcessorGraph::handleAsyncUpdate()
  28615. {
  28616. buildRenderingSequence();
  28617. }
  28618. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28619. {
  28620. currentAudioInputBuffer = 0;
  28621. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28622. currentMidiInputBuffer = 0;
  28623. currentMidiOutputBuffer.clear();
  28624. clearRenderingSequence();
  28625. buildRenderingSequence();
  28626. }
  28627. void AudioProcessorGraph::releaseResources()
  28628. {
  28629. for (int i = 0; i < nodes.size(); ++i)
  28630. nodes.getUnchecked(i)->unprepare();
  28631. renderingBuffers.setSize (1, 1);
  28632. midiBuffers.clear();
  28633. currentAudioInputBuffer = 0;
  28634. currentAudioOutputBuffer.setSize (1, 1);
  28635. currentMidiInputBuffer = 0;
  28636. currentMidiOutputBuffer.clear();
  28637. }
  28638. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28639. {
  28640. const int numSamples = buffer.getNumSamples();
  28641. const ScopedLock sl (renderLock);
  28642. currentAudioInputBuffer = &buffer;
  28643. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28644. currentAudioOutputBuffer.clear();
  28645. currentMidiInputBuffer = &midiMessages;
  28646. currentMidiOutputBuffer.clear();
  28647. int i;
  28648. for (i = 0; i < renderingOps.size(); ++i)
  28649. {
  28650. GraphRenderingOps::AudioGraphRenderingOp* const op
  28651. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28652. op->perform (renderingBuffers, midiBuffers, numSamples);
  28653. }
  28654. for (i = 0; i < buffer.getNumChannels(); ++i)
  28655. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28656. midiMessages.clear();
  28657. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28658. }
  28659. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28660. {
  28661. return "Input " + String (channelIndex + 1);
  28662. }
  28663. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28664. {
  28665. return "Output " + String (channelIndex + 1);
  28666. }
  28667. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28668. {
  28669. return true;
  28670. }
  28671. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28672. {
  28673. return true;
  28674. }
  28675. bool AudioProcessorGraph::acceptsMidi() const
  28676. {
  28677. return true;
  28678. }
  28679. bool AudioProcessorGraph::producesMidi() const
  28680. {
  28681. return true;
  28682. }
  28683. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28684. {
  28685. }
  28686. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28687. {
  28688. }
  28689. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28690. : type (type_),
  28691. graph (0)
  28692. {
  28693. }
  28694. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28695. {
  28696. }
  28697. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28698. {
  28699. switch (type)
  28700. {
  28701. case audioOutputNode:
  28702. return "Audio Output";
  28703. case audioInputNode:
  28704. return "Audio Input";
  28705. case midiOutputNode:
  28706. return "Midi Output";
  28707. case midiInputNode:
  28708. return "Midi Input";
  28709. default:
  28710. break;
  28711. }
  28712. return String::empty;
  28713. }
  28714. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28715. {
  28716. d.name = getName();
  28717. d.uid = d.name.hashCode();
  28718. d.category = "I/O devices";
  28719. d.pluginFormatName = "Internal";
  28720. d.manufacturerName = "Raw Material Software";
  28721. d.version = "1.0";
  28722. d.isInstrument = false;
  28723. d.numInputChannels = getNumInputChannels();
  28724. if (type == audioOutputNode && graph != 0)
  28725. d.numInputChannels = graph->getNumInputChannels();
  28726. d.numOutputChannels = getNumOutputChannels();
  28727. if (type == audioInputNode && graph != 0)
  28728. d.numOutputChannels = graph->getNumOutputChannels();
  28729. }
  28730. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  28731. {
  28732. jassert (graph != 0);
  28733. }
  28734. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  28735. {
  28736. }
  28737. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  28738. MidiBuffer& midiMessages)
  28739. {
  28740. jassert (graph != 0);
  28741. switch (type)
  28742. {
  28743. case audioOutputNode:
  28744. {
  28745. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  28746. buffer.getNumChannels()); --i >= 0;)
  28747. {
  28748. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  28749. }
  28750. break;
  28751. }
  28752. case audioInputNode:
  28753. {
  28754. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  28755. buffer.getNumChannels()); --i >= 0;)
  28756. {
  28757. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  28758. }
  28759. break;
  28760. }
  28761. case midiOutputNode:
  28762. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  28763. break;
  28764. case midiInputNode:
  28765. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  28766. break;
  28767. default:
  28768. break;
  28769. }
  28770. }
  28771. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  28772. {
  28773. return type == midiOutputNode;
  28774. }
  28775. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  28776. {
  28777. return type == midiInputNode;
  28778. }
  28779. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  28780. {
  28781. switch (type)
  28782. {
  28783. case audioOutputNode:
  28784. return "Output " + String (channelIndex + 1);
  28785. case midiOutputNode:
  28786. return "Midi Output";
  28787. default:
  28788. break;
  28789. }
  28790. return String::empty;
  28791. }
  28792. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  28793. {
  28794. switch (type)
  28795. {
  28796. case audioInputNode:
  28797. return "Input " + String (channelIndex + 1);
  28798. case midiInputNode:
  28799. return "Midi Input";
  28800. default:
  28801. break;
  28802. }
  28803. return String::empty;
  28804. }
  28805. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  28806. {
  28807. return type == audioInputNode || type == audioOutputNode;
  28808. }
  28809. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  28810. {
  28811. return isInputChannelStereoPair (index);
  28812. }
  28813. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  28814. {
  28815. return type == audioInputNode || type == midiInputNode;
  28816. }
  28817. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  28818. {
  28819. return type == audioOutputNode || type == midiOutputNode;
  28820. }
  28821. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  28822. {
  28823. return 0;
  28824. }
  28825. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  28826. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  28827. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  28828. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  28829. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  28830. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  28831. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  28832. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  28833. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  28834. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  28835. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  28836. {
  28837. }
  28838. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  28839. {
  28840. }
  28841. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  28842. {
  28843. graph = newGraph;
  28844. if (graph != 0)
  28845. {
  28846. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  28847. type == audioInputNode ? graph->getNumInputChannels() : 0,
  28848. getSampleRate(),
  28849. getBlockSize());
  28850. updateHostDisplay();
  28851. }
  28852. }
  28853. END_JUCE_NAMESPACE
  28854. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  28855. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28856. BEGIN_JUCE_NAMESPACE
  28857. AudioProcessorPlayer::AudioProcessorPlayer()
  28858. : processor (0),
  28859. sampleRate (0),
  28860. blockSize (0),
  28861. isPrepared (false),
  28862. numInputChans (0),
  28863. numOutputChans (0),
  28864. tempBuffer (1, 1)
  28865. {
  28866. }
  28867. AudioProcessorPlayer::~AudioProcessorPlayer()
  28868. {
  28869. setProcessor (0);
  28870. }
  28871. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  28872. {
  28873. if (processor != processorToPlay)
  28874. {
  28875. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  28876. {
  28877. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  28878. sampleRate, blockSize);
  28879. processorToPlay->prepareToPlay (sampleRate, blockSize);
  28880. }
  28881. AudioProcessor* oldOne;
  28882. {
  28883. const ScopedLock sl (lock);
  28884. oldOne = isPrepared ? processor : 0;
  28885. processor = processorToPlay;
  28886. isPrepared = true;
  28887. }
  28888. if (oldOne != 0)
  28889. oldOne->releaseResources();
  28890. }
  28891. }
  28892. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  28893. int numInputChannels,
  28894. float** outputChannelData,
  28895. int numOutputChannels,
  28896. int numSamples)
  28897. {
  28898. // these should have been prepared by audioDeviceAboutToStart()...
  28899. jassert (sampleRate > 0 && blockSize > 0);
  28900. incomingMidi.clear();
  28901. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  28902. int i, totalNumChans = 0;
  28903. if (numInputChannels > numOutputChannels)
  28904. {
  28905. // if there aren't enough output channels for the number of
  28906. // inputs, we need to create some temporary extra ones (can't
  28907. // use the input data in case it gets written to)
  28908. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  28909. false, false, true);
  28910. for (i = 0; i < numOutputChannels; ++i)
  28911. {
  28912. channels[totalNumChans] = outputChannelData[i];
  28913. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28914. ++totalNumChans;
  28915. }
  28916. for (i = numOutputChannels; i < numInputChannels; ++i)
  28917. {
  28918. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  28919. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28920. ++totalNumChans;
  28921. }
  28922. }
  28923. else
  28924. {
  28925. for (i = 0; i < numInputChannels; ++i)
  28926. {
  28927. channels[totalNumChans] = outputChannelData[i];
  28928. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  28929. ++totalNumChans;
  28930. }
  28931. for (i = numInputChannels; i < numOutputChannels; ++i)
  28932. {
  28933. channels[totalNumChans] = outputChannelData[i];
  28934. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  28935. ++totalNumChans;
  28936. }
  28937. }
  28938. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  28939. const ScopedLock sl (lock);
  28940. if (processor != 0)
  28941. processor->processBlock (buffer, incomingMidi);
  28942. }
  28943. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  28944. {
  28945. const ScopedLock sl (lock);
  28946. sampleRate = device->getCurrentSampleRate();
  28947. blockSize = device->getCurrentBufferSizeSamples();
  28948. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  28949. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  28950. messageCollector.reset (sampleRate);
  28951. zeromem (channels, sizeof (channels));
  28952. if (processor != 0)
  28953. {
  28954. if (isPrepared)
  28955. processor->releaseResources();
  28956. AudioProcessor* const oldProcessor = processor;
  28957. setProcessor (0);
  28958. setProcessor (oldProcessor);
  28959. }
  28960. }
  28961. void AudioProcessorPlayer::audioDeviceStopped()
  28962. {
  28963. const ScopedLock sl (lock);
  28964. if (processor != 0 && isPrepared)
  28965. processor->releaseResources();
  28966. sampleRate = 0.0;
  28967. blockSize = 0;
  28968. isPrepared = false;
  28969. tempBuffer.setSize (1, 1);
  28970. }
  28971. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  28972. {
  28973. messageCollector.addMessageToQueue (message);
  28974. }
  28975. END_JUCE_NAMESPACE
  28976. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  28977. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  28978. BEGIN_JUCE_NAMESPACE
  28979. class ProcessorParameterPropertyComp : public PropertyComponent,
  28980. public AudioProcessorListener,
  28981. public AsyncUpdater
  28982. {
  28983. public:
  28984. ProcessorParameterPropertyComp (const String& name,
  28985. AudioProcessor* const owner_,
  28986. const int index_)
  28987. : PropertyComponent (name),
  28988. owner (owner_),
  28989. index (index_)
  28990. {
  28991. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  28992. owner_->addListener (this);
  28993. }
  28994. ~ProcessorParameterPropertyComp()
  28995. {
  28996. owner->removeListener (this);
  28997. deleteAllChildren();
  28998. }
  28999. void refresh()
  29000. {
  29001. slider->setValue (owner->getParameter (index), false);
  29002. }
  29003. void audioProcessorChanged (AudioProcessor*) {}
  29004. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29005. {
  29006. if (parameterIndex == index)
  29007. triggerAsyncUpdate();
  29008. }
  29009. void handleAsyncUpdate()
  29010. {
  29011. refresh();
  29012. }
  29013. juce_UseDebuggingNewOperator
  29014. private:
  29015. AudioProcessor* const owner;
  29016. const int index;
  29017. Slider* slider;
  29018. class ParamSlider : public Slider
  29019. {
  29020. public:
  29021. ParamSlider (AudioProcessor* const owner_, const int index_)
  29022. : Slider (String::empty),
  29023. owner (owner_),
  29024. index (index_)
  29025. {
  29026. setRange (0.0, 1.0, 0.0);
  29027. setSliderStyle (Slider::LinearBar);
  29028. setTextBoxIsEditable (false);
  29029. setScrollWheelEnabled (false);
  29030. }
  29031. ~ParamSlider()
  29032. {
  29033. }
  29034. void valueChanged()
  29035. {
  29036. const float newVal = (float) getValue();
  29037. if (owner->getParameter (index) != newVal)
  29038. owner->setParameter (index, newVal);
  29039. }
  29040. const String getTextFromValue (double /*value*/)
  29041. {
  29042. return owner->getParameterText (index);
  29043. }
  29044. juce_UseDebuggingNewOperator
  29045. private:
  29046. AudioProcessor* const owner;
  29047. const int index;
  29048. ParamSlider (const ParamSlider&);
  29049. ParamSlider& operator= (const ParamSlider&);
  29050. };
  29051. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29052. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29053. };
  29054. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29055. : AudioProcessorEditor (owner_)
  29056. {
  29057. setOpaque (true);
  29058. addAndMakeVisible (panel = new PropertyPanel());
  29059. Array <PropertyComponent*> params;
  29060. const int numParams = owner_->getNumParameters();
  29061. int totalHeight = 0;
  29062. for (int i = 0; i < numParams; ++i)
  29063. {
  29064. String name (owner_->getParameterName (i));
  29065. if (name.trim().isEmpty())
  29066. name = "Unnamed";
  29067. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29068. params.add (pc);
  29069. totalHeight += pc->getPreferredHeight();
  29070. }
  29071. panel->addProperties (params);
  29072. setSize (400, jlimit (25, 400, totalHeight));
  29073. }
  29074. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29075. {
  29076. deleteAllChildren();
  29077. }
  29078. void GenericAudioProcessorEditor::paint (Graphics& g)
  29079. {
  29080. g.fillAll (Colours::white);
  29081. }
  29082. void GenericAudioProcessorEditor::resized()
  29083. {
  29084. panel->setSize (getWidth(), getHeight());
  29085. }
  29086. END_JUCE_NAMESPACE
  29087. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29088. /*** Start of inlined file: juce_Sampler.cpp ***/
  29089. BEGIN_JUCE_NAMESPACE
  29090. SamplerSound::SamplerSound (const String& name_,
  29091. AudioFormatReader& source,
  29092. const BigInteger& midiNotes_,
  29093. const int midiNoteForNormalPitch,
  29094. const double attackTimeSecs,
  29095. const double releaseTimeSecs,
  29096. const double maxSampleLengthSeconds)
  29097. : name (name_),
  29098. midiNotes (midiNotes_),
  29099. midiRootNote (midiNoteForNormalPitch)
  29100. {
  29101. sourceSampleRate = source.sampleRate;
  29102. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29103. {
  29104. length = 0;
  29105. attackSamples = 0;
  29106. releaseSamples = 0;
  29107. }
  29108. else
  29109. {
  29110. length = jmin ((int) source.lengthInSamples,
  29111. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29112. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29113. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29114. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29115. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29116. }
  29117. }
  29118. SamplerSound::~SamplerSound()
  29119. {
  29120. }
  29121. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29122. {
  29123. return midiNotes [midiNoteNumber];
  29124. }
  29125. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29126. {
  29127. return true;
  29128. }
  29129. SamplerVoice::SamplerVoice()
  29130. : pitchRatio (0.0),
  29131. sourceSamplePosition (0.0),
  29132. lgain (0.0f),
  29133. rgain (0.0f),
  29134. isInAttack (false),
  29135. isInRelease (false)
  29136. {
  29137. }
  29138. SamplerVoice::~SamplerVoice()
  29139. {
  29140. }
  29141. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29142. {
  29143. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29144. }
  29145. void SamplerVoice::startNote (const int midiNoteNumber,
  29146. const float velocity,
  29147. SynthesiserSound* s,
  29148. const int /*currentPitchWheelPosition*/)
  29149. {
  29150. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29151. jassert (sound != 0); // this object can only play SamplerSounds!
  29152. if (sound != 0)
  29153. {
  29154. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29155. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29156. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29157. sourceSamplePosition = 0.0;
  29158. lgain = velocity;
  29159. rgain = velocity;
  29160. isInAttack = (sound->attackSamples > 0);
  29161. isInRelease = false;
  29162. if (isInAttack)
  29163. {
  29164. attackReleaseLevel = 0.0f;
  29165. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29166. }
  29167. else
  29168. {
  29169. attackReleaseLevel = 1.0f;
  29170. attackDelta = 0.0f;
  29171. }
  29172. if (sound->releaseSamples > 0)
  29173. {
  29174. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29175. }
  29176. else
  29177. {
  29178. releaseDelta = 0.0f;
  29179. }
  29180. }
  29181. }
  29182. void SamplerVoice::stopNote (const bool allowTailOff)
  29183. {
  29184. if (allowTailOff)
  29185. {
  29186. isInAttack = false;
  29187. isInRelease = true;
  29188. }
  29189. else
  29190. {
  29191. clearCurrentNote();
  29192. }
  29193. }
  29194. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29195. {
  29196. }
  29197. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29198. const int /*newValue*/)
  29199. {
  29200. }
  29201. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29202. {
  29203. const SamplerSound* const playingSound = static_cast <SamplerSound*> (getCurrentlyPlayingSound().getObject());
  29204. if (playingSound != 0)
  29205. {
  29206. const float* const inL = playingSound->data->getSampleData (0, 0);
  29207. const float* const inR = playingSound->data->getNumChannels() > 1
  29208. ? playingSound->data->getSampleData (1, 0) : 0;
  29209. float* outL = outputBuffer.getSampleData (0, startSample);
  29210. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29211. while (--numSamples >= 0)
  29212. {
  29213. const int pos = (int) sourceSamplePosition;
  29214. const float alpha = (float) (sourceSamplePosition - pos);
  29215. const float invAlpha = 1.0f - alpha;
  29216. // just using a very simple linear interpolation here..
  29217. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29218. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29219. : l;
  29220. l *= lgain;
  29221. r *= rgain;
  29222. if (isInAttack)
  29223. {
  29224. l *= attackReleaseLevel;
  29225. r *= attackReleaseLevel;
  29226. attackReleaseLevel += attackDelta;
  29227. if (attackReleaseLevel >= 1.0f)
  29228. {
  29229. attackReleaseLevel = 1.0f;
  29230. isInAttack = false;
  29231. }
  29232. }
  29233. else if (isInRelease)
  29234. {
  29235. l *= attackReleaseLevel;
  29236. r *= attackReleaseLevel;
  29237. attackReleaseLevel += releaseDelta;
  29238. if (attackReleaseLevel <= 0.0f)
  29239. {
  29240. stopNote (false);
  29241. break;
  29242. }
  29243. }
  29244. if (outR != 0)
  29245. {
  29246. *outL++ += l;
  29247. *outR++ += r;
  29248. }
  29249. else
  29250. {
  29251. *outL++ += (l + r) * 0.5f;
  29252. }
  29253. sourceSamplePosition += pitchRatio;
  29254. if (sourceSamplePosition > playingSound->length)
  29255. {
  29256. stopNote (false);
  29257. break;
  29258. }
  29259. }
  29260. }
  29261. }
  29262. END_JUCE_NAMESPACE
  29263. /*** End of inlined file: juce_Sampler.cpp ***/
  29264. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29265. BEGIN_JUCE_NAMESPACE
  29266. SynthesiserSound::SynthesiserSound()
  29267. {
  29268. }
  29269. SynthesiserSound::~SynthesiserSound()
  29270. {
  29271. }
  29272. SynthesiserVoice::SynthesiserVoice()
  29273. : currentSampleRate (44100.0),
  29274. currentlyPlayingNote (-1),
  29275. noteOnTime (0),
  29276. currentlyPlayingSound (0)
  29277. {
  29278. }
  29279. SynthesiserVoice::~SynthesiserVoice()
  29280. {
  29281. }
  29282. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29283. {
  29284. return currentlyPlayingSound != 0
  29285. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29286. }
  29287. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29288. {
  29289. currentSampleRate = newRate;
  29290. }
  29291. void SynthesiserVoice::clearCurrentNote()
  29292. {
  29293. currentlyPlayingNote = -1;
  29294. currentlyPlayingSound = 0;
  29295. }
  29296. Synthesiser::Synthesiser()
  29297. : sampleRate (0),
  29298. lastNoteOnCounter (0),
  29299. shouldStealNotes (true)
  29300. {
  29301. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29302. lastPitchWheelValues[i] = 0x2000;
  29303. }
  29304. Synthesiser::~Synthesiser()
  29305. {
  29306. }
  29307. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29308. {
  29309. const ScopedLock sl (lock);
  29310. return voices [index];
  29311. }
  29312. void Synthesiser::clearVoices()
  29313. {
  29314. const ScopedLock sl (lock);
  29315. voices.clear();
  29316. }
  29317. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29318. {
  29319. const ScopedLock sl (lock);
  29320. voices.add (newVoice);
  29321. }
  29322. void Synthesiser::removeVoice (const int index)
  29323. {
  29324. const ScopedLock sl (lock);
  29325. voices.remove (index);
  29326. }
  29327. void Synthesiser::clearSounds()
  29328. {
  29329. const ScopedLock sl (lock);
  29330. sounds.clear();
  29331. }
  29332. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29333. {
  29334. const ScopedLock sl (lock);
  29335. sounds.add (newSound);
  29336. }
  29337. void Synthesiser::removeSound (const int index)
  29338. {
  29339. const ScopedLock sl (lock);
  29340. sounds.remove (index);
  29341. }
  29342. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29343. {
  29344. shouldStealNotes = shouldStealNotes_;
  29345. }
  29346. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29347. {
  29348. if (sampleRate != newRate)
  29349. {
  29350. const ScopedLock sl (lock);
  29351. allNotesOff (0, false);
  29352. sampleRate = newRate;
  29353. for (int i = voices.size(); --i >= 0;)
  29354. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29355. }
  29356. }
  29357. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29358. const MidiBuffer& midiData,
  29359. int startSample,
  29360. int numSamples)
  29361. {
  29362. // must set the sample rate before using this!
  29363. jassert (sampleRate != 0);
  29364. const ScopedLock sl (lock);
  29365. MidiBuffer::Iterator midiIterator (midiData);
  29366. midiIterator.setNextSamplePosition (startSample);
  29367. MidiMessage m (0xf4, 0.0);
  29368. while (numSamples > 0)
  29369. {
  29370. int midiEventPos;
  29371. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29372. && midiEventPos < startSample + numSamples;
  29373. const int numThisTime = useEvent ? midiEventPos - startSample
  29374. : numSamples;
  29375. if (numThisTime > 0)
  29376. {
  29377. for (int i = voices.size(); --i >= 0;)
  29378. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29379. }
  29380. if (useEvent)
  29381. {
  29382. if (m.isNoteOn())
  29383. {
  29384. const int channel = m.getChannel();
  29385. noteOn (channel,
  29386. m.getNoteNumber(),
  29387. m.getFloatVelocity());
  29388. }
  29389. else if (m.isNoteOff())
  29390. {
  29391. noteOff (m.getChannel(),
  29392. m.getNoteNumber(),
  29393. true);
  29394. }
  29395. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29396. {
  29397. allNotesOff (m.getChannel(), true);
  29398. }
  29399. else if (m.isPitchWheel())
  29400. {
  29401. const int channel = m.getChannel();
  29402. const int wheelPos = m.getPitchWheelValue();
  29403. lastPitchWheelValues [channel - 1] = wheelPos;
  29404. handlePitchWheel (channel, wheelPos);
  29405. }
  29406. else if (m.isController())
  29407. {
  29408. handleController (m.getChannel(),
  29409. m.getControllerNumber(),
  29410. m.getControllerValue());
  29411. }
  29412. }
  29413. startSample += numThisTime;
  29414. numSamples -= numThisTime;
  29415. }
  29416. }
  29417. void Synthesiser::noteOn (const int midiChannel,
  29418. const int midiNoteNumber,
  29419. const float velocity)
  29420. {
  29421. const ScopedLock sl (lock);
  29422. for (int i = sounds.size(); --i >= 0;)
  29423. {
  29424. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29425. if (sound->appliesToNote (midiNoteNumber)
  29426. && sound->appliesToChannel (midiChannel))
  29427. {
  29428. startVoice (findFreeVoice (sound, shouldStealNotes),
  29429. sound, midiChannel, midiNoteNumber, velocity);
  29430. }
  29431. }
  29432. }
  29433. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29434. SynthesiserSound* const sound,
  29435. const int midiChannel,
  29436. const int midiNoteNumber,
  29437. const float velocity)
  29438. {
  29439. if (voice != 0 && sound != 0)
  29440. {
  29441. if (voice->currentlyPlayingSound != 0)
  29442. voice->stopNote (false);
  29443. voice->startNote (midiNoteNumber,
  29444. velocity,
  29445. sound,
  29446. lastPitchWheelValues [midiChannel - 1]);
  29447. voice->currentlyPlayingNote = midiNoteNumber;
  29448. voice->noteOnTime = ++lastNoteOnCounter;
  29449. voice->currentlyPlayingSound = sound;
  29450. }
  29451. }
  29452. void Synthesiser::noteOff (const int midiChannel,
  29453. const int midiNoteNumber,
  29454. const bool allowTailOff)
  29455. {
  29456. const ScopedLock sl (lock);
  29457. for (int i = voices.size(); --i >= 0;)
  29458. {
  29459. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29460. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29461. {
  29462. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29463. if (sound != 0
  29464. && sound->appliesToNote (midiNoteNumber)
  29465. && sound->appliesToChannel (midiChannel))
  29466. {
  29467. voice->stopNote (allowTailOff);
  29468. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29469. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29470. }
  29471. }
  29472. }
  29473. }
  29474. void Synthesiser::allNotesOff (const int midiChannel,
  29475. const bool allowTailOff)
  29476. {
  29477. const ScopedLock sl (lock);
  29478. for (int i = voices.size(); --i >= 0;)
  29479. {
  29480. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29481. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29482. voice->stopNote (allowTailOff);
  29483. }
  29484. }
  29485. void Synthesiser::handlePitchWheel (const int midiChannel,
  29486. const int wheelValue)
  29487. {
  29488. const ScopedLock sl (lock);
  29489. for (int i = voices.size(); --i >= 0;)
  29490. {
  29491. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29492. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29493. {
  29494. voice->pitchWheelMoved (wheelValue);
  29495. }
  29496. }
  29497. }
  29498. void Synthesiser::handleController (const int midiChannel,
  29499. const int controllerNumber,
  29500. const int controllerValue)
  29501. {
  29502. const ScopedLock sl (lock);
  29503. for (int i = voices.size(); --i >= 0;)
  29504. {
  29505. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29506. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29507. voice->controllerMoved (controllerNumber, controllerValue);
  29508. }
  29509. }
  29510. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29511. const bool stealIfNoneAvailable) const
  29512. {
  29513. const ScopedLock sl (lock);
  29514. for (int i = voices.size(); --i >= 0;)
  29515. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29516. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29517. return voices.getUnchecked (i);
  29518. if (stealIfNoneAvailable)
  29519. {
  29520. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29521. SynthesiserVoice* oldest = 0;
  29522. for (int i = voices.size(); --i >= 0;)
  29523. {
  29524. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29525. if (voice->canPlaySound (soundToPlay)
  29526. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29527. oldest = voice;
  29528. }
  29529. jassert (oldest != 0);
  29530. return oldest;
  29531. }
  29532. return 0;
  29533. }
  29534. END_JUCE_NAMESPACE
  29535. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29536. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29537. BEGIN_JUCE_NAMESPACE
  29538. ActionBroadcaster::ActionBroadcaster() throw()
  29539. {
  29540. // are you trying to create this object before or after juce has been intialised??
  29541. jassert (MessageManager::instance != 0);
  29542. }
  29543. ActionBroadcaster::~ActionBroadcaster()
  29544. {
  29545. // all event-based objects must be deleted BEFORE juce is shut down!
  29546. jassert (MessageManager::instance != 0);
  29547. }
  29548. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29549. {
  29550. actionListenerList.addActionListener (listener);
  29551. }
  29552. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29553. {
  29554. jassert (actionListenerList.isValidMessageListener());
  29555. if (actionListenerList.isValidMessageListener())
  29556. actionListenerList.removeActionListener (listener);
  29557. }
  29558. void ActionBroadcaster::removeAllActionListeners()
  29559. {
  29560. actionListenerList.removeAllActionListeners();
  29561. }
  29562. void ActionBroadcaster::sendActionMessage (const String& message) const
  29563. {
  29564. actionListenerList.sendActionMessage (message);
  29565. }
  29566. END_JUCE_NAMESPACE
  29567. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29568. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29569. BEGIN_JUCE_NAMESPACE
  29570. // special message of our own with a string in it
  29571. class ActionMessage : public Message
  29572. {
  29573. public:
  29574. const String message;
  29575. ActionMessage (const String& messageText,
  29576. void* const listener_) throw()
  29577. : message (messageText)
  29578. {
  29579. pointerParameter = listener_;
  29580. }
  29581. ~ActionMessage() throw()
  29582. {
  29583. }
  29584. private:
  29585. ActionMessage (const ActionMessage&);
  29586. ActionMessage& operator= (const ActionMessage&);
  29587. };
  29588. ActionListenerList::ActionListenerList() throw()
  29589. {
  29590. }
  29591. ActionListenerList::~ActionListenerList() throw()
  29592. {
  29593. }
  29594. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29595. {
  29596. const ScopedLock sl (actionListenerLock_);
  29597. jassert (listener != 0);
  29598. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29599. if (listener != 0)
  29600. actionListeners_.add (listener);
  29601. }
  29602. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29603. {
  29604. const ScopedLock sl (actionListenerLock_);
  29605. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29606. actionListeners_.removeValue (listener);
  29607. }
  29608. void ActionListenerList::removeAllActionListeners() throw()
  29609. {
  29610. const ScopedLock sl (actionListenerLock_);
  29611. actionListeners_.clear();
  29612. }
  29613. void ActionListenerList::sendActionMessage (const String& message) const
  29614. {
  29615. const ScopedLock sl (actionListenerLock_);
  29616. for (int i = actionListeners_.size(); --i >= 0;)
  29617. postMessage (new ActionMessage (message, static_cast <ActionListener*> (actionListeners_.getUnchecked(i))));
  29618. }
  29619. void ActionListenerList::handleMessage (const Message& message)
  29620. {
  29621. const ActionMessage& am = (const ActionMessage&) message;
  29622. if (actionListeners_.contains (am.pointerParameter))
  29623. static_cast <ActionListener*> (am.pointerParameter)->actionListenerCallback (am.message);
  29624. }
  29625. END_JUCE_NAMESPACE
  29626. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29627. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29628. BEGIN_JUCE_NAMESPACE
  29629. AsyncUpdater::AsyncUpdater() throw()
  29630. : asyncMessagePending (false)
  29631. {
  29632. internalAsyncHandler.owner = this;
  29633. }
  29634. AsyncUpdater::~AsyncUpdater()
  29635. {
  29636. }
  29637. void AsyncUpdater::triggerAsyncUpdate() throw()
  29638. {
  29639. if (! asyncMessagePending)
  29640. {
  29641. asyncMessagePending = true;
  29642. internalAsyncHandler.postMessage (new Message());
  29643. }
  29644. }
  29645. void AsyncUpdater::cancelPendingUpdate() throw()
  29646. {
  29647. asyncMessagePending = false;
  29648. }
  29649. void AsyncUpdater::handleUpdateNowIfNeeded()
  29650. {
  29651. if (asyncMessagePending)
  29652. {
  29653. asyncMessagePending = false;
  29654. handleAsyncUpdate();
  29655. }
  29656. }
  29657. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29658. {
  29659. owner->handleUpdateNowIfNeeded();
  29660. }
  29661. END_JUCE_NAMESPACE
  29662. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29663. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29664. BEGIN_JUCE_NAMESPACE
  29665. ChangeBroadcaster::ChangeBroadcaster() throw()
  29666. {
  29667. // are you trying to create this object before or after juce has been intialised??
  29668. jassert (MessageManager::instance != 0);
  29669. }
  29670. ChangeBroadcaster::~ChangeBroadcaster()
  29671. {
  29672. // all event-based objects must be deleted BEFORE juce is shut down!
  29673. jassert (MessageManager::instance != 0);
  29674. }
  29675. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29676. {
  29677. changeListenerList.addChangeListener (listener);
  29678. }
  29679. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29680. {
  29681. jassert (changeListenerList.isValidMessageListener());
  29682. if (changeListenerList.isValidMessageListener())
  29683. changeListenerList.removeChangeListener (listener);
  29684. }
  29685. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29686. {
  29687. changeListenerList.removeAllChangeListeners();
  29688. }
  29689. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29690. {
  29691. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29692. }
  29693. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29694. {
  29695. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29696. }
  29697. void ChangeBroadcaster::dispatchPendingMessages()
  29698. {
  29699. changeListenerList.dispatchPendingMessages();
  29700. }
  29701. END_JUCE_NAMESPACE
  29702. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29703. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29704. BEGIN_JUCE_NAMESPACE
  29705. ChangeListenerList::ChangeListenerList() throw()
  29706. : lastChangedObject (0),
  29707. messagePending (false)
  29708. {
  29709. }
  29710. ChangeListenerList::~ChangeListenerList() throw()
  29711. {
  29712. }
  29713. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29714. {
  29715. const ScopedLock sl (lock);
  29716. jassert (listener != 0);
  29717. if (listener != 0)
  29718. listeners.add (listener);
  29719. }
  29720. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  29721. {
  29722. const ScopedLock sl (lock);
  29723. listeners.removeValue (listener);
  29724. }
  29725. void ChangeListenerList::removeAllChangeListeners() throw()
  29726. {
  29727. const ScopedLock sl (lock);
  29728. listeners.clear();
  29729. }
  29730. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  29731. {
  29732. const ScopedLock sl (lock);
  29733. if ((! messagePending) && (listeners.size() > 0))
  29734. {
  29735. lastChangedObject = objectThatHasChanged;
  29736. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  29737. messagePending = true;
  29738. }
  29739. }
  29740. void ChangeListenerList::handleMessage (const Message& message)
  29741. {
  29742. sendSynchronousChangeMessage (message.pointerParameter);
  29743. }
  29744. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  29745. {
  29746. const ScopedLock sl (lock);
  29747. messagePending = false;
  29748. for (int i = listeners.size(); --i >= 0;)
  29749. {
  29750. ChangeListener* const l = static_cast <ChangeListener*> (listeners.getUnchecked (i));
  29751. {
  29752. const ScopedUnlock tempUnlocker (lock);
  29753. l->changeListenerCallback (objectThatHasChanged);
  29754. }
  29755. i = jmin (i, listeners.size());
  29756. }
  29757. }
  29758. void ChangeListenerList::dispatchPendingMessages()
  29759. {
  29760. if (messagePending)
  29761. sendSynchronousChangeMessage (lastChangedObject);
  29762. }
  29763. END_JUCE_NAMESPACE
  29764. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  29765. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  29766. BEGIN_JUCE_NAMESPACE
  29767. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  29768. const uint32 magicMessageHeaderNumber)
  29769. : Thread ("Juce IPC connection"),
  29770. callbackConnectionState (false),
  29771. useMessageThread (callbacksOnMessageThread),
  29772. magicMessageHeader (magicMessageHeaderNumber),
  29773. pipeReceiveMessageTimeout (-1)
  29774. {
  29775. }
  29776. InterprocessConnection::~InterprocessConnection()
  29777. {
  29778. callbackConnectionState = false;
  29779. disconnect();
  29780. }
  29781. bool InterprocessConnection::connectToSocket (const String& hostName,
  29782. const int portNumber,
  29783. const int timeOutMillisecs)
  29784. {
  29785. disconnect();
  29786. const ScopedLock sl (pipeAndSocketLock);
  29787. socket = new StreamingSocket();
  29788. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  29789. {
  29790. connectionMadeInt();
  29791. startThread();
  29792. return true;
  29793. }
  29794. else
  29795. {
  29796. socket = 0;
  29797. return false;
  29798. }
  29799. }
  29800. bool InterprocessConnection::connectToPipe (const String& pipeName,
  29801. const int pipeReceiveMessageTimeoutMs)
  29802. {
  29803. disconnect();
  29804. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29805. if (newPipe->openExisting (pipeName))
  29806. {
  29807. const ScopedLock sl (pipeAndSocketLock);
  29808. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29809. initialiseWithPipe (newPipe.release());
  29810. return true;
  29811. }
  29812. return false;
  29813. }
  29814. bool InterprocessConnection::createPipe (const String& pipeName,
  29815. const int pipeReceiveMessageTimeoutMs)
  29816. {
  29817. disconnect();
  29818. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  29819. if (newPipe->createNewPipe (pipeName))
  29820. {
  29821. const ScopedLock sl (pipeAndSocketLock);
  29822. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  29823. initialiseWithPipe (newPipe.release());
  29824. return true;
  29825. }
  29826. return false;
  29827. }
  29828. void InterprocessConnection::disconnect()
  29829. {
  29830. if (socket != 0)
  29831. socket->close();
  29832. if (pipe != 0)
  29833. {
  29834. pipe->cancelPendingReads();
  29835. pipe->close();
  29836. }
  29837. stopThread (4000);
  29838. {
  29839. const ScopedLock sl (pipeAndSocketLock);
  29840. socket = 0;
  29841. pipe = 0;
  29842. }
  29843. connectionLostInt();
  29844. }
  29845. bool InterprocessConnection::isConnected() const
  29846. {
  29847. const ScopedLock sl (pipeAndSocketLock);
  29848. return ((socket != 0 && socket->isConnected())
  29849. || (pipe != 0 && pipe->isOpen()))
  29850. && isThreadRunning();
  29851. }
  29852. const String InterprocessConnection::getConnectedHostName() const
  29853. {
  29854. if (pipe != 0)
  29855. {
  29856. return "localhost";
  29857. }
  29858. else if (socket != 0)
  29859. {
  29860. if (! socket->isLocal())
  29861. return socket->getHostName();
  29862. return "localhost";
  29863. }
  29864. return String::empty;
  29865. }
  29866. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  29867. {
  29868. uint32 messageHeader[2];
  29869. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  29870. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  29871. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  29872. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  29873. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  29874. size_t bytesWritten = 0;
  29875. const ScopedLock sl (pipeAndSocketLock);
  29876. if (socket != 0)
  29877. {
  29878. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  29879. }
  29880. else if (pipe != 0)
  29881. {
  29882. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  29883. }
  29884. if (bytesWritten < 0)
  29885. {
  29886. // error..
  29887. return false;
  29888. }
  29889. return (bytesWritten == messageData.getSize());
  29890. }
  29891. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  29892. {
  29893. jassert (socket == 0);
  29894. socket = socket_;
  29895. connectionMadeInt();
  29896. startThread();
  29897. }
  29898. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  29899. {
  29900. jassert (pipe == 0);
  29901. pipe = pipe_;
  29902. connectionMadeInt();
  29903. startThread();
  29904. }
  29905. const int messageMagicNumber = 0xb734128b;
  29906. void InterprocessConnection::handleMessage (const Message& message)
  29907. {
  29908. if (message.intParameter1 == messageMagicNumber)
  29909. {
  29910. switch (message.intParameter2)
  29911. {
  29912. case 0:
  29913. {
  29914. ScopedPointer <MemoryBlock> data (static_cast <MemoryBlock*> (message.pointerParameter));
  29915. messageReceived (*data);
  29916. break;
  29917. }
  29918. case 1:
  29919. connectionMade();
  29920. break;
  29921. case 2:
  29922. connectionLost();
  29923. break;
  29924. }
  29925. }
  29926. }
  29927. void InterprocessConnection::connectionMadeInt()
  29928. {
  29929. if (! callbackConnectionState)
  29930. {
  29931. callbackConnectionState = true;
  29932. if (useMessageThread)
  29933. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  29934. else
  29935. connectionMade();
  29936. }
  29937. }
  29938. void InterprocessConnection::connectionLostInt()
  29939. {
  29940. if (callbackConnectionState)
  29941. {
  29942. callbackConnectionState = false;
  29943. if (useMessageThread)
  29944. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  29945. else
  29946. connectionLost();
  29947. }
  29948. }
  29949. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  29950. {
  29951. jassert (callbackConnectionState);
  29952. if (useMessageThread)
  29953. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  29954. else
  29955. messageReceived (data);
  29956. }
  29957. bool InterprocessConnection::readNextMessageInt()
  29958. {
  29959. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  29960. uint32 messageHeader[2];
  29961. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  29962. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  29963. if (bytes == sizeof (messageHeader)
  29964. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  29965. {
  29966. int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  29967. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  29968. {
  29969. MemoryBlock messageData (bytesInMessage, true);
  29970. int bytesRead = 0;
  29971. while (bytesInMessage > 0)
  29972. {
  29973. if (threadShouldExit())
  29974. return false;
  29975. const int numThisTime = jmin (bytesInMessage, 65536);
  29976. const int bytesIn = (socket != 0) ? socket->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, true)
  29977. : pipe->read (static_cast <char*> (messageData.getData()) + bytesRead, numThisTime, pipeReceiveMessageTimeout);
  29978. if (bytesIn <= 0)
  29979. break;
  29980. bytesRead += bytesIn;
  29981. bytesInMessage -= bytesIn;
  29982. }
  29983. if (bytesRead >= 0)
  29984. deliverDataInt (messageData);
  29985. }
  29986. }
  29987. else if (bytes < 0)
  29988. {
  29989. {
  29990. const ScopedLock sl (pipeAndSocketLock);
  29991. socket = 0;
  29992. }
  29993. connectionLostInt();
  29994. return false;
  29995. }
  29996. return true;
  29997. }
  29998. void InterprocessConnection::run()
  29999. {
  30000. while (! threadShouldExit())
  30001. {
  30002. if (socket != 0)
  30003. {
  30004. const int ready = socket->waitUntilReady (true, 0);
  30005. if (ready < 0)
  30006. {
  30007. {
  30008. const ScopedLock sl (pipeAndSocketLock);
  30009. socket = 0;
  30010. }
  30011. connectionLostInt();
  30012. break;
  30013. }
  30014. else if (ready > 0)
  30015. {
  30016. if (! readNextMessageInt())
  30017. break;
  30018. }
  30019. else
  30020. {
  30021. Thread::sleep (2);
  30022. }
  30023. }
  30024. else if (pipe != 0)
  30025. {
  30026. if (! pipe->isOpen())
  30027. {
  30028. {
  30029. const ScopedLock sl (pipeAndSocketLock);
  30030. pipe = 0;
  30031. }
  30032. connectionLostInt();
  30033. break;
  30034. }
  30035. else
  30036. {
  30037. if (! readNextMessageInt())
  30038. break;
  30039. }
  30040. }
  30041. else
  30042. {
  30043. break;
  30044. }
  30045. }
  30046. }
  30047. END_JUCE_NAMESPACE
  30048. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30049. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30050. BEGIN_JUCE_NAMESPACE
  30051. InterprocessConnectionServer::InterprocessConnectionServer()
  30052. : Thread ("Juce IPC server")
  30053. {
  30054. }
  30055. InterprocessConnectionServer::~InterprocessConnectionServer()
  30056. {
  30057. stop();
  30058. }
  30059. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30060. {
  30061. stop();
  30062. socket = new StreamingSocket();
  30063. if (socket->createListener (portNumber))
  30064. {
  30065. startThread();
  30066. return true;
  30067. }
  30068. socket = 0;
  30069. return false;
  30070. }
  30071. void InterprocessConnectionServer::stop()
  30072. {
  30073. signalThreadShouldExit();
  30074. if (socket != 0)
  30075. socket->close();
  30076. stopThread (4000);
  30077. socket = 0;
  30078. }
  30079. void InterprocessConnectionServer::run()
  30080. {
  30081. while ((! threadShouldExit()) && socket != 0)
  30082. {
  30083. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30084. if (clientSocket != 0)
  30085. {
  30086. InterprocessConnection* newConnection = createConnectionObject();
  30087. if (newConnection != 0)
  30088. newConnection->initialiseWithSocket (clientSocket.release());
  30089. }
  30090. }
  30091. }
  30092. END_JUCE_NAMESPACE
  30093. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30094. /*** Start of inlined file: juce_Message.cpp ***/
  30095. BEGIN_JUCE_NAMESPACE
  30096. Message::Message() throw()
  30097. : intParameter1 (0),
  30098. intParameter2 (0),
  30099. intParameter3 (0),
  30100. pointerParameter (0)
  30101. {
  30102. }
  30103. Message::Message (const int intParameter1_,
  30104. const int intParameter2_,
  30105. const int intParameter3_,
  30106. void* const pointerParameter_) throw()
  30107. : intParameter1 (intParameter1_),
  30108. intParameter2 (intParameter2_),
  30109. intParameter3 (intParameter3_),
  30110. pointerParameter (pointerParameter_)
  30111. {
  30112. }
  30113. Message::~Message() throw()
  30114. {
  30115. }
  30116. END_JUCE_NAMESPACE
  30117. /*** End of inlined file: juce_Message.cpp ***/
  30118. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30119. BEGIN_JUCE_NAMESPACE
  30120. MessageListener::MessageListener() throw()
  30121. {
  30122. // are you trying to create a messagelistener before or after juce has been intialised??
  30123. jassert (MessageManager::instance != 0);
  30124. if (MessageManager::instance != 0)
  30125. MessageManager::instance->messageListeners.add (this);
  30126. }
  30127. MessageListener::~MessageListener()
  30128. {
  30129. if (MessageManager::instance != 0)
  30130. MessageManager::instance->messageListeners.removeValue (this);
  30131. }
  30132. void MessageListener::postMessage (Message* const message) const throw()
  30133. {
  30134. message->messageRecipient = const_cast <MessageListener*> (this);
  30135. if (MessageManager::instance == 0)
  30136. MessageManager::getInstance();
  30137. MessageManager::instance->postMessageToQueue (message);
  30138. }
  30139. bool MessageListener::isValidMessageListener() const throw()
  30140. {
  30141. return (MessageManager::instance != 0)
  30142. && MessageManager::instance->messageListeners.contains (this);
  30143. }
  30144. END_JUCE_NAMESPACE
  30145. /*** End of inlined file: juce_MessageListener.cpp ***/
  30146. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30147. BEGIN_JUCE_NAMESPACE
  30148. // platform-specific functions..
  30149. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30150. bool juce_postMessageToSystemQueue (void* message);
  30151. MessageManager* MessageManager::instance = 0;
  30152. static const int quitMessageId = 0xfffff321;
  30153. MessageManager::MessageManager() throw()
  30154. : quitMessagePosted (false),
  30155. quitMessageReceived (false),
  30156. threadWithLock (0)
  30157. {
  30158. messageThreadId = Thread::getCurrentThreadId();
  30159. }
  30160. MessageManager::~MessageManager() throw()
  30161. {
  30162. broadcastListeners = 0;
  30163. doPlatformSpecificShutdown();
  30164. jassert (instance == this);
  30165. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30166. }
  30167. MessageManager* MessageManager::getInstance() throw()
  30168. {
  30169. if (instance == 0)
  30170. {
  30171. instance = new MessageManager();
  30172. doPlatformSpecificInitialisation();
  30173. }
  30174. return instance;
  30175. }
  30176. void MessageManager::postMessageToQueue (Message* const message)
  30177. {
  30178. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30179. delete message;
  30180. }
  30181. CallbackMessage::CallbackMessage() throw() {}
  30182. CallbackMessage::~CallbackMessage() throw() {}
  30183. void CallbackMessage::post()
  30184. {
  30185. if (MessageManager::instance != 0)
  30186. MessageManager::instance->postCallbackMessage (this);
  30187. }
  30188. void MessageManager::postCallbackMessage (Message* const message)
  30189. {
  30190. message->messageRecipient = 0;
  30191. postMessageToQueue (message);
  30192. }
  30193. // not for public use..
  30194. void MessageManager::deliverMessage (void* const message)
  30195. {
  30196. const ScopedPointer <Message> m (static_cast <Message*> (message));
  30197. MessageListener* const recipient = m->messageRecipient;
  30198. JUCE_TRY
  30199. {
  30200. if (messageListeners.contains (recipient))
  30201. {
  30202. recipient->handleMessage (*m);
  30203. }
  30204. else if (recipient == 0)
  30205. {
  30206. if (m->intParameter1 == quitMessageId)
  30207. {
  30208. quitMessageReceived = true;
  30209. }
  30210. else
  30211. {
  30212. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> (static_cast <Message*> (m));
  30213. if (cm != 0)
  30214. cm->messageCallback();
  30215. }
  30216. }
  30217. }
  30218. JUCE_CATCH_EXCEPTION
  30219. }
  30220. #if ! (JUCE_MAC || JUCE_IPHONE)
  30221. void MessageManager::runDispatchLoop()
  30222. {
  30223. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30224. runDispatchLoopUntil (-1);
  30225. }
  30226. void MessageManager::stopDispatchLoop()
  30227. {
  30228. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30229. m->messageRecipient = 0;
  30230. postMessageToQueue (m);
  30231. quitMessagePosted = true;
  30232. }
  30233. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30234. {
  30235. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30236. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30237. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30238. && ! quitMessageReceived)
  30239. {
  30240. JUCE_TRY
  30241. {
  30242. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30243. {
  30244. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30245. if (msToWait > 0)
  30246. Thread::sleep (jmin (5, msToWait));
  30247. }
  30248. }
  30249. JUCE_CATCH_EXCEPTION
  30250. }
  30251. return ! quitMessageReceived;
  30252. }
  30253. #endif
  30254. void MessageManager::deliverBroadcastMessage (const String& value)
  30255. {
  30256. if (broadcastListeners != 0)
  30257. broadcastListeners->sendActionMessage (value);
  30258. }
  30259. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30260. {
  30261. if (broadcastListeners == 0)
  30262. broadcastListeners = new ActionListenerList();
  30263. broadcastListeners->addActionListener (listener);
  30264. }
  30265. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30266. {
  30267. if (broadcastListeners != 0)
  30268. broadcastListeners->removeActionListener (listener);
  30269. }
  30270. bool MessageManager::isThisTheMessageThread() const throw()
  30271. {
  30272. return Thread::getCurrentThreadId() == messageThreadId;
  30273. }
  30274. void MessageManager::setCurrentThreadAsMessageThread()
  30275. {
  30276. if (messageThreadId != Thread::getCurrentThreadId())
  30277. {
  30278. messageThreadId = Thread::getCurrentThreadId();
  30279. // This is needed on windows to make sure the message window is created by this thread
  30280. doPlatformSpecificShutdown();
  30281. doPlatformSpecificInitialisation();
  30282. }
  30283. }
  30284. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30285. {
  30286. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30287. return thisThread == messageThreadId || thisThread == threadWithLock;
  30288. }
  30289. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30290. {
  30291. public:
  30292. SharedEvents() {}
  30293. ~SharedEvents() {}
  30294. WaitableEvent lockedEvent, releaseEvent;
  30295. private:
  30296. SharedEvents (const SharedEvents&);
  30297. SharedEvents& operator= (const SharedEvents&);
  30298. };
  30299. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30300. {
  30301. public:
  30302. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30303. ~BlockingMessage() throw() {}
  30304. void messageCallback()
  30305. {
  30306. events->lockedEvent.signal();
  30307. events->releaseEvent.wait();
  30308. }
  30309. juce_UseDebuggingNewOperator
  30310. private:
  30311. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30312. BlockingMessage (const BlockingMessage&);
  30313. BlockingMessage& operator= (const BlockingMessage&);
  30314. };
  30315. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30316. : sharedEvents (0),
  30317. locked (false)
  30318. {
  30319. init (threadToCheck, 0);
  30320. }
  30321. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30322. : sharedEvents (0),
  30323. locked (false)
  30324. {
  30325. init (0, jobToCheckForExitSignal);
  30326. }
  30327. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30328. {
  30329. if (MessageManager::instance != 0)
  30330. {
  30331. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30332. {
  30333. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30334. }
  30335. else
  30336. {
  30337. if (threadToCheck == 0 && job == 0)
  30338. {
  30339. MessageManager::instance->lockingLock.enter();
  30340. }
  30341. else
  30342. {
  30343. while (! MessageManager::instance->lockingLock.tryEnter())
  30344. {
  30345. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30346. || (job != 0 && job->shouldExit()))
  30347. return;
  30348. Thread::sleep (1);
  30349. }
  30350. }
  30351. sharedEvents = new SharedEvents();
  30352. sharedEvents->incReferenceCount();
  30353. (new BlockingMessage (sharedEvents))->post();
  30354. while (! sharedEvents->lockedEvent.wait (50))
  30355. {
  30356. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30357. || (job != 0 && job->shouldExit()))
  30358. {
  30359. sharedEvents->releaseEvent.signal();
  30360. sharedEvents->decReferenceCount();
  30361. sharedEvents = 0;
  30362. MessageManager::instance->lockingLock.exit();
  30363. return;
  30364. }
  30365. }
  30366. jassert (MessageManager::instance->threadWithLock == 0);
  30367. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30368. locked = true;
  30369. }
  30370. }
  30371. }
  30372. MessageManagerLock::~MessageManagerLock() throw()
  30373. {
  30374. if (sharedEvents != 0)
  30375. {
  30376. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30377. sharedEvents->releaseEvent.signal();
  30378. sharedEvents->decReferenceCount();
  30379. if (MessageManager::instance != 0)
  30380. {
  30381. MessageManager::instance->threadWithLock = 0;
  30382. MessageManager::instance->lockingLock.exit();
  30383. }
  30384. }
  30385. }
  30386. END_JUCE_NAMESPACE
  30387. /*** End of inlined file: juce_MessageManager.cpp ***/
  30388. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30389. BEGIN_JUCE_NAMESPACE
  30390. class MultiTimer::MultiTimerCallback : public Timer
  30391. {
  30392. public:
  30393. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30394. : timerId (timerId_),
  30395. owner (owner_)
  30396. {
  30397. }
  30398. ~MultiTimerCallback()
  30399. {
  30400. }
  30401. void timerCallback()
  30402. {
  30403. owner.timerCallback (timerId);
  30404. }
  30405. const int timerId;
  30406. private:
  30407. MultiTimer& owner;
  30408. };
  30409. MultiTimer::MultiTimer() throw()
  30410. {
  30411. }
  30412. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30413. {
  30414. }
  30415. MultiTimer::~MultiTimer()
  30416. {
  30417. const ScopedLock sl (timerListLock);
  30418. timers.clear();
  30419. }
  30420. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30421. {
  30422. const ScopedLock sl (timerListLock);
  30423. for (int i = timers.size(); --i >= 0;)
  30424. {
  30425. MultiTimerCallback* const t = timers.getUnchecked(i);
  30426. if (t->timerId == timerId)
  30427. {
  30428. t->startTimer (intervalInMilliseconds);
  30429. return;
  30430. }
  30431. }
  30432. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30433. timers.add (newTimer);
  30434. newTimer->startTimer (intervalInMilliseconds);
  30435. }
  30436. void MultiTimer::stopTimer (const int timerId) throw()
  30437. {
  30438. const ScopedLock sl (timerListLock);
  30439. for (int i = timers.size(); --i >= 0;)
  30440. {
  30441. MultiTimerCallback* const t = timers.getUnchecked(i);
  30442. if (t->timerId == timerId)
  30443. t->stopTimer();
  30444. }
  30445. }
  30446. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30447. {
  30448. const ScopedLock sl (timerListLock);
  30449. for (int i = timers.size(); --i >= 0;)
  30450. {
  30451. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30452. if (t->timerId == timerId)
  30453. return t->isTimerRunning();
  30454. }
  30455. return false;
  30456. }
  30457. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30458. {
  30459. const ScopedLock sl (timerListLock);
  30460. for (int i = timers.size(); --i >= 0;)
  30461. {
  30462. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30463. if (t->timerId == timerId)
  30464. return t->getTimerInterval();
  30465. }
  30466. return 0;
  30467. }
  30468. END_JUCE_NAMESPACE
  30469. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30470. /*** Start of inlined file: juce_Timer.cpp ***/
  30471. BEGIN_JUCE_NAMESPACE
  30472. class InternalTimerThread : private Thread,
  30473. private MessageListener,
  30474. private DeletedAtShutdown,
  30475. private AsyncUpdater
  30476. {
  30477. public:
  30478. InternalTimerThread()
  30479. : Thread ("Juce Timer"),
  30480. firstTimer (0),
  30481. callbackNeeded (false)
  30482. {
  30483. triggerAsyncUpdate();
  30484. }
  30485. ~InternalTimerThread() throw()
  30486. {
  30487. stopThread (4000);
  30488. jassert (instance == this || instance == 0);
  30489. if (instance == this)
  30490. instance = 0;
  30491. }
  30492. void run()
  30493. {
  30494. uint32 lastTime = Time::getMillisecondCounter();
  30495. while (! threadShouldExit())
  30496. {
  30497. const uint32 now = Time::getMillisecondCounter();
  30498. if (now <= lastTime)
  30499. {
  30500. wait (2);
  30501. continue;
  30502. }
  30503. const int elapsed = now - lastTime;
  30504. lastTime = now;
  30505. int timeUntilFirstTimer = 1000;
  30506. {
  30507. const ScopedLock sl (lock);
  30508. decrementAllCounters (elapsed);
  30509. if (firstTimer != 0)
  30510. timeUntilFirstTimer = firstTimer->countdownMs;
  30511. }
  30512. if (timeUntilFirstTimer <= 0)
  30513. {
  30514. if (callbackNeeded.set (true))
  30515. {
  30516. postMessage (new Message());
  30517. const uint32 messageDeliveryTimeout = now + 2000;
  30518. while (callbackNeeded.get())
  30519. {
  30520. wait (4);
  30521. if (threadShouldExit())
  30522. return;
  30523. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30524. break;
  30525. }
  30526. }
  30527. }
  30528. else
  30529. {
  30530. // don't wait for too long because running this loop also helps keep the
  30531. // Time::getApproximateMillisecondTimer value stay up-to-date
  30532. wait (jlimit (1, 50, timeUntilFirstTimer));
  30533. }
  30534. }
  30535. }
  30536. void callTimers()
  30537. {
  30538. const ScopedLock sl (lock);
  30539. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30540. {
  30541. Timer* const t = firstTimer;
  30542. t->countdownMs = t->periodMs;
  30543. removeTimer (t);
  30544. addTimer (t);
  30545. const ScopedUnlock ul (lock);
  30546. JUCE_TRY
  30547. {
  30548. t->timerCallback();
  30549. }
  30550. JUCE_CATCH_EXCEPTION
  30551. }
  30552. callbackNeeded.set (false);
  30553. }
  30554. void handleMessage (const Message&)
  30555. {
  30556. callTimers();
  30557. }
  30558. void callTimersSynchronously()
  30559. {
  30560. if (! isThreadRunning())
  30561. {
  30562. // (This is relied on by some plugins in cases where the MM has
  30563. // had to restart and the async callback never started)
  30564. cancelPendingUpdate();
  30565. triggerAsyncUpdate();
  30566. }
  30567. callTimers();
  30568. }
  30569. static void callAnyTimersSynchronously()
  30570. {
  30571. if (InternalTimerThread::instance != 0)
  30572. InternalTimerThread::instance->callTimersSynchronously();
  30573. }
  30574. static inline void add (Timer* const tim) throw()
  30575. {
  30576. if (instance == 0)
  30577. instance = new InternalTimerThread();
  30578. const ScopedLock sl (instance->lock);
  30579. instance->addTimer (tim);
  30580. }
  30581. static inline void remove (Timer* const tim) throw()
  30582. {
  30583. if (instance != 0)
  30584. {
  30585. const ScopedLock sl (instance->lock);
  30586. instance->removeTimer (tim);
  30587. }
  30588. }
  30589. static inline void resetCounter (Timer* const tim,
  30590. const int newCounter) throw()
  30591. {
  30592. if (instance != 0)
  30593. {
  30594. tim->countdownMs = newCounter;
  30595. tim->periodMs = newCounter;
  30596. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30597. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30598. {
  30599. const ScopedLock sl (instance->lock);
  30600. instance->removeTimer (tim);
  30601. instance->addTimer (tim);
  30602. }
  30603. }
  30604. }
  30605. private:
  30606. friend class Timer;
  30607. static InternalTimerThread* instance;
  30608. static CriticalSection lock;
  30609. Timer* volatile firstTimer;
  30610. class AtomicBool
  30611. {
  30612. public:
  30613. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30614. ~AtomicBool() throw() {}
  30615. bool get() const throw() { return value != 0; }
  30616. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30617. private:
  30618. int32 value;
  30619. AtomicBool (const AtomicBool&);
  30620. AtomicBool& operator= (const AtomicBool&);
  30621. };
  30622. AtomicBool callbackNeeded;
  30623. void addTimer (Timer* const t) throw()
  30624. {
  30625. #ifdef JUCE_DEBUG
  30626. Timer* tt = firstTimer;
  30627. while (tt != 0)
  30628. {
  30629. // trying to add a timer that's already here - shouldn't get to this point,
  30630. // so if you get this assertion, let me know!
  30631. jassert (tt != t);
  30632. tt = tt->next;
  30633. }
  30634. jassert (t->previous == 0 && t->next == 0);
  30635. #endif
  30636. Timer* i = firstTimer;
  30637. if (i == 0 || i->countdownMs > t->countdownMs)
  30638. {
  30639. t->next = firstTimer;
  30640. firstTimer = t;
  30641. }
  30642. else
  30643. {
  30644. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30645. i = i->next;
  30646. jassert (i != 0);
  30647. t->next = i->next;
  30648. t->previous = i;
  30649. i->next = t;
  30650. }
  30651. if (t->next != 0)
  30652. t->next->previous = t;
  30653. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30654. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30655. notify();
  30656. }
  30657. void removeTimer (Timer* const t) throw()
  30658. {
  30659. #ifdef JUCE_DEBUG
  30660. Timer* tt = firstTimer;
  30661. bool found = false;
  30662. while (tt != 0)
  30663. {
  30664. if (tt == t)
  30665. {
  30666. found = true;
  30667. break;
  30668. }
  30669. tt = tt->next;
  30670. }
  30671. // trying to remove a timer that's not here - shouldn't get to this point,
  30672. // so if you get this assertion, let me know!
  30673. jassert (found);
  30674. #endif
  30675. if (t->previous != 0)
  30676. {
  30677. jassert (firstTimer != t);
  30678. t->previous->next = t->next;
  30679. }
  30680. else
  30681. {
  30682. jassert (firstTimer == t);
  30683. firstTimer = t->next;
  30684. }
  30685. if (t->next != 0)
  30686. t->next->previous = t->previous;
  30687. t->next = 0;
  30688. t->previous = 0;
  30689. }
  30690. void decrementAllCounters (const int numMillisecs) const
  30691. {
  30692. Timer* t = firstTimer;
  30693. while (t != 0)
  30694. {
  30695. t->countdownMs -= numMillisecs;
  30696. t = t->next;
  30697. }
  30698. }
  30699. void handleAsyncUpdate()
  30700. {
  30701. startThread (7);
  30702. }
  30703. InternalTimerThread (const InternalTimerThread&);
  30704. InternalTimerThread& operator= (const InternalTimerThread&);
  30705. };
  30706. InternalTimerThread* InternalTimerThread::instance = 0;
  30707. CriticalSection InternalTimerThread::lock;
  30708. void juce_callAnyTimersSynchronously()
  30709. {
  30710. InternalTimerThread::callAnyTimersSynchronously();
  30711. }
  30712. #ifdef JUCE_DEBUG
  30713. static SortedSet <Timer*> activeTimers;
  30714. #endif
  30715. Timer::Timer() throw()
  30716. : countdownMs (0),
  30717. periodMs (0),
  30718. previous (0),
  30719. next (0)
  30720. {
  30721. #ifdef JUCE_DEBUG
  30722. activeTimers.add (this);
  30723. #endif
  30724. }
  30725. Timer::Timer (const Timer&) throw()
  30726. : countdownMs (0),
  30727. periodMs (0),
  30728. previous (0),
  30729. next (0)
  30730. {
  30731. #ifdef JUCE_DEBUG
  30732. activeTimers.add (this);
  30733. #endif
  30734. }
  30735. Timer::~Timer()
  30736. {
  30737. stopTimer();
  30738. #ifdef JUCE_DEBUG
  30739. activeTimers.removeValue (this);
  30740. #endif
  30741. }
  30742. void Timer::startTimer (const int interval) throw()
  30743. {
  30744. const ScopedLock sl (InternalTimerThread::lock);
  30745. #ifdef JUCE_DEBUG
  30746. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30747. jassert (activeTimers.contains (this));
  30748. #endif
  30749. if (periodMs == 0)
  30750. {
  30751. countdownMs = interval;
  30752. periodMs = jmax (1, interval);
  30753. InternalTimerThread::add (this);
  30754. }
  30755. else
  30756. {
  30757. InternalTimerThread::resetCounter (this, interval);
  30758. }
  30759. }
  30760. void Timer::stopTimer() throw()
  30761. {
  30762. const ScopedLock sl (InternalTimerThread::lock);
  30763. #ifdef JUCE_DEBUG
  30764. // this isn't a valid object! Your timer might be a dangling pointer or something..
  30765. jassert (activeTimers.contains (this));
  30766. #endif
  30767. if (periodMs > 0)
  30768. {
  30769. InternalTimerThread::remove (this);
  30770. periodMs = 0;
  30771. }
  30772. }
  30773. END_JUCE_NAMESPACE
  30774. /*** End of inlined file: juce_Timer.cpp ***/
  30775. #endif
  30776. #if JUCE_BUILD_GUI
  30777. /*** Start of inlined file: juce_Component.cpp ***/
  30778. BEGIN_JUCE_NAMESPACE
  30779. Component* Component::currentlyFocusedComponent = 0;
  30780. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  30781. static Array <int> modalReturnValues;
  30782. enum ComponentMessageNumbers
  30783. {
  30784. customCommandMessage = 0x7fff0001,
  30785. exitModalStateMessage = 0x7fff0002
  30786. };
  30787. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  30788. static uint32 nextComponentUID = 0;
  30789. Component::Component()
  30790. : parentComponent_ (0),
  30791. componentUID (++nextComponentUID),
  30792. numDeepMouseListeners (0),
  30793. lookAndFeel_ (0),
  30794. effect_ (0),
  30795. bufferedImage_ (0),
  30796. mouseListeners_ (0),
  30797. keyListeners_ (0),
  30798. componentFlags_ (0)
  30799. {
  30800. }
  30801. Component::Component (const String& name)
  30802. : componentName_ (name),
  30803. parentComponent_ (0),
  30804. componentUID (++nextComponentUID),
  30805. numDeepMouseListeners (0),
  30806. lookAndFeel_ (0),
  30807. effect_ (0),
  30808. bufferedImage_ (0),
  30809. mouseListeners_ (0),
  30810. keyListeners_ (0),
  30811. componentFlags_ (0)
  30812. {
  30813. }
  30814. Component::~Component()
  30815. {
  30816. componentListeners.call (&ComponentListener::componentBeingDeleted, *this);
  30817. if (parentComponent_ != 0)
  30818. {
  30819. parentComponent_->removeChildComponent (this);
  30820. }
  30821. else if ((currentlyFocusedComponent == this)
  30822. || isParentOf (currentlyFocusedComponent))
  30823. {
  30824. giveAwayFocus();
  30825. }
  30826. if (flags.hasHeavyweightPeerFlag)
  30827. removeFromDesktop();
  30828. modalComponentStack.removeValue (this);
  30829. for (int i = childComponentList_.size(); --i >= 0;)
  30830. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  30831. delete bufferedImage_;
  30832. delete mouseListeners_;
  30833. delete keyListeners_;
  30834. }
  30835. void Component::setName (const String& name)
  30836. {
  30837. // if component methods are being called from threads other than the message
  30838. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30839. checkMessageManagerIsLocked
  30840. if (componentName_ != name)
  30841. {
  30842. componentName_ = name;
  30843. if (flags.hasHeavyweightPeerFlag)
  30844. {
  30845. ComponentPeer* const peer = getPeer();
  30846. jassert (peer != 0);
  30847. if (peer != 0)
  30848. peer->setTitle (name);
  30849. }
  30850. BailOutChecker checker (this);
  30851. componentListeners.callChecked (checker, &ComponentListener::componentNameChanged, *this);
  30852. }
  30853. }
  30854. void Component::setVisible (bool shouldBeVisible)
  30855. {
  30856. if (flags.visibleFlag != shouldBeVisible)
  30857. {
  30858. // if component methods are being called from threads other than the message
  30859. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  30860. checkMessageManagerIsLocked
  30861. SafePointer<Component> safePointer (this);
  30862. flags.visibleFlag = shouldBeVisible;
  30863. internalRepaint (0, 0, getWidth(), getHeight());
  30864. sendFakeMouseMove();
  30865. if (! shouldBeVisible)
  30866. {
  30867. if (currentlyFocusedComponent == this
  30868. || isParentOf (currentlyFocusedComponent))
  30869. {
  30870. if (parentComponent_ != 0)
  30871. parentComponent_->grabKeyboardFocus();
  30872. else
  30873. giveAwayFocus();
  30874. }
  30875. }
  30876. if (safePointer != 0)
  30877. {
  30878. sendVisibilityChangeMessage();
  30879. if (safePointer != 0 && flags.hasHeavyweightPeerFlag)
  30880. {
  30881. ComponentPeer* const peer = getPeer();
  30882. jassert (peer != 0);
  30883. if (peer != 0)
  30884. {
  30885. peer->setVisible (shouldBeVisible);
  30886. internalHierarchyChanged();
  30887. }
  30888. }
  30889. }
  30890. }
  30891. }
  30892. void Component::visibilityChanged()
  30893. {
  30894. }
  30895. void Component::sendVisibilityChangeMessage()
  30896. {
  30897. BailOutChecker checker (this);
  30898. visibilityChanged();
  30899. if (! checker.shouldBailOut())
  30900. componentListeners.callChecked (checker, &ComponentListener::componentVisibilityChanged, *this);
  30901. }
  30902. bool Component::isShowing() const
  30903. {
  30904. if (flags.visibleFlag)
  30905. {
  30906. if (parentComponent_ != 0)
  30907. {
  30908. return parentComponent_->isShowing();
  30909. }
  30910. else
  30911. {
  30912. const ComponentPeer* const peer = getPeer();
  30913. return peer != 0 && ! peer->isMinimised();
  30914. }
  30915. }
  30916. return false;
  30917. }
  30918. class FadeOutProxyComponent : public Component,
  30919. public Timer
  30920. {
  30921. public:
  30922. FadeOutProxyComponent (Component* comp,
  30923. const int fadeLengthMs,
  30924. const int deltaXToMove,
  30925. const int deltaYToMove,
  30926. const float scaleFactorAtEnd)
  30927. : lastTime (0),
  30928. alpha (1.0f),
  30929. scale (1.0f)
  30930. {
  30931. image = comp->createComponentSnapshot (comp->getLocalBounds());
  30932. setBounds (comp->getBounds());
  30933. comp->getParentComponent()->addAndMakeVisible (this);
  30934. toBehind (comp);
  30935. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  30936. centreX = comp->getX() + comp->getWidth() * 0.5f;
  30937. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  30938. centreY = comp->getY() + comp->getHeight() * 0.5f;
  30939. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  30940. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  30941. setInterceptsMouseClicks (false, false);
  30942. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  30943. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  30944. }
  30945. ~FadeOutProxyComponent()
  30946. {
  30947. delete image;
  30948. }
  30949. void paint (Graphics& g)
  30950. {
  30951. g.setOpacity (alpha);
  30952. g.drawImage (image,
  30953. 0, 0, getWidth(), getHeight(),
  30954. 0, 0, image->getWidth(), image->getHeight());
  30955. }
  30956. void timerCallback()
  30957. {
  30958. const uint32 now = Time::getMillisecondCounter();
  30959. if (lastTime == 0)
  30960. lastTime = now;
  30961. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  30962. lastTime = now;
  30963. alpha += alphaChangePerMs * msPassed;
  30964. if (alpha > 0)
  30965. {
  30966. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  30967. {
  30968. centreX += xChangePerMs * msPassed;
  30969. centreY += yChangePerMs * msPassed;
  30970. scale += scaleChangePerMs * msPassed;
  30971. const int w = roundToInt (image->getWidth() * scale);
  30972. const int h = roundToInt (image->getHeight() * scale);
  30973. setBounds (roundToInt (centreX) - w / 2,
  30974. roundToInt (centreY) - h / 2,
  30975. w, h);
  30976. }
  30977. repaint();
  30978. }
  30979. else
  30980. {
  30981. delete this;
  30982. }
  30983. }
  30984. juce_UseDebuggingNewOperator
  30985. private:
  30986. Image* image;
  30987. uint32 lastTime;
  30988. float alpha, alphaChangePerMs;
  30989. float centreX, xChangePerMs;
  30990. float centreY, yChangePerMs;
  30991. float scale, scaleChangePerMs;
  30992. FadeOutProxyComponent (const FadeOutProxyComponent&);
  30993. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  30994. };
  30995. void Component::fadeOutComponent (const int millisecondsToFade,
  30996. const int deltaXToMove,
  30997. const int deltaYToMove,
  30998. const float scaleFactorAtEnd)
  30999. {
  31000. //xxx won't work for comps without parents
  31001. if (isShowing() && millisecondsToFade > 0)
  31002. new FadeOutProxyComponent (this, millisecondsToFade,
  31003. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31004. setVisible (false);
  31005. }
  31006. bool Component::isValidComponent() const
  31007. {
  31008. return (this != 0) && isValidMessageListener();
  31009. }
  31010. void* Component::getWindowHandle() const
  31011. {
  31012. const ComponentPeer* const peer = getPeer();
  31013. if (peer != 0)
  31014. return peer->getNativeHandle();
  31015. return 0;
  31016. }
  31017. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31018. {
  31019. // if component methods are being called from threads other than the message
  31020. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31021. checkMessageManagerIsLocked
  31022. if (isOpaque())
  31023. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31024. else
  31025. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31026. int currentStyleFlags = 0;
  31027. // don't use getPeer(), so that we only get the peer that's specifically
  31028. // for this comp, and not for one of its parents.
  31029. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31030. if (peer != 0)
  31031. currentStyleFlags = peer->getStyleFlags();
  31032. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31033. {
  31034. SafePointer<Component> safePointer (this);
  31035. #if JUCE_LINUX
  31036. // it's wise to give the component a non-zero size before
  31037. // putting it on the desktop, as X windows get confused by this, and
  31038. // a (1, 1) minimum size is enforced here.
  31039. setSize (jmax (1, getWidth()),
  31040. jmax (1, getHeight()));
  31041. #endif
  31042. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31043. bool wasFullscreen = false;
  31044. bool wasMinimised = false;
  31045. ComponentBoundsConstrainer* currentConstainer = 0;
  31046. Rectangle<int> oldNonFullScreenBounds;
  31047. if (peer != 0)
  31048. {
  31049. wasFullscreen = peer->isFullScreen();
  31050. wasMinimised = peer->isMinimised();
  31051. currentConstainer = peer->getConstrainer();
  31052. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31053. removeFromDesktop();
  31054. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31055. }
  31056. if (parentComponent_ != 0)
  31057. parentComponent_->removeChildComponent (this);
  31058. if (safePointer != 0)
  31059. {
  31060. flags.hasHeavyweightPeerFlag = true;
  31061. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31062. Desktop::getInstance().addDesktopComponent (this);
  31063. bounds_.setPosition (topLeft);
  31064. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31065. peer->setVisible (isVisible());
  31066. if (wasFullscreen)
  31067. {
  31068. peer->setFullScreen (true);
  31069. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31070. }
  31071. if (wasMinimised)
  31072. peer->setMinimised (true);
  31073. if (isAlwaysOnTop())
  31074. peer->setAlwaysOnTop (true);
  31075. peer->setConstrainer (currentConstainer);
  31076. repaint();
  31077. }
  31078. internalHierarchyChanged();
  31079. }
  31080. }
  31081. void Component::removeFromDesktop()
  31082. {
  31083. // if component methods are being called from threads other than the message
  31084. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31085. checkMessageManagerIsLocked
  31086. if (flags.hasHeavyweightPeerFlag)
  31087. {
  31088. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31089. flags.hasHeavyweightPeerFlag = false;
  31090. jassert (peer != 0);
  31091. delete peer;
  31092. Desktop::getInstance().removeDesktopComponent (this);
  31093. }
  31094. }
  31095. bool Component::isOnDesktop() const throw()
  31096. {
  31097. return flags.hasHeavyweightPeerFlag;
  31098. }
  31099. void Component::userTriedToCloseWindow()
  31100. {
  31101. /* This means that the user's trying to get rid of your window with the 'close window' system
  31102. menu option (on windows) or possibly the task manager - you should really handle this
  31103. and delete or hide your component in an appropriate way.
  31104. If you want to ignore the event and don't want to trigger this assertion, just override
  31105. this method and do nothing.
  31106. */
  31107. jassertfalse
  31108. }
  31109. void Component::minimisationStateChanged (bool)
  31110. {
  31111. }
  31112. void Component::setOpaque (const bool shouldBeOpaque)
  31113. {
  31114. if (shouldBeOpaque != flags.opaqueFlag)
  31115. {
  31116. flags.opaqueFlag = shouldBeOpaque;
  31117. if (flags.hasHeavyweightPeerFlag)
  31118. {
  31119. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31120. if (peer != 0)
  31121. {
  31122. // to make it recreate the heavyweight window
  31123. addToDesktop (peer->getStyleFlags());
  31124. }
  31125. }
  31126. repaint();
  31127. }
  31128. }
  31129. bool Component::isOpaque() const throw()
  31130. {
  31131. return flags.opaqueFlag;
  31132. }
  31133. void Component::setBufferedToImage (const bool shouldBeBuffered)
  31134. {
  31135. if (shouldBeBuffered != flags.bufferToImageFlag)
  31136. {
  31137. deleteAndZero (bufferedImage_);
  31138. flags.bufferToImageFlag = shouldBeBuffered;
  31139. }
  31140. }
  31141. void Component::toFront (const bool setAsForeground)
  31142. {
  31143. // if component methods are being called from threads other than the message
  31144. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31145. checkMessageManagerIsLocked
  31146. if (flags.hasHeavyweightPeerFlag)
  31147. {
  31148. ComponentPeer* const peer = getPeer();
  31149. if (peer != 0)
  31150. {
  31151. peer->toFront (setAsForeground);
  31152. if (setAsForeground && ! hasKeyboardFocus (true))
  31153. grabKeyboardFocus();
  31154. }
  31155. }
  31156. else if (parentComponent_ != 0)
  31157. {
  31158. if (parentComponent_->childComponentList_.getLast() != this)
  31159. {
  31160. const int index = parentComponent_->childComponentList_.indexOf (this);
  31161. if (index >= 0)
  31162. {
  31163. int insertIndex = -1;
  31164. if (! flags.alwaysOnTopFlag)
  31165. {
  31166. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31167. while (insertIndex > 0
  31168. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31169. {
  31170. --insertIndex;
  31171. }
  31172. }
  31173. if (index != insertIndex)
  31174. {
  31175. parentComponent_->childComponentList_.move (index, insertIndex);
  31176. sendFakeMouseMove();
  31177. repaintParent();
  31178. }
  31179. }
  31180. }
  31181. if (setAsForeground)
  31182. {
  31183. internalBroughtToFront();
  31184. grabKeyboardFocus();
  31185. }
  31186. }
  31187. }
  31188. void Component::toBehind (Component* const other)
  31189. {
  31190. if (other != 0)
  31191. {
  31192. // the two components must belong to the same parent..
  31193. jassert (parentComponent_ == other->parentComponent_);
  31194. if (parentComponent_ != 0)
  31195. {
  31196. const int index = parentComponent_->childComponentList_.indexOf (this);
  31197. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31198. if (index >= 0
  31199. && otherIndex >= 0
  31200. && index != otherIndex - 1
  31201. && other != this)
  31202. {
  31203. if (index < otherIndex)
  31204. --otherIndex;
  31205. parentComponent_->childComponentList_.move (index, otherIndex);
  31206. sendFakeMouseMove();
  31207. repaintParent();
  31208. }
  31209. }
  31210. else if (isOnDesktop())
  31211. {
  31212. jassert (other->isOnDesktop());
  31213. if (other->isOnDesktop())
  31214. {
  31215. ComponentPeer* const us = getPeer();
  31216. ComponentPeer* const them = other->getPeer();
  31217. jassert (us != 0 && them != 0);
  31218. if (us != 0 && them != 0)
  31219. us->toBehind (them);
  31220. }
  31221. }
  31222. }
  31223. }
  31224. void Component::toBack()
  31225. {
  31226. if (isOnDesktop())
  31227. {
  31228. jassertfalse //xxx need to add this to native window
  31229. }
  31230. else if (parentComponent_ != 0
  31231. && parentComponent_->childComponentList_.getFirst() != this)
  31232. {
  31233. const int index = parentComponent_->childComponentList_.indexOf (this);
  31234. if (index > 0)
  31235. {
  31236. int insertIndex = 0;
  31237. if (flags.alwaysOnTopFlag)
  31238. {
  31239. while (insertIndex < parentComponent_->childComponentList_.size()
  31240. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31241. {
  31242. ++insertIndex;
  31243. }
  31244. }
  31245. if (index != insertIndex)
  31246. {
  31247. parentComponent_->childComponentList_.move (index, insertIndex);
  31248. sendFakeMouseMove();
  31249. repaintParent();
  31250. }
  31251. }
  31252. }
  31253. }
  31254. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31255. {
  31256. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31257. {
  31258. flags.alwaysOnTopFlag = shouldStayOnTop;
  31259. if (isOnDesktop())
  31260. {
  31261. ComponentPeer* const peer = getPeer();
  31262. jassert (peer != 0);
  31263. if (peer != 0)
  31264. {
  31265. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31266. {
  31267. // some kinds of peer can't change their always-on-top status, so
  31268. // for these, we'll need to create a new window
  31269. const int oldFlags = peer->getStyleFlags();
  31270. removeFromDesktop();
  31271. addToDesktop (oldFlags);
  31272. }
  31273. }
  31274. }
  31275. if (shouldStayOnTop)
  31276. toFront (false);
  31277. internalHierarchyChanged();
  31278. }
  31279. }
  31280. bool Component::isAlwaysOnTop() const throw()
  31281. {
  31282. return flags.alwaysOnTopFlag;
  31283. }
  31284. int Component::proportionOfWidth (const float proportion) const throw()
  31285. {
  31286. return roundToInt (proportion * bounds_.getWidth());
  31287. }
  31288. int Component::proportionOfHeight (const float proportion) const throw()
  31289. {
  31290. return roundToInt (proportion * bounds_.getHeight());
  31291. }
  31292. int Component::getParentWidth() const throw()
  31293. {
  31294. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31295. : getParentMonitorArea().getWidth();
  31296. }
  31297. int Component::getParentHeight() const throw()
  31298. {
  31299. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31300. : getParentMonitorArea().getHeight();
  31301. }
  31302. int Component::getScreenX() const
  31303. {
  31304. return getScreenPosition().getX();
  31305. }
  31306. int Component::getScreenY() const
  31307. {
  31308. return getScreenPosition().getY();
  31309. }
  31310. const Point<int> Component::getScreenPosition() const
  31311. {
  31312. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31313. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31314. : getPosition());
  31315. }
  31316. const Rectangle<int> Component::getScreenBounds() const
  31317. {
  31318. return bounds_.withPosition (getScreenPosition());
  31319. }
  31320. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31321. {
  31322. const Component* c = this;
  31323. Point<int> p (relativePosition);
  31324. do
  31325. {
  31326. if (c->flags.hasHeavyweightPeerFlag)
  31327. return c->getPeer()->relativePositionToGlobal (p);
  31328. p += c->getPosition();
  31329. c = c->parentComponent_;
  31330. }
  31331. while (c != 0);
  31332. return p;
  31333. }
  31334. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31335. {
  31336. if (flags.hasHeavyweightPeerFlag)
  31337. {
  31338. return getPeer()->globalPositionToRelative (screenPosition);
  31339. }
  31340. else
  31341. {
  31342. if (parentComponent_ != 0)
  31343. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31344. return screenPosition - getPosition();
  31345. }
  31346. }
  31347. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31348. {
  31349. Point<int> p (positionRelativeToThis);
  31350. if (targetComponent != 0)
  31351. {
  31352. const Component* c = this;
  31353. do
  31354. {
  31355. if (c == targetComponent)
  31356. return p;
  31357. if (c->flags.hasHeavyweightPeerFlag)
  31358. {
  31359. p = c->getPeer()->relativePositionToGlobal (p);
  31360. break;
  31361. }
  31362. p += c->getPosition();
  31363. c = c->parentComponent_;
  31364. }
  31365. while (c != 0);
  31366. p = targetComponent->globalPositionToRelative (p);
  31367. }
  31368. return p;
  31369. }
  31370. void Component::setBounds (int x, int y, int w, int h)
  31371. {
  31372. // if component methods are being called from threads other than the message
  31373. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31374. checkMessageManagerIsLocked
  31375. if (w < 0) w = 0;
  31376. if (h < 0) h = 0;
  31377. const bool wasResized = (getWidth() != w || getHeight() != h);
  31378. const bool wasMoved = (getX() != x || getY() != y);
  31379. #ifdef JUCE_DEBUG
  31380. // It's a very bad idea to try to resize a window during its paint() method!
  31381. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31382. #endif
  31383. if (wasMoved || wasResized)
  31384. {
  31385. if (flags.visibleFlag)
  31386. {
  31387. // send a fake mouse move to trigger enter/exit messages if needed..
  31388. sendFakeMouseMove();
  31389. if (! flags.hasHeavyweightPeerFlag)
  31390. repaintParent();
  31391. }
  31392. bounds_.setBounds (x, y, w, h);
  31393. if (wasResized)
  31394. repaint();
  31395. else if (! flags.hasHeavyweightPeerFlag)
  31396. repaintParent();
  31397. if (flags.hasHeavyweightPeerFlag)
  31398. {
  31399. ComponentPeer* const peer = getPeer();
  31400. if (peer != 0)
  31401. {
  31402. if (wasMoved && wasResized)
  31403. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31404. else if (wasMoved)
  31405. peer->setPosition (getX(), getY());
  31406. else if (wasResized)
  31407. peer->setSize (getWidth(), getHeight());
  31408. }
  31409. }
  31410. sendMovedResizedMessages (wasMoved, wasResized);
  31411. }
  31412. }
  31413. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31414. {
  31415. JUCE_TRY
  31416. {
  31417. if (wasMoved)
  31418. moved();
  31419. if (wasResized)
  31420. {
  31421. resized();
  31422. for (int i = childComponentList_.size(); --i >= 0;)
  31423. {
  31424. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31425. i = jmin (i, childComponentList_.size());
  31426. }
  31427. }
  31428. BailOutChecker checker (this);
  31429. if (parentComponent_ != 0)
  31430. parentComponent_->childBoundsChanged (this);
  31431. if (! checker.shouldBailOut())
  31432. componentListeners.callChecked (checker, &ComponentListener::componentMovedOrResized,
  31433. *this, wasMoved, wasResized);
  31434. }
  31435. JUCE_CATCH_EXCEPTION
  31436. }
  31437. void Component::setSize (const int w, const int h)
  31438. {
  31439. setBounds (getX(), getY(), w, h);
  31440. }
  31441. void Component::setTopLeftPosition (const int x, const int y)
  31442. {
  31443. setBounds (x, y, getWidth(), getHeight());
  31444. }
  31445. void Component::setTopRightPosition (const int x, const int y)
  31446. {
  31447. setTopLeftPosition (x - getWidth(), y);
  31448. }
  31449. void Component::setBounds (const Rectangle<int>& r)
  31450. {
  31451. setBounds (r.getX(),
  31452. r.getY(),
  31453. r.getWidth(),
  31454. r.getHeight());
  31455. }
  31456. void Component::setBoundsRelative (const float x, const float y,
  31457. const float w, const float h)
  31458. {
  31459. const int pw = getParentWidth();
  31460. const int ph = getParentHeight();
  31461. setBounds (roundToInt (x * pw),
  31462. roundToInt (y * ph),
  31463. roundToInt (w * pw),
  31464. roundToInt (h * ph));
  31465. }
  31466. void Component::setCentrePosition (const int x, const int y)
  31467. {
  31468. setTopLeftPosition (x - getWidth() / 2,
  31469. y - getHeight() / 2);
  31470. }
  31471. void Component::setCentreRelative (const float x, const float y)
  31472. {
  31473. setCentrePosition (roundToInt (getParentWidth() * x),
  31474. roundToInt (getParentHeight() * y));
  31475. }
  31476. void Component::centreWithSize (const int width, const int height)
  31477. {
  31478. setBounds ((getParentWidth() - width) / 2,
  31479. (getParentHeight() - height) / 2,
  31480. width,
  31481. height);
  31482. }
  31483. void Component::setBoundsInset (const BorderSize& borders)
  31484. {
  31485. setBounds (borders.getLeft(),
  31486. borders.getTop(),
  31487. getParentWidth() - (borders.getLeftAndRight()),
  31488. getParentHeight() - (borders.getTopAndBottom()));
  31489. }
  31490. void Component::setBoundsToFit (int x, int y, int width, int height,
  31491. const Justification& justification,
  31492. const bool onlyReduceInSize)
  31493. {
  31494. // it's no good calling this method unless both the component and
  31495. // target rectangle have a finite size.
  31496. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31497. if (getWidth() > 0 && getHeight() > 0
  31498. && width > 0 && height > 0)
  31499. {
  31500. int newW, newH;
  31501. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31502. {
  31503. newW = getWidth();
  31504. newH = getHeight();
  31505. }
  31506. else
  31507. {
  31508. const double imageRatio = getHeight() / (double) getWidth();
  31509. const double targetRatio = height / (double) width;
  31510. if (imageRatio <= targetRatio)
  31511. {
  31512. newW = width;
  31513. newH = jmin (height, roundToInt (newW * imageRatio));
  31514. }
  31515. else
  31516. {
  31517. newH = height;
  31518. newW = jmin (width, roundToInt (newH / imageRatio));
  31519. }
  31520. }
  31521. if (newW > 0 && newH > 0)
  31522. {
  31523. int newX, newY;
  31524. justification.applyToRectangle (newX, newY, newW, newH,
  31525. x, y, width, height);
  31526. setBounds (newX, newY, newW, newH);
  31527. }
  31528. }
  31529. }
  31530. bool Component::hitTest (int x, int y)
  31531. {
  31532. if (! flags.ignoresMouseClicksFlag)
  31533. return true;
  31534. if (flags.allowChildMouseClicksFlag)
  31535. {
  31536. for (int i = getNumChildComponents(); --i >= 0;)
  31537. {
  31538. Component* const c = getChildComponent (i);
  31539. if (c->isVisible()
  31540. && c->bounds_.contains (x, y)
  31541. && c->hitTest (x - c->getX(),
  31542. y - c->getY()))
  31543. {
  31544. return true;
  31545. }
  31546. }
  31547. }
  31548. return false;
  31549. }
  31550. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31551. const bool allowClicksOnChildComponents) throw()
  31552. {
  31553. flags.ignoresMouseClicksFlag = ! allowClicks;
  31554. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31555. }
  31556. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31557. bool& allowsClicksOnChildComponents) const throw()
  31558. {
  31559. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31560. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31561. }
  31562. bool Component::contains (const int x, const int y)
  31563. {
  31564. if (((unsigned int) x) < (unsigned int) getWidth()
  31565. && ((unsigned int) y) < (unsigned int) getHeight()
  31566. && hitTest (x, y))
  31567. {
  31568. if (parentComponent_ != 0)
  31569. {
  31570. return parentComponent_->contains (x + getX(),
  31571. y + getY());
  31572. }
  31573. else if (flags.hasHeavyweightPeerFlag)
  31574. {
  31575. const ComponentPeer* const peer = getPeer();
  31576. if (peer != 0)
  31577. return peer->contains (Point<int> (x, y), true);
  31578. }
  31579. }
  31580. return false;
  31581. }
  31582. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31583. {
  31584. if (! contains (x, y))
  31585. return false;
  31586. Component* p = this;
  31587. while (p->parentComponent_ != 0)
  31588. {
  31589. x += p->getX();
  31590. y += p->getY();
  31591. p = p->parentComponent_;
  31592. }
  31593. const Component* const c = p->getComponentAt (x, y);
  31594. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31595. }
  31596. Component* Component::getComponentAt (const Point<int>& position)
  31597. {
  31598. return getComponentAt (position.getX(), position.getY());
  31599. }
  31600. Component* Component::getComponentAt (const int x, const int y)
  31601. {
  31602. if (flags.visibleFlag
  31603. && ((unsigned int) x) < (unsigned int) getWidth()
  31604. && ((unsigned int) y) < (unsigned int) getHeight()
  31605. && hitTest (x, y))
  31606. {
  31607. for (int i = childComponentList_.size(); --i >= 0;)
  31608. {
  31609. Component* const child = childComponentList_.getUnchecked(i);
  31610. Component* const c = child->getComponentAt (x - child->getX(),
  31611. y - child->getY());
  31612. if (c != 0)
  31613. return c;
  31614. }
  31615. return this;
  31616. }
  31617. return 0;
  31618. }
  31619. void Component::addChildComponent (Component* const child, int zOrder)
  31620. {
  31621. // if component methods are being called from threads other than the message
  31622. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31623. checkMessageManagerIsLocked
  31624. if (child != 0 && child->parentComponent_ != this)
  31625. {
  31626. if (child->parentComponent_ != 0)
  31627. child->parentComponent_->removeChildComponent (child);
  31628. else
  31629. child->removeFromDesktop();
  31630. child->parentComponent_ = this;
  31631. if (child->isVisible())
  31632. child->repaintParent();
  31633. if (! child->isAlwaysOnTop())
  31634. {
  31635. if (zOrder < 0 || zOrder > childComponentList_.size())
  31636. zOrder = childComponentList_.size();
  31637. while (zOrder > 0)
  31638. {
  31639. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31640. break;
  31641. --zOrder;
  31642. }
  31643. }
  31644. childComponentList_.insert (zOrder, child);
  31645. child->internalHierarchyChanged();
  31646. internalChildrenChanged();
  31647. }
  31648. }
  31649. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31650. {
  31651. if (child != 0)
  31652. {
  31653. child->setVisible (true);
  31654. addChildComponent (child, zOrder);
  31655. }
  31656. }
  31657. void Component::removeChildComponent (Component* const child)
  31658. {
  31659. removeChildComponent (childComponentList_.indexOf (child));
  31660. }
  31661. Component* Component::removeChildComponent (const int index)
  31662. {
  31663. // if component methods are being called from threads other than the message
  31664. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31665. checkMessageManagerIsLocked
  31666. Component* const child = childComponentList_ [index];
  31667. if (child != 0)
  31668. {
  31669. sendFakeMouseMove();
  31670. child->repaintParent();
  31671. childComponentList_.remove (index);
  31672. child->parentComponent_ = 0;
  31673. JUCE_TRY
  31674. {
  31675. if ((currentlyFocusedComponent == child)
  31676. || child->isParentOf (currentlyFocusedComponent))
  31677. {
  31678. // get rid first to force the grabKeyboardFocus to change to us.
  31679. giveAwayFocus();
  31680. grabKeyboardFocus();
  31681. }
  31682. }
  31683. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31684. catch (const std::exception& e)
  31685. {
  31686. currentlyFocusedComponent = 0;
  31687. Desktop::getInstance().triggerFocusCallback();
  31688. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31689. }
  31690. catch (...)
  31691. {
  31692. currentlyFocusedComponent = 0;
  31693. Desktop::getInstance().triggerFocusCallback();
  31694. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31695. }
  31696. #endif
  31697. child->internalHierarchyChanged();
  31698. internalChildrenChanged();
  31699. }
  31700. return child;
  31701. }
  31702. void Component::removeAllChildren()
  31703. {
  31704. while (childComponentList_.size() > 0)
  31705. removeChildComponent (childComponentList_.size() - 1);
  31706. }
  31707. void Component::deleteAllChildren()
  31708. {
  31709. while (childComponentList_.size() > 0)
  31710. delete (removeChildComponent (childComponentList_.size() - 1));
  31711. }
  31712. int Component::getNumChildComponents() const throw()
  31713. {
  31714. return childComponentList_.size();
  31715. }
  31716. Component* Component::getChildComponent (const int index) const throw()
  31717. {
  31718. return childComponentList_ [index];
  31719. }
  31720. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  31721. {
  31722. return childComponentList_.indexOf (const_cast <Component*> (child));
  31723. }
  31724. Component* Component::getTopLevelComponent() const throw()
  31725. {
  31726. const Component* comp = this;
  31727. while (comp->parentComponent_ != 0)
  31728. comp = comp->parentComponent_;
  31729. return const_cast <Component*> (comp);
  31730. }
  31731. bool Component::isParentOf (const Component* possibleChild) const throw()
  31732. {
  31733. if (! possibleChild->isValidComponent())
  31734. {
  31735. jassert (possibleChild == 0);
  31736. return false;
  31737. }
  31738. while (possibleChild != 0)
  31739. {
  31740. possibleChild = possibleChild->parentComponent_;
  31741. if (possibleChild == this)
  31742. return true;
  31743. }
  31744. return false;
  31745. }
  31746. void Component::parentHierarchyChanged()
  31747. {
  31748. }
  31749. void Component::childrenChanged()
  31750. {
  31751. }
  31752. void Component::internalChildrenChanged()
  31753. {
  31754. if (componentListeners.isEmpty())
  31755. {
  31756. childrenChanged();
  31757. }
  31758. else
  31759. {
  31760. BailOutChecker checker (this);
  31761. childrenChanged();
  31762. if (! checker.shouldBailOut())
  31763. componentListeners.callChecked (checker, &ComponentListener::componentChildrenChanged, *this);
  31764. }
  31765. }
  31766. void Component::internalHierarchyChanged()
  31767. {
  31768. BailOutChecker checker (this);
  31769. parentHierarchyChanged();
  31770. if (checker.shouldBailOut())
  31771. return;
  31772. componentListeners.callChecked (checker, &ComponentListener::componentParentHierarchyChanged, *this);
  31773. if (checker.shouldBailOut())
  31774. return;
  31775. for (int i = childComponentList_.size(); --i >= 0;)
  31776. {
  31777. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  31778. if (checker.shouldBailOut())
  31779. {
  31780. // you really shouldn't delete the parent component during a callback telling you
  31781. // that it's changed..
  31782. jassertfalse;
  31783. return;
  31784. }
  31785. i = jmin (i, childComponentList_.size());
  31786. }
  31787. }
  31788. void* Component::runModalLoopCallback (void* userData)
  31789. {
  31790. return (void*) (pointer_sized_int) static_cast <Component*> (userData)->runModalLoop();
  31791. }
  31792. int Component::runModalLoop()
  31793. {
  31794. if (! MessageManager::getInstance()->isThisTheMessageThread())
  31795. {
  31796. // use a callback so this can be called from non-gui threads
  31797. return (int) (pointer_sized_int)
  31798. MessageManager::getInstance()
  31799. ->callFunctionOnMessageThread (&runModalLoopCallback, this);
  31800. }
  31801. SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  31802. if (! isCurrentlyModal())
  31803. enterModalState();
  31804. JUCE_TRY
  31805. {
  31806. while (flags.currentlyModalFlag && flags.visibleFlag)
  31807. {
  31808. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  31809. break;
  31810. // check whether this component was deleted during the last message
  31811. if (! isValidMessageListener())
  31812. break;
  31813. }
  31814. }
  31815. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31816. catch (const std::exception& e)
  31817. {
  31818. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31819. return 0;
  31820. }
  31821. catch (...)
  31822. {
  31823. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  31824. return 0;
  31825. }
  31826. #endif
  31827. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31828. int returnValue = 0;
  31829. if (modalIndex >= 0)
  31830. {
  31831. modalComponentReturnValueKeys.remove (modalIndex);
  31832. returnValue = modalReturnValues.remove (modalIndex);
  31833. }
  31834. modalComponentStack.removeValue (this);
  31835. if (prevFocused != 0)
  31836. prevFocused->grabKeyboardFocus();
  31837. return returnValue;
  31838. }
  31839. void Component::enterModalState (const bool takeKeyboardFocus_)
  31840. {
  31841. // if component methods are being called from threads other than the message
  31842. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31843. checkMessageManagerIsLocked
  31844. // Check for an attempt to make a component modal when it already is!
  31845. // This can cause nasty problems..
  31846. jassert (! flags.currentlyModalFlag);
  31847. if (! isCurrentlyModal())
  31848. {
  31849. modalComponentStack.add (this);
  31850. modalComponentReturnValueKeys.add (this);
  31851. modalReturnValues.add (0);
  31852. flags.currentlyModalFlag = true;
  31853. setVisible (true);
  31854. if (takeKeyboardFocus_)
  31855. grabKeyboardFocus();
  31856. }
  31857. }
  31858. void Component::exitModalState (const int returnValue)
  31859. {
  31860. if (isCurrentlyModal())
  31861. {
  31862. if (MessageManager::getInstance()->isThisTheMessageThread())
  31863. {
  31864. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  31865. if (modalIndex >= 0)
  31866. {
  31867. modalReturnValues.set (modalIndex, returnValue);
  31868. }
  31869. else
  31870. {
  31871. modalComponentReturnValueKeys.add (this);
  31872. modalReturnValues.add (returnValue);
  31873. }
  31874. modalComponentStack.removeValue (this);
  31875. flags.currentlyModalFlag = false;
  31876. bringModalComponentToFront();
  31877. }
  31878. else
  31879. {
  31880. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  31881. }
  31882. }
  31883. }
  31884. bool Component::isCurrentlyModal() const throw()
  31885. {
  31886. return flags.currentlyModalFlag
  31887. && getCurrentlyModalComponent() == this;
  31888. }
  31889. bool Component::isCurrentlyBlockedByAnotherModalComponent() const
  31890. {
  31891. Component* const mc = getCurrentlyModalComponent();
  31892. return mc != 0
  31893. && mc != this
  31894. && (! mc->isParentOf (this))
  31895. && ! mc->canModalEventBeSentToComponent (this);
  31896. }
  31897. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  31898. {
  31899. return modalComponentStack.size();
  31900. }
  31901. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  31902. {
  31903. Component* const c = static_cast <Component*> (modalComponentStack [modalComponentStack.size() - index - 1]);
  31904. return c->isValidComponent() ? c : 0;
  31905. }
  31906. void Component::bringModalComponentToFront()
  31907. {
  31908. ComponentPeer* lastOne = 0;
  31909. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  31910. {
  31911. Component* const c = getCurrentlyModalComponent (i);
  31912. if (c == 0)
  31913. break;
  31914. ComponentPeer* peer = c->getPeer();
  31915. if (peer != 0 && peer != lastOne)
  31916. {
  31917. if (lastOne == 0)
  31918. {
  31919. peer->toFront (true);
  31920. peer->grabFocus();
  31921. }
  31922. else
  31923. peer->toBehind (lastOne);
  31924. lastOne = peer;
  31925. }
  31926. }
  31927. }
  31928. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  31929. {
  31930. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  31931. }
  31932. bool Component::isBroughtToFrontOnMouseClick() const throw()
  31933. {
  31934. return flags.bringToFrontOnClickFlag;
  31935. }
  31936. void Component::setMouseCursor (const MouseCursor& cursor)
  31937. {
  31938. if (cursor_ != cursor)
  31939. {
  31940. cursor_ = cursor;
  31941. if (flags.visibleFlag)
  31942. updateMouseCursor();
  31943. }
  31944. }
  31945. const MouseCursor Component::getMouseCursor()
  31946. {
  31947. return cursor_;
  31948. }
  31949. void Component::updateMouseCursor() const
  31950. {
  31951. sendFakeMouseMove();
  31952. }
  31953. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  31954. {
  31955. flags.repaintOnMouseActivityFlag = shouldRepaint;
  31956. }
  31957. void Component::repaintParent()
  31958. {
  31959. if (flags.visibleFlag)
  31960. internalRepaint (0, 0, getWidth(), getHeight());
  31961. }
  31962. void Component::repaint()
  31963. {
  31964. repaint (0, 0, getWidth(), getHeight());
  31965. }
  31966. void Component::repaint (const int x, const int y,
  31967. const int w, const int h)
  31968. {
  31969. deleteAndZero (bufferedImage_);
  31970. if (flags.visibleFlag)
  31971. internalRepaint (x, y, w, h);
  31972. }
  31973. void Component::internalRepaint (int x, int y, int w, int h)
  31974. {
  31975. // if component methods are being called from threads other than the message
  31976. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31977. checkMessageManagerIsLocked
  31978. if (x < 0)
  31979. {
  31980. w += x;
  31981. x = 0;
  31982. }
  31983. if (x + w > getWidth())
  31984. w = getWidth() - x;
  31985. if (w > 0)
  31986. {
  31987. if (y < 0)
  31988. {
  31989. h += y;
  31990. y = 0;
  31991. }
  31992. if (y + h > getHeight())
  31993. h = getHeight() - y;
  31994. if (h > 0)
  31995. {
  31996. if (parentComponent_ != 0)
  31997. {
  31998. x += getX();
  31999. y += getY();
  32000. if (parentComponent_->flags.visibleFlag)
  32001. parentComponent_->internalRepaint (x, y, w, h);
  32002. }
  32003. else if (flags.hasHeavyweightPeerFlag)
  32004. {
  32005. ComponentPeer* const peer = getPeer();
  32006. if (peer != 0)
  32007. peer->repaint (x, y, w, h);
  32008. }
  32009. }
  32010. }
  32011. }
  32012. void Component::renderComponent (Graphics& g)
  32013. {
  32014. const Rectangle<int> clipBounds (g.getClipBounds());
  32015. g.saveState();
  32016. clipObscuredRegions (g, clipBounds, 0, 0);
  32017. if (! g.isClipEmpty())
  32018. {
  32019. if (flags.bufferToImageFlag)
  32020. {
  32021. if (bufferedImage_ == 0)
  32022. {
  32023. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32024. getWidth(), getHeight(), ! flags.opaqueFlag);
  32025. Graphics imG (*bufferedImage_);
  32026. paint (imG);
  32027. }
  32028. g.setColour (Colours::black);
  32029. g.drawImageAt (bufferedImage_, 0, 0);
  32030. }
  32031. else
  32032. {
  32033. paint (g);
  32034. }
  32035. }
  32036. g.restoreState();
  32037. for (int i = 0; i < childComponentList_.size(); ++i)
  32038. {
  32039. Component* const child = childComponentList_.getUnchecked (i);
  32040. if (child->isVisible() && clipBounds.intersects (child->getBounds()))
  32041. {
  32042. g.saveState();
  32043. if (g.reduceClipRegion (child->getX(), child->getY(),
  32044. child->getWidth(), child->getHeight()))
  32045. {
  32046. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32047. {
  32048. const Component* const sibling = childComponentList_.getUnchecked (j);
  32049. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32050. g.excludeClipRegion (sibling->getBounds());
  32051. }
  32052. if (! g.isClipEmpty())
  32053. {
  32054. g.setOrigin (child->getX(), child->getY());
  32055. child->paintEntireComponent (g);
  32056. }
  32057. }
  32058. g.restoreState();
  32059. }
  32060. }
  32061. g.saveState();
  32062. paintOverChildren (g);
  32063. g.restoreState();
  32064. }
  32065. void Component::paintEntireComponent (Graphics& g)
  32066. {
  32067. jassert (! g.isClipEmpty());
  32068. #ifdef JUCE_DEBUG
  32069. flags.isInsidePaintCall = true;
  32070. #endif
  32071. if (effect_ != 0)
  32072. {
  32073. ScopedPointer<Image> effectImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32074. getWidth(), getHeight(),
  32075. ! flags.opaqueFlag));
  32076. {
  32077. Graphics g2 (*effectImage);
  32078. renderComponent (g2);
  32079. }
  32080. effect_->applyEffect (*effectImage, g);
  32081. }
  32082. else
  32083. {
  32084. renderComponent (g);
  32085. }
  32086. #ifdef JUCE_DEBUG
  32087. flags.isInsidePaintCall = false;
  32088. #endif
  32089. }
  32090. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32091. const bool clipImageToComponentBounds)
  32092. {
  32093. Rectangle<int> r (areaToGrab);
  32094. if (clipImageToComponentBounds)
  32095. r = r.getIntersection (getLocalBounds());
  32096. ScopedPointer<Image> componentImage (Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32097. jmax (1, r.getWidth()),
  32098. jmax (1, r.getHeight()),
  32099. true));
  32100. Graphics imageContext (*componentImage);
  32101. imageContext.setOrigin (-r.getX(), -r.getY());
  32102. paintEntireComponent (imageContext);
  32103. return componentImage.release();
  32104. }
  32105. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32106. {
  32107. if (effect_ != effect)
  32108. {
  32109. effect_ = effect;
  32110. repaint();
  32111. }
  32112. }
  32113. LookAndFeel& Component::getLookAndFeel() const throw()
  32114. {
  32115. const Component* c = this;
  32116. do
  32117. {
  32118. if (c->lookAndFeel_ != 0)
  32119. return *(c->lookAndFeel_);
  32120. c = c->parentComponent_;
  32121. }
  32122. while (c != 0);
  32123. return LookAndFeel::getDefaultLookAndFeel();
  32124. }
  32125. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32126. {
  32127. if (lookAndFeel_ != newLookAndFeel)
  32128. {
  32129. lookAndFeel_ = newLookAndFeel;
  32130. sendLookAndFeelChange();
  32131. }
  32132. }
  32133. void Component::lookAndFeelChanged()
  32134. {
  32135. }
  32136. void Component::sendLookAndFeelChange()
  32137. {
  32138. repaint();
  32139. lookAndFeelChanged();
  32140. // (it's not a great idea to do anything that would delete this component
  32141. // during the lookAndFeelChanged() callback)
  32142. jassert (isValidComponent());
  32143. SafePointer<Component> safePointer (this);
  32144. for (int i = childComponentList_.size(); --i >= 0;)
  32145. {
  32146. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32147. if (safePointer == 0)
  32148. return;
  32149. i = jmin (i, childComponentList_.size());
  32150. }
  32151. }
  32152. static const var::identifier getColourPropertyId (const int colourId)
  32153. {
  32154. String s;
  32155. s.preallocateStorage (18);
  32156. s << "jcclr_" << String::toHexString (colourId);
  32157. return s;
  32158. }
  32159. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const
  32160. {
  32161. var* v = properties.getItem (getColourPropertyId (colourId));
  32162. if (v != 0)
  32163. return Colour ((int) *v);
  32164. if (inheritFromParent && parentComponent_ != 0)
  32165. return parentComponent_->findColour (colourId, true);
  32166. return getLookAndFeel().findColour (colourId);
  32167. }
  32168. bool Component::isColourSpecified (const int colourId) const
  32169. {
  32170. return properties.contains (getColourPropertyId (colourId));
  32171. }
  32172. void Component::removeColour (const int colourId)
  32173. {
  32174. if (properties.remove (getColourPropertyId (colourId)))
  32175. colourChanged();
  32176. }
  32177. void Component::setColour (const int colourId, const Colour& colour)
  32178. {
  32179. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32180. colourChanged();
  32181. }
  32182. void Component::copyAllExplicitColoursTo (Component& target) const
  32183. {
  32184. bool changed = false;
  32185. for (int i = properties.size(); --i >= 0;)
  32186. {
  32187. const var::identifier name (properties.getName(i));
  32188. if (name.name.startsWith ("jcclr_"))
  32189. if (target.properties.set (name, properties [name]))
  32190. changed = true;
  32191. }
  32192. if (changed)
  32193. target.colourChanged();
  32194. }
  32195. void Component::colourChanged()
  32196. {
  32197. }
  32198. const Rectangle<int> Component::getLocalBounds() const throw()
  32199. {
  32200. return Rectangle<int> (0, 0, getWidth(), getHeight());
  32201. }
  32202. const Rectangle<int> Component::getUnclippedArea() const
  32203. {
  32204. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32205. Component* p = parentComponent_;
  32206. int px = getX();
  32207. int py = getY();
  32208. while (p != 0)
  32209. {
  32210. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32211. return Rectangle<int>();
  32212. px += p->getX();
  32213. py += p->getY();
  32214. p = p->parentComponent_;
  32215. }
  32216. return Rectangle<int> (x, y, w, h);
  32217. }
  32218. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32219. const int deltaX, const int deltaY) const
  32220. {
  32221. for (int i = childComponentList_.size(); --i >= 0;)
  32222. {
  32223. const Component* const c = childComponentList_.getUnchecked(i);
  32224. if (c->isVisible())
  32225. {
  32226. const Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32227. if (! newClip.isEmpty())
  32228. {
  32229. if (c->isOpaque())
  32230. {
  32231. g.excludeClipRegion (newClip.translated (deltaX, deltaY));
  32232. }
  32233. else
  32234. {
  32235. c->clipObscuredRegions (g, newClip.translated (-c->getX(), -c->getY()),
  32236. c->getX() + deltaX,
  32237. c->getY() + deltaY);
  32238. }
  32239. }
  32240. }
  32241. }
  32242. }
  32243. void Component::getVisibleArea (RectangleList& result, const bool includeSiblings) const
  32244. {
  32245. result.clear();
  32246. const Rectangle<int> unclipped (getUnclippedArea());
  32247. if (! unclipped.isEmpty())
  32248. {
  32249. result.add (unclipped);
  32250. if (includeSiblings)
  32251. {
  32252. const Component* const c = getTopLevelComponent();
  32253. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32254. c->getLocalBounds(), this);
  32255. }
  32256. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32257. result.consolidate();
  32258. }
  32259. }
  32260. void Component::subtractObscuredRegions (RectangleList& result,
  32261. const Point<int>& delta,
  32262. const Rectangle<int>& clipRect,
  32263. const Component* const compToAvoid) const
  32264. {
  32265. for (int i = childComponentList_.size(); --i >= 0;)
  32266. {
  32267. const Component* const c = childComponentList_.getUnchecked(i);
  32268. if (c != compToAvoid && c->isVisible())
  32269. {
  32270. if (c->isOpaque())
  32271. {
  32272. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32273. childBounds.translate (delta.getX(), delta.getY());
  32274. result.subtract (childBounds);
  32275. }
  32276. else
  32277. {
  32278. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32279. newClip.translate (-c->getX(), -c->getY());
  32280. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32281. newClip, compToAvoid);
  32282. }
  32283. }
  32284. }
  32285. }
  32286. void Component::mouseEnter (const MouseEvent&)
  32287. {
  32288. // base class does nothing
  32289. }
  32290. void Component::mouseExit (const MouseEvent&)
  32291. {
  32292. // base class does nothing
  32293. }
  32294. void Component::mouseDown (const MouseEvent&)
  32295. {
  32296. // base class does nothing
  32297. }
  32298. void Component::mouseUp (const MouseEvent&)
  32299. {
  32300. // base class does nothing
  32301. }
  32302. void Component::mouseDrag (const MouseEvent&)
  32303. {
  32304. // base class does nothing
  32305. }
  32306. void Component::mouseMove (const MouseEvent&)
  32307. {
  32308. // base class does nothing
  32309. }
  32310. void Component::mouseDoubleClick (const MouseEvent&)
  32311. {
  32312. // base class does nothing
  32313. }
  32314. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32315. {
  32316. // the base class just passes this event up to its parent..
  32317. if (parentComponent_ != 0)
  32318. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32319. wheelIncrementX, wheelIncrementY);
  32320. }
  32321. void Component::resized()
  32322. {
  32323. // base class does nothing
  32324. }
  32325. void Component::moved()
  32326. {
  32327. // base class does nothing
  32328. }
  32329. void Component::childBoundsChanged (Component*)
  32330. {
  32331. // base class does nothing
  32332. }
  32333. void Component::parentSizeChanged()
  32334. {
  32335. // base class does nothing
  32336. }
  32337. void Component::addComponentListener (ComponentListener* const newListener)
  32338. {
  32339. jassert (isValidComponent());
  32340. componentListeners.add (newListener);
  32341. }
  32342. void Component::removeComponentListener (ComponentListener* const listenerToRemove)
  32343. {
  32344. jassert (isValidComponent());
  32345. componentListeners.remove (listenerToRemove);
  32346. }
  32347. void Component::inputAttemptWhenModal()
  32348. {
  32349. bringModalComponentToFront();
  32350. getLookAndFeel().playAlertSound();
  32351. }
  32352. bool Component::canModalEventBeSentToComponent (const Component*)
  32353. {
  32354. return false;
  32355. }
  32356. void Component::internalModalInputAttempt()
  32357. {
  32358. Component* const current = getCurrentlyModalComponent();
  32359. if (current != 0)
  32360. current->inputAttemptWhenModal();
  32361. }
  32362. void Component::paint (Graphics&)
  32363. {
  32364. // all painting is done in the subclasses
  32365. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32366. }
  32367. void Component::paintOverChildren (Graphics&)
  32368. {
  32369. // all painting is done in the subclasses
  32370. }
  32371. void Component::handleMessage (const Message& message)
  32372. {
  32373. if (message.intParameter1 == exitModalStateMessage)
  32374. {
  32375. exitModalState (message.intParameter2);
  32376. }
  32377. else if (message.intParameter1 == customCommandMessage)
  32378. {
  32379. handleCommandMessage (message.intParameter2);
  32380. }
  32381. }
  32382. void Component::postCommandMessage (const int commandId)
  32383. {
  32384. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32385. }
  32386. void Component::handleCommandMessage (int)
  32387. {
  32388. // used by subclasses
  32389. }
  32390. void Component::addMouseListener (MouseListener* const newListener,
  32391. const bool wantsEventsForAllNestedChildComponents)
  32392. {
  32393. // if component methods are being called from threads other than the message
  32394. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32395. checkMessageManagerIsLocked
  32396. if (mouseListeners_ == 0)
  32397. mouseListeners_ = new Array<MouseListener*>();
  32398. if (! mouseListeners_->contains (newListener))
  32399. {
  32400. if (wantsEventsForAllNestedChildComponents)
  32401. {
  32402. mouseListeners_->insert (0, newListener);
  32403. ++numDeepMouseListeners;
  32404. }
  32405. else
  32406. {
  32407. mouseListeners_->add (newListener);
  32408. }
  32409. }
  32410. }
  32411. void Component::removeMouseListener (MouseListener* const listenerToRemove)
  32412. {
  32413. // if component methods are being called from threads other than the message
  32414. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32415. checkMessageManagerIsLocked
  32416. if (mouseListeners_ != 0)
  32417. {
  32418. const int index = mouseListeners_->indexOf (listenerToRemove);
  32419. if (index >= 0)
  32420. {
  32421. if (index < numDeepMouseListeners)
  32422. --numDeepMouseListeners;
  32423. mouseListeners_->remove (index);
  32424. }
  32425. }
  32426. }
  32427. void Component::internalMouseEnter (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32428. {
  32429. if (isCurrentlyBlockedByAnotherModalComponent())
  32430. {
  32431. // if something else is modal, always just show a normal mouse cursor
  32432. source.showMouseCursor (MouseCursor::NormalCursor);
  32433. return;
  32434. }
  32435. if (! flags.mouseInsideFlag)
  32436. {
  32437. flags.mouseInsideFlag = true;
  32438. flags.mouseOverFlag = true;
  32439. flags.draggingFlag = false;
  32440. BailOutChecker checker (this);
  32441. if (flags.repaintOnMouseActivityFlag)
  32442. repaint();
  32443. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32444. this, time, relativePos,
  32445. time, 0, false);
  32446. mouseEnter (me);
  32447. if (checker.shouldBailOut())
  32448. return;
  32449. Desktop::getInstance().resetTimer();
  32450. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseEnter, me);
  32451. if (checker.shouldBailOut())
  32452. return;
  32453. if (mouseListeners_ != 0)
  32454. {
  32455. for (int i = mouseListeners_->size(); --i >= 0;)
  32456. {
  32457. mouseListeners_->getUnchecked(i)->mouseEnter (me);
  32458. if (checker.shouldBailOut())
  32459. return;
  32460. i = jmin (i, mouseListeners_->size());
  32461. }
  32462. }
  32463. Component* p = parentComponent_;
  32464. while (p != 0)
  32465. {
  32466. if (p->numDeepMouseListeners > 0)
  32467. {
  32468. BailOutChecker checker (this, p);
  32469. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32470. {
  32471. p->mouseListeners_->getUnchecked(i)->mouseEnter (me);
  32472. if (checker.shouldBailOut())
  32473. return;
  32474. i = jmin (i, p->numDeepMouseListeners);
  32475. }
  32476. }
  32477. p = p->parentComponent_;
  32478. }
  32479. }
  32480. }
  32481. void Component::internalMouseExit (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32482. {
  32483. BailOutChecker checker (this);
  32484. if (flags.draggingFlag)
  32485. {
  32486. internalMouseUp (source, relativePos, time, source.getCurrentModifiers().getRawFlags());
  32487. if (checker.shouldBailOut())
  32488. return;
  32489. }
  32490. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32491. {
  32492. flags.mouseInsideFlag = false;
  32493. flags.mouseOverFlag = false;
  32494. flags.draggingFlag = false;
  32495. if (flags.repaintOnMouseActivityFlag)
  32496. repaint();
  32497. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32498. this, time, relativePos,
  32499. time, 0, false);
  32500. mouseExit (me);
  32501. if (checker.shouldBailOut())
  32502. return;
  32503. Desktop::getInstance().resetTimer();
  32504. Desktop::getInstance().mouseListeners.callChecked (checker, &MouseListener::mouseExit, me);
  32505. if (checker.shouldBailOut())
  32506. return;
  32507. if (mouseListeners_ != 0)
  32508. {
  32509. for (int i = mouseListeners_->size(); --i >= 0;)
  32510. {
  32511. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32512. if (checker.shouldBailOut())
  32513. return;
  32514. i = jmin (i, mouseListeners_->size());
  32515. }
  32516. }
  32517. Component* p = parentComponent_;
  32518. while (p != 0)
  32519. {
  32520. if (p->numDeepMouseListeners > 0)
  32521. {
  32522. BailOutChecker checker (this, p);
  32523. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32524. {
  32525. p->mouseListeners_->getUnchecked (i)->mouseExit (me);
  32526. if (checker.shouldBailOut())
  32527. return;
  32528. i = jmin (i, p->numDeepMouseListeners);
  32529. }
  32530. }
  32531. p = p->parentComponent_;
  32532. }
  32533. }
  32534. }
  32535. class InternalDragRepeater : public Timer
  32536. {
  32537. public:
  32538. InternalDragRepeater()
  32539. {}
  32540. ~InternalDragRepeater()
  32541. {
  32542. clearSingletonInstance();
  32543. }
  32544. juce_DeclareSingleton_SingleThreaded_Minimal (InternalDragRepeater)
  32545. void timerCallback()
  32546. {
  32547. Desktop& desktop = Desktop::getInstance();
  32548. int numMiceDown = 0;
  32549. for (int i = desktop.getNumMouseSources(); --i >= 0;)
  32550. {
  32551. MouseInputSource* const source = desktop.getMouseSource(i);
  32552. if (source->isDragging())
  32553. {
  32554. source->triggerFakeMove();
  32555. ++numMiceDown;
  32556. }
  32557. }
  32558. if (numMiceDown == 0)
  32559. deleteInstance();
  32560. }
  32561. juce_UseDebuggingNewOperator
  32562. private:
  32563. InternalDragRepeater (const InternalDragRepeater&);
  32564. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32565. };
  32566. juce_ImplementSingleton_SingleThreaded (InternalDragRepeater)
  32567. void Component::beginDragAutoRepeat (const int interval)
  32568. {
  32569. if (interval > 0)
  32570. {
  32571. if (InternalDragRepeater::getInstance()->getTimerInterval() != interval)
  32572. InternalDragRepeater::getInstance()->startTimer (interval);
  32573. }
  32574. else
  32575. {
  32576. InternalDragRepeater::deleteInstance();
  32577. }
  32578. }
  32579. void Component::internalMouseDown (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32580. {
  32581. Desktop& desktop = Desktop::getInstance();
  32582. BailOutChecker checker (this);
  32583. if (isCurrentlyBlockedByAnotherModalComponent())
  32584. {
  32585. internalModalInputAttempt();
  32586. if (checker.shouldBailOut())
  32587. return;
  32588. // If processing the input attempt has exited the modal loop, we'll allow the event
  32589. // to be delivered..
  32590. if (isCurrentlyBlockedByAnotherModalComponent())
  32591. {
  32592. // allow blocked mouse-events to go to global listeners..
  32593. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32594. this, time, relativePos, time,
  32595. source.getNumberOfMultipleClicks(), false);
  32596. desktop.resetTimer();
  32597. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32598. return;
  32599. }
  32600. }
  32601. {
  32602. Component* c = this;
  32603. while (c != 0)
  32604. {
  32605. if (c->isBroughtToFrontOnMouseClick())
  32606. {
  32607. c->toFront (true);
  32608. if (checker.shouldBailOut())
  32609. return;
  32610. }
  32611. c = c->parentComponent_;
  32612. }
  32613. }
  32614. if (! flags.dontFocusOnMouseClickFlag)
  32615. {
  32616. grabFocusInternal (focusChangedByMouseClick);
  32617. if (checker.shouldBailOut())
  32618. return;
  32619. }
  32620. flags.draggingFlag = true;
  32621. flags.mouseOverFlag = true;
  32622. if (flags.repaintOnMouseActivityFlag)
  32623. repaint();
  32624. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32625. this, time, relativePos, time,
  32626. source.getNumberOfMultipleClicks(), false);
  32627. mouseDown (me);
  32628. if (checker.shouldBailOut())
  32629. return;
  32630. desktop.resetTimer();
  32631. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDown, me);
  32632. if (checker.shouldBailOut())
  32633. return;
  32634. if (mouseListeners_ != 0)
  32635. {
  32636. for (int i = mouseListeners_->size(); --i >= 0;)
  32637. {
  32638. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  32639. if (checker.shouldBailOut())
  32640. return;
  32641. i = jmin (i, mouseListeners_->size());
  32642. }
  32643. }
  32644. Component* p = parentComponent_;
  32645. while (p != 0)
  32646. {
  32647. if (p->numDeepMouseListeners > 0)
  32648. {
  32649. BailOutChecker checker (this, p);
  32650. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32651. {
  32652. p->mouseListeners_->getUnchecked (i)->mouseDown (me);
  32653. if (checker.shouldBailOut())
  32654. return;
  32655. i = jmin (i, p->numDeepMouseListeners);
  32656. }
  32657. }
  32658. p = p->parentComponent_;
  32659. }
  32660. }
  32661. void Component::internalMouseUp (MouseInputSource& source, const Point<int>& relativePos, const Time& time, const ModifierKeys& oldModifiers)
  32662. {
  32663. if (flags.draggingFlag)
  32664. {
  32665. Desktop& desktop = Desktop::getInstance();
  32666. flags.draggingFlag = false;
  32667. BailOutChecker checker (this);
  32668. if (flags.repaintOnMouseActivityFlag)
  32669. repaint();
  32670. const MouseEvent me (source, relativePos,
  32671. oldModifiers, this, time,
  32672. globalPositionToRelative (source.getLastMouseDownPosition()),
  32673. source.getLastMouseDownTime(),
  32674. source.getNumberOfMultipleClicks(),
  32675. source.hasMouseMovedSignificantlySincePressed());
  32676. mouseUp (me);
  32677. if (checker.shouldBailOut())
  32678. return;
  32679. desktop.resetTimer();
  32680. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseUp, me);
  32681. if (checker.shouldBailOut())
  32682. return;
  32683. if (mouseListeners_ != 0)
  32684. {
  32685. for (int i = mouseListeners_->size(); --i >= 0;)
  32686. {
  32687. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  32688. if (checker.shouldBailOut())
  32689. return;
  32690. i = jmin (i, mouseListeners_->size());
  32691. }
  32692. }
  32693. {
  32694. Component* p = parentComponent_;
  32695. while (p != 0)
  32696. {
  32697. if (p->numDeepMouseListeners > 0)
  32698. {
  32699. BailOutChecker checker (this, p);
  32700. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32701. {
  32702. p->mouseListeners_->getUnchecked (i)->mouseUp (me);
  32703. if (checker.shouldBailOut())
  32704. return;
  32705. i = jmin (i, p->numDeepMouseListeners);
  32706. }
  32707. }
  32708. p = p->parentComponent_;
  32709. }
  32710. }
  32711. // check for double-click
  32712. if (me.getNumberOfClicks() >= 2)
  32713. {
  32714. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  32715. mouseDoubleClick (me);
  32716. if (checker.shouldBailOut())
  32717. return;
  32718. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDoubleClick, me);
  32719. if (checker.shouldBailOut())
  32720. return;
  32721. for (int i = numListeners; --i >= 0;)
  32722. {
  32723. if (checker.shouldBailOut())
  32724. return;
  32725. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  32726. if (ml != 0)
  32727. ml->mouseDoubleClick (me);
  32728. }
  32729. if (checker.shouldBailOut())
  32730. return;
  32731. Component* p = parentComponent_;
  32732. while (p != 0)
  32733. {
  32734. if (p->numDeepMouseListeners > 0)
  32735. {
  32736. BailOutChecker checker (this, p);
  32737. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32738. {
  32739. p->mouseListeners_->getUnchecked (i)->mouseDoubleClick (me);
  32740. if (checker.shouldBailOut())
  32741. return;
  32742. i = jmin (i, p->numDeepMouseListeners);
  32743. }
  32744. }
  32745. p = p->parentComponent_;
  32746. }
  32747. }
  32748. }
  32749. }
  32750. void Component::internalMouseDrag (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32751. {
  32752. if (flags.draggingFlag)
  32753. {
  32754. Desktop& desktop = Desktop::getInstance();
  32755. flags.mouseOverFlag = reallyContains (relativePos.getX(), relativePos.getY(), false);
  32756. BailOutChecker checker (this);
  32757. const MouseEvent me (source, relativePos,
  32758. source.getCurrentModifiers(), this, time,
  32759. globalPositionToRelative (source.getLastMouseDownPosition()),
  32760. source.getLastMouseDownTime(),
  32761. source.getNumberOfMultipleClicks(),
  32762. source.hasMouseMovedSignificantlySincePressed());
  32763. mouseDrag (me);
  32764. if (checker.shouldBailOut())
  32765. return;
  32766. desktop.resetTimer();
  32767. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  32768. if (checker.shouldBailOut())
  32769. return;
  32770. if (mouseListeners_ != 0)
  32771. {
  32772. for (int i = mouseListeners_->size(); --i >= 0;)
  32773. {
  32774. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  32775. if (checker.shouldBailOut())
  32776. return;
  32777. i = jmin (i, mouseListeners_->size());
  32778. }
  32779. }
  32780. Component* p = parentComponent_;
  32781. while (p != 0)
  32782. {
  32783. if (p->numDeepMouseListeners > 0)
  32784. {
  32785. BailOutChecker checker (this, p);
  32786. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32787. {
  32788. p->mouseListeners_->getUnchecked (i)->mouseDrag (me);
  32789. if (checker.shouldBailOut())
  32790. return;
  32791. i = jmin (i, p->numDeepMouseListeners);
  32792. }
  32793. }
  32794. p = p->parentComponent_;
  32795. }
  32796. }
  32797. }
  32798. void Component::internalMouseMove (MouseInputSource& source, const Point<int>& relativePos, const Time& time)
  32799. {
  32800. Desktop& desktop = Desktop::getInstance();
  32801. BailOutChecker checker (this);
  32802. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32803. this, time, relativePos,
  32804. time, 0, false);
  32805. if (isCurrentlyBlockedByAnotherModalComponent())
  32806. {
  32807. // allow blocked mouse-events to go to global listeners..
  32808. desktop.sendMouseMove();
  32809. }
  32810. else
  32811. {
  32812. flags.mouseOverFlag = true;
  32813. mouseMove (me);
  32814. if (checker.shouldBailOut())
  32815. return;
  32816. desktop.resetTimer();
  32817. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  32818. if (checker.shouldBailOut())
  32819. return;
  32820. if (mouseListeners_ != 0)
  32821. {
  32822. for (int i = mouseListeners_->size(); --i >= 0;)
  32823. {
  32824. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  32825. if (checker.shouldBailOut())
  32826. return;
  32827. i = jmin (i, mouseListeners_->size());
  32828. }
  32829. }
  32830. Component* p = parentComponent_;
  32831. while (p != 0)
  32832. {
  32833. if (p->numDeepMouseListeners > 0)
  32834. {
  32835. BailOutChecker checker (this, p);
  32836. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32837. {
  32838. p->mouseListeners_->getUnchecked (i)->mouseMove (me);
  32839. if (checker.shouldBailOut())
  32840. return;
  32841. i = jmin (i, p->numDeepMouseListeners);
  32842. }
  32843. }
  32844. p = p->parentComponent_;
  32845. }
  32846. }
  32847. }
  32848. void Component::internalMouseWheel (MouseInputSource& source, const Point<int>& relativePos,
  32849. const Time& time, const float amountX, const float amountY)
  32850. {
  32851. Desktop& desktop = Desktop::getInstance();
  32852. BailOutChecker checker (this);
  32853. const float wheelIncrementX = amountX * (1.0f / 256.0f);
  32854. const float wheelIncrementY = amountY * (1.0f / 256.0f);
  32855. const MouseEvent me (source, relativePos, source.getCurrentModifiers(),
  32856. this, time, relativePos, time, 0, false);
  32857. if (isCurrentlyBlockedByAnotherModalComponent())
  32858. {
  32859. // allow blocked mouse-events to go to global listeners..
  32860. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32861. }
  32862. else
  32863. {
  32864. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32865. if (checker.shouldBailOut())
  32866. return;
  32867. desktop.mouseListeners.callChecked (checker, &MouseListener::mouseWheelMove, me, wheelIncrementX, wheelIncrementY);
  32868. if (checker.shouldBailOut())
  32869. return;
  32870. if (mouseListeners_ != 0)
  32871. {
  32872. for (int i = mouseListeners_->size(); --i >= 0;)
  32873. {
  32874. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32875. if (checker.shouldBailOut())
  32876. return;
  32877. i = jmin (i, mouseListeners_->size());
  32878. }
  32879. }
  32880. Component* p = parentComponent_;
  32881. while (p != 0)
  32882. {
  32883. if (p->numDeepMouseListeners > 0)
  32884. {
  32885. BailOutChecker checker (this, p);
  32886. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32887. {
  32888. p->mouseListeners_->getUnchecked (i)->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  32889. if (checker.shouldBailOut())
  32890. return;
  32891. i = jmin (i, p->numDeepMouseListeners);
  32892. }
  32893. }
  32894. p = p->parentComponent_;
  32895. }
  32896. }
  32897. }
  32898. void Component::sendFakeMouseMove() const
  32899. {
  32900. Desktop::getInstance().getMainMouseSource().triggerFakeMove();
  32901. }
  32902. void Component::broughtToFront()
  32903. {
  32904. }
  32905. void Component::internalBroughtToFront()
  32906. {
  32907. if (! isValidComponent())
  32908. return;
  32909. if (flags.hasHeavyweightPeerFlag)
  32910. Desktop::getInstance().componentBroughtToFront (this);
  32911. BailOutChecker checker (this);
  32912. broughtToFront();
  32913. if (checker.shouldBailOut())
  32914. return;
  32915. componentListeners.callChecked (checker, &ComponentListener::componentBroughtToFront, *this);
  32916. if (checker.shouldBailOut())
  32917. return;
  32918. // When brought to the front and there's a modal component blocking this one,
  32919. // we need to bring the modal one to the front instead..
  32920. Component* const cm = getCurrentlyModalComponent();
  32921. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  32922. bringModalComponentToFront();
  32923. }
  32924. void Component::focusGained (FocusChangeType)
  32925. {
  32926. // base class does nothing
  32927. }
  32928. void Component::internalFocusGain (const FocusChangeType cause)
  32929. {
  32930. SafePointer<Component> safePointer (this);
  32931. focusGained (cause);
  32932. if (safePointer != 0)
  32933. internalChildFocusChange (cause);
  32934. }
  32935. void Component::focusLost (FocusChangeType)
  32936. {
  32937. // base class does nothing
  32938. }
  32939. void Component::internalFocusLoss (const FocusChangeType cause)
  32940. {
  32941. SafePointer<Component> safePointer (this);
  32942. focusLost (focusChangedDirectly);
  32943. if (safePointer != 0)
  32944. internalChildFocusChange (cause);
  32945. }
  32946. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  32947. {
  32948. // base class does nothing
  32949. }
  32950. void Component::internalChildFocusChange (FocusChangeType cause)
  32951. {
  32952. const bool childIsNowFocused = hasKeyboardFocus (true);
  32953. if (flags.childCompFocusedFlag != childIsNowFocused)
  32954. {
  32955. flags.childCompFocusedFlag = childIsNowFocused;
  32956. SafePointer<Component> safePointer (this);
  32957. focusOfChildComponentChanged (cause);
  32958. if (safePointer == 0)
  32959. return;
  32960. }
  32961. if (parentComponent_ != 0)
  32962. parentComponent_->internalChildFocusChange (cause);
  32963. }
  32964. bool Component::isEnabled() const throw()
  32965. {
  32966. return (! flags.isDisabledFlag)
  32967. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  32968. }
  32969. void Component::setEnabled (const bool shouldBeEnabled)
  32970. {
  32971. if (flags.isDisabledFlag == shouldBeEnabled)
  32972. {
  32973. flags.isDisabledFlag = ! shouldBeEnabled;
  32974. // if any parent components are disabled, setting our flag won't make a difference,
  32975. // so no need to send a change message
  32976. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  32977. sendEnablementChangeMessage();
  32978. }
  32979. }
  32980. void Component::sendEnablementChangeMessage()
  32981. {
  32982. SafePointer<Component> safePointer (this);
  32983. enablementChanged();
  32984. if (safePointer == 0)
  32985. return;
  32986. for (int i = getNumChildComponents(); --i >= 0;)
  32987. {
  32988. Component* const c = getChildComponent (i);
  32989. if (c != 0)
  32990. {
  32991. c->sendEnablementChangeMessage();
  32992. if (safePointer == 0)
  32993. return;
  32994. }
  32995. }
  32996. }
  32997. void Component::enablementChanged()
  32998. {
  32999. }
  33000. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33001. {
  33002. flags.wantsFocusFlag = wantsFocus;
  33003. }
  33004. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33005. {
  33006. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33007. }
  33008. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33009. {
  33010. return ! flags.dontFocusOnMouseClickFlag;
  33011. }
  33012. bool Component::getWantsKeyboardFocus() const throw()
  33013. {
  33014. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33015. }
  33016. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33017. {
  33018. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33019. }
  33020. bool Component::isFocusContainer() const throw()
  33021. {
  33022. return flags.isFocusContainerFlag;
  33023. }
  33024. int Component::getExplicitFocusOrder() const
  33025. {
  33026. return properties ["_jexfo"];
  33027. }
  33028. void Component::setExplicitFocusOrder (const int newFocusOrderIndex)
  33029. {
  33030. properties.set ("_jexfo", newFocusOrderIndex);
  33031. }
  33032. KeyboardFocusTraverser* Component::createFocusTraverser()
  33033. {
  33034. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33035. return new KeyboardFocusTraverser();
  33036. return parentComponent_->createFocusTraverser();
  33037. }
  33038. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33039. {
  33040. // give the focus to this component
  33041. if (currentlyFocusedComponent != this)
  33042. {
  33043. JUCE_TRY
  33044. {
  33045. // get the focus onto our desktop window
  33046. ComponentPeer* const peer = getPeer();
  33047. if (peer != 0)
  33048. {
  33049. SafePointer<Component> safePointer (this);
  33050. peer->grabFocus();
  33051. if (peer->isFocused() && currentlyFocusedComponent != this)
  33052. {
  33053. Component* const componentLosingFocus = currentlyFocusedComponent;
  33054. currentlyFocusedComponent = this;
  33055. Desktop::getInstance().triggerFocusCallback();
  33056. // call this after setting currentlyFocusedComponent so that the one that's
  33057. // losing it has a chance to see where focus is going
  33058. if (componentLosingFocus->isValidComponent())
  33059. componentLosingFocus->internalFocusLoss (cause);
  33060. if (currentlyFocusedComponent == this)
  33061. {
  33062. focusGained (cause);
  33063. if (safePointer != 0)
  33064. internalChildFocusChange (cause);
  33065. }
  33066. }
  33067. }
  33068. }
  33069. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33070. catch (const std::exception& e)
  33071. {
  33072. currentlyFocusedComponent = 0;
  33073. Desktop::getInstance().triggerFocusCallback();
  33074. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33075. }
  33076. catch (...)
  33077. {
  33078. currentlyFocusedComponent = 0;
  33079. Desktop::getInstance().triggerFocusCallback();
  33080. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33081. }
  33082. #endif
  33083. }
  33084. }
  33085. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33086. {
  33087. if (isShowing())
  33088. {
  33089. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33090. {
  33091. takeKeyboardFocus (cause);
  33092. }
  33093. else
  33094. {
  33095. if (isParentOf (currentlyFocusedComponent)
  33096. && currentlyFocusedComponent->isShowing())
  33097. {
  33098. // do nothing if the focused component is actually a child of ours..
  33099. }
  33100. else
  33101. {
  33102. // find the default child component..
  33103. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33104. if (traverser != 0)
  33105. {
  33106. Component* const defaultComp = traverser->getDefaultComponent (this);
  33107. traverser = 0;
  33108. if (defaultComp != 0)
  33109. {
  33110. defaultComp->grabFocusInternal (cause, false);
  33111. return;
  33112. }
  33113. }
  33114. if (canTryParent && parentComponent_ != 0)
  33115. {
  33116. // if no children want it and we're allowed to try our parent comp,
  33117. // then pass up to parent, which will try our siblings.
  33118. parentComponent_->grabFocusInternal (cause, true);
  33119. }
  33120. }
  33121. }
  33122. }
  33123. }
  33124. void Component::grabKeyboardFocus()
  33125. {
  33126. // if component methods are being called from threads other than the message
  33127. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33128. checkMessageManagerIsLocked
  33129. grabFocusInternal (focusChangedDirectly);
  33130. }
  33131. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33132. {
  33133. // if component methods are being called from threads other than the message
  33134. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33135. checkMessageManagerIsLocked
  33136. if (parentComponent_ != 0)
  33137. {
  33138. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33139. if (traverser != 0)
  33140. {
  33141. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33142. : traverser->getPreviousComponent (this);
  33143. traverser = 0;
  33144. if (nextComp != 0)
  33145. {
  33146. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33147. {
  33148. SafePointer<Component> nextCompPointer (nextComp);
  33149. internalModalInputAttempt();
  33150. if (nextCompPointer == 0 || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33151. return;
  33152. }
  33153. nextComp->grabFocusInternal (focusChangedByTabKey);
  33154. return;
  33155. }
  33156. }
  33157. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33158. }
  33159. }
  33160. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const
  33161. {
  33162. return (currentlyFocusedComponent == this)
  33163. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33164. }
  33165. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33166. {
  33167. return currentlyFocusedComponent;
  33168. }
  33169. void Component::giveAwayFocus()
  33170. {
  33171. // use a copy so we can clear the value before the call
  33172. Component* const componentLosingFocus = currentlyFocusedComponent;
  33173. currentlyFocusedComponent = 0;
  33174. Desktop::getInstance().triggerFocusCallback();
  33175. if (componentLosingFocus->isValidComponent())
  33176. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33177. }
  33178. bool Component::isMouseOver() const throw()
  33179. {
  33180. return flags.mouseOverFlag;
  33181. }
  33182. bool Component::isMouseButtonDown() const throw()
  33183. {
  33184. return flags.draggingFlag;
  33185. }
  33186. bool Component::isMouseOverOrDragging() const throw()
  33187. {
  33188. return flags.mouseOverFlag || flags.draggingFlag;
  33189. }
  33190. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33191. {
  33192. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33193. }
  33194. const Point<int> Component::getMouseXYRelative() const
  33195. {
  33196. return globalPositionToRelative (Desktop::getMousePosition());
  33197. }
  33198. const Rectangle<int> Component::getParentMonitorArea() const
  33199. {
  33200. return Desktop::getInstance()
  33201. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33202. getHeight() / 2)));
  33203. }
  33204. void Component::addKeyListener (KeyListener* const newListener)
  33205. {
  33206. if (keyListeners_ == 0)
  33207. keyListeners_ = new VoidArray();
  33208. keyListeners_->addIfNotAlreadyThere (newListener);
  33209. }
  33210. void Component::removeKeyListener (KeyListener* const listenerToRemove)
  33211. {
  33212. if (keyListeners_ != 0)
  33213. keyListeners_->removeValue (listenerToRemove);
  33214. }
  33215. bool Component::keyPressed (const KeyPress&)
  33216. {
  33217. return false;
  33218. }
  33219. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33220. {
  33221. return false;
  33222. }
  33223. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33224. {
  33225. if (parentComponent_ != 0)
  33226. parentComponent_->modifierKeysChanged (modifiers);
  33227. }
  33228. void Component::internalModifierKeysChanged()
  33229. {
  33230. sendFakeMouseMove();
  33231. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33232. }
  33233. ComponentPeer* Component::getPeer() const
  33234. {
  33235. if (flags.hasHeavyweightPeerFlag)
  33236. return ComponentPeer::getPeerFor (this);
  33237. else if (parentComponent_ != 0)
  33238. return parentComponent_->getPeer();
  33239. else
  33240. return 0;
  33241. }
  33242. Component::BailOutChecker::BailOutChecker (Component* const component1, Component* const component2_)
  33243. : safePointer1 (component1), safePointer2 (component2_), component2 (component2_)
  33244. {
  33245. jassert (component1 != 0);
  33246. }
  33247. bool Component::BailOutChecker::shouldBailOut() const throw()
  33248. {
  33249. return safePointer1 == 0 || safePointer2.getComponent() != component2;
  33250. }
  33251. END_JUCE_NAMESPACE
  33252. /*** End of inlined file: juce_Component.cpp ***/
  33253. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33254. BEGIN_JUCE_NAMESPACE
  33255. void ComponentListener::componentMovedOrResized (Component&, bool, bool) {}
  33256. void ComponentListener::componentBroughtToFront (Component&) {}
  33257. void ComponentListener::componentVisibilityChanged (Component&) {}
  33258. void ComponentListener::componentChildrenChanged (Component&) {}
  33259. void ComponentListener::componentParentHierarchyChanged (Component&) {}
  33260. void ComponentListener::componentNameChanged (Component&) {}
  33261. void ComponentListener::componentBeingDeleted (Component&) {}
  33262. END_JUCE_NAMESPACE
  33263. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33264. /*** Start of inlined file: juce_Desktop.cpp ***/
  33265. BEGIN_JUCE_NAMESPACE
  33266. Desktop::Desktop()
  33267. : mouseClickCounter (0),
  33268. kioskModeComponent (0)
  33269. {
  33270. createMouseInputSources();
  33271. refreshMonitorSizes();
  33272. }
  33273. Desktop::~Desktop()
  33274. {
  33275. jassert (instance == this);
  33276. instance = 0;
  33277. // doh! If you don't delete all your windows before exiting, you're going to
  33278. // be leaking memory!
  33279. jassert (desktopComponents.size() == 0);
  33280. }
  33281. Desktop& JUCE_CALLTYPE Desktop::getInstance()
  33282. {
  33283. if (instance == 0)
  33284. instance = new Desktop();
  33285. return *instance;
  33286. }
  33287. Desktop* Desktop::instance = 0;
  33288. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33289. const bool clipToWorkArea);
  33290. void Desktop::refreshMonitorSizes()
  33291. {
  33292. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33293. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33294. monitorCoordsClipped.clear();
  33295. monitorCoordsUnclipped.clear();
  33296. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33297. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33298. jassert (monitorCoordsClipped.size() > 0
  33299. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33300. if (oldClipped != monitorCoordsClipped
  33301. || oldUnclipped != monitorCoordsUnclipped)
  33302. {
  33303. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33304. {
  33305. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33306. if (p != 0)
  33307. p->handleScreenSizeChange();
  33308. }
  33309. }
  33310. }
  33311. int Desktop::getNumDisplayMonitors() const throw()
  33312. {
  33313. return monitorCoordsClipped.size();
  33314. }
  33315. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33316. {
  33317. return clippedToWorkArea ? monitorCoordsClipped [index]
  33318. : monitorCoordsUnclipped [index];
  33319. }
  33320. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33321. {
  33322. RectangleList rl;
  33323. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33324. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33325. return rl;
  33326. }
  33327. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33328. {
  33329. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33330. }
  33331. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const
  33332. {
  33333. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33334. double bestDistance = 1.0e10;
  33335. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33336. {
  33337. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33338. if (rect.contains (position))
  33339. return rect;
  33340. const double distance = rect.getCentre().getDistanceFrom (position);
  33341. if (distance < bestDistance)
  33342. {
  33343. bestDistance = distance;
  33344. best = rect;
  33345. }
  33346. }
  33347. return best;
  33348. }
  33349. int Desktop::getNumComponents() const throw()
  33350. {
  33351. return desktopComponents.size();
  33352. }
  33353. Component* Desktop::getComponent (const int index) const throw()
  33354. {
  33355. return desktopComponents [index];
  33356. }
  33357. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33358. {
  33359. for (int i = desktopComponents.size(); --i >= 0;)
  33360. {
  33361. Component* const c = desktopComponents.getUnchecked(i);
  33362. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33363. if (c->contains (relative.getX(), relative.getY()))
  33364. return c->getComponentAt (relative.getX(), relative.getY());
  33365. }
  33366. return 0;
  33367. }
  33368. void Desktop::addDesktopComponent (Component* const c)
  33369. {
  33370. jassert (c != 0);
  33371. jassert (! desktopComponents.contains (c));
  33372. desktopComponents.addIfNotAlreadyThere (c);
  33373. }
  33374. void Desktop::removeDesktopComponent (Component* const c)
  33375. {
  33376. desktopComponents.removeValue (c);
  33377. }
  33378. void Desktop::componentBroughtToFront (Component* const c)
  33379. {
  33380. const int index = desktopComponents.indexOf (c);
  33381. jassert (index >= 0);
  33382. if (index >= 0)
  33383. {
  33384. int newIndex = -1;
  33385. if (! c->isAlwaysOnTop())
  33386. {
  33387. newIndex = desktopComponents.size();
  33388. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33389. --newIndex;
  33390. --newIndex;
  33391. }
  33392. desktopComponents.move (index, newIndex);
  33393. }
  33394. }
  33395. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33396. {
  33397. return getInstance().getMainMouseSource().getLastMouseDownPosition();
  33398. }
  33399. int Desktop::getMouseButtonClickCounter() throw()
  33400. {
  33401. return getInstance().mouseClickCounter;
  33402. }
  33403. void Desktop::incrementMouseClickCounter() throw()
  33404. {
  33405. ++mouseClickCounter;
  33406. }
  33407. int Desktop::getNumDraggingMouseSources() const throw()
  33408. {
  33409. int num = 0;
  33410. for (int i = mouseSources.size(); --i >= 0;)
  33411. if (mouseSources.getUnchecked(i)->isDragging())
  33412. ++num;
  33413. return num;
  33414. }
  33415. MouseInputSource* Desktop::getDraggingMouseSource (int index) const throw()
  33416. {
  33417. int num = 0;
  33418. for (int i = mouseSources.size(); --i >= 0;)
  33419. {
  33420. MouseInputSource* const mi = mouseSources.getUnchecked(i);
  33421. if (mi->isDragging())
  33422. {
  33423. if (index == num)
  33424. return mi;
  33425. ++num;
  33426. }
  33427. }
  33428. return 0;
  33429. }
  33430. void Desktop::addFocusChangeListener (FocusChangeListener* const listener)
  33431. {
  33432. focusListeners.add (listener);
  33433. }
  33434. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener)
  33435. {
  33436. focusListeners.remove (listener);
  33437. }
  33438. void Desktop::triggerFocusCallback()
  33439. {
  33440. triggerAsyncUpdate();
  33441. }
  33442. void Desktop::handleAsyncUpdate()
  33443. {
  33444. Component* currentFocus = Component::getCurrentlyFocusedComponent();
  33445. focusListeners.call (&FocusChangeListener::globalFocusChanged, currentFocus);
  33446. }
  33447. void Desktop::addGlobalMouseListener (MouseListener* const listener)
  33448. {
  33449. mouseListeners.add (listener);
  33450. resetTimer();
  33451. }
  33452. void Desktop::removeGlobalMouseListener (MouseListener* const listener)
  33453. {
  33454. mouseListeners.remove (listener);
  33455. resetTimer();
  33456. }
  33457. void Desktop::timerCallback()
  33458. {
  33459. if (lastFakeMouseMove != getMousePosition())
  33460. sendMouseMove();
  33461. }
  33462. void Desktop::sendMouseMove()
  33463. {
  33464. if (! mouseListeners.isEmpty())
  33465. {
  33466. startTimer (20);
  33467. lastFakeMouseMove = getMousePosition();
  33468. Component* const target = findComponentAt (lastFakeMouseMove);
  33469. if (target != 0)
  33470. {
  33471. Component::BailOutChecker checker (target);
  33472. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  33473. const Time now (Time::getCurrentTime());
  33474. const MouseEvent me (getMainMouseSource(), pos, ModifierKeys::getCurrentModifiers(),
  33475. target, now, pos, now, 0, false);
  33476. if (me.mods.isAnyMouseButtonDown())
  33477. mouseListeners.callChecked (checker, &MouseListener::mouseDrag, me);
  33478. else
  33479. mouseListeners.callChecked (checker, &MouseListener::mouseMove, me);
  33480. }
  33481. }
  33482. }
  33483. void Desktop::resetTimer()
  33484. {
  33485. if (mouseListeners.size() == 0)
  33486. stopTimer();
  33487. else
  33488. startTimer (100);
  33489. lastFakeMouseMove = getMousePosition();
  33490. }
  33491. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  33492. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  33493. {
  33494. if (kioskModeComponent != componentToUse)
  33495. {
  33496. // agh! Don't delete a component without first stopping it being the kiosk comp
  33497. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  33498. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  33499. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  33500. if (kioskModeComponent->isValidComponent())
  33501. {
  33502. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  33503. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  33504. }
  33505. kioskModeComponent = componentToUse;
  33506. if (kioskModeComponent != 0)
  33507. {
  33508. jassert (kioskModeComponent->isValidComponent());
  33509. // Only components that are already on the desktop can be put into kiosk mode!
  33510. jassert (kioskModeComponent->isOnDesktop());
  33511. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  33512. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  33513. }
  33514. }
  33515. }
  33516. END_JUCE_NAMESPACE
  33517. /*** End of inlined file: juce_Desktop.cpp ***/
  33518. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  33519. BEGIN_JUCE_NAMESPACE
  33520. ArrowButton::ArrowButton (const String& name,
  33521. float arrowDirectionInRadians,
  33522. const Colour& arrowColour)
  33523. : Button (name),
  33524. colour (arrowColour)
  33525. {
  33526. path.lineTo (0.0f, 1.0f);
  33527. path.lineTo (1.0f, 0.5f);
  33528. path.closeSubPath();
  33529. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  33530. 0.5f, 0.5f));
  33531. setComponentEffect (&shadow);
  33532. buttonStateChanged();
  33533. }
  33534. ArrowButton::~ArrowButton()
  33535. {
  33536. }
  33537. void ArrowButton::paintButton (Graphics& g,
  33538. bool /*isMouseOverButton*/,
  33539. bool /*isButtonDown*/)
  33540. {
  33541. g.setColour (colour);
  33542. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  33543. (float) offset,
  33544. (float) (getWidth() - 3),
  33545. (float) (getHeight() - 3),
  33546. false));
  33547. }
  33548. void ArrowButton::buttonStateChanged()
  33549. {
  33550. offset = (isDown()) ? 1 : 0;
  33551. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  33552. 0.3f, -1, 0);
  33553. }
  33554. END_JUCE_NAMESPACE
  33555. /*** End of inlined file: juce_ArrowButton.cpp ***/
  33556. /*** Start of inlined file: juce_Button.cpp ***/
  33557. BEGIN_JUCE_NAMESPACE
  33558. class Button::RepeatTimer : public Timer
  33559. {
  33560. public:
  33561. RepeatTimer (Button& owner_) : owner (owner_) {}
  33562. void timerCallback() { owner.repeatTimerCallback(); }
  33563. juce_UseDebuggingNewOperator
  33564. private:
  33565. Button& owner;
  33566. RepeatTimer (const RepeatTimer&);
  33567. RepeatTimer& operator= (const RepeatTimer&);
  33568. };
  33569. Button::Button (const String& name)
  33570. : Component (name),
  33571. text (name),
  33572. buttonPressTime (0),
  33573. lastTimeCallbackTime (0),
  33574. commandManagerToUse (0),
  33575. autoRepeatDelay (-1),
  33576. autoRepeatSpeed (0),
  33577. autoRepeatMinimumDelay (-1),
  33578. radioGroupId (0),
  33579. commandID (0),
  33580. connectedEdgeFlags (0),
  33581. buttonState (buttonNormal),
  33582. lastToggleState (false),
  33583. clickTogglesState (false),
  33584. needsToRelease (false),
  33585. needsRepainting (false),
  33586. isKeyDown (false),
  33587. triggerOnMouseDown (false),
  33588. generateTooltip (false)
  33589. {
  33590. setWantsKeyboardFocus (true);
  33591. isOn.addListener (this);
  33592. }
  33593. Button::~Button()
  33594. {
  33595. isOn.removeListener (this);
  33596. if (commandManagerToUse != 0)
  33597. commandManagerToUse->removeListener (this);
  33598. repeatTimer = 0;
  33599. clearShortcuts();
  33600. }
  33601. void Button::setButtonText (const String& newText)
  33602. {
  33603. if (text != newText)
  33604. {
  33605. text = newText;
  33606. repaint();
  33607. }
  33608. }
  33609. void Button::setTooltip (const String& newTooltip)
  33610. {
  33611. SettableTooltipClient::setTooltip (newTooltip);
  33612. generateTooltip = false;
  33613. }
  33614. const String Button::getTooltip()
  33615. {
  33616. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  33617. {
  33618. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  33619. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  33620. for (int i = 0; i < keyPresses.size(); ++i)
  33621. {
  33622. const String key (keyPresses.getReference(i).getTextDescription());
  33623. tt << " [";
  33624. if (key.length() == 1)
  33625. tt << TRANS("shortcut") << ": '" << key << "']";
  33626. else
  33627. tt << key << ']';
  33628. }
  33629. return tt;
  33630. }
  33631. return SettableTooltipClient::getTooltip();
  33632. }
  33633. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  33634. {
  33635. if (connectedEdgeFlags != connectedEdgeFlags_)
  33636. {
  33637. connectedEdgeFlags = connectedEdgeFlags_;
  33638. repaint();
  33639. }
  33640. }
  33641. void Button::setToggleState (const bool shouldBeOn,
  33642. const bool sendChangeNotification)
  33643. {
  33644. if (shouldBeOn != lastToggleState)
  33645. {
  33646. isOn = shouldBeOn;
  33647. lastToggleState = shouldBeOn;
  33648. repaint();
  33649. if (sendChangeNotification)
  33650. {
  33651. Component::SafePointer<Component> deletionWatcher (this);
  33652. sendClickMessage (ModifierKeys());
  33653. if (deletionWatcher == 0)
  33654. return;
  33655. }
  33656. if (lastToggleState)
  33657. turnOffOtherButtonsInGroup (sendChangeNotification);
  33658. }
  33659. }
  33660. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  33661. {
  33662. clickTogglesState = shouldToggle;
  33663. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33664. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33665. // it is that this button represents, and the button will update its state to reflect this
  33666. // in the applicationCommandListChanged() method.
  33667. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33668. }
  33669. bool Button::getClickingTogglesState() const throw()
  33670. {
  33671. return clickTogglesState;
  33672. }
  33673. void Button::valueChanged (Value& value)
  33674. {
  33675. if (value.refersToSameSourceAs (isOn))
  33676. setToggleState (isOn.getValue(), true);
  33677. }
  33678. void Button::setRadioGroupId (const int newGroupId)
  33679. {
  33680. if (radioGroupId != newGroupId)
  33681. {
  33682. radioGroupId = newGroupId;
  33683. if (lastToggleState)
  33684. turnOffOtherButtonsInGroup (true);
  33685. }
  33686. }
  33687. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  33688. {
  33689. Component* const p = getParentComponent();
  33690. if (p != 0 && radioGroupId != 0)
  33691. {
  33692. Component::SafePointer<Component> deletionWatcher (this);
  33693. for (int i = p->getNumChildComponents(); --i >= 0;)
  33694. {
  33695. Component* const c = p->getChildComponent (i);
  33696. if (c != this)
  33697. {
  33698. Button* const b = dynamic_cast <Button*> (c);
  33699. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  33700. {
  33701. b->setToggleState (false, sendChangeNotification);
  33702. if (deletionWatcher == 0)
  33703. return;
  33704. }
  33705. }
  33706. }
  33707. }
  33708. }
  33709. void Button::enablementChanged()
  33710. {
  33711. updateState (0);
  33712. repaint();
  33713. }
  33714. Button::ButtonState Button::updateState (const MouseEvent* const e)
  33715. {
  33716. ButtonState state = buttonNormal;
  33717. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  33718. {
  33719. Point<int> mousePos;
  33720. if (e == 0)
  33721. mousePos = getMouseXYRelative();
  33722. else
  33723. mousePos = e->getEventRelativeTo (this).getPosition();
  33724. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  33725. const bool down = isMouseButtonDown();
  33726. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  33727. state = buttonDown;
  33728. else if (over)
  33729. state = buttonOver;
  33730. }
  33731. setState (state);
  33732. return state;
  33733. }
  33734. void Button::setState (const ButtonState newState)
  33735. {
  33736. if (buttonState != newState)
  33737. {
  33738. buttonState = newState;
  33739. repaint();
  33740. if (buttonState == buttonDown)
  33741. {
  33742. buttonPressTime = Time::getApproximateMillisecondCounter();
  33743. lastTimeCallbackTime = buttonPressTime;
  33744. }
  33745. sendStateMessage();
  33746. }
  33747. }
  33748. bool Button::isDown() const throw()
  33749. {
  33750. return buttonState == buttonDown;
  33751. }
  33752. bool Button::isOver() const throw()
  33753. {
  33754. return buttonState != buttonNormal;
  33755. }
  33756. void Button::buttonStateChanged()
  33757. {
  33758. }
  33759. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  33760. {
  33761. const uint32 now = Time::getApproximateMillisecondCounter();
  33762. return now > buttonPressTime ? now - buttonPressTime : 0;
  33763. }
  33764. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  33765. {
  33766. triggerOnMouseDown = isTriggeredOnMouseDown;
  33767. }
  33768. void Button::clicked()
  33769. {
  33770. }
  33771. void Button::clicked (const ModifierKeys& /*modifiers*/)
  33772. {
  33773. clicked();
  33774. }
  33775. static const int clickMessageId = 0x2f3f4f99;
  33776. void Button::triggerClick()
  33777. {
  33778. postCommandMessage (clickMessageId);
  33779. }
  33780. void Button::internalClickCallback (const ModifierKeys& modifiers)
  33781. {
  33782. if (clickTogglesState)
  33783. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  33784. sendClickMessage (modifiers);
  33785. }
  33786. void Button::flashButtonState()
  33787. {
  33788. if (isEnabled())
  33789. {
  33790. needsToRelease = true;
  33791. setState (buttonDown);
  33792. getRepeatTimer().startTimer (100);
  33793. }
  33794. }
  33795. void Button::handleCommandMessage (int commandId)
  33796. {
  33797. if (commandId == clickMessageId)
  33798. {
  33799. if (isEnabled())
  33800. {
  33801. flashButtonState();
  33802. internalClickCallback (ModifierKeys::getCurrentModifiers());
  33803. }
  33804. }
  33805. else
  33806. {
  33807. Component::handleCommandMessage (commandId);
  33808. }
  33809. }
  33810. void Button::addButtonListener (ButtonListener* const newListener)
  33811. {
  33812. buttonListeners.add (newListener);
  33813. }
  33814. void Button::removeButtonListener (ButtonListener* const listener)
  33815. {
  33816. buttonListeners.remove (listener);
  33817. }
  33818. void Button::sendClickMessage (const ModifierKeys& modifiers)
  33819. {
  33820. Component::BailOutChecker checker (this);
  33821. if (commandManagerToUse != 0 && commandID != 0)
  33822. {
  33823. ApplicationCommandTarget::InvocationInfo info (commandID);
  33824. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  33825. info.originatingComponent = this;
  33826. commandManagerToUse->invoke (info, true);
  33827. }
  33828. clicked (modifiers);
  33829. if (! checker.shouldBailOut())
  33830. buttonListeners.callChecked (checker, &ButtonListener::buttonClicked, this);
  33831. }
  33832. void Button::sendStateMessage()
  33833. {
  33834. Component::BailOutChecker checker (this);
  33835. buttonStateChanged();
  33836. if (! checker.shouldBailOut())
  33837. buttonListeners.callChecked (checker, &ButtonListener::buttonStateChanged, this);
  33838. }
  33839. void Button::paint (Graphics& g)
  33840. {
  33841. if (needsToRelease && isEnabled())
  33842. {
  33843. needsToRelease = false;
  33844. needsRepainting = true;
  33845. }
  33846. paintButton (g, isOver(), isDown());
  33847. }
  33848. void Button::mouseEnter (const MouseEvent& e)
  33849. {
  33850. updateState (&e);
  33851. }
  33852. void Button::mouseExit (const MouseEvent& e)
  33853. {
  33854. updateState (&e);
  33855. }
  33856. void Button::mouseDown (const MouseEvent& e)
  33857. {
  33858. updateState (&e);
  33859. if (isDown())
  33860. {
  33861. if (autoRepeatDelay >= 0)
  33862. getRepeatTimer().startTimer (autoRepeatDelay);
  33863. if (triggerOnMouseDown)
  33864. internalClickCallback (e.mods);
  33865. }
  33866. }
  33867. void Button::mouseUp (const MouseEvent& e)
  33868. {
  33869. const bool wasDown = isDown();
  33870. updateState (&e);
  33871. if (wasDown && isOver() && ! triggerOnMouseDown)
  33872. internalClickCallback (e.mods);
  33873. }
  33874. void Button::mouseDrag (const MouseEvent& e)
  33875. {
  33876. const ButtonState oldState = buttonState;
  33877. updateState (&e);
  33878. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  33879. getRepeatTimer().startTimer (autoRepeatSpeed);
  33880. }
  33881. void Button::focusGained (FocusChangeType)
  33882. {
  33883. updateState (0);
  33884. repaint();
  33885. }
  33886. void Button::focusLost (FocusChangeType)
  33887. {
  33888. updateState (0);
  33889. repaint();
  33890. }
  33891. void Button::setVisible (bool shouldBeVisible)
  33892. {
  33893. if (shouldBeVisible != isVisible())
  33894. {
  33895. Component::setVisible (shouldBeVisible);
  33896. if (! shouldBeVisible)
  33897. needsToRelease = false;
  33898. updateState (0);
  33899. }
  33900. else
  33901. {
  33902. Component::setVisible (shouldBeVisible);
  33903. }
  33904. }
  33905. void Button::parentHierarchyChanged()
  33906. {
  33907. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  33908. if (newKeySource != keySource.getComponent())
  33909. {
  33910. if (keySource != 0)
  33911. keySource->removeKeyListener (this);
  33912. keySource = newKeySource;
  33913. if (keySource != 0)
  33914. keySource->addKeyListener (this);
  33915. }
  33916. }
  33917. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  33918. const int commandID_,
  33919. const bool generateTooltip_)
  33920. {
  33921. commandID = commandID_;
  33922. generateTooltip = generateTooltip_;
  33923. if (commandManagerToUse != commandManagerToUse_)
  33924. {
  33925. if (commandManagerToUse != 0)
  33926. commandManagerToUse->removeListener (this);
  33927. commandManagerToUse = commandManagerToUse_;
  33928. if (commandManagerToUse != 0)
  33929. commandManagerToUse->addListener (this);
  33930. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  33931. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  33932. // it is that this button represents, and the button will update its state to reflect this
  33933. // in the applicationCommandListChanged() method.
  33934. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  33935. }
  33936. if (commandManagerToUse != 0)
  33937. applicationCommandListChanged();
  33938. else
  33939. setEnabled (true);
  33940. }
  33941. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  33942. {
  33943. if (info.commandID == commandID
  33944. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  33945. {
  33946. flashButtonState();
  33947. }
  33948. }
  33949. void Button::applicationCommandListChanged()
  33950. {
  33951. if (commandManagerToUse != 0)
  33952. {
  33953. ApplicationCommandInfo info (0);
  33954. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  33955. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  33956. if (target != 0)
  33957. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  33958. }
  33959. }
  33960. void Button::addShortcut (const KeyPress& key)
  33961. {
  33962. if (key.isValid())
  33963. {
  33964. jassert (! isRegisteredForShortcut (key)); // already registered!
  33965. shortcuts.add (key);
  33966. parentHierarchyChanged();
  33967. }
  33968. }
  33969. void Button::clearShortcuts()
  33970. {
  33971. shortcuts.clear();
  33972. parentHierarchyChanged();
  33973. }
  33974. bool Button::isShortcutPressed() const
  33975. {
  33976. if (! isCurrentlyBlockedByAnotherModalComponent())
  33977. {
  33978. for (int i = shortcuts.size(); --i >= 0;)
  33979. if (shortcuts.getReference(i).isCurrentlyDown())
  33980. return true;
  33981. }
  33982. return false;
  33983. }
  33984. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  33985. {
  33986. for (int i = shortcuts.size(); --i >= 0;)
  33987. if (key == shortcuts.getReference(i))
  33988. return true;
  33989. return false;
  33990. }
  33991. bool Button::keyStateChanged (const bool, Component*)
  33992. {
  33993. if (! isEnabled())
  33994. return false;
  33995. const bool wasDown = isKeyDown;
  33996. isKeyDown = isShortcutPressed();
  33997. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  33998. getRepeatTimer().startTimer (autoRepeatDelay);
  33999. updateState (0);
  34000. if (isEnabled() && wasDown && ! isKeyDown)
  34001. {
  34002. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34003. // (return immediately - this button may now have been deleted)
  34004. return true;
  34005. }
  34006. return wasDown || isKeyDown;
  34007. }
  34008. bool Button::keyPressed (const KeyPress&, Component*)
  34009. {
  34010. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34011. return isShortcutPressed();
  34012. }
  34013. bool Button::keyPressed (const KeyPress& key)
  34014. {
  34015. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34016. {
  34017. triggerClick();
  34018. return true;
  34019. }
  34020. return false;
  34021. }
  34022. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34023. const int repeatMillisecs,
  34024. const int minimumDelayInMillisecs) throw()
  34025. {
  34026. autoRepeatDelay = initialDelayMillisecs;
  34027. autoRepeatSpeed = repeatMillisecs;
  34028. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34029. }
  34030. void Button::repeatTimerCallback()
  34031. {
  34032. if (needsRepainting)
  34033. {
  34034. getRepeatTimer().stopTimer();
  34035. updateState (0);
  34036. needsRepainting = false;
  34037. }
  34038. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34039. {
  34040. int repeatSpeed = autoRepeatSpeed;
  34041. if (autoRepeatMinimumDelay >= 0)
  34042. {
  34043. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34044. timeHeldDown *= timeHeldDown;
  34045. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34046. }
  34047. repeatSpeed = jmax (1, repeatSpeed);
  34048. getRepeatTimer().startTimer (repeatSpeed);
  34049. const uint32 now = Time::getApproximateMillisecondCounter();
  34050. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34051. lastTimeCallbackTime = now;
  34052. Component::SafePointer<Component> deletionWatcher (this);
  34053. for (int i = numTimesToCallback; --i >= 0;)
  34054. {
  34055. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34056. if (deletionWatcher == 0 || ! isDown())
  34057. return;
  34058. }
  34059. }
  34060. else if (! needsToRelease)
  34061. {
  34062. getRepeatTimer().stopTimer();
  34063. }
  34064. }
  34065. Button::RepeatTimer& Button::getRepeatTimer()
  34066. {
  34067. if (repeatTimer == 0)
  34068. repeatTimer = new RepeatTimer (*this);
  34069. return *repeatTimer;
  34070. }
  34071. END_JUCE_NAMESPACE
  34072. /*** End of inlined file: juce_Button.cpp ***/
  34073. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34074. BEGIN_JUCE_NAMESPACE
  34075. DrawableButton::DrawableButton (const String& name,
  34076. const DrawableButton::ButtonStyle buttonStyle)
  34077. : Button (name),
  34078. style (buttonStyle),
  34079. edgeIndent (3)
  34080. {
  34081. if (buttonStyle == ImageOnButtonBackground)
  34082. {
  34083. backgroundOff = Colour (0xffbbbbff);
  34084. backgroundOn = Colour (0xff3333ff);
  34085. }
  34086. else
  34087. {
  34088. backgroundOff = Colours::transparentBlack;
  34089. backgroundOn = Colour (0xaabbbbff);
  34090. }
  34091. }
  34092. DrawableButton::~DrawableButton()
  34093. {
  34094. deleteImages();
  34095. }
  34096. void DrawableButton::deleteImages()
  34097. {
  34098. }
  34099. void DrawableButton::setImages (const Drawable* normal,
  34100. const Drawable* over,
  34101. const Drawable* down,
  34102. const Drawable* disabled,
  34103. const Drawable* normalOn,
  34104. const Drawable* overOn,
  34105. const Drawable* downOn,
  34106. const Drawable* disabledOn)
  34107. {
  34108. deleteImages();
  34109. jassert (normal != 0); // you really need to give it at least a normal image..
  34110. if (normal != 0)
  34111. normalImage = normal->createCopy();
  34112. if (over != 0)
  34113. overImage = over->createCopy();
  34114. if (down != 0)
  34115. downImage = down->createCopy();
  34116. if (disabled != 0)
  34117. disabledImage = disabled->createCopy();
  34118. if (normalOn != 0)
  34119. normalImageOn = normalOn->createCopy();
  34120. if (overOn != 0)
  34121. overImageOn = overOn->createCopy();
  34122. if (downOn != 0)
  34123. downImageOn = downOn->createCopy();
  34124. if (disabledOn != 0)
  34125. disabledImageOn = disabledOn->createCopy();
  34126. repaint();
  34127. }
  34128. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34129. {
  34130. if (style != newStyle)
  34131. {
  34132. style = newStyle;
  34133. repaint();
  34134. }
  34135. }
  34136. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34137. const Colour& toggledOnColour)
  34138. {
  34139. if (backgroundOff != toggledOffColour
  34140. || backgroundOn != toggledOnColour)
  34141. {
  34142. backgroundOff = toggledOffColour;
  34143. backgroundOn = toggledOnColour;
  34144. repaint();
  34145. }
  34146. }
  34147. const Colour& DrawableButton::getBackgroundColour() const throw()
  34148. {
  34149. return getToggleState() ? backgroundOn
  34150. : backgroundOff;
  34151. }
  34152. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34153. {
  34154. edgeIndent = numPixelsIndent;
  34155. repaint();
  34156. }
  34157. void DrawableButton::paintButton (Graphics& g,
  34158. bool isMouseOverButton,
  34159. bool isButtonDown)
  34160. {
  34161. Rectangle<int> imageSpace;
  34162. if (style == ImageOnButtonBackground)
  34163. {
  34164. const int insetX = getWidth() / 4;
  34165. const int insetY = getHeight() / 4;
  34166. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34167. getLookAndFeel().drawButtonBackground (g, *this,
  34168. getBackgroundColour(),
  34169. isMouseOverButton,
  34170. isButtonDown);
  34171. }
  34172. else
  34173. {
  34174. g.fillAll (getBackgroundColour());
  34175. const int textH = (style == ImageAboveTextLabel)
  34176. ? jmin (16, proportionOfHeight (0.25f))
  34177. : 0;
  34178. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34179. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34180. imageSpace.setBounds (indentX, indentY,
  34181. getWidth() - indentX * 2,
  34182. getHeight() - indentY * 2 - textH);
  34183. if (textH > 0)
  34184. {
  34185. g.setFont ((float) textH);
  34186. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34187. g.drawFittedText (getButtonText(),
  34188. 2, getHeight() - textH - 1,
  34189. getWidth() - 4, textH,
  34190. Justification::centred, 1);
  34191. }
  34192. }
  34193. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34194. g.setOpacity (1.0f);
  34195. const Drawable* imageToDraw = 0;
  34196. if (isEnabled())
  34197. {
  34198. imageToDraw = getCurrentImage();
  34199. }
  34200. else
  34201. {
  34202. imageToDraw = getToggleState() ? disabledImageOn
  34203. : disabledImage;
  34204. if (imageToDraw == 0)
  34205. {
  34206. g.setOpacity (0.4f);
  34207. imageToDraw = getNormalImage();
  34208. }
  34209. }
  34210. if (imageToDraw != 0)
  34211. {
  34212. if (style == ImageRaw)
  34213. {
  34214. imageToDraw->draw (g, 1.0f);
  34215. }
  34216. else
  34217. {
  34218. imageToDraw->drawWithin (g,
  34219. imageSpace.getX(),
  34220. imageSpace.getY(),
  34221. imageSpace.getWidth(),
  34222. imageSpace.getHeight(),
  34223. RectanglePlacement::centred,
  34224. 1.0f);
  34225. }
  34226. }
  34227. }
  34228. const Drawable* DrawableButton::getCurrentImage() const throw()
  34229. {
  34230. if (isDown())
  34231. return getDownImage();
  34232. if (isOver())
  34233. return getOverImage();
  34234. return getNormalImage();
  34235. }
  34236. const Drawable* DrawableButton::getNormalImage() const throw()
  34237. {
  34238. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34239. : normalImage;
  34240. }
  34241. const Drawable* DrawableButton::getOverImage() const throw()
  34242. {
  34243. const Drawable* d = normalImage;
  34244. if (getToggleState())
  34245. {
  34246. if (overImageOn != 0)
  34247. d = overImageOn;
  34248. else if (normalImageOn != 0)
  34249. d = normalImageOn;
  34250. else if (overImage != 0)
  34251. d = overImage;
  34252. }
  34253. else
  34254. {
  34255. if (overImage != 0)
  34256. d = overImage;
  34257. }
  34258. return d;
  34259. }
  34260. const Drawable* DrawableButton::getDownImage() const throw()
  34261. {
  34262. const Drawable* d = normalImage;
  34263. if (getToggleState())
  34264. {
  34265. if (downImageOn != 0)
  34266. d = downImageOn;
  34267. else if (overImageOn != 0)
  34268. d = overImageOn;
  34269. else if (normalImageOn != 0)
  34270. d = normalImageOn;
  34271. else if (downImage != 0)
  34272. d = downImage;
  34273. else
  34274. d = getOverImage();
  34275. }
  34276. else
  34277. {
  34278. if (downImage != 0)
  34279. d = downImage;
  34280. else
  34281. d = getOverImage();
  34282. }
  34283. return d;
  34284. }
  34285. END_JUCE_NAMESPACE
  34286. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34287. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34288. BEGIN_JUCE_NAMESPACE
  34289. HyperlinkButton::HyperlinkButton (const String& linkText,
  34290. const URL& linkURL)
  34291. : Button (linkText),
  34292. url (linkURL),
  34293. font (14.0f, Font::underlined),
  34294. resizeFont (true),
  34295. justification (Justification::centred)
  34296. {
  34297. setMouseCursor (MouseCursor::PointingHandCursor);
  34298. setTooltip (linkURL.toString (false));
  34299. }
  34300. HyperlinkButton::~HyperlinkButton()
  34301. {
  34302. }
  34303. void HyperlinkButton::setFont (const Font& newFont,
  34304. const bool resizeToMatchComponentHeight,
  34305. const Justification& justificationType)
  34306. {
  34307. font = newFont;
  34308. resizeFont = resizeToMatchComponentHeight;
  34309. justification = justificationType;
  34310. repaint();
  34311. }
  34312. void HyperlinkButton::setURL (const URL& newURL) throw()
  34313. {
  34314. url = newURL;
  34315. setTooltip (newURL.toString (false));
  34316. }
  34317. const Font HyperlinkButton::getFontToUse() const
  34318. {
  34319. Font f (font);
  34320. if (resizeFont)
  34321. f.setHeight (getHeight() * 0.7f);
  34322. return f;
  34323. }
  34324. void HyperlinkButton::changeWidthToFitText()
  34325. {
  34326. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34327. }
  34328. void HyperlinkButton::colourChanged()
  34329. {
  34330. repaint();
  34331. }
  34332. void HyperlinkButton::clicked()
  34333. {
  34334. if (url.isWellFormed())
  34335. url.launchInDefaultBrowser();
  34336. }
  34337. void HyperlinkButton::paintButton (Graphics& g,
  34338. bool isMouseOverButton,
  34339. bool isButtonDown)
  34340. {
  34341. const Colour textColour (findColour (textColourId));
  34342. if (isEnabled())
  34343. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34344. : textColour);
  34345. else
  34346. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34347. g.setFont (getFontToUse());
  34348. g.drawText (getButtonText(),
  34349. 2, 0, getWidth() - 2, getHeight(),
  34350. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34351. true);
  34352. }
  34353. END_JUCE_NAMESPACE
  34354. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34355. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34356. BEGIN_JUCE_NAMESPACE
  34357. ImageButton::ImageButton (const String& text_)
  34358. : Button (text_),
  34359. scaleImageToFit (true),
  34360. preserveProportions (true),
  34361. alphaThreshold (0),
  34362. imageX (0),
  34363. imageY (0),
  34364. imageW (0),
  34365. imageH (0),
  34366. normalImage (0),
  34367. overImage (0),
  34368. downImage (0)
  34369. {
  34370. }
  34371. ImageButton::~ImageButton()
  34372. {
  34373. deleteImages();
  34374. }
  34375. void ImageButton::deleteImages()
  34376. {
  34377. ImageCache::releaseOrDelete (normalImage);
  34378. ImageCache::releaseOrDelete (overImage);
  34379. ImageCache::releaseOrDelete (downImage);
  34380. }
  34381. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34382. const bool rescaleImagesWhenButtonSizeChanges,
  34383. const bool preserveImageProportions,
  34384. Image* const normalImage_,
  34385. const float imageOpacityWhenNormal,
  34386. const Colour& overlayColourWhenNormal,
  34387. Image* const overImage_,
  34388. const float imageOpacityWhenOver,
  34389. const Colour& overlayColourWhenOver,
  34390. Image* const downImage_,
  34391. const float imageOpacityWhenDown,
  34392. const Colour& overlayColourWhenDown,
  34393. const float hitTestAlphaThreshold)
  34394. {
  34395. deleteImages();
  34396. normalImage = normalImage_;
  34397. overImage = overImage_;
  34398. downImage = downImage_;
  34399. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34400. {
  34401. imageW = normalImage->getWidth();
  34402. imageH = normalImage->getHeight();
  34403. setSize (imageW, imageH);
  34404. }
  34405. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34406. preserveProportions = preserveImageProportions;
  34407. normalOpacity = imageOpacityWhenNormal;
  34408. normalOverlay = overlayColourWhenNormal;
  34409. overOpacity = imageOpacityWhenOver;
  34410. overOverlay = overlayColourWhenOver;
  34411. downOpacity = imageOpacityWhenDown;
  34412. downOverlay = overlayColourWhenDown;
  34413. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34414. repaint();
  34415. }
  34416. Image* ImageButton::getCurrentImage() const
  34417. {
  34418. if (isDown() || getToggleState())
  34419. return getDownImage();
  34420. if (isOver())
  34421. return getOverImage();
  34422. return getNormalImage();
  34423. }
  34424. Image* ImageButton::getNormalImage() const throw()
  34425. {
  34426. return normalImage;
  34427. }
  34428. Image* ImageButton::getOverImage() const throw()
  34429. {
  34430. return (overImage != 0) ? overImage
  34431. : normalImage;
  34432. }
  34433. Image* ImageButton::getDownImage() const throw()
  34434. {
  34435. return (downImage != 0) ? downImage
  34436. : getOverImage();
  34437. }
  34438. void ImageButton::paintButton (Graphics& g,
  34439. bool isMouseOverButton,
  34440. bool isButtonDown)
  34441. {
  34442. if (! isEnabled())
  34443. {
  34444. isMouseOverButton = false;
  34445. isButtonDown = false;
  34446. }
  34447. Image* const im = getCurrentImage();
  34448. if (im != 0)
  34449. {
  34450. const int iw = im->getWidth();
  34451. const int ih = im->getHeight();
  34452. imageW = getWidth();
  34453. imageH = getHeight();
  34454. imageX = (imageW - iw) >> 1;
  34455. imageY = (imageH - ih) >> 1;
  34456. if (scaleImageToFit)
  34457. {
  34458. if (preserveProportions)
  34459. {
  34460. int newW, newH;
  34461. const float imRatio = ih / (float)iw;
  34462. const float destRatio = imageH / (float)imageW;
  34463. if (imRatio > destRatio)
  34464. {
  34465. newW = roundToInt (imageH / imRatio);
  34466. newH = imageH;
  34467. }
  34468. else
  34469. {
  34470. newW = imageW;
  34471. newH = roundToInt (imageW * imRatio);
  34472. }
  34473. imageX = (imageW - newW) / 2;
  34474. imageY = (imageH - newH) / 2;
  34475. imageW = newW;
  34476. imageH = newH;
  34477. }
  34478. else
  34479. {
  34480. imageX = 0;
  34481. imageY = 0;
  34482. }
  34483. }
  34484. if (! scaleImageToFit)
  34485. {
  34486. imageW = iw;
  34487. imageH = ih;
  34488. }
  34489. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  34490. isButtonDown ? downOverlay
  34491. : (isMouseOverButton ? overOverlay
  34492. : normalOverlay),
  34493. isButtonDown ? downOpacity
  34494. : (isMouseOverButton ? overOpacity
  34495. : normalOpacity),
  34496. *this);
  34497. }
  34498. }
  34499. bool ImageButton::hitTest (int x, int y)
  34500. {
  34501. if (alphaThreshold == 0)
  34502. return true;
  34503. Image* const im = getCurrentImage();
  34504. return im == 0
  34505. || (imageW > 0 && imageH > 0
  34506. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  34507. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  34508. }
  34509. END_JUCE_NAMESPACE
  34510. /*** End of inlined file: juce_ImageButton.cpp ***/
  34511. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  34512. BEGIN_JUCE_NAMESPACE
  34513. ShapeButton::ShapeButton (const String& text_,
  34514. const Colour& normalColour_,
  34515. const Colour& overColour_,
  34516. const Colour& downColour_)
  34517. : Button (text_),
  34518. normalColour (normalColour_),
  34519. overColour (overColour_),
  34520. downColour (downColour_),
  34521. maintainShapeProportions (false),
  34522. outlineWidth (0.0f)
  34523. {
  34524. }
  34525. ShapeButton::~ShapeButton()
  34526. {
  34527. }
  34528. void ShapeButton::setColours (const Colour& newNormalColour,
  34529. const Colour& newOverColour,
  34530. const Colour& newDownColour)
  34531. {
  34532. normalColour = newNormalColour;
  34533. overColour = newOverColour;
  34534. downColour = newDownColour;
  34535. }
  34536. void ShapeButton::setOutline (const Colour& newOutlineColour,
  34537. const float newOutlineWidth)
  34538. {
  34539. outlineColour = newOutlineColour;
  34540. outlineWidth = newOutlineWidth;
  34541. }
  34542. void ShapeButton::setShape (const Path& newShape,
  34543. const bool resizeNowToFitThisShape,
  34544. const bool maintainShapeProportions_,
  34545. const bool hasShadow)
  34546. {
  34547. shape = newShape;
  34548. maintainShapeProportions = maintainShapeProportions_;
  34549. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  34550. setComponentEffect ((hasShadow) ? &shadow : 0);
  34551. if (resizeNowToFitThisShape)
  34552. {
  34553. Rectangle<float> bounds (shape.getBounds());
  34554. if (hasShadow)
  34555. bounds.expand (4.0f, 4.0f);
  34556. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  34557. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  34558. 1 + (int) (bounds.getHeight() + outlineWidth));
  34559. }
  34560. }
  34561. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  34562. {
  34563. if (! isEnabled())
  34564. {
  34565. isMouseOverButton = false;
  34566. isButtonDown = false;
  34567. }
  34568. g.setColour ((isButtonDown) ? downColour
  34569. : (isMouseOverButton) ? overColour
  34570. : normalColour);
  34571. int w = getWidth();
  34572. int h = getHeight();
  34573. if (getComponentEffect() != 0)
  34574. {
  34575. w -= 4;
  34576. h -= 4;
  34577. }
  34578. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  34579. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  34580. w - offset - outlineWidth,
  34581. h - offset - outlineWidth,
  34582. maintainShapeProportions));
  34583. g.fillPath (shape, trans);
  34584. if (outlineWidth > 0.0f)
  34585. {
  34586. g.setColour (outlineColour);
  34587. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  34588. }
  34589. }
  34590. END_JUCE_NAMESPACE
  34591. /*** End of inlined file: juce_ShapeButton.cpp ***/
  34592. /*** Start of inlined file: juce_TextButton.cpp ***/
  34593. BEGIN_JUCE_NAMESPACE
  34594. TextButton::TextButton (const String& name,
  34595. const String& toolTip)
  34596. : Button (name)
  34597. {
  34598. setTooltip (toolTip);
  34599. }
  34600. TextButton::~TextButton()
  34601. {
  34602. }
  34603. void TextButton::paintButton (Graphics& g,
  34604. bool isMouseOverButton,
  34605. bool isButtonDown)
  34606. {
  34607. getLookAndFeel().drawButtonBackground (g, *this,
  34608. findColour (getToggleState() ? buttonOnColourId
  34609. : buttonColourId),
  34610. isMouseOverButton,
  34611. isButtonDown);
  34612. getLookAndFeel().drawButtonText (g, *this,
  34613. isMouseOverButton,
  34614. isButtonDown);
  34615. }
  34616. void TextButton::colourChanged()
  34617. {
  34618. repaint();
  34619. }
  34620. const Font TextButton::getFont()
  34621. {
  34622. return Font (jmin (15.0f, getHeight() * 0.6f));
  34623. }
  34624. void TextButton::changeWidthToFitText (const int newHeight)
  34625. {
  34626. if (newHeight >= 0)
  34627. setSize (jmax (1, getWidth()), newHeight);
  34628. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  34629. getHeight());
  34630. }
  34631. END_JUCE_NAMESPACE
  34632. /*** End of inlined file: juce_TextButton.cpp ***/
  34633. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  34634. BEGIN_JUCE_NAMESPACE
  34635. ToggleButton::ToggleButton (const String& buttonText)
  34636. : Button (buttonText)
  34637. {
  34638. setClickingTogglesState (true);
  34639. }
  34640. ToggleButton::~ToggleButton()
  34641. {
  34642. }
  34643. void ToggleButton::paintButton (Graphics& g,
  34644. bool isMouseOverButton,
  34645. bool isButtonDown)
  34646. {
  34647. getLookAndFeel().drawToggleButton (g, *this,
  34648. isMouseOverButton,
  34649. isButtonDown);
  34650. }
  34651. void ToggleButton::changeWidthToFitText()
  34652. {
  34653. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  34654. }
  34655. void ToggleButton::colourChanged()
  34656. {
  34657. repaint();
  34658. }
  34659. END_JUCE_NAMESPACE
  34660. /*** End of inlined file: juce_ToggleButton.cpp ***/
  34661. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  34662. BEGIN_JUCE_NAMESPACE
  34663. ToolbarButton::ToolbarButton (const int itemId_,
  34664. const String& buttonText,
  34665. Drawable* const normalImage_,
  34666. Drawable* const toggledOnImage_)
  34667. : ToolbarItemComponent (itemId_, buttonText, true),
  34668. normalImage (normalImage_),
  34669. toggledOnImage (toggledOnImage_)
  34670. {
  34671. }
  34672. ToolbarButton::~ToolbarButton()
  34673. {
  34674. }
  34675. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  34676. bool /*isToolbarVertical*/,
  34677. int& preferredSize,
  34678. int& minSize, int& maxSize)
  34679. {
  34680. preferredSize = minSize = maxSize = toolbarDepth;
  34681. return true;
  34682. }
  34683. void ToolbarButton::paintButtonArea (Graphics& g,
  34684. int width, int height,
  34685. bool /*isMouseOver*/,
  34686. bool /*isMouseDown*/)
  34687. {
  34688. Drawable* d = normalImage;
  34689. if (getToggleState() && toggledOnImage != 0)
  34690. d = toggledOnImage;
  34691. if (! isEnabled())
  34692. {
  34693. Image im (Image::ARGB, width, height, true);
  34694. Graphics g2 (im);
  34695. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34696. im.desaturate();
  34697. g.drawImageAt (&im, 0, 0);
  34698. }
  34699. else
  34700. {
  34701. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  34702. }
  34703. }
  34704. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  34705. {
  34706. }
  34707. END_JUCE_NAMESPACE
  34708. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  34709. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  34710. BEGIN_JUCE_NAMESPACE
  34711. class CodeDocumentLine
  34712. {
  34713. public:
  34714. CodeDocumentLine (const juce_wchar* const line_,
  34715. const int lineLength_,
  34716. const int numNewLineChars,
  34717. const int lineStartInFile_)
  34718. : line (line_, lineLength_),
  34719. lineStartInFile (lineStartInFile_),
  34720. lineLength (lineLength_),
  34721. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  34722. {
  34723. }
  34724. ~CodeDocumentLine()
  34725. {
  34726. }
  34727. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  34728. {
  34729. const juce_wchar* const t = text;
  34730. int pos = 0;
  34731. while (t [pos] != 0)
  34732. {
  34733. const int startOfLine = pos;
  34734. int numNewLineChars = 0;
  34735. while (t[pos] != 0)
  34736. {
  34737. if (t[pos] == '\r')
  34738. {
  34739. ++numNewLineChars;
  34740. ++pos;
  34741. if (t[pos] == '\n')
  34742. {
  34743. ++numNewLineChars;
  34744. ++pos;
  34745. }
  34746. break;
  34747. }
  34748. if (t[pos] == '\n')
  34749. {
  34750. ++numNewLineChars;
  34751. ++pos;
  34752. break;
  34753. }
  34754. ++pos;
  34755. }
  34756. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  34757. numNewLineChars, startOfLine));
  34758. }
  34759. jassert (pos == text.length());
  34760. }
  34761. bool endsWithLineBreak() const throw()
  34762. {
  34763. return lineLengthWithoutNewLines != lineLength;
  34764. }
  34765. void updateLength() throw()
  34766. {
  34767. lineLengthWithoutNewLines = lineLength = line.length();
  34768. while (lineLengthWithoutNewLines > 0
  34769. && (line [lineLengthWithoutNewLines - 1] == '\n'
  34770. || line [lineLengthWithoutNewLines - 1] == '\r'))
  34771. {
  34772. --lineLengthWithoutNewLines;
  34773. }
  34774. }
  34775. String line;
  34776. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  34777. };
  34778. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  34779. : document (document_),
  34780. currentLine (document_->lines[0]),
  34781. line (0),
  34782. position (0)
  34783. {
  34784. }
  34785. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  34786. : document (other.document),
  34787. currentLine (other.currentLine),
  34788. line (other.line),
  34789. position (other.position)
  34790. {
  34791. }
  34792. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  34793. {
  34794. document = other.document;
  34795. currentLine = other.currentLine;
  34796. line = other.line;
  34797. position = other.position;
  34798. return *this;
  34799. }
  34800. CodeDocument::Iterator::~Iterator() throw()
  34801. {
  34802. }
  34803. juce_wchar CodeDocument::Iterator::nextChar()
  34804. {
  34805. if (currentLine == 0)
  34806. return 0;
  34807. jassert (currentLine == document->lines.getUnchecked (line));
  34808. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  34809. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34810. {
  34811. ++line;
  34812. currentLine = document->lines [line];
  34813. }
  34814. return result;
  34815. }
  34816. void CodeDocument::Iterator::skip()
  34817. {
  34818. if (currentLine != 0)
  34819. {
  34820. jassert (currentLine == document->lines.getUnchecked (line));
  34821. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  34822. {
  34823. ++line;
  34824. currentLine = document->lines [line];
  34825. }
  34826. }
  34827. }
  34828. void CodeDocument::Iterator::skipToEndOfLine()
  34829. {
  34830. if (currentLine != 0)
  34831. {
  34832. jassert (currentLine == document->lines.getUnchecked (line));
  34833. ++line;
  34834. currentLine = document->lines [line];
  34835. if (currentLine != 0)
  34836. position = currentLine->lineStartInFile;
  34837. else
  34838. position = document->getNumCharacters();
  34839. }
  34840. }
  34841. juce_wchar CodeDocument::Iterator::peekNextChar() const
  34842. {
  34843. if (currentLine == 0)
  34844. return 0;
  34845. jassert (currentLine == document->lines.getUnchecked (line));
  34846. return const_cast <const String&> (currentLine->line) [position - currentLine->lineStartInFile];
  34847. }
  34848. void CodeDocument::Iterator::skipWhitespace()
  34849. {
  34850. while (CharacterFunctions::isWhitespace (peekNextChar()))
  34851. skip();
  34852. }
  34853. bool CodeDocument::Iterator::isEOF() const throw()
  34854. {
  34855. return currentLine == 0;
  34856. }
  34857. CodeDocument::Position::Position() throw()
  34858. : owner (0), characterPos (0), line (0),
  34859. indexInLine (0), positionMaintained (false)
  34860. {
  34861. }
  34862. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34863. const int line_, const int indexInLine_) throw()
  34864. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34865. characterPos (0), line (line_),
  34866. indexInLine (indexInLine_), positionMaintained (false)
  34867. {
  34868. setLineAndIndex (line_, indexInLine_);
  34869. }
  34870. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  34871. const int characterPos_) throw()
  34872. : owner (const_cast <CodeDocument*> (ownerDocument)),
  34873. positionMaintained (false)
  34874. {
  34875. setPosition (characterPos_);
  34876. }
  34877. CodeDocument::Position::Position (const Position& other) throw()
  34878. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  34879. indexInLine (other.indexInLine), positionMaintained (false)
  34880. {
  34881. jassert (*this == other);
  34882. }
  34883. CodeDocument::Position::~Position() throw()
  34884. {
  34885. setPositionMaintained (false);
  34886. }
  34887. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  34888. {
  34889. if (this != &other)
  34890. {
  34891. const bool wasPositionMaintained = positionMaintained;
  34892. if (owner != other.owner)
  34893. setPositionMaintained (false);
  34894. owner = other.owner;
  34895. line = other.line;
  34896. indexInLine = other.indexInLine;
  34897. characterPos = other.characterPos;
  34898. setPositionMaintained (wasPositionMaintained);
  34899. jassert (*this == other);
  34900. }
  34901. return *this;
  34902. }
  34903. bool CodeDocument::Position::operator== (const Position& other) const throw()
  34904. {
  34905. jassert ((characterPos == other.characterPos)
  34906. == (line == other.line && indexInLine == other.indexInLine));
  34907. return characterPos == other.characterPos
  34908. && line == other.line
  34909. && indexInLine == other.indexInLine
  34910. && owner == other.owner;
  34911. }
  34912. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  34913. {
  34914. return ! operator== (other);
  34915. }
  34916. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  34917. {
  34918. jassert (owner != 0);
  34919. if (owner->lines.size() == 0)
  34920. {
  34921. line = 0;
  34922. indexInLine = 0;
  34923. characterPos = 0;
  34924. }
  34925. else
  34926. {
  34927. if (newLine >= owner->lines.size())
  34928. {
  34929. line = owner->lines.size() - 1;
  34930. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34931. jassert (l != 0);
  34932. indexInLine = l->lineLengthWithoutNewLines;
  34933. characterPos = l->lineStartInFile + indexInLine;
  34934. }
  34935. else
  34936. {
  34937. line = jmax (0, newLine);
  34938. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34939. jassert (l != 0);
  34940. if (l->lineLengthWithoutNewLines > 0)
  34941. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  34942. else
  34943. indexInLine = 0;
  34944. characterPos = l->lineStartInFile + indexInLine;
  34945. }
  34946. }
  34947. }
  34948. void CodeDocument::Position::setPosition (const int newPosition) throw()
  34949. {
  34950. jassert (owner != 0);
  34951. line = 0;
  34952. indexInLine = 0;
  34953. characterPos = 0;
  34954. if (newPosition > 0)
  34955. {
  34956. int lineStart = 0;
  34957. int lineEnd = owner->lines.size();
  34958. for (;;)
  34959. {
  34960. if (lineEnd - lineStart < 4)
  34961. {
  34962. for (int i = lineStart; i < lineEnd; ++i)
  34963. {
  34964. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  34965. int index = newPosition - l->lineStartInFile;
  34966. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  34967. {
  34968. line = i;
  34969. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  34970. characterPos = l->lineStartInFile + indexInLine;
  34971. }
  34972. }
  34973. break;
  34974. }
  34975. else
  34976. {
  34977. const int midIndex = (lineStart + lineEnd + 1) / 2;
  34978. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  34979. if (newPosition >= mid->lineStartInFile)
  34980. lineStart = midIndex;
  34981. else
  34982. lineEnd = midIndex;
  34983. }
  34984. }
  34985. }
  34986. }
  34987. void CodeDocument::Position::moveBy (int characterDelta) throw()
  34988. {
  34989. jassert (owner != 0);
  34990. if (characterDelta == 1)
  34991. {
  34992. setPosition (getPosition());
  34993. // If moving right, make sure we don't get stuck between the \r and \n characters..
  34994. if (line < owner->lines.size())
  34995. {
  34996. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  34997. if (indexInLine + characterDelta < l->lineLength
  34998. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  34999. ++characterDelta;
  35000. }
  35001. }
  35002. setPosition (characterPos + characterDelta);
  35003. }
  35004. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35005. {
  35006. CodeDocument::Position p (*this);
  35007. p.moveBy (characterDelta);
  35008. return p;
  35009. }
  35010. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35011. {
  35012. CodeDocument::Position p (*this);
  35013. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35014. return p;
  35015. }
  35016. const juce_wchar CodeDocument::Position::getCharacter() const throw()
  35017. {
  35018. const CodeDocumentLine* const l = owner->lines [line];
  35019. return l == 0 ? 0 : l->line [getIndexInLine()];
  35020. }
  35021. const String CodeDocument::Position::getLineText() const throw()
  35022. {
  35023. const CodeDocumentLine* const l = owner->lines [line];
  35024. return l == 0 ? String::empty : l->line;
  35025. }
  35026. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35027. {
  35028. if (isMaintained != positionMaintained)
  35029. {
  35030. positionMaintained = isMaintained;
  35031. if (owner != 0)
  35032. {
  35033. if (isMaintained)
  35034. {
  35035. jassert (! owner->positionsToMaintain.contains (this));
  35036. owner->positionsToMaintain.add (this);
  35037. }
  35038. else
  35039. {
  35040. jassert (owner->positionsToMaintain.contains (this));
  35041. owner->positionsToMaintain.removeValue (this);
  35042. }
  35043. }
  35044. }
  35045. }
  35046. CodeDocument::CodeDocument()
  35047. : undoManager (std::numeric_limits<int>::max(), 10000),
  35048. currentActionIndex (0),
  35049. indexOfSavedState (-1),
  35050. maximumLineLength (-1),
  35051. newLineChars ("\r\n")
  35052. {
  35053. }
  35054. CodeDocument::~CodeDocument()
  35055. {
  35056. }
  35057. const String CodeDocument::getAllContent() const throw()
  35058. {
  35059. return getTextBetween (Position (this, 0),
  35060. Position (this, lines.size(), 0));
  35061. }
  35062. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35063. {
  35064. if (end.getPosition() <= start.getPosition())
  35065. return String::empty;
  35066. const int startLine = start.getLineNumber();
  35067. const int endLine = end.getLineNumber();
  35068. if (startLine == endLine)
  35069. {
  35070. CodeDocumentLine* const line = lines [startLine];
  35071. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35072. }
  35073. String result;
  35074. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35075. String::Concatenator concatenator (result);
  35076. const int maxLine = jmin (lines.size() - 1, endLine);
  35077. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35078. {
  35079. const CodeDocumentLine* line = lines.getUnchecked(i);
  35080. int len = line->lineLength;
  35081. if (i == startLine)
  35082. {
  35083. const int index = start.getIndexInLine();
  35084. concatenator.append (line->line.substring (index, len));
  35085. }
  35086. else if (i == endLine)
  35087. {
  35088. len = end.getIndexInLine();
  35089. concatenator.append (line->line.substring (0, len));
  35090. }
  35091. else
  35092. {
  35093. concatenator.append (line->line);
  35094. }
  35095. }
  35096. return result;
  35097. }
  35098. int CodeDocument::getNumCharacters() const throw()
  35099. {
  35100. const CodeDocumentLine* const lastLine = lines.getLast();
  35101. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35102. }
  35103. const String CodeDocument::getLine (const int lineIndex) const throw()
  35104. {
  35105. const CodeDocumentLine* const line = lines [lineIndex];
  35106. return (line == 0) ? String::empty : line->line;
  35107. }
  35108. int CodeDocument::getMaximumLineLength() throw()
  35109. {
  35110. if (maximumLineLength < 0)
  35111. {
  35112. maximumLineLength = 0;
  35113. for (int i = lines.size(); --i >= 0;)
  35114. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35115. }
  35116. return maximumLineLength;
  35117. }
  35118. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35119. {
  35120. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35121. }
  35122. void CodeDocument::insertText (const Position& position, const String& text)
  35123. {
  35124. insert (text, position.getPosition(), true);
  35125. }
  35126. void CodeDocument::replaceAllContent (const String& newContent)
  35127. {
  35128. remove (0, getNumCharacters(), true);
  35129. insert (newContent, 0, true);
  35130. }
  35131. bool CodeDocument::loadFromStream (InputStream& stream)
  35132. {
  35133. replaceAllContent (stream.readEntireStreamAsString());
  35134. setSavePoint();
  35135. clearUndoHistory();
  35136. return true;
  35137. }
  35138. bool CodeDocument::writeToStream (OutputStream& stream)
  35139. {
  35140. for (int i = 0; i < lines.size(); ++i)
  35141. {
  35142. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35143. const char* utf8 = temp.toUTF8();
  35144. if (! stream.write (utf8, (int) strlen (utf8)))
  35145. return false;
  35146. }
  35147. return true;
  35148. }
  35149. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35150. {
  35151. jassert (newLine == "\r\n" || newLine == "\n" || newLine == "\r");
  35152. newLineChars = newLine;
  35153. }
  35154. void CodeDocument::newTransaction()
  35155. {
  35156. undoManager.beginNewTransaction (String::empty);
  35157. }
  35158. void CodeDocument::undo()
  35159. {
  35160. newTransaction();
  35161. undoManager.undo();
  35162. }
  35163. void CodeDocument::redo()
  35164. {
  35165. undoManager.redo();
  35166. }
  35167. void CodeDocument::clearUndoHistory()
  35168. {
  35169. undoManager.clearUndoHistory();
  35170. }
  35171. void CodeDocument::setSavePoint() throw()
  35172. {
  35173. indexOfSavedState = currentActionIndex;
  35174. }
  35175. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35176. {
  35177. return currentActionIndex != indexOfSavedState;
  35178. }
  35179. static int getCodeCharacterCategory (const juce_wchar character) throw()
  35180. {
  35181. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35182. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35183. }
  35184. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35185. {
  35186. Position p (position);
  35187. const int maxDistance = 256;
  35188. int i = 0;
  35189. while (i < maxDistance
  35190. && CharacterFunctions::isWhitespace (p.getCharacter())
  35191. && (i == 0 || (p.getCharacter() != '\n'
  35192. && p.getCharacter() != '\r')))
  35193. {
  35194. ++i;
  35195. p.moveBy (1);
  35196. }
  35197. if (i == 0)
  35198. {
  35199. const int type = getCodeCharacterCategory (p.getCharacter());
  35200. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35201. {
  35202. ++i;
  35203. p.moveBy (1);
  35204. }
  35205. while (i < maxDistance
  35206. && CharacterFunctions::isWhitespace (p.getCharacter())
  35207. && (i == 0 || (p.getCharacter() != '\n'
  35208. && p.getCharacter() != '\r')))
  35209. {
  35210. ++i;
  35211. p.moveBy (1);
  35212. }
  35213. }
  35214. return p;
  35215. }
  35216. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35217. {
  35218. Position p (position);
  35219. const int maxDistance = 256;
  35220. int i = 0;
  35221. bool stoppedAtLineStart = false;
  35222. while (i < maxDistance)
  35223. {
  35224. const juce_wchar c = p.movedBy (-1).getCharacter();
  35225. if (c == '\r' || c == '\n')
  35226. {
  35227. stoppedAtLineStart = true;
  35228. if (i > 0)
  35229. break;
  35230. }
  35231. if (! CharacterFunctions::isWhitespace (c))
  35232. break;
  35233. p.moveBy (-1);
  35234. ++i;
  35235. }
  35236. if (i < maxDistance && ! stoppedAtLineStart)
  35237. {
  35238. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35239. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35240. {
  35241. p.moveBy (-1);
  35242. ++i;
  35243. }
  35244. }
  35245. return p;
  35246. }
  35247. void CodeDocument::checkLastLineStatus()
  35248. {
  35249. while (lines.size() > 0
  35250. && lines.getLast()->lineLength == 0
  35251. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35252. {
  35253. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35254. lines.removeLast();
  35255. }
  35256. const CodeDocumentLine* const lastLine = lines.getLast();
  35257. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35258. {
  35259. // check that there's an empty line at the end if the preceding one ends in a newline..
  35260. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35261. }
  35262. }
  35263. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35264. {
  35265. listeners.add (listener);
  35266. }
  35267. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35268. {
  35269. listeners.remove (listener);
  35270. }
  35271. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35272. {
  35273. Position startPos (this, startLine, 0);
  35274. Position endPos (this, endLine, 0);
  35275. listeners.call (&Listener::codeDocumentChanged, startPos, endPos);
  35276. }
  35277. class CodeDocumentInsertAction : public UndoableAction
  35278. {
  35279. CodeDocument& owner;
  35280. const String text;
  35281. int insertPos;
  35282. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35283. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35284. public:
  35285. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35286. : owner (owner_),
  35287. text (text_),
  35288. insertPos (insertPos_)
  35289. {
  35290. }
  35291. ~CodeDocumentInsertAction() {}
  35292. bool perform()
  35293. {
  35294. owner.currentActionIndex++;
  35295. owner.insert (text, insertPos, false);
  35296. return true;
  35297. }
  35298. bool undo()
  35299. {
  35300. owner.currentActionIndex--;
  35301. owner.remove (insertPos, insertPos + text.length(), false);
  35302. return true;
  35303. }
  35304. int getSizeInUnits() { return text.length() + 32; }
  35305. };
  35306. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35307. {
  35308. if (text.isEmpty())
  35309. return;
  35310. if (undoable)
  35311. {
  35312. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35313. }
  35314. else
  35315. {
  35316. Position pos (this, insertPos);
  35317. const int firstAffectedLine = pos.getLineNumber();
  35318. int lastAffectedLine = firstAffectedLine + 1;
  35319. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35320. String textInsideOriginalLine (text);
  35321. if (firstLine != 0)
  35322. {
  35323. const int index = pos.getIndexInLine();
  35324. textInsideOriginalLine = firstLine->line.substring (0, index)
  35325. + textInsideOriginalLine
  35326. + firstLine->line.substring (index);
  35327. }
  35328. maximumLineLength = -1;
  35329. Array <CodeDocumentLine*> newLines;
  35330. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35331. jassert (newLines.size() > 0);
  35332. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35333. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35334. lines.set (firstAffectedLine, newFirstLine);
  35335. if (newLines.size() > 1)
  35336. {
  35337. for (int i = 1; i < newLines.size(); ++i)
  35338. {
  35339. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35340. lines.insert (firstAffectedLine + i, l);
  35341. }
  35342. lastAffectedLine = lines.size();
  35343. }
  35344. int i, lineStart = newFirstLine->lineStartInFile;
  35345. for (i = firstAffectedLine; i < lines.size(); ++i)
  35346. {
  35347. CodeDocumentLine* const l = lines.getUnchecked (i);
  35348. l->lineStartInFile = lineStart;
  35349. lineStart += l->lineLength;
  35350. }
  35351. checkLastLineStatus();
  35352. const int newTextLength = text.length();
  35353. for (i = 0; i < positionsToMaintain.size(); ++i)
  35354. {
  35355. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35356. if (p->getPosition() >= insertPos)
  35357. p->setPosition (p->getPosition() + newTextLength);
  35358. }
  35359. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35360. }
  35361. }
  35362. class CodeDocumentDeleteAction : public UndoableAction
  35363. {
  35364. CodeDocument& owner;
  35365. int startPos, endPos;
  35366. String removedText;
  35367. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35368. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35369. public:
  35370. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35371. : owner (owner_),
  35372. startPos (startPos_),
  35373. endPos (endPos_)
  35374. {
  35375. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35376. CodeDocument::Position (&owner, endPos));
  35377. }
  35378. ~CodeDocumentDeleteAction() {}
  35379. bool perform()
  35380. {
  35381. owner.currentActionIndex++;
  35382. owner.remove (startPos, endPos, false);
  35383. return true;
  35384. }
  35385. bool undo()
  35386. {
  35387. owner.currentActionIndex--;
  35388. owner.insert (removedText, startPos, false);
  35389. return true;
  35390. }
  35391. int getSizeInUnits() { return removedText.length() + 32; }
  35392. };
  35393. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35394. {
  35395. if (endPos <= startPos)
  35396. return;
  35397. if (undoable)
  35398. {
  35399. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35400. }
  35401. else
  35402. {
  35403. Position startPosition (this, startPos);
  35404. Position endPosition (this, endPos);
  35405. maximumLineLength = -1;
  35406. const int firstAffectedLine = startPosition.getLineNumber();
  35407. const int endLine = endPosition.getLineNumber();
  35408. int lastAffectedLine = firstAffectedLine + 1;
  35409. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35410. if (firstAffectedLine == endLine)
  35411. {
  35412. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35413. + firstLine->line.substring (endPosition.getIndexInLine());
  35414. firstLine->updateLength();
  35415. }
  35416. else
  35417. {
  35418. lastAffectedLine = lines.size();
  35419. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35420. jassert (lastLine != 0);
  35421. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35422. + lastLine->line.substring (endPosition.getIndexInLine());
  35423. firstLine->updateLength();
  35424. int numLinesToRemove = endLine - firstAffectedLine;
  35425. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35426. }
  35427. int i;
  35428. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35429. {
  35430. CodeDocumentLine* const l = lines.getUnchecked (i);
  35431. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  35432. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  35433. }
  35434. checkLastLineStatus();
  35435. const int totalChars = getNumCharacters();
  35436. for (i = 0; i < positionsToMaintain.size(); ++i)
  35437. {
  35438. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  35439. if (p->getPosition() > startPosition.getPosition())
  35440. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  35441. if (p->getPosition() > totalChars)
  35442. p->setPosition (totalChars);
  35443. }
  35444. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35445. }
  35446. }
  35447. END_JUCE_NAMESPACE
  35448. /*** End of inlined file: juce_CodeDocument.cpp ***/
  35449. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  35450. BEGIN_JUCE_NAMESPACE
  35451. class CodeEditorComponent::CaretComponent : public Component,
  35452. public Timer
  35453. {
  35454. public:
  35455. CaretComponent()
  35456. {
  35457. setAlwaysOnTop (true);
  35458. setInterceptsMouseClicks (false, false);
  35459. }
  35460. ~CaretComponent()
  35461. {
  35462. }
  35463. void paint (Graphics& g)
  35464. {
  35465. if (getParentComponent()->hasKeyboardFocus (true))
  35466. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  35467. }
  35468. void timerCallback()
  35469. {
  35470. setVisible (! isVisible());
  35471. }
  35472. void updatePosition (CodeEditorComponent& owner)
  35473. {
  35474. startTimer (400);
  35475. setVisible (true);
  35476. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  35477. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  35478. }
  35479. private:
  35480. CaretComponent (const CaretComponent&);
  35481. CaretComponent& operator= (const CaretComponent&);
  35482. };
  35483. class CodeEditorComponent::CodeEditorLine
  35484. {
  35485. public:
  35486. CodeEditorLine() throw()
  35487. : highlightColumnStart (0), highlightColumnEnd (0)
  35488. {
  35489. }
  35490. ~CodeEditorLine() throw()
  35491. {
  35492. }
  35493. bool update (CodeDocument& document, int lineNum,
  35494. CodeDocument::Iterator& source,
  35495. CodeTokeniser* analyser, const int spacesPerTab,
  35496. const CodeDocument::Position& selectionStart,
  35497. const CodeDocument::Position& selectionEnd)
  35498. {
  35499. Array <SyntaxToken> newTokens;
  35500. newTokens.ensureStorageAllocated (8);
  35501. if (analyser == 0)
  35502. {
  35503. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  35504. }
  35505. else if (lineNum < document.getNumLines())
  35506. {
  35507. const CodeDocument::Position pos (&document, lineNum, 0);
  35508. createTokens (pos.getPosition(), pos.getLineText(),
  35509. source, analyser, newTokens);
  35510. }
  35511. replaceTabsWithSpaces (newTokens, spacesPerTab);
  35512. int newHighlightStart = 0;
  35513. int newHighlightEnd = 0;
  35514. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  35515. {
  35516. const String line (document.getLine (lineNum));
  35517. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  35518. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  35519. line, spacesPerTab);
  35520. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  35521. line, spacesPerTab);
  35522. }
  35523. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  35524. {
  35525. highlightColumnStart = newHighlightStart;
  35526. highlightColumnEnd = newHighlightEnd;
  35527. }
  35528. else
  35529. {
  35530. if (tokens.size() == newTokens.size())
  35531. {
  35532. bool allTheSame = true;
  35533. for (int i = newTokens.size(); --i >= 0;)
  35534. {
  35535. if (tokens.getReference(i) != newTokens.getReference(i))
  35536. {
  35537. allTheSame = false;
  35538. break;
  35539. }
  35540. }
  35541. if (allTheSame)
  35542. return false;
  35543. }
  35544. }
  35545. tokens.swapWithArray (newTokens);
  35546. return true;
  35547. }
  35548. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  35549. float x, const int y, const int baselineOffset, const int lineHeight,
  35550. const Colour& highlightColour) const throw()
  35551. {
  35552. if (highlightColumnStart < highlightColumnEnd)
  35553. {
  35554. g.setColour (highlightColour);
  35555. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  35556. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  35557. }
  35558. int lastType = std::numeric_limits<int>::min();
  35559. for (int i = 0; i < tokens.size(); ++i)
  35560. {
  35561. SyntaxToken& token = tokens.getReference(i);
  35562. if (lastType != token.tokenType)
  35563. {
  35564. lastType = token.tokenType;
  35565. g.setColour (owner.getColourForTokenType (lastType));
  35566. }
  35567. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  35568. if (i < tokens.size() - 1)
  35569. {
  35570. if (token.width < 0)
  35571. token.width = font.getStringWidthFloat (token.text);
  35572. x += token.width;
  35573. }
  35574. }
  35575. }
  35576. private:
  35577. struct SyntaxToken
  35578. {
  35579. String text;
  35580. int tokenType;
  35581. float width;
  35582. SyntaxToken (const String& text_, const int type) throw()
  35583. : text (text_), tokenType (type), width (-1.0f)
  35584. {
  35585. }
  35586. bool operator!= (const SyntaxToken& other) const throw()
  35587. {
  35588. return text != other.text || tokenType != other.tokenType;
  35589. }
  35590. };
  35591. Array <SyntaxToken> tokens;
  35592. int highlightColumnStart, highlightColumnEnd;
  35593. static void createTokens (int startPosition, const String& lineText,
  35594. CodeDocument::Iterator& source,
  35595. CodeTokeniser* analyser,
  35596. Array <SyntaxToken>& newTokens)
  35597. {
  35598. CodeDocument::Iterator lastIterator (source);
  35599. const int lineLength = lineText.length();
  35600. for (;;)
  35601. {
  35602. int tokenType = analyser->readNextToken (source);
  35603. int tokenStart = lastIterator.getPosition();
  35604. int tokenEnd = source.getPosition();
  35605. if (tokenEnd <= tokenStart)
  35606. break;
  35607. tokenEnd -= startPosition;
  35608. if (tokenEnd > 0)
  35609. {
  35610. tokenStart -= startPosition;
  35611. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  35612. tokenType));
  35613. if (tokenEnd >= lineLength)
  35614. break;
  35615. }
  35616. lastIterator = source;
  35617. }
  35618. source = lastIterator;
  35619. }
  35620. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  35621. {
  35622. int x = 0;
  35623. for (int i = 0; i < tokens.size(); ++i)
  35624. {
  35625. SyntaxToken& t = tokens.getReference(i);
  35626. for (;;)
  35627. {
  35628. int tabPos = t.text.indexOfChar ('\t');
  35629. if (tabPos < 0)
  35630. break;
  35631. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  35632. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (" ", spacesNeeded));
  35633. }
  35634. x += t.text.length();
  35635. }
  35636. }
  35637. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  35638. {
  35639. jassert (index <= line.length());
  35640. int col = 0;
  35641. for (int i = 0; i < index; ++i)
  35642. {
  35643. if (line[i] != '\t')
  35644. ++col;
  35645. else
  35646. col += spacesPerTab - (col % spacesPerTab);
  35647. }
  35648. return col;
  35649. }
  35650. };
  35651. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  35652. CodeTokeniser* const codeTokeniser_)
  35653. : document (document_),
  35654. firstLineOnScreen (0),
  35655. gutter (5),
  35656. spacesPerTab (4),
  35657. lineHeight (0),
  35658. linesOnScreen (0),
  35659. columnsOnScreen (0),
  35660. scrollbarThickness (16),
  35661. columnToTryToMaintain (-1),
  35662. useSpacesForTabs (false),
  35663. xOffset (0),
  35664. codeTokeniser (codeTokeniser_)
  35665. {
  35666. caretPos = CodeDocument::Position (&document_, 0, 0);
  35667. caretPos.setPositionMaintained (true);
  35668. selectionStart = CodeDocument::Position (&document_, 0, 0);
  35669. selectionStart.setPositionMaintained (true);
  35670. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  35671. selectionEnd.setPositionMaintained (true);
  35672. setOpaque (true);
  35673. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  35674. setWantsKeyboardFocus (true);
  35675. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  35676. verticalScrollBar->setSingleStepSize (1.0);
  35677. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  35678. horizontalScrollBar->setSingleStepSize (1.0);
  35679. addAndMakeVisible (caret = new CaretComponent());
  35680. Font f (12.0f);
  35681. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  35682. setFont (f);
  35683. resetToDefaultColours();
  35684. verticalScrollBar->addListener (this);
  35685. horizontalScrollBar->addListener (this);
  35686. document.addListener (this);
  35687. }
  35688. CodeEditorComponent::~CodeEditorComponent()
  35689. {
  35690. document.removeListener (this);
  35691. deleteAllChildren();
  35692. }
  35693. void CodeEditorComponent::loadContent (const String& newContent)
  35694. {
  35695. clearCachedIterators (0);
  35696. document.replaceAllContent (newContent);
  35697. document.clearUndoHistory();
  35698. document.setSavePoint();
  35699. caretPos.setPosition (0);
  35700. selectionStart.setPosition (0);
  35701. selectionEnd.setPosition (0);
  35702. scrollToLine (0);
  35703. }
  35704. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  35705. const CodeDocument::Position& affectedTextEnd)
  35706. {
  35707. clearCachedIterators (affectedTextStart.getLineNumber());
  35708. triggerAsyncUpdate();
  35709. caret->updatePosition (*this);
  35710. columnToTryToMaintain = -1;
  35711. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  35712. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  35713. deselectAll();
  35714. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  35715. || caretPos.getPosition() < affectedTextStart.getPosition())
  35716. moveCaretTo (affectedTextStart, false);
  35717. updateScrollBars();
  35718. }
  35719. void CodeEditorComponent::resized()
  35720. {
  35721. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  35722. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  35723. lines.clear();
  35724. rebuildLineTokens();
  35725. caret->updatePosition (*this);
  35726. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  35727. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  35728. updateScrollBars();
  35729. }
  35730. void CodeEditorComponent::paint (Graphics& g)
  35731. {
  35732. handleUpdateNowIfNeeded();
  35733. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  35734. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  35735. g.setFont (font);
  35736. const int baselineOffset = (int) font.getAscent();
  35737. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  35738. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  35739. const Rectangle<int> clip (g.getClipBounds());
  35740. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  35741. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  35742. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  35743. {
  35744. lines.getUnchecked(j)->draw (*this, g, font,
  35745. (float) (gutter - xOffset * charWidth),
  35746. lineHeight * j, baselineOffset, lineHeight,
  35747. highlightColour);
  35748. }
  35749. }
  35750. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  35751. {
  35752. if (scrollbarThickness != thickness)
  35753. {
  35754. scrollbarThickness = thickness;
  35755. resized();
  35756. }
  35757. }
  35758. void CodeEditorComponent::handleAsyncUpdate()
  35759. {
  35760. rebuildLineTokens();
  35761. }
  35762. void CodeEditorComponent::rebuildLineTokens()
  35763. {
  35764. cancelPendingUpdate();
  35765. const int numNeeded = linesOnScreen + 1;
  35766. int minLineToRepaint = numNeeded;
  35767. int maxLineToRepaint = 0;
  35768. if (numNeeded != lines.size())
  35769. {
  35770. lines.clear();
  35771. for (int i = numNeeded; --i >= 0;)
  35772. lines.add (new CodeEditorLine());
  35773. minLineToRepaint = 0;
  35774. maxLineToRepaint = numNeeded;
  35775. }
  35776. jassert (numNeeded == lines.size());
  35777. CodeDocument::Iterator source (&document);
  35778. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  35779. for (int i = 0; i < numNeeded; ++i)
  35780. {
  35781. CodeEditorLine* const line = lines.getUnchecked(i);
  35782. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  35783. selectionStart, selectionEnd))
  35784. {
  35785. minLineToRepaint = jmin (minLineToRepaint, i);
  35786. maxLineToRepaint = jmax (maxLineToRepaint, i);
  35787. }
  35788. }
  35789. if (minLineToRepaint <= maxLineToRepaint)
  35790. {
  35791. repaint (gutter, lineHeight * minLineToRepaint - 1,
  35792. verticalScrollBar->getX() - gutter,
  35793. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  35794. }
  35795. }
  35796. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  35797. {
  35798. caretPos = newPos;
  35799. columnToTryToMaintain = -1;
  35800. if (highlighting)
  35801. {
  35802. if (dragType == notDragging)
  35803. {
  35804. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  35805. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  35806. dragType = draggingSelectionStart;
  35807. else
  35808. dragType = draggingSelectionEnd;
  35809. }
  35810. if (dragType == draggingSelectionStart)
  35811. {
  35812. selectionStart = caretPos;
  35813. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35814. {
  35815. const CodeDocument::Position temp (selectionStart);
  35816. selectionStart = selectionEnd;
  35817. selectionEnd = temp;
  35818. dragType = draggingSelectionEnd;
  35819. }
  35820. }
  35821. else
  35822. {
  35823. selectionEnd = caretPos;
  35824. if (selectionEnd.getPosition() < selectionStart.getPosition())
  35825. {
  35826. const CodeDocument::Position temp (selectionStart);
  35827. selectionStart = selectionEnd;
  35828. selectionEnd = temp;
  35829. dragType = draggingSelectionStart;
  35830. }
  35831. }
  35832. triggerAsyncUpdate();
  35833. }
  35834. else
  35835. {
  35836. deselectAll();
  35837. }
  35838. caret->updatePosition (*this);
  35839. scrollToKeepCaretOnScreen();
  35840. updateScrollBars();
  35841. }
  35842. void CodeEditorComponent::deselectAll()
  35843. {
  35844. if (selectionStart != selectionEnd)
  35845. triggerAsyncUpdate();
  35846. selectionStart = caretPos;
  35847. selectionEnd = caretPos;
  35848. }
  35849. void CodeEditorComponent::updateScrollBars()
  35850. {
  35851. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  35852. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  35853. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  35854. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  35855. }
  35856. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  35857. {
  35858. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  35859. newFirstLineOnScreen);
  35860. if (newFirstLineOnScreen != firstLineOnScreen)
  35861. {
  35862. firstLineOnScreen = newFirstLineOnScreen;
  35863. caret->updatePosition (*this);
  35864. updateCachedIterators (firstLineOnScreen);
  35865. triggerAsyncUpdate();
  35866. }
  35867. }
  35868. void CodeEditorComponent::scrollToColumnInternal (double column)
  35869. {
  35870. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  35871. if (xOffset != newOffset)
  35872. {
  35873. xOffset = newOffset;
  35874. caret->updatePosition (*this);
  35875. repaint();
  35876. }
  35877. }
  35878. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  35879. {
  35880. scrollToLineInternal (newFirstLineOnScreen);
  35881. updateScrollBars();
  35882. }
  35883. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  35884. {
  35885. scrollToColumnInternal (newFirstColumnOnScreen);
  35886. updateScrollBars();
  35887. }
  35888. void CodeEditorComponent::scrollBy (int deltaLines)
  35889. {
  35890. scrollToLine (firstLineOnScreen + deltaLines);
  35891. }
  35892. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  35893. {
  35894. if (caretPos.getLineNumber() < firstLineOnScreen)
  35895. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  35896. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  35897. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  35898. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35899. if (column >= xOffset + columnsOnScreen - 1)
  35900. scrollToColumn (column + 1 - columnsOnScreen);
  35901. else if (column < xOffset)
  35902. scrollToColumn (column);
  35903. }
  35904. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  35905. {
  35906. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  35907. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  35908. roundToInt (charWidth),
  35909. lineHeight);
  35910. }
  35911. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  35912. {
  35913. const int line = y / lineHeight + firstLineOnScreen;
  35914. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  35915. const int index = columnToIndex (line, column);
  35916. return CodeDocument::Position (&document, line, index);
  35917. }
  35918. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  35919. {
  35920. document.deleteSection (selectionStart, selectionEnd);
  35921. if (newText.isNotEmpty())
  35922. document.insertText (caretPos, newText);
  35923. scrollToKeepCaretOnScreen();
  35924. }
  35925. void CodeEditorComponent::insertTabAtCaret()
  35926. {
  35927. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  35928. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  35929. {
  35930. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  35931. }
  35932. if (useSpacesForTabs)
  35933. {
  35934. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  35935. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  35936. insertTextAtCaret (String::repeatedString (" ", spacesNeeded));
  35937. }
  35938. else
  35939. {
  35940. insertTextAtCaret ("\t");
  35941. }
  35942. }
  35943. void CodeEditorComponent::cut()
  35944. {
  35945. insertTextAtCaret (String::empty);
  35946. }
  35947. void CodeEditorComponent::copy()
  35948. {
  35949. newTransaction();
  35950. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  35951. if (selection.isNotEmpty())
  35952. SystemClipboard::copyTextToClipboard (selection);
  35953. }
  35954. void CodeEditorComponent::copyThenCut()
  35955. {
  35956. copy();
  35957. cut();
  35958. newTransaction();
  35959. }
  35960. void CodeEditorComponent::paste()
  35961. {
  35962. newTransaction();
  35963. const String clip (SystemClipboard::getTextFromClipboard());
  35964. if (clip.isNotEmpty())
  35965. insertTextAtCaret (clip);
  35966. newTransaction();
  35967. }
  35968. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  35969. {
  35970. newTransaction();
  35971. if (moveInWholeWordSteps)
  35972. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  35973. else
  35974. moveCaretTo (caretPos.movedBy (-1), selecting);
  35975. }
  35976. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  35977. {
  35978. newTransaction();
  35979. if (moveInWholeWordSteps)
  35980. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  35981. else
  35982. moveCaretTo (caretPos.movedBy (1), selecting);
  35983. }
  35984. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  35985. {
  35986. CodeDocument::Position pos (caretPos);
  35987. const int newLineNum = pos.getLineNumber() + delta;
  35988. if (columnToTryToMaintain < 0)
  35989. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  35990. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  35991. const int colToMaintain = columnToTryToMaintain;
  35992. moveCaretTo (pos, selecting);
  35993. columnToTryToMaintain = colToMaintain;
  35994. }
  35995. void CodeEditorComponent::cursorDown (const bool selecting)
  35996. {
  35997. newTransaction();
  35998. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  35999. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36000. else
  36001. moveLineDelta (1, selecting);
  36002. }
  36003. void CodeEditorComponent::cursorUp (const bool selecting)
  36004. {
  36005. newTransaction();
  36006. if (caretPos.getLineNumber() == 0)
  36007. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36008. else
  36009. moveLineDelta (-1, selecting);
  36010. }
  36011. void CodeEditorComponent::pageDown (const bool selecting)
  36012. {
  36013. newTransaction();
  36014. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36015. moveLineDelta (linesOnScreen, selecting);
  36016. }
  36017. void CodeEditorComponent::pageUp (const bool selecting)
  36018. {
  36019. newTransaction();
  36020. scrollBy (-linesOnScreen);
  36021. moveLineDelta (-linesOnScreen, selecting);
  36022. }
  36023. void CodeEditorComponent::scrollUp()
  36024. {
  36025. newTransaction();
  36026. scrollBy (1);
  36027. if (caretPos.getLineNumber() < firstLineOnScreen)
  36028. moveLineDelta (1, false);
  36029. }
  36030. void CodeEditorComponent::scrollDown()
  36031. {
  36032. newTransaction();
  36033. scrollBy (-1);
  36034. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36035. moveLineDelta (-1, false);
  36036. }
  36037. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36038. {
  36039. newTransaction();
  36040. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36041. }
  36042. static int findFirstNonWhitespaceChar (const String& line) throw()
  36043. {
  36044. const int len = line.length();
  36045. for (int i = 0; i < len; ++i)
  36046. if (! CharacterFunctions::isWhitespace (line [i]))
  36047. return i;
  36048. return 0;
  36049. }
  36050. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36051. {
  36052. newTransaction();
  36053. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36054. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36055. index = 0;
  36056. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36057. }
  36058. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36059. {
  36060. newTransaction();
  36061. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36062. }
  36063. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36064. {
  36065. newTransaction();
  36066. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36067. }
  36068. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36069. {
  36070. if (moveInWholeWordSteps)
  36071. {
  36072. cut(); // in case something is already highlighted
  36073. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36074. }
  36075. else
  36076. {
  36077. if (selectionStart == selectionEnd)
  36078. selectionStart.moveBy (-1);
  36079. }
  36080. cut();
  36081. }
  36082. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36083. {
  36084. if (moveInWholeWordSteps)
  36085. {
  36086. cut(); // in case something is already highlighted
  36087. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36088. }
  36089. else
  36090. {
  36091. if (selectionStart == selectionEnd)
  36092. selectionEnd.moveBy (1);
  36093. else
  36094. newTransaction();
  36095. }
  36096. cut();
  36097. }
  36098. void CodeEditorComponent::selectAll()
  36099. {
  36100. newTransaction();
  36101. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36102. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36103. }
  36104. void CodeEditorComponent::undo()
  36105. {
  36106. document.undo();
  36107. scrollToKeepCaretOnScreen();
  36108. }
  36109. void CodeEditorComponent::redo()
  36110. {
  36111. document.redo();
  36112. scrollToKeepCaretOnScreen();
  36113. }
  36114. void CodeEditorComponent::newTransaction()
  36115. {
  36116. document.newTransaction();
  36117. startTimer (600);
  36118. }
  36119. void CodeEditorComponent::timerCallback()
  36120. {
  36121. newTransaction();
  36122. }
  36123. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36124. {
  36125. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36126. }
  36127. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36128. {
  36129. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36130. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36131. }
  36132. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36133. {
  36134. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36135. CodeDocument::Position (&document, range.getEnd()));
  36136. }
  36137. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36138. {
  36139. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36140. const bool shiftDown = key.getModifiers().isShiftDown();
  36141. if (key.isKeyCode (KeyPress::leftKey))
  36142. {
  36143. cursorLeft (moveInWholeWordSteps, shiftDown);
  36144. }
  36145. else if (key.isKeyCode (KeyPress::rightKey))
  36146. {
  36147. cursorRight (moveInWholeWordSteps, shiftDown);
  36148. }
  36149. else if (key.isKeyCode (KeyPress::upKey))
  36150. {
  36151. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36152. scrollDown();
  36153. #if JUCE_MAC
  36154. else if (key.getModifiers().isCommandDown())
  36155. goToStartOfDocument (shiftDown);
  36156. #endif
  36157. else
  36158. cursorUp (shiftDown);
  36159. }
  36160. else if (key.isKeyCode (KeyPress::downKey))
  36161. {
  36162. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36163. scrollUp();
  36164. #if JUCE_MAC
  36165. else if (key.getModifiers().isCommandDown())
  36166. goToEndOfDocument (shiftDown);
  36167. #endif
  36168. else
  36169. cursorDown (shiftDown);
  36170. }
  36171. else if (key.isKeyCode (KeyPress::pageDownKey))
  36172. {
  36173. pageDown (shiftDown);
  36174. }
  36175. else if (key.isKeyCode (KeyPress::pageUpKey))
  36176. {
  36177. pageUp (shiftDown);
  36178. }
  36179. else if (key.isKeyCode (KeyPress::homeKey))
  36180. {
  36181. if (moveInWholeWordSteps)
  36182. goToStartOfDocument (shiftDown);
  36183. else
  36184. goToStartOfLine (shiftDown);
  36185. }
  36186. else if (key.isKeyCode (KeyPress::endKey))
  36187. {
  36188. if (moveInWholeWordSteps)
  36189. goToEndOfDocument (shiftDown);
  36190. else
  36191. goToEndOfLine (shiftDown);
  36192. }
  36193. else if (key.isKeyCode (KeyPress::backspaceKey))
  36194. {
  36195. backspace (moveInWholeWordSteps);
  36196. }
  36197. else if (key.isKeyCode (KeyPress::deleteKey))
  36198. {
  36199. deleteForward (moveInWholeWordSteps);
  36200. }
  36201. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0))
  36202. {
  36203. copy();
  36204. }
  36205. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  36206. {
  36207. copyThenCut();
  36208. }
  36209. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0))
  36210. {
  36211. paste();
  36212. }
  36213. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  36214. {
  36215. undo();
  36216. }
  36217. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0)
  36218. || key == KeyPress ('z', ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36219. {
  36220. redo();
  36221. }
  36222. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  36223. {
  36224. selectAll();
  36225. }
  36226. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36227. {
  36228. insertTabAtCaret();
  36229. }
  36230. else if (key == KeyPress::returnKey)
  36231. {
  36232. newTransaction();
  36233. insertTextAtCaret (document.getNewLineCharacters());
  36234. }
  36235. else if (key.isKeyCode (KeyPress::escapeKey))
  36236. {
  36237. newTransaction();
  36238. }
  36239. else if (key.getTextCharacter() >= ' ')
  36240. {
  36241. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36242. }
  36243. else
  36244. {
  36245. return false;
  36246. }
  36247. return true;
  36248. }
  36249. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36250. {
  36251. newTransaction();
  36252. dragType = notDragging;
  36253. if (! e.mods.isPopupMenu())
  36254. {
  36255. beginDragAutoRepeat (100);
  36256. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36257. }
  36258. else
  36259. {
  36260. }
  36261. }
  36262. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36263. {
  36264. if (! e.mods.isPopupMenu())
  36265. moveCaretTo (getPositionAt (e.x, e.y), true);
  36266. }
  36267. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36268. {
  36269. newTransaction();
  36270. beginDragAutoRepeat (0);
  36271. dragType = notDragging;
  36272. }
  36273. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36274. {
  36275. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36276. CodeDocument::Position tokenEnd (tokenStart);
  36277. if (e.getNumberOfClicks() > 2)
  36278. {
  36279. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36280. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36281. }
  36282. else
  36283. {
  36284. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36285. tokenEnd.moveBy (1);
  36286. tokenStart = tokenEnd;
  36287. while (tokenStart.getIndexInLine() > 0
  36288. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36289. tokenStart.moveBy (-1);
  36290. }
  36291. moveCaretTo (tokenEnd, false);
  36292. moveCaretTo (tokenStart, true);
  36293. }
  36294. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36295. {
  36296. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36297. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36298. }
  36299. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  36300. {
  36301. if (scrollBarThatHasMoved == verticalScrollBar)
  36302. scrollToLineInternal ((int) newRangeStart);
  36303. else
  36304. scrollToColumnInternal (newRangeStart);
  36305. }
  36306. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36307. {
  36308. useSpacesForTabs = insertSpaces;
  36309. if (spacesPerTab != numSpaces)
  36310. {
  36311. spacesPerTab = numSpaces;
  36312. triggerAsyncUpdate();
  36313. }
  36314. }
  36315. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36316. {
  36317. const String line (document.getLine (lineNum));
  36318. jassert (index <= line.length());
  36319. int col = 0;
  36320. for (int i = 0; i < index; ++i)
  36321. {
  36322. if (line[i] != '\t')
  36323. ++col;
  36324. else
  36325. col += getTabSize() - (col % getTabSize());
  36326. }
  36327. return col;
  36328. }
  36329. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36330. {
  36331. const String line (document.getLine (lineNum));
  36332. const int lineLength = line.length();
  36333. int i, col = 0;
  36334. for (i = 0; i < lineLength; ++i)
  36335. {
  36336. if (line[i] != '\t')
  36337. ++col;
  36338. else
  36339. col += getTabSize() - (col % getTabSize());
  36340. if (col > column)
  36341. break;
  36342. }
  36343. return i;
  36344. }
  36345. void CodeEditorComponent::setFont (const Font& newFont)
  36346. {
  36347. font = newFont;
  36348. charWidth = font.getStringWidthFloat ("0");
  36349. lineHeight = roundToInt (font.getHeight());
  36350. resized();
  36351. }
  36352. void CodeEditorComponent::resetToDefaultColours()
  36353. {
  36354. coloursForTokenCategories.clear();
  36355. if (codeTokeniser != 0)
  36356. {
  36357. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36358. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36359. }
  36360. }
  36361. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36362. {
  36363. jassert (tokenType < 256);
  36364. while (coloursForTokenCategories.size() < tokenType)
  36365. coloursForTokenCategories.add (Colours::black);
  36366. coloursForTokenCategories.set (tokenType, colour);
  36367. repaint();
  36368. }
  36369. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36370. {
  36371. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36372. return findColour (CodeEditorComponent::defaultTextColourId);
  36373. return coloursForTokenCategories.getReference (tokenType);
  36374. }
  36375. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36376. {
  36377. int i;
  36378. for (i = cachedIterators.size(); --i >= 0;)
  36379. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36380. break;
  36381. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36382. }
  36383. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36384. {
  36385. const int maxNumCachedPositions = 5000;
  36386. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36387. if (cachedIterators.size() == 0)
  36388. cachedIterators.add (new CodeDocument::Iterator (&document));
  36389. if (codeTokeniser == 0)
  36390. return;
  36391. for (;;)
  36392. {
  36393. CodeDocument::Iterator* last = cachedIterators.getLast();
  36394. if (last->getLine() >= maxLineNum)
  36395. break;
  36396. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36397. cachedIterators.add (t);
  36398. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36399. for (;;)
  36400. {
  36401. codeTokeniser->readNextToken (*t);
  36402. if (t->getLine() >= targetLine)
  36403. break;
  36404. if (t->isEOF())
  36405. return;
  36406. }
  36407. }
  36408. }
  36409. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36410. {
  36411. if (codeTokeniser == 0)
  36412. return;
  36413. for (int i = cachedIterators.size(); --i >= 0;)
  36414. {
  36415. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36416. if (t->getPosition() <= position)
  36417. {
  36418. source = *t;
  36419. break;
  36420. }
  36421. }
  36422. while (source.getPosition() < position)
  36423. {
  36424. const CodeDocument::Iterator original (source);
  36425. codeTokeniser->readNextToken (source);
  36426. if (source.getPosition() > position || source.isEOF())
  36427. {
  36428. source = original;
  36429. break;
  36430. }
  36431. }
  36432. }
  36433. END_JUCE_NAMESPACE
  36434. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  36435. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36436. BEGIN_JUCE_NAMESPACE
  36437. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  36438. {
  36439. }
  36440. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  36441. {
  36442. }
  36443. namespace CppTokeniser
  36444. {
  36445. static bool isIdentifierStart (const juce_wchar c) throw()
  36446. {
  36447. return CharacterFunctions::isLetter (c)
  36448. || c == '_' || c == '@';
  36449. }
  36450. static bool isIdentifierBody (const juce_wchar c) throw()
  36451. {
  36452. return CharacterFunctions::isLetter (c)
  36453. || CharacterFunctions::isDigit (c)
  36454. || c == '_' || c == '@';
  36455. }
  36456. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  36457. {
  36458. static const juce_wchar* keywords2Char[] =
  36459. { T("if"), T("do"), T("or"), 0 };
  36460. static const juce_wchar* keywords3Char[] =
  36461. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  36462. static const juce_wchar* keywords4Char[] =
  36463. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  36464. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  36465. static const juce_wchar* keywords5Char[] =
  36466. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  36467. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  36468. static const juce_wchar* keywords6Char[] =
  36469. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  36470. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  36471. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  36472. static const juce_wchar* keywordsOther[] =
  36473. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  36474. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  36475. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  36476. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  36477. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  36478. int tokenLength = 0;
  36479. juce_wchar possibleIdentifier [19];
  36480. while (isIdentifierBody (source.peekNextChar()))
  36481. {
  36482. const juce_wchar c = source.nextChar();
  36483. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  36484. possibleIdentifier [tokenLength] = c;
  36485. ++tokenLength;
  36486. }
  36487. if (tokenLength > 1 && tokenLength <= 16)
  36488. {
  36489. possibleIdentifier [tokenLength] = 0;
  36490. const juce_wchar** k;
  36491. switch (tokenLength)
  36492. {
  36493. case 2: k = keywords2Char; break;
  36494. case 3: k = keywords3Char; break;
  36495. case 4: k = keywords4Char; break;
  36496. case 5: k = keywords5Char; break;
  36497. case 6: k = keywords6Char; break;
  36498. default: k = keywordsOther; break;
  36499. }
  36500. int i = 0;
  36501. while (k[i] != 0)
  36502. {
  36503. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  36504. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  36505. ++i;
  36506. }
  36507. }
  36508. return CPlusPlusCodeTokeniser::tokenType_identifier;
  36509. }
  36510. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  36511. {
  36512. const juce_wchar c = source.peekNextChar();
  36513. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  36514. source.skip();
  36515. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  36516. return false;
  36517. return true;
  36518. }
  36519. static bool isHexDigit (const juce_wchar c) throw()
  36520. {
  36521. return (c >= '0' && c <= '9')
  36522. || (c >= 'a' && c <= 'f')
  36523. || (c >= 'A' && c <= 'F');
  36524. }
  36525. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  36526. {
  36527. if (source.nextChar() != '0')
  36528. return false;
  36529. juce_wchar c = source.nextChar();
  36530. if (c != 'x' && c != 'X')
  36531. return false;
  36532. int numDigits = 0;
  36533. while (isHexDigit (source.peekNextChar()))
  36534. {
  36535. ++numDigits;
  36536. source.skip();
  36537. }
  36538. if (numDigits == 0)
  36539. return false;
  36540. return skipNumberSuffix (source);
  36541. }
  36542. static bool isOctalDigit (const juce_wchar c) throw()
  36543. {
  36544. return c >= '0' && c <= '7';
  36545. }
  36546. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  36547. {
  36548. if (source.nextChar() != '0')
  36549. return false;
  36550. if (! isOctalDigit (source.nextChar()))
  36551. return false;
  36552. while (isOctalDigit (source.peekNextChar()))
  36553. source.skip();
  36554. return skipNumberSuffix (source);
  36555. }
  36556. static bool isDecimalDigit (const juce_wchar c) throw()
  36557. {
  36558. return c >= '0' && c <= '9';
  36559. }
  36560. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  36561. {
  36562. int numChars = 0;
  36563. while (isDecimalDigit (source.peekNextChar()))
  36564. {
  36565. ++numChars;
  36566. source.skip();
  36567. }
  36568. if (numChars == 0)
  36569. return false;
  36570. return skipNumberSuffix (source);
  36571. }
  36572. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  36573. {
  36574. int numDigits = 0;
  36575. while (isDecimalDigit (source.peekNextChar()))
  36576. {
  36577. source.skip();
  36578. ++numDigits;
  36579. }
  36580. const bool hasPoint = (source.peekNextChar() == '.');
  36581. if (hasPoint)
  36582. {
  36583. source.skip();
  36584. while (isDecimalDigit (source.peekNextChar()))
  36585. {
  36586. source.skip();
  36587. ++numDigits;
  36588. }
  36589. }
  36590. if (numDigits == 0)
  36591. return false;
  36592. juce_wchar c = source.peekNextChar();
  36593. const bool hasExponent = (c == 'e' || c == 'E');
  36594. if (hasExponent)
  36595. {
  36596. source.skip();
  36597. c = source.peekNextChar();
  36598. if (c == '+' || c == '-')
  36599. source.skip();
  36600. int numExpDigits = 0;
  36601. while (isDecimalDigit (source.peekNextChar()))
  36602. {
  36603. source.skip();
  36604. ++numExpDigits;
  36605. }
  36606. if (numExpDigits == 0)
  36607. return false;
  36608. }
  36609. c = source.peekNextChar();
  36610. if (c == 'f' || c == 'F')
  36611. source.skip();
  36612. else if (! (hasExponent || hasPoint))
  36613. return false;
  36614. return true;
  36615. }
  36616. static int parseNumber (CodeDocument::Iterator& source)
  36617. {
  36618. const CodeDocument::Iterator original (source);
  36619. if (parseFloatLiteral (source))
  36620. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  36621. source = original;
  36622. if (parseHexLiteral (source))
  36623. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36624. source = original;
  36625. if (parseOctalLiteral (source))
  36626. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36627. source = original;
  36628. if (parseDecimalLiteral (source))
  36629. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  36630. source = original;
  36631. source.skip();
  36632. return CPlusPlusCodeTokeniser::tokenType_error;
  36633. }
  36634. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  36635. {
  36636. const juce_wchar quote = source.nextChar();
  36637. for (;;)
  36638. {
  36639. const juce_wchar c = source.nextChar();
  36640. if (c == quote || c == 0)
  36641. break;
  36642. if (c == '\\')
  36643. source.skip();
  36644. }
  36645. }
  36646. static void skipComment (CodeDocument::Iterator& source) throw()
  36647. {
  36648. bool lastWasStar = false;
  36649. for (;;)
  36650. {
  36651. const juce_wchar c = source.nextChar();
  36652. if (c == 0 || (c == '/' && lastWasStar))
  36653. break;
  36654. lastWasStar = (c == '*');
  36655. }
  36656. }
  36657. }
  36658. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  36659. {
  36660. int result = tokenType_error;
  36661. source.skipWhitespace();
  36662. juce_wchar firstChar = source.peekNextChar();
  36663. switch (firstChar)
  36664. {
  36665. case 0:
  36666. source.skip();
  36667. break;
  36668. case '0':
  36669. case '1':
  36670. case '2':
  36671. case '3':
  36672. case '4':
  36673. case '5':
  36674. case '6':
  36675. case '7':
  36676. case '8':
  36677. case '9':
  36678. result = CppTokeniser::parseNumber (source);
  36679. break;
  36680. case '.':
  36681. result = CppTokeniser::parseNumber (source);
  36682. if (result == tokenType_error)
  36683. result = tokenType_punctuation;
  36684. break;
  36685. case ',':
  36686. case ';':
  36687. case ':':
  36688. source.skip();
  36689. result = tokenType_punctuation;
  36690. break;
  36691. case '(':
  36692. case ')':
  36693. case '{':
  36694. case '}':
  36695. case '[':
  36696. case ']':
  36697. source.skip();
  36698. result = tokenType_bracket;
  36699. break;
  36700. case '"':
  36701. case '\'':
  36702. CppTokeniser::skipQuotedString (source);
  36703. result = tokenType_stringLiteral;
  36704. break;
  36705. case '+':
  36706. result = tokenType_operator;
  36707. source.skip();
  36708. if (source.peekNextChar() == '+')
  36709. source.skip();
  36710. else if (source.peekNextChar() == '=')
  36711. source.skip();
  36712. break;
  36713. case '-':
  36714. source.skip();
  36715. result = CppTokeniser::parseNumber (source);
  36716. if (result == tokenType_error)
  36717. {
  36718. result = tokenType_operator;
  36719. if (source.peekNextChar() == '-')
  36720. source.skip();
  36721. else if (source.peekNextChar() == '=')
  36722. source.skip();
  36723. }
  36724. break;
  36725. case '*':
  36726. case '%':
  36727. case '=':
  36728. case '!':
  36729. result = tokenType_operator;
  36730. source.skip();
  36731. if (source.peekNextChar() == '=')
  36732. source.skip();
  36733. break;
  36734. case '/':
  36735. result = tokenType_operator;
  36736. source.skip();
  36737. if (source.peekNextChar() == '=')
  36738. {
  36739. source.skip();
  36740. }
  36741. else if (source.peekNextChar() == '/')
  36742. {
  36743. result = tokenType_comment;
  36744. source.skipToEndOfLine();
  36745. }
  36746. else if (source.peekNextChar() == '*')
  36747. {
  36748. source.skip();
  36749. result = tokenType_comment;
  36750. CppTokeniser::skipComment (source);
  36751. }
  36752. break;
  36753. case '?':
  36754. case '~':
  36755. source.skip();
  36756. result = tokenType_operator;
  36757. break;
  36758. case '<':
  36759. source.skip();
  36760. result = tokenType_operator;
  36761. if (source.peekNextChar() == '=')
  36762. {
  36763. source.skip();
  36764. }
  36765. else if (source.peekNextChar() == '<')
  36766. {
  36767. source.skip();
  36768. if (source.peekNextChar() == '=')
  36769. source.skip();
  36770. }
  36771. break;
  36772. case '>':
  36773. source.skip();
  36774. result = tokenType_operator;
  36775. if (source.peekNextChar() == '=')
  36776. {
  36777. source.skip();
  36778. }
  36779. else if (source.peekNextChar() == '<')
  36780. {
  36781. source.skip();
  36782. if (source.peekNextChar() == '=')
  36783. source.skip();
  36784. }
  36785. break;
  36786. case '|':
  36787. source.skip();
  36788. result = tokenType_operator;
  36789. if (source.peekNextChar() == '=')
  36790. {
  36791. source.skip();
  36792. }
  36793. else if (source.peekNextChar() == '|')
  36794. {
  36795. source.skip();
  36796. if (source.peekNextChar() == '=')
  36797. source.skip();
  36798. }
  36799. break;
  36800. case '&':
  36801. source.skip();
  36802. result = tokenType_operator;
  36803. if (source.peekNextChar() == '=')
  36804. {
  36805. source.skip();
  36806. }
  36807. else if (source.peekNextChar() == '&')
  36808. {
  36809. source.skip();
  36810. if (source.peekNextChar() == '=')
  36811. source.skip();
  36812. }
  36813. break;
  36814. case '^':
  36815. source.skip();
  36816. result = tokenType_operator;
  36817. if (source.peekNextChar() == '=')
  36818. {
  36819. source.skip();
  36820. }
  36821. else if (source.peekNextChar() == '^')
  36822. {
  36823. source.skip();
  36824. if (source.peekNextChar() == '=')
  36825. source.skip();
  36826. }
  36827. break;
  36828. case '#':
  36829. result = tokenType_preprocessor;
  36830. source.skipToEndOfLine();
  36831. break;
  36832. default:
  36833. if (CppTokeniser::isIdentifierStart (firstChar))
  36834. result = CppTokeniser::parseIdentifier (source);
  36835. else
  36836. source.skip();
  36837. break;
  36838. }
  36839. //jassert (result != tokenType_unknown);
  36840. return result;
  36841. }
  36842. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  36843. {
  36844. StringArray s;
  36845. s.add ("Error");
  36846. s.add ("Comment");
  36847. s.add ("C++ keyword");
  36848. s.add ("Identifier");
  36849. s.add ("Integer literal");
  36850. s.add ("Float literal");
  36851. s.add ("String literal");
  36852. s.add ("Operator");
  36853. s.add ("Bracket");
  36854. s.add ("Punctuation");
  36855. s.add ("Preprocessor line");
  36856. return s;
  36857. }
  36858. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  36859. {
  36860. const uint32 colours[] =
  36861. {
  36862. 0xffcc0000, // error
  36863. 0xff00aa00, // comment
  36864. 0xff0000cc, // keyword
  36865. 0xff000000, // identifier
  36866. 0xff880000, // int literal
  36867. 0xff885500, // float literal
  36868. 0xff990099, // string literal
  36869. 0xff225500, // operator
  36870. 0xff000055, // bracket
  36871. 0xff004400, // punctuation
  36872. 0xff660000 // preprocessor
  36873. };
  36874. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  36875. return Colour (colours [tokenType]);
  36876. return Colours::black;
  36877. }
  36878. END_JUCE_NAMESPACE
  36879. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  36880. /*** Start of inlined file: juce_ComboBox.cpp ***/
  36881. BEGIN_JUCE_NAMESPACE
  36882. ComboBox::ComboBox (const String& name)
  36883. : Component (name),
  36884. lastCurrentId (0),
  36885. isButtonDown (false),
  36886. separatorPending (false),
  36887. menuActive (false),
  36888. label (0)
  36889. {
  36890. noChoicesMessage = TRANS("(no choices)");
  36891. setRepaintsOnMouseActivity (true);
  36892. lookAndFeelChanged();
  36893. currentId.addListener (this);
  36894. }
  36895. ComboBox::~ComboBox()
  36896. {
  36897. currentId.removeListener (this);
  36898. if (menuActive)
  36899. PopupMenu::dismissAllActiveMenus();
  36900. label = 0;
  36901. deleteAllChildren();
  36902. }
  36903. void ComboBox::setEditableText (const bool isEditable)
  36904. {
  36905. label->setEditable (isEditable, isEditable, false);
  36906. setWantsKeyboardFocus (! isEditable);
  36907. resized();
  36908. }
  36909. bool ComboBox::isTextEditable() const throw()
  36910. {
  36911. return label->isEditable();
  36912. }
  36913. void ComboBox::setJustificationType (const Justification& justification) throw()
  36914. {
  36915. label->setJustificationType (justification);
  36916. }
  36917. const Justification ComboBox::getJustificationType() const throw()
  36918. {
  36919. return label->getJustificationType();
  36920. }
  36921. void ComboBox::setTooltip (const String& newTooltip)
  36922. {
  36923. SettableTooltipClient::setTooltip (newTooltip);
  36924. label->setTooltip (newTooltip);
  36925. }
  36926. void ComboBox::addItem (const String& newItemText,
  36927. const int newItemId) throw()
  36928. {
  36929. // you can't add empty strings to the list..
  36930. jassert (newItemText.isNotEmpty());
  36931. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  36932. jassert (newItemId != 0);
  36933. // you shouldn't use duplicate item IDs!
  36934. jassert (getItemForId (newItemId) == 0);
  36935. if (newItemText.isNotEmpty() && newItemId != 0)
  36936. {
  36937. if (separatorPending)
  36938. {
  36939. separatorPending = false;
  36940. ItemInfo* const item = new ItemInfo();
  36941. item->itemId = 0;
  36942. item->isEnabled = false;
  36943. item->isHeading = false;
  36944. items.add (item);
  36945. }
  36946. ItemInfo* const item = new ItemInfo();
  36947. item->name = newItemText;
  36948. item->itemId = newItemId;
  36949. item->isEnabled = true;
  36950. item->isHeading = false;
  36951. items.add (item);
  36952. }
  36953. }
  36954. void ComboBox::addSeparator() throw()
  36955. {
  36956. separatorPending = (items.size() > 0);
  36957. }
  36958. void ComboBox::addSectionHeading (const String& headingName) throw()
  36959. {
  36960. // you can't add empty strings to the list..
  36961. jassert (headingName.isNotEmpty());
  36962. if (headingName.isNotEmpty())
  36963. {
  36964. if (separatorPending)
  36965. {
  36966. separatorPending = false;
  36967. ItemInfo* const item = new ItemInfo();
  36968. item->itemId = 0;
  36969. item->isEnabled = false;
  36970. item->isHeading = false;
  36971. items.add (item);
  36972. }
  36973. ItemInfo* const item = new ItemInfo();
  36974. item->name = headingName;
  36975. item->itemId = 0;
  36976. item->isEnabled = true;
  36977. item->isHeading = true;
  36978. items.add (item);
  36979. }
  36980. }
  36981. void ComboBox::setItemEnabled (const int itemId,
  36982. const bool shouldBeEnabled) throw()
  36983. {
  36984. ItemInfo* const item = getItemForId (itemId);
  36985. if (item != 0)
  36986. item->isEnabled = shouldBeEnabled;
  36987. }
  36988. void ComboBox::changeItemText (const int itemId,
  36989. const String& newText) throw()
  36990. {
  36991. ItemInfo* const item = getItemForId (itemId);
  36992. jassert (item != 0);
  36993. if (item != 0)
  36994. item->name = newText;
  36995. }
  36996. void ComboBox::clear (const bool dontSendChangeMessage)
  36997. {
  36998. items.clear();
  36999. separatorPending = false;
  37000. if (! label->isEditable())
  37001. setSelectedItemIndex (-1, dontSendChangeMessage);
  37002. }
  37003. bool ComboBox::ItemInfo::isSeparator() const throw()
  37004. {
  37005. return name.isEmpty();
  37006. }
  37007. bool ComboBox::ItemInfo::isRealItem() const throw()
  37008. {
  37009. return ! (isHeading || name.isEmpty());
  37010. }
  37011. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37012. {
  37013. if (itemId != 0)
  37014. {
  37015. for (int i = items.size(); --i >= 0;)
  37016. if (items.getUnchecked(i)->itemId == itemId)
  37017. return items.getUnchecked(i);
  37018. }
  37019. return 0;
  37020. }
  37021. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37022. {
  37023. int n = 0;
  37024. for (int i = 0; i < items.size(); ++i)
  37025. {
  37026. ItemInfo* const item = items.getUnchecked(i);
  37027. if (item->isRealItem())
  37028. if (n++ == index)
  37029. return item;
  37030. }
  37031. return 0;
  37032. }
  37033. int ComboBox::getNumItems() const throw()
  37034. {
  37035. int n = 0;
  37036. for (int i = items.size(); --i >= 0;)
  37037. if (items.getUnchecked(i)->isRealItem())
  37038. ++n;
  37039. return n;
  37040. }
  37041. const String ComboBox::getItemText (const int index) const throw()
  37042. {
  37043. const ItemInfo* const item = getItemForIndex (index);
  37044. if (item != 0)
  37045. return item->name;
  37046. return String::empty;
  37047. }
  37048. int ComboBox::getItemId (const int index) const throw()
  37049. {
  37050. const ItemInfo* const item = getItemForIndex (index);
  37051. return (item != 0) ? item->itemId : 0;
  37052. }
  37053. int ComboBox::indexOfItemId (const int itemId) const throw()
  37054. {
  37055. int n = 0;
  37056. for (int i = 0; i < items.size(); ++i)
  37057. {
  37058. const ItemInfo* const item = items.getUnchecked(i);
  37059. if (item->isRealItem())
  37060. {
  37061. if (item->itemId == itemId)
  37062. return n;
  37063. ++n;
  37064. }
  37065. }
  37066. return -1;
  37067. }
  37068. int ComboBox::getSelectedItemIndex() const throw()
  37069. {
  37070. int index = indexOfItemId (currentId.getValue());
  37071. if (getText() != getItemText (index))
  37072. index = -1;
  37073. return index;
  37074. }
  37075. void ComboBox::setSelectedItemIndex (const int index,
  37076. const bool dontSendChangeMessage) throw()
  37077. {
  37078. setSelectedId (getItemId (index), dontSendChangeMessage);
  37079. }
  37080. int ComboBox::getSelectedId() const throw()
  37081. {
  37082. const ItemInfo* const item = getItemForId (currentId.getValue());
  37083. return (item != 0 && getText() == item->name)
  37084. ? item->itemId
  37085. : 0;
  37086. }
  37087. void ComboBox::setSelectedId (const int newItemId,
  37088. const bool dontSendChangeMessage) throw()
  37089. {
  37090. const ItemInfo* const item = getItemForId (newItemId);
  37091. const String newItemText (item != 0 ? item->name : String::empty);
  37092. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37093. {
  37094. if (! dontSendChangeMessage)
  37095. triggerAsyncUpdate();
  37096. label->setText (newItemText, false);
  37097. lastCurrentId = newItemId;
  37098. currentId = newItemId;
  37099. repaint(); // for the benefit of the 'none selected' text
  37100. }
  37101. }
  37102. void ComboBox::valueChanged (Value&)
  37103. {
  37104. if (lastCurrentId != (int) currentId.getValue())
  37105. setSelectedId (currentId.getValue(), false);
  37106. }
  37107. const String ComboBox::getText() const throw()
  37108. {
  37109. return label->getText();
  37110. }
  37111. void ComboBox::setText (const String& newText,
  37112. const bool dontSendChangeMessage) throw()
  37113. {
  37114. for (int i = items.size(); --i >= 0;)
  37115. {
  37116. const ItemInfo* const item = items.getUnchecked(i);
  37117. if (item->isRealItem()
  37118. && item->name == newText)
  37119. {
  37120. setSelectedId (item->itemId, dontSendChangeMessage);
  37121. return;
  37122. }
  37123. }
  37124. lastCurrentId = 0;
  37125. currentId = 0;
  37126. if (label->getText() != newText)
  37127. {
  37128. label->setText (newText, false);
  37129. if (! dontSendChangeMessage)
  37130. triggerAsyncUpdate();
  37131. }
  37132. repaint();
  37133. }
  37134. void ComboBox::showEditor()
  37135. {
  37136. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37137. label->showEditor();
  37138. }
  37139. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37140. {
  37141. textWhenNothingSelected = newMessage;
  37142. repaint();
  37143. }
  37144. const String ComboBox::getTextWhenNothingSelected() const throw()
  37145. {
  37146. return textWhenNothingSelected;
  37147. }
  37148. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37149. {
  37150. noChoicesMessage = newMessage;
  37151. }
  37152. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37153. {
  37154. return noChoicesMessage;
  37155. }
  37156. void ComboBox::paint (Graphics& g)
  37157. {
  37158. getLookAndFeel().drawComboBox (g,
  37159. getWidth(),
  37160. getHeight(),
  37161. isButtonDown,
  37162. label->getRight(),
  37163. 0,
  37164. getWidth() - label->getRight(),
  37165. getHeight(),
  37166. *this);
  37167. if (textWhenNothingSelected.isNotEmpty()
  37168. && label->getText().isEmpty()
  37169. && ! label->isBeingEdited())
  37170. {
  37171. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37172. g.setFont (label->getFont());
  37173. g.drawFittedText (textWhenNothingSelected,
  37174. label->getX() + 2, label->getY() + 1,
  37175. label->getWidth() - 4, label->getHeight() - 2,
  37176. label->getJustificationType(),
  37177. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37178. }
  37179. }
  37180. void ComboBox::resized()
  37181. {
  37182. if (getHeight() > 0 && getWidth() > 0)
  37183. getLookAndFeel().positionComboBoxText (*this, *label);
  37184. }
  37185. void ComboBox::enablementChanged()
  37186. {
  37187. repaint();
  37188. }
  37189. void ComboBox::lookAndFeelChanged()
  37190. {
  37191. repaint();
  37192. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37193. if (label != 0)
  37194. {
  37195. newLabel->setEditable (label->isEditable());
  37196. newLabel->setJustificationType (label->getJustificationType());
  37197. newLabel->setTooltip (label->getTooltip());
  37198. newLabel->setText (label->getText(), false);
  37199. }
  37200. label = newLabel;
  37201. addAndMakeVisible (newLabel);
  37202. newLabel->addListener (this);
  37203. newLabel->addMouseListener (this, false);
  37204. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37205. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37206. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37207. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37208. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37209. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37210. resized();
  37211. }
  37212. void ComboBox::colourChanged()
  37213. {
  37214. lookAndFeelChanged();
  37215. }
  37216. bool ComboBox::keyPressed (const KeyPress& key)
  37217. {
  37218. bool used = false;
  37219. if (key.isKeyCode (KeyPress::upKey)
  37220. || key.isKeyCode (KeyPress::leftKey))
  37221. {
  37222. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37223. used = true;
  37224. }
  37225. else if (key.isKeyCode (KeyPress::downKey)
  37226. || key.isKeyCode (KeyPress::rightKey))
  37227. {
  37228. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37229. used = true;
  37230. }
  37231. else if (key.isKeyCode (KeyPress::returnKey))
  37232. {
  37233. showPopup();
  37234. used = true;
  37235. }
  37236. return used;
  37237. }
  37238. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37239. {
  37240. // only forward key events that aren't used by this component
  37241. return isKeyDown
  37242. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37243. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37244. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37245. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37246. }
  37247. void ComboBox::focusGained (FocusChangeType)
  37248. {
  37249. repaint();
  37250. }
  37251. void ComboBox::focusLost (FocusChangeType)
  37252. {
  37253. repaint();
  37254. }
  37255. void ComboBox::labelTextChanged (Label*)
  37256. {
  37257. triggerAsyncUpdate();
  37258. }
  37259. void ComboBox::showPopup()
  37260. {
  37261. if (! menuActive)
  37262. {
  37263. const int selectedId = getSelectedId();
  37264. Component::SafePointer<Component> deletionWatcher (this);
  37265. PopupMenu menu;
  37266. menu.setLookAndFeel (&getLookAndFeel());
  37267. for (int i = 0; i < items.size(); ++i)
  37268. {
  37269. const ItemInfo* const item = items.getUnchecked(i);
  37270. if (item->isSeparator())
  37271. menu.addSeparator();
  37272. else if (item->isHeading)
  37273. menu.addSectionHeader (item->name);
  37274. else
  37275. menu.addItem (item->itemId, item->name,
  37276. item->isEnabled, item->itemId == selectedId);
  37277. }
  37278. if (items.size() == 0)
  37279. menu.addItem (1, noChoicesMessage, false);
  37280. const int itemHeight = jlimit (12, 24, getHeight());
  37281. menuActive = true;
  37282. const int resultId = menu.showAt (this, selectedId,
  37283. getWidth(), 1, itemHeight);
  37284. if (deletionWatcher == 0)
  37285. return;
  37286. menuActive = false;
  37287. if (resultId != 0)
  37288. setSelectedId (resultId);
  37289. }
  37290. }
  37291. void ComboBox::mouseDown (const MouseEvent& e)
  37292. {
  37293. beginDragAutoRepeat (300);
  37294. isButtonDown = isEnabled();
  37295. if (isButtonDown
  37296. && (e.eventComponent == this || ! label->isEditable()))
  37297. {
  37298. showPopup();
  37299. }
  37300. }
  37301. void ComboBox::mouseDrag (const MouseEvent& e)
  37302. {
  37303. beginDragAutoRepeat (50);
  37304. if (isButtonDown && ! e.mouseWasClicked())
  37305. showPopup();
  37306. }
  37307. void ComboBox::mouseUp (const MouseEvent& e2)
  37308. {
  37309. if (isButtonDown)
  37310. {
  37311. isButtonDown = false;
  37312. repaint();
  37313. const MouseEvent e (e2.getEventRelativeTo (this));
  37314. if (reallyContains (e.x, e.y, true)
  37315. && (e2.eventComponent == this || ! label->isEditable()))
  37316. {
  37317. showPopup();
  37318. }
  37319. }
  37320. }
  37321. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37322. {
  37323. listeners.add (listener);
  37324. }
  37325. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37326. {
  37327. listeners.remove (listener);
  37328. }
  37329. void ComboBox::handleAsyncUpdate()
  37330. {
  37331. Component::BailOutChecker checker (this);
  37332. listeners.callChecked (checker, &ComboBoxListener::comboBoxChanged, this);
  37333. }
  37334. END_JUCE_NAMESPACE
  37335. /*** End of inlined file: juce_ComboBox.cpp ***/
  37336. /*** Start of inlined file: juce_Label.cpp ***/
  37337. BEGIN_JUCE_NAMESPACE
  37338. Label::Label (const String& componentName,
  37339. const String& labelText)
  37340. : Component (componentName),
  37341. textValue (labelText),
  37342. lastTextValue (labelText),
  37343. font (15.0f),
  37344. justification (Justification::centredLeft),
  37345. ownerComponent (0),
  37346. horizontalBorderSize (5),
  37347. verticalBorderSize (1),
  37348. minimumHorizontalScale (0.7f),
  37349. editSingleClick (false),
  37350. editDoubleClick (false),
  37351. lossOfFocusDiscardsChanges (false)
  37352. {
  37353. setColour (TextEditor::textColourId, Colours::black);
  37354. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37355. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37356. textValue.addListener (this);
  37357. }
  37358. Label::~Label()
  37359. {
  37360. textValue.removeListener (this);
  37361. if (ownerComponent != 0)
  37362. ownerComponent->removeComponentListener (this);
  37363. editor = 0;
  37364. }
  37365. void Label::setText (const String& newText,
  37366. const bool broadcastChangeMessage)
  37367. {
  37368. hideEditor (true);
  37369. if (lastTextValue != newText)
  37370. {
  37371. lastTextValue = newText;
  37372. textValue = newText;
  37373. repaint();
  37374. textWasChanged();
  37375. if (ownerComponent != 0)
  37376. componentMovedOrResized (*ownerComponent, true, true);
  37377. if (broadcastChangeMessage)
  37378. callChangeListeners();
  37379. }
  37380. }
  37381. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37382. {
  37383. return (returnActiveEditorContents && isBeingEdited())
  37384. ? editor->getText()
  37385. : textValue.toString();
  37386. }
  37387. void Label::valueChanged (Value&)
  37388. {
  37389. if (lastTextValue != textValue.toString())
  37390. setText (textValue.toString(), true);
  37391. }
  37392. void Label::setFont (const Font& newFont) throw()
  37393. {
  37394. font = newFont;
  37395. repaint();
  37396. }
  37397. const Font& Label::getFont() const throw()
  37398. {
  37399. return font;
  37400. }
  37401. void Label::setEditable (const bool editOnSingleClick,
  37402. const bool editOnDoubleClick,
  37403. const bool lossOfFocusDiscardsChanges_) throw()
  37404. {
  37405. editSingleClick = editOnSingleClick;
  37406. editDoubleClick = editOnDoubleClick;
  37407. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37408. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37409. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37410. }
  37411. void Label::setJustificationType (const Justification& justification_) throw()
  37412. {
  37413. justification = justification_;
  37414. repaint();
  37415. }
  37416. void Label::setBorderSize (int h, int v)
  37417. {
  37418. horizontalBorderSize = h;
  37419. verticalBorderSize = v;
  37420. repaint();
  37421. }
  37422. Component* Label::getAttachedComponent() const
  37423. {
  37424. return static_cast<Component*> (ownerComponent);
  37425. }
  37426. void Label::attachToComponent (Component* owner,
  37427. const bool onLeft)
  37428. {
  37429. if (ownerComponent != 0)
  37430. ownerComponent->removeComponentListener (this);
  37431. ownerComponent = owner;
  37432. leftOfOwnerComp = onLeft;
  37433. if (ownerComponent != 0)
  37434. {
  37435. setVisible (owner->isVisible());
  37436. ownerComponent->addComponentListener (this);
  37437. componentParentHierarchyChanged (*ownerComponent);
  37438. componentMovedOrResized (*ownerComponent, true, true);
  37439. }
  37440. }
  37441. void Label::componentMovedOrResized (Component& component,
  37442. bool /*wasMoved*/,
  37443. bool /*wasResized*/)
  37444. {
  37445. if (leftOfOwnerComp)
  37446. {
  37447. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  37448. component.getHeight());
  37449. setTopRightPosition (component.getX(), component.getY());
  37450. }
  37451. else
  37452. {
  37453. setSize (component.getWidth(),
  37454. 8 + roundToInt (getFont().getHeight()));
  37455. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  37456. }
  37457. }
  37458. void Label::componentParentHierarchyChanged (Component& component)
  37459. {
  37460. if (component.getParentComponent() != 0)
  37461. component.getParentComponent()->addChildComponent (this);
  37462. }
  37463. void Label::componentVisibilityChanged (Component& component)
  37464. {
  37465. setVisible (component.isVisible());
  37466. }
  37467. void Label::textWasEdited()
  37468. {
  37469. }
  37470. void Label::textWasChanged()
  37471. {
  37472. }
  37473. void Label::showEditor()
  37474. {
  37475. if (editor == 0)
  37476. {
  37477. addAndMakeVisible (editor = createEditorComponent());
  37478. editor->setText (getText(), false);
  37479. editor->addListener (this);
  37480. editor->grabKeyboardFocus();
  37481. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  37482. editor->addListener (this);
  37483. resized();
  37484. repaint();
  37485. editorShown (editor);
  37486. enterModalState (false);
  37487. editor->grabKeyboardFocus();
  37488. }
  37489. }
  37490. void Label::editorShown (TextEditor* /*editorComponent*/)
  37491. {
  37492. }
  37493. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  37494. {
  37495. }
  37496. bool Label::updateFromTextEditorContents()
  37497. {
  37498. jassert (editor != 0);
  37499. const String newText (editor->getText());
  37500. if (textValue.toString() != newText)
  37501. {
  37502. lastTextValue = newText;
  37503. textValue = newText;
  37504. repaint();
  37505. textWasChanged();
  37506. if (ownerComponent != 0)
  37507. componentMovedOrResized (*ownerComponent, true, true);
  37508. return true;
  37509. }
  37510. return false;
  37511. }
  37512. void Label::hideEditor (const bool discardCurrentEditorContents)
  37513. {
  37514. if (editor != 0)
  37515. {
  37516. Component::SafePointer<Component> deletionChecker (this);
  37517. editorAboutToBeHidden (editor);
  37518. const bool changed = (! discardCurrentEditorContents)
  37519. && updateFromTextEditorContents();
  37520. editor = 0;
  37521. repaint();
  37522. if (changed)
  37523. textWasEdited();
  37524. if (deletionChecker != 0)
  37525. exitModalState (0);
  37526. if (changed && deletionChecker != 0)
  37527. callChangeListeners();
  37528. }
  37529. }
  37530. void Label::inputAttemptWhenModal()
  37531. {
  37532. if (editor != 0)
  37533. {
  37534. if (lossOfFocusDiscardsChanges)
  37535. textEditorEscapeKeyPressed (*editor);
  37536. else
  37537. textEditorReturnKeyPressed (*editor);
  37538. }
  37539. }
  37540. bool Label::isBeingEdited() const throw()
  37541. {
  37542. return editor != 0;
  37543. }
  37544. TextEditor* Label::createEditorComponent()
  37545. {
  37546. TextEditor* const ed = new TextEditor (getName());
  37547. ed->setFont (font);
  37548. // copy these colours from our own settings..
  37549. const int cols[] = { TextEditor::backgroundColourId,
  37550. TextEditor::textColourId,
  37551. TextEditor::highlightColourId,
  37552. TextEditor::highlightedTextColourId,
  37553. TextEditor::caretColourId,
  37554. TextEditor::outlineColourId,
  37555. TextEditor::focusedOutlineColourId,
  37556. TextEditor::shadowColourId };
  37557. for (int i = 0; i < numElementsInArray (cols); ++i)
  37558. ed->setColour (cols[i], findColour (cols[i]));
  37559. return ed;
  37560. }
  37561. void Label::paint (Graphics& g)
  37562. {
  37563. getLookAndFeel().drawLabel (g, *this);
  37564. }
  37565. void Label::mouseUp (const MouseEvent& e)
  37566. {
  37567. if (editSingleClick
  37568. && e.mouseWasClicked()
  37569. && contains (e.x, e.y)
  37570. && ! e.mods.isPopupMenu())
  37571. {
  37572. showEditor();
  37573. }
  37574. }
  37575. void Label::mouseDoubleClick (const MouseEvent& e)
  37576. {
  37577. if (editDoubleClick && ! e.mods.isPopupMenu())
  37578. showEditor();
  37579. }
  37580. void Label::resized()
  37581. {
  37582. if (editor != 0)
  37583. editor->setBoundsInset (BorderSize (0));
  37584. }
  37585. void Label::focusGained (FocusChangeType cause)
  37586. {
  37587. if (editSingleClick && cause == focusChangedByTabKey)
  37588. showEditor();
  37589. }
  37590. void Label::enablementChanged()
  37591. {
  37592. repaint();
  37593. }
  37594. void Label::colourChanged()
  37595. {
  37596. repaint();
  37597. }
  37598. void Label::setMinimumHorizontalScale (const float newScale)
  37599. {
  37600. if (minimumHorizontalScale != newScale)
  37601. {
  37602. minimumHorizontalScale = newScale;
  37603. repaint();
  37604. }
  37605. }
  37606. // We'll use a custom focus traverser here to make sure focus goes from the
  37607. // text editor to another component rather than back to the label itself.
  37608. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  37609. {
  37610. public:
  37611. LabelKeyboardFocusTraverser() {}
  37612. Component* getNextComponent (Component* current)
  37613. {
  37614. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  37615. ? current->getParentComponent() : current);
  37616. }
  37617. Component* getPreviousComponent (Component* current)
  37618. {
  37619. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  37620. ? current->getParentComponent() : current);
  37621. }
  37622. };
  37623. KeyboardFocusTraverser* Label::createFocusTraverser()
  37624. {
  37625. return new LabelKeyboardFocusTraverser();
  37626. }
  37627. void Label::addListener (LabelListener* const listener) throw()
  37628. {
  37629. listeners.add (listener);
  37630. }
  37631. void Label::removeListener (LabelListener* const listener) throw()
  37632. {
  37633. listeners.remove (listener);
  37634. }
  37635. void Label::callChangeListeners()
  37636. {
  37637. Component::BailOutChecker checker (this);
  37638. listeners.callChecked (checker, &LabelListener::labelTextChanged, this);
  37639. }
  37640. void Label::textEditorTextChanged (TextEditor& ed)
  37641. {
  37642. if (editor != 0)
  37643. {
  37644. jassert (&ed == editor);
  37645. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  37646. {
  37647. if (lossOfFocusDiscardsChanges)
  37648. textEditorEscapeKeyPressed (ed);
  37649. else
  37650. textEditorReturnKeyPressed (ed);
  37651. }
  37652. }
  37653. }
  37654. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  37655. {
  37656. if (editor != 0)
  37657. {
  37658. jassert (&ed == editor);
  37659. (void) ed;
  37660. const bool changed = updateFromTextEditorContents();
  37661. hideEditor (true);
  37662. if (changed)
  37663. {
  37664. Component::SafePointer<Component> deletionChecker (this);
  37665. textWasEdited();
  37666. if (deletionChecker != 0)
  37667. callChangeListeners();
  37668. }
  37669. }
  37670. }
  37671. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  37672. {
  37673. if (editor != 0)
  37674. {
  37675. jassert (&ed == editor);
  37676. (void) ed;
  37677. editor->setText (textValue.toString(), false);
  37678. hideEditor (true);
  37679. }
  37680. }
  37681. void Label::textEditorFocusLost (TextEditor& ed)
  37682. {
  37683. textEditorTextChanged (ed);
  37684. }
  37685. END_JUCE_NAMESPACE
  37686. /*** End of inlined file: juce_Label.cpp ***/
  37687. /*** Start of inlined file: juce_ListBox.cpp ***/
  37688. BEGIN_JUCE_NAMESPACE
  37689. class ListBoxRowComponent : public Component,
  37690. public TooltipClient
  37691. {
  37692. public:
  37693. ListBoxRowComponent (ListBox& owner_)
  37694. : owner (owner_),
  37695. row (-1),
  37696. selected (false),
  37697. isDragging (false)
  37698. {
  37699. }
  37700. ~ListBoxRowComponent()
  37701. {
  37702. deleteAllChildren();
  37703. }
  37704. void paint (Graphics& g)
  37705. {
  37706. if (owner.getModel() != 0)
  37707. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  37708. }
  37709. void update (const int row_, const bool selected_)
  37710. {
  37711. if (row != row_ || selected != selected_)
  37712. {
  37713. repaint();
  37714. row = row_;
  37715. selected = selected_;
  37716. }
  37717. if (owner.getModel() != 0)
  37718. {
  37719. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  37720. if (customComp != 0)
  37721. {
  37722. addAndMakeVisible (customComp);
  37723. customComp->setBounds (0, 0, getWidth(), getHeight());
  37724. for (int i = getNumChildComponents(); --i >= 0;)
  37725. if (getChildComponent (i) != customComp)
  37726. delete getChildComponent (i);
  37727. }
  37728. else
  37729. {
  37730. deleteAllChildren();
  37731. }
  37732. }
  37733. }
  37734. void mouseDown (const MouseEvent& e)
  37735. {
  37736. isDragging = false;
  37737. selectRowOnMouseUp = false;
  37738. if (isEnabled())
  37739. {
  37740. if (! selected)
  37741. {
  37742. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37743. if (owner.getModel() != 0)
  37744. owner.getModel()->listBoxItemClicked (row, e);
  37745. }
  37746. else
  37747. {
  37748. selectRowOnMouseUp = true;
  37749. }
  37750. }
  37751. }
  37752. void mouseUp (const MouseEvent& e)
  37753. {
  37754. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  37755. {
  37756. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  37757. if (owner.getModel() != 0)
  37758. owner.getModel()->listBoxItemClicked (row, e);
  37759. }
  37760. }
  37761. void mouseDoubleClick (const MouseEvent& e)
  37762. {
  37763. if (owner.getModel() != 0 && isEnabled())
  37764. owner.getModel()->listBoxItemDoubleClicked (row, e);
  37765. }
  37766. void mouseDrag (const MouseEvent& e)
  37767. {
  37768. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  37769. {
  37770. const SparseSet <int> selectedRows (owner.getSelectedRows());
  37771. if (selectedRows.size() > 0)
  37772. {
  37773. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  37774. if (dragDescription.isNotEmpty())
  37775. {
  37776. isDragging = true;
  37777. owner.startDragAndDrop (e, dragDescription);
  37778. }
  37779. }
  37780. }
  37781. }
  37782. void resized()
  37783. {
  37784. if (getNumChildComponents() > 0)
  37785. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  37786. }
  37787. const String getTooltip()
  37788. {
  37789. if (owner.getModel() != 0)
  37790. return owner.getModel()->getTooltipForRow (row);
  37791. return String::empty;
  37792. }
  37793. juce_UseDebuggingNewOperator
  37794. bool neededFlag;
  37795. private:
  37796. ListBox& owner;
  37797. int row;
  37798. bool selected, isDragging, selectRowOnMouseUp;
  37799. ListBoxRowComponent (const ListBoxRowComponent&);
  37800. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  37801. };
  37802. class ListViewport : public Viewport
  37803. {
  37804. public:
  37805. int firstIndex, firstWholeIndex, lastWholeIndex;
  37806. bool hasUpdated;
  37807. ListViewport (ListBox& owner_)
  37808. : owner (owner_)
  37809. {
  37810. setWantsKeyboardFocus (false);
  37811. setViewedComponent (new Component());
  37812. getViewedComponent()->addMouseListener (this, false);
  37813. getViewedComponent()->setWantsKeyboardFocus (false);
  37814. }
  37815. ~ListViewport()
  37816. {
  37817. getViewedComponent()->removeMouseListener (this);
  37818. getViewedComponent()->deleteAllChildren();
  37819. }
  37820. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  37821. {
  37822. return static_cast <ListBoxRowComponent*>
  37823. (getViewedComponent()->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents())));
  37824. }
  37825. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  37826. {
  37827. const int index = getIndexOfChildComponent (rowComponent);
  37828. const int num = getViewedComponent()->getNumChildComponents();
  37829. for (int i = num; --i >= 0;)
  37830. if (((firstIndex + i) % jmax (1, num)) == index)
  37831. return firstIndex + i;
  37832. return -1;
  37833. }
  37834. Component* getComponentForRowIfOnscreen (const int row) const throw()
  37835. {
  37836. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  37837. ? getComponentForRow (row) : 0;
  37838. }
  37839. void visibleAreaChanged (int, int, int, int)
  37840. {
  37841. updateVisibleArea (true);
  37842. if (owner.getModel() != 0)
  37843. owner.getModel()->listWasScrolled();
  37844. }
  37845. void updateVisibleArea (const bool makeSureItUpdatesContent)
  37846. {
  37847. hasUpdated = false;
  37848. const int newX = getViewedComponent()->getX();
  37849. int newY = getViewedComponent()->getY();
  37850. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  37851. const int newH = owner.totalItems * owner.getRowHeight();
  37852. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  37853. newY = getMaximumVisibleHeight() - newH;
  37854. getViewedComponent()->setBounds (newX, newY, newW, newH);
  37855. if (makeSureItUpdatesContent && ! hasUpdated)
  37856. updateContents();
  37857. }
  37858. void updateContents()
  37859. {
  37860. hasUpdated = true;
  37861. const int rowHeight = owner.getRowHeight();
  37862. if (rowHeight > 0)
  37863. {
  37864. const int y = getViewPositionY();
  37865. const int w = getViewedComponent()->getWidth();
  37866. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  37867. while (numNeeded > getViewedComponent()->getNumChildComponents())
  37868. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  37869. jassert (numNeeded >= 0);
  37870. while (numNeeded < getViewedComponent()->getNumChildComponents())
  37871. {
  37872. Component* const rowToRemove
  37873. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  37874. delete rowToRemove;
  37875. }
  37876. firstIndex = y / rowHeight;
  37877. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  37878. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  37879. for (int i = 0; i < numNeeded; ++i)
  37880. {
  37881. const int row = i + firstIndex;
  37882. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  37883. if (rowComp != 0)
  37884. {
  37885. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  37886. rowComp->update (row, owner.isRowSelected (row));
  37887. }
  37888. }
  37889. }
  37890. if (owner.headerComponent != 0)
  37891. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  37892. owner.outlineThickness,
  37893. jmax (owner.getWidth() - owner.outlineThickness * 2,
  37894. getViewedComponent()->getWidth()),
  37895. owner.headerComponent->getHeight());
  37896. }
  37897. void paint (Graphics& g)
  37898. {
  37899. if (isOpaque())
  37900. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  37901. }
  37902. bool keyPressed (const KeyPress& key)
  37903. {
  37904. if (key.isKeyCode (KeyPress::upKey)
  37905. || key.isKeyCode (KeyPress::downKey)
  37906. || key.isKeyCode (KeyPress::pageUpKey)
  37907. || key.isKeyCode (KeyPress::pageDownKey)
  37908. || key.isKeyCode (KeyPress::homeKey)
  37909. || key.isKeyCode (KeyPress::endKey))
  37910. {
  37911. // we want to avoid these keypresses going to the viewport, and instead allow
  37912. // them to pass up to our listbox..
  37913. return false;
  37914. }
  37915. return Viewport::keyPressed (key);
  37916. }
  37917. juce_UseDebuggingNewOperator
  37918. private:
  37919. ListBox& owner;
  37920. ListViewport (const ListViewport&);
  37921. ListViewport& operator= (const ListViewport&);
  37922. };
  37923. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  37924. : Component (name),
  37925. model (model_),
  37926. headerComponent (0),
  37927. totalItems (0),
  37928. rowHeight (22),
  37929. minimumRowWidth (0),
  37930. outlineThickness (0),
  37931. lastRowSelected (-1),
  37932. mouseMoveSelects (false),
  37933. multipleSelection (false),
  37934. hasDoneInitialUpdate (false)
  37935. {
  37936. addAndMakeVisible (viewport = new ListViewport (*this));
  37937. setWantsKeyboardFocus (true);
  37938. colourChanged();
  37939. }
  37940. ListBox::~ListBox()
  37941. {
  37942. deleteAllChildren();
  37943. }
  37944. void ListBox::setModel (ListBoxModel* const newModel)
  37945. {
  37946. if (model != newModel)
  37947. {
  37948. model = newModel;
  37949. updateContent();
  37950. }
  37951. }
  37952. void ListBox::setMultipleSelectionEnabled (bool b)
  37953. {
  37954. multipleSelection = b;
  37955. }
  37956. void ListBox::setMouseMoveSelectsRows (bool b)
  37957. {
  37958. mouseMoveSelects = b;
  37959. if (b)
  37960. addMouseListener (this, true);
  37961. }
  37962. void ListBox::paint (Graphics& g)
  37963. {
  37964. if (! hasDoneInitialUpdate)
  37965. updateContent();
  37966. g.fillAll (findColour (backgroundColourId));
  37967. }
  37968. void ListBox::paintOverChildren (Graphics& g)
  37969. {
  37970. if (outlineThickness > 0)
  37971. {
  37972. g.setColour (findColour (outlineColourId));
  37973. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  37974. }
  37975. }
  37976. void ListBox::resized()
  37977. {
  37978. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  37979. outlineThickness,
  37980. outlineThickness,
  37981. outlineThickness));
  37982. viewport->setSingleStepSizes (20, getRowHeight());
  37983. viewport->updateVisibleArea (false);
  37984. }
  37985. void ListBox::visibilityChanged()
  37986. {
  37987. viewport->updateVisibleArea (true);
  37988. }
  37989. Viewport* ListBox::getViewport() const throw()
  37990. {
  37991. return viewport;
  37992. }
  37993. void ListBox::updateContent()
  37994. {
  37995. hasDoneInitialUpdate = true;
  37996. totalItems = (model != 0) ? model->getNumRows() : 0;
  37997. bool selectionChanged = false;
  37998. if (selected [selected.size() - 1] >= totalItems)
  37999. {
  38000. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38001. lastRowSelected = getSelectedRow (0);
  38002. selectionChanged = true;
  38003. }
  38004. viewport->updateVisibleArea (isVisible());
  38005. viewport->resized();
  38006. if (selectionChanged && model != 0)
  38007. model->selectedRowsChanged (lastRowSelected);
  38008. }
  38009. void ListBox::selectRow (const int row,
  38010. bool dontScroll,
  38011. bool deselectOthersFirst)
  38012. {
  38013. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38014. }
  38015. void ListBox::selectRowInternal (const int row,
  38016. bool dontScroll,
  38017. bool deselectOthersFirst,
  38018. bool isMouseClick)
  38019. {
  38020. if (! multipleSelection)
  38021. deselectOthersFirst = true;
  38022. if ((! isRowSelected (row))
  38023. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38024. {
  38025. if (((unsigned int) row) < (unsigned int) totalItems)
  38026. {
  38027. if (deselectOthersFirst)
  38028. selected.clear();
  38029. selected.addRange (row, 1);
  38030. if (getHeight() == 0 || getWidth() == 0)
  38031. dontScroll = true;
  38032. viewport->hasUpdated = false;
  38033. if (row < viewport->firstWholeIndex && ! dontScroll)
  38034. {
  38035. viewport->setViewPosition (viewport->getViewPositionX(),
  38036. row * getRowHeight());
  38037. }
  38038. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38039. {
  38040. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38041. if (row >= lastRowSelected + rowsOnScreen
  38042. && rowsOnScreen < totalItems - 1
  38043. && ! isMouseClick)
  38044. {
  38045. viewport->setViewPosition (viewport->getViewPositionX(),
  38046. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38047. * getRowHeight());
  38048. }
  38049. else
  38050. {
  38051. viewport->setViewPosition (viewport->getViewPositionX(),
  38052. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38053. }
  38054. }
  38055. if (! viewport->hasUpdated)
  38056. viewport->updateContents();
  38057. lastRowSelected = row;
  38058. model->selectedRowsChanged (row);
  38059. }
  38060. else
  38061. {
  38062. if (deselectOthersFirst)
  38063. deselectAllRows();
  38064. }
  38065. }
  38066. }
  38067. void ListBox::deselectRow (const int row)
  38068. {
  38069. if (selected.contains (row))
  38070. {
  38071. selected.removeRange (row, 1);
  38072. if (row == lastRowSelected)
  38073. lastRowSelected = getSelectedRow (0);
  38074. viewport->updateContents();
  38075. model->selectedRowsChanged (lastRowSelected);
  38076. }
  38077. }
  38078. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38079. const bool sendNotificationEventToModel)
  38080. {
  38081. selected = setOfRowsToBeSelected;
  38082. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38083. if (! isRowSelected (lastRowSelected))
  38084. lastRowSelected = getSelectedRow (0);
  38085. viewport->updateContents();
  38086. if ((model != 0) && sendNotificationEventToModel)
  38087. model->selectedRowsChanged (lastRowSelected);
  38088. }
  38089. const SparseSet<int> ListBox::getSelectedRows() const
  38090. {
  38091. return selected;
  38092. }
  38093. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38094. {
  38095. if (multipleSelection && (firstRow != lastRow))
  38096. {
  38097. const int numRows = totalItems - 1;
  38098. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38099. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38100. selected.addRange (jmin (firstRow, lastRow),
  38101. abs (firstRow - lastRow) + 1);
  38102. selected.removeRange (lastRow, 1);
  38103. }
  38104. selectRowInternal (lastRow, false, false, true);
  38105. }
  38106. void ListBox::flipRowSelection (const int row)
  38107. {
  38108. if (isRowSelected (row))
  38109. deselectRow (row);
  38110. else
  38111. selectRowInternal (row, false, false, true);
  38112. }
  38113. void ListBox::deselectAllRows()
  38114. {
  38115. if (! selected.isEmpty())
  38116. {
  38117. selected.clear();
  38118. lastRowSelected = -1;
  38119. viewport->updateContents();
  38120. if (model != 0)
  38121. model->selectedRowsChanged (lastRowSelected);
  38122. }
  38123. }
  38124. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38125. const ModifierKeys& mods)
  38126. {
  38127. if (multipleSelection && mods.isCommandDown())
  38128. {
  38129. flipRowSelection (row);
  38130. }
  38131. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38132. {
  38133. selectRangeOfRows (lastRowSelected, row);
  38134. }
  38135. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38136. {
  38137. selectRowInternal (row, false, true, true);
  38138. }
  38139. }
  38140. int ListBox::getNumSelectedRows() const
  38141. {
  38142. return selected.size();
  38143. }
  38144. int ListBox::getSelectedRow (const int index) const
  38145. {
  38146. return (((unsigned int) index) < (unsigned int) selected.size())
  38147. ? selected [index] : -1;
  38148. }
  38149. bool ListBox::isRowSelected (const int row) const
  38150. {
  38151. return selected.contains (row);
  38152. }
  38153. int ListBox::getLastRowSelected() const
  38154. {
  38155. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38156. }
  38157. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38158. {
  38159. if (((unsigned int) x) < (unsigned int) getWidth())
  38160. {
  38161. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38162. if (((unsigned int) row) < (unsigned int) totalItems)
  38163. return row;
  38164. }
  38165. return -1;
  38166. }
  38167. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38168. {
  38169. if (((unsigned int) x) < (unsigned int) getWidth())
  38170. {
  38171. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38172. return jlimit (0, totalItems, row);
  38173. }
  38174. return -1;
  38175. }
  38176. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38177. {
  38178. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38179. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38180. }
  38181. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38182. {
  38183. return viewport->getRowNumberOfComponent (rowComponent);
  38184. }
  38185. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38186. const bool relativeToComponentTopLeft) const throw()
  38187. {
  38188. const int rowHeight = getRowHeight();
  38189. int y = viewport->getY() + rowHeight * rowNumber;
  38190. if (relativeToComponentTopLeft)
  38191. y -= viewport->getViewPositionY();
  38192. return Rectangle<int> (viewport->getX(), y,
  38193. viewport->getViewedComponent()->getWidth(), rowHeight);
  38194. }
  38195. void ListBox::setVerticalPosition (const double proportion)
  38196. {
  38197. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38198. viewport->setViewPosition (viewport->getViewPositionX(),
  38199. jmax (0, roundToInt (proportion * offscreen)));
  38200. }
  38201. double ListBox::getVerticalPosition() const
  38202. {
  38203. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38204. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38205. : 0;
  38206. }
  38207. int ListBox::getVisibleRowWidth() const throw()
  38208. {
  38209. return viewport->getViewWidth();
  38210. }
  38211. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38212. {
  38213. if (row < viewport->firstWholeIndex)
  38214. {
  38215. viewport->setViewPosition (viewport->getViewPositionX(),
  38216. row * getRowHeight());
  38217. }
  38218. else if (row >= viewport->lastWholeIndex)
  38219. {
  38220. viewport->setViewPosition (viewport->getViewPositionX(),
  38221. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38222. }
  38223. }
  38224. bool ListBox::keyPressed (const KeyPress& key)
  38225. {
  38226. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38227. const bool multiple = multipleSelection
  38228. && (lastRowSelected >= 0)
  38229. && (key.getModifiers().isShiftDown()
  38230. || key.getModifiers().isCtrlDown()
  38231. || key.getModifiers().isCommandDown());
  38232. if (key.isKeyCode (KeyPress::upKey))
  38233. {
  38234. if (multiple)
  38235. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38236. else
  38237. selectRow (jmax (0, lastRowSelected - 1));
  38238. }
  38239. else if (key.isKeyCode (KeyPress::returnKey)
  38240. && isRowSelected (lastRowSelected))
  38241. {
  38242. if (model != 0)
  38243. model->returnKeyPressed (lastRowSelected);
  38244. }
  38245. else if (key.isKeyCode (KeyPress::pageUpKey))
  38246. {
  38247. if (multiple)
  38248. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38249. else
  38250. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38251. }
  38252. else if (key.isKeyCode (KeyPress::pageDownKey))
  38253. {
  38254. if (multiple)
  38255. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38256. else
  38257. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38258. }
  38259. else if (key.isKeyCode (KeyPress::homeKey))
  38260. {
  38261. if (multiple && key.getModifiers().isShiftDown())
  38262. selectRangeOfRows (lastRowSelected, 0);
  38263. else
  38264. selectRow (0);
  38265. }
  38266. else if (key.isKeyCode (KeyPress::endKey))
  38267. {
  38268. if (multiple && key.getModifiers().isShiftDown())
  38269. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38270. else
  38271. selectRow (totalItems - 1);
  38272. }
  38273. else if (key.isKeyCode (KeyPress::downKey))
  38274. {
  38275. if (multiple)
  38276. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38277. else
  38278. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38279. }
  38280. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38281. && isRowSelected (lastRowSelected))
  38282. {
  38283. if (model != 0)
  38284. model->deleteKeyPressed (lastRowSelected);
  38285. }
  38286. else if (multiple && key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  38287. {
  38288. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38289. }
  38290. else
  38291. {
  38292. return false;
  38293. }
  38294. return true;
  38295. }
  38296. bool ListBox::keyStateChanged (const bool isKeyDown)
  38297. {
  38298. return isKeyDown
  38299. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38300. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38301. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38302. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38303. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38304. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38305. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38306. }
  38307. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38308. {
  38309. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38310. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38311. }
  38312. void ListBox::mouseMove (const MouseEvent& e)
  38313. {
  38314. if (mouseMoveSelects)
  38315. {
  38316. const MouseEvent e2 (e.getEventRelativeTo (this));
  38317. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38318. }
  38319. }
  38320. void ListBox::mouseExit (const MouseEvent& e)
  38321. {
  38322. mouseMove (e);
  38323. }
  38324. void ListBox::mouseUp (const MouseEvent& e)
  38325. {
  38326. if (e.mouseWasClicked() && model != 0)
  38327. model->backgroundClicked();
  38328. }
  38329. void ListBox::setRowHeight (const int newHeight)
  38330. {
  38331. rowHeight = jmax (1, newHeight);
  38332. viewport->setSingleStepSizes (20, rowHeight);
  38333. updateContent();
  38334. }
  38335. int ListBox::getNumRowsOnScreen() const throw()
  38336. {
  38337. return viewport->getMaximumVisibleHeight() / rowHeight;
  38338. }
  38339. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38340. {
  38341. minimumRowWidth = newMinimumWidth;
  38342. updateContent();
  38343. }
  38344. int ListBox::getVisibleContentWidth() const throw()
  38345. {
  38346. return viewport->getMaximumVisibleWidth();
  38347. }
  38348. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38349. {
  38350. return viewport->getVerticalScrollBar();
  38351. }
  38352. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38353. {
  38354. return viewport->getHorizontalScrollBar();
  38355. }
  38356. void ListBox::colourChanged()
  38357. {
  38358. setOpaque (findColour (backgroundColourId).isOpaque());
  38359. viewport->setOpaque (isOpaque());
  38360. repaint();
  38361. }
  38362. void ListBox::setOutlineThickness (const int outlineThickness_)
  38363. {
  38364. outlineThickness = outlineThickness_;
  38365. resized();
  38366. }
  38367. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38368. {
  38369. if (headerComponent != newHeaderComponent)
  38370. {
  38371. delete headerComponent;
  38372. headerComponent = newHeaderComponent;
  38373. addAndMakeVisible (newHeaderComponent);
  38374. ListBox::resized();
  38375. }
  38376. }
  38377. void ListBox::repaintRow (const int rowNumber) throw()
  38378. {
  38379. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38380. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38381. }
  38382. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38383. {
  38384. Rectangle<int> imageArea;
  38385. const int firstRow = getRowContainingPosition (0, 0);
  38386. int i;
  38387. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38388. {
  38389. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38390. if (rowComp != 0 && isRowSelected (firstRow + i))
  38391. {
  38392. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38393. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38394. if (imageArea.isEmpty())
  38395. imageArea = rowRect;
  38396. else
  38397. imageArea = imageArea.getUnion (rowRect);
  38398. }
  38399. }
  38400. imageArea = imageArea.getIntersection (getLocalBounds());
  38401. imageX = imageArea.getX();
  38402. imageY = imageArea.getY();
  38403. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38404. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38405. {
  38406. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38407. if (rowComp != 0 && isRowSelected (firstRow + i))
  38408. {
  38409. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38410. Graphics g (*snapshot);
  38411. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38412. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38413. rowComp->paintEntireComponent (g);
  38414. }
  38415. }
  38416. return snapshot;
  38417. }
  38418. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38419. {
  38420. DragAndDropContainer* const dragContainer
  38421. = DragAndDropContainer::findParentDragContainerFor (this);
  38422. if (dragContainer != 0)
  38423. {
  38424. int x, y;
  38425. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38426. dragImage->multiplyAllAlphas (0.6f);
  38427. MouseEvent e2 (e.getEventRelativeTo (this));
  38428. const Point<int> p (x - e2.x, y - e2.y);
  38429. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  38430. }
  38431. else
  38432. {
  38433. // to be able to do a drag-and-drop operation, the listbox needs to
  38434. // be inside a component which is also a DragAndDropContainer.
  38435. jassertfalse
  38436. }
  38437. }
  38438. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  38439. {
  38440. (void) existingComponentToUpdate;
  38441. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  38442. return 0;
  38443. }
  38444. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  38445. {
  38446. }
  38447. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  38448. {
  38449. }
  38450. void ListBoxModel::backgroundClicked()
  38451. {
  38452. }
  38453. void ListBoxModel::selectedRowsChanged (int)
  38454. {
  38455. }
  38456. void ListBoxModel::deleteKeyPressed (int)
  38457. {
  38458. }
  38459. void ListBoxModel::returnKeyPressed (int)
  38460. {
  38461. }
  38462. void ListBoxModel::listWasScrolled()
  38463. {
  38464. }
  38465. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  38466. {
  38467. return String::empty;
  38468. }
  38469. const String ListBoxModel::getTooltipForRow (int)
  38470. {
  38471. return String::empty;
  38472. }
  38473. END_JUCE_NAMESPACE
  38474. /*** End of inlined file: juce_ListBox.cpp ***/
  38475. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  38476. BEGIN_JUCE_NAMESPACE
  38477. ProgressBar::ProgressBar (double& progress_)
  38478. : progress (progress_),
  38479. displayPercentage (true),
  38480. lastCallbackTime (0)
  38481. {
  38482. currentValue = jlimit (0.0, 1.0, progress);
  38483. }
  38484. ProgressBar::~ProgressBar()
  38485. {
  38486. }
  38487. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  38488. {
  38489. displayPercentage = shouldDisplayPercentage;
  38490. repaint();
  38491. }
  38492. void ProgressBar::setTextToDisplay (const String& text)
  38493. {
  38494. displayPercentage = false;
  38495. displayedMessage = text;
  38496. }
  38497. void ProgressBar::lookAndFeelChanged()
  38498. {
  38499. setOpaque (findColour (backgroundColourId).isOpaque());
  38500. }
  38501. void ProgressBar::colourChanged()
  38502. {
  38503. lookAndFeelChanged();
  38504. }
  38505. void ProgressBar::paint (Graphics& g)
  38506. {
  38507. String text;
  38508. if (displayPercentage)
  38509. {
  38510. if (currentValue >= 0 && currentValue <= 1.0)
  38511. text << roundToInt (currentValue * 100.0) << '%';
  38512. }
  38513. else
  38514. {
  38515. text = displayedMessage;
  38516. }
  38517. getLookAndFeel().drawProgressBar (g, *this,
  38518. getWidth(), getHeight(),
  38519. currentValue, text);
  38520. }
  38521. void ProgressBar::visibilityChanged()
  38522. {
  38523. if (isVisible())
  38524. startTimer (30);
  38525. else
  38526. stopTimer();
  38527. }
  38528. void ProgressBar::timerCallback()
  38529. {
  38530. double newProgress = progress;
  38531. const uint32 now = Time::getMillisecondCounter();
  38532. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  38533. lastCallbackTime = now;
  38534. if (currentValue != newProgress
  38535. || newProgress < 0 || newProgress >= 1.0
  38536. || currentMessage != displayedMessage)
  38537. {
  38538. if (currentValue < newProgress
  38539. && newProgress >= 0 && newProgress < 1.0
  38540. && currentValue >= 0 && currentValue < 1.0)
  38541. {
  38542. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  38543. newProgress);
  38544. }
  38545. currentValue = newProgress;
  38546. currentMessage = displayedMessage;
  38547. repaint();
  38548. }
  38549. }
  38550. END_JUCE_NAMESPACE
  38551. /*** End of inlined file: juce_ProgressBar.cpp ***/
  38552. /*** Start of inlined file: juce_Slider.cpp ***/
  38553. BEGIN_JUCE_NAMESPACE
  38554. class SliderPopupDisplayComponent : public BubbleComponent
  38555. {
  38556. public:
  38557. SliderPopupDisplayComponent (Slider* const owner_)
  38558. : owner (owner_),
  38559. font (15.0f, Font::bold)
  38560. {
  38561. setAlwaysOnTop (true);
  38562. }
  38563. ~SliderPopupDisplayComponent()
  38564. {
  38565. }
  38566. void paintContent (Graphics& g, int w, int h)
  38567. {
  38568. g.setFont (font);
  38569. g.setColour (Colours::black);
  38570. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  38571. }
  38572. void getContentSize (int& w, int& h)
  38573. {
  38574. w = font.getStringWidth (text) + 18;
  38575. h = (int) (font.getHeight() * 1.6f);
  38576. }
  38577. void updatePosition (const String& newText)
  38578. {
  38579. if (text != newText)
  38580. {
  38581. text = newText;
  38582. repaint();
  38583. }
  38584. BubbleComponent::setPosition (owner);
  38585. }
  38586. juce_UseDebuggingNewOperator
  38587. private:
  38588. Slider* owner;
  38589. Font font;
  38590. String text;
  38591. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  38592. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  38593. };
  38594. Slider::Slider (const String& name)
  38595. : Component (name),
  38596. lastCurrentValue (0),
  38597. lastValueMin (0),
  38598. lastValueMax (0),
  38599. minimum (0),
  38600. maximum (10),
  38601. interval (0),
  38602. skewFactor (1.0),
  38603. velocityModeSensitivity (1.0),
  38604. velocityModeOffset (0.0),
  38605. velocityModeThreshold (1),
  38606. rotaryStart (float_Pi * 1.2f),
  38607. rotaryEnd (float_Pi * 2.8f),
  38608. numDecimalPlaces (7),
  38609. sliderRegionStart (0),
  38610. sliderRegionSize (1),
  38611. sliderBeingDragged (-1),
  38612. pixelsForFullDragExtent (250),
  38613. style (LinearHorizontal),
  38614. textBoxPos (TextBoxLeft),
  38615. textBoxWidth (80),
  38616. textBoxHeight (20),
  38617. incDecButtonMode (incDecButtonsNotDraggable),
  38618. editableText (true),
  38619. doubleClickToValue (false),
  38620. isVelocityBased (false),
  38621. userKeyOverridesVelocity (true),
  38622. rotaryStop (true),
  38623. incDecButtonsSideBySide (false),
  38624. sendChangeOnlyOnRelease (false),
  38625. popupDisplayEnabled (false),
  38626. menuEnabled (false),
  38627. menuShown (false),
  38628. scrollWheelEnabled (true),
  38629. snapsToMousePos (true),
  38630. valueBox (0),
  38631. incButton (0),
  38632. decButton (0),
  38633. popupDisplay (0),
  38634. parentForPopupDisplay (0)
  38635. {
  38636. setWantsKeyboardFocus (false);
  38637. setRepaintsOnMouseActivity (true);
  38638. lookAndFeelChanged();
  38639. updateText();
  38640. currentValue.addListener (this);
  38641. valueMin.addListener (this);
  38642. valueMax.addListener (this);
  38643. }
  38644. Slider::~Slider()
  38645. {
  38646. currentValue.removeListener (this);
  38647. valueMin.removeListener (this);
  38648. valueMax.removeListener (this);
  38649. popupDisplay = 0;
  38650. deleteAllChildren();
  38651. }
  38652. void Slider::handleAsyncUpdate()
  38653. {
  38654. cancelPendingUpdate();
  38655. Component::BailOutChecker checker (this);
  38656. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this);
  38657. }
  38658. void Slider::sendDragStart()
  38659. {
  38660. startedDragging();
  38661. Component::BailOutChecker checker (this);
  38662. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  38663. }
  38664. void Slider::sendDragEnd()
  38665. {
  38666. stoppedDragging();
  38667. sliderBeingDragged = -1;
  38668. Component::BailOutChecker checker (this);
  38669. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  38670. }
  38671. void Slider::addListener (SliderListener* const listener)
  38672. {
  38673. listeners.add (listener);
  38674. }
  38675. void Slider::removeListener (SliderListener* const listener)
  38676. {
  38677. listeners.remove (listener);
  38678. }
  38679. void Slider::setSliderStyle (const SliderStyle newStyle)
  38680. {
  38681. if (style != newStyle)
  38682. {
  38683. style = newStyle;
  38684. repaint();
  38685. lookAndFeelChanged();
  38686. }
  38687. }
  38688. void Slider::setRotaryParameters (const float startAngleRadians,
  38689. const float endAngleRadians,
  38690. const bool stopAtEnd)
  38691. {
  38692. // make sure the values are sensible..
  38693. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  38694. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  38695. jassert (rotaryStart < rotaryEnd);
  38696. rotaryStart = startAngleRadians;
  38697. rotaryEnd = endAngleRadians;
  38698. rotaryStop = stopAtEnd;
  38699. }
  38700. void Slider::setVelocityBasedMode (const bool velBased)
  38701. {
  38702. isVelocityBased = velBased;
  38703. }
  38704. void Slider::setVelocityModeParameters (const double sensitivity,
  38705. const int threshold,
  38706. const double offset,
  38707. const bool userCanPressKeyToSwapMode)
  38708. {
  38709. jassert (threshold >= 0);
  38710. jassert (sensitivity > 0);
  38711. jassert (offset >= 0);
  38712. velocityModeSensitivity = sensitivity;
  38713. velocityModeOffset = offset;
  38714. velocityModeThreshold = threshold;
  38715. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  38716. }
  38717. void Slider::setSkewFactor (const double factor)
  38718. {
  38719. skewFactor = factor;
  38720. }
  38721. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  38722. {
  38723. if (maximum > minimum)
  38724. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  38725. / (maximum - minimum));
  38726. }
  38727. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  38728. {
  38729. jassert (distanceForFullScaleDrag > 0);
  38730. pixelsForFullDragExtent = distanceForFullScaleDrag;
  38731. }
  38732. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  38733. {
  38734. if (incDecButtonMode != mode)
  38735. {
  38736. incDecButtonMode = mode;
  38737. lookAndFeelChanged();
  38738. }
  38739. }
  38740. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  38741. const bool isReadOnly,
  38742. const int textEntryBoxWidth,
  38743. const int textEntryBoxHeight)
  38744. {
  38745. textBoxPos = newPosition;
  38746. editableText = ! isReadOnly;
  38747. textBoxWidth = textEntryBoxWidth;
  38748. textBoxHeight = textEntryBoxHeight;
  38749. repaint();
  38750. lookAndFeelChanged();
  38751. }
  38752. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  38753. {
  38754. editableText = shouldBeEditable;
  38755. if (valueBox != 0)
  38756. valueBox->setEditable (shouldBeEditable && isEnabled());
  38757. }
  38758. void Slider::showTextBox()
  38759. {
  38760. jassert (editableText); // this should probably be avoided in read-only sliders.
  38761. if (valueBox != 0)
  38762. valueBox->showEditor();
  38763. }
  38764. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  38765. {
  38766. if (valueBox != 0)
  38767. {
  38768. valueBox->hideEditor (discardCurrentEditorContents);
  38769. if (discardCurrentEditorContents)
  38770. updateText();
  38771. }
  38772. }
  38773. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  38774. {
  38775. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  38776. }
  38777. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  38778. {
  38779. snapsToMousePos = shouldSnapToMouse;
  38780. }
  38781. void Slider::setPopupDisplayEnabled (const bool enabled,
  38782. Component* const parentComponentToUse)
  38783. {
  38784. popupDisplayEnabled = enabled;
  38785. parentForPopupDisplay = parentComponentToUse;
  38786. }
  38787. void Slider::colourChanged()
  38788. {
  38789. lookAndFeelChanged();
  38790. }
  38791. void Slider::lookAndFeelChanged()
  38792. {
  38793. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  38794. : getTextFromValue (currentValue.getValue()));
  38795. deleteAllChildren();
  38796. valueBox = 0;
  38797. LookAndFeel& lf = getLookAndFeel();
  38798. if (textBoxPos != NoTextBox)
  38799. {
  38800. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  38801. valueBox->setWantsKeyboardFocus (false);
  38802. valueBox->setText (previousTextBoxContent, false);
  38803. valueBox->setEditable (editableText && isEnabled());
  38804. valueBox->addListener (this);
  38805. if (style == LinearBar)
  38806. valueBox->addMouseListener (this, false);
  38807. valueBox->setTooltip (getTooltip());
  38808. }
  38809. if (style == IncDecButtons)
  38810. {
  38811. addAndMakeVisible (incButton = lf.createSliderButton (true));
  38812. incButton->addButtonListener (this);
  38813. addAndMakeVisible (decButton = lf.createSliderButton (false));
  38814. decButton->addButtonListener (this);
  38815. if (incDecButtonMode != incDecButtonsNotDraggable)
  38816. {
  38817. incButton->addMouseListener (this, false);
  38818. decButton->addMouseListener (this, false);
  38819. }
  38820. else
  38821. {
  38822. incButton->setRepeatSpeed (300, 100, 20);
  38823. incButton->addMouseListener (decButton, false);
  38824. decButton->setRepeatSpeed (300, 100, 20);
  38825. decButton->addMouseListener (incButton, false);
  38826. }
  38827. incButton->setTooltip (getTooltip());
  38828. decButton->setTooltip (getTooltip());
  38829. }
  38830. setComponentEffect (lf.getSliderEffect());
  38831. resized();
  38832. repaint();
  38833. }
  38834. void Slider::setRange (const double newMin,
  38835. const double newMax,
  38836. const double newInt)
  38837. {
  38838. if (minimum != newMin
  38839. || maximum != newMax
  38840. || interval != newInt)
  38841. {
  38842. minimum = newMin;
  38843. maximum = newMax;
  38844. interval = newInt;
  38845. // figure out the number of DPs needed to display all values at this
  38846. // interval setting.
  38847. numDecimalPlaces = 7;
  38848. if (newInt != 0)
  38849. {
  38850. int v = abs ((int) (newInt * 10000000));
  38851. while ((v % 10) == 0)
  38852. {
  38853. --numDecimalPlaces;
  38854. v /= 10;
  38855. }
  38856. }
  38857. // keep the current values inside the new range..
  38858. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38859. {
  38860. setValue (getValue(), false, false);
  38861. }
  38862. else
  38863. {
  38864. setMinValue (getMinValue(), false, false);
  38865. setMaxValue (getMaxValue(), false, false);
  38866. }
  38867. updateText();
  38868. }
  38869. }
  38870. void Slider::triggerChangeMessage (const bool synchronous)
  38871. {
  38872. if (synchronous)
  38873. handleAsyncUpdate();
  38874. else
  38875. triggerAsyncUpdate();
  38876. valueChanged();
  38877. }
  38878. void Slider::valueChanged (Value& value)
  38879. {
  38880. if (value.refersToSameSourceAs (currentValue))
  38881. {
  38882. if (style != TwoValueHorizontal && style != TwoValueVertical)
  38883. setValue (currentValue.getValue(), false, false);
  38884. }
  38885. else if (value.refersToSameSourceAs (valueMin))
  38886. setMinValue (valueMin.getValue(), false, false, true);
  38887. else if (value.refersToSameSourceAs (valueMax))
  38888. setMaxValue (valueMax.getValue(), false, false, true);
  38889. }
  38890. double Slider::getValue() const
  38891. {
  38892. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  38893. // methods to get the two values.
  38894. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38895. return currentValue.getValue();
  38896. }
  38897. void Slider::setValue (double newValue,
  38898. const bool sendUpdateMessage,
  38899. const bool sendMessageSynchronously)
  38900. {
  38901. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  38902. // methods to set the two values.
  38903. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  38904. newValue = constrainedValue (newValue);
  38905. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  38906. {
  38907. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  38908. newValue = jlimit ((double) valueMin.getValue(),
  38909. (double) valueMax.getValue(),
  38910. newValue);
  38911. }
  38912. if (newValue != lastCurrentValue)
  38913. {
  38914. if (valueBox != 0)
  38915. valueBox->hideEditor (true);
  38916. lastCurrentValue = newValue;
  38917. currentValue = newValue;
  38918. updateText();
  38919. repaint();
  38920. if (popupDisplay != 0)
  38921. {
  38922. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38923. ->updatePosition (getTextFromValue (newValue));
  38924. popupDisplay->repaint();
  38925. }
  38926. if (sendUpdateMessage)
  38927. triggerChangeMessage (sendMessageSynchronously);
  38928. }
  38929. }
  38930. double Slider::getMinValue() const
  38931. {
  38932. // The minimum value only applies to sliders that are in two- or three-value mode.
  38933. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38934. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38935. return valueMin.getValue();
  38936. }
  38937. double Slider::getMaxValue() const
  38938. {
  38939. // The maximum value only applies to sliders that are in two- or three-value mode.
  38940. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38941. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38942. return valueMax.getValue();
  38943. }
  38944. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38945. {
  38946. // The minimum value only applies to sliders that are in two- or three-value mode.
  38947. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38948. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38949. newValue = constrainedValue (newValue);
  38950. if (style == TwoValueHorizontal || style == TwoValueVertical)
  38951. {
  38952. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  38953. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38954. newValue = jmin ((double) valueMax.getValue(), newValue);
  38955. }
  38956. else
  38957. {
  38958. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  38959. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38960. newValue = jmin (lastCurrentValue, newValue);
  38961. }
  38962. if (lastValueMin != newValue)
  38963. {
  38964. lastValueMin = newValue;
  38965. valueMin = newValue;
  38966. repaint();
  38967. if (popupDisplay != 0)
  38968. {
  38969. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  38970. ->updatePosition (getTextFromValue (newValue));
  38971. popupDisplay->repaint();
  38972. }
  38973. if (sendUpdateMessage)
  38974. triggerChangeMessage (sendMessageSynchronously);
  38975. }
  38976. }
  38977. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  38978. {
  38979. // The maximum value only applies to sliders that are in two- or three-value mode.
  38980. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  38981. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  38982. newValue = constrainedValue (newValue);
  38983. if (style == TwoValueHorizontal || style == TwoValueVertical)
  38984. {
  38985. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  38986. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38987. newValue = jmax ((double) valueMin.getValue(), newValue);
  38988. }
  38989. else
  38990. {
  38991. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  38992. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  38993. newValue = jmax (lastCurrentValue, newValue);
  38994. }
  38995. if (lastValueMax != newValue)
  38996. {
  38997. lastValueMax = newValue;
  38998. valueMax = newValue;
  38999. repaint();
  39000. if (popupDisplay != 0)
  39001. {
  39002. static_cast <SliderPopupDisplayComponent*> (static_cast <Component*> (popupDisplay))
  39003. ->updatePosition (getTextFromValue (valueMax.getValue()));
  39004. popupDisplay->repaint();
  39005. }
  39006. if (sendUpdateMessage)
  39007. triggerChangeMessage (sendMessageSynchronously);
  39008. }
  39009. }
  39010. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39011. const double valueToSetOnDoubleClick)
  39012. {
  39013. doubleClickToValue = isDoubleClickEnabled;
  39014. doubleClickReturnValue = valueToSetOnDoubleClick;
  39015. }
  39016. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39017. {
  39018. isEnabled_ = doubleClickToValue;
  39019. return doubleClickReturnValue;
  39020. }
  39021. void Slider::updateText()
  39022. {
  39023. if (valueBox != 0)
  39024. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39025. }
  39026. void Slider::setTextValueSuffix (const String& suffix)
  39027. {
  39028. if (textSuffix != suffix)
  39029. {
  39030. textSuffix = suffix;
  39031. updateText();
  39032. }
  39033. }
  39034. const String Slider::getTextValueSuffix() const
  39035. {
  39036. return textSuffix;
  39037. }
  39038. const String Slider::getTextFromValue (double v)
  39039. {
  39040. if (getNumDecimalPlacesToDisplay() > 0)
  39041. return String (v, getNumDecimalPlacesToDisplay()) + getTextValueSuffix();
  39042. else
  39043. return String (roundToInt (v)) + getTextValueSuffix();
  39044. }
  39045. double Slider::getValueFromText (const String& text)
  39046. {
  39047. String t (text.trimStart());
  39048. if (t.endsWith (textSuffix))
  39049. t = t.substring (0, t.length() - textSuffix.length());
  39050. while (t.startsWithChar ('+'))
  39051. t = t.substring (1).trimStart();
  39052. return t.initialSectionContainingOnly ("0123456789.,-")
  39053. .getDoubleValue();
  39054. }
  39055. double Slider::proportionOfLengthToValue (double proportion)
  39056. {
  39057. if (skewFactor != 1.0 && proportion > 0.0)
  39058. proportion = exp (log (proportion) / skewFactor);
  39059. return minimum + (maximum - minimum) * proportion;
  39060. }
  39061. double Slider::valueToProportionOfLength (double value)
  39062. {
  39063. const double n = (value - minimum) / (maximum - minimum);
  39064. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39065. }
  39066. double Slider::snapValue (double attemptedValue, const bool)
  39067. {
  39068. return attemptedValue;
  39069. }
  39070. void Slider::startedDragging()
  39071. {
  39072. }
  39073. void Slider::stoppedDragging()
  39074. {
  39075. }
  39076. void Slider::valueChanged()
  39077. {
  39078. }
  39079. void Slider::enablementChanged()
  39080. {
  39081. repaint();
  39082. }
  39083. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39084. {
  39085. menuEnabled = menuEnabled_;
  39086. }
  39087. void Slider::setScrollWheelEnabled (const bool enabled)
  39088. {
  39089. scrollWheelEnabled = enabled;
  39090. }
  39091. void Slider::labelTextChanged (Label* label)
  39092. {
  39093. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39094. if (newValue != (double) currentValue.getValue())
  39095. {
  39096. sendDragStart();
  39097. setValue (newValue, true, true);
  39098. sendDragEnd();
  39099. }
  39100. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39101. }
  39102. void Slider::buttonClicked (Button* button)
  39103. {
  39104. if (style == IncDecButtons)
  39105. {
  39106. sendDragStart();
  39107. if (button == incButton)
  39108. setValue (snapValue (getValue() + interval, false), true, true);
  39109. else if (button == decButton)
  39110. setValue (snapValue (getValue() - interval, false), true, true);
  39111. sendDragEnd();
  39112. }
  39113. }
  39114. double Slider::constrainedValue (double value) const
  39115. {
  39116. if (interval > 0)
  39117. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39118. if (value <= minimum || maximum <= minimum)
  39119. value = minimum;
  39120. else if (value >= maximum)
  39121. value = maximum;
  39122. return value;
  39123. }
  39124. float Slider::getLinearSliderPos (const double value)
  39125. {
  39126. double sliderPosProportional;
  39127. if (maximum > minimum)
  39128. {
  39129. if (value < minimum)
  39130. {
  39131. sliderPosProportional = 0.0;
  39132. }
  39133. else if (value > maximum)
  39134. {
  39135. sliderPosProportional = 1.0;
  39136. }
  39137. else
  39138. {
  39139. sliderPosProportional = valueToProportionOfLength (value);
  39140. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39141. }
  39142. }
  39143. else
  39144. {
  39145. sliderPosProportional = 0.5;
  39146. }
  39147. if (isVertical() || style == IncDecButtons)
  39148. sliderPosProportional = 1.0 - sliderPosProportional;
  39149. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39150. }
  39151. bool Slider::isHorizontal() const
  39152. {
  39153. return style == LinearHorizontal
  39154. || style == LinearBar
  39155. || style == TwoValueHorizontal
  39156. || style == ThreeValueHorizontal;
  39157. }
  39158. bool Slider::isVertical() const
  39159. {
  39160. return style == LinearVertical
  39161. || style == TwoValueVertical
  39162. || style == ThreeValueVertical;
  39163. }
  39164. bool Slider::incDecDragDirectionIsHorizontal() const
  39165. {
  39166. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39167. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39168. }
  39169. float Slider::getPositionOfValue (const double value)
  39170. {
  39171. if (isHorizontal() || isVertical())
  39172. {
  39173. return getLinearSliderPos (value);
  39174. }
  39175. else
  39176. {
  39177. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39178. return 0.0f;
  39179. }
  39180. }
  39181. void Slider::paint (Graphics& g)
  39182. {
  39183. if (style != IncDecButtons)
  39184. {
  39185. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39186. {
  39187. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39188. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39189. getLookAndFeel().drawRotarySlider (g,
  39190. sliderRect.getX(),
  39191. sliderRect.getY(),
  39192. sliderRect.getWidth(),
  39193. sliderRect.getHeight(),
  39194. sliderPos,
  39195. rotaryStart, rotaryEnd,
  39196. *this);
  39197. }
  39198. else
  39199. {
  39200. getLookAndFeel().drawLinearSlider (g,
  39201. sliderRect.getX(),
  39202. sliderRect.getY(),
  39203. sliderRect.getWidth(),
  39204. sliderRect.getHeight(),
  39205. getLinearSliderPos (lastCurrentValue),
  39206. getLinearSliderPos (lastValueMin),
  39207. getLinearSliderPos (lastValueMax),
  39208. style,
  39209. *this);
  39210. }
  39211. if (style == LinearBar && valueBox == 0)
  39212. {
  39213. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39214. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39215. }
  39216. }
  39217. }
  39218. void Slider::resized()
  39219. {
  39220. int minXSpace = 0;
  39221. int minYSpace = 0;
  39222. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39223. minXSpace = 30;
  39224. else
  39225. minYSpace = 15;
  39226. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39227. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39228. if (style == LinearBar)
  39229. {
  39230. if (valueBox != 0)
  39231. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39232. }
  39233. else
  39234. {
  39235. if (textBoxPos == NoTextBox)
  39236. {
  39237. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39238. }
  39239. else if (textBoxPos == TextBoxLeft)
  39240. {
  39241. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39242. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39243. }
  39244. else if (textBoxPos == TextBoxRight)
  39245. {
  39246. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39247. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39248. }
  39249. else if (textBoxPos == TextBoxAbove)
  39250. {
  39251. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39252. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39253. }
  39254. else if (textBoxPos == TextBoxBelow)
  39255. {
  39256. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39257. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39258. }
  39259. }
  39260. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39261. if (style == LinearBar)
  39262. {
  39263. const int barIndent = 1;
  39264. sliderRegionStart = barIndent;
  39265. sliderRegionSize = getWidth() - barIndent * 2;
  39266. sliderRect.setBounds (sliderRegionStart, barIndent,
  39267. sliderRegionSize, getHeight() - barIndent * 2);
  39268. }
  39269. else if (isHorizontal())
  39270. {
  39271. sliderRegionStart = sliderRect.getX() + indent;
  39272. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39273. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39274. sliderRegionSize, sliderRect.getHeight());
  39275. }
  39276. else if (isVertical())
  39277. {
  39278. sliderRegionStart = sliderRect.getY() + indent;
  39279. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39280. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39281. sliderRect.getWidth(), sliderRegionSize);
  39282. }
  39283. else
  39284. {
  39285. sliderRegionStart = 0;
  39286. sliderRegionSize = 100;
  39287. }
  39288. if (style == IncDecButtons)
  39289. {
  39290. Rectangle<int> buttonRect (sliderRect);
  39291. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39292. buttonRect.expand (-2, 0);
  39293. else
  39294. buttonRect.expand (0, -2);
  39295. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39296. if (incDecButtonsSideBySide)
  39297. {
  39298. decButton->setBounds (buttonRect.getX(),
  39299. buttonRect.getY(),
  39300. buttonRect.getWidth() / 2,
  39301. buttonRect.getHeight());
  39302. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39303. incButton->setBounds (buttonRect.getCentreX(),
  39304. buttonRect.getY(),
  39305. buttonRect.getWidth() / 2,
  39306. buttonRect.getHeight());
  39307. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39308. }
  39309. else
  39310. {
  39311. incButton->setBounds (buttonRect.getX(),
  39312. buttonRect.getY(),
  39313. buttonRect.getWidth(),
  39314. buttonRect.getHeight() / 2);
  39315. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39316. decButton->setBounds (buttonRect.getX(),
  39317. buttonRect.getCentreY(),
  39318. buttonRect.getWidth(),
  39319. buttonRect.getHeight() / 2);
  39320. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39321. }
  39322. }
  39323. }
  39324. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39325. {
  39326. repaint();
  39327. }
  39328. void Slider::mouseDown (const MouseEvent& e)
  39329. {
  39330. mouseWasHidden = false;
  39331. incDecDragged = false;
  39332. mouseXWhenLastDragged = e.x;
  39333. mouseYWhenLastDragged = e.y;
  39334. mouseDragStartX = e.getMouseDownX();
  39335. mouseDragStartY = e.getMouseDownY();
  39336. if (isEnabled())
  39337. {
  39338. if (e.mods.isPopupMenu() && menuEnabled)
  39339. {
  39340. menuShown = true;
  39341. PopupMenu m;
  39342. m.setLookAndFeel (&getLookAndFeel());
  39343. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39344. m.addSeparator();
  39345. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39346. {
  39347. PopupMenu rotaryMenu;
  39348. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39349. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39350. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39351. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39352. }
  39353. const int r = m.show();
  39354. if (r == 1)
  39355. {
  39356. setVelocityBasedMode (! isVelocityBased);
  39357. }
  39358. else if (r == 2)
  39359. {
  39360. setSliderStyle (Rotary);
  39361. }
  39362. else if (r == 3)
  39363. {
  39364. setSliderStyle (RotaryHorizontalDrag);
  39365. }
  39366. else if (r == 4)
  39367. {
  39368. setSliderStyle (RotaryVerticalDrag);
  39369. }
  39370. }
  39371. else if (maximum > minimum)
  39372. {
  39373. menuShown = false;
  39374. if (valueBox != 0)
  39375. valueBox->hideEditor (true);
  39376. sliderBeingDragged = 0;
  39377. if (style == TwoValueHorizontal
  39378. || style == TwoValueVertical
  39379. || style == ThreeValueHorizontal
  39380. || style == ThreeValueVertical)
  39381. {
  39382. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39383. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39384. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39385. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39386. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39387. {
  39388. if (maxPosDistance <= minPosDistance)
  39389. sliderBeingDragged = 2;
  39390. else
  39391. sliderBeingDragged = 1;
  39392. }
  39393. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39394. {
  39395. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39396. sliderBeingDragged = 1;
  39397. else if (normalPosDistance >= maxPosDistance)
  39398. sliderBeingDragged = 2;
  39399. }
  39400. }
  39401. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39402. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39403. * valueToProportionOfLength (currentValue.getValue());
  39404. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39405. : ((sliderBeingDragged == 1) ? valueMin
  39406. : currentValue)).getValue();
  39407. valueOnMouseDown = valueWhenLastDragged;
  39408. if (popupDisplayEnabled)
  39409. {
  39410. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39411. popupDisplay = popup;
  39412. if (parentForPopupDisplay != 0)
  39413. {
  39414. parentForPopupDisplay->addChildComponent (popup);
  39415. }
  39416. else
  39417. {
  39418. popup->addToDesktop (0);
  39419. }
  39420. popup->setVisible (true);
  39421. }
  39422. sendDragStart();
  39423. mouseDrag (e);
  39424. }
  39425. }
  39426. }
  39427. void Slider::mouseUp (const MouseEvent&)
  39428. {
  39429. if (isEnabled()
  39430. && (! menuShown)
  39431. && (maximum > minimum)
  39432. && (style != IncDecButtons || incDecDragged))
  39433. {
  39434. restoreMouseIfHidden();
  39435. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  39436. triggerChangeMessage (false);
  39437. sendDragEnd();
  39438. popupDisplay = 0;
  39439. if (style == IncDecButtons)
  39440. {
  39441. incButton->setState (Button::buttonNormal);
  39442. decButton->setState (Button::buttonNormal);
  39443. }
  39444. }
  39445. }
  39446. void Slider::restoreMouseIfHidden()
  39447. {
  39448. if (mouseWasHidden)
  39449. {
  39450. mouseWasHidden = false;
  39451. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  39452. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  39453. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  39454. : ((sliderBeingDragged == 1) ? getMinValue()
  39455. : (double) currentValue.getValue());
  39456. Point<int> mousePos;
  39457. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39458. {
  39459. mousePos = Desktop::getLastMouseDownPosition();
  39460. if (style == RotaryHorizontalDrag)
  39461. {
  39462. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  39463. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  39464. }
  39465. else
  39466. {
  39467. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  39468. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  39469. }
  39470. }
  39471. else
  39472. {
  39473. const int pixelPos = (int) getLinearSliderPos (pos);
  39474. mousePos = relativePositionToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  39475. isVertical() ? pixelPos : (getHeight() / 2)));
  39476. }
  39477. Desktop::setMousePosition (mousePos);
  39478. }
  39479. }
  39480. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  39481. {
  39482. if (isEnabled()
  39483. && style != IncDecButtons
  39484. && style != Rotary
  39485. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  39486. {
  39487. restoreMouseIfHidden();
  39488. }
  39489. }
  39490. static double smallestAngleBetween (double a1, double a2)
  39491. {
  39492. return jmin (fabs (a1 - a2),
  39493. fabs (a1 + double_Pi * 2.0 - a2),
  39494. fabs (a2 + double_Pi * 2.0 - a1));
  39495. }
  39496. void Slider::mouseDrag (const MouseEvent& e)
  39497. {
  39498. if (isEnabled()
  39499. && (! menuShown)
  39500. && (maximum > minimum))
  39501. {
  39502. if (style == Rotary)
  39503. {
  39504. int dx = e.x - sliderRect.getCentreX();
  39505. int dy = e.y - sliderRect.getCentreY();
  39506. if (dx * dx + dy * dy > 25)
  39507. {
  39508. double angle = atan2 ((double) dx, (double) -dy);
  39509. while (angle < 0.0)
  39510. angle += double_Pi * 2.0;
  39511. if (rotaryStop && ! e.mouseWasClicked())
  39512. {
  39513. if (fabs (angle - lastAngle) > double_Pi)
  39514. {
  39515. if (angle >= lastAngle)
  39516. angle -= double_Pi * 2.0;
  39517. else
  39518. angle += double_Pi * 2.0;
  39519. }
  39520. if (angle >= lastAngle)
  39521. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  39522. else
  39523. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  39524. }
  39525. else
  39526. {
  39527. while (angle < rotaryStart)
  39528. angle += double_Pi * 2.0;
  39529. if (angle > rotaryEnd)
  39530. {
  39531. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  39532. angle = rotaryStart;
  39533. else
  39534. angle = rotaryEnd;
  39535. }
  39536. }
  39537. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  39538. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  39539. lastAngle = angle;
  39540. }
  39541. }
  39542. else
  39543. {
  39544. if (style == LinearBar && e.mouseWasClicked()
  39545. && valueBox != 0 && valueBox->isEditable())
  39546. return;
  39547. if (style == IncDecButtons && ! incDecDragged)
  39548. {
  39549. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  39550. return;
  39551. incDecDragged = true;
  39552. mouseDragStartX = e.x;
  39553. mouseDragStartY = e.y;
  39554. }
  39555. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  39556. : false))
  39557. || ((maximum - minimum) / sliderRegionSize < interval))
  39558. {
  39559. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  39560. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  39561. if (style == RotaryHorizontalDrag
  39562. || style == RotaryVerticalDrag
  39563. || style == IncDecButtons
  39564. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  39565. && ! snapsToMousePos))
  39566. {
  39567. const int mouseDiff = (style == RotaryHorizontalDrag
  39568. || style == LinearHorizontal
  39569. || style == LinearBar
  39570. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39571. ? e.x - mouseDragStartX
  39572. : mouseDragStartY - e.y;
  39573. double newPos = valueToProportionOfLength (valueOnMouseDown)
  39574. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  39575. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  39576. if (style == IncDecButtons)
  39577. {
  39578. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  39579. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  39580. }
  39581. }
  39582. else
  39583. {
  39584. if (isVertical())
  39585. scaledMousePos = 1.0 - scaledMousePos;
  39586. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  39587. }
  39588. }
  39589. else
  39590. {
  39591. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  39592. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  39593. ? e.x - mouseXWhenLastDragged
  39594. : e.y - mouseYWhenLastDragged;
  39595. const double maxSpeed = jmax (200, sliderRegionSize);
  39596. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  39597. if (speed != 0)
  39598. {
  39599. speed = 0.2 * velocityModeSensitivity
  39600. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  39601. + jmax (0.0, (double) (speed - velocityModeThreshold))
  39602. / maxSpeed))));
  39603. if (mouseDiff < 0)
  39604. speed = -speed;
  39605. if (isVertical() || style == RotaryVerticalDrag
  39606. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  39607. speed = -speed;
  39608. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  39609. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  39610. e.source.enableUnboundedMouseMovement (true, false);
  39611. mouseWasHidden = true;
  39612. }
  39613. }
  39614. }
  39615. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  39616. if (sliderBeingDragged == 0)
  39617. {
  39618. setValue (snapValue (valueWhenLastDragged, true),
  39619. ! sendChangeOnlyOnRelease, true);
  39620. }
  39621. else if (sliderBeingDragged == 1)
  39622. {
  39623. setMinValue (snapValue (valueWhenLastDragged, true),
  39624. ! sendChangeOnlyOnRelease, false, true);
  39625. if (e.mods.isShiftDown())
  39626. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  39627. else
  39628. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39629. }
  39630. else
  39631. {
  39632. jassert (sliderBeingDragged == 2);
  39633. setMaxValue (snapValue (valueWhenLastDragged, true),
  39634. ! sendChangeOnlyOnRelease, false, true);
  39635. if (e.mods.isShiftDown())
  39636. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  39637. else
  39638. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39639. }
  39640. mouseXWhenLastDragged = e.x;
  39641. mouseYWhenLastDragged = e.y;
  39642. }
  39643. }
  39644. void Slider::mouseDoubleClick (const MouseEvent&)
  39645. {
  39646. if (doubleClickToValue
  39647. && isEnabled()
  39648. && style != IncDecButtons
  39649. && minimum <= doubleClickReturnValue
  39650. && maximum >= doubleClickReturnValue)
  39651. {
  39652. sendDragStart();
  39653. setValue (doubleClickReturnValue, true, true);
  39654. sendDragEnd();
  39655. }
  39656. }
  39657. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  39658. {
  39659. if (scrollWheelEnabled && isEnabled()
  39660. && style != TwoValueHorizontal
  39661. && style != TwoValueVertical)
  39662. {
  39663. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  39664. {
  39665. if (valueBox != 0)
  39666. valueBox->hideEditor (false);
  39667. const double value = (double) currentValue.getValue();
  39668. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  39669. const double currentPos = valueToProportionOfLength (value);
  39670. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  39671. double delta = (newValue != value)
  39672. ? jmax (fabs (newValue - value), interval) : 0;
  39673. if (value > newValue)
  39674. delta = -delta;
  39675. sendDragStart();
  39676. setValue (snapValue (value + delta, false), true, true);
  39677. sendDragEnd();
  39678. }
  39679. }
  39680. else
  39681. {
  39682. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  39683. }
  39684. }
  39685. void SliderListener::sliderDragStarted (Slider*)
  39686. {
  39687. }
  39688. void SliderListener::sliderDragEnded (Slider*)
  39689. {
  39690. }
  39691. END_JUCE_NAMESPACE
  39692. /*** End of inlined file: juce_Slider.cpp ***/
  39693. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  39694. BEGIN_JUCE_NAMESPACE
  39695. class DragOverlayComp : public Component
  39696. {
  39697. public:
  39698. DragOverlayComp (Image* const image_)
  39699. : image (image_)
  39700. {
  39701. image->multiplyAllAlphas (0.8f);
  39702. setAlwaysOnTop (true);
  39703. }
  39704. ~DragOverlayComp()
  39705. {
  39706. }
  39707. void paint (Graphics& g)
  39708. {
  39709. g.drawImageAt (image, 0, 0);
  39710. }
  39711. private:
  39712. ScopedPointer <Image> image;
  39713. DragOverlayComp (const DragOverlayComp&);
  39714. DragOverlayComp& operator= (const DragOverlayComp&);
  39715. };
  39716. TableHeaderComponent::TableHeaderComponent()
  39717. : columnsChanged (false),
  39718. columnsResized (false),
  39719. sortChanged (false),
  39720. menuActive (true),
  39721. stretchToFit (false),
  39722. columnIdBeingResized (0),
  39723. columnIdBeingDragged (0),
  39724. columnIdUnderMouse (0),
  39725. lastDeliberateWidth (0)
  39726. {
  39727. }
  39728. TableHeaderComponent::~TableHeaderComponent()
  39729. {
  39730. dragOverlayComp = 0;
  39731. }
  39732. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  39733. {
  39734. menuActive = hasMenu;
  39735. }
  39736. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  39737. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  39738. {
  39739. if (onlyCountVisibleColumns)
  39740. {
  39741. int num = 0;
  39742. for (int i = columns.size(); --i >= 0;)
  39743. if (columns.getUnchecked(i)->isVisible())
  39744. ++num;
  39745. return num;
  39746. }
  39747. else
  39748. {
  39749. return columns.size();
  39750. }
  39751. }
  39752. const String TableHeaderComponent::getColumnName (const int columnId) const
  39753. {
  39754. const ColumnInfo* const ci = getInfoForId (columnId);
  39755. return ci != 0 ? ci->name : String::empty;
  39756. }
  39757. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  39758. {
  39759. ColumnInfo* const ci = getInfoForId (columnId);
  39760. if (ci != 0 && ci->name != newName)
  39761. {
  39762. ci->name = newName;
  39763. sendColumnsChanged();
  39764. }
  39765. }
  39766. void TableHeaderComponent::addColumn (const String& columnName,
  39767. const int columnId,
  39768. const int width,
  39769. const int minimumWidth,
  39770. const int maximumWidth,
  39771. const int propertyFlags,
  39772. const int insertIndex)
  39773. {
  39774. // can't have a duplicate or null ID!
  39775. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  39776. jassert (width > 0);
  39777. ColumnInfo* const ci = new ColumnInfo();
  39778. ci->name = columnName;
  39779. ci->id = columnId;
  39780. ci->width = width;
  39781. ci->lastDeliberateWidth = width;
  39782. ci->minimumWidth = minimumWidth;
  39783. ci->maximumWidth = maximumWidth;
  39784. if (ci->maximumWidth < 0)
  39785. ci->maximumWidth = std::numeric_limits<int>::max();
  39786. jassert (ci->maximumWidth >= ci->minimumWidth);
  39787. ci->propertyFlags = propertyFlags;
  39788. columns.insert (insertIndex, ci);
  39789. sendColumnsChanged();
  39790. }
  39791. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  39792. {
  39793. const int index = getIndexOfColumnId (columnIdToRemove, false);
  39794. if (index >= 0)
  39795. {
  39796. columns.remove (index);
  39797. sortChanged = true;
  39798. sendColumnsChanged();
  39799. }
  39800. }
  39801. void TableHeaderComponent::removeAllColumns()
  39802. {
  39803. if (columns.size() > 0)
  39804. {
  39805. columns.clear();
  39806. sendColumnsChanged();
  39807. }
  39808. }
  39809. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  39810. {
  39811. const int currentIndex = getIndexOfColumnId (columnId, false);
  39812. newIndex = visibleIndexToTotalIndex (newIndex);
  39813. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  39814. {
  39815. columns.move (currentIndex, newIndex);
  39816. sendColumnsChanged();
  39817. }
  39818. }
  39819. int TableHeaderComponent::getColumnWidth (const int columnId) const
  39820. {
  39821. const ColumnInfo* const ci = getInfoForId (columnId);
  39822. return ci != 0 ? ci->width : 0;
  39823. }
  39824. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  39825. {
  39826. ColumnInfo* const ci = getInfoForId (columnId);
  39827. if (ci != 0 && ci->width != newWidth)
  39828. {
  39829. const int numColumns = getNumColumns (true);
  39830. ci->lastDeliberateWidth = ci->width
  39831. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  39832. if (stretchToFit)
  39833. {
  39834. const int index = getIndexOfColumnId (columnId, true) + 1;
  39835. if (((unsigned int) index) < (unsigned int) numColumns)
  39836. {
  39837. const int x = getColumnPosition (index).getX();
  39838. if (lastDeliberateWidth == 0)
  39839. lastDeliberateWidth = getTotalWidth();
  39840. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  39841. }
  39842. }
  39843. repaint();
  39844. columnsResized = true;
  39845. triggerAsyncUpdate();
  39846. }
  39847. }
  39848. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  39849. {
  39850. int n = 0;
  39851. for (int i = 0; i < columns.size(); ++i)
  39852. {
  39853. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  39854. {
  39855. if (columns.getUnchecked(i)->id == columnId)
  39856. return n;
  39857. ++n;
  39858. }
  39859. }
  39860. return -1;
  39861. }
  39862. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  39863. {
  39864. if (onlyCountVisibleColumns)
  39865. index = visibleIndexToTotalIndex (index);
  39866. const ColumnInfo* const ci = columns [index];
  39867. return (ci != 0) ? ci->id : 0;
  39868. }
  39869. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  39870. {
  39871. int x = 0, width = 0, n = 0;
  39872. for (int i = 0; i < columns.size(); ++i)
  39873. {
  39874. x += width;
  39875. if (columns.getUnchecked(i)->isVisible())
  39876. {
  39877. width = columns.getUnchecked(i)->width;
  39878. if (n++ == index)
  39879. break;
  39880. }
  39881. else
  39882. {
  39883. width = 0;
  39884. }
  39885. }
  39886. return Rectangle<int> (x, 0, width, getHeight());
  39887. }
  39888. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  39889. {
  39890. if (xToFind >= 0)
  39891. {
  39892. int x = 0;
  39893. for (int i = 0; i < columns.size(); ++i)
  39894. {
  39895. const ColumnInfo* const ci = columns.getUnchecked(i);
  39896. if (ci->isVisible())
  39897. {
  39898. x += ci->width;
  39899. if (xToFind < x)
  39900. return ci->id;
  39901. }
  39902. }
  39903. }
  39904. return 0;
  39905. }
  39906. int TableHeaderComponent::getTotalWidth() const
  39907. {
  39908. int w = 0;
  39909. for (int i = columns.size(); --i >= 0;)
  39910. if (columns.getUnchecked(i)->isVisible())
  39911. w += columns.getUnchecked(i)->width;
  39912. return w;
  39913. }
  39914. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  39915. {
  39916. stretchToFit = shouldStretchToFit;
  39917. lastDeliberateWidth = getTotalWidth();
  39918. resized();
  39919. }
  39920. bool TableHeaderComponent::isStretchToFitActive() const
  39921. {
  39922. return stretchToFit;
  39923. }
  39924. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  39925. {
  39926. if (stretchToFit && getWidth() > 0
  39927. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  39928. {
  39929. lastDeliberateWidth = targetTotalWidth;
  39930. resizeColumnsToFit (0, targetTotalWidth);
  39931. }
  39932. }
  39933. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  39934. {
  39935. targetTotalWidth = jmax (targetTotalWidth, 0);
  39936. StretchableObjectResizer sor;
  39937. int i;
  39938. for (i = firstColumnIndex; i < columns.size(); ++i)
  39939. {
  39940. ColumnInfo* const ci = columns.getUnchecked(i);
  39941. if (ci->isVisible())
  39942. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  39943. }
  39944. sor.resizeToFit (targetTotalWidth);
  39945. int visIndex = 0;
  39946. for (i = firstColumnIndex; i < columns.size(); ++i)
  39947. {
  39948. ColumnInfo* const ci = columns.getUnchecked(i);
  39949. if (ci->isVisible())
  39950. {
  39951. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  39952. (int) floor (sor.getItemSize (visIndex++)));
  39953. if (newWidth != ci->width)
  39954. {
  39955. ci->width = newWidth;
  39956. repaint();
  39957. columnsResized = true;
  39958. triggerAsyncUpdate();
  39959. }
  39960. }
  39961. }
  39962. }
  39963. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  39964. {
  39965. ColumnInfo* const ci = getInfoForId (columnId);
  39966. if (ci != 0 && shouldBeVisible != ci->isVisible())
  39967. {
  39968. if (shouldBeVisible)
  39969. ci->propertyFlags |= visible;
  39970. else
  39971. ci->propertyFlags &= ~visible;
  39972. sendColumnsChanged();
  39973. resized();
  39974. }
  39975. }
  39976. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  39977. {
  39978. const ColumnInfo* const ci = getInfoForId (columnId);
  39979. return ci != 0 && ci->isVisible();
  39980. }
  39981. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  39982. {
  39983. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  39984. {
  39985. for (int i = columns.size(); --i >= 0;)
  39986. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  39987. ColumnInfo* const ci = getInfoForId (columnId);
  39988. if (ci != 0)
  39989. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  39990. reSortTable();
  39991. }
  39992. }
  39993. int TableHeaderComponent::getSortColumnId() const
  39994. {
  39995. for (int i = columns.size(); --i >= 0;)
  39996. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  39997. return columns.getUnchecked(i)->id;
  39998. return 0;
  39999. }
  40000. bool TableHeaderComponent::isSortedForwards() const
  40001. {
  40002. for (int i = columns.size(); --i >= 0;)
  40003. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40004. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40005. return true;
  40006. }
  40007. void TableHeaderComponent::reSortTable()
  40008. {
  40009. sortChanged = true;
  40010. repaint();
  40011. triggerAsyncUpdate();
  40012. }
  40013. const String TableHeaderComponent::toString() const
  40014. {
  40015. String s;
  40016. XmlElement doc ("TABLELAYOUT");
  40017. doc.setAttribute ("sortedCol", getSortColumnId());
  40018. doc.setAttribute ("sortForwards", isSortedForwards());
  40019. for (int i = 0; i < columns.size(); ++i)
  40020. {
  40021. const ColumnInfo* const ci = columns.getUnchecked (i);
  40022. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40023. e->setAttribute ("id", ci->id);
  40024. e->setAttribute ("visible", ci->isVisible());
  40025. e->setAttribute ("width", ci->width);
  40026. }
  40027. return doc.createDocument (String::empty, true, false);
  40028. }
  40029. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40030. {
  40031. XmlDocument doc (storedVersion);
  40032. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40033. int index = 0;
  40034. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40035. {
  40036. forEachXmlChildElement (*storedXml, col)
  40037. {
  40038. const int tabId = col->getIntAttribute ("id");
  40039. ColumnInfo* const ci = getInfoForId (tabId);
  40040. if (ci != 0)
  40041. {
  40042. columns.move (columns.indexOf (ci), index);
  40043. ci->width = col->getIntAttribute ("width");
  40044. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40045. }
  40046. ++index;
  40047. }
  40048. columnsResized = true;
  40049. sendColumnsChanged();
  40050. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40051. storedXml->getBoolAttribute ("sortForwards", true));
  40052. }
  40053. }
  40054. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40055. {
  40056. listeners.addIfNotAlreadyThere (newListener);
  40057. }
  40058. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40059. {
  40060. listeners.removeValue (listenerToRemove);
  40061. }
  40062. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40063. {
  40064. const ColumnInfo* const ci = getInfoForId (columnId);
  40065. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40066. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40067. }
  40068. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40069. {
  40070. for (int i = 0; i < columns.size(); ++i)
  40071. {
  40072. const ColumnInfo* const ci = columns.getUnchecked(i);
  40073. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40074. menu.addItem (ci->id, ci->name,
  40075. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40076. isColumnVisible (ci->id));
  40077. }
  40078. }
  40079. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40080. {
  40081. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40082. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40083. }
  40084. void TableHeaderComponent::paint (Graphics& g)
  40085. {
  40086. LookAndFeel& lf = getLookAndFeel();
  40087. lf.drawTableHeaderBackground (g, *this);
  40088. const Rectangle<int> clip (g.getClipBounds());
  40089. int x = 0;
  40090. for (int i = 0; i < columns.size(); ++i)
  40091. {
  40092. const ColumnInfo* const ci = columns.getUnchecked(i);
  40093. if (ci->isVisible())
  40094. {
  40095. if (x + ci->width > clip.getX()
  40096. && (ci->id != columnIdBeingDragged
  40097. || dragOverlayComp == 0
  40098. || ! dragOverlayComp->isVisible()))
  40099. {
  40100. g.saveState();
  40101. g.setOrigin (x, 0);
  40102. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40103. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40104. ci->id == columnIdUnderMouse,
  40105. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40106. ci->propertyFlags);
  40107. g.restoreState();
  40108. }
  40109. x += ci->width;
  40110. if (x >= clip.getRight())
  40111. break;
  40112. }
  40113. }
  40114. }
  40115. void TableHeaderComponent::resized()
  40116. {
  40117. }
  40118. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40119. {
  40120. updateColumnUnderMouse (e.x, e.y);
  40121. }
  40122. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40123. {
  40124. updateColumnUnderMouse (e.x, e.y);
  40125. }
  40126. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40127. {
  40128. updateColumnUnderMouse (e.x, e.y);
  40129. }
  40130. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40131. {
  40132. repaint();
  40133. columnIdBeingResized = 0;
  40134. columnIdBeingDragged = 0;
  40135. if (columnIdUnderMouse != 0)
  40136. {
  40137. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40138. if (e.mods.isPopupMenu())
  40139. columnClicked (columnIdUnderMouse, e.mods);
  40140. }
  40141. if (menuActive && e.mods.isPopupMenu())
  40142. showColumnChooserMenu (columnIdUnderMouse);
  40143. }
  40144. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40145. {
  40146. if (columnIdBeingResized == 0
  40147. && columnIdBeingDragged == 0
  40148. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40149. {
  40150. dragOverlayComp = 0;
  40151. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40152. if (columnIdBeingResized != 0)
  40153. {
  40154. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40155. initialColumnWidth = ci->width;
  40156. }
  40157. else
  40158. {
  40159. beginDrag (e);
  40160. }
  40161. }
  40162. if (columnIdBeingResized != 0)
  40163. {
  40164. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40165. if (ci != 0)
  40166. {
  40167. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40168. initialColumnWidth + e.getDistanceFromDragStartX());
  40169. if (stretchToFit)
  40170. {
  40171. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40172. int minWidthOnRight = 0;
  40173. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40174. if (columns.getUnchecked (i)->isVisible())
  40175. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40176. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40177. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40178. }
  40179. setColumnWidth (columnIdBeingResized, w);
  40180. }
  40181. }
  40182. else if (columnIdBeingDragged != 0)
  40183. {
  40184. if (e.y >= -50 && e.y < getHeight() + 50)
  40185. {
  40186. if (dragOverlayComp != 0)
  40187. {
  40188. dragOverlayComp->setVisible (true);
  40189. dragOverlayComp->setBounds (jlimit (0,
  40190. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40191. e.x - draggingColumnOffset),
  40192. 0,
  40193. dragOverlayComp->getWidth(),
  40194. getHeight());
  40195. for (int i = columns.size(); --i >= 0;)
  40196. {
  40197. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40198. int newIndex = currentIndex;
  40199. if (newIndex > 0)
  40200. {
  40201. // if the previous column isn't draggable, we can't move our column
  40202. // past it, because that'd change the undraggable column's position..
  40203. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40204. if ((previous->propertyFlags & draggable) != 0)
  40205. {
  40206. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40207. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40208. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40209. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40210. {
  40211. --newIndex;
  40212. }
  40213. }
  40214. }
  40215. if (newIndex < columns.size() - 1)
  40216. {
  40217. // if the next column isn't draggable, we can't move our column
  40218. // past it, because that'd change the undraggable column's position..
  40219. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40220. if ((nextCol->propertyFlags & draggable) != 0)
  40221. {
  40222. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40223. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40224. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40225. > abs (dragOverlayComp->getRight() - rightOfNext))
  40226. {
  40227. ++newIndex;
  40228. }
  40229. }
  40230. }
  40231. if (newIndex != currentIndex)
  40232. moveColumn (columnIdBeingDragged, newIndex);
  40233. else
  40234. break;
  40235. }
  40236. }
  40237. }
  40238. else
  40239. {
  40240. endDrag (draggingColumnOriginalIndex);
  40241. }
  40242. }
  40243. }
  40244. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40245. {
  40246. if (columnIdBeingDragged == 0)
  40247. {
  40248. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40249. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40250. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40251. {
  40252. columnIdBeingDragged = 0;
  40253. }
  40254. else
  40255. {
  40256. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40257. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40258. const int temp = columnIdBeingDragged;
  40259. columnIdBeingDragged = 0;
  40260. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40261. columnIdBeingDragged = temp;
  40262. dragOverlayComp->setBounds (columnRect);
  40263. for (int i = listeners.size(); --i >= 0;)
  40264. {
  40265. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40266. i = jmin (i, listeners.size() - 1);
  40267. }
  40268. }
  40269. }
  40270. }
  40271. void TableHeaderComponent::endDrag (const int finalIndex)
  40272. {
  40273. if (columnIdBeingDragged != 0)
  40274. {
  40275. moveColumn (columnIdBeingDragged, finalIndex);
  40276. columnIdBeingDragged = 0;
  40277. repaint();
  40278. for (int i = listeners.size(); --i >= 0;)
  40279. {
  40280. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40281. i = jmin (i, listeners.size() - 1);
  40282. }
  40283. }
  40284. }
  40285. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40286. {
  40287. mouseDrag (e);
  40288. for (int i = columns.size(); --i >= 0;)
  40289. if (columns.getUnchecked (i)->isVisible())
  40290. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40291. columnIdBeingResized = 0;
  40292. repaint();
  40293. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40294. updateColumnUnderMouse (e.x, e.y);
  40295. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40296. columnClicked (columnIdUnderMouse, e.mods);
  40297. dragOverlayComp = 0;
  40298. }
  40299. const MouseCursor TableHeaderComponent::getMouseCursor()
  40300. {
  40301. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40302. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40303. return Component::getMouseCursor();
  40304. }
  40305. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40306. {
  40307. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40308. }
  40309. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40310. {
  40311. for (int i = columns.size(); --i >= 0;)
  40312. if (columns.getUnchecked(i)->id == id)
  40313. return columns.getUnchecked(i);
  40314. return 0;
  40315. }
  40316. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40317. {
  40318. int n = 0;
  40319. for (int i = 0; i < columns.size(); ++i)
  40320. {
  40321. if (columns.getUnchecked(i)->isVisible())
  40322. {
  40323. if (n == visibleIndex)
  40324. return i;
  40325. ++n;
  40326. }
  40327. }
  40328. return -1;
  40329. }
  40330. void TableHeaderComponent::sendColumnsChanged()
  40331. {
  40332. if (stretchToFit && lastDeliberateWidth > 0)
  40333. resizeAllColumnsToFit (lastDeliberateWidth);
  40334. repaint();
  40335. columnsChanged = true;
  40336. triggerAsyncUpdate();
  40337. }
  40338. void TableHeaderComponent::handleAsyncUpdate()
  40339. {
  40340. const bool changed = columnsChanged || sortChanged;
  40341. const bool sized = columnsResized || changed;
  40342. const bool sorted = sortChanged;
  40343. columnsChanged = false;
  40344. columnsResized = false;
  40345. sortChanged = false;
  40346. if (sorted)
  40347. {
  40348. for (int i = listeners.size(); --i >= 0;)
  40349. {
  40350. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40351. i = jmin (i, listeners.size() - 1);
  40352. }
  40353. }
  40354. if (changed)
  40355. {
  40356. for (int i = listeners.size(); --i >= 0;)
  40357. {
  40358. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40359. i = jmin (i, listeners.size() - 1);
  40360. }
  40361. }
  40362. if (sized)
  40363. {
  40364. for (int i = listeners.size(); --i >= 0;)
  40365. {
  40366. listeners.getUnchecked(i)->tableColumnsResized (this);
  40367. i = jmin (i, listeners.size() - 1);
  40368. }
  40369. }
  40370. }
  40371. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40372. {
  40373. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40374. {
  40375. const int draggableDistance = 3;
  40376. int x = 0;
  40377. for (int i = 0; i < columns.size(); ++i)
  40378. {
  40379. const ColumnInfo* const ci = columns.getUnchecked(i);
  40380. if (ci->isVisible())
  40381. {
  40382. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40383. && (ci->propertyFlags & resizable) != 0)
  40384. return ci->id;
  40385. x += ci->width;
  40386. }
  40387. }
  40388. }
  40389. return 0;
  40390. }
  40391. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40392. {
  40393. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40394. ? getColumnIdAtX (x) : 0;
  40395. if (newCol != columnIdUnderMouse)
  40396. {
  40397. columnIdUnderMouse = newCol;
  40398. repaint();
  40399. }
  40400. }
  40401. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40402. {
  40403. PopupMenu m;
  40404. addMenuItems (m, columnIdClicked);
  40405. if (m.getNumItems() > 0)
  40406. {
  40407. m.setLookAndFeel (&getLookAndFeel());
  40408. const int result = m.show();
  40409. if (result != 0)
  40410. reactToMenuItem (result, columnIdClicked);
  40411. }
  40412. }
  40413. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40414. {
  40415. }
  40416. END_JUCE_NAMESPACE
  40417. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40418. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40419. BEGIN_JUCE_NAMESPACE
  40420. static const char* const tableColumnPropertyTag = "_tableColumnID";
  40421. class TableListRowComp : public Component,
  40422. public TooltipClient
  40423. {
  40424. public:
  40425. TableListRowComp (TableListBox& owner_)
  40426. : owner (owner_),
  40427. row (-1),
  40428. isSelected (false)
  40429. {
  40430. }
  40431. ~TableListRowComp()
  40432. {
  40433. deleteAllChildren();
  40434. }
  40435. void paint (Graphics& g)
  40436. {
  40437. TableListBoxModel* const model = owner.getModel();
  40438. if (model != 0)
  40439. {
  40440. const TableHeaderComponent* const header = owner.getHeader();
  40441. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  40442. const int numColumns = header->getNumColumns (true);
  40443. for (int i = 0; i < numColumns; ++i)
  40444. {
  40445. if (! columnsWithComponents [i])
  40446. {
  40447. const int columnId = header->getColumnIdOfIndex (i, true);
  40448. Rectangle<int> columnRect (header->getColumnPosition (i));
  40449. columnRect.setSize (columnRect.getWidth(), getHeight());
  40450. g.saveState();
  40451. g.reduceClipRegion (columnRect);
  40452. g.setOrigin (columnRect.getX(), 0);
  40453. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  40454. g.restoreState();
  40455. }
  40456. }
  40457. }
  40458. }
  40459. void update (const int newRow, const bool isNowSelected)
  40460. {
  40461. if (newRow != row || isNowSelected != isSelected)
  40462. {
  40463. row = newRow;
  40464. isSelected = isNowSelected;
  40465. repaint();
  40466. }
  40467. if (row < owner.getNumRows())
  40468. {
  40469. jassert (row >= 0);
  40470. const var::identifier tagPropertyName ("_tableLastUseNum");
  40471. const int newTag = Random::getSystemRandom().nextInt();
  40472. const TableHeaderComponent* const header = owner.getHeader();
  40473. const int numColumns = header->getNumColumns (true);
  40474. int i;
  40475. columnsWithComponents.clear();
  40476. if (owner.getModel() != 0)
  40477. {
  40478. for (i = 0; i < numColumns; ++i)
  40479. {
  40480. const int columnId = header->getColumnIdOfIndex (i, true);
  40481. Component* const newComp
  40482. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  40483. findChildComponentForColumn (columnId));
  40484. if (newComp != 0)
  40485. {
  40486. addAndMakeVisible (newComp);
  40487. newComp->getProperties().set (tagPropertyName, newTag);
  40488. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  40489. const Rectangle<int> columnRect (header->getColumnPosition (i));
  40490. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40491. columnsWithComponents.setBit (i);
  40492. }
  40493. }
  40494. }
  40495. for (i = getNumChildComponents(); --i >= 0;)
  40496. {
  40497. Component* const c = getChildComponent (i);
  40498. if ((int) c->getProperties() [tagPropertyName] != newTag)
  40499. delete c;
  40500. }
  40501. }
  40502. else
  40503. {
  40504. columnsWithComponents.clear();
  40505. deleteAllChildren();
  40506. }
  40507. }
  40508. void resized()
  40509. {
  40510. for (int i = getNumChildComponents(); --i >= 0;)
  40511. {
  40512. Component* const c = getChildComponent (i);
  40513. const int columnId = c->getProperties() [tableColumnPropertyTag];
  40514. if (columnId != 0)
  40515. {
  40516. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  40517. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  40518. }
  40519. }
  40520. }
  40521. void mouseDown (const MouseEvent& e)
  40522. {
  40523. isDragging = false;
  40524. selectRowOnMouseUp = false;
  40525. if (isEnabled())
  40526. {
  40527. if (! isSelected)
  40528. {
  40529. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40530. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40531. if (columnId != 0 && owner.getModel() != 0)
  40532. owner.getModel()->cellClicked (row, columnId, e);
  40533. }
  40534. else
  40535. {
  40536. selectRowOnMouseUp = true;
  40537. }
  40538. }
  40539. }
  40540. void mouseDrag (const MouseEvent& e)
  40541. {
  40542. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  40543. {
  40544. const SparseSet <int> selectedRows (owner.getSelectedRows());
  40545. if (selectedRows.size() > 0)
  40546. {
  40547. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  40548. if (dragDescription.isNotEmpty())
  40549. {
  40550. isDragging = true;
  40551. owner.startDragAndDrop (e, dragDescription);
  40552. }
  40553. }
  40554. }
  40555. }
  40556. void mouseUp (const MouseEvent& e)
  40557. {
  40558. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  40559. {
  40560. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  40561. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40562. if (columnId != 0 && owner.getModel() != 0)
  40563. owner.getModel()->cellClicked (row, columnId, e);
  40564. }
  40565. }
  40566. void mouseDoubleClick (const MouseEvent& e)
  40567. {
  40568. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  40569. if (columnId != 0 && owner.getModel() != 0)
  40570. owner.getModel()->cellDoubleClicked (row, columnId, e);
  40571. }
  40572. const String getTooltip()
  40573. {
  40574. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  40575. if (columnId != 0 && owner.getModel() != 0)
  40576. return owner.getModel()->getCellTooltip (row, columnId);
  40577. return String::empty;
  40578. }
  40579. juce_UseDebuggingNewOperator
  40580. private:
  40581. TableListBox& owner;
  40582. int row;
  40583. bool isSelected, isDragging, selectRowOnMouseUp;
  40584. BigInteger columnsWithComponents;
  40585. Component* findChildComponentForColumn (const int columnId) const
  40586. {
  40587. for (int i = getNumChildComponents(); --i >= 0;)
  40588. {
  40589. Component* const c = getChildComponent (i);
  40590. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  40591. return c;
  40592. }
  40593. return 0;
  40594. }
  40595. TableListRowComp (const TableListRowComp&);
  40596. TableListRowComp& operator= (const TableListRowComp&);
  40597. };
  40598. class TableListBoxHeader : public TableHeaderComponent
  40599. {
  40600. public:
  40601. TableListBoxHeader (TableListBox& owner_)
  40602. : owner (owner_)
  40603. {
  40604. }
  40605. ~TableListBoxHeader()
  40606. {
  40607. }
  40608. void addMenuItems (PopupMenu& menu, int columnIdClicked)
  40609. {
  40610. if (owner.isAutoSizeMenuOptionShown())
  40611. {
  40612. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  40613. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  40614. menu.addSeparator();
  40615. }
  40616. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  40617. }
  40618. void reactToMenuItem (int menuReturnId, int columnIdClicked)
  40619. {
  40620. if (menuReturnId == 0xf836743)
  40621. {
  40622. owner.autoSizeColumn (columnIdClicked);
  40623. }
  40624. else if (menuReturnId == 0xf836744)
  40625. {
  40626. owner.autoSizeAllColumns();
  40627. }
  40628. else
  40629. {
  40630. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  40631. }
  40632. }
  40633. juce_UseDebuggingNewOperator
  40634. private:
  40635. TableListBox& owner;
  40636. TableListBoxHeader (const TableListBoxHeader&);
  40637. TableListBoxHeader& operator= (const TableListBoxHeader&);
  40638. };
  40639. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  40640. : ListBox (name, 0),
  40641. model (model_),
  40642. autoSizeOptionsShown (true)
  40643. {
  40644. ListBox::model = this;
  40645. header = new TableListBoxHeader (*this);
  40646. header->setSize (100, 28);
  40647. header->addListener (this);
  40648. setHeaderComponent (header);
  40649. }
  40650. TableListBox::~TableListBox()
  40651. {
  40652. deleteAllChildren();
  40653. }
  40654. void TableListBox::setModel (TableListBoxModel* const newModel)
  40655. {
  40656. if (model != newModel)
  40657. {
  40658. model = newModel;
  40659. updateContent();
  40660. }
  40661. }
  40662. int TableListBox::getHeaderHeight() const
  40663. {
  40664. return header->getHeight();
  40665. }
  40666. void TableListBox::setHeaderHeight (const int newHeight)
  40667. {
  40668. header->setSize (header->getWidth(), newHeight);
  40669. resized();
  40670. }
  40671. void TableListBox::autoSizeColumn (const int columnId)
  40672. {
  40673. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  40674. if (width > 0)
  40675. header->setColumnWidth (columnId, width);
  40676. }
  40677. void TableListBox::autoSizeAllColumns()
  40678. {
  40679. for (int i = 0; i < header->getNumColumns (true); ++i)
  40680. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  40681. }
  40682. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  40683. {
  40684. autoSizeOptionsShown = shouldBeShown;
  40685. }
  40686. bool TableListBox::isAutoSizeMenuOptionShown() const
  40687. {
  40688. return autoSizeOptionsShown;
  40689. }
  40690. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  40691. const int rowNumber,
  40692. const bool relativeToComponentTopLeft) const
  40693. {
  40694. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40695. if (relativeToComponentTopLeft)
  40696. headerCell.translate (header->getX(), 0);
  40697. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  40698. return Rectangle<int> (headerCell.getX(), row.getY(),
  40699. headerCell.getWidth(), row.getHeight());
  40700. }
  40701. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  40702. {
  40703. ScrollBar* const scrollbar = getHorizontalScrollBar();
  40704. if (scrollbar != 0)
  40705. {
  40706. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  40707. double x = scrollbar->getCurrentRangeStart();
  40708. const double w = scrollbar->getCurrentRangeSize();
  40709. if (pos.getX() < x)
  40710. x = pos.getX();
  40711. else if (pos.getRight() > x + w)
  40712. x += jmax (0.0, pos.getRight() - (x + w));
  40713. scrollbar->setCurrentRangeStart (x);
  40714. }
  40715. }
  40716. int TableListBox::getNumRows()
  40717. {
  40718. return model != 0 ? model->getNumRows() : 0;
  40719. }
  40720. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  40721. {
  40722. }
  40723. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  40724. {
  40725. if (existingComponentToUpdate == 0)
  40726. existingComponentToUpdate = new TableListRowComp (*this);
  40727. static_cast <TableListRowComp*> (existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  40728. return existingComponentToUpdate;
  40729. }
  40730. void TableListBox::selectedRowsChanged (int row)
  40731. {
  40732. if (model != 0)
  40733. model->selectedRowsChanged (row);
  40734. }
  40735. void TableListBox::deleteKeyPressed (int row)
  40736. {
  40737. if (model != 0)
  40738. model->deleteKeyPressed (row);
  40739. }
  40740. void TableListBox::returnKeyPressed (int row)
  40741. {
  40742. if (model != 0)
  40743. model->returnKeyPressed (row);
  40744. }
  40745. void TableListBox::backgroundClicked()
  40746. {
  40747. if (model != 0)
  40748. model->backgroundClicked();
  40749. }
  40750. void TableListBox::listWasScrolled()
  40751. {
  40752. if (model != 0)
  40753. model->listWasScrolled();
  40754. }
  40755. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  40756. {
  40757. setMinimumContentWidth (header->getTotalWidth());
  40758. repaint();
  40759. updateColumnComponents();
  40760. }
  40761. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  40762. {
  40763. setMinimumContentWidth (header->getTotalWidth());
  40764. repaint();
  40765. updateColumnComponents();
  40766. }
  40767. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  40768. {
  40769. if (model != 0)
  40770. model->sortOrderChanged (header->getSortColumnId(),
  40771. header->isSortedForwards());
  40772. }
  40773. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  40774. {
  40775. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  40776. repaint();
  40777. }
  40778. void TableListBox::resized()
  40779. {
  40780. ListBox::resized();
  40781. header->resizeAllColumnsToFit (getVisibleContentWidth());
  40782. setMinimumContentWidth (header->getTotalWidth());
  40783. }
  40784. void TableListBox::updateColumnComponents() const
  40785. {
  40786. const int firstRow = getRowContainingPosition (0, 0);
  40787. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  40788. {
  40789. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  40790. if (rowComp != 0)
  40791. rowComp->resized();
  40792. }
  40793. }
  40794. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  40795. {
  40796. }
  40797. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  40798. {
  40799. }
  40800. void TableListBoxModel::backgroundClicked()
  40801. {
  40802. }
  40803. void TableListBoxModel::sortOrderChanged (int, const bool)
  40804. {
  40805. }
  40806. int TableListBoxModel::getColumnAutoSizeWidth (int)
  40807. {
  40808. return 0;
  40809. }
  40810. void TableListBoxModel::selectedRowsChanged (int)
  40811. {
  40812. }
  40813. void TableListBoxModel::deleteKeyPressed (int)
  40814. {
  40815. }
  40816. void TableListBoxModel::returnKeyPressed (int)
  40817. {
  40818. }
  40819. void TableListBoxModel::listWasScrolled()
  40820. {
  40821. }
  40822. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  40823. {
  40824. return String::empty;
  40825. }
  40826. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  40827. {
  40828. return String::empty;
  40829. }
  40830. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  40831. {
  40832. (void) existingComponentToUpdate;
  40833. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  40834. return 0;
  40835. }
  40836. END_JUCE_NAMESPACE
  40837. /*** End of inlined file: juce_TableListBox.cpp ***/
  40838. /*** Start of inlined file: juce_TextEditor.cpp ***/
  40839. BEGIN_JUCE_NAMESPACE
  40840. // a word or space that can't be broken down any further
  40841. struct TextAtom
  40842. {
  40843. String atomText;
  40844. float width;
  40845. uint16 numChars;
  40846. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  40847. bool isNewLine() const { return atomText[0] == '\r' || atomText[0] == '\n'; }
  40848. const String getText (const juce_wchar passwordCharacter) const
  40849. {
  40850. if (passwordCharacter == 0)
  40851. return atomText;
  40852. else
  40853. return String::repeatedString (String::charToString (passwordCharacter),
  40854. atomText.length());
  40855. }
  40856. const String getTrimmedText (const juce_wchar passwordCharacter) const
  40857. {
  40858. if (passwordCharacter == 0)
  40859. return atomText.substring (0, numChars);
  40860. else if (isNewLine())
  40861. return String::empty;
  40862. else
  40863. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  40864. }
  40865. };
  40866. // a run of text with a single font and colour
  40867. class TextEditor::UniformTextSection
  40868. {
  40869. public:
  40870. UniformTextSection (const String& text,
  40871. const Font& font_,
  40872. const Colour& colour_,
  40873. const juce_wchar passwordCharacter)
  40874. : font (font_),
  40875. colour (colour_)
  40876. {
  40877. initialiseAtoms (text, passwordCharacter);
  40878. }
  40879. UniformTextSection (const UniformTextSection& other)
  40880. : font (other.font),
  40881. colour (other.colour)
  40882. {
  40883. atoms.ensureStorageAllocated (other.atoms.size());
  40884. for (int i = 0; i < other.atoms.size(); ++i)
  40885. atoms.add (new TextAtom (*other.atoms.getUnchecked(i)));
  40886. }
  40887. ~UniformTextSection()
  40888. {
  40889. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  40890. }
  40891. void clear()
  40892. {
  40893. for (int i = atoms.size(); --i >= 0;)
  40894. delete getAtom(i);
  40895. atoms.clear();
  40896. }
  40897. int getNumAtoms() const
  40898. {
  40899. return atoms.size();
  40900. }
  40901. TextAtom* getAtom (const int index) const throw()
  40902. {
  40903. return atoms.getUnchecked (index);
  40904. }
  40905. void append (const UniformTextSection& other, const juce_wchar passwordCharacter)
  40906. {
  40907. if (other.atoms.size() > 0)
  40908. {
  40909. TextAtom* const lastAtom = atoms.getLast();
  40910. int i = 0;
  40911. if (lastAtom != 0)
  40912. {
  40913. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  40914. {
  40915. TextAtom* const first = other.getAtom(0);
  40916. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  40917. {
  40918. lastAtom->atomText += first->atomText;
  40919. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  40920. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  40921. delete first;
  40922. ++i;
  40923. }
  40924. }
  40925. }
  40926. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  40927. while (i < other.atoms.size())
  40928. {
  40929. atoms.add (other.getAtom(i));
  40930. ++i;
  40931. }
  40932. }
  40933. }
  40934. UniformTextSection* split (const int indexToBreakAt,
  40935. const juce_wchar passwordCharacter)
  40936. {
  40937. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  40938. font, colour,
  40939. passwordCharacter);
  40940. int index = 0;
  40941. for (int i = 0; i < atoms.size(); ++i)
  40942. {
  40943. TextAtom* const atom = getAtom(i);
  40944. const int nextIndex = index + atom->numChars;
  40945. if (index == indexToBreakAt)
  40946. {
  40947. int j;
  40948. for (j = i; j < atoms.size(); ++j)
  40949. section2->atoms.add (getAtom (j));
  40950. for (j = atoms.size(); --j >= i;)
  40951. atoms.remove (j);
  40952. break;
  40953. }
  40954. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  40955. {
  40956. TextAtom* const secondAtom = new TextAtom();
  40957. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  40958. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  40959. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  40960. section2->atoms.add (secondAtom);
  40961. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  40962. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  40963. atom->numChars = (uint16) (indexToBreakAt - index);
  40964. int j;
  40965. for (j = i + 1; j < atoms.size(); ++j)
  40966. section2->atoms.add (getAtom (j));
  40967. for (j = atoms.size(); --j > i;)
  40968. atoms.remove (j);
  40969. break;
  40970. }
  40971. index = nextIndex;
  40972. }
  40973. return section2;
  40974. }
  40975. void appendAllText (String::Concatenator& concatenator) const
  40976. {
  40977. for (int i = 0; i < atoms.size(); ++i)
  40978. concatenator.append (getAtom(i)->atomText);
  40979. }
  40980. void appendSubstring (String::Concatenator& concatenator,
  40981. const Range<int>& range) const
  40982. {
  40983. int index = 0;
  40984. for (int i = 0; i < atoms.size(); ++i)
  40985. {
  40986. const TextAtom* const atom = getAtom (i);
  40987. const int nextIndex = index + atom->numChars;
  40988. if (range.getStart() < nextIndex)
  40989. {
  40990. if (range.getEnd() <= index)
  40991. break;
  40992. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  40993. if (! r.isEmpty())
  40994. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  40995. }
  40996. index = nextIndex;
  40997. }
  40998. }
  40999. int getTotalLength() const
  41000. {
  41001. int total = 0;
  41002. for (int i = atoms.size(); --i >= 0;)
  41003. total += getAtom(i)->numChars;
  41004. return total;
  41005. }
  41006. void setFont (const Font& newFont,
  41007. const juce_wchar passwordCharacter)
  41008. {
  41009. if (font != newFont)
  41010. {
  41011. font = newFont;
  41012. for (int i = atoms.size(); --i >= 0;)
  41013. {
  41014. TextAtom* const atom = atoms.getUnchecked(i);
  41015. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41016. }
  41017. }
  41018. }
  41019. juce_UseDebuggingNewOperator
  41020. Font font;
  41021. Colour colour;
  41022. private:
  41023. Array <TextAtom*> atoms;
  41024. void initialiseAtoms (const String& textToParse,
  41025. const juce_wchar passwordCharacter)
  41026. {
  41027. int i = 0;
  41028. const int len = textToParse.length();
  41029. const juce_wchar* const text = textToParse;
  41030. while (i < len)
  41031. {
  41032. int start = i;
  41033. // create a whitespace atom unless it starts with non-ws
  41034. if (CharacterFunctions::isWhitespace (text[i])
  41035. && text[i] != '\r'
  41036. && text[i] != '\n')
  41037. {
  41038. while (i < len
  41039. && CharacterFunctions::isWhitespace (text[i])
  41040. && text[i] != '\r'
  41041. && text[i] != '\n')
  41042. {
  41043. ++i;
  41044. }
  41045. }
  41046. else
  41047. {
  41048. if (text[i] == '\r')
  41049. {
  41050. ++i;
  41051. if ((i < len) && (text[i] == '\n'))
  41052. {
  41053. ++start;
  41054. ++i;
  41055. }
  41056. }
  41057. else if (text[i] == '\n')
  41058. {
  41059. ++i;
  41060. }
  41061. else
  41062. {
  41063. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41064. ++i;
  41065. }
  41066. }
  41067. TextAtom* const atom = new TextAtom();
  41068. atom->atomText = String (text + start, i - start);
  41069. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41070. atom->numChars = (uint16) (i - start);
  41071. atoms.add (atom);
  41072. }
  41073. }
  41074. UniformTextSection& operator= (const UniformTextSection& other);
  41075. };
  41076. class TextEditor::Iterator
  41077. {
  41078. public:
  41079. Iterator (const Array <UniformTextSection*>& sections_,
  41080. const float wordWrapWidth_,
  41081. const juce_wchar passwordCharacter_)
  41082. : indexInText (0),
  41083. lineY (0),
  41084. lineHeight (0),
  41085. maxDescent (0),
  41086. atomX (0),
  41087. atomRight (0),
  41088. atom (0),
  41089. currentSection (0),
  41090. sections (sections_),
  41091. sectionIndex (0),
  41092. atomIndex (0),
  41093. wordWrapWidth (wordWrapWidth_),
  41094. passwordCharacter (passwordCharacter_)
  41095. {
  41096. jassert (wordWrapWidth_ > 0);
  41097. if (sections.size() > 0)
  41098. {
  41099. currentSection = sections.getUnchecked (sectionIndex);
  41100. if (currentSection != 0)
  41101. beginNewLine();
  41102. }
  41103. }
  41104. Iterator (const Iterator& other)
  41105. : indexInText (other.indexInText),
  41106. lineY (other.lineY),
  41107. lineHeight (other.lineHeight),
  41108. maxDescent (other.maxDescent),
  41109. atomX (other.atomX),
  41110. atomRight (other.atomRight),
  41111. atom (other.atom),
  41112. currentSection (other.currentSection),
  41113. sections (other.sections),
  41114. sectionIndex (other.sectionIndex),
  41115. atomIndex (other.atomIndex),
  41116. wordWrapWidth (other.wordWrapWidth),
  41117. passwordCharacter (other.passwordCharacter),
  41118. tempAtom (other.tempAtom)
  41119. {
  41120. }
  41121. ~Iterator()
  41122. {
  41123. }
  41124. bool next()
  41125. {
  41126. if (atom == &tempAtom)
  41127. {
  41128. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41129. if (numRemaining > 0)
  41130. {
  41131. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41132. atomX = 0;
  41133. if (tempAtom.numChars > 0)
  41134. lineY += lineHeight;
  41135. indexInText += tempAtom.numChars;
  41136. GlyphArrangement g;
  41137. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41138. int split;
  41139. for (split = 0; split < g.getNumGlyphs(); ++split)
  41140. if (shouldWrap (g.getGlyph (split).getRight()))
  41141. break;
  41142. if (split > 0 && split <= numRemaining)
  41143. {
  41144. tempAtom.numChars = (uint16) split;
  41145. tempAtom.width = g.getGlyph (split - 1).getRight();
  41146. atomRight = atomX + tempAtom.width;
  41147. return true;
  41148. }
  41149. }
  41150. }
  41151. bool forceNewLine = false;
  41152. if (sectionIndex >= sections.size())
  41153. {
  41154. moveToEndOfLastAtom();
  41155. return false;
  41156. }
  41157. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41158. {
  41159. if (atomIndex >= currentSection->getNumAtoms())
  41160. {
  41161. if (++sectionIndex >= sections.size())
  41162. {
  41163. moveToEndOfLastAtom();
  41164. return false;
  41165. }
  41166. atomIndex = 0;
  41167. currentSection = sections.getUnchecked (sectionIndex);
  41168. }
  41169. else
  41170. {
  41171. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41172. if (! lastAtom->isWhitespace())
  41173. {
  41174. // handle the case where the last atom in a section is actually part of the same
  41175. // word as the first atom of the next section...
  41176. float right = atomRight + lastAtom->width;
  41177. float lineHeight2 = lineHeight;
  41178. float maxDescent2 = maxDescent;
  41179. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41180. {
  41181. const UniformTextSection* const s = sections.getUnchecked (section);
  41182. if (s->getNumAtoms() == 0)
  41183. break;
  41184. const TextAtom* const nextAtom = s->getAtom (0);
  41185. if (nextAtom->isWhitespace())
  41186. break;
  41187. right += nextAtom->width;
  41188. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41189. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41190. if (shouldWrap (right))
  41191. {
  41192. lineHeight = lineHeight2;
  41193. maxDescent = maxDescent2;
  41194. forceNewLine = true;
  41195. break;
  41196. }
  41197. if (s->getNumAtoms() > 1)
  41198. break;
  41199. }
  41200. }
  41201. }
  41202. }
  41203. if (atom != 0)
  41204. {
  41205. atomX = atomRight;
  41206. indexInText += atom->numChars;
  41207. if (atom->isNewLine())
  41208. beginNewLine();
  41209. }
  41210. atom = currentSection->getAtom (atomIndex);
  41211. atomRight = atomX + atom->width;
  41212. ++atomIndex;
  41213. if (shouldWrap (atomRight) || forceNewLine)
  41214. {
  41215. if (atom->isWhitespace())
  41216. {
  41217. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41218. atomRight = jmin (atomRight, wordWrapWidth);
  41219. }
  41220. else
  41221. {
  41222. atomRight = atom->width;
  41223. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41224. {
  41225. tempAtom = *atom;
  41226. tempAtom.width = 0;
  41227. tempAtom.numChars = 0;
  41228. atom = &tempAtom;
  41229. if (atomX > 0)
  41230. beginNewLine();
  41231. return next();
  41232. }
  41233. beginNewLine();
  41234. return true;
  41235. }
  41236. }
  41237. return true;
  41238. }
  41239. void beginNewLine()
  41240. {
  41241. atomX = 0;
  41242. lineY += lineHeight;
  41243. int tempSectionIndex = sectionIndex;
  41244. int tempAtomIndex = atomIndex;
  41245. const UniformTextSection* section = sections.getUnchecked (tempSectionIndex);
  41246. lineHeight = section->font.getHeight();
  41247. maxDescent = section->font.getDescent();
  41248. float x = (atom != 0) ? atom->width : 0;
  41249. while (! shouldWrap (x))
  41250. {
  41251. if (tempSectionIndex >= sections.size())
  41252. break;
  41253. bool checkSize = false;
  41254. if (tempAtomIndex >= section->getNumAtoms())
  41255. {
  41256. if (++tempSectionIndex >= sections.size())
  41257. break;
  41258. tempAtomIndex = 0;
  41259. section = sections.getUnchecked (tempSectionIndex);
  41260. checkSize = true;
  41261. }
  41262. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41263. if (nextAtom == 0)
  41264. break;
  41265. x += nextAtom->width;
  41266. if (shouldWrap (x) || nextAtom->isNewLine())
  41267. break;
  41268. if (checkSize)
  41269. {
  41270. lineHeight = jmax (lineHeight, section->font.getHeight());
  41271. maxDescent = jmax (maxDescent, section->font.getDescent());
  41272. }
  41273. ++tempAtomIndex;
  41274. }
  41275. }
  41276. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41277. {
  41278. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41279. {
  41280. if (lastSection != currentSection)
  41281. {
  41282. lastSection = currentSection;
  41283. g.setColour (currentSection->colour);
  41284. g.setFont (currentSection->font);
  41285. }
  41286. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41287. GlyphArrangement ga;
  41288. ga.addLineOfText (currentSection->font,
  41289. atom->getTrimmedText (passwordCharacter),
  41290. atomX,
  41291. (float) roundToInt (lineY + lineHeight - maxDescent));
  41292. ga.draw (g);
  41293. }
  41294. }
  41295. void drawSelection (Graphics& g,
  41296. const Range<int>& selection) const
  41297. {
  41298. const int startX = roundToInt (indexToX (selection.getStart()));
  41299. const int endX = roundToInt (indexToX (selection.getEnd()));
  41300. const int y = roundToInt (lineY);
  41301. const int nextY = roundToInt (lineY + lineHeight);
  41302. g.fillRect (startX, y, endX - startX, nextY - y);
  41303. }
  41304. void drawSelectedText (Graphics& g,
  41305. const Range<int>& selection,
  41306. const Colour& selectedTextColour) const
  41307. {
  41308. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41309. {
  41310. GlyphArrangement ga;
  41311. ga.addLineOfText (currentSection->font,
  41312. atom->getTrimmedText (passwordCharacter),
  41313. atomX,
  41314. (float) roundToInt (lineY + lineHeight - maxDescent));
  41315. if (selection.getEnd() < indexInText + atom->numChars)
  41316. {
  41317. GlyphArrangement ga2 (ga);
  41318. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41319. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41320. g.setColour (currentSection->colour);
  41321. ga2.draw (g);
  41322. }
  41323. if (selection.getStart() > indexInText)
  41324. {
  41325. GlyphArrangement ga2 (ga);
  41326. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41327. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41328. g.setColour (currentSection->colour);
  41329. ga2.draw (g);
  41330. }
  41331. g.setColour (selectedTextColour);
  41332. ga.draw (g);
  41333. }
  41334. }
  41335. float indexToX (const int indexToFind) const
  41336. {
  41337. if (indexToFind <= indexInText)
  41338. return atomX;
  41339. if (indexToFind >= indexInText + atom->numChars)
  41340. return atomRight;
  41341. GlyphArrangement g;
  41342. g.addLineOfText (currentSection->font,
  41343. atom->getText (passwordCharacter),
  41344. atomX, 0.0f);
  41345. if (indexToFind - indexInText >= g.getNumGlyphs())
  41346. return atomRight;
  41347. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41348. }
  41349. int xToIndex (const float xToFind) const
  41350. {
  41351. if (xToFind <= atomX || atom->isNewLine())
  41352. return indexInText;
  41353. if (xToFind >= atomRight)
  41354. return indexInText + atom->numChars;
  41355. GlyphArrangement g;
  41356. g.addLineOfText (currentSection->font,
  41357. atom->getText (passwordCharacter),
  41358. atomX, 0.0f);
  41359. int j;
  41360. for (j = 0; j < g.getNumGlyphs(); ++j)
  41361. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41362. break;
  41363. return indexInText + j;
  41364. }
  41365. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41366. {
  41367. while (next())
  41368. {
  41369. if (indexInText + atom->numChars > index)
  41370. {
  41371. cx = indexToX (index);
  41372. cy = lineY;
  41373. lineHeight_ = lineHeight;
  41374. return true;
  41375. }
  41376. }
  41377. cx = atomX;
  41378. cy = lineY;
  41379. lineHeight_ = lineHeight;
  41380. return false;
  41381. }
  41382. juce_UseDebuggingNewOperator
  41383. int indexInText;
  41384. float lineY, lineHeight, maxDescent;
  41385. float atomX, atomRight;
  41386. const TextAtom* atom;
  41387. const UniformTextSection* currentSection;
  41388. private:
  41389. const Array <UniformTextSection*>& sections;
  41390. int sectionIndex, atomIndex;
  41391. const float wordWrapWidth;
  41392. const juce_wchar passwordCharacter;
  41393. TextAtom tempAtom;
  41394. Iterator& operator= (const Iterator&);
  41395. void moveToEndOfLastAtom()
  41396. {
  41397. if (atom != 0)
  41398. {
  41399. atomX = atomRight;
  41400. if (atom->isNewLine())
  41401. {
  41402. atomX = 0.0f;
  41403. lineY += lineHeight;
  41404. }
  41405. }
  41406. }
  41407. bool shouldWrap (const float x) const
  41408. {
  41409. return (x - 0.0001f) >= wordWrapWidth;
  41410. }
  41411. };
  41412. class TextEditor::InsertAction : public UndoableAction
  41413. {
  41414. TextEditor& owner;
  41415. const String text;
  41416. const int insertIndex, oldCaretPos, newCaretPos;
  41417. const Font font;
  41418. const Colour colour;
  41419. InsertAction (const InsertAction&);
  41420. InsertAction& operator= (const InsertAction&);
  41421. public:
  41422. InsertAction (TextEditor& owner_,
  41423. const String& text_,
  41424. const int insertIndex_,
  41425. const Font& font_,
  41426. const Colour& colour_,
  41427. const int oldCaretPos_,
  41428. const int newCaretPos_)
  41429. : owner (owner_),
  41430. text (text_),
  41431. insertIndex (insertIndex_),
  41432. oldCaretPos (oldCaretPos_),
  41433. newCaretPos (newCaretPos_),
  41434. font (font_),
  41435. colour (colour_)
  41436. {
  41437. }
  41438. ~InsertAction()
  41439. {
  41440. }
  41441. bool perform()
  41442. {
  41443. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  41444. return true;
  41445. }
  41446. bool undo()
  41447. {
  41448. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  41449. return true;
  41450. }
  41451. int getSizeInUnits()
  41452. {
  41453. return text.length() + 16;
  41454. }
  41455. };
  41456. class TextEditor::RemoveAction : public UndoableAction
  41457. {
  41458. TextEditor& owner;
  41459. const Range<int> range;
  41460. const int oldCaretPos, newCaretPos;
  41461. Array <UniformTextSection*> removedSections;
  41462. RemoveAction (const RemoveAction&);
  41463. RemoveAction& operator= (const RemoveAction&);
  41464. public:
  41465. RemoveAction (TextEditor& owner_,
  41466. const Range<int> range_,
  41467. const int oldCaretPos_,
  41468. const int newCaretPos_,
  41469. const Array <UniformTextSection*>& removedSections_)
  41470. : owner (owner_),
  41471. range (range_),
  41472. oldCaretPos (oldCaretPos_),
  41473. newCaretPos (newCaretPos_),
  41474. removedSections (removedSections_)
  41475. {
  41476. }
  41477. ~RemoveAction()
  41478. {
  41479. for (int i = removedSections.size(); --i >= 0;)
  41480. {
  41481. UniformTextSection* const section = removedSections.getUnchecked (i);
  41482. section->clear();
  41483. delete section;
  41484. }
  41485. }
  41486. bool perform()
  41487. {
  41488. owner.remove (range, 0, newCaretPos);
  41489. return true;
  41490. }
  41491. bool undo()
  41492. {
  41493. owner.reinsert (range.getStart(), removedSections);
  41494. owner.moveCursorTo (oldCaretPos, false);
  41495. return true;
  41496. }
  41497. int getSizeInUnits()
  41498. {
  41499. int n = 0;
  41500. for (int i = removedSections.size(); --i >= 0;)
  41501. n += removedSections.getUnchecked (i)->getTotalLength();
  41502. return n + 16;
  41503. }
  41504. };
  41505. class TextEditor::TextHolderComponent : public Component,
  41506. public Timer,
  41507. public Value::Listener
  41508. {
  41509. public:
  41510. TextHolderComponent (TextEditor& owner_)
  41511. : owner (owner_)
  41512. {
  41513. setWantsKeyboardFocus (false);
  41514. setInterceptsMouseClicks (false, true);
  41515. owner.getTextValue().addListener (this);
  41516. }
  41517. ~TextHolderComponent()
  41518. {
  41519. owner.getTextValue().removeListener (this);
  41520. }
  41521. void paint (Graphics& g)
  41522. {
  41523. owner.drawContent (g);
  41524. }
  41525. void timerCallback()
  41526. {
  41527. owner.timerCallbackInt();
  41528. }
  41529. const MouseCursor getMouseCursor()
  41530. {
  41531. return owner.getMouseCursor();
  41532. }
  41533. void valueChanged (Value&)
  41534. {
  41535. owner.textWasChangedByValue();
  41536. }
  41537. private:
  41538. TextEditor& owner;
  41539. TextHolderComponent (const TextHolderComponent&);
  41540. TextHolderComponent& operator= (const TextHolderComponent&);
  41541. };
  41542. class TextEditorViewport : public Viewport
  41543. {
  41544. public:
  41545. TextEditorViewport (TextEditor* const owner_)
  41546. : owner (owner_),
  41547. lastWordWrapWidth (0)
  41548. {
  41549. }
  41550. ~TextEditorViewport()
  41551. {
  41552. }
  41553. void visibleAreaChanged (int, int, int, int)
  41554. {
  41555. const float wordWrapWidth = owner->getWordWrapWidth();
  41556. if (wordWrapWidth != lastWordWrapWidth)
  41557. {
  41558. lastWordWrapWidth = wordWrapWidth;
  41559. owner->updateTextHolderSize();
  41560. }
  41561. }
  41562. private:
  41563. TextEditor* const owner;
  41564. float lastWordWrapWidth;
  41565. TextEditorViewport (const TextEditorViewport&);
  41566. TextEditorViewport& operator= (const TextEditorViewport&);
  41567. };
  41568. namespace TextEditorDefs
  41569. {
  41570. const int flashSpeedIntervalMs = 380;
  41571. const int textChangeMessageId = 0x10003001;
  41572. const int returnKeyMessageId = 0x10003002;
  41573. const int escapeKeyMessageId = 0x10003003;
  41574. const int focusLossMessageId = 0x10003004;
  41575. const int maxActionsPerTransaction = 100;
  41576. }
  41577. TextEditor::TextEditor (const String& name,
  41578. const juce_wchar passwordCharacter_)
  41579. : Component (name),
  41580. borderSize (1, 1, 1, 3),
  41581. readOnly (false),
  41582. multiline (false),
  41583. wordWrap (false),
  41584. returnKeyStartsNewLine (false),
  41585. caretVisible (true),
  41586. popupMenuEnabled (true),
  41587. selectAllTextWhenFocused (false),
  41588. scrollbarVisible (true),
  41589. wasFocused (false),
  41590. caretFlashState (true),
  41591. keepCursorOnScreen (true),
  41592. tabKeyUsed (false),
  41593. menuActive (false),
  41594. valueTextNeedsUpdating (false),
  41595. cursorX (0),
  41596. cursorY (0),
  41597. cursorHeight (0),
  41598. maxTextLength (0),
  41599. leftIndent (4),
  41600. topIndent (4),
  41601. lastTransactionTime (0),
  41602. currentFont (14.0f),
  41603. totalNumChars (0),
  41604. caretPosition (0),
  41605. passwordCharacter (passwordCharacter_),
  41606. dragType (notDragging)
  41607. {
  41608. setOpaque (true);
  41609. addAndMakeVisible (viewport = new TextEditorViewport (this));
  41610. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  41611. viewport->setWantsKeyboardFocus (false);
  41612. viewport->setScrollBarsShown (false, false);
  41613. setMouseCursor (MouseCursor::IBeamCursor);
  41614. setWantsKeyboardFocus (true);
  41615. }
  41616. TextEditor::~TextEditor()
  41617. {
  41618. textValue.referTo (Value());
  41619. clearInternal (0);
  41620. viewport = 0;
  41621. textHolder = 0;
  41622. }
  41623. void TextEditor::newTransaction()
  41624. {
  41625. lastTransactionTime = Time::getApproximateMillisecondCounter();
  41626. undoManager.beginNewTransaction();
  41627. }
  41628. void TextEditor::doUndoRedo (const bool isRedo)
  41629. {
  41630. if (! isReadOnly())
  41631. {
  41632. if (isRedo ? undoManager.redo()
  41633. : undoManager.undo())
  41634. {
  41635. scrollToMakeSureCursorIsVisible();
  41636. repaint();
  41637. textChanged();
  41638. }
  41639. }
  41640. }
  41641. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  41642. const bool shouldWordWrap)
  41643. {
  41644. multiline = shouldBeMultiLine;
  41645. wordWrap = shouldWordWrap && shouldBeMultiLine;
  41646. setScrollbarsShown (scrollbarVisible);
  41647. viewport->setViewPosition (0, 0);
  41648. resized();
  41649. scrollToMakeSureCursorIsVisible();
  41650. }
  41651. bool TextEditor::isMultiLine() const
  41652. {
  41653. return multiline;
  41654. }
  41655. void TextEditor::setScrollbarsShown (bool enabled)
  41656. {
  41657. scrollbarVisible = enabled;
  41658. enabled = enabled && isMultiLine();
  41659. viewport->setScrollBarsShown (enabled, enabled);
  41660. }
  41661. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  41662. {
  41663. readOnly = shouldBeReadOnly;
  41664. enablementChanged();
  41665. }
  41666. bool TextEditor::isReadOnly() const
  41667. {
  41668. return readOnly || ! isEnabled();
  41669. }
  41670. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  41671. {
  41672. returnKeyStartsNewLine = shouldStartNewLine;
  41673. }
  41674. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  41675. {
  41676. tabKeyUsed = shouldTabKeyBeUsed;
  41677. }
  41678. void TextEditor::setPopupMenuEnabled (const bool b)
  41679. {
  41680. popupMenuEnabled = b;
  41681. }
  41682. void TextEditor::setSelectAllWhenFocused (const bool b)
  41683. {
  41684. selectAllTextWhenFocused = b;
  41685. }
  41686. const Font TextEditor::getFont() const
  41687. {
  41688. return currentFont;
  41689. }
  41690. void TextEditor::setFont (const Font& newFont)
  41691. {
  41692. currentFont = newFont;
  41693. scrollToMakeSureCursorIsVisible();
  41694. }
  41695. void TextEditor::applyFontToAllText (const Font& newFont)
  41696. {
  41697. currentFont = newFont;
  41698. const Colour overallColour (findColour (textColourId));
  41699. for (int i = sections.size(); --i >= 0;)
  41700. {
  41701. UniformTextSection* const uts = sections.getUnchecked (i);
  41702. uts->setFont (newFont, passwordCharacter);
  41703. uts->colour = overallColour;
  41704. }
  41705. coalesceSimilarSections();
  41706. updateTextHolderSize();
  41707. scrollToMakeSureCursorIsVisible();
  41708. repaint();
  41709. }
  41710. void TextEditor::colourChanged()
  41711. {
  41712. setOpaque (findColour (backgroundColourId).isOpaque());
  41713. repaint();
  41714. }
  41715. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  41716. {
  41717. caretVisible = shouldCaretBeVisible;
  41718. if (shouldCaretBeVisible)
  41719. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41720. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  41721. : MouseCursor::NormalCursor);
  41722. }
  41723. void TextEditor::setInputRestrictions (const int maxLen,
  41724. const String& chars)
  41725. {
  41726. maxTextLength = jmax (0, maxLen);
  41727. allowedCharacters = chars;
  41728. }
  41729. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  41730. {
  41731. textToShowWhenEmpty = text;
  41732. colourForTextWhenEmpty = colourToUse;
  41733. }
  41734. void TextEditor::setPasswordCharacter (const juce_wchar newPasswordCharacter)
  41735. {
  41736. if (passwordCharacter != newPasswordCharacter)
  41737. {
  41738. passwordCharacter = newPasswordCharacter;
  41739. resized();
  41740. repaint();
  41741. }
  41742. }
  41743. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  41744. {
  41745. viewport->setScrollBarThickness (newThicknessPixels);
  41746. }
  41747. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  41748. {
  41749. viewport->setScrollBarButtonVisibility (buttonsVisible);
  41750. }
  41751. void TextEditor::clear()
  41752. {
  41753. clearInternal (0);
  41754. updateTextHolderSize();
  41755. undoManager.clearUndoHistory();
  41756. }
  41757. void TextEditor::setText (const String& newText,
  41758. const bool sendTextChangeMessage)
  41759. {
  41760. const int newLength = newText.length();
  41761. if (newLength != getTotalNumChars() || getText() != newText)
  41762. {
  41763. const int oldCursorPos = caretPosition;
  41764. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  41765. clearInternal (0);
  41766. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  41767. // if you're adding text with line-feeds to a single-line text editor, it
  41768. // ain't gonna look right!
  41769. jassert (multiline || ! newText.containsAnyOf ("\r\n"));
  41770. if (cursorWasAtEnd && ! isMultiLine())
  41771. moveCursorTo (getTotalNumChars(), false);
  41772. else
  41773. moveCursorTo (oldCursorPos, false);
  41774. if (sendTextChangeMessage)
  41775. textChanged();
  41776. repaint();
  41777. }
  41778. updateTextHolderSize();
  41779. scrollToMakeSureCursorIsVisible();
  41780. undoManager.clearUndoHistory();
  41781. }
  41782. Value& TextEditor::getTextValue()
  41783. {
  41784. if (valueTextNeedsUpdating)
  41785. {
  41786. valueTextNeedsUpdating = false;
  41787. textValue = getText();
  41788. }
  41789. return textValue;
  41790. }
  41791. void TextEditor::textWasChangedByValue()
  41792. {
  41793. if (textValue.getValueSource().getReferenceCount() > 1)
  41794. setText (textValue.getValue());
  41795. }
  41796. void TextEditor::textChanged()
  41797. {
  41798. updateTextHolderSize();
  41799. postCommandMessage (TextEditorDefs::textChangeMessageId);
  41800. if (textValue.getValueSource().getReferenceCount() > 1)
  41801. {
  41802. valueTextNeedsUpdating = false;
  41803. textValue = getText();
  41804. }
  41805. }
  41806. void TextEditor::returnPressed()
  41807. {
  41808. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  41809. }
  41810. void TextEditor::escapePressed()
  41811. {
  41812. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  41813. }
  41814. void TextEditor::addListener (TextEditorListener* const newListener)
  41815. {
  41816. listeners.add (newListener);
  41817. }
  41818. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  41819. {
  41820. listeners.remove (listenerToRemove);
  41821. }
  41822. void TextEditor::timerCallbackInt()
  41823. {
  41824. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  41825. if (caretFlashState != newState)
  41826. {
  41827. caretFlashState = newState;
  41828. if (caretFlashState)
  41829. wasFocused = true;
  41830. if (caretVisible
  41831. && hasKeyboardFocus (false)
  41832. && ! isReadOnly())
  41833. {
  41834. repaintCaret();
  41835. }
  41836. }
  41837. const unsigned int now = Time::getApproximateMillisecondCounter();
  41838. if (now > lastTransactionTime + 200)
  41839. newTransaction();
  41840. }
  41841. void TextEditor::repaintCaret()
  41842. {
  41843. if (! findColour (caretColourId).isTransparent())
  41844. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  41845. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  41846. 4,
  41847. roundToInt (cursorHeight) + 2);
  41848. }
  41849. void TextEditor::repaintText (const Range<int>& range)
  41850. {
  41851. if (! range.isEmpty())
  41852. {
  41853. float x = 0, y = 0, lh = currentFont.getHeight();
  41854. const float wordWrapWidth = getWordWrapWidth();
  41855. if (wordWrapWidth > 0)
  41856. {
  41857. Iterator i (sections, wordWrapWidth, passwordCharacter);
  41858. i.getCharPosition (range.getStart(), x, y, lh);
  41859. const int y1 = (int) y;
  41860. int y2;
  41861. if (range.getEnd() >= getTotalNumChars())
  41862. {
  41863. y2 = textHolder->getHeight();
  41864. }
  41865. else
  41866. {
  41867. i.getCharPosition (range.getEnd(), x, y, lh);
  41868. y2 = (int) (y + lh * 2.0f);
  41869. }
  41870. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  41871. }
  41872. }
  41873. }
  41874. void TextEditor::moveCaret (int newCaretPos)
  41875. {
  41876. if (newCaretPos < 0)
  41877. newCaretPos = 0;
  41878. else if (newCaretPos > getTotalNumChars())
  41879. newCaretPos = getTotalNumChars();
  41880. if (newCaretPos != getCaretPosition())
  41881. {
  41882. repaintCaret();
  41883. caretFlashState = true;
  41884. caretPosition = newCaretPos;
  41885. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  41886. scrollToMakeSureCursorIsVisible();
  41887. repaintCaret();
  41888. }
  41889. }
  41890. void TextEditor::setCaretPosition (const int newIndex)
  41891. {
  41892. moveCursorTo (newIndex, false);
  41893. }
  41894. int TextEditor::getCaretPosition() const
  41895. {
  41896. return caretPosition;
  41897. }
  41898. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  41899. const int desiredCaretY)
  41900. {
  41901. updateCaretPosition();
  41902. int vx = roundToInt (cursorX) - desiredCaretX;
  41903. int vy = roundToInt (cursorY) - desiredCaretY;
  41904. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  41905. {
  41906. vx += desiredCaretX - proportionOfWidth (0.2f);
  41907. }
  41908. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  41909. {
  41910. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  41911. }
  41912. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  41913. if (! isMultiLine())
  41914. {
  41915. vy = viewport->getViewPositionY();
  41916. }
  41917. else
  41918. {
  41919. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  41920. const int curH = roundToInt (cursorHeight);
  41921. if (desiredCaretY < 0)
  41922. {
  41923. vy = jmax (0, desiredCaretY + vy);
  41924. }
  41925. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  41926. {
  41927. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  41928. }
  41929. }
  41930. viewport->setViewPosition (vx, vy);
  41931. }
  41932. const Rectangle<int> TextEditor::getCaretRectangle()
  41933. {
  41934. updateCaretPosition();
  41935. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  41936. roundToInt (cursorY) - viewport->getY(),
  41937. 1, roundToInt (cursorHeight));
  41938. }
  41939. float TextEditor::getWordWrapWidth() const
  41940. {
  41941. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  41942. : 1.0e10f;
  41943. }
  41944. void TextEditor::updateTextHolderSize()
  41945. {
  41946. const float wordWrapWidth = getWordWrapWidth();
  41947. if (wordWrapWidth > 0)
  41948. {
  41949. float maxWidth = 0.0f;
  41950. Iterator i (sections, wordWrapWidth, passwordCharacter);
  41951. while (i.next())
  41952. maxWidth = jmax (maxWidth, i.atomRight);
  41953. const int w = leftIndent + roundToInt (maxWidth);
  41954. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  41955. currentFont.getHeight()));
  41956. textHolder->setSize (w + 1, h + 1);
  41957. }
  41958. }
  41959. int TextEditor::getTextWidth() const
  41960. {
  41961. return textHolder->getWidth();
  41962. }
  41963. int TextEditor::getTextHeight() const
  41964. {
  41965. return textHolder->getHeight();
  41966. }
  41967. void TextEditor::setIndents (const int newLeftIndent,
  41968. const int newTopIndent)
  41969. {
  41970. leftIndent = newLeftIndent;
  41971. topIndent = newTopIndent;
  41972. }
  41973. void TextEditor::setBorder (const BorderSize& border)
  41974. {
  41975. borderSize = border;
  41976. resized();
  41977. }
  41978. const BorderSize TextEditor::getBorder() const
  41979. {
  41980. return borderSize;
  41981. }
  41982. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  41983. {
  41984. keepCursorOnScreen = shouldScrollToShowCursor;
  41985. }
  41986. void TextEditor::updateCaretPosition()
  41987. {
  41988. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  41989. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  41990. }
  41991. void TextEditor::scrollToMakeSureCursorIsVisible()
  41992. {
  41993. updateCaretPosition();
  41994. if (keepCursorOnScreen)
  41995. {
  41996. int x = viewport->getViewPositionX();
  41997. int y = viewport->getViewPositionY();
  41998. const int relativeCursorX = roundToInt (cursorX) - x;
  41999. const int relativeCursorY = roundToInt (cursorY) - y;
  42000. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42001. {
  42002. x += relativeCursorX - proportionOfWidth (0.2f);
  42003. }
  42004. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42005. {
  42006. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42007. }
  42008. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42009. if (! isMultiLine())
  42010. {
  42011. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42012. }
  42013. else
  42014. {
  42015. const int curH = roundToInt (cursorHeight);
  42016. if (relativeCursorY < 0)
  42017. {
  42018. y = jmax (0, relativeCursorY + y);
  42019. }
  42020. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42021. {
  42022. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42023. }
  42024. }
  42025. viewport->setViewPosition (x, y);
  42026. }
  42027. }
  42028. void TextEditor::moveCursorTo (const int newPosition,
  42029. const bool isSelecting)
  42030. {
  42031. if (isSelecting)
  42032. {
  42033. moveCaret (newPosition);
  42034. const Range<int> oldSelection (selection);
  42035. if (dragType == notDragging)
  42036. {
  42037. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42038. dragType = draggingSelectionStart;
  42039. else
  42040. dragType = draggingSelectionEnd;
  42041. }
  42042. if (dragType == draggingSelectionStart)
  42043. {
  42044. if (getCaretPosition() >= selection.getEnd())
  42045. dragType = draggingSelectionEnd;
  42046. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42047. }
  42048. else
  42049. {
  42050. if (getCaretPosition() < selection.getStart())
  42051. dragType = draggingSelectionStart;
  42052. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42053. }
  42054. repaintText (selection.getUnionWith (oldSelection));
  42055. }
  42056. else
  42057. {
  42058. dragType = notDragging;
  42059. repaintText (selection);
  42060. moveCaret (newPosition);
  42061. selection = Range<int>::emptyRange (getCaretPosition());
  42062. }
  42063. }
  42064. int TextEditor::getTextIndexAt (const int x,
  42065. const int y)
  42066. {
  42067. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42068. (float) (y + viewport->getViewPositionY() - topIndent));
  42069. }
  42070. void TextEditor::insertTextAtCaret (const String& newText_)
  42071. {
  42072. String newText (newText_);
  42073. if (allowedCharacters.isNotEmpty())
  42074. newText = newText.retainCharacters (allowedCharacters);
  42075. if ((! returnKeyStartsNewLine) && newText == "\n")
  42076. {
  42077. returnPressed();
  42078. return;
  42079. }
  42080. if (! isMultiLine())
  42081. newText = newText.replaceCharacters ("\r\n", " ");
  42082. else
  42083. newText = newText.replace ("\r\n", "\n");
  42084. const int newCaretPos = selection.getStart() + newText.length();
  42085. const int insertIndex = selection.getStart();
  42086. remove (selection, getUndoManager(),
  42087. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42088. if (maxTextLength > 0)
  42089. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42090. if (newText.isNotEmpty())
  42091. insert (newText,
  42092. insertIndex,
  42093. currentFont,
  42094. findColour (textColourId),
  42095. getUndoManager(),
  42096. newCaretPos);
  42097. textChanged();
  42098. }
  42099. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42100. {
  42101. moveCursorTo (newSelection.getStart(), false);
  42102. moveCursorTo (newSelection.getEnd(), true);
  42103. }
  42104. void TextEditor::copy()
  42105. {
  42106. if (passwordCharacter == 0)
  42107. {
  42108. const String selection (getHighlightedText());
  42109. if (selection.isNotEmpty())
  42110. SystemClipboard::copyTextToClipboard (selection);
  42111. }
  42112. }
  42113. void TextEditor::paste()
  42114. {
  42115. if (! isReadOnly())
  42116. {
  42117. const String clip (SystemClipboard::getTextFromClipboard());
  42118. if (clip.isNotEmpty())
  42119. insertTextAtCaret (clip);
  42120. }
  42121. }
  42122. void TextEditor::cut()
  42123. {
  42124. if (! isReadOnly())
  42125. {
  42126. moveCaret (selection.getEnd());
  42127. insertTextAtCaret (String::empty);
  42128. }
  42129. }
  42130. void TextEditor::drawContent (Graphics& g)
  42131. {
  42132. const float wordWrapWidth = getWordWrapWidth();
  42133. if (wordWrapWidth > 0)
  42134. {
  42135. g.setOrigin (leftIndent, topIndent);
  42136. const Rectangle<int> clip (g.getClipBounds());
  42137. Colour selectedTextColour;
  42138. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42139. while (i.lineY + 200.0 < clip.getY() && i.next())
  42140. {}
  42141. if (! selection.isEmpty())
  42142. {
  42143. g.setColour (findColour (highlightColourId)
  42144. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42145. selectedTextColour = findColour (highlightedTextColourId);
  42146. Iterator i2 (i);
  42147. while (i2.next() && i2.lineY < clip.getBottom())
  42148. {
  42149. if (i2.lineY + i2.lineHeight >= clip.getY()
  42150. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42151. {
  42152. i2.drawSelection (g, selection);
  42153. }
  42154. }
  42155. }
  42156. const UniformTextSection* lastSection = 0;
  42157. while (i.next() && i.lineY < clip.getBottom())
  42158. {
  42159. if (i.lineY + i.lineHeight >= clip.getY())
  42160. {
  42161. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42162. {
  42163. i.drawSelectedText (g, selection, selectedTextColour);
  42164. lastSection = 0;
  42165. }
  42166. else
  42167. {
  42168. i.draw (g, lastSection);
  42169. }
  42170. }
  42171. }
  42172. }
  42173. }
  42174. void TextEditor::paint (Graphics& g)
  42175. {
  42176. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42177. }
  42178. void TextEditor::paintOverChildren (Graphics& g)
  42179. {
  42180. if (caretFlashState
  42181. && hasKeyboardFocus (false)
  42182. && caretVisible
  42183. && ! isReadOnly())
  42184. {
  42185. g.setColour (findColour (caretColourId));
  42186. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42187. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42188. 2.0f, cursorHeight);
  42189. }
  42190. if (textToShowWhenEmpty.isNotEmpty()
  42191. && (! hasKeyboardFocus (false))
  42192. && getTotalNumChars() == 0)
  42193. {
  42194. g.setColour (colourForTextWhenEmpty);
  42195. g.setFont (getFont());
  42196. if (isMultiLine())
  42197. {
  42198. g.drawText (textToShowWhenEmpty,
  42199. 0, 0, getWidth(), getHeight(),
  42200. Justification::centred, true);
  42201. }
  42202. else
  42203. {
  42204. g.drawText (textToShowWhenEmpty,
  42205. leftIndent, topIndent,
  42206. viewport->getWidth() - leftIndent,
  42207. viewport->getHeight() - topIndent,
  42208. Justification::centredLeft, true);
  42209. }
  42210. }
  42211. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42212. }
  42213. void TextEditor::mouseDown (const MouseEvent& e)
  42214. {
  42215. beginDragAutoRepeat (100);
  42216. newTransaction();
  42217. if (wasFocused || ! selectAllTextWhenFocused)
  42218. {
  42219. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42220. {
  42221. moveCursorTo (getTextIndexAt (e.x, e.y),
  42222. e.mods.isShiftDown());
  42223. }
  42224. else
  42225. {
  42226. PopupMenu m;
  42227. m.setLookAndFeel (&getLookAndFeel());
  42228. addPopupMenuItems (m, &e);
  42229. menuActive = true;
  42230. const int result = m.show();
  42231. menuActive = false;
  42232. if (result != 0)
  42233. performPopupMenuAction (result);
  42234. }
  42235. }
  42236. }
  42237. void TextEditor::mouseDrag (const MouseEvent& e)
  42238. {
  42239. if (wasFocused || ! selectAllTextWhenFocused)
  42240. {
  42241. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42242. {
  42243. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42244. }
  42245. }
  42246. }
  42247. void TextEditor::mouseUp (const MouseEvent& e)
  42248. {
  42249. newTransaction();
  42250. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42251. if (wasFocused || ! selectAllTextWhenFocused)
  42252. {
  42253. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42254. {
  42255. moveCaret (getTextIndexAt (e.x, e.y));
  42256. }
  42257. }
  42258. wasFocused = true;
  42259. }
  42260. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42261. {
  42262. int tokenEnd = getTextIndexAt (e.x, e.y);
  42263. int tokenStart = tokenEnd;
  42264. if (e.getNumberOfClicks() > 3)
  42265. {
  42266. tokenStart = 0;
  42267. tokenEnd = getTotalNumChars();
  42268. }
  42269. else
  42270. {
  42271. const String t (getText());
  42272. const int totalLength = getTotalNumChars();
  42273. while (tokenEnd < totalLength)
  42274. {
  42275. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42276. ++tokenEnd;
  42277. else
  42278. break;
  42279. }
  42280. tokenStart = tokenEnd;
  42281. while (tokenStart > 0)
  42282. {
  42283. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42284. --tokenStart;
  42285. else
  42286. break;
  42287. }
  42288. if (e.getNumberOfClicks() > 2)
  42289. {
  42290. while (tokenEnd < totalLength)
  42291. {
  42292. if (t [tokenEnd] != '\r' && t [tokenEnd] != '\n')
  42293. ++tokenEnd;
  42294. else
  42295. break;
  42296. }
  42297. while (tokenStart > 0)
  42298. {
  42299. if (t [tokenStart - 1] != '\r' && t [tokenStart - 1] != '\n')
  42300. --tokenStart;
  42301. else
  42302. break;
  42303. }
  42304. }
  42305. }
  42306. moveCursorTo (tokenEnd, false);
  42307. moveCursorTo (tokenStart, true);
  42308. }
  42309. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42310. {
  42311. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42312. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42313. }
  42314. bool TextEditor::keyPressed (const KeyPress& key)
  42315. {
  42316. if (isReadOnly() && key != KeyPress ('c', ModifierKeys::commandModifier, 0))
  42317. return false;
  42318. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42319. if (key.isKeyCode (KeyPress::leftKey)
  42320. || key.isKeyCode (KeyPress::upKey))
  42321. {
  42322. newTransaction();
  42323. int newPos;
  42324. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42325. newPos = indexAtPosition (cursorX, cursorY - 1);
  42326. else if (moveInWholeWordSteps)
  42327. newPos = findWordBreakBefore (getCaretPosition());
  42328. else
  42329. newPos = getCaretPosition() - 1;
  42330. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42331. }
  42332. else if (key.isKeyCode (KeyPress::rightKey)
  42333. || key.isKeyCode (KeyPress::downKey))
  42334. {
  42335. newTransaction();
  42336. int newPos;
  42337. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42338. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42339. else if (moveInWholeWordSteps)
  42340. newPos = findWordBreakAfter (getCaretPosition());
  42341. else
  42342. newPos = getCaretPosition() + 1;
  42343. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42344. }
  42345. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42346. {
  42347. newTransaction();
  42348. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42349. key.getModifiers().isShiftDown());
  42350. }
  42351. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42352. {
  42353. newTransaction();
  42354. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42355. key.getModifiers().isShiftDown());
  42356. }
  42357. else if (key.isKeyCode (KeyPress::homeKey))
  42358. {
  42359. newTransaction();
  42360. if (isMultiLine() && ! moveInWholeWordSteps)
  42361. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42362. key.getModifiers().isShiftDown());
  42363. else
  42364. moveCursorTo (0, key.getModifiers().isShiftDown());
  42365. }
  42366. else if (key.isKeyCode (KeyPress::endKey))
  42367. {
  42368. newTransaction();
  42369. if (isMultiLine() && ! moveInWholeWordSteps)
  42370. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42371. key.getModifiers().isShiftDown());
  42372. else
  42373. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42374. }
  42375. else if (key.isKeyCode (KeyPress::backspaceKey))
  42376. {
  42377. if (moveInWholeWordSteps)
  42378. {
  42379. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42380. }
  42381. else
  42382. {
  42383. if (selection.isEmpty() && selection.getStart() > 0)
  42384. selection.setStart (selection.getEnd() - 1);
  42385. }
  42386. cut();
  42387. }
  42388. else if (key.isKeyCode (KeyPress::deleteKey))
  42389. {
  42390. if (key.getModifiers().isShiftDown())
  42391. copy();
  42392. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42393. selection.setEnd (selection.getStart() + 1);
  42394. cut();
  42395. }
  42396. else if (key == KeyPress ('c', ModifierKeys::commandModifier, 0)
  42397. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42398. {
  42399. newTransaction();
  42400. copy();
  42401. }
  42402. else if (key == KeyPress ('x', ModifierKeys::commandModifier, 0))
  42403. {
  42404. newTransaction();
  42405. copy();
  42406. cut();
  42407. }
  42408. else if (key == KeyPress ('v', ModifierKeys::commandModifier, 0)
  42409. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42410. {
  42411. newTransaction();
  42412. paste();
  42413. }
  42414. else if (key == KeyPress ('z', ModifierKeys::commandModifier, 0))
  42415. {
  42416. newTransaction();
  42417. doUndoRedo (false);
  42418. }
  42419. else if (key == KeyPress ('y', ModifierKeys::commandModifier, 0))
  42420. {
  42421. newTransaction();
  42422. doUndoRedo (true);
  42423. }
  42424. else if (key == KeyPress ('a', ModifierKeys::commandModifier, 0))
  42425. {
  42426. newTransaction();
  42427. moveCursorTo (getTotalNumChars(), false);
  42428. moveCursorTo (0, true);
  42429. }
  42430. else if (key == KeyPress::returnKey)
  42431. {
  42432. newTransaction();
  42433. insertTextAtCaret ("\n");
  42434. }
  42435. else if (key.isKeyCode (KeyPress::escapeKey))
  42436. {
  42437. newTransaction();
  42438. moveCursorTo (getCaretPosition(), false);
  42439. escapePressed();
  42440. }
  42441. else if (key.getTextCharacter() >= ' '
  42442. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  42443. {
  42444. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  42445. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42446. }
  42447. else
  42448. {
  42449. return false;
  42450. }
  42451. return true;
  42452. }
  42453. bool TextEditor::keyStateChanged (const bool isKeyDown)
  42454. {
  42455. if (! isKeyDown)
  42456. return false;
  42457. #if JUCE_WIN32
  42458. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  42459. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  42460. #endif
  42461. // (overridden to avoid forwarding key events to the parent)
  42462. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  42463. }
  42464. const int baseMenuItemID = 0x7fff0000;
  42465. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  42466. {
  42467. const bool writable = ! isReadOnly();
  42468. if (passwordCharacter == 0)
  42469. {
  42470. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  42471. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  42472. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  42473. }
  42474. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  42475. m.addSeparator();
  42476. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  42477. m.addSeparator();
  42478. if (getUndoManager() != 0)
  42479. {
  42480. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  42481. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  42482. }
  42483. }
  42484. void TextEditor::performPopupMenuAction (const int menuItemID)
  42485. {
  42486. switch (menuItemID)
  42487. {
  42488. case baseMenuItemID + 1:
  42489. copy();
  42490. cut();
  42491. break;
  42492. case baseMenuItemID + 2:
  42493. copy();
  42494. break;
  42495. case baseMenuItemID + 3:
  42496. paste();
  42497. break;
  42498. case baseMenuItemID + 4:
  42499. cut();
  42500. break;
  42501. case baseMenuItemID + 5:
  42502. moveCursorTo (getTotalNumChars(), false);
  42503. moveCursorTo (0, true);
  42504. break;
  42505. case baseMenuItemID + 6:
  42506. doUndoRedo (false);
  42507. break;
  42508. case baseMenuItemID + 7:
  42509. doUndoRedo (true);
  42510. break;
  42511. default:
  42512. break;
  42513. }
  42514. }
  42515. void TextEditor::focusGained (FocusChangeType)
  42516. {
  42517. newTransaction();
  42518. caretFlashState = true;
  42519. if (selectAllTextWhenFocused)
  42520. {
  42521. moveCursorTo (0, false);
  42522. moveCursorTo (getTotalNumChars(), true);
  42523. }
  42524. repaint();
  42525. if (caretVisible)
  42526. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42527. ComponentPeer* const peer = getPeer();
  42528. if (peer != 0 && ! isReadOnly())
  42529. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  42530. }
  42531. void TextEditor::focusLost (FocusChangeType)
  42532. {
  42533. newTransaction();
  42534. wasFocused = false;
  42535. textHolder->stopTimer();
  42536. caretFlashState = false;
  42537. postCommandMessage (TextEditorDefs::focusLossMessageId);
  42538. repaint();
  42539. }
  42540. void TextEditor::resized()
  42541. {
  42542. viewport->setBoundsInset (borderSize);
  42543. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  42544. updateTextHolderSize();
  42545. if (! isMultiLine())
  42546. {
  42547. scrollToMakeSureCursorIsVisible();
  42548. }
  42549. else
  42550. {
  42551. updateCaretPosition();
  42552. }
  42553. }
  42554. void TextEditor::handleCommandMessage (const int commandId)
  42555. {
  42556. Component::BailOutChecker checker (this);
  42557. switch (commandId)
  42558. {
  42559. case TextEditorDefs::textChangeMessageId:
  42560. listeners.callChecked (checker, &TextEditorListener::textEditorTextChanged, (TextEditor&) *this);
  42561. break;
  42562. case TextEditorDefs::returnKeyMessageId:
  42563. listeners.callChecked (checker, &TextEditorListener::textEditorReturnKeyPressed, (TextEditor&) *this);
  42564. break;
  42565. case TextEditorDefs::escapeKeyMessageId:
  42566. listeners.callChecked (checker, &TextEditorListener::textEditorEscapeKeyPressed, (TextEditor&) *this);
  42567. break;
  42568. case TextEditorDefs::focusLossMessageId:
  42569. listeners.callChecked (checker, &TextEditorListener::textEditorFocusLost, (TextEditor&) *this);
  42570. break;
  42571. default:
  42572. jassertfalse
  42573. break;
  42574. }
  42575. }
  42576. void TextEditor::enablementChanged()
  42577. {
  42578. setMouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  42579. : MouseCursor::IBeamCursor);
  42580. repaint();
  42581. }
  42582. UndoManager* TextEditor::getUndoManager() throw()
  42583. {
  42584. return isReadOnly() ? &undoManager : 0;
  42585. }
  42586. void TextEditor::clearInternal (UndoManager* const um)
  42587. {
  42588. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  42589. }
  42590. void TextEditor::insert (const String& text,
  42591. const int insertIndex,
  42592. const Font& font,
  42593. const Colour& colour,
  42594. UndoManager* const um,
  42595. const int caretPositionToMoveTo)
  42596. {
  42597. if (text.isNotEmpty())
  42598. {
  42599. if (um != 0)
  42600. {
  42601. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42602. newTransaction();
  42603. um->perform (new InsertAction (*this, text, insertIndex, font, colour,
  42604. caretPosition, caretPositionToMoveTo));
  42605. }
  42606. else
  42607. {
  42608. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  42609. // a line gets moved due to word wrap
  42610. int index = 0;
  42611. int nextIndex = 0;
  42612. for (int i = 0; i < sections.size(); ++i)
  42613. {
  42614. nextIndex = index + sections.getUnchecked (i)->getTotalLength();
  42615. if (insertIndex == index)
  42616. {
  42617. sections.insert (i, new UniformTextSection (text,
  42618. font, colour,
  42619. passwordCharacter));
  42620. break;
  42621. }
  42622. else if (insertIndex > index && insertIndex < nextIndex)
  42623. {
  42624. splitSection (i, insertIndex - index);
  42625. sections.insert (i + 1, new UniformTextSection (text,
  42626. font, colour,
  42627. passwordCharacter));
  42628. break;
  42629. }
  42630. index = nextIndex;
  42631. }
  42632. if (nextIndex == insertIndex)
  42633. sections.add (new UniformTextSection (text,
  42634. font, colour,
  42635. passwordCharacter));
  42636. coalesceSimilarSections();
  42637. totalNumChars = -1;
  42638. valueTextNeedsUpdating = true;
  42639. moveCursorTo (caretPositionToMoveTo, false);
  42640. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  42641. }
  42642. }
  42643. }
  42644. void TextEditor::reinsert (const int insertIndex,
  42645. const Array <UniformTextSection*>& sectionsToInsert)
  42646. {
  42647. int index = 0;
  42648. int nextIndex = 0;
  42649. for (int i = 0; i < sections.size(); ++i)
  42650. {
  42651. nextIndex = index + sections.getUnchecked (i)->getTotalLength();
  42652. if (insertIndex == index)
  42653. {
  42654. for (int j = sectionsToInsert.size(); --j >= 0;)
  42655. sections.insert (i, new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42656. break;
  42657. }
  42658. else if (insertIndex > index && insertIndex < nextIndex)
  42659. {
  42660. splitSection (i, insertIndex - index);
  42661. for (int j = sectionsToInsert.size(); --j >= 0;)
  42662. sections.insert (i + 1, new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42663. break;
  42664. }
  42665. index = nextIndex;
  42666. }
  42667. if (nextIndex == insertIndex)
  42668. {
  42669. for (int j = 0; j < sectionsToInsert.size(); ++j)
  42670. sections.add (new UniformTextSection (*sectionsToInsert.getUnchecked(j)));
  42671. }
  42672. coalesceSimilarSections();
  42673. totalNumChars = -1;
  42674. valueTextNeedsUpdating = true;
  42675. }
  42676. void TextEditor::remove (const Range<int>& range,
  42677. UndoManager* const um,
  42678. const int caretPositionToMoveTo)
  42679. {
  42680. if (! range.isEmpty())
  42681. {
  42682. int index = 0;
  42683. for (int i = 0; i < sections.size(); ++i)
  42684. {
  42685. const int nextIndex = index + sections.getUnchecked(i)->getTotalLength();
  42686. if (range.getStart() > index && range.getStart() < nextIndex)
  42687. {
  42688. splitSection (i, range.getStart() - index);
  42689. --i;
  42690. }
  42691. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  42692. {
  42693. splitSection (i, range.getEnd() - index);
  42694. --i;
  42695. }
  42696. else
  42697. {
  42698. index = nextIndex;
  42699. if (index > range.getEnd())
  42700. break;
  42701. }
  42702. }
  42703. index = 0;
  42704. if (um != 0)
  42705. {
  42706. Array <UniformTextSection*> removedSections;
  42707. for (int i = 0; i < sections.size(); ++i)
  42708. {
  42709. if (range.getEnd() <= range.getStart())
  42710. break;
  42711. UniformTextSection* const section = sections.getUnchecked (i);
  42712. const int nextIndex = index + section->getTotalLength();
  42713. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  42714. removedSections.add (new UniformTextSection (*section));
  42715. index = nextIndex;
  42716. }
  42717. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  42718. newTransaction();
  42719. um->perform (new RemoveAction (*this, range, caretPosition,
  42720. caretPositionToMoveTo, removedSections));
  42721. }
  42722. else
  42723. {
  42724. Range<int> remainingRange (range);
  42725. for (int i = 0; i < sections.size(); ++i)
  42726. {
  42727. UniformTextSection* const section = sections.getUnchecked (i);
  42728. const int nextIndex = index + section->getTotalLength();
  42729. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  42730. {
  42731. sections.remove(i);
  42732. section->clear();
  42733. delete section;
  42734. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  42735. if (remainingRange.isEmpty())
  42736. break;
  42737. --i;
  42738. }
  42739. else
  42740. {
  42741. index = nextIndex;
  42742. }
  42743. }
  42744. coalesceSimilarSections();
  42745. totalNumChars = -1;
  42746. valueTextNeedsUpdating = true;
  42747. moveCursorTo (caretPositionToMoveTo, false);
  42748. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  42749. }
  42750. }
  42751. }
  42752. const String TextEditor::getText() const
  42753. {
  42754. String t;
  42755. t.preallocateStorage (getTotalNumChars());
  42756. String::Concatenator concatenator (t);
  42757. for (int i = 0; i < sections.size(); ++i)
  42758. sections.getUnchecked (i)->appendAllText (concatenator);
  42759. return t;
  42760. }
  42761. const String TextEditor::getTextInRange (const Range<int>& range) const
  42762. {
  42763. String t;
  42764. if (! range.isEmpty())
  42765. {
  42766. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  42767. String::Concatenator concatenator (t);
  42768. int index = 0;
  42769. for (int i = 0; i < sections.size(); ++i)
  42770. {
  42771. const UniformTextSection* const s = sections.getUnchecked (i);
  42772. const int nextIndex = index + s->getTotalLength();
  42773. if (range.getStart() < nextIndex)
  42774. {
  42775. if (range.getEnd() <= index)
  42776. break;
  42777. s->appendSubstring (concatenator, range - index);
  42778. }
  42779. index = nextIndex;
  42780. }
  42781. }
  42782. return t;
  42783. }
  42784. const String TextEditor::getHighlightedText() const
  42785. {
  42786. return getTextInRange (selection);
  42787. }
  42788. int TextEditor::getTotalNumChars() const
  42789. {
  42790. if (totalNumChars < 0)
  42791. {
  42792. totalNumChars = 0;
  42793. for (int i = sections.size(); --i >= 0;)
  42794. totalNumChars += sections.getUnchecked (i)->getTotalLength();
  42795. }
  42796. return totalNumChars;
  42797. }
  42798. bool TextEditor::isEmpty() const
  42799. {
  42800. return getTotalNumChars() == 0;
  42801. }
  42802. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  42803. {
  42804. const float wordWrapWidth = getWordWrapWidth();
  42805. if (wordWrapWidth > 0 && sections.size() > 0)
  42806. {
  42807. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42808. i.getCharPosition (index, cx, cy, lineHeight);
  42809. }
  42810. else
  42811. {
  42812. cx = cy = 0;
  42813. lineHeight = currentFont.getHeight();
  42814. }
  42815. }
  42816. int TextEditor::indexAtPosition (const float x, const float y)
  42817. {
  42818. const float wordWrapWidth = getWordWrapWidth();
  42819. if (wordWrapWidth > 0)
  42820. {
  42821. Iterator i (sections, wordWrapWidth, passwordCharacter);
  42822. while (i.next())
  42823. {
  42824. if (i.lineY + i.lineHeight > y)
  42825. {
  42826. if (i.lineY > y)
  42827. return jmax (0, i.indexInText - 1);
  42828. if (i.atomX >= x)
  42829. return i.indexInText;
  42830. if (x < i.atomRight)
  42831. return i.xToIndex (x);
  42832. }
  42833. }
  42834. }
  42835. return getTotalNumChars();
  42836. }
  42837. static int getCharacterCategory (const juce_wchar character)
  42838. {
  42839. return CharacterFunctions::isLetterOrDigit (character)
  42840. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  42841. }
  42842. int TextEditor::findWordBreakAfter (const int position) const
  42843. {
  42844. const String t (getTextInRange (Range<int> (position, position + 512)));
  42845. const int totalLength = t.length();
  42846. int i = 0;
  42847. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42848. ++i;
  42849. const int type = getCharacterCategory (t[i]);
  42850. while (i < totalLength && type == getCharacterCategory (t[i]))
  42851. ++i;
  42852. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  42853. ++i;
  42854. return position + i;
  42855. }
  42856. int TextEditor::findWordBreakBefore (const int position) const
  42857. {
  42858. if (position <= 0)
  42859. return 0;
  42860. const int startOfBuffer = jmax (0, position - 512);
  42861. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  42862. int i = position - startOfBuffer;
  42863. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  42864. --i;
  42865. if (i > 0)
  42866. {
  42867. const int type = getCharacterCategory (t [i - 1]);
  42868. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  42869. --i;
  42870. }
  42871. jassert (startOfBuffer + i >= 0);
  42872. return startOfBuffer + i;
  42873. }
  42874. void TextEditor::splitSection (const int sectionIndex,
  42875. const int charToSplitAt)
  42876. {
  42877. jassert (sections[sectionIndex] != 0);
  42878. sections.insert (sectionIndex + 1,
  42879. sections.getUnchecked (sectionIndex)->split (charToSplitAt, passwordCharacter));
  42880. }
  42881. void TextEditor::coalesceSimilarSections()
  42882. {
  42883. for (int i = 0; i < sections.size() - 1; ++i)
  42884. {
  42885. UniformTextSection* const s1 = sections.getUnchecked (i);
  42886. UniformTextSection* const s2 = sections.getUnchecked (i + 1);
  42887. if (s1->font == s2->font
  42888. && s1->colour == s2->colour)
  42889. {
  42890. s1->append (*s2, passwordCharacter);
  42891. sections.remove (i + 1);
  42892. delete s2;
  42893. --i;
  42894. }
  42895. }
  42896. }
  42897. END_JUCE_NAMESPACE
  42898. /*** End of inlined file: juce_TextEditor.cpp ***/
  42899. /*** Start of inlined file: juce_Toolbar.cpp ***/
  42900. BEGIN_JUCE_NAMESPACE
  42901. const char* const Toolbar::toolbarDragDescriptor = "_toolbarItem_";
  42902. class ToolbarSpacerComp : public ToolbarItemComponent
  42903. {
  42904. public:
  42905. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  42906. : ToolbarItemComponent (itemId_, String::empty, false),
  42907. fixedSize (fixedSize_),
  42908. drawBar (drawBar_)
  42909. {
  42910. }
  42911. ~ToolbarSpacerComp()
  42912. {
  42913. }
  42914. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  42915. int& preferredSize, int& minSize, int& maxSize)
  42916. {
  42917. if (fixedSize <= 0)
  42918. {
  42919. preferredSize = toolbarThickness * 2;
  42920. minSize = 4;
  42921. maxSize = 32768;
  42922. }
  42923. else
  42924. {
  42925. maxSize = roundToInt (toolbarThickness * fixedSize);
  42926. minSize = drawBar ? maxSize : jmin (4, maxSize);
  42927. preferredSize = maxSize;
  42928. if (getEditingMode() == editableOnPalette)
  42929. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  42930. }
  42931. return true;
  42932. }
  42933. void paintButtonArea (Graphics&, int, int, bool, bool)
  42934. {
  42935. }
  42936. void contentAreaChanged (const Rectangle<int>&)
  42937. {
  42938. }
  42939. int getResizeOrder() const throw()
  42940. {
  42941. return fixedSize <= 0 ? 0 : 1;
  42942. }
  42943. void paint (Graphics& g)
  42944. {
  42945. const int w = getWidth();
  42946. const int h = getHeight();
  42947. if (drawBar)
  42948. {
  42949. g.setColour (findColour (Toolbar::separatorColourId, true));
  42950. const float thickness = 0.2f;
  42951. if (isToolbarVertical())
  42952. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  42953. else
  42954. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  42955. }
  42956. if (getEditingMode() != normalMode && ! drawBar)
  42957. {
  42958. g.setColour (findColour (Toolbar::separatorColourId, true));
  42959. const int indentX = jmin (2, (w - 3) / 2);
  42960. const int indentY = jmin (2, (h - 3) / 2);
  42961. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  42962. if (fixedSize <= 0)
  42963. {
  42964. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  42965. if (isToolbarVertical())
  42966. {
  42967. x1 = w * 0.5f;
  42968. y1 = h * 0.4f;
  42969. x2 = x1;
  42970. y2 = indentX * 2.0f;
  42971. x3 = x1;
  42972. y3 = h * 0.6f;
  42973. x4 = x1;
  42974. y4 = h - y2;
  42975. hw = w * 0.15f;
  42976. hl = w * 0.2f;
  42977. }
  42978. else
  42979. {
  42980. x1 = w * 0.4f;
  42981. y1 = h * 0.5f;
  42982. x2 = indentX * 2.0f;
  42983. y2 = y1;
  42984. x3 = w * 0.6f;
  42985. y3 = y1;
  42986. x4 = w - x2;
  42987. y4 = y1;
  42988. hw = h * 0.15f;
  42989. hl = h * 0.2f;
  42990. }
  42991. Path p;
  42992. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  42993. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  42994. g.fillPath (p);
  42995. }
  42996. }
  42997. }
  42998. juce_UseDebuggingNewOperator
  42999. private:
  43000. const float fixedSize;
  43001. const bool drawBar;
  43002. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43003. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43004. };
  43005. class MissingItemsComponent : public PopupMenuCustomComponent
  43006. {
  43007. public:
  43008. MissingItemsComponent (Toolbar& owner_, const int height_)
  43009. : PopupMenuCustomComponent (true),
  43010. owner (owner_),
  43011. height (height_)
  43012. {
  43013. for (int i = owner_.items.size(); --i >= 0;)
  43014. {
  43015. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43016. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43017. {
  43018. oldIndexes.insert (0, i);
  43019. addAndMakeVisible (tc, 0);
  43020. }
  43021. }
  43022. layout (400);
  43023. }
  43024. ~MissingItemsComponent()
  43025. {
  43026. // deleting the toolbar while its menu it open??
  43027. jassert (owner.isValidComponent());
  43028. for (int i = 0; i < getNumChildComponents(); ++i)
  43029. {
  43030. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43031. if (tc != 0)
  43032. {
  43033. tc->setVisible (false);
  43034. const int index = oldIndexes.remove (i);
  43035. owner.addChildComponent (tc, index);
  43036. --i;
  43037. }
  43038. }
  43039. owner.resized();
  43040. }
  43041. void layout (const int preferredWidth)
  43042. {
  43043. const int indent = 8;
  43044. int x = indent;
  43045. int y = indent;
  43046. int maxX = 0;
  43047. for (int i = 0; i < getNumChildComponents(); ++i)
  43048. {
  43049. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43050. if (tc != 0)
  43051. {
  43052. int preferredSize = 1, minSize = 1, maxSize = 1;
  43053. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43054. {
  43055. if (x + preferredSize > preferredWidth && x > indent)
  43056. {
  43057. x = indent;
  43058. y += height;
  43059. }
  43060. tc->setBounds (x, y, preferredSize, height);
  43061. x += preferredSize;
  43062. maxX = jmax (maxX, x);
  43063. }
  43064. }
  43065. }
  43066. setSize (maxX + 8, y + height + 8);
  43067. }
  43068. void getIdealSize (int& idealWidth, int& idealHeight)
  43069. {
  43070. idealWidth = getWidth();
  43071. idealHeight = getHeight();
  43072. }
  43073. juce_UseDebuggingNewOperator
  43074. private:
  43075. Toolbar& owner;
  43076. const int height;
  43077. Array <int> oldIndexes;
  43078. MissingItemsComponent (const MissingItemsComponent&);
  43079. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43080. };
  43081. Toolbar::Toolbar()
  43082. : vertical (false),
  43083. isEditingActive (false),
  43084. toolbarStyle (Toolbar::iconsOnly)
  43085. {
  43086. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43087. missingItemsButton->setAlwaysOnTop (true);
  43088. missingItemsButton->addButtonListener (this);
  43089. }
  43090. Toolbar::~Toolbar()
  43091. {
  43092. animator.cancelAllAnimations (true);
  43093. deleteAllChildren();
  43094. }
  43095. void Toolbar::setVertical (const bool shouldBeVertical)
  43096. {
  43097. if (vertical != shouldBeVertical)
  43098. {
  43099. vertical = shouldBeVertical;
  43100. resized();
  43101. }
  43102. }
  43103. void Toolbar::clear()
  43104. {
  43105. for (int i = items.size(); --i >= 0;)
  43106. {
  43107. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43108. items.remove (i);
  43109. delete tc;
  43110. }
  43111. resized();
  43112. }
  43113. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43114. {
  43115. if (itemId == ToolbarItemFactory::separatorBarId)
  43116. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43117. else if (itemId == ToolbarItemFactory::spacerId)
  43118. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43119. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43120. return new ToolbarSpacerComp (itemId, 0, false);
  43121. return factory.createItem (itemId);
  43122. }
  43123. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43124. const int itemId,
  43125. const int insertIndex)
  43126. {
  43127. // An ID can't be zero - this might indicate a mistake somewhere?
  43128. jassert (itemId != 0);
  43129. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43130. if (tc != 0)
  43131. {
  43132. #ifdef JUCE_DEBUG
  43133. Array <int> allowedIds;
  43134. factory.getAllToolbarItemIds (allowedIds);
  43135. // If your factory can create an item for a given ID, it must also return
  43136. // that ID from its getAllToolbarItemIds() method!
  43137. jassert (allowedIds.contains (itemId));
  43138. #endif
  43139. items.insert (insertIndex, tc);
  43140. addAndMakeVisible (tc, insertIndex);
  43141. }
  43142. }
  43143. void Toolbar::addItem (ToolbarItemFactory& factory,
  43144. const int itemId,
  43145. const int insertIndex)
  43146. {
  43147. addItemInternal (factory, itemId, insertIndex);
  43148. resized();
  43149. }
  43150. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43151. {
  43152. Array <int> ids;
  43153. factoryToUse.getDefaultItemSet (ids);
  43154. clear();
  43155. for (int i = 0; i < ids.size(); ++i)
  43156. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43157. resized();
  43158. }
  43159. void Toolbar::removeToolbarItem (const int itemIndex)
  43160. {
  43161. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43162. if (tc != 0)
  43163. {
  43164. items.removeValue (tc);
  43165. delete tc;
  43166. resized();
  43167. }
  43168. }
  43169. int Toolbar::getNumItems() const throw()
  43170. {
  43171. return items.size();
  43172. }
  43173. int Toolbar::getItemId (const int itemIndex) const throw()
  43174. {
  43175. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43176. return tc != 0 ? tc->getItemId() : 0;
  43177. }
  43178. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43179. {
  43180. return items [itemIndex];
  43181. }
  43182. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43183. {
  43184. for (;;)
  43185. {
  43186. index += delta;
  43187. ToolbarItemComponent* const tc = getItemComponent (index);
  43188. if (tc == 0)
  43189. break;
  43190. if (tc->isActive)
  43191. return tc;
  43192. }
  43193. return 0;
  43194. }
  43195. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43196. {
  43197. if (toolbarStyle != newStyle)
  43198. {
  43199. toolbarStyle = newStyle;
  43200. updateAllItemPositions (false);
  43201. }
  43202. }
  43203. const String Toolbar::toString() const
  43204. {
  43205. String s ("TB:");
  43206. for (int i = 0; i < getNumItems(); ++i)
  43207. s << getItemId(i) << ' ';
  43208. return s.trimEnd();
  43209. }
  43210. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43211. const String& savedVersion)
  43212. {
  43213. if (! savedVersion.startsWith ("TB:"))
  43214. return false;
  43215. StringArray tokens;
  43216. tokens.addTokens (savedVersion.substring (3), false);
  43217. clear();
  43218. for (int i = 0; i < tokens.size(); ++i)
  43219. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43220. resized();
  43221. return true;
  43222. }
  43223. void Toolbar::paint (Graphics& g)
  43224. {
  43225. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43226. }
  43227. int Toolbar::getThickness() const throw()
  43228. {
  43229. return vertical ? getWidth() : getHeight();
  43230. }
  43231. int Toolbar::getLength() const throw()
  43232. {
  43233. return vertical ? getHeight() : getWidth();
  43234. }
  43235. void Toolbar::setEditingActive (const bool active)
  43236. {
  43237. if (isEditingActive != active)
  43238. {
  43239. isEditingActive = active;
  43240. updateAllItemPositions (false);
  43241. }
  43242. }
  43243. void Toolbar::resized()
  43244. {
  43245. updateAllItemPositions (false);
  43246. }
  43247. void Toolbar::updateAllItemPositions (const bool animate)
  43248. {
  43249. if (getWidth() > 0 && getHeight() > 0)
  43250. {
  43251. StretchableObjectResizer resizer;
  43252. int i;
  43253. for (i = 0; i < items.size(); ++i)
  43254. {
  43255. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43256. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43257. : ToolbarItemComponent::normalMode);
  43258. tc->setStyle (toolbarStyle);
  43259. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43260. int preferredSize = 1, minSize = 1, maxSize = 1;
  43261. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43262. preferredSize, minSize, maxSize))
  43263. {
  43264. tc->isActive = true;
  43265. resizer.addItem (preferredSize, minSize, maxSize,
  43266. spacer != 0 ? spacer->getResizeOrder() : 2);
  43267. }
  43268. else
  43269. {
  43270. tc->isActive = false;
  43271. tc->setVisible (false);
  43272. }
  43273. }
  43274. resizer.resizeToFit (getLength());
  43275. int totalLength = 0;
  43276. for (i = 0; i < resizer.getNumItems(); ++i)
  43277. totalLength += (int) resizer.getItemSize (i);
  43278. const bool itemsOffTheEnd = totalLength > getLength();
  43279. const int extrasButtonSize = getThickness() / 2;
  43280. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43281. missingItemsButton->setVisible (itemsOffTheEnd);
  43282. missingItemsButton->setEnabled (! isEditingActive);
  43283. if (vertical)
  43284. missingItemsButton->setCentrePosition (getWidth() / 2,
  43285. getHeight() - 4 - extrasButtonSize / 2);
  43286. else
  43287. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43288. getHeight() / 2);
  43289. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43290. : missingItemsButton->getX()) - 4
  43291. : getLength();
  43292. int pos = 0, activeIndex = 0;
  43293. for (i = 0; i < items.size(); ++i)
  43294. {
  43295. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43296. if (tc->isActive)
  43297. {
  43298. const int size = (int) resizer.getItemSize (activeIndex++);
  43299. Rectangle<int> newBounds;
  43300. if (vertical)
  43301. newBounds.setBounds (0, pos, getWidth(), size);
  43302. else
  43303. newBounds.setBounds (pos, 0, size, getHeight());
  43304. if (animate)
  43305. {
  43306. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43307. }
  43308. else
  43309. {
  43310. animator.cancelAnimation (tc, false);
  43311. tc->setBounds (newBounds);
  43312. }
  43313. pos += size;
  43314. tc->setVisible (pos <= maxLength
  43315. && ((! tc->isBeingDragged)
  43316. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43317. }
  43318. }
  43319. }
  43320. }
  43321. void Toolbar::buttonClicked (Button*)
  43322. {
  43323. jassert (missingItemsButton->isShowing());
  43324. if (missingItemsButton->isShowing())
  43325. {
  43326. PopupMenu m;
  43327. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43328. m.showAt (missingItemsButton);
  43329. }
  43330. }
  43331. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43332. Component* /*sourceComponent*/)
  43333. {
  43334. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43335. }
  43336. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43337. {
  43338. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43339. if (tc != 0)
  43340. {
  43341. if (getNumItems() == 0)
  43342. {
  43343. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43344. {
  43345. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43346. if (palette != 0)
  43347. palette->replaceComponent (tc);
  43348. }
  43349. else
  43350. {
  43351. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43352. }
  43353. items.add (tc);
  43354. addChildComponent (tc);
  43355. updateAllItemPositions (false);
  43356. }
  43357. else
  43358. {
  43359. for (int i = getNumItems(); --i >= 0;)
  43360. {
  43361. int currentIndex = getIndexOfChildComponent (tc);
  43362. if (currentIndex < 0)
  43363. {
  43364. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43365. {
  43366. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43367. if (palette != 0)
  43368. palette->replaceComponent (tc);
  43369. }
  43370. else
  43371. {
  43372. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43373. }
  43374. items.add (tc);
  43375. addChildComponent (tc);
  43376. currentIndex = getIndexOfChildComponent (tc);
  43377. updateAllItemPositions (true);
  43378. }
  43379. int newIndex = currentIndex;
  43380. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43381. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43382. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43383. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43384. if (prev != 0)
  43385. {
  43386. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43387. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43388. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43389. {
  43390. newIndex = getIndexOfChildComponent (prev);
  43391. }
  43392. }
  43393. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43394. if (next != 0)
  43395. {
  43396. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43397. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43398. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43399. {
  43400. newIndex = getIndexOfChildComponent (next) + 1;
  43401. }
  43402. }
  43403. if (newIndex != currentIndex)
  43404. {
  43405. items.removeValue (tc);
  43406. removeChildComponent (tc);
  43407. addChildComponent (tc, newIndex);
  43408. items.insert (newIndex, tc);
  43409. updateAllItemPositions (true);
  43410. }
  43411. else
  43412. {
  43413. break;
  43414. }
  43415. }
  43416. }
  43417. }
  43418. }
  43419. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  43420. {
  43421. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43422. if (tc != 0)
  43423. {
  43424. if (isParentOf (tc))
  43425. {
  43426. items.removeValue (tc);
  43427. removeChildComponent (tc);
  43428. updateAllItemPositions (true);
  43429. }
  43430. }
  43431. }
  43432. void Toolbar::itemDropped (const String&, Component*, int, int)
  43433. {
  43434. }
  43435. void Toolbar::mouseDown (const MouseEvent& e)
  43436. {
  43437. if (e.mods.isPopupMenu())
  43438. {
  43439. }
  43440. }
  43441. class ToolbarCustomisationDialog : public DialogWindow
  43442. {
  43443. public:
  43444. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  43445. Toolbar* const toolbar_,
  43446. const int optionFlags)
  43447. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  43448. toolbar (toolbar_)
  43449. {
  43450. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  43451. setResizable (true, true);
  43452. setResizeLimits (400, 300, 1500, 1000);
  43453. positionNearBar();
  43454. }
  43455. ~ToolbarCustomisationDialog()
  43456. {
  43457. setContentComponent (0, true);
  43458. }
  43459. void closeButtonPressed()
  43460. {
  43461. setVisible (false);
  43462. }
  43463. bool canModalEventBeSentToComponent (const Component* comp)
  43464. {
  43465. return toolbar->isParentOf (comp);
  43466. }
  43467. void positionNearBar()
  43468. {
  43469. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  43470. const int tbx = toolbar->getScreenX();
  43471. const int tby = toolbar->getScreenY();
  43472. const int gap = 8;
  43473. int x, y;
  43474. if (toolbar->isVertical())
  43475. {
  43476. y = tby;
  43477. if (tbx > screenSize.getCentreX())
  43478. x = tbx - getWidth() - gap;
  43479. else
  43480. x = tbx + toolbar->getWidth() + gap;
  43481. }
  43482. else
  43483. {
  43484. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  43485. if (tby > screenSize.getCentreY())
  43486. y = tby - getHeight() - gap;
  43487. else
  43488. y = tby + toolbar->getHeight() + gap;
  43489. }
  43490. setTopLeftPosition (x, y);
  43491. }
  43492. private:
  43493. Toolbar* const toolbar;
  43494. class CustomiserPanel : public Component,
  43495. private ComboBoxListener,
  43496. private ButtonListener
  43497. {
  43498. public:
  43499. CustomiserPanel (ToolbarItemFactory& factory_,
  43500. Toolbar* const toolbar_,
  43501. const int optionFlags)
  43502. : factory (factory_),
  43503. toolbar (toolbar_),
  43504. styleBox (0),
  43505. defaultButton (0)
  43506. {
  43507. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  43508. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  43509. | Toolbar::allowIconsWithTextChoice
  43510. | Toolbar::allowTextOnlyChoice)) != 0)
  43511. {
  43512. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  43513. styleBox->setEditableText (false);
  43514. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  43515. styleBox->addItem (TRANS("Show icons only"), 1);
  43516. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  43517. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  43518. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  43519. styleBox->addItem (TRANS("Show descriptions only"), 3);
  43520. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  43521. styleBox->setSelectedId (1);
  43522. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  43523. styleBox->setSelectedId (2);
  43524. else if (toolbar_->getStyle() == Toolbar::textOnly)
  43525. styleBox->setSelectedId (3);
  43526. styleBox->addListener (this);
  43527. }
  43528. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  43529. {
  43530. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  43531. defaultButton->addButtonListener (this);
  43532. }
  43533. addAndMakeVisible (instructions = new Label (String::empty,
  43534. 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.")));
  43535. instructions->setFont (Font (13.0f));
  43536. setSize (500, 300);
  43537. }
  43538. ~CustomiserPanel()
  43539. {
  43540. deleteAllChildren();
  43541. }
  43542. void comboBoxChanged (ComboBox*)
  43543. {
  43544. if (styleBox->getSelectedId() == 1)
  43545. toolbar->setStyle (Toolbar::iconsOnly);
  43546. else if (styleBox->getSelectedId() == 2)
  43547. toolbar->setStyle (Toolbar::iconsWithText);
  43548. else if (styleBox->getSelectedId() == 3)
  43549. toolbar->setStyle (Toolbar::textOnly);
  43550. palette->resized(); // to make it update the styles
  43551. }
  43552. void buttonClicked (Button*)
  43553. {
  43554. toolbar->addDefaultItems (factory);
  43555. }
  43556. void paint (Graphics& g)
  43557. {
  43558. Colour background;
  43559. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  43560. if (dw != 0)
  43561. background = dw->getBackgroundColour();
  43562. g.setColour (background.contrasting().withAlpha (0.3f));
  43563. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  43564. }
  43565. void resized()
  43566. {
  43567. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  43568. if (styleBox != 0)
  43569. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  43570. if (defaultButton != 0)
  43571. {
  43572. defaultButton->changeWidthToFitText (22);
  43573. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  43574. }
  43575. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  43576. }
  43577. private:
  43578. ToolbarItemFactory& factory;
  43579. Toolbar* const toolbar;
  43580. Label* instructions;
  43581. ToolbarItemPalette* palette;
  43582. ComboBox* styleBox;
  43583. TextButton* defaultButton;
  43584. };
  43585. };
  43586. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  43587. {
  43588. setEditingActive (true);
  43589. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  43590. dw.runModalLoop();
  43591. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  43592. setEditingActive (false);
  43593. }
  43594. END_JUCE_NAMESPACE
  43595. /*** End of inlined file: juce_Toolbar.cpp ***/
  43596. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  43597. BEGIN_JUCE_NAMESPACE
  43598. ToolbarItemFactory::ToolbarItemFactory()
  43599. {
  43600. }
  43601. ToolbarItemFactory::~ToolbarItemFactory()
  43602. {
  43603. }
  43604. class ItemDragAndDropOverlayComponent : public Component
  43605. {
  43606. public:
  43607. ItemDragAndDropOverlayComponent()
  43608. : isDragging (false)
  43609. {
  43610. setAlwaysOnTop (true);
  43611. setRepaintsOnMouseActivity (true);
  43612. setMouseCursor (MouseCursor::DraggingHandCursor);
  43613. }
  43614. ~ItemDragAndDropOverlayComponent()
  43615. {
  43616. }
  43617. void paint (Graphics& g)
  43618. {
  43619. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43620. if (isMouseOverOrDragging()
  43621. && tc != 0
  43622. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43623. {
  43624. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  43625. g.drawRect (0, 0, getWidth(), getHeight(),
  43626. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  43627. }
  43628. }
  43629. void mouseDown (const MouseEvent& e)
  43630. {
  43631. isDragging = false;
  43632. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43633. if (tc != 0)
  43634. {
  43635. tc->dragOffsetX = e.x;
  43636. tc->dragOffsetY = e.y;
  43637. }
  43638. }
  43639. void mouseDrag (const MouseEvent& e)
  43640. {
  43641. if (! (isDragging || e.mouseWasClicked()))
  43642. {
  43643. isDragging = true;
  43644. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  43645. if (dnd != 0)
  43646. {
  43647. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  43648. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43649. if (tc != 0)
  43650. {
  43651. tc->isBeingDragged = true;
  43652. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43653. tc->setVisible (false);
  43654. }
  43655. }
  43656. }
  43657. }
  43658. void mouseUp (const MouseEvent&)
  43659. {
  43660. isDragging = false;
  43661. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  43662. if (tc != 0)
  43663. {
  43664. tc->isBeingDragged = false;
  43665. Toolbar* const tb = tc->getToolbar();
  43666. if (tb != 0)
  43667. tb->updateAllItemPositions (true);
  43668. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  43669. delete tc;
  43670. }
  43671. }
  43672. void parentSizeChanged()
  43673. {
  43674. setBounds (0, 0, getParentWidth(), getParentHeight());
  43675. }
  43676. juce_UseDebuggingNewOperator
  43677. private:
  43678. bool isDragging;
  43679. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  43680. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  43681. };
  43682. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  43683. const String& labelText,
  43684. const bool isBeingUsedAsAButton_)
  43685. : Button (labelText),
  43686. itemId (itemId_),
  43687. mode (normalMode),
  43688. toolbarStyle (Toolbar::iconsOnly),
  43689. dragOffsetX (0),
  43690. dragOffsetY (0),
  43691. isActive (true),
  43692. isBeingDragged (false),
  43693. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  43694. {
  43695. // Your item ID can't be 0!
  43696. jassert (itemId_ != 0);
  43697. }
  43698. ToolbarItemComponent::~ToolbarItemComponent()
  43699. {
  43700. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43701. overlayComp = 0;
  43702. }
  43703. Toolbar* ToolbarItemComponent::getToolbar() const
  43704. {
  43705. return dynamic_cast <Toolbar*> (getParentComponent());
  43706. }
  43707. bool ToolbarItemComponent::isToolbarVertical() const
  43708. {
  43709. const Toolbar* const t = getToolbar();
  43710. return t != 0 && t->isVertical();
  43711. }
  43712. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  43713. {
  43714. if (toolbarStyle != newStyle)
  43715. {
  43716. toolbarStyle = newStyle;
  43717. repaint();
  43718. resized();
  43719. }
  43720. }
  43721. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  43722. {
  43723. if (isBeingUsedAsAButton)
  43724. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  43725. isMouseOver, isMouseDown, *this);
  43726. if (toolbarStyle != Toolbar::iconsOnly)
  43727. {
  43728. const int indent = contentArea.getX();
  43729. int y = indent;
  43730. int h = getHeight() - indent * 2;
  43731. if (toolbarStyle == Toolbar::iconsWithText)
  43732. {
  43733. y = contentArea.getBottom() + indent / 2;
  43734. h -= contentArea.getHeight();
  43735. }
  43736. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  43737. getButtonText(), *this);
  43738. }
  43739. if (! contentArea.isEmpty())
  43740. {
  43741. g.saveState();
  43742. g.setOrigin (contentArea.getX(), contentArea.getY());
  43743. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  43744. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  43745. g.restoreState();
  43746. }
  43747. }
  43748. void ToolbarItemComponent::resized()
  43749. {
  43750. if (toolbarStyle != Toolbar::textOnly)
  43751. {
  43752. const int indent = jmin (proportionOfWidth (0.08f),
  43753. proportionOfHeight (0.08f));
  43754. contentArea = Rectangle<int> (indent, indent,
  43755. getWidth() - indent * 2,
  43756. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  43757. : (getHeight() - indent * 2));
  43758. }
  43759. else
  43760. {
  43761. contentArea = Rectangle<int>();
  43762. }
  43763. contentAreaChanged (contentArea);
  43764. }
  43765. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  43766. {
  43767. if (mode != newMode)
  43768. {
  43769. mode = newMode;
  43770. repaint();
  43771. if (mode == normalMode)
  43772. {
  43773. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  43774. overlayComp = 0;
  43775. }
  43776. else if (overlayComp == 0)
  43777. {
  43778. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  43779. overlayComp->parentSizeChanged();
  43780. }
  43781. resized();
  43782. }
  43783. }
  43784. END_JUCE_NAMESPACE
  43785. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  43786. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  43787. BEGIN_JUCE_NAMESPACE
  43788. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  43789. Toolbar* const toolbar_)
  43790. : factory (factory_),
  43791. toolbar (toolbar_)
  43792. {
  43793. Component* const itemHolder = new Component();
  43794. Array <int> allIds;
  43795. factory_.getAllToolbarItemIds (allIds);
  43796. for (int i = 0; i < allIds.size(); ++i)
  43797. {
  43798. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  43799. jassert (tc != 0);
  43800. if (tc != 0)
  43801. {
  43802. itemHolder->addAndMakeVisible (tc);
  43803. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  43804. }
  43805. }
  43806. viewport = new Viewport();
  43807. viewport->setViewedComponent (itemHolder);
  43808. addAndMakeVisible (viewport);
  43809. }
  43810. ToolbarItemPalette::~ToolbarItemPalette()
  43811. {
  43812. viewport->getViewedComponent()->deleteAllChildren();
  43813. deleteAllChildren();
  43814. }
  43815. void ToolbarItemPalette::resized()
  43816. {
  43817. viewport->setBoundsInset (BorderSize (1));
  43818. Component* const itemHolder = viewport->getViewedComponent();
  43819. const int indent = 8;
  43820. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  43821. const int height = toolbar->getThickness();
  43822. int x = indent;
  43823. int y = indent;
  43824. int maxX = 0;
  43825. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  43826. {
  43827. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  43828. if (tc != 0)
  43829. {
  43830. tc->setStyle (toolbar->getStyle());
  43831. int preferredSize = 1, minSize = 1, maxSize = 1;
  43832. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43833. {
  43834. if (x + preferredSize > preferredWidth && x > indent)
  43835. {
  43836. x = indent;
  43837. y += height;
  43838. }
  43839. tc->setBounds (x, y, preferredSize, height);
  43840. x += preferredSize + 8;
  43841. maxX = jmax (maxX, x);
  43842. }
  43843. }
  43844. }
  43845. itemHolder->setSize (maxX, y + height + 8);
  43846. }
  43847. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  43848. {
  43849. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  43850. jassert (tc != 0);
  43851. if (tc != 0)
  43852. {
  43853. tc->setBounds (comp->getBounds());
  43854. tc->setStyle (toolbar->getStyle());
  43855. tc->setEditingMode (comp->getEditingMode());
  43856. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  43857. }
  43858. }
  43859. END_JUCE_NAMESPACE
  43860. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  43861. /*** Start of inlined file: juce_TreeView.cpp ***/
  43862. BEGIN_JUCE_NAMESPACE
  43863. class TreeViewContentComponent : public Component,
  43864. public TooltipClient
  43865. {
  43866. public:
  43867. TreeViewContentComponent (TreeView* const owner_)
  43868. : owner (owner_),
  43869. buttonUnderMouse (0),
  43870. isDragging (false)
  43871. {
  43872. }
  43873. ~TreeViewContentComponent()
  43874. {
  43875. deleteAllChildren();
  43876. }
  43877. void mouseDown (const MouseEvent& e)
  43878. {
  43879. updateButtonUnderMouse (e);
  43880. isDragging = false;
  43881. needSelectionOnMouseUp = false;
  43882. Rectangle<int> pos;
  43883. TreeViewItem* const item = findItemAt (e.y, pos);
  43884. if (item == 0)
  43885. return;
  43886. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  43887. // as selection clicks)
  43888. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  43889. {
  43890. if (e.x >= pos.getX() - owner->getIndentSize())
  43891. item->setOpen (! item->isOpen());
  43892. // (clicks to the left of an open/close button are ignored)
  43893. }
  43894. else
  43895. {
  43896. // mouse-down inside the body of the item..
  43897. if (! owner->isMultiSelectEnabled())
  43898. item->setSelected (true, true);
  43899. else if (item->isSelected())
  43900. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  43901. else
  43902. selectBasedOnModifiers (item, e.mods);
  43903. if (e.x >= pos.getX())
  43904. item->itemClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43905. }
  43906. }
  43907. void mouseUp (const MouseEvent& e)
  43908. {
  43909. updateButtonUnderMouse (e);
  43910. if (needSelectionOnMouseUp && e.mouseWasClicked())
  43911. {
  43912. Rectangle<int> pos;
  43913. TreeViewItem* const item = findItemAt (e.y, pos);
  43914. if (item != 0)
  43915. selectBasedOnModifiers (item, e.mods);
  43916. }
  43917. }
  43918. void mouseDoubleClick (const MouseEvent& e)
  43919. {
  43920. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  43921. {
  43922. Rectangle<int> pos;
  43923. TreeViewItem* const item = findItemAt (e.y, pos);
  43924. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  43925. item->itemDoubleClicked (e.withNewPosition (e.getPosition() - pos.getPosition()));
  43926. }
  43927. }
  43928. void mouseDrag (const MouseEvent& e)
  43929. {
  43930. if (isEnabled()
  43931. && ! (isDragging || e.mouseWasClicked()
  43932. || e.getDistanceFromDragStart() < 5
  43933. || e.mods.isPopupMenu()))
  43934. {
  43935. isDragging = true;
  43936. Rectangle<int> pos;
  43937. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  43938. if (item != 0 && e.getMouseDownX() >= pos.getX())
  43939. {
  43940. const String dragDescription (item->getDragSourceDescription());
  43941. if (dragDescription.isNotEmpty())
  43942. {
  43943. DragAndDropContainer* const dragContainer
  43944. = DragAndDropContainer::findParentDragContainerFor (this);
  43945. if (dragContainer != 0)
  43946. {
  43947. pos.setSize (pos.getWidth(), item->itemHeight);
  43948. Image* dragImage = Component::createComponentSnapshot (pos, true);
  43949. dragImage->multiplyAllAlphas (0.6f);
  43950. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  43951. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  43952. }
  43953. else
  43954. {
  43955. // to be able to do a drag-and-drop operation, the treeview needs to
  43956. // be inside a component which is also a DragAndDropContainer.
  43957. jassertfalse
  43958. }
  43959. }
  43960. }
  43961. }
  43962. }
  43963. void mouseMove (const MouseEvent& e)
  43964. {
  43965. updateButtonUnderMouse (e);
  43966. }
  43967. void mouseExit (const MouseEvent& e)
  43968. {
  43969. updateButtonUnderMouse (e);
  43970. }
  43971. void paint (Graphics& g);
  43972. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  43973. static bool isMouseDraggingInChildCompOf (Component* const comp)
  43974. {
  43975. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  43976. {
  43977. MouseInputSource* source = Desktop::getInstance().getMouseSource(i);
  43978. if (source->isDragging())
  43979. {
  43980. Component* const underMouse = source->getComponentUnderMouse();
  43981. if (underMouse != 0 && (comp == underMouse || comp->isParentOf (underMouse)))
  43982. return true;
  43983. }
  43984. }
  43985. return false;
  43986. }
  43987. void updateComponents()
  43988. {
  43989. const int visibleTop = -getY();
  43990. const int visibleBottom = visibleTop + getParentHeight();
  43991. BigInteger itemsToKeep;
  43992. TreeViewItem* item = owner->rootItem;
  43993. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  43994. while (item != 0 && y < visibleBottom)
  43995. {
  43996. y += item->itemHeight;
  43997. if (y >= visibleTop)
  43998. {
  43999. const int index = rowComponentIds.indexOf (item->uid);
  44000. if (index < 0)
  44001. {
  44002. Component* const comp = item->createItemComponent();
  44003. if (comp != 0)
  44004. {
  44005. addAndMakeVisible (comp);
  44006. itemsToKeep.setBit (rowComponentItems.size());
  44007. rowComponentItems.add (item);
  44008. rowComponentIds.add (item->uid);
  44009. rowComponents.add (comp);
  44010. }
  44011. }
  44012. else
  44013. {
  44014. itemsToKeep.setBit (index);
  44015. }
  44016. }
  44017. item = item->getNextVisibleItem (true);
  44018. }
  44019. for (int i = rowComponentItems.size(); --i >= 0;)
  44020. {
  44021. Component* const comp = rowComponents.getUnchecked(i);
  44022. bool keep = false;
  44023. if (isParentOf (comp))
  44024. {
  44025. if (itemsToKeep[i])
  44026. {
  44027. const TreeViewItem* const item = rowComponentItems.getUnchecked(i);
  44028. Rectangle<int> pos (item->getItemPosition (false));
  44029. pos.setSize (pos.getWidth(), item->itemHeight);
  44030. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44031. {
  44032. keep = true;
  44033. comp->setBounds (pos);
  44034. }
  44035. }
  44036. if ((! keep) && isMouseDraggingInChildCompOf (comp))
  44037. {
  44038. keep = true;
  44039. comp->setSize (0, 0);
  44040. }
  44041. }
  44042. if (! keep)
  44043. {
  44044. delete comp;
  44045. rowComponents.remove (i);
  44046. rowComponentIds.remove (i);
  44047. rowComponentItems.remove (i);
  44048. }
  44049. }
  44050. }
  44051. void updateButtonUnderMouse (const MouseEvent& e)
  44052. {
  44053. TreeViewItem* newItem = 0;
  44054. if (owner->openCloseButtonsVisible)
  44055. {
  44056. Rectangle<int> pos;
  44057. TreeViewItem* item = findItemAt (e.y, pos);
  44058. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44059. {
  44060. newItem = item;
  44061. if (! newItem->mightContainSubItems())
  44062. newItem = 0;
  44063. }
  44064. }
  44065. if (buttonUnderMouse != newItem)
  44066. {
  44067. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44068. {
  44069. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44070. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44071. }
  44072. buttonUnderMouse = newItem;
  44073. if (buttonUnderMouse != 0)
  44074. {
  44075. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44076. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44077. }
  44078. }
  44079. }
  44080. bool isMouseOverButton (TreeViewItem* item) const throw()
  44081. {
  44082. return item == buttonUnderMouse;
  44083. }
  44084. void resized()
  44085. {
  44086. owner->itemsChanged();
  44087. }
  44088. const String getTooltip()
  44089. {
  44090. Rectangle<int> pos;
  44091. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44092. if (item != 0)
  44093. return item->getTooltip();
  44094. return owner->getTooltip();
  44095. }
  44096. juce_UseDebuggingNewOperator
  44097. private:
  44098. TreeView* const owner;
  44099. Array <TreeViewItem*> rowComponentItems;
  44100. Array <int> rowComponentIds;
  44101. Array <Component*> rowComponents;
  44102. TreeViewItem* buttonUnderMouse;
  44103. bool isDragging, needSelectionOnMouseUp;
  44104. TreeViewContentComponent (const TreeViewContentComponent&);
  44105. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44106. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44107. {
  44108. TreeViewItem* firstSelected = 0;
  44109. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44110. {
  44111. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44112. jassert (lastSelected != 0);
  44113. int rowStart = firstSelected->getRowNumberInTree();
  44114. int rowEnd = lastSelected->getRowNumberInTree();
  44115. if (rowStart > rowEnd)
  44116. swapVariables (rowStart, rowEnd);
  44117. int ourRow = item->getRowNumberInTree();
  44118. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44119. if (ourRow > otherEnd)
  44120. swapVariables (ourRow, otherEnd);
  44121. for (int i = ourRow; i <= otherEnd; ++i)
  44122. owner->getItemOnRow (i)->setSelected (true, false);
  44123. }
  44124. else
  44125. {
  44126. const bool cmd = modifiers.isCommandDown();
  44127. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44128. }
  44129. }
  44130. bool containsItem (TreeViewItem* const item) const
  44131. {
  44132. for (int i = rowComponentItems.size(); --i >= 0;)
  44133. if (rowComponentItems.getUnchecked(i) == item)
  44134. return true;
  44135. return false;
  44136. }
  44137. };
  44138. class TreeView::TreeViewport : public Viewport
  44139. {
  44140. public:
  44141. TreeViewport() throw() {}
  44142. ~TreeViewport() throw() {}
  44143. void updateComponents()
  44144. {
  44145. TreeViewContentComponent* const tvc = static_cast <TreeViewContentComponent*> (getViewedComponent());
  44146. if (tvc != 0)
  44147. tvc->updateComponents();
  44148. repaint();
  44149. }
  44150. void visibleAreaChanged (int, int, int, int)
  44151. {
  44152. updateComponents();
  44153. }
  44154. juce_UseDebuggingNewOperator
  44155. private:
  44156. TreeViewport (const TreeViewport&);
  44157. TreeViewport& operator= (const TreeViewport&);
  44158. };
  44159. TreeView::TreeView (const String& componentName)
  44160. : Component (componentName),
  44161. rootItem (0),
  44162. dragInsertPointHighlight (0),
  44163. dragTargetGroupHighlight (0),
  44164. indentSize (24),
  44165. defaultOpenness (false),
  44166. needsRecalculating (true),
  44167. rootItemVisible (true),
  44168. multiSelectEnabled (false),
  44169. openCloseButtonsVisible (true)
  44170. {
  44171. addAndMakeVisible (viewport = new TreeViewport());
  44172. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44173. viewport->setWantsKeyboardFocus (false);
  44174. setWantsKeyboardFocus (true);
  44175. }
  44176. TreeView::~TreeView()
  44177. {
  44178. if (rootItem != 0)
  44179. rootItem->setOwnerView (0);
  44180. deleteAllChildren();
  44181. }
  44182. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44183. {
  44184. if (rootItem != newRootItem)
  44185. {
  44186. if (newRootItem != 0)
  44187. {
  44188. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44189. if (newRootItem->ownerView != 0)
  44190. newRootItem->ownerView->setRootItem (0);
  44191. }
  44192. if (rootItem != 0)
  44193. rootItem->setOwnerView (0);
  44194. rootItem = newRootItem;
  44195. if (newRootItem != 0)
  44196. newRootItem->setOwnerView (this);
  44197. needsRecalculating = true;
  44198. handleAsyncUpdate();
  44199. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44200. {
  44201. rootItem->setOpen (false); // force a re-open
  44202. rootItem->setOpen (true);
  44203. }
  44204. }
  44205. }
  44206. void TreeView::deleteRootItem()
  44207. {
  44208. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44209. setRootItem (0);
  44210. }
  44211. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44212. {
  44213. rootItemVisible = shouldBeVisible;
  44214. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44215. {
  44216. rootItem->setOpen (false); // force a re-open
  44217. rootItem->setOpen (true);
  44218. }
  44219. itemsChanged();
  44220. }
  44221. void TreeView::colourChanged()
  44222. {
  44223. setOpaque (findColour (backgroundColourId).isOpaque());
  44224. repaint();
  44225. }
  44226. void TreeView::setIndentSize (const int newIndentSize)
  44227. {
  44228. if (indentSize != newIndentSize)
  44229. {
  44230. indentSize = newIndentSize;
  44231. resized();
  44232. }
  44233. }
  44234. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44235. {
  44236. if (defaultOpenness != isOpenByDefault)
  44237. {
  44238. defaultOpenness = isOpenByDefault;
  44239. itemsChanged();
  44240. }
  44241. }
  44242. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44243. {
  44244. multiSelectEnabled = canMultiSelect;
  44245. }
  44246. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44247. {
  44248. if (openCloseButtonsVisible != shouldBeVisible)
  44249. {
  44250. openCloseButtonsVisible = shouldBeVisible;
  44251. itemsChanged();
  44252. }
  44253. }
  44254. Viewport* TreeView::getViewport() const throw()
  44255. {
  44256. return viewport;
  44257. }
  44258. void TreeView::clearSelectedItems()
  44259. {
  44260. if (rootItem != 0)
  44261. rootItem->deselectAllRecursively();
  44262. }
  44263. int TreeView::getNumSelectedItems() const throw()
  44264. {
  44265. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44266. }
  44267. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44268. {
  44269. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44270. }
  44271. int TreeView::getNumRowsInTree() const
  44272. {
  44273. if (rootItem != 0)
  44274. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44275. return 0;
  44276. }
  44277. TreeViewItem* TreeView::getItemOnRow (int index) const
  44278. {
  44279. if (! rootItemVisible)
  44280. ++index;
  44281. if (rootItem != 0 && index >= 0)
  44282. return rootItem->getItemOnRow (index);
  44283. return 0;
  44284. }
  44285. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44286. {
  44287. TreeViewContentComponent* const tc = static_cast <TreeViewContentComponent*> (viewport->getViewedComponent());
  44288. Rectangle<int> pos;
  44289. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44290. }
  44291. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44292. {
  44293. if (rootItem == 0)
  44294. return 0;
  44295. return rootItem->findItemFromIdentifierString (identifierString);
  44296. }
  44297. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44298. {
  44299. XmlElement* e = 0;
  44300. if (rootItem != 0)
  44301. {
  44302. e = rootItem->getOpennessState();
  44303. if (e != 0 && alsoIncludeScrollPosition)
  44304. e->setAttribute ("scrollPos", viewport->getViewPositionY());
  44305. }
  44306. return e;
  44307. }
  44308. void TreeView::restoreOpennessState (const XmlElement& newState)
  44309. {
  44310. if (rootItem != 0)
  44311. {
  44312. rootItem->restoreOpennessState (newState);
  44313. if (newState.hasAttribute ("scrollPos"))
  44314. viewport->setViewPosition (viewport->getViewPositionX(),
  44315. newState.getIntAttribute ("scrollPos"));
  44316. }
  44317. }
  44318. void TreeView::paint (Graphics& g)
  44319. {
  44320. g.fillAll (findColour (backgroundColourId));
  44321. }
  44322. void TreeView::resized()
  44323. {
  44324. viewport->setBounds (0, 0, getWidth(), getHeight());
  44325. itemsChanged();
  44326. handleAsyncUpdate();
  44327. }
  44328. void TreeView::enablementChanged()
  44329. {
  44330. repaint();
  44331. }
  44332. void TreeView::moveSelectedRow (int delta)
  44333. {
  44334. if (delta == 0)
  44335. return;
  44336. int rowSelected = 0;
  44337. TreeViewItem* const firstSelected = getSelectedItem (0);
  44338. if (firstSelected != 0)
  44339. rowSelected = firstSelected->getRowNumberInTree();
  44340. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44341. for (;;)
  44342. {
  44343. TreeViewItem* item = getItemOnRow (rowSelected);
  44344. if (item != 0)
  44345. {
  44346. if (! item->canBeSelected())
  44347. {
  44348. // if the row we want to highlight doesn't allow it, try skipping
  44349. // to the next item..
  44350. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44351. rowSelected + (delta < 0 ? -1 : 1));
  44352. if (rowSelected != nextRowToTry)
  44353. {
  44354. rowSelected = nextRowToTry;
  44355. continue;
  44356. }
  44357. else
  44358. {
  44359. break;
  44360. }
  44361. }
  44362. item->setSelected (true, true);
  44363. scrollToKeepItemVisible (item);
  44364. }
  44365. break;
  44366. }
  44367. }
  44368. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44369. {
  44370. if (item != 0 && item->ownerView == this)
  44371. {
  44372. handleAsyncUpdate();
  44373. item = item->getDeepestOpenParentItem();
  44374. int y = item->y;
  44375. int viewTop = viewport->getViewPositionY();
  44376. if (y < viewTop)
  44377. {
  44378. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44379. }
  44380. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44381. {
  44382. viewport->setViewPosition (viewport->getViewPositionX(),
  44383. (y + item->itemHeight) - viewport->getViewHeight());
  44384. }
  44385. }
  44386. }
  44387. bool TreeView::keyPressed (const KeyPress& key)
  44388. {
  44389. if (key.isKeyCode (KeyPress::upKey))
  44390. {
  44391. moveSelectedRow (-1);
  44392. }
  44393. else if (key.isKeyCode (KeyPress::downKey))
  44394. {
  44395. moveSelectedRow (1);
  44396. }
  44397. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44398. {
  44399. if (rootItem != 0)
  44400. {
  44401. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44402. if (key.isKeyCode (KeyPress::pageUpKey))
  44403. rowsOnScreen = -rowsOnScreen;
  44404. moveSelectedRow (rowsOnScreen);
  44405. }
  44406. }
  44407. else if (key.isKeyCode (KeyPress::homeKey))
  44408. {
  44409. moveSelectedRow (-0x3fffffff);
  44410. }
  44411. else if (key.isKeyCode (KeyPress::endKey))
  44412. {
  44413. moveSelectedRow (0x3fffffff);
  44414. }
  44415. else if (key.isKeyCode (KeyPress::returnKey))
  44416. {
  44417. TreeViewItem* const firstSelected = getSelectedItem (0);
  44418. if (firstSelected != 0)
  44419. firstSelected->setOpen (! firstSelected->isOpen());
  44420. }
  44421. else if (key.isKeyCode (KeyPress::leftKey))
  44422. {
  44423. TreeViewItem* const firstSelected = getSelectedItem (0);
  44424. if (firstSelected != 0)
  44425. {
  44426. if (firstSelected->isOpen())
  44427. {
  44428. firstSelected->setOpen (false);
  44429. }
  44430. else
  44431. {
  44432. TreeViewItem* parent = firstSelected->parentItem;
  44433. if ((! rootItemVisible) && parent == rootItem)
  44434. parent = 0;
  44435. if (parent != 0)
  44436. {
  44437. parent->setSelected (true, true);
  44438. scrollToKeepItemVisible (parent);
  44439. }
  44440. }
  44441. }
  44442. }
  44443. else if (key.isKeyCode (KeyPress::rightKey))
  44444. {
  44445. TreeViewItem* const firstSelected = getSelectedItem (0);
  44446. if (firstSelected != 0)
  44447. {
  44448. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  44449. moveSelectedRow (1);
  44450. else
  44451. firstSelected->setOpen (true);
  44452. }
  44453. }
  44454. else
  44455. {
  44456. return false;
  44457. }
  44458. return true;
  44459. }
  44460. void TreeView::itemsChanged() throw()
  44461. {
  44462. needsRecalculating = true;
  44463. repaint();
  44464. triggerAsyncUpdate();
  44465. }
  44466. void TreeView::handleAsyncUpdate()
  44467. {
  44468. if (needsRecalculating)
  44469. {
  44470. needsRecalculating = false;
  44471. const ScopedLock sl (nodeAlterationLock);
  44472. if (rootItem != 0)
  44473. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  44474. viewport->updateComponents();
  44475. if (rootItem != 0)
  44476. {
  44477. viewport->getViewedComponent()
  44478. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  44479. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  44480. }
  44481. else
  44482. {
  44483. viewport->getViewedComponent()->setSize (0, 0);
  44484. }
  44485. }
  44486. }
  44487. class TreeView::InsertPointHighlight : public Component
  44488. {
  44489. public:
  44490. InsertPointHighlight()
  44491. : lastItem (0)
  44492. {
  44493. setSize (100, 12);
  44494. setAlwaysOnTop (true);
  44495. setInterceptsMouseClicks (false, false);
  44496. }
  44497. ~InsertPointHighlight() {}
  44498. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  44499. {
  44500. lastItem = item;
  44501. lastIndex = insertIndex;
  44502. const int offset = getHeight() / 2;
  44503. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  44504. }
  44505. void paint (Graphics& g)
  44506. {
  44507. Path p;
  44508. const float h = (float) getHeight();
  44509. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  44510. p.startNewSubPath (h - 2.0f, h / 2.0f);
  44511. p.lineTo ((float) getWidth(), h / 2.0f);
  44512. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44513. g.strokePath (p, PathStrokeType (2.0f));
  44514. }
  44515. TreeViewItem* lastItem;
  44516. int lastIndex;
  44517. private:
  44518. InsertPointHighlight (const InsertPointHighlight&);
  44519. InsertPointHighlight& operator= (const InsertPointHighlight&);
  44520. };
  44521. class TreeView::TargetGroupHighlight : public Component
  44522. {
  44523. public:
  44524. TargetGroupHighlight()
  44525. {
  44526. setAlwaysOnTop (true);
  44527. setInterceptsMouseClicks (false, false);
  44528. }
  44529. ~TargetGroupHighlight() {}
  44530. void setTargetPosition (TreeViewItem* const item) throw()
  44531. {
  44532. Rectangle<int> r (item->getItemPosition (true));
  44533. r.setHeight (item->getItemHeight());
  44534. setBounds (r);
  44535. }
  44536. void paint (Graphics& g)
  44537. {
  44538. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  44539. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  44540. }
  44541. private:
  44542. TargetGroupHighlight (const TargetGroupHighlight&);
  44543. TargetGroupHighlight& operator= (const TargetGroupHighlight&);
  44544. };
  44545. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  44546. {
  44547. beginDragAutoRepeat (1000 / 30);
  44548. if (dragInsertPointHighlight == 0)
  44549. {
  44550. addAndMakeVisible (dragInsertPointHighlight = new InsertPointHighlight());
  44551. addAndMakeVisible (dragTargetGroupHighlight = new TargetGroupHighlight());
  44552. }
  44553. dragInsertPointHighlight->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  44554. dragTargetGroupHighlight->setTargetPosition (item);
  44555. }
  44556. void TreeView::hideDragHighlight() throw()
  44557. {
  44558. deleteAndZero (dragInsertPointHighlight);
  44559. deleteAndZero (dragTargetGroupHighlight);
  44560. }
  44561. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  44562. const StringArray& files, const String& sourceDescription,
  44563. Component* sourceComponent) const throw()
  44564. {
  44565. insertIndex = 0;
  44566. TreeViewItem* item = getItemAt (y);
  44567. if (item == 0)
  44568. return 0;
  44569. Rectangle<int> itemPos (item->getItemPosition (true));
  44570. insertIndex = item->getIndexInParent();
  44571. const int oldY = y;
  44572. y = itemPos.getY();
  44573. if (item->getNumSubItems() == 0 || ! item->isOpen())
  44574. {
  44575. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44576. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44577. {
  44578. // Check if we're trying to drag into an empty group item..
  44579. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  44580. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  44581. {
  44582. insertIndex = 0;
  44583. x = itemPos.getX() + getIndentSize();
  44584. y = itemPos.getBottom();
  44585. return item;
  44586. }
  44587. }
  44588. }
  44589. if (oldY > itemPos.getCentreY())
  44590. {
  44591. y += item->getItemHeight();
  44592. while (item->isLastOfSiblings() && item->parentItem != 0
  44593. && item->parentItem->parentItem != 0)
  44594. {
  44595. if (x > itemPos.getX())
  44596. break;
  44597. item = item->parentItem;
  44598. itemPos = item->getItemPosition (true);
  44599. insertIndex = item->getIndexInParent();
  44600. }
  44601. ++insertIndex;
  44602. }
  44603. x = itemPos.getX();
  44604. return item->parentItem;
  44605. }
  44606. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44607. {
  44608. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  44609. int insertIndex;
  44610. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44611. if (item != 0)
  44612. {
  44613. if (scrolled || dragInsertPointHighlight == 0
  44614. || dragInsertPointHighlight->lastItem != item
  44615. || dragInsertPointHighlight->lastIndex != insertIndex)
  44616. {
  44617. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  44618. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44619. showDragHighlight (item, insertIndex, x, y);
  44620. else
  44621. hideDragHighlight();
  44622. }
  44623. }
  44624. else
  44625. {
  44626. hideDragHighlight();
  44627. }
  44628. }
  44629. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  44630. {
  44631. hideDragHighlight();
  44632. int insertIndex;
  44633. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  44634. if (item != 0)
  44635. {
  44636. if (files.size() > 0)
  44637. {
  44638. if (item->isInterestedInFileDrag (files))
  44639. item->filesDropped (files, insertIndex);
  44640. }
  44641. else
  44642. {
  44643. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  44644. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  44645. }
  44646. }
  44647. }
  44648. bool TreeView::isInterestedInFileDrag (const StringArray&)
  44649. {
  44650. return true;
  44651. }
  44652. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  44653. {
  44654. fileDragMove (files, x, y);
  44655. }
  44656. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  44657. {
  44658. handleDrag (files, String::empty, 0, x, y);
  44659. }
  44660. void TreeView::fileDragExit (const StringArray&)
  44661. {
  44662. hideDragHighlight();
  44663. }
  44664. void TreeView::filesDropped (const StringArray& files, int x, int y)
  44665. {
  44666. handleDrop (files, String::empty, 0, x, y);
  44667. }
  44668. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44669. {
  44670. return true;
  44671. }
  44672. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44673. {
  44674. itemDragMove (sourceDescription, sourceComponent, x, y);
  44675. }
  44676. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44677. {
  44678. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  44679. }
  44680. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44681. {
  44682. hideDragHighlight();
  44683. }
  44684. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  44685. {
  44686. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  44687. }
  44688. void TreeViewContentComponent::paint (Graphics& g)
  44689. {
  44690. if (owner->rootItem != 0)
  44691. {
  44692. owner->handleAsyncUpdate();
  44693. if (! owner->rootItemVisible)
  44694. g.setOrigin (0, -owner->rootItem->itemHeight);
  44695. owner->rootItem->paintRecursively (g, getWidth());
  44696. }
  44697. }
  44698. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  44699. {
  44700. if (owner->rootItem != 0)
  44701. {
  44702. owner->handleAsyncUpdate();
  44703. if (! owner->rootItemVisible)
  44704. y += owner->rootItem->itemHeight;
  44705. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  44706. if (ti != 0)
  44707. itemPosition = ti->getItemPosition (false);
  44708. return ti;
  44709. }
  44710. return 0;
  44711. }
  44712. enum TreeViewOpenness
  44713. {
  44714. opennessDefault = 0,
  44715. opennessClosed = 1,
  44716. opennessOpen = 2
  44717. };
  44718. TreeViewItem::TreeViewItem()
  44719. : ownerView (0),
  44720. parentItem (0),
  44721. y (0),
  44722. itemHeight (0),
  44723. totalHeight (0),
  44724. selected (false),
  44725. redrawNeeded (true),
  44726. drawLinesInside (true),
  44727. drawsInLeftMargin (false),
  44728. openness (opennessDefault)
  44729. {
  44730. static int nextUID = 0;
  44731. uid = nextUID++;
  44732. }
  44733. TreeViewItem::~TreeViewItem()
  44734. {
  44735. }
  44736. const String TreeViewItem::getUniqueName() const
  44737. {
  44738. return String::empty;
  44739. }
  44740. void TreeViewItem::itemOpennessChanged (bool)
  44741. {
  44742. }
  44743. int TreeViewItem::getNumSubItems() const throw()
  44744. {
  44745. return subItems.size();
  44746. }
  44747. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  44748. {
  44749. return subItems [index];
  44750. }
  44751. void TreeViewItem::clearSubItems()
  44752. {
  44753. if (subItems.size() > 0)
  44754. {
  44755. if (ownerView != 0)
  44756. {
  44757. const ScopedLock sl (ownerView->nodeAlterationLock);
  44758. subItems.clear();
  44759. treeHasChanged();
  44760. }
  44761. else
  44762. {
  44763. subItems.clear();
  44764. }
  44765. }
  44766. }
  44767. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  44768. {
  44769. if (newItem != 0)
  44770. {
  44771. newItem->parentItem = this;
  44772. newItem->setOwnerView (ownerView);
  44773. newItem->y = 0;
  44774. newItem->itemHeight = newItem->getItemHeight();
  44775. newItem->totalHeight = 0;
  44776. newItem->itemWidth = newItem->getItemWidth();
  44777. newItem->totalWidth = 0;
  44778. if (ownerView != 0)
  44779. {
  44780. const ScopedLock sl (ownerView->nodeAlterationLock);
  44781. subItems.insert (insertPosition, newItem);
  44782. treeHasChanged();
  44783. if (newItem->isOpen())
  44784. newItem->itemOpennessChanged (true);
  44785. }
  44786. else
  44787. {
  44788. subItems.insert (insertPosition, newItem);
  44789. if (newItem->isOpen())
  44790. newItem->itemOpennessChanged (true);
  44791. }
  44792. }
  44793. }
  44794. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  44795. {
  44796. if (ownerView != 0)
  44797. {
  44798. const ScopedLock sl (ownerView->nodeAlterationLock);
  44799. if (((unsigned int) index) < (unsigned int) subItems.size())
  44800. {
  44801. subItems.remove (index, deleteItem);
  44802. treeHasChanged();
  44803. }
  44804. }
  44805. else
  44806. {
  44807. subItems.remove (index, deleteItem);
  44808. }
  44809. }
  44810. bool TreeViewItem::isOpen() const throw()
  44811. {
  44812. if (openness == opennessDefault)
  44813. return ownerView != 0 && ownerView->defaultOpenness;
  44814. else
  44815. return openness == opennessOpen;
  44816. }
  44817. void TreeViewItem::setOpen (const bool shouldBeOpen)
  44818. {
  44819. if (isOpen() != shouldBeOpen)
  44820. {
  44821. openness = shouldBeOpen ? opennessOpen
  44822. : opennessClosed;
  44823. treeHasChanged();
  44824. itemOpennessChanged (isOpen());
  44825. }
  44826. }
  44827. bool TreeViewItem::isSelected() const throw()
  44828. {
  44829. return selected;
  44830. }
  44831. void TreeViewItem::deselectAllRecursively()
  44832. {
  44833. setSelected (false, false);
  44834. for (int i = 0; i < subItems.size(); ++i)
  44835. subItems.getUnchecked(i)->deselectAllRecursively();
  44836. }
  44837. void TreeViewItem::setSelected (const bool shouldBeSelected,
  44838. const bool deselectOtherItemsFirst)
  44839. {
  44840. if (shouldBeSelected && ! canBeSelected())
  44841. return;
  44842. if (deselectOtherItemsFirst)
  44843. getTopLevelItem()->deselectAllRecursively();
  44844. if (shouldBeSelected != selected)
  44845. {
  44846. selected = shouldBeSelected;
  44847. if (ownerView != 0)
  44848. ownerView->repaint();
  44849. itemSelectionChanged (shouldBeSelected);
  44850. }
  44851. }
  44852. void TreeViewItem::paintItem (Graphics&, int, int)
  44853. {
  44854. }
  44855. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  44856. {
  44857. ownerView->getLookAndFeel()
  44858. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  44859. }
  44860. void TreeViewItem::itemClicked (const MouseEvent&)
  44861. {
  44862. }
  44863. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  44864. {
  44865. if (mightContainSubItems())
  44866. setOpen (! isOpen());
  44867. }
  44868. void TreeViewItem::itemSelectionChanged (bool)
  44869. {
  44870. }
  44871. const String TreeViewItem::getTooltip()
  44872. {
  44873. return String::empty;
  44874. }
  44875. const String TreeViewItem::getDragSourceDescription()
  44876. {
  44877. return String::empty;
  44878. }
  44879. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  44880. {
  44881. return false;
  44882. }
  44883. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  44884. {
  44885. }
  44886. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  44887. {
  44888. return false;
  44889. }
  44890. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  44891. {
  44892. }
  44893. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  44894. {
  44895. const int indentX = getIndentX();
  44896. int width = itemWidth;
  44897. if (ownerView != 0 && width < 0)
  44898. width = ownerView->viewport->getViewWidth() - indentX;
  44899. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  44900. if (relativeToTreeViewTopLeft)
  44901. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  44902. r.getY() - ownerView->viewport->getViewPositionY());
  44903. return r;
  44904. }
  44905. void TreeViewItem::treeHasChanged() const throw()
  44906. {
  44907. if (ownerView != 0)
  44908. ownerView->itemsChanged();
  44909. }
  44910. void TreeViewItem::repaintItem() const
  44911. {
  44912. if (ownerView != 0 && areAllParentsOpen())
  44913. {
  44914. const Rectangle<int> r (getItemPosition (true));
  44915. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  44916. }
  44917. }
  44918. bool TreeViewItem::areAllParentsOpen() const throw()
  44919. {
  44920. return parentItem == 0
  44921. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  44922. }
  44923. void TreeViewItem::updatePositions (int newY)
  44924. {
  44925. y = newY;
  44926. itemHeight = getItemHeight();
  44927. totalHeight = itemHeight;
  44928. itemWidth = getItemWidth();
  44929. totalWidth = jmax (itemWidth, 0) + getIndentX();
  44930. if (isOpen())
  44931. {
  44932. newY += totalHeight;
  44933. for (int i = 0; i < subItems.size(); ++i)
  44934. {
  44935. TreeViewItem* const ti = subItems.getUnchecked(i);
  44936. ti->updatePositions (newY);
  44937. newY += ti->totalHeight;
  44938. totalHeight += ti->totalHeight;
  44939. totalWidth = jmax (totalWidth, ti->totalWidth);
  44940. }
  44941. }
  44942. }
  44943. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  44944. {
  44945. TreeViewItem* result = this;
  44946. TreeViewItem* item = this;
  44947. while (item->parentItem != 0)
  44948. {
  44949. item = item->parentItem;
  44950. if (! item->isOpen())
  44951. result = item;
  44952. }
  44953. return result;
  44954. }
  44955. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  44956. {
  44957. ownerView = newOwner;
  44958. for (int i = subItems.size(); --i >= 0;)
  44959. subItems.getUnchecked(i)->setOwnerView (newOwner);
  44960. }
  44961. int TreeViewItem::getIndentX() const throw()
  44962. {
  44963. const int indentWidth = ownerView->getIndentSize();
  44964. int x = ownerView->rootItemVisible ? indentWidth : 0;
  44965. if (! ownerView->openCloseButtonsVisible)
  44966. x -= indentWidth;
  44967. TreeViewItem* p = parentItem;
  44968. while (p != 0)
  44969. {
  44970. x += indentWidth;
  44971. p = p->parentItem;
  44972. }
  44973. return x;
  44974. }
  44975. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  44976. {
  44977. drawsInLeftMargin = canDrawInLeftMargin;
  44978. }
  44979. void TreeViewItem::paintRecursively (Graphics& g, int width)
  44980. {
  44981. jassert (ownerView != 0);
  44982. if (ownerView == 0)
  44983. return;
  44984. const int indent = getIndentX();
  44985. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  44986. g.setColour (ownerView->findColour (TreeView::linesColourId));
  44987. const float halfH = itemHeight * 0.5f;
  44988. int depth = 0;
  44989. TreeViewItem* p = parentItem;
  44990. while (p != 0)
  44991. {
  44992. ++depth;
  44993. p = p->parentItem;
  44994. }
  44995. if (! ownerView->rootItemVisible)
  44996. --depth;
  44997. const int indentWidth = ownerView->getIndentSize();
  44998. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  44999. {
  45000. float x = (depth + 0.5f) * indentWidth;
  45001. if (depth >= 0)
  45002. {
  45003. if (parentItem != 0 && parentItem->drawLinesInside)
  45004. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45005. if ((parentItem != 0 && parentItem->drawLinesInside)
  45006. || (parentItem == 0 && drawLinesInside))
  45007. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45008. }
  45009. p = parentItem;
  45010. int d = depth;
  45011. while (p != 0 && --d >= 0)
  45012. {
  45013. x -= (float) indentWidth;
  45014. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45015. && ! p->isLastOfSiblings())
  45016. {
  45017. g.drawLine (x, 0, x, (float) itemHeight);
  45018. }
  45019. p = p->parentItem;
  45020. }
  45021. if (mightContainSubItems())
  45022. {
  45023. g.saveState();
  45024. g.setOrigin (depth * indentWidth, 0);
  45025. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45026. paintOpenCloseButton (g, indentWidth, itemHeight,
  45027. static_cast <TreeViewContentComponent*> (ownerView->viewport->getViewedComponent())
  45028. ->isMouseOverButton (this));
  45029. g.restoreState();
  45030. }
  45031. }
  45032. {
  45033. g.saveState();
  45034. g.setOrigin (indent, 0);
  45035. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45036. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45037. paintItem (g, itemW, itemHeight);
  45038. g.restoreState();
  45039. }
  45040. if (isOpen())
  45041. {
  45042. const Rectangle<int> clip (g.getClipBounds());
  45043. for (int i = 0; i < subItems.size(); ++i)
  45044. {
  45045. TreeViewItem* const ti = subItems.getUnchecked(i);
  45046. const int relY = ti->y - y;
  45047. if (relY >= clip.getBottom())
  45048. break;
  45049. if (relY + ti->totalHeight >= clip.getY())
  45050. {
  45051. g.saveState();
  45052. g.setOrigin (0, relY);
  45053. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45054. ti->paintRecursively (g, width);
  45055. g.restoreState();
  45056. }
  45057. }
  45058. }
  45059. }
  45060. bool TreeViewItem::isLastOfSiblings() const throw()
  45061. {
  45062. return parentItem == 0
  45063. || parentItem->subItems.getLast() == this;
  45064. }
  45065. int TreeViewItem::getIndexInParent() const throw()
  45066. {
  45067. if (parentItem == 0)
  45068. return 0;
  45069. return parentItem->subItems.indexOf (this);
  45070. }
  45071. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45072. {
  45073. return (parentItem == 0) ? this
  45074. : parentItem->getTopLevelItem();
  45075. }
  45076. int TreeViewItem::getNumRows() const throw()
  45077. {
  45078. int num = 1;
  45079. if (isOpen())
  45080. {
  45081. for (int i = subItems.size(); --i >= 0;)
  45082. num += subItems.getUnchecked(i)->getNumRows();
  45083. }
  45084. return num;
  45085. }
  45086. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45087. {
  45088. if (index == 0)
  45089. return this;
  45090. if (index > 0 && isOpen())
  45091. {
  45092. --index;
  45093. for (int i = 0; i < subItems.size(); ++i)
  45094. {
  45095. TreeViewItem* const item = subItems.getUnchecked(i);
  45096. if (index == 0)
  45097. return item;
  45098. const int numRows = item->getNumRows();
  45099. if (numRows > index)
  45100. return item->getItemOnRow (index);
  45101. index -= numRows;
  45102. }
  45103. }
  45104. return 0;
  45105. }
  45106. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45107. {
  45108. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45109. {
  45110. const int h = itemHeight;
  45111. if (targetY < h)
  45112. return this;
  45113. if (isOpen())
  45114. {
  45115. targetY -= h;
  45116. for (int i = 0; i < subItems.size(); ++i)
  45117. {
  45118. TreeViewItem* const ti = subItems.getUnchecked(i);
  45119. if (targetY < ti->totalHeight)
  45120. return ti->findItemRecursively (targetY);
  45121. targetY -= ti->totalHeight;
  45122. }
  45123. }
  45124. }
  45125. return 0;
  45126. }
  45127. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45128. {
  45129. int total = 0;
  45130. if (isSelected())
  45131. ++total;
  45132. for (int i = subItems.size(); --i >= 0;)
  45133. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45134. return total;
  45135. }
  45136. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45137. {
  45138. if (isSelected())
  45139. {
  45140. if (index == 0)
  45141. return this;
  45142. --index;
  45143. }
  45144. if (index >= 0)
  45145. {
  45146. for (int i = 0; i < subItems.size(); ++i)
  45147. {
  45148. TreeViewItem* const item = subItems.getUnchecked(i);
  45149. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45150. if (found != 0)
  45151. return found;
  45152. index -= item->countSelectedItemsRecursively();
  45153. }
  45154. }
  45155. return 0;
  45156. }
  45157. int TreeViewItem::getRowNumberInTree() const throw()
  45158. {
  45159. if (parentItem != 0 && ownerView != 0)
  45160. {
  45161. int n = 1 + parentItem->getRowNumberInTree();
  45162. int ourIndex = parentItem->subItems.indexOf (this);
  45163. jassert (ourIndex >= 0);
  45164. while (--ourIndex >= 0)
  45165. n += parentItem->subItems [ourIndex]->getNumRows();
  45166. if (parentItem->parentItem == 0
  45167. && ! ownerView->rootItemVisible)
  45168. --n;
  45169. return n;
  45170. }
  45171. else
  45172. {
  45173. return 0;
  45174. }
  45175. }
  45176. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45177. {
  45178. drawLinesInside = drawLines;
  45179. }
  45180. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45181. {
  45182. if (recurse && isOpen() && subItems.size() > 0)
  45183. return subItems [0];
  45184. if (parentItem != 0)
  45185. {
  45186. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45187. if (nextIndex >= parentItem->subItems.size())
  45188. return parentItem->getNextVisibleItem (false);
  45189. return parentItem->subItems [nextIndex];
  45190. }
  45191. return 0;
  45192. }
  45193. const String TreeViewItem::getItemIdentifierString() const
  45194. {
  45195. String s;
  45196. if (parentItem != 0)
  45197. s = parentItem->getItemIdentifierString();
  45198. return s + "/" + getUniqueName().replaceCharacter ('/', '\\');
  45199. }
  45200. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45201. {
  45202. const String uid (getUniqueName());
  45203. if (uid == identifierString)
  45204. return this;
  45205. if (identifierString.startsWith (uid + "/"))
  45206. {
  45207. const String remainingPath (identifierString.substring (uid.length() + 1));
  45208. bool wasOpen = isOpen();
  45209. setOpen (true);
  45210. for (int i = subItems.size(); --i >= 0;)
  45211. {
  45212. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45213. if (item != 0)
  45214. return item;
  45215. }
  45216. setOpen (wasOpen);
  45217. }
  45218. return 0;
  45219. }
  45220. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45221. {
  45222. if (e.hasTagName ("CLOSED"))
  45223. {
  45224. setOpen (false);
  45225. }
  45226. else if (e.hasTagName ("OPEN"))
  45227. {
  45228. setOpen (true);
  45229. forEachXmlChildElement (e, n)
  45230. {
  45231. const String id (n->getStringAttribute ("id"));
  45232. for (int i = 0; i < subItems.size(); ++i)
  45233. {
  45234. TreeViewItem* const ti = subItems.getUnchecked(i);
  45235. if (ti->getUniqueName() == id)
  45236. {
  45237. ti->restoreOpennessState (*n);
  45238. break;
  45239. }
  45240. }
  45241. }
  45242. }
  45243. }
  45244. XmlElement* TreeViewItem::getOpennessState() const throw()
  45245. {
  45246. const String name (getUniqueName());
  45247. if (name.isNotEmpty())
  45248. {
  45249. XmlElement* e;
  45250. if (isOpen())
  45251. {
  45252. e = new XmlElement ("OPEN");
  45253. for (int i = 0; i < subItems.size(); ++i)
  45254. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45255. }
  45256. else
  45257. {
  45258. e = new XmlElement ("CLOSED");
  45259. }
  45260. e->setAttribute ("id", name);
  45261. return e;
  45262. }
  45263. else
  45264. {
  45265. // trying to save the openness for an element that has no name - this won't
  45266. // work because it needs the names to identify what to open.
  45267. jassertfalse
  45268. }
  45269. return 0;
  45270. }
  45271. END_JUCE_NAMESPACE
  45272. /*** End of inlined file: juce_TreeView.cpp ***/
  45273. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45274. BEGIN_JUCE_NAMESPACE
  45275. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45276. : fileList (listToShow)
  45277. {
  45278. }
  45279. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45280. {
  45281. }
  45282. FileBrowserListener::~FileBrowserListener()
  45283. {
  45284. }
  45285. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener)
  45286. {
  45287. listeners.add (listener);
  45288. }
  45289. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener)
  45290. {
  45291. listeners.remove (listener);
  45292. }
  45293. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45294. {
  45295. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45296. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45297. }
  45298. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45299. {
  45300. if (fileList.getDirectory().exists())
  45301. {
  45302. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45303. listeners.callChecked (checker, &FileBrowserListener::fileClicked, file, e);
  45304. }
  45305. }
  45306. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45307. {
  45308. if (fileList.getDirectory().exists())
  45309. {
  45310. Component::BailOutChecker checker (dynamic_cast <Component*> (this));
  45311. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, file);
  45312. }
  45313. }
  45314. END_JUCE_NAMESPACE
  45315. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45316. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45317. BEGIN_JUCE_NAMESPACE
  45318. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45319. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45320. Time* creationTime, bool* isReadOnly);
  45321. bool juce_findFileNext (void* handle, String& resultFile,
  45322. bool* isDirectory, bool* isHidden, int64* fileSize,
  45323. Time* modTime, Time* creationTime, bool* isReadOnly);
  45324. void juce_findFileClose (void* handle);
  45325. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45326. TimeSliceThread& thread_)
  45327. : fileFilter (fileFilter_),
  45328. thread (thread_),
  45329. includeDirectories (false),
  45330. includeFiles (false),
  45331. ignoreHiddenFiles (true),
  45332. fileFindHandle (0),
  45333. shouldStop (true)
  45334. {
  45335. }
  45336. DirectoryContentsList::~DirectoryContentsList()
  45337. {
  45338. clear();
  45339. }
  45340. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45341. {
  45342. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45343. }
  45344. const File& DirectoryContentsList::getDirectory() const
  45345. {
  45346. return root;
  45347. }
  45348. void DirectoryContentsList::setDirectory (const File& directory,
  45349. const bool includeDirectories_,
  45350. const bool includeFiles_)
  45351. {
  45352. if (directory != root
  45353. || includeDirectories != includeDirectories_
  45354. || includeFiles != includeFiles_)
  45355. {
  45356. clear();
  45357. root = directory;
  45358. includeDirectories = includeDirectories_;
  45359. includeFiles = includeFiles_;
  45360. refresh();
  45361. }
  45362. }
  45363. void DirectoryContentsList::clear()
  45364. {
  45365. shouldStop = true;
  45366. thread.removeTimeSliceClient (this);
  45367. if (fileFindHandle != 0)
  45368. {
  45369. juce_findFileClose (fileFindHandle);
  45370. fileFindHandle = 0;
  45371. }
  45372. if (files.size() > 0)
  45373. {
  45374. files.clear();
  45375. changed();
  45376. }
  45377. }
  45378. void DirectoryContentsList::refresh()
  45379. {
  45380. clear();
  45381. if (root.isDirectory())
  45382. {
  45383. String fileFound;
  45384. bool fileFoundIsDir, isHidden, isReadOnly;
  45385. int64 fileSize;
  45386. Time modTime, creationTime;
  45387. String path (root.getFullPathName());
  45388. if (! path.endsWithChar (File::separator))
  45389. path += File::separator;
  45390. jassert (fileFindHandle == 0);
  45391. fileFindHandle = juce_findFileStart (path, "*", fileFound,
  45392. &fileFoundIsDir,
  45393. &isHidden,
  45394. &fileSize,
  45395. &modTime,
  45396. &creationTime,
  45397. &isReadOnly);
  45398. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45399. {
  45400. if (addFile (fileFound, fileFoundIsDir, isHidden,
  45401. fileSize, modTime, creationTime, isReadOnly))
  45402. {
  45403. changed();
  45404. }
  45405. }
  45406. shouldStop = false;
  45407. thread.addTimeSliceClient (this);
  45408. }
  45409. }
  45410. int DirectoryContentsList::getNumFiles() const
  45411. {
  45412. return files.size();
  45413. }
  45414. bool DirectoryContentsList::getFileInfo (const int index,
  45415. FileInfo& result) const
  45416. {
  45417. const ScopedLock sl (fileListLock);
  45418. const FileInfo* const info = files [index];
  45419. if (info != 0)
  45420. {
  45421. result = *info;
  45422. return true;
  45423. }
  45424. return false;
  45425. }
  45426. const File DirectoryContentsList::getFile (const int index) const
  45427. {
  45428. const ScopedLock sl (fileListLock);
  45429. const FileInfo* const info = files [index];
  45430. if (info != 0)
  45431. return root.getChildFile (info->filename);
  45432. return File::nonexistent;
  45433. }
  45434. bool DirectoryContentsList::isStillLoading() const
  45435. {
  45436. return fileFindHandle != 0;
  45437. }
  45438. void DirectoryContentsList::changed()
  45439. {
  45440. sendChangeMessage (this);
  45441. }
  45442. bool DirectoryContentsList::useTimeSlice()
  45443. {
  45444. const uint32 startTime = Time::getApproximateMillisecondCounter();
  45445. bool hasChanged = false;
  45446. for (int i = 100; --i >= 0;)
  45447. {
  45448. if (! checkNextFile (hasChanged))
  45449. {
  45450. if (hasChanged)
  45451. changed();
  45452. return false;
  45453. }
  45454. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  45455. break;
  45456. }
  45457. if (hasChanged)
  45458. changed();
  45459. return true;
  45460. }
  45461. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  45462. {
  45463. if (fileFindHandle != 0)
  45464. {
  45465. String fileFound;
  45466. bool fileFoundIsDir, isHidden, isReadOnly;
  45467. int64 fileSize;
  45468. Time modTime, creationTime;
  45469. if (juce_findFileNext (fileFindHandle, fileFound,
  45470. &fileFoundIsDir, &isHidden,
  45471. &fileSize,
  45472. &modTime,
  45473. &creationTime,
  45474. &isReadOnly))
  45475. {
  45476. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  45477. modTime, creationTime, isReadOnly))
  45478. {
  45479. hasChanged = true;
  45480. }
  45481. return true;
  45482. }
  45483. else
  45484. {
  45485. juce_findFileClose (fileFindHandle);
  45486. fileFindHandle = 0;
  45487. }
  45488. }
  45489. return false;
  45490. }
  45491. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  45492. const DirectoryContentsList::FileInfo* const second)
  45493. {
  45494. #if JUCE_WINDOWS
  45495. if (first->isDirectory != second->isDirectory)
  45496. return first->isDirectory ? -1 : 1;
  45497. #endif
  45498. return first->filename.compareIgnoreCase (second->filename);
  45499. }
  45500. bool DirectoryContentsList::addFile (const String& filename,
  45501. const bool isDir,
  45502. const bool isHidden,
  45503. const int64 fileSize,
  45504. const Time& modTime,
  45505. const Time& creationTime,
  45506. const bool isReadOnly)
  45507. {
  45508. if (filename == ".."
  45509. || filename == "."
  45510. || (ignoreHiddenFiles && isHidden))
  45511. return false;
  45512. const File file (root.getChildFile (filename));
  45513. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  45514. && (fileFilter == 0
  45515. || ((! isDir) && fileFilter->isFileSuitable (file))
  45516. || (isDir && fileFilter->isDirectorySuitable (file))))
  45517. {
  45518. ScopedPointer <FileInfo> info (new FileInfo());
  45519. info->filename = filename;
  45520. info->fileSize = fileSize;
  45521. info->modificationTime = modTime;
  45522. info->creationTime = creationTime;
  45523. info->isDirectory = isDir;
  45524. info->isReadOnly = isReadOnly;
  45525. const ScopedLock sl (fileListLock);
  45526. for (int i = files.size(); --i >= 0;)
  45527. if (files.getUnchecked(i)->filename == info->filename)
  45528. return false;
  45529. files.addSorted (*this, info.release());
  45530. return true;
  45531. }
  45532. return false;
  45533. }
  45534. END_JUCE_NAMESPACE
  45535. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  45536. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  45537. BEGIN_JUCE_NAMESPACE
  45538. FileBrowserComponent::FileBrowserComponent (int flags_,
  45539. const File& initialFileOrDirectory,
  45540. const FileFilter* fileFilter_,
  45541. FilePreviewComponent* previewComp_)
  45542. : FileFilter (String::empty),
  45543. fileFilter (fileFilter_),
  45544. flags (flags_),
  45545. previewComp (previewComp_),
  45546. thread ("Juce FileBrowser")
  45547. {
  45548. // You need to specify one or other of the open/save flags..
  45549. jassert ((flags & (saveMode | openMode)) != 0);
  45550. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  45551. // You need to specify at least one of these flags..
  45552. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  45553. String filename;
  45554. if (initialFileOrDirectory == File::nonexistent)
  45555. {
  45556. currentRoot = File::getCurrentWorkingDirectory();
  45557. }
  45558. else if (initialFileOrDirectory.isDirectory())
  45559. {
  45560. currentRoot = initialFileOrDirectory;
  45561. }
  45562. else
  45563. {
  45564. chosenFiles.add (initialFileOrDirectory);
  45565. currentRoot = initialFileOrDirectory.getParentDirectory();
  45566. filename = initialFileOrDirectory.getFileName();
  45567. }
  45568. fileList = new DirectoryContentsList (this, thread);
  45569. if ((flags & useTreeView) != 0)
  45570. {
  45571. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  45572. if ((flags & canSelectMultipleItems) != 0)
  45573. tree->setMultiSelectEnabled (true);
  45574. addAndMakeVisible (tree);
  45575. fileListComponent = tree;
  45576. }
  45577. else
  45578. {
  45579. FileListComponent* const list = new FileListComponent (*fileList);
  45580. list->setOutlineThickness (1);
  45581. if ((flags & canSelectMultipleItems) != 0)
  45582. list->setMultipleSelectionEnabled (true);
  45583. addAndMakeVisible (list);
  45584. fileListComponent = list;
  45585. }
  45586. fileListComponent->addListener (this);
  45587. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  45588. currentPathBox->setEditableText (true);
  45589. StringArray rootNames, rootPaths;
  45590. const BigInteger separators (getRoots (rootNames, rootPaths));
  45591. for (int i = 0; i < rootNames.size(); ++i)
  45592. {
  45593. if (separators [i])
  45594. currentPathBox->addSeparator();
  45595. currentPathBox->addItem (rootNames[i], i + 1);
  45596. }
  45597. currentPathBox->addSeparator();
  45598. currentPathBox->addListener (this);
  45599. addAndMakeVisible (filenameBox = new TextEditor());
  45600. filenameBox->setMultiLine (false);
  45601. filenameBox->setSelectAllWhenFocused (true);
  45602. filenameBox->setText (filename, false);
  45603. filenameBox->addListener (this);
  45604. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  45605. Label* label = new Label ("f", TRANS("file:"));
  45606. addAndMakeVisible (label);
  45607. label->attachToComponent (filenameBox, true);
  45608. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  45609. goUpButton->addButtonListener (this);
  45610. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  45611. if (previewComp != 0)
  45612. addAndMakeVisible (previewComp);
  45613. setRoot (currentRoot);
  45614. thread.startThread (4);
  45615. }
  45616. FileBrowserComponent::~FileBrowserComponent()
  45617. {
  45618. if (previewComp != 0)
  45619. removeChildComponent (previewComp);
  45620. deleteAllChildren();
  45621. fileList = 0;
  45622. thread.stopThread (10000);
  45623. }
  45624. void FileBrowserComponent::addListener (FileBrowserListener* const newListener)
  45625. {
  45626. listeners.add (newListener);
  45627. }
  45628. void FileBrowserComponent::removeListener (FileBrowserListener* const listener)
  45629. {
  45630. listeners.remove (listener);
  45631. }
  45632. bool FileBrowserComponent::isSaveMode() const throw()
  45633. {
  45634. return (flags & saveMode) != 0;
  45635. }
  45636. int FileBrowserComponent::getNumSelectedFiles() const throw()
  45637. {
  45638. if (chosenFiles.size() == 0 && currentFileIsValid())
  45639. return 1;
  45640. return chosenFiles.size();
  45641. }
  45642. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  45643. {
  45644. if (! filenameBox->isReadOnly())
  45645. return currentRoot.getChildFile (filenameBox->getText());
  45646. else
  45647. return chosenFiles[index];
  45648. }
  45649. bool FileBrowserComponent::currentFileIsValid() const
  45650. {
  45651. if (isSaveMode())
  45652. return ! getSelectedFile (0).isDirectory();
  45653. else
  45654. return getSelectedFile (0).exists();
  45655. }
  45656. const File FileBrowserComponent::getHighlightedFile() const throw()
  45657. {
  45658. return fileListComponent->getSelectedFile (0);
  45659. }
  45660. bool FileBrowserComponent::isFileSuitable (const File& file) const
  45661. {
  45662. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  45663. : false;
  45664. }
  45665. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  45666. {
  45667. return true;
  45668. }
  45669. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  45670. {
  45671. if (f.isDirectory())
  45672. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  45673. return (flags & canSelectFiles) != 0 && f.exists()
  45674. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  45675. }
  45676. const File FileBrowserComponent::getRoot() const
  45677. {
  45678. return currentRoot;
  45679. }
  45680. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  45681. {
  45682. if (currentRoot != newRootDirectory)
  45683. {
  45684. fileListComponent->scrollToTop();
  45685. String path (newRootDirectory.getFullPathName());
  45686. if (path.isEmpty())
  45687. path += File::separator;
  45688. StringArray rootNames, rootPaths;
  45689. getRoots (rootNames, rootPaths);
  45690. if (! rootPaths.contains (path, true))
  45691. {
  45692. bool alreadyListed = false;
  45693. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  45694. {
  45695. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  45696. {
  45697. alreadyListed = true;
  45698. break;
  45699. }
  45700. }
  45701. if (! alreadyListed)
  45702. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  45703. }
  45704. }
  45705. currentRoot = newRootDirectory;
  45706. fileList->setDirectory (currentRoot, true, true);
  45707. String currentRootName (currentRoot.getFullPathName());
  45708. if (currentRootName.isEmpty())
  45709. currentRootName += File::separator;
  45710. currentPathBox->setText (currentRootName, true);
  45711. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  45712. && currentRoot.getParentDirectory() != currentRoot);
  45713. }
  45714. void FileBrowserComponent::goUp()
  45715. {
  45716. setRoot (getRoot().getParentDirectory());
  45717. }
  45718. void FileBrowserComponent::refresh()
  45719. {
  45720. fileList->refresh();
  45721. }
  45722. const String FileBrowserComponent::getActionVerb() const
  45723. {
  45724. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  45725. }
  45726. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  45727. {
  45728. return previewComp;
  45729. }
  45730. void FileBrowserComponent::resized()
  45731. {
  45732. getLookAndFeel()
  45733. .layoutFileBrowserComponent (*this, fileListComponent,
  45734. previewComp, currentPathBox,
  45735. filenameBox, goUpButton);
  45736. }
  45737. void FileBrowserComponent::sendListenerChangeMessage()
  45738. {
  45739. Component::BailOutChecker checker (this);
  45740. if (previewComp != 0)
  45741. previewComp->selectedFileChanged (getSelectedFile (0));
  45742. // You shouldn't delete the browser when the file gets changed!
  45743. jassert (! checker.shouldBailOut());
  45744. listeners.callChecked (checker, &FileBrowserListener::selectionChanged);
  45745. }
  45746. void FileBrowserComponent::selectionChanged()
  45747. {
  45748. StringArray newFilenames;
  45749. bool resetChosenFiles = true;
  45750. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  45751. {
  45752. const File f (fileListComponent->getSelectedFile (i));
  45753. if (isFileOrDirSuitable (f))
  45754. {
  45755. if (resetChosenFiles)
  45756. {
  45757. chosenFiles.clear();
  45758. resetChosenFiles = false;
  45759. }
  45760. chosenFiles.add (f);
  45761. newFilenames.add (f.getRelativePathFrom (getRoot()));
  45762. }
  45763. }
  45764. if (newFilenames.size() > 0)
  45765. filenameBox->setText (newFilenames.joinIntoString (", "), false);
  45766. sendListenerChangeMessage();
  45767. }
  45768. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  45769. {
  45770. Component::BailOutChecker checker (this);
  45771. listeners.callChecked (checker, &FileBrowserListener::fileClicked, f, e);
  45772. }
  45773. void FileBrowserComponent::fileDoubleClicked (const File& f)
  45774. {
  45775. if (f.isDirectory())
  45776. {
  45777. setRoot (f);
  45778. }
  45779. else
  45780. {
  45781. Component::BailOutChecker checker (this);
  45782. listeners.callChecked (checker, &FileBrowserListener::fileDoubleClicked, f);
  45783. }
  45784. }
  45785. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  45786. {
  45787. #if JUCE_LINUX || JUCE_WINDOWS
  45788. if (key.getModifiers().isCommandDown()
  45789. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  45790. {
  45791. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  45792. fileList->refresh();
  45793. return true;
  45794. }
  45795. #endif
  45796. return false;
  45797. }
  45798. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  45799. {
  45800. sendListenerChangeMessage();
  45801. }
  45802. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  45803. {
  45804. if (filenameBox->getText().containsChar (File::separator))
  45805. {
  45806. const File f (currentRoot.getChildFile (filenameBox->getText()));
  45807. if (f.isDirectory())
  45808. {
  45809. setRoot (f);
  45810. chosenFiles.clear();
  45811. filenameBox->setText (String::empty);
  45812. }
  45813. else
  45814. {
  45815. setRoot (f.getParentDirectory());
  45816. chosenFiles.clear();
  45817. chosenFiles.add (f);
  45818. filenameBox->setText (f.getFileName());
  45819. }
  45820. }
  45821. else
  45822. {
  45823. fileDoubleClicked (getSelectedFile (0));
  45824. }
  45825. }
  45826. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  45827. {
  45828. }
  45829. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  45830. {
  45831. if (! isSaveMode())
  45832. selectionChanged();
  45833. }
  45834. void FileBrowserComponent::buttonClicked (Button*)
  45835. {
  45836. goUp();
  45837. }
  45838. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  45839. {
  45840. const String newText (currentPathBox->getText().trim().unquoted());
  45841. if (newText.isNotEmpty())
  45842. {
  45843. const int index = currentPathBox->getSelectedId() - 1;
  45844. StringArray rootNames, rootPaths;
  45845. getRoots (rootNames, rootPaths);
  45846. if (rootPaths [index].isNotEmpty())
  45847. {
  45848. setRoot (File (rootPaths [index]));
  45849. }
  45850. else
  45851. {
  45852. File f (newText);
  45853. for (;;)
  45854. {
  45855. if (f.isDirectory())
  45856. {
  45857. setRoot (f);
  45858. break;
  45859. }
  45860. if (f.getParentDirectory() == f)
  45861. break;
  45862. f = f.getParentDirectory();
  45863. }
  45864. }
  45865. }
  45866. }
  45867. const BigInteger FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  45868. {
  45869. BigInteger separators;
  45870. #if JUCE_WINDOWS
  45871. Array<File> roots;
  45872. File::findFileSystemRoots (roots);
  45873. rootPaths.clear();
  45874. for (int i = 0; i < roots.size(); ++i)
  45875. {
  45876. const File& drive = roots.getReference(i);
  45877. String name (drive.getFullPathName());
  45878. rootPaths.add (name);
  45879. if (drive.isOnHardDisk())
  45880. {
  45881. String volume (drive.getVolumeLabel());
  45882. if (volume.isEmpty())
  45883. volume = TRANS("Hard Drive");
  45884. name << " [" << drive.getVolumeLabel() << ']';
  45885. }
  45886. else if (drive.isOnCDRomDrive())
  45887. {
  45888. name << TRANS(" [CD/DVD drive]");
  45889. }
  45890. rootNames.add (name);
  45891. }
  45892. separators.setBit (rootPaths.size());
  45893. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45894. rootNames.add ("Documents");
  45895. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45896. rootNames.add ("Desktop");
  45897. #endif
  45898. #if JUCE_MAC
  45899. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45900. rootNames.add ("Home folder");
  45901. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  45902. rootNames.add ("Documents");
  45903. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45904. rootNames.add ("Desktop");
  45905. separators.setBit (rootPaths.size());
  45906. Array <File> volumes;
  45907. File vol ("/Volumes");
  45908. vol.findChildFiles (volumes, File::findDirectories, false);
  45909. for (int i = 0; i < volumes.size(); ++i)
  45910. {
  45911. const File& volume = volumes.getReference(i);
  45912. if (volume.isDirectory() && ! volume.getFileName().startsWithChar ('.'))
  45913. {
  45914. rootPaths.add (volume.getFullPathName());
  45915. rootNames.add (volume.getFileName());
  45916. }
  45917. }
  45918. #endif
  45919. #if JUCE_LINUX
  45920. rootPaths.add ("/");
  45921. rootNames.add ("/");
  45922. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  45923. rootNames.add ("Home folder");
  45924. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  45925. rootNames.add ("Desktop");
  45926. #endif
  45927. return separators;
  45928. }
  45929. END_JUCE_NAMESPACE
  45930. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  45931. /*** Start of inlined file: juce_FileChooser.cpp ***/
  45932. BEGIN_JUCE_NAMESPACE
  45933. FileChooser::FileChooser (const String& chooserBoxTitle,
  45934. const File& currentFileOrDirectory,
  45935. const String& fileFilters,
  45936. const bool useNativeDialogBox_)
  45937. : title (chooserBoxTitle),
  45938. filters (fileFilters),
  45939. startingFile (currentFileOrDirectory),
  45940. useNativeDialogBox (useNativeDialogBox_)
  45941. {
  45942. #if JUCE_LINUX
  45943. useNativeDialogBox = false;
  45944. #endif
  45945. if (! fileFilters.containsNonWhitespaceChars())
  45946. filters = "*";
  45947. }
  45948. FileChooser::~FileChooser()
  45949. {
  45950. }
  45951. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  45952. {
  45953. return showDialog (false, true, false, false, false, previewComponent);
  45954. }
  45955. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  45956. {
  45957. return showDialog (false, true, false, false, true, previewComponent);
  45958. }
  45959. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  45960. {
  45961. return showDialog (true, true, false, false, true, previewComponent);
  45962. }
  45963. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  45964. {
  45965. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  45966. }
  45967. bool FileChooser::browseForDirectory()
  45968. {
  45969. return showDialog (true, false, false, false, false, 0);
  45970. }
  45971. const File FileChooser::getResult() const
  45972. {
  45973. // if you've used a multiple-file select, you should use the getResults() method
  45974. // to retrieve all the files that were chosen.
  45975. jassert (results.size() <= 1);
  45976. return results.getFirst();
  45977. }
  45978. const Array<File>& FileChooser::getResults() const
  45979. {
  45980. return results;
  45981. }
  45982. bool FileChooser::showDialog (const bool selectsDirectories,
  45983. const bool selectsFiles,
  45984. const bool isSave,
  45985. const bool warnAboutOverwritingExistingFiles,
  45986. const bool selectMultipleFiles,
  45987. FilePreviewComponent* const previewComponent)
  45988. {
  45989. Component::SafePointer<Component> previouslyFocused (Component::getCurrentlyFocusedComponent());
  45990. results.clear();
  45991. // the preview component needs to be the right size before you pass it in here..
  45992. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  45993. && previewComponent->getHeight() > 10));
  45994. #if JUCE_WINDOWS
  45995. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  45996. #elif JUCE_MAC
  45997. if (useNativeDialogBox && (previewComponent == 0))
  45998. #else
  45999. if (false)
  46000. #endif
  46001. {
  46002. showPlatformDialog (results, title, startingFile, filters,
  46003. selectsDirectories, selectsFiles, isSave,
  46004. warnAboutOverwritingExistingFiles,
  46005. selectMultipleFiles,
  46006. previewComponent);
  46007. }
  46008. else
  46009. {
  46010. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46011. selectsDirectories ? "*" : String::empty,
  46012. String::empty);
  46013. int flags = isSave ? FileBrowserComponent::saveMode
  46014. : FileBrowserComponent::openMode;
  46015. if (selectsFiles)
  46016. flags |= FileBrowserComponent::canSelectFiles;
  46017. if (selectsDirectories)
  46018. flags |= FileBrowserComponent::canSelectDirectories;
  46019. if (selectMultipleFiles)
  46020. flags |= FileBrowserComponent::canSelectMultipleItems;
  46021. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46022. FileChooserDialogBox box (title, String::empty,
  46023. browserComponent,
  46024. warnAboutOverwritingExistingFiles,
  46025. browserComponent.findColour (AlertWindow::backgroundColourId));
  46026. if (box.show())
  46027. {
  46028. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46029. results.add (browserComponent.getSelectedFile (i));
  46030. }
  46031. }
  46032. if (previouslyFocused != 0)
  46033. previouslyFocused->grabKeyboardFocus();
  46034. return results.size() > 0;
  46035. }
  46036. FilePreviewComponent::FilePreviewComponent()
  46037. {
  46038. }
  46039. FilePreviewComponent::~FilePreviewComponent()
  46040. {
  46041. }
  46042. END_JUCE_NAMESPACE
  46043. /*** End of inlined file: juce_FileChooser.cpp ***/
  46044. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46045. BEGIN_JUCE_NAMESPACE
  46046. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46047. const String& instructions,
  46048. FileBrowserComponent& chooserComponent,
  46049. const bool warnAboutOverwritingExistingFiles_,
  46050. const Colour& backgroundColour)
  46051. : ResizableWindow (name, backgroundColour, true),
  46052. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46053. {
  46054. content = new ContentComponent();
  46055. content->setName (name);
  46056. content->instructions = instructions;
  46057. content->chooserComponent = &chooserComponent;
  46058. content->addAndMakeVisible (&chooserComponent);
  46059. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46060. content->addAndMakeVisible (content->okButton);
  46061. content->okButton->addButtonListener (this);
  46062. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46063. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46064. content->cancelButton = new TextButton (TRANS("Cancel"));
  46065. content->addAndMakeVisible (content->cancelButton);
  46066. content->cancelButton->addButtonListener (this);
  46067. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46068. setContentComponent (content);
  46069. setResizable (true, true);
  46070. setResizeLimits (300, 300, 1200, 1000);
  46071. content->chooserComponent->addListener (this);
  46072. }
  46073. FileChooserDialogBox::~FileChooserDialogBox()
  46074. {
  46075. content->chooserComponent->removeListener (this);
  46076. }
  46077. bool FileChooserDialogBox::show (int w, int h)
  46078. {
  46079. if (w <= 0)
  46080. {
  46081. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46082. if (previewComp != 0)
  46083. w = 400 + previewComp->getWidth();
  46084. else
  46085. w = 600;
  46086. }
  46087. if (h <= 0)
  46088. h = 500;
  46089. centreWithSize (w, h);
  46090. const bool ok = (runModalLoop() != 0);
  46091. setVisible (false);
  46092. return ok;
  46093. }
  46094. void FileChooserDialogBox::buttonClicked (Button* button)
  46095. {
  46096. if (button == content->okButton)
  46097. {
  46098. if (warnAboutOverwritingExistingFiles
  46099. && content->chooserComponent->isSaveMode()
  46100. && content->chooserComponent->getSelectedFile(0).exists())
  46101. {
  46102. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46103. TRANS("File already exists"),
  46104. TRANS("There's already a file called:")
  46105. + "\n\n" + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46106. + "\n\n" + TRANS("Are you sure you want to overwrite it?"),
  46107. TRANS("overwrite"),
  46108. TRANS("cancel")))
  46109. {
  46110. return;
  46111. }
  46112. }
  46113. exitModalState (1);
  46114. }
  46115. else if (button == content->cancelButton)
  46116. closeButtonPressed();
  46117. }
  46118. void FileChooserDialogBox::closeButtonPressed()
  46119. {
  46120. setVisible (false);
  46121. }
  46122. void FileChooserDialogBox::selectionChanged()
  46123. {
  46124. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46125. }
  46126. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46127. {
  46128. }
  46129. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46130. {
  46131. selectionChanged();
  46132. content->okButton->triggerClick();
  46133. }
  46134. FileChooserDialogBox::ContentComponent::ContentComponent()
  46135. {
  46136. setInterceptsMouseClicks (false, true);
  46137. }
  46138. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46139. {
  46140. delete okButton;
  46141. delete cancelButton;
  46142. }
  46143. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46144. {
  46145. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46146. text.draw (g);
  46147. }
  46148. void FileChooserDialogBox::ContentComponent::resized()
  46149. {
  46150. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46151. const Rectangle<float> bb (text.getBoundingBox (0, text.getNumGlyphs(), false));
  46152. const int y = roundToInt (bb.getBottom()) + 10;
  46153. const int buttonHeight = 26;
  46154. const int buttonY = getHeight() - buttonHeight - 8;
  46155. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46156. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46157. proportionOfWidth (0.2f), buttonHeight);
  46158. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46159. proportionOfWidth (0.2f), buttonHeight);
  46160. }
  46161. END_JUCE_NAMESPACE
  46162. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46163. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46164. BEGIN_JUCE_NAMESPACE
  46165. FileFilter::FileFilter (const String& filterDescription)
  46166. : description (filterDescription)
  46167. {
  46168. }
  46169. FileFilter::~FileFilter()
  46170. {
  46171. }
  46172. const String& FileFilter::getDescription() const throw()
  46173. {
  46174. return description;
  46175. }
  46176. END_JUCE_NAMESPACE
  46177. /*** End of inlined file: juce_FileFilter.cpp ***/
  46178. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46179. BEGIN_JUCE_NAMESPACE
  46180. Image* juce_createIconForFile (const File& file);
  46181. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46182. : ListBox (String::empty, 0),
  46183. DirectoryContentsDisplayComponent (listToShow)
  46184. {
  46185. setModel (this);
  46186. fileList.addChangeListener (this);
  46187. }
  46188. FileListComponent::~FileListComponent()
  46189. {
  46190. fileList.removeChangeListener (this);
  46191. deleteAllChildren();
  46192. }
  46193. int FileListComponent::getNumSelectedFiles() const
  46194. {
  46195. return getNumSelectedRows();
  46196. }
  46197. const File FileListComponent::getSelectedFile (int index) const
  46198. {
  46199. return fileList.getFile (getSelectedRow (index));
  46200. }
  46201. void FileListComponent::scrollToTop()
  46202. {
  46203. getVerticalScrollBar()->setCurrentRangeStart (0);
  46204. }
  46205. void FileListComponent::changeListenerCallback (void*)
  46206. {
  46207. updateContent();
  46208. if (lastDirectory != fileList.getDirectory())
  46209. {
  46210. lastDirectory = fileList.getDirectory();
  46211. deselectAllRows();
  46212. }
  46213. }
  46214. class FileListItemComponent : public Component,
  46215. public TimeSliceClient,
  46216. public AsyncUpdater
  46217. {
  46218. public:
  46219. FileListItemComponent (FileListComponent& owner_, TimeSliceThread& thread_)
  46220. : owner (owner_), thread (thread_),
  46221. highlighted (false), index (0), icon (0)
  46222. {
  46223. }
  46224. ~FileListItemComponent()
  46225. {
  46226. thread.removeTimeSliceClient (this);
  46227. clearIcon();
  46228. }
  46229. void paint (Graphics& g)
  46230. {
  46231. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46232. file.getFileName(),
  46233. icon,
  46234. fileSize, modTime,
  46235. isDirectory, highlighted,
  46236. index);
  46237. }
  46238. void mouseDown (const MouseEvent& e)
  46239. {
  46240. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46241. owner.sendMouseClickMessage (file, e);
  46242. }
  46243. void mouseDoubleClick (const MouseEvent&)
  46244. {
  46245. owner.sendDoubleClickMessage (file);
  46246. }
  46247. void update (const File& root,
  46248. const DirectoryContentsList::FileInfo* const fileInfo,
  46249. const int index_,
  46250. const bool highlighted_)
  46251. {
  46252. thread.removeTimeSliceClient (this);
  46253. if (highlighted_ != highlighted
  46254. || index_ != index)
  46255. {
  46256. index = index_;
  46257. highlighted = highlighted_;
  46258. repaint();
  46259. }
  46260. File newFile;
  46261. String newFileSize;
  46262. String newModTime;
  46263. if (fileInfo != 0)
  46264. {
  46265. newFile = root.getChildFile (fileInfo->filename);
  46266. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46267. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46268. }
  46269. if (newFile != file
  46270. || fileSize != newFileSize
  46271. || modTime != newModTime)
  46272. {
  46273. file = newFile;
  46274. fileSize = newFileSize;
  46275. modTime = newModTime;
  46276. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46277. repaint();
  46278. clearIcon();
  46279. }
  46280. if (file != File::nonexistent
  46281. && icon == 0 && ! isDirectory)
  46282. {
  46283. updateIcon (true);
  46284. if (icon == 0)
  46285. thread.addTimeSliceClient (this);
  46286. }
  46287. }
  46288. bool useTimeSlice()
  46289. {
  46290. updateIcon (false);
  46291. return false;
  46292. }
  46293. void handleAsyncUpdate()
  46294. {
  46295. repaint();
  46296. }
  46297. juce_UseDebuggingNewOperator
  46298. private:
  46299. FileListComponent& owner;
  46300. TimeSliceThread& thread;
  46301. bool highlighted;
  46302. int index;
  46303. File file;
  46304. String fileSize;
  46305. String modTime;
  46306. Image* icon;
  46307. bool isDirectory;
  46308. void clearIcon()
  46309. {
  46310. ImageCache::release (icon);
  46311. icon = 0;
  46312. }
  46313. void updateIcon (const bool onlyUpdateIfCached)
  46314. {
  46315. if (icon == 0)
  46316. {
  46317. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46318. Image* im = ImageCache::getFromHashCode (hashCode);
  46319. if (im == 0 && ! onlyUpdateIfCached)
  46320. {
  46321. im = juce_createIconForFile (file);
  46322. if (im != 0)
  46323. ImageCache::addImageToCache (im, hashCode);
  46324. }
  46325. if (im != 0)
  46326. {
  46327. icon = im;
  46328. triggerAsyncUpdate();
  46329. }
  46330. }
  46331. }
  46332. };
  46333. int FileListComponent::getNumRows()
  46334. {
  46335. return fileList.getNumFiles();
  46336. }
  46337. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46338. {
  46339. }
  46340. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46341. {
  46342. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46343. if (comp == 0)
  46344. {
  46345. delete existingComponentToUpdate;
  46346. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46347. }
  46348. DirectoryContentsList::FileInfo fileInfo;
  46349. if (fileList.getFileInfo (row, fileInfo))
  46350. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46351. else
  46352. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46353. return comp;
  46354. }
  46355. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46356. {
  46357. sendSelectionChangeMessage();
  46358. }
  46359. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46360. {
  46361. }
  46362. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46363. {
  46364. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46365. }
  46366. END_JUCE_NAMESPACE
  46367. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46368. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46369. BEGIN_JUCE_NAMESPACE
  46370. FilenameComponent::FilenameComponent (const String& name,
  46371. const File& currentFile,
  46372. const bool canEditFilename,
  46373. const bool isDirectory,
  46374. const bool isForSaving,
  46375. const String& fileBrowserWildcard,
  46376. const String& enforcedSuffix_,
  46377. const String& textWhenNothingSelected)
  46378. : Component (name),
  46379. maxRecentFiles (30),
  46380. isDir (isDirectory),
  46381. isSaving (isForSaving),
  46382. isFileDragOver (false),
  46383. wildcard (fileBrowserWildcard),
  46384. enforcedSuffix (enforcedSuffix_)
  46385. {
  46386. addAndMakeVisible (filenameBox = new ComboBox ("fn"));
  46387. filenameBox->setEditableText (canEditFilename);
  46388. filenameBox->addListener (this);
  46389. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  46390. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  46391. browseButton = 0;
  46392. setBrowseButtonText ("...");
  46393. setCurrentFile (currentFile, true);
  46394. }
  46395. FilenameComponent::~FilenameComponent()
  46396. {
  46397. deleteAllChildren();
  46398. }
  46399. void FilenameComponent::paintOverChildren (Graphics& g)
  46400. {
  46401. if (isFileDragOver)
  46402. {
  46403. g.setColour (Colours::red.withAlpha (0.2f));
  46404. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  46405. }
  46406. }
  46407. void FilenameComponent::resized()
  46408. {
  46409. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  46410. }
  46411. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  46412. {
  46413. browseButtonText = newBrowseButtonText;
  46414. lookAndFeelChanged();
  46415. }
  46416. void FilenameComponent::lookAndFeelChanged()
  46417. {
  46418. deleteAndZero (browseButton);
  46419. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  46420. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  46421. resized();
  46422. browseButton->addButtonListener (this);
  46423. }
  46424. void FilenameComponent::setTooltip (const String& newTooltip)
  46425. {
  46426. SettableTooltipClient::setTooltip (newTooltip);
  46427. filenameBox->setTooltip (newTooltip);
  46428. }
  46429. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46430. {
  46431. defaultBrowseFile = newDefaultDirectory;
  46432. }
  46433. void FilenameComponent::buttonClicked (Button*)
  46434. {
  46435. FileChooser fc (TRANS("Choose a new file"),
  46436. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  46437. : getCurrentFile(),
  46438. wildcard);
  46439. if (isDir ? fc.browseForDirectory()
  46440. : (isSaving ? fc.browseForFileToSave (false)
  46441. : fc.browseForFileToOpen()))
  46442. {
  46443. setCurrentFile (fc.getResult(), true);
  46444. }
  46445. }
  46446. void FilenameComponent::comboBoxChanged (ComboBox*)
  46447. {
  46448. setCurrentFile (getCurrentFile(), true);
  46449. }
  46450. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  46451. {
  46452. return true;
  46453. }
  46454. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  46455. {
  46456. isFileDragOver = false;
  46457. repaint();
  46458. const File f (filenames[0]);
  46459. if (f.exists() && (f.isDirectory() == isDir))
  46460. setCurrentFile (f, true);
  46461. }
  46462. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  46463. {
  46464. isFileDragOver = true;
  46465. repaint();
  46466. }
  46467. void FilenameComponent::fileDragExit (const StringArray&)
  46468. {
  46469. isFileDragOver = false;
  46470. repaint();
  46471. }
  46472. const File FilenameComponent::getCurrentFile() const
  46473. {
  46474. File f (filenameBox->getText());
  46475. if (enforcedSuffix.isNotEmpty())
  46476. f = f.withFileExtension (enforcedSuffix);
  46477. return f;
  46478. }
  46479. void FilenameComponent::setCurrentFile (File newFile,
  46480. const bool addToRecentlyUsedList,
  46481. const bool sendChangeNotification)
  46482. {
  46483. if (enforcedSuffix.isNotEmpty())
  46484. newFile = newFile.withFileExtension (enforcedSuffix);
  46485. if (newFile.getFullPathName() != lastFilename)
  46486. {
  46487. lastFilename = newFile.getFullPathName();
  46488. if (addToRecentlyUsedList)
  46489. addRecentlyUsedFile (newFile);
  46490. filenameBox->setText (lastFilename, true);
  46491. if (sendChangeNotification)
  46492. triggerAsyncUpdate();
  46493. }
  46494. }
  46495. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  46496. {
  46497. filenameBox->setEditableText (shouldBeEditable);
  46498. }
  46499. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  46500. {
  46501. StringArray names;
  46502. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  46503. names.add (filenameBox->getItemText (i));
  46504. return names;
  46505. }
  46506. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  46507. {
  46508. if (filenames != getRecentlyUsedFilenames())
  46509. {
  46510. filenameBox->clear();
  46511. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  46512. filenameBox->addItem (filenames[i], i + 1);
  46513. }
  46514. }
  46515. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  46516. {
  46517. maxRecentFiles = jmax (1, newMaximum);
  46518. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  46519. }
  46520. void FilenameComponent::addRecentlyUsedFile (const File& file)
  46521. {
  46522. StringArray files (getRecentlyUsedFilenames());
  46523. if (file.getFullPathName().isNotEmpty())
  46524. {
  46525. files.removeString (file.getFullPathName(), true);
  46526. files.insert (0, file.getFullPathName());
  46527. setRecentlyUsedFilenames (files);
  46528. }
  46529. }
  46530. void FilenameComponent::addListener (FilenameComponentListener* const listener)
  46531. {
  46532. listeners.add (listener);
  46533. }
  46534. void FilenameComponent::removeListener (FilenameComponentListener* const listener)
  46535. {
  46536. listeners.remove (listener);
  46537. }
  46538. void FilenameComponent::handleAsyncUpdate()
  46539. {
  46540. Component::BailOutChecker checker (this);
  46541. listeners.callChecked (checker, &FilenameComponentListener::filenameComponentChanged, this);
  46542. }
  46543. END_JUCE_NAMESPACE
  46544. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  46545. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46546. BEGIN_JUCE_NAMESPACE
  46547. FileSearchPathListComponent::FileSearchPathListComponent()
  46548. {
  46549. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  46550. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  46551. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  46552. listBox->setOutlineThickness (1);
  46553. addAndMakeVisible (addButton = new TextButton ("+"));
  46554. addButton->addButtonListener (this);
  46555. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46556. addAndMakeVisible (removeButton = new TextButton ("-"));
  46557. removeButton->addButtonListener (this);
  46558. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  46559. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  46560. changeButton->addButtonListener (this);
  46561. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46562. upButton->addButtonListener (this);
  46563. {
  46564. Path arrowPath;
  46565. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  46566. DrawablePath arrowImage;
  46567. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46568. arrowImage.setPath (arrowPath);
  46569. upButton->setImages (&arrowImage);
  46570. }
  46571. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  46572. downButton->addButtonListener (this);
  46573. {
  46574. Path arrowPath;
  46575. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  46576. DrawablePath arrowImage;
  46577. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  46578. arrowImage.setPath (arrowPath);
  46579. downButton->setImages (&arrowImage);
  46580. }
  46581. updateButtons();
  46582. }
  46583. FileSearchPathListComponent::~FileSearchPathListComponent()
  46584. {
  46585. deleteAllChildren();
  46586. }
  46587. void FileSearchPathListComponent::updateButtons()
  46588. {
  46589. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  46590. removeButton->setEnabled (anythingSelected);
  46591. changeButton->setEnabled (anythingSelected);
  46592. upButton->setEnabled (anythingSelected);
  46593. downButton->setEnabled (anythingSelected);
  46594. }
  46595. void FileSearchPathListComponent::changed()
  46596. {
  46597. listBox->updateContent();
  46598. listBox->repaint();
  46599. updateButtons();
  46600. }
  46601. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  46602. {
  46603. if (newPath.toString() != path.toString())
  46604. {
  46605. path = newPath;
  46606. changed();
  46607. }
  46608. }
  46609. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory)
  46610. {
  46611. defaultBrowseTarget = newDefaultDirectory;
  46612. }
  46613. int FileSearchPathListComponent::getNumRows()
  46614. {
  46615. return path.getNumPaths();
  46616. }
  46617. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  46618. {
  46619. if (rowIsSelected)
  46620. g.fillAll (findColour (TextEditor::highlightColourId));
  46621. g.setColour (findColour (ListBox::textColourId));
  46622. Font f (height * 0.7f);
  46623. f.setHorizontalScale (0.9f);
  46624. g.setFont (f);
  46625. g.drawText (path [rowNumber].getFullPathName(),
  46626. 4, 0, width - 6, height,
  46627. Justification::centredLeft, true);
  46628. }
  46629. void FileSearchPathListComponent::deleteKeyPressed (int row)
  46630. {
  46631. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  46632. {
  46633. path.remove (row);
  46634. changed();
  46635. }
  46636. }
  46637. void FileSearchPathListComponent::returnKeyPressed (int row)
  46638. {
  46639. FileChooser chooser (TRANS("Change folder..."), path [row], "*");
  46640. if (chooser.browseForDirectory())
  46641. {
  46642. path.remove (row);
  46643. path.add (chooser.getResult(), row);
  46644. changed();
  46645. }
  46646. }
  46647. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  46648. {
  46649. returnKeyPressed (row);
  46650. }
  46651. void FileSearchPathListComponent::selectedRowsChanged (int)
  46652. {
  46653. updateButtons();
  46654. }
  46655. void FileSearchPathListComponent::paint (Graphics& g)
  46656. {
  46657. g.fillAll (findColour (backgroundColourId));
  46658. }
  46659. void FileSearchPathListComponent::resized()
  46660. {
  46661. const int buttonH = 22;
  46662. const int buttonY = getHeight() - buttonH - 4;
  46663. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  46664. addButton->setBounds (2, buttonY, buttonH, buttonH);
  46665. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  46666. changeButton->changeWidthToFitText (buttonH);
  46667. downButton->setSize (buttonH * 2, buttonH);
  46668. upButton->setSize (buttonH * 2, buttonH);
  46669. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  46670. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  46671. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  46672. }
  46673. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  46674. {
  46675. return true;
  46676. }
  46677. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  46678. {
  46679. for (int i = filenames.size(); --i >= 0;)
  46680. {
  46681. const File f (filenames[i]);
  46682. if (f.isDirectory())
  46683. {
  46684. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  46685. path.add (f, row);
  46686. changed();
  46687. }
  46688. }
  46689. }
  46690. void FileSearchPathListComponent::buttonClicked (Button* button)
  46691. {
  46692. const int currentRow = listBox->getSelectedRow();
  46693. if (button == removeButton)
  46694. {
  46695. deleteKeyPressed (currentRow);
  46696. }
  46697. else if (button == addButton)
  46698. {
  46699. File start (defaultBrowseTarget);
  46700. if (start == File::nonexistent)
  46701. start = path [0];
  46702. if (start == File::nonexistent)
  46703. start = File::getCurrentWorkingDirectory();
  46704. FileChooser chooser (TRANS("Add a folder..."), start, "*");
  46705. if (chooser.browseForDirectory())
  46706. {
  46707. path.add (chooser.getResult(), currentRow);
  46708. }
  46709. }
  46710. else if (button == changeButton)
  46711. {
  46712. returnKeyPressed (currentRow);
  46713. }
  46714. else if (button == upButton)
  46715. {
  46716. if (currentRow > 0 && currentRow < path.getNumPaths())
  46717. {
  46718. const File f (path[currentRow]);
  46719. path.remove (currentRow);
  46720. path.add (f, currentRow - 1);
  46721. listBox->selectRow (currentRow - 1);
  46722. }
  46723. }
  46724. else if (button == downButton)
  46725. {
  46726. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  46727. {
  46728. const File f (path[currentRow]);
  46729. path.remove (currentRow);
  46730. path.add (f, currentRow + 1);
  46731. listBox->selectRow (currentRow + 1);
  46732. }
  46733. }
  46734. changed();
  46735. }
  46736. END_JUCE_NAMESPACE
  46737. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  46738. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  46739. BEGIN_JUCE_NAMESPACE
  46740. Image* juce_createIconForFile (const File& file);
  46741. class FileListTreeItem : public TreeViewItem,
  46742. public TimeSliceClient,
  46743. public AsyncUpdater,
  46744. public ChangeListener
  46745. {
  46746. public:
  46747. FileListTreeItem (FileTreeComponent& owner_,
  46748. DirectoryContentsList* const parentContentsList_,
  46749. const int indexInContentsList_,
  46750. const File& file_,
  46751. TimeSliceThread& thread_)
  46752. : file (file_),
  46753. owner (owner_),
  46754. parentContentsList (parentContentsList_),
  46755. indexInContentsList (indexInContentsList_),
  46756. subContentsList (0),
  46757. canDeleteSubContentsList (false),
  46758. thread (thread_),
  46759. icon (0)
  46760. {
  46761. DirectoryContentsList::FileInfo fileInfo;
  46762. if (parentContentsList_ != 0
  46763. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  46764. {
  46765. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  46766. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  46767. isDirectory = fileInfo.isDirectory;
  46768. }
  46769. else
  46770. {
  46771. isDirectory = true;
  46772. }
  46773. }
  46774. ~FileListTreeItem()
  46775. {
  46776. thread.removeTimeSliceClient (this);
  46777. clearSubItems();
  46778. ImageCache::release (icon);
  46779. if (canDeleteSubContentsList)
  46780. delete subContentsList;
  46781. }
  46782. bool mightContainSubItems() { return isDirectory; }
  46783. const String getUniqueName() const { return file.getFullPathName(); }
  46784. int getItemHeight() const { return 22; }
  46785. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  46786. void itemOpennessChanged (bool isNowOpen)
  46787. {
  46788. if (isNowOpen)
  46789. {
  46790. clearSubItems();
  46791. isDirectory = file.isDirectory();
  46792. if (isDirectory)
  46793. {
  46794. if (subContentsList == 0)
  46795. {
  46796. jassert (parentContentsList != 0);
  46797. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  46798. l->setDirectory (file, true, true);
  46799. setSubContentsList (l);
  46800. canDeleteSubContentsList = true;
  46801. }
  46802. changeListenerCallback (0);
  46803. }
  46804. }
  46805. }
  46806. void setSubContentsList (DirectoryContentsList* newList)
  46807. {
  46808. jassert (subContentsList == 0);
  46809. subContentsList = newList;
  46810. newList->addChangeListener (this);
  46811. }
  46812. void changeListenerCallback (void*)
  46813. {
  46814. clearSubItems();
  46815. if (isOpen() && subContentsList != 0)
  46816. {
  46817. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  46818. {
  46819. FileListTreeItem* const item
  46820. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  46821. addSubItem (item);
  46822. }
  46823. }
  46824. }
  46825. void paintItem (Graphics& g, int width, int height)
  46826. {
  46827. if (file != File::nonexistent)
  46828. {
  46829. updateIcon (true);
  46830. if (icon == 0)
  46831. thread.addTimeSliceClient (this);
  46832. }
  46833. owner.getLookAndFeel()
  46834. .drawFileBrowserRow (g, width, height,
  46835. file.getFileName(),
  46836. icon,
  46837. fileSize, modTime,
  46838. isDirectory, isSelected(),
  46839. indexInContentsList);
  46840. }
  46841. void itemClicked (const MouseEvent& e)
  46842. {
  46843. owner.sendMouseClickMessage (file, e);
  46844. }
  46845. void itemDoubleClicked (const MouseEvent& e)
  46846. {
  46847. TreeViewItem::itemDoubleClicked (e);
  46848. owner.sendDoubleClickMessage (file);
  46849. }
  46850. void itemSelectionChanged (bool)
  46851. {
  46852. owner.sendSelectionChangeMessage();
  46853. }
  46854. bool useTimeSlice()
  46855. {
  46856. updateIcon (false);
  46857. thread.removeTimeSliceClient (this);
  46858. return false;
  46859. }
  46860. void handleAsyncUpdate()
  46861. {
  46862. owner.repaint();
  46863. }
  46864. const File file;
  46865. juce_UseDebuggingNewOperator
  46866. private:
  46867. FileTreeComponent& owner;
  46868. DirectoryContentsList* parentContentsList;
  46869. int indexInContentsList;
  46870. DirectoryContentsList* subContentsList;
  46871. bool isDirectory, canDeleteSubContentsList;
  46872. TimeSliceThread& thread;
  46873. Image* icon;
  46874. String fileSize;
  46875. String modTime;
  46876. void updateIcon (const bool onlyUpdateIfCached)
  46877. {
  46878. if (icon == 0)
  46879. {
  46880. const int hashCode = (file.getFullPathName() + "_iconCacheSalt").hashCode();
  46881. Image* im = ImageCache::getFromHashCode (hashCode);
  46882. if (im == 0 && ! onlyUpdateIfCached)
  46883. {
  46884. im = juce_createIconForFile (file);
  46885. if (im != 0)
  46886. ImageCache::addImageToCache (im, hashCode);
  46887. }
  46888. if (im != 0)
  46889. {
  46890. icon = im;
  46891. triggerAsyncUpdate();
  46892. }
  46893. }
  46894. }
  46895. };
  46896. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  46897. : DirectoryContentsDisplayComponent (listToShow)
  46898. {
  46899. FileListTreeItem* const root
  46900. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  46901. listToShow.getTimeSliceThread());
  46902. root->setSubContentsList (&listToShow);
  46903. setRootItemVisible (false);
  46904. setRootItem (root);
  46905. }
  46906. FileTreeComponent::~FileTreeComponent()
  46907. {
  46908. deleteRootItem();
  46909. }
  46910. const File FileTreeComponent::getSelectedFile (const int index) const
  46911. {
  46912. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  46913. if (item != 0)
  46914. return item->file;
  46915. return File::nonexistent;
  46916. }
  46917. void FileTreeComponent::scrollToTop()
  46918. {
  46919. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  46920. }
  46921. void FileTreeComponent::setDragAndDropDescription (const String& description)
  46922. {
  46923. dragAndDropDescription = description;
  46924. }
  46925. END_JUCE_NAMESPACE
  46926. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  46927. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  46928. BEGIN_JUCE_NAMESPACE
  46929. ImagePreviewComponent::ImagePreviewComponent()
  46930. {
  46931. }
  46932. ImagePreviewComponent::~ImagePreviewComponent()
  46933. {
  46934. }
  46935. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  46936. {
  46937. const int availableW = proportionOfWidth (0.97f);
  46938. const int availableH = getHeight() - 13 * 4;
  46939. const double scale = jmin (1.0,
  46940. availableW / (double) w,
  46941. availableH / (double) h);
  46942. w = roundToInt (scale * w);
  46943. h = roundToInt (scale * h);
  46944. }
  46945. void ImagePreviewComponent::selectedFileChanged (const File& file)
  46946. {
  46947. if (fileToLoad != file)
  46948. {
  46949. fileToLoad = file;
  46950. startTimer (100);
  46951. }
  46952. }
  46953. void ImagePreviewComponent::timerCallback()
  46954. {
  46955. stopTimer();
  46956. currentThumbnail = 0;
  46957. currentDetails = String::empty;
  46958. repaint();
  46959. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  46960. if (in != 0)
  46961. {
  46962. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  46963. if (format != 0)
  46964. {
  46965. currentThumbnail = format->decodeImage (*in);
  46966. if (currentThumbnail != 0)
  46967. {
  46968. int w = currentThumbnail->getWidth();
  46969. int h = currentThumbnail->getHeight();
  46970. currentDetails
  46971. << fileToLoad.getFileName() << "\n"
  46972. << format->getFormatName() << "\n"
  46973. << w << " x " << h << " pixels\n"
  46974. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  46975. getThumbSize (w, h);
  46976. currentThumbnail = currentThumbnail->createCopy (w, h);
  46977. }
  46978. }
  46979. }
  46980. }
  46981. void ImagePreviewComponent::paint (Graphics& g)
  46982. {
  46983. if (currentThumbnail != 0)
  46984. {
  46985. g.setFont (13.0f);
  46986. int w = currentThumbnail->getWidth();
  46987. int h = currentThumbnail->getHeight();
  46988. getThumbSize (w, h);
  46989. const int numLines = 4;
  46990. const int totalH = 13 * numLines + h + 4;
  46991. const int y = (getHeight() - totalH) / 2;
  46992. g.drawImageWithin (currentThumbnail,
  46993. (getWidth() - w) / 2, y, w, h,
  46994. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  46995. false);
  46996. g.drawFittedText (currentDetails,
  46997. 0, y + h + 4, getWidth(), 100,
  46998. Justification::centredTop, numLines);
  46999. }
  47000. }
  47001. END_JUCE_NAMESPACE
  47002. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47003. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47004. BEGIN_JUCE_NAMESPACE
  47005. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47006. const String& directoryWildcardPatterns,
  47007. const String& description_)
  47008. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47009. : (description_ + " (" + fileWildcardPatterns + ")"))
  47010. {
  47011. parse (fileWildcardPatterns, fileWildcards);
  47012. parse (directoryWildcardPatterns, directoryWildcards);
  47013. }
  47014. WildcardFileFilter::~WildcardFileFilter()
  47015. {
  47016. }
  47017. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47018. {
  47019. return match (file, fileWildcards);
  47020. }
  47021. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47022. {
  47023. return match (file, directoryWildcards);
  47024. }
  47025. void WildcardFileFilter::parse (const String& pattern, StringArray& result)
  47026. {
  47027. result.addTokens (pattern.toLowerCase(), ";,", "\"'");
  47028. result.trim();
  47029. result.removeEmptyStrings();
  47030. // special case for *.*, because people use it to mean "any file", but it
  47031. // would actually ignore files with no extension.
  47032. for (int i = result.size(); --i >= 0;)
  47033. if (result[i] == "*.*")
  47034. result.set (i, "*");
  47035. }
  47036. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards)
  47037. {
  47038. const String filename (file.getFileName());
  47039. for (int i = wildcards.size(); --i >= 0;)
  47040. if (filename.matchesWildcard (wildcards[i], true))
  47041. return true;
  47042. return false;
  47043. }
  47044. END_JUCE_NAMESPACE
  47045. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47046. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47047. BEGIN_JUCE_NAMESPACE
  47048. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47049. {
  47050. }
  47051. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47052. {
  47053. }
  47054. namespace KeyboardFocusHelpers
  47055. {
  47056. // This will sort a set of components, so that they are ordered in terms of
  47057. // left-to-right and then top-to-bottom.
  47058. class ScreenPositionComparator
  47059. {
  47060. public:
  47061. ScreenPositionComparator() {}
  47062. static int compareElements (const Component* const first, const Component* const second)
  47063. {
  47064. int explicitOrder1 = first->getExplicitFocusOrder();
  47065. if (explicitOrder1 <= 0)
  47066. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47067. int explicitOrder2 = second->getExplicitFocusOrder();
  47068. if (explicitOrder2 <= 0)
  47069. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47070. if (explicitOrder1 != explicitOrder2)
  47071. return explicitOrder1 - explicitOrder2;
  47072. const int diff = first->getY() - second->getY();
  47073. return (diff == 0) ? first->getX() - second->getX()
  47074. : diff;
  47075. }
  47076. };
  47077. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47078. {
  47079. if (parent->getNumChildComponents() > 0)
  47080. {
  47081. Array <Component*> localComps;
  47082. ScreenPositionComparator comparator;
  47083. int i;
  47084. for (i = parent->getNumChildComponents(); --i >= 0;)
  47085. {
  47086. Component* const c = parent->getChildComponent (i);
  47087. if (c->isVisible() && c->isEnabled())
  47088. localComps.addSorted (comparator, c);
  47089. }
  47090. for (i = 0; i < localComps.size(); ++i)
  47091. {
  47092. Component* const c = localComps.getUnchecked (i);
  47093. if (c->getWantsKeyboardFocus())
  47094. comps.add (c);
  47095. if (! c->isFocusContainer())
  47096. findAllFocusableComponents (c, comps);
  47097. }
  47098. }
  47099. }
  47100. }
  47101. static Component* getIncrementedComponent (Component* const current, const int delta)
  47102. {
  47103. Component* focusContainer = current->getParentComponent();
  47104. if (focusContainer != 0)
  47105. {
  47106. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47107. focusContainer = focusContainer->getParentComponent();
  47108. if (focusContainer != 0)
  47109. {
  47110. Array <Component*> comps;
  47111. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47112. if (comps.size() > 0)
  47113. {
  47114. const int index = comps.indexOf (current);
  47115. return comps [(index + comps.size() + delta) % comps.size()];
  47116. }
  47117. }
  47118. }
  47119. return 0;
  47120. }
  47121. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47122. {
  47123. return getIncrementedComponent (current, 1);
  47124. }
  47125. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47126. {
  47127. return getIncrementedComponent (current, -1);
  47128. }
  47129. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47130. {
  47131. Array <Component*> comps;
  47132. if (parentComponent != 0)
  47133. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47134. return comps.getFirst();
  47135. }
  47136. END_JUCE_NAMESPACE
  47137. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47138. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47139. BEGIN_JUCE_NAMESPACE
  47140. bool KeyListener::keyStateChanged (const bool, Component*)
  47141. {
  47142. return false;
  47143. }
  47144. END_JUCE_NAMESPACE
  47145. /*** End of inlined file: juce_KeyListener.cpp ***/
  47146. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47147. BEGIN_JUCE_NAMESPACE
  47148. // N.B. these two includes are put here deliberately to avoid problems with
  47149. // old GCCs failing on long include paths
  47150. const int maxKeys = 3;
  47151. class KeyMappingChangeButton : public Button
  47152. {
  47153. public:
  47154. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47155. const CommandID commandID_,
  47156. const String& keyName,
  47157. const int keyNum_)
  47158. : Button (keyName),
  47159. owner (owner_),
  47160. commandID (commandID_),
  47161. keyNum (keyNum_)
  47162. {
  47163. setWantsKeyboardFocus (false);
  47164. setTriggeredOnMouseDown (keyNum >= 0);
  47165. if (keyNum_ < 0)
  47166. setTooltip (TRANS("adds a new key-mapping"));
  47167. else
  47168. setTooltip (TRANS("click to change this key-mapping"));
  47169. }
  47170. ~KeyMappingChangeButton()
  47171. {
  47172. }
  47173. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47174. {
  47175. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47176. keyNum >= 0 ? getName() : String::empty);
  47177. }
  47178. void clicked()
  47179. {
  47180. if (keyNum >= 0)
  47181. {
  47182. // existing key clicked..
  47183. PopupMenu m;
  47184. m.addItem (1, TRANS("change this key-mapping"));
  47185. m.addSeparator();
  47186. m.addItem (2, TRANS("remove this key-mapping"));
  47187. const int res = m.show();
  47188. if (res == 1)
  47189. {
  47190. owner->assignNewKey (commandID, keyNum);
  47191. }
  47192. else if (res == 2)
  47193. {
  47194. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47195. }
  47196. }
  47197. else
  47198. {
  47199. // + button pressed..
  47200. owner->assignNewKey (commandID, -1);
  47201. }
  47202. }
  47203. void fitToContent (const int h) throw()
  47204. {
  47205. if (keyNum < 0)
  47206. {
  47207. setSize (h, h);
  47208. }
  47209. else
  47210. {
  47211. Font f (h * 0.6f);
  47212. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47213. }
  47214. }
  47215. juce_UseDebuggingNewOperator
  47216. private:
  47217. KeyMappingEditorComponent* const owner;
  47218. const CommandID commandID;
  47219. const int keyNum;
  47220. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47221. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47222. };
  47223. class KeyMappingItemComponent : public Component
  47224. {
  47225. public:
  47226. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47227. const CommandID commandID_)
  47228. : owner (owner_),
  47229. commandID (commandID_)
  47230. {
  47231. setInterceptsMouseClicks (false, true);
  47232. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47233. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47234. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47235. {
  47236. KeyMappingChangeButton* const kb
  47237. = new KeyMappingChangeButton (owner_, commandID,
  47238. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47239. kb->setEnabled (! isReadOnly);
  47240. addAndMakeVisible (kb);
  47241. }
  47242. KeyMappingChangeButton* const kb
  47243. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47244. addChildComponent (kb);
  47245. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47246. }
  47247. ~KeyMappingItemComponent()
  47248. {
  47249. deleteAllChildren();
  47250. }
  47251. void paint (Graphics& g)
  47252. {
  47253. g.setFont (getHeight() * 0.7f);
  47254. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47255. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47256. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47257. Justification::centredLeft, true);
  47258. }
  47259. void resized()
  47260. {
  47261. int x = getWidth() - 4;
  47262. for (int i = getNumChildComponents(); --i >= 0;)
  47263. {
  47264. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47265. kb->fitToContent (getHeight() - 2);
  47266. kb->setTopRightPosition (x, 1);
  47267. x -= kb->getWidth() + 5;
  47268. }
  47269. }
  47270. juce_UseDebuggingNewOperator
  47271. private:
  47272. KeyMappingEditorComponent* const owner;
  47273. const CommandID commandID;
  47274. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47275. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47276. };
  47277. class KeyMappingTreeViewItem : public TreeViewItem
  47278. {
  47279. public:
  47280. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47281. const CommandID commandID_)
  47282. : owner (owner_),
  47283. commandID (commandID_)
  47284. {
  47285. }
  47286. ~KeyMappingTreeViewItem()
  47287. {
  47288. }
  47289. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47290. bool mightContainSubItems() { return false; }
  47291. int getItemHeight() const { return 20; }
  47292. Component* createItemComponent()
  47293. {
  47294. return new KeyMappingItemComponent (owner, commandID);
  47295. }
  47296. juce_UseDebuggingNewOperator
  47297. private:
  47298. KeyMappingEditorComponent* const owner;
  47299. const CommandID commandID;
  47300. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47301. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47302. };
  47303. class KeyCategoryTreeViewItem : public TreeViewItem
  47304. {
  47305. public:
  47306. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47307. const String& name)
  47308. : owner (owner_),
  47309. categoryName (name)
  47310. {
  47311. }
  47312. ~KeyCategoryTreeViewItem()
  47313. {
  47314. }
  47315. const String getUniqueName() const { return categoryName + "_cat"; }
  47316. bool mightContainSubItems() { return true; }
  47317. int getItemHeight() const { return 28; }
  47318. void paintItem (Graphics& g, int width, int height)
  47319. {
  47320. g.setFont (height * 0.6f, Font::bold);
  47321. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47322. g.drawText (categoryName,
  47323. 2, 0, width - 2, height,
  47324. Justification::centredLeft, true);
  47325. }
  47326. void itemOpennessChanged (bool isNowOpen)
  47327. {
  47328. if (isNowOpen)
  47329. {
  47330. if (getNumSubItems() == 0)
  47331. {
  47332. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47333. for (int i = 0; i < commands.size(); ++i)
  47334. {
  47335. if (owner->shouldCommandBeIncluded (commands[i]))
  47336. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47337. }
  47338. }
  47339. }
  47340. else
  47341. {
  47342. clearSubItems();
  47343. }
  47344. }
  47345. juce_UseDebuggingNewOperator
  47346. private:
  47347. KeyMappingEditorComponent* owner;
  47348. String categoryName;
  47349. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47350. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47351. };
  47352. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47353. const bool showResetToDefaultButton)
  47354. : mappings (mappingManager)
  47355. {
  47356. jassert (mappingManager != 0); // can't be null!
  47357. mappingManager->addChangeListener (this);
  47358. setLinesDrawnForSubItems (false);
  47359. resetButton = 0;
  47360. if (showResetToDefaultButton)
  47361. {
  47362. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47363. resetButton->addButtonListener (this);
  47364. }
  47365. addAndMakeVisible (tree = new TreeView());
  47366. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47367. tree->setRootItemVisible (false);
  47368. tree->setDefaultOpenness (true);
  47369. tree->setRootItem (this);
  47370. }
  47371. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  47372. {
  47373. mappings->removeChangeListener (this);
  47374. deleteAllChildren();
  47375. }
  47376. bool KeyMappingEditorComponent::mightContainSubItems()
  47377. {
  47378. return true;
  47379. }
  47380. const String KeyMappingEditorComponent::getUniqueName() const
  47381. {
  47382. return "keys";
  47383. }
  47384. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  47385. const Colour& textColour)
  47386. {
  47387. setColour (backgroundColourId, mainBackground);
  47388. setColour (textColourId, textColour);
  47389. tree->setColour (TreeView::backgroundColourId, mainBackground);
  47390. }
  47391. void KeyMappingEditorComponent::parentHierarchyChanged()
  47392. {
  47393. changeListenerCallback (0);
  47394. }
  47395. void KeyMappingEditorComponent::resized()
  47396. {
  47397. int h = getHeight();
  47398. if (resetButton != 0)
  47399. {
  47400. const int buttonHeight = 20;
  47401. h -= buttonHeight + 8;
  47402. int x = getWidth() - 8;
  47403. const int y = h + 6;
  47404. resetButton->changeWidthToFitText (buttonHeight);
  47405. resetButton->setTopRightPosition (x, y);
  47406. }
  47407. tree->setBounds (0, 0, getWidth(), h);
  47408. }
  47409. void KeyMappingEditorComponent::buttonClicked (Button* button)
  47410. {
  47411. if (button == resetButton)
  47412. {
  47413. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  47414. TRANS("Reset to defaults"),
  47415. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  47416. TRANS("Reset")))
  47417. {
  47418. mappings->resetToDefaultMappings();
  47419. }
  47420. }
  47421. }
  47422. void KeyMappingEditorComponent::changeListenerCallback (void*)
  47423. {
  47424. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  47425. clearSubItems();
  47426. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  47427. for (int i = 0; i < categories.size(); ++i)
  47428. {
  47429. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  47430. int count = 0;
  47431. for (int j = 0; j < commands.size(); ++j)
  47432. if (shouldCommandBeIncluded (commands[j]))
  47433. ++count;
  47434. if (count > 0)
  47435. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  47436. }
  47437. if (openness != 0)
  47438. tree->restoreOpennessState (*openness);
  47439. }
  47440. class KeyEntryWindow : public AlertWindow
  47441. {
  47442. public:
  47443. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  47444. : AlertWindow (TRANS("New key-mapping"),
  47445. TRANS("Please press a key combination now..."),
  47446. AlertWindow::NoIcon),
  47447. owner (owner_)
  47448. {
  47449. addButton (TRANS("ok"), 1);
  47450. addButton (TRANS("cancel"), 0);
  47451. // (avoid return + escape keys getting processed by the buttons..)
  47452. for (int i = getNumChildComponents(); --i >= 0;)
  47453. getChildComponent (i)->setWantsKeyboardFocus (false);
  47454. setWantsKeyboardFocus (true);
  47455. grabKeyboardFocus();
  47456. }
  47457. ~KeyEntryWindow()
  47458. {
  47459. }
  47460. bool keyPressed (const KeyPress& key)
  47461. {
  47462. lastPress = key;
  47463. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  47464. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  47465. if (previousCommand != 0)
  47466. {
  47467. message << "\n\n"
  47468. << TRANS("(Currently assigned to \"")
  47469. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  47470. << "\")";
  47471. }
  47472. setMessage (message);
  47473. return true;
  47474. }
  47475. bool keyStateChanged (bool)
  47476. {
  47477. return true;
  47478. }
  47479. KeyPress lastPress;
  47480. juce_UseDebuggingNewOperator
  47481. private:
  47482. KeyMappingEditorComponent* owner;
  47483. KeyEntryWindow (const KeyEntryWindow&);
  47484. KeyEntryWindow& operator= (const KeyEntryWindow&);
  47485. };
  47486. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  47487. {
  47488. KeyEntryWindow entryWindow (this);
  47489. if (entryWindow.runModalLoop() != 0)
  47490. {
  47491. entryWindow.setVisible (false);
  47492. if (entryWindow.lastPress.isValid())
  47493. {
  47494. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  47495. if (previousCommand != 0)
  47496. {
  47497. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  47498. TRANS("Change key-mapping"),
  47499. TRANS("This key is already assigned to the command \"")
  47500. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  47501. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  47502. TRANS("re-assign"),
  47503. TRANS("cancel")))
  47504. {
  47505. return;
  47506. }
  47507. }
  47508. mappings->removeKeyPress (entryWindow.lastPress);
  47509. if (index >= 0)
  47510. mappings->removeKeyPress (commandID, index);
  47511. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  47512. }
  47513. }
  47514. }
  47515. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  47516. {
  47517. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47518. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  47519. }
  47520. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  47521. {
  47522. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  47523. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  47524. }
  47525. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  47526. {
  47527. return key.getTextDescription();
  47528. }
  47529. END_JUCE_NAMESPACE
  47530. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47531. /*** Start of inlined file: juce_KeyPress.cpp ***/
  47532. BEGIN_JUCE_NAMESPACE
  47533. KeyPress::KeyPress() throw()
  47534. : keyCode (0),
  47535. mods (0),
  47536. textCharacter (0)
  47537. {
  47538. }
  47539. KeyPress::KeyPress (const int keyCode_,
  47540. const ModifierKeys& mods_,
  47541. const juce_wchar textCharacter_) throw()
  47542. : keyCode (keyCode_),
  47543. mods (mods_),
  47544. textCharacter (textCharacter_)
  47545. {
  47546. }
  47547. KeyPress::KeyPress (const int keyCode_) throw()
  47548. : keyCode (keyCode_),
  47549. textCharacter (0)
  47550. {
  47551. }
  47552. KeyPress::KeyPress (const KeyPress& other) throw()
  47553. : keyCode (other.keyCode),
  47554. mods (other.mods),
  47555. textCharacter (other.textCharacter)
  47556. {
  47557. }
  47558. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  47559. {
  47560. keyCode = other.keyCode;
  47561. mods = other.mods;
  47562. textCharacter = other.textCharacter;
  47563. return *this;
  47564. }
  47565. bool KeyPress::operator== (const KeyPress& other) const throw()
  47566. {
  47567. return mods.getRawFlags() == other.mods.getRawFlags()
  47568. && (textCharacter == other.textCharacter
  47569. || textCharacter == 0
  47570. || other.textCharacter == 0)
  47571. && (keyCode == other.keyCode
  47572. || (keyCode < 256
  47573. && other.keyCode < 256
  47574. && CharacterFunctions::toLowerCase ((juce_wchar) keyCode)
  47575. == CharacterFunctions::toLowerCase ((juce_wchar) other.keyCode)));
  47576. }
  47577. bool KeyPress::operator!= (const KeyPress& other) const throw()
  47578. {
  47579. return ! operator== (other);
  47580. }
  47581. bool KeyPress::isCurrentlyDown() const
  47582. {
  47583. return isKeyCurrentlyDown (keyCode)
  47584. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  47585. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  47586. }
  47587. namespace KeyPressHelpers
  47588. {
  47589. struct KeyNameAndCode
  47590. {
  47591. const char* name;
  47592. int code;
  47593. };
  47594. static const KeyNameAndCode translations[] =
  47595. {
  47596. { "spacebar", KeyPress::spaceKey },
  47597. { "return", KeyPress::returnKey },
  47598. { "escape", KeyPress::escapeKey },
  47599. { "backspace", KeyPress::backspaceKey },
  47600. { "cursor left", KeyPress::leftKey },
  47601. { "cursor right", KeyPress::rightKey },
  47602. { "cursor up", KeyPress::upKey },
  47603. { "cursor down", KeyPress::downKey },
  47604. { "page up", KeyPress::pageUpKey },
  47605. { "page down", KeyPress::pageDownKey },
  47606. { "home", KeyPress::homeKey },
  47607. { "end", KeyPress::endKey },
  47608. { "delete", KeyPress::deleteKey },
  47609. { "insert", KeyPress::insertKey },
  47610. { "tab", KeyPress::tabKey },
  47611. { "play", KeyPress::playKey },
  47612. { "stop", KeyPress::stopKey },
  47613. { "fast forward", KeyPress::fastForwardKey },
  47614. { "rewind", KeyPress::rewindKey }
  47615. };
  47616. static const String numberPadPrefix() { return "numpad "; }
  47617. }
  47618. const KeyPress KeyPress::createFromDescription (const String& desc)
  47619. {
  47620. int modifiers = 0;
  47621. if (desc.containsWholeWordIgnoreCase ("ctrl")
  47622. || desc.containsWholeWordIgnoreCase ("control")
  47623. || desc.containsWholeWordIgnoreCase ("ctl"))
  47624. modifiers |= ModifierKeys::ctrlModifier;
  47625. if (desc.containsWholeWordIgnoreCase ("shift")
  47626. || desc.containsWholeWordIgnoreCase ("shft"))
  47627. modifiers |= ModifierKeys::shiftModifier;
  47628. if (desc.containsWholeWordIgnoreCase ("alt")
  47629. || desc.containsWholeWordIgnoreCase ("option"))
  47630. modifiers |= ModifierKeys::altModifier;
  47631. if (desc.containsWholeWordIgnoreCase ("command")
  47632. || desc.containsWholeWordIgnoreCase ("cmd"))
  47633. modifiers |= ModifierKeys::commandModifier;
  47634. int key = 0;
  47635. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47636. {
  47637. if (desc.containsWholeWordIgnoreCase (String (KeyPressHelpers::translations[i].name)))
  47638. {
  47639. key = KeyPressHelpers::translations[i].code;
  47640. break;
  47641. }
  47642. }
  47643. if (key == 0)
  47644. {
  47645. // see if it's a numpad key..
  47646. if (desc.containsIgnoreCase (KeyPressHelpers::numberPadPrefix()))
  47647. {
  47648. const juce_wchar lastChar = desc.trimEnd().getLastCharacter();
  47649. if (lastChar >= '0' && lastChar <= '9')
  47650. key = numberPad0 + lastChar - '0';
  47651. else if (lastChar == '+')
  47652. key = numberPadAdd;
  47653. else if (lastChar == '-')
  47654. key = numberPadSubtract;
  47655. else if (lastChar == '*')
  47656. key = numberPadMultiply;
  47657. else if (lastChar == '/')
  47658. key = numberPadDivide;
  47659. else if (lastChar == '.')
  47660. key = numberPadDecimalPoint;
  47661. else if (lastChar == '=')
  47662. key = numberPadEquals;
  47663. else if (desc.endsWith ("separator"))
  47664. key = numberPadSeparator;
  47665. else if (desc.endsWith ("delete"))
  47666. key = numberPadDelete;
  47667. }
  47668. if (key == 0)
  47669. {
  47670. // see if it's a function key..
  47671. for (int i = 1; i <= 12; ++i)
  47672. if (desc.containsWholeWordIgnoreCase ("f" + String (i)))
  47673. key = F1Key + i - 1;
  47674. if (key == 0)
  47675. {
  47676. // give up and use the hex code..
  47677. const int hexCode = desc.fromFirstOccurrenceOf ("#", false, false)
  47678. .toLowerCase()
  47679. .retainCharacters ("0123456789abcdef")
  47680. .getHexValue32();
  47681. if (hexCode > 0)
  47682. key = hexCode;
  47683. else
  47684. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  47685. }
  47686. }
  47687. }
  47688. return KeyPress (key, ModifierKeys (modifiers), 0);
  47689. }
  47690. const String KeyPress::getTextDescription() const
  47691. {
  47692. String desc;
  47693. if (keyCode > 0)
  47694. {
  47695. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  47696. // want to store it as being a slash, not shift+whatever.
  47697. if (textCharacter == '/')
  47698. return "/";
  47699. if (mods.isCtrlDown())
  47700. desc << "ctrl + ";
  47701. if (mods.isShiftDown())
  47702. desc << "shift + ";
  47703. #if JUCE_MAC
  47704. // only do this on the mac, because on Windows ctrl and command are the same,
  47705. // and this would get confusing
  47706. if (mods.isCommandDown())
  47707. desc << "command + ";
  47708. if (mods.isAltDown())
  47709. desc << "option + ";
  47710. #else
  47711. if (mods.isAltDown())
  47712. desc << "alt + ";
  47713. #endif
  47714. for (int i = 0; i < numElementsInArray (KeyPressHelpers::translations); ++i)
  47715. if (keyCode == KeyPressHelpers::translations[i].code)
  47716. return desc + KeyPressHelpers::translations[i].name;
  47717. if (keyCode >= F1Key && keyCode <= F16Key)
  47718. desc << 'F' << (1 + keyCode - F1Key);
  47719. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  47720. desc << KeyPressHelpers::numberPadPrefix() << (keyCode - numberPad0);
  47721. else if (keyCode >= 33 && keyCode < 176)
  47722. desc += CharacterFunctions::toUpperCase ((juce_wchar) keyCode);
  47723. else if (keyCode == numberPadAdd)
  47724. desc << KeyPressHelpers::numberPadPrefix() << '+';
  47725. else if (keyCode == numberPadSubtract)
  47726. desc << KeyPressHelpers::numberPadPrefix() << '-';
  47727. else if (keyCode == numberPadMultiply)
  47728. desc << KeyPressHelpers::numberPadPrefix() << '*';
  47729. else if (keyCode == numberPadDivide)
  47730. desc << KeyPressHelpers::numberPadPrefix() << '/';
  47731. else if (keyCode == numberPadSeparator)
  47732. desc << KeyPressHelpers::numberPadPrefix() << "separator";
  47733. else if (keyCode == numberPadDecimalPoint)
  47734. desc << KeyPressHelpers::numberPadPrefix() << '.';
  47735. else if (keyCode == numberPadDelete)
  47736. desc << KeyPressHelpers::numberPadPrefix() << "delete";
  47737. else
  47738. desc << '#' << String::toHexString (keyCode);
  47739. }
  47740. return desc;
  47741. }
  47742. END_JUCE_NAMESPACE
  47743. /*** End of inlined file: juce_KeyPress.cpp ***/
  47744. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  47745. BEGIN_JUCE_NAMESPACE
  47746. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_)
  47747. : commandManager (commandManager_)
  47748. {
  47749. // A manager is needed to get the descriptions of commands, and will be called when
  47750. // a command is invoked. So you can't leave this null..
  47751. jassert (commandManager_ != 0);
  47752. Desktop::getInstance().addFocusChangeListener (this);
  47753. }
  47754. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other)
  47755. : commandManager (other.commandManager)
  47756. {
  47757. Desktop::getInstance().addFocusChangeListener (this);
  47758. }
  47759. KeyPressMappingSet::~KeyPressMappingSet()
  47760. {
  47761. Desktop::getInstance().removeFocusChangeListener (this);
  47762. }
  47763. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const
  47764. {
  47765. for (int i = 0; i < mappings.size(); ++i)
  47766. if (mappings.getUnchecked(i)->commandID == commandID)
  47767. return mappings.getUnchecked (i)->keypresses;
  47768. return Array <KeyPress> ();
  47769. }
  47770. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  47771. const KeyPress& newKeyPress,
  47772. int insertIndex)
  47773. {
  47774. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  47775. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  47776. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  47777. && ! newKeyPress.getModifiers().isShiftDown()));
  47778. if (findCommandForKeyPress (newKeyPress) != commandID)
  47779. {
  47780. removeKeyPress (newKeyPress);
  47781. if (newKeyPress.isValid())
  47782. {
  47783. for (int i = mappings.size(); --i >= 0;)
  47784. {
  47785. if (mappings.getUnchecked(i)->commandID == commandID)
  47786. {
  47787. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  47788. sendChangeMessage (this);
  47789. return;
  47790. }
  47791. }
  47792. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47793. if (ci != 0)
  47794. {
  47795. CommandMapping* const cm = new CommandMapping();
  47796. cm->commandID = commandID;
  47797. cm->keypresses.add (newKeyPress);
  47798. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  47799. mappings.add (cm);
  47800. sendChangeMessage (this);
  47801. }
  47802. }
  47803. }
  47804. }
  47805. void KeyPressMappingSet::resetToDefaultMappings()
  47806. {
  47807. mappings.clear();
  47808. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  47809. {
  47810. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  47811. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47812. {
  47813. addKeyPress (ci->commandID,
  47814. ci->defaultKeypresses.getReference (j));
  47815. }
  47816. }
  47817. sendChangeMessage (this);
  47818. }
  47819. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID)
  47820. {
  47821. clearAllKeyPresses (commandID);
  47822. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47823. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  47824. {
  47825. addKeyPress (ci->commandID,
  47826. ci->defaultKeypresses.getReference (j));
  47827. }
  47828. }
  47829. void KeyPressMappingSet::clearAllKeyPresses()
  47830. {
  47831. if (mappings.size() > 0)
  47832. {
  47833. sendChangeMessage (this);
  47834. mappings.clear();
  47835. }
  47836. }
  47837. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID)
  47838. {
  47839. for (int i = mappings.size(); --i >= 0;)
  47840. {
  47841. if (mappings.getUnchecked(i)->commandID == commandID)
  47842. {
  47843. mappings.remove (i);
  47844. sendChangeMessage (this);
  47845. }
  47846. }
  47847. }
  47848. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress)
  47849. {
  47850. if (keypress.isValid())
  47851. {
  47852. for (int i = mappings.size(); --i >= 0;)
  47853. {
  47854. CommandMapping* const cm = mappings.getUnchecked(i);
  47855. for (int j = cm->keypresses.size(); --j >= 0;)
  47856. {
  47857. if (keypress == cm->keypresses [j])
  47858. {
  47859. cm->keypresses.remove (j);
  47860. sendChangeMessage (this);
  47861. }
  47862. }
  47863. }
  47864. }
  47865. }
  47866. void KeyPressMappingSet::removeKeyPress (const CommandID commandID, const int keyPressIndex)
  47867. {
  47868. for (int i = mappings.size(); --i >= 0;)
  47869. {
  47870. if (mappings.getUnchecked(i)->commandID == commandID)
  47871. {
  47872. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  47873. sendChangeMessage (this);
  47874. break;
  47875. }
  47876. }
  47877. }
  47878. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  47879. {
  47880. for (int i = 0; i < mappings.size(); ++i)
  47881. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  47882. return mappings.getUnchecked(i)->commandID;
  47883. return 0;
  47884. }
  47885. bool KeyPressMappingSet::containsMapping (const CommandID commandID, const KeyPress& keyPress) const throw()
  47886. {
  47887. for (int i = mappings.size(); --i >= 0;)
  47888. if (mappings.getUnchecked(i)->commandID == commandID)
  47889. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  47890. return false;
  47891. }
  47892. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  47893. const KeyPress& key,
  47894. const bool isKeyDown,
  47895. const int millisecsSinceKeyPressed,
  47896. Component* const originatingComponent) const
  47897. {
  47898. ApplicationCommandTarget::InvocationInfo info (commandID);
  47899. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  47900. info.isKeyDown = isKeyDown;
  47901. info.keyPress = key;
  47902. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  47903. info.originatingComponent = originatingComponent;
  47904. commandManager->invoke (info, false);
  47905. }
  47906. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  47907. {
  47908. if (xmlVersion.hasTagName ("KEYMAPPINGS"))
  47909. {
  47910. if (xmlVersion.getBoolAttribute ("basedOnDefaults", true))
  47911. {
  47912. // if the XML was created as a set of differences from the default mappings,
  47913. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  47914. resetToDefaultMappings();
  47915. }
  47916. else
  47917. {
  47918. // if the XML was created calling createXml (false), then we need to clear all
  47919. // the keys and treat the xml as describing the entire set of mappings.
  47920. clearAllKeyPresses();
  47921. }
  47922. forEachXmlChildElement (xmlVersion, map)
  47923. {
  47924. const CommandID commandId = map->getStringAttribute ("commandId").getHexValue32();
  47925. if (commandId != 0)
  47926. {
  47927. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute ("key")));
  47928. if (map->hasTagName ("MAPPING"))
  47929. {
  47930. addKeyPress (commandId, key);
  47931. }
  47932. else if (map->hasTagName ("UNMAPPING"))
  47933. {
  47934. if (containsMapping (commandId, key))
  47935. removeKeyPress (key);
  47936. }
  47937. }
  47938. }
  47939. return true;
  47940. }
  47941. return false;
  47942. }
  47943. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  47944. {
  47945. ScopedPointer <KeyPressMappingSet> defaultSet;
  47946. if (saveDifferencesFromDefaultSet)
  47947. {
  47948. defaultSet = new KeyPressMappingSet (commandManager);
  47949. defaultSet->resetToDefaultMappings();
  47950. }
  47951. XmlElement* const doc = new XmlElement ("KEYMAPPINGS");
  47952. doc->setAttribute ("basedOnDefaults", saveDifferencesFromDefaultSet);
  47953. int i;
  47954. for (i = 0; i < mappings.size(); ++i)
  47955. {
  47956. const CommandMapping* const cm = mappings.getUnchecked(i);
  47957. for (int j = 0; j < cm->keypresses.size(); ++j)
  47958. {
  47959. if (defaultSet == 0
  47960. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  47961. {
  47962. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  47963. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  47964. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  47965. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  47966. }
  47967. }
  47968. }
  47969. if (defaultSet != 0)
  47970. {
  47971. for (i = 0; i < defaultSet->mappings.size(); ++i)
  47972. {
  47973. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  47974. for (int j = 0; j < cm->keypresses.size(); ++j)
  47975. {
  47976. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  47977. {
  47978. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  47979. map->setAttribute ("commandId", String::toHexString ((int) cm->commandID));
  47980. map->setAttribute ("description", commandManager->getDescriptionOfCommand (cm->commandID));
  47981. map->setAttribute ("key", cm->keypresses.getReference (j).getTextDescription());
  47982. }
  47983. }
  47984. }
  47985. }
  47986. return doc;
  47987. }
  47988. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  47989. Component* originatingComponent)
  47990. {
  47991. bool used = false;
  47992. const CommandID commandID = findCommandForKeyPress (key);
  47993. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  47994. if (ci != 0
  47995. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  47996. {
  47997. ApplicationCommandInfo info (0);
  47998. if (commandManager->getTargetForCommand (commandID, info) != 0
  47999. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48000. {
  48001. invokeCommand (commandID, key, true, 0, originatingComponent);
  48002. used = true;
  48003. }
  48004. else
  48005. {
  48006. if (originatingComponent != 0)
  48007. originatingComponent->getLookAndFeel().playAlertSound();
  48008. }
  48009. }
  48010. return used;
  48011. }
  48012. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48013. {
  48014. bool used = false;
  48015. const uint32 now = Time::getMillisecondCounter();
  48016. for (int i = mappings.size(); --i >= 0;)
  48017. {
  48018. CommandMapping* const cm = mappings.getUnchecked(i);
  48019. if (cm->wantsKeyUpDownCallbacks)
  48020. {
  48021. for (int j = cm->keypresses.size(); --j >= 0;)
  48022. {
  48023. const KeyPress key (cm->keypresses.getReference (j));
  48024. const bool isDown = key.isCurrentlyDown();
  48025. int keyPressEntryIndex = 0;
  48026. bool wasDown = false;
  48027. for (int k = keysDown.size(); --k >= 0;)
  48028. {
  48029. if (key == keysDown.getUnchecked(k)->key)
  48030. {
  48031. keyPressEntryIndex = k;
  48032. wasDown = true;
  48033. used = true;
  48034. break;
  48035. }
  48036. }
  48037. if (isDown != wasDown)
  48038. {
  48039. int millisecs = 0;
  48040. if (isDown)
  48041. {
  48042. KeyPressTime* const k = new KeyPressTime();
  48043. k->key = key;
  48044. k->timeWhenPressed = now;
  48045. keysDown.add (k);
  48046. }
  48047. else
  48048. {
  48049. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48050. if (now > pressTime)
  48051. millisecs = now - pressTime;
  48052. keysDown.remove (keyPressEntryIndex);
  48053. }
  48054. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48055. used = true;
  48056. }
  48057. }
  48058. }
  48059. }
  48060. return used;
  48061. }
  48062. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48063. {
  48064. if (focusedComponent != 0)
  48065. focusedComponent->keyStateChanged (false);
  48066. }
  48067. END_JUCE_NAMESPACE
  48068. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48069. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48070. BEGIN_JUCE_NAMESPACE
  48071. ModifierKeys::ModifierKeys (const int flags_) throw()
  48072. : flags (flags_)
  48073. {
  48074. }
  48075. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48076. : flags (other.flags)
  48077. {
  48078. }
  48079. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48080. {
  48081. flags = other.flags;
  48082. return *this;
  48083. }
  48084. ModifierKeys ModifierKeys::currentModifiers;
  48085. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48086. {
  48087. return currentModifiers;
  48088. }
  48089. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48090. {
  48091. int num = 0;
  48092. if (isLeftButtonDown()) ++num;
  48093. if (isRightButtonDown()) ++num;
  48094. if (isMiddleButtonDown()) ++num;
  48095. return num;
  48096. }
  48097. END_JUCE_NAMESPACE
  48098. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48099. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48100. BEGIN_JUCE_NAMESPACE
  48101. class ComponentAnimator::AnimationTask
  48102. {
  48103. public:
  48104. AnimationTask (Component* const comp)
  48105. : component (comp)
  48106. {
  48107. }
  48108. Component::SafePointer<Component> component;
  48109. Rectangle<int> destination;
  48110. int msElapsed, msTotal;
  48111. double startSpeed, midSpeed, endSpeed, lastProgress;
  48112. double left, top, right, bottom;
  48113. bool useTimeslice (const int elapsed)
  48114. {
  48115. if (component == 0)
  48116. return false;
  48117. msElapsed += elapsed;
  48118. double newProgress = msElapsed / (double) msTotal;
  48119. if (newProgress >= 0 && newProgress < 1.0)
  48120. {
  48121. newProgress = timeToDistance (newProgress);
  48122. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48123. jassert (newProgress >= lastProgress);
  48124. lastProgress = newProgress;
  48125. left += (destination.getX() - left) * delta;
  48126. top += (destination.getY() - top) * delta;
  48127. right += (destination.getRight() - right) * delta;
  48128. bottom += (destination.getBottom() - bottom) * delta;
  48129. if (delta < 1.0)
  48130. {
  48131. const Rectangle<int> newBounds (roundToInt (left),
  48132. roundToInt (top),
  48133. roundToInt (right - left),
  48134. roundToInt (bottom - top));
  48135. if (newBounds != destination)
  48136. {
  48137. component->setBounds (newBounds);
  48138. return true;
  48139. }
  48140. }
  48141. }
  48142. component->setBounds (destination);
  48143. return false;
  48144. }
  48145. void moveToFinalDestination()
  48146. {
  48147. if (component != 0)
  48148. component->setBounds (destination);
  48149. }
  48150. private:
  48151. inline double timeToDistance (const double time) const
  48152. {
  48153. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48154. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48155. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48156. }
  48157. };
  48158. ComponentAnimator::ComponentAnimator()
  48159. : lastTime (0)
  48160. {
  48161. }
  48162. ComponentAnimator::~ComponentAnimator()
  48163. {
  48164. cancelAllAnimations (false);
  48165. jassert (tasks.size() == 0);
  48166. }
  48167. ComponentAnimator::AnimationTask* ComponentAnimator::findTaskFor (Component* const component) const
  48168. {
  48169. for (int i = tasks.size(); --i >= 0;)
  48170. if (component == tasks.getUnchecked(i)->component.getComponent())
  48171. return tasks.getUnchecked(i);
  48172. return 0;
  48173. }
  48174. void ComponentAnimator::animateComponent (Component* const component,
  48175. const Rectangle<int>& finalPosition,
  48176. const int millisecondsToSpendMoving,
  48177. const double startSpeed,
  48178. const double endSpeed)
  48179. {
  48180. if (component != 0)
  48181. {
  48182. AnimationTask* at = findTaskFor (component);
  48183. if (at == 0)
  48184. {
  48185. at = new AnimationTask (component);
  48186. tasks.add (at);
  48187. sendChangeMessage (this);
  48188. }
  48189. at->msElapsed = 0;
  48190. at->lastProgress = 0;
  48191. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48192. at->destination = finalPosition;
  48193. // the speeds must be 0 or greater!
  48194. jassert (startSpeed >= 0 && endSpeed >= 0)
  48195. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48196. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48197. at->midSpeed = invTotalDistance;
  48198. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48199. at->left = component->getX();
  48200. at->top = component->getY();
  48201. at->right = component->getRight();
  48202. at->bottom = component->getBottom();
  48203. if (! isTimerRunning())
  48204. {
  48205. lastTime = Time::getMillisecondCounter();
  48206. startTimer (1000 / 50);
  48207. }
  48208. }
  48209. }
  48210. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48211. {
  48212. for (int i = tasks.size(); --i >= 0;)
  48213. {
  48214. AnimationTask* const at = tasks.getUnchecked(i);
  48215. if (moveComponentsToTheirFinalPositions)
  48216. at->moveToFinalDestination();
  48217. delete at;
  48218. tasks.remove (i);
  48219. sendChangeMessage (this);
  48220. }
  48221. }
  48222. void ComponentAnimator::cancelAnimation (Component* const component,
  48223. const bool moveComponentToItsFinalPosition)
  48224. {
  48225. AnimationTask* const at = findTaskFor (component);
  48226. if (at != 0)
  48227. {
  48228. if (moveComponentToItsFinalPosition)
  48229. at->moveToFinalDestination();
  48230. tasks.removeValue (at);
  48231. delete at;
  48232. sendChangeMessage (this);
  48233. }
  48234. }
  48235. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48236. {
  48237. AnimationTask* const at = findTaskFor (component);
  48238. if (at != 0)
  48239. return at->destination;
  48240. else if (component != 0)
  48241. return component->getBounds();
  48242. return Rectangle<int>();
  48243. }
  48244. bool ComponentAnimator::isAnimating (Component* component) const
  48245. {
  48246. return findTaskFor (component) != 0;
  48247. }
  48248. void ComponentAnimator::timerCallback()
  48249. {
  48250. const uint32 timeNow = Time::getMillisecondCounter();
  48251. if (lastTime == 0 || lastTime == timeNow)
  48252. lastTime = timeNow;
  48253. const int elapsed = timeNow - lastTime;
  48254. for (int i = tasks.size(); --i >= 0;)
  48255. {
  48256. AnimationTask* const at = tasks.getUnchecked(i);
  48257. if (! at->useTimeslice (elapsed))
  48258. {
  48259. tasks.remove (i);
  48260. delete at;
  48261. sendChangeMessage (this);
  48262. }
  48263. }
  48264. lastTime = timeNow;
  48265. if (tasks.size() == 0)
  48266. stopTimer();
  48267. }
  48268. END_JUCE_NAMESPACE
  48269. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48270. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48271. BEGIN_JUCE_NAMESPACE
  48272. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48273. : minW (0),
  48274. maxW (0x3fffffff),
  48275. minH (0),
  48276. maxH (0x3fffffff),
  48277. minOffTop (0),
  48278. minOffLeft (0),
  48279. minOffBottom (0),
  48280. minOffRight (0),
  48281. aspectRatio (0.0)
  48282. {
  48283. }
  48284. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48285. {
  48286. }
  48287. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48288. {
  48289. minW = minimumWidth;
  48290. }
  48291. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48292. {
  48293. maxW = maximumWidth;
  48294. }
  48295. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48296. {
  48297. minH = minimumHeight;
  48298. }
  48299. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48300. {
  48301. maxH = maximumHeight;
  48302. }
  48303. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48304. {
  48305. jassert (maxW >= minimumWidth);
  48306. jassert (maxH >= minimumHeight);
  48307. jassert (minimumWidth > 0 && minimumHeight > 0);
  48308. minW = minimumWidth;
  48309. minH = minimumHeight;
  48310. if (minW > maxW)
  48311. maxW = minW;
  48312. if (minH > maxH)
  48313. maxH = minH;
  48314. }
  48315. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48316. {
  48317. jassert (maximumWidth >= minW);
  48318. jassert (maximumHeight >= minH);
  48319. jassert (maximumWidth > 0 && maximumHeight > 0);
  48320. maxW = jmax (minW, maximumWidth);
  48321. maxH = jmax (minH, maximumHeight);
  48322. }
  48323. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48324. const int minimumHeight,
  48325. const int maximumWidth,
  48326. const int maximumHeight) throw()
  48327. {
  48328. jassert (maximumWidth >= minimumWidth);
  48329. jassert (maximumHeight >= minimumHeight);
  48330. jassert (maximumWidth > 0 && maximumHeight > 0);
  48331. jassert (minimumWidth > 0 && minimumHeight > 0);
  48332. minW = jmax (0, minimumWidth);
  48333. minH = jmax (0, minimumHeight);
  48334. maxW = jmax (minW, maximumWidth);
  48335. maxH = jmax (minH, maximumHeight);
  48336. }
  48337. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48338. const int minimumWhenOffTheLeft,
  48339. const int minimumWhenOffTheBottom,
  48340. const int minimumWhenOffTheRight) throw()
  48341. {
  48342. minOffTop = minimumWhenOffTheTop;
  48343. minOffLeft = minimumWhenOffTheLeft;
  48344. minOffBottom = minimumWhenOffTheBottom;
  48345. minOffRight = minimumWhenOffTheRight;
  48346. }
  48347. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48348. {
  48349. aspectRatio = jmax (0.0, widthOverHeight);
  48350. }
  48351. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48352. {
  48353. return aspectRatio;
  48354. }
  48355. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48356. const Rectangle<int>& targetBounds,
  48357. const bool isStretchingTop,
  48358. const bool isStretchingLeft,
  48359. const bool isStretchingBottom,
  48360. const bool isStretchingRight)
  48361. {
  48362. jassert (component != 0);
  48363. Rectangle<int> limits, bounds (targetBounds);
  48364. BorderSize border;
  48365. Component* const parent = component->getParentComponent();
  48366. if (parent == 0)
  48367. {
  48368. ComponentPeer* peer = component->getPeer();
  48369. if (peer != 0)
  48370. border = peer->getFrameSize();
  48371. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  48372. }
  48373. else
  48374. {
  48375. limits.setSize (parent->getWidth(), parent->getHeight());
  48376. }
  48377. border.addTo (bounds);
  48378. checkBounds (bounds,
  48379. border.addedTo (component->getBounds()), limits,
  48380. isStretchingTop, isStretchingLeft,
  48381. isStretchingBottom, isStretchingRight);
  48382. border.subtractFrom (bounds);
  48383. applyBoundsToComponent (component, bounds);
  48384. }
  48385. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  48386. {
  48387. setBoundsForComponent (component, component->getBounds(),
  48388. false, false, false, false);
  48389. }
  48390. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  48391. const Rectangle<int>& bounds)
  48392. {
  48393. component->setBounds (bounds);
  48394. }
  48395. void ComponentBoundsConstrainer::resizeStart()
  48396. {
  48397. }
  48398. void ComponentBoundsConstrainer::resizeEnd()
  48399. {
  48400. }
  48401. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  48402. const Rectangle<int>& old,
  48403. const Rectangle<int>& limits,
  48404. const bool isStretchingTop,
  48405. const bool isStretchingLeft,
  48406. const bool isStretchingBottom,
  48407. const bool isStretchingRight)
  48408. {
  48409. int x = bounds.getX();
  48410. int y = bounds.getY();
  48411. int w = bounds.getWidth();
  48412. int h = bounds.getHeight();
  48413. // constrain the size if it's being stretched..
  48414. if (isStretchingLeft)
  48415. {
  48416. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  48417. w = old.getRight() - x;
  48418. }
  48419. if (isStretchingRight)
  48420. {
  48421. w = jlimit (minW, maxW, w);
  48422. }
  48423. if (isStretchingTop)
  48424. {
  48425. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  48426. h = old.getBottom() - y;
  48427. }
  48428. if (isStretchingBottom)
  48429. {
  48430. h = jlimit (minH, maxH, h);
  48431. }
  48432. // constrain the aspect ratio if one has been specified..
  48433. if (aspectRatio > 0.0 && w > 0 && h > 0)
  48434. {
  48435. bool adjustWidth;
  48436. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48437. {
  48438. adjustWidth = true;
  48439. }
  48440. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48441. {
  48442. adjustWidth = false;
  48443. }
  48444. else
  48445. {
  48446. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  48447. const double newRatio = fabs (w / (double) h);
  48448. adjustWidth = (oldRatio > newRatio);
  48449. }
  48450. if (adjustWidth)
  48451. {
  48452. w = roundToInt (h * aspectRatio);
  48453. if (w > maxW || w < minW)
  48454. {
  48455. w = jlimit (minW, maxW, w);
  48456. h = roundToInt (w / aspectRatio);
  48457. }
  48458. }
  48459. else
  48460. {
  48461. h = roundToInt (w / aspectRatio);
  48462. if (h > maxH || h < minH)
  48463. {
  48464. h = jlimit (minH, maxH, h);
  48465. w = roundToInt (h * aspectRatio);
  48466. }
  48467. }
  48468. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  48469. {
  48470. x = old.getX() + (old.getWidth() - w) / 2;
  48471. }
  48472. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  48473. {
  48474. y = old.getY() + (old.getHeight() - h) / 2;
  48475. }
  48476. else
  48477. {
  48478. if (isStretchingLeft)
  48479. x = old.getRight() - w;
  48480. if (isStretchingTop)
  48481. y = old.getBottom() - h;
  48482. }
  48483. }
  48484. // ...and constrain the position if limits have been set for that.
  48485. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  48486. {
  48487. if (minOffTop > 0)
  48488. {
  48489. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  48490. if (y < limit)
  48491. {
  48492. if (isStretchingTop)
  48493. h -= (limit - y);
  48494. y = limit;
  48495. }
  48496. }
  48497. if (minOffLeft > 0)
  48498. {
  48499. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  48500. if (x < limit)
  48501. {
  48502. if (isStretchingLeft)
  48503. w -= (limit - x);
  48504. x = limit;
  48505. }
  48506. }
  48507. if (minOffBottom > 0)
  48508. {
  48509. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  48510. if (y > limit)
  48511. {
  48512. if (isStretchingBottom)
  48513. h += (limit - y);
  48514. else
  48515. y = limit;
  48516. }
  48517. }
  48518. if (minOffRight > 0)
  48519. {
  48520. const int limit = limits.getRight() - jmin (minOffRight, w);
  48521. if (x > limit)
  48522. {
  48523. if (isStretchingRight)
  48524. w += (limit - x);
  48525. else
  48526. x = limit;
  48527. }
  48528. }
  48529. }
  48530. jassert (w >= 0 && h >= 0);
  48531. bounds = Rectangle<int> (x, y, w, h);
  48532. }
  48533. END_JUCE_NAMESPACE
  48534. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48535. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48536. BEGIN_JUCE_NAMESPACE
  48537. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  48538. : component (component_),
  48539. lastPeer (0),
  48540. reentrant (false)
  48541. {
  48542. jassert (component != 0); // can't use this with a null pointer..
  48543. component->addComponentListener (this);
  48544. registerWithParentComps();
  48545. }
  48546. ComponentMovementWatcher::~ComponentMovementWatcher()
  48547. {
  48548. component->removeComponentListener (this);
  48549. unregister();
  48550. }
  48551. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  48552. {
  48553. // agh! don't delete the target component without deleting this object first!
  48554. jassert (component != 0);
  48555. if (! reentrant)
  48556. {
  48557. reentrant = true;
  48558. ComponentPeer* const peer = component->getPeer();
  48559. if (peer != lastPeer)
  48560. {
  48561. componentPeerChanged();
  48562. if (component == 0)
  48563. return;
  48564. lastPeer = peer;
  48565. }
  48566. unregister();
  48567. registerWithParentComps();
  48568. reentrant = false;
  48569. componentMovedOrResized (*component, true, true);
  48570. }
  48571. }
  48572. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  48573. {
  48574. // agh! don't delete the target component without deleting this object first!
  48575. jassert (component != 0);
  48576. if (wasMoved)
  48577. {
  48578. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  48579. wasMoved = lastBounds.getPosition() != pos;
  48580. lastBounds.setPosition (pos);
  48581. }
  48582. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  48583. lastBounds.setSize (component->getWidth(), component->getHeight());
  48584. if (wasMoved || wasResized)
  48585. componentMovedOrResized (wasMoved, wasResized);
  48586. }
  48587. void ComponentMovementWatcher::registerWithParentComps() throw()
  48588. {
  48589. Component* p = component->getParentComponent();
  48590. while (p != 0)
  48591. {
  48592. p->addComponentListener (this);
  48593. registeredParentComps.add (p);
  48594. p = p->getParentComponent();
  48595. }
  48596. }
  48597. void ComponentMovementWatcher::unregister() throw()
  48598. {
  48599. for (int i = registeredParentComps.size(); --i >= 0;)
  48600. static_cast <Component*> (registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  48601. registeredParentComps.clear();
  48602. }
  48603. END_JUCE_NAMESPACE
  48604. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  48605. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  48606. BEGIN_JUCE_NAMESPACE
  48607. GroupComponent::GroupComponent (const String& componentName,
  48608. const String& labelText)
  48609. : Component (componentName),
  48610. text (labelText),
  48611. justification (Justification::left)
  48612. {
  48613. setInterceptsMouseClicks (false, true);
  48614. }
  48615. GroupComponent::~GroupComponent()
  48616. {
  48617. }
  48618. void GroupComponent::setText (const String& newText)
  48619. {
  48620. if (text != newText)
  48621. {
  48622. text = newText;
  48623. repaint();
  48624. }
  48625. }
  48626. const String GroupComponent::getText() const
  48627. {
  48628. return text;
  48629. }
  48630. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  48631. {
  48632. if (justification.getFlags() != newJustification.getFlags())
  48633. {
  48634. justification = newJustification;
  48635. repaint();
  48636. }
  48637. }
  48638. void GroupComponent::paint (Graphics& g)
  48639. {
  48640. getLookAndFeel()
  48641. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  48642. text, justification,
  48643. *this);
  48644. }
  48645. void GroupComponent::enablementChanged()
  48646. {
  48647. repaint();
  48648. }
  48649. void GroupComponent::colourChanged()
  48650. {
  48651. repaint();
  48652. }
  48653. END_JUCE_NAMESPACE
  48654. /*** End of inlined file: juce_GroupComponent.cpp ***/
  48655. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  48656. BEGIN_JUCE_NAMESPACE
  48657. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  48658. : DocumentWindow (String::empty, backgroundColour,
  48659. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  48660. {
  48661. }
  48662. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  48663. {
  48664. }
  48665. void MultiDocumentPanelWindow::maximiseButtonPressed()
  48666. {
  48667. MultiDocumentPanel* const owner = getOwner();
  48668. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48669. if (owner != 0)
  48670. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  48671. }
  48672. void MultiDocumentPanelWindow::closeButtonPressed()
  48673. {
  48674. MultiDocumentPanel* const owner = getOwner();
  48675. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  48676. if (owner != 0)
  48677. owner->closeDocument (getContentComponent(), true);
  48678. }
  48679. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  48680. {
  48681. DocumentWindow::activeWindowStatusChanged();
  48682. updateOrder();
  48683. }
  48684. void MultiDocumentPanelWindow::broughtToFront()
  48685. {
  48686. DocumentWindow::broughtToFront();
  48687. updateOrder();
  48688. }
  48689. void MultiDocumentPanelWindow::updateOrder()
  48690. {
  48691. MultiDocumentPanel* const owner = getOwner();
  48692. if (owner != 0)
  48693. owner->updateOrder();
  48694. }
  48695. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  48696. {
  48697. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48698. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48699. }
  48700. class MDITabbedComponentInternal : public TabbedComponent
  48701. {
  48702. public:
  48703. MDITabbedComponentInternal()
  48704. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  48705. {
  48706. }
  48707. ~MDITabbedComponentInternal()
  48708. {
  48709. }
  48710. void currentTabChanged (int, const String&)
  48711. {
  48712. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  48713. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  48714. if (owner != 0)
  48715. owner->updateOrder();
  48716. }
  48717. };
  48718. MultiDocumentPanel::MultiDocumentPanel()
  48719. : mode (MaximisedWindowsWithTabs),
  48720. tabComponent (0),
  48721. backgroundColour (Colours::lightblue),
  48722. maximumNumDocuments (0),
  48723. numDocsBeforeTabsUsed (0)
  48724. {
  48725. setOpaque (true);
  48726. }
  48727. MultiDocumentPanel::~MultiDocumentPanel()
  48728. {
  48729. closeAllDocuments (false);
  48730. }
  48731. static bool shouldDeleteComp (Component* const c)
  48732. {
  48733. return c->getProperties() ["mdiDocumentDelete_"];
  48734. }
  48735. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  48736. {
  48737. while (components.size() > 0)
  48738. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  48739. return false;
  48740. return true;
  48741. }
  48742. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  48743. {
  48744. return new MultiDocumentPanelWindow (backgroundColour);
  48745. }
  48746. void MultiDocumentPanel::addWindow (Component* component)
  48747. {
  48748. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  48749. dw->setResizable (true, false);
  48750. dw->setContentComponent (component, false, true);
  48751. dw->setName (component->getName());
  48752. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  48753. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  48754. int x = 4;
  48755. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  48756. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  48757. x += 16;
  48758. dw->setTopLeftPosition (x, x);
  48759. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  48760. if (pos.toString().isNotEmpty())
  48761. dw->restoreWindowStateFromString (pos.toString());
  48762. addAndMakeVisible (dw);
  48763. dw->toFront (true);
  48764. }
  48765. bool MultiDocumentPanel::addDocument (Component* const component,
  48766. const Colour& docColour,
  48767. const bool deleteWhenRemoved)
  48768. {
  48769. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  48770. // with a frame-within-a-frame! Just pass in the bare content component.
  48771. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  48772. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  48773. return false;
  48774. components.add (component);
  48775. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  48776. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  48777. component->addComponentListener (this);
  48778. if (mode == FloatingWindows)
  48779. {
  48780. if (isFullscreenWhenOneDocument())
  48781. {
  48782. if (components.size() == 1)
  48783. {
  48784. addAndMakeVisible (component);
  48785. }
  48786. else
  48787. {
  48788. if (components.size() == 2)
  48789. addWindow (components.getFirst());
  48790. addWindow (component);
  48791. }
  48792. }
  48793. else
  48794. {
  48795. addWindow (component);
  48796. }
  48797. }
  48798. else
  48799. {
  48800. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  48801. {
  48802. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  48803. Array <Component*> temp (components);
  48804. for (int i = 0; i < temp.size(); ++i)
  48805. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  48806. resized();
  48807. }
  48808. else
  48809. {
  48810. if (tabComponent != 0)
  48811. tabComponent->addTab (component->getName(), docColour, component, false);
  48812. else
  48813. addAndMakeVisible (component);
  48814. }
  48815. setActiveDocument (component);
  48816. }
  48817. resized();
  48818. activeDocumentChanged();
  48819. return true;
  48820. }
  48821. bool MultiDocumentPanel::closeDocument (Component* component,
  48822. const bool checkItsOkToCloseFirst)
  48823. {
  48824. if (components.contains (component))
  48825. {
  48826. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  48827. return false;
  48828. component->removeComponentListener (this);
  48829. const bool shouldDelete = shouldDeleteComp (component);
  48830. component->getProperties().remove ("mdiDocumentDelete_");
  48831. component->getProperties().remove ("mdiDocumentBkg_");
  48832. if (mode == FloatingWindows)
  48833. {
  48834. for (int i = getNumChildComponents(); --i >= 0;)
  48835. {
  48836. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48837. if (dw != 0 && dw->getContentComponent() == component)
  48838. {
  48839. dw->setContentComponent (0, false);
  48840. delete dw;
  48841. break;
  48842. }
  48843. }
  48844. if (shouldDelete)
  48845. delete component;
  48846. components.removeValue (component);
  48847. if (isFullscreenWhenOneDocument() && components.size() == 1)
  48848. {
  48849. for (int i = getNumChildComponents(); --i >= 0;)
  48850. {
  48851. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48852. if (dw != 0)
  48853. {
  48854. dw->setContentComponent (0, false);
  48855. delete dw;
  48856. }
  48857. }
  48858. addAndMakeVisible (components.getFirst());
  48859. }
  48860. }
  48861. else
  48862. {
  48863. jassert (components.indexOf (component) >= 0);
  48864. if (tabComponent != 0)
  48865. {
  48866. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48867. if (tabComponent->getTabContentComponent (i) == component)
  48868. tabComponent->removeTab (i);
  48869. }
  48870. else
  48871. {
  48872. removeChildComponent (component);
  48873. }
  48874. if (shouldDelete)
  48875. delete component;
  48876. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  48877. deleteAndZero (tabComponent);
  48878. components.removeValue (component);
  48879. if (components.size() > 0 && tabComponent == 0)
  48880. addAndMakeVisible (components.getFirst());
  48881. }
  48882. resized();
  48883. activeDocumentChanged();
  48884. }
  48885. else
  48886. {
  48887. jassertfalse
  48888. }
  48889. return true;
  48890. }
  48891. int MultiDocumentPanel::getNumDocuments() const throw()
  48892. {
  48893. return components.size();
  48894. }
  48895. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  48896. {
  48897. return components [index];
  48898. }
  48899. Component* MultiDocumentPanel::getActiveDocument() const throw()
  48900. {
  48901. if (mode == FloatingWindows)
  48902. {
  48903. for (int i = getNumChildComponents(); --i >= 0;)
  48904. {
  48905. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48906. if (dw != 0 && dw->isActiveWindow())
  48907. return dw->getContentComponent();
  48908. }
  48909. }
  48910. return components.getLast();
  48911. }
  48912. void MultiDocumentPanel::setActiveDocument (Component* component)
  48913. {
  48914. if (mode == FloatingWindows)
  48915. {
  48916. component = getContainerComp (component);
  48917. if (component != 0)
  48918. component->toFront (true);
  48919. }
  48920. else if (tabComponent != 0)
  48921. {
  48922. jassert (components.indexOf (component) >= 0);
  48923. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  48924. {
  48925. if (tabComponent->getTabContentComponent (i) == component)
  48926. {
  48927. tabComponent->setCurrentTabIndex (i);
  48928. break;
  48929. }
  48930. }
  48931. }
  48932. else
  48933. {
  48934. component->grabKeyboardFocus();
  48935. }
  48936. }
  48937. void MultiDocumentPanel::activeDocumentChanged()
  48938. {
  48939. }
  48940. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  48941. {
  48942. maximumNumDocuments = newNumber;
  48943. }
  48944. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  48945. {
  48946. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  48947. }
  48948. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  48949. {
  48950. return numDocsBeforeTabsUsed != 0;
  48951. }
  48952. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  48953. {
  48954. if (mode != newLayoutMode)
  48955. {
  48956. mode = newLayoutMode;
  48957. if (mode == FloatingWindows)
  48958. {
  48959. deleteAndZero (tabComponent);
  48960. }
  48961. else
  48962. {
  48963. for (int i = getNumChildComponents(); --i >= 0;)
  48964. {
  48965. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  48966. if (dw != 0)
  48967. {
  48968. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  48969. dw->setContentComponent (0, false);
  48970. delete dw;
  48971. }
  48972. }
  48973. }
  48974. resized();
  48975. const Array <Component*> tempComps (components);
  48976. components.clear();
  48977. for (int i = 0; i < tempComps.size(); ++i)
  48978. {
  48979. Component* const c = tempComps.getUnchecked(i);
  48980. addDocument (c,
  48981. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  48982. shouldDeleteComp (c));
  48983. }
  48984. }
  48985. }
  48986. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  48987. {
  48988. if (backgroundColour != newBackgroundColour)
  48989. {
  48990. backgroundColour = newBackgroundColour;
  48991. setOpaque (newBackgroundColour.isOpaque());
  48992. repaint();
  48993. }
  48994. }
  48995. void MultiDocumentPanel::paint (Graphics& g)
  48996. {
  48997. g.fillAll (backgroundColour);
  48998. }
  48999. void MultiDocumentPanel::resized()
  49000. {
  49001. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49002. {
  49003. for (int i = getNumChildComponents(); --i >= 0;)
  49004. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49005. }
  49006. setWantsKeyboardFocus (components.size() == 0);
  49007. }
  49008. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49009. {
  49010. if (mode == FloatingWindows)
  49011. {
  49012. for (int i = 0; i < getNumChildComponents(); ++i)
  49013. {
  49014. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49015. if (dw != 0 && dw->getContentComponent() == c)
  49016. {
  49017. c = dw;
  49018. break;
  49019. }
  49020. }
  49021. }
  49022. return c;
  49023. }
  49024. void MultiDocumentPanel::componentNameChanged (Component&)
  49025. {
  49026. if (mode == FloatingWindows)
  49027. {
  49028. for (int i = 0; i < getNumChildComponents(); ++i)
  49029. {
  49030. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49031. if (dw != 0)
  49032. dw->setName (dw->getContentComponent()->getName());
  49033. }
  49034. }
  49035. else if (tabComponent != 0)
  49036. {
  49037. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49038. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49039. }
  49040. }
  49041. void MultiDocumentPanel::updateOrder()
  49042. {
  49043. const Array <Component*> oldList (components);
  49044. if (mode == FloatingWindows)
  49045. {
  49046. components.clear();
  49047. for (int i = 0; i < getNumChildComponents(); ++i)
  49048. {
  49049. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49050. if (dw != 0)
  49051. components.add (dw->getContentComponent());
  49052. }
  49053. }
  49054. else
  49055. {
  49056. if (tabComponent != 0)
  49057. {
  49058. Component* const current = tabComponent->getCurrentContentComponent();
  49059. if (current != 0)
  49060. {
  49061. components.removeValue (current);
  49062. components.add (current);
  49063. }
  49064. }
  49065. }
  49066. if (components != oldList)
  49067. activeDocumentChanged();
  49068. }
  49069. END_JUCE_NAMESPACE
  49070. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49071. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49072. BEGIN_JUCE_NAMESPACE
  49073. ResizableBorderComponent::Zone::Zone (int zoneFlags) throw()
  49074. : zone (zoneFlags)
  49075. {
  49076. }
  49077. ResizableBorderComponent::Zone::Zone (const ResizableBorderComponent::Zone& other) throw() : zone (other.zone) {}
  49078. ResizableBorderComponent::Zone& ResizableBorderComponent::Zone::operator= (const ResizableBorderComponent::Zone& other) throw() { zone = other.zone; return *this; }
  49079. bool ResizableBorderComponent::Zone::operator== (const ResizableBorderComponent::Zone& other) const throw() { return zone == other.zone; }
  49080. bool ResizableBorderComponent::Zone::operator!= (const ResizableBorderComponent::Zone& other) const throw() { return zone != other.zone; }
  49081. const ResizableBorderComponent::Zone ResizableBorderComponent::Zone::fromPositionOnBorder (const Rectangle<int>& totalSize,
  49082. const BorderSize& border,
  49083. const Point<int>& position)
  49084. {
  49085. int z = 0;
  49086. if (totalSize.contains (position)
  49087. && ! border.subtractedFrom (totalSize).contains (position))
  49088. {
  49089. const int minW = jmax (totalSize.getWidth() / 10, jmin (10, totalSize.getWidth() / 3));
  49090. if (position.getX() < jmax (border.getLeft(), minW))
  49091. z |= left;
  49092. else if (position.getX() >= totalSize.getWidth() - jmax (border.getRight(), minW))
  49093. z |= right;
  49094. const int minH = jmax (totalSize.getHeight() / 10, jmin (10, totalSize.getHeight() / 3));
  49095. if (position.getY() < jmax (border.getTop(), minH))
  49096. z |= top;
  49097. else if (position.getY() >= totalSize.getHeight() - jmax (border.getBottom(), minH))
  49098. z |= bottom;
  49099. }
  49100. return Zone (z);
  49101. }
  49102. const MouseCursor ResizableBorderComponent::Zone::getMouseCursor() const throw()
  49103. {
  49104. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49105. switch (zone)
  49106. {
  49107. case (left | top): mc = MouseCursor::TopLeftCornerResizeCursor; break;
  49108. case top: mc = MouseCursor::TopEdgeResizeCursor; break;
  49109. case (right | top): mc = MouseCursor::TopRightCornerResizeCursor; break;
  49110. case left: mc = MouseCursor::LeftEdgeResizeCursor; break;
  49111. case right: mc = MouseCursor::RightEdgeResizeCursor; break;
  49112. case (left | bottom): mc = MouseCursor::BottomLeftCornerResizeCursor; break;
  49113. case bottom: mc = MouseCursor::BottomEdgeResizeCursor; break;
  49114. case (right | bottom): mc = MouseCursor::BottomRightCornerResizeCursor; break;
  49115. default: break;
  49116. }
  49117. return mc;
  49118. }
  49119. const Rectangle<int> ResizableBorderComponent::Zone::resizeRectangleBy (Rectangle<int> b, const Point<int>& offset) const throw()
  49120. {
  49121. if (isDraggingWholeObject())
  49122. return b + offset;
  49123. if (isDraggingLeftEdge())
  49124. b.setLeft (b.getX() + offset.getX());
  49125. if (isDraggingRightEdge())
  49126. b.setWidth (jmax (0, b.getWidth() + offset.getX()));
  49127. if (isDraggingTopEdge())
  49128. b.setTop (b.getY() + offset.getY());
  49129. if (isDraggingBottomEdge())
  49130. b.setHeight (jmax (0, b.getHeight() + offset.getY()));
  49131. return b;
  49132. }
  49133. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49134. ComponentBoundsConstrainer* const constrainer_)
  49135. : component (componentToResize),
  49136. constrainer (constrainer_),
  49137. borderSize (5),
  49138. mouseZone (0)
  49139. {
  49140. }
  49141. ResizableBorderComponent::~ResizableBorderComponent()
  49142. {
  49143. }
  49144. void ResizableBorderComponent::paint (Graphics& g)
  49145. {
  49146. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49147. }
  49148. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49149. {
  49150. updateMouseZone (e);
  49151. }
  49152. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49153. {
  49154. updateMouseZone (e);
  49155. }
  49156. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49157. {
  49158. if (component == 0)
  49159. {
  49160. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49161. return;
  49162. }
  49163. updateMouseZone (e);
  49164. originalBounds = component->getBounds();
  49165. if (constrainer != 0)
  49166. constrainer->resizeStart();
  49167. }
  49168. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49169. {
  49170. if (component == 0)
  49171. {
  49172. jassertfalse // You've deleted the component that this resizer was supposed to be using!
  49173. return;
  49174. }
  49175. const Rectangle<int> bounds (mouseZone.resizeRectangleBy (originalBounds, e.getOffsetFromDragStart()));
  49176. if (constrainer != 0)
  49177. constrainer->setBoundsForComponent (component, bounds,
  49178. mouseZone.isDraggingTopEdge(),
  49179. mouseZone.isDraggingLeftEdge(),
  49180. mouseZone.isDraggingBottomEdge(),
  49181. mouseZone.isDraggingRightEdge());
  49182. else
  49183. component->setBounds (bounds);
  49184. }
  49185. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49186. {
  49187. if (constrainer != 0)
  49188. constrainer->resizeEnd();
  49189. }
  49190. bool ResizableBorderComponent::hitTest (int x, int y)
  49191. {
  49192. return x < borderSize.getLeft()
  49193. || x >= getWidth() - borderSize.getRight()
  49194. || y < borderSize.getTop()
  49195. || y >= getHeight() - borderSize.getBottom();
  49196. }
  49197. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize)
  49198. {
  49199. if (borderSize != newBorderSize)
  49200. {
  49201. borderSize = newBorderSize;
  49202. repaint();
  49203. }
  49204. }
  49205. const BorderSize ResizableBorderComponent::getBorderThickness() const
  49206. {
  49207. return borderSize;
  49208. }
  49209. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e)
  49210. {
  49211. Zone newZone (Zone::fromPositionOnBorder (getLocalBounds(), borderSize, e.getPosition()));
  49212. if (mouseZone != newZone)
  49213. {
  49214. mouseZone = newZone;
  49215. setMouseCursor (newZone.getMouseCursor());
  49216. }
  49217. }
  49218. END_JUCE_NAMESPACE
  49219. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49220. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49221. BEGIN_JUCE_NAMESPACE
  49222. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49223. ComponentBoundsConstrainer* const constrainer_)
  49224. : component (componentToResize),
  49225. constrainer (constrainer_)
  49226. {
  49227. setRepaintsOnMouseActivity (true);
  49228. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49229. }
  49230. ResizableCornerComponent::~ResizableCornerComponent()
  49231. {
  49232. }
  49233. void ResizableCornerComponent::paint (Graphics& g)
  49234. {
  49235. getLookAndFeel()
  49236. .drawCornerResizer (g, getWidth(), getHeight(),
  49237. isMouseOverOrDragging(),
  49238. isMouseButtonDown());
  49239. }
  49240. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49241. {
  49242. if (component == 0)
  49243. {
  49244. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49245. return;
  49246. }
  49247. originalBounds = component->getBounds();
  49248. if (constrainer != 0)
  49249. constrainer->resizeStart();
  49250. }
  49251. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49252. {
  49253. if (component == 0)
  49254. {
  49255. jassertfalse; // You've deleted the component that this resizer is supposed to be controlling!
  49256. return;
  49257. }
  49258. Rectangle<int> r (originalBounds.withSize (originalBounds.getWidth() + e.getDistanceFromDragStartX(),
  49259. originalBounds.getHeight() + e.getDistanceFromDragStartY()));
  49260. if (constrainer != 0)
  49261. constrainer->setBoundsForComponent (component, r, false, false, true, true);
  49262. else
  49263. component->setBounds (r);
  49264. }
  49265. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49266. {
  49267. if (constrainer != 0)
  49268. constrainer->resizeStart();
  49269. }
  49270. bool ResizableCornerComponent::hitTest (int x, int y)
  49271. {
  49272. if (getWidth() <= 0)
  49273. return false;
  49274. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49275. return y >= yAtX - getHeight() / 4;
  49276. }
  49277. END_JUCE_NAMESPACE
  49278. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49279. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49280. BEGIN_JUCE_NAMESPACE
  49281. class ScrollBar::ScrollbarButton : public Button
  49282. {
  49283. public:
  49284. int direction;
  49285. ScrollbarButton (const int direction_, ScrollBar& owner_)
  49286. : Button (String::empty),
  49287. direction (direction_),
  49288. owner (owner_)
  49289. {
  49290. setWantsKeyboardFocus (false);
  49291. }
  49292. ~ScrollbarButton()
  49293. {
  49294. }
  49295. void paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  49296. {
  49297. getLookAndFeel()
  49298. .drawScrollbarButton (g, owner,
  49299. getWidth(), getHeight(),
  49300. direction,
  49301. owner.isVertical(),
  49302. isMouseOver, isMouseDown);
  49303. }
  49304. void clicked()
  49305. {
  49306. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49307. }
  49308. juce_UseDebuggingNewOperator
  49309. private:
  49310. ScrollBar& owner;
  49311. ScrollbarButton (const ScrollbarButton&);
  49312. ScrollbarButton& operator= (const ScrollbarButton&);
  49313. };
  49314. ScrollBar::ScrollBar (const bool vertical_,
  49315. const bool buttonsAreVisible)
  49316. : totalRange (0.0, 1.0),
  49317. visibleRange (0.0, 0.1),
  49318. singleStepSize (0.1),
  49319. thumbAreaStart (0),
  49320. thumbAreaSize (0),
  49321. thumbStart (0),
  49322. thumbSize (0),
  49323. initialDelayInMillisecs (100),
  49324. repeatDelayInMillisecs (50),
  49325. minimumDelayInMillisecs (10),
  49326. vertical (vertical_),
  49327. isDraggingThumb (false),
  49328. alwaysVisible (false),
  49329. upButton (0),
  49330. downButton (0)
  49331. {
  49332. setButtonVisibility (buttonsAreVisible);
  49333. setRepaintsOnMouseActivity (true);
  49334. setFocusContainer (true);
  49335. }
  49336. ScrollBar::~ScrollBar()
  49337. {
  49338. deleteAllChildren();
  49339. }
  49340. void ScrollBar::setRangeLimits (const Range<double>& newRangeLimit)
  49341. {
  49342. if (totalRange != newRangeLimit)
  49343. {
  49344. totalRange = newRangeLimit;
  49345. setCurrentRange (visibleRange);
  49346. updateThumbPosition();
  49347. }
  49348. }
  49349. void ScrollBar::setRangeLimits (const double newMinimum, const double newMaximum)
  49350. {
  49351. jassert (newMaximum >= newMinimum); // these can't be the wrong way round!
  49352. setRangeLimits (Range<double> (newMinimum, newMaximum));
  49353. }
  49354. void ScrollBar::setCurrentRange (const Range<double>& newRange)
  49355. {
  49356. const Range<double> constrainedRange (totalRange.constrainRange (newRange));
  49357. if (visibleRange != constrainedRange)
  49358. {
  49359. visibleRange = constrainedRange;
  49360. updateThumbPosition();
  49361. triggerAsyncUpdate();
  49362. }
  49363. }
  49364. void ScrollBar::setCurrentRange (const double newStart, const double newSize)
  49365. {
  49366. setCurrentRange (Range<double> (newStart, newStart + newSize));
  49367. }
  49368. void ScrollBar::setCurrentRangeStart (const double newStart)
  49369. {
  49370. setCurrentRange (visibleRange.movedToStartAt (newStart));
  49371. }
  49372. void ScrollBar::setSingleStepSize (const double newSingleStepSize)
  49373. {
  49374. singleStepSize = newSingleStepSize;
  49375. }
  49376. void ScrollBar::moveScrollbarInSteps (const int howManySteps)
  49377. {
  49378. setCurrentRange (visibleRange + howManySteps * singleStepSize);
  49379. }
  49380. void ScrollBar::moveScrollbarInPages (const int howManyPages)
  49381. {
  49382. setCurrentRange (visibleRange + howManyPages * visibleRange.getLength());
  49383. }
  49384. void ScrollBar::scrollToTop()
  49385. {
  49386. setCurrentRange (visibleRange.movedToStartAt (getMinimumRangeLimit()));
  49387. }
  49388. void ScrollBar::scrollToBottom()
  49389. {
  49390. setCurrentRange (visibleRange.movedToEndAt (getMaximumRangeLimit()));
  49391. }
  49392. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  49393. const int repeatDelayInMillisecs_,
  49394. const int minimumDelayInMillisecs_)
  49395. {
  49396. initialDelayInMillisecs = initialDelayInMillisecs_;
  49397. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  49398. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  49399. if (upButton != 0)
  49400. {
  49401. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49402. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49403. }
  49404. }
  49405. void ScrollBar::addListener (ScrollBarListener* const listener)
  49406. {
  49407. listeners.add (listener);
  49408. }
  49409. void ScrollBar::removeListener (ScrollBarListener* const listener)
  49410. {
  49411. listeners.remove (listener);
  49412. }
  49413. void ScrollBar::handleAsyncUpdate()
  49414. {
  49415. double start = visibleRange.getStart(); // (need to use a temp variable for VC7 compatibility)
  49416. listeners.call (&ScrollBarListener::scrollBarMoved, this, start);
  49417. }
  49418. void ScrollBar::updateThumbPosition()
  49419. {
  49420. int newThumbSize = roundToInt (totalRange.getLength() > 0 ? (visibleRange.getLength() * thumbAreaSize) / totalRange.getLength()
  49421. : thumbAreaSize);
  49422. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49423. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  49424. if (newThumbSize > thumbAreaSize)
  49425. newThumbSize = thumbAreaSize;
  49426. int newThumbStart = thumbAreaStart;
  49427. if (totalRange.getLength() > visibleRange.getLength())
  49428. newThumbStart += roundToInt (((visibleRange.getStart() - totalRange.getStart()) * (thumbAreaSize - newThumbSize))
  49429. / (totalRange.getLength() - visibleRange.getLength()));
  49430. setVisible (alwaysVisible || (totalRange.getLength() > visibleRange.getLength() && visibleRange.getLength() > 0.0));
  49431. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  49432. {
  49433. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  49434. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  49435. if (vertical)
  49436. repaint (0, repaintStart, getWidth(), repaintSize);
  49437. else
  49438. repaint (repaintStart, 0, repaintSize, getHeight());
  49439. thumbStart = newThumbStart;
  49440. thumbSize = newThumbSize;
  49441. }
  49442. }
  49443. void ScrollBar::setOrientation (const bool shouldBeVertical)
  49444. {
  49445. if (vertical != shouldBeVertical)
  49446. {
  49447. vertical = shouldBeVertical;
  49448. if (upButton != 0)
  49449. {
  49450. upButton->direction = vertical ? 0 : 3;
  49451. downButton->direction = vertical ? 2 : 1;
  49452. }
  49453. updateThumbPosition();
  49454. }
  49455. }
  49456. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  49457. {
  49458. delete upButton;
  49459. upButton = 0;
  49460. delete downButton;
  49461. downButton = 0;
  49462. if (buttonsAreVisible)
  49463. {
  49464. addAndMakeVisible (upButton = new ScrollbarButton (vertical ? 0 : 3, *this));
  49465. addAndMakeVisible (downButton = new ScrollbarButton (vertical ? 2 : 1, *this));
  49466. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  49467. }
  49468. updateThumbPosition();
  49469. }
  49470. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  49471. {
  49472. alwaysVisible = ! shouldHideWhenFullRange;
  49473. updateThumbPosition();
  49474. }
  49475. void ScrollBar::paint (Graphics& g)
  49476. {
  49477. if (thumbAreaSize > 0)
  49478. {
  49479. LookAndFeel& lf = getLookAndFeel();
  49480. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  49481. ? thumbSize : 0;
  49482. if (vertical)
  49483. {
  49484. lf.drawScrollbar (g, *this,
  49485. 0, thumbAreaStart,
  49486. getWidth(), thumbAreaSize,
  49487. vertical,
  49488. thumbStart, thumb,
  49489. isMouseOver(), isMouseButtonDown());
  49490. }
  49491. else
  49492. {
  49493. lf.drawScrollbar (g, *this,
  49494. thumbAreaStart, 0,
  49495. thumbAreaSize, getHeight(),
  49496. vertical,
  49497. thumbStart, thumb,
  49498. isMouseOver(), isMouseButtonDown());
  49499. }
  49500. }
  49501. }
  49502. void ScrollBar::lookAndFeelChanged()
  49503. {
  49504. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  49505. }
  49506. void ScrollBar::resized()
  49507. {
  49508. const int length = ((vertical) ? getHeight() : getWidth());
  49509. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  49510. : 0;
  49511. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49512. {
  49513. thumbAreaStart = length >> 1;
  49514. thumbAreaSize = 0;
  49515. }
  49516. else
  49517. {
  49518. thumbAreaStart = buttonSize;
  49519. thumbAreaSize = length - (buttonSize << 1);
  49520. }
  49521. if (upButton != 0)
  49522. {
  49523. if (vertical)
  49524. {
  49525. upButton->setBounds (0, 0, getWidth(), buttonSize);
  49526. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  49527. }
  49528. else
  49529. {
  49530. upButton->setBounds (0, 0, buttonSize, getHeight());
  49531. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  49532. }
  49533. }
  49534. updateThumbPosition();
  49535. }
  49536. void ScrollBar::mouseDown (const MouseEvent& e)
  49537. {
  49538. isDraggingThumb = false;
  49539. lastMousePos = vertical ? e.y : e.x;
  49540. dragStartMousePos = lastMousePos;
  49541. dragStartRange = visibleRange.getStart();
  49542. if (dragStartMousePos < thumbStart)
  49543. {
  49544. moveScrollbarInPages (-1);
  49545. startTimer (400);
  49546. }
  49547. else if (dragStartMousePos >= thumbStart + thumbSize)
  49548. {
  49549. moveScrollbarInPages (1);
  49550. startTimer (400);
  49551. }
  49552. else
  49553. {
  49554. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  49555. && (thumbAreaSize > thumbSize);
  49556. }
  49557. }
  49558. void ScrollBar::mouseDrag (const MouseEvent& e)
  49559. {
  49560. if (isDraggingThumb)
  49561. {
  49562. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  49563. setCurrentRangeStart (dragStartRange
  49564. + deltaPixels * (totalRange.getLength() - visibleRange.getLength())
  49565. / (thumbAreaSize - thumbSize));
  49566. }
  49567. else
  49568. {
  49569. lastMousePos = (vertical) ? e.y : e.x;
  49570. }
  49571. }
  49572. void ScrollBar::mouseUp (const MouseEvent&)
  49573. {
  49574. isDraggingThumb = false;
  49575. stopTimer();
  49576. repaint();
  49577. }
  49578. void ScrollBar::mouseWheelMove (const MouseEvent&,
  49579. float wheelIncrementX,
  49580. float wheelIncrementY)
  49581. {
  49582. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  49583. if (increment < 0)
  49584. increment = jmin (increment * 10.0f, -1.0f);
  49585. else if (increment > 0)
  49586. increment = jmax (increment * 10.0f, 1.0f);
  49587. setCurrentRange (visibleRange - singleStepSize * increment);
  49588. }
  49589. void ScrollBar::timerCallback()
  49590. {
  49591. if (isMouseButtonDown())
  49592. {
  49593. startTimer (40);
  49594. if (lastMousePos < thumbStart)
  49595. setCurrentRange (visibleRange - visibleRange.getLength());
  49596. else if (lastMousePos > thumbStart + thumbSize)
  49597. setCurrentRangeStart (visibleRange.getEnd());
  49598. }
  49599. else
  49600. {
  49601. stopTimer();
  49602. }
  49603. }
  49604. bool ScrollBar::keyPressed (const KeyPress& key)
  49605. {
  49606. if (! isVisible())
  49607. return false;
  49608. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  49609. moveScrollbarInSteps (-1);
  49610. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  49611. moveScrollbarInSteps (1);
  49612. else if (key.isKeyCode (KeyPress::pageUpKey))
  49613. moveScrollbarInPages (-1);
  49614. else if (key.isKeyCode (KeyPress::pageDownKey))
  49615. moveScrollbarInPages (1);
  49616. else if (key.isKeyCode (KeyPress::homeKey))
  49617. scrollToTop();
  49618. else if (key.isKeyCode (KeyPress::endKey))
  49619. scrollToBottom();
  49620. else
  49621. return false;
  49622. return true;
  49623. }
  49624. END_JUCE_NAMESPACE
  49625. /*** End of inlined file: juce_ScrollBar.cpp ***/
  49626. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  49627. BEGIN_JUCE_NAMESPACE
  49628. StretchableLayoutManager::StretchableLayoutManager()
  49629. : totalSize (0)
  49630. {
  49631. }
  49632. StretchableLayoutManager::~StretchableLayoutManager()
  49633. {
  49634. }
  49635. void StretchableLayoutManager::clearAllItems()
  49636. {
  49637. items.clear();
  49638. totalSize = 0;
  49639. }
  49640. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  49641. const double minimumSize,
  49642. const double maximumSize,
  49643. const double preferredSize)
  49644. {
  49645. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  49646. if (layout == 0)
  49647. {
  49648. layout = new ItemLayoutProperties();
  49649. layout->itemIndex = itemIndex;
  49650. int i;
  49651. for (i = 0; i < items.size(); ++i)
  49652. if (items.getUnchecked (i)->itemIndex > itemIndex)
  49653. break;
  49654. items.insert (i, layout);
  49655. }
  49656. layout->minSize = minimumSize;
  49657. layout->maxSize = maximumSize;
  49658. layout->preferredSize = preferredSize;
  49659. layout->currentSize = 0;
  49660. }
  49661. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  49662. double& minimumSize,
  49663. double& maximumSize,
  49664. double& preferredSize) const
  49665. {
  49666. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49667. if (layout != 0)
  49668. {
  49669. minimumSize = layout->minSize;
  49670. maximumSize = layout->maxSize;
  49671. preferredSize = layout->preferredSize;
  49672. return true;
  49673. }
  49674. return false;
  49675. }
  49676. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  49677. {
  49678. totalSize = newTotalSize;
  49679. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  49680. }
  49681. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  49682. {
  49683. int pos = 0;
  49684. for (int i = 0; i < itemIndex; ++i)
  49685. {
  49686. const ItemLayoutProperties* const layout = getInfoFor (i);
  49687. if (layout != 0)
  49688. pos += layout->currentSize;
  49689. }
  49690. return pos;
  49691. }
  49692. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  49693. {
  49694. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49695. if (layout != 0)
  49696. return layout->currentSize;
  49697. return 0;
  49698. }
  49699. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  49700. {
  49701. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  49702. if (layout != 0)
  49703. return -layout->currentSize / (double) totalSize;
  49704. return 0;
  49705. }
  49706. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  49707. int newPosition)
  49708. {
  49709. for (int i = items.size(); --i >= 0;)
  49710. {
  49711. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  49712. if (layout->itemIndex == itemIndex)
  49713. {
  49714. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  49715. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  49716. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  49717. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  49718. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  49719. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  49720. endPos += layout->currentSize;
  49721. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  49722. updatePrefSizesToMatchCurrentPositions();
  49723. break;
  49724. }
  49725. }
  49726. }
  49727. void StretchableLayoutManager::layOutComponents (Component** const components,
  49728. int numComponents,
  49729. int x, int y, int w, int h,
  49730. const bool vertically,
  49731. const bool resizeOtherDimension)
  49732. {
  49733. setTotalSize (vertically ? h : w);
  49734. int pos = vertically ? y : x;
  49735. for (int i = 0; i < numComponents; ++i)
  49736. {
  49737. const ItemLayoutProperties* const layout = getInfoFor (i);
  49738. if (layout != 0)
  49739. {
  49740. Component* const c = components[i];
  49741. if (c != 0)
  49742. {
  49743. if (i == numComponents - 1)
  49744. {
  49745. // if it's the last item, crop it to exactly fit the available space..
  49746. if (resizeOtherDimension)
  49747. {
  49748. if (vertically)
  49749. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  49750. else
  49751. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  49752. }
  49753. else
  49754. {
  49755. if (vertically)
  49756. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  49757. else
  49758. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  49759. }
  49760. }
  49761. else
  49762. {
  49763. if (resizeOtherDimension)
  49764. {
  49765. if (vertically)
  49766. c->setBounds (x, pos, w, layout->currentSize);
  49767. else
  49768. c->setBounds (pos, y, layout->currentSize, h);
  49769. }
  49770. else
  49771. {
  49772. if (vertically)
  49773. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  49774. else
  49775. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  49776. }
  49777. }
  49778. }
  49779. pos += layout->currentSize;
  49780. }
  49781. }
  49782. }
  49783. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  49784. {
  49785. for (int i = items.size(); --i >= 0;)
  49786. if (items.getUnchecked(i)->itemIndex == itemIndex)
  49787. return items.getUnchecked(i);
  49788. return 0;
  49789. }
  49790. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  49791. const int endIndex,
  49792. const int availableSpace,
  49793. int startPos)
  49794. {
  49795. // calculate the total sizes
  49796. int i;
  49797. double totalIdealSize = 0.0;
  49798. int totalMinimums = 0;
  49799. for (i = startIndex; i < endIndex; ++i)
  49800. {
  49801. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49802. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  49803. totalMinimums += layout->currentSize;
  49804. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  49805. }
  49806. if (totalIdealSize <= 0)
  49807. totalIdealSize = 1.0;
  49808. // now calc the best sizes..
  49809. int extraSpace = availableSpace - totalMinimums;
  49810. while (extraSpace > 0)
  49811. {
  49812. int numWantingMoreSpace = 0;
  49813. int numHavingTakenExtraSpace = 0;
  49814. // first figure out how many comps want a slice of the extra space..
  49815. for (i = startIndex; i < endIndex; ++i)
  49816. {
  49817. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49818. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49819. const int bestSize = jlimit (layout->currentSize,
  49820. jmax (layout->currentSize,
  49821. sizeToRealSize (layout->maxSize, totalSize)),
  49822. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49823. if (bestSize > layout->currentSize)
  49824. ++numWantingMoreSpace;
  49825. }
  49826. // ..share out the extra space..
  49827. for (i = startIndex; i < endIndex; ++i)
  49828. {
  49829. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49830. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  49831. int bestSize = jlimit (layout->currentSize,
  49832. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  49833. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  49834. const int extraWanted = bestSize - layout->currentSize;
  49835. if (extraWanted > 0)
  49836. {
  49837. const int extraAllowed = jmin (extraWanted,
  49838. extraSpace / jmax (1, numWantingMoreSpace));
  49839. if (extraAllowed > 0)
  49840. {
  49841. ++numHavingTakenExtraSpace;
  49842. --numWantingMoreSpace;
  49843. layout->currentSize += extraAllowed;
  49844. extraSpace -= extraAllowed;
  49845. }
  49846. }
  49847. }
  49848. if (numHavingTakenExtraSpace <= 0)
  49849. break;
  49850. }
  49851. // ..and calculate the end position
  49852. for (i = startIndex; i < endIndex; ++i)
  49853. {
  49854. ItemLayoutProperties* const layout = items.getUnchecked(i);
  49855. startPos += layout->currentSize;
  49856. }
  49857. return startPos;
  49858. }
  49859. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  49860. const int endIndex) const
  49861. {
  49862. int totalMinimums = 0;
  49863. for (int i = startIndex; i < endIndex; ++i)
  49864. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  49865. return totalMinimums;
  49866. }
  49867. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  49868. {
  49869. int totalMaximums = 0;
  49870. for (int i = startIndex; i < endIndex; ++i)
  49871. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  49872. return totalMaximums;
  49873. }
  49874. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  49875. {
  49876. for (int i = 0; i < items.size(); ++i)
  49877. {
  49878. ItemLayoutProperties* const layout = items.getUnchecked (i);
  49879. layout->preferredSize
  49880. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  49881. : getItemCurrentAbsoluteSize (i);
  49882. }
  49883. }
  49884. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  49885. {
  49886. if (size < 0)
  49887. size *= -totalSpace;
  49888. return roundToInt (size);
  49889. }
  49890. END_JUCE_NAMESPACE
  49891. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  49892. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49893. BEGIN_JUCE_NAMESPACE
  49894. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  49895. const int itemIndex_,
  49896. const bool isVertical_)
  49897. : layout (layout_),
  49898. itemIndex (itemIndex_),
  49899. isVertical (isVertical_)
  49900. {
  49901. setRepaintsOnMouseActivity (true);
  49902. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  49903. : MouseCursor::UpDownResizeCursor));
  49904. }
  49905. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  49906. {
  49907. }
  49908. void StretchableLayoutResizerBar::paint (Graphics& g)
  49909. {
  49910. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  49911. getWidth(), getHeight(),
  49912. isVertical,
  49913. isMouseOver(),
  49914. isMouseButtonDown());
  49915. }
  49916. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  49917. {
  49918. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  49919. }
  49920. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  49921. {
  49922. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  49923. : e.getDistanceFromDragStartY());
  49924. layout->setItemPosition (itemIndex, desiredPos);
  49925. hasBeenMoved();
  49926. }
  49927. void StretchableLayoutResizerBar::hasBeenMoved()
  49928. {
  49929. if (getParentComponent() != 0)
  49930. getParentComponent()->resized();
  49931. }
  49932. END_JUCE_NAMESPACE
  49933. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  49934. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  49935. BEGIN_JUCE_NAMESPACE
  49936. StretchableObjectResizer::StretchableObjectResizer()
  49937. {
  49938. }
  49939. StretchableObjectResizer::~StretchableObjectResizer()
  49940. {
  49941. }
  49942. void StretchableObjectResizer::addItem (const double size,
  49943. const double minSize, const double maxSize,
  49944. const int order)
  49945. {
  49946. // the order must be >= 0 but less than the maximum integer value.
  49947. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  49948. Item* const item = new Item();
  49949. item->size = size;
  49950. item->minSize = minSize;
  49951. item->maxSize = maxSize;
  49952. item->order = order;
  49953. items.add (item);
  49954. }
  49955. double StretchableObjectResizer::getItemSize (const int index) const throw()
  49956. {
  49957. const Item* const it = items [index];
  49958. return it != 0 ? it->size : 0;
  49959. }
  49960. void StretchableObjectResizer::resizeToFit (const double targetSize)
  49961. {
  49962. int order = 0;
  49963. for (;;)
  49964. {
  49965. double currentSize = 0;
  49966. double minSize = 0;
  49967. double maxSize = 0;
  49968. int nextHighestOrder = std::numeric_limits<int>::max();
  49969. for (int i = 0; i < items.size(); ++i)
  49970. {
  49971. const Item* const it = items.getUnchecked(i);
  49972. currentSize += it->size;
  49973. if (it->order <= order)
  49974. {
  49975. minSize += it->minSize;
  49976. maxSize += it->maxSize;
  49977. }
  49978. else
  49979. {
  49980. minSize += it->size;
  49981. maxSize += it->size;
  49982. nextHighestOrder = jmin (nextHighestOrder, it->order);
  49983. }
  49984. }
  49985. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  49986. if (thisIterationTarget >= currentSize)
  49987. {
  49988. const double availableExtraSpace = maxSize - currentSize;
  49989. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  49990. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  49991. for (int i = 0; i < items.size(); ++i)
  49992. {
  49993. Item* const it = items.getUnchecked(i);
  49994. if (it->order <= order)
  49995. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  49996. }
  49997. }
  49998. else
  49999. {
  50000. const double amountOfSlack = currentSize - minSize;
  50001. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50002. const double scale = targetAmountOfSlack / amountOfSlack;
  50003. for (int i = 0; i < items.size(); ++i)
  50004. {
  50005. Item* const it = items.getUnchecked(i);
  50006. if (it->order <= order)
  50007. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50008. }
  50009. }
  50010. if (nextHighestOrder < std::numeric_limits<int>::max())
  50011. order = nextHighestOrder;
  50012. else
  50013. break;
  50014. }
  50015. }
  50016. END_JUCE_NAMESPACE
  50017. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50018. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50019. BEGIN_JUCE_NAMESPACE
  50020. TabBarButton::TabBarButton (const String& name,
  50021. TabbedButtonBar* const owner_,
  50022. const int index)
  50023. : Button (name),
  50024. owner (owner_),
  50025. tabIndex (index),
  50026. overlapPixels (0)
  50027. {
  50028. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50029. setComponentEffect (&shadow);
  50030. setWantsKeyboardFocus (false);
  50031. }
  50032. TabBarButton::~TabBarButton()
  50033. {
  50034. }
  50035. void TabBarButton::paintButton (Graphics& g,
  50036. bool isMouseOverButton,
  50037. bool isButtonDown)
  50038. {
  50039. int x, y, w, h;
  50040. getActiveArea (x, y, w, h);
  50041. g.setOrigin (x, y);
  50042. getLookAndFeel()
  50043. .drawTabButton (g, w, h,
  50044. owner->getTabBackgroundColour (tabIndex),
  50045. tabIndex, getButtonText(), *this,
  50046. owner->getOrientation(),
  50047. isMouseOverButton, isButtonDown,
  50048. getToggleState());
  50049. }
  50050. void TabBarButton::clicked (const ModifierKeys& mods)
  50051. {
  50052. if (mods.isPopupMenu())
  50053. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50054. else
  50055. owner->setCurrentTabIndex (tabIndex);
  50056. }
  50057. bool TabBarButton::hitTest (int mx, int my)
  50058. {
  50059. int x, y, w, h;
  50060. getActiveArea (x, y, w, h);
  50061. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50062. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50063. {
  50064. if (((unsigned int) mx) < (unsigned int) getWidth()
  50065. && my >= y + overlapPixels
  50066. && my < y + h - overlapPixels)
  50067. return true;
  50068. }
  50069. else
  50070. {
  50071. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50072. && ((unsigned int) my) < (unsigned int) getHeight())
  50073. return true;
  50074. }
  50075. Path p;
  50076. getLookAndFeel()
  50077. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50078. owner->getOrientation(),
  50079. false, false, getToggleState());
  50080. return p.contains ((float) (mx - x),
  50081. (float) (my - y));
  50082. }
  50083. int TabBarButton::getBestTabLength (const int depth)
  50084. {
  50085. return jlimit (depth * 2,
  50086. depth * 7,
  50087. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50088. }
  50089. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50090. {
  50091. x = 0;
  50092. y = 0;
  50093. int r = getWidth();
  50094. int b = getHeight();
  50095. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50096. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50097. r -= spaceAroundImage;
  50098. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50099. x += spaceAroundImage;
  50100. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50101. y += spaceAroundImage;
  50102. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50103. b -= spaceAroundImage;
  50104. w = r - x;
  50105. h = b - y;
  50106. }
  50107. class TabAreaBehindFrontButtonComponent : public Component
  50108. {
  50109. public:
  50110. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50111. : owner (owner_)
  50112. {
  50113. setInterceptsMouseClicks (false, false);
  50114. }
  50115. ~TabAreaBehindFrontButtonComponent()
  50116. {
  50117. }
  50118. void paint (Graphics& g)
  50119. {
  50120. getLookAndFeel()
  50121. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50122. *owner, owner->getOrientation());
  50123. }
  50124. void enablementChanged()
  50125. {
  50126. repaint();
  50127. }
  50128. private:
  50129. TabbedButtonBar* const owner;
  50130. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50131. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50132. };
  50133. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50134. : orientation (orientation_),
  50135. currentTabIndex (-1),
  50136. extraTabsButton (0)
  50137. {
  50138. setInterceptsMouseClicks (false, true);
  50139. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50140. setFocusContainer (true);
  50141. }
  50142. TabbedButtonBar::~TabbedButtonBar()
  50143. {
  50144. deleteAllChildren();
  50145. }
  50146. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50147. {
  50148. orientation = newOrientation;
  50149. for (int i = getNumChildComponents(); --i >= 0;)
  50150. getChildComponent (i)->resized();
  50151. resized();
  50152. }
  50153. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50154. {
  50155. return new TabBarButton (name, this, index);
  50156. }
  50157. void TabbedButtonBar::clearTabs()
  50158. {
  50159. tabs.clear();
  50160. tabColours.clear();
  50161. currentTabIndex = -1;
  50162. deleteAndZero (extraTabsButton);
  50163. removeChildComponent (behindFrontTab);
  50164. deleteAllChildren();
  50165. addChildComponent (behindFrontTab);
  50166. setCurrentTabIndex (-1);
  50167. }
  50168. void TabbedButtonBar::addTab (const String& tabName,
  50169. const Colour& tabBackgroundColour,
  50170. int insertIndex)
  50171. {
  50172. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50173. if (tabName.isNotEmpty())
  50174. {
  50175. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50176. insertIndex = tabs.size();
  50177. for (int i = tabs.size(); --i >= insertIndex;)
  50178. {
  50179. TabBarButton* const tb = getTabButton (i);
  50180. if (tb != 0)
  50181. tb->tabIndex++;
  50182. }
  50183. tabs.insert (insertIndex, tabName);
  50184. tabColours.insert (insertIndex, tabBackgroundColour);
  50185. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50186. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50187. addAndMakeVisible (tb, insertIndex);
  50188. resized();
  50189. if (currentTabIndex < 0)
  50190. setCurrentTabIndex (0);
  50191. }
  50192. }
  50193. void TabbedButtonBar::setTabName (const int tabIndex,
  50194. const String& newName)
  50195. {
  50196. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50197. && tabs[tabIndex] != newName)
  50198. {
  50199. tabs.set (tabIndex, newName);
  50200. TabBarButton* const tb = getTabButton (tabIndex);
  50201. if (tb != 0)
  50202. tb->setButtonText (newName);
  50203. resized();
  50204. }
  50205. }
  50206. void TabbedButtonBar::removeTab (const int tabIndex)
  50207. {
  50208. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50209. {
  50210. const int oldTabIndex = currentTabIndex;
  50211. if (currentTabIndex == tabIndex)
  50212. currentTabIndex = -1;
  50213. tabs.remove (tabIndex);
  50214. tabColours.remove (tabIndex);
  50215. delete getTabButton (tabIndex);
  50216. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50217. {
  50218. TabBarButton* const tb = getTabButton (i);
  50219. if (tb != 0)
  50220. tb->tabIndex--;
  50221. }
  50222. resized();
  50223. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50224. }
  50225. }
  50226. void TabbedButtonBar::moveTab (const int currentIndex,
  50227. const int newIndex)
  50228. {
  50229. tabs.move (currentIndex, newIndex);
  50230. tabColours.move (currentIndex, newIndex);
  50231. resized();
  50232. }
  50233. int TabbedButtonBar::getNumTabs() const
  50234. {
  50235. return tabs.size();
  50236. }
  50237. const StringArray TabbedButtonBar::getTabNames() const
  50238. {
  50239. return tabs;
  50240. }
  50241. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50242. {
  50243. if (currentTabIndex != newIndex)
  50244. {
  50245. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50246. newIndex = -1;
  50247. currentTabIndex = newIndex;
  50248. for (int i = 0; i < getNumChildComponents(); ++i)
  50249. {
  50250. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50251. if (tb != 0)
  50252. tb->setToggleState (tb->tabIndex == newIndex, false);
  50253. }
  50254. resized();
  50255. if (sendChangeMessage_)
  50256. sendChangeMessage (this);
  50257. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50258. }
  50259. }
  50260. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50261. {
  50262. for (int i = getNumChildComponents(); --i >= 0;)
  50263. {
  50264. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50265. if (tb != 0 && tb->tabIndex == index)
  50266. return tb;
  50267. }
  50268. return 0;
  50269. }
  50270. void TabbedButtonBar::lookAndFeelChanged()
  50271. {
  50272. deleteAndZero (extraTabsButton);
  50273. resized();
  50274. }
  50275. void TabbedButtonBar::resized()
  50276. {
  50277. const double minimumScale = 0.7;
  50278. int depth = getWidth();
  50279. int length = getHeight();
  50280. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50281. swapVariables (depth, length);
  50282. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50283. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50284. int i, totalLength = overlap;
  50285. int numVisibleButtons = tabs.size();
  50286. for (i = 0; i < getNumChildComponents(); ++i)
  50287. {
  50288. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50289. if (tb != 0)
  50290. {
  50291. totalLength += tb->getBestTabLength (depth) - overlap;
  50292. tb->overlapPixels = overlap / 2;
  50293. }
  50294. }
  50295. double scale = 1.0;
  50296. if (totalLength > length)
  50297. scale = jmax (minimumScale, length / (double) totalLength);
  50298. const bool isTooBig = totalLength * scale > length;
  50299. int tabsButtonPos = 0;
  50300. if (isTooBig)
  50301. {
  50302. if (extraTabsButton == 0)
  50303. {
  50304. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50305. extraTabsButton->addButtonListener (this);
  50306. extraTabsButton->setAlwaysOnTop (true);
  50307. extraTabsButton->setTriggeredOnMouseDown (true);
  50308. }
  50309. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50310. extraTabsButton->setSize (buttonSize, buttonSize);
  50311. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50312. {
  50313. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50314. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50315. }
  50316. else
  50317. {
  50318. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50319. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50320. }
  50321. totalLength = 0;
  50322. for (i = 0; i < tabs.size(); ++i)
  50323. {
  50324. TabBarButton* const tb = getTabButton (i);
  50325. if (tb != 0)
  50326. {
  50327. const int newLength = totalLength + tb->getBestTabLength (depth);
  50328. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50329. {
  50330. totalLength += overlap;
  50331. break;
  50332. }
  50333. numVisibleButtons = i + 1;
  50334. totalLength = newLength - overlap;
  50335. }
  50336. }
  50337. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  50338. }
  50339. else
  50340. {
  50341. deleteAndZero (extraTabsButton);
  50342. }
  50343. int pos = 0;
  50344. TabBarButton* frontTab = 0;
  50345. for (i = 0; i < tabs.size(); ++i)
  50346. {
  50347. TabBarButton* const tb = getTabButton (i);
  50348. if (tb != 0)
  50349. {
  50350. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  50351. if (i < numVisibleButtons)
  50352. {
  50353. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50354. tb->setBounds (pos, 0, bestLength, getHeight());
  50355. else
  50356. tb->setBounds (0, pos, getWidth(), bestLength);
  50357. tb->toBack();
  50358. if (tb->tabIndex == currentTabIndex)
  50359. frontTab = tb;
  50360. tb->setVisible (true);
  50361. }
  50362. else
  50363. {
  50364. tb->setVisible (false);
  50365. }
  50366. pos += bestLength - overlap;
  50367. }
  50368. }
  50369. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  50370. if (frontTab != 0)
  50371. {
  50372. frontTab->toFront (false);
  50373. behindFrontTab->toBehind (frontTab);
  50374. }
  50375. }
  50376. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  50377. {
  50378. return tabColours [tabIndex];
  50379. }
  50380. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50381. {
  50382. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  50383. && tabColours [tabIndex] != newColour)
  50384. {
  50385. tabColours.set (tabIndex, newColour);
  50386. repaint();
  50387. }
  50388. }
  50389. void TabbedButtonBar::buttonClicked (Button* button)
  50390. {
  50391. if (extraTabsButton == button)
  50392. {
  50393. PopupMenu m;
  50394. for (int i = 0; i < tabs.size(); ++i)
  50395. {
  50396. TabBarButton* const tb = getTabButton (i);
  50397. if (tb != 0 && ! tb->isVisible())
  50398. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  50399. }
  50400. const int res = m.showAt (extraTabsButton);
  50401. if (res != 0)
  50402. setCurrentTabIndex (res - 1);
  50403. }
  50404. }
  50405. void TabbedButtonBar::currentTabChanged (const int, const String&)
  50406. {
  50407. }
  50408. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  50409. {
  50410. }
  50411. END_JUCE_NAMESPACE
  50412. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  50413. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  50414. BEGIN_JUCE_NAMESPACE
  50415. class TabCompButtonBar : public TabbedButtonBar
  50416. {
  50417. public:
  50418. TabCompButtonBar (TabbedComponent* const owner_,
  50419. const TabbedButtonBar::Orientation orientation)
  50420. : TabbedButtonBar (orientation),
  50421. owner (owner_)
  50422. {
  50423. }
  50424. ~TabCompButtonBar()
  50425. {
  50426. }
  50427. void currentTabChanged (int newCurrentTabIndex,
  50428. const String& newTabName)
  50429. {
  50430. owner->changeCallback (newCurrentTabIndex, newTabName);
  50431. }
  50432. void popupMenuClickOnTab (int tabIndex,
  50433. const String& tabName)
  50434. {
  50435. owner->popupMenuClickOnTab (tabIndex, tabName);
  50436. }
  50437. const Colour getTabBackgroundColour (const int tabIndex)
  50438. {
  50439. return owner->tabs->getTabBackgroundColour (tabIndex);
  50440. }
  50441. TabBarButton* createTabButton (const String& tabName, int tabIndex)
  50442. {
  50443. return owner->createTabButton (tabName, tabIndex);
  50444. }
  50445. juce_UseDebuggingNewOperator
  50446. private:
  50447. TabbedComponent* const owner;
  50448. TabCompButtonBar (const TabCompButtonBar&);
  50449. TabCompButtonBar& operator= (const TabCompButtonBar&);
  50450. };
  50451. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  50452. : panelComponent (0),
  50453. tabDepth (30),
  50454. outlineThickness (1),
  50455. edgeIndent (0)
  50456. {
  50457. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  50458. }
  50459. TabbedComponent::~TabbedComponent()
  50460. {
  50461. clearTabs();
  50462. delete tabs;
  50463. }
  50464. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  50465. {
  50466. tabs->setOrientation (orientation);
  50467. resized();
  50468. }
  50469. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  50470. {
  50471. return tabs->getOrientation();
  50472. }
  50473. void TabbedComponent::setTabBarDepth (const int newDepth)
  50474. {
  50475. if (tabDepth != newDepth)
  50476. {
  50477. tabDepth = newDepth;
  50478. resized();
  50479. }
  50480. }
  50481. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  50482. {
  50483. return new TabBarButton (tabName, tabs, tabIndex);
  50484. }
  50485. void TabbedComponent::clearTabs()
  50486. {
  50487. if (panelComponent != 0)
  50488. {
  50489. panelComponent->setVisible (false);
  50490. removeChildComponent (panelComponent);
  50491. panelComponent = 0;
  50492. }
  50493. tabs->clearTabs();
  50494. for (int i = contentComponents.size(); --i >= 0;)
  50495. {
  50496. Component* const c = contentComponents.getUnchecked(i);
  50497. // be careful not to delete these components until they've been removed from the tab component
  50498. jassert (c == 0 || c->isValidComponent());
  50499. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50500. delete c;
  50501. }
  50502. contentComponents.clear();
  50503. }
  50504. void TabbedComponent::addTab (const String& tabName,
  50505. const Colour& tabBackgroundColour,
  50506. Component* const contentComponent,
  50507. const bool deleteComponentWhenNotNeeded,
  50508. const int insertIndex)
  50509. {
  50510. contentComponents.insert (insertIndex, contentComponent);
  50511. if (contentComponent != 0)
  50512. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  50513. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  50514. }
  50515. void TabbedComponent::setTabName (const int tabIndex,
  50516. const String& newName)
  50517. {
  50518. tabs->setTabName (tabIndex, newName);
  50519. }
  50520. void TabbedComponent::removeTab (const int tabIndex)
  50521. {
  50522. Component* const c = contentComponents [tabIndex];
  50523. if (c != 0 && (bool) c->getProperties() ["deleteByTabComp_"])
  50524. {
  50525. if (c == panelComponent)
  50526. panelComponent = 0;
  50527. delete c;
  50528. }
  50529. contentComponents.remove (tabIndex);
  50530. tabs->removeTab (tabIndex);
  50531. }
  50532. int TabbedComponent::getNumTabs() const
  50533. {
  50534. return tabs->getNumTabs();
  50535. }
  50536. const StringArray TabbedComponent::getTabNames() const
  50537. {
  50538. return tabs->getTabNames();
  50539. }
  50540. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  50541. {
  50542. return contentComponents [tabIndex];
  50543. }
  50544. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  50545. {
  50546. return tabs->getTabBackgroundColour (tabIndex);
  50547. }
  50548. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  50549. {
  50550. tabs->setTabBackgroundColour (tabIndex, newColour);
  50551. if (getCurrentTabIndex() == tabIndex)
  50552. repaint();
  50553. }
  50554. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  50555. {
  50556. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  50557. }
  50558. int TabbedComponent::getCurrentTabIndex() const
  50559. {
  50560. return tabs->getCurrentTabIndex();
  50561. }
  50562. const String& TabbedComponent::getCurrentTabName() const
  50563. {
  50564. return tabs->getCurrentTabName();
  50565. }
  50566. void TabbedComponent::setOutline (int thickness)
  50567. {
  50568. outlineThickness = thickness;
  50569. repaint();
  50570. }
  50571. void TabbedComponent::setIndent (const int indentThickness)
  50572. {
  50573. edgeIndent = indentThickness;
  50574. }
  50575. void TabbedComponent::paint (Graphics& g)
  50576. {
  50577. g.fillAll (findColour (backgroundColourId));
  50578. const TabbedButtonBar::Orientation o = getOrientation();
  50579. int x = 0;
  50580. int y = 0;
  50581. int r = getWidth();
  50582. int b = getHeight();
  50583. if (o == TabbedButtonBar::TabsAtTop)
  50584. y += tabDepth;
  50585. else if (o == TabbedButtonBar::TabsAtBottom)
  50586. b -= tabDepth;
  50587. else if (o == TabbedButtonBar::TabsAtLeft)
  50588. x += tabDepth;
  50589. else if (o == TabbedButtonBar::TabsAtRight)
  50590. r -= tabDepth;
  50591. g.reduceClipRegion (x, y, r - x, b - y);
  50592. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  50593. if (outlineThickness > 0)
  50594. {
  50595. if (o == TabbedButtonBar::TabsAtTop)
  50596. --y;
  50597. else if (o == TabbedButtonBar::TabsAtBottom)
  50598. ++b;
  50599. else if (o == TabbedButtonBar::TabsAtLeft)
  50600. --x;
  50601. else if (o == TabbedButtonBar::TabsAtRight)
  50602. ++r;
  50603. g.setColour (findColour (outlineColourId));
  50604. g.drawRect (x, y, r - x, b - y, outlineThickness);
  50605. }
  50606. }
  50607. void TabbedComponent::resized()
  50608. {
  50609. const TabbedButtonBar::Orientation o = getOrientation();
  50610. const int indent = edgeIndent + outlineThickness;
  50611. BorderSize indents (indent);
  50612. if (o == TabbedButtonBar::TabsAtTop)
  50613. {
  50614. tabs->setBounds (0, 0, getWidth(), tabDepth);
  50615. indents.setTop (tabDepth + edgeIndent);
  50616. }
  50617. else if (o == TabbedButtonBar::TabsAtBottom)
  50618. {
  50619. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  50620. indents.setBottom (tabDepth + edgeIndent);
  50621. }
  50622. else if (o == TabbedButtonBar::TabsAtLeft)
  50623. {
  50624. tabs->setBounds (0, 0, tabDepth, getHeight());
  50625. indents.setLeft (tabDepth + edgeIndent);
  50626. }
  50627. else if (o == TabbedButtonBar::TabsAtRight)
  50628. {
  50629. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  50630. indents.setRight (tabDepth + edgeIndent);
  50631. }
  50632. const Rectangle<int> bounds (indents.subtractedFrom (getLocalBounds()));
  50633. for (int i = contentComponents.size(); --i >= 0;)
  50634. if (contentComponents.getUnchecked (i) != 0)
  50635. contentComponents.getUnchecked (i)->setBounds (bounds);
  50636. }
  50637. void TabbedComponent::lookAndFeelChanged()
  50638. {
  50639. for (int i = contentComponents.size(); --i >= 0;)
  50640. if (contentComponents.getUnchecked (i) != 0)
  50641. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  50642. }
  50643. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  50644. const String& newTabName)
  50645. {
  50646. if (panelComponent != 0)
  50647. {
  50648. panelComponent->setVisible (false);
  50649. removeChildComponent (panelComponent);
  50650. panelComponent = 0;
  50651. }
  50652. if (getCurrentTabIndex() >= 0)
  50653. {
  50654. panelComponent = contentComponents [getCurrentTabIndex()];
  50655. if (panelComponent != 0)
  50656. {
  50657. // do these ops as two stages instead of addAndMakeVisible() so that the
  50658. // component has always got a parent when it gets the visibilityChanged() callback
  50659. addChildComponent (panelComponent);
  50660. panelComponent->setVisible (true);
  50661. panelComponent->toFront (true);
  50662. }
  50663. repaint();
  50664. }
  50665. resized();
  50666. currentTabChanged (newCurrentTabIndex, newTabName);
  50667. }
  50668. void TabbedComponent::currentTabChanged (const int, const String&)
  50669. {
  50670. }
  50671. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  50672. {
  50673. }
  50674. END_JUCE_NAMESPACE
  50675. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  50676. /*** Start of inlined file: juce_Viewport.cpp ***/
  50677. BEGIN_JUCE_NAMESPACE
  50678. Viewport::Viewport (const String& componentName)
  50679. : Component (componentName),
  50680. contentComp (0),
  50681. lastVX (0),
  50682. lastVY (0),
  50683. lastVW (0),
  50684. lastVH (0),
  50685. scrollBarThickness (0),
  50686. singleStepX (16),
  50687. singleStepY (16),
  50688. showHScrollbar (true),
  50689. showVScrollbar (true)
  50690. {
  50691. // content holder is used to clip the contents so they don't overlap the scrollbars
  50692. addAndMakeVisible (contentHolder = new Component());
  50693. contentHolder->setInterceptsMouseClicks (false, true);
  50694. verticalScrollBar = new ScrollBar (true);
  50695. horizontalScrollBar = new ScrollBar (false);
  50696. addChildComponent (verticalScrollBar);
  50697. addChildComponent (horizontalScrollBar);
  50698. verticalScrollBar->addListener (this);
  50699. horizontalScrollBar->addListener (this);
  50700. setInterceptsMouseClicks (false, true);
  50701. setWantsKeyboardFocus (true);
  50702. }
  50703. Viewport::~Viewport()
  50704. {
  50705. contentHolder->deleteAllChildren();
  50706. deleteAllChildren();
  50707. }
  50708. void Viewport::visibleAreaChanged (int, int, int, int)
  50709. {
  50710. }
  50711. void Viewport::setViewedComponent (Component* const newViewedComponent)
  50712. {
  50713. if (contentComp.getComponent() != newViewedComponent)
  50714. {
  50715. {
  50716. ScopedPointer<Component> oldCompDeleter (contentComp);
  50717. contentComp = 0;
  50718. }
  50719. contentComp = newViewedComponent;
  50720. if (contentComp != 0)
  50721. {
  50722. contentComp->setTopLeftPosition (0, 0);
  50723. contentHolder->addAndMakeVisible (contentComp);
  50724. contentComp->addComponentListener (this);
  50725. }
  50726. updateVisibleRegion();
  50727. }
  50728. }
  50729. int Viewport::getMaximumVisibleWidth() const throw()
  50730. {
  50731. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50732. }
  50733. int Viewport::getMaximumVisibleHeight() const throw()
  50734. {
  50735. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  50736. }
  50737. void Viewport::setViewPosition (const int xPixelsOffset,
  50738. const int yPixelsOffset)
  50739. {
  50740. if (contentComp != 0)
  50741. contentComp->setTopLeftPosition (-xPixelsOffset,
  50742. -yPixelsOffset);
  50743. }
  50744. void Viewport::setViewPositionProportionately (const double x,
  50745. const double y)
  50746. {
  50747. if (contentComp != 0)
  50748. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  50749. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  50750. }
  50751. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  50752. {
  50753. if (contentComp != 0)
  50754. {
  50755. int dx = 0, dy = 0;
  50756. if (mouseX < activeBorderThickness)
  50757. dx = activeBorderThickness - mouseX;
  50758. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  50759. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  50760. if (dx < 0)
  50761. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  50762. else
  50763. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  50764. if (mouseY < activeBorderThickness)
  50765. dy = activeBorderThickness - mouseY;
  50766. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  50767. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  50768. if (dy < 0)
  50769. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  50770. else
  50771. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  50772. if (dx != 0 || dy != 0)
  50773. {
  50774. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  50775. contentComp->getY() + dy);
  50776. return true;
  50777. }
  50778. }
  50779. return false;
  50780. }
  50781. void Viewport::componentMovedOrResized (Component&, bool, bool)
  50782. {
  50783. updateVisibleRegion();
  50784. }
  50785. void Viewport::resized()
  50786. {
  50787. updateVisibleRegion();
  50788. }
  50789. void Viewport::updateVisibleRegion()
  50790. {
  50791. if (contentComp != 0)
  50792. {
  50793. const int newVX = -contentComp->getX();
  50794. const int newVY = -contentComp->getY();
  50795. if (newVX == 0 && newVY == 0
  50796. && contentComp->getWidth() <= getWidth()
  50797. && contentComp->getHeight() <= getHeight())
  50798. {
  50799. horizontalScrollBar->setVisible (false);
  50800. verticalScrollBar->setVisible (false);
  50801. }
  50802. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  50803. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50804. horizontalScrollBar->setSingleStepSize (singleStepX);
  50805. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  50806. horizontalScrollBar->setVisible (false);
  50807. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  50808. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50809. verticalScrollBar->setSingleStepSize (singleStepY);
  50810. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  50811. verticalScrollBar->setVisible (false);
  50812. if (verticalScrollBar->isVisible())
  50813. {
  50814. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50815. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  50816. verticalScrollBar
  50817. ->setBounds (getMaximumVisibleWidth(), 0,
  50818. getScrollBarThickness(), getMaximumVisibleHeight());
  50819. }
  50820. if (horizontalScrollBar->isVisible())
  50821. {
  50822. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  50823. horizontalScrollBar
  50824. ->setBounds (0, getMaximumVisibleHeight(),
  50825. getMaximumVisibleWidth(), getScrollBarThickness());
  50826. }
  50827. contentHolder->setSize (getMaximumVisibleWidth(),
  50828. getMaximumVisibleHeight());
  50829. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  50830. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  50831. if (newVX != lastVX
  50832. || newVY != lastVY
  50833. || newVW != lastVW
  50834. || newVH != lastVH)
  50835. {
  50836. lastVX = newVX;
  50837. lastVY = newVY;
  50838. lastVW = newVW;
  50839. lastVH = newVH;
  50840. visibleAreaChanged (newVX, newVY, newVW, newVH);
  50841. }
  50842. horizontalScrollBar->handleUpdateNowIfNeeded();
  50843. verticalScrollBar->handleUpdateNowIfNeeded();
  50844. }
  50845. else
  50846. {
  50847. horizontalScrollBar->setVisible (false);
  50848. verticalScrollBar->setVisible (false);
  50849. }
  50850. }
  50851. void Viewport::setSingleStepSizes (const int stepX,
  50852. const int stepY)
  50853. {
  50854. singleStepX = stepX;
  50855. singleStepY = stepY;
  50856. updateVisibleRegion();
  50857. }
  50858. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  50859. const bool showHorizontalScrollbarIfNeeded)
  50860. {
  50861. showVScrollbar = showVerticalScrollbarIfNeeded;
  50862. showHScrollbar = showHorizontalScrollbarIfNeeded;
  50863. updateVisibleRegion();
  50864. }
  50865. void Viewport::setScrollBarThickness (const int thickness)
  50866. {
  50867. scrollBarThickness = thickness;
  50868. updateVisibleRegion();
  50869. }
  50870. int Viewport::getScrollBarThickness() const throw()
  50871. {
  50872. return (scrollBarThickness > 0) ? scrollBarThickness
  50873. : getLookAndFeel().getDefaultScrollbarWidth();
  50874. }
  50875. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  50876. {
  50877. verticalScrollBar->setButtonVisibility (buttonsVisible);
  50878. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  50879. }
  50880. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart)
  50881. {
  50882. if (scrollBarThatHasMoved == horizontalScrollBar)
  50883. {
  50884. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  50885. }
  50886. else if (scrollBarThatHasMoved == verticalScrollBar)
  50887. {
  50888. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  50889. }
  50890. }
  50891. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50892. {
  50893. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  50894. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  50895. }
  50896. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  50897. {
  50898. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  50899. {
  50900. const bool hasVertBar = verticalScrollBar->isVisible();
  50901. const bool hasHorzBar = horizontalScrollBar->isVisible();
  50902. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  50903. {
  50904. if (wheelIncrementX == 0 && ! hasVertBar)
  50905. wheelIncrementX = wheelIncrementY;
  50906. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  50907. wheelIncrementX, wheelIncrementY);
  50908. return true;
  50909. }
  50910. else if (hasVertBar && wheelIncrementY != 0)
  50911. {
  50912. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  50913. wheelIncrementX, wheelIncrementY);
  50914. return true;
  50915. }
  50916. }
  50917. return false;
  50918. }
  50919. bool Viewport::keyPressed (const KeyPress& key)
  50920. {
  50921. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  50922. || key.isKeyCode (KeyPress::downKey)
  50923. || key.isKeyCode (KeyPress::pageUpKey)
  50924. || key.isKeyCode (KeyPress::pageDownKey)
  50925. || key.isKeyCode (KeyPress::homeKey)
  50926. || key.isKeyCode (KeyPress::endKey);
  50927. if (verticalScrollBar->isVisible() && isUpDownKey)
  50928. return verticalScrollBar->keyPressed (key);
  50929. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  50930. || key.isKeyCode (KeyPress::rightKey);
  50931. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  50932. return horizontalScrollBar->keyPressed (key);
  50933. return false;
  50934. }
  50935. END_JUCE_NAMESPACE
  50936. /*** End of inlined file: juce_Viewport.cpp ***/
  50937. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  50938. BEGIN_JUCE_NAMESPACE
  50939. static const Colour createBaseColour (const Colour& buttonColour,
  50940. const bool hasKeyboardFocus,
  50941. const bool isMouseOverButton,
  50942. const bool isButtonDown) throw()
  50943. {
  50944. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  50945. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  50946. if (isButtonDown)
  50947. return baseColour.contrasting (0.2f);
  50948. else if (isMouseOverButton)
  50949. return baseColour.contrasting (0.1f);
  50950. return baseColour;
  50951. }
  50952. LookAndFeel::LookAndFeel()
  50953. {
  50954. /* if this fails it means you're trying to create a LookAndFeel object before
  50955. the static Colours have been initialised. That ain't gonna work. It probably
  50956. means that you're using a static LookAndFeel object and that your compiler has
  50957. decided to intialise it before the Colours class.
  50958. */
  50959. jassert (Colours::white == Colour (0xffffffff));
  50960. // set up the standard set of colours..
  50961. const int textButtonColour = 0xffbbbbff;
  50962. const int textHighlightColour = 0x401111ee;
  50963. const int standardOutlineColour = 0xb2808080;
  50964. static const int standardColours[] =
  50965. {
  50966. TextButton::buttonColourId, textButtonColour,
  50967. TextButton::buttonOnColourId, 0xff4444ff,
  50968. TextButton::textColourOnId, 0xff000000,
  50969. TextButton::textColourOffId, 0xff000000,
  50970. ComboBox::buttonColourId, 0xffbbbbff,
  50971. ComboBox::outlineColourId, standardOutlineColour,
  50972. ToggleButton::textColourId, 0xff000000,
  50973. TextEditor::backgroundColourId, 0xffffffff,
  50974. TextEditor::textColourId, 0xff000000,
  50975. TextEditor::highlightColourId, textHighlightColour,
  50976. TextEditor::highlightedTextColourId, 0xff000000,
  50977. TextEditor::caretColourId, 0xff000000,
  50978. TextEditor::outlineColourId, 0x00000000,
  50979. TextEditor::focusedOutlineColourId, textButtonColour,
  50980. TextEditor::shadowColourId, 0x38000000,
  50981. Label::backgroundColourId, 0x00000000,
  50982. Label::textColourId, 0xff000000,
  50983. Label::outlineColourId, 0x00000000,
  50984. ScrollBar::backgroundColourId, 0x00000000,
  50985. ScrollBar::thumbColourId, 0xffffffff,
  50986. ScrollBar::trackColourId, 0xffffffff,
  50987. TreeView::linesColourId, 0x4c000000,
  50988. TreeView::backgroundColourId, 0x00000000,
  50989. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  50990. PopupMenu::backgroundColourId, 0xffffffff,
  50991. PopupMenu::textColourId, 0xff000000,
  50992. PopupMenu::headerTextColourId, 0xff000000,
  50993. PopupMenu::highlightedTextColourId, 0xffffffff,
  50994. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  50995. ComboBox::textColourId, 0xff000000,
  50996. ComboBox::backgroundColourId, 0xffffffff,
  50997. ComboBox::arrowColourId, 0x99000000,
  50998. ListBox::backgroundColourId, 0xffffffff,
  50999. ListBox::outlineColourId, standardOutlineColour,
  51000. ListBox::textColourId, 0xff000000,
  51001. Slider::backgroundColourId, 0x00000000,
  51002. Slider::thumbColourId, textButtonColour,
  51003. Slider::trackColourId, 0x7fffffff,
  51004. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51005. Slider::rotarySliderOutlineColourId, 0x66000000,
  51006. Slider::textBoxTextColourId, 0xff000000,
  51007. Slider::textBoxBackgroundColourId, 0xffffffff,
  51008. Slider::textBoxHighlightColourId, textHighlightColour,
  51009. Slider::textBoxOutlineColourId, standardOutlineColour,
  51010. ResizableWindow::backgroundColourId, 0xff777777,
  51011. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51012. AlertWindow::backgroundColourId, 0xffededed,
  51013. AlertWindow::textColourId, 0xff000000,
  51014. AlertWindow::outlineColourId, 0xff666666,
  51015. ProgressBar::backgroundColourId, 0xffeeeeee,
  51016. ProgressBar::foregroundColourId, 0xffaaaaee,
  51017. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51018. TooltipWindow::textColourId, 0xff000000,
  51019. TooltipWindow::outlineColourId, 0x4c000000,
  51020. TabbedComponent::backgroundColourId, 0x00000000,
  51021. TabbedComponent::outlineColourId, 0xff777777,
  51022. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51023. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51024. Toolbar::backgroundColourId, 0xfff6f8f9,
  51025. Toolbar::separatorColourId, 0x4c000000,
  51026. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51027. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51028. Toolbar::labelTextColourId, 0xff000000,
  51029. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51030. HyperlinkButton::textColourId, 0xcc1111ee,
  51031. GroupComponent::outlineColourId, 0x66000000,
  51032. GroupComponent::textColourId, 0xff000000,
  51033. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51034. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51035. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51036. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51037. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51038. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51039. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51040. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51041. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51042. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51043. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51044. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51045. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51046. CodeEditorComponent::caretColourId, 0xff000000,
  51047. CodeEditorComponent::highlightColourId, textHighlightColour,
  51048. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51049. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51050. ColourSelector::labelTextColourId, 0xff000000,
  51051. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51052. KeyMappingEditorComponent::textColourId, 0xff000000,
  51053. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51054. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51055. };
  51056. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51057. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51058. static String defaultSansName, defaultSerifName, defaultFixedName;
  51059. if (defaultSansName.isEmpty())
  51060. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51061. defaultSans = defaultSansName;
  51062. defaultSerif = defaultSerifName;
  51063. defaultFixed = defaultFixedName;
  51064. }
  51065. LookAndFeel::~LookAndFeel()
  51066. {
  51067. }
  51068. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51069. {
  51070. const int index = colourIds.indexOf (colourId);
  51071. if (index >= 0)
  51072. return colours [index];
  51073. jassertfalse
  51074. return Colours::black;
  51075. }
  51076. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51077. {
  51078. const int index = colourIds.indexOf (colourId);
  51079. if (index >= 0)
  51080. colours.set (index, colour);
  51081. colourIds.add (colourId);
  51082. colours.add (colour);
  51083. }
  51084. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51085. {
  51086. return colourIds.contains (colourId);
  51087. }
  51088. static LookAndFeel* defaultLF = 0;
  51089. static LookAndFeel* currentDefaultLF = 0;
  51090. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51091. {
  51092. // if this happens, your app hasn't initialised itself properly.. if you're
  51093. // trying to hack your own main() function, have a look at
  51094. // JUCEApplication::initialiseForGUI()
  51095. jassert (currentDefaultLF != 0);
  51096. return *currentDefaultLF;
  51097. }
  51098. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51099. {
  51100. if (newDefaultLookAndFeel == 0)
  51101. {
  51102. if (defaultLF == 0)
  51103. defaultLF = new LookAndFeel();
  51104. newDefaultLookAndFeel = defaultLF;
  51105. }
  51106. currentDefaultLF = newDefaultLookAndFeel;
  51107. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51108. {
  51109. Component* const c = Desktop::getInstance().getComponent (i);
  51110. if (c != 0)
  51111. c->sendLookAndFeelChange();
  51112. }
  51113. }
  51114. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51115. {
  51116. if (currentDefaultLF == defaultLF)
  51117. currentDefaultLF = 0;
  51118. deleteAndZero (defaultLF);
  51119. }
  51120. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51121. {
  51122. String faceName (font.getTypefaceName());
  51123. if (faceName == Font::getDefaultSansSerifFontName())
  51124. faceName = defaultSans;
  51125. else if (faceName == Font::getDefaultSerifFontName())
  51126. faceName = defaultSerif;
  51127. else if (faceName == Font::getDefaultMonospacedFontName())
  51128. faceName = defaultFixed;
  51129. Font f (font);
  51130. f.setTypefaceName (faceName);
  51131. return Typeface::createSystemTypefaceFor (f);
  51132. }
  51133. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51134. {
  51135. defaultSans = newName;
  51136. }
  51137. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51138. {
  51139. return component.getMouseCursor();
  51140. }
  51141. void LookAndFeel::drawButtonBackground (Graphics& g,
  51142. Button& button,
  51143. const Colour& backgroundColour,
  51144. bool isMouseOverButton,
  51145. bool isButtonDown)
  51146. {
  51147. const int width = button.getWidth();
  51148. const int height = button.getHeight();
  51149. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51150. const float halfThickness = outlineThickness * 0.5f;
  51151. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51152. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51153. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51154. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51155. const Colour baseColour (createBaseColour (backgroundColour,
  51156. button.hasKeyboardFocus (true),
  51157. isMouseOverButton, isButtonDown)
  51158. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51159. drawGlassLozenge (g,
  51160. indentL,
  51161. indentT,
  51162. width - indentL - indentR,
  51163. height - indentT - indentB,
  51164. baseColour, outlineThickness, -1.0f,
  51165. button.isConnectedOnLeft(),
  51166. button.isConnectedOnRight(),
  51167. button.isConnectedOnTop(),
  51168. button.isConnectedOnBottom());
  51169. }
  51170. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51171. {
  51172. return button.getFont();
  51173. }
  51174. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51175. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51176. {
  51177. Font font (getFontForTextButton (button));
  51178. g.setFont (font);
  51179. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51180. : TextButton::textColourOffId)
  51181. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51182. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51183. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51184. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51185. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51186. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51187. g.drawFittedText (button.getButtonText(),
  51188. leftIndent,
  51189. yIndent,
  51190. button.getWidth() - leftIndent - rightIndent,
  51191. button.getHeight() - yIndent * 2,
  51192. Justification::centred, 2);
  51193. }
  51194. void LookAndFeel::drawTickBox (Graphics& g,
  51195. Component& component,
  51196. float x, float y, float w, float h,
  51197. const bool ticked,
  51198. const bool isEnabled,
  51199. const bool isMouseOverButton,
  51200. const bool isButtonDown)
  51201. {
  51202. const float boxSize = w * 0.7f;
  51203. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51204. createBaseColour (component.findColour (TextButton::buttonColourId)
  51205. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51206. true,
  51207. isMouseOverButton,
  51208. isButtonDown),
  51209. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51210. if (ticked)
  51211. {
  51212. Path tick;
  51213. tick.startNewSubPath (1.5f, 3.0f);
  51214. tick.lineTo (3.0f, 6.0f);
  51215. tick.lineTo (6.0f, 0.0f);
  51216. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51217. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51218. .translated (x, y));
  51219. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51220. }
  51221. }
  51222. void LookAndFeel::drawToggleButton (Graphics& g,
  51223. ToggleButton& button,
  51224. bool isMouseOverButton,
  51225. bool isButtonDown)
  51226. {
  51227. if (button.hasKeyboardFocus (true))
  51228. {
  51229. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51230. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51231. }
  51232. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51233. const float tickWidth = fontSize * 1.1f;
  51234. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51235. tickWidth, tickWidth,
  51236. button.getToggleState(),
  51237. button.isEnabled(),
  51238. isMouseOverButton,
  51239. isButtonDown);
  51240. g.setColour (button.findColour (ToggleButton::textColourId));
  51241. g.setFont (fontSize);
  51242. if (! button.isEnabled())
  51243. g.setOpacity (0.5f);
  51244. const int textX = (int) tickWidth + 5;
  51245. g.drawFittedText (button.getButtonText(),
  51246. textX, 0,
  51247. button.getWidth() - textX - 2, button.getHeight(),
  51248. Justification::centredLeft, 10);
  51249. }
  51250. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51251. {
  51252. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51253. const int tickWidth = jmin (24, button.getHeight());
  51254. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51255. button.getHeight());
  51256. }
  51257. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51258. const String& message,
  51259. const String& button1,
  51260. const String& button2,
  51261. const String& button3,
  51262. AlertWindow::AlertIconType iconType,
  51263. int numButtons,
  51264. Component* associatedComponent)
  51265. {
  51266. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51267. if (numButtons == 1)
  51268. {
  51269. aw->addButton (button1, 0,
  51270. KeyPress (KeyPress::escapeKey, 0, 0),
  51271. KeyPress (KeyPress::returnKey, 0, 0));
  51272. }
  51273. else
  51274. {
  51275. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51276. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51277. if (button1ShortCut == button2ShortCut)
  51278. button2ShortCut = KeyPress();
  51279. if (numButtons == 2)
  51280. {
  51281. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51282. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51283. }
  51284. else if (numButtons == 3)
  51285. {
  51286. aw->addButton (button1, 1, button1ShortCut);
  51287. aw->addButton (button2, 2, button2ShortCut);
  51288. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51289. }
  51290. }
  51291. return aw;
  51292. }
  51293. void LookAndFeel::drawAlertBox (Graphics& g,
  51294. AlertWindow& alert,
  51295. const Rectangle<int>& textArea,
  51296. TextLayout& textLayout)
  51297. {
  51298. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51299. int iconSpaceUsed = 0;
  51300. Justification alignment (Justification::horizontallyCentred);
  51301. const int iconWidth = 80;
  51302. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51303. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51304. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51305. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51306. iconSize, iconSize);
  51307. if (alert.getAlertType() != AlertWindow::NoIcon)
  51308. {
  51309. Path icon;
  51310. uint32 colour;
  51311. char character;
  51312. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51313. {
  51314. colour = 0x55ff5555;
  51315. character = '!';
  51316. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51317. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51318. (float) iconRect.getX(), (float) iconRect.getBottom());
  51319. icon = icon.createPathWithRoundedCorners (5.0f);
  51320. }
  51321. else
  51322. {
  51323. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  51324. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  51325. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  51326. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  51327. }
  51328. GlyphArrangement ga;
  51329. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  51330. String::charToString (character),
  51331. (float) iconRect.getX(), (float) iconRect.getY(),
  51332. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  51333. Justification::centred, false);
  51334. ga.createPath (icon);
  51335. icon.setUsingNonZeroWinding (false);
  51336. g.setColour (Colour (colour));
  51337. g.fillPath (icon);
  51338. iconSpaceUsed = iconWidth;
  51339. alignment = Justification::left;
  51340. }
  51341. g.setColour (alert.findColour (AlertWindow::textColourId));
  51342. textLayout.drawWithin (g,
  51343. textArea.getX() + iconSpaceUsed, textArea.getY(),
  51344. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  51345. alignment.getFlags() | Justification::top);
  51346. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  51347. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  51348. }
  51349. int LookAndFeel::getAlertBoxWindowFlags()
  51350. {
  51351. return ComponentPeer::windowAppearsOnTaskbar
  51352. | ComponentPeer::windowHasDropShadow;
  51353. }
  51354. int LookAndFeel::getAlertWindowButtonHeight()
  51355. {
  51356. return 28;
  51357. }
  51358. const Font LookAndFeel::getAlertWindowFont()
  51359. {
  51360. return Font (12.0f);
  51361. }
  51362. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  51363. int width, int height,
  51364. double progress, const String& textToShow)
  51365. {
  51366. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  51367. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  51368. g.fillAll (background);
  51369. if (progress >= 0.0f && progress < 1.0f)
  51370. {
  51371. drawGlassLozenge (g, 1.0f, 1.0f,
  51372. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  51373. (float) (height - 2),
  51374. foreground,
  51375. 0.5f, 0.0f,
  51376. true, true, true, true);
  51377. }
  51378. else
  51379. {
  51380. // spinning bar..
  51381. g.setColour (foreground);
  51382. const int stripeWidth = height * 2;
  51383. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  51384. Path p;
  51385. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  51386. p.addQuadrilateral (x, 0.0f,
  51387. x + stripeWidth * 0.5f, 0.0f,
  51388. x, (float) height,
  51389. x - stripeWidth * 0.5f, (float) height);
  51390. Image im (Image::ARGB, width, height, true);
  51391. {
  51392. Graphics g2 (im);
  51393. drawGlassLozenge (g2, 1.0f, 1.0f,
  51394. (float) (width - 2),
  51395. (float) (height - 2),
  51396. foreground,
  51397. 0.5f, 0.0f,
  51398. true, true, true, true);
  51399. }
  51400. g.setTiledImageFill (im, 0, 0, 0.85f);
  51401. g.fillPath (p);
  51402. }
  51403. if (textToShow.isNotEmpty())
  51404. {
  51405. g.setColour (Colour::contrasting (background, foreground));
  51406. g.setFont (height * 0.6f);
  51407. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  51408. }
  51409. }
  51410. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  51411. {
  51412. const float radius = jmin (w, h) * 0.4f;
  51413. const float thickness = radius * 0.15f;
  51414. Path p;
  51415. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  51416. radius * 0.6f, thickness,
  51417. thickness * 0.5f);
  51418. const float cx = x + w * 0.5f;
  51419. const float cy = y + h * 0.5f;
  51420. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  51421. for (int i = 0; i < 12; ++i)
  51422. {
  51423. const int n = (i + 12 - animationIndex) % 12;
  51424. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  51425. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  51426. .translated (cx, cy));
  51427. }
  51428. }
  51429. void LookAndFeel::drawScrollbarButton (Graphics& g,
  51430. ScrollBar& scrollbar,
  51431. int width, int height,
  51432. int buttonDirection,
  51433. bool /*isScrollbarVertical*/,
  51434. bool /*isMouseOverButton*/,
  51435. bool isButtonDown)
  51436. {
  51437. Path p;
  51438. if (buttonDirection == 0)
  51439. p.addTriangle (width * 0.5f, height * 0.2f,
  51440. width * 0.1f, height * 0.7f,
  51441. width * 0.9f, height * 0.7f);
  51442. else if (buttonDirection == 1)
  51443. p.addTriangle (width * 0.8f, height * 0.5f,
  51444. width * 0.3f, height * 0.1f,
  51445. width * 0.3f, height * 0.9f);
  51446. else if (buttonDirection == 2)
  51447. p.addTriangle (width * 0.5f, height * 0.8f,
  51448. width * 0.1f, height * 0.3f,
  51449. width * 0.9f, height * 0.3f);
  51450. else if (buttonDirection == 3)
  51451. p.addTriangle (width * 0.2f, height * 0.5f,
  51452. width * 0.7f, height * 0.1f,
  51453. width * 0.7f, height * 0.9f);
  51454. if (isButtonDown)
  51455. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  51456. else
  51457. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51458. g.fillPath (p);
  51459. g.setColour (Colour (0x80000000));
  51460. g.strokePath (p, PathStrokeType (0.5f));
  51461. }
  51462. void LookAndFeel::drawScrollbar (Graphics& g,
  51463. ScrollBar& scrollbar,
  51464. int x, int y,
  51465. int width, int height,
  51466. bool isScrollbarVertical,
  51467. int thumbStartPosition,
  51468. int thumbSize,
  51469. bool /*isMouseOver*/,
  51470. bool /*isMouseDown*/)
  51471. {
  51472. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  51473. Path slotPath, thumbPath;
  51474. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  51475. const float slotIndentx2 = slotIndent * 2.0f;
  51476. const float thumbIndent = slotIndent + 1.0f;
  51477. const float thumbIndentx2 = thumbIndent * 2.0f;
  51478. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  51479. if (isScrollbarVertical)
  51480. {
  51481. slotPath.addRoundedRectangle (x + slotIndent,
  51482. y + slotIndent,
  51483. width - slotIndentx2,
  51484. height - slotIndentx2,
  51485. (width - slotIndentx2) * 0.5f);
  51486. if (thumbSize > 0)
  51487. thumbPath.addRoundedRectangle (x + thumbIndent,
  51488. thumbStartPosition + thumbIndent,
  51489. width - thumbIndentx2,
  51490. thumbSize - thumbIndentx2,
  51491. (width - thumbIndentx2) * 0.5f);
  51492. gx1 = (float) x;
  51493. gx2 = x + width * 0.7f;
  51494. }
  51495. else
  51496. {
  51497. slotPath.addRoundedRectangle (x + slotIndent,
  51498. y + slotIndent,
  51499. width - slotIndentx2,
  51500. height - slotIndentx2,
  51501. (height - slotIndentx2) * 0.5f);
  51502. if (thumbSize > 0)
  51503. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  51504. y + thumbIndent,
  51505. thumbSize - thumbIndentx2,
  51506. height - thumbIndentx2,
  51507. (height - thumbIndentx2) * 0.5f);
  51508. gy1 = (float) y;
  51509. gy2 = y + height * 0.7f;
  51510. }
  51511. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  51512. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  51513. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  51514. g.fillPath (slotPath);
  51515. if (isScrollbarVertical)
  51516. {
  51517. gx1 = x + width * 0.6f;
  51518. gx2 = (float) x + width;
  51519. }
  51520. else
  51521. {
  51522. gy1 = y + height * 0.6f;
  51523. gy2 = (float) y + height;
  51524. }
  51525. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  51526. Colour (0x19000000), gx2, gy2, false));
  51527. g.fillPath (slotPath);
  51528. g.setColour (thumbColour);
  51529. g.fillPath (thumbPath);
  51530. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  51531. Colours::transparentBlack, gx2, gy2, false));
  51532. g.saveState();
  51533. if (isScrollbarVertical)
  51534. g.reduceClipRegion (x + width / 2, y, width, height);
  51535. else
  51536. g.reduceClipRegion (x, y + height / 2, width, height);
  51537. g.fillPath (thumbPath);
  51538. g.restoreState();
  51539. g.setColour (Colour (0x4c000000));
  51540. g.strokePath (thumbPath, PathStrokeType (0.4f));
  51541. }
  51542. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  51543. {
  51544. return 0;
  51545. }
  51546. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  51547. {
  51548. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  51549. }
  51550. int LookAndFeel::getDefaultScrollbarWidth()
  51551. {
  51552. return 18;
  51553. }
  51554. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  51555. {
  51556. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  51557. : scrollbar.getHeight());
  51558. }
  51559. const Path LookAndFeel::getTickShape (const float height)
  51560. {
  51561. static const unsigned char tickShapeData[] =
  51562. {
  51563. 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,
  51564. 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,
  51565. 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,
  51566. 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,
  51567. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  51568. };
  51569. Path p;
  51570. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  51571. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51572. return p;
  51573. }
  51574. const Path LookAndFeel::getCrossShape (const float height)
  51575. {
  51576. static const unsigned char crossShapeData[] =
  51577. {
  51578. 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,
  51579. 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,
  51580. 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,
  51581. 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,
  51582. 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,
  51583. 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,
  51584. 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
  51585. };
  51586. Path p;
  51587. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  51588. p.scaleToFit (0, 0, height * 2.0f, height, true);
  51589. return p;
  51590. }
  51591. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  51592. {
  51593. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  51594. x += (w - boxSize) >> 1;
  51595. y += (h - boxSize) >> 1;
  51596. w = boxSize;
  51597. h = boxSize;
  51598. g.setColour (Colour (0xe5ffffff));
  51599. g.fillRect (x, y, w, h);
  51600. g.setColour (Colour (0x80000000));
  51601. g.drawRect (x, y, w, h);
  51602. const float size = boxSize / 2 + 1.0f;
  51603. const float centre = (float) (boxSize / 2);
  51604. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  51605. if (isPlus)
  51606. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  51607. }
  51608. void LookAndFeel::drawBubble (Graphics& g,
  51609. float tipX, float tipY,
  51610. float boxX, float boxY,
  51611. float boxW, float boxH)
  51612. {
  51613. int side = 0;
  51614. if (tipX < boxX)
  51615. side = 1;
  51616. else if (tipX > boxX + boxW)
  51617. side = 3;
  51618. else if (tipY > boxY + boxH)
  51619. side = 2;
  51620. const float indent = 2.0f;
  51621. Path p;
  51622. p.addBubble (boxX + indent,
  51623. boxY + indent,
  51624. boxW - indent * 2.0f,
  51625. boxH - indent * 2.0f,
  51626. 5.0f,
  51627. tipX, tipY,
  51628. side,
  51629. 0.5f,
  51630. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  51631. //xxx need to take comp as param for colour
  51632. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  51633. g.fillPath (p);
  51634. //xxx as above
  51635. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  51636. g.strokePath (p, PathStrokeType (1.33f));
  51637. }
  51638. const Font LookAndFeel::getPopupMenuFont()
  51639. {
  51640. return Font (17.0f);
  51641. }
  51642. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  51643. const bool isSeparator,
  51644. int standardMenuItemHeight,
  51645. int& idealWidth,
  51646. int& idealHeight)
  51647. {
  51648. if (isSeparator)
  51649. {
  51650. idealWidth = 50;
  51651. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  51652. }
  51653. else
  51654. {
  51655. Font font (getPopupMenuFont());
  51656. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  51657. font.setHeight (standardMenuItemHeight / 1.3f);
  51658. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  51659. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  51660. }
  51661. }
  51662. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  51663. {
  51664. const Colour background (findColour (PopupMenu::backgroundColourId));
  51665. g.fillAll (background);
  51666. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  51667. for (int i = 0; i < height; i += 3)
  51668. g.fillRect (0, i, width, 1);
  51669. #if ! JUCE_MAC
  51670. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  51671. g.drawRect (0, 0, width, height);
  51672. #endif
  51673. }
  51674. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  51675. int width, int height,
  51676. bool isScrollUpArrow)
  51677. {
  51678. const Colour background (findColour (PopupMenu::backgroundColourId));
  51679. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  51680. background.withAlpha (0.0f),
  51681. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  51682. false));
  51683. g.fillRect (1, 1, width - 2, height - 2);
  51684. const float hw = width * 0.5f;
  51685. const float arrowW = height * 0.3f;
  51686. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  51687. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  51688. Path p;
  51689. p.addTriangle (hw - arrowW, y1,
  51690. hw + arrowW, y1,
  51691. hw, y2);
  51692. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  51693. g.fillPath (p);
  51694. }
  51695. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  51696. int width, int height,
  51697. const bool isSeparator,
  51698. const bool isActive,
  51699. const bool isHighlighted,
  51700. const bool isTicked,
  51701. const bool hasSubMenu,
  51702. const String& text,
  51703. const String& shortcutKeyText,
  51704. Image* image,
  51705. const Colour* const textColourToUse)
  51706. {
  51707. const float halfH = height * 0.5f;
  51708. if (isSeparator)
  51709. {
  51710. const float separatorIndent = 5.5f;
  51711. g.setColour (Colour (0x33000000));
  51712. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  51713. g.setColour (Colour (0x66ffffff));
  51714. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  51715. }
  51716. else
  51717. {
  51718. Colour textColour (findColour (PopupMenu::textColourId));
  51719. if (textColourToUse != 0)
  51720. textColour = *textColourToUse;
  51721. if (isHighlighted)
  51722. {
  51723. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  51724. g.fillRect (1, 1, width - 2, height - 2);
  51725. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  51726. }
  51727. else
  51728. {
  51729. g.setColour (textColour);
  51730. }
  51731. if (! isActive)
  51732. g.setOpacity (0.3f);
  51733. Font font (getPopupMenuFont());
  51734. if (font.getHeight() > height / 1.3f)
  51735. font.setHeight (height / 1.3f);
  51736. g.setFont (font);
  51737. const int leftBorder = (height * 5) / 4;
  51738. const int rightBorder = 4;
  51739. if (image != 0)
  51740. {
  51741. g.drawImageWithin (image,
  51742. 2, 1, leftBorder - 4, height - 2,
  51743. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  51744. }
  51745. else if (isTicked)
  51746. {
  51747. const Path tick (getTickShape (1.0f));
  51748. const float th = font.getAscent();
  51749. const float ty = halfH - th * 0.5f;
  51750. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  51751. th, true));
  51752. }
  51753. g.drawFittedText (text,
  51754. leftBorder, 0,
  51755. width - (leftBorder + rightBorder), height,
  51756. Justification::centredLeft, 1);
  51757. if (shortcutKeyText.isNotEmpty())
  51758. {
  51759. Font f2 (font);
  51760. f2.setHeight (f2.getHeight() * 0.75f);
  51761. f2.setHorizontalScale (0.95f);
  51762. g.setFont (f2);
  51763. g.drawText (shortcutKeyText,
  51764. leftBorder,
  51765. 0,
  51766. width - (leftBorder + rightBorder + 4),
  51767. height,
  51768. Justification::centredRight,
  51769. true);
  51770. }
  51771. if (hasSubMenu)
  51772. {
  51773. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  51774. const float x = width - height * 0.6f;
  51775. Path p;
  51776. p.addTriangle (x, halfH - arrowH * 0.5f,
  51777. x, halfH + arrowH * 0.5f,
  51778. x + arrowH * 0.6f, halfH);
  51779. g.fillPath (p);
  51780. }
  51781. }
  51782. }
  51783. int LookAndFeel::getMenuWindowFlags()
  51784. {
  51785. return ComponentPeer::windowHasDropShadow;
  51786. }
  51787. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  51788. bool, MenuBarComponent& menuBar)
  51789. {
  51790. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  51791. if (menuBar.isEnabled())
  51792. {
  51793. drawShinyButtonShape (g,
  51794. -4.0f, 0.0f,
  51795. width + 8.0f, (float) height,
  51796. 0.0f,
  51797. baseColour,
  51798. 0.4f,
  51799. true, true, true, true);
  51800. }
  51801. else
  51802. {
  51803. g.fillAll (baseColour);
  51804. }
  51805. }
  51806. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  51807. {
  51808. return Font (menuBar.getHeight() * 0.7f);
  51809. }
  51810. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  51811. {
  51812. return getMenuBarFont (menuBar, itemIndex, itemText)
  51813. .getStringWidth (itemText) + menuBar.getHeight();
  51814. }
  51815. void LookAndFeel::drawMenuBarItem (Graphics& g,
  51816. int width, int height,
  51817. int itemIndex,
  51818. const String& itemText,
  51819. bool isMouseOverItem,
  51820. bool isMenuOpen,
  51821. bool /*isMouseOverBar*/,
  51822. MenuBarComponent& menuBar)
  51823. {
  51824. if (! menuBar.isEnabled())
  51825. {
  51826. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  51827. .withMultipliedAlpha (0.5f));
  51828. }
  51829. else if (isMenuOpen || isMouseOverItem)
  51830. {
  51831. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  51832. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  51833. }
  51834. else
  51835. {
  51836. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  51837. }
  51838. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  51839. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  51840. }
  51841. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  51842. TextEditor& textEditor)
  51843. {
  51844. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  51845. }
  51846. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  51847. {
  51848. if (textEditor.isEnabled())
  51849. {
  51850. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  51851. {
  51852. const int border = 2;
  51853. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  51854. g.drawRect (0, 0, width, height, border);
  51855. g.setOpacity (1.0f);
  51856. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  51857. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  51858. }
  51859. else
  51860. {
  51861. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  51862. g.drawRect (0, 0, width, height);
  51863. g.setOpacity (1.0f);
  51864. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  51865. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  51866. }
  51867. }
  51868. }
  51869. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  51870. const bool isButtonDown,
  51871. int buttonX, int buttonY,
  51872. int buttonW, int buttonH,
  51873. ComboBox& box)
  51874. {
  51875. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  51876. if (box.isEnabled() && box.hasKeyboardFocus (false))
  51877. {
  51878. g.setColour (box.findColour (TextButton::buttonColourId));
  51879. g.drawRect (0, 0, width, height, 2);
  51880. }
  51881. else
  51882. {
  51883. g.setColour (box.findColour (ComboBox::outlineColourId));
  51884. g.drawRect (0, 0, width, height);
  51885. }
  51886. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  51887. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  51888. box.hasKeyboardFocus (true),
  51889. false, isButtonDown)
  51890. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  51891. drawGlassLozenge (g,
  51892. buttonX + outlineThickness, buttonY + outlineThickness,
  51893. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  51894. baseColour, outlineThickness, -1.0f,
  51895. true, true, true, true);
  51896. if (box.isEnabled())
  51897. {
  51898. const float arrowX = 0.3f;
  51899. const float arrowH = 0.2f;
  51900. Path p;
  51901. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  51902. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  51903. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  51904. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  51905. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  51906. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  51907. g.setColour (box.findColour (ComboBox::arrowColourId));
  51908. g.fillPath (p);
  51909. }
  51910. }
  51911. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  51912. {
  51913. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  51914. }
  51915. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  51916. {
  51917. return new Label (String::empty, String::empty);
  51918. }
  51919. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  51920. {
  51921. label.setBounds (1, 1,
  51922. box.getWidth() + 3 - box.getHeight(),
  51923. box.getHeight() - 2);
  51924. label.setFont (getComboBoxFont (box));
  51925. }
  51926. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  51927. {
  51928. g.fillAll (label.findColour (Label::backgroundColourId));
  51929. if (! label.isBeingEdited())
  51930. {
  51931. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  51932. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  51933. g.setFont (label.getFont());
  51934. g.drawFittedText (label.getText(),
  51935. label.getHorizontalBorderSize(),
  51936. label.getVerticalBorderSize(),
  51937. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  51938. label.getHeight() - 2 * label.getVerticalBorderSize(),
  51939. label.getJustificationType(),
  51940. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  51941. label.getMinimumHorizontalScale());
  51942. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  51943. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51944. }
  51945. else if (label.isEnabled())
  51946. {
  51947. g.setColour (label.findColour (Label::outlineColourId));
  51948. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  51949. }
  51950. }
  51951. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  51952. int x, int y,
  51953. int width, int height,
  51954. float /*sliderPos*/,
  51955. float /*minSliderPos*/,
  51956. float /*maxSliderPos*/,
  51957. const Slider::SliderStyle /*style*/,
  51958. Slider& slider)
  51959. {
  51960. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  51961. const Colour trackColour (slider.findColour (Slider::trackColourId));
  51962. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  51963. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  51964. Path indent;
  51965. if (slider.isHorizontal())
  51966. {
  51967. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  51968. const float ih = sliderRadius;
  51969. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  51970. gradCol2, 0.0f, iy + ih, false));
  51971. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  51972. width + sliderRadius, ih,
  51973. 5.0f);
  51974. g.fillPath (indent);
  51975. }
  51976. else
  51977. {
  51978. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  51979. const float iw = sliderRadius;
  51980. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  51981. gradCol2, ix + iw, 0.0f, false));
  51982. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  51983. iw, height + sliderRadius,
  51984. 5.0f);
  51985. g.fillPath (indent);
  51986. }
  51987. g.setColour (Colour (0x4c000000));
  51988. g.strokePath (indent, PathStrokeType (0.5f));
  51989. }
  51990. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  51991. int x, int y,
  51992. int width, int height,
  51993. float sliderPos,
  51994. float minSliderPos,
  51995. float maxSliderPos,
  51996. const Slider::SliderStyle style,
  51997. Slider& slider)
  51998. {
  51999. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52000. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52001. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52002. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52003. slider.isMouseButtonDown() && slider.isEnabled()));
  52004. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52005. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52006. {
  52007. float kx, ky;
  52008. if (style == Slider::LinearVertical)
  52009. {
  52010. kx = x + width * 0.5f;
  52011. ky = sliderPos;
  52012. }
  52013. else
  52014. {
  52015. kx = sliderPos;
  52016. ky = y + height * 0.5f;
  52017. }
  52018. drawGlassSphere (g,
  52019. kx - sliderRadius,
  52020. ky - sliderRadius,
  52021. sliderRadius * 2.0f,
  52022. knobColour, outlineThickness);
  52023. }
  52024. else
  52025. {
  52026. if (style == Slider::ThreeValueVertical)
  52027. {
  52028. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52029. sliderPos - sliderRadius,
  52030. sliderRadius * 2.0f,
  52031. knobColour, outlineThickness);
  52032. }
  52033. else if (style == Slider::ThreeValueHorizontal)
  52034. {
  52035. drawGlassSphere (g,sliderPos - sliderRadius,
  52036. y + height * 0.5f - sliderRadius,
  52037. sliderRadius * 2.0f,
  52038. knobColour, outlineThickness);
  52039. }
  52040. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52041. {
  52042. const float sr = jmin (sliderRadius, width * 0.4f);
  52043. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52044. minSliderPos - sliderRadius,
  52045. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52046. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52047. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52048. }
  52049. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52050. {
  52051. const float sr = jmin (sliderRadius, height * 0.4f);
  52052. drawGlassPointer (g, minSliderPos - sr,
  52053. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52054. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52055. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52056. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52057. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52058. }
  52059. }
  52060. }
  52061. void LookAndFeel::drawLinearSlider (Graphics& g,
  52062. int x, int y,
  52063. int width, int height,
  52064. float sliderPos,
  52065. float minSliderPos,
  52066. float maxSliderPos,
  52067. const Slider::SliderStyle style,
  52068. Slider& slider)
  52069. {
  52070. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52071. if (style == Slider::LinearBar)
  52072. {
  52073. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52074. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52075. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52076. false,
  52077. isMouseOver,
  52078. isMouseOver || slider.isMouseButtonDown()));
  52079. drawShinyButtonShape (g,
  52080. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52081. baseColour,
  52082. slider.isEnabled() ? 0.9f : 0.3f,
  52083. true, true, true, true);
  52084. }
  52085. else
  52086. {
  52087. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52088. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52089. }
  52090. }
  52091. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52092. {
  52093. return jmin (7,
  52094. slider.getHeight() / 2,
  52095. slider.getWidth() / 2) + 2;
  52096. }
  52097. void LookAndFeel::drawRotarySlider (Graphics& g,
  52098. int x, int y,
  52099. int width, int height,
  52100. float sliderPos,
  52101. const float rotaryStartAngle,
  52102. const float rotaryEndAngle,
  52103. Slider& slider)
  52104. {
  52105. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52106. const float centreX = x + width * 0.5f;
  52107. const float centreY = y + height * 0.5f;
  52108. const float rx = centreX - radius;
  52109. const float ry = centreY - radius;
  52110. const float rw = radius * 2.0f;
  52111. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52112. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52113. if (radius > 12.0f)
  52114. {
  52115. if (slider.isEnabled())
  52116. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52117. else
  52118. g.setColour (Colour (0x80808080));
  52119. const float thickness = 0.7f;
  52120. {
  52121. Path filledArc;
  52122. filledArc.addPieSegment (rx, ry, rw, rw,
  52123. rotaryStartAngle,
  52124. angle,
  52125. thickness);
  52126. g.fillPath (filledArc);
  52127. }
  52128. if (thickness > 0)
  52129. {
  52130. const float innerRadius = radius * 0.2f;
  52131. Path p;
  52132. p.addTriangle (-innerRadius, 0.0f,
  52133. 0.0f, -radius * thickness * 1.1f,
  52134. innerRadius, 0.0f);
  52135. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52136. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52137. }
  52138. if (slider.isEnabled())
  52139. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52140. else
  52141. g.setColour (Colour (0x80808080));
  52142. Path outlineArc;
  52143. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52144. outlineArc.closeSubPath();
  52145. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52146. }
  52147. else
  52148. {
  52149. if (slider.isEnabled())
  52150. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52151. else
  52152. g.setColour (Colour (0x80808080));
  52153. Path p;
  52154. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52155. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52156. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52157. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52158. }
  52159. }
  52160. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52161. {
  52162. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52163. }
  52164. class SliderLabelComp : public Label
  52165. {
  52166. public:
  52167. SliderLabelComp() : Label (String::empty, String::empty) {}
  52168. ~SliderLabelComp() {}
  52169. void mouseWheelMove (const MouseEvent&, float, float) {}
  52170. };
  52171. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52172. {
  52173. Label* const l = new SliderLabelComp();
  52174. l->setJustificationType (Justification::centred);
  52175. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52176. l->setColour (Label::backgroundColourId,
  52177. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52178. : slider.findColour (Slider::textBoxBackgroundColourId));
  52179. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52180. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52181. l->setColour (TextEditor::backgroundColourId,
  52182. slider.findColour (Slider::textBoxBackgroundColourId)
  52183. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52184. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52185. return l;
  52186. }
  52187. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52188. {
  52189. return 0;
  52190. }
  52191. static const TextLayout layoutTooltipText (const String& text) throw()
  52192. {
  52193. const float tooltipFontSize = 12.0f;
  52194. const int maxToolTipWidth = 400;
  52195. const Font f (tooltipFontSize, Font::bold);
  52196. TextLayout tl (text, f);
  52197. tl.layout (maxToolTipWidth, Justification::left, true);
  52198. return tl;
  52199. }
  52200. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52201. {
  52202. const TextLayout tl (layoutTooltipText (tipText));
  52203. width = tl.getWidth() + 14;
  52204. height = tl.getHeight() + 6;
  52205. }
  52206. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52207. {
  52208. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52209. const Colour textCol (findColour (TooltipWindow::textColourId));
  52210. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52211. g.setColour (findColour (TooltipWindow::outlineColourId));
  52212. g.drawRect (0, 0, width, height, 1);
  52213. #endif
  52214. const TextLayout tl (layoutTooltipText (text));
  52215. g.setColour (findColour (TooltipWindow::textColourId));
  52216. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52217. }
  52218. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52219. {
  52220. return new TextButton (text, TRANS("click to browse for a different file"));
  52221. }
  52222. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52223. ComboBox* filenameBox,
  52224. Button* browseButton)
  52225. {
  52226. browseButton->setSize (80, filenameComp.getHeight());
  52227. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52228. if (tb != 0)
  52229. tb->changeWidthToFitText();
  52230. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52231. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52232. }
  52233. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52234. int imageX, int imageY, int imageW, int imageH,
  52235. const Colour& overlayColour,
  52236. float imageOpacity,
  52237. ImageButton& button)
  52238. {
  52239. if (! button.isEnabled())
  52240. imageOpacity *= 0.3f;
  52241. if (! overlayColour.isOpaque())
  52242. {
  52243. g.setOpacity (imageOpacity);
  52244. g.drawImage (image, imageX, imageY, imageW, imageH,
  52245. 0, 0, image->getWidth(), image->getHeight(), false);
  52246. }
  52247. if (! overlayColour.isTransparent())
  52248. {
  52249. g.setColour (overlayColour);
  52250. g.drawImage (image, imageX, imageY, imageW, imageH,
  52251. 0, 0, image->getWidth(), image->getHeight(), true);
  52252. }
  52253. }
  52254. void LookAndFeel::drawCornerResizer (Graphics& g,
  52255. int w, int h,
  52256. bool /*isMouseOver*/,
  52257. bool /*isMouseDragging*/)
  52258. {
  52259. const float lineThickness = jmin (w, h) * 0.075f;
  52260. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52261. {
  52262. g.setColour (Colours::lightgrey);
  52263. g.drawLine (w * i,
  52264. h + 1.0f,
  52265. w + 1.0f,
  52266. h * i,
  52267. lineThickness);
  52268. g.setColour (Colours::darkgrey);
  52269. g.drawLine (w * i + lineThickness,
  52270. h + 1.0f,
  52271. w + 1.0f,
  52272. h * i + lineThickness,
  52273. lineThickness);
  52274. }
  52275. }
  52276. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52277. const BorderSize& /*borders*/)
  52278. {
  52279. }
  52280. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52281. const BorderSize& /*border*/, ResizableWindow& window)
  52282. {
  52283. g.fillAll (window.getBackgroundColour());
  52284. }
  52285. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52286. const BorderSize& border, ResizableWindow&)
  52287. {
  52288. g.setColour (Colour (0x80000000));
  52289. g.drawRect (0, 0, w, h);
  52290. g.setColour (Colour (0x19000000));
  52291. g.drawRect (border.getLeft() - 1,
  52292. border.getTop() - 1,
  52293. w + 2 - border.getLeftAndRight(),
  52294. h + 2 - border.getTopAndBottom());
  52295. }
  52296. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52297. Graphics& g, int w, int h,
  52298. int titleSpaceX, int titleSpaceW,
  52299. const Image* icon,
  52300. bool drawTitleTextOnLeft)
  52301. {
  52302. const bool isActive = window.isActiveWindow();
  52303. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52304. 0.0f, 0.0f,
  52305. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52306. 0.0f, (float) h, false));
  52307. g.fillAll();
  52308. Font font (h * 0.65f, Font::bold);
  52309. g.setFont (font);
  52310. int textW = font.getStringWidth (window.getName());
  52311. int iconW = 0;
  52312. int iconH = 0;
  52313. if (icon != 0)
  52314. {
  52315. iconH = (int) font.getHeight();
  52316. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52317. }
  52318. textW = jmin (titleSpaceW, textW + iconW);
  52319. int textX = drawTitleTextOnLeft ? titleSpaceX
  52320. : jmax (titleSpaceX, (w - textW) / 2);
  52321. if (textX + textW > titleSpaceX + titleSpaceW)
  52322. textX = titleSpaceX + titleSpaceW - textW;
  52323. if (icon != 0)
  52324. {
  52325. g.setOpacity (isActive ? 1.0f : 0.6f);
  52326. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  52327. RectanglePlacement::centred, false);
  52328. textX += iconW;
  52329. textW -= iconW;
  52330. }
  52331. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  52332. g.setColour (findColour (DocumentWindow::textColourId));
  52333. else
  52334. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  52335. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  52336. }
  52337. class GlassWindowButton : public Button
  52338. {
  52339. public:
  52340. GlassWindowButton (const String& name, const Colour& col,
  52341. const Path& normalShape_,
  52342. const Path& toggledShape_) throw()
  52343. : Button (name),
  52344. colour (col),
  52345. normalShape (normalShape_),
  52346. toggledShape (toggledShape_)
  52347. {
  52348. }
  52349. ~GlassWindowButton()
  52350. {
  52351. }
  52352. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  52353. {
  52354. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  52355. if (! isEnabled())
  52356. alpha *= 0.5f;
  52357. float x = 0, y = 0, diam;
  52358. if (getWidth() < getHeight())
  52359. {
  52360. diam = (float) getWidth();
  52361. y = (getHeight() - getWidth()) * 0.5f;
  52362. }
  52363. else
  52364. {
  52365. diam = (float) getHeight();
  52366. y = (getWidth() - getHeight()) * 0.5f;
  52367. }
  52368. x += diam * 0.05f;
  52369. y += diam * 0.05f;
  52370. diam *= 0.9f;
  52371. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  52372. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  52373. g.fillEllipse (x, y, diam, diam);
  52374. x += 2.0f;
  52375. y += 2.0f;
  52376. diam -= 4.0f;
  52377. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  52378. Path& p = getToggleState() ? toggledShape : normalShape;
  52379. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  52380. diam * 0.4f, diam * 0.4f, true));
  52381. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  52382. g.fillPath (p, t);
  52383. }
  52384. juce_UseDebuggingNewOperator
  52385. private:
  52386. Colour colour;
  52387. Path normalShape, toggledShape;
  52388. GlassWindowButton (const GlassWindowButton&);
  52389. GlassWindowButton& operator= (const GlassWindowButton&);
  52390. };
  52391. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  52392. {
  52393. Path shape;
  52394. const float crossThickness = 0.25f;
  52395. if (buttonType == DocumentWindow::closeButton)
  52396. {
  52397. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  52398. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  52399. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  52400. }
  52401. else if (buttonType == DocumentWindow::minimiseButton)
  52402. {
  52403. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52404. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  52405. }
  52406. else if (buttonType == DocumentWindow::maximiseButton)
  52407. {
  52408. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  52409. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  52410. Path fullscreenShape;
  52411. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  52412. fullscreenShape.lineTo (0.0f, 100.0f);
  52413. fullscreenShape.lineTo (0.0f, 0.0f);
  52414. fullscreenShape.lineTo (100.0f, 0.0f);
  52415. fullscreenShape.lineTo (100.0f, 45.0f);
  52416. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  52417. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  52418. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  52419. }
  52420. jassertfalse
  52421. return 0;
  52422. }
  52423. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  52424. int titleBarX,
  52425. int titleBarY,
  52426. int titleBarW,
  52427. int titleBarH,
  52428. Button* minimiseButton,
  52429. Button* maximiseButton,
  52430. Button* closeButton,
  52431. bool positionTitleBarButtonsOnLeft)
  52432. {
  52433. const int buttonW = titleBarH - titleBarH / 8;
  52434. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  52435. : titleBarX + titleBarW - buttonW - buttonW / 4;
  52436. if (closeButton != 0)
  52437. {
  52438. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52439. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  52440. }
  52441. if (positionTitleBarButtonsOnLeft)
  52442. swapVariables (minimiseButton, maximiseButton);
  52443. if (maximiseButton != 0)
  52444. {
  52445. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52446. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  52447. }
  52448. if (minimiseButton != 0)
  52449. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  52450. }
  52451. int LookAndFeel::getDefaultMenuBarHeight()
  52452. {
  52453. return 24;
  52454. }
  52455. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  52456. {
  52457. return new DropShadower (0.4f, 1, 5, 10);
  52458. }
  52459. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  52460. int w, int h,
  52461. bool /*isVerticalBar*/,
  52462. bool isMouseOver,
  52463. bool isMouseDragging)
  52464. {
  52465. float alpha = 0.5f;
  52466. if (isMouseOver || isMouseDragging)
  52467. {
  52468. g.fillAll (Colour (0x190000ff));
  52469. alpha = 1.0f;
  52470. }
  52471. const float cx = w * 0.5f;
  52472. const float cy = h * 0.5f;
  52473. const float cr = jmin (w, h) * 0.4f;
  52474. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  52475. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  52476. true));
  52477. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  52478. }
  52479. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  52480. const String& text,
  52481. const Justification& position,
  52482. GroupComponent& group)
  52483. {
  52484. const float textH = 15.0f;
  52485. const float indent = 3.0f;
  52486. const float textEdgeGap = 4.0f;
  52487. float cs = 5.0f;
  52488. Font f (textH);
  52489. Path p;
  52490. float x = indent;
  52491. float y = f.getAscent() - 3.0f;
  52492. float w = jmax (0.0f, width - x * 2.0f);
  52493. float h = jmax (0.0f, height - y - indent);
  52494. cs = jmin (cs, w * 0.5f, h * 0.5f);
  52495. const float cs2 = 2.0f * cs;
  52496. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  52497. float textX = cs + textEdgeGap;
  52498. if (position.testFlags (Justification::horizontallyCentred))
  52499. textX = cs + (w - cs2 - textW) * 0.5f;
  52500. else if (position.testFlags (Justification::right))
  52501. textX = w - cs - textW - textEdgeGap;
  52502. p.startNewSubPath (x + textX + textW, y);
  52503. p.lineTo (x + w - cs, y);
  52504. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  52505. p.lineTo (x + w, y + h - cs);
  52506. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  52507. p.lineTo (x + cs, y + h);
  52508. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  52509. p.lineTo (x, y + cs);
  52510. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  52511. p.lineTo (x + textX, y);
  52512. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  52513. g.setColour (group.findColour (GroupComponent::outlineColourId)
  52514. .withMultipliedAlpha (alpha));
  52515. g.strokePath (p, PathStrokeType (2.0f));
  52516. g.setColour (group.findColour (GroupComponent::textColourId)
  52517. .withMultipliedAlpha (alpha));
  52518. g.setFont (f);
  52519. g.drawText (text,
  52520. roundToInt (x + textX), 0,
  52521. roundToInt (textW),
  52522. roundToInt (textH),
  52523. Justification::centred, true);
  52524. }
  52525. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  52526. {
  52527. return 1 + tabDepth / 3;
  52528. }
  52529. int LookAndFeel::getTabButtonSpaceAroundImage()
  52530. {
  52531. return 4;
  52532. }
  52533. void LookAndFeel::createTabButtonShape (Path& p,
  52534. int width, int height,
  52535. int /*tabIndex*/,
  52536. const String& /*text*/,
  52537. Button& /*button*/,
  52538. TabbedButtonBar::Orientation orientation,
  52539. const bool /*isMouseOver*/,
  52540. const bool /*isMouseDown*/,
  52541. const bool /*isFrontTab*/)
  52542. {
  52543. const float w = (float) width;
  52544. const float h = (float) height;
  52545. float length = w;
  52546. float depth = h;
  52547. if (orientation == TabbedButtonBar::TabsAtLeft
  52548. || orientation == TabbedButtonBar::TabsAtRight)
  52549. {
  52550. swapVariables (length, depth);
  52551. }
  52552. const float indent = (float) getTabButtonOverlap ((int) depth);
  52553. const float overhang = 4.0f;
  52554. if (orientation == TabbedButtonBar::TabsAtLeft)
  52555. {
  52556. p.startNewSubPath (w, 0.0f);
  52557. p.lineTo (0.0f, indent);
  52558. p.lineTo (0.0f, h - indent);
  52559. p.lineTo (w, h);
  52560. p.lineTo (w + overhang, h + overhang);
  52561. p.lineTo (w + overhang, -overhang);
  52562. }
  52563. else if (orientation == TabbedButtonBar::TabsAtRight)
  52564. {
  52565. p.startNewSubPath (0.0f, 0.0f);
  52566. p.lineTo (w, indent);
  52567. p.lineTo (w, h - indent);
  52568. p.lineTo (0.0f, h);
  52569. p.lineTo (-overhang, h + overhang);
  52570. p.lineTo (-overhang, -overhang);
  52571. }
  52572. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52573. {
  52574. p.startNewSubPath (0.0f, 0.0f);
  52575. p.lineTo (indent, h);
  52576. p.lineTo (w - indent, h);
  52577. p.lineTo (w, 0.0f);
  52578. p.lineTo (w + overhang, -overhang);
  52579. p.lineTo (-overhang, -overhang);
  52580. }
  52581. else
  52582. {
  52583. p.startNewSubPath (0.0f, h);
  52584. p.lineTo (indent, 0.0f);
  52585. p.lineTo (w - indent, 0.0f);
  52586. p.lineTo (w, h);
  52587. p.lineTo (w + overhang, h + overhang);
  52588. p.lineTo (-overhang, h + overhang);
  52589. }
  52590. p.closeSubPath();
  52591. p = p.createPathWithRoundedCorners (3.0f);
  52592. }
  52593. void LookAndFeel::fillTabButtonShape (Graphics& g,
  52594. const Path& path,
  52595. const Colour& preferredColour,
  52596. int /*tabIndex*/,
  52597. const String& /*text*/,
  52598. Button& button,
  52599. TabbedButtonBar::Orientation /*orientation*/,
  52600. const bool /*isMouseOver*/,
  52601. const bool /*isMouseDown*/,
  52602. const bool isFrontTab)
  52603. {
  52604. g.setColour (isFrontTab ? preferredColour
  52605. : preferredColour.withMultipliedAlpha (0.9f));
  52606. g.fillPath (path);
  52607. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  52608. : TabbedButtonBar::tabOutlineColourId, false)
  52609. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  52610. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  52611. }
  52612. void LookAndFeel::drawTabButtonText (Graphics& g,
  52613. int x, int y, int w, int h,
  52614. const Colour& preferredBackgroundColour,
  52615. int /*tabIndex*/,
  52616. const String& text,
  52617. Button& button,
  52618. TabbedButtonBar::Orientation orientation,
  52619. const bool isMouseOver,
  52620. const bool isMouseDown,
  52621. const bool isFrontTab)
  52622. {
  52623. int length = w;
  52624. int depth = h;
  52625. if (orientation == TabbedButtonBar::TabsAtLeft
  52626. || orientation == TabbedButtonBar::TabsAtRight)
  52627. {
  52628. swapVariables (length, depth);
  52629. }
  52630. Font font (depth * 0.6f);
  52631. font.setUnderline (button.hasKeyboardFocus (false));
  52632. GlyphArrangement textLayout;
  52633. textLayout.addFittedText (font, text.trim(),
  52634. 0.0f, 0.0f, (float) length, (float) depth,
  52635. Justification::centred,
  52636. jmax (1, depth / 12));
  52637. AffineTransform transform;
  52638. if (orientation == TabbedButtonBar::TabsAtLeft)
  52639. {
  52640. transform = transform.rotated (float_Pi * -0.5f)
  52641. .translated ((float) x, (float) (y + h));
  52642. }
  52643. else if (orientation == TabbedButtonBar::TabsAtRight)
  52644. {
  52645. transform = transform.rotated (float_Pi * 0.5f)
  52646. .translated ((float) (x + w), (float) y);
  52647. }
  52648. else
  52649. {
  52650. transform = transform.translated ((float) x, (float) y);
  52651. }
  52652. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  52653. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  52654. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  52655. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  52656. else
  52657. g.setColour (preferredBackgroundColour.contrasting());
  52658. if (! (isMouseOver || isMouseDown))
  52659. g.setOpacity (0.8f);
  52660. if (! button.isEnabled())
  52661. g.setOpacity (0.3f);
  52662. textLayout.draw (g, transform);
  52663. }
  52664. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  52665. const String& text,
  52666. int tabDepth,
  52667. Button&)
  52668. {
  52669. Font f (tabDepth * 0.6f);
  52670. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  52671. }
  52672. void LookAndFeel::drawTabButton (Graphics& g,
  52673. int w, int h,
  52674. const Colour& preferredColour,
  52675. int tabIndex,
  52676. const String& text,
  52677. Button& button,
  52678. TabbedButtonBar::Orientation orientation,
  52679. const bool isMouseOver,
  52680. const bool isMouseDown,
  52681. const bool isFrontTab)
  52682. {
  52683. int length = w;
  52684. int depth = h;
  52685. if (orientation == TabbedButtonBar::TabsAtLeft
  52686. || orientation == TabbedButtonBar::TabsAtRight)
  52687. {
  52688. swapVariables (length, depth);
  52689. }
  52690. Path tabShape;
  52691. createTabButtonShape (tabShape, w, h,
  52692. tabIndex, text, button, orientation,
  52693. isMouseOver, isMouseDown, isFrontTab);
  52694. fillTabButtonShape (g, tabShape, preferredColour,
  52695. tabIndex, text, button, orientation,
  52696. isMouseOver, isMouseDown, isFrontTab);
  52697. const int indent = getTabButtonOverlap (depth);
  52698. int x = 0, y = 0;
  52699. if (orientation == TabbedButtonBar::TabsAtLeft
  52700. || orientation == TabbedButtonBar::TabsAtRight)
  52701. {
  52702. y += indent;
  52703. h -= indent * 2;
  52704. }
  52705. else
  52706. {
  52707. x += indent;
  52708. w -= indent * 2;
  52709. }
  52710. drawTabButtonText (g, x, y, w, h, preferredColour,
  52711. tabIndex, text, button, orientation,
  52712. isMouseOver, isMouseDown, isFrontTab);
  52713. }
  52714. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  52715. int w, int h,
  52716. TabbedButtonBar& tabBar,
  52717. TabbedButtonBar::Orientation orientation)
  52718. {
  52719. const float shadowSize = 0.2f;
  52720. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  52721. Rectangle<int> shadowRect;
  52722. if (orientation == TabbedButtonBar::TabsAtLeft)
  52723. {
  52724. x1 = (float) w;
  52725. x2 = w * (1.0f - shadowSize);
  52726. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  52727. }
  52728. else if (orientation == TabbedButtonBar::TabsAtRight)
  52729. {
  52730. x2 = w * shadowSize;
  52731. shadowRect.setBounds (0, 0, (int) x2, h);
  52732. }
  52733. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52734. {
  52735. y2 = h * shadowSize;
  52736. shadowRect.setBounds (0, 0, w, (int) y2);
  52737. }
  52738. else
  52739. {
  52740. y1 = (float) h;
  52741. y2 = h * (1.0f - shadowSize);
  52742. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  52743. }
  52744. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  52745. Colours::transparentBlack, x2, y2, false));
  52746. shadowRect.expand (2, 2);
  52747. g.fillRect (shadowRect);
  52748. g.setColour (Colour (0x80000000));
  52749. if (orientation == TabbedButtonBar::TabsAtLeft)
  52750. {
  52751. g.fillRect (w - 1, 0, 1, h);
  52752. }
  52753. else if (orientation == TabbedButtonBar::TabsAtRight)
  52754. {
  52755. g.fillRect (0, 0, 1, h);
  52756. }
  52757. else if (orientation == TabbedButtonBar::TabsAtBottom)
  52758. {
  52759. g.fillRect (0, 0, w, 1);
  52760. }
  52761. else
  52762. {
  52763. g.fillRect (0, h - 1, w, 1);
  52764. }
  52765. }
  52766. Button* LookAndFeel::createTabBarExtrasButton()
  52767. {
  52768. const float thickness = 7.0f;
  52769. const float indent = 22.0f;
  52770. Path p;
  52771. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  52772. DrawablePath ellipse;
  52773. ellipse.setPath (p);
  52774. ellipse.setFill (Colour (0x99ffffff));
  52775. p.clear();
  52776. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  52777. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  52778. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  52779. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  52780. p.setUsingNonZeroWinding (false);
  52781. DrawablePath dp;
  52782. dp.setPath (p);
  52783. dp.setFill (Colour (0x59000000));
  52784. DrawableComposite normalImage;
  52785. normalImage.insertDrawable (ellipse);
  52786. normalImage.insertDrawable (dp);
  52787. dp.setFill (Colour (0xcc000000));
  52788. DrawableComposite overImage;
  52789. overImage.insertDrawable (ellipse);
  52790. overImage.insertDrawable (dp);
  52791. DrawableButton* db = new DrawableButton ("tabs", DrawableButton::ImageFitted);
  52792. db->setImages (&normalImage, &overImage, 0);
  52793. return db;
  52794. }
  52795. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  52796. {
  52797. g.fillAll (Colours::white);
  52798. const int w = header.getWidth();
  52799. const int h = header.getHeight();
  52800. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  52801. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  52802. false));
  52803. g.fillRect (0, h / 2, w, h);
  52804. g.setColour (Colour (0x33000000));
  52805. g.fillRect (0, h - 1, w, 1);
  52806. for (int i = header.getNumColumns (true); --i >= 0;)
  52807. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  52808. }
  52809. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  52810. int width, int height,
  52811. bool isMouseOver, bool isMouseDown,
  52812. int columnFlags)
  52813. {
  52814. if (isMouseDown)
  52815. g.fillAll (Colour (0x8899aadd));
  52816. else if (isMouseOver)
  52817. g.fillAll (Colour (0x5599aadd));
  52818. int rightOfText = width - 4;
  52819. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  52820. {
  52821. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  52822. const float bottom = height - top;
  52823. const float w = height * 0.5f;
  52824. const float x = rightOfText - (w * 1.25f);
  52825. rightOfText = (int) x;
  52826. Path sortArrow;
  52827. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  52828. g.setColour (Colour (0x99000000));
  52829. g.fillPath (sortArrow);
  52830. }
  52831. g.setColour (Colours::black);
  52832. g.setFont (height * 0.5f, Font::bold);
  52833. const int textX = 4;
  52834. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  52835. }
  52836. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  52837. {
  52838. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  52839. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  52840. background.darker (0.1f),
  52841. toolbar.isVertical() ? w - 1.0f : 0.0f,
  52842. toolbar.isVertical() ? 0.0f : h - 1.0f,
  52843. false));
  52844. g.fillAll();
  52845. }
  52846. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  52847. {
  52848. return createTabBarExtrasButton();
  52849. }
  52850. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  52851. bool isMouseOver, bool isMouseDown,
  52852. ToolbarItemComponent& component)
  52853. {
  52854. if (isMouseDown)
  52855. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  52856. else if (isMouseOver)
  52857. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  52858. }
  52859. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  52860. const String& text, ToolbarItemComponent& component)
  52861. {
  52862. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  52863. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  52864. const float fontHeight = jmin (14.0f, height * 0.85f);
  52865. g.setFont (fontHeight);
  52866. g.drawFittedText (text,
  52867. x, y, width, height,
  52868. Justification::centred,
  52869. jmax (1, height / (int) fontHeight));
  52870. }
  52871. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  52872. bool isOpen, int width, int height)
  52873. {
  52874. const int buttonSize = (height * 3) / 4;
  52875. const int buttonIndent = (height - buttonSize) / 2;
  52876. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  52877. const int textX = buttonIndent * 2 + buttonSize + 2;
  52878. g.setColour (Colours::black);
  52879. g.setFont (height * 0.7f, Font::bold);
  52880. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  52881. }
  52882. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  52883. PropertyComponent&)
  52884. {
  52885. g.setColour (Colour (0x66ffffff));
  52886. g.fillRect (0, 0, width, height - 1);
  52887. }
  52888. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  52889. PropertyComponent& component)
  52890. {
  52891. g.setColour (Colours::black);
  52892. if (! component.isEnabled())
  52893. g.setOpacity (0.6f);
  52894. g.setFont (jmin (height, 24) * 0.65f);
  52895. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  52896. g.drawFittedText (component.getName(),
  52897. 3, r.getY(), r.getX() - 5, r.getHeight(),
  52898. Justification::centredLeft, 2);
  52899. }
  52900. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  52901. {
  52902. return Rectangle<int> (component.getWidth() / 3, 1,
  52903. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  52904. }
  52905. void LookAndFeel::createFileChooserHeaderText (const String& title,
  52906. const String& instructions,
  52907. GlyphArrangement& text,
  52908. int width)
  52909. {
  52910. text.clear();
  52911. text.addJustifiedText (Font (17.0f, Font::bold), title,
  52912. 8.0f, 22.0f, width - 16.0f,
  52913. Justification::centred);
  52914. text.addJustifiedText (Font (14.0f), instructions,
  52915. 8.0f, 24.0f + 16.0f, width - 16.0f,
  52916. Justification::centred);
  52917. }
  52918. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  52919. const String& filename, Image* icon,
  52920. const String& fileSizeDescription,
  52921. const String& fileTimeDescription,
  52922. const bool isDirectory,
  52923. const bool isItemSelected,
  52924. const int /*itemIndex*/)
  52925. {
  52926. if (isItemSelected)
  52927. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  52928. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  52929. g.setFont (height * 0.7f);
  52930. Image* im = icon;
  52931. Image* toRelease = 0;
  52932. if (im == 0)
  52933. {
  52934. toRelease = im = (isDirectory ? getDefaultFolderImage()
  52935. : getDefaultDocumentFileImage());
  52936. }
  52937. const int x = 32;
  52938. if (im != 0)
  52939. {
  52940. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  52941. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  52942. false);
  52943. ImageCache::release (toRelease);
  52944. }
  52945. if (width > 450 && ! isDirectory)
  52946. {
  52947. const int sizeX = roundToInt (width * 0.7f);
  52948. const int dateX = roundToInt (width * 0.8f);
  52949. g.drawFittedText (filename,
  52950. x, 0, sizeX - x, height,
  52951. Justification::centredLeft, 1);
  52952. g.setFont (height * 0.5f);
  52953. g.setColour (Colours::darkgrey);
  52954. if (! isDirectory)
  52955. {
  52956. g.drawFittedText (fileSizeDescription,
  52957. sizeX, 0, dateX - sizeX - 8, height,
  52958. Justification::centredRight, 1);
  52959. g.drawFittedText (fileTimeDescription,
  52960. dateX, 0, width - 8 - dateX, height,
  52961. Justification::centredRight, 1);
  52962. }
  52963. }
  52964. else
  52965. {
  52966. g.drawFittedText (filename,
  52967. x, 0, width - x, height,
  52968. Justification::centredLeft, 1);
  52969. }
  52970. }
  52971. Button* LookAndFeel::createFileBrowserGoUpButton()
  52972. {
  52973. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  52974. Path arrowPath;
  52975. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  52976. DrawablePath arrowImage;
  52977. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  52978. arrowImage.setPath (arrowPath);
  52979. goUpButton->setImages (&arrowImage);
  52980. return goUpButton;
  52981. }
  52982. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  52983. DirectoryContentsDisplayComponent* fileListComponent,
  52984. FilePreviewComponent* previewComp,
  52985. ComboBox* currentPathBox,
  52986. TextEditor* filenameBox,
  52987. Button* goUpButton)
  52988. {
  52989. const int x = 8;
  52990. int w = browserComp.getWidth() - x - x;
  52991. if (previewComp != 0)
  52992. {
  52993. const int previewWidth = w / 3;
  52994. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  52995. w -= previewWidth + 4;
  52996. }
  52997. int y = 4;
  52998. const int controlsHeight = 22;
  52999. const int bottomSectionHeight = controlsHeight + 8;
  53000. const int upButtonWidth = 50;
  53001. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53002. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53003. y += controlsHeight + 4;
  53004. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53005. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53006. y = listAsComp->getBottom() + 4;
  53007. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53008. }
  53009. Image* LookAndFeel::getDefaultFolderImage()
  53010. {
  53011. 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,
  53012. 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,
  53013. 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,
  53014. 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,
  53015. 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,
  53016. 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,
  53017. 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,
  53018. 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,
  53019. 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,
  53020. 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,
  53021. 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,
  53022. 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,
  53023. 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,
  53024. 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,
  53025. 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,
  53026. 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,
  53027. 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,
  53028. 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,
  53029. 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,
  53030. 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,
  53031. 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,
  53032. 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,
  53033. 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,
  53034. 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,
  53035. 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,
  53036. 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,
  53037. 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,
  53038. 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,
  53039. 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,
  53040. 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,
  53041. 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,
  53042. 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,
  53043. 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,
  53044. 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,
  53045. 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,
  53046. 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,
  53047. 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,
  53048. 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,
  53049. 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,
  53050. 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,
  53051. 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,
  53052. 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,
  53053. 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,
  53054. 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};
  53055. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53056. }
  53057. Image* LookAndFeel::getDefaultDocumentFileImage()
  53058. {
  53059. 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,
  53060. 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,
  53061. 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,
  53062. 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,
  53063. 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,
  53064. 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,
  53065. 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,
  53066. 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,
  53067. 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,
  53068. 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,
  53069. 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,
  53070. 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,
  53071. 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,
  53072. 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,
  53073. 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,
  53074. 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,
  53075. 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,
  53076. 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,
  53077. 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,
  53078. 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,
  53079. 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,
  53080. 174,66,96,130,0,0};
  53081. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53082. }
  53083. void LookAndFeel::playAlertSound()
  53084. {
  53085. PlatformUtilities::beep();
  53086. }
  53087. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53088. {
  53089. g.setColour (Colours::white.withAlpha (0.7f));
  53090. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53091. g.setColour (Colours::black.withAlpha (0.2f));
  53092. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53093. const int totalBlocks = 7;
  53094. const int numBlocks = roundToInt (totalBlocks * level);
  53095. const float w = (width - 6.0f) / (float) totalBlocks;
  53096. for (int i = 0; i < totalBlocks; ++i)
  53097. {
  53098. if (i >= numBlocks)
  53099. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53100. else
  53101. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53102. : Colours::red);
  53103. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53104. }
  53105. }
  53106. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53107. {
  53108. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53109. if (keyDescription.isNotEmpty())
  53110. {
  53111. if (button.isEnabled())
  53112. {
  53113. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53114. g.fillAll (textColour.withAlpha (alpha));
  53115. g.setOpacity (0.3f);
  53116. g.drawBevel (0, 0, width, height, 2);
  53117. }
  53118. g.setColour (textColour);
  53119. g.setFont (height * 0.6f);
  53120. g.drawFittedText (keyDescription,
  53121. 3, 0, width - 6, height,
  53122. Justification::centred, 1);
  53123. }
  53124. else
  53125. {
  53126. const float thickness = 7.0f;
  53127. const float indent = 22.0f;
  53128. Path p;
  53129. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53130. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53131. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53132. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53133. p.setUsingNonZeroWinding (false);
  53134. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53135. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53136. }
  53137. if (button.hasKeyboardFocus (false))
  53138. {
  53139. g.setColour (textColour.withAlpha (0.4f));
  53140. g.drawRect (0, 0, width, height);
  53141. }
  53142. }
  53143. static void createRoundedPath (Path& p,
  53144. const float x, const float y,
  53145. const float w, const float h,
  53146. const float cs,
  53147. const bool curveTopLeft, const bool curveTopRight,
  53148. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53149. {
  53150. const float cs2 = 2.0f * cs;
  53151. if (curveTopLeft)
  53152. {
  53153. p.startNewSubPath (x, y + cs);
  53154. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53155. }
  53156. else
  53157. {
  53158. p.startNewSubPath (x, y);
  53159. }
  53160. if (curveTopRight)
  53161. {
  53162. p.lineTo (x + w - cs, y);
  53163. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53164. }
  53165. else
  53166. {
  53167. p.lineTo (x + w, y);
  53168. }
  53169. if (curveBottomRight)
  53170. {
  53171. p.lineTo (x + w, y + h - cs);
  53172. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53173. }
  53174. else
  53175. {
  53176. p.lineTo (x + w, y + h);
  53177. }
  53178. if (curveBottomLeft)
  53179. {
  53180. p.lineTo (x + cs, y + h);
  53181. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53182. }
  53183. else
  53184. {
  53185. p.lineTo (x, y + h);
  53186. }
  53187. p.closeSubPath();
  53188. }
  53189. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53190. float x, float y, float w, float h,
  53191. float maxCornerSize,
  53192. const Colour& baseColour,
  53193. const float strokeWidth,
  53194. const bool flatOnLeft,
  53195. const bool flatOnRight,
  53196. const bool flatOnTop,
  53197. const bool flatOnBottom) throw()
  53198. {
  53199. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53200. return;
  53201. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53202. Path outline;
  53203. createRoundedPath (outline, x, y, w, h, cs,
  53204. ! (flatOnLeft || flatOnTop),
  53205. ! (flatOnRight || flatOnTop),
  53206. ! (flatOnLeft || flatOnBottom),
  53207. ! (flatOnRight || flatOnBottom));
  53208. ColourGradient cg (baseColour, 0.0f, y,
  53209. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53210. false);
  53211. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53212. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53213. g.setGradientFill (cg);
  53214. g.fillPath (outline);
  53215. g.setColour (Colour (0x80000000));
  53216. g.strokePath (outline, PathStrokeType (strokeWidth));
  53217. }
  53218. void LookAndFeel::drawGlassSphere (Graphics& g,
  53219. const float x, const float y,
  53220. const float diameter,
  53221. const Colour& colour,
  53222. const float outlineThickness) throw()
  53223. {
  53224. if (diameter <= outlineThickness)
  53225. return;
  53226. Path p;
  53227. p.addEllipse (x, y, diameter, diameter);
  53228. {
  53229. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53230. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53231. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53232. g.setGradientFill (cg);
  53233. g.fillPath (p);
  53234. }
  53235. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53236. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53237. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53238. ColourGradient cg (Colours::transparentBlack,
  53239. x + diameter * 0.5f, y + diameter * 0.5f,
  53240. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53241. x, y + diameter * 0.5f, true);
  53242. cg.addColour (0.7, Colours::transparentBlack);
  53243. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53244. g.setGradientFill (cg);
  53245. g.fillPath (p);
  53246. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53247. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53248. }
  53249. void LookAndFeel::drawGlassPointer (Graphics& g,
  53250. const float x, const float y,
  53251. const float diameter,
  53252. const Colour& colour, const float outlineThickness,
  53253. const int direction) throw()
  53254. {
  53255. if (diameter <= outlineThickness)
  53256. return;
  53257. Path p;
  53258. p.startNewSubPath (x + diameter * 0.5f, y);
  53259. p.lineTo (x + diameter, y + diameter * 0.6f);
  53260. p.lineTo (x + diameter, y + diameter);
  53261. p.lineTo (x, y + diameter);
  53262. p.lineTo (x, y + diameter * 0.6f);
  53263. p.closeSubPath();
  53264. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53265. {
  53266. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53267. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53268. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53269. g.setGradientFill (cg);
  53270. g.fillPath (p);
  53271. }
  53272. ColourGradient cg (Colours::transparentBlack,
  53273. x + diameter * 0.5f, y + diameter * 0.5f,
  53274. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53275. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53276. cg.addColour (0.5, Colours::transparentBlack);
  53277. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53278. g.setGradientFill (cg);
  53279. g.fillPath (p);
  53280. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53281. g.strokePath (p, PathStrokeType (outlineThickness));
  53282. }
  53283. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53284. const float x, const float y,
  53285. const float width, const float height,
  53286. const Colour& colour,
  53287. const float outlineThickness,
  53288. const float cornerSize,
  53289. const bool flatOnLeft,
  53290. const bool flatOnRight,
  53291. const bool flatOnTop,
  53292. const bool flatOnBottom) throw()
  53293. {
  53294. if (width <= outlineThickness || height <= outlineThickness)
  53295. return;
  53296. const int intX = (int) x;
  53297. const int intY = (int) y;
  53298. const int intW = (int) width;
  53299. const int intH = (int) height;
  53300. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53301. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53302. const int intEdge = (int) edgeBlurRadius;
  53303. Path outline;
  53304. createRoundedPath (outline, x, y, width, height, cs,
  53305. ! (flatOnLeft || flatOnTop),
  53306. ! (flatOnRight || flatOnTop),
  53307. ! (flatOnLeft || flatOnBottom),
  53308. ! (flatOnRight || flatOnBottom));
  53309. {
  53310. ColourGradient cg (colour.darker (0.2f), 0, y,
  53311. colour.darker (0.2f), 0, y + height, false);
  53312. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53313. cg.addColour (0.4, colour);
  53314. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53315. g.setGradientFill (cg);
  53316. g.fillPath (outline);
  53317. }
  53318. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53319. colour.darker (0.2f), x, y + height * 0.5f, true);
  53320. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53321. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53322. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53323. {
  53324. g.saveState();
  53325. g.setGradientFill (cg);
  53326. g.reduceClipRegion (intX, intY, intEdge, intH);
  53327. g.fillPath (outline);
  53328. g.restoreState();
  53329. }
  53330. if (! (flatOnRight || flatOnTop || flatOnBottom))
  53331. {
  53332. cg.x1 = x + width - edgeBlurRadius;
  53333. cg.x2 = x + width;
  53334. g.saveState();
  53335. g.setGradientFill (cg);
  53336. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  53337. g.fillPath (outline);
  53338. g.restoreState();
  53339. }
  53340. {
  53341. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  53342. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  53343. Path highlight;
  53344. createRoundedPath (highlight,
  53345. x + leftIndent,
  53346. y + cs * 0.1f,
  53347. width - (leftIndent + rightIndent),
  53348. height * 0.4f, cs * 0.4f,
  53349. ! (flatOnLeft || flatOnTop),
  53350. ! (flatOnRight || flatOnTop),
  53351. ! (flatOnLeft || flatOnBottom),
  53352. ! (flatOnRight || flatOnBottom));
  53353. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  53354. Colours::transparentWhite, 0, y + height * 0.4f, false));
  53355. g.fillPath (highlight);
  53356. }
  53357. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  53358. g.strokePath (outline, PathStrokeType (outlineThickness));
  53359. }
  53360. END_JUCE_NAMESPACE
  53361. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  53362. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53363. BEGIN_JUCE_NAMESPACE
  53364. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  53365. {
  53366. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  53367. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  53368. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  53369. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  53370. setColour (Slider::thumbColourId, Colours::white);
  53371. setColour (Slider::trackColourId, Colour (0x7f000000));
  53372. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  53373. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  53374. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  53375. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  53376. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  53377. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  53378. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  53379. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  53380. }
  53381. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  53382. {
  53383. }
  53384. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  53385. Button& button,
  53386. const Colour& backgroundColour,
  53387. bool isMouseOverButton,
  53388. bool isButtonDown)
  53389. {
  53390. const int width = button.getWidth();
  53391. const int height = button.getHeight();
  53392. const float indent = 2.0f;
  53393. const int cornerSize = jmin (roundToInt (width * 0.4f),
  53394. roundToInt (height * 0.4f));
  53395. Path p;
  53396. p.addRoundedRectangle (indent, indent,
  53397. width - indent * 2.0f,
  53398. height - indent * 2.0f,
  53399. (float) cornerSize);
  53400. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  53401. if (isMouseOverButton)
  53402. {
  53403. if (isButtonDown)
  53404. bc = bc.brighter();
  53405. else if (bc.getBrightness() > 0.5f)
  53406. bc = bc.darker (0.1f);
  53407. else
  53408. bc = bc.brighter (0.1f);
  53409. }
  53410. g.setColour (bc);
  53411. g.fillPath (p);
  53412. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  53413. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  53414. }
  53415. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  53416. Component& /*component*/,
  53417. float x, float y, float w, float h,
  53418. const bool ticked,
  53419. const bool isEnabled,
  53420. const bool /*isMouseOverButton*/,
  53421. const bool isButtonDown)
  53422. {
  53423. Path box;
  53424. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  53425. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  53426. : Colours::lightgrey.withAlpha (0.1f));
  53427. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  53428. g.fillPath (box, trans);
  53429. g.setColour (Colours::black.withAlpha (0.6f));
  53430. g.strokePath (box, PathStrokeType (0.9f), trans);
  53431. if (ticked)
  53432. {
  53433. Path tick;
  53434. tick.startNewSubPath (1.5f, 3.0f);
  53435. tick.lineTo (3.0f, 6.0f);
  53436. tick.lineTo (6.0f, 0.0f);
  53437. g.setColour (isEnabled ? Colours::black : Colours::grey);
  53438. g.strokePath (tick, PathStrokeType (2.5f), trans);
  53439. }
  53440. }
  53441. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  53442. ToggleButton& button,
  53443. bool isMouseOverButton,
  53444. bool isButtonDown)
  53445. {
  53446. if (button.hasKeyboardFocus (true))
  53447. {
  53448. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  53449. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  53450. }
  53451. const int tickWidth = jmin (20, button.getHeight() - 4);
  53452. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  53453. (float) tickWidth, (float) tickWidth,
  53454. button.getToggleState(),
  53455. button.isEnabled(),
  53456. isMouseOverButton,
  53457. isButtonDown);
  53458. g.setColour (button.findColour (ToggleButton::textColourId));
  53459. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  53460. if (! button.isEnabled())
  53461. g.setOpacity (0.5f);
  53462. const int textX = tickWidth + 5;
  53463. g.drawFittedText (button.getButtonText(),
  53464. textX, 4,
  53465. button.getWidth() - textX - 2, button.getHeight() - 8,
  53466. Justification::centredLeft, 10);
  53467. }
  53468. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  53469. int width, int height,
  53470. double progress, const String& textToShow)
  53471. {
  53472. if (progress < 0 || progress >= 1.0)
  53473. {
  53474. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  53475. }
  53476. else
  53477. {
  53478. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  53479. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  53480. g.fillAll (background);
  53481. g.setColour (foreground);
  53482. g.fillRect (1, 1,
  53483. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  53484. height - 2);
  53485. if (textToShow.isNotEmpty())
  53486. {
  53487. g.setColour (Colour::contrasting (background, foreground));
  53488. g.setFont (height * 0.6f);
  53489. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  53490. }
  53491. }
  53492. }
  53493. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  53494. ScrollBar& bar,
  53495. int width, int height,
  53496. int buttonDirection,
  53497. bool isScrollbarVertical,
  53498. bool isMouseOverButton,
  53499. bool isButtonDown)
  53500. {
  53501. if (isScrollbarVertical)
  53502. width -= 2;
  53503. else
  53504. height -= 2;
  53505. Path p;
  53506. if (buttonDirection == 0)
  53507. p.addTriangle (width * 0.5f, height * 0.2f,
  53508. width * 0.1f, height * 0.7f,
  53509. width * 0.9f, height * 0.7f);
  53510. else if (buttonDirection == 1)
  53511. p.addTriangle (width * 0.8f, height * 0.5f,
  53512. width * 0.3f, height * 0.1f,
  53513. width * 0.3f, height * 0.9f);
  53514. else if (buttonDirection == 2)
  53515. p.addTriangle (width * 0.5f, height * 0.8f,
  53516. width * 0.1f, height * 0.3f,
  53517. width * 0.9f, height * 0.3f);
  53518. else if (buttonDirection == 3)
  53519. p.addTriangle (width * 0.2f, height * 0.5f,
  53520. width * 0.7f, height * 0.1f,
  53521. width * 0.7f, height * 0.9f);
  53522. if (isButtonDown)
  53523. g.setColour (Colours::white);
  53524. else if (isMouseOverButton)
  53525. g.setColour (Colours::white.withAlpha (0.7f));
  53526. else
  53527. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  53528. g.fillPath (p);
  53529. g.setColour (Colours::black.withAlpha (0.5f));
  53530. g.strokePath (p, PathStrokeType (0.5f));
  53531. }
  53532. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  53533. ScrollBar& bar,
  53534. int x, int y,
  53535. int width, int height,
  53536. bool isScrollbarVertical,
  53537. int thumbStartPosition,
  53538. int thumbSize,
  53539. bool isMouseOver,
  53540. bool isMouseDown)
  53541. {
  53542. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  53543. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53544. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  53545. if (thumbSize > 0.0f)
  53546. {
  53547. Rectangle<int> thumb;
  53548. if (isScrollbarVertical)
  53549. {
  53550. width -= 2;
  53551. g.fillRect (x + roundToInt (width * 0.35f), y,
  53552. roundToInt (width * 0.3f), height);
  53553. thumb.setBounds (x + 1, thumbStartPosition,
  53554. width - 2, thumbSize);
  53555. }
  53556. else
  53557. {
  53558. height -= 2;
  53559. g.fillRect (x, y + roundToInt (height * 0.35f),
  53560. width, roundToInt (height * 0.3f));
  53561. thumb.setBounds (thumbStartPosition, y + 1,
  53562. thumbSize, height - 2);
  53563. }
  53564. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  53565. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  53566. g.fillRect (thumb);
  53567. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  53568. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  53569. if (thumbSize > 16)
  53570. {
  53571. for (int i = 3; --i >= 0;)
  53572. {
  53573. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  53574. g.setColour (Colours::black.withAlpha (0.15f));
  53575. if (isScrollbarVertical)
  53576. {
  53577. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  53578. g.setColour (Colours::white.withAlpha (0.15f));
  53579. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  53580. }
  53581. else
  53582. {
  53583. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  53584. g.setColour (Colours::white.withAlpha (0.15f));
  53585. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  53586. }
  53587. }
  53588. }
  53589. }
  53590. }
  53591. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  53592. {
  53593. return &scrollbarShadow;
  53594. }
  53595. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  53596. {
  53597. g.fillAll (findColour (PopupMenu::backgroundColourId));
  53598. g.setColour (Colours::black.withAlpha (0.6f));
  53599. g.drawRect (0, 0, width, height);
  53600. }
  53601. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  53602. bool, MenuBarComponent& menuBar)
  53603. {
  53604. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  53605. }
  53606. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  53607. {
  53608. if (textEditor.isEnabled())
  53609. {
  53610. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  53611. g.drawRect (0, 0, width, height);
  53612. }
  53613. }
  53614. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  53615. const bool isButtonDown,
  53616. int buttonX, int buttonY,
  53617. int buttonW, int buttonH,
  53618. ComboBox& box)
  53619. {
  53620. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  53621. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  53622. : ComboBox::backgroundColourId));
  53623. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  53624. g.setColour (box.findColour (ComboBox::outlineColourId));
  53625. g.drawRect (0, 0, width, height);
  53626. const float arrowX = 0.2f;
  53627. const float arrowH = 0.3f;
  53628. if (box.isEnabled())
  53629. {
  53630. Path p;
  53631. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  53632. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  53633. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  53634. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  53635. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  53636. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  53637. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  53638. : ComboBox::buttonColourId));
  53639. g.fillPath (p);
  53640. }
  53641. }
  53642. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  53643. {
  53644. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  53645. f.setHorizontalScale (0.9f);
  53646. return f;
  53647. }
  53648. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  53649. {
  53650. Path p;
  53651. p.addTriangle (x1, y1, x2, y2, x3, y3);
  53652. g.setColour (fill);
  53653. g.fillPath (p);
  53654. g.setColour (outline);
  53655. g.strokePath (p, PathStrokeType (0.3f));
  53656. }
  53657. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  53658. int x, int y,
  53659. int w, int h,
  53660. float sliderPos,
  53661. float minSliderPos,
  53662. float maxSliderPos,
  53663. const Slider::SliderStyle style,
  53664. Slider& slider)
  53665. {
  53666. g.fillAll (slider.findColour (Slider::backgroundColourId));
  53667. if (style == Slider::LinearBar)
  53668. {
  53669. g.setColour (slider.findColour (Slider::thumbColourId));
  53670. g.fillRect (x, y, (int) sliderPos - x, h);
  53671. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  53672. g.drawRect (x, y, (int) sliderPos - x, h);
  53673. }
  53674. else
  53675. {
  53676. g.setColour (slider.findColour (Slider::trackColourId)
  53677. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  53678. if (slider.isHorizontal())
  53679. {
  53680. g.fillRect (x, y + roundToInt (h * 0.6f),
  53681. w, roundToInt (h * 0.2f));
  53682. }
  53683. else
  53684. {
  53685. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  53686. jmin (4, roundToInt (w * 0.2f)), h);
  53687. }
  53688. float alpha = 0.35f;
  53689. if (slider.isEnabled())
  53690. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  53691. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  53692. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  53693. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  53694. {
  53695. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  53696. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  53697. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  53698. fill, outline);
  53699. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  53700. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  53701. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  53702. fill, outline);
  53703. }
  53704. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  53705. {
  53706. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53707. minSliderPos - 7.0f, y + h * 0.9f ,
  53708. minSliderPos, y + h * 0.9f,
  53709. fill, outline);
  53710. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  53711. maxSliderPos, y + h * 0.9f,
  53712. maxSliderPos + 7.0f, y + h * 0.9f,
  53713. fill, outline);
  53714. }
  53715. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  53716. {
  53717. drawTriangle (g, sliderPos, y + h * 0.9f,
  53718. sliderPos - 7.0f, y + h * 0.2f,
  53719. sliderPos + 7.0f, y + h * 0.2f,
  53720. fill, outline);
  53721. }
  53722. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  53723. {
  53724. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  53725. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  53726. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  53727. fill, outline);
  53728. }
  53729. }
  53730. }
  53731. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  53732. {
  53733. if (isIncrement)
  53734. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  53735. else
  53736. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  53737. }
  53738. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  53739. {
  53740. return &scrollbarShadow;
  53741. }
  53742. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  53743. {
  53744. return 8;
  53745. }
  53746. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  53747. int w, int h,
  53748. bool isMouseOver,
  53749. bool isMouseDragging)
  53750. {
  53751. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  53752. : Colours::darkgrey);
  53753. const float lineThickness = jmin (w, h) * 0.1f;
  53754. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  53755. {
  53756. g.drawLine (w * i,
  53757. h + 1.0f,
  53758. w + 1.0f,
  53759. h * i,
  53760. lineThickness);
  53761. }
  53762. }
  53763. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  53764. {
  53765. Path shape;
  53766. if (buttonType == DocumentWindow::closeButton)
  53767. {
  53768. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  53769. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  53770. ShapeButton* const b = new ShapeButton ("close",
  53771. Colour (0x7fff3333),
  53772. Colour (0xd7ff3333),
  53773. Colour (0xf7ff3333));
  53774. b->setShape (shape, true, true, true);
  53775. return b;
  53776. }
  53777. else if (buttonType == DocumentWindow::minimiseButton)
  53778. {
  53779. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53780. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  53781. DrawablePath dp;
  53782. dp.setPath (shape);
  53783. dp.setFill (Colours::black.withAlpha (0.3f));
  53784. b->setImages (&dp);
  53785. return b;
  53786. }
  53787. else if (buttonType == DocumentWindow::maximiseButton)
  53788. {
  53789. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  53790. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  53791. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  53792. DrawablePath dp;
  53793. dp.setPath (shape);
  53794. dp.setFill (Colours::black.withAlpha (0.3f));
  53795. b->setImages (&dp);
  53796. return b;
  53797. }
  53798. jassertfalse
  53799. return 0;
  53800. }
  53801. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53802. int titleBarX,
  53803. int titleBarY,
  53804. int titleBarW,
  53805. int titleBarH,
  53806. Button* minimiseButton,
  53807. Button* maximiseButton,
  53808. Button* closeButton,
  53809. bool positionTitleBarButtonsOnLeft)
  53810. {
  53811. titleBarY += titleBarH / 8;
  53812. titleBarH -= titleBarH / 4;
  53813. const int buttonW = titleBarH;
  53814. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53815. : titleBarX + titleBarW - buttonW - 4;
  53816. if (closeButton != 0)
  53817. {
  53818. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53819. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  53820. : -(buttonW + buttonW / 5);
  53821. }
  53822. if (positionTitleBarButtonsOnLeft)
  53823. swapVariables (minimiseButton, maximiseButton);
  53824. if (maximiseButton != 0)
  53825. {
  53826. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53827. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53828. }
  53829. if (minimiseButton != 0)
  53830. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  53831. }
  53832. END_JUCE_NAMESPACE
  53833. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  53834. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  53835. BEGIN_JUCE_NAMESPACE
  53836. class DummyMenuComponent : public Component
  53837. {
  53838. DummyMenuComponent (const DummyMenuComponent&);
  53839. DummyMenuComponent& operator= (const DummyMenuComponent&);
  53840. public:
  53841. DummyMenuComponent() {}
  53842. ~DummyMenuComponent() {}
  53843. void inputAttemptWhenModal()
  53844. {
  53845. exitModalState (0);
  53846. }
  53847. };
  53848. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  53849. : model (0),
  53850. itemUnderMouse (-1),
  53851. currentPopupIndex (-1),
  53852. indexToShowAgain (-1),
  53853. lastMouseX (0),
  53854. lastMouseY (0),
  53855. inModalState (false)
  53856. {
  53857. setRepaintsOnMouseActivity (true);
  53858. setWantsKeyboardFocus (false);
  53859. setMouseClickGrabsKeyboardFocus (false);
  53860. setModel (model_);
  53861. }
  53862. MenuBarComponent::~MenuBarComponent()
  53863. {
  53864. setModel (0);
  53865. Desktop::getInstance().removeGlobalMouseListener (this);
  53866. currentPopup = 0;
  53867. }
  53868. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  53869. {
  53870. if (model != newModel)
  53871. {
  53872. if (model != 0)
  53873. model->removeListener (this);
  53874. model = newModel;
  53875. if (model != 0)
  53876. model->addListener (this);
  53877. repaint();
  53878. menuBarItemsChanged (0);
  53879. }
  53880. }
  53881. void MenuBarComponent::paint (Graphics& g)
  53882. {
  53883. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  53884. getLookAndFeel().drawMenuBarBackground (g,
  53885. getWidth(),
  53886. getHeight(),
  53887. isMouseOverBar,
  53888. *this);
  53889. if (model != 0)
  53890. {
  53891. for (int i = 0; i < menuNames.size(); ++i)
  53892. {
  53893. g.saveState();
  53894. g.setOrigin (xPositions [i], 0);
  53895. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  53896. getLookAndFeel().drawMenuBarItem (g,
  53897. xPositions[i + 1] - xPositions[i],
  53898. getHeight(),
  53899. i,
  53900. menuNames[i],
  53901. i == itemUnderMouse,
  53902. i == currentPopupIndex,
  53903. isMouseOverBar,
  53904. *this);
  53905. g.restoreState();
  53906. }
  53907. }
  53908. }
  53909. void MenuBarComponent::resized()
  53910. {
  53911. xPositions.clear();
  53912. int x = 2;
  53913. xPositions.add (x);
  53914. for (int i = 0; i < menuNames.size(); ++i)
  53915. {
  53916. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  53917. xPositions.add (x);
  53918. }
  53919. }
  53920. int MenuBarComponent::getItemAt (const int x, const int y)
  53921. {
  53922. for (int i = 0; i < xPositions.size(); ++i)
  53923. if (x >= xPositions[i] && x < xPositions[i + 1])
  53924. return reallyContains (x, y, true) ? i : -1;
  53925. return -1;
  53926. }
  53927. void MenuBarComponent::repaintMenuItem (int index)
  53928. {
  53929. if (((unsigned int) index) < (unsigned int) xPositions.size())
  53930. {
  53931. const int x1 = xPositions [index];
  53932. const int x2 = xPositions [index + 1];
  53933. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  53934. }
  53935. }
  53936. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  53937. {
  53938. const int newItem = getItemAt (x, y);
  53939. if (itemUnderMouse != newItem)
  53940. {
  53941. repaintMenuItem (itemUnderMouse);
  53942. itemUnderMouse = newItem;
  53943. repaintMenuItem (itemUnderMouse);
  53944. }
  53945. }
  53946. void MenuBarComponent::hideCurrentMenu()
  53947. {
  53948. currentPopup = 0;
  53949. repaint();
  53950. }
  53951. void MenuBarComponent::showMenu (int index)
  53952. {
  53953. if (index != currentPopupIndex)
  53954. {
  53955. if (inModalState)
  53956. {
  53957. hideCurrentMenu();
  53958. indexToShowAgain = index;
  53959. return;
  53960. }
  53961. indexToShowAgain = -1;
  53962. currentPopupIndex = -1;
  53963. itemUnderMouse = index;
  53964. currentPopup = 0;
  53965. menuBarItemsChanged (0);
  53966. Component::SafePointer<Component> prevFocused (getCurrentlyFocusedComponent());
  53967. Component::SafePointer<Component> deletionChecker (this);
  53968. enterModalState (false);
  53969. inModalState = true;
  53970. int result = 0;
  53971. ApplicationCommandManager* managerOfChosenCommand = 0;
  53972. Desktop::getInstance().addGlobalMouseListener (this);
  53973. for (;;)
  53974. {
  53975. const int x = getScreenX() + xPositions [itemUnderMouse];
  53976. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  53977. currentPopupIndex = itemUnderMouse;
  53978. indexToShowAgain = -1;
  53979. repaint();
  53980. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  53981. {
  53982. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  53983. menuNames [itemUnderMouse]));
  53984. if (m.lookAndFeel == 0)
  53985. m.setLookAndFeel (&getLookAndFeel());
  53986. currentPopup = m.createMenuComponent (x, getScreenY(),
  53987. w, getHeight(),
  53988. 0, w, 0, 0,
  53989. true, this,
  53990. &managerOfChosenCommand,
  53991. this);
  53992. }
  53993. if (currentPopup == 0)
  53994. {
  53995. currentPopup = new DummyMenuComponent();
  53996. addAndMakeVisible (currentPopup);
  53997. }
  53998. currentPopup->enterModalState (false);
  53999. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54000. // be stuck behind other comps that are already modal..
  54001. result = currentPopup->runModalLoop();
  54002. if (deletionChecker == 0)
  54003. return;
  54004. const int lastPopupIndex = currentPopupIndex;
  54005. currentPopup = 0;
  54006. currentPopupIndex = -1;
  54007. if (result != 0)
  54008. {
  54009. topLevelIndexClicked = lastPopupIndex;
  54010. break;
  54011. }
  54012. else if (indexToShowAgain >= 0)
  54013. {
  54014. menuBarItemsChanged (0);
  54015. repaint();
  54016. itemUnderMouse = indexToShowAgain;
  54017. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54018. break;
  54019. }
  54020. else
  54021. {
  54022. break;
  54023. }
  54024. }
  54025. Desktop::getInstance().removeGlobalMouseListener (this);
  54026. inModalState = false;
  54027. exitModalState (0);
  54028. if (prevFocused != 0)
  54029. prevFocused->grabKeyboardFocus();
  54030. const Point<int> mousePos (getMouseXYRelative());
  54031. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54032. repaint();
  54033. if (result != 0)
  54034. {
  54035. if (managerOfChosenCommand != 0)
  54036. {
  54037. ApplicationCommandTarget::InvocationInfo info (result);
  54038. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54039. managerOfChosenCommand->invoke (info, true);
  54040. }
  54041. postCommandMessage (result);
  54042. }
  54043. }
  54044. }
  54045. void MenuBarComponent::handleCommandMessage (int commandId)
  54046. {
  54047. if (model != 0)
  54048. model->menuItemSelected (commandId, topLevelIndexClicked);
  54049. }
  54050. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54051. {
  54052. if (e.eventComponent == this)
  54053. updateItemUnderMouse (e.x, e.y);
  54054. }
  54055. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54056. {
  54057. if (e.eventComponent == this)
  54058. updateItemUnderMouse (e.x, e.y);
  54059. }
  54060. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54061. {
  54062. if (currentPopupIndex < 0)
  54063. {
  54064. const MouseEvent e2 (e.getEventRelativeTo (this));
  54065. updateItemUnderMouse (e2.x, e2.y);
  54066. currentPopupIndex = -2;
  54067. showMenu (itemUnderMouse);
  54068. }
  54069. }
  54070. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54071. {
  54072. const MouseEvent e2 (e.getEventRelativeTo (this));
  54073. const int item = getItemAt (e2.x, e2.y);
  54074. if (item >= 0)
  54075. showMenu (item);
  54076. }
  54077. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54078. {
  54079. const MouseEvent e2 (e.getEventRelativeTo (this));
  54080. updateItemUnderMouse (e2.x, e2.y);
  54081. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> (static_cast <Component*> (currentPopup)) != 0)
  54082. hideCurrentMenu();
  54083. }
  54084. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54085. {
  54086. const MouseEvent e2 (e.getEventRelativeTo (this));
  54087. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54088. {
  54089. if (currentPopupIndex >= 0)
  54090. {
  54091. const int item = getItemAt (e2.x, e2.y);
  54092. if (item >= 0)
  54093. showMenu (item);
  54094. }
  54095. else
  54096. {
  54097. updateItemUnderMouse (e2.x, e2.y);
  54098. }
  54099. lastMouseX = e2.x;
  54100. lastMouseY = e2.y;
  54101. }
  54102. }
  54103. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54104. {
  54105. bool used = false;
  54106. const int numMenus = menuNames.size();
  54107. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54108. if (key.isKeyCode (KeyPress::leftKey))
  54109. {
  54110. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54111. used = true;
  54112. }
  54113. else if (key.isKeyCode (KeyPress::rightKey))
  54114. {
  54115. showMenu ((currentIndex + 1) % numMenus);
  54116. used = true;
  54117. }
  54118. return used;
  54119. }
  54120. void MenuBarComponent::inputAttemptWhenModal()
  54121. {
  54122. hideCurrentMenu();
  54123. }
  54124. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54125. {
  54126. StringArray newNames;
  54127. if (model != 0)
  54128. newNames = model->getMenuBarNames();
  54129. if (newNames != menuNames)
  54130. {
  54131. menuNames = newNames;
  54132. repaint();
  54133. resized();
  54134. }
  54135. }
  54136. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54137. const ApplicationCommandTarget::InvocationInfo& info)
  54138. {
  54139. if (model == 0
  54140. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54141. return;
  54142. for (int i = 0; i < menuNames.size(); ++i)
  54143. {
  54144. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54145. if (menu.containsCommandItem (info.commandID))
  54146. {
  54147. itemUnderMouse = i;
  54148. repaintMenuItem (i);
  54149. startTimer (200);
  54150. break;
  54151. }
  54152. }
  54153. }
  54154. void MenuBarComponent::timerCallback()
  54155. {
  54156. stopTimer();
  54157. const Point<int> mousePos (getMouseXYRelative());
  54158. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54159. }
  54160. END_JUCE_NAMESPACE
  54161. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54162. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54163. BEGIN_JUCE_NAMESPACE
  54164. MenuBarModel::MenuBarModel() throw()
  54165. : manager (0)
  54166. {
  54167. }
  54168. MenuBarModel::~MenuBarModel()
  54169. {
  54170. setApplicationCommandManagerToWatch (0);
  54171. }
  54172. void MenuBarModel::menuItemsChanged()
  54173. {
  54174. triggerAsyncUpdate();
  54175. }
  54176. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54177. {
  54178. if (manager != newManager)
  54179. {
  54180. if (manager != 0)
  54181. manager->removeListener (this);
  54182. manager = newManager;
  54183. if (manager != 0)
  54184. manager->addListener (this);
  54185. }
  54186. }
  54187. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54188. {
  54189. listeners.add (newListener);
  54190. }
  54191. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54192. {
  54193. // Trying to remove a listener that isn't on the list!
  54194. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54195. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54196. jassert (listeners.contains (listenerToRemove));
  54197. listeners.remove (listenerToRemove);
  54198. }
  54199. void MenuBarModel::handleAsyncUpdate()
  54200. {
  54201. listeners.call (&MenuBarModelListener::menuBarItemsChanged, this);
  54202. }
  54203. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54204. {
  54205. listeners.call (&MenuBarModelListener::menuCommandInvoked, this, info);
  54206. }
  54207. void MenuBarModel::applicationCommandListChanged()
  54208. {
  54209. menuItemsChanged();
  54210. }
  54211. END_JUCE_NAMESPACE
  54212. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54213. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54214. BEGIN_JUCE_NAMESPACE
  54215. class PopupMenu::Item
  54216. {
  54217. public:
  54218. Item()
  54219. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54220. usesColour (false), customComp (0), commandManager (0)
  54221. {
  54222. }
  54223. Item (const int itemId_,
  54224. const String& text_,
  54225. const bool active_,
  54226. const bool isTicked_,
  54227. const Image* im,
  54228. const Colour& textColour_,
  54229. const bool usesColour_,
  54230. PopupMenuCustomComponent* const customComp_,
  54231. const PopupMenu* const subMenu_,
  54232. ApplicationCommandManager* const commandManager_)
  54233. : itemId (itemId_), text (text_), textColour (textColour_),
  54234. active (active_), isSeparator (false), isTicked (isTicked_),
  54235. usesColour (usesColour_), customComp (customComp_),
  54236. commandManager (commandManager_)
  54237. {
  54238. if (subMenu_ != 0)
  54239. subMenu = new PopupMenu (*subMenu_);
  54240. if (im != 0)
  54241. image = im->createCopy();
  54242. if (commandManager_ != 0 && itemId_ != 0)
  54243. {
  54244. String shortcutKey;
  54245. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54246. ->getKeyPressesAssignedToCommand (itemId_));
  54247. for (int i = 0; i < keyPresses.size(); ++i)
  54248. {
  54249. const String key (keyPresses.getReference(i).getTextDescription());
  54250. if (shortcutKey.isNotEmpty())
  54251. shortcutKey << ", ";
  54252. if (key.length() == 1)
  54253. shortcutKey << "shortcut: '" << key << '\'';
  54254. else
  54255. shortcutKey << key;
  54256. }
  54257. shortcutKey = shortcutKey.trim();
  54258. if (shortcutKey.isNotEmpty())
  54259. text << "<end>" << shortcutKey;
  54260. }
  54261. }
  54262. Item (const Item& other)
  54263. : itemId (other.itemId),
  54264. text (other.text),
  54265. textColour (other.textColour),
  54266. active (other.active),
  54267. isSeparator (other.isSeparator),
  54268. isTicked (other.isTicked),
  54269. usesColour (other.usesColour),
  54270. customComp (other.customComp),
  54271. commandManager (other.commandManager)
  54272. {
  54273. if (other.subMenu != 0)
  54274. subMenu = new PopupMenu (*(other.subMenu));
  54275. if (other.image != 0)
  54276. image = other.image->createCopy();
  54277. }
  54278. ~Item()
  54279. {
  54280. customComp = 0;
  54281. }
  54282. bool canBeTriggered() const throw()
  54283. {
  54284. return active && ! (isSeparator || (subMenu != 0));
  54285. }
  54286. bool hasActiveSubMenu() const throw()
  54287. {
  54288. return active && (subMenu != 0);
  54289. }
  54290. const int itemId;
  54291. String text;
  54292. const Colour textColour;
  54293. const bool active, isSeparator, isTicked, usesColour;
  54294. ScopedPointer <Image> image;
  54295. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54296. ScopedPointer <PopupMenu> subMenu;
  54297. ApplicationCommandManager* const commandManager;
  54298. juce_UseDebuggingNewOperator
  54299. private:
  54300. Item& operator= (const Item&);
  54301. };
  54302. class PopupMenu::ItemComponent : public Component
  54303. {
  54304. public:
  54305. ItemComponent (const PopupMenu::Item& itemInfo_)
  54306. : itemInfo (itemInfo_),
  54307. isHighlighted (false)
  54308. {
  54309. if (itemInfo.customComp != 0)
  54310. addAndMakeVisible (itemInfo.customComp);
  54311. }
  54312. ~ItemComponent()
  54313. {
  54314. if (itemInfo.customComp != 0)
  54315. removeChildComponent (itemInfo.customComp);
  54316. }
  54317. void getIdealSize (int& idealWidth,
  54318. int& idealHeight,
  54319. const int standardItemHeight)
  54320. {
  54321. if (itemInfo.customComp != 0)
  54322. {
  54323. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  54324. }
  54325. else
  54326. {
  54327. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  54328. itemInfo.isSeparator,
  54329. standardItemHeight,
  54330. idealWidth,
  54331. idealHeight);
  54332. }
  54333. }
  54334. void paint (Graphics& g)
  54335. {
  54336. if (itemInfo.customComp == 0)
  54337. {
  54338. String mainText (itemInfo.text);
  54339. String endText;
  54340. const int endIndex = mainText.indexOf ("<end>");
  54341. if (endIndex >= 0)
  54342. {
  54343. endText = mainText.substring (endIndex + 5).trim();
  54344. mainText = mainText.substring (0, endIndex);
  54345. }
  54346. getLookAndFeel()
  54347. .drawPopupMenuItem (g, getWidth(), getHeight(),
  54348. itemInfo.isSeparator,
  54349. itemInfo.active,
  54350. isHighlighted,
  54351. itemInfo.isTicked,
  54352. itemInfo.subMenu != 0,
  54353. mainText, endText,
  54354. itemInfo.image,
  54355. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  54356. }
  54357. }
  54358. void resized()
  54359. {
  54360. if (getNumChildComponents() > 0)
  54361. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  54362. }
  54363. void setHighlighted (bool shouldBeHighlighted)
  54364. {
  54365. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  54366. if (isHighlighted != shouldBeHighlighted)
  54367. {
  54368. isHighlighted = shouldBeHighlighted;
  54369. if (itemInfo.customComp != 0)
  54370. {
  54371. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  54372. itemInfo.customComp->repaint();
  54373. }
  54374. repaint();
  54375. }
  54376. }
  54377. PopupMenu::Item itemInfo;
  54378. juce_UseDebuggingNewOperator
  54379. private:
  54380. bool isHighlighted;
  54381. ItemComponent (const ItemComponent&);
  54382. ItemComponent& operator= (const ItemComponent&);
  54383. };
  54384. namespace PopupMenuSettings
  54385. {
  54386. static const int scrollZone = 24;
  54387. static const int borderSize = 2;
  54388. static const int timerInterval = 50;
  54389. static const int dismissCommandId = 0x6287345f;
  54390. }
  54391. class PopupMenu::Window : public Component,
  54392. private Timer
  54393. {
  54394. public:
  54395. Window()
  54396. : Component ("menu"),
  54397. owner (0),
  54398. currentChild (0),
  54399. activeSubMenu (0),
  54400. menuBarComponent (0),
  54401. managerOfChosenCommand (0),
  54402. minimumWidth (0),
  54403. maximumNumColumns (7),
  54404. standardItemHeight (0),
  54405. isOver (false),
  54406. hasBeenOver (false),
  54407. isDown (false),
  54408. needsToScroll (false),
  54409. hideOnExit (false),
  54410. disableMouseMoves (false),
  54411. hasAnyJuceCompHadFocus (false),
  54412. numColumns (0),
  54413. contentHeight (0),
  54414. childYOffset (0),
  54415. timeEnteredCurrentChildComp (0),
  54416. scrollAcceleration (1.0)
  54417. {
  54418. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  54419. setWantsKeyboardFocus (true);
  54420. setMouseClickGrabsKeyboardFocus (false);
  54421. setOpaque (true);
  54422. setAlwaysOnTop (true);
  54423. Desktop::getInstance().addGlobalMouseListener (this);
  54424. getActiveWindows().add (this);
  54425. }
  54426. ~Window()
  54427. {
  54428. getActiveWindows().removeValue (this);
  54429. Desktop::getInstance().removeGlobalMouseListener (this);
  54430. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54431. activeSubMenu = 0;
  54432. deleteAllChildren();
  54433. }
  54434. static Window* create (const PopupMenu& menu,
  54435. const bool dismissOnMouseUp,
  54436. Window* const owner_,
  54437. const int minX, const int maxX,
  54438. const int minY, const int maxY,
  54439. const int minimumWidth,
  54440. const int maximumNumColumns,
  54441. const int standardItemHeight,
  54442. const bool alignToRectangle,
  54443. const int itemIdThatMustBeVisible,
  54444. Component* const menuBarComponent,
  54445. ApplicationCommandManager** managerOfChosenCommand,
  54446. Component* const componentAttachedTo)
  54447. {
  54448. if (menu.items.size() > 0)
  54449. {
  54450. int totalItems = 0;
  54451. ScopedPointer <Window> mw (new Window());
  54452. mw->setLookAndFeel (menu.lookAndFeel);
  54453. mw->setWantsKeyboardFocus (false);
  54454. mw->minimumWidth = minimumWidth;
  54455. mw->maximumNumColumns = maximumNumColumns;
  54456. mw->standardItemHeight = standardItemHeight;
  54457. mw->dismissOnMouseUp = dismissOnMouseUp;
  54458. for (int i = 0; i < menu.items.size(); ++i)
  54459. {
  54460. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  54461. mw->addItem (*item);
  54462. ++totalItems;
  54463. }
  54464. if (totalItems > 0)
  54465. {
  54466. mw->owner = owner_;
  54467. mw->menuBarComponent = menuBarComponent;
  54468. mw->managerOfChosenCommand = managerOfChosenCommand;
  54469. mw->componentAttachedTo = componentAttachedTo;
  54470. mw->componentAttachedToOriginal = componentAttachedTo;
  54471. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  54472. mw->setTopLeftPosition (mw->windowPos.getX(),
  54473. mw->windowPos.getY());
  54474. mw->updateYPositions();
  54475. if (itemIdThatMustBeVisible != 0)
  54476. {
  54477. const int y = minY - mw->windowPos.getY();
  54478. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  54479. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  54480. }
  54481. mw->resizeToBestWindowPos();
  54482. mw->addToDesktop (ComponentPeer::windowIsTemporary
  54483. | mw->getLookAndFeel().getMenuWindowFlags());
  54484. return mw.release();
  54485. }
  54486. }
  54487. return 0;
  54488. }
  54489. void paint (Graphics& g)
  54490. {
  54491. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  54492. }
  54493. void paintOverChildren (Graphics& g)
  54494. {
  54495. if (isScrolling())
  54496. {
  54497. LookAndFeel& lf = getLookAndFeel();
  54498. if (isScrollZoneActive (false))
  54499. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  54500. if (isScrollZoneActive (true))
  54501. {
  54502. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  54503. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  54504. }
  54505. }
  54506. }
  54507. bool isScrollZoneActive (bool bottomOne) const
  54508. {
  54509. return isScrolling()
  54510. && (bottomOne
  54511. ? childYOffset < contentHeight - windowPos.getHeight()
  54512. : childYOffset > 0);
  54513. }
  54514. void addItem (const PopupMenu::Item& item)
  54515. {
  54516. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  54517. addAndMakeVisible (mic);
  54518. int itemW = 80;
  54519. int itemH = 16;
  54520. mic->getIdealSize (itemW, itemH, standardItemHeight);
  54521. mic->setSize (itemW, jlimit (2, 600, itemH));
  54522. mic->addMouseListener (this, false);
  54523. }
  54524. // hide this and all sub-comps
  54525. void hide (const PopupMenu::Item* const item)
  54526. {
  54527. if (isVisible())
  54528. {
  54529. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54530. activeSubMenu = 0;
  54531. currentChild = 0;
  54532. exitModalState (item != 0 ? item->itemId : 0);
  54533. setVisible (false);
  54534. if (item != 0
  54535. && item->commandManager != 0
  54536. && item->itemId != 0)
  54537. {
  54538. *managerOfChosenCommand = item->commandManager;
  54539. }
  54540. }
  54541. }
  54542. void dismissMenu (const PopupMenu::Item* const item)
  54543. {
  54544. if (owner != 0)
  54545. {
  54546. owner->dismissMenu (item);
  54547. }
  54548. else
  54549. {
  54550. if (item != 0)
  54551. {
  54552. // need a copy of this on the stack as the one passed in will get deleted during this call
  54553. const PopupMenu::Item mi (*item);
  54554. hide (&mi);
  54555. }
  54556. else
  54557. {
  54558. hide (0);
  54559. }
  54560. }
  54561. }
  54562. void mouseMove (const MouseEvent&)
  54563. {
  54564. timerCallback();
  54565. }
  54566. void mouseDown (const MouseEvent&)
  54567. {
  54568. timerCallback();
  54569. }
  54570. void mouseDrag (const MouseEvent&)
  54571. {
  54572. timerCallback();
  54573. }
  54574. void mouseUp (const MouseEvent&)
  54575. {
  54576. timerCallback();
  54577. }
  54578. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  54579. {
  54580. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  54581. lastMouse = Point<int> (-1, -1);
  54582. }
  54583. bool keyPressed (const KeyPress& key)
  54584. {
  54585. if (key.isKeyCode (KeyPress::downKey))
  54586. {
  54587. selectNextItem (1);
  54588. }
  54589. else if (key.isKeyCode (KeyPress::upKey))
  54590. {
  54591. selectNextItem (-1);
  54592. }
  54593. else if (key.isKeyCode (KeyPress::leftKey))
  54594. {
  54595. if (owner != 0)
  54596. {
  54597. Component::SafePointer<Window> parentWindow (owner);
  54598. PopupMenu::ItemComponent* currentChildOfParent = parentWindow->currentChild;
  54599. hide (0);
  54600. if (parentWindow != 0)
  54601. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  54602. disableTimerUntilMouseMoves();
  54603. }
  54604. else if (menuBarComponent != 0)
  54605. {
  54606. menuBarComponent->keyPressed (key);
  54607. }
  54608. }
  54609. else if (key.isKeyCode (KeyPress::rightKey))
  54610. {
  54611. disableTimerUntilMouseMoves();
  54612. if (showSubMenuFor (currentChild))
  54613. {
  54614. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54615. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  54616. activeSubMenu->selectNextItem (1);
  54617. }
  54618. else if (menuBarComponent != 0)
  54619. {
  54620. menuBarComponent->keyPressed (key);
  54621. }
  54622. }
  54623. else if (key.isKeyCode (KeyPress::returnKey))
  54624. {
  54625. triggerCurrentlyHighlightedItem();
  54626. }
  54627. else if (key.isKeyCode (KeyPress::escapeKey))
  54628. {
  54629. dismissMenu (0);
  54630. }
  54631. else
  54632. {
  54633. return false;
  54634. }
  54635. return true;
  54636. }
  54637. void inputAttemptWhenModal()
  54638. {
  54639. timerCallback();
  54640. if (! isOverAnyMenu())
  54641. {
  54642. if (componentAttachedTo != 0)
  54643. {
  54644. // we want to dismiss the menu, but if we do it synchronously, then
  54645. // the mouse-click will be allowed to pass through. That's good, except
  54646. // when the user clicks on the button that orginally popped the menu up,
  54647. // as they'll expect the menu to go away, and in fact it'll just
  54648. // come back. So only dismiss synchronously if they're not on the original
  54649. // comp that we're attached to.
  54650. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  54651. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  54652. {
  54653. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  54654. return;
  54655. }
  54656. }
  54657. dismissMenu (0);
  54658. }
  54659. }
  54660. void handleCommandMessage (int commandId)
  54661. {
  54662. Component::handleCommandMessage (commandId);
  54663. if (commandId == PopupMenuSettings::dismissCommandId)
  54664. dismissMenu (0);
  54665. }
  54666. void timerCallback()
  54667. {
  54668. if (! isVisible())
  54669. return;
  54670. if (componentAttachedTo != componentAttachedToOriginal)
  54671. {
  54672. dismissMenu (0);
  54673. return;
  54674. }
  54675. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  54676. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  54677. return;
  54678. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  54679. // move rather than a real timer callback
  54680. const Point<int> globalMousePos (Desktop::getMousePosition());
  54681. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  54682. const uint32 now = Time::getMillisecondCounter();
  54683. if (now > timeEnteredCurrentChildComp + 100
  54684. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  54685. && currentChild->isValidComponent()
  54686. && (! disableMouseMoves)
  54687. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  54688. {
  54689. showSubMenuFor (currentChild);
  54690. }
  54691. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  54692. {
  54693. highlightItemUnderMouse (globalMousePos, localMousePos);
  54694. }
  54695. bool overScrollArea = false;
  54696. if (isScrolling()
  54697. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  54698. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  54699. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  54700. {
  54701. if (now > lastScroll + 20)
  54702. {
  54703. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  54704. int amount = 0;
  54705. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  54706. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  54707. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  54708. lastScroll = now;
  54709. }
  54710. overScrollArea = true;
  54711. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  54712. }
  54713. else
  54714. {
  54715. scrollAcceleration = 1.0;
  54716. }
  54717. const bool wasDown = isDown;
  54718. bool isOverAny = isOverAnyMenu();
  54719. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  54720. {
  54721. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54722. isOverAny = isOverAnyMenu();
  54723. }
  54724. if (hideOnExit && hasBeenOver && ! isOverAny)
  54725. {
  54726. hide (0);
  54727. }
  54728. else
  54729. {
  54730. isDown = hasBeenOver
  54731. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  54732. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  54733. bool anyFocused = Process::isForegroundProcess();
  54734. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  54735. {
  54736. // because no component at all may have focus, our test here will
  54737. // only be triggered when something has focus and then loses it.
  54738. anyFocused = ! hasAnyJuceCompHadFocus;
  54739. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  54740. {
  54741. if (ComponentPeer::getPeer (i)->isFocused())
  54742. {
  54743. anyFocused = true;
  54744. hasAnyJuceCompHadFocus = true;
  54745. break;
  54746. }
  54747. }
  54748. }
  54749. if (! anyFocused)
  54750. {
  54751. if (now > lastFocused + 10)
  54752. {
  54753. wasHiddenBecauseOfAppChange() = true;
  54754. dismissMenu (0);
  54755. return; // may have been deleted by the previous call..
  54756. }
  54757. }
  54758. else if (wasDown && now > menuCreationTime + 250
  54759. && ! (isDown || overScrollArea))
  54760. {
  54761. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  54762. if (isOver)
  54763. {
  54764. triggerCurrentlyHighlightedItem();
  54765. }
  54766. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  54767. {
  54768. dismissMenu (0);
  54769. }
  54770. return; // may have been deleted by the previous calls..
  54771. }
  54772. else
  54773. {
  54774. lastFocused = now;
  54775. }
  54776. }
  54777. }
  54778. static Array<Window*>& getActiveWindows()
  54779. {
  54780. static Array<Window*> activeMenuWindows;
  54781. return activeMenuWindows;
  54782. }
  54783. static bool& wasHiddenBecauseOfAppChange() throw()
  54784. {
  54785. static bool b = false;
  54786. return b;
  54787. }
  54788. juce_UseDebuggingNewOperator
  54789. private:
  54790. Window* owner;
  54791. PopupMenu::ItemComponent* currentChild;
  54792. ScopedPointer <Window> activeSubMenu;
  54793. Component* menuBarComponent;
  54794. ApplicationCommandManager** managerOfChosenCommand;
  54795. Component::SafePointer<Component> componentAttachedTo;
  54796. Component* componentAttachedToOriginal;
  54797. Rectangle<int> windowPos;
  54798. Point<int> lastMouse;
  54799. int minimumWidth, maximumNumColumns, standardItemHeight;
  54800. bool isOver, hasBeenOver, isDown, needsToScroll;
  54801. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  54802. int numColumns, contentHeight, childYOffset;
  54803. Array <int> columnWidths;
  54804. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  54805. double scrollAcceleration;
  54806. bool overlaps (const Rectangle<int>& r) const
  54807. {
  54808. return r.intersects (getBounds())
  54809. || (owner != 0 && owner->overlaps (r));
  54810. }
  54811. bool isOverAnyMenu() const
  54812. {
  54813. return (owner != 0) ? owner->isOverAnyMenu()
  54814. : isOverChildren();
  54815. }
  54816. bool isOverChildren() const
  54817. {
  54818. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  54819. return isVisible()
  54820. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  54821. }
  54822. void updateMouseOverStatus (const Point<int>& globalMousePos)
  54823. {
  54824. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  54825. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  54826. if (activeSubMenu != 0)
  54827. activeSubMenu->updateMouseOverStatus (globalMousePos);
  54828. }
  54829. bool treeContains (const Window* const window) const throw()
  54830. {
  54831. const Window* mw = this;
  54832. while (mw->owner != 0)
  54833. mw = mw->owner;
  54834. while (mw != 0)
  54835. {
  54836. if (mw == window)
  54837. return true;
  54838. mw = mw->activeSubMenu;
  54839. }
  54840. return false;
  54841. }
  54842. void calculateWindowPos (const int minX, const int maxX,
  54843. const int minY, const int maxY,
  54844. const bool alignToRectangle)
  54845. {
  54846. const Rectangle<int> mon (Desktop::getInstance()
  54847. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  54848. (minY + maxY) / 2),
  54849. #if JUCE_MAC
  54850. true));
  54851. #else
  54852. false)); // on windows, don't stop the menu overlapping the taskbar
  54853. #endif
  54854. int x, y, widthToUse, heightToUse;
  54855. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  54856. if (alignToRectangle)
  54857. {
  54858. x = minX;
  54859. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  54860. const int spaceOver = minY - mon.getY();
  54861. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  54862. y = maxY;
  54863. else
  54864. y = minY - heightToUse;
  54865. }
  54866. else
  54867. {
  54868. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  54869. if (owner != 0)
  54870. {
  54871. if (owner->owner != 0)
  54872. {
  54873. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  54874. > owner->owner->getX() + owner->owner->getWidth() / 2);
  54875. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  54876. tendTowardsRight = true;
  54877. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  54878. tendTowardsRight = false;
  54879. }
  54880. else if (maxX + widthToUse < mon.getRight() - 32)
  54881. {
  54882. tendTowardsRight = true;
  54883. }
  54884. }
  54885. const int biggestSpace = jmax (mon.getRight() - maxX,
  54886. minX - mon.getX()) - 32;
  54887. if (biggestSpace < widthToUse)
  54888. {
  54889. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  54890. if (numColumns > 1)
  54891. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  54892. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  54893. }
  54894. if (tendTowardsRight)
  54895. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  54896. else
  54897. x = jmax (mon.getX() + 4, minX - widthToUse);
  54898. y = minY;
  54899. if ((minY + maxY) / 2 > mon.getCentreY())
  54900. y = jmax (mon.getY(), maxY - heightToUse);
  54901. }
  54902. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  54903. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  54904. windowPos.setBounds (x, y, widthToUse, heightToUse);
  54905. // sets this flag if it's big enough to obscure any of its parent menus
  54906. hideOnExit = (owner != 0)
  54907. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  54908. }
  54909. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  54910. {
  54911. numColumns = 0;
  54912. contentHeight = 0;
  54913. const int maxMenuH = getParentHeight() - 24;
  54914. int totalW;
  54915. do
  54916. {
  54917. ++numColumns;
  54918. totalW = workOutBestSize (maxMenuW);
  54919. if (totalW > maxMenuW)
  54920. {
  54921. numColumns = jmax (1, numColumns - 1);
  54922. totalW = workOutBestSize (maxMenuW); // to update col widths
  54923. break;
  54924. }
  54925. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  54926. {
  54927. break;
  54928. }
  54929. } while (numColumns < maximumNumColumns);
  54930. const int actualH = jmin (contentHeight, maxMenuH);
  54931. needsToScroll = contentHeight > actualH;
  54932. width = updateYPositions();
  54933. height = actualH + PopupMenuSettings::borderSize * 2;
  54934. }
  54935. int workOutBestSize (const int maxMenuW)
  54936. {
  54937. int totalW = 0;
  54938. contentHeight = 0;
  54939. int childNum = 0;
  54940. for (int col = 0; col < numColumns; ++col)
  54941. {
  54942. int i, colW = 50, colH = 0;
  54943. const int numChildren = jmin (getNumChildComponents() - childNum,
  54944. (getNumChildComponents() + numColumns - 1) / numColumns);
  54945. for (i = numChildren; --i >= 0;)
  54946. {
  54947. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  54948. colH += getChildComponent (childNum + i)->getHeight();
  54949. }
  54950. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  54951. columnWidths.set (col, colW);
  54952. totalW += colW;
  54953. contentHeight = jmax (contentHeight, colH);
  54954. childNum += numChildren;
  54955. }
  54956. if (totalW < minimumWidth)
  54957. {
  54958. totalW = minimumWidth;
  54959. for (int col = 0; col < numColumns; ++col)
  54960. columnWidths.set (0, totalW / numColumns);
  54961. }
  54962. return totalW;
  54963. }
  54964. void ensureItemIsVisible (const int itemId, int wantedY)
  54965. {
  54966. jassert (itemId != 0)
  54967. for (int i = getNumChildComponents(); --i >= 0;)
  54968. {
  54969. PopupMenu::ItemComponent* const m = static_cast <PopupMenu::ItemComponent*> (getChildComponent (i));
  54970. if (m != 0
  54971. && m->itemInfo.itemId == itemId
  54972. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  54973. {
  54974. const int currentY = m->getY();
  54975. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  54976. {
  54977. if (wantedY < 0)
  54978. wantedY = jlimit (PopupMenuSettings::scrollZone,
  54979. jmax (PopupMenuSettings::scrollZone,
  54980. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  54981. currentY);
  54982. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  54983. int deltaY = wantedY - currentY;
  54984. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  54985. jmin (windowPos.getHeight(), mon.getHeight()));
  54986. const int newY = jlimit (mon.getY(),
  54987. mon.getBottom() - windowPos.getHeight(),
  54988. windowPos.getY() + deltaY);
  54989. deltaY -= newY - windowPos.getY();
  54990. childYOffset -= deltaY;
  54991. windowPos.setPosition (windowPos.getX(), newY);
  54992. updateYPositions();
  54993. }
  54994. break;
  54995. }
  54996. }
  54997. }
  54998. void resizeToBestWindowPos()
  54999. {
  55000. Rectangle<int> r (windowPos);
  55001. if (childYOffset < 0)
  55002. {
  55003. r.setBounds (r.getX(), r.getY() - childYOffset,
  55004. r.getWidth(), r.getHeight() + childYOffset);
  55005. }
  55006. else if (childYOffset > 0)
  55007. {
  55008. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55009. if (spaceAtBottom > 0)
  55010. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55011. }
  55012. setBounds (r);
  55013. updateYPositions();
  55014. }
  55015. void alterChildYPos (const int delta)
  55016. {
  55017. if (isScrolling())
  55018. {
  55019. childYOffset += delta;
  55020. if (delta < 0)
  55021. {
  55022. childYOffset = jmax (childYOffset, 0);
  55023. }
  55024. else if (delta > 0)
  55025. {
  55026. childYOffset = jmin (childYOffset,
  55027. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55028. }
  55029. updateYPositions();
  55030. }
  55031. else
  55032. {
  55033. childYOffset = 0;
  55034. }
  55035. resizeToBestWindowPos();
  55036. repaint();
  55037. }
  55038. int updateYPositions()
  55039. {
  55040. int x = 0;
  55041. int childNum = 0;
  55042. for (int col = 0; col < numColumns; ++col)
  55043. {
  55044. const int numChildren = jmin (getNumChildComponents() - childNum,
  55045. (getNumChildComponents() + numColumns - 1) / numColumns);
  55046. const int colW = columnWidths [col];
  55047. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55048. for (int i = 0; i < numChildren; ++i)
  55049. {
  55050. Component* const c = getChildComponent (childNum + i);
  55051. c->setBounds (x, y, colW, c->getHeight());
  55052. y += c->getHeight();
  55053. }
  55054. x += colW;
  55055. childNum += numChildren;
  55056. }
  55057. return x;
  55058. }
  55059. bool isScrolling() const throw()
  55060. {
  55061. return childYOffset != 0 || needsToScroll;
  55062. }
  55063. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55064. {
  55065. if (currentChild->isValidComponent())
  55066. currentChild->setHighlighted (false);
  55067. currentChild = child;
  55068. if (currentChild != 0)
  55069. {
  55070. currentChild->setHighlighted (true);
  55071. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55072. }
  55073. }
  55074. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55075. {
  55076. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55077. activeSubMenu = 0;
  55078. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55079. {
  55080. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55081. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55082. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55083. dismissOnMouseUp,
  55084. this,
  55085. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55086. 0, maximumNumColumns,
  55087. standardItemHeight,
  55088. false, 0, menuBarComponent,
  55089. managerOfChosenCommand,
  55090. componentAttachedTo);
  55091. if (activeSubMenu != 0)
  55092. {
  55093. activeSubMenu->setVisible (true);
  55094. activeSubMenu->enterModalState (false);
  55095. activeSubMenu->toFront (false);
  55096. return true;
  55097. }
  55098. }
  55099. return false;
  55100. }
  55101. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55102. {
  55103. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55104. if (isOver)
  55105. hasBeenOver = true;
  55106. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55107. {
  55108. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55109. if (disableMouseMoves && isOver)
  55110. disableMouseMoves = false;
  55111. }
  55112. if (disableMouseMoves || (activeSubMenu != 0 && activeSubMenu->isOverChildren()))
  55113. return;
  55114. bool isMovingTowardsMenu = false;
  55115. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55116. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55117. {
  55118. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55119. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55120. // extends from the last mouse pos to the submenu's rectangle..
  55121. float subX = (float) activeSubMenu->getScreenX();
  55122. if (activeSubMenu->getX() > getX())
  55123. {
  55124. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55125. }
  55126. else
  55127. {
  55128. lastMouse += Point<int> (2, 0);
  55129. subX += activeSubMenu->getWidth();
  55130. }
  55131. Path areaTowardsSubMenu;
  55132. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55133. (float) lastMouse.getY(),
  55134. subX,
  55135. (float) activeSubMenu->getScreenY(),
  55136. subX,
  55137. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55138. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55139. }
  55140. lastMouse = globalMousePos;
  55141. if (! isMovingTowardsMenu)
  55142. {
  55143. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55144. if (c == this)
  55145. c = 0;
  55146. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55147. if (mic == 0 && c != 0)
  55148. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55149. if (mic != currentChild
  55150. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55151. {
  55152. if (isOver && (c != 0) && (activeSubMenu != 0))
  55153. {
  55154. activeSubMenu->hide (0);
  55155. }
  55156. if (! isOver)
  55157. mic = 0;
  55158. setCurrentlyHighlightedChild (mic);
  55159. }
  55160. }
  55161. }
  55162. void triggerCurrentlyHighlightedItem()
  55163. {
  55164. if (currentChild->isValidComponent()
  55165. && currentChild->itemInfo.canBeTriggered()
  55166. && (currentChild->itemInfo.customComp == 0
  55167. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55168. {
  55169. dismissMenu (&currentChild->itemInfo);
  55170. }
  55171. }
  55172. void selectNextItem (const int delta)
  55173. {
  55174. disableTimerUntilMouseMoves();
  55175. PopupMenu::ItemComponent* mic = 0;
  55176. bool wasLastOne = (currentChild == 0);
  55177. const int numItems = getNumChildComponents();
  55178. for (int i = 0; i < numItems + 1; ++i)
  55179. {
  55180. int index = (delta > 0) ? i : (numItems - 1 - i);
  55181. index = (index + numItems) % numItems;
  55182. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55183. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55184. && wasLastOne)
  55185. break;
  55186. if (mic == currentChild)
  55187. wasLastOne = true;
  55188. }
  55189. setCurrentlyHighlightedChild (mic);
  55190. }
  55191. void disableTimerUntilMouseMoves()
  55192. {
  55193. disableMouseMoves = true;
  55194. if (owner != 0)
  55195. owner->disableTimerUntilMouseMoves();
  55196. }
  55197. Window (const Window&);
  55198. Window& operator= (const Window&);
  55199. };
  55200. PopupMenu::PopupMenu()
  55201. : lookAndFeel (0),
  55202. separatorPending (false)
  55203. {
  55204. }
  55205. PopupMenu::PopupMenu (const PopupMenu& other)
  55206. : lookAndFeel (other.lookAndFeel),
  55207. separatorPending (false)
  55208. {
  55209. items.ensureStorageAllocated (other.items.size());
  55210. for (int i = 0; i < other.items.size(); ++i)
  55211. items.add (new Item (*other.items.getUnchecked(i)));
  55212. }
  55213. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55214. {
  55215. if (this != &other)
  55216. {
  55217. lookAndFeel = other.lookAndFeel;
  55218. clear();
  55219. items.ensureStorageAllocated (other.items.size());
  55220. for (int i = 0; i < other.items.size(); ++i)
  55221. items.add (new Item (*other.items.getUnchecked(i)));
  55222. }
  55223. return *this;
  55224. }
  55225. PopupMenu::~PopupMenu()
  55226. {
  55227. clear();
  55228. }
  55229. void PopupMenu::clear()
  55230. {
  55231. items.clear();
  55232. separatorPending = false;
  55233. }
  55234. void PopupMenu::addSeparatorIfPending()
  55235. {
  55236. if (separatorPending)
  55237. {
  55238. separatorPending = false;
  55239. if (items.size() > 0)
  55240. items.add (new Item());
  55241. }
  55242. }
  55243. void PopupMenu::addItem (const int itemResultId,
  55244. const String& itemText,
  55245. const bool isActive,
  55246. const bool isTicked,
  55247. const Image* const iconToUse)
  55248. {
  55249. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55250. // didn't pick anything, so you shouldn't use it as the id
  55251. // for an item..
  55252. addSeparatorIfPending();
  55253. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55254. iconToUse, Colours::black, false, 0, 0, 0));
  55255. }
  55256. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55257. const int commandID,
  55258. const String& displayName)
  55259. {
  55260. jassert (commandManager != 0 && commandID != 0);
  55261. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55262. if (registeredInfo != 0)
  55263. {
  55264. ApplicationCommandInfo info (*registeredInfo);
  55265. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55266. addSeparatorIfPending();
  55267. items.add (new Item (commandID,
  55268. displayName.isNotEmpty() ? displayName
  55269. : info.shortName,
  55270. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55271. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55272. 0,
  55273. Colours::black,
  55274. false,
  55275. 0, 0,
  55276. commandManager));
  55277. }
  55278. }
  55279. void PopupMenu::addColouredItem (const int itemResultId,
  55280. const String& itemText,
  55281. const Colour& itemTextColour,
  55282. const bool isActive,
  55283. const bool isTicked,
  55284. const Image* const iconToUse)
  55285. {
  55286. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55287. // didn't pick anything, so you shouldn't use it as the id
  55288. // for an item..
  55289. addSeparatorIfPending();
  55290. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55291. iconToUse, itemTextColour, true, 0, 0, 0));
  55292. }
  55293. void PopupMenu::addCustomItem (const int itemResultId,
  55294. PopupMenuCustomComponent* const customComponent)
  55295. {
  55296. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55297. // didn't pick anything, so you shouldn't use it as the id
  55298. // for an item..
  55299. addSeparatorIfPending();
  55300. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55301. Colours::black, false, customComponent, 0, 0));
  55302. }
  55303. class NormalComponentWrapper : public PopupMenuCustomComponent
  55304. {
  55305. public:
  55306. NormalComponentWrapper (Component* const comp,
  55307. const int w, const int h,
  55308. const bool triggerMenuItemAutomaticallyWhenClicked)
  55309. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  55310. width (w),
  55311. height (h)
  55312. {
  55313. addAndMakeVisible (comp);
  55314. }
  55315. ~NormalComponentWrapper() {}
  55316. void getIdealSize (int& idealWidth, int& idealHeight)
  55317. {
  55318. idealWidth = width;
  55319. idealHeight = height;
  55320. }
  55321. void resized()
  55322. {
  55323. if (getChildComponent(0) != 0)
  55324. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  55325. }
  55326. juce_UseDebuggingNewOperator
  55327. private:
  55328. const int width, height;
  55329. NormalComponentWrapper (const NormalComponentWrapper&);
  55330. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  55331. };
  55332. void PopupMenu::addCustomItem (const int itemResultId,
  55333. Component* customComponent,
  55334. int idealWidth, int idealHeight,
  55335. const bool triggerMenuItemAutomaticallyWhenClicked)
  55336. {
  55337. addCustomItem (itemResultId,
  55338. new NormalComponentWrapper (customComponent,
  55339. idealWidth, idealHeight,
  55340. triggerMenuItemAutomaticallyWhenClicked));
  55341. }
  55342. void PopupMenu::addSubMenu (const String& subMenuName,
  55343. const PopupMenu& subMenu,
  55344. const bool isActive,
  55345. Image* const iconToUse,
  55346. const bool isTicked)
  55347. {
  55348. addSeparatorIfPending();
  55349. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  55350. iconToUse, Colours::black, false, 0, &subMenu, 0));
  55351. }
  55352. void PopupMenu::addSeparator()
  55353. {
  55354. separatorPending = true;
  55355. }
  55356. class HeaderItemComponent : public PopupMenuCustomComponent
  55357. {
  55358. public:
  55359. HeaderItemComponent (const String& name)
  55360. : PopupMenuCustomComponent (false)
  55361. {
  55362. setName (name);
  55363. }
  55364. ~HeaderItemComponent()
  55365. {
  55366. }
  55367. void paint (Graphics& g)
  55368. {
  55369. Font f (getLookAndFeel().getPopupMenuFont());
  55370. f.setBold (true);
  55371. g.setFont (f);
  55372. g.setColour (findColour (PopupMenu::headerTextColourId));
  55373. g.drawFittedText (getName(),
  55374. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  55375. Justification::bottomLeft, 1);
  55376. }
  55377. void getIdealSize (int& idealWidth,
  55378. int& idealHeight)
  55379. {
  55380. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  55381. idealHeight += idealHeight / 2;
  55382. idealWidth += idealWidth / 4;
  55383. }
  55384. juce_UseDebuggingNewOperator
  55385. };
  55386. void PopupMenu::addSectionHeader (const String& title)
  55387. {
  55388. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  55389. }
  55390. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  55391. const int itemIdThatMustBeVisible,
  55392. const int minimumWidth,
  55393. const int maximumNumColumns,
  55394. const int standardItemHeight,
  55395. const bool alignToRectangle,
  55396. Component* menuBarComponent,
  55397. ApplicationCommandManager** managerOfChosenCommand,
  55398. Component* const componentAttachedTo)
  55399. {
  55400. Window* const pw
  55401. = Window::create (*this,
  55402. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  55403. 0,
  55404. x, x + w,
  55405. y, y + h,
  55406. minimumWidth,
  55407. maximumNumColumns,
  55408. standardItemHeight,
  55409. alignToRectangle,
  55410. itemIdThatMustBeVisible,
  55411. menuBarComponent,
  55412. managerOfChosenCommand,
  55413. componentAttachedTo);
  55414. if (pw != 0)
  55415. pw->setVisible (true);
  55416. return pw;
  55417. }
  55418. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  55419. const int itemIdThatMustBeVisible,
  55420. const int minimumWidth,
  55421. const int maximumNumColumns,
  55422. const int standardItemHeight,
  55423. const bool alignToRectangle,
  55424. Component* const componentAttachedTo)
  55425. {
  55426. Component::SafePointer<Component> prevFocused (Component::getCurrentlyFocusedComponent());
  55427. Component::SafePointer<Component> prevTopLevel ((prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0);
  55428. Window::wasHiddenBecauseOfAppChange() = false;
  55429. int result = 0;
  55430. ApplicationCommandManager* managerOfChosenCommand = 0;
  55431. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  55432. itemIdThatMustBeVisible,
  55433. minimumWidth,
  55434. maximumNumColumns > 0 ? maximumNumColumns : 7,
  55435. standardItemHeight,
  55436. alignToRectangle, 0,
  55437. &managerOfChosenCommand,
  55438. componentAttachedTo));
  55439. if (popupComp != 0)
  55440. {
  55441. popupComp->enterModalState (false);
  55442. popupComp->toFront (false); // need to do this after making it modal, or it could
  55443. // be stuck behind other comps that are already modal..
  55444. result = popupComp->runModalLoop();
  55445. popupComp = 0;
  55446. if (! Window::wasHiddenBecauseOfAppChange())
  55447. {
  55448. if (prevTopLevel != 0)
  55449. prevTopLevel->toFront (true);
  55450. if (prevFocused != 0)
  55451. prevFocused->grabKeyboardFocus();
  55452. }
  55453. }
  55454. if (managerOfChosenCommand != 0 && result != 0)
  55455. {
  55456. ApplicationCommandTarget::InvocationInfo info (result);
  55457. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  55458. managerOfChosenCommand->invoke (info, true);
  55459. }
  55460. return result;
  55461. }
  55462. int PopupMenu::show (const int itemIdThatMustBeVisible,
  55463. const int minimumWidth,
  55464. const int maximumNumColumns,
  55465. const int standardItemHeight)
  55466. {
  55467. const Point<int> mousePos (Desktop::getMousePosition());
  55468. return showAt (mousePos.getX(), mousePos.getY(),
  55469. itemIdThatMustBeVisible,
  55470. minimumWidth,
  55471. maximumNumColumns,
  55472. standardItemHeight);
  55473. }
  55474. int PopupMenu::showAt (const int screenX,
  55475. const int screenY,
  55476. const int itemIdThatMustBeVisible,
  55477. const int minimumWidth,
  55478. const int maximumNumColumns,
  55479. const int standardItemHeight)
  55480. {
  55481. return showMenu (screenX, screenY, 1, 1,
  55482. itemIdThatMustBeVisible,
  55483. minimumWidth, maximumNumColumns,
  55484. standardItemHeight,
  55485. false, 0);
  55486. }
  55487. int PopupMenu::showAt (Component* componentToAttachTo,
  55488. const int itemIdThatMustBeVisible,
  55489. const int minimumWidth,
  55490. const int maximumNumColumns,
  55491. const int standardItemHeight)
  55492. {
  55493. if (componentToAttachTo != 0)
  55494. {
  55495. return showMenu (componentToAttachTo->getScreenX(),
  55496. componentToAttachTo->getScreenY(),
  55497. componentToAttachTo->getWidth(),
  55498. componentToAttachTo->getHeight(),
  55499. itemIdThatMustBeVisible,
  55500. minimumWidth,
  55501. maximumNumColumns,
  55502. standardItemHeight,
  55503. true, componentToAttachTo);
  55504. }
  55505. else
  55506. {
  55507. return show (itemIdThatMustBeVisible,
  55508. minimumWidth,
  55509. maximumNumColumns,
  55510. standardItemHeight);
  55511. }
  55512. }
  55513. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  55514. {
  55515. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  55516. {
  55517. Window* const pmw = Window::getActiveWindows()[i];
  55518. if (pmw != 0)
  55519. pmw->dismissMenu (0);
  55520. }
  55521. }
  55522. int PopupMenu::getNumItems() const throw()
  55523. {
  55524. int num = 0;
  55525. for (int i = items.size(); --i >= 0;)
  55526. if (! (items.getUnchecked(i))->isSeparator)
  55527. ++num;
  55528. return num;
  55529. }
  55530. bool PopupMenu::containsCommandItem (const int commandID) const
  55531. {
  55532. for (int i = items.size(); --i >= 0;)
  55533. {
  55534. const Item* mi = items.getUnchecked (i);
  55535. if ((mi->itemId == commandID && mi->commandManager != 0)
  55536. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  55537. {
  55538. return true;
  55539. }
  55540. }
  55541. return false;
  55542. }
  55543. bool PopupMenu::containsAnyActiveItems() const throw()
  55544. {
  55545. for (int i = items.size(); --i >= 0;)
  55546. {
  55547. const Item* const mi = items.getUnchecked (i);
  55548. if (mi->subMenu != 0)
  55549. {
  55550. if (mi->subMenu->containsAnyActiveItems())
  55551. return true;
  55552. }
  55553. else if (mi->active)
  55554. {
  55555. return true;
  55556. }
  55557. }
  55558. return false;
  55559. }
  55560. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  55561. {
  55562. lookAndFeel = newLookAndFeel;
  55563. }
  55564. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  55565. : isHighlighted (false),
  55566. isTriggeredAutomatically (isTriggeredAutomatically_)
  55567. {
  55568. }
  55569. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  55570. {
  55571. }
  55572. void PopupMenuCustomComponent::triggerMenuItem()
  55573. {
  55574. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  55575. if (mic != 0)
  55576. {
  55577. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  55578. if (pmw != 0)
  55579. {
  55580. pmw->dismissMenu (&mic->itemInfo);
  55581. }
  55582. else
  55583. {
  55584. // something must have gone wrong with the component hierarchy if this happens..
  55585. jassertfalse
  55586. }
  55587. }
  55588. else
  55589. {
  55590. // why isn't this component inside a menu? Not much point triggering the item if
  55591. // there's no menu.
  55592. jassertfalse
  55593. }
  55594. }
  55595. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  55596. : subMenu (0),
  55597. itemId (0),
  55598. isSeparator (false),
  55599. isTicked (false),
  55600. isEnabled (false),
  55601. isCustomComponent (false),
  55602. isSectionHeader (false),
  55603. customColour (0),
  55604. customImage (0),
  55605. menu (menu_),
  55606. index (0)
  55607. {
  55608. }
  55609. PopupMenu::MenuItemIterator::~MenuItemIterator()
  55610. {
  55611. }
  55612. bool PopupMenu::MenuItemIterator::next()
  55613. {
  55614. if (index >= menu.items.size())
  55615. return false;
  55616. const Item* const item = menu.items.getUnchecked (index);
  55617. ++index;
  55618. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  55619. subMenu = item->subMenu;
  55620. itemId = item->itemId;
  55621. isSeparator = item->isSeparator;
  55622. isTicked = item->isTicked;
  55623. isEnabled = item->active;
  55624. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  55625. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  55626. customColour = item->usesColour ? &(item->textColour) : 0;
  55627. customImage = item->image;
  55628. commandManager = item->commandManager;
  55629. return true;
  55630. }
  55631. END_JUCE_NAMESPACE
  55632. /*** End of inlined file: juce_PopupMenu.cpp ***/
  55633. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  55634. BEGIN_JUCE_NAMESPACE
  55635. ComponentDragger::ComponentDragger()
  55636. : constrainer (0)
  55637. {
  55638. }
  55639. ComponentDragger::~ComponentDragger()
  55640. {
  55641. }
  55642. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  55643. ComponentBoundsConstrainer* const constrainer_)
  55644. {
  55645. jassert (componentToDrag->isValidComponent());
  55646. if (componentToDrag != 0)
  55647. {
  55648. constrainer = constrainer_;
  55649. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  55650. }
  55651. }
  55652. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  55653. {
  55654. jassert (componentToDrag->isValidComponent());
  55655. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  55656. if (componentToDrag != 0)
  55657. {
  55658. Rectangle<int> bounds (componentToDrag->getBounds().withPosition (originalPos));
  55659. const Component* const parentComp = componentToDrag->getParentComponent();
  55660. if (parentComp != 0)
  55661. bounds.setPosition (parentComp->globalPositionToRelative (originalPos));
  55662. bounds.setPosition (bounds.getPosition() + e.getOffsetFromDragStart());
  55663. if (constrainer != 0)
  55664. constrainer->setBoundsForComponent (componentToDrag, bounds, false, false, false, false);
  55665. else
  55666. componentToDrag->setBounds (bounds);
  55667. }
  55668. }
  55669. END_JUCE_NAMESPACE
  55670. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  55671. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  55672. BEGIN_JUCE_NAMESPACE
  55673. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  55674. bool juce_performDragDropText (const String& text, bool& shouldStop);
  55675. class DragImageComponent : public Component,
  55676. public Timer
  55677. {
  55678. public:
  55679. DragImageComponent (Image* const im,
  55680. const String& desc,
  55681. Component* const sourceComponent,
  55682. Component* const mouseDragSource_,
  55683. DragAndDropContainer* const o,
  55684. const Point<int>& imageOffset_)
  55685. : image (im),
  55686. source (sourceComponent),
  55687. mouseDragSource (mouseDragSource_),
  55688. owner (o),
  55689. dragDesc (desc),
  55690. imageOffset (imageOffset_),
  55691. hasCheckedForExternalDrag (false),
  55692. drawImage (true)
  55693. {
  55694. setSize (im->getWidth(), im->getHeight());
  55695. if (mouseDragSource == 0)
  55696. mouseDragSource = source;
  55697. mouseDragSource->addMouseListener (this, false);
  55698. startTimer (200);
  55699. setInterceptsMouseClicks (false, false);
  55700. setAlwaysOnTop (true);
  55701. }
  55702. ~DragImageComponent()
  55703. {
  55704. if (owner->dragImageComponent == this)
  55705. owner->dragImageComponent.release();
  55706. if (mouseDragSource != 0)
  55707. {
  55708. mouseDragSource->removeMouseListener (this);
  55709. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDesc, source))
  55710. getCurrentlyOver()->itemDragExit (dragDesc, source);
  55711. }
  55712. }
  55713. void paint (Graphics& g)
  55714. {
  55715. if (isOpaque())
  55716. g.fillAll (Colours::white);
  55717. if (drawImage)
  55718. {
  55719. g.setOpacity (1.0f);
  55720. g.drawImageAt (image, 0, 0);
  55721. }
  55722. }
  55723. DragAndDropTarget* findTarget (const Point<int>& screenPos, Point<int>& relativePos)
  55724. {
  55725. Component* hit = getParentComponent();
  55726. if (hit == 0)
  55727. {
  55728. hit = Desktop::getInstance().findComponentAt (screenPos);
  55729. }
  55730. else
  55731. {
  55732. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  55733. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  55734. }
  55735. // (note: use a local copy of the dragDesc member in case the callback runs
  55736. // a modal loop and deletes this object before the method completes)
  55737. const String dragDescLocal (dragDesc);
  55738. while (hit != 0)
  55739. {
  55740. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  55741. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55742. {
  55743. relativePos = hit->globalPositionToRelative (screenPos);
  55744. return ddt;
  55745. }
  55746. hit = hit->getParentComponent();
  55747. }
  55748. return 0;
  55749. }
  55750. void mouseUp (const MouseEvent& e)
  55751. {
  55752. if (e.originalComponent != this)
  55753. {
  55754. if (mouseDragSource != 0)
  55755. mouseDragSource->removeMouseListener (this);
  55756. bool dropAccepted = false;
  55757. DragAndDropTarget* ddt = 0;
  55758. Point<int> relPos;
  55759. if (isVisible())
  55760. {
  55761. setVisible (false);
  55762. ddt = findTarget (e.getScreenPosition(), relPos);
  55763. // fade this component and remove it - it'll be deleted later by the timer callback
  55764. dropAccepted = ddt != 0;
  55765. setVisible (true);
  55766. if (dropAccepted || source == 0)
  55767. {
  55768. fadeOutComponent (120);
  55769. }
  55770. else
  55771. {
  55772. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  55773. source->getHeight() / 2)));
  55774. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  55775. getHeight() / 2)));
  55776. fadeOutComponent (120,
  55777. target.getX() - ourCentre.getX(),
  55778. target.getY() - ourCentre.getY());
  55779. }
  55780. }
  55781. if (getParentComponent() != 0)
  55782. getParentComponent()->removeChildComponent (this);
  55783. if (dropAccepted && ddt != 0)
  55784. {
  55785. // (note: use a local copy of the dragDesc member in case the callback runs
  55786. // a modal loop and deletes this object before the method completes)
  55787. const String dragDescLocal (dragDesc);
  55788. currentlyOverComp = 0;
  55789. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  55790. }
  55791. // careful - this object could now be deleted..
  55792. }
  55793. }
  55794. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  55795. {
  55796. // (note: use a local copy of the dragDesc member in case the callback runs
  55797. // a modal loop and deletes this object before it returns)
  55798. const String dragDescLocal (dragDesc);
  55799. Point<int> newPos (screenPos + imageOffset);
  55800. if (getParentComponent() != 0)
  55801. newPos = getParentComponent()->globalPositionToRelative (newPos);
  55802. //if (newX != getX() || newY != getY())
  55803. {
  55804. setTopLeftPosition (newPos.getX(), newPos.getY());
  55805. Point<int> relPos;
  55806. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  55807. Component* ddtComp = dynamic_cast <Component*> (ddt);
  55808. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  55809. if (ddtComp != currentlyOverComp)
  55810. {
  55811. if (currentlyOverComp != 0 && source != 0
  55812. && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55813. {
  55814. getCurrentlyOver()->itemDragExit (dragDescLocal, source);
  55815. }
  55816. currentlyOverComp = ddtComp;
  55817. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  55818. ddt->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  55819. }
  55820. if (getCurrentlyOver() != 0 && getCurrentlyOver()->isInterestedInDragSource (dragDescLocal, source))
  55821. getCurrentlyOver()->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  55822. if (getCurrentlyOver() == 0
  55823. && canDoExternalDrag
  55824. && ! hasCheckedForExternalDrag)
  55825. {
  55826. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  55827. {
  55828. hasCheckedForExternalDrag = true;
  55829. StringArray files;
  55830. bool canMoveFiles = false;
  55831. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  55832. && files.size() > 0)
  55833. {
  55834. Component::SafePointer<Component> cdw (this);
  55835. setVisible (false);
  55836. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  55837. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  55838. if (cdw != 0)
  55839. delete this;
  55840. return;
  55841. }
  55842. }
  55843. }
  55844. }
  55845. }
  55846. void mouseDrag (const MouseEvent& e)
  55847. {
  55848. if (e.originalComponent != this)
  55849. updateLocation (true, e.getScreenPosition());
  55850. }
  55851. void timerCallback()
  55852. {
  55853. if (source == 0)
  55854. {
  55855. delete this;
  55856. }
  55857. else if (! isMouseButtonDownAnywhere())
  55858. {
  55859. if (mouseDragSource != 0)
  55860. mouseDragSource->removeMouseListener (this);
  55861. delete this;
  55862. }
  55863. }
  55864. private:
  55865. ScopedPointer<Image> image;
  55866. Component::SafePointer<Component> source;
  55867. Component::SafePointer<Component> mouseDragSource;
  55868. DragAndDropContainer* const owner;
  55869. Component::SafePointer<Component> currentlyOverComp;
  55870. DragAndDropTarget* getCurrentlyOver()
  55871. {
  55872. return dynamic_cast <DragAndDropTarget*> (static_cast <Component*> (currentlyOverComp));
  55873. }
  55874. String dragDesc;
  55875. const Point<int> imageOffset;
  55876. bool hasCheckedForExternalDrag, drawImage;
  55877. DragImageComponent (const DragImageComponent&);
  55878. DragImageComponent& operator= (const DragImageComponent&);
  55879. };
  55880. DragAndDropContainer::DragAndDropContainer()
  55881. {
  55882. }
  55883. DragAndDropContainer::~DragAndDropContainer()
  55884. {
  55885. dragImageComponent = 0;
  55886. }
  55887. void DragAndDropContainer::startDragging (const String& sourceDescription,
  55888. Component* sourceComponent,
  55889. Image* dragImage_,
  55890. const bool allowDraggingToExternalWindows,
  55891. const Point<int>* imageOffsetFromMouse)
  55892. {
  55893. ScopedPointer <Image> dragImage (dragImage_);
  55894. if (dragImageComponent == 0)
  55895. {
  55896. Component* const thisComp = dynamic_cast <Component*> (this);
  55897. if (thisComp == 0)
  55898. {
  55899. jassertfalse; // Your DragAndDropContainer needs to be a Component!
  55900. return;
  55901. }
  55902. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource (0);
  55903. if (draggingSource == 0 || ! draggingSource->isDragging())
  55904. {
  55905. jassertfalse; // You must call startDragging() from within a mouseDown or mouseDrag callback!
  55906. return;
  55907. }
  55908. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  55909. Point<int> imageOffset;
  55910. if (dragImage == 0)
  55911. {
  55912. dragImage = sourceComponent->createComponentSnapshot (sourceComponent->getLocalBounds());
  55913. if (dragImage->getFormat() != Image::ARGB)
  55914. {
  55915. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  55916. Graphics g2 (*newIm);
  55917. g2.drawImageAt (dragImage, 0, 0);
  55918. dragImage = newIm;
  55919. }
  55920. dragImage->multiplyAllAlphas (0.6f);
  55921. const int lo = 150;
  55922. const int hi = 400;
  55923. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  55924. Point<int> clipped (dragImage->getBounds().getConstrainedPoint (relPos));
  55925. for (int y = dragImage->getHeight(); --y >= 0;)
  55926. {
  55927. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  55928. for (int x = dragImage->getWidth(); --x >= 0;)
  55929. {
  55930. const int dx = x - clipped.getX();
  55931. const int distance = roundToInt (sqrt (dx * dx + dy));
  55932. if (distance > lo)
  55933. {
  55934. const float alpha = (distance > hi) ? 0
  55935. : (hi - distance) / (float) (hi - lo)
  55936. + Random::getSystemRandom().nextFloat() * 0.008f;
  55937. dragImage->multiplyAlphaAt (x, y, alpha);
  55938. }
  55939. }
  55940. }
  55941. imageOffset = -clipped;
  55942. }
  55943. else
  55944. {
  55945. if (imageOffsetFromMouse == 0)
  55946. imageOffset = Point<int> (dragImage->getWidth() / -2,
  55947. dragImage->getHeight() / -2);
  55948. else
  55949. imageOffset = *imageOffsetFromMouse;
  55950. }
  55951. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  55952. draggingSource->getComponentUnderMouse(), this, imageOffset);
  55953. currentDragDesc = sourceDescription;
  55954. if (allowDraggingToExternalWindows)
  55955. {
  55956. if (! Desktop::canUseSemiTransparentWindows())
  55957. dragImageComponent->setOpaque (true);
  55958. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  55959. | ComponentPeer::windowIsTemporary
  55960. | ComponentPeer::windowIgnoresKeyPresses);
  55961. }
  55962. else
  55963. thisComp->addChildComponent (dragImageComponent);
  55964. static_cast <DragImageComponent*> (static_cast <Component*> (dragImageComponent))->updateLocation (false, lastMouseDown);
  55965. dragImageComponent->setVisible (true);
  55966. }
  55967. }
  55968. bool DragAndDropContainer::isDragAndDropActive() const
  55969. {
  55970. return dragImageComponent != 0;
  55971. }
  55972. const String DragAndDropContainer::getCurrentDragDescription() const
  55973. {
  55974. return (dragImageComponent != 0) ? currentDragDesc
  55975. : String::empty;
  55976. }
  55977. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  55978. {
  55979. if (c == 0)
  55980. return 0;
  55981. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  55982. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  55983. }
  55984. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  55985. {
  55986. return false;
  55987. }
  55988. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  55989. {
  55990. }
  55991. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  55992. {
  55993. }
  55994. void DragAndDropTarget::itemDragExit (const String&, Component*)
  55995. {
  55996. }
  55997. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  55998. {
  55999. return true;
  56000. }
  56001. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56002. {
  56003. }
  56004. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56005. {
  56006. }
  56007. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56008. {
  56009. }
  56010. END_JUCE_NAMESPACE
  56011. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56012. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56013. BEGIN_JUCE_NAMESPACE
  56014. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY);
  56015. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type);
  56016. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard);
  56017. class MouseCursor::SharedCursorHandle
  56018. {
  56019. public:
  56020. explicit SharedCursorHandle (const MouseCursor::StandardCursorType type)
  56021. : handle (juce_createStandardMouseCursor (type)),
  56022. refCount (1),
  56023. standardType (type),
  56024. isStandard (true)
  56025. {
  56026. }
  56027. SharedCursorHandle (const Image& image, const int hotSpotX, const int hotSpotY)
  56028. : handle (juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY)),
  56029. refCount (1),
  56030. standardType (MouseCursor::NormalCursor),
  56031. isStandard (false)
  56032. {
  56033. }
  56034. static SharedCursorHandle* createStandard (const MouseCursor::StandardCursorType type)
  56035. {
  56036. const ScopedLock sl (getLock());
  56037. for (int i = getCursors().size(); --i >= 0;)
  56038. {
  56039. SharedCursorHandle* const sc = getCursors().getUnchecked(i);
  56040. if (sc->standardType == type)
  56041. return sc->retain();
  56042. }
  56043. SharedCursorHandle* const sc = new SharedCursorHandle (type);
  56044. getCursors().add (sc);
  56045. return sc;
  56046. }
  56047. SharedCursorHandle* retain() throw()
  56048. {
  56049. Atomic::increment (refCount);
  56050. return this;
  56051. }
  56052. void release()
  56053. {
  56054. if (Atomic::decrementAndReturn (refCount) == 0)
  56055. {
  56056. if (isStandard)
  56057. {
  56058. const ScopedLock sl (getLock());
  56059. getCursors().removeValue (this);
  56060. }
  56061. delete this;
  56062. }
  56063. }
  56064. void* getHandle() const throw() { return handle; }
  56065. juce_UseDebuggingNewOperator
  56066. private:
  56067. void* const handle;
  56068. int32 refCount;
  56069. const MouseCursor::StandardCursorType standardType;
  56070. const bool isStandard;
  56071. static CriticalSection& getLock()
  56072. {
  56073. static CriticalSection lock;
  56074. return lock;
  56075. }
  56076. static Array <SharedCursorHandle*>& getCursors()
  56077. {
  56078. static Array <SharedCursorHandle*> cursors;
  56079. return cursors;
  56080. }
  56081. ~SharedCursorHandle()
  56082. {
  56083. juce_deleteMouseCursor (handle, isStandard);
  56084. }
  56085. SharedCursorHandle& operator= (const SharedCursorHandle&);
  56086. };
  56087. MouseCursor::MouseCursor()
  56088. : cursorHandle (SharedCursorHandle::createStandard (NormalCursor))
  56089. {
  56090. jassert (cursorHandle != 0);
  56091. }
  56092. MouseCursor::MouseCursor (const StandardCursorType type)
  56093. : cursorHandle (SharedCursorHandle::createStandard (type))
  56094. {
  56095. jassert (cursorHandle != 0);
  56096. }
  56097. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY)
  56098. : cursorHandle (new SharedCursorHandle (image, hotSpotX, hotSpotY))
  56099. {
  56100. }
  56101. MouseCursor::MouseCursor (const MouseCursor& other)
  56102. : cursorHandle (other.cursorHandle->retain())
  56103. {
  56104. }
  56105. MouseCursor::~MouseCursor()
  56106. {
  56107. cursorHandle->release();
  56108. }
  56109. MouseCursor& MouseCursor::operator= (const MouseCursor& other)
  56110. {
  56111. other.cursorHandle->retain();
  56112. cursorHandle->release();
  56113. cursorHandle = other.cursorHandle;
  56114. return *this;
  56115. }
  56116. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56117. {
  56118. return getHandle() == other.getHandle();
  56119. }
  56120. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56121. {
  56122. return getHandle() != other.getHandle();
  56123. }
  56124. void* MouseCursor::getHandle() const throw()
  56125. {
  56126. return cursorHandle->getHandle();
  56127. }
  56128. void MouseCursor::showWaitCursor() throw()
  56129. {
  56130. Desktop::getInstance().getMainMouseSource().showMouseCursor (MouseCursor::WaitCursor);
  56131. }
  56132. void MouseCursor::hideWaitCursor() throw()
  56133. {
  56134. Desktop::getInstance().getMainMouseSource().revealCursor();
  56135. }
  56136. END_JUCE_NAMESPACE
  56137. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56138. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56139. BEGIN_JUCE_NAMESPACE
  56140. MouseEvent::MouseEvent (MouseInputSource& source_,
  56141. const Point<int>& position,
  56142. const ModifierKeys& mods_,
  56143. Component* const originator,
  56144. const Time& eventTime_,
  56145. const Point<int> mouseDownPos_,
  56146. const Time& mouseDownTime_,
  56147. const int numberOfClicks_,
  56148. const bool mouseWasDragged) throw()
  56149. : x (position.getX()),
  56150. y (position.getY()),
  56151. mods (mods_),
  56152. eventComponent (originator),
  56153. originalComponent (originator),
  56154. eventTime (eventTime_),
  56155. source (source_),
  56156. mouseDownPos (mouseDownPos_),
  56157. mouseDownTime (mouseDownTime_),
  56158. numberOfClicks (numberOfClicks_),
  56159. wasMovedSinceMouseDown (mouseWasDragged)
  56160. {
  56161. }
  56162. MouseEvent::~MouseEvent() throw()
  56163. {
  56164. }
  56165. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56166. {
  56167. if (otherComponent == 0)
  56168. {
  56169. jassertfalse
  56170. return *this;
  56171. }
  56172. return MouseEvent (source, eventComponent->relativePositionToOtherComponent (otherComponent, getPosition()),
  56173. mods, originalComponent, eventTime,
  56174. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56175. mouseDownTime, numberOfClicks, wasMovedSinceMouseDown);
  56176. }
  56177. const MouseEvent MouseEvent::withNewPosition (const Point<int>& newPosition) const throw()
  56178. {
  56179. return MouseEvent (source, newPosition, mods, originalComponent,
  56180. eventTime, mouseDownPos, mouseDownTime,
  56181. numberOfClicks, wasMovedSinceMouseDown);
  56182. }
  56183. bool MouseEvent::mouseWasClicked() const throw()
  56184. {
  56185. return ! wasMovedSinceMouseDown;
  56186. }
  56187. int MouseEvent::getMouseDownX() const throw()
  56188. {
  56189. return mouseDownPos.getX();
  56190. }
  56191. int MouseEvent::getMouseDownY() const throw()
  56192. {
  56193. return mouseDownPos.getY();
  56194. }
  56195. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56196. {
  56197. return mouseDownPos;
  56198. }
  56199. int MouseEvent::getDistanceFromDragStartX() const throw()
  56200. {
  56201. return x - mouseDownPos.getX();
  56202. }
  56203. int MouseEvent::getDistanceFromDragStartY() const throw()
  56204. {
  56205. return y - mouseDownPos.getY();
  56206. }
  56207. int MouseEvent::getDistanceFromDragStart() const throw()
  56208. {
  56209. return mouseDownPos.getDistanceFrom (getPosition());
  56210. }
  56211. const Point<int> MouseEvent::getOffsetFromDragStart() const throw()
  56212. {
  56213. return getPosition() - mouseDownPos;
  56214. }
  56215. int MouseEvent::getLengthOfMousePress() const throw()
  56216. {
  56217. if (mouseDownTime.toMilliseconds() > 0)
  56218. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56219. return 0;
  56220. }
  56221. const Point<int> MouseEvent::getPosition() const throw()
  56222. {
  56223. return Point<int> (x, y);
  56224. }
  56225. int MouseEvent::getScreenX() const
  56226. {
  56227. return getScreenPosition().getX();
  56228. }
  56229. int MouseEvent::getScreenY() const
  56230. {
  56231. return getScreenPosition().getY();
  56232. }
  56233. const Point<int> MouseEvent::getScreenPosition() const
  56234. {
  56235. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56236. }
  56237. int MouseEvent::getMouseDownScreenX() const
  56238. {
  56239. return getMouseDownScreenPosition().getX();
  56240. }
  56241. int MouseEvent::getMouseDownScreenY() const
  56242. {
  56243. return getMouseDownScreenPosition().getY();
  56244. }
  56245. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56246. {
  56247. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56248. }
  56249. static int doubleClickTimeOutMs = 400;
  56250. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56251. {
  56252. doubleClickTimeOutMs = newTime;
  56253. }
  56254. int MouseEvent::getDoubleClickTimeout() throw()
  56255. {
  56256. return doubleClickTimeOutMs;
  56257. }
  56258. END_JUCE_NAMESPACE
  56259. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56260. /*** Start of inlined file: juce_MouseInputSource.cpp ***/
  56261. BEGIN_JUCE_NAMESPACE
  56262. class MouseInputSourceInternal : public AsyncUpdater
  56263. {
  56264. public:
  56265. MouseInputSourceInternal (MouseInputSource& source_, const int index_, const bool isMouseDevice_)
  56266. : index (index_), isMouseDevice (isMouseDevice_), source (source_), lastPeer (0), lastTime (0),
  56267. isUnboundedMouseModeOn (false), isCursorVisibleUntilOffscreen (false), currentCursorHandle (0)
  56268. {
  56269. zerostruct (mouseDowns);
  56270. }
  56271. ~MouseInputSourceInternal()
  56272. {
  56273. }
  56274. bool isDragging() const throw()
  56275. {
  56276. return buttonState.isAnyMouseButtonDown();
  56277. }
  56278. Component* getComponentUnderMouse() const
  56279. {
  56280. return static_cast <Component*> (componentUnderMouse);
  56281. }
  56282. const ModifierKeys getCurrentModifiers() const
  56283. {
  56284. return ModifierKeys::getCurrentModifiers().withoutMouseButtons().withFlags (buttonState.getRawFlags());
  56285. }
  56286. ComponentPeer* getPeer()
  56287. {
  56288. if (! ComponentPeer::isValidPeer (lastPeer))
  56289. lastPeer = 0;
  56290. return lastPeer;
  56291. }
  56292. Component* findComponentAt (const Point<int>& screenPos)
  56293. {
  56294. ComponentPeer* const peer = getPeer();
  56295. if (peer != 0)
  56296. {
  56297. Component* const comp = peer->getComponent();
  56298. const Point<int> relativePos (comp->globalPositionToRelative (screenPos));
  56299. // (the contains() call is needed to test for overlapping desktop windows)
  56300. if (comp->contains (relativePos.getX(), relativePos.getY()))
  56301. return comp->getComponentAt (relativePos);
  56302. }
  56303. return 0;
  56304. }
  56305. const Point<int> getScreenPosition() const throw()
  56306. {
  56307. return lastScreenPos + unboundedMouseOffset;
  56308. }
  56309. void sendMouseEnter (Component* const comp, const Point<int>& screenPos, const int64 time)
  56310. {
  56311. //DBG ("Mouse " + String (source.getIndex()) + " enter: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56312. comp->internalMouseEnter (source, comp->globalPositionToRelative (screenPos), time);
  56313. }
  56314. void sendMouseExit (Component* const comp, const Point<int>& screenPos, const int64 time)
  56315. {
  56316. //DBG ("Mouse " + String (source.getIndex()) + " exit: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56317. comp->internalMouseExit (source, comp->globalPositionToRelative (screenPos), time);
  56318. }
  56319. void sendMouseMove (Component* const comp, const Point<int>& screenPos, const int64 time)
  56320. {
  56321. //DBG ("Mouse " + String (source.getIndex()) + " move: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56322. comp->internalMouseMove (source, comp->globalPositionToRelative (screenPos), time);
  56323. }
  56324. void sendMouseDown (Component* const comp, const Point<int>& screenPos, const int64 time)
  56325. {
  56326. //DBG ("Mouse " + String (source.getIndex()) + " down: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56327. comp->internalMouseDown (source, comp->globalPositionToRelative (screenPos), time);
  56328. }
  56329. void sendMouseDrag (Component* const comp, const Point<int>& screenPos, const int64 time)
  56330. {
  56331. //DBG ("Mouse " + String (source.getIndex()) + " drag: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56332. comp->internalMouseDrag (source, comp->globalPositionToRelative (screenPos), time);
  56333. }
  56334. void sendMouseUp (Component* const comp, const Point<int>& screenPos, const int64 time)
  56335. {
  56336. //DBG ("Mouse " + String (source.getIndex()) + " up: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56337. comp->internalMouseUp (source, comp->globalPositionToRelative (screenPos), time, getCurrentModifiers());
  56338. }
  56339. void sendMouseWheel (Component* const comp, const Point<int>& screenPos, const int64 time, float x, float y)
  56340. {
  56341. //DBG ("Mouse " + String (source.getIndex()) + " wheel: " + comp->globalPositionToRelative (screenPos).toString() + " - Comp: " + String::toHexString ((int) comp));
  56342. comp->internalMouseWheel (source, comp->globalPositionToRelative (screenPos), time, x, y);
  56343. }
  56344. void setButtons (const Point<int>& screenPos, const int64 time, const ModifierKeys& newButtonState)
  56345. {
  56346. if (buttonState != newButtonState)
  56347. {
  56348. // (ignore secondary clicks when there's already a button down)
  56349. if (buttonState.isAnyMouseButtonDown() == newButtonState.isAnyMouseButtonDown())
  56350. {
  56351. buttonState = newButtonState;
  56352. return;
  56353. }
  56354. if (buttonState.isAnyMouseButtonDown())
  56355. {
  56356. Component* const current = getComponentUnderMouse();
  56357. if (current != 0)
  56358. sendMouseUp (current, screenPos + unboundedMouseOffset, time);
  56359. enableUnboundedMouseMovement (false, false);
  56360. }
  56361. buttonState = newButtonState;
  56362. if (buttonState.isAnyMouseButtonDown())
  56363. {
  56364. Desktop::getInstance().incrementMouseClickCounter();
  56365. Component* const current = getComponentUnderMouse();
  56366. if (current != 0)
  56367. {
  56368. registerMouseDown (screenPos, time, current);
  56369. sendMouseDown (current, screenPos, time);
  56370. }
  56371. }
  56372. }
  56373. }
  56374. void setComponentUnderMouse (Component* const newComponent, const Point<int>& screenPos, const int64 time)
  56375. {
  56376. Component* current = getComponentUnderMouse();
  56377. if (newComponent != current)
  56378. {
  56379. Component::SafePointer<Component> safeNewComp (newComponent);
  56380. const ModifierKeys originalButtonState (buttonState);
  56381. if (current != 0)
  56382. {
  56383. setButtons (screenPos, time, ModifierKeys());
  56384. sendMouseExit (current, screenPos, time);
  56385. buttonState = originalButtonState;
  56386. }
  56387. componentUnderMouse = safeNewComp;
  56388. current = getComponentUnderMouse();
  56389. if (current != 0)
  56390. sendMouseEnter (current, screenPos, time);
  56391. revealCursor (false);
  56392. setButtons (screenPos, time, originalButtonState);
  56393. }
  56394. }
  56395. void setPeer (ComponentPeer* const newPeer, const Point<int>& screenPos, const int64 time)
  56396. {
  56397. ModifierKeys::updateCurrentModifiers();
  56398. if (newPeer != lastPeer)
  56399. {
  56400. setComponentUnderMouse (0, screenPos, time);
  56401. lastPeer = newPeer;
  56402. setComponentUnderMouse (findComponentAt (screenPos), screenPos, time);
  56403. }
  56404. }
  56405. void setScreenPos (const Point<int>& newScreenPos, const int64 time, const bool forceUpdate)
  56406. {
  56407. if (! isDragging())
  56408. setComponentUnderMouse (findComponentAt (newScreenPos), newScreenPos, time);
  56409. if (newScreenPos != lastScreenPos || forceUpdate)
  56410. {
  56411. cancelPendingUpdate();
  56412. lastScreenPos = newScreenPos;
  56413. Component* const current = getComponentUnderMouse();
  56414. if (current != 0)
  56415. {
  56416. if (isDragging())
  56417. {
  56418. registerMouseDrag (newScreenPos);
  56419. sendMouseDrag (current, newScreenPos + unboundedMouseOffset, time);
  56420. if (isUnboundedMouseModeOn)
  56421. handleUnboundedDrag (current);
  56422. }
  56423. else
  56424. {
  56425. sendMouseMove (current, newScreenPos, time);
  56426. }
  56427. }
  56428. revealCursor (false);
  56429. }
  56430. }
  56431. void handleEvent (ComponentPeer* const newPeer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& newMods)
  56432. {
  56433. jassert (newPeer != 0);
  56434. lastTime = time;
  56435. const Point<int> screenPos (newPeer->relativePositionToGlobal (positionWithinPeer));
  56436. if (isDragging() && newMods.isAnyMouseButtonDown())
  56437. {
  56438. setScreenPos (screenPos, time, false);
  56439. }
  56440. else
  56441. {
  56442. setPeer (newPeer, screenPos, time);
  56443. ComponentPeer* peer = getPeer();
  56444. if (peer != 0)
  56445. {
  56446. setButtons (screenPos, time, newMods);
  56447. peer = getPeer();
  56448. if (peer != 0)
  56449. setScreenPos (peer->relativePositionToGlobal (positionWithinPeer), time, false);
  56450. }
  56451. }
  56452. }
  56453. void handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, int64 time, float x, float y)
  56454. {
  56455. jassert (peer != 0);
  56456. lastTime = time;
  56457. const Point<int> screenPos (peer->relativePositionToGlobal (positionWithinPeer));
  56458. setPeer (peer, screenPos, time);
  56459. setScreenPos (screenPos, time, false);
  56460. triggerFakeMove();
  56461. if (! isDragging())
  56462. {
  56463. Component* current = getComponentUnderMouse();
  56464. if (current != 0)
  56465. sendMouseWheel (current, screenPos, time, x, y);
  56466. }
  56467. }
  56468. const Time getLastMouseDownTime() const throw()
  56469. {
  56470. return Time (mouseDowns[0].time);
  56471. }
  56472. const Point<int> getLastMouseDownPosition() const throw()
  56473. {
  56474. return mouseDowns[0].position;
  56475. }
  56476. int getNumberOfMultipleClicks() const throw()
  56477. {
  56478. int numClicks = 0;
  56479. if (mouseDowns[0].time != 0)
  56480. {
  56481. if (! mouseMovedSignificantlySincePressed)
  56482. ++numClicks;
  56483. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  56484. {
  56485. if (mouseDowns[0].time - mouseDowns[i].time < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  56486. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  56487. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  56488. && mouseDowns[0].component == mouseDowns[i].component)
  56489. {
  56490. ++numClicks;
  56491. }
  56492. else
  56493. {
  56494. break;
  56495. }
  56496. }
  56497. }
  56498. return numClicks;
  56499. }
  56500. bool hasMouseMovedSignificantlySincePressed() const throw()
  56501. {
  56502. return mouseMovedSignificantlySincePressed
  56503. || lastTime > mouseDowns[0].time + 300;
  56504. }
  56505. void triggerFakeMove()
  56506. {
  56507. triggerAsyncUpdate();
  56508. }
  56509. void handleAsyncUpdate()
  56510. {
  56511. if (! isDragging())
  56512. setScreenPos (Desktop::getMousePosition(), jmax (lastTime, Time::currentTimeMillis()), true);
  56513. }
  56514. void enableUnboundedMouseMovement (bool enable, bool keepCursorVisibleUntilOffscreen)
  56515. {
  56516. enable = enable && isDragging();
  56517. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  56518. if (enable != isUnboundedMouseModeOn)
  56519. {
  56520. if ((! enable) && ((! isCursorVisibleUntilOffscreen) || ! unboundedMouseOffset.isOrigin()))
  56521. {
  56522. // when released, return the mouse to within the component's bounds
  56523. Component* current = getComponentUnderMouse();
  56524. if (current != 0)
  56525. Desktop::setMousePosition (current->getScreenBounds()
  56526. .getConstrainedPoint (current->getMouseXYRelative()));
  56527. }
  56528. isUnboundedMouseModeOn = enable;
  56529. unboundedMouseOffset = Point<int>();
  56530. revealCursor (true);
  56531. }
  56532. }
  56533. void handleUnboundedDrag (Component* current)
  56534. {
  56535. const Rectangle<int> screenArea (current->getParentMonitorArea().expanded (-2, -2));
  56536. if (! screenArea.contains (lastScreenPos))
  56537. {
  56538. const Point<int> componentCentre (current->getScreenBounds().getCentre());
  56539. unboundedMouseOffset += (lastScreenPos - componentCentre);
  56540. Desktop::setMousePosition (componentCentre);
  56541. }
  56542. else if (isCursorVisibleUntilOffscreen
  56543. && (! unboundedMouseOffset.isOrigin())
  56544. && screenArea.contains (lastScreenPos + unboundedMouseOffset))
  56545. {
  56546. Desktop::setMousePosition (lastScreenPos + unboundedMouseOffset);
  56547. unboundedMouseOffset = Point<int>();
  56548. }
  56549. }
  56550. void showMouseCursor (MouseCursor cursor, bool forcedUpdate)
  56551. {
  56552. if (isUnboundedMouseModeOn && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  56553. {
  56554. cursor = MouseCursor::NoCursor;
  56555. forcedUpdate = true;
  56556. }
  56557. if (forcedUpdate || cursor.getHandle() != currentCursorHandle)
  56558. {
  56559. currentCursorHandle = cursor.getHandle();
  56560. cursor.showInWindow (getPeer());
  56561. }
  56562. }
  56563. void hideCursor()
  56564. {
  56565. showMouseCursor (MouseCursor::NoCursor, true);
  56566. }
  56567. void revealCursor (bool forcedUpdate)
  56568. {
  56569. MouseCursor mc (MouseCursor::NormalCursor);
  56570. Component* current = getComponentUnderMouse();
  56571. if (current != 0)
  56572. mc = current->getLookAndFeel().getMouseCursorFor (*current);
  56573. showMouseCursor (mc, forcedUpdate);
  56574. }
  56575. int index;
  56576. bool isMouseDevice;
  56577. Point<int> lastScreenPos;
  56578. ModifierKeys buttonState;
  56579. private:
  56580. MouseInputSource& source;
  56581. Component::SafePointer<Component> componentUnderMouse;
  56582. ComponentPeer* lastPeer;
  56583. Point<int> unboundedMouseOffset;
  56584. bool isUnboundedMouseModeOn, isCursorVisibleUntilOffscreen;
  56585. void* currentCursorHandle;
  56586. struct RecentMouseDown
  56587. {
  56588. Point<int> position;
  56589. int64 time;
  56590. Component* component;
  56591. };
  56592. RecentMouseDown mouseDowns[4];
  56593. bool mouseMovedSignificantlySincePressed;
  56594. int64 lastTime;
  56595. void registerMouseDown (const Point<int>& screenPos, const int64 time, Component* const component) throw()
  56596. {
  56597. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  56598. mouseDowns[i] = mouseDowns[i - 1];
  56599. mouseDowns[0].position = screenPos;
  56600. mouseDowns[0].time = time;
  56601. mouseDowns[0].component = component;
  56602. mouseMovedSignificantlySincePressed = false;
  56603. }
  56604. void registerMouseDrag (const Point<int>& screenPos) throw()
  56605. {
  56606. mouseMovedSignificantlySincePressed = mouseMovedSignificantlySincePressed
  56607. || mouseDowns[0].position.getDistanceFrom (screenPos) >= 4;
  56608. }
  56609. MouseInputSourceInternal (const MouseInputSourceInternal&);
  56610. MouseInputSourceInternal& operator= (const MouseInputSourceInternal&);
  56611. };
  56612. MouseInputSource::MouseInputSource (const int index, const bool isMouseDevice)
  56613. {
  56614. pimpl = new MouseInputSourceInternal (*this, index, isMouseDevice);
  56615. }
  56616. MouseInputSource::~MouseInputSource()
  56617. {
  56618. }
  56619. bool MouseInputSource::isMouse() const { return pimpl->isMouseDevice; }
  56620. bool MouseInputSource::isTouch() const { return ! isMouse(); }
  56621. bool MouseInputSource::canHover() const { return isMouse(); }
  56622. bool MouseInputSource::hasMouseWheel() const { return isMouse(); }
  56623. int MouseInputSource::getIndex() const { return pimpl->index; }
  56624. bool MouseInputSource::isDragging() const { return pimpl->isDragging(); }
  56625. const Point<int> MouseInputSource::getScreenPosition() const { return pimpl->getScreenPosition(); }
  56626. const ModifierKeys MouseInputSource::getCurrentModifiers() const { return pimpl->getCurrentModifiers(); }
  56627. Component* MouseInputSource::getComponentUnderMouse() const { return pimpl->getComponentUnderMouse(); }
  56628. void MouseInputSource::triggerFakeMove() const { pimpl->triggerFakeMove(); }
  56629. int MouseInputSource::getNumberOfMultipleClicks() const throw() { return pimpl->getNumberOfMultipleClicks(); }
  56630. const Time MouseInputSource::getLastMouseDownTime() const throw() { return pimpl->getLastMouseDownTime(); }
  56631. const Point<int> MouseInputSource::getLastMouseDownPosition() const throw() { return pimpl->getLastMouseDownPosition(); }
  56632. bool MouseInputSource::hasMouseMovedSignificantlySincePressed() const throw() { return pimpl->hasMouseMovedSignificantlySincePressed(); }
  56633. bool MouseInputSource::canDoUnboundedMovement() const throw() { return isMouse(); }
  56634. void MouseInputSource::enableUnboundedMouseMovement (bool isEnabled, bool keepCursorVisibleUntilOffscreen) { pimpl->enableUnboundedMouseMovement (isEnabled, keepCursorVisibleUntilOffscreen); }
  56635. bool MouseInputSource::hasMouseCursor() const throw() { return isMouse(); }
  56636. void MouseInputSource::showMouseCursor (const MouseCursor& cursor) { pimpl->showMouseCursor (cursor, false); }
  56637. void MouseInputSource::hideCursor() { pimpl->hideCursor(); }
  56638. void MouseInputSource::revealCursor() { pimpl->revealCursor (false); }
  56639. void MouseInputSource::forceMouseCursorUpdate() { pimpl->revealCursor (true); }
  56640. void MouseInputSource::handleEvent (ComponentPeer* peer, const Point<int>& positionWithinPeer, const int64 time, const ModifierKeys& mods)
  56641. {
  56642. pimpl->handleEvent (peer, positionWithinPeer, time, mods.withOnlyMouseButtons());
  56643. }
  56644. void MouseInputSource::handleWheel (ComponentPeer* const peer, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  56645. {
  56646. pimpl->handleWheel (peer, positionWithinPeer, time, x, y);
  56647. }
  56648. END_JUCE_NAMESPACE
  56649. /*** End of inlined file: juce_MouseInputSource.cpp ***/
  56650. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56651. BEGIN_JUCE_NAMESPACE
  56652. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56653. : source (0),
  56654. hoverTimeMillisecs (hoverTimeMillisecs_),
  56655. hasJustHovered (false)
  56656. {
  56657. internalTimer.owner = this;
  56658. }
  56659. MouseHoverDetector::~MouseHoverDetector()
  56660. {
  56661. setHoverComponent (0);
  56662. }
  56663. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56664. {
  56665. hoverTimeMillisecs = newTimeInMillisecs;
  56666. }
  56667. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56668. {
  56669. if (source != newSourceComponent)
  56670. {
  56671. internalTimer.stopTimer();
  56672. hasJustHovered = false;
  56673. if (source != 0)
  56674. {
  56675. // ! you need to delete the hover detector before deleting its component
  56676. jassert (source->isValidComponent());
  56677. source->removeMouseListener (&internalTimer);
  56678. }
  56679. source = newSourceComponent;
  56680. if (newSourceComponent != 0)
  56681. newSourceComponent->addMouseListener (&internalTimer, false);
  56682. }
  56683. }
  56684. void MouseHoverDetector::hoverTimerCallback()
  56685. {
  56686. internalTimer.stopTimer();
  56687. if (source != 0)
  56688. {
  56689. const Point<int> pos (source->getMouseXYRelative());
  56690. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56691. {
  56692. hasJustHovered = true;
  56693. mouseHovered (pos.getX(), pos.getY());
  56694. }
  56695. }
  56696. }
  56697. void MouseHoverDetector::checkJustHoveredCallback()
  56698. {
  56699. if (hasJustHovered)
  56700. {
  56701. hasJustHovered = false;
  56702. mouseMovedAfterHover();
  56703. }
  56704. }
  56705. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  56706. {
  56707. owner->hoverTimerCallback();
  56708. }
  56709. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  56710. {
  56711. stopTimer();
  56712. owner->checkJustHoveredCallback();
  56713. }
  56714. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  56715. {
  56716. stopTimer();
  56717. owner->checkJustHoveredCallback();
  56718. }
  56719. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  56720. {
  56721. stopTimer();
  56722. owner->checkJustHoveredCallback();
  56723. }
  56724. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  56725. {
  56726. stopTimer();
  56727. owner->checkJustHoveredCallback();
  56728. }
  56729. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  56730. {
  56731. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  56732. {
  56733. lastX = e.x;
  56734. lastY = e.y;
  56735. if (owner->source != 0)
  56736. startTimer (owner->hoverTimeMillisecs);
  56737. owner->checkJustHoveredCallback();
  56738. }
  56739. }
  56740. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  56741. {
  56742. stopTimer();
  56743. owner->checkJustHoveredCallback();
  56744. }
  56745. END_JUCE_NAMESPACE
  56746. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  56747. /*** Start of inlined file: juce_MouseListener.cpp ***/
  56748. BEGIN_JUCE_NAMESPACE
  56749. void MouseListener::mouseEnter (const MouseEvent&)
  56750. {
  56751. }
  56752. void MouseListener::mouseExit (const MouseEvent&)
  56753. {
  56754. }
  56755. void MouseListener::mouseDown (const MouseEvent&)
  56756. {
  56757. }
  56758. void MouseListener::mouseUp (const MouseEvent&)
  56759. {
  56760. }
  56761. void MouseListener::mouseDrag (const MouseEvent&)
  56762. {
  56763. }
  56764. void MouseListener::mouseMove (const MouseEvent&)
  56765. {
  56766. }
  56767. void MouseListener::mouseDoubleClick (const MouseEvent&)
  56768. {
  56769. }
  56770. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  56771. {
  56772. }
  56773. END_JUCE_NAMESPACE
  56774. /*** End of inlined file: juce_MouseListener.cpp ***/
  56775. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56776. BEGIN_JUCE_NAMESPACE
  56777. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  56778. const String& buttonTextWhenTrue,
  56779. const String& buttonTextWhenFalse)
  56780. : PropertyComponent (name),
  56781. onText (buttonTextWhenTrue),
  56782. offText (buttonTextWhenFalse)
  56783. {
  56784. createButton();
  56785. button->addButtonListener (this);
  56786. }
  56787. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  56788. const String& name,
  56789. const String& buttonText)
  56790. : PropertyComponent (name),
  56791. onText (buttonText),
  56792. offText (buttonText)
  56793. {
  56794. createButton();
  56795. button->setButtonText (buttonText);
  56796. button->getToggleStateValue().referTo (valueToControl);
  56797. button->setClickingTogglesState (true);
  56798. }
  56799. BooleanPropertyComponent::~BooleanPropertyComponent()
  56800. {
  56801. deleteAllChildren();
  56802. }
  56803. void BooleanPropertyComponent::createButton()
  56804. {
  56805. addAndMakeVisible (button = new ToggleButton (String::empty));
  56806. button->setClickingTogglesState (false);
  56807. }
  56808. void BooleanPropertyComponent::setState (const bool newState)
  56809. {
  56810. button->setToggleState (newState, true);
  56811. }
  56812. bool BooleanPropertyComponent::getState() const
  56813. {
  56814. return button->getToggleState();
  56815. }
  56816. void BooleanPropertyComponent::paint (Graphics& g)
  56817. {
  56818. PropertyComponent::paint (g);
  56819. const Rectangle<int> r (button->getBounds());
  56820. g.setColour (Colours::white);
  56821. g.fillRect (r);
  56822. g.setColour (findColour (ComboBox::outlineColourId));
  56823. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  56824. }
  56825. void BooleanPropertyComponent::refresh()
  56826. {
  56827. button->setToggleState (getState(), false);
  56828. button->setButtonText (button->getToggleState() ? onText : offText);
  56829. }
  56830. void BooleanPropertyComponent::buttonClicked (Button*)
  56831. {
  56832. setState (! getState());
  56833. }
  56834. END_JUCE_NAMESPACE
  56835. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  56836. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56837. BEGIN_JUCE_NAMESPACE
  56838. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  56839. const bool triggerOnMouseDown)
  56840. : PropertyComponent (name)
  56841. {
  56842. addAndMakeVisible (button = new TextButton (String::empty));
  56843. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  56844. button->addButtonListener (this);
  56845. }
  56846. ButtonPropertyComponent::~ButtonPropertyComponent()
  56847. {
  56848. deleteAllChildren();
  56849. }
  56850. void ButtonPropertyComponent::refresh()
  56851. {
  56852. button->setButtonText (getButtonText());
  56853. }
  56854. void ButtonPropertyComponent::buttonClicked (Button*)
  56855. {
  56856. buttonClicked();
  56857. }
  56858. END_JUCE_NAMESPACE
  56859. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  56860. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56861. BEGIN_JUCE_NAMESPACE
  56862. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  56863. : PropertyComponent (name),
  56864. comboBox (0)
  56865. {
  56866. }
  56867. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  56868. const String& name,
  56869. const StringArray& choices_,
  56870. const Array <int>* choiceIDs)
  56871. : PropertyComponent (name),
  56872. choices (choices_),
  56873. comboBox (0)
  56874. {
  56875. createComboBox (choiceIDs);
  56876. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  56877. }
  56878. ChoicePropertyComponent::~ChoicePropertyComponent()
  56879. {
  56880. deleteAllChildren();
  56881. }
  56882. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  56883. {
  56884. // The array of IDs must contain the same number of values as the choices list!
  56885. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  56886. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  56887. for (int i = 0; i < choices.size(); ++i)
  56888. {
  56889. if (choices[i].isNotEmpty())
  56890. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  56891. : ((*choiceIDs)[i]));
  56892. else
  56893. comboBox->addSeparator();
  56894. }
  56895. comboBox->setEditableText (false);
  56896. }
  56897. void ChoicePropertyComponent::setIndex (const int newIndex)
  56898. {
  56899. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  56900. }
  56901. int ChoicePropertyComponent::getIndex() const
  56902. {
  56903. return comboBox->getSelectedItemIndex();
  56904. }
  56905. const StringArray& ChoicePropertyComponent::getChoices() const
  56906. {
  56907. return choices;
  56908. }
  56909. void ChoicePropertyComponent::refresh()
  56910. {
  56911. if (comboBox == 0)
  56912. {
  56913. createComboBox (0);
  56914. comboBox->addListener (this);
  56915. }
  56916. comboBox->setSelectedId (getIndex() + 1, true);
  56917. }
  56918. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  56919. {
  56920. const int newIndex = comboBox->getSelectedId() - 1;
  56921. if (newIndex != getIndex())
  56922. setIndex (newIndex);
  56923. }
  56924. END_JUCE_NAMESPACE
  56925. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  56926. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  56927. BEGIN_JUCE_NAMESPACE
  56928. PropertyComponent::PropertyComponent (const String& name,
  56929. const int preferredHeight_)
  56930. : Component (name),
  56931. preferredHeight (preferredHeight_)
  56932. {
  56933. jassert (name.isNotEmpty());
  56934. }
  56935. PropertyComponent::~PropertyComponent()
  56936. {
  56937. }
  56938. void PropertyComponent::paint (Graphics& g)
  56939. {
  56940. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  56941. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  56942. }
  56943. void PropertyComponent::resized()
  56944. {
  56945. if (getNumChildComponents() > 0)
  56946. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  56947. }
  56948. void PropertyComponent::enablementChanged()
  56949. {
  56950. repaint();
  56951. }
  56952. END_JUCE_NAMESPACE
  56953. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  56954. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  56955. BEGIN_JUCE_NAMESPACE
  56956. class PropertyPanel::PropertyHolderComponent : public Component
  56957. {
  56958. public:
  56959. PropertyHolderComponent()
  56960. {
  56961. }
  56962. ~PropertyHolderComponent()
  56963. {
  56964. deleteAllChildren();
  56965. }
  56966. void paint (Graphics&)
  56967. {
  56968. }
  56969. void updateLayout (int width);
  56970. void refreshAll() const;
  56971. private:
  56972. PropertyHolderComponent (const PropertyHolderComponent&);
  56973. PropertyHolderComponent& operator= (const PropertyHolderComponent&);
  56974. };
  56975. class PropertySectionComponent : public Component
  56976. {
  56977. public:
  56978. PropertySectionComponent (const String& sectionTitle,
  56979. const Array <PropertyComponent*>& newProperties,
  56980. const bool open)
  56981. : Component (sectionTitle),
  56982. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  56983. isOpen_ (open)
  56984. {
  56985. for (int i = newProperties.size(); --i >= 0;)
  56986. {
  56987. addAndMakeVisible (newProperties.getUnchecked(i));
  56988. newProperties.getUnchecked(i)->refresh();
  56989. }
  56990. }
  56991. ~PropertySectionComponent()
  56992. {
  56993. deleteAllChildren();
  56994. }
  56995. void paint (Graphics& g)
  56996. {
  56997. if (titleHeight > 0)
  56998. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  56999. }
  57000. void resized()
  57001. {
  57002. int y = titleHeight;
  57003. for (int i = getNumChildComponents(); --i >= 0;)
  57004. {
  57005. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57006. if (pec != 0)
  57007. {
  57008. const int prefH = pec->getPreferredHeight();
  57009. pec->setBounds (1, y, getWidth() - 2, prefH);
  57010. y += prefH;
  57011. }
  57012. }
  57013. }
  57014. int getPreferredHeight() const
  57015. {
  57016. int y = titleHeight;
  57017. if (isOpen())
  57018. {
  57019. for (int i = 0; i < getNumChildComponents(); ++i)
  57020. {
  57021. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57022. if (pec != 0)
  57023. y += pec->getPreferredHeight();
  57024. }
  57025. }
  57026. return y;
  57027. }
  57028. void setOpen (const bool open)
  57029. {
  57030. if (isOpen_ != open)
  57031. {
  57032. isOpen_ = open;
  57033. for (int i = 0; i < getNumChildComponents(); ++i)
  57034. {
  57035. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57036. if (pec != 0)
  57037. pec->setVisible (open);
  57038. }
  57039. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57040. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57041. if (pp != 0)
  57042. pp->resized();
  57043. }
  57044. }
  57045. bool isOpen() const
  57046. {
  57047. return isOpen_;
  57048. }
  57049. void refreshAll() const
  57050. {
  57051. for (int i = 0; i < getNumChildComponents(); ++i)
  57052. {
  57053. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57054. if (pec != 0)
  57055. pec->refresh();
  57056. }
  57057. }
  57058. void mouseDown (const MouseEvent&)
  57059. {
  57060. }
  57061. void mouseUp (const MouseEvent& e)
  57062. {
  57063. if (e.getMouseDownX() < titleHeight
  57064. && e.x < titleHeight
  57065. && e.y < titleHeight
  57066. && e.getNumberOfClicks() != 2)
  57067. {
  57068. setOpen (! isOpen());
  57069. }
  57070. }
  57071. void mouseDoubleClick (const MouseEvent& e)
  57072. {
  57073. if (e.y < titleHeight)
  57074. setOpen (! isOpen());
  57075. }
  57076. private:
  57077. int titleHeight;
  57078. bool isOpen_;
  57079. PropertySectionComponent (const PropertySectionComponent&);
  57080. PropertySectionComponent& operator= (const PropertySectionComponent&);
  57081. };
  57082. void PropertyPanel::PropertyHolderComponent::updateLayout (const int width)
  57083. {
  57084. int y = 0;
  57085. for (int i = getNumChildComponents(); --i >= 0;)
  57086. {
  57087. PropertySectionComponent* const section
  57088. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57089. if (section != 0)
  57090. {
  57091. const int prefH = section->getPreferredHeight();
  57092. section->setBounds (0, y, width, prefH);
  57093. y += prefH;
  57094. }
  57095. }
  57096. setSize (width, y);
  57097. repaint();
  57098. }
  57099. void PropertyPanel::PropertyHolderComponent::refreshAll() const
  57100. {
  57101. for (int i = getNumChildComponents(); --i >= 0;)
  57102. {
  57103. PropertySectionComponent* const section
  57104. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57105. if (section != 0)
  57106. section->refreshAll();
  57107. }
  57108. }
  57109. PropertyPanel::PropertyPanel()
  57110. {
  57111. messageWhenEmpty = TRANS("(nothing selected)");
  57112. addAndMakeVisible (viewport = new Viewport());
  57113. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57114. viewport->setFocusContainer (true);
  57115. }
  57116. PropertyPanel::~PropertyPanel()
  57117. {
  57118. clear();
  57119. deleteAllChildren();
  57120. }
  57121. void PropertyPanel::paint (Graphics& g)
  57122. {
  57123. if (propertyHolderComponent->getNumChildComponents() == 0)
  57124. {
  57125. g.setColour (Colours::black.withAlpha (0.5f));
  57126. g.setFont (14.0f);
  57127. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57128. Justification::centred, true);
  57129. }
  57130. }
  57131. void PropertyPanel::resized()
  57132. {
  57133. viewport->setBounds (0, 0, getWidth(), getHeight());
  57134. updatePropHolderLayout();
  57135. }
  57136. void PropertyPanel::clear()
  57137. {
  57138. if (propertyHolderComponent->getNumChildComponents() > 0)
  57139. {
  57140. propertyHolderComponent->deleteAllChildren();
  57141. repaint();
  57142. }
  57143. }
  57144. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57145. {
  57146. if (propertyHolderComponent->getNumChildComponents() == 0)
  57147. repaint();
  57148. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57149. newProperties,
  57150. true), 0);
  57151. updatePropHolderLayout();
  57152. }
  57153. void PropertyPanel::addSection (const String& sectionTitle,
  57154. const Array <PropertyComponent*>& newProperties,
  57155. const bool shouldBeOpen)
  57156. {
  57157. jassert (sectionTitle.isNotEmpty());
  57158. if (propertyHolderComponent->getNumChildComponents() == 0)
  57159. repaint();
  57160. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57161. newProperties,
  57162. shouldBeOpen), 0);
  57163. updatePropHolderLayout();
  57164. }
  57165. void PropertyPanel::updatePropHolderLayout() const
  57166. {
  57167. const int maxWidth = viewport->getMaximumVisibleWidth();
  57168. propertyHolderComponent->updateLayout (maxWidth);
  57169. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57170. if (maxWidth != newMaxWidth)
  57171. {
  57172. // need to do this twice because of scrollbars changing the size, etc.
  57173. propertyHolderComponent->updateLayout (newMaxWidth);
  57174. }
  57175. }
  57176. void PropertyPanel::refreshAll() const
  57177. {
  57178. propertyHolderComponent->refreshAll();
  57179. }
  57180. const StringArray PropertyPanel::getSectionNames() const
  57181. {
  57182. StringArray s;
  57183. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57184. {
  57185. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57186. if (section != 0 && section->getName().isNotEmpty())
  57187. s.add (section->getName());
  57188. }
  57189. return s;
  57190. }
  57191. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57192. {
  57193. int index = 0;
  57194. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57195. {
  57196. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57197. if (section != 0 && section->getName().isNotEmpty())
  57198. {
  57199. if (index == sectionIndex)
  57200. return section->isOpen();
  57201. ++index;
  57202. }
  57203. }
  57204. return false;
  57205. }
  57206. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57207. {
  57208. int index = 0;
  57209. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57210. {
  57211. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57212. if (section != 0 && section->getName().isNotEmpty())
  57213. {
  57214. if (index == sectionIndex)
  57215. {
  57216. section->setOpen (shouldBeOpen);
  57217. break;
  57218. }
  57219. ++index;
  57220. }
  57221. }
  57222. }
  57223. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57224. {
  57225. int index = 0;
  57226. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57227. {
  57228. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57229. if (section != 0 && section->getName().isNotEmpty())
  57230. {
  57231. if (index == sectionIndex)
  57232. {
  57233. section->setEnabled (shouldBeEnabled);
  57234. break;
  57235. }
  57236. ++index;
  57237. }
  57238. }
  57239. }
  57240. XmlElement* PropertyPanel::getOpennessState() const
  57241. {
  57242. XmlElement* const xml = new XmlElement ("PROPERTYPANELSTATE");
  57243. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57244. const StringArray sections (getSectionNames());
  57245. for (int i = 0; i < sections.size(); ++i)
  57246. {
  57247. if (sections[i].isNotEmpty())
  57248. {
  57249. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57250. e->setAttribute ("name", sections[i]);
  57251. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57252. }
  57253. }
  57254. return xml;
  57255. }
  57256. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57257. {
  57258. if (xml.hasTagName ("PROPERTYPANELSTATE"))
  57259. {
  57260. const StringArray sections (getSectionNames());
  57261. forEachXmlChildElementWithTagName (xml, e, "SECTION")
  57262. {
  57263. setSectionOpen (sections.indexOf (e->getStringAttribute ("name")),
  57264. e->getBoolAttribute ("open"));
  57265. }
  57266. viewport->setViewPosition (viewport->getViewPositionX(),
  57267. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57268. }
  57269. }
  57270. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57271. {
  57272. if (messageWhenEmpty != newMessage)
  57273. {
  57274. messageWhenEmpty = newMessage;
  57275. repaint();
  57276. }
  57277. }
  57278. const String& PropertyPanel::getMessageWhenEmpty() const
  57279. {
  57280. return messageWhenEmpty;
  57281. }
  57282. END_JUCE_NAMESPACE
  57283. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57284. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57285. BEGIN_JUCE_NAMESPACE
  57286. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57287. const double rangeMin,
  57288. const double rangeMax,
  57289. const double interval,
  57290. const double skewFactor)
  57291. : PropertyComponent (name)
  57292. {
  57293. addAndMakeVisible (slider = new Slider (name));
  57294. slider->setRange (rangeMin, rangeMax, interval);
  57295. slider->setSkewFactor (skewFactor);
  57296. slider->setSliderStyle (Slider::LinearBar);
  57297. slider->addListener (this);
  57298. }
  57299. SliderPropertyComponent::SliderPropertyComponent (const Value& valueToControl,
  57300. const String& name,
  57301. const double rangeMin,
  57302. const double rangeMax,
  57303. const double interval,
  57304. const double skewFactor)
  57305. : PropertyComponent (name)
  57306. {
  57307. addAndMakeVisible (slider = new Slider (name));
  57308. slider->setRange (rangeMin, rangeMax, interval);
  57309. slider->setSkewFactor (skewFactor);
  57310. slider->setSliderStyle (Slider::LinearBar);
  57311. slider->getValueObject().referTo (valueToControl);
  57312. }
  57313. SliderPropertyComponent::~SliderPropertyComponent()
  57314. {
  57315. deleteAllChildren();
  57316. }
  57317. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57318. {
  57319. }
  57320. double SliderPropertyComponent::getValue() const
  57321. {
  57322. return slider->getValue();
  57323. }
  57324. void SliderPropertyComponent::refresh()
  57325. {
  57326. slider->setValue (getValue(), false);
  57327. }
  57328. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57329. {
  57330. if (getValue() != slider->getValue())
  57331. setValue (slider->getValue());
  57332. }
  57333. END_JUCE_NAMESPACE
  57334. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57335. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57336. BEGIN_JUCE_NAMESPACE
  57337. class TextPropLabel : public Label
  57338. {
  57339. TextPropertyComponent& owner;
  57340. int maxChars;
  57341. bool isMultiline;
  57342. public:
  57343. TextPropLabel (TextPropertyComponent& owner_,
  57344. const int maxChars_, const bool isMultiline_)
  57345. : Label (String::empty, String::empty),
  57346. owner (owner_),
  57347. maxChars (maxChars_),
  57348. isMultiline (isMultiline_)
  57349. {
  57350. setEditable (true, true, false);
  57351. setColour (backgroundColourId, Colours::white);
  57352. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57353. }
  57354. ~TextPropLabel()
  57355. {
  57356. }
  57357. TextEditor* createEditorComponent()
  57358. {
  57359. TextEditor* const textEditor = Label::createEditorComponent();
  57360. textEditor->setInputRestrictions (maxChars);
  57361. if (isMultiline)
  57362. {
  57363. textEditor->setMultiLine (true, true);
  57364. textEditor->setReturnKeyStartsNewLine (true);
  57365. }
  57366. return textEditor;
  57367. }
  57368. void textWasEdited()
  57369. {
  57370. owner.textWasEdited();
  57371. }
  57372. };
  57373. TextPropertyComponent::TextPropertyComponent (const String& name,
  57374. const int maxNumChars,
  57375. const bool isMultiLine)
  57376. : PropertyComponent (name)
  57377. {
  57378. createEditor (maxNumChars, isMultiLine);
  57379. }
  57380. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57381. const String& name,
  57382. const int maxNumChars,
  57383. const bool isMultiLine)
  57384. : PropertyComponent (name)
  57385. {
  57386. createEditor (maxNumChars, isMultiLine);
  57387. textEditor->getTextValue().referTo (valueToControl);
  57388. }
  57389. TextPropertyComponent::~TextPropertyComponent()
  57390. {
  57391. deleteAllChildren();
  57392. }
  57393. void TextPropertyComponent::setText (const String& newText)
  57394. {
  57395. textEditor->setText (newText, true);
  57396. }
  57397. const String TextPropertyComponent::getText() const
  57398. {
  57399. return textEditor->getText();
  57400. }
  57401. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57402. {
  57403. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57404. if (isMultiLine)
  57405. {
  57406. textEditor->setJustificationType (Justification::topLeft);
  57407. preferredHeight = 120;
  57408. }
  57409. }
  57410. void TextPropertyComponent::refresh()
  57411. {
  57412. textEditor->setText (getText(), false);
  57413. }
  57414. void TextPropertyComponent::textWasEdited()
  57415. {
  57416. const String newText (textEditor->getText());
  57417. if (getText() != newText)
  57418. setText (newText);
  57419. }
  57420. END_JUCE_NAMESPACE
  57421. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57422. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57423. BEGIN_JUCE_NAMESPACE
  57424. class SimpleDeviceManagerInputLevelMeter : public Component,
  57425. public Timer
  57426. {
  57427. public:
  57428. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57429. : manager (manager_),
  57430. level (0)
  57431. {
  57432. startTimer (50);
  57433. manager->enableInputLevelMeasurement (true);
  57434. }
  57435. ~SimpleDeviceManagerInputLevelMeter()
  57436. {
  57437. manager->enableInputLevelMeasurement (false);
  57438. }
  57439. void timerCallback()
  57440. {
  57441. const float newLevel = (float) manager->getCurrentInputLevel();
  57442. if (fabsf (level - newLevel) > 0.005f)
  57443. {
  57444. level = newLevel;
  57445. repaint();
  57446. }
  57447. }
  57448. void paint (Graphics& g)
  57449. {
  57450. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57451. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57452. }
  57453. private:
  57454. AudioDeviceManager* const manager;
  57455. float level;
  57456. SimpleDeviceManagerInputLevelMeter (const SimpleDeviceManagerInputLevelMeter&);
  57457. SimpleDeviceManagerInputLevelMeter& operator= (const SimpleDeviceManagerInputLevelMeter&);
  57458. };
  57459. class MidiInputSelectorComponentListBox : public ListBox,
  57460. public ListBoxModel
  57461. {
  57462. public:
  57463. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57464. const String& noItemsMessage_,
  57465. const int minNumber_,
  57466. const int maxNumber_)
  57467. : ListBox (String::empty, 0),
  57468. deviceManager (deviceManager_),
  57469. noItemsMessage (noItemsMessage_),
  57470. minNumber (minNumber_),
  57471. maxNumber (maxNumber_)
  57472. {
  57473. items = MidiInput::getDevices();
  57474. setModel (this);
  57475. setOutlineThickness (1);
  57476. }
  57477. ~MidiInputSelectorComponentListBox()
  57478. {
  57479. }
  57480. int getNumRows()
  57481. {
  57482. return items.size();
  57483. }
  57484. void paintListBoxItem (int row,
  57485. Graphics& g,
  57486. int width, int height,
  57487. bool rowIsSelected)
  57488. {
  57489. if (((unsigned int) row) < (unsigned int) items.size())
  57490. {
  57491. if (rowIsSelected)
  57492. g.fillAll (findColour (TextEditor::highlightColourId)
  57493. .withMultipliedAlpha (0.3f));
  57494. const String item (items [row]);
  57495. bool enabled = deviceManager.isMidiInputEnabled (item);
  57496. const int x = getTickX();
  57497. const float tickW = height * 0.75f;
  57498. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57499. enabled, true, true, false);
  57500. g.setFont (height * 0.6f);
  57501. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57502. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57503. }
  57504. }
  57505. void listBoxItemClicked (int row, const MouseEvent& e)
  57506. {
  57507. selectRow (row);
  57508. if (e.x < getTickX())
  57509. flipEnablement (row);
  57510. }
  57511. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57512. {
  57513. flipEnablement (row);
  57514. }
  57515. void returnKeyPressed (int row)
  57516. {
  57517. flipEnablement (row);
  57518. }
  57519. void paint (Graphics& g)
  57520. {
  57521. ListBox::paint (g);
  57522. if (items.size() == 0)
  57523. {
  57524. g.setColour (Colours::grey);
  57525. g.setFont (13.0f);
  57526. g.drawText (noItemsMessage,
  57527. 0, 0, getWidth(), getHeight() / 2,
  57528. Justification::centred, true);
  57529. }
  57530. }
  57531. int getBestHeight (const int preferredHeight)
  57532. {
  57533. const int extra = getOutlineThickness() * 2;
  57534. return jmax (getRowHeight() * 2 + extra,
  57535. jmin (getRowHeight() * getNumRows() + extra,
  57536. preferredHeight));
  57537. }
  57538. juce_UseDebuggingNewOperator
  57539. private:
  57540. AudioDeviceManager& deviceManager;
  57541. const String noItemsMessage;
  57542. StringArray items;
  57543. int minNumber, maxNumber;
  57544. void flipEnablement (const int row)
  57545. {
  57546. if (((unsigned int) row) < (unsigned int) items.size())
  57547. {
  57548. const String item (items [row]);
  57549. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57550. }
  57551. }
  57552. int getTickX() const
  57553. {
  57554. return getRowHeight() + 5;
  57555. }
  57556. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57557. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57558. };
  57559. class AudioDeviceSettingsPanel : public Component,
  57560. public ComboBoxListener,
  57561. public ChangeListener,
  57562. public ButtonListener
  57563. {
  57564. public:
  57565. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57566. AudioIODeviceType::DeviceSetupDetails& setup_,
  57567. const bool hideAdvancedOptionsWithButton)
  57568. : type (type_),
  57569. setup (setup_)
  57570. {
  57571. sampleRateDropDown = 0;
  57572. sampleRateLabel = 0;
  57573. bufferSizeDropDown = 0;
  57574. bufferSizeLabel = 0;
  57575. outputDeviceDropDown = 0;
  57576. outputDeviceLabel = 0;
  57577. inputDeviceDropDown = 0;
  57578. inputDeviceLabel = 0;
  57579. testButton = 0;
  57580. inputLevelMeter = 0;
  57581. showUIButton = 0;
  57582. inputChanList = 0;
  57583. outputChanList = 0;
  57584. inputChanLabel = 0;
  57585. outputChanLabel = 0;
  57586. showAdvancedSettingsButton = 0;
  57587. if (hideAdvancedOptionsWithButton)
  57588. {
  57589. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57590. showAdvancedSettingsButton->addButtonListener (this);
  57591. }
  57592. type->scanForDevices();
  57593. setup.manager->addChangeListener (this);
  57594. changeListenerCallback (0);
  57595. }
  57596. ~AudioDeviceSettingsPanel()
  57597. {
  57598. setup.manager->removeChangeListener (this);
  57599. deleteAndZero (outputDeviceLabel);
  57600. deleteAndZero (inputDeviceLabel);
  57601. deleteAndZero (sampleRateLabel);
  57602. deleteAndZero (bufferSizeLabel);
  57603. deleteAndZero (showUIButton);
  57604. deleteAndZero (inputChanLabel);
  57605. deleteAndZero (outputChanLabel);
  57606. deleteAndZero (showAdvancedSettingsButton);
  57607. deleteAllChildren();
  57608. }
  57609. void resized()
  57610. {
  57611. const int lx = proportionOfWidth (0.35f);
  57612. const int w = proportionOfWidth (0.4f);
  57613. const int h = 24;
  57614. const int space = 6;
  57615. const int dh = h + space;
  57616. int y = 0;
  57617. if (outputDeviceDropDown != 0)
  57618. {
  57619. outputDeviceDropDown->setBounds (lx, y, w, h);
  57620. if (testButton != 0)
  57621. testButton->setBounds (proportionOfWidth (0.77f),
  57622. outputDeviceDropDown->getY(),
  57623. proportionOfWidth (0.18f),
  57624. h);
  57625. y += dh;
  57626. }
  57627. if (inputDeviceDropDown != 0)
  57628. {
  57629. inputDeviceDropDown->setBounds (lx, y, w, h);
  57630. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57631. inputDeviceDropDown->getY(),
  57632. proportionOfWidth (0.18f),
  57633. h);
  57634. y += dh;
  57635. }
  57636. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57637. if (outputChanList != 0)
  57638. {
  57639. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57640. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57641. y += bh + space;
  57642. }
  57643. if (inputChanList != 0)
  57644. {
  57645. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57646. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57647. y += bh + space;
  57648. }
  57649. y += space * 2;
  57650. if (showAdvancedSettingsButton != 0)
  57651. {
  57652. showAdvancedSettingsButton->changeWidthToFitText (h);
  57653. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57654. }
  57655. if (sampleRateDropDown != 0)
  57656. {
  57657. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57658. || ! showAdvancedSettingsButton->isVisible());
  57659. sampleRateDropDown->setBounds (lx, y, w, h);
  57660. y += dh;
  57661. }
  57662. if (bufferSizeDropDown != 0)
  57663. {
  57664. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57665. || ! showAdvancedSettingsButton->isVisible());
  57666. bufferSizeDropDown->setBounds (lx, y, w, h);
  57667. y += dh;
  57668. }
  57669. if (showUIButton != 0)
  57670. {
  57671. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57672. || ! showAdvancedSettingsButton->isVisible());
  57673. showUIButton->changeWidthToFitText (h);
  57674. showUIButton->setTopLeftPosition (lx, y);
  57675. }
  57676. }
  57677. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57678. {
  57679. if (comboBoxThatHasChanged == 0)
  57680. return;
  57681. AudioDeviceManager::AudioDeviceSetup config;
  57682. setup.manager->getAudioDeviceSetup (config);
  57683. String error;
  57684. if (comboBoxThatHasChanged == outputDeviceDropDown
  57685. || comboBoxThatHasChanged == inputDeviceDropDown)
  57686. {
  57687. if (outputDeviceDropDown != 0)
  57688. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57689. : outputDeviceDropDown->getText();
  57690. if (inputDeviceDropDown != 0)
  57691. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57692. : inputDeviceDropDown->getText();
  57693. if (! type->hasSeparateInputsAndOutputs())
  57694. config.inputDeviceName = config.outputDeviceName;
  57695. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57696. config.useDefaultInputChannels = true;
  57697. else
  57698. config.useDefaultOutputChannels = true;
  57699. error = setup.manager->setAudioDeviceSetup (config, true);
  57700. showCorrectDeviceName (inputDeviceDropDown, true);
  57701. showCorrectDeviceName (outputDeviceDropDown, false);
  57702. updateControlPanelButton();
  57703. resized();
  57704. }
  57705. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57706. {
  57707. if (sampleRateDropDown->getSelectedId() > 0)
  57708. {
  57709. config.sampleRate = sampleRateDropDown->getSelectedId();
  57710. error = setup.manager->setAudioDeviceSetup (config, true);
  57711. }
  57712. }
  57713. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  57714. {
  57715. if (bufferSizeDropDown->getSelectedId() > 0)
  57716. {
  57717. config.bufferSize = bufferSizeDropDown->getSelectedId();
  57718. error = setup.manager->setAudioDeviceSetup (config, true);
  57719. }
  57720. }
  57721. if (error.isNotEmpty())
  57722. {
  57723. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  57724. "Error when trying to open audio device!",
  57725. error);
  57726. }
  57727. }
  57728. void buttonClicked (Button* button)
  57729. {
  57730. if (button == showAdvancedSettingsButton)
  57731. {
  57732. showAdvancedSettingsButton->setVisible (false);
  57733. resized();
  57734. }
  57735. else if (button == showUIButton)
  57736. {
  57737. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  57738. if (device != 0 && device->showControlPanel())
  57739. {
  57740. setup.manager->closeAudioDevice();
  57741. setup.manager->restartLastAudioDevice();
  57742. getTopLevelComponent()->toFront (true);
  57743. }
  57744. }
  57745. else if (button == testButton && testButton != 0)
  57746. {
  57747. setup.manager->playTestSound();
  57748. }
  57749. }
  57750. void updateControlPanelButton()
  57751. {
  57752. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57753. deleteAndZero (showUIButton);
  57754. if (currentDevice != 0 && currentDevice->hasControlPanel())
  57755. {
  57756. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  57757. TRANS ("opens the device's own control panel")));
  57758. showUIButton->addButtonListener (this);
  57759. }
  57760. resized();
  57761. }
  57762. void changeListenerCallback (void*)
  57763. {
  57764. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57765. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  57766. {
  57767. if (outputDeviceDropDown == 0)
  57768. {
  57769. outputDeviceDropDown = new ComboBox (String::empty);
  57770. outputDeviceDropDown->addListener (this);
  57771. addAndMakeVisible (outputDeviceDropDown);
  57772. outputDeviceLabel = new Label (String::empty,
  57773. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  57774. : TRANS ("device:"));
  57775. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  57776. if (setup.maxNumOutputChannels > 0)
  57777. {
  57778. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  57779. testButton->addButtonListener (this);
  57780. }
  57781. }
  57782. addNamesToDeviceBox (*outputDeviceDropDown, false);
  57783. }
  57784. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  57785. {
  57786. if (inputDeviceDropDown == 0)
  57787. {
  57788. inputDeviceDropDown = new ComboBox (String::empty);
  57789. inputDeviceDropDown->addListener (this);
  57790. addAndMakeVisible (inputDeviceDropDown);
  57791. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  57792. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  57793. addAndMakeVisible (inputLevelMeter
  57794. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  57795. }
  57796. addNamesToDeviceBox (*inputDeviceDropDown, true);
  57797. }
  57798. updateControlPanelButton();
  57799. showCorrectDeviceName (inputDeviceDropDown, true);
  57800. showCorrectDeviceName (outputDeviceDropDown, false);
  57801. if (currentDevice != 0)
  57802. {
  57803. if (setup.maxNumOutputChannels > 0
  57804. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  57805. {
  57806. if (outputChanList == 0)
  57807. {
  57808. addAndMakeVisible (outputChanList
  57809. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  57810. TRANS ("(no audio output channels found)")));
  57811. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  57812. outputChanLabel->attachToComponent (outputChanList, true);
  57813. }
  57814. outputChanList->refresh();
  57815. }
  57816. else
  57817. {
  57818. deleteAndZero (outputChanLabel);
  57819. deleteAndZero (outputChanList);
  57820. }
  57821. if (setup.maxNumInputChannels > 0
  57822. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  57823. {
  57824. if (inputChanList == 0)
  57825. {
  57826. addAndMakeVisible (inputChanList
  57827. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  57828. TRANS ("(no audio input channels found)")));
  57829. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  57830. inputChanLabel->attachToComponent (inputChanList, true);
  57831. }
  57832. inputChanList->refresh();
  57833. }
  57834. else
  57835. {
  57836. deleteAndZero (inputChanLabel);
  57837. deleteAndZero (inputChanList);
  57838. }
  57839. // sample rate..
  57840. {
  57841. if (sampleRateDropDown == 0)
  57842. {
  57843. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  57844. sampleRateDropDown->addListener (this);
  57845. delete sampleRateLabel;
  57846. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  57847. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  57848. }
  57849. else
  57850. {
  57851. sampleRateDropDown->clear();
  57852. sampleRateDropDown->removeListener (this);
  57853. }
  57854. const int numRates = currentDevice->getNumSampleRates();
  57855. for (int i = 0; i < numRates; ++i)
  57856. {
  57857. const int rate = roundToInt (currentDevice->getSampleRate (i));
  57858. sampleRateDropDown->addItem (String (rate) + " Hz", rate);
  57859. }
  57860. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  57861. sampleRateDropDown->addListener (this);
  57862. }
  57863. // buffer size
  57864. {
  57865. if (bufferSizeDropDown == 0)
  57866. {
  57867. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  57868. bufferSizeDropDown->addListener (this);
  57869. delete bufferSizeLabel;
  57870. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  57871. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  57872. }
  57873. else
  57874. {
  57875. bufferSizeDropDown->clear();
  57876. }
  57877. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  57878. double currentRate = currentDevice->getCurrentSampleRate();
  57879. if (currentRate == 0)
  57880. currentRate = 48000.0;
  57881. for (int i = 0; i < numBufferSizes; ++i)
  57882. {
  57883. const int bs = currentDevice->getBufferSizeSamples (i);
  57884. bufferSizeDropDown->addItem (String (bs)
  57885. + " samples ("
  57886. + String (bs * 1000.0 / currentRate, 1)
  57887. + " ms)",
  57888. bs);
  57889. }
  57890. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  57891. }
  57892. }
  57893. else
  57894. {
  57895. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  57896. deleteAndZero (sampleRateLabel);
  57897. deleteAndZero (bufferSizeLabel);
  57898. deleteAndZero (sampleRateDropDown);
  57899. deleteAndZero (bufferSizeDropDown);
  57900. if (outputDeviceDropDown != 0)
  57901. outputDeviceDropDown->setSelectedId (-1, true);
  57902. if (inputDeviceDropDown != 0)
  57903. inputDeviceDropDown->setSelectedId (-1, true);
  57904. }
  57905. resized();
  57906. setSize (getWidth(), getLowestY() + 4);
  57907. }
  57908. private:
  57909. AudioIODeviceType* const type;
  57910. const AudioIODeviceType::DeviceSetupDetails setup;
  57911. ComboBox* outputDeviceDropDown;
  57912. ComboBox* inputDeviceDropDown;
  57913. ComboBox* sampleRateDropDown;
  57914. ComboBox* bufferSizeDropDown;
  57915. Label* outputDeviceLabel;
  57916. Label* inputDeviceLabel;
  57917. Label* sampleRateLabel;
  57918. Label* bufferSizeLabel;
  57919. Label* inputChanLabel;
  57920. Label* outputChanLabel;
  57921. TextButton* testButton;
  57922. Component* inputLevelMeter;
  57923. TextButton* showUIButton;
  57924. TextButton* showAdvancedSettingsButton;
  57925. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  57926. {
  57927. if (box != 0)
  57928. {
  57929. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  57930. const int index = type->getIndexOfDevice (currentDevice, isInput);
  57931. box->setSelectedId (index + 1, true);
  57932. if (testButton != 0 && ! isInput)
  57933. testButton->setEnabled (index >= 0);
  57934. }
  57935. }
  57936. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  57937. {
  57938. const StringArray devs (type->getDeviceNames (isInputs));
  57939. combo.clear (true);
  57940. for (int i = 0; i < devs.size(); ++i)
  57941. combo.addItem (devs[i], i + 1);
  57942. combo.addItem (TRANS("<< none >>"), -1);
  57943. combo.setSelectedId (-1, true);
  57944. }
  57945. int getLowestY() const
  57946. {
  57947. int y = 0;
  57948. for (int i = getNumChildComponents(); --i >= 0;)
  57949. y = jmax (y, getChildComponent (i)->getBottom());
  57950. return y;
  57951. }
  57952. public:
  57953. class ChannelSelectorListBox : public ListBox,
  57954. public ListBoxModel
  57955. {
  57956. public:
  57957. enum BoxType
  57958. {
  57959. audioInputType,
  57960. audioOutputType
  57961. };
  57962. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  57963. const BoxType type_,
  57964. const String& noItemsMessage_)
  57965. : ListBox (String::empty, 0),
  57966. setup (setup_),
  57967. type (type_),
  57968. noItemsMessage (noItemsMessage_)
  57969. {
  57970. refresh();
  57971. setModel (this);
  57972. setOutlineThickness (1);
  57973. }
  57974. ~ChannelSelectorListBox()
  57975. {
  57976. }
  57977. void refresh()
  57978. {
  57979. items.clear();
  57980. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  57981. if (currentDevice != 0)
  57982. {
  57983. if (type == audioInputType)
  57984. items = currentDevice->getInputChannelNames();
  57985. else if (type == audioOutputType)
  57986. items = currentDevice->getOutputChannelNames();
  57987. if (setup.useStereoPairs)
  57988. {
  57989. StringArray pairs;
  57990. for (int i = 0; i < items.size(); i += 2)
  57991. {
  57992. const String name (items[i]);
  57993. const String name2 (items[i + 1]);
  57994. String commonBit;
  57995. for (int j = 0; j < name.length(); ++j)
  57996. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  57997. commonBit = name.substring (0, j);
  57998. // Make sure we only split the name at a space, because otherwise, things
  57999. // like "input 11" + "input 12" would become "input 11 + 2"
  58000. while (commonBit.isNotEmpty() && ! CharacterFunctions::isWhitespace (commonBit.getLastCharacter()))
  58001. commonBit = commonBit.dropLastCharacters (1);
  58002. pairs.add (name.trim() + " + " + name2.substring (commonBit.length()).trim());
  58003. }
  58004. items = pairs;
  58005. }
  58006. }
  58007. updateContent();
  58008. repaint();
  58009. }
  58010. int getNumRows()
  58011. {
  58012. return items.size();
  58013. }
  58014. void paintListBoxItem (int row,
  58015. Graphics& g,
  58016. int width, int height,
  58017. bool rowIsSelected)
  58018. {
  58019. if (((unsigned int) row) < (unsigned int) items.size())
  58020. {
  58021. if (rowIsSelected)
  58022. g.fillAll (findColour (TextEditor::highlightColourId)
  58023. .withMultipliedAlpha (0.3f));
  58024. const String item (items [row]);
  58025. bool enabled = false;
  58026. AudioDeviceManager::AudioDeviceSetup config;
  58027. setup.manager->getAudioDeviceSetup (config);
  58028. if (setup.useStereoPairs)
  58029. {
  58030. if (type == audioInputType)
  58031. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58032. else if (type == audioOutputType)
  58033. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58034. }
  58035. else
  58036. {
  58037. if (type == audioInputType)
  58038. enabled = config.inputChannels [row];
  58039. else if (type == audioOutputType)
  58040. enabled = config.outputChannels [row];
  58041. }
  58042. const int x = getTickX();
  58043. const float tickW = height * 0.75f;
  58044. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58045. enabled, true, true, false);
  58046. g.setFont (height * 0.6f);
  58047. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58048. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58049. }
  58050. }
  58051. void listBoxItemClicked (int row, const MouseEvent& e)
  58052. {
  58053. selectRow (row);
  58054. if (e.x < getTickX())
  58055. flipEnablement (row);
  58056. }
  58057. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58058. {
  58059. flipEnablement (row);
  58060. }
  58061. void returnKeyPressed (int row)
  58062. {
  58063. flipEnablement (row);
  58064. }
  58065. void paint (Graphics& g)
  58066. {
  58067. ListBox::paint (g);
  58068. if (items.size() == 0)
  58069. {
  58070. g.setColour (Colours::grey);
  58071. g.setFont (13.0f);
  58072. g.drawText (noItemsMessage,
  58073. 0, 0, getWidth(), getHeight() / 2,
  58074. Justification::centred, true);
  58075. }
  58076. }
  58077. int getBestHeight (int maxHeight)
  58078. {
  58079. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58080. getNumRows())
  58081. + getOutlineThickness() * 2;
  58082. }
  58083. juce_UseDebuggingNewOperator
  58084. private:
  58085. const AudioIODeviceType::DeviceSetupDetails setup;
  58086. const BoxType type;
  58087. const String noItemsMessage;
  58088. StringArray items;
  58089. void flipEnablement (const int row)
  58090. {
  58091. jassert (type == audioInputType || type == audioOutputType);
  58092. if (((unsigned int) row) < (unsigned int) items.size())
  58093. {
  58094. AudioDeviceManager::AudioDeviceSetup config;
  58095. setup.manager->getAudioDeviceSetup (config);
  58096. if (setup.useStereoPairs)
  58097. {
  58098. BigInteger bits;
  58099. BigInteger& original = (type == audioInputType ? config.inputChannels
  58100. : config.outputChannels);
  58101. int i;
  58102. for (i = 0; i < 256; i += 2)
  58103. bits.setBit (i / 2, original [i] || original [i + 1]);
  58104. if (type == audioInputType)
  58105. {
  58106. config.useDefaultInputChannels = false;
  58107. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58108. }
  58109. else
  58110. {
  58111. config.useDefaultOutputChannels = false;
  58112. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58113. }
  58114. for (i = 0; i < 256; ++i)
  58115. original.setBit (i, bits [i / 2]);
  58116. }
  58117. else
  58118. {
  58119. if (type == audioInputType)
  58120. {
  58121. config.useDefaultInputChannels = false;
  58122. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58123. }
  58124. else
  58125. {
  58126. config.useDefaultOutputChannels = false;
  58127. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58128. }
  58129. }
  58130. String error (setup.manager->setAudioDeviceSetup (config, true));
  58131. if (! error.isEmpty())
  58132. {
  58133. //xxx
  58134. }
  58135. }
  58136. }
  58137. static void flipBit (BigInteger& chans, int index, int minNumber, int maxNumber)
  58138. {
  58139. const int numActive = chans.countNumberOfSetBits();
  58140. if (chans [index])
  58141. {
  58142. if (numActive > minNumber)
  58143. chans.setBit (index, false);
  58144. }
  58145. else
  58146. {
  58147. if (numActive >= maxNumber)
  58148. {
  58149. const int firstActiveChan = chans.findNextSetBit();
  58150. chans.setBit (index > firstActiveChan
  58151. ? firstActiveChan : chans.getHighestBit(),
  58152. false);
  58153. }
  58154. chans.setBit (index, true);
  58155. }
  58156. }
  58157. int getTickX() const
  58158. {
  58159. return getRowHeight() + 5;
  58160. }
  58161. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58162. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58163. };
  58164. private:
  58165. ChannelSelectorListBox* inputChanList;
  58166. ChannelSelectorListBox* outputChanList;
  58167. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58168. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58169. };
  58170. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58171. const int minInputChannels_,
  58172. const int maxInputChannels_,
  58173. const int minOutputChannels_,
  58174. const int maxOutputChannels_,
  58175. const bool showMidiInputOptions,
  58176. const bool showMidiOutputSelector,
  58177. const bool showChannelsAsStereoPairs_,
  58178. const bool hideAdvancedOptionsWithButton_)
  58179. : deviceManager (deviceManager_),
  58180. deviceTypeDropDown (0),
  58181. deviceTypeDropDownLabel (0),
  58182. audioDeviceSettingsComp (0),
  58183. minOutputChannels (minOutputChannels_),
  58184. maxOutputChannels (maxOutputChannels_),
  58185. minInputChannels (minInputChannels_),
  58186. maxInputChannels (maxInputChannels_),
  58187. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58188. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58189. {
  58190. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58191. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58192. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58193. {
  58194. deviceTypeDropDown = new ComboBox (String::empty);
  58195. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58196. {
  58197. deviceTypeDropDown
  58198. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58199. i + 1);
  58200. }
  58201. addAndMakeVisible (deviceTypeDropDown);
  58202. deviceTypeDropDown->addListener (this);
  58203. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58204. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58205. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58206. }
  58207. if (showMidiInputOptions)
  58208. {
  58209. addAndMakeVisible (midiInputsList
  58210. = new MidiInputSelectorComponentListBox (deviceManager,
  58211. TRANS("(no midi inputs available)"),
  58212. 0, 0));
  58213. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58214. midiInputsLabel->setJustificationType (Justification::topRight);
  58215. midiInputsLabel->attachToComponent (midiInputsList, true);
  58216. }
  58217. else
  58218. {
  58219. midiInputsList = 0;
  58220. midiInputsLabel = 0;
  58221. }
  58222. if (showMidiOutputSelector)
  58223. {
  58224. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58225. midiOutputSelector->addListener (this);
  58226. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58227. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58228. }
  58229. else
  58230. {
  58231. midiOutputSelector = 0;
  58232. midiOutputLabel = 0;
  58233. }
  58234. deviceManager_.addChangeListener (this);
  58235. changeListenerCallback (0);
  58236. }
  58237. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58238. {
  58239. deviceManager.removeChangeListener (this);
  58240. deleteAllChildren();
  58241. }
  58242. void AudioDeviceSelectorComponent::resized()
  58243. {
  58244. const int lx = proportionOfWidth (0.35f);
  58245. const int w = proportionOfWidth (0.4f);
  58246. const int h = 24;
  58247. const int space = 6;
  58248. const int dh = h + space;
  58249. int y = 15;
  58250. if (deviceTypeDropDown != 0)
  58251. {
  58252. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58253. y += dh + space * 2;
  58254. }
  58255. if (audioDeviceSettingsComp != 0)
  58256. {
  58257. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58258. y += audioDeviceSettingsComp->getHeight() + space;
  58259. }
  58260. if (midiInputsList != 0)
  58261. {
  58262. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58263. midiInputsList->setBounds (lx, y, w, bh);
  58264. y += bh + space;
  58265. }
  58266. if (midiOutputSelector != 0)
  58267. midiOutputSelector->setBounds (lx, y, w, h);
  58268. }
  58269. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58270. {
  58271. if (child == audioDeviceSettingsComp)
  58272. resized();
  58273. }
  58274. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58275. {
  58276. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58277. if (device != 0 && device->hasControlPanel())
  58278. {
  58279. if (device->showControlPanel())
  58280. deviceManager.restartLastAudioDevice();
  58281. getTopLevelComponent()->toFront (true);
  58282. }
  58283. }
  58284. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58285. {
  58286. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58287. {
  58288. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58289. if (type != 0)
  58290. {
  58291. deleteAndZero (audioDeviceSettingsComp);
  58292. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58293. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58294. }
  58295. }
  58296. else if (comboBoxThatHasChanged == midiOutputSelector)
  58297. {
  58298. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58299. }
  58300. }
  58301. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58302. {
  58303. if (deviceTypeDropDown != 0)
  58304. {
  58305. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58306. }
  58307. if (audioDeviceSettingsComp == 0
  58308. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58309. {
  58310. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58311. deleteAndZero (audioDeviceSettingsComp);
  58312. AudioIODeviceType* const type
  58313. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58314. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58315. if (type != 0)
  58316. {
  58317. AudioIODeviceType::DeviceSetupDetails details;
  58318. details.manager = &deviceManager;
  58319. details.minNumInputChannels = minInputChannels;
  58320. details.maxNumInputChannels = maxInputChannels;
  58321. details.minNumOutputChannels = minOutputChannels;
  58322. details.maxNumOutputChannels = maxOutputChannels;
  58323. details.useStereoPairs = showChannelsAsStereoPairs;
  58324. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58325. if (audioDeviceSettingsComp != 0)
  58326. {
  58327. addAndMakeVisible (audioDeviceSettingsComp);
  58328. audioDeviceSettingsComp->resized();
  58329. }
  58330. }
  58331. }
  58332. if (midiInputsList != 0)
  58333. {
  58334. midiInputsList->updateContent();
  58335. midiInputsList->repaint();
  58336. }
  58337. if (midiOutputSelector != 0)
  58338. {
  58339. midiOutputSelector->clear();
  58340. const StringArray midiOuts (MidiOutput::getDevices());
  58341. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58342. midiOutputSelector->addSeparator();
  58343. for (int i = 0; i < midiOuts.size(); ++i)
  58344. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58345. int current = -1;
  58346. if (deviceManager.getDefaultMidiOutput() != 0)
  58347. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58348. midiOutputSelector->setSelectedId (current, true);
  58349. }
  58350. resized();
  58351. }
  58352. END_JUCE_NAMESPACE
  58353. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58354. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58355. BEGIN_JUCE_NAMESPACE
  58356. BubbleComponent::BubbleComponent()
  58357. : side (0),
  58358. allowablePlacements (above | below | left | right),
  58359. arrowTipX (0.0f),
  58360. arrowTipY (0.0f)
  58361. {
  58362. setInterceptsMouseClicks (false, false);
  58363. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58364. setComponentEffect (&shadow);
  58365. }
  58366. BubbleComponent::~BubbleComponent()
  58367. {
  58368. }
  58369. void BubbleComponent::paint (Graphics& g)
  58370. {
  58371. int x = content.getX();
  58372. int y = content.getY();
  58373. int w = content.getWidth();
  58374. int h = content.getHeight();
  58375. int cw, ch;
  58376. getContentSize (cw, ch);
  58377. if (side == 3)
  58378. x += w - cw;
  58379. else if (side != 1)
  58380. x += (w - cw) / 2;
  58381. w = cw;
  58382. if (side == 2)
  58383. y += h - ch;
  58384. else if (side != 0)
  58385. y += (h - ch) / 2;
  58386. h = ch;
  58387. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58388. (float) x, (float) y,
  58389. (float) w, (float) h);
  58390. const int cx = x + (w - cw) / 2;
  58391. const int cy = y + (h - ch) / 2;
  58392. const int indent = 3;
  58393. g.setOrigin (cx + indent, cy + indent);
  58394. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58395. paintContent (g, cw - indent * 2, ch - indent * 2);
  58396. }
  58397. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58398. {
  58399. allowablePlacements = newPlacement;
  58400. }
  58401. void BubbleComponent::setPosition (Component* componentToPointTo)
  58402. {
  58403. jassert (componentToPointTo->isValidComponent());
  58404. Point<int> pos;
  58405. if (getParentComponent() != 0)
  58406. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58407. else
  58408. pos = componentToPointTo->relativePositionToGlobal (pos);
  58409. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58410. }
  58411. void BubbleComponent::setPosition (const int arrowTipX_,
  58412. const int arrowTipY_)
  58413. {
  58414. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58415. }
  58416. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58417. {
  58418. Rectangle<int> availableSpace;
  58419. if (getParentComponent() != 0)
  58420. {
  58421. availableSpace.setSize (getParentComponent()->getWidth(),
  58422. getParentComponent()->getHeight());
  58423. }
  58424. else
  58425. {
  58426. availableSpace = getParentMonitorArea();
  58427. }
  58428. int x = 0;
  58429. int y = 0;
  58430. int w = 150;
  58431. int h = 30;
  58432. getContentSize (w, h);
  58433. w += 30;
  58434. h += 30;
  58435. const float edgeIndent = 2.0f;
  58436. const int arrowLength = jmin (10, h / 3, w / 3);
  58437. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58438. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58439. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58440. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58441. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58442. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58443. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58444. {
  58445. spaceLeft = spaceRight = 0;
  58446. }
  58447. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58448. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58449. {
  58450. spaceAbove = spaceBelow = 0;
  58451. }
  58452. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58453. {
  58454. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58455. arrowTipX = w * 0.5f;
  58456. content.setSize (w, h - arrowLength);
  58457. if (spaceAbove >= spaceBelow)
  58458. {
  58459. // above
  58460. y = rectangleToPointTo.getY() - h;
  58461. content.setPosition (0, 0);
  58462. arrowTipY = h - edgeIndent;
  58463. side = 2;
  58464. }
  58465. else
  58466. {
  58467. // below
  58468. y = rectangleToPointTo.getBottom();
  58469. content.setPosition (0, arrowLength);
  58470. arrowTipY = edgeIndent;
  58471. side = 0;
  58472. }
  58473. }
  58474. else
  58475. {
  58476. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58477. arrowTipY = h * 0.5f;
  58478. content.setSize (w - arrowLength, h);
  58479. if (spaceLeft > spaceRight)
  58480. {
  58481. // on the left
  58482. x = rectangleToPointTo.getX() - w;
  58483. content.setPosition (0, 0);
  58484. arrowTipX = w - edgeIndent;
  58485. side = 3;
  58486. }
  58487. else
  58488. {
  58489. // on the right
  58490. x = rectangleToPointTo.getRight();
  58491. content.setPosition (arrowLength, 0);
  58492. arrowTipX = edgeIndent;
  58493. side = 1;
  58494. }
  58495. }
  58496. setBounds (x, y, w, h);
  58497. }
  58498. END_JUCE_NAMESPACE
  58499. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58500. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58501. BEGIN_JUCE_NAMESPACE
  58502. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58503. : fadeOutLength (fadeOutLengthMs),
  58504. deleteAfterUse (false)
  58505. {
  58506. }
  58507. BubbleMessageComponent::~BubbleMessageComponent()
  58508. {
  58509. fadeOutComponent (fadeOutLength);
  58510. }
  58511. void BubbleMessageComponent::showAt (int x, int y,
  58512. const String& text,
  58513. const int numMillisecondsBeforeRemoving,
  58514. const bool removeWhenMouseClicked,
  58515. const bool deleteSelfAfterUse)
  58516. {
  58517. textLayout.clear();
  58518. textLayout.setText (text, Font (14.0f));
  58519. textLayout.layout (256, Justification::centredLeft, true);
  58520. setPosition (x, y);
  58521. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58522. }
  58523. void BubbleMessageComponent::showAt (Component* const component,
  58524. const String& text,
  58525. const int numMillisecondsBeforeRemoving,
  58526. const bool removeWhenMouseClicked,
  58527. const bool deleteSelfAfterUse)
  58528. {
  58529. textLayout.clear();
  58530. textLayout.setText (text, Font (14.0f));
  58531. textLayout.layout (256, Justification::centredLeft, true);
  58532. setPosition (component);
  58533. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58534. }
  58535. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58536. const bool removeWhenMouseClicked,
  58537. const bool deleteSelfAfterUse)
  58538. {
  58539. setVisible (true);
  58540. deleteAfterUse = deleteSelfAfterUse;
  58541. if (numMillisecondsBeforeRemoving > 0)
  58542. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58543. else
  58544. expiryTime = 0;
  58545. startTimer (77);
  58546. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58547. if (! (removeWhenMouseClicked && isShowing()))
  58548. mouseClickCounter += 0xfffff;
  58549. repaint();
  58550. }
  58551. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58552. {
  58553. w = textLayout.getWidth() + 16;
  58554. h = textLayout.getHeight() + 16;
  58555. }
  58556. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58557. {
  58558. g.setColour (findColour (TooltipWindow::textColourId));
  58559. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58560. }
  58561. void BubbleMessageComponent::timerCallback()
  58562. {
  58563. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58564. {
  58565. stopTimer();
  58566. setVisible (false);
  58567. if (deleteAfterUse)
  58568. delete this;
  58569. }
  58570. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58571. {
  58572. stopTimer();
  58573. fadeOutComponent (fadeOutLength);
  58574. if (deleteAfterUse)
  58575. delete this;
  58576. }
  58577. }
  58578. END_JUCE_NAMESPACE
  58579. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58580. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58581. BEGIN_JUCE_NAMESPACE
  58582. static const int swatchesPerRow = 8;
  58583. static const int swatchHeight = 22;
  58584. class ColourComponentSlider : public Slider
  58585. {
  58586. public:
  58587. ColourComponentSlider (const String& name)
  58588. : Slider (name)
  58589. {
  58590. setRange (0.0, 255.0, 1.0);
  58591. }
  58592. ~ColourComponentSlider()
  58593. {
  58594. }
  58595. const String getTextFromValue (double value)
  58596. {
  58597. return String::toHexString ((int) value).toUpperCase().paddedLeft ('0', 2);
  58598. }
  58599. double getValueFromText (const String& text)
  58600. {
  58601. return (double) text.getHexValue32();
  58602. }
  58603. private:
  58604. ColourComponentSlider (const ColourComponentSlider&);
  58605. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58606. };
  58607. class ColourSpaceMarker : public Component
  58608. {
  58609. public:
  58610. ColourSpaceMarker()
  58611. {
  58612. setInterceptsMouseClicks (false, false);
  58613. }
  58614. ~ColourSpaceMarker()
  58615. {
  58616. }
  58617. void paint (Graphics& g)
  58618. {
  58619. g.setColour (Colour::greyLevel (0.1f));
  58620. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58621. g.setColour (Colour::greyLevel (0.9f));
  58622. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58623. }
  58624. private:
  58625. ColourSpaceMarker (const ColourSpaceMarker&);
  58626. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58627. };
  58628. class ColourSelector::ColourSpaceView : public Component
  58629. {
  58630. public:
  58631. ColourSpaceView (ColourSelector* owner_,
  58632. float& h_, float& s_, float& v_,
  58633. const int edgeSize)
  58634. : owner (owner_),
  58635. h (h_), s (s_), v (v_),
  58636. lastHue (0.0f),
  58637. edge (edgeSize)
  58638. {
  58639. addAndMakeVisible (marker = new ColourSpaceMarker());
  58640. setMouseCursor (MouseCursor::CrosshairCursor);
  58641. }
  58642. ~ColourSpaceView()
  58643. {
  58644. deleteAllChildren();
  58645. }
  58646. void paint (Graphics& g)
  58647. {
  58648. if (colours == 0)
  58649. {
  58650. const int width = getWidth() / 2;
  58651. const int height = getHeight() / 2;
  58652. colours = new Image (Image::RGB, width, height, false);
  58653. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58654. for (int y = 0; y < height; ++y)
  58655. {
  58656. const float v = 1.0f - y / (float) height;
  58657. for (int x = 0; x < width; ++x)
  58658. {
  58659. const float s = x / (float) width;
  58660. const Colour col (h, s, v, 1.0f);
  58661. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58662. pix->set (col.getPixelARGB());
  58663. }
  58664. }
  58665. }
  58666. g.setOpacity (1.0f);
  58667. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58668. 0, 0, colours->getWidth(), colours->getHeight());
  58669. }
  58670. void mouseDown (const MouseEvent& e)
  58671. {
  58672. mouseDrag (e);
  58673. }
  58674. void mouseDrag (const MouseEvent& e)
  58675. {
  58676. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58677. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58678. owner->setSV (s, v);
  58679. }
  58680. void updateIfNeeded()
  58681. {
  58682. if (lastHue != h)
  58683. {
  58684. lastHue = h;
  58685. colours = 0;
  58686. repaint();
  58687. }
  58688. updateMarker();
  58689. }
  58690. void resized()
  58691. {
  58692. colours = 0;
  58693. updateMarker();
  58694. }
  58695. private:
  58696. ColourSelector* const owner;
  58697. float& h;
  58698. float& s;
  58699. float& v;
  58700. float lastHue;
  58701. ColourSpaceMarker* marker;
  58702. const int edge;
  58703. ScopedPointer <Image> colours;
  58704. void updateMarker() const throw()
  58705. {
  58706. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58707. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58708. edge * 2, edge * 2);
  58709. }
  58710. ColourSpaceView (const ColourSpaceView&);
  58711. ColourSpaceView& operator= (const ColourSpaceView&);
  58712. };
  58713. class HueSelectorMarker : public Component
  58714. {
  58715. public:
  58716. HueSelectorMarker()
  58717. {
  58718. setInterceptsMouseClicks (false, false);
  58719. }
  58720. ~HueSelectorMarker()
  58721. {
  58722. }
  58723. void paint (Graphics& g)
  58724. {
  58725. Path p;
  58726. p.addTriangle (1.0f, 1.0f,
  58727. getWidth() * 0.3f, getHeight() * 0.5f,
  58728. 1.0f, getHeight() - 1.0f);
  58729. p.addTriangle (getWidth() - 1.0f, 1.0f,
  58730. getWidth() * 0.7f, getHeight() * 0.5f,
  58731. getWidth() - 1.0f, getHeight() - 1.0f);
  58732. g.setColour (Colours::white.withAlpha (0.75f));
  58733. g.fillPath (p);
  58734. g.setColour (Colours::black.withAlpha (0.75f));
  58735. g.strokePath (p, PathStrokeType (1.2f));
  58736. }
  58737. private:
  58738. HueSelectorMarker (const HueSelectorMarker&);
  58739. HueSelectorMarker& operator= (const HueSelectorMarker&);
  58740. };
  58741. class ColourSelector::HueSelectorComp : public Component
  58742. {
  58743. public:
  58744. HueSelectorComp (ColourSelector* owner_,
  58745. float& h_, float& s_, float& v_,
  58746. const int edgeSize)
  58747. : owner (owner_),
  58748. h (h_), s (s_), v (v_),
  58749. lastHue (0.0f),
  58750. edge (edgeSize)
  58751. {
  58752. addAndMakeVisible (marker = new HueSelectorMarker());
  58753. }
  58754. ~HueSelectorComp()
  58755. {
  58756. deleteAllChildren();
  58757. }
  58758. void paint (Graphics& g)
  58759. {
  58760. const float yScale = 1.0f / (getHeight() - edge * 2);
  58761. const Rectangle<int> clip (g.getClipBounds());
  58762. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  58763. {
  58764. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  58765. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  58766. }
  58767. }
  58768. void resized()
  58769. {
  58770. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  58771. getWidth(), edge * 2);
  58772. }
  58773. void mouseDown (const MouseEvent& e)
  58774. {
  58775. mouseDrag (e);
  58776. }
  58777. void mouseDrag (const MouseEvent& e)
  58778. {
  58779. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  58780. owner->setHue (hue);
  58781. }
  58782. void updateIfNeeded()
  58783. {
  58784. resized();
  58785. }
  58786. private:
  58787. ColourSelector* const owner;
  58788. float& h;
  58789. float& s;
  58790. float& v;
  58791. float lastHue;
  58792. HueSelectorMarker* marker;
  58793. const int edge;
  58794. HueSelectorComp (const HueSelectorComp&);
  58795. HueSelectorComp& operator= (const HueSelectorComp&);
  58796. };
  58797. class ColourSelector::SwatchComponent : public Component
  58798. {
  58799. public:
  58800. SwatchComponent (ColourSelector* owner_, int index_)
  58801. : owner (owner_),
  58802. index (index_)
  58803. {
  58804. }
  58805. ~SwatchComponent()
  58806. {
  58807. }
  58808. void paint (Graphics& g)
  58809. {
  58810. const Colour colour (owner->getSwatchColour (index));
  58811. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  58812. 6, 6,
  58813. Colour (0xffdddddd).overlaidWith (colour),
  58814. Colour (0xffffffff).overlaidWith (colour));
  58815. }
  58816. void mouseDown (const MouseEvent&)
  58817. {
  58818. PopupMenu m;
  58819. m.addItem (1, TRANS("Use this swatch as the current colour"));
  58820. m.addSeparator();
  58821. m.addItem (2, TRANS("Set this swatch to the current colour"));
  58822. const int r = m.showAt (this);
  58823. if (r == 1)
  58824. {
  58825. owner->setCurrentColour (owner->getSwatchColour (index));
  58826. }
  58827. else if (r == 2)
  58828. {
  58829. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  58830. {
  58831. owner->setSwatchColour (index, owner->getCurrentColour());
  58832. repaint();
  58833. }
  58834. }
  58835. }
  58836. private:
  58837. ColourSelector* const owner;
  58838. const int index;
  58839. SwatchComponent (const SwatchComponent&);
  58840. SwatchComponent& operator= (const SwatchComponent&);
  58841. };
  58842. ColourSelector::ColourSelector (const int flags_,
  58843. const int edgeGap_,
  58844. const int gapAroundColourSpaceComponent)
  58845. : colour (Colours::white),
  58846. flags (flags_),
  58847. topSpace (0),
  58848. edgeGap (edgeGap_)
  58849. {
  58850. // not much point having a selector with no components in it!
  58851. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  58852. updateHSV();
  58853. if ((flags & showSliders) != 0)
  58854. {
  58855. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  58856. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  58857. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  58858. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  58859. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  58860. for (int i = 4; --i >= 0;)
  58861. sliders[i]->addListener (this);
  58862. }
  58863. else
  58864. {
  58865. zeromem (sliders, sizeof (sliders));
  58866. }
  58867. if ((flags & showColourspace) != 0)
  58868. {
  58869. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  58870. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  58871. }
  58872. else
  58873. {
  58874. colourSpace = 0;
  58875. hueSelector = 0;
  58876. }
  58877. update();
  58878. }
  58879. ColourSelector::~ColourSelector()
  58880. {
  58881. dispatchPendingMessages();
  58882. swatchComponents.clear();
  58883. deleteAllChildren();
  58884. }
  58885. const Colour ColourSelector::getCurrentColour() const
  58886. {
  58887. return ((flags & showAlphaChannel) != 0) ? colour
  58888. : colour.withAlpha ((uint8) 0xff);
  58889. }
  58890. void ColourSelector::setCurrentColour (const Colour& c)
  58891. {
  58892. if (c != colour)
  58893. {
  58894. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  58895. updateHSV();
  58896. update();
  58897. }
  58898. }
  58899. void ColourSelector::setHue (float newH)
  58900. {
  58901. newH = jlimit (0.0f, 1.0f, newH);
  58902. if (h != newH)
  58903. {
  58904. h = newH;
  58905. colour = Colour (h, s, v, colour.getFloatAlpha());
  58906. update();
  58907. }
  58908. }
  58909. void ColourSelector::setSV (float newS, float newV)
  58910. {
  58911. newS = jlimit (0.0f, 1.0f, newS);
  58912. newV = jlimit (0.0f, 1.0f, newV);
  58913. if (s != newS || v != newV)
  58914. {
  58915. s = newS;
  58916. v = newV;
  58917. colour = Colour (h, s, v, colour.getFloatAlpha());
  58918. update();
  58919. }
  58920. }
  58921. void ColourSelector::updateHSV()
  58922. {
  58923. colour.getHSB (h, s, v);
  58924. }
  58925. void ColourSelector::update()
  58926. {
  58927. if (sliders[0] != 0)
  58928. {
  58929. sliders[0]->setValue ((int) colour.getRed());
  58930. sliders[1]->setValue ((int) colour.getGreen());
  58931. sliders[2]->setValue ((int) colour.getBlue());
  58932. sliders[3]->setValue ((int) colour.getAlpha());
  58933. }
  58934. if (colourSpace != 0)
  58935. {
  58936. colourSpace->updateIfNeeded();
  58937. hueSelector->updateIfNeeded();
  58938. }
  58939. if ((flags & showColourAtTop) != 0)
  58940. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  58941. sendChangeMessage (this);
  58942. }
  58943. void ColourSelector::paint (Graphics& g)
  58944. {
  58945. g.fillAll (findColour (backgroundColourId));
  58946. if ((flags & showColourAtTop) != 0)
  58947. {
  58948. const Colour colour (getCurrentColour());
  58949. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  58950. 10, 10,
  58951. Colour (0xffdddddd).overlaidWith (colour),
  58952. Colour (0xffffffff).overlaidWith (colour));
  58953. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  58954. g.setFont (14.0f, true);
  58955. g.drawText (colour.toDisplayString ((flags & showAlphaChannel) != 0),
  58956. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  58957. Justification::centred, false);
  58958. }
  58959. if ((flags & showSliders) != 0)
  58960. {
  58961. g.setColour (findColour (labelTextColourId));
  58962. g.setFont (11.0f);
  58963. for (int i = 4; --i >= 0;)
  58964. {
  58965. if (sliders[i]->isVisible())
  58966. g.drawText (sliders[i]->getName() + ":",
  58967. 0, sliders[i]->getY(),
  58968. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  58969. Justification::centredRight, false);
  58970. }
  58971. }
  58972. }
  58973. void ColourSelector::resized()
  58974. {
  58975. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  58976. const int numSwatches = getNumSwatches();
  58977. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  58978. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  58979. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  58980. int y = topSpace;
  58981. if ((flags & showColourspace) != 0)
  58982. {
  58983. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  58984. colourSpace->setBounds (edgeGap, y,
  58985. getWidth() - hueWidth - edgeGap - 4,
  58986. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  58987. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  58988. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  58989. colourSpace->getHeight());
  58990. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  58991. }
  58992. if ((flags & showSliders) != 0)
  58993. {
  58994. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  58995. for (int i = 0; i < numSliders; ++i)
  58996. {
  58997. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  58998. proportionOfWidth (0.72f), sliderHeight - 2);
  58999. y += sliderHeight;
  59000. }
  59001. }
  59002. if (numSwatches > 0)
  59003. {
  59004. const int startX = 8;
  59005. const int xGap = 4;
  59006. const int yGap = 4;
  59007. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59008. y += edgeGap;
  59009. if (swatchComponents.size() != numSwatches)
  59010. {
  59011. swatchComponents.clear();
  59012. for (int i = 0; i < numSwatches; ++i)
  59013. {
  59014. SwatchComponent* const sc = new SwatchComponent (this, i);
  59015. swatchComponents.add (sc);
  59016. addAndMakeVisible (sc);
  59017. }
  59018. }
  59019. int x = startX;
  59020. for (int i = 0; i < swatchComponents.size(); ++i)
  59021. {
  59022. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59023. sc->setBounds (x + xGap / 2,
  59024. y + yGap / 2,
  59025. swatchWidth - xGap,
  59026. swatchHeight - yGap);
  59027. if (((i + 1) % swatchesPerRow) == 0)
  59028. {
  59029. x = startX;
  59030. y += swatchHeight;
  59031. }
  59032. else
  59033. {
  59034. x += swatchWidth;
  59035. }
  59036. }
  59037. }
  59038. }
  59039. void ColourSelector::sliderValueChanged (Slider*)
  59040. {
  59041. if (sliders[0] != 0)
  59042. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59043. (uint8) sliders[1]->getValue(),
  59044. (uint8) sliders[2]->getValue(),
  59045. (uint8) sliders[3]->getValue()));
  59046. }
  59047. int ColourSelector::getNumSwatches() const
  59048. {
  59049. return 0;
  59050. }
  59051. const Colour ColourSelector::getSwatchColour (const int) const
  59052. {
  59053. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59054. return Colours::black;
  59055. }
  59056. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59057. {
  59058. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59059. }
  59060. END_JUCE_NAMESPACE
  59061. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59062. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59063. BEGIN_JUCE_NAMESPACE
  59064. class ShadowWindow : public Component
  59065. {
  59066. Component* owner;
  59067. Image** shadowImageSections;
  59068. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59069. public:
  59070. ShadowWindow (Component* const owner_,
  59071. const int type_,
  59072. Image** const shadowImageSections_)
  59073. : owner (owner_),
  59074. shadowImageSections (shadowImageSections_),
  59075. type (type_)
  59076. {
  59077. setInterceptsMouseClicks (false, false);
  59078. if (owner_->isOnDesktop())
  59079. {
  59080. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59081. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59082. | ComponentPeer::windowIsTemporary
  59083. | ComponentPeer::windowIgnoresKeyPresses);
  59084. }
  59085. else if (owner_->getParentComponent() != 0)
  59086. {
  59087. owner_->getParentComponent()->addChildComponent (this);
  59088. }
  59089. }
  59090. ~ShadowWindow()
  59091. {
  59092. }
  59093. void paint (Graphics& g)
  59094. {
  59095. Image* const topLeft = shadowImageSections [type * 3];
  59096. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59097. Image* const filler = shadowImageSections [type * 3 + 2];
  59098. g.setOpacity (1.0f);
  59099. if (type < 2)
  59100. {
  59101. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59102. g.drawImage (topLeft,
  59103. 0, 0, topLeft->getWidth(), imH,
  59104. 0, 0, topLeft->getWidth(), imH);
  59105. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59106. g.drawImage (bottomRight,
  59107. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59108. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59109. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59110. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59111. }
  59112. else
  59113. {
  59114. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59115. g.drawImage (topLeft,
  59116. 0, 0, imW, topLeft->getHeight(),
  59117. 0, 0, imW, topLeft->getHeight());
  59118. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59119. g.drawImage (bottomRight,
  59120. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59121. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59122. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59123. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59124. }
  59125. }
  59126. void resized()
  59127. {
  59128. repaint(); // (needed for correct repainting)
  59129. }
  59130. private:
  59131. ShadowWindow (const ShadowWindow&);
  59132. ShadowWindow& operator= (const ShadowWindow&);
  59133. };
  59134. DropShadower::DropShadower (const float alpha_,
  59135. const int xOffset_,
  59136. const int yOffset_,
  59137. const float blurRadius_)
  59138. : owner (0),
  59139. numShadows (0),
  59140. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59141. xOffset (xOffset_),
  59142. yOffset (yOffset_),
  59143. alpha (alpha_),
  59144. blurRadius (blurRadius_),
  59145. inDestructor (false),
  59146. reentrant (false)
  59147. {
  59148. }
  59149. DropShadower::~DropShadower()
  59150. {
  59151. if (owner != 0)
  59152. owner->removeComponentListener (this);
  59153. inDestructor = true;
  59154. deleteShadowWindows();
  59155. }
  59156. void DropShadower::deleteShadowWindows()
  59157. {
  59158. if (numShadows > 0)
  59159. {
  59160. int i;
  59161. for (i = numShadows; --i >= 0;)
  59162. delete shadowWindows[i];
  59163. for (i = 12; --i >= 0;)
  59164. delete shadowImageSections[i];
  59165. numShadows = 0;
  59166. }
  59167. }
  59168. void DropShadower::setOwner (Component* componentToFollow)
  59169. {
  59170. if (componentToFollow != owner)
  59171. {
  59172. if (owner != 0)
  59173. owner->removeComponentListener (this);
  59174. // (the component can't be null)
  59175. jassert (componentToFollow != 0);
  59176. owner = componentToFollow;
  59177. jassert (owner != 0);
  59178. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59179. owner->addComponentListener (this);
  59180. updateShadows();
  59181. }
  59182. }
  59183. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59184. {
  59185. updateShadows();
  59186. }
  59187. void DropShadower::componentBroughtToFront (Component&)
  59188. {
  59189. bringShadowWindowsToFront();
  59190. }
  59191. void DropShadower::componentChildrenChanged (Component&)
  59192. {
  59193. }
  59194. void DropShadower::componentParentHierarchyChanged (Component&)
  59195. {
  59196. deleteShadowWindows();
  59197. updateShadows();
  59198. }
  59199. void DropShadower::componentVisibilityChanged (Component&)
  59200. {
  59201. updateShadows();
  59202. }
  59203. void DropShadower::updateShadows()
  59204. {
  59205. if (reentrant || inDestructor || (owner == 0))
  59206. return;
  59207. reentrant = true;
  59208. ComponentPeer* const nw = owner->getPeer();
  59209. const bool isOwnerVisible = owner->isVisible()
  59210. && (nw == 0 || ! nw->isMinimised());
  59211. const bool createShadowWindows = numShadows == 0
  59212. && owner->getWidth() > 0
  59213. && owner->getHeight() > 0
  59214. && isOwnerVisible
  59215. && (Desktop::canUseSemiTransparentWindows()
  59216. || owner->getParentComponent() != 0);
  59217. if (createShadowWindows)
  59218. {
  59219. // keep a cached version of the image to save doing the gaussian too often
  59220. String imageId;
  59221. imageId << shadowEdge << ',' << xOffset << ',' << yOffset << ',' << alpha;
  59222. const int hash = imageId.hashCode();
  59223. Image* bigIm = ImageCache::getFromHashCode (hash);
  59224. if (bigIm == 0)
  59225. {
  59226. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59227. Graphics bigG (*bigIm);
  59228. bigG.setColour (Colours::black.withAlpha (alpha));
  59229. bigG.fillRect (shadowEdge + xOffset,
  59230. shadowEdge + yOffset,
  59231. bigIm->getWidth() - (shadowEdge * 2),
  59232. bigIm->getHeight() - (shadowEdge * 2));
  59233. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59234. blurKernel.createGaussianBlur (blurRadius);
  59235. blurKernel.applyToImage (*bigIm, 0,
  59236. Rectangle<int> (xOffset, yOffset,
  59237. bigIm->getWidth(), bigIm->getHeight()));
  59238. ImageCache::addImageToCache (bigIm, hash);
  59239. }
  59240. const int iw = bigIm->getWidth();
  59241. const int ih = bigIm->getHeight();
  59242. const int shadowEdge2 = shadowEdge * 2;
  59243. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59244. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59245. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59246. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59247. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59248. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59249. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59250. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59251. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59252. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59253. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59254. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59255. ImageCache::release (bigIm);
  59256. for (int i = 0; i < 4; ++i)
  59257. {
  59258. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59259. ++numShadows;
  59260. }
  59261. }
  59262. if (numShadows > 0)
  59263. {
  59264. for (int i = numShadows; --i >= 0;)
  59265. {
  59266. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59267. shadowWindows[i]->setVisible (isOwnerVisible);
  59268. }
  59269. const int x = owner->getX();
  59270. const int y = owner->getY() - shadowEdge;
  59271. const int w = owner->getWidth();
  59272. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59273. shadowWindows[0]->setBounds (x - shadowEdge,
  59274. y,
  59275. shadowEdge,
  59276. h);
  59277. shadowWindows[1]->setBounds (x + w,
  59278. y,
  59279. shadowEdge,
  59280. h);
  59281. shadowWindows[2]->setBounds (x,
  59282. y,
  59283. w,
  59284. shadowEdge);
  59285. shadowWindows[3]->setBounds (x,
  59286. owner->getBottom(),
  59287. w,
  59288. shadowEdge);
  59289. }
  59290. reentrant = false;
  59291. if (createShadowWindows)
  59292. bringShadowWindowsToFront();
  59293. }
  59294. void DropShadower::setShadowImage (Image* const src, const int num, const int w, const int h,
  59295. const int sx, const int sy)
  59296. {
  59297. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59298. Graphics g (*shadowImageSections[num]);
  59299. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59300. }
  59301. void DropShadower::bringShadowWindowsToFront()
  59302. {
  59303. if (! (inDestructor || reentrant))
  59304. {
  59305. updateShadows();
  59306. reentrant = true;
  59307. for (int i = numShadows; --i >= 0;)
  59308. shadowWindows[i]->toBehind (owner);
  59309. reentrant = false;
  59310. }
  59311. }
  59312. END_JUCE_NAMESPACE
  59313. /*** End of inlined file: juce_DropShadower.cpp ***/
  59314. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59315. BEGIN_JUCE_NAMESPACE
  59316. class MagnifyingPeer : public ComponentPeer
  59317. {
  59318. public:
  59319. MagnifyingPeer (Component* const component_,
  59320. MagnifierComponent* const magnifierComp_)
  59321. : ComponentPeer (component_, 0),
  59322. magnifierComp (magnifierComp_)
  59323. {
  59324. }
  59325. ~MagnifyingPeer()
  59326. {
  59327. }
  59328. void* getNativeHandle() const { return 0; }
  59329. void setVisible (bool) {}
  59330. void setTitle (const String&) {}
  59331. void setPosition (int, int) {}
  59332. void setSize (int, int) {}
  59333. void setBounds (int, int, int, int, bool) {}
  59334. void setMinimised (bool) {}
  59335. bool isMinimised() const { return false; }
  59336. void setFullScreen (bool) {}
  59337. bool isFullScreen() const { return false; }
  59338. const BorderSize getFrameSize() const { return BorderSize (0); }
  59339. bool setAlwaysOnTop (bool) { return true; }
  59340. void toFront (bool) {}
  59341. void toBehind (ComponentPeer*) {}
  59342. void setIcon (const Image&) {}
  59343. bool isFocused() const
  59344. {
  59345. return magnifierComp->hasKeyboardFocus (true);
  59346. }
  59347. void grabFocus()
  59348. {
  59349. ComponentPeer* peer = magnifierComp->getPeer();
  59350. if (peer != 0)
  59351. peer->grabFocus();
  59352. }
  59353. void textInputRequired (const Point<int>& position)
  59354. {
  59355. ComponentPeer* peer = magnifierComp->getPeer();
  59356. if (peer != 0)
  59357. peer->textInputRequired (position);
  59358. }
  59359. const Rectangle<int> getBounds() const
  59360. {
  59361. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59362. component->getWidth(), component->getHeight());
  59363. }
  59364. const Point<int> getScreenPosition() const
  59365. {
  59366. return magnifierComp->getScreenPosition();
  59367. }
  59368. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59369. {
  59370. const double zoom = magnifierComp->getScaleFactor();
  59371. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59372. roundToInt (relativePosition.getY() * zoom)));
  59373. }
  59374. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59375. {
  59376. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59377. const double zoom = magnifierComp->getScaleFactor();
  59378. return Point<int> (roundToInt (p.getX() / zoom),
  59379. roundToInt (p.getY() / zoom));
  59380. }
  59381. bool contains (const Point<int>& position, bool) const
  59382. {
  59383. return ((unsigned int) position.getX()) < (unsigned int) magnifierComp->getWidth()
  59384. && ((unsigned int) position.getY()) < (unsigned int) magnifierComp->getHeight();
  59385. }
  59386. void repaint (int x, int y, int w, int h)
  59387. {
  59388. const double zoom = magnifierComp->getScaleFactor();
  59389. magnifierComp->repaint ((int) (x * zoom),
  59390. (int) (y * zoom),
  59391. roundToInt (w * zoom) + 1,
  59392. roundToInt (h * zoom) + 1);
  59393. }
  59394. void performAnyPendingRepaintsNow()
  59395. {
  59396. }
  59397. juce_UseDebuggingNewOperator
  59398. private:
  59399. MagnifierComponent* const magnifierComp;
  59400. MagnifyingPeer (const MagnifyingPeer&);
  59401. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59402. };
  59403. class PeerHolderComp : public Component
  59404. {
  59405. public:
  59406. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59407. : magnifierComp (magnifierComp_)
  59408. {
  59409. setVisible (true);
  59410. }
  59411. ~PeerHolderComp()
  59412. {
  59413. }
  59414. ComponentPeer* createNewPeer (int, void*)
  59415. {
  59416. return new MagnifyingPeer (this, magnifierComp);
  59417. }
  59418. void childBoundsChanged (Component* c)
  59419. {
  59420. if (c != 0)
  59421. {
  59422. setSize (c->getWidth(), c->getHeight());
  59423. magnifierComp->childBoundsChanged (this);
  59424. }
  59425. }
  59426. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59427. {
  59428. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59429. Component* const p = magnifierComp->getParentComponent();
  59430. if (p != 0)
  59431. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59432. }
  59433. private:
  59434. MagnifierComponent* const magnifierComp;
  59435. PeerHolderComp (const PeerHolderComp&);
  59436. PeerHolderComp& operator= (const PeerHolderComp&);
  59437. };
  59438. MagnifierComponent::MagnifierComponent (Component* const content_,
  59439. const bool deleteContentCompWhenNoLongerNeeded)
  59440. : content (content_),
  59441. scaleFactor (0.0),
  59442. peer (0),
  59443. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59444. quality (Graphics::lowResamplingQuality),
  59445. mouseSource (0, true)
  59446. {
  59447. holderComp = new PeerHolderComp (this);
  59448. setScaleFactor (1.0);
  59449. }
  59450. MagnifierComponent::~MagnifierComponent()
  59451. {
  59452. delete holderComp;
  59453. if (deleteContent)
  59454. delete content;
  59455. }
  59456. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59457. {
  59458. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59459. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59460. if (scaleFactor != newScaleFactor)
  59461. {
  59462. scaleFactor = newScaleFactor;
  59463. if (scaleFactor == 1.0)
  59464. {
  59465. holderComp->removeFromDesktop();
  59466. peer = 0;
  59467. addChildComponent (content);
  59468. childBoundsChanged (content);
  59469. }
  59470. else
  59471. {
  59472. holderComp->addAndMakeVisible (content);
  59473. holderComp->childBoundsChanged (content);
  59474. childBoundsChanged (holderComp);
  59475. holderComp->addToDesktop (0);
  59476. peer = holderComp->getPeer();
  59477. }
  59478. repaint();
  59479. }
  59480. }
  59481. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59482. {
  59483. quality = newQuality;
  59484. }
  59485. void MagnifierComponent::paint (Graphics& g)
  59486. {
  59487. const int w = holderComp->getWidth();
  59488. const int h = holderComp->getHeight();
  59489. if (w == 0 || h == 0)
  59490. return;
  59491. const Rectangle<int> r (g.getClipBounds());
  59492. const int srcX = (int) (r.getX() / scaleFactor);
  59493. const int srcY = (int) (r.getY() / scaleFactor);
  59494. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59495. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59496. if (scaleFactor >= 1.0)
  59497. {
  59498. ++srcW;
  59499. ++srcH;
  59500. }
  59501. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59502. temp.clear (srcX, srcY, srcW, srcH);
  59503. {
  59504. Graphics g2 (temp);
  59505. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59506. holderComp->paintEntireComponent (g2);
  59507. }
  59508. g.setImageResamplingQuality (quality);
  59509. g.drawImageTransformed (&temp, temp.getBounds(),
  59510. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59511. false);
  59512. }
  59513. void MagnifierComponent::childBoundsChanged (Component* c)
  59514. {
  59515. if (c != 0)
  59516. setSize (roundToInt (c->getWidth() * scaleFactor),
  59517. roundToInt (c->getHeight() * scaleFactor));
  59518. }
  59519. void MagnifierComponent::passOnMouseEventToPeer (const MouseEvent& e)
  59520. {
  59521. if (peer != 0)
  59522. mouseSource.handleEvent (peer, Point<int> (scaleInt (e.x), scaleInt (e.y)),
  59523. e.eventTime.toMilliseconds(), ModifierKeys::getCurrentModifiers());
  59524. }
  59525. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59526. {
  59527. passOnMouseEventToPeer (e);
  59528. }
  59529. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59530. {
  59531. passOnMouseEventToPeer (e);
  59532. }
  59533. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59534. {
  59535. passOnMouseEventToPeer (e);
  59536. }
  59537. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59538. {
  59539. passOnMouseEventToPeer (e);
  59540. }
  59541. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59542. {
  59543. passOnMouseEventToPeer (e);
  59544. }
  59545. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59546. {
  59547. passOnMouseEventToPeer (e);
  59548. }
  59549. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59550. {
  59551. if (peer != 0)
  59552. peer->handleMouseWheel (e.source.getIndex(),
  59553. Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds(),
  59554. ix * 256.0f, iy * 256.0f);
  59555. else
  59556. Component::mouseWheelMove (e, ix, iy);
  59557. }
  59558. int MagnifierComponent::scaleInt (const int n) const
  59559. {
  59560. return roundToInt (n / scaleFactor);
  59561. }
  59562. END_JUCE_NAMESPACE
  59563. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59564. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59565. BEGIN_JUCE_NAMESPACE
  59566. class MidiKeyboardUpDownButton : public Button
  59567. {
  59568. public:
  59569. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59570. const int delta_)
  59571. : Button (String::empty),
  59572. owner (owner_),
  59573. delta (delta_)
  59574. {
  59575. setOpaque (true);
  59576. }
  59577. ~MidiKeyboardUpDownButton()
  59578. {
  59579. }
  59580. void clicked()
  59581. {
  59582. int note = owner->getLowestVisibleKey();
  59583. if (delta < 0)
  59584. note = (note - 1) / 12;
  59585. else
  59586. note = note / 12 + 1;
  59587. owner->setLowestVisibleKey (note * 12);
  59588. }
  59589. void paintButton (Graphics& g,
  59590. bool isMouseOverButton,
  59591. bool isButtonDown)
  59592. {
  59593. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59594. isMouseOverButton, isButtonDown,
  59595. delta > 0);
  59596. }
  59597. private:
  59598. MidiKeyboardComponent* const owner;
  59599. const int delta;
  59600. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59601. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59602. };
  59603. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59604. const Orientation orientation_)
  59605. : state (state_),
  59606. xOffset (0),
  59607. blackNoteLength (1),
  59608. keyWidth (16.0f),
  59609. orientation (orientation_),
  59610. midiChannel (1),
  59611. midiInChannelMask (0xffff),
  59612. velocity (1.0f),
  59613. noteUnderMouse (-1),
  59614. mouseDownNote (-1),
  59615. rangeStart (0),
  59616. rangeEnd (127),
  59617. firstKey (12 * 4),
  59618. canScroll (true),
  59619. mouseDragging (false),
  59620. useMousePositionForVelocity (true),
  59621. keyMappingOctave (6),
  59622. octaveNumForMiddleC (3)
  59623. {
  59624. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59625. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59626. // initialise with a default set of querty key-mappings..
  59627. const char* const keymap = "awsedftgyhujkolp;";
  59628. for (int i = String (keymap).length(); --i >= 0;)
  59629. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59630. setOpaque (true);
  59631. setWantsKeyboardFocus (true);
  59632. state.addListener (this);
  59633. }
  59634. MidiKeyboardComponent::~MidiKeyboardComponent()
  59635. {
  59636. state.removeListener (this);
  59637. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59638. deleteAllChildren();
  59639. }
  59640. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59641. {
  59642. keyWidth = widthInPixels;
  59643. resized();
  59644. }
  59645. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59646. {
  59647. if (orientation != newOrientation)
  59648. {
  59649. orientation = newOrientation;
  59650. resized();
  59651. }
  59652. }
  59653. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59654. const int highestNote)
  59655. {
  59656. jassert (lowestNote >= 0 && lowestNote <= 127);
  59657. jassert (highestNote >= 0 && highestNote <= 127);
  59658. jassert (lowestNote <= highestNote);
  59659. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59660. {
  59661. rangeStart = jlimit (0, 127, lowestNote);
  59662. rangeEnd = jlimit (0, 127, highestNote);
  59663. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59664. resized();
  59665. }
  59666. }
  59667. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59668. {
  59669. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59670. if (noteNumber != firstKey)
  59671. {
  59672. firstKey = noteNumber;
  59673. sendChangeMessage (this);
  59674. resized();
  59675. }
  59676. }
  59677. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59678. {
  59679. if (canScroll != canScroll_)
  59680. {
  59681. canScroll = canScroll_;
  59682. resized();
  59683. }
  59684. }
  59685. void MidiKeyboardComponent::colourChanged()
  59686. {
  59687. repaint();
  59688. }
  59689. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59690. {
  59691. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59692. if (midiChannel != midiChannelNumber)
  59693. {
  59694. resetAnyKeysInUse();
  59695. midiChannel = jlimit (1, 16, midiChannelNumber);
  59696. }
  59697. }
  59698. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  59699. {
  59700. midiInChannelMask = midiChannelMask;
  59701. triggerAsyncUpdate();
  59702. }
  59703. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  59704. {
  59705. velocity = jlimit (0.0f, 1.0f, velocity_);
  59706. useMousePositionForVelocity = useMousePositionForVelocity_;
  59707. }
  59708. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  59709. {
  59710. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  59711. static const float blackNoteWidth = 0.7f;
  59712. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  59713. 1.0f, 2 - blackNoteWidth * 0.4f,
  59714. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  59715. 4.0f, 5 - blackNoteWidth * 0.5f,
  59716. 5.0f, 6 - blackNoteWidth * 0.3f,
  59717. 6.0f };
  59718. static const float widths[] = { 1.0f, blackNoteWidth,
  59719. 1.0f, blackNoteWidth,
  59720. 1.0f, 1.0f, blackNoteWidth,
  59721. 1.0f, blackNoteWidth,
  59722. 1.0f, blackNoteWidth,
  59723. 1.0f };
  59724. const int octave = midiNoteNumber / 12;
  59725. const int note = midiNoteNumber % 12;
  59726. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  59727. w = roundToInt (widths [note] * keyWidth);
  59728. }
  59729. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  59730. {
  59731. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  59732. int rx, rw;
  59733. getKeyPosition (rangeStart, keyWidth, rx, rw);
  59734. x -= xOffset + rx;
  59735. }
  59736. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  59737. {
  59738. int x, y;
  59739. getKeyPos (midiNoteNumber, x, y);
  59740. return x;
  59741. }
  59742. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  59743. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  59744. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  59745. {
  59746. if (! reallyContains (pos.getX(), pos.getY(), false))
  59747. return -1;
  59748. Point<int> p (pos);
  59749. if (orientation != horizontalKeyboard)
  59750. {
  59751. p = Point<int> (p.getY(), p.getX());
  59752. if (orientation == verticalKeyboardFacingLeft)
  59753. p = Point<int> (p.getX(), getWidth() - p.getY());
  59754. else
  59755. p = Point<int> (getHeight() - p.getX(), p.getY());
  59756. }
  59757. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  59758. }
  59759. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  59760. {
  59761. if (pos.getY() < blackNoteLength)
  59762. {
  59763. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59764. {
  59765. for (int i = 0; i < 5; ++i)
  59766. {
  59767. const int note = octaveStart + blackNotes [i];
  59768. if (note >= rangeStart && note <= rangeEnd)
  59769. {
  59770. int kx, kw;
  59771. getKeyPos (note, kx, kw);
  59772. kx += xOffset;
  59773. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59774. {
  59775. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  59776. return note;
  59777. }
  59778. }
  59779. }
  59780. }
  59781. }
  59782. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  59783. {
  59784. for (int i = 0; i < 7; ++i)
  59785. {
  59786. const int note = octaveStart + whiteNotes [i];
  59787. if (note >= rangeStart && note <= rangeEnd)
  59788. {
  59789. int kx, kw;
  59790. getKeyPos (note, kx, kw);
  59791. kx += xOffset;
  59792. if (pos.getX() >= kx && pos.getX() < kx + kw)
  59793. {
  59794. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  59795. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  59796. return note;
  59797. }
  59798. }
  59799. }
  59800. }
  59801. mousePositionVelocity = 0;
  59802. return -1;
  59803. }
  59804. void MidiKeyboardComponent::repaintNote (const int noteNum)
  59805. {
  59806. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59807. {
  59808. int x, w;
  59809. getKeyPos (noteNum, x, w);
  59810. if (orientation == horizontalKeyboard)
  59811. repaint (x, 0, w, getHeight());
  59812. else if (orientation == verticalKeyboardFacingLeft)
  59813. repaint (0, x, getWidth(), w);
  59814. else if (orientation == verticalKeyboardFacingRight)
  59815. repaint (0, getHeight() - x - w, getWidth(), w);
  59816. }
  59817. }
  59818. void MidiKeyboardComponent::paint (Graphics& g)
  59819. {
  59820. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  59821. const Colour lineColour (findColour (keySeparatorLineColourId));
  59822. const Colour textColour (findColour (textLabelColourId));
  59823. int x, w, octave;
  59824. for (octave = 0; octave < 128; octave += 12)
  59825. {
  59826. for (int white = 0; white < 7; ++white)
  59827. {
  59828. const int noteNum = octave + whiteNotes [white];
  59829. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59830. {
  59831. getKeyPos (noteNum, x, w);
  59832. if (orientation == horizontalKeyboard)
  59833. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  59834. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59835. noteUnderMouse == noteNum,
  59836. lineColour, textColour);
  59837. else if (orientation == verticalKeyboardFacingLeft)
  59838. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  59839. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59840. noteUnderMouse == noteNum,
  59841. lineColour, textColour);
  59842. else if (orientation == verticalKeyboardFacingRight)
  59843. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  59844. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59845. noteUnderMouse == noteNum,
  59846. lineColour, textColour);
  59847. }
  59848. }
  59849. }
  59850. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  59851. if (orientation == verticalKeyboardFacingLeft)
  59852. {
  59853. x1 = getWidth() - 1.0f;
  59854. x2 = getWidth() - 5.0f;
  59855. }
  59856. else if (orientation == verticalKeyboardFacingRight)
  59857. x2 = 5.0f;
  59858. else
  59859. y2 = 5.0f;
  59860. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  59861. Colours::transparentBlack, x2, y2, false));
  59862. getKeyPos (rangeEnd, x, w);
  59863. x += w;
  59864. if (orientation == verticalKeyboardFacingLeft)
  59865. g.fillRect (getWidth() - 5, 0, 5, x);
  59866. else if (orientation == verticalKeyboardFacingRight)
  59867. g.fillRect (0, 0, 5, x);
  59868. else
  59869. g.fillRect (0, 0, x, 5);
  59870. g.setColour (lineColour);
  59871. if (orientation == verticalKeyboardFacingLeft)
  59872. g.fillRect (0, 0, 1, x);
  59873. else if (orientation == verticalKeyboardFacingRight)
  59874. g.fillRect (getWidth() - 1, 0, 1, x);
  59875. else
  59876. g.fillRect (0, getHeight() - 1, x, 1);
  59877. const Colour blackNoteColour (findColour (blackNoteColourId));
  59878. for (octave = 0; octave < 128; octave += 12)
  59879. {
  59880. for (int black = 0; black < 5; ++black)
  59881. {
  59882. const int noteNum = octave + blackNotes [black];
  59883. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  59884. {
  59885. getKeyPos (noteNum, x, w);
  59886. if (orientation == horizontalKeyboard)
  59887. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  59888. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59889. noteUnderMouse == noteNum,
  59890. blackNoteColour);
  59891. else if (orientation == verticalKeyboardFacingLeft)
  59892. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  59893. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59894. noteUnderMouse == noteNum,
  59895. blackNoteColour);
  59896. else if (orientation == verticalKeyboardFacingRight)
  59897. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  59898. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  59899. noteUnderMouse == noteNum,
  59900. blackNoteColour);
  59901. }
  59902. }
  59903. }
  59904. }
  59905. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  59906. Graphics& g, int x, int y, int w, int h,
  59907. bool isDown, bool isOver,
  59908. const Colour& lineColour,
  59909. const Colour& textColour)
  59910. {
  59911. Colour c (Colours::transparentWhite);
  59912. if (isDown)
  59913. c = findColour (keyDownOverlayColourId);
  59914. if (isOver)
  59915. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59916. g.setColour (c);
  59917. g.fillRect (x, y, w, h);
  59918. const String text (getWhiteNoteText (midiNoteNumber));
  59919. if (! text.isEmpty())
  59920. {
  59921. g.setColour (textColour);
  59922. Font f (jmin (12.0f, keyWidth * 0.9f));
  59923. f.setHorizontalScale (0.8f);
  59924. g.setFont (f);
  59925. Justification justification (Justification::centredBottom);
  59926. if (orientation == verticalKeyboardFacingLeft)
  59927. justification = Justification::centredLeft;
  59928. else if (orientation == verticalKeyboardFacingRight)
  59929. justification = Justification::centredRight;
  59930. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  59931. }
  59932. g.setColour (lineColour);
  59933. if (orientation == horizontalKeyboard)
  59934. g.fillRect (x, y, 1, h);
  59935. else if (orientation == verticalKeyboardFacingLeft)
  59936. g.fillRect (x, y, w, 1);
  59937. else if (orientation == verticalKeyboardFacingRight)
  59938. g.fillRect (x, y + h - 1, w, 1);
  59939. if (midiNoteNumber == rangeEnd)
  59940. {
  59941. if (orientation == horizontalKeyboard)
  59942. g.fillRect (x + w, y, 1, h);
  59943. else if (orientation == verticalKeyboardFacingLeft)
  59944. g.fillRect (x, y + h, w, 1);
  59945. else if (orientation == verticalKeyboardFacingRight)
  59946. g.fillRect (x, y - 1, w, 1);
  59947. }
  59948. }
  59949. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  59950. Graphics& g, int x, int y, int w, int h,
  59951. bool isDown, bool isOver,
  59952. const Colour& noteFillColour)
  59953. {
  59954. Colour c (noteFillColour);
  59955. if (isDown)
  59956. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  59957. if (isOver)
  59958. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  59959. g.setColour (c);
  59960. g.fillRect (x, y, w, h);
  59961. if (isDown)
  59962. {
  59963. g.setColour (noteFillColour);
  59964. g.drawRect (x, y, w, h);
  59965. }
  59966. else
  59967. {
  59968. const int xIndent = jmax (1, jmin (w, h) / 8);
  59969. g.setColour (c.brighter());
  59970. if (orientation == horizontalKeyboard)
  59971. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  59972. else if (orientation == verticalKeyboardFacingLeft)
  59973. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  59974. else if (orientation == verticalKeyboardFacingRight)
  59975. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  59976. }
  59977. }
  59978. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  59979. {
  59980. octaveNumForMiddleC = octaveNumForMiddleC_;
  59981. repaint();
  59982. }
  59983. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  59984. {
  59985. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  59986. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  59987. return String::empty;
  59988. }
  59989. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  59990. const bool isMouseOver,
  59991. const bool isButtonDown,
  59992. const bool movesOctavesUp)
  59993. {
  59994. g.fillAll (findColour (upDownButtonBackgroundColourId));
  59995. float angle;
  59996. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  59997. angle = movesOctavesUp ? 0.0f : 0.5f;
  59998. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  59999. angle = movesOctavesUp ? 0.25f : 0.75f;
  60000. else
  60001. angle = movesOctavesUp ? 0.75f : 0.25f;
  60002. Path path;
  60003. path.lineTo (0.0f, 1.0f);
  60004. path.lineTo (1.0f, 0.5f);
  60005. path.closeSubPath();
  60006. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60007. g.setColour (findColour (upDownButtonArrowColourId)
  60008. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60009. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60010. w - 2.0f,
  60011. h - 2.0f,
  60012. true));
  60013. }
  60014. void MidiKeyboardComponent::resized()
  60015. {
  60016. int w = getWidth();
  60017. int h = getHeight();
  60018. if (w > 0 && h > 0)
  60019. {
  60020. if (orientation != horizontalKeyboard)
  60021. swapVariables (w, h);
  60022. blackNoteLength = roundToInt (h * 0.7f);
  60023. int kx2, kw2;
  60024. getKeyPos (rangeEnd, kx2, kw2);
  60025. kx2 += kw2;
  60026. if (firstKey != rangeStart)
  60027. {
  60028. int kx1, kw1;
  60029. getKeyPos (rangeStart, kx1, kw1);
  60030. if (kx2 - kx1 <= w)
  60031. {
  60032. firstKey = rangeStart;
  60033. sendChangeMessage (this);
  60034. repaint();
  60035. }
  60036. }
  60037. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60038. scrollDown->setVisible (showScrollButtons);
  60039. scrollUp->setVisible (showScrollButtons);
  60040. xOffset = 0;
  60041. if (showScrollButtons)
  60042. {
  60043. const int scrollButtonW = jmin (12, w / 2);
  60044. if (orientation == horizontalKeyboard)
  60045. {
  60046. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60047. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60048. }
  60049. else if (orientation == verticalKeyboardFacingLeft)
  60050. {
  60051. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60052. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60053. }
  60054. else if (orientation == verticalKeyboardFacingRight)
  60055. {
  60056. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60057. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60058. }
  60059. int endOfLastKey, kw;
  60060. getKeyPos (rangeEnd, endOfLastKey, kw);
  60061. endOfLastKey += kw;
  60062. float mousePositionVelocity;
  60063. const int spaceAvailable = w - scrollButtonW * 2;
  60064. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60065. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60066. {
  60067. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60068. sendChangeMessage (this);
  60069. }
  60070. int newOffset = 0;
  60071. getKeyPos (firstKey, newOffset, kw);
  60072. xOffset = newOffset - scrollButtonW;
  60073. }
  60074. else
  60075. {
  60076. firstKey = rangeStart;
  60077. }
  60078. timerCallback();
  60079. repaint();
  60080. }
  60081. }
  60082. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60083. {
  60084. triggerAsyncUpdate();
  60085. }
  60086. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60087. {
  60088. triggerAsyncUpdate();
  60089. }
  60090. void MidiKeyboardComponent::handleAsyncUpdate()
  60091. {
  60092. for (int i = rangeStart; i <= rangeEnd; ++i)
  60093. {
  60094. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60095. {
  60096. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60097. repaintNote (i);
  60098. }
  60099. }
  60100. }
  60101. void MidiKeyboardComponent::resetAnyKeysInUse()
  60102. {
  60103. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60104. {
  60105. state.allNotesOff (midiChannel);
  60106. keysPressed.clear();
  60107. mouseDownNote = -1;
  60108. }
  60109. }
  60110. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60111. {
  60112. float mousePositionVelocity = 0.0f;
  60113. const int newNote = (mouseDragging || isMouseOver())
  60114. ? xyToNote (pos, mousePositionVelocity) : -1;
  60115. if (noteUnderMouse != newNote)
  60116. {
  60117. if (mouseDownNote >= 0)
  60118. {
  60119. state.noteOff (midiChannel, mouseDownNote);
  60120. mouseDownNote = -1;
  60121. }
  60122. if (mouseDragging && newNote >= 0)
  60123. {
  60124. if (! useMousePositionForVelocity)
  60125. mousePositionVelocity = 1.0f;
  60126. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60127. mouseDownNote = newNote;
  60128. }
  60129. repaintNote (noteUnderMouse);
  60130. noteUnderMouse = newNote;
  60131. repaintNote (noteUnderMouse);
  60132. }
  60133. else if (mouseDownNote >= 0 && ! mouseDragging)
  60134. {
  60135. state.noteOff (midiChannel, mouseDownNote);
  60136. mouseDownNote = -1;
  60137. }
  60138. }
  60139. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60140. {
  60141. updateNoteUnderMouse (e.getPosition());
  60142. stopTimer();
  60143. }
  60144. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60145. {
  60146. float mousePositionVelocity;
  60147. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60148. if (newNote >= 0)
  60149. mouseDraggedToKey (newNote, e);
  60150. updateNoteUnderMouse (e.getPosition());
  60151. }
  60152. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60153. {
  60154. return true;
  60155. }
  60156. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60157. {
  60158. }
  60159. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60160. {
  60161. float mousePositionVelocity;
  60162. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60163. mouseDragging = false;
  60164. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60165. {
  60166. repaintNote (noteUnderMouse);
  60167. noteUnderMouse = -1;
  60168. mouseDragging = true;
  60169. updateNoteUnderMouse (e.getPosition());
  60170. startTimer (500);
  60171. }
  60172. }
  60173. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60174. {
  60175. mouseDragging = false;
  60176. updateNoteUnderMouse (e.getPosition());
  60177. stopTimer();
  60178. }
  60179. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60180. {
  60181. updateNoteUnderMouse (e.getPosition());
  60182. }
  60183. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60184. {
  60185. updateNoteUnderMouse (e.getPosition());
  60186. }
  60187. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60188. {
  60189. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60190. }
  60191. void MidiKeyboardComponent::timerCallback()
  60192. {
  60193. updateNoteUnderMouse (getMouseXYRelative());
  60194. }
  60195. void MidiKeyboardComponent::clearKeyMappings()
  60196. {
  60197. resetAnyKeysInUse();
  60198. keyPressNotes.clear();
  60199. keyPresses.clear();
  60200. }
  60201. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60202. const int midiNoteOffsetFromC)
  60203. {
  60204. removeKeyPressForNote (midiNoteOffsetFromC);
  60205. keyPressNotes.add (midiNoteOffsetFromC);
  60206. keyPresses.add (key);
  60207. }
  60208. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60209. {
  60210. for (int i = keyPressNotes.size(); --i >= 0;)
  60211. {
  60212. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60213. {
  60214. keyPressNotes.remove (i);
  60215. keyPresses.remove (i);
  60216. }
  60217. }
  60218. }
  60219. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60220. {
  60221. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60222. keyMappingOctave = newOctaveNumber;
  60223. }
  60224. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60225. {
  60226. bool keyPressUsed = false;
  60227. for (int i = keyPresses.size(); --i >= 0;)
  60228. {
  60229. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60230. if (keyPresses.getReference(i).isCurrentlyDown())
  60231. {
  60232. if (! keysPressed [note])
  60233. {
  60234. keysPressed.setBit (note);
  60235. state.noteOn (midiChannel, note, velocity);
  60236. keyPressUsed = true;
  60237. }
  60238. }
  60239. else
  60240. {
  60241. if (keysPressed [note])
  60242. {
  60243. keysPressed.clearBit (note);
  60244. state.noteOff (midiChannel, note);
  60245. keyPressUsed = true;
  60246. }
  60247. }
  60248. }
  60249. return keyPressUsed;
  60250. }
  60251. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60252. {
  60253. resetAnyKeysInUse();
  60254. }
  60255. END_JUCE_NAMESPACE
  60256. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60257. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60258. #if JUCE_OPENGL
  60259. BEGIN_JUCE_NAMESPACE
  60260. extern void juce_glViewport (const int w, const int h);
  60261. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60262. const int alphaBits_,
  60263. const int depthBufferBits_,
  60264. const int stencilBufferBits_)
  60265. : redBits (bitsPerRGBComponent),
  60266. greenBits (bitsPerRGBComponent),
  60267. blueBits (bitsPerRGBComponent),
  60268. alphaBits (alphaBits_),
  60269. depthBufferBits (depthBufferBits_),
  60270. stencilBufferBits (stencilBufferBits_),
  60271. accumulationBufferRedBits (0),
  60272. accumulationBufferGreenBits (0),
  60273. accumulationBufferBlueBits (0),
  60274. accumulationBufferAlphaBits (0),
  60275. fullSceneAntiAliasingNumSamples (0)
  60276. {
  60277. }
  60278. OpenGLPixelFormat::OpenGLPixelFormat (const OpenGLPixelFormat& other)
  60279. : redBits (other.redBits),
  60280. greenBits (other.greenBits),
  60281. blueBits (other.blueBits),
  60282. alphaBits (other.alphaBits),
  60283. depthBufferBits (other.depthBufferBits),
  60284. stencilBufferBits (other.stencilBufferBits),
  60285. accumulationBufferRedBits (other.accumulationBufferRedBits),
  60286. accumulationBufferGreenBits (other.accumulationBufferGreenBits),
  60287. accumulationBufferBlueBits (other.accumulationBufferBlueBits),
  60288. accumulationBufferAlphaBits (other.accumulationBufferAlphaBits),
  60289. fullSceneAntiAliasingNumSamples (other.fullSceneAntiAliasingNumSamples)
  60290. {
  60291. }
  60292. OpenGLPixelFormat& OpenGLPixelFormat::operator= (const OpenGLPixelFormat& other)
  60293. {
  60294. redBits = other.redBits;
  60295. greenBits = other.greenBits;
  60296. blueBits = other.blueBits;
  60297. alphaBits = other.alphaBits;
  60298. depthBufferBits = other.depthBufferBits;
  60299. stencilBufferBits = other.stencilBufferBits;
  60300. accumulationBufferRedBits = other.accumulationBufferRedBits;
  60301. accumulationBufferGreenBits = other.accumulationBufferGreenBits;
  60302. accumulationBufferBlueBits = other.accumulationBufferBlueBits;
  60303. accumulationBufferAlphaBits = other.accumulationBufferAlphaBits;
  60304. fullSceneAntiAliasingNumSamples = other.fullSceneAntiAliasingNumSamples;
  60305. return *this;
  60306. }
  60307. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const
  60308. {
  60309. return redBits == other.redBits
  60310. && greenBits == other.greenBits
  60311. && blueBits == other.blueBits
  60312. && alphaBits == other.alphaBits
  60313. && depthBufferBits == other.depthBufferBits
  60314. && stencilBufferBits == other.stencilBufferBits
  60315. && accumulationBufferRedBits == other.accumulationBufferRedBits
  60316. && accumulationBufferGreenBits == other.accumulationBufferGreenBits
  60317. && accumulationBufferBlueBits == other.accumulationBufferBlueBits
  60318. && accumulationBufferAlphaBits == other.accumulationBufferAlphaBits
  60319. && fullSceneAntiAliasingNumSamples == other.fullSceneAntiAliasingNumSamples;
  60320. }
  60321. static VoidArray knownContexts;
  60322. OpenGLContext::OpenGLContext() throw()
  60323. {
  60324. knownContexts.add (this);
  60325. }
  60326. OpenGLContext::~OpenGLContext()
  60327. {
  60328. knownContexts.removeValue (this);
  60329. }
  60330. OpenGLContext* OpenGLContext::getCurrentContext()
  60331. {
  60332. for (int i = knownContexts.size(); --i >= 0;)
  60333. {
  60334. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60335. if (oglc->isActive())
  60336. return oglc;
  60337. }
  60338. return 0;
  60339. }
  60340. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60341. {
  60342. public:
  60343. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60344. : ComponentMovementWatcher (owner_),
  60345. owner (owner_),
  60346. wasShowing (false)
  60347. {
  60348. }
  60349. ~OpenGLComponentWatcher() {}
  60350. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60351. {
  60352. owner->updateContextPosition();
  60353. }
  60354. void componentPeerChanged()
  60355. {
  60356. const ScopedLock sl (owner->getContextLock());
  60357. owner->deleteContext();
  60358. }
  60359. void componentVisibilityChanged (Component&)
  60360. {
  60361. const bool isShowingNow = owner->isShowing();
  60362. if (wasShowing != isShowingNow)
  60363. {
  60364. wasShowing = isShowingNow;
  60365. owner->updateContextPosition();
  60366. }
  60367. }
  60368. juce_UseDebuggingNewOperator
  60369. private:
  60370. OpenGLComponent* const owner;
  60371. bool wasShowing;
  60372. };
  60373. OpenGLComponent::OpenGLComponent (const OpenGLType type_)
  60374. : type (type_),
  60375. contextToShareListsWith (0),
  60376. needToUpdateViewport (true)
  60377. {
  60378. setOpaque (true);
  60379. componentWatcher = new OpenGLComponentWatcher (this);
  60380. }
  60381. OpenGLComponent::~OpenGLComponent()
  60382. {
  60383. deleteContext();
  60384. componentWatcher = 0;
  60385. }
  60386. void OpenGLComponent::deleteContext()
  60387. {
  60388. const ScopedLock sl (contextLock);
  60389. context = 0;
  60390. }
  60391. void OpenGLComponent::updateContextPosition()
  60392. {
  60393. needToUpdateViewport = true;
  60394. if (getWidth() > 0 && getHeight() > 0)
  60395. {
  60396. Component* const topComp = getTopLevelComponent();
  60397. if (topComp->getPeer() != 0)
  60398. {
  60399. const ScopedLock sl (contextLock);
  60400. if (context != 0)
  60401. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60402. getScreenY() - topComp->getScreenY(),
  60403. getWidth(),
  60404. getHeight(),
  60405. topComp->getHeight());
  60406. }
  60407. }
  60408. }
  60409. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60410. {
  60411. OpenGLPixelFormat pf;
  60412. const ScopedLock sl (contextLock);
  60413. if (context != 0)
  60414. pf = context->getPixelFormat();
  60415. return pf;
  60416. }
  60417. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60418. {
  60419. if (! (preferredPixelFormat == formatToUse))
  60420. {
  60421. const ScopedLock sl (contextLock);
  60422. deleteContext();
  60423. preferredPixelFormat = formatToUse;
  60424. }
  60425. }
  60426. void OpenGLComponent::shareWith (OpenGLContext* c)
  60427. {
  60428. if (contextToShareListsWith != c)
  60429. {
  60430. const ScopedLock sl (contextLock);
  60431. deleteContext();
  60432. contextToShareListsWith = c;
  60433. }
  60434. }
  60435. bool OpenGLComponent::makeCurrentContextActive()
  60436. {
  60437. if (context == 0)
  60438. {
  60439. const ScopedLock sl (contextLock);
  60440. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60441. {
  60442. context = createContext();
  60443. if (context != 0)
  60444. {
  60445. updateContextPosition();
  60446. if (context->makeActive())
  60447. newOpenGLContextCreated();
  60448. }
  60449. }
  60450. }
  60451. return context != 0 && context->makeActive();
  60452. }
  60453. void OpenGLComponent::makeCurrentContextInactive()
  60454. {
  60455. if (context != 0)
  60456. context->makeInactive();
  60457. }
  60458. bool OpenGLComponent::isActiveContext() const throw()
  60459. {
  60460. return context != 0 && context->isActive();
  60461. }
  60462. void OpenGLComponent::swapBuffers()
  60463. {
  60464. if (context != 0)
  60465. context->swapBuffers();
  60466. }
  60467. void OpenGLComponent::paint (Graphics&)
  60468. {
  60469. if (renderAndSwapBuffers())
  60470. {
  60471. ComponentPeer* const peer = getPeer();
  60472. if (peer != 0)
  60473. {
  60474. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60475. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60476. }
  60477. }
  60478. }
  60479. bool OpenGLComponent::renderAndSwapBuffers()
  60480. {
  60481. const ScopedLock sl (contextLock);
  60482. if (! makeCurrentContextActive())
  60483. return false;
  60484. if (needToUpdateViewport)
  60485. {
  60486. needToUpdateViewport = false;
  60487. juce_glViewport (getWidth(), getHeight());
  60488. }
  60489. renderOpenGL();
  60490. swapBuffers();
  60491. return true;
  60492. }
  60493. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60494. {
  60495. Component::internalRepaint (x, y, w, h);
  60496. if (context != 0)
  60497. context->repaint();
  60498. }
  60499. END_JUCE_NAMESPACE
  60500. #endif
  60501. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60502. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60503. BEGIN_JUCE_NAMESPACE
  60504. PreferencesPanel::PreferencesPanel()
  60505. : buttonSize (70)
  60506. {
  60507. }
  60508. PreferencesPanel::~PreferencesPanel()
  60509. {
  60510. currentPage = 0;
  60511. deleteAllChildren();
  60512. }
  60513. void PreferencesPanel::addSettingsPage (const String& title,
  60514. const Drawable* icon,
  60515. const Drawable* overIcon,
  60516. const Drawable* downIcon)
  60517. {
  60518. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60519. button->setImages (icon, overIcon, downIcon);
  60520. button->setRadioGroupId (1);
  60521. button->addButtonListener (this);
  60522. button->setClickingTogglesState (true);
  60523. button->setWantsKeyboardFocus (false);
  60524. addAndMakeVisible (button);
  60525. resized();
  60526. if (currentPage == 0)
  60527. setCurrentPage (title);
  60528. }
  60529. void PreferencesPanel::addSettingsPage (const String& title,
  60530. const char* imageData,
  60531. const int imageDataSize)
  60532. {
  60533. DrawableImage icon, iconOver, iconDown;
  60534. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60535. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60536. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60537. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60538. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60539. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60540. }
  60541. class PrefsDialogWindow : public DialogWindow
  60542. {
  60543. public:
  60544. PrefsDialogWindow (const String& dialogtitle,
  60545. const Colour& backgroundColour)
  60546. : DialogWindow (dialogtitle, backgroundColour, true)
  60547. {
  60548. }
  60549. ~PrefsDialogWindow()
  60550. {
  60551. }
  60552. void closeButtonPressed()
  60553. {
  60554. exitModalState (0);
  60555. }
  60556. private:
  60557. PrefsDialogWindow (const PrefsDialogWindow&);
  60558. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60559. };
  60560. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60561. int dialogWidth,
  60562. int dialogHeight,
  60563. const Colour& backgroundColour)
  60564. {
  60565. setSize (dialogWidth, dialogHeight);
  60566. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60567. dw.setContentComponent (this, true, true);
  60568. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60569. dw.runModalLoop();
  60570. dw.setContentComponent (0, false, false);
  60571. }
  60572. void PreferencesPanel::resized()
  60573. {
  60574. int x = 0;
  60575. for (int i = 0; i < getNumChildComponents(); ++i)
  60576. {
  60577. Component* c = getChildComponent (i);
  60578. if (dynamic_cast <DrawableButton*> (c) == 0)
  60579. {
  60580. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60581. }
  60582. else
  60583. {
  60584. c->setBounds (x, 0, buttonSize, buttonSize);
  60585. x += buttonSize;
  60586. }
  60587. }
  60588. }
  60589. void PreferencesPanel::paint (Graphics& g)
  60590. {
  60591. g.setColour (Colours::grey);
  60592. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60593. }
  60594. void PreferencesPanel::setCurrentPage (const String& pageName)
  60595. {
  60596. if (currentPageName != pageName)
  60597. {
  60598. currentPageName = pageName;
  60599. currentPage = 0;
  60600. currentPage = createComponentForPage (pageName);
  60601. if (currentPage != 0)
  60602. {
  60603. addAndMakeVisible (currentPage);
  60604. currentPage->toBack();
  60605. resized();
  60606. }
  60607. for (int i = 0; i < getNumChildComponents(); ++i)
  60608. {
  60609. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60610. if (db != 0 && db->getName() == pageName)
  60611. {
  60612. db->setToggleState (true, false);
  60613. break;
  60614. }
  60615. }
  60616. }
  60617. }
  60618. void PreferencesPanel::buttonClicked (Button*)
  60619. {
  60620. for (int i = 0; i < getNumChildComponents(); ++i)
  60621. {
  60622. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60623. if (db != 0 && db->getToggleState())
  60624. {
  60625. setCurrentPage (db->getName());
  60626. break;
  60627. }
  60628. }
  60629. }
  60630. END_JUCE_NAMESPACE
  60631. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60632. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60633. #if JUCE_WINDOWS || JUCE_LINUX
  60634. BEGIN_JUCE_NAMESPACE
  60635. SystemTrayIconComponent::SystemTrayIconComponent()
  60636. {
  60637. addToDesktop (0);
  60638. }
  60639. SystemTrayIconComponent::~SystemTrayIconComponent()
  60640. {
  60641. }
  60642. END_JUCE_NAMESPACE
  60643. #endif
  60644. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60645. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60646. BEGIN_JUCE_NAMESPACE
  60647. class AlertWindowTextEditor : public TextEditor
  60648. {
  60649. public:
  60650. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60651. : TextEditor (name, isPasswordBox ? getDefaultPasswordChar() : 0)
  60652. {
  60653. setSelectAllWhenFocused (true);
  60654. }
  60655. ~AlertWindowTextEditor()
  60656. {
  60657. }
  60658. void returnPressed()
  60659. {
  60660. // pass these up the component hierarchy to be trigger the buttons
  60661. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, '\n'));
  60662. }
  60663. void escapePressed()
  60664. {
  60665. // pass these up the component hierarchy to be trigger the buttons
  60666. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60667. }
  60668. private:
  60669. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60670. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60671. static juce_wchar getDefaultPasswordChar() throw()
  60672. {
  60673. #if JUCE_LINUX
  60674. return 0x2022;
  60675. #else
  60676. return 0x25cf;
  60677. #endif
  60678. }
  60679. };
  60680. AlertWindow::AlertWindow (const String& title,
  60681. const String& message,
  60682. AlertIconType iconType,
  60683. Component* associatedComponent_)
  60684. : TopLevelWindow (title, true),
  60685. alertIconType (iconType),
  60686. associatedComponent (associatedComponent_)
  60687. {
  60688. if (message.isEmpty())
  60689. text = " "; // to force an update if the message is empty
  60690. setMessage (message);
  60691. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60692. {
  60693. Component* const c = Desktop::getInstance().getComponent (i);
  60694. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60695. {
  60696. setAlwaysOnTop (true);
  60697. break;
  60698. }
  60699. }
  60700. if (JUCEApplication::getInstance() == 0)
  60701. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60702. lookAndFeelChanged();
  60703. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60704. }
  60705. AlertWindow::~AlertWindow()
  60706. {
  60707. for (int i = customComps.size(); --i >= 0;)
  60708. removeChildComponent ((Component*) customComps[i]);
  60709. deleteAllChildren();
  60710. }
  60711. void AlertWindow::userTriedToCloseWindow()
  60712. {
  60713. exitModalState (0);
  60714. }
  60715. void AlertWindow::setMessage (const String& message)
  60716. {
  60717. const String newMessage (message.substring (0, 2048));
  60718. if (text != newMessage)
  60719. {
  60720. text = newMessage;
  60721. font.setHeight (15.0f);
  60722. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60723. textLayout.setText (getName() + "\n\n", titleFont);
  60724. textLayout.appendText (text, font);
  60725. updateLayout (true);
  60726. repaint();
  60727. }
  60728. }
  60729. void AlertWindow::buttonClicked (Button* button)
  60730. {
  60731. for (int i = 0; i < buttons.size(); i++)
  60732. {
  60733. TextButton* const c = (TextButton*) buttons[i];
  60734. if (button->getName() == c->getName())
  60735. {
  60736. if (c->getParentComponent() != 0)
  60737. c->getParentComponent()->exitModalState (c->getCommandID());
  60738. break;
  60739. }
  60740. }
  60741. }
  60742. void AlertWindow::addButton (const String& name,
  60743. const int returnValue,
  60744. const KeyPress& shortcutKey1,
  60745. const KeyPress& shortcutKey2)
  60746. {
  60747. TextButton* const b = new TextButton (name, String::empty);
  60748. b->setWantsKeyboardFocus (true);
  60749. b->setMouseClickGrabsKeyboardFocus (false);
  60750. b->setCommandToTrigger (0, returnValue, false);
  60751. b->addShortcut (shortcutKey1);
  60752. b->addShortcut (shortcutKey2);
  60753. b->addButtonListener (this);
  60754. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  60755. addAndMakeVisible (b, 0);
  60756. buttons.add (b);
  60757. updateLayout (false);
  60758. }
  60759. int AlertWindow::getNumButtons() const
  60760. {
  60761. return buttons.size();
  60762. }
  60763. void AlertWindow::addTextEditor (const String& name,
  60764. const String& initialContents,
  60765. const String& onScreenLabel,
  60766. const bool isPasswordBox)
  60767. {
  60768. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  60769. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  60770. tc->setFont (font);
  60771. tc->setText (initialContents);
  60772. tc->setCaretPosition (initialContents.length());
  60773. addAndMakeVisible (tc);
  60774. textBoxes.add (tc);
  60775. allComps.add (tc);
  60776. textboxNames.add (onScreenLabel);
  60777. updateLayout (false);
  60778. }
  60779. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  60780. {
  60781. for (int i = textBoxes.size(); --i >= 0;)
  60782. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  60783. return ((TextEditor*)textBoxes[i])->getText();
  60784. return String::empty;
  60785. }
  60786. void AlertWindow::addComboBox (const String& name,
  60787. const StringArray& items,
  60788. const String& onScreenLabel)
  60789. {
  60790. ComboBox* const cb = new ComboBox (name);
  60791. for (int i = 0; i < items.size(); ++i)
  60792. cb->addItem (items[i], i + 1);
  60793. addAndMakeVisible (cb);
  60794. cb->setSelectedItemIndex (0);
  60795. comboBoxes.add (cb);
  60796. allComps.add (cb);
  60797. comboBoxNames.add (onScreenLabel);
  60798. updateLayout (false);
  60799. }
  60800. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  60801. {
  60802. for (int i = comboBoxes.size(); --i >= 0;)
  60803. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  60804. return (ComboBox*) comboBoxes[i];
  60805. return 0;
  60806. }
  60807. class AlertTextComp : public TextEditor
  60808. {
  60809. public:
  60810. AlertTextComp (const String& message,
  60811. const Font& font)
  60812. {
  60813. setReadOnly (true);
  60814. setMultiLine (true, true);
  60815. setCaretVisible (false);
  60816. setScrollbarsShown (true);
  60817. lookAndFeelChanged();
  60818. setWantsKeyboardFocus (false);
  60819. setFont (font);
  60820. setText (message, false);
  60821. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  60822. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  60823. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  60824. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  60825. }
  60826. ~AlertTextComp()
  60827. {
  60828. }
  60829. int getPreferredWidth() const throw() { return bestWidth; }
  60830. void updateLayout (const int width)
  60831. {
  60832. TextLayout text;
  60833. text.appendText (getText(), getFont());
  60834. text.layout (width - 8, Justification::topLeft, true);
  60835. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  60836. }
  60837. private:
  60838. int bestWidth;
  60839. AlertTextComp (const AlertTextComp&);
  60840. AlertTextComp& operator= (const AlertTextComp&);
  60841. };
  60842. void AlertWindow::addTextBlock (const String& text)
  60843. {
  60844. AlertTextComp* const c = new AlertTextComp (text, font);
  60845. textBlocks.add (c);
  60846. allComps.add (c);
  60847. addAndMakeVisible (c);
  60848. updateLayout (false);
  60849. }
  60850. void AlertWindow::addProgressBarComponent (double& progressValue)
  60851. {
  60852. ProgressBar* const pb = new ProgressBar (progressValue);
  60853. progressBars.add (pb);
  60854. allComps.add (pb);
  60855. addAndMakeVisible (pb);
  60856. updateLayout (false);
  60857. }
  60858. void AlertWindow::addCustomComponent (Component* const component)
  60859. {
  60860. customComps.add (component);
  60861. allComps.add (component);
  60862. addAndMakeVisible (component);
  60863. updateLayout (false);
  60864. }
  60865. int AlertWindow::getNumCustomComponents() const
  60866. {
  60867. return customComps.size();
  60868. }
  60869. Component* AlertWindow::getCustomComponent (const int index) const
  60870. {
  60871. return (Component*) customComps [index];
  60872. }
  60873. Component* AlertWindow::removeCustomComponent (const int index)
  60874. {
  60875. Component* const c = getCustomComponent (index);
  60876. if (c != 0)
  60877. {
  60878. customComps.removeValue (c);
  60879. allComps.removeValue (c);
  60880. removeChildComponent (c);
  60881. updateLayout (false);
  60882. }
  60883. return c;
  60884. }
  60885. void AlertWindow::paint (Graphics& g)
  60886. {
  60887. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  60888. g.setColour (findColour (textColourId));
  60889. g.setFont (getLookAndFeel().getAlertWindowFont());
  60890. int i;
  60891. for (i = textBoxes.size(); --i >= 0;)
  60892. {
  60893. const TextEditor* const te = (TextEditor*) textBoxes[i];
  60894. g.drawFittedText (textboxNames[i],
  60895. te->getX(), te->getY() - 14,
  60896. te->getWidth(), 14,
  60897. Justification::centredLeft, 1);
  60898. }
  60899. for (i = comboBoxNames.size(); --i >= 0;)
  60900. {
  60901. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  60902. g.drawFittedText (comboBoxNames[i],
  60903. cb->getX(), cb->getY() - 14,
  60904. cb->getWidth(), 14,
  60905. Justification::centredLeft, 1);
  60906. }
  60907. for (i = customComps.size(); --i >= 0;)
  60908. {
  60909. const Component* const c = (Component*) customComps[i];
  60910. g.drawFittedText (c->getName(),
  60911. c->getX(), c->getY() - 14,
  60912. c->getWidth(), 14,
  60913. Justification::centredLeft, 1);
  60914. }
  60915. }
  60916. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  60917. {
  60918. const int titleH = 24;
  60919. const int iconWidth = 80;
  60920. const int wid = jmax (font.getStringWidth (text),
  60921. font.getStringWidth (getName()));
  60922. const int sw = (int) sqrt (font.getHeight() * wid);
  60923. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  60924. const int edgeGap = 10;
  60925. const int labelHeight = 18;
  60926. int iconSpace;
  60927. if (alertIconType == NoIcon)
  60928. {
  60929. textLayout.layout (w, Justification::horizontallyCentred, true);
  60930. iconSpace = 0;
  60931. }
  60932. else
  60933. {
  60934. textLayout.layout (w, Justification::left, true);
  60935. iconSpace = iconWidth;
  60936. }
  60937. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  60938. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60939. const int textLayoutH = textLayout.getHeight();
  60940. const int textBottom = 16 + titleH + textLayoutH;
  60941. int h = textBottom;
  60942. int buttonW = 40;
  60943. int i;
  60944. for (i = 0; i < buttons.size(); ++i)
  60945. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  60946. w = jmax (buttonW, w);
  60947. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  60948. if (buttons.size() > 0)
  60949. h += 20 + ((TextButton*) buttons[0])->getHeight();
  60950. for (i = customComps.size(); --i >= 0;)
  60951. {
  60952. Component* c = (Component*) customComps[i];
  60953. w = jmax (w, (c->getWidth() * 100) / 80);
  60954. h += 10 + c->getHeight();
  60955. if (c->getName().isNotEmpty())
  60956. h += labelHeight;
  60957. }
  60958. for (i = textBlocks.size(); --i >= 0;)
  60959. {
  60960. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60961. w = jmax (w, ac->getPreferredWidth());
  60962. }
  60963. w = jmin (w, (int) (getParentWidth() * 0.7f));
  60964. for (i = textBlocks.size(); --i >= 0;)
  60965. {
  60966. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  60967. ac->updateLayout ((int) (w * 0.8f));
  60968. h += ac->getHeight() + 10;
  60969. }
  60970. h = jmin (getParentHeight() - 50, h);
  60971. if (onlyIncreaseSize)
  60972. {
  60973. w = jmax (w, getWidth());
  60974. h = jmax (h, getHeight());
  60975. }
  60976. if (! isVisible())
  60977. {
  60978. centreAroundComponent (associatedComponent, w, h);
  60979. }
  60980. else
  60981. {
  60982. const int cx = getX() + getWidth() / 2;
  60983. const int cy = getY() + getHeight() / 2;
  60984. setBounds (cx - w / 2,
  60985. cy - h / 2,
  60986. w, h);
  60987. }
  60988. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  60989. const int spacer = 16;
  60990. int totalWidth = -spacer;
  60991. for (i = buttons.size(); --i >= 0;)
  60992. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  60993. int x = (w - totalWidth) / 2;
  60994. int y = (int) (getHeight() * 0.95f);
  60995. for (i = 0; i < buttons.size(); ++i)
  60996. {
  60997. TextButton* const c = (TextButton*) buttons[i];
  60998. int ny = proportionOfHeight (0.95f) - c->getHeight();
  60999. c->setTopLeftPosition (x, ny);
  61000. if (ny < y)
  61001. y = ny;
  61002. x += c->getWidth() + spacer;
  61003. c->toFront (false);
  61004. }
  61005. y = textBottom;
  61006. for (i = 0; i < allComps.size(); ++i)
  61007. {
  61008. Component* const c = (Component*) allComps[i];
  61009. int h = 22;
  61010. const int comboIndex = comboBoxes.indexOf (c);
  61011. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61012. y += labelHeight;
  61013. const int tbIndex = textBoxes.indexOf (c);
  61014. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61015. y += labelHeight;
  61016. if (customComps.contains (c))
  61017. {
  61018. if (c->getName().isNotEmpty())
  61019. y += labelHeight;
  61020. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61021. h = c->getHeight();
  61022. }
  61023. else if (textBlocks.contains (c))
  61024. {
  61025. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61026. h = c->getHeight();
  61027. }
  61028. else
  61029. {
  61030. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61031. }
  61032. y += h + 10;
  61033. }
  61034. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61035. }
  61036. bool AlertWindow::containsAnyExtraComponents() const
  61037. {
  61038. return textBoxes.size()
  61039. + comboBoxes.size()
  61040. + progressBars.size()
  61041. + customComps.size() > 0;
  61042. }
  61043. void AlertWindow::mouseDown (const MouseEvent&)
  61044. {
  61045. dragger.startDraggingComponent (this, &constrainer);
  61046. }
  61047. void AlertWindow::mouseDrag (const MouseEvent& e)
  61048. {
  61049. dragger.dragComponent (this, e);
  61050. }
  61051. bool AlertWindow::keyPressed (const KeyPress& key)
  61052. {
  61053. for (int i = buttons.size(); --i >= 0;)
  61054. {
  61055. TextButton* const b = (TextButton*) buttons[i];
  61056. if (b->isRegisteredForShortcut (key))
  61057. {
  61058. b->triggerClick();
  61059. return true;
  61060. }
  61061. }
  61062. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61063. {
  61064. exitModalState (0);
  61065. return true;
  61066. }
  61067. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61068. {
  61069. ((TextButton*) buttons.getFirst())->triggerClick();
  61070. return true;
  61071. }
  61072. return false;
  61073. }
  61074. void AlertWindow::lookAndFeelChanged()
  61075. {
  61076. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61077. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61078. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61079. }
  61080. int AlertWindow::getDesktopWindowStyleFlags() const
  61081. {
  61082. return getLookAndFeel().getAlertBoxWindowFlags();
  61083. }
  61084. struct AlertWindowInfo
  61085. {
  61086. String title, message, button1, button2, button3;
  61087. AlertWindow::AlertIconType iconType;
  61088. int numButtons;
  61089. Component::SafePointer<Component> associatedComponent;
  61090. int run() const
  61091. {
  61092. return (int) (pointer_sized_int)
  61093. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61094. }
  61095. private:
  61096. int show() const
  61097. {
  61098. LookAndFeel& lf = associatedComponent != 0 ? associatedComponent->getLookAndFeel()
  61099. : LookAndFeel::getDefaultLookAndFeel();
  61100. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61101. iconType, numButtons, associatedComponent));
  61102. jassert (alertBox != 0); // you have to return one of these!
  61103. return alertBox->runModalLoop();
  61104. }
  61105. static void* showCallback (void* userData)
  61106. {
  61107. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61108. }
  61109. };
  61110. void AlertWindow::showMessageBox (AlertIconType iconType,
  61111. const String& title,
  61112. const String& message,
  61113. const String& buttonText,
  61114. Component* associatedComponent)
  61115. {
  61116. AlertWindowInfo info;
  61117. info.title = title;
  61118. info.message = message;
  61119. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61120. info.iconType = iconType;
  61121. info.numButtons = 1;
  61122. info.associatedComponent = associatedComponent;
  61123. info.run();
  61124. }
  61125. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61126. const String& title,
  61127. const String& message,
  61128. const String& button1Text,
  61129. const String& button2Text,
  61130. Component* associatedComponent)
  61131. {
  61132. AlertWindowInfo info;
  61133. info.title = title;
  61134. info.message = message;
  61135. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61136. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61137. info.iconType = iconType;
  61138. info.numButtons = 2;
  61139. info.associatedComponent = associatedComponent;
  61140. return info.run() != 0;
  61141. }
  61142. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61143. const String& title,
  61144. const String& message,
  61145. const String& button1Text,
  61146. const String& button2Text,
  61147. const String& button3Text,
  61148. Component* associatedComponent)
  61149. {
  61150. AlertWindowInfo info;
  61151. info.title = title;
  61152. info.message = message;
  61153. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61154. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61155. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61156. info.iconType = iconType;
  61157. info.numButtons = 3;
  61158. info.associatedComponent = associatedComponent;
  61159. return info.run();
  61160. }
  61161. END_JUCE_NAMESPACE
  61162. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61163. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61164. BEGIN_JUCE_NAMESPACE
  61165. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61166. static VoidArray heavyweightPeers;
  61167. ComponentPeer::ComponentPeer (Component* const component_,
  61168. const int styleFlags_) throw()
  61169. : component (component_),
  61170. styleFlags (styleFlags_),
  61171. lastPaintTime (0),
  61172. constrainer (0),
  61173. lastDragAndDropCompUnderMouse (0),
  61174. fakeMouseMessageSent (false),
  61175. isWindowMinimised (false)
  61176. {
  61177. heavyweightPeers.add (this);
  61178. }
  61179. ComponentPeer::~ComponentPeer()
  61180. {
  61181. heavyweightPeers.removeValue (this);
  61182. Desktop::getInstance().triggerFocusCallback();
  61183. }
  61184. int ComponentPeer::getNumPeers() throw()
  61185. {
  61186. return heavyweightPeers.size();
  61187. }
  61188. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61189. {
  61190. return (ComponentPeer*) heavyweightPeers [index];
  61191. }
  61192. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61193. {
  61194. for (int i = heavyweightPeers.size(); --i >= 0;)
  61195. {
  61196. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61197. if (peer->getComponent() == component)
  61198. return peer;
  61199. }
  61200. return 0;
  61201. }
  61202. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61203. {
  61204. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61205. }
  61206. void ComponentPeer::updateCurrentModifiers() throw()
  61207. {
  61208. ModifierKeys::updateCurrentModifiers();
  61209. }
  61210. void ComponentPeer::handleMouseEvent (const int touchIndex, const Point<int>& positionWithinPeer, const ModifierKeys& newMods, const int64 time)
  61211. {
  61212. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61213. jassert (mouse != 0); // not enough sources!
  61214. mouse->handleEvent (this, positionWithinPeer, time, newMods);
  61215. }
  61216. void ComponentPeer::handleMouseWheel (const int touchIndex, const Point<int>& positionWithinPeer, const int64 time, const float x, const float y)
  61217. {
  61218. MouseInputSource* const mouse = Desktop::getInstance().getMouseSource (touchIndex);
  61219. jassert (mouse != 0); // not enough sources!
  61220. mouse->handleWheel (this, positionWithinPeer, time, x, y);
  61221. }
  61222. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61223. {
  61224. Graphics g (&contextToPaintTo);
  61225. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61226. g.saveState();
  61227. #endif
  61228. JUCE_TRY
  61229. {
  61230. component->paintEntireComponent (g);
  61231. }
  61232. JUCE_CATCH_EXCEPTION
  61233. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61234. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61235. // clearly when things are being repainted.
  61236. {
  61237. g.restoreState();
  61238. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61239. (uint8) Random::getSystemRandom().nextInt (255),
  61240. (uint8) Random::getSystemRandom().nextInt (255),
  61241. (uint8) 0x50));
  61242. }
  61243. #endif
  61244. }
  61245. bool ComponentPeer::handleKeyPress (const int keyCode,
  61246. const juce_wchar textCharacter)
  61247. {
  61248. updateCurrentModifiers();
  61249. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61250. ? Component::getCurrentlyFocusedComponent()
  61251. : component;
  61252. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61253. {
  61254. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61255. if (currentModalComp != 0)
  61256. target = currentModalComp;
  61257. }
  61258. const KeyPress keyInfo (keyCode,
  61259. ModifierKeys::getCurrentModifiers().getRawFlags()
  61260. & ModifierKeys::allKeyboardModifiers,
  61261. textCharacter);
  61262. bool keyWasUsed = false;
  61263. while (target != 0)
  61264. {
  61265. const Component::SafePointer<Component> deletionChecker (target);
  61266. if (target->keyListeners_ != 0)
  61267. {
  61268. for (int i = target->keyListeners_->size(); --i >= 0;)
  61269. {
  61270. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61271. if (keyWasUsed || deletionChecker == 0)
  61272. return keyWasUsed;
  61273. i = jmin (i, target->keyListeners_->size());
  61274. }
  61275. }
  61276. keyWasUsed = target->keyPressed (keyInfo);
  61277. if (keyWasUsed || deletionChecker == 0)
  61278. break;
  61279. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61280. {
  61281. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61282. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61283. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61284. break;
  61285. }
  61286. target = target->parentComponent_;
  61287. }
  61288. return keyWasUsed;
  61289. }
  61290. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61291. {
  61292. updateCurrentModifiers();
  61293. Component* target = Component::getCurrentlyFocusedComponent() != 0
  61294. ? Component::getCurrentlyFocusedComponent()
  61295. : component;
  61296. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61297. {
  61298. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61299. if (currentModalComp != 0)
  61300. target = currentModalComp;
  61301. }
  61302. bool keyWasUsed = false;
  61303. while (target != 0)
  61304. {
  61305. const Component::SafePointer<Component> deletionChecker (target);
  61306. keyWasUsed = target->keyStateChanged (isKeyDown);
  61307. if (keyWasUsed || deletionChecker == 0)
  61308. break;
  61309. if (target->keyListeners_ != 0)
  61310. {
  61311. for (int i = target->keyListeners_->size(); --i >= 0;)
  61312. {
  61313. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61314. if (keyWasUsed || deletionChecker == 0)
  61315. return keyWasUsed;
  61316. i = jmin (i, target->keyListeners_->size());
  61317. }
  61318. }
  61319. target = target->parentComponent_;
  61320. }
  61321. return keyWasUsed;
  61322. }
  61323. void ComponentPeer::handleModifierKeysChange()
  61324. {
  61325. updateCurrentModifiers();
  61326. Component* target = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  61327. if (target == 0)
  61328. target = Component::getCurrentlyFocusedComponent();
  61329. if (target == 0)
  61330. target = component;
  61331. if (target != 0)
  61332. target->internalModifierKeysChanged();
  61333. }
  61334. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61335. {
  61336. Component* const c = Component::getCurrentlyFocusedComponent();
  61337. if (component->isParentOf (c))
  61338. return dynamic_cast <TextInputTarget*> (c);
  61339. return 0;
  61340. }
  61341. void ComponentPeer::handleBroughtToFront()
  61342. {
  61343. updateCurrentModifiers();
  61344. if (component != 0)
  61345. component->internalBroughtToFront();
  61346. }
  61347. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61348. {
  61349. constrainer = newConstrainer;
  61350. }
  61351. void ComponentPeer::handleMovedOrResized()
  61352. {
  61353. jassert (component->isValidComponent());
  61354. updateCurrentModifiers();
  61355. const bool nowMinimised = isMinimised();
  61356. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61357. {
  61358. const Component::SafePointer<Component> deletionChecker (component);
  61359. const Rectangle<int> newBounds (getBounds());
  61360. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61361. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61362. if (wasMoved || wasResized)
  61363. {
  61364. component->bounds_ = newBounds;
  61365. if (wasResized)
  61366. component->repaint();
  61367. component->sendMovedResizedMessages (wasMoved, wasResized);
  61368. if (deletionChecker == 0)
  61369. return;
  61370. }
  61371. }
  61372. if (isWindowMinimised != nowMinimised)
  61373. {
  61374. isWindowMinimised = nowMinimised;
  61375. component->minimisationStateChanged (nowMinimised);
  61376. component->sendVisibilityChangeMessage();
  61377. }
  61378. if (! isFullScreen())
  61379. lastNonFullscreenBounds = component->getBounds();
  61380. }
  61381. void ComponentPeer::handleFocusGain()
  61382. {
  61383. updateCurrentModifiers();
  61384. if (component->isParentOf (lastFocusedComponent))
  61385. {
  61386. Component::currentlyFocusedComponent = lastFocusedComponent;
  61387. Desktop::getInstance().triggerFocusCallback();
  61388. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61389. }
  61390. else
  61391. {
  61392. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61393. component->grabKeyboardFocus();
  61394. else
  61395. Component::bringModalComponentToFront();
  61396. }
  61397. }
  61398. void ComponentPeer::handleFocusLoss()
  61399. {
  61400. updateCurrentModifiers();
  61401. if (component->hasKeyboardFocus (true))
  61402. {
  61403. lastFocusedComponent = Component::currentlyFocusedComponent;
  61404. if (lastFocusedComponent != 0)
  61405. {
  61406. Component::currentlyFocusedComponent = 0;
  61407. Desktop::getInstance().triggerFocusCallback();
  61408. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61409. }
  61410. }
  61411. }
  61412. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61413. {
  61414. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61415. ? static_cast <Component*> (lastFocusedComponent)
  61416. : component;
  61417. }
  61418. void ComponentPeer::handleScreenSizeChange()
  61419. {
  61420. updateCurrentModifiers();
  61421. component->parentSizeChanged();
  61422. handleMovedOrResized();
  61423. }
  61424. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61425. {
  61426. lastNonFullscreenBounds = newBounds;
  61427. }
  61428. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61429. {
  61430. return lastNonFullscreenBounds;
  61431. }
  61432. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61433. const StringArray& files,
  61434. FileDragAndDropTarget* const lastOne)
  61435. {
  61436. while (c != 0)
  61437. {
  61438. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61439. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61440. return t;
  61441. c = c->getParentComponent();
  61442. }
  61443. return 0;
  61444. }
  61445. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61446. {
  61447. updateCurrentModifiers();
  61448. FileDragAndDropTarget* lastTarget
  61449. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61450. FileDragAndDropTarget* newTarget = 0;
  61451. Component* const compUnderMouse = component->getComponentAt (position);
  61452. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61453. {
  61454. lastDragAndDropCompUnderMouse = compUnderMouse;
  61455. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61456. if (newTarget != lastTarget)
  61457. {
  61458. if (lastTarget != 0)
  61459. lastTarget->fileDragExit (files);
  61460. dragAndDropTargetComponent = 0;
  61461. if (newTarget != 0)
  61462. {
  61463. dragAndDropTargetComponent = dynamic_cast <Component*> (newTarget);
  61464. const Point<int> pos (component->relativePositionToOtherComponent (dragAndDropTargetComponent, position));
  61465. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61466. }
  61467. }
  61468. }
  61469. else
  61470. {
  61471. newTarget = lastTarget;
  61472. }
  61473. if (newTarget != 0)
  61474. {
  61475. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61476. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61477. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61478. }
  61479. }
  61480. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61481. {
  61482. handleFileDragMove (files, Point<int> (-1, -1));
  61483. jassert (dragAndDropTargetComponent == 0);
  61484. lastDragAndDropCompUnderMouse = 0;
  61485. }
  61486. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61487. {
  61488. handleFileDragMove (files, position);
  61489. if (dragAndDropTargetComponent != 0)
  61490. {
  61491. FileDragAndDropTarget* const target
  61492. = dynamic_cast<FileDragAndDropTarget*> (static_cast<Component*> (dragAndDropTargetComponent));
  61493. dragAndDropTargetComponent = 0;
  61494. lastDragAndDropCompUnderMouse = 0;
  61495. if (target != 0)
  61496. {
  61497. Component* const targetComp = dynamic_cast <Component*> (target);
  61498. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61499. {
  61500. targetComp->internalModalInputAttempt();
  61501. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61502. return;
  61503. }
  61504. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61505. target->filesDropped (files, pos.getX(), pos.getY());
  61506. }
  61507. }
  61508. }
  61509. void ComponentPeer::handleUserClosingWindow()
  61510. {
  61511. updateCurrentModifiers();
  61512. component->userTriedToCloseWindow();
  61513. }
  61514. void ComponentPeer::bringModalComponentToFront()
  61515. {
  61516. Component::bringModalComponentToFront();
  61517. }
  61518. void ComponentPeer::clearMaskedRegion() throw()
  61519. {
  61520. maskedRegion.clear();
  61521. }
  61522. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61523. {
  61524. maskedRegion.add (x, y, w, h);
  61525. }
  61526. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61527. {
  61528. StringArray s;
  61529. s.add ("Software Renderer");
  61530. return s;
  61531. }
  61532. int ComponentPeer::getCurrentRenderingEngine() throw()
  61533. {
  61534. return 0;
  61535. }
  61536. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61537. {
  61538. }
  61539. END_JUCE_NAMESPACE
  61540. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61541. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61542. BEGIN_JUCE_NAMESPACE
  61543. DialogWindow::DialogWindow (const String& name,
  61544. const Colour& backgroundColour_,
  61545. const bool escapeKeyTriggersCloseButton_,
  61546. const bool addToDesktop_)
  61547. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61548. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61549. {
  61550. }
  61551. DialogWindow::~DialogWindow()
  61552. {
  61553. }
  61554. void DialogWindow::resized()
  61555. {
  61556. DocumentWindow::resized();
  61557. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61558. if (escapeKeyTriggersCloseButton
  61559. && getCloseButton() != 0
  61560. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61561. {
  61562. getCloseButton()->addShortcut (esc);
  61563. }
  61564. }
  61565. class TempDialogWindow : public DialogWindow
  61566. {
  61567. public:
  61568. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61569. : DialogWindow (title, colour, escapeCloses, true)
  61570. {
  61571. }
  61572. ~TempDialogWindow()
  61573. {
  61574. }
  61575. void closeButtonPressed()
  61576. {
  61577. setVisible (false);
  61578. }
  61579. private:
  61580. TempDialogWindow (const TempDialogWindow&);
  61581. TempDialogWindow& operator= (const TempDialogWindow&);
  61582. };
  61583. int DialogWindow::showModalDialog (const String& dialogTitle,
  61584. Component* contentComponent,
  61585. Component* componentToCentreAround,
  61586. const Colour& colour,
  61587. const bool escapeKeyTriggersCloseButton,
  61588. const bool shouldBeResizable,
  61589. const bool useBottomRightCornerResizer)
  61590. {
  61591. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  61592. dw.setContentComponent (contentComponent, true, true);
  61593. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  61594. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  61595. const int result = dw.runModalLoop();
  61596. dw.setContentComponent (0, false);
  61597. return result;
  61598. }
  61599. END_JUCE_NAMESPACE
  61600. /*** End of inlined file: juce_DialogWindow.cpp ***/
  61601. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  61602. BEGIN_JUCE_NAMESPACE
  61603. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  61604. {
  61605. public:
  61606. ButtonListenerProxy (DocumentWindow& owner_)
  61607. : owner (owner_)
  61608. {
  61609. }
  61610. void buttonClicked (Button* button)
  61611. {
  61612. if (button == owner.getMinimiseButton())
  61613. owner.minimiseButtonPressed();
  61614. else if (button == owner.getMaximiseButton())
  61615. owner.maximiseButtonPressed();
  61616. else if (button == owner.getCloseButton())
  61617. owner.closeButtonPressed();
  61618. }
  61619. juce_UseDebuggingNewOperator
  61620. private:
  61621. DocumentWindow& owner;
  61622. ButtonListenerProxy (const ButtonListenerProxy&);
  61623. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  61624. };
  61625. DocumentWindow::DocumentWindow (const String& title,
  61626. const Colour& backgroundColour,
  61627. const int requiredButtons_,
  61628. const bool addToDesktop_)
  61629. : ResizableWindow (title, backgroundColour, addToDesktop_),
  61630. titleBarHeight (26),
  61631. menuBarHeight (24),
  61632. requiredButtons (requiredButtons_),
  61633. #if JUCE_MAC
  61634. positionTitleBarButtonsOnLeft (true),
  61635. #else
  61636. positionTitleBarButtonsOnLeft (false),
  61637. #endif
  61638. drawTitleTextCentred (true),
  61639. menuBarModel (0)
  61640. {
  61641. setResizeLimits (128, 128, 32768, 32768);
  61642. lookAndFeelChanged();
  61643. }
  61644. DocumentWindow::~DocumentWindow()
  61645. {
  61646. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61647. titleBarButtons[i] = 0;
  61648. menuBar = 0;
  61649. }
  61650. void DocumentWindow::repaintTitleBar()
  61651. {
  61652. const Rectangle<int> titleBarArea (getTitleBarArea());
  61653. repaint (titleBarArea.getX(), titleBarArea.getY(),
  61654. titleBarArea.getWidth(), titleBarArea.getHeight());
  61655. }
  61656. void DocumentWindow::setName (const String& newName)
  61657. {
  61658. if (newName != getName())
  61659. {
  61660. Component::setName (newName);
  61661. repaintTitleBar();
  61662. }
  61663. }
  61664. void DocumentWindow::setIcon (const Image* imageToUse)
  61665. {
  61666. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  61667. repaintTitleBar();
  61668. }
  61669. void DocumentWindow::setTitleBarHeight (const int newHeight)
  61670. {
  61671. titleBarHeight = newHeight;
  61672. resized();
  61673. repaintTitleBar();
  61674. }
  61675. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  61676. const bool positionTitleBarButtonsOnLeft_)
  61677. {
  61678. requiredButtons = requiredButtons_;
  61679. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  61680. lookAndFeelChanged();
  61681. }
  61682. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  61683. {
  61684. drawTitleTextCentred = textShouldBeCentred;
  61685. repaintTitleBar();
  61686. }
  61687. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  61688. const int menuBarHeight_)
  61689. {
  61690. if (menuBarModel != menuBarModel_)
  61691. {
  61692. menuBar = 0;
  61693. menuBarModel = menuBarModel_;
  61694. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  61695. : getLookAndFeel().getDefaultMenuBarHeight();
  61696. if (menuBarModel != 0)
  61697. {
  61698. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61699. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  61700. menuBar->setEnabled (isActiveWindow());
  61701. }
  61702. resized();
  61703. }
  61704. }
  61705. void DocumentWindow::closeButtonPressed()
  61706. {
  61707. /* If you've got a close button, you have to override this method to get
  61708. rid of your window!
  61709. If the window is just a pop-up, you should override this method and make
  61710. it delete the window in whatever way is appropriate for your app. E.g. you
  61711. might just want to call "delete this".
  61712. If your app is centred around this window such that the whole app should quit when
  61713. the window is closed, then you will probably want to use this method as an opportunity
  61714. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  61715. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  61716. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  61717. or closing it via the taskbar icon on Windows).
  61718. */
  61719. jassertfalse
  61720. }
  61721. void DocumentWindow::minimiseButtonPressed()
  61722. {
  61723. setMinimised (true);
  61724. }
  61725. void DocumentWindow::maximiseButtonPressed()
  61726. {
  61727. setFullScreen (! isFullScreen());
  61728. }
  61729. void DocumentWindow::paint (Graphics& g)
  61730. {
  61731. ResizableWindow::paint (g);
  61732. if (resizableBorder == 0)
  61733. {
  61734. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  61735. const BorderSize border (getBorderThickness());
  61736. g.fillRect (0, 0, getWidth(), border.getTop());
  61737. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  61738. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  61739. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  61740. }
  61741. const Rectangle<int> titleBarArea (getTitleBarArea());
  61742. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  61743. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  61744. int titleSpaceX1 = 6;
  61745. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  61746. for (int i = 0; i < 3; ++i)
  61747. {
  61748. if (titleBarButtons[i] != 0)
  61749. {
  61750. if (positionTitleBarButtonsOnLeft)
  61751. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  61752. else
  61753. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  61754. }
  61755. }
  61756. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  61757. titleBarArea.getWidth(),
  61758. titleBarArea.getHeight(),
  61759. titleSpaceX1,
  61760. jmax (1, titleSpaceX2 - titleSpaceX1),
  61761. titleBarIcon,
  61762. ! drawTitleTextCentred);
  61763. }
  61764. void DocumentWindow::resized()
  61765. {
  61766. ResizableWindow::resized();
  61767. if (titleBarButtons[1] != 0)
  61768. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  61769. const Rectangle<int> titleBarArea (getTitleBarArea());
  61770. getLookAndFeel()
  61771. .positionDocumentWindowButtons (*this,
  61772. titleBarArea.getX(), titleBarArea.getY(),
  61773. titleBarArea.getWidth(), titleBarArea.getHeight(),
  61774. titleBarButtons[0],
  61775. titleBarButtons[1],
  61776. titleBarButtons[2],
  61777. positionTitleBarButtonsOnLeft);
  61778. if (menuBar != 0)
  61779. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  61780. titleBarArea.getWidth(), menuBarHeight);
  61781. }
  61782. const BorderSize DocumentWindow::getBorderThickness()
  61783. {
  61784. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  61785. ? 0 : (resizableBorder != 0 ? 4 : 1));
  61786. }
  61787. const BorderSize DocumentWindow::getContentComponentBorder()
  61788. {
  61789. BorderSize border (getBorderThickness());
  61790. border.setTop (border.getTop()
  61791. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  61792. + (menuBar != 0 ? menuBarHeight : 0));
  61793. return border;
  61794. }
  61795. int DocumentWindow::getTitleBarHeight() const
  61796. {
  61797. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  61798. }
  61799. const Rectangle<int> DocumentWindow::getTitleBarArea()
  61800. {
  61801. const BorderSize border (getBorderThickness());
  61802. return Rectangle<int> (border.getLeft(), border.getTop(),
  61803. getWidth() - border.getLeftAndRight(),
  61804. getTitleBarHeight());
  61805. }
  61806. Button* DocumentWindow::getCloseButton() const throw()
  61807. {
  61808. return titleBarButtons[2];
  61809. }
  61810. Button* DocumentWindow::getMinimiseButton() const throw()
  61811. {
  61812. return titleBarButtons[0];
  61813. }
  61814. Button* DocumentWindow::getMaximiseButton() const throw()
  61815. {
  61816. return titleBarButtons[1];
  61817. }
  61818. int DocumentWindow::getDesktopWindowStyleFlags() const
  61819. {
  61820. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  61821. if ((requiredButtons & minimiseButton) != 0)
  61822. flags |= ComponentPeer::windowHasMinimiseButton;
  61823. if ((requiredButtons & maximiseButton) != 0)
  61824. flags |= ComponentPeer::windowHasMaximiseButton;
  61825. if ((requiredButtons & closeButton) != 0)
  61826. flags |= ComponentPeer::windowHasCloseButton;
  61827. return flags;
  61828. }
  61829. void DocumentWindow::lookAndFeelChanged()
  61830. {
  61831. int i;
  61832. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  61833. titleBarButtons[i] = 0;
  61834. if (! isUsingNativeTitleBar())
  61835. {
  61836. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  61837. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  61838. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  61839. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  61840. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  61841. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  61842. for (i = 0; i < 3; ++i)
  61843. {
  61844. if (titleBarButtons[i] != 0)
  61845. {
  61846. if (buttonListener == 0)
  61847. buttonListener = new ButtonListenerProxy (*this);
  61848. titleBarButtons[i]->addButtonListener (buttonListener);
  61849. titleBarButtons[i]->setWantsKeyboardFocus (false);
  61850. // (call the Component method directly to avoid the assertion in ResizableWindow)
  61851. Component::addAndMakeVisible (titleBarButtons[i]);
  61852. }
  61853. }
  61854. if (getCloseButton() != 0)
  61855. {
  61856. #if JUCE_MAC
  61857. getCloseButton()->addShortcut (KeyPress ('w', ModifierKeys::commandModifier, 0));
  61858. #else
  61859. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  61860. #endif
  61861. }
  61862. }
  61863. activeWindowStatusChanged();
  61864. ResizableWindow::lookAndFeelChanged();
  61865. }
  61866. void DocumentWindow::parentHierarchyChanged()
  61867. {
  61868. lookAndFeelChanged();
  61869. }
  61870. void DocumentWindow::activeWindowStatusChanged()
  61871. {
  61872. ResizableWindow::activeWindowStatusChanged();
  61873. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  61874. if (titleBarButtons[i] != 0)
  61875. titleBarButtons[i]->setEnabled (isActiveWindow());
  61876. if (menuBar != 0)
  61877. menuBar->setEnabled (isActiveWindow());
  61878. }
  61879. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  61880. {
  61881. if (getTitleBarArea().contains (e.x, e.y)
  61882. && getMaximiseButton() != 0)
  61883. {
  61884. getMaximiseButton()->triggerClick();
  61885. }
  61886. }
  61887. void DocumentWindow::userTriedToCloseWindow()
  61888. {
  61889. closeButtonPressed();
  61890. }
  61891. END_JUCE_NAMESPACE
  61892. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  61893. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  61894. BEGIN_JUCE_NAMESPACE
  61895. ResizableWindow::ResizableWindow (const String& name,
  61896. const bool addToDesktop_)
  61897. : TopLevelWindow (name, addToDesktop_),
  61898. resizeToFitContent (false),
  61899. fullscreen (false),
  61900. lastNonFullScreenPos (50, 50, 256, 256),
  61901. constrainer (0)
  61902. #ifdef JUCE_DEBUG
  61903. , hasBeenResized (false)
  61904. #endif
  61905. {
  61906. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61907. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  61908. if (addToDesktop_)
  61909. Component::addToDesktop (getDesktopWindowStyleFlags());
  61910. }
  61911. ResizableWindow::ResizableWindow (const String& name,
  61912. const Colour& backgroundColour_,
  61913. const bool addToDesktop_)
  61914. : TopLevelWindow (name, addToDesktop_),
  61915. resizeToFitContent (false),
  61916. fullscreen (false),
  61917. lastNonFullScreenPos (50, 50, 256, 256),
  61918. constrainer (0)
  61919. #ifdef JUCE_DEBUG
  61920. , hasBeenResized (false)
  61921. #endif
  61922. {
  61923. setBackgroundColour (backgroundColour_);
  61924. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  61925. if (addToDesktop_)
  61926. Component::addToDesktop (getDesktopWindowStyleFlags());
  61927. }
  61928. ResizableWindow::~ResizableWindow()
  61929. {
  61930. resizableCorner = 0;
  61931. resizableBorder = 0;
  61932. contentComponent = 0;
  61933. // have you been adding your own components directly to this window..? tut tut tut.
  61934. // Read the instructions for using a ResizableWindow!
  61935. jassert (getNumChildComponents() == 0);
  61936. }
  61937. int ResizableWindow::getDesktopWindowStyleFlags() const
  61938. {
  61939. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  61940. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  61941. flags |= ComponentPeer::windowIsResizable;
  61942. return flags;
  61943. }
  61944. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  61945. const bool deleteOldOne,
  61946. const bool resizeToFit)
  61947. {
  61948. resizeToFitContent = resizeToFit;
  61949. if (newContentComponent != static_cast <Component*> (contentComponent))
  61950. {
  61951. if (! deleteOldOne)
  61952. removeChildComponent (contentComponent.release());
  61953. contentComponent = newContentComponent;
  61954. Component::addAndMakeVisible (contentComponent);
  61955. }
  61956. if (resizeToFit)
  61957. childBoundsChanged (contentComponent);
  61958. resized(); // must always be called to position the new content comp
  61959. }
  61960. void ResizableWindow::setContentComponentSize (int width, int height)
  61961. {
  61962. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  61963. const BorderSize border (getContentComponentBorder());
  61964. setSize (width + border.getLeftAndRight(),
  61965. height + border.getTopAndBottom());
  61966. }
  61967. const BorderSize ResizableWindow::getBorderThickness()
  61968. {
  61969. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  61970. }
  61971. const BorderSize ResizableWindow::getContentComponentBorder()
  61972. {
  61973. return getBorderThickness();
  61974. }
  61975. void ResizableWindow::moved()
  61976. {
  61977. updateLastPos();
  61978. }
  61979. void ResizableWindow::visibilityChanged()
  61980. {
  61981. TopLevelWindow::visibilityChanged();
  61982. updateLastPos();
  61983. }
  61984. void ResizableWindow::resized()
  61985. {
  61986. if (resizableBorder != 0)
  61987. {
  61988. resizableBorder->setVisible (! isFullScreen());
  61989. resizableBorder->setBorderThickness (getBorderThickness());
  61990. resizableBorder->setSize (getWidth(), getHeight());
  61991. resizableBorder->toBack();
  61992. }
  61993. if (resizableCorner != 0)
  61994. {
  61995. resizableCorner->setVisible (! isFullScreen());
  61996. const int resizerSize = 18;
  61997. resizableCorner->setBounds (getWidth() - resizerSize,
  61998. getHeight() - resizerSize,
  61999. resizerSize, resizerSize);
  62000. }
  62001. if (contentComponent != 0)
  62002. contentComponent->setBoundsInset (getContentComponentBorder());
  62003. updateLastPos();
  62004. #ifdef JUCE_DEBUG
  62005. hasBeenResized = true;
  62006. #endif
  62007. }
  62008. void ResizableWindow::childBoundsChanged (Component* child)
  62009. {
  62010. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62011. {
  62012. // not going to look very good if this component has a zero size..
  62013. jassert (child->getWidth() > 0);
  62014. jassert (child->getHeight() > 0);
  62015. const BorderSize borders (getContentComponentBorder());
  62016. setSize (child->getWidth() + borders.getLeftAndRight(),
  62017. child->getHeight() + borders.getTopAndBottom());
  62018. }
  62019. }
  62020. void ResizableWindow::activeWindowStatusChanged()
  62021. {
  62022. const BorderSize borders (getContentComponentBorder());
  62023. repaint (0, 0, getWidth(), borders.getTop());
  62024. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62025. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62026. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62027. }
  62028. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62029. const bool useBottomRightCornerResizer)
  62030. {
  62031. if (shouldBeResizable)
  62032. {
  62033. if (useBottomRightCornerResizer)
  62034. {
  62035. resizableBorder = 0;
  62036. if (resizableCorner == 0)
  62037. {
  62038. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62039. resizableCorner->setAlwaysOnTop (true);
  62040. }
  62041. }
  62042. else
  62043. {
  62044. resizableCorner = 0;
  62045. if (resizableBorder == 0)
  62046. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62047. }
  62048. }
  62049. else
  62050. {
  62051. resizableCorner = 0;
  62052. resizableBorder = 0;
  62053. }
  62054. if (isUsingNativeTitleBar())
  62055. recreateDesktopWindow();
  62056. childBoundsChanged (contentComponent);
  62057. resized();
  62058. }
  62059. bool ResizableWindow::isResizable() const throw()
  62060. {
  62061. return resizableCorner != 0
  62062. || resizableBorder != 0;
  62063. }
  62064. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62065. const int newMinimumHeight,
  62066. const int newMaximumWidth,
  62067. const int newMaximumHeight) throw()
  62068. {
  62069. // if you've set up a custom constrainer then these settings won't have any effect..
  62070. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62071. if (constrainer == 0)
  62072. setConstrainer (&defaultConstrainer);
  62073. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62074. newMaximumWidth, newMaximumHeight);
  62075. setBoundsConstrained (getBounds());
  62076. }
  62077. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62078. {
  62079. if (constrainer != newConstrainer)
  62080. {
  62081. constrainer = newConstrainer;
  62082. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62083. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62084. resizableCorner = 0;
  62085. resizableBorder = 0;
  62086. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62087. ComponentPeer* const peer = getPeer();
  62088. if (peer != 0)
  62089. peer->setConstrainer (newConstrainer);
  62090. }
  62091. }
  62092. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62093. {
  62094. if (constrainer != 0)
  62095. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62096. else
  62097. setBounds (bounds);
  62098. }
  62099. void ResizableWindow::paint (Graphics& g)
  62100. {
  62101. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62102. getBorderThickness(), *this);
  62103. if (! isFullScreen())
  62104. {
  62105. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62106. getBorderThickness(), *this);
  62107. }
  62108. #ifdef JUCE_DEBUG
  62109. /* If this fails, then you've probably written a subclass with a resized()
  62110. callback but forgotten to make it call its parent class's resized() method.
  62111. It's important when you override methods like resized(), moved(),
  62112. etc., that you make sure the base class methods also get called.
  62113. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62114. because your content should all be inside the content component - and it's the
  62115. content component's resized() method that you should be using to do your
  62116. layout.
  62117. */
  62118. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62119. #endif
  62120. }
  62121. void ResizableWindow::lookAndFeelChanged()
  62122. {
  62123. resized();
  62124. if (isOnDesktop())
  62125. {
  62126. Component::addToDesktop (getDesktopWindowStyleFlags());
  62127. ComponentPeer* const peer = getPeer();
  62128. if (peer != 0)
  62129. peer->setConstrainer (constrainer);
  62130. }
  62131. }
  62132. const Colour ResizableWindow::getBackgroundColour() const throw()
  62133. {
  62134. return findColour (backgroundColourId, false);
  62135. }
  62136. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62137. {
  62138. Colour backgroundColour (newColour);
  62139. if (! Desktop::canUseSemiTransparentWindows())
  62140. backgroundColour = newColour.withAlpha (1.0f);
  62141. setColour (backgroundColourId, backgroundColour);
  62142. setOpaque (backgroundColour.isOpaque());
  62143. repaint();
  62144. }
  62145. bool ResizableWindow::isFullScreen() const
  62146. {
  62147. if (isOnDesktop())
  62148. {
  62149. ComponentPeer* const peer = getPeer();
  62150. return peer != 0 && peer->isFullScreen();
  62151. }
  62152. return fullscreen;
  62153. }
  62154. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62155. {
  62156. if (shouldBeFullScreen != isFullScreen())
  62157. {
  62158. updateLastPos();
  62159. fullscreen = shouldBeFullScreen;
  62160. if (isOnDesktop())
  62161. {
  62162. ComponentPeer* const peer = getPeer();
  62163. if (peer != 0)
  62164. {
  62165. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62166. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62167. peer->setFullScreen (shouldBeFullScreen);
  62168. if (! shouldBeFullScreen)
  62169. setBounds (lastPos);
  62170. }
  62171. else
  62172. {
  62173. jassertfalse
  62174. }
  62175. }
  62176. else
  62177. {
  62178. if (shouldBeFullScreen)
  62179. setBounds (0, 0, getParentWidth(), getParentHeight());
  62180. else
  62181. setBounds (lastNonFullScreenPos);
  62182. }
  62183. resized();
  62184. }
  62185. }
  62186. bool ResizableWindow::isMinimised() const
  62187. {
  62188. ComponentPeer* const peer = getPeer();
  62189. return (peer != 0) && peer->isMinimised();
  62190. }
  62191. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62192. {
  62193. if (shouldMinimise != isMinimised())
  62194. {
  62195. ComponentPeer* const peer = getPeer();
  62196. if (peer != 0)
  62197. {
  62198. updateLastPos();
  62199. peer->setMinimised (shouldMinimise);
  62200. }
  62201. else
  62202. {
  62203. jassertfalse
  62204. }
  62205. }
  62206. }
  62207. void ResizableWindow::updateLastPos()
  62208. {
  62209. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62210. {
  62211. lastNonFullScreenPos = getBounds();
  62212. }
  62213. }
  62214. void ResizableWindow::parentSizeChanged()
  62215. {
  62216. if (isFullScreen() && getParentComponent() != 0)
  62217. {
  62218. setBounds (0, 0, getParentWidth(), getParentHeight());
  62219. }
  62220. }
  62221. const String ResizableWindow::getWindowStateAsString()
  62222. {
  62223. updateLastPos();
  62224. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62225. }
  62226. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62227. {
  62228. StringArray tokens;
  62229. tokens.addTokens (s, false);
  62230. tokens.removeEmptyStrings();
  62231. tokens.trim();
  62232. const bool fs = tokens[0].startsWithIgnoreCase ("fs");
  62233. const int firstCoord = fs ? 1 : 0;
  62234. if (tokens.size() != firstCoord + 4)
  62235. return false;
  62236. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62237. tokens[firstCoord + 1].getIntValue(),
  62238. tokens[firstCoord + 2].getIntValue(),
  62239. tokens[firstCoord + 3].getIntValue());
  62240. if (newPos.isEmpty())
  62241. return false;
  62242. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62243. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62244. if (peer != 0)
  62245. peer->getFrameSize().addTo (newPos);
  62246. if (! screen.contains (newPos))
  62247. {
  62248. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62249. jmin (newPos.getHeight(), screen.getHeight()));
  62250. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62251. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62252. }
  62253. if (peer != 0)
  62254. {
  62255. peer->getFrameSize().subtractFrom (newPos);
  62256. peer->setNonFullScreenBounds (newPos);
  62257. }
  62258. lastNonFullScreenPos = newPos;
  62259. setFullScreen (fs);
  62260. if (! fs)
  62261. setBoundsConstrained (newPos);
  62262. return true;
  62263. }
  62264. void ResizableWindow::mouseDown (const MouseEvent&)
  62265. {
  62266. if (! isFullScreen())
  62267. dragger.startDraggingComponent (this, constrainer);
  62268. }
  62269. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62270. {
  62271. if (! isFullScreen())
  62272. dragger.dragComponent (this, e);
  62273. }
  62274. #ifdef JUCE_DEBUG
  62275. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62276. {
  62277. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62278. manages its child components automatically, and if you add your own it'll cause
  62279. trouble. Instead, use setContentComponent() to give it a component which
  62280. will be automatically resized and kept in the right place - then you can add
  62281. subcomponents to the content comp. See the notes for the ResizableWindow class
  62282. for more info.
  62283. If you really know what you're doing and want to avoid this assertion, just call
  62284. Component::addChildComponent directly.
  62285. */
  62286. jassertfalse
  62287. Component::addChildComponent (child, zOrder);
  62288. }
  62289. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62290. {
  62291. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62292. manages its child components automatically, and if you add your own it'll cause
  62293. trouble. Instead, use setContentComponent() to give it a component which
  62294. will be automatically resized and kept in the right place - then you can add
  62295. subcomponents to the content comp. See the notes for the ResizableWindow class
  62296. for more info.
  62297. If you really know what you're doing and want to avoid this assertion, just call
  62298. Component::addAndMakeVisible directly.
  62299. */
  62300. jassertfalse
  62301. Component::addAndMakeVisible (child, zOrder);
  62302. }
  62303. #endif
  62304. END_JUCE_NAMESPACE
  62305. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62306. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62307. BEGIN_JUCE_NAMESPACE
  62308. SplashScreen::SplashScreen()
  62309. : backgroundImage (0)
  62310. {
  62311. setOpaque (true);
  62312. }
  62313. SplashScreen::~SplashScreen()
  62314. {
  62315. ImageCache::releaseOrDelete (backgroundImage);
  62316. }
  62317. void SplashScreen::show (const String& title,
  62318. Image* const backgroundImage_,
  62319. const int minimumTimeToDisplayFor,
  62320. const bool useDropShadow,
  62321. const bool removeOnMouseClick)
  62322. {
  62323. backgroundImage = backgroundImage_;
  62324. jassert (backgroundImage_ != 0);
  62325. if (backgroundImage_ != 0)
  62326. {
  62327. setOpaque (! backgroundImage_->hasAlphaChannel());
  62328. show (title,
  62329. backgroundImage_->getWidth(),
  62330. backgroundImage_->getHeight(),
  62331. minimumTimeToDisplayFor,
  62332. useDropShadow,
  62333. removeOnMouseClick);
  62334. }
  62335. }
  62336. void SplashScreen::show (const String& title,
  62337. const int width,
  62338. const int height,
  62339. const int minimumTimeToDisplayFor,
  62340. const bool useDropShadow,
  62341. const bool removeOnMouseClick)
  62342. {
  62343. setName (title);
  62344. setAlwaysOnTop (true);
  62345. setVisible (true);
  62346. centreWithSize (width, height);
  62347. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62348. toFront (false);
  62349. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62350. repaint();
  62351. originalClickCounter = removeOnMouseClick
  62352. ? Desktop::getMouseButtonClickCounter()
  62353. : std::numeric_limits<int>::max();
  62354. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62355. startTimer (50);
  62356. }
  62357. void SplashScreen::paint (Graphics& g)
  62358. {
  62359. if (backgroundImage != 0)
  62360. {
  62361. g.setOpacity (1.0f);
  62362. g.drawImage (backgroundImage,
  62363. 0, 0, getWidth(), getHeight(),
  62364. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62365. }
  62366. }
  62367. void SplashScreen::timerCallback()
  62368. {
  62369. if (Time::getCurrentTime() > earliestTimeToDelete
  62370. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62371. {
  62372. delete this;
  62373. }
  62374. }
  62375. END_JUCE_NAMESPACE
  62376. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62377. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62378. BEGIN_JUCE_NAMESPACE
  62379. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62380. const bool hasProgressBar,
  62381. const bool hasCancelButton,
  62382. const int timeOutMsWhenCancelling_,
  62383. const String& cancelButtonText)
  62384. : Thread ("Juce Progress Window"),
  62385. progress (0.0),
  62386. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62387. {
  62388. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62389. .createAlertWindow (title, String::empty, cancelButtonText,
  62390. String::empty, String::empty,
  62391. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62392. if (hasProgressBar)
  62393. alertWindow->addProgressBarComponent (progress);
  62394. }
  62395. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62396. {
  62397. stopThread (timeOutMsWhenCancelling);
  62398. }
  62399. bool ThreadWithProgressWindow::runThread (const int priority)
  62400. {
  62401. startThread (priority);
  62402. startTimer (100);
  62403. {
  62404. const ScopedLock sl (messageLock);
  62405. alertWindow->setMessage (message);
  62406. }
  62407. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62408. stopThread (timeOutMsWhenCancelling);
  62409. alertWindow->setVisible (false);
  62410. return finishedNaturally;
  62411. }
  62412. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62413. {
  62414. progress = newProgress;
  62415. }
  62416. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62417. {
  62418. const ScopedLock sl (messageLock);
  62419. message = newStatusMessage;
  62420. }
  62421. void ThreadWithProgressWindow::timerCallback()
  62422. {
  62423. if (! isThreadRunning())
  62424. {
  62425. // thread has finished normally..
  62426. alertWindow->exitModalState (1);
  62427. alertWindow->setVisible (false);
  62428. }
  62429. else
  62430. {
  62431. const ScopedLock sl (messageLock);
  62432. alertWindow->setMessage (message);
  62433. }
  62434. }
  62435. END_JUCE_NAMESPACE
  62436. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62437. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62438. BEGIN_JUCE_NAMESPACE
  62439. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62440. const int millisecondsBeforeTipAppears_)
  62441. : Component ("tooltip"),
  62442. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62443. mouseClicks (0),
  62444. lastHideTime (0),
  62445. lastComponentUnderMouse (0),
  62446. changedCompsSinceShown (true)
  62447. {
  62448. if (Desktop::getInstance().getMainMouseSource().canHover())
  62449. startTimer (123);
  62450. setAlwaysOnTop (true);
  62451. setOpaque (true);
  62452. if (parentComponent != 0)
  62453. parentComponent->addChildComponent (this);
  62454. }
  62455. TooltipWindow::~TooltipWindow()
  62456. {
  62457. hide();
  62458. }
  62459. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62460. {
  62461. millisecondsBeforeTipAppears = newTimeMs;
  62462. }
  62463. void TooltipWindow::paint (Graphics& g)
  62464. {
  62465. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62466. }
  62467. void TooltipWindow::mouseEnter (const MouseEvent&)
  62468. {
  62469. hide();
  62470. }
  62471. void TooltipWindow::showFor (const String& tip)
  62472. {
  62473. jassert (tip.isNotEmpty());
  62474. tipShowing = tip;
  62475. Point<int> mousePos (Desktop::getMousePosition());
  62476. if (getParentComponent() != 0)
  62477. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62478. int x, y, w, h;
  62479. getLookAndFeel().getTooltipSize (tip, w, h);
  62480. if (mousePos.getX() > getParentWidth() / 2)
  62481. x = mousePos.getX() - (w + 12);
  62482. else
  62483. x = mousePos.getX() + 24;
  62484. if (mousePos.getY() > getParentHeight() / 2)
  62485. y = mousePos.getY() - (h + 6);
  62486. else
  62487. y = mousePos.getY() + 6;
  62488. setBounds (x, y, w, h);
  62489. setVisible (true);
  62490. if (getParentComponent() == 0)
  62491. {
  62492. addToDesktop (ComponentPeer::windowHasDropShadow
  62493. | ComponentPeer::windowIsTemporary
  62494. | ComponentPeer::windowIgnoresKeyPresses);
  62495. }
  62496. toFront (false);
  62497. }
  62498. const String TooltipWindow::getTipFor (Component* const c)
  62499. {
  62500. if (c != 0
  62501. && Process::isForegroundProcess()
  62502. && ! Component::isMouseButtonDownAnywhere())
  62503. {
  62504. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62505. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62506. return ttc->getTooltip();
  62507. }
  62508. return String::empty;
  62509. }
  62510. void TooltipWindow::hide()
  62511. {
  62512. tipShowing = String::empty;
  62513. removeFromDesktop();
  62514. setVisible (false);
  62515. }
  62516. void TooltipWindow::timerCallback()
  62517. {
  62518. const unsigned int now = Time::getApproximateMillisecondCounter();
  62519. Component* const newComp = Desktop::getInstance().getMainMouseSource().getComponentUnderMouse();
  62520. const String newTip (getTipFor (newComp));
  62521. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62522. lastComponentUnderMouse = newComp;
  62523. lastTipUnderMouse = newTip;
  62524. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62525. const bool mouseWasClicked = clickCount > mouseClicks;
  62526. mouseClicks = clickCount;
  62527. const Point<int> mousePos (Desktop::getMousePosition());
  62528. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62529. lastMousePos = mousePos;
  62530. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62531. lastCompChangeTime = now;
  62532. if (isVisible() || now < lastHideTime + 500)
  62533. {
  62534. // if a tip is currently visible (or has just disappeared), update to a new one
  62535. // immediately if needed..
  62536. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62537. {
  62538. if (isVisible())
  62539. {
  62540. lastHideTime = now;
  62541. hide();
  62542. }
  62543. }
  62544. else if (tipChanged)
  62545. {
  62546. showFor (newTip);
  62547. }
  62548. }
  62549. else
  62550. {
  62551. // if there isn't currently a tip, but one is needed, only let it
  62552. // appear after a timeout..
  62553. if (newTip.isNotEmpty()
  62554. && newTip != tipShowing
  62555. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62556. {
  62557. showFor (newTip);
  62558. }
  62559. }
  62560. }
  62561. END_JUCE_NAMESPACE
  62562. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62563. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62564. BEGIN_JUCE_NAMESPACE
  62565. class TopLevelWindowManager : public Timer,
  62566. public DeletedAtShutdown
  62567. {
  62568. public:
  62569. TopLevelWindowManager()
  62570. : currentActive (0)
  62571. {
  62572. }
  62573. ~TopLevelWindowManager()
  62574. {
  62575. clearSingletonInstance();
  62576. }
  62577. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62578. void timerCallback()
  62579. {
  62580. startTimer (jmin (1731, getTimerInterval() * 2));
  62581. TopLevelWindow* active = 0;
  62582. if (Process::isForegroundProcess())
  62583. {
  62584. active = currentActive;
  62585. Component* const c = Component::getCurrentlyFocusedComponent();
  62586. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  62587. if (tlw == 0 && c != 0)
  62588. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  62589. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  62590. if (tlw != 0)
  62591. active = tlw;
  62592. }
  62593. if (active != currentActive)
  62594. {
  62595. currentActive = active;
  62596. for (int i = windows.size(); --i >= 0;)
  62597. {
  62598. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  62599. tlw->setWindowActive (isWindowActive (tlw));
  62600. i = jmin (i, windows.size() - 1);
  62601. }
  62602. Desktop::getInstance().triggerFocusCallback();
  62603. }
  62604. }
  62605. bool addWindow (TopLevelWindow* const w) throw()
  62606. {
  62607. windows.add (w);
  62608. startTimer (10);
  62609. return isWindowActive (w);
  62610. }
  62611. void removeWindow (TopLevelWindow* const w) throw()
  62612. {
  62613. startTimer (10);
  62614. if (currentActive == w)
  62615. currentActive = 0;
  62616. windows.removeValue (w);
  62617. if (windows.size() == 0)
  62618. deleteInstance();
  62619. }
  62620. VoidArray windows;
  62621. private:
  62622. TopLevelWindow* currentActive;
  62623. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  62624. {
  62625. return (tlw == currentActive
  62626. || tlw->isParentOf (currentActive)
  62627. || tlw->hasKeyboardFocus (true))
  62628. && tlw->isShowing();
  62629. }
  62630. TopLevelWindowManager (const TopLevelWindowManager&);
  62631. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  62632. };
  62633. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  62634. void juce_CheckCurrentlyFocusedTopLevelWindow()
  62635. {
  62636. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  62637. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  62638. }
  62639. TopLevelWindow::TopLevelWindow (const String& name,
  62640. const bool addToDesktop_)
  62641. : Component (name),
  62642. useDropShadow (true),
  62643. useNativeTitleBar (false),
  62644. windowIsActive_ (false)
  62645. {
  62646. setOpaque (true);
  62647. if (addToDesktop_)
  62648. Component::addToDesktop (getDesktopWindowStyleFlags());
  62649. else
  62650. setDropShadowEnabled (true);
  62651. setWantsKeyboardFocus (true);
  62652. setBroughtToFrontOnMouseClick (true);
  62653. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  62654. }
  62655. TopLevelWindow::~TopLevelWindow()
  62656. {
  62657. shadower = 0;
  62658. TopLevelWindowManager::getInstance()->removeWindow (this);
  62659. }
  62660. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  62661. {
  62662. if (hasKeyboardFocus (true))
  62663. TopLevelWindowManager::getInstance()->timerCallback();
  62664. else
  62665. TopLevelWindowManager::getInstance()->startTimer (10);
  62666. }
  62667. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  62668. {
  62669. if (windowIsActive_ != isNowActive)
  62670. {
  62671. windowIsActive_ = isNowActive;
  62672. activeWindowStatusChanged();
  62673. }
  62674. }
  62675. void TopLevelWindow::activeWindowStatusChanged()
  62676. {
  62677. }
  62678. void TopLevelWindow::parentHierarchyChanged()
  62679. {
  62680. setDropShadowEnabled (useDropShadow);
  62681. }
  62682. void TopLevelWindow::visibilityChanged()
  62683. {
  62684. if (isShowing())
  62685. toFront (true);
  62686. }
  62687. int TopLevelWindow::getDesktopWindowStyleFlags() const
  62688. {
  62689. int flags = ComponentPeer::windowAppearsOnTaskbar;
  62690. if (useDropShadow)
  62691. flags |= ComponentPeer::windowHasDropShadow;
  62692. if (useNativeTitleBar)
  62693. flags |= ComponentPeer::windowHasTitleBar;
  62694. return flags;
  62695. }
  62696. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  62697. {
  62698. useDropShadow = useShadow;
  62699. if (isOnDesktop())
  62700. {
  62701. shadower = 0;
  62702. Component::addToDesktop (getDesktopWindowStyleFlags());
  62703. }
  62704. else
  62705. {
  62706. if (useShadow && isOpaque())
  62707. {
  62708. if (shadower == 0)
  62709. {
  62710. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  62711. if (shadower != 0)
  62712. shadower->setOwner (this);
  62713. }
  62714. }
  62715. else
  62716. {
  62717. shadower = 0;
  62718. }
  62719. }
  62720. }
  62721. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  62722. {
  62723. if (useNativeTitleBar != useNativeTitleBar_)
  62724. {
  62725. useNativeTitleBar = useNativeTitleBar_;
  62726. recreateDesktopWindow();
  62727. sendLookAndFeelChange();
  62728. }
  62729. }
  62730. void TopLevelWindow::recreateDesktopWindow()
  62731. {
  62732. if (isOnDesktop())
  62733. {
  62734. Component::addToDesktop (getDesktopWindowStyleFlags());
  62735. toFront (true);
  62736. }
  62737. }
  62738. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  62739. {
  62740. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  62741. because this class needs to make sure its layout corresponds with settings like whether
  62742. it's got a native title bar or not.
  62743. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  62744. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  62745. method, then add or remove whatever flags are necessary from this value before returning it.
  62746. */
  62747. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  62748. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  62749. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  62750. if (windowStyleFlags != getDesktopWindowStyleFlags())
  62751. sendLookAndFeelChange();
  62752. }
  62753. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  62754. {
  62755. if (c == 0)
  62756. c = TopLevelWindow::getActiveTopLevelWindow();
  62757. if (c == 0)
  62758. {
  62759. centreWithSize (width, height);
  62760. }
  62761. else
  62762. {
  62763. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  62764. (c->getHeight() - height) / 2)));
  62765. Rectangle<int> parentArea (c->getParentMonitorArea());
  62766. if (getParentComponent() != 0)
  62767. {
  62768. p = getParentComponent()->globalPositionToRelative (p);
  62769. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  62770. }
  62771. parentArea.reduce (12, 12);
  62772. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  62773. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  62774. width, height);
  62775. }
  62776. }
  62777. int TopLevelWindow::getNumTopLevelWindows() throw()
  62778. {
  62779. return TopLevelWindowManager::getInstance()->windows.size();
  62780. }
  62781. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  62782. {
  62783. return static_cast <TopLevelWindow*> (TopLevelWindowManager::getInstance()->windows [index]);
  62784. }
  62785. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  62786. {
  62787. TopLevelWindow* best = 0;
  62788. int bestNumTWLParents = -1;
  62789. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  62790. {
  62791. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  62792. if (tlw->isActiveWindow())
  62793. {
  62794. int numTWLParents = 0;
  62795. const Component* c = tlw->getParentComponent();
  62796. while (c != 0)
  62797. {
  62798. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  62799. ++numTWLParents;
  62800. c = c->getParentComponent();
  62801. }
  62802. if (bestNumTWLParents < numTWLParents)
  62803. {
  62804. best = tlw;
  62805. bestNumTWLParents = numTWLParents;
  62806. }
  62807. }
  62808. }
  62809. return best;
  62810. }
  62811. END_JUCE_NAMESPACE
  62812. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  62813. /*** Start of inlined file: juce_Colour.cpp ***/
  62814. BEGIN_JUCE_NAMESPACE
  62815. namespace ColourHelpers
  62816. {
  62817. static uint8 floatAlphaToInt (const float alpha) throw()
  62818. {
  62819. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  62820. }
  62821. static void convertHSBtoRGB (float h, float s, float v,
  62822. uint8& r, uint8& g, uint8& b) throw()
  62823. {
  62824. v = jlimit (0.0f, 1.0f, v);
  62825. v *= 255.0f;
  62826. const uint8 intV = (uint8) roundToInt (v);
  62827. if (s <= 0)
  62828. {
  62829. r = intV;
  62830. g = intV;
  62831. b = intV;
  62832. }
  62833. else
  62834. {
  62835. s = jmin (1.0f, s);
  62836. h = jlimit (0.0f, 1.0f, h);
  62837. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  62838. const float f = h - floorf (h);
  62839. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  62840. const float y = v * (1.0f - s * f);
  62841. const float z = v * (1.0f - (s * (1.0f - f)));
  62842. if (h < 1.0f)
  62843. {
  62844. r = intV;
  62845. g = (uint8) roundToInt (z);
  62846. b = x;
  62847. }
  62848. else if (h < 2.0f)
  62849. {
  62850. r = (uint8) roundToInt (y);
  62851. g = intV;
  62852. b = x;
  62853. }
  62854. else if (h < 3.0f)
  62855. {
  62856. r = x;
  62857. g = intV;
  62858. b = (uint8) roundToInt (z);
  62859. }
  62860. else if (h < 4.0f)
  62861. {
  62862. r = x;
  62863. g = (uint8) roundToInt (y);
  62864. b = intV;
  62865. }
  62866. else if (h < 5.0f)
  62867. {
  62868. r = (uint8) roundToInt (z);
  62869. g = x;
  62870. b = intV;
  62871. }
  62872. else if (h < 6.0f)
  62873. {
  62874. r = intV;
  62875. g = x;
  62876. b = (uint8) roundToInt (y);
  62877. }
  62878. else
  62879. {
  62880. r = 0;
  62881. g = 0;
  62882. b = 0;
  62883. }
  62884. }
  62885. }
  62886. }
  62887. Colour::Colour() throw()
  62888. : argb (0)
  62889. {
  62890. }
  62891. Colour::Colour (const Colour& other) throw()
  62892. : argb (other.argb)
  62893. {
  62894. }
  62895. Colour& Colour::operator= (const Colour& other) throw()
  62896. {
  62897. argb = other.argb;
  62898. return *this;
  62899. }
  62900. bool Colour::operator== (const Colour& other) const throw()
  62901. {
  62902. return argb.getARGB() == other.argb.getARGB();
  62903. }
  62904. bool Colour::operator!= (const Colour& other) const throw()
  62905. {
  62906. return argb.getARGB() != other.argb.getARGB();
  62907. }
  62908. Colour::Colour (const uint32 argb_) throw()
  62909. : argb (argb_)
  62910. {
  62911. }
  62912. Colour::Colour (const uint8 red,
  62913. const uint8 green,
  62914. const uint8 blue) throw()
  62915. {
  62916. argb.setARGB (0xff, red, green, blue);
  62917. }
  62918. const Colour Colour::fromRGB (const uint8 red,
  62919. const uint8 green,
  62920. const uint8 blue) throw()
  62921. {
  62922. return Colour (red, green, blue);
  62923. }
  62924. Colour::Colour (const uint8 red,
  62925. const uint8 green,
  62926. const uint8 blue,
  62927. const uint8 alpha) throw()
  62928. {
  62929. argb.setARGB (alpha, red, green, blue);
  62930. }
  62931. const Colour Colour::fromRGBA (const uint8 red,
  62932. const uint8 green,
  62933. const uint8 blue,
  62934. const uint8 alpha) throw()
  62935. {
  62936. return Colour (red, green, blue, alpha);
  62937. }
  62938. Colour::Colour (const uint8 red,
  62939. const uint8 green,
  62940. const uint8 blue,
  62941. const float alpha) throw()
  62942. {
  62943. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), red, green, blue);
  62944. }
  62945. const Colour Colour::fromRGBAFloat (const uint8 red,
  62946. const uint8 green,
  62947. const uint8 blue,
  62948. const float alpha) throw()
  62949. {
  62950. return Colour (red, green, blue, alpha);
  62951. }
  62952. Colour::Colour (const float hue,
  62953. const float saturation,
  62954. const float brightness,
  62955. const float alpha) throw()
  62956. {
  62957. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62958. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62959. argb.setARGB (ColourHelpers::floatAlphaToInt (alpha), r, g, b);
  62960. }
  62961. const Colour Colour::fromHSV (const float hue,
  62962. const float saturation,
  62963. const float brightness,
  62964. const float alpha) throw()
  62965. {
  62966. return Colour (hue, saturation, brightness, alpha);
  62967. }
  62968. Colour::Colour (const float hue,
  62969. const float saturation,
  62970. const float brightness,
  62971. const uint8 alpha) throw()
  62972. {
  62973. uint8 r = getRed(), g = getGreen(), b = getBlue();
  62974. ColourHelpers::convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  62975. argb.setARGB (alpha, r, g, b);
  62976. }
  62977. Colour::~Colour() throw()
  62978. {
  62979. }
  62980. const PixelARGB Colour::getPixelARGB() const throw()
  62981. {
  62982. PixelARGB p (argb);
  62983. p.premultiply();
  62984. return p;
  62985. }
  62986. uint32 Colour::getARGB() const throw()
  62987. {
  62988. return argb.getARGB();
  62989. }
  62990. bool Colour::isTransparent() const throw()
  62991. {
  62992. return getAlpha() == 0;
  62993. }
  62994. bool Colour::isOpaque() const throw()
  62995. {
  62996. return getAlpha() == 0xff;
  62997. }
  62998. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  62999. {
  63000. PixelARGB newCol (argb);
  63001. newCol.setAlpha (newAlpha);
  63002. return Colour (newCol.getARGB());
  63003. }
  63004. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63005. {
  63006. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63007. PixelARGB newCol (argb);
  63008. newCol.setAlpha (ColourHelpers::floatAlphaToInt (newAlpha));
  63009. return Colour (newCol.getARGB());
  63010. }
  63011. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63012. {
  63013. jassert (alphaMultiplier >= 0);
  63014. PixelARGB newCol (argb);
  63015. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63016. return Colour (newCol.getARGB());
  63017. }
  63018. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63019. {
  63020. const int destAlpha = getAlpha();
  63021. if (destAlpha > 0)
  63022. {
  63023. const int invA = 0xff - (int) src.getAlpha();
  63024. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63025. if (resA > 0)
  63026. {
  63027. const int da = (invA * destAlpha) / resA;
  63028. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63029. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63030. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63031. (uint8) resA);
  63032. }
  63033. return *this;
  63034. }
  63035. else
  63036. {
  63037. return src;
  63038. }
  63039. }
  63040. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63041. {
  63042. if (proportionOfOther <= 0)
  63043. return *this;
  63044. if (proportionOfOther >= 1.0f)
  63045. return other;
  63046. PixelARGB c1 (getPixelARGB());
  63047. const PixelARGB c2 (other.getPixelARGB());
  63048. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63049. c1.unpremultiply();
  63050. return Colour (c1.getARGB());
  63051. }
  63052. float Colour::getFloatRed() const throw()
  63053. {
  63054. return getRed() / 255.0f;
  63055. }
  63056. float Colour::getFloatGreen() const throw()
  63057. {
  63058. return getGreen() / 255.0f;
  63059. }
  63060. float Colour::getFloatBlue() const throw()
  63061. {
  63062. return getBlue() / 255.0f;
  63063. }
  63064. float Colour::getFloatAlpha() const throw()
  63065. {
  63066. return getAlpha() / 255.0f;
  63067. }
  63068. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63069. {
  63070. const int r = getRed();
  63071. const int g = getGreen();
  63072. const int b = getBlue();
  63073. const int hi = jmax (r, g, b);
  63074. const int lo = jmin (r, g, b);
  63075. if (hi != 0)
  63076. {
  63077. s = (hi - lo) / (float) hi;
  63078. if (s != 0)
  63079. {
  63080. const float invDiff = 1.0f / (hi - lo);
  63081. const float red = (hi - r) * invDiff;
  63082. const float green = (hi - g) * invDiff;
  63083. const float blue = (hi - b) * invDiff;
  63084. if (r == hi)
  63085. h = blue - green;
  63086. else if (g == hi)
  63087. h = 2.0f + red - blue;
  63088. else
  63089. h = 4.0f + green - red;
  63090. h *= 1.0f / 6.0f;
  63091. if (h < 0)
  63092. ++h;
  63093. }
  63094. else
  63095. {
  63096. h = 0;
  63097. }
  63098. }
  63099. else
  63100. {
  63101. s = 0;
  63102. h = 0;
  63103. }
  63104. v = hi / 255.0f;
  63105. }
  63106. float Colour::getHue() const throw()
  63107. {
  63108. float h, s, b;
  63109. getHSB (h, s, b);
  63110. return h;
  63111. }
  63112. const Colour Colour::withHue (const float hue) const throw()
  63113. {
  63114. float h, s, b;
  63115. getHSB (h, s, b);
  63116. return Colour (hue, s, b, getAlpha());
  63117. }
  63118. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63119. {
  63120. float h, s, b;
  63121. getHSB (h, s, b);
  63122. h += amountToRotate;
  63123. h -= floorf (h);
  63124. return Colour (h, s, b, getAlpha());
  63125. }
  63126. float Colour::getSaturation() const throw()
  63127. {
  63128. float h, s, b;
  63129. getHSB (h, s, b);
  63130. return s;
  63131. }
  63132. const Colour Colour::withSaturation (const float saturation) const throw()
  63133. {
  63134. float h, s, b;
  63135. getHSB (h, s, b);
  63136. return Colour (h, saturation, b, getAlpha());
  63137. }
  63138. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63139. {
  63140. float h, s, b;
  63141. getHSB (h, s, b);
  63142. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63143. }
  63144. float Colour::getBrightness() const throw()
  63145. {
  63146. float h, s, b;
  63147. getHSB (h, s, b);
  63148. return b;
  63149. }
  63150. const Colour Colour::withBrightness (const float brightness) const throw()
  63151. {
  63152. float h, s, b;
  63153. getHSB (h, s, b);
  63154. return Colour (h, s, brightness, getAlpha());
  63155. }
  63156. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63157. {
  63158. float h, s, b;
  63159. getHSB (h, s, b);
  63160. b *= amount;
  63161. if (b > 1.0f)
  63162. b = 1.0f;
  63163. return Colour (h, s, b, getAlpha());
  63164. }
  63165. const Colour Colour::brighter (float amount) const throw()
  63166. {
  63167. amount = 1.0f / (1.0f + amount);
  63168. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63169. (uint8) (255 - (amount * (255 - getGreen()))),
  63170. (uint8) (255 - (amount * (255 - getBlue()))),
  63171. getAlpha());
  63172. }
  63173. const Colour Colour::darker (float amount) const throw()
  63174. {
  63175. amount = 1.0f / (1.0f + amount);
  63176. return Colour ((uint8) (amount * getRed()),
  63177. (uint8) (amount * getGreen()),
  63178. (uint8) (amount * getBlue()),
  63179. getAlpha());
  63180. }
  63181. const Colour Colour::greyLevel (const float brightness) throw()
  63182. {
  63183. const uint8 level
  63184. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63185. return Colour (level, level, level);
  63186. }
  63187. const Colour Colour::contrasting (const float amount) const throw()
  63188. {
  63189. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63190. ? Colours::black
  63191. : Colours::white).withAlpha (amount));
  63192. }
  63193. const Colour Colour::contrasting (const Colour& colour1,
  63194. const Colour& colour2) throw()
  63195. {
  63196. const float b1 = colour1.getBrightness();
  63197. const float b2 = colour2.getBrightness();
  63198. float best = 0.0f;
  63199. float bestDist = 0.0f;
  63200. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63201. {
  63202. const float d1 = fabsf (i - b1);
  63203. const float d2 = fabsf (i - b2);
  63204. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63205. if (dist > bestDist)
  63206. {
  63207. best = i;
  63208. bestDist = dist;
  63209. }
  63210. }
  63211. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63212. .withBrightness (best);
  63213. }
  63214. const String Colour::toString() const
  63215. {
  63216. return String::toHexString ((int) argb.getARGB());
  63217. }
  63218. const Colour Colour::fromString (const String& encodedColourString)
  63219. {
  63220. return Colour ((uint32) encodedColourString.getHexValue32());
  63221. }
  63222. const String Colour::toDisplayString (const bool includeAlphaValue) const
  63223. {
  63224. return String::toHexString ((int) (argb.getARGB() & (includeAlphaValue ? 0xffffffff : 0xffffff)))
  63225. .paddedLeft ('0', includeAlphaValue ? 8 : 6)
  63226. .toUpperCase();
  63227. }
  63228. END_JUCE_NAMESPACE
  63229. /*** End of inlined file: juce_Colour.cpp ***/
  63230. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63231. BEGIN_JUCE_NAMESPACE
  63232. ColourGradient::ColourGradient() throw()
  63233. {
  63234. #ifdef JUCE_DEBUG
  63235. x1 = 987654.0f;
  63236. #endif
  63237. }
  63238. ColourGradient::ColourGradient (const Colour& colour1,
  63239. const float x1_,
  63240. const float y1_,
  63241. const Colour& colour2,
  63242. const float x2_,
  63243. const float y2_,
  63244. const bool isRadial_) throw()
  63245. : x1 (x1_),
  63246. y1 (y1_),
  63247. x2 (x2_),
  63248. y2 (y2_),
  63249. isRadial (isRadial_)
  63250. {
  63251. colours.add (0);
  63252. colours.add (colour1.getARGB());
  63253. colours.add (1 << 16);
  63254. colours.add (colour2.getARGB());
  63255. }
  63256. ColourGradient::~ColourGradient() throw()
  63257. {
  63258. }
  63259. void ColourGradient::clearColours() throw()
  63260. {
  63261. colours.clear();
  63262. }
  63263. void ColourGradient::addColour (const double proportionAlongGradient,
  63264. const Colour& colour) throw()
  63265. {
  63266. // must be within the two end-points
  63267. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63268. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63269. int i;
  63270. for (i = 0; i < colours.size(); i += 2)
  63271. if (colours.getUnchecked(i) > pos)
  63272. break;
  63273. colours.insert (i, pos);
  63274. colours.insert (i + 1, colour.getARGB());
  63275. }
  63276. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63277. {
  63278. for (int i = 1; i < colours.size(); i += 2)
  63279. {
  63280. const Colour c (colours.getUnchecked(i));
  63281. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63282. }
  63283. }
  63284. int ColourGradient::getNumColours() const throw()
  63285. {
  63286. return colours.size() >> 1;
  63287. }
  63288. double ColourGradient::getColourPosition (const int index) const throw()
  63289. {
  63290. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63291. }
  63292. const Colour ColourGradient::getColour (const int index) const throw()
  63293. {
  63294. return Colour (colours [(index << 1) + 1]);
  63295. }
  63296. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63297. {
  63298. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63299. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63300. if (integerPos <= 0 || colours.size() <= 2)
  63301. return getColour (0);
  63302. int i = colours.size() - 2;
  63303. while (integerPos < (int) colours.getUnchecked(i))
  63304. i -= 2;
  63305. if (i >= colours.size() - 2)
  63306. return Colour (colours.getUnchecked(i));
  63307. const int pos1 = colours.getUnchecked (i);
  63308. const Colour col1 (colours.getUnchecked (i + 1));
  63309. const int pos2 = colours.getUnchecked (i + 2);
  63310. const Colour col2 (colours.getUnchecked (i + 3));
  63311. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63312. }
  63313. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63314. {
  63315. #ifdef JUCE_DEBUG
  63316. // trying to use the object without setting its co-ordinates? Have a careful read of
  63317. // the comments for the constructors.
  63318. jassert (x1 != 987654.0f);
  63319. #endif
  63320. const int numColours = colours.size() >> 1;
  63321. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63322. transform.transformPoint (tx1, ty1);
  63323. transform.transformPoint (tx2, ty2);
  63324. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63325. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63326. lookupTable.malloc (numEntries);
  63327. if (numColours >= 2)
  63328. {
  63329. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63330. PixelARGB pix1 (colours.getUnchecked (1));
  63331. pix1.premultiply();
  63332. int index = 0;
  63333. for (int j = 2; j < colours.size(); j += 2)
  63334. {
  63335. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63336. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63337. pix2.premultiply();
  63338. for (int i = 0; i < numToDo; ++i)
  63339. {
  63340. jassert (index >= 0 && index < numEntries);
  63341. lookupTable[index] = pix1;
  63342. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63343. ++index;
  63344. }
  63345. pix1 = pix2;
  63346. }
  63347. while (index < numEntries)
  63348. lookupTable [index++] = pix1;
  63349. }
  63350. else
  63351. {
  63352. jassertfalse // no colours specified!
  63353. }
  63354. return numEntries;
  63355. }
  63356. bool ColourGradient::isOpaque() const throw()
  63357. {
  63358. for (int i = 1; i < colours.size(); i += 2)
  63359. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63360. return false;
  63361. return true;
  63362. }
  63363. bool ColourGradient::isInvisible() const throw()
  63364. {
  63365. for (int i = 1; i < colours.size(); i += 2)
  63366. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63367. return false;
  63368. return true;
  63369. }
  63370. END_JUCE_NAMESPACE
  63371. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63372. /*** Start of inlined file: juce_Colours.cpp ***/
  63373. BEGIN_JUCE_NAMESPACE
  63374. const Colour Colours::transparentBlack (0);
  63375. const Colour Colours::transparentWhite (0x00ffffff);
  63376. const Colour Colours::aliceblue (0xfff0f8ff);
  63377. const Colour Colours::antiquewhite (0xfffaebd7);
  63378. const Colour Colours::aqua (0xff00ffff);
  63379. const Colour Colours::aquamarine (0xff7fffd4);
  63380. const Colour Colours::azure (0xfff0ffff);
  63381. const Colour Colours::beige (0xfff5f5dc);
  63382. const Colour Colours::bisque (0xffffe4c4);
  63383. const Colour Colours::black (0xff000000);
  63384. const Colour Colours::blanchedalmond (0xffffebcd);
  63385. const Colour Colours::blue (0xff0000ff);
  63386. const Colour Colours::blueviolet (0xff8a2be2);
  63387. const Colour Colours::brown (0xffa52a2a);
  63388. const Colour Colours::burlywood (0xffdeb887);
  63389. const Colour Colours::cadetblue (0xff5f9ea0);
  63390. const Colour Colours::chartreuse (0xff7fff00);
  63391. const Colour Colours::chocolate (0xffd2691e);
  63392. const Colour Colours::coral (0xffff7f50);
  63393. const Colour Colours::cornflowerblue (0xff6495ed);
  63394. const Colour Colours::cornsilk (0xfffff8dc);
  63395. const Colour Colours::crimson (0xffdc143c);
  63396. const Colour Colours::cyan (0xff00ffff);
  63397. const Colour Colours::darkblue (0xff00008b);
  63398. const Colour Colours::darkcyan (0xff008b8b);
  63399. const Colour Colours::darkgoldenrod (0xffb8860b);
  63400. const Colour Colours::darkgrey (0xff555555);
  63401. const Colour Colours::darkgreen (0xff006400);
  63402. const Colour Colours::darkkhaki (0xffbdb76b);
  63403. const Colour Colours::darkmagenta (0xff8b008b);
  63404. const Colour Colours::darkolivegreen (0xff556b2f);
  63405. const Colour Colours::darkorange (0xffff8c00);
  63406. const Colour Colours::darkorchid (0xff9932cc);
  63407. const Colour Colours::darkred (0xff8b0000);
  63408. const Colour Colours::darksalmon (0xffe9967a);
  63409. const Colour Colours::darkseagreen (0xff8fbc8f);
  63410. const Colour Colours::darkslateblue (0xff483d8b);
  63411. const Colour Colours::darkslategrey (0xff2f4f4f);
  63412. const Colour Colours::darkturquoise (0xff00ced1);
  63413. const Colour Colours::darkviolet (0xff9400d3);
  63414. const Colour Colours::deeppink (0xffff1493);
  63415. const Colour Colours::deepskyblue (0xff00bfff);
  63416. const Colour Colours::dimgrey (0xff696969);
  63417. const Colour Colours::dodgerblue (0xff1e90ff);
  63418. const Colour Colours::firebrick (0xffb22222);
  63419. const Colour Colours::floralwhite (0xfffffaf0);
  63420. const Colour Colours::forestgreen (0xff228b22);
  63421. const Colour Colours::fuchsia (0xffff00ff);
  63422. const Colour Colours::gainsboro (0xffdcdcdc);
  63423. const Colour Colours::gold (0xffffd700);
  63424. const Colour Colours::goldenrod (0xffdaa520);
  63425. const Colour Colours::grey (0xff808080);
  63426. const Colour Colours::green (0xff008000);
  63427. const Colour Colours::greenyellow (0xffadff2f);
  63428. const Colour Colours::honeydew (0xfff0fff0);
  63429. const Colour Colours::hotpink (0xffff69b4);
  63430. const Colour Colours::indianred (0xffcd5c5c);
  63431. const Colour Colours::indigo (0xff4b0082);
  63432. const Colour Colours::ivory (0xfffffff0);
  63433. const Colour Colours::khaki (0xfff0e68c);
  63434. const Colour Colours::lavender (0xffe6e6fa);
  63435. const Colour Colours::lavenderblush (0xfffff0f5);
  63436. const Colour Colours::lemonchiffon (0xfffffacd);
  63437. const Colour Colours::lightblue (0xffadd8e6);
  63438. const Colour Colours::lightcoral (0xfff08080);
  63439. const Colour Colours::lightcyan (0xffe0ffff);
  63440. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63441. const Colour Colours::lightgreen (0xff90ee90);
  63442. const Colour Colours::lightgrey (0xffd3d3d3);
  63443. const Colour Colours::lightpink (0xffffb6c1);
  63444. const Colour Colours::lightsalmon (0xffffa07a);
  63445. const Colour Colours::lightseagreen (0xff20b2aa);
  63446. const Colour Colours::lightskyblue (0xff87cefa);
  63447. const Colour Colours::lightslategrey (0xff778899);
  63448. const Colour Colours::lightsteelblue (0xffb0c4de);
  63449. const Colour Colours::lightyellow (0xffffffe0);
  63450. const Colour Colours::lime (0xff00ff00);
  63451. const Colour Colours::limegreen (0xff32cd32);
  63452. const Colour Colours::linen (0xfffaf0e6);
  63453. const Colour Colours::magenta (0xffff00ff);
  63454. const Colour Colours::maroon (0xff800000);
  63455. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63456. const Colour Colours::mediumblue (0xff0000cd);
  63457. const Colour Colours::mediumorchid (0xffba55d3);
  63458. const Colour Colours::mediumpurple (0xff9370db);
  63459. const Colour Colours::mediumseagreen (0xff3cb371);
  63460. const Colour Colours::mediumslateblue (0xff7b68ee);
  63461. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63462. const Colour Colours::mediumturquoise (0xff48d1cc);
  63463. const Colour Colours::mediumvioletred (0xffc71585);
  63464. const Colour Colours::midnightblue (0xff191970);
  63465. const Colour Colours::mintcream (0xfff5fffa);
  63466. const Colour Colours::mistyrose (0xffffe4e1);
  63467. const Colour Colours::navajowhite (0xffffdead);
  63468. const Colour Colours::navy (0xff000080);
  63469. const Colour Colours::oldlace (0xfffdf5e6);
  63470. const Colour Colours::olive (0xff808000);
  63471. const Colour Colours::olivedrab (0xff6b8e23);
  63472. const Colour Colours::orange (0xffffa500);
  63473. const Colour Colours::orangered (0xffff4500);
  63474. const Colour Colours::orchid (0xffda70d6);
  63475. const Colour Colours::palegoldenrod (0xffeee8aa);
  63476. const Colour Colours::palegreen (0xff98fb98);
  63477. const Colour Colours::paleturquoise (0xffafeeee);
  63478. const Colour Colours::palevioletred (0xffdb7093);
  63479. const Colour Colours::papayawhip (0xffffefd5);
  63480. const Colour Colours::peachpuff (0xffffdab9);
  63481. const Colour Colours::peru (0xffcd853f);
  63482. const Colour Colours::pink (0xffffc0cb);
  63483. const Colour Colours::plum (0xffdda0dd);
  63484. const Colour Colours::powderblue (0xffb0e0e6);
  63485. const Colour Colours::purple (0xff800080);
  63486. const Colour Colours::red (0xffff0000);
  63487. const Colour Colours::rosybrown (0xffbc8f8f);
  63488. const Colour Colours::royalblue (0xff4169e1);
  63489. const Colour Colours::saddlebrown (0xff8b4513);
  63490. const Colour Colours::salmon (0xfffa8072);
  63491. const Colour Colours::sandybrown (0xfff4a460);
  63492. const Colour Colours::seagreen (0xff2e8b57);
  63493. const Colour Colours::seashell (0xfffff5ee);
  63494. const Colour Colours::sienna (0xffa0522d);
  63495. const Colour Colours::silver (0xffc0c0c0);
  63496. const Colour Colours::skyblue (0xff87ceeb);
  63497. const Colour Colours::slateblue (0xff6a5acd);
  63498. const Colour Colours::slategrey (0xff708090);
  63499. const Colour Colours::snow (0xfffffafa);
  63500. const Colour Colours::springgreen (0xff00ff7f);
  63501. const Colour Colours::steelblue (0xff4682b4);
  63502. const Colour Colours::tan (0xffd2b48c);
  63503. const Colour Colours::teal (0xff008080);
  63504. const Colour Colours::thistle (0xffd8bfd8);
  63505. const Colour Colours::tomato (0xffff6347);
  63506. const Colour Colours::turquoise (0xff40e0d0);
  63507. const Colour Colours::violet (0xffee82ee);
  63508. const Colour Colours::wheat (0xfff5deb3);
  63509. const Colour Colours::white (0xffffffff);
  63510. const Colour Colours::whitesmoke (0xfff5f5f5);
  63511. const Colour Colours::yellow (0xffffff00);
  63512. const Colour Colours::yellowgreen (0xff9acd32);
  63513. const Colour Colours::findColourForName (const String& colourName,
  63514. const Colour& defaultColour)
  63515. {
  63516. static const int presets[] =
  63517. {
  63518. // (first value is the string's hashcode, second is ARGB)
  63519. 0x05978fff, 0xff000000, /* black */
  63520. 0x06bdcc29, 0xffffffff, /* white */
  63521. 0x002e305a, 0xff0000ff, /* blue */
  63522. 0x00308adf, 0xff808080, /* grey */
  63523. 0x05e0cf03, 0xff008000, /* green */
  63524. 0x0001b891, 0xffff0000, /* red */
  63525. 0xd43c6474, 0xffffff00, /* yellow */
  63526. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63527. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63528. 0x002dcebc, 0xff00ffff, /* aqua */
  63529. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63530. 0x0590228f, 0xfff0ffff, /* azure */
  63531. 0x05947fe4, 0xfff5f5dc, /* beige */
  63532. 0xad388e35, 0xffffe4c4, /* bisque */
  63533. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63534. 0x39129959, 0xff8a2be2, /* blueviolet */
  63535. 0x059a8136, 0xffa52a2a, /* brown */
  63536. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63537. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63538. 0x6b748956, 0xff7fff00, /* chartreuse */
  63539. 0x2903623c, 0xffd2691e, /* chocolate */
  63540. 0x05a74431, 0xffff7f50, /* coral */
  63541. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63542. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63543. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63544. 0x002ed323, 0xff00ffff, /* cyan */
  63545. 0x67cc74d0, 0xff00008b, /* darkblue */
  63546. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63547. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63548. 0x67cecf55, 0xff555555, /* darkgrey */
  63549. 0x920b194d, 0xff006400, /* darkgreen */
  63550. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63551. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63552. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63553. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63554. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63555. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63556. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63557. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63558. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63559. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63560. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63561. 0xc8769375, 0xff9400d3, /* darkviolet */
  63562. 0x25832862, 0xffff1493, /* deeppink */
  63563. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63564. 0x634c8b67, 0xff696969, /* dimgrey */
  63565. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63566. 0xef19e3cb, 0xffb22222, /* firebrick */
  63567. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63568. 0xd086fd06, 0xff228b22, /* forestgreen */
  63569. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63570. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63571. 0x00308060, 0xffffd700, /* gold */
  63572. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63573. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63574. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63575. 0x41892743, 0xffff69b4, /* hotpink */
  63576. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63577. 0xb969fed2, 0xff4b0082, /* indigo */
  63578. 0x05fef6a9, 0xfffffff0, /* ivory */
  63579. 0x06149302, 0xfff0e68c, /* khaki */
  63580. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63581. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63582. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63583. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63584. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63585. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63586. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63587. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63588. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63589. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63590. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  63591. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  63592. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  63593. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  63594. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  63595. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  63596. 0x0032afd5, 0xff00ff00, /* lime */
  63597. 0x607bbc4e, 0xff32cd32, /* limegreen */
  63598. 0x06234efa, 0xfffaf0e6, /* linen */
  63599. 0x316858a9, 0xffff00ff, /* magenta */
  63600. 0xbf8ca470, 0xff800000, /* maroon */
  63601. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  63602. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  63603. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  63604. 0x07556b71, 0xff9370db, /* mediumpurple */
  63605. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  63606. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  63607. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  63608. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  63609. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  63610. 0x168eb32a, 0xff191970, /* midnightblue */
  63611. 0x4306b960, 0xfff5fffa, /* mintcream */
  63612. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  63613. 0xe97218a6, 0xffffdead, /* navajowhite */
  63614. 0x00337bb6, 0xff000080, /* navy */
  63615. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  63616. 0x064ee1db, 0xff808000, /* olive */
  63617. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  63618. 0xc3de262e, 0xffffa500, /* orange */
  63619. 0x58bebba3, 0xffff4500, /* orangered */
  63620. 0xc3def8a3, 0xffda70d6, /* orchid */
  63621. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  63622. 0x3d9dd619, 0xff98fb98, /* palegreen */
  63623. 0x74022737, 0xffafeeee, /* paleturquoise */
  63624. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  63625. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  63626. 0x93e1b776, 0xffffdab9, /* peachpuff */
  63627. 0x003472f8, 0xffcd853f, /* peru */
  63628. 0x00348176, 0xffffc0cb, /* pink */
  63629. 0x00348d94, 0xffdda0dd, /* plum */
  63630. 0xd036be93, 0xffb0e0e6, /* powderblue */
  63631. 0xc5c507bc, 0xff800080, /* purple */
  63632. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  63633. 0xbd9413e1, 0xff4169e1, /* royalblue */
  63634. 0xf456044f, 0xff8b4513, /* saddlebrown */
  63635. 0xc9c6f66e, 0xfffa8072, /* salmon */
  63636. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  63637. 0x34636c14, 0xff2e8b57, /* seagreen */
  63638. 0x3507fb41, 0xfffff5ee, /* seashell */
  63639. 0xca348772, 0xffa0522d, /* sienna */
  63640. 0xca37d30d, 0xffc0c0c0, /* silver */
  63641. 0x80da74fb, 0xff87ceeb, /* skyblue */
  63642. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  63643. 0x44ab37f8, 0xff708090, /* slategrey */
  63644. 0x0035f183, 0xfffffafa, /* snow */
  63645. 0xd5440d16, 0xff00ff7f, /* springgreen */
  63646. 0x3e1524a5, 0xff4682b4, /* steelblue */
  63647. 0x0001bfa1, 0xffd2b48c, /* tan */
  63648. 0x0036425c, 0xff008080, /* teal */
  63649. 0xafc8858f, 0xffd8bfd8, /* thistle */
  63650. 0xcc41600a, 0xffff6347, /* tomato */
  63651. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  63652. 0xcf57947f, 0xffee82ee, /* violet */
  63653. 0x06bdbae7, 0xfff5deb3, /* wheat */
  63654. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  63655. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  63656. };
  63657. const int hash = colourName.trim().toLowerCase().hashCode();
  63658. for (int i = 0; i < numElementsInArray (presets); i += 2)
  63659. if (presets [i] == hash)
  63660. return Colour (presets [i + 1]);
  63661. return defaultColour;
  63662. }
  63663. END_JUCE_NAMESPACE
  63664. /*** End of inlined file: juce_Colours.cpp ***/
  63665. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  63666. BEGIN_JUCE_NAMESPACE
  63667. const int juce_edgeTableDefaultEdgesPerLine = 32;
  63668. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  63669. const Path& path, const AffineTransform& transform)
  63670. : bounds (bounds_),
  63671. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63672. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63673. needToCheckEmptinesss (true)
  63674. {
  63675. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  63676. int* t = table;
  63677. for (int i = bounds.getHeight(); --i >= 0;)
  63678. {
  63679. *t = 0;
  63680. t += lineStrideElements;
  63681. }
  63682. const int topLimit = bounds.getY() << 8;
  63683. const int heightLimit = bounds.getHeight() << 8;
  63684. const int leftLimit = bounds.getX() << 8;
  63685. const int rightLimit = bounds.getRight() << 8;
  63686. PathFlatteningIterator iter (path, transform);
  63687. while (iter.next())
  63688. {
  63689. int y1 = roundToInt (iter.y1 * 256.0f);
  63690. int y2 = roundToInt (iter.y2 * 256.0f);
  63691. if (y1 != y2)
  63692. {
  63693. y1 -= topLimit;
  63694. y2 -= topLimit;
  63695. const int startY = y1;
  63696. int direction = -1;
  63697. if (y1 > y2)
  63698. {
  63699. swapVariables (y1, y2);
  63700. direction = 1;
  63701. }
  63702. if (y1 < 0)
  63703. y1 = 0;
  63704. if (y2 > heightLimit)
  63705. y2 = heightLimit;
  63706. if (y1 < y2)
  63707. {
  63708. const double startX = 256.0f * iter.x1;
  63709. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  63710. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  63711. do
  63712. {
  63713. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  63714. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  63715. if (x < leftLimit)
  63716. x = leftLimit;
  63717. else if (x >= rightLimit)
  63718. x = rightLimit - 1;
  63719. addEdgePoint (x, y1 >> 8, direction * step);
  63720. y1 += step;
  63721. }
  63722. while (y1 < y2);
  63723. }
  63724. }
  63725. }
  63726. sanitiseLevels (path.isUsingNonZeroWinding());
  63727. }
  63728. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd)
  63729. : bounds (rectangleToAdd),
  63730. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63731. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63732. needToCheckEmptinesss (true)
  63733. {
  63734. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63735. table[0] = 0;
  63736. const int x1 = rectangleToAdd.getX() << 8;
  63737. const int x2 = rectangleToAdd.getRight() << 8;
  63738. int* t = table;
  63739. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  63740. {
  63741. t[0] = 2;
  63742. t[1] = x1;
  63743. t[2] = 255;
  63744. t[3] = x2;
  63745. t[4] = 0;
  63746. t += lineStrideElements;
  63747. }
  63748. }
  63749. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd)
  63750. : bounds (rectanglesToAdd.getBounds()),
  63751. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63752. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63753. needToCheckEmptinesss (true)
  63754. {
  63755. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63756. int* t = table;
  63757. for (int i = bounds.getHeight(); --i >= 0;)
  63758. {
  63759. *t = 0;
  63760. t += lineStrideElements;
  63761. }
  63762. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  63763. {
  63764. const Rectangle<int>* const r = iter.getRectangle();
  63765. const int x1 = r->getX() << 8;
  63766. const int x2 = r->getRight() << 8;
  63767. int y = r->getY() - bounds.getY();
  63768. for (int j = r->getHeight(); --j >= 0;)
  63769. {
  63770. addEdgePoint (x1, y, 255);
  63771. addEdgePoint (x2, y, -255);
  63772. ++y;
  63773. }
  63774. }
  63775. sanitiseLevels (true);
  63776. }
  63777. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h)
  63778. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  63779. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  63780. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  63781. needToCheckEmptinesss (true)
  63782. {
  63783. jassert (w > 0 && h > 0);
  63784. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63785. table[0] = 0;
  63786. const int x1 = roundToInt (x * 256.0f);
  63787. const int x2 = roundToInt ((x + w) * 256.0f);
  63788. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  63789. jassert (y1 < 256);
  63790. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  63791. if (x2 <= x1 || y2 <= y1)
  63792. {
  63793. bounds.setHeight (0);
  63794. return;
  63795. }
  63796. int lineY = 0;
  63797. int* t = table;
  63798. if ((y1 >> 8) == (y2 >> 8))
  63799. {
  63800. t[0] = 2;
  63801. t[1] = x1;
  63802. t[2] = y2 - y1;
  63803. t[3] = x2;
  63804. t[4] = 0;
  63805. ++lineY;
  63806. t += lineStrideElements;
  63807. }
  63808. else
  63809. {
  63810. t[0] = 2;
  63811. t[1] = x1;
  63812. t[2] = 255 - (y1 & 255);
  63813. t[3] = x2;
  63814. t[4] = 0;
  63815. ++lineY;
  63816. t += lineStrideElements;
  63817. while (lineY < (y2 >> 8))
  63818. {
  63819. t[0] = 2;
  63820. t[1] = x1;
  63821. t[2] = 255;
  63822. t[3] = x2;
  63823. t[4] = 0;
  63824. ++lineY;
  63825. t += lineStrideElements;
  63826. }
  63827. jassert (lineY < bounds.getHeight());
  63828. t[0] = 2;
  63829. t[1] = x1;
  63830. t[2] = y2 & 255;
  63831. t[3] = x2;
  63832. t[4] = 0;
  63833. ++lineY;
  63834. t += lineStrideElements;
  63835. }
  63836. while (lineY < bounds.getHeight())
  63837. {
  63838. t[0] = 0;
  63839. t += lineStrideElements;
  63840. ++lineY;
  63841. }
  63842. }
  63843. EdgeTable::EdgeTable (const EdgeTable& other)
  63844. : table (0)
  63845. {
  63846. operator= (other);
  63847. }
  63848. EdgeTable& EdgeTable::operator= (const EdgeTable& other)
  63849. {
  63850. bounds = other.bounds;
  63851. maxEdgesPerLine = other.maxEdgesPerLine;
  63852. lineStrideElements = other.lineStrideElements;
  63853. needToCheckEmptinesss = other.needToCheckEmptinesss;
  63854. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  63855. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  63856. return *this;
  63857. }
  63858. EdgeTable::~EdgeTable()
  63859. {
  63860. }
  63861. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  63862. {
  63863. while (--numLines >= 0)
  63864. {
  63865. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  63866. src += srcLineStride;
  63867. dest += destLineStride;
  63868. }
  63869. }
  63870. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  63871. {
  63872. // Convert the table from relative windings to absolute levels..
  63873. int* lineStart = table;
  63874. for (int i = bounds.getHeight(); --i >= 0;)
  63875. {
  63876. int* line = lineStart;
  63877. lineStart += lineStrideElements;
  63878. int num = *line;
  63879. if (num == 0)
  63880. continue;
  63881. int level = 0;
  63882. if (useNonZeroWinding)
  63883. {
  63884. while (--num > 0)
  63885. {
  63886. line += 2;
  63887. level += *line;
  63888. int corrected = abs (level);
  63889. if (corrected >> 8)
  63890. corrected = 255;
  63891. *line = corrected;
  63892. }
  63893. }
  63894. else
  63895. {
  63896. while (--num > 0)
  63897. {
  63898. line += 2;
  63899. level += *line;
  63900. int corrected = abs (level);
  63901. if (corrected >> 8)
  63902. {
  63903. corrected &= 511;
  63904. if (corrected >> 8)
  63905. corrected = 511 - corrected;
  63906. }
  63907. *line = corrected;
  63908. }
  63909. }
  63910. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  63911. }
  63912. }
  63913. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  63914. {
  63915. if (newNumEdgesPerLine != maxEdgesPerLine)
  63916. {
  63917. maxEdgesPerLine = newNumEdgesPerLine;
  63918. jassert (bounds.getHeight() > 0);
  63919. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  63920. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  63921. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  63922. table.swapWith (newTable);
  63923. lineStrideElements = newLineStrideElements;
  63924. }
  63925. }
  63926. void EdgeTable::optimiseTable() throw()
  63927. {
  63928. int maxLineElements = 0;
  63929. for (int i = bounds.getHeight(); --i >= 0;)
  63930. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  63931. remapTableForNumEdges (maxLineElements);
  63932. }
  63933. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  63934. {
  63935. jassert (y >= 0 && y < bounds.getHeight());
  63936. int* line = table + lineStrideElements * y;
  63937. const int numPoints = line[0];
  63938. int n = numPoints << 1;
  63939. if (n > 0)
  63940. {
  63941. while (n > 0)
  63942. {
  63943. const int cx = line [n - 1];
  63944. if (cx <= x)
  63945. {
  63946. if (cx == x)
  63947. {
  63948. line [n] += winding;
  63949. return;
  63950. }
  63951. break;
  63952. }
  63953. n -= 2;
  63954. }
  63955. if (numPoints >= maxEdgesPerLine)
  63956. {
  63957. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  63958. jassert (numPoints < maxEdgesPerLine);
  63959. line = table + lineStrideElements * y;
  63960. }
  63961. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  63962. }
  63963. line [n + 1] = x;
  63964. line [n + 2] = winding;
  63965. line[0]++;
  63966. }
  63967. void EdgeTable::translate (float dx, int dy) throw()
  63968. {
  63969. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  63970. int* lineStart = table;
  63971. const int intDx = (int) (dx * 256.0f);
  63972. for (int i = bounds.getHeight(); --i >= 0;)
  63973. {
  63974. int* line = lineStart;
  63975. lineStart += lineStrideElements;
  63976. int num = *line++;
  63977. while (--num >= 0)
  63978. {
  63979. *line += intDx;
  63980. line += 2;
  63981. }
  63982. }
  63983. }
  63984. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  63985. {
  63986. jassert (y >= 0 && y < bounds.getHeight());
  63987. int* dest = table + lineStrideElements * y;
  63988. if (dest[0] == 0)
  63989. return;
  63990. int otherNumPoints = *otherLine;
  63991. if (otherNumPoints == 0)
  63992. {
  63993. *dest = 0;
  63994. return;
  63995. }
  63996. const int right = bounds.getRight() << 8;
  63997. // optimise for the common case where our line lies entirely within a
  63998. // single pair of points, as happens when clipping to a simple rect.
  63999. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64000. {
  64001. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64002. return;
  64003. }
  64004. ++otherLine;
  64005. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64006. int* temp = (int*) alloca (lineSizeBytes);
  64007. memcpy (temp, dest, lineSizeBytes);
  64008. const int* src1 = temp;
  64009. int srcNum1 = *src1++;
  64010. int x1 = *src1++;
  64011. const int* src2 = otherLine;
  64012. int srcNum2 = otherNumPoints;
  64013. int x2 = *src2++;
  64014. int destIndex = 0, destTotal = 0;
  64015. int level1 = 0, level2 = 0;
  64016. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64017. while (srcNum1 > 0 && srcNum2 > 0)
  64018. {
  64019. int nextX;
  64020. if (x1 < x2)
  64021. {
  64022. nextX = x1;
  64023. level1 = *src1++;
  64024. x1 = *src1++;
  64025. --srcNum1;
  64026. }
  64027. else if (x1 == x2)
  64028. {
  64029. nextX = x1;
  64030. level1 = *src1++;
  64031. level2 = *src2++;
  64032. x1 = *src1++;
  64033. x2 = *src2++;
  64034. --srcNum1;
  64035. --srcNum2;
  64036. }
  64037. else
  64038. {
  64039. nextX = x2;
  64040. level2 = *src2++;
  64041. x2 = *src2++;
  64042. --srcNum2;
  64043. }
  64044. if (nextX > lastX)
  64045. {
  64046. if (nextX >= right)
  64047. break;
  64048. lastX = nextX;
  64049. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64050. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64051. if (nextLevel != lastLevel)
  64052. {
  64053. if (destTotal >= maxEdgesPerLine)
  64054. {
  64055. dest[0] = destTotal;
  64056. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64057. dest = table + lineStrideElements * y;
  64058. }
  64059. ++destTotal;
  64060. lastLevel = nextLevel;
  64061. dest[++destIndex] = nextX;
  64062. dest[++destIndex] = nextLevel;
  64063. }
  64064. }
  64065. }
  64066. if (lastLevel > 0)
  64067. {
  64068. if (destTotal >= maxEdgesPerLine)
  64069. {
  64070. dest[0] = destTotal;
  64071. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64072. dest = table + lineStrideElements * y;
  64073. }
  64074. ++destTotal;
  64075. dest[++destIndex] = right;
  64076. dest[++destIndex] = 0;
  64077. }
  64078. dest[0] = destTotal;
  64079. #if JUCE_DEBUG
  64080. int last = std::numeric_limits<int>::min();
  64081. for (int i = 0; i < dest[0]; ++i)
  64082. {
  64083. jassert (dest[i * 2 + 1] > last);
  64084. last = dest[i * 2 + 1];
  64085. }
  64086. jassert (dest [dest[0] * 2] == 0);
  64087. #endif
  64088. }
  64089. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64090. {
  64091. int* lastItem = dest + (dest[0] * 2 - 1);
  64092. if (x2 < lastItem[0])
  64093. {
  64094. if (x2 <= dest[1])
  64095. {
  64096. dest[0] = 0;
  64097. return;
  64098. }
  64099. while (x2 < lastItem[-2])
  64100. {
  64101. --(dest[0]);
  64102. lastItem -= 2;
  64103. }
  64104. lastItem[0] = x2;
  64105. lastItem[1] = 0;
  64106. }
  64107. if (x1 > dest[1])
  64108. {
  64109. while (lastItem[0] > x1)
  64110. lastItem -= 2;
  64111. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64112. if (itemsRemoved > 0)
  64113. {
  64114. dest[0] -= itemsRemoved;
  64115. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64116. }
  64117. dest[1] = x1;
  64118. }
  64119. }
  64120. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64121. {
  64122. const Rectangle<int> clipped (r.getIntersection (bounds));
  64123. if (clipped.isEmpty())
  64124. {
  64125. needToCheckEmptinesss = false;
  64126. bounds.setHeight (0);
  64127. }
  64128. else
  64129. {
  64130. const int top = clipped.getY() - bounds.getY();
  64131. const int bottom = clipped.getBottom() - bounds.getY();
  64132. if (bottom < bounds.getHeight())
  64133. bounds.setHeight (bottom);
  64134. if (clipped.getRight() < bounds.getRight())
  64135. bounds.setRight (clipped.getRight());
  64136. for (int i = top; --i >= 0;)
  64137. table [lineStrideElements * i] = 0;
  64138. if (clipped.getX() > bounds.getX())
  64139. {
  64140. const int x1 = clipped.getX() << 8;
  64141. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64142. int* line = table + lineStrideElements * top;
  64143. for (int i = bottom - top; --i >= 0;)
  64144. {
  64145. if (line[0] != 0)
  64146. clipEdgeTableLineToRange (line, x1, x2);
  64147. line += lineStrideElements;
  64148. }
  64149. }
  64150. needToCheckEmptinesss = true;
  64151. }
  64152. }
  64153. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64154. {
  64155. const Rectangle<int> clipped (r.getIntersection (bounds));
  64156. if (! clipped.isEmpty())
  64157. {
  64158. const int top = clipped.getY() - bounds.getY();
  64159. const int bottom = clipped.getBottom() - bounds.getY();
  64160. //XXX optimise here by shortening the table if it fills top or bottom
  64161. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64162. clipped.getX() << 8, 0,
  64163. clipped.getRight() << 8, 255,
  64164. std::numeric_limits<int>::max(), 0 };
  64165. for (int i = top; i < bottom; ++i)
  64166. intersectWithEdgeTableLine (i, rectLine);
  64167. needToCheckEmptinesss = true;
  64168. }
  64169. }
  64170. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64171. {
  64172. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64173. if (clipped.isEmpty())
  64174. {
  64175. needToCheckEmptinesss = false;
  64176. bounds.setHeight (0);
  64177. }
  64178. else
  64179. {
  64180. const int top = clipped.getY() - bounds.getY();
  64181. const int bottom = clipped.getBottom() - bounds.getY();
  64182. if (bottom < bounds.getHeight())
  64183. bounds.setHeight (bottom);
  64184. if (clipped.getRight() < bounds.getRight())
  64185. bounds.setRight (clipped.getRight());
  64186. int i = 0;
  64187. for (i = top; --i >= 0;)
  64188. table [lineStrideElements * i] = 0;
  64189. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64190. for (i = top; i < bottom; ++i)
  64191. {
  64192. intersectWithEdgeTableLine (i, otherLine);
  64193. otherLine += other.lineStrideElements;
  64194. }
  64195. needToCheckEmptinesss = true;
  64196. }
  64197. }
  64198. void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw()
  64199. {
  64200. y -= bounds.getY();
  64201. if (y < 0 || y >= bounds.getHeight())
  64202. return;
  64203. needToCheckEmptinesss = true;
  64204. if (numPixels <= 0)
  64205. {
  64206. table [lineStrideElements * y] = 0;
  64207. return;
  64208. }
  64209. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64210. int destIndex = 0, lastLevel = 0;
  64211. while (--numPixels >= 0)
  64212. {
  64213. const int alpha = *mask;
  64214. mask += maskStride;
  64215. if (alpha != lastLevel)
  64216. {
  64217. tempLine[++destIndex] = (x << 8);
  64218. tempLine[++destIndex] = alpha;
  64219. lastLevel = alpha;
  64220. }
  64221. ++x;
  64222. }
  64223. if (lastLevel > 0)
  64224. {
  64225. tempLine[++destIndex] = (x << 8);
  64226. tempLine[++destIndex] = 0;
  64227. }
  64228. tempLine[0] = destIndex >> 1;
  64229. intersectWithEdgeTableLine (y, tempLine);
  64230. }
  64231. bool EdgeTable::isEmpty() throw()
  64232. {
  64233. if (needToCheckEmptinesss)
  64234. {
  64235. needToCheckEmptinesss = false;
  64236. int* t = table;
  64237. for (int i = bounds.getHeight(); --i >= 0;)
  64238. {
  64239. if (t[0] > 1)
  64240. return false;
  64241. t += lineStrideElements;
  64242. }
  64243. bounds.setHeight (0);
  64244. }
  64245. return bounds.getHeight() == 0;
  64246. }
  64247. END_JUCE_NAMESPACE
  64248. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64249. /*** Start of inlined file: juce_FillType.cpp ***/
  64250. BEGIN_JUCE_NAMESPACE
  64251. FillType::FillType() throw()
  64252. : colour (0xff000000), image (0)
  64253. {
  64254. }
  64255. FillType::FillType (const Colour& colour_) throw()
  64256. : colour (colour_), image (0)
  64257. {
  64258. }
  64259. FillType::FillType (const ColourGradient& gradient_) throw()
  64260. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64261. {
  64262. }
  64263. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64264. : colour (0xff000000), image (&image_), transform (transform_)
  64265. {
  64266. }
  64267. FillType::FillType (const FillType& other) throw()
  64268. : colour (other.colour),
  64269. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64270. image (other.image), transform (other.transform)
  64271. {
  64272. }
  64273. FillType& FillType::operator= (const FillType& other) throw()
  64274. {
  64275. if (this != &other)
  64276. {
  64277. colour = other.colour;
  64278. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64279. image = other.image;
  64280. transform = other.transform;
  64281. }
  64282. return *this;
  64283. }
  64284. FillType::~FillType() throw()
  64285. {
  64286. }
  64287. void FillType::setColour (const Colour& newColour) throw()
  64288. {
  64289. gradient = 0;
  64290. image = 0;
  64291. colour = newColour;
  64292. }
  64293. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64294. {
  64295. if (gradient != 0)
  64296. {
  64297. *gradient = newGradient;
  64298. }
  64299. else
  64300. {
  64301. image = 0;
  64302. gradient = new ColourGradient (newGradient);
  64303. colour = Colours::black;
  64304. }
  64305. }
  64306. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64307. {
  64308. gradient = 0;
  64309. image = &image_;
  64310. transform = transform_;
  64311. colour = Colours::black;
  64312. }
  64313. void FillType::setOpacity (const float newOpacity) throw()
  64314. {
  64315. colour = colour.withAlpha (newOpacity);
  64316. }
  64317. END_JUCE_NAMESPACE
  64318. /*** End of inlined file: juce_FillType.cpp ***/
  64319. /*** Start of inlined file: juce_Graphics.cpp ***/
  64320. BEGIN_JUCE_NAMESPACE
  64321. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64322. template <typename Type>
  64323. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64324. {
  64325. const int maxVal = 0x3fffffff;
  64326. return (int) x >= -maxVal && (int) x <= maxVal
  64327. && (int) y >= -maxVal && (int) y <= maxVal
  64328. && (int) w >= -maxVal && (int) w <= maxVal
  64329. && (int) h >= -maxVal && (int) h <= maxVal;
  64330. }
  64331. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64332. {
  64333. }
  64334. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64335. {
  64336. }
  64337. Graphics::Graphics (Image& imageToDrawOnto)
  64338. : context (imageToDrawOnto.createLowLevelContext()),
  64339. contextToDelete (context),
  64340. saveStatePending (false)
  64341. {
  64342. }
  64343. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64344. : context (internalContext),
  64345. saveStatePending (false)
  64346. {
  64347. }
  64348. Graphics::~Graphics()
  64349. {
  64350. }
  64351. void Graphics::resetToDefaultState()
  64352. {
  64353. saveStateIfPending();
  64354. context->setFill (FillType());
  64355. context->setFont (Font());
  64356. context->setInterpolationQuality (defaultQuality);
  64357. }
  64358. bool Graphics::isVectorDevice() const
  64359. {
  64360. return context->isVectorDevice();
  64361. }
  64362. bool Graphics::reduceClipRegion (const int x, const int y, const int w, const int h)
  64363. {
  64364. saveStateIfPending();
  64365. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64366. }
  64367. bool Graphics::reduceClipRegion (const RectangleList& clipRegion)
  64368. {
  64369. saveStateIfPending();
  64370. return context->clipToRectangleList (clipRegion);
  64371. }
  64372. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform)
  64373. {
  64374. saveStateIfPending();
  64375. context->clipToPath (path, transform);
  64376. return ! context->isClipEmpty();
  64377. }
  64378. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform)
  64379. {
  64380. saveStateIfPending();
  64381. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64382. return ! context->isClipEmpty();
  64383. }
  64384. void Graphics::excludeClipRegion (const Rectangle<int>& rectangleToExclude)
  64385. {
  64386. saveStateIfPending();
  64387. context->excludeClipRectangle (rectangleToExclude);
  64388. }
  64389. bool Graphics::isClipEmpty() const
  64390. {
  64391. return context->isClipEmpty();
  64392. }
  64393. const Rectangle<int> Graphics::getClipBounds() const
  64394. {
  64395. return context->getClipBounds();
  64396. }
  64397. void Graphics::saveState()
  64398. {
  64399. saveStateIfPending();
  64400. saveStatePending = true;
  64401. }
  64402. void Graphics::restoreState()
  64403. {
  64404. if (saveStatePending)
  64405. saveStatePending = false;
  64406. else
  64407. context->restoreState();
  64408. }
  64409. void Graphics::saveStateIfPending()
  64410. {
  64411. if (saveStatePending)
  64412. {
  64413. saveStatePending = false;
  64414. context->saveState();
  64415. }
  64416. }
  64417. void Graphics::setOrigin (const int newOriginX, const int newOriginY)
  64418. {
  64419. saveStateIfPending();
  64420. context->setOrigin (newOriginX, newOriginY);
  64421. }
  64422. bool Graphics::clipRegionIntersects (const int x, const int y, const int w, const int h) const
  64423. {
  64424. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64425. }
  64426. void Graphics::setColour (const Colour& newColour)
  64427. {
  64428. saveStateIfPending();
  64429. context->setFill (newColour);
  64430. }
  64431. void Graphics::setOpacity (const float newOpacity)
  64432. {
  64433. saveStateIfPending();
  64434. context->setOpacity (newOpacity);
  64435. }
  64436. void Graphics::setGradientFill (const ColourGradient& gradient)
  64437. {
  64438. setFillType (gradient);
  64439. }
  64440. void Graphics::setTiledImageFill (const Image& imageToUse, const int anchorX, const int anchorY, const float opacity)
  64441. {
  64442. saveStateIfPending();
  64443. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64444. context->setOpacity (opacity);
  64445. }
  64446. void Graphics::setFillType (const FillType& newFill)
  64447. {
  64448. saveStateIfPending();
  64449. context->setFill (newFill);
  64450. }
  64451. void Graphics::setFont (const Font& newFont)
  64452. {
  64453. saveStateIfPending();
  64454. context->setFont (newFont);
  64455. }
  64456. void Graphics::setFont (const float newFontHeight, const int newFontStyleFlags)
  64457. {
  64458. saveStateIfPending();
  64459. Font f (context->getFont());
  64460. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64461. context->setFont (f);
  64462. }
  64463. void Graphics::drawSingleLineText (const String& text, const int startX, const int baselineY) const
  64464. {
  64465. if (text.isNotEmpty()
  64466. && startX < context->getClipBounds().getRight())
  64467. {
  64468. GlyphArrangement arr;
  64469. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64470. arr.draw (*this);
  64471. }
  64472. }
  64473. void Graphics::drawTextAsPath (const String& text, const AffineTransform& transform) const
  64474. {
  64475. if (text.isNotEmpty())
  64476. {
  64477. GlyphArrangement arr;
  64478. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64479. arr.draw (*this, transform);
  64480. }
  64481. }
  64482. void Graphics::drawMultiLineText (const String& text, const int startX, const int baselineY, const int maximumLineWidth) const
  64483. {
  64484. if (text.isNotEmpty()
  64485. && startX < context->getClipBounds().getRight())
  64486. {
  64487. GlyphArrangement arr;
  64488. arr.addJustifiedText (context->getFont(), text,
  64489. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64490. Justification::left);
  64491. arr.draw (*this);
  64492. }
  64493. }
  64494. void Graphics::drawText (const String& text,
  64495. const int x, const int y, const int width, const int height,
  64496. const Justification& justificationType,
  64497. const bool useEllipsesIfTooBig) const
  64498. {
  64499. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64500. {
  64501. GlyphArrangement arr;
  64502. arr.addCurtailedLineOfText (context->getFont(), text,
  64503. 0.0f, 0.0f, (float) width,
  64504. useEllipsesIfTooBig);
  64505. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64506. (float) x, (float) y, (float) width, (float) height,
  64507. justificationType);
  64508. arr.draw (*this);
  64509. }
  64510. }
  64511. void Graphics::drawFittedText (const String& text,
  64512. const int x, const int y, const int width, const int height,
  64513. const Justification& justification,
  64514. const int maximumNumberOfLines,
  64515. const float minimumHorizontalScale) const
  64516. {
  64517. if (text.isNotEmpty()
  64518. && width > 0 && height > 0
  64519. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64520. {
  64521. GlyphArrangement arr;
  64522. arr.addFittedText (context->getFont(), text,
  64523. (float) x, (float) y, (float) width, (float) height,
  64524. justification,
  64525. maximumNumberOfLines,
  64526. minimumHorizontalScale);
  64527. arr.draw (*this);
  64528. }
  64529. }
  64530. void Graphics::fillRect (int x, int y, int width, int height) const
  64531. {
  64532. // passing in a silly number can cause maths problems in rendering!
  64533. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64534. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64535. }
  64536. void Graphics::fillRect (const Rectangle<int>& r) const
  64537. {
  64538. context->fillRect (r, false);
  64539. }
  64540. void Graphics::fillRect (const float x, const float y, const float width, const float height) const
  64541. {
  64542. // passing in a silly number can cause maths problems in rendering!
  64543. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64544. Path p;
  64545. p.addRectangle (x, y, width, height);
  64546. fillPath (p);
  64547. }
  64548. void Graphics::setPixel (int x, int y) const
  64549. {
  64550. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64551. }
  64552. void Graphics::fillAll() const
  64553. {
  64554. fillRect (context->getClipBounds());
  64555. }
  64556. void Graphics::fillAll (const Colour& colourToUse) const
  64557. {
  64558. if (! colourToUse.isTransparent())
  64559. {
  64560. const Rectangle<int> clip (context->getClipBounds());
  64561. context->saveState();
  64562. context->setFill (colourToUse);
  64563. context->fillRect (clip, false);
  64564. context->restoreState();
  64565. }
  64566. }
  64567. void Graphics::fillPath (const Path& path, const AffineTransform& transform) const
  64568. {
  64569. if ((! context->isClipEmpty()) && ! path.isEmpty())
  64570. context->fillPath (path, transform);
  64571. }
  64572. void Graphics::strokePath (const Path& path,
  64573. const PathStrokeType& strokeType,
  64574. const AffineTransform& transform) const
  64575. {
  64576. Path stroke;
  64577. strokeType.createStrokedPath (stroke, path, transform);
  64578. fillPath (stroke);
  64579. }
  64580. void Graphics::drawRect (const int x, const int y, const int width, const int height,
  64581. const int lineThickness) const
  64582. {
  64583. // passing in a silly number can cause maths problems in rendering!
  64584. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64585. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  64586. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64587. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  64588. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  64589. }
  64590. void Graphics::drawRect (const float x, const float y, const float width, const float height, const float lineThickness) const
  64591. {
  64592. // passing in a silly number can cause maths problems in rendering!
  64593. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64594. Path p;
  64595. p.addRectangle (x, y, width, lineThickness);
  64596. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64597. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  64598. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  64599. fillPath (p);
  64600. }
  64601. void Graphics::drawRect (const Rectangle<int>& r, const int lineThickness) const
  64602. {
  64603. drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight(), lineThickness);
  64604. }
  64605. void Graphics::drawBevel (const int x, const int y, const int width, const int height,
  64606. const int bevelThickness, const Colour& topLeftColour, const Colour& bottomRightColour,
  64607. const bool useGradient, const bool sharpEdgeOnOutside) const
  64608. {
  64609. // passing in a silly number can cause maths problems in rendering!
  64610. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64611. if (clipRegionIntersects (x, y, width, height))
  64612. {
  64613. context->saveState();
  64614. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  64615. const float ramp = oldOpacity / bevelThickness;
  64616. for (int i = bevelThickness; --i >= 0;)
  64617. {
  64618. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  64619. : oldOpacity;
  64620. context->setFill (topLeftColour.withMultipliedAlpha (op));
  64621. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  64622. context->setFill (topLeftColour.withMultipliedAlpha (op * 0.75f));
  64623. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  64624. context->setFill (bottomRightColour.withMultipliedAlpha (op));
  64625. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  64626. context->setFill (bottomRightColour.withMultipliedAlpha (op * 0.75f));
  64627. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  64628. }
  64629. context->restoreState();
  64630. }
  64631. }
  64632. void Graphics::fillEllipse (const float x, const float y, const float width, const float height) const
  64633. {
  64634. // passing in a silly number can cause maths problems in rendering!
  64635. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64636. Path p;
  64637. p.addEllipse (x, y, width, height);
  64638. fillPath (p);
  64639. }
  64640. void Graphics::drawEllipse (const float x, const float y, const float width, const float height,
  64641. const float lineThickness) const
  64642. {
  64643. // passing in a silly number can cause maths problems in rendering!
  64644. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64645. Path p;
  64646. p.addEllipse (x, y, width, height);
  64647. strokePath (p, PathStrokeType (lineThickness));
  64648. }
  64649. void Graphics::fillRoundedRectangle (const float x, const float y, const float width, const float height, const float cornerSize) const
  64650. {
  64651. // passing in a silly number can cause maths problems in rendering!
  64652. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64653. Path p;
  64654. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64655. fillPath (p);
  64656. }
  64657. void Graphics::fillRoundedRectangle (const Rectangle<float>& r, const float cornerSize) const
  64658. {
  64659. fillRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize);
  64660. }
  64661. void Graphics::drawRoundedRectangle (const float x, const float y, const float width, const float height,
  64662. const float cornerSize, const float lineThickness) const
  64663. {
  64664. // passing in a silly number can cause maths problems in rendering!
  64665. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64666. Path p;
  64667. p.addRoundedRectangle (x, y, width, height, cornerSize);
  64668. strokePath (p, PathStrokeType (lineThickness));
  64669. }
  64670. void Graphics::drawRoundedRectangle (const Rectangle<float>& r, const float cornerSize, const float lineThickness) const
  64671. {
  64672. drawRoundedRectangle (r.getX(), r.getY(), r.getWidth(), r.getHeight(), cornerSize, lineThickness);
  64673. }
  64674. void Graphics::drawArrow (const float startX, const float startY, const float endX, const float endY,
  64675. const float lineThickness, const float arrowheadWidth, const float arrowheadLength) const
  64676. {
  64677. Path p;
  64678. p.addArrow (startX, startY, endX, endY,
  64679. lineThickness, arrowheadWidth, arrowheadLength);
  64680. fillPath (p);
  64681. }
  64682. void Graphics::fillCheckerBoard (int x, int y, int width, int height,
  64683. const int checkWidth, const int checkHeight,
  64684. const Colour& colour1, const Colour& colour2) const
  64685. {
  64686. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  64687. if (checkWidth > 0 && checkHeight > 0)
  64688. {
  64689. context->saveState();
  64690. if (colour1 == colour2)
  64691. {
  64692. context->setFill (colour1);
  64693. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64694. }
  64695. else
  64696. {
  64697. const Rectangle<int> clip (context->getClipBounds());
  64698. const int right = jmin (x + width, clip.getRight());
  64699. const int bottom = jmin (y + height, clip.getBottom());
  64700. int cy = 0;
  64701. while (y < bottom)
  64702. {
  64703. int cx = cy;
  64704. for (int xx = x; xx < right; xx += checkWidth)
  64705. {
  64706. context->setFill (((cx++ & 1) == 0) ? colour1 : colour2);
  64707. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  64708. false);
  64709. }
  64710. ++cy;
  64711. y += checkHeight;
  64712. }
  64713. }
  64714. context->restoreState();
  64715. }
  64716. }
  64717. void Graphics::drawVerticalLine (const int x, float top, float bottom) const
  64718. {
  64719. context->drawVerticalLine (x, top, bottom);
  64720. }
  64721. void Graphics::drawHorizontalLine (const int y, float left, float right) const
  64722. {
  64723. context->drawHorizontalLine (y, left, right);
  64724. }
  64725. void Graphics::drawLine (float x1, float y1, float x2, float y2) const
  64726. {
  64727. context->drawLine (x1, y1, x2, y2);
  64728. }
  64729. void Graphics::drawLine (const float startX, const float startY,
  64730. const float endX, const float endY,
  64731. const float lineThickness) const
  64732. {
  64733. Path p;
  64734. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  64735. fillPath (p);
  64736. }
  64737. void Graphics::drawLine (const Line& line) const
  64738. {
  64739. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  64740. }
  64741. void Graphics::drawLine (const Line& line, const float lineThickness) const
  64742. {
  64743. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  64744. }
  64745. void Graphics::drawDashedLine (const float startX, const float startY,
  64746. const float endX, const float endY,
  64747. const float* const dashLengths,
  64748. const int numDashLengths,
  64749. const float lineThickness) const
  64750. {
  64751. const double dx = endX - startX;
  64752. const double dy = endY - startY;
  64753. const double totalLen = juce_hypot (dx, dy);
  64754. if (totalLen >= 0.5)
  64755. {
  64756. const double onePixAlpha = 1.0 / totalLen;
  64757. double alpha = 0.0;
  64758. float x = startX;
  64759. float y = startY;
  64760. int n = 0;
  64761. while (alpha < 1.0f)
  64762. {
  64763. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  64764. n = n % numDashLengths;
  64765. const float oldX = x;
  64766. const float oldY = y;
  64767. x = (float) (startX + dx * alpha);
  64768. y = (float) (startY + dy * alpha);
  64769. if ((n & 1) != 0)
  64770. {
  64771. if (lineThickness != 1.0f)
  64772. drawLine (oldX, oldY, x, y, lineThickness);
  64773. else
  64774. drawLine (oldX, oldY, x, y);
  64775. }
  64776. }
  64777. }
  64778. }
  64779. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality)
  64780. {
  64781. saveStateIfPending();
  64782. context->setInterpolationQuality (newQuality);
  64783. }
  64784. void Graphics::drawImageAt (const Image* const imageToDraw,
  64785. const int topLeftX, const int topLeftY,
  64786. const bool fillAlphaChannelWithCurrentBrush) const
  64787. {
  64788. if (imageToDraw != 0)
  64789. {
  64790. const int imageW = imageToDraw->getWidth();
  64791. const int imageH = imageToDraw->getHeight();
  64792. drawImage (imageToDraw,
  64793. topLeftX, topLeftY, imageW, imageH,
  64794. 0, 0, imageW, imageH,
  64795. fillAlphaChannelWithCurrentBrush);
  64796. }
  64797. }
  64798. void Graphics::drawImageWithin (const Image* const imageToDraw,
  64799. const int destX, const int destY,
  64800. const int destW, const int destH,
  64801. const RectanglePlacement& placementWithinTarget,
  64802. const bool fillAlphaChannelWithCurrentBrush) const
  64803. {
  64804. // passing in a silly number can cause maths problems in rendering!
  64805. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  64806. if (imageToDraw != 0)
  64807. {
  64808. const int imageW = imageToDraw->getWidth();
  64809. const int imageH = imageToDraw->getHeight();
  64810. if (imageW > 0 && imageH > 0)
  64811. {
  64812. double newX = 0.0, newY = 0.0;
  64813. double newW = imageW;
  64814. double newH = imageH;
  64815. placementWithinTarget.applyTo (newX, newY, newW, newH,
  64816. destX, destY, destW, destH);
  64817. if (newW > 0 && newH > 0)
  64818. {
  64819. drawImage (imageToDraw,
  64820. roundToInt (newX), roundToInt (newY),
  64821. roundToInt (newW), roundToInt (newH),
  64822. 0, 0, imageW, imageH,
  64823. fillAlphaChannelWithCurrentBrush);
  64824. }
  64825. }
  64826. }
  64827. }
  64828. void Graphics::drawImage (const Image* const imageToDraw,
  64829. int dx, int dy, int dw, int dh,
  64830. int sx, int sy, int sw, int sh,
  64831. const bool fillAlphaChannelWithCurrentBrush) const
  64832. {
  64833. // passing in a silly number can cause maths problems in rendering!
  64834. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  64835. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  64836. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  64837. {
  64838. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  64839. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  64840. .translated ((float) dx, (float) dy),
  64841. fillAlphaChannelWithCurrentBrush);
  64842. }
  64843. }
  64844. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  64845. const Rectangle<int>& imageSubRegion,
  64846. const AffineTransform& transform,
  64847. const bool fillAlphaChannelWithCurrentBrush) const
  64848. {
  64849. if (imageToDraw != 0 && ! context->isClipEmpty())
  64850. {
  64851. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  64852. if (fillAlphaChannelWithCurrentBrush)
  64853. {
  64854. context->saveState();
  64855. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  64856. fillAll();
  64857. context->restoreState();
  64858. }
  64859. else
  64860. {
  64861. context->drawImage (*imageToDraw, srcClip, transform, false);
  64862. }
  64863. }
  64864. }
  64865. END_JUCE_NAMESPACE
  64866. /*** End of inlined file: juce_Graphics.cpp ***/
  64867. /*** Start of inlined file: juce_Justification.cpp ***/
  64868. BEGIN_JUCE_NAMESPACE
  64869. Justification::Justification (const Justification& other) throw()
  64870. : flags (other.flags)
  64871. {
  64872. }
  64873. Justification& Justification::operator= (const Justification& other) throw()
  64874. {
  64875. flags = other.flags;
  64876. return *this;
  64877. }
  64878. int Justification::getOnlyVerticalFlags() const throw()
  64879. {
  64880. return flags & (top | bottom | verticallyCentred);
  64881. }
  64882. int Justification::getOnlyHorizontalFlags() const throw()
  64883. {
  64884. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  64885. }
  64886. void Justification::applyToRectangle (int& x, int& y,
  64887. const int w, const int h,
  64888. const int spaceX, const int spaceY,
  64889. const int spaceW, const int spaceH) const throw()
  64890. {
  64891. if ((flags & horizontallyCentred) != 0)
  64892. {
  64893. x = spaceX + ((spaceW - w) >> 1);
  64894. }
  64895. else if ((flags & right) != 0)
  64896. {
  64897. x = spaceX + spaceW - w;
  64898. }
  64899. else
  64900. {
  64901. x = spaceX;
  64902. }
  64903. if ((flags & verticallyCentred) != 0)
  64904. {
  64905. y = spaceY + ((spaceH - h) >> 1);
  64906. }
  64907. else if ((flags & bottom) != 0)
  64908. {
  64909. y = spaceY + spaceH - h;
  64910. }
  64911. else
  64912. {
  64913. y = spaceY;
  64914. }
  64915. }
  64916. END_JUCE_NAMESPACE
  64917. /*** End of inlined file: juce_Justification.cpp ***/
  64918. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  64919. BEGIN_JUCE_NAMESPACE
  64920. // this will throw an assertion if you try to draw something that's not
  64921. // possible in postscript
  64922. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  64923. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  64924. #define notPossibleInPostscriptAssert jassertfalse
  64925. #else
  64926. #define notPossibleInPostscriptAssert
  64927. #endif
  64928. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  64929. const String& documentTitle,
  64930. const int totalWidth_,
  64931. const int totalHeight_)
  64932. : out (resultingPostScript),
  64933. totalWidth (totalWidth_),
  64934. totalHeight (totalHeight_),
  64935. needToClip (true)
  64936. {
  64937. stateStack.add (new SavedState());
  64938. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  64939. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  64940. out << "%!PS-Adobe-3.0 EPSF-3.0"
  64941. "\n%%BoundingBox: 0 0 600 824"
  64942. "\n%%Pages: 0"
  64943. "\n%%Creator: Raw Material Software JUCE"
  64944. "\n%%Title: " << documentTitle <<
  64945. "\n%%CreationDate: none"
  64946. "\n%%LanguageLevel: 2"
  64947. "\n%%EndComments"
  64948. "\n%%BeginProlog"
  64949. "\n%%BeginResource: JRes"
  64950. "\n/bd {bind def} bind def"
  64951. "\n/c {setrgbcolor} bd"
  64952. "\n/m {moveto} bd"
  64953. "\n/l {lineto} bd"
  64954. "\n/rl {rlineto} bd"
  64955. "\n/ct {curveto} bd"
  64956. "\n/cp {closepath} bd"
  64957. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  64958. "\n/doclip {initclip newpath} bd"
  64959. "\n/endclip {clip newpath} bd"
  64960. "\n%%EndResource"
  64961. "\n%%EndProlog"
  64962. "\n%%BeginSetup"
  64963. "\n%%EndSetup"
  64964. "\n%%Page: 1 1"
  64965. "\n%%BeginPageSetup"
  64966. "\n%%EndPageSetup\n\n"
  64967. << "40 800 translate\n"
  64968. << scale << ' ' << scale << " scale\n\n";
  64969. }
  64970. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  64971. {
  64972. }
  64973. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  64974. {
  64975. return true;
  64976. }
  64977. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  64978. {
  64979. if (x != 0 || y != 0)
  64980. {
  64981. stateStack.getLast()->xOffset += x;
  64982. stateStack.getLast()->yOffset += y;
  64983. needToClip = true;
  64984. }
  64985. }
  64986. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  64987. {
  64988. needToClip = true;
  64989. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  64990. }
  64991. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  64992. {
  64993. needToClip = true;
  64994. return stateStack.getLast()->clip.clipTo (clipRegion);
  64995. }
  64996. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  64997. {
  64998. needToClip = true;
  64999. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65000. }
  65001. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65002. {
  65003. writeClip();
  65004. Path p (path);
  65005. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65006. writePath (p);
  65007. out << "clip\n";
  65008. }
  65009. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65010. {
  65011. needToClip = true;
  65012. jassertfalse // xxx
  65013. }
  65014. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65015. {
  65016. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65017. }
  65018. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65019. {
  65020. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65021. -stateStack.getLast()->yOffset);
  65022. }
  65023. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65024. {
  65025. return stateStack.getLast()->clip.isEmpty();
  65026. }
  65027. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65028. : xOffset (0),
  65029. yOffset (0)
  65030. {
  65031. }
  65032. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65033. {
  65034. }
  65035. void LowLevelGraphicsPostScriptRenderer::saveState()
  65036. {
  65037. stateStack.add (new SavedState (*stateStack.getLast()));
  65038. }
  65039. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65040. {
  65041. jassert (stateStack.size() > 0);
  65042. if (stateStack.size() > 0)
  65043. stateStack.removeLast();
  65044. }
  65045. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65046. {
  65047. if (needToClip)
  65048. {
  65049. needToClip = false;
  65050. out << "doclip ";
  65051. int itemsOnLine = 0;
  65052. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65053. {
  65054. if (++itemsOnLine == 6)
  65055. {
  65056. itemsOnLine = 0;
  65057. out << '\n';
  65058. }
  65059. const Rectangle<int>& r = *i.getRectangle();
  65060. out << r.getX() << ' ' << -r.getY() << ' '
  65061. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65062. }
  65063. out << "endclip\n";
  65064. }
  65065. }
  65066. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65067. {
  65068. Colour c (Colours::white.overlaidWith (colour));
  65069. if (lastColour != c)
  65070. {
  65071. lastColour = c;
  65072. out << String (c.getFloatRed(), 3) << ' '
  65073. << String (c.getFloatGreen(), 3) << ' '
  65074. << String (c.getFloatBlue(), 3) << " c\n";
  65075. }
  65076. }
  65077. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65078. {
  65079. out << String (x, 2) << ' '
  65080. << String (-y, 2) << ' ';
  65081. }
  65082. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65083. {
  65084. out << "newpath ";
  65085. float lastX = 0.0f;
  65086. float lastY = 0.0f;
  65087. int itemsOnLine = 0;
  65088. Path::Iterator i (path);
  65089. while (i.next())
  65090. {
  65091. if (++itemsOnLine == 4)
  65092. {
  65093. itemsOnLine = 0;
  65094. out << '\n';
  65095. }
  65096. switch (i.elementType)
  65097. {
  65098. case Path::Iterator::startNewSubPath:
  65099. writeXY (i.x1, i.y1);
  65100. lastX = i.x1;
  65101. lastY = i.y1;
  65102. out << "m ";
  65103. break;
  65104. case Path::Iterator::lineTo:
  65105. writeXY (i.x1, i.y1);
  65106. lastX = i.x1;
  65107. lastY = i.y1;
  65108. out << "l ";
  65109. break;
  65110. case Path::Iterator::quadraticTo:
  65111. {
  65112. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65113. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65114. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65115. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65116. writeXY (cp1x, cp1y);
  65117. writeXY (cp2x, cp2y);
  65118. writeXY (i.x2, i.y2);
  65119. out << "ct ";
  65120. lastX = i.x2;
  65121. lastY = i.y2;
  65122. }
  65123. break;
  65124. case Path::Iterator::cubicTo:
  65125. writeXY (i.x1, i.y1);
  65126. writeXY (i.x2, i.y2);
  65127. writeXY (i.x3, i.y3);
  65128. out << "ct ";
  65129. lastX = i.x3;
  65130. lastY = i.y3;
  65131. break;
  65132. case Path::Iterator::closePath:
  65133. out << "cp ";
  65134. break;
  65135. default:
  65136. jassertfalse
  65137. break;
  65138. }
  65139. }
  65140. out << '\n';
  65141. }
  65142. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65143. {
  65144. out << "[ "
  65145. << trans.mat00 << ' '
  65146. << trans.mat10 << ' '
  65147. << trans.mat01 << ' '
  65148. << trans.mat11 << ' '
  65149. << trans.mat02 << ' '
  65150. << trans.mat12 << " ] concat ";
  65151. }
  65152. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65153. {
  65154. stateStack.getLast()->fillType = fillType;
  65155. }
  65156. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65157. {
  65158. }
  65159. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65160. {
  65161. }
  65162. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65163. {
  65164. if (stateStack.getLast()->fillType.isColour())
  65165. {
  65166. writeClip();
  65167. writeColour (stateStack.getLast()->fillType.colour);
  65168. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65169. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65170. }
  65171. else
  65172. {
  65173. Path p;
  65174. p.addRectangle (r);
  65175. fillPath (p, AffineTransform::identity);
  65176. }
  65177. }
  65178. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65179. {
  65180. if (stateStack.getLast()->fillType.isColour())
  65181. {
  65182. writeClip();
  65183. Path p (path);
  65184. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65185. (float) stateStack.getLast()->yOffset));
  65186. writePath (p);
  65187. writeColour (stateStack.getLast()->fillType.colour);
  65188. out << "fill\n";
  65189. }
  65190. else if (stateStack.getLast()->fillType.isGradient())
  65191. {
  65192. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65193. // postscript can't do semi-transparent ones.
  65194. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65195. writeClip();
  65196. out << "gsave ";
  65197. {
  65198. Path p (path);
  65199. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65200. writePath (p);
  65201. out << "clip\n";
  65202. }
  65203. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65204. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65205. // time-being, this just fills it with the average colour..
  65206. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65207. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65208. out << "grestore\n";
  65209. }
  65210. }
  65211. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65212. const int sx, const int sy,
  65213. const int maxW, const int maxH) const
  65214. {
  65215. out << "{<\n";
  65216. const int w = jmin (maxW, im.getWidth());
  65217. const int h = jmin (maxH, im.getHeight());
  65218. int charsOnLine = 0;
  65219. const Image::BitmapData srcData (im, 0, 0, w, h);
  65220. Colour pixel;
  65221. for (int y = h; --y >= 0;)
  65222. {
  65223. for (int x = 0; x < w; ++x)
  65224. {
  65225. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65226. if (x >= sx && y >= sy)
  65227. {
  65228. if (im.isARGB())
  65229. {
  65230. PixelARGB p (*(const PixelARGB*) pixelData);
  65231. p.unpremultiply();
  65232. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65233. }
  65234. else if (im.isRGB())
  65235. {
  65236. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65237. }
  65238. else
  65239. {
  65240. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65241. }
  65242. }
  65243. else
  65244. {
  65245. pixel = Colours::transparentWhite;
  65246. }
  65247. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65248. out << String::toHexString (pixelValues, 3, 0);
  65249. charsOnLine += 3;
  65250. if (charsOnLine > 100)
  65251. {
  65252. out << '\n';
  65253. charsOnLine = 0;
  65254. }
  65255. }
  65256. }
  65257. out << "\n>}\n";
  65258. }
  65259. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65260. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65261. {
  65262. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65263. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65264. writeClip();
  65265. out << "gsave ";
  65266. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65267. .scaled (1.0f, -1.0f));
  65268. RectangleList imageClip;
  65269. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65270. imageClip.clipTo (srcClip);
  65271. out << "newpath ";
  65272. int itemsOnLine = 0;
  65273. for (RectangleList::Iterator i (imageClip); i.next();)
  65274. {
  65275. if (++itemsOnLine == 6)
  65276. {
  65277. out << '\n';
  65278. itemsOnLine = 0;
  65279. }
  65280. const Rectangle<int>& r = *i.getRectangle();
  65281. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65282. }
  65283. out << " clip newpath\n";
  65284. out << w << ' ' << h << " scale\n";
  65285. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65286. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65287. out << "false 3 colorimage grestore\n";
  65288. needToClip = true;
  65289. }
  65290. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65291. {
  65292. Path p;
  65293. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65294. fillPath (p, AffineTransform::identity);
  65295. }
  65296. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65297. {
  65298. drawLine (x, top, x, bottom);
  65299. }
  65300. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65301. {
  65302. drawLine (left, y, right, y);
  65303. }
  65304. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65305. {
  65306. stateStack.getLast()->font = newFont;
  65307. }
  65308. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65309. {
  65310. return stateStack.getLast()->font;
  65311. }
  65312. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65313. {
  65314. Path p;
  65315. Font& font = stateStack.getLast()->font;
  65316. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65317. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65318. }
  65319. END_JUCE_NAMESPACE
  65320. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65321. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65322. BEGIN_JUCE_NAMESPACE
  65323. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65324. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65325. #endif
  65326. #if JUCE_MSVC
  65327. #if JUCE_DEBUG
  65328. #pragma optimize ("t", on) // optimise just this file, to avoid sluggish graphics when debugging
  65329. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65330. #endif
  65331. #pragma warning (push)
  65332. #pragma warning (disable: 4127) // "expression is constant" warning
  65333. #endif
  65334. template <class PixelType, bool replaceExisting = false>
  65335. class SolidColourEdgeTableRenderer
  65336. {
  65337. public:
  65338. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65339. : data (data_),
  65340. sourceColour (colour)
  65341. {
  65342. if (sizeof (PixelType) == 3)
  65343. {
  65344. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65345. && sourceColour.getGreen() == sourceColour.getBlue();
  65346. filler[0].set (sourceColour);
  65347. filler[1].set (sourceColour);
  65348. filler[2].set (sourceColour);
  65349. filler[3].set (sourceColour);
  65350. }
  65351. }
  65352. forcedinline void setEdgeTableYPos (const int y) throw()
  65353. {
  65354. linePixels = (PixelType*) data.getLinePointer (y);
  65355. }
  65356. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65357. {
  65358. if (replaceExisting)
  65359. linePixels[x].set (sourceColour);
  65360. else
  65361. linePixels[x].blend (sourceColour, alphaLevel);
  65362. }
  65363. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65364. {
  65365. PixelARGB p (sourceColour);
  65366. p.multiplyAlpha (alphaLevel);
  65367. PixelType* dest = linePixels + x;
  65368. if (replaceExisting || p.getAlpha() >= 0xff)
  65369. replaceLine (dest, p, width);
  65370. else
  65371. blendLine (dest, p, width);
  65372. }
  65373. private:
  65374. const Image::BitmapData& data;
  65375. PixelType* linePixels;
  65376. PixelARGB sourceColour;
  65377. PixelRGB filler [4];
  65378. bool areRGBComponentsEqual;
  65379. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const throw()
  65380. {
  65381. do
  65382. {
  65383. dest->blend (colour);
  65384. ++dest;
  65385. } while (--width > 0);
  65386. }
  65387. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65388. {
  65389. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65390. {
  65391. memset (dest, colour.getRed(), width * 3);
  65392. }
  65393. else
  65394. {
  65395. if (width >> 5)
  65396. {
  65397. const int* const intFiller = (const int*) filler;
  65398. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65399. {
  65400. dest->set (colour);
  65401. ++dest;
  65402. --width;
  65403. }
  65404. while (width > 4)
  65405. {
  65406. ((int*) dest) [0] = intFiller[0];
  65407. ((int*) dest) [1] = intFiller[1];
  65408. ((int*) dest) [2] = intFiller[2];
  65409. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65410. width -= 4;
  65411. }
  65412. }
  65413. while (--width >= 0)
  65414. {
  65415. dest->set (colour);
  65416. ++dest;
  65417. }
  65418. }
  65419. }
  65420. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65421. {
  65422. memset (dest, colour.getAlpha(), width);
  65423. }
  65424. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65425. {
  65426. do
  65427. {
  65428. dest->set (colour);
  65429. ++dest;
  65430. } while (--width > 0);
  65431. }
  65432. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65433. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65434. };
  65435. class LinearGradientPixelGenerator
  65436. {
  65437. public:
  65438. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65439. : lookupTable (lookupTable_), numEntries (numEntries_)
  65440. {
  65441. jassert (numEntries_ >= 0);
  65442. float x1 = gradient.x1;
  65443. float y1 = gradient.y1;
  65444. float x2 = gradient.x2;
  65445. float y2 = gradient.y2;
  65446. if (! transform.isIdentity())
  65447. {
  65448. const Line l (x2, y2, x1, y1);
  65449. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65450. float x3 = p3.getX();
  65451. float y3 = p3.getY();
  65452. transform.transformPoint (x1, y1);
  65453. transform.transformPoint (x2, y2);
  65454. transform.transformPoint (x3, y3);
  65455. const Line l2 (x2, y2, x3, y3);
  65456. const float prop = l2.findNearestPointTo (x1, y1);
  65457. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65458. x2 = newP2.getX();
  65459. y2 = newP2.getY();
  65460. }
  65461. vertical = fabs (x1 - x2) < 0.001f;
  65462. horizontal = fabs (y1 - y2) < 0.001f;
  65463. if (vertical)
  65464. {
  65465. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65466. start = roundToInt (y1 * scale);
  65467. }
  65468. else if (horizontal)
  65469. {
  65470. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65471. start = roundToInt (x1 * scale);
  65472. }
  65473. else
  65474. {
  65475. grad = (y2 - y1) / (double) (x1 - x2);
  65476. yTerm = y1 - x1 / grad;
  65477. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65478. grad *= scale;
  65479. }
  65480. }
  65481. forcedinline void setY (const int y) throw()
  65482. {
  65483. if (vertical)
  65484. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65485. else if (! horizontal)
  65486. start = roundToInt ((y - yTerm) * grad);
  65487. }
  65488. inline const PixelARGB getPixel (const int x) const throw()
  65489. {
  65490. return vertical ? linePix
  65491. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65492. }
  65493. private:
  65494. const PixelARGB* const lookupTable;
  65495. const int numEntries;
  65496. PixelARGB linePix;
  65497. int start, scale;
  65498. double grad, yTerm;
  65499. bool vertical, horizontal;
  65500. enum { numScaleBits = 12 };
  65501. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65502. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  65503. };
  65504. class RadialGradientPixelGenerator
  65505. {
  65506. public:
  65507. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  65508. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65509. : lookupTable (lookupTable_),
  65510. numEntries (numEntries_),
  65511. gx1 (gradient.x1),
  65512. gy1 (gradient.y1)
  65513. {
  65514. jassert (numEntries_ >= 0);
  65515. const float gdx = gradient.x1 - gradient.x2;
  65516. const float gdy = gradient.y1 - gradient.y2;
  65517. maxDist = gdx * gdx + gdy * gdy;
  65518. invScale = numEntries / sqrt (maxDist);
  65519. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  65520. }
  65521. forcedinline void setY (const int y) throw()
  65522. {
  65523. dy = y - gy1;
  65524. dy *= dy;
  65525. }
  65526. inline const PixelARGB getPixel (const int px) const throw()
  65527. {
  65528. double x = px - gx1;
  65529. x *= x;
  65530. x += dy;
  65531. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  65532. }
  65533. protected:
  65534. const PixelARGB* const lookupTable;
  65535. const int numEntries;
  65536. const double gx1, gy1;
  65537. double maxDist, invScale, dy;
  65538. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  65539. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  65540. };
  65541. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  65542. {
  65543. public:
  65544. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  65545. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65546. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  65547. inverseTransform (transform.inverted())
  65548. {
  65549. tM10 = inverseTransform.mat10;
  65550. tM00 = inverseTransform.mat00;
  65551. }
  65552. forcedinline void setY (const int y) throw()
  65553. {
  65554. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  65555. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  65556. }
  65557. inline const PixelARGB getPixel (const int px) const throw()
  65558. {
  65559. double x = px;
  65560. const double y = tM10 * x + lineYM11;
  65561. x = tM00 * x + lineYM01;
  65562. x *= x;
  65563. x += y * y;
  65564. if (x >= maxDist)
  65565. return lookupTable [numEntries];
  65566. else
  65567. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  65568. }
  65569. private:
  65570. double tM10, tM00, lineYM01, lineYM11;
  65571. const AffineTransform inverseTransform;
  65572. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  65573. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  65574. };
  65575. template <class PixelType, class GradientType>
  65576. class GradientEdgeTableRenderer : public GradientType
  65577. {
  65578. public:
  65579. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  65580. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  65581. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  65582. destData (destData_)
  65583. {
  65584. }
  65585. forcedinline void setEdgeTableYPos (const int y) throw()
  65586. {
  65587. linePixels = (PixelType*) destData.getLinePointer (y);
  65588. GradientType::setY (y);
  65589. }
  65590. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65591. {
  65592. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  65593. }
  65594. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  65595. {
  65596. PixelType* dest = linePixels + x;
  65597. if (alphaLevel < 0xff)
  65598. {
  65599. do
  65600. {
  65601. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  65602. } while (--width > 0);
  65603. }
  65604. else
  65605. {
  65606. do
  65607. {
  65608. (dest++)->blend (GradientType::getPixel (x++));
  65609. } while (--width > 0);
  65610. }
  65611. }
  65612. private:
  65613. const Image::BitmapData& destData;
  65614. PixelType* linePixels;
  65615. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  65616. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  65617. };
  65618. static forcedinline int safeModulo (int n, const int divisor) throw()
  65619. {
  65620. jassert (divisor > 0);
  65621. n %= divisor;
  65622. return (n < 0) ? (n + divisor) : n;
  65623. }
  65624. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65625. class ImageFillEdgeTableRenderer
  65626. {
  65627. public:
  65628. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65629. const Image::BitmapData& srcData_,
  65630. const int extraAlpha_,
  65631. const int x, const int y) throw()
  65632. : destData (destData_),
  65633. srcData (srcData_),
  65634. extraAlpha (extraAlpha_ + 1),
  65635. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  65636. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  65637. {
  65638. }
  65639. forcedinline void setEdgeTableYPos (int y) throw()
  65640. {
  65641. linePixels = (DestPixelType*) destData.getLinePointer (y);
  65642. y -= yOffset;
  65643. if (repeatPattern)
  65644. {
  65645. jassert (y >= 0);
  65646. y %= srcData.height;
  65647. }
  65648. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  65649. }
  65650. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  65651. {
  65652. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65653. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  65654. }
  65655. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  65656. {
  65657. DestPixelType* dest = linePixels + x;
  65658. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  65659. x -= xOffset;
  65660. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  65661. if (alphaLevel < 0xfe)
  65662. {
  65663. do
  65664. {
  65665. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  65666. } while (--width > 0);
  65667. }
  65668. else
  65669. {
  65670. if (repeatPattern)
  65671. {
  65672. do
  65673. {
  65674. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  65675. } while (--width > 0);
  65676. }
  65677. else
  65678. {
  65679. copyRow (dest, sourceLineStart + x, width);
  65680. }
  65681. }
  65682. }
  65683. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  65684. {
  65685. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  65686. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  65687. uint8* mask = (uint8*) (s + x - xOffset);
  65688. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  65689. mask += PixelARGB::indexA;
  65690. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  65691. }
  65692. private:
  65693. const Image::BitmapData& destData;
  65694. const Image::BitmapData& srcData;
  65695. const int extraAlpha, xOffset, yOffset;
  65696. DestPixelType* linePixels;
  65697. SrcPixelType* sourceLineStart;
  65698. template <class PixelType1, class PixelType2>
  65699. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  65700. {
  65701. do
  65702. {
  65703. dest++ ->blend (*src++);
  65704. } while (--width > 0);
  65705. }
  65706. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  65707. {
  65708. memcpy (dest, src, width * sizeof (PixelRGB));
  65709. }
  65710. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  65711. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  65712. };
  65713. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  65714. class TransformedImageFillEdgeTableRenderer
  65715. {
  65716. public:
  65717. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  65718. const Image::BitmapData& srcData_,
  65719. const AffineTransform& transform,
  65720. const int extraAlpha_,
  65721. const bool betterQuality_) throw()
  65722. : interpolator (transform),
  65723. destData (destData_),
  65724. srcData (srcData_),
  65725. extraAlpha (extraAlpha_ + 1),
  65726. betterQuality (betterQuality_),
  65727. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  65728. pixelOffsetInt (betterQuality_ ? -128 : 0),
  65729. maxX (srcData_.width - 1),
  65730. maxY (srcData_.height - 1),
  65731. scratchSize (2048)
  65732. {
  65733. scratchBuffer.malloc (scratchSize);
  65734. }
  65735. ~TransformedImageFillEdgeTableRenderer() throw()
  65736. {
  65737. }
  65738. forcedinline void setEdgeTableYPos (const int newY) throw()
  65739. {
  65740. y = newY;
  65741. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  65742. }
  65743. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  65744. {
  65745. alphaLevel *= extraAlpha;
  65746. alphaLevel >>= 8;
  65747. SrcPixelType p;
  65748. generate (&p, x, 1);
  65749. linePixels[x].blend (p, alphaLevel);
  65750. }
  65751. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  65752. {
  65753. if (width > scratchSize)
  65754. {
  65755. scratchSize = width;
  65756. scratchBuffer.malloc (scratchSize);
  65757. }
  65758. SrcPixelType* span = scratchBuffer;
  65759. generate (span, x, width);
  65760. DestPixelType* dest = linePixels + x;
  65761. alphaLevel *= extraAlpha;
  65762. alphaLevel >>= 8;
  65763. if (alphaLevel < 0xfe)
  65764. {
  65765. do
  65766. {
  65767. dest++ ->blend (*span++, alphaLevel);
  65768. } while (--width > 0);
  65769. }
  65770. else
  65771. {
  65772. do
  65773. {
  65774. dest++ ->blend (*span++);
  65775. } while (--width > 0);
  65776. }
  65777. }
  65778. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  65779. {
  65780. if (width > scratchSize)
  65781. {
  65782. scratchSize = width;
  65783. scratchBuffer.malloc (scratchSize);
  65784. }
  65785. y = y_;
  65786. generate (scratchBuffer, x, width);
  65787. et.clipLineToMask (x, y_,
  65788. reinterpret_cast<uint8*> (scratchBuffer.getData()) + SrcPixelType::indexA,
  65789. sizeof (SrcPixelType), width);
  65790. }
  65791. private:
  65792. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  65793. {
  65794. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65795. do
  65796. {
  65797. int hiResX, hiResY;
  65798. this->interpolator.next (hiResX, hiResY);
  65799. hiResX += pixelOffsetInt;
  65800. hiResY += pixelOffsetInt;
  65801. int loResX = hiResX >> 8;
  65802. int loResY = hiResY >> 8;
  65803. if (repeatPattern)
  65804. {
  65805. loResX = safeModulo (loResX, srcData.width);
  65806. loResY = safeModulo (loResY, srcData.height);
  65807. }
  65808. if (betterQuality
  65809. && ((unsigned int) loResX) < (unsigned int) maxX
  65810. && ((unsigned int) loResY) < (unsigned int) maxY)
  65811. {
  65812. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  65813. hiResX &= 255;
  65814. hiResY &= 255;
  65815. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65816. uint32 weight = (256 - hiResX) * (256 - hiResY);
  65817. c[0] += weight * src[0];
  65818. c[1] += weight * src[1];
  65819. c[2] += weight * src[2];
  65820. c[3] += weight * src[3];
  65821. weight = hiResX * (256 - hiResY);
  65822. c[0] += weight * src[4];
  65823. c[1] += weight * src[5];
  65824. c[2] += weight * src[6];
  65825. c[3] += weight * src[7];
  65826. src += this->srcData.lineStride;
  65827. weight = (256 - hiResX) * hiResY;
  65828. c[0] += weight * src[0];
  65829. c[1] += weight * src[1];
  65830. c[2] += weight * src[2];
  65831. c[3] += weight * src[3];
  65832. weight = hiResX * hiResY;
  65833. c[0] += weight * src[4];
  65834. c[1] += weight * src[5];
  65835. c[2] += weight * src[6];
  65836. c[3] += weight * src[7];
  65837. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  65838. (uint8) (c[PixelARGB::indexR] >> 16),
  65839. (uint8) (c[PixelARGB::indexG] >> 16),
  65840. (uint8) (c[PixelARGB::indexB] >> 16));
  65841. }
  65842. else
  65843. {
  65844. if (! repeatPattern)
  65845. {
  65846. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65847. if (loResX < 0) loResX = 0;
  65848. if (loResY < 0) loResY = 0;
  65849. if (loResX > maxX) loResX = maxX;
  65850. if (loResY > maxY) loResY = maxY;
  65851. }
  65852. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  65853. }
  65854. ++dest;
  65855. } while (--numPixels > 0);
  65856. }
  65857. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  65858. {
  65859. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65860. do
  65861. {
  65862. int hiResX, hiResY;
  65863. this->interpolator.next (hiResX, hiResY);
  65864. hiResX += pixelOffsetInt;
  65865. hiResY += pixelOffsetInt;
  65866. int loResX = hiResX >> 8;
  65867. int loResY = hiResY >> 8;
  65868. if (repeatPattern)
  65869. {
  65870. loResX = safeModulo (loResX, srcData.width);
  65871. loResY = safeModulo (loResY, srcData.height);
  65872. }
  65873. if (betterQuality
  65874. && ((unsigned int) loResX) < (unsigned int) maxX
  65875. && ((unsigned int) loResY) < (unsigned int) maxY)
  65876. {
  65877. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  65878. hiResX &= 255;
  65879. hiResY &= 255;
  65880. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65881. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  65882. c[0] += weight * src[0];
  65883. c[1] += weight * src[1];
  65884. c[2] += weight * src[2];
  65885. weight = hiResX * (256 - hiResY);
  65886. c[0] += weight * src[3];
  65887. c[1] += weight * src[4];
  65888. c[2] += weight * src[5];
  65889. src += this->srcData.lineStride;
  65890. weight = (256 - hiResX) * hiResY;
  65891. c[0] += weight * src[0];
  65892. c[1] += weight * src[1];
  65893. c[2] += weight * src[2];
  65894. weight = hiResX * hiResY;
  65895. c[0] += weight * src[3];
  65896. c[1] += weight * src[4];
  65897. c[2] += weight * src[5];
  65898. dest->setARGB ((uint8) 255,
  65899. (uint8) (c[PixelRGB::indexR] >> 16),
  65900. (uint8) (c[PixelRGB::indexG] >> 16),
  65901. (uint8) (c[PixelRGB::indexB] >> 16));
  65902. }
  65903. else
  65904. {
  65905. if (! repeatPattern)
  65906. {
  65907. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65908. if (loResX < 0) loResX = 0;
  65909. if (loResY < 0) loResY = 0;
  65910. if (loResX > maxX) loResX = maxX;
  65911. if (loResY > maxY) loResY = maxY;
  65912. }
  65913. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  65914. }
  65915. ++dest;
  65916. } while (--numPixels > 0);
  65917. }
  65918. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  65919. {
  65920. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  65921. do
  65922. {
  65923. int hiResX, hiResY;
  65924. this->interpolator.next (hiResX, hiResY);
  65925. hiResX += pixelOffsetInt;
  65926. hiResY += pixelOffsetInt;
  65927. int loResX = hiResX >> 8;
  65928. int loResY = hiResY >> 8;
  65929. if (repeatPattern)
  65930. {
  65931. loResX = safeModulo (loResX, srcData.width);
  65932. loResY = safeModulo (loResY, srcData.height);
  65933. }
  65934. if (betterQuality
  65935. && ((unsigned int) loResX) < (unsigned int) maxX
  65936. && ((unsigned int) loResY) < (unsigned int) maxY)
  65937. {
  65938. hiResX &= 255;
  65939. hiResY &= 255;
  65940. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  65941. uint32 c = 256 * 128;
  65942. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  65943. c += src[1] * (hiResX * (256 - hiResY));
  65944. src += this->srcData.lineStride;
  65945. c += src[0] * ((256 - hiResX) * hiResY);
  65946. c += src[1] * (hiResX * hiResY);
  65947. *((uint8*) dest) = (uint8) c;
  65948. }
  65949. else
  65950. {
  65951. if (! repeatPattern)
  65952. {
  65953. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  65954. if (loResX < 0) loResX = 0;
  65955. if (loResY < 0) loResY = 0;
  65956. if (loResX > maxX) loResX = maxX;
  65957. if (loResY > maxY) loResY = maxY;
  65958. }
  65959. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  65960. }
  65961. ++dest;
  65962. } while (--numPixels > 0);
  65963. }
  65964. class TransformedImageSpanInterpolator
  65965. {
  65966. public:
  65967. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  65968. : inverseTransform (transform.inverted())
  65969. {}
  65970. void setStartOfLine (float x, float y, const int numPixels) throw()
  65971. {
  65972. float x1 = x, y1 = y;
  65973. inverseTransform.transformPoint (x1, y1);
  65974. x += numPixels;
  65975. inverseTransform.transformPoint (x, y);
  65976. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  65977. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  65978. }
  65979. void next (int& x, int& y) throw()
  65980. {
  65981. x = xBresenham.n;
  65982. xBresenham.stepToNext();
  65983. y = yBresenham.n;
  65984. yBresenham.stepToNext();
  65985. }
  65986. private:
  65987. class BresenhamInterpolator
  65988. {
  65989. public:
  65990. BresenhamInterpolator() throw() {}
  65991. void set (const int n1, const int n2, const int numSteps_) throw()
  65992. {
  65993. numSteps = jmax (1, numSteps_);
  65994. step = (n2 - n1) / numSteps;
  65995. remainder = modulo = (n2 - n1) % numSteps;
  65996. n = n1;
  65997. if (modulo <= 0)
  65998. {
  65999. modulo += numSteps;
  66000. remainder += numSteps;
  66001. --step;
  66002. }
  66003. modulo -= numSteps;
  66004. }
  66005. forcedinline void stepToNext() throw()
  66006. {
  66007. modulo += remainder;
  66008. n += step;
  66009. if (modulo > 0)
  66010. {
  66011. modulo -= numSteps;
  66012. ++n;
  66013. }
  66014. }
  66015. int n;
  66016. private:
  66017. int numSteps, step, modulo, remainder;
  66018. };
  66019. const AffineTransform inverseTransform;
  66020. BresenhamInterpolator xBresenham, yBresenham;
  66021. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66022. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66023. };
  66024. TransformedImageSpanInterpolator interpolator;
  66025. const Image::BitmapData& destData;
  66026. const Image::BitmapData& srcData;
  66027. const int extraAlpha;
  66028. const bool betterQuality;
  66029. const float pixelOffset;
  66030. const int pixelOffsetInt, maxX, maxY;
  66031. int y;
  66032. DestPixelType* linePixels;
  66033. HeapBlock <SrcPixelType> scratchBuffer;
  66034. int scratchSize;
  66035. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66036. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66037. };
  66038. class LLGCSavedState
  66039. {
  66040. public:
  66041. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66042. const Font& font_, const FillType& fillType_,
  66043. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66044. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66045. xOffset (xOffset_), yOffset (yOffset_),
  66046. font (font_), fillType (fillType_),
  66047. interpolationQuality (interpolationQuality_)
  66048. {
  66049. }
  66050. LLGCSavedState (const LLGCSavedState& other) throw()
  66051. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66052. yOffset (other.yOffset), font (other.font),
  66053. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66054. {
  66055. }
  66056. ~LLGCSavedState() throw()
  66057. {
  66058. }
  66059. bool clipToRectangle (const Rectangle<int>& r) throw()
  66060. {
  66061. dupeEdgeTableIfMultiplyReferenced();
  66062. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66063. return ! edgeTable->edgeTable.isEmpty();
  66064. }
  66065. bool clipToRectangleList (const RectangleList& r) throw()
  66066. {
  66067. dupeEdgeTableIfMultiplyReferenced();
  66068. RectangleList offsetList (r);
  66069. offsetList.offsetAll (xOffset, yOffset);
  66070. EdgeTable e2 (offsetList);
  66071. edgeTable->edgeTable.clipToEdgeTable (e2);
  66072. return ! edgeTable->edgeTable.isEmpty();
  66073. }
  66074. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66075. {
  66076. dupeEdgeTableIfMultiplyReferenced();
  66077. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66078. return ! edgeTable->edgeTable.isEmpty();
  66079. }
  66080. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66081. {
  66082. dupeEdgeTableIfMultiplyReferenced();
  66083. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66084. edgeTable->edgeTable.clipToEdgeTable (et);
  66085. }
  66086. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66087. {
  66088. et.clipToEdgeTable (edgeTable->edgeTable);
  66089. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66090. if (fillType.isGradient())
  66091. {
  66092. jassert (! replaceContents); // that option is just for solid colours
  66093. ColourGradient g2 (*(fillType.gradient));
  66094. g2.multiplyOpacity (fillType.getOpacity());
  66095. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66096. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66097. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66098. const bool isIdentity = transform.isOnlyTranslation();
  66099. if (isIdentity)
  66100. {
  66101. // If our translation doesn't involve any distortion, we can speed it up..
  66102. transform.transformPoint (g2.x1, g2.y1);
  66103. transform.transformPoint (g2.x2, g2.y2);
  66104. transform = AffineTransform::identity;
  66105. }
  66106. HeapBlock <PixelARGB> lookupTable;
  66107. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66108. jassert (numLookupEntries > 0);
  66109. switch (image.getFormat())
  66110. {
  66111. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66112. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66113. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66114. }
  66115. }
  66116. else if (fillType.isTiledImage())
  66117. {
  66118. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66119. }
  66120. else
  66121. {
  66122. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66123. switch (image.getFormat())
  66124. {
  66125. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66126. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66127. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66128. }
  66129. }
  66130. }
  66131. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66132. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66133. {
  66134. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66135. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66136. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66137. const int alpha = fillType.colour.getAlpha();
  66138. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66139. if (transform.isOnlyTranslation())
  66140. {
  66141. // If our translation doesn't involve any distortion, just use a simple blit..
  66142. int tx = (int) (transform.getTranslationX() * 256.0f);
  66143. int ty = (int) (transform.getTranslationY() * 256.0f);
  66144. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66145. {
  66146. tx = ((tx + 128) >> 8);
  66147. ty = ((ty + 128) >> 8);
  66148. if (tiledFillClipRegion != 0)
  66149. {
  66150. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66151. }
  66152. else
  66153. {
  66154. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66155. et.clipToEdgeTable (edgeTable->edgeTable);
  66156. if (! et.isEmpty())
  66157. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66158. }
  66159. return;
  66160. }
  66161. }
  66162. if (transform.isSingularity())
  66163. return;
  66164. if (tiledFillClipRegion != 0)
  66165. {
  66166. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66167. }
  66168. else
  66169. {
  66170. Path p;
  66171. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66172. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66173. et.clipToEdgeTable (edgeTable->edgeTable);
  66174. if (! et.isEmpty())
  66175. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66176. }
  66177. }
  66178. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66179. {
  66180. if (! image.hasAlphaChannel())
  66181. {
  66182. Path p;
  66183. p.addRectangle (srcClip);
  66184. clipToPath (p, t);
  66185. return;
  66186. }
  66187. dupeEdgeTableIfMultiplyReferenced();
  66188. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66189. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66190. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66191. EdgeTable& et = edgeTable->edgeTable;
  66192. if (transform.isOnlyTranslation())
  66193. {
  66194. // If our translation doesn't involve any distortion, just use a simple blit..
  66195. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66196. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66197. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66198. {
  66199. const int imageX = ((tx + 128) >> 8);
  66200. const int imageY = ((ty + 128) >> 8);
  66201. if (image.getFormat() == Image::ARGB)
  66202. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66203. else
  66204. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66205. return;
  66206. }
  66207. }
  66208. if (transform.isSingularity())
  66209. {
  66210. et.clipToRectangle (Rectangle<int>());
  66211. return;
  66212. }
  66213. {
  66214. Path p;
  66215. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66216. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66217. et.clipToEdgeTable (et2);
  66218. }
  66219. if (! et.isEmpty())
  66220. {
  66221. if (image.getFormat() == Image::ARGB)
  66222. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66223. else
  66224. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66225. }
  66226. }
  66227. template <class SrcPixelType>
  66228. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66229. {
  66230. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66231. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66232. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66233. et.getMaximumBounds().getWidth());
  66234. }
  66235. template <class SrcPixelType>
  66236. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66237. {
  66238. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66239. et.clipToRectangle (r);
  66240. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66241. for (int y = 0; y < r.getHeight(); ++y)
  66242. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66243. }
  66244. class EdgeTableHolder : public ReferenceCountedObject
  66245. {
  66246. public:
  66247. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66248. EdgeTable edgeTable;
  66249. };
  66250. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66251. int xOffset, yOffset;
  66252. Font font;
  66253. FillType fillType;
  66254. Graphics::ResamplingQuality interpolationQuality;
  66255. private:
  66256. LLGCSavedState& operator= (const LLGCSavedState&);
  66257. void dupeEdgeTableIfMultiplyReferenced() throw()
  66258. {
  66259. if (edgeTable->getReferenceCount() > 1)
  66260. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66261. }
  66262. template <class DestPixelType>
  66263. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66264. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66265. {
  66266. jassert (destData.pixelStride == sizeof (DestPixelType));
  66267. if (g.isRadial)
  66268. {
  66269. if (isIdentity)
  66270. {
  66271. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66272. et.iterate (renderer);
  66273. }
  66274. else
  66275. {
  66276. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66277. et.iterate (renderer);
  66278. }
  66279. }
  66280. else
  66281. {
  66282. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66283. et.iterate (renderer);
  66284. }
  66285. }
  66286. template <class DestPixelType>
  66287. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66288. {
  66289. jassert (destData.pixelStride == sizeof (DestPixelType));
  66290. if (replaceContents)
  66291. {
  66292. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66293. et.iterate (r);
  66294. }
  66295. else
  66296. {
  66297. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66298. et.iterate (r);
  66299. }
  66300. }
  66301. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66302. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66303. {
  66304. switch (destImage.getFormat())
  66305. {
  66306. case Image::ARGB:
  66307. switch (srcImage.getFormat())
  66308. {
  66309. case Image::ARGB:
  66310. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66311. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66312. break;
  66313. case Image::RGB:
  66314. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66315. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66316. break;
  66317. default:
  66318. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66319. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66320. break;
  66321. }
  66322. break;
  66323. case Image::RGB:
  66324. switch (srcImage.getFormat())
  66325. {
  66326. case Image::ARGB:
  66327. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66328. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66329. break;
  66330. case Image::RGB:
  66331. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66332. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66333. break;
  66334. default:
  66335. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66336. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66337. break;
  66338. }
  66339. break;
  66340. default:
  66341. switch (srcImage.getFormat())
  66342. {
  66343. case Image::ARGB:
  66344. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66345. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66346. break;
  66347. case Image::RGB:
  66348. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66349. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66350. break;
  66351. default:
  66352. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66353. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66354. break;
  66355. }
  66356. break;
  66357. }
  66358. }
  66359. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66360. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66361. {
  66362. switch (destImage.getFormat())
  66363. {
  66364. case Image::ARGB:
  66365. switch (srcImage.getFormat())
  66366. {
  66367. case Image::ARGB:
  66368. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66369. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66370. break;
  66371. case Image::RGB:
  66372. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66373. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66374. break;
  66375. default:
  66376. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66377. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66378. break;
  66379. }
  66380. break;
  66381. case Image::RGB:
  66382. switch (srcImage.getFormat())
  66383. {
  66384. case Image::ARGB:
  66385. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66386. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66387. break;
  66388. case Image::RGB:
  66389. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66390. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66391. break;
  66392. default:
  66393. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66394. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66395. break;
  66396. }
  66397. break;
  66398. default:
  66399. switch (srcImage.getFormat())
  66400. {
  66401. case Image::ARGB:
  66402. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66403. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66404. break;
  66405. case Image::RGB:
  66406. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66407. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66408. break;
  66409. default:
  66410. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66411. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66412. break;
  66413. }
  66414. break;
  66415. }
  66416. }
  66417. };
  66418. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66419. : image (image_)
  66420. {
  66421. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66422. FillType(), Graphics::mediumResamplingQuality);
  66423. }
  66424. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66425. {
  66426. }
  66427. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66428. {
  66429. return false;
  66430. }
  66431. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66432. {
  66433. currentState->xOffset += x;
  66434. currentState->yOffset += y;
  66435. }
  66436. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66437. {
  66438. return currentState->clipToRectangle (r);
  66439. }
  66440. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66441. {
  66442. return currentState->clipToRectangleList (clipRegion);
  66443. }
  66444. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66445. {
  66446. currentState->excludeClipRectangle (r);
  66447. }
  66448. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66449. {
  66450. currentState->clipToPath (path, transform);
  66451. }
  66452. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66453. {
  66454. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66455. }
  66456. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66457. {
  66458. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66459. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66460. }
  66461. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66462. {
  66463. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66464. }
  66465. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66466. {
  66467. return currentState->edgeTable->edgeTable.isEmpty();
  66468. }
  66469. void LowLevelGraphicsSoftwareRenderer::saveState()
  66470. {
  66471. stateStack.add (new LLGCSavedState (*currentState));
  66472. }
  66473. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66474. {
  66475. LLGCSavedState* const top = stateStack.getLast();
  66476. if (top != 0)
  66477. {
  66478. currentState = top;
  66479. stateStack.removeLast (1, false);
  66480. }
  66481. else
  66482. {
  66483. jassertfalse // trying to pop with an empty stack!
  66484. }
  66485. }
  66486. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66487. {
  66488. currentState->fillType = fillType;
  66489. }
  66490. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66491. {
  66492. currentState->fillType.setOpacity (newOpacity);
  66493. }
  66494. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66495. {
  66496. currentState->interpolationQuality = quality;
  66497. }
  66498. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66499. {
  66500. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66501. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  66502. if (! clipped.isEmpty())
  66503. {
  66504. EdgeTable et (clipped);
  66505. currentState->fillEdgeTable (image, et, replaceExistingContents);
  66506. }
  66507. }
  66508. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  66509. {
  66510. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  66511. path, transform.translated ((float) currentState->xOffset,
  66512. (float) currentState->yOffset));
  66513. currentState->fillEdgeTable (image, et);
  66514. }
  66515. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  66516. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  66517. {
  66518. jassert (sourceImage.getBounds().contains (srcClip));
  66519. currentState->renderImage (image, sourceImage, srcClip, transform,
  66520. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  66521. }
  66522. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  66523. {
  66524. Path p;
  66525. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  66526. fillPath (p, AffineTransform::identity);
  66527. }
  66528. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  66529. {
  66530. if (bottom > top)
  66531. {
  66532. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  66533. currentState->fillEdgeTable (image, et);
  66534. }
  66535. }
  66536. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  66537. {
  66538. if (right > left)
  66539. {
  66540. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  66541. (float) (right - left), 1.0f);
  66542. currentState->fillEdgeTable (image, et);
  66543. }
  66544. }
  66545. class GlyphCache : private DeletedAtShutdown
  66546. {
  66547. public:
  66548. GlyphCache() throw()
  66549. : accessCounter (0), hits (0), misses (0)
  66550. {
  66551. for (int i = 120; --i >= 0;)
  66552. glyphs.add (new CachedGlyph());
  66553. }
  66554. ~GlyphCache() throw()
  66555. {
  66556. clearSingletonInstance();
  66557. }
  66558. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  66559. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  66560. {
  66561. ++accessCounter;
  66562. int oldestCounter = std::numeric_limits<int>::max();
  66563. CachedGlyph* oldest = 0;
  66564. for (int i = glyphs.size(); --i >= 0;)
  66565. {
  66566. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  66567. if (glyph->glyph == glyphNumber && glyph->font == font)
  66568. {
  66569. ++hits;
  66570. glyph->lastAccessCount = accessCounter;
  66571. glyph->draw (state, image, x, y);
  66572. return;
  66573. }
  66574. if (glyph->lastAccessCount <= oldestCounter)
  66575. {
  66576. oldestCounter = glyph->lastAccessCount;
  66577. oldest = glyph;
  66578. }
  66579. }
  66580. if (hits + ++misses > (glyphs.size() << 4))
  66581. {
  66582. if (misses * 2 > hits)
  66583. {
  66584. for (int i = 32; --i >= 0;)
  66585. glyphs.add (new CachedGlyph());
  66586. }
  66587. hits = misses = 0;
  66588. oldest = glyphs.getLast();
  66589. }
  66590. jassert (oldest != 0);
  66591. oldest->lastAccessCount = accessCounter;
  66592. oldest->generate (font, glyphNumber);
  66593. oldest->draw (state, image, x, y);
  66594. }
  66595. class CachedGlyph
  66596. {
  66597. public:
  66598. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  66599. ~CachedGlyph() {}
  66600. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  66601. {
  66602. if (edgeTable != 0)
  66603. {
  66604. EdgeTable et (*edgeTable);
  66605. et.translate (x, roundToInt (y));
  66606. state.fillEdgeTable (image, et, false);
  66607. }
  66608. }
  66609. void generate (const Font& newFont, const int glyphNumber) throw()
  66610. {
  66611. font = newFont;
  66612. glyph = glyphNumber;
  66613. edgeTable = 0;
  66614. Path glyphPath;
  66615. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  66616. if (! glyphPath.isEmpty())
  66617. {
  66618. const float fontHeight = font.getHeight();
  66619. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  66620. .translated (0.0f, -0.5f));
  66621. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  66622. glyphPath, transform);
  66623. }
  66624. }
  66625. int glyph, lastAccessCount;
  66626. Font font;
  66627. juce_UseDebuggingNewOperator
  66628. private:
  66629. ScopedPointer <EdgeTable> edgeTable;
  66630. CachedGlyph (const CachedGlyph&);
  66631. CachedGlyph& operator= (const CachedGlyph&);
  66632. };
  66633. juce_UseDebuggingNewOperator
  66634. private:
  66635. OwnedArray <CachedGlyph> glyphs;
  66636. int accessCounter, hits, misses;
  66637. GlyphCache (const GlyphCache&);
  66638. GlyphCache& operator= (const GlyphCache&);
  66639. };
  66640. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  66641. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  66642. {
  66643. currentState->font = newFont;
  66644. }
  66645. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  66646. {
  66647. return currentState->font;
  66648. }
  66649. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  66650. {
  66651. Font& f = currentState->font;
  66652. if (transform.isOnlyTranslation())
  66653. {
  66654. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  66655. transform.getTranslationX() + (float) currentState->xOffset,
  66656. transform.getTranslationY() + (float) currentState->yOffset);
  66657. }
  66658. else
  66659. {
  66660. Path p;
  66661. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  66662. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  66663. }
  66664. }
  66665. #if JUCE_MSVC
  66666. #pragma warning (pop)
  66667. #if JUCE_DEBUG
  66668. #pragma optimize ("", on) // resets optimisations to the project defaults
  66669. #endif
  66670. #endif
  66671. END_JUCE_NAMESPACE
  66672. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  66673. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  66674. BEGIN_JUCE_NAMESPACE
  66675. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  66676. : flags (other.flags)
  66677. {
  66678. }
  66679. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  66680. {
  66681. flags = other.flags;
  66682. return *this;
  66683. }
  66684. void RectanglePlacement::applyTo (double& x, double& y,
  66685. double& w, double& h,
  66686. const double dx, const double dy,
  66687. const double dw, const double dh) const throw()
  66688. {
  66689. if (w == 0 || h == 0)
  66690. return;
  66691. if ((flags & stretchToFit) != 0)
  66692. {
  66693. x = dx;
  66694. y = dy;
  66695. w = dw;
  66696. h = dh;
  66697. }
  66698. else
  66699. {
  66700. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  66701. : jmin (dw / w, dh / h);
  66702. if ((flags & onlyReduceInSize) != 0)
  66703. scale = jmin (scale, 1.0);
  66704. if ((flags & onlyIncreaseInSize) != 0)
  66705. scale = jmax (scale, 1.0);
  66706. w *= scale;
  66707. h *= scale;
  66708. if ((flags & xLeft) != 0)
  66709. x = dx;
  66710. else if ((flags & xRight) != 0)
  66711. x = dx + dw - w;
  66712. else
  66713. x = dx + (dw - w) * 0.5;
  66714. if ((flags & yTop) != 0)
  66715. y = dy;
  66716. else if ((flags & yBottom) != 0)
  66717. y = dy + dh - h;
  66718. else
  66719. y = dy + (dh - h) * 0.5;
  66720. }
  66721. }
  66722. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  66723. float w, float h,
  66724. const float dx, const float dy,
  66725. const float dw, const float dh) const throw()
  66726. {
  66727. if (w == 0 || h == 0)
  66728. return AffineTransform::identity;
  66729. const float scaleX = dw / w;
  66730. const float scaleY = dh / h;
  66731. if ((flags & stretchToFit) != 0)
  66732. return AffineTransform::translation (-x, -y)
  66733. .scaled (scaleX, scaleY)
  66734. .translated (dx, dy);
  66735. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  66736. : jmin (scaleX, scaleY);
  66737. if ((flags & onlyReduceInSize) != 0)
  66738. scale = jmin (scale, 1.0f);
  66739. if ((flags & onlyIncreaseInSize) != 0)
  66740. scale = jmax (scale, 1.0f);
  66741. w *= scale;
  66742. h *= scale;
  66743. float newX = dx;
  66744. if ((flags & xRight) != 0)
  66745. newX += dw - w; // right
  66746. else if ((flags & xLeft) == 0)
  66747. newX += (dw - w) / 2.0f; // centre
  66748. float newY = dy;
  66749. if ((flags & yBottom) != 0)
  66750. newY += dh - h; // bottom
  66751. else if ((flags & yTop) == 0)
  66752. newY += (dh - h) / 2.0f; // centre
  66753. return AffineTransform::translation (-x, -y)
  66754. .scaled (scale, scale)
  66755. .translated (newX, newY);
  66756. }
  66757. END_JUCE_NAMESPACE
  66758. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  66759. /*** Start of inlined file: juce_Drawable.cpp ***/
  66760. BEGIN_JUCE_NAMESPACE
  66761. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  66762. const AffineTransform& transform_,
  66763. const float opacity_) throw()
  66764. : g (g_),
  66765. transform (transform_),
  66766. opacity (opacity_)
  66767. {
  66768. }
  66769. Drawable::Drawable()
  66770. {
  66771. }
  66772. Drawable::~Drawable()
  66773. {
  66774. }
  66775. void Drawable::draw (Graphics& g, const float opacity,
  66776. const AffineTransform& transform) const
  66777. {
  66778. render (RenderingContext (g, transform, opacity));
  66779. }
  66780. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  66781. {
  66782. draw (g, opacity, AffineTransform::translation (x, y));
  66783. }
  66784. void Drawable::drawWithin (Graphics& g,
  66785. const int destX,
  66786. const int destY,
  66787. const int destW,
  66788. const int destH,
  66789. const RectanglePlacement& placement,
  66790. const float opacity) const
  66791. {
  66792. if (destW > 0 && destH > 0)
  66793. {
  66794. Rectangle<float> bounds (getBounds());
  66795. draw (g, opacity,
  66796. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  66797. (float) destX, (float) destY,
  66798. (float) destW, (float) destH));
  66799. }
  66800. }
  66801. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  66802. {
  66803. Drawable* result = 0;
  66804. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  66805. if (image != 0)
  66806. {
  66807. DrawableImage* const di = new DrawableImage();
  66808. di->setImage (image, true);
  66809. result = di;
  66810. }
  66811. else
  66812. {
  66813. const String asString (String::createStringFromData (data, (int) numBytes));
  66814. XmlDocument doc (asString);
  66815. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  66816. if (outer != 0 && outer->hasTagName ("svg"))
  66817. {
  66818. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  66819. if (svg != 0)
  66820. result = Drawable::createFromSVG (*svg);
  66821. }
  66822. }
  66823. return result;
  66824. }
  66825. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  66826. {
  66827. MemoryBlock mb;
  66828. dataSource.readIntoMemoryBlock (mb);
  66829. return createFromImageData (mb.getData(), mb.getSize());
  66830. }
  66831. Drawable* Drawable::createFromImageFile (const File& file)
  66832. {
  66833. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  66834. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  66835. }
  66836. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  66837. {
  66838. Drawable* d = DrawablePath::createFromValueTree (tree);
  66839. if (d == 0)
  66840. {
  66841. d = DrawableComposite::createFromValueTree (tree);
  66842. if (d == 0)
  66843. {
  66844. d = DrawableImage::createFromValueTree (tree);
  66845. if (d == 0)
  66846. d = DrawableText::createFromValueTree (tree);
  66847. }
  66848. }
  66849. return d;
  66850. }
  66851. END_JUCE_NAMESPACE
  66852. /*** End of inlined file: juce_Drawable.cpp ***/
  66853. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  66854. BEGIN_JUCE_NAMESPACE
  66855. DrawableComposite::DrawableComposite()
  66856. {
  66857. }
  66858. DrawableComposite::~DrawableComposite()
  66859. {
  66860. }
  66861. void DrawableComposite::insertDrawable (Drawable* drawable,
  66862. const AffineTransform& transform,
  66863. const int index)
  66864. {
  66865. if (drawable != 0)
  66866. {
  66867. if (! drawables.contains (drawable))
  66868. {
  66869. drawables.insert (index, drawable);
  66870. if (transform.isIdentity())
  66871. transforms.insert (index, 0);
  66872. else
  66873. transforms.insert (index, new AffineTransform (transform));
  66874. }
  66875. else
  66876. {
  66877. jassertfalse // trying to add a drawable that's already in here!
  66878. }
  66879. }
  66880. }
  66881. void DrawableComposite::insertDrawable (const Drawable& drawable,
  66882. const AffineTransform& transform,
  66883. const int index)
  66884. {
  66885. insertDrawable (drawable.createCopy(), transform, index);
  66886. }
  66887. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  66888. {
  66889. drawables.remove (index, deleteDrawable);
  66890. transforms.remove (index);
  66891. }
  66892. void DrawableComposite::bringToFront (const int index)
  66893. {
  66894. if (index >= 0 && index < drawables.size() - 1)
  66895. {
  66896. drawables.move (index, -1);
  66897. transforms.move (index, -1);
  66898. }
  66899. }
  66900. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  66901. {
  66902. if (drawables.size() > 0 && context.opacity > 0)
  66903. {
  66904. if (context.opacity >= 1.0f || drawables.size() == 1)
  66905. {
  66906. Drawable::RenderingContext contextCopy (context);
  66907. for (int i = 0; i < drawables.size(); ++i)
  66908. {
  66909. const AffineTransform* const t = transforms.getUnchecked(i);
  66910. contextCopy.transform = (t == 0) ? context.transform
  66911. : t->followedBy (context.transform);
  66912. drawables.getUnchecked(i)->render (contextCopy);
  66913. }
  66914. }
  66915. else
  66916. {
  66917. // To correctly render a whole composite layer with an overall transparency,
  66918. // we need to render everything opaquely into a temp buffer, then blend that
  66919. // with the target opacity...
  66920. const Rectangle<int> clipBounds (context.g.getClipBounds());
  66921. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  66922. {
  66923. Graphics tempG (tempImage);
  66924. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  66925. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  66926. render (tempContext);
  66927. }
  66928. context.g.setOpacity (context.opacity);
  66929. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  66930. }
  66931. }
  66932. }
  66933. const Rectangle<float> DrawableComposite::getBounds() const
  66934. {
  66935. Rectangle<float> bounds;
  66936. for (int i = 0; i < drawables.size(); ++i)
  66937. {
  66938. const Drawable* const d = drawables.getUnchecked(i);
  66939. const AffineTransform* const t = transforms.getUnchecked(i);
  66940. const Rectangle<float> childBounds (t == 0 ? d->getBounds()
  66941. : d->getBounds().transformed (*t));
  66942. if (bounds.isEmpty())
  66943. bounds = childBounds;
  66944. else if (! childBounds.isEmpty())
  66945. bounds = bounds.getUnion (childBounds);
  66946. }
  66947. return bounds;
  66948. }
  66949. bool DrawableComposite::hitTest (float x, float y) const
  66950. {
  66951. for (int i = 0; i < drawables.size(); ++i)
  66952. {
  66953. float tx = x;
  66954. float ty = y;
  66955. const AffineTransform* const t = transforms.getUnchecked(i);
  66956. if (t != 0)
  66957. t->inverted().transformPoint (tx, ty);
  66958. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  66959. return true;
  66960. }
  66961. return false;
  66962. }
  66963. Drawable* DrawableComposite::createCopy() const
  66964. {
  66965. DrawableComposite* const dc = new DrawableComposite();
  66966. for (int i = 0; i < drawables.size(); ++i)
  66967. {
  66968. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  66969. const AffineTransform* const t = transforms.getUnchecked(i);
  66970. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  66971. }
  66972. return dc;
  66973. }
  66974. ValueTree DrawableComposite::createValueTree() const throw()
  66975. {
  66976. ValueTree v ("Group");
  66977. if (getName().isNotEmpty())
  66978. v.setProperty ("id", getName(), 0);
  66979. for (int i = 0; i < drawables.size(); ++i)
  66980. {
  66981. Drawable* const d = drawables.getUnchecked(i);
  66982. ValueTree child (d->createValueTree());
  66983. AffineTransform* transform = transforms.getUnchecked(i);
  66984. if (transform != 0)
  66985. {
  66986. String t;
  66987. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  66988. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  66989. child.setProperty ("transform", t, 0);
  66990. }
  66991. v.addChild (child, -1, 0);
  66992. }
  66993. return v;
  66994. }
  66995. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  66996. {
  66997. if (! tree.hasType ("Group"))
  66998. return 0;
  66999. DrawableComposite* dc = new DrawableComposite();
  67000. dc->setName (tree ["id"]);
  67001. for (int i = 0; i < tree.getNumChildren(); ++i)
  67002. {
  67003. ValueTree childTree (tree.getChild (i));
  67004. Drawable* d = Drawable::createFromValueTree (childTree);
  67005. if (d != 0)
  67006. {
  67007. AffineTransform transform;
  67008. const String transformAtt (childTree ["transform"].toString());
  67009. if (transformAtt.isNotEmpty())
  67010. {
  67011. StringArray tokens;
  67012. tokens.addTokens (transformAtt.trim(), false);
  67013. tokens.removeEmptyStrings (true);
  67014. if (tokens.size() == 6)
  67015. {
  67016. float f[6];
  67017. for (int j = 0; j < 6; ++j)
  67018. f[j] = (float) tokens[j].getDoubleValue();
  67019. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67020. }
  67021. }
  67022. dc->insertDrawable (d, transform);
  67023. }
  67024. }
  67025. return dc;
  67026. }
  67027. END_JUCE_NAMESPACE
  67028. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67029. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67030. BEGIN_JUCE_NAMESPACE
  67031. DrawableImage::DrawableImage()
  67032. : image (0),
  67033. canDeleteImage (false),
  67034. opacity (1.0f),
  67035. overlayColour (0x00000000)
  67036. {
  67037. }
  67038. DrawableImage::~DrawableImage()
  67039. {
  67040. clearImage();
  67041. }
  67042. void DrawableImage::clearImage()
  67043. {
  67044. if (canDeleteImage && image != 0)
  67045. ImageCache::releaseOrDelete (image);
  67046. image = 0;
  67047. }
  67048. void DrawableImage::setImage (const Image& imageToCopy)
  67049. {
  67050. clearImage();
  67051. image = new Image (imageToCopy);
  67052. canDeleteImage = true;
  67053. }
  67054. void DrawableImage::setImage (Image* imageToUse,
  67055. const bool releaseWhenNotNeeded)
  67056. {
  67057. clearImage();
  67058. image = imageToUse;
  67059. canDeleteImage = releaseWhenNotNeeded;
  67060. }
  67061. void DrawableImage::setOpacity (const float newOpacity)
  67062. {
  67063. opacity = newOpacity;
  67064. }
  67065. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67066. {
  67067. overlayColour = newOverlayColour;
  67068. }
  67069. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67070. {
  67071. if (image != 0)
  67072. {
  67073. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67074. {
  67075. context.g.setOpacity (context.opacity * opacity);
  67076. context.g.drawImageTransformed (image, image->getBounds(),
  67077. context.transform, false);
  67078. }
  67079. if (! overlayColour.isTransparent())
  67080. {
  67081. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67082. context.g.drawImageTransformed (image, image->getBounds(),
  67083. context.transform, true);
  67084. }
  67085. }
  67086. }
  67087. const Rectangle<float> DrawableImage::getBounds() const
  67088. {
  67089. if (image == 0)
  67090. return Rectangle<float>();
  67091. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67092. }
  67093. bool DrawableImage::hitTest (float x, float y) const
  67094. {
  67095. return image != 0
  67096. && x >= 0.0f
  67097. && y >= 0.0f
  67098. && x < image->getWidth()
  67099. && y < image->getHeight()
  67100. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67101. }
  67102. Drawable* DrawableImage::createCopy() const
  67103. {
  67104. DrawableImage* const di = new DrawableImage();
  67105. di->opacity = opacity;
  67106. di->overlayColour = overlayColour;
  67107. if (image != 0)
  67108. {
  67109. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67110. {
  67111. di->setImage (*image);
  67112. }
  67113. else
  67114. {
  67115. ImageCache::incReferenceCount (image);
  67116. di->setImage (image, true);
  67117. }
  67118. }
  67119. return di;
  67120. }
  67121. ValueTree DrawableImage::createValueTree() const throw()
  67122. {
  67123. ValueTree v ("Image");
  67124. if (getName().isNotEmpty())
  67125. v.setProperty ("id", getName(), 0);
  67126. if (opacity < 1.0f)
  67127. v.setProperty ("opacity", (double) opacity, 0);
  67128. if (! overlayColour.isTransparent())
  67129. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67130. if (image != 0)
  67131. {
  67132. MemoryOutputStream imageData;
  67133. PNGImageFormat pngFormat;
  67134. if (pngFormat.writeImageToStream (*image, imageData))
  67135. {
  67136. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67137. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67138. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67139. v.setProperty ("data", base64, 0);
  67140. }
  67141. }
  67142. return v;
  67143. }
  67144. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67145. {
  67146. if (! tree.hasType ("Image"))
  67147. return 0;
  67148. DrawableImage* di = new DrawableImage();
  67149. di->setName (tree ["id"]);
  67150. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67151. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67152. MemoryBlock imageData;
  67153. if (imageData.fromBase64Encoding (tree ["data"]))
  67154. {
  67155. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67156. if (im == 0)
  67157. return false;
  67158. di->setImage (im, true);
  67159. }
  67160. return di;
  67161. }
  67162. END_JUCE_NAMESPACE
  67163. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67164. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67165. BEGIN_JUCE_NAMESPACE
  67166. DrawablePath::DrawablePath()
  67167. : mainFill (Colours::black),
  67168. strokeFill (Colours::transparentBlack),
  67169. strokeType (0.0f)
  67170. {
  67171. }
  67172. DrawablePath::~DrawablePath()
  67173. {
  67174. }
  67175. void DrawablePath::setPath (const Path& newPath) throw()
  67176. {
  67177. path = newPath;
  67178. updateOutline();
  67179. }
  67180. void DrawablePath::setFill (const FillType& newFill) throw()
  67181. {
  67182. mainFill = newFill;
  67183. }
  67184. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67185. {
  67186. strokeFill = newFill;
  67187. }
  67188. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67189. {
  67190. strokeType = newStrokeType;
  67191. updateOutline();
  67192. }
  67193. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67194. {
  67195. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67196. }
  67197. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67198. {
  67199. {
  67200. FillType f (mainFill);
  67201. if (f.isGradient())
  67202. f.gradient->multiplyOpacity (context.opacity);
  67203. f.transform = f.transform.followedBy (context.transform);
  67204. context.g.setFillType (f);
  67205. context.g.fillPath (path, context.transform);
  67206. }
  67207. if (strokeType.getStrokeThickness() > 0.0f)
  67208. {
  67209. FillType f (strokeFill);
  67210. if (f.isGradient())
  67211. f.gradient->multiplyOpacity (context.opacity);
  67212. f.transform = f.transform.followedBy (context.transform);
  67213. context.g.setFillType (f);
  67214. context.g.fillPath (stroke, context.transform);
  67215. }
  67216. }
  67217. void DrawablePath::updateOutline()
  67218. {
  67219. stroke.clear();
  67220. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67221. }
  67222. const Rectangle<float> DrawablePath::getBounds() const
  67223. {
  67224. if (strokeType.getStrokeThickness() > 0.0f)
  67225. return stroke.getBounds();
  67226. else
  67227. return path.getBounds();
  67228. }
  67229. bool DrawablePath::hitTest (float x, float y) const
  67230. {
  67231. return path.contains (x, y)
  67232. || stroke.contains (x, y);
  67233. }
  67234. Drawable* DrawablePath::createCopy() const
  67235. {
  67236. DrawablePath* const dp = new DrawablePath();
  67237. dp->path = path;
  67238. dp->stroke = stroke;
  67239. dp->mainFill = mainFill;
  67240. dp->strokeFill = strokeFill;
  67241. dp->strokeType = strokeType;
  67242. return dp;
  67243. }
  67244. static const FillType readFillTypeFromTree (const ValueTree& v)
  67245. {
  67246. const String type (v["type"].toString());
  67247. if (type.equalsIgnoreCase ("solid"))
  67248. {
  67249. const String colour (v ["colour"].toString());
  67250. return Colour (colour.isEmpty() ? (uint32) 0xff000000
  67251. : (uint32) colour.getHexValue32());
  67252. }
  67253. else if (type.equalsIgnoreCase ("gradient"))
  67254. {
  67255. ColourGradient g;
  67256. g.x1 = v["x1"];
  67257. g.y1 = v["y1"];
  67258. g.x2 = v["x2"];
  67259. g.y2 = v["y2"];
  67260. g.isRadial = v["radial"];
  67261. StringArray colours;
  67262. colours.addTokens (v["colours"].toString(), false);
  67263. for (int i = 0; i < colours.size() / 2; ++i)
  67264. g.addColour (colours[i * 2].getDoubleValue(),
  67265. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67266. return g;
  67267. }
  67268. jassertfalse
  67269. return FillType();
  67270. }
  67271. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67272. {
  67273. ValueTree v (tagName);
  67274. if (fillType.isColour())
  67275. {
  67276. v.setProperty ("type", "solid", 0);
  67277. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67278. }
  67279. else if (fillType.isGradient())
  67280. {
  67281. v.setProperty ("type", "gradient", 0);
  67282. v.setProperty ("x1", fillType.gradient->x1, 0);
  67283. v.setProperty ("y1", fillType.gradient->y1, 0);
  67284. v.setProperty ("x2", fillType.gradient->x2, 0);
  67285. v.setProperty ("y2", fillType.gradient->y2, 0);
  67286. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67287. String s;
  67288. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67289. s << " " << fillType.gradient->getColourPosition (i)
  67290. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67291. v.setProperty ("colours", s.trimStart(), 0);
  67292. }
  67293. else
  67294. {
  67295. jassertfalse //xxx
  67296. }
  67297. return v;
  67298. }
  67299. ValueTree DrawablePath::createValueTree() const throw()
  67300. {
  67301. ValueTree v ("Path");
  67302. v.addChild (createTreeForFillType ("fill", mainFill), -1, 0);
  67303. v.addChild (createTreeForFillType ("stroke", strokeFill), -1, 0);
  67304. if (getName().isNotEmpty())
  67305. v.setProperty ("id", getName(), 0);
  67306. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67307. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67308. ? "miter" : (strokeType.getJointStyle() == PathStrokeType::curved ? "curved" : "bevel"), 0);
  67309. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67310. ? "butt" : (strokeType.getEndStyle() == PathStrokeType::square ? "square" : "round"), 0);
  67311. v.setProperty ("path", path.toString(), 0);
  67312. return v;
  67313. }
  67314. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67315. {
  67316. if (! tree.hasType ("Path"))
  67317. return 0;
  67318. DrawablePath* p = new DrawablePath();
  67319. p->setName (tree ["id"]);
  67320. p->mainFill = readFillTypeFromTree (tree.getChildWithName ("fill"));
  67321. p->strokeFill = readFillTypeFromTree (tree.getChildWithName ("stroke"));
  67322. const String jointStyle (tree ["jointStyle"].toString());
  67323. const String endStyle (tree ["capStyle"].toString());
  67324. p->strokeType
  67325. = PathStrokeType (tree ["strokeWidth"],
  67326. jointStyle.equalsIgnoreCase ("curved") ? PathStrokeType::curved
  67327. : (jointStyle.equalsIgnoreCase ("bevel") ? PathStrokeType::beveled
  67328. : PathStrokeType::mitered),
  67329. endStyle.equalsIgnoreCase ("square") ? PathStrokeType::square
  67330. : (endStyle.equalsIgnoreCase ("round") ? PathStrokeType::rounded
  67331. : PathStrokeType::butt));
  67332. p->path.clear();
  67333. p->path.restoreFromString (tree ["path"]);
  67334. p->updateOutline();
  67335. return p;
  67336. }
  67337. END_JUCE_NAMESPACE
  67338. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67339. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67340. BEGIN_JUCE_NAMESPACE
  67341. DrawableText::DrawableText()
  67342. : colour (Colours::white)
  67343. {
  67344. }
  67345. DrawableText::~DrawableText()
  67346. {
  67347. }
  67348. void DrawableText::setText (const GlyphArrangement& newText)
  67349. {
  67350. text = newText;
  67351. }
  67352. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67353. {
  67354. text.clear();
  67355. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67356. }
  67357. void DrawableText::setColour (const Colour& newColour)
  67358. {
  67359. colour = newColour;
  67360. }
  67361. void DrawableText::render (const Drawable::RenderingContext& context) const
  67362. {
  67363. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67364. text.draw (context.g, context.transform);
  67365. }
  67366. const Rectangle<float> DrawableText::getBounds() const
  67367. {
  67368. return text.getBoundingBox (0, -1, false);
  67369. }
  67370. bool DrawableText::hitTest (float x, float y) const
  67371. {
  67372. return text.findGlyphIndexAt (x, y) >= 0;
  67373. }
  67374. Drawable* DrawableText::createCopy() const
  67375. {
  67376. DrawableText* const dt = new DrawableText();
  67377. dt->text = text;
  67378. dt->colour = colour;
  67379. return dt;
  67380. }
  67381. ValueTree DrawableText::createValueTree() const throw()
  67382. {
  67383. ValueTree v ("Text");
  67384. if (getName().isNotEmpty())
  67385. v.setProperty ("id", getName(), 0);
  67386. jassertfalse // xxx not finished!
  67387. return v;
  67388. }
  67389. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67390. {
  67391. if (! tree.hasType ("Text"))
  67392. return 0;
  67393. DrawableText* dt = new DrawableText();
  67394. dt->setName (tree ["id"]);
  67395. jassertfalse // xxx not finished!
  67396. return dt;
  67397. }
  67398. END_JUCE_NAMESPACE
  67399. /*** End of inlined file: juce_DrawableText.cpp ***/
  67400. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67401. BEGIN_JUCE_NAMESPACE
  67402. class SVGState
  67403. {
  67404. public:
  67405. SVGState (const XmlElement* const topLevel)
  67406. : topLevelXml (topLevel),
  67407. elementX (0), elementY (0),
  67408. width (512), height (512),
  67409. viewBoxW (0), viewBoxH (0)
  67410. {
  67411. }
  67412. ~SVGState()
  67413. {
  67414. }
  67415. Drawable* parseSVGElement (const XmlElement& xml)
  67416. {
  67417. if (! xml.hasTagName ("svg"))
  67418. return 0;
  67419. DrawableComposite* const drawable = new DrawableComposite();
  67420. drawable->setName (xml.getStringAttribute ("id"));
  67421. SVGState newState (*this);
  67422. if (xml.hasAttribute ("transform"))
  67423. newState.addTransform (xml);
  67424. newState.elementX = getCoordLength (xml.getStringAttribute ("x", String (newState.elementX)), viewBoxW);
  67425. newState.elementY = getCoordLength (xml.getStringAttribute ("y", String (newState.elementY)), viewBoxH);
  67426. newState.width = getCoordLength (xml.getStringAttribute ("width", String (newState.width)), viewBoxW);
  67427. newState.height = getCoordLength (xml.getStringAttribute ("height", String (newState.height)), viewBoxH);
  67428. if (xml.hasAttribute ("viewBox"))
  67429. {
  67430. const String viewParams (xml.getStringAttribute ("viewBox"));
  67431. int i = 0;
  67432. float vx, vy, vw, vh;
  67433. if (parseCoords (viewParams, vx, vy, i, true)
  67434. && parseCoords (viewParams, vw, vh, i, true)
  67435. && vw > 0
  67436. && vh > 0)
  67437. {
  67438. newState.viewBoxW = vw;
  67439. newState.viewBoxH = vh;
  67440. int placementFlags = 0;
  67441. const String aspect (xml.getStringAttribute ("preserveAspectRatio"));
  67442. if (aspect.containsIgnoreCase ("none"))
  67443. {
  67444. placementFlags = RectanglePlacement::stretchToFit;
  67445. }
  67446. else
  67447. {
  67448. if (aspect.containsIgnoreCase ("slice"))
  67449. placementFlags |= RectanglePlacement::fillDestination;
  67450. if (aspect.containsIgnoreCase ("xMin"))
  67451. placementFlags |= RectanglePlacement::xLeft;
  67452. else if (aspect.containsIgnoreCase ("xMax"))
  67453. placementFlags |= RectanglePlacement::xRight;
  67454. else
  67455. placementFlags |= RectanglePlacement::xMid;
  67456. if (aspect.containsIgnoreCase ("yMin"))
  67457. placementFlags |= RectanglePlacement::yTop;
  67458. else if (aspect.containsIgnoreCase ("yMax"))
  67459. placementFlags |= RectanglePlacement::yBottom;
  67460. else
  67461. placementFlags |= RectanglePlacement::yMid;
  67462. }
  67463. const RectanglePlacement placement (placementFlags);
  67464. newState.transform
  67465. = placement.getTransformToFit (vx, vy, vw, vh,
  67466. 0.0f, 0.0f, newState.width, newState.height)
  67467. .followedBy (newState.transform);
  67468. }
  67469. }
  67470. else
  67471. {
  67472. if (viewBoxW == 0)
  67473. newState.viewBoxW = newState.width;
  67474. if (viewBoxH == 0)
  67475. newState.viewBoxH = newState.height;
  67476. }
  67477. newState.parseSubElements (xml, drawable);
  67478. return drawable;
  67479. }
  67480. private:
  67481. const XmlElement* const topLevelXml;
  67482. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67483. AffineTransform transform;
  67484. String cssStyleText;
  67485. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67486. {
  67487. forEachXmlChildElement (xml, e)
  67488. {
  67489. Drawable* d = 0;
  67490. if (e->hasTagName ("g"))
  67491. d = parseGroupElement (*e);
  67492. else if (e->hasTagName ("svg"))
  67493. d = parseSVGElement (*e);
  67494. else if (e->hasTagName ("path"))
  67495. d = parsePath (*e);
  67496. else if (e->hasTagName ("rect"))
  67497. d = parseRect (*e);
  67498. else if (e->hasTagName ("circle"))
  67499. d = parseCircle (*e);
  67500. else if (e->hasTagName ("ellipse"))
  67501. d = parseEllipse (*e);
  67502. else if (e->hasTagName ("line"))
  67503. d = parseLine (*e);
  67504. else if (e->hasTagName ("polyline"))
  67505. d = parsePolygon (*e, true);
  67506. else if (e->hasTagName ("polygon"))
  67507. d = parsePolygon (*e, false);
  67508. else if (e->hasTagName ("text"))
  67509. d = parseText (*e);
  67510. else if (e->hasTagName ("switch"))
  67511. d = parseSwitch (*e);
  67512. else if (e->hasTagName ("style"))
  67513. parseCSSStyle (*e);
  67514. parentDrawable->insertDrawable (d);
  67515. }
  67516. }
  67517. DrawableComposite* parseSwitch (const XmlElement& xml)
  67518. {
  67519. const XmlElement* const group = xml.getChildByName ("g");
  67520. if (group != 0)
  67521. return parseGroupElement (*group);
  67522. return 0;
  67523. }
  67524. DrawableComposite* parseGroupElement (const XmlElement& xml)
  67525. {
  67526. DrawableComposite* const drawable = new DrawableComposite();
  67527. drawable->setName (xml.getStringAttribute ("id"));
  67528. if (xml.hasAttribute ("transform"))
  67529. {
  67530. SVGState newState (*this);
  67531. newState.addTransform (xml);
  67532. newState.parseSubElements (xml, drawable);
  67533. }
  67534. else
  67535. {
  67536. parseSubElements (xml, drawable);
  67537. }
  67538. return drawable;
  67539. }
  67540. Drawable* parsePath (const XmlElement& xml) const
  67541. {
  67542. const String d (xml.getStringAttribute ("d").trimStart());
  67543. Path path;
  67544. if (getStyleAttribute (&xml, "fill-rule").trim().equalsIgnoreCase ("evenodd"))
  67545. path.setUsingNonZeroWinding (false);
  67546. int index = 0;
  67547. float lastX = 0, lastY = 0;
  67548. float lastX2 = 0, lastY2 = 0;
  67549. juce_wchar lastCommandChar = 0;
  67550. bool isRelative = true;
  67551. bool carryOn = true;
  67552. const String validCommandChars ("MmLlHhVvCcSsQqTtAaZz");
  67553. while (d[index] != 0)
  67554. {
  67555. float x, y, x2, y2, x3, y3;
  67556. if (validCommandChars.containsChar (d[index]))
  67557. {
  67558. lastCommandChar = d [index++];
  67559. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  67560. }
  67561. switch (lastCommandChar)
  67562. {
  67563. case 'M':
  67564. case 'm':
  67565. case 'L':
  67566. case 'l':
  67567. if (parseCoords (d, x, y, index, false))
  67568. {
  67569. if (isRelative)
  67570. {
  67571. x += lastX;
  67572. y += lastY;
  67573. }
  67574. if (lastCommandChar == 'M' || lastCommandChar == 'm')
  67575. {
  67576. path.startNewSubPath (x, y);
  67577. lastCommandChar = 'l';
  67578. }
  67579. else
  67580. path.lineTo (x, y);
  67581. lastX2 = lastX;
  67582. lastY2 = lastY;
  67583. lastX = x;
  67584. lastY = y;
  67585. }
  67586. else
  67587. {
  67588. ++index;
  67589. }
  67590. break;
  67591. case 'H':
  67592. case 'h':
  67593. if (parseCoord (d, x, index, false, true))
  67594. {
  67595. if (isRelative)
  67596. x += lastX;
  67597. path.lineTo (x, lastY);
  67598. lastX2 = lastX;
  67599. lastX = x;
  67600. }
  67601. else
  67602. {
  67603. ++index;
  67604. }
  67605. break;
  67606. case 'V':
  67607. case 'v':
  67608. if (parseCoord (d, y, index, false, false))
  67609. {
  67610. if (isRelative)
  67611. y += lastY;
  67612. path.lineTo (lastX, y);
  67613. lastY2 = lastY;
  67614. lastY = y;
  67615. }
  67616. else
  67617. {
  67618. ++index;
  67619. }
  67620. break;
  67621. case 'C':
  67622. case 'c':
  67623. if (parseCoords (d, x, y, index, false)
  67624. && parseCoords (d, x2, y2, index, false)
  67625. && parseCoords (d, x3, y3, index, false))
  67626. {
  67627. if (isRelative)
  67628. {
  67629. x += lastX;
  67630. y += lastY;
  67631. x2 += lastX;
  67632. y2 += lastY;
  67633. x3 += lastX;
  67634. y3 += lastY;
  67635. }
  67636. path.cubicTo (x, y, x2, y2, x3, y3);
  67637. lastX2 = x2;
  67638. lastY2 = y2;
  67639. lastX = x3;
  67640. lastY = y3;
  67641. }
  67642. else
  67643. {
  67644. ++index;
  67645. }
  67646. break;
  67647. case 'S':
  67648. case 's':
  67649. if (parseCoords (d, x, y, index, false)
  67650. && parseCoords (d, x3, y3, index, false))
  67651. {
  67652. if (isRelative)
  67653. {
  67654. x += lastX;
  67655. y += lastY;
  67656. x3 += lastX;
  67657. y3 += lastY;
  67658. }
  67659. x2 = lastX + (lastX - lastX2);
  67660. y2 = lastY + (lastY - lastY2);
  67661. path.cubicTo (x2, y2, x, y, x3, y3);
  67662. lastX2 = x;
  67663. lastY2 = y;
  67664. lastX = x3;
  67665. lastY = y3;
  67666. }
  67667. else
  67668. {
  67669. ++index;
  67670. }
  67671. break;
  67672. case 'Q':
  67673. case 'q':
  67674. if (parseCoords (d, x, y, index, false)
  67675. && parseCoords (d, x2, y2, index, false))
  67676. {
  67677. if (isRelative)
  67678. {
  67679. x += lastX;
  67680. y += lastY;
  67681. x2 += lastX;
  67682. y2 += lastY;
  67683. }
  67684. path.quadraticTo (x, y, x2, y2);
  67685. lastX2 = x;
  67686. lastY2 = y;
  67687. lastX = x2;
  67688. lastY = y2;
  67689. }
  67690. else
  67691. {
  67692. ++index;
  67693. }
  67694. break;
  67695. case 'T':
  67696. case 't':
  67697. if (parseCoords (d, x, y, index, false))
  67698. {
  67699. if (isRelative)
  67700. {
  67701. x += lastX;
  67702. y += lastY;
  67703. }
  67704. x2 = lastX + (lastX - lastX2);
  67705. y2 = lastY + (lastY - lastY2);
  67706. path.quadraticTo (x2, y2, x, y);
  67707. lastX2 = x2;
  67708. lastY2 = y2;
  67709. lastX = x;
  67710. lastY = y;
  67711. }
  67712. else
  67713. {
  67714. ++index;
  67715. }
  67716. break;
  67717. case 'A':
  67718. case 'a':
  67719. if (parseCoords (d, x, y, index, false))
  67720. {
  67721. String num;
  67722. if (parseNextNumber (d, num, index, false))
  67723. {
  67724. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  67725. if (parseNextNumber (d, num, index, false))
  67726. {
  67727. const bool largeArc = num.getIntValue() != 0;
  67728. if (parseNextNumber (d, num, index, false))
  67729. {
  67730. const bool sweep = num.getIntValue() != 0;
  67731. if (parseCoords (d, x2, y2, index, false))
  67732. {
  67733. if (isRelative)
  67734. {
  67735. x2 += lastX;
  67736. y2 += lastY;
  67737. }
  67738. if (lastX != x2 || lastY != y2)
  67739. {
  67740. double centreX, centreY, startAngle, deltaAngle;
  67741. double rx = x, ry = y;
  67742. endpointToCentreParameters (lastX, lastY, x2, y2,
  67743. angle, largeArc, sweep,
  67744. rx, ry, centreX, centreY,
  67745. startAngle, deltaAngle);
  67746. path.addCentredArc ((float) centreX, (float) centreY,
  67747. (float) rx, (float) ry,
  67748. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  67749. false);
  67750. path.lineTo (x2, y2);
  67751. }
  67752. lastX2 = lastX;
  67753. lastY2 = lastY;
  67754. lastX = x2;
  67755. lastY = y2;
  67756. }
  67757. }
  67758. }
  67759. }
  67760. }
  67761. else
  67762. {
  67763. ++index;
  67764. }
  67765. break;
  67766. case 'Z':
  67767. case 'z':
  67768. path.closeSubPath();
  67769. while (CharacterFunctions::isWhitespace (d [index]))
  67770. ++index;
  67771. break;
  67772. default:
  67773. carryOn = false;
  67774. break;
  67775. }
  67776. if (! carryOn)
  67777. break;
  67778. }
  67779. return parseShape (xml, path);
  67780. }
  67781. Drawable* parseRect (const XmlElement& xml) const
  67782. {
  67783. Path rect;
  67784. const bool hasRX = xml.hasAttribute ("rx");
  67785. const bool hasRY = xml.hasAttribute ("ry");
  67786. if (hasRX || hasRY)
  67787. {
  67788. float rx = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67789. float ry = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67790. if (! hasRX)
  67791. rx = ry;
  67792. else if (! hasRY)
  67793. ry = rx;
  67794. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67795. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67796. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67797. getCoordLength (xml.getStringAttribute ("height"), viewBoxH),
  67798. rx, ry);
  67799. }
  67800. else
  67801. {
  67802. rect.addRectangle (getCoordLength (xml.getStringAttribute ("x"), viewBoxW),
  67803. getCoordLength (xml.getStringAttribute ("y"), viewBoxH),
  67804. getCoordLength (xml.getStringAttribute ("width"), viewBoxW),
  67805. getCoordLength (xml.getStringAttribute ("height"), viewBoxH));
  67806. }
  67807. return parseShape (xml, rect);
  67808. }
  67809. Drawable* parseCircle (const XmlElement& xml) const
  67810. {
  67811. Path circle;
  67812. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67813. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67814. const float radius = getCoordLength (xml.getStringAttribute ("r"), viewBoxW);
  67815. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  67816. return parseShape (xml, circle);
  67817. }
  67818. Drawable* parseEllipse (const XmlElement& xml) const
  67819. {
  67820. Path ellipse;
  67821. const float cx = getCoordLength (xml.getStringAttribute ("cx"), viewBoxW);
  67822. const float cy = getCoordLength (xml.getStringAttribute ("cy"), viewBoxH);
  67823. const float radiusX = getCoordLength (xml.getStringAttribute ("rx"), viewBoxW);
  67824. const float radiusY = getCoordLength (xml.getStringAttribute ("ry"), viewBoxH);
  67825. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  67826. return parseShape (xml, ellipse);
  67827. }
  67828. Drawable* parseLine (const XmlElement& xml) const
  67829. {
  67830. Path line;
  67831. const float x1 = getCoordLength (xml.getStringAttribute ("x1"), viewBoxW);
  67832. const float y1 = getCoordLength (xml.getStringAttribute ("y1"), viewBoxH);
  67833. const float x2 = getCoordLength (xml.getStringAttribute ("x2"), viewBoxW);
  67834. const float y2 = getCoordLength (xml.getStringAttribute ("y2"), viewBoxH);
  67835. line.startNewSubPath (x1, y1);
  67836. line.lineTo (x2, y2);
  67837. return parseShape (xml, line);
  67838. }
  67839. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  67840. {
  67841. const String points (xml.getStringAttribute ("points"));
  67842. Path path;
  67843. int index = 0;
  67844. float x, y;
  67845. if (parseCoords (points, x, y, index, true))
  67846. {
  67847. float firstX = x;
  67848. float firstY = y;
  67849. float lastX = 0, lastY = 0;
  67850. path.startNewSubPath (x, y);
  67851. while (parseCoords (points, x, y, index, true))
  67852. {
  67853. lastX = x;
  67854. lastY = y;
  67855. path.lineTo (x, y);
  67856. }
  67857. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  67858. path.closeSubPath();
  67859. }
  67860. return parseShape (xml, path);
  67861. }
  67862. Drawable* parseShape (const XmlElement& xml, Path& path,
  67863. const bool shouldParseTransform = true) const
  67864. {
  67865. if (shouldParseTransform && xml.hasAttribute ("transform"))
  67866. {
  67867. SVGState newState (*this);
  67868. newState.addTransform (xml);
  67869. return newState.parseShape (xml, path, false);
  67870. }
  67871. DrawablePath* dp = new DrawablePath();
  67872. dp->setName (xml.getStringAttribute ("id"));
  67873. dp->setFill (Colours::transparentBlack);
  67874. path.applyTransform (transform);
  67875. dp->setPath (path);
  67876. Path::Iterator iter (path);
  67877. bool containsClosedSubPath = false;
  67878. while (iter.next())
  67879. {
  67880. if (iter.elementType == Path::Iterator::closePath)
  67881. {
  67882. containsClosedSubPath = true;
  67883. break;
  67884. }
  67885. }
  67886. dp->setFill (getPathFillType (path,
  67887. getStyleAttribute (&xml, "fill"),
  67888. getStyleAttribute (&xml, "fill-opacity"),
  67889. getStyleAttribute (&xml, "opacity"),
  67890. containsClosedSubPath ? Colours::black
  67891. : Colours::transparentBlack));
  67892. const String strokeType (getStyleAttribute (&xml, "stroke"));
  67893. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase ("none"))
  67894. {
  67895. dp->setStrokeFill (getPathFillType (path, strokeType,
  67896. getStyleAttribute (&xml, "stroke-opacity"),
  67897. getStyleAttribute (&xml, "opacity"),
  67898. Colours::transparentBlack));
  67899. dp->setStrokeType (getStrokeFor (&xml));
  67900. }
  67901. return dp;
  67902. }
  67903. const XmlElement* findLinkedElement (const XmlElement* e) const
  67904. {
  67905. const String id (e->getStringAttribute ("xlink:href"));
  67906. if (! id.startsWithChar ('#'))
  67907. return 0;
  67908. return findElementForId (topLevelXml, id.substring (1));
  67909. }
  67910. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  67911. {
  67912. if (fillXml == 0)
  67913. return;
  67914. forEachXmlChildElementWithTagName (*fillXml, e, "stop")
  67915. {
  67916. int index = 0;
  67917. Colour col (parseColour (getStyleAttribute (e, "stop-color"), index, Colours::black));
  67918. const String opacity (getStyleAttribute (e, "stop-opacity", "1"));
  67919. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  67920. double offset = e->getDoubleAttribute ("offset");
  67921. if (e->getStringAttribute ("offset").containsChar ('%'))
  67922. offset *= 0.01;
  67923. cg.addColour (jlimit (0.0, 1.0, offset), col);
  67924. }
  67925. }
  67926. const FillType getPathFillType (const Path& path,
  67927. const String& fill,
  67928. const String& fillOpacity,
  67929. const String& overallOpacity,
  67930. const Colour& defaultColour) const
  67931. {
  67932. float opacity = 1.0f;
  67933. if (overallOpacity.isNotEmpty())
  67934. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  67935. if (fillOpacity.isNotEmpty())
  67936. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  67937. if (fill.startsWithIgnoreCase ("url"))
  67938. {
  67939. const String id (fill.fromFirstOccurrenceOf ("#", false, false)
  67940. .upToLastOccurrenceOf (")", false, false).trim());
  67941. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  67942. if (fillXml != 0
  67943. && (fillXml->hasTagName ("linearGradient")
  67944. || fillXml->hasTagName ("radialGradient")))
  67945. {
  67946. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  67947. ColourGradient gradient;
  67948. addGradientStopsIn (gradient, inheritedFrom);
  67949. addGradientStopsIn (gradient, fillXml);
  67950. if (gradient.getNumColours() > 0)
  67951. {
  67952. gradient.addColour (0.0, gradient.getColour (0));
  67953. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  67954. }
  67955. else
  67956. {
  67957. gradient.addColour (0.0, Colours::black);
  67958. gradient.addColour (1.0, Colours::black);
  67959. }
  67960. if (overallOpacity.isNotEmpty())
  67961. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  67962. jassert (gradient.getNumColours() > 0);
  67963. gradient.isRadial = fillXml->hasTagName ("radialGradient");
  67964. float width = viewBoxW;
  67965. float height = viewBoxH;
  67966. float dx = 0.0f;
  67967. float dy = 0.0f;
  67968. const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse");
  67969. if (! userSpace)
  67970. {
  67971. const Rectangle<float> bounds (path.getBounds());
  67972. dx = bounds.getX();
  67973. dy = bounds.getY();
  67974. width = bounds.getWidth();
  67975. height = bounds.getHeight();
  67976. }
  67977. if (gradient.isRadial)
  67978. {
  67979. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), width);
  67980. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), height);
  67981. const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), width);
  67982. gradient.x2 = gradient.x1 + radius;
  67983. gradient.y2 = gradient.y1;
  67984. //xxx (the fx, fy focal point isn't handled properly here..)
  67985. }
  67986. else
  67987. {
  67988. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), width);
  67989. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), height);
  67990. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), width);
  67991. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), height);
  67992. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  67993. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  67994. }
  67995. FillType type (gradient);
  67996. type.transform = parseTransform (fillXml->getStringAttribute ("gradientTransform"))
  67997. .followedBy (transform);
  67998. return type;
  67999. }
  68000. }
  68001. if (fill.equalsIgnoreCase ("none"))
  68002. return Colours::transparentBlack;
  68003. int i = 0;
  68004. const Colour colour (parseColour (fill, i, defaultColour));
  68005. return colour.withMultipliedAlpha (opacity);
  68006. }
  68007. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68008. {
  68009. const String width (getStyleAttribute (xml, "stroke-width"));
  68010. const String cap (getStyleAttribute (xml, "stroke-linecap"));
  68011. const String join (getStyleAttribute (xml, "stroke-linejoin"));
  68012. //const String mitreLimit (getStyleAttribute (xml, "stroke-miterlimit"));
  68013. //const String dashArray (getStyleAttribute (xml, "stroke-dasharray"));
  68014. //const String dashOffset (getStyleAttribute (xml, "stroke-dashoffset"));
  68015. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68016. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68017. if (join.equalsIgnoreCase ("round"))
  68018. joinStyle = PathStrokeType::curved;
  68019. else if (join.equalsIgnoreCase ("bevel"))
  68020. joinStyle = PathStrokeType::beveled;
  68021. if (cap.equalsIgnoreCase ("round"))
  68022. capStyle = PathStrokeType::rounded;
  68023. else if (cap.equalsIgnoreCase ("square"))
  68024. capStyle = PathStrokeType::square;
  68025. float ox = 0.0f, oy = 0.0f;
  68026. transform.transformPoint (ox, oy);
  68027. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68028. transform.transformPoint (x, y);
  68029. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68030. joinStyle, capStyle);
  68031. }
  68032. Drawable* parseText (const XmlElement& xml)
  68033. {
  68034. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68035. getCoordList (xCoords, getInheritedAttribute (&xml, "x"), true, true);
  68036. getCoordList (yCoords, getInheritedAttribute (&xml, "y"), true, false);
  68037. getCoordList (dxCoords, getInheritedAttribute (&xml, "dx"), true, true);
  68038. getCoordList (dyCoords, getInheritedAttribute (&xml, "dy"), true, false);
  68039. //xxx not done text yet!
  68040. forEachXmlChildElement (xml, e)
  68041. {
  68042. if (e->isTextElement())
  68043. {
  68044. const String text (e->getText());
  68045. Path path;
  68046. Drawable* s = parseShape (*e, path);
  68047. delete s;
  68048. }
  68049. else if (e->hasTagName ("tspan"))
  68050. {
  68051. Drawable* s = parseText (*e);
  68052. delete s;
  68053. }
  68054. }
  68055. return 0;
  68056. }
  68057. void addTransform (const XmlElement& xml)
  68058. {
  68059. transform = parseTransform (xml.getStringAttribute ("transform"))
  68060. .followedBy (transform);
  68061. }
  68062. bool parseCoord (const String& s, float& value, int& index,
  68063. const bool allowUnits, const bool isX) const
  68064. {
  68065. String number;
  68066. if (! parseNextNumber (s, number, index, allowUnits))
  68067. {
  68068. value = 0;
  68069. return false;
  68070. }
  68071. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68072. return true;
  68073. }
  68074. bool parseCoords (const String& s, float& x, float& y,
  68075. int& index, const bool allowUnits) const
  68076. {
  68077. return parseCoord (s, x, index, allowUnits, true)
  68078. && parseCoord (s, y, index, allowUnits, false);
  68079. }
  68080. float getCoordLength (const String& s, const float sizeForProportions) const
  68081. {
  68082. float n = s.getFloatValue();
  68083. const int len = s.length();
  68084. if (len > 2)
  68085. {
  68086. const float dpi = 96.0f;
  68087. const juce_wchar n1 = s [len - 2];
  68088. const juce_wchar n2 = s [len - 1];
  68089. if (n1 == 'i' && n2 == 'n')
  68090. n *= dpi;
  68091. else if (n1 == 'm' && n2 == 'm')
  68092. n *= dpi / 25.4f;
  68093. else if (n1 == 'c' && n2 == 'm')
  68094. n *= dpi / 2.54f;
  68095. else if (n1 == 'p' && n2 == 'c')
  68096. n *= 15.0f;
  68097. else if (n2 == '%')
  68098. n *= 0.01f * sizeForProportions;
  68099. }
  68100. return n;
  68101. }
  68102. void getCoordList (Array <float>& coords, const String& list,
  68103. const bool allowUnits, const bool isX) const
  68104. {
  68105. int index = 0;
  68106. float value;
  68107. while (parseCoord (list, value, index, allowUnits, isX))
  68108. coords.add (value);
  68109. }
  68110. void parseCSSStyle (const XmlElement& xml)
  68111. {
  68112. cssStyleText = xml.getAllSubText() + "\n" + cssStyleText;
  68113. }
  68114. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68115. const String& defaultValue = String::empty) const
  68116. {
  68117. if (xml->hasAttribute (attributeName))
  68118. return xml->getStringAttribute (attributeName, defaultValue);
  68119. const String styleAtt (xml->getStringAttribute ("style"));
  68120. if (styleAtt.isNotEmpty())
  68121. {
  68122. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68123. if (value.isNotEmpty())
  68124. return value;
  68125. }
  68126. else if (xml->hasAttribute ("class"))
  68127. {
  68128. const String className ("." + xml->getStringAttribute ("class"));
  68129. int index = cssStyleText.indexOfIgnoreCase (className + " ");
  68130. if (index < 0)
  68131. index = cssStyleText.indexOfIgnoreCase (className + "{");
  68132. if (index >= 0)
  68133. {
  68134. const int openBracket = cssStyleText.indexOfChar (index, '{');
  68135. if (openBracket > index)
  68136. {
  68137. const int closeBracket = cssStyleText.indexOfChar (openBracket, '}');
  68138. if (closeBracket > openBracket)
  68139. {
  68140. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68141. if (value.isNotEmpty())
  68142. return value;
  68143. }
  68144. }
  68145. }
  68146. }
  68147. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68148. if (xml != 0)
  68149. return getStyleAttribute (xml, attributeName, defaultValue);
  68150. return defaultValue;
  68151. }
  68152. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68153. {
  68154. if (xml->hasAttribute (attributeName))
  68155. return xml->getStringAttribute (attributeName);
  68156. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68157. if (xml != 0)
  68158. return getInheritedAttribute (xml, attributeName);
  68159. return String::empty;
  68160. }
  68161. static bool isIdentifierChar (const juce_wchar c)
  68162. {
  68163. return CharacterFunctions::isLetter (c) || c == '-';
  68164. }
  68165. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68166. {
  68167. int i = 0;
  68168. for (;;)
  68169. {
  68170. i = list.indexOf (i, attributeName);
  68171. if (i < 0)
  68172. break;
  68173. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68174. && ! isIdentifierChar (list [i + attributeName.length()]))
  68175. {
  68176. i = list.indexOfChar (i, ':');
  68177. if (i < 0)
  68178. break;
  68179. int end = list.indexOfChar (i, ';');
  68180. if (end < 0)
  68181. end = 0x7ffff;
  68182. return list.substring (i + 1, end).trim();
  68183. }
  68184. ++i;
  68185. }
  68186. return defaultValue;
  68187. }
  68188. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68189. {
  68190. const juce_wchar* const s = source;
  68191. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68192. ++index;
  68193. int start = index;
  68194. if (CharacterFunctions::isDigit (s[index]) || s[index] == '.' || s[index] == '-')
  68195. ++index;
  68196. while (CharacterFunctions::isDigit (s[index]) || s[index] == '.')
  68197. ++index;
  68198. if ((s[index] == 'e' || s[index] == 'E')
  68199. && (CharacterFunctions::isDigit (s[index + 1])
  68200. || s[index + 1] == '-'
  68201. || s[index + 1] == '+'))
  68202. {
  68203. index += 2;
  68204. while (CharacterFunctions::isDigit (s[index]))
  68205. ++index;
  68206. }
  68207. if (allowUnits)
  68208. {
  68209. while (CharacterFunctions::isLetter (s[index]))
  68210. ++index;
  68211. }
  68212. if (index == start)
  68213. return false;
  68214. value = String (s + start, index - start);
  68215. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == ',')
  68216. ++index;
  68217. return true;
  68218. }
  68219. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68220. {
  68221. if (s [index] == '#')
  68222. {
  68223. uint32 hex [6];
  68224. zeromem (hex, sizeof (hex));
  68225. int numChars = 0;
  68226. for (int i = 6; --i >= 0;)
  68227. {
  68228. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68229. if (hexValue >= 0)
  68230. hex [numChars++] = hexValue;
  68231. else
  68232. break;
  68233. }
  68234. if (numChars <= 3)
  68235. return Colour ((uint8) (hex [0] * 0x11),
  68236. (uint8) (hex [1] * 0x11),
  68237. (uint8) (hex [2] * 0x11));
  68238. else
  68239. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68240. (uint8) ((hex [2] << 4) + hex [3]),
  68241. (uint8) ((hex [4] << 4) + hex [5]));
  68242. }
  68243. else if (s [index] == 'r'
  68244. && s [index + 1] == 'g'
  68245. && s [index + 2] == 'b')
  68246. {
  68247. const int openBracket = s.indexOfChar (index, '(');
  68248. const int closeBracket = s.indexOfChar (openBracket, ')');
  68249. if (openBracket >= 3 && closeBracket > openBracket)
  68250. {
  68251. index = closeBracket;
  68252. StringArray tokens;
  68253. tokens.addTokens (s.substring (openBracket + 1, closeBracket), ",", "");
  68254. tokens.trim();
  68255. tokens.removeEmptyStrings();
  68256. if (tokens[0].containsChar ('%'))
  68257. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68258. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68259. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68260. else
  68261. return Colour ((uint8) tokens[0].getIntValue(),
  68262. (uint8) tokens[1].getIntValue(),
  68263. (uint8) tokens[2].getIntValue());
  68264. }
  68265. }
  68266. return Colours::findColourForName (s, defaultColour);
  68267. }
  68268. static const AffineTransform parseTransform (String t)
  68269. {
  68270. AffineTransform result;
  68271. while (t.isNotEmpty())
  68272. {
  68273. StringArray tokens;
  68274. tokens.addTokens (t.fromFirstOccurrenceOf ("(", false, false)
  68275. .upToFirstOccurrenceOf (")", false, false),
  68276. ", ", String::empty);
  68277. tokens.removeEmptyStrings (true);
  68278. float numbers [6];
  68279. for (int i = 0; i < 6; ++i)
  68280. numbers[i] = tokens[i].getFloatValue();
  68281. AffineTransform trans;
  68282. if (t.startsWithIgnoreCase ("matrix"))
  68283. {
  68284. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68285. numbers[1], numbers[3], numbers[5]);
  68286. }
  68287. else if (t.startsWithIgnoreCase ("translate"))
  68288. {
  68289. jassert (tokens.size() == 2);
  68290. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68291. }
  68292. else if (t.startsWithIgnoreCase ("scale"))
  68293. {
  68294. if (tokens.size() == 1)
  68295. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68296. else
  68297. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68298. }
  68299. else if (t.startsWithIgnoreCase ("rotate"))
  68300. {
  68301. if (tokens.size() != 3)
  68302. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68303. else
  68304. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68305. numbers[1], numbers[2]);
  68306. }
  68307. else if (t.startsWithIgnoreCase ("skewX"))
  68308. {
  68309. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68310. 0.0f, 1.0f, 0.0f);
  68311. }
  68312. else if (t.startsWithIgnoreCase ("skewY"))
  68313. {
  68314. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68315. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68316. }
  68317. result = trans.followedBy (result);
  68318. t = t.fromFirstOccurrenceOf (")", false, false).trimStart();
  68319. }
  68320. return result;
  68321. }
  68322. static void endpointToCentreParameters (const double x1, const double y1,
  68323. const double x2, const double y2,
  68324. const double angle,
  68325. const bool largeArc, const bool sweep,
  68326. double& rx, double& ry,
  68327. double& centreX, double& centreY,
  68328. double& startAngle, double& deltaAngle)
  68329. {
  68330. const double midX = (x1 - x2) * 0.5;
  68331. const double midY = (y1 - y2) * 0.5;
  68332. const double cosAngle = cos (angle);
  68333. const double sinAngle = sin (angle);
  68334. const double xp = cosAngle * midX + sinAngle * midY;
  68335. const double yp = cosAngle * midY - sinAngle * midX;
  68336. const double xp2 = xp * xp;
  68337. const double yp2 = yp * yp;
  68338. double rx2 = rx * rx;
  68339. double ry2 = ry * ry;
  68340. const double s = (xp2 / rx2) + (yp2 / ry2);
  68341. double c;
  68342. if (s <= 1.0)
  68343. {
  68344. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68345. / (( rx2 * yp2) + (ry2 * xp2))));
  68346. if (largeArc == sweep)
  68347. c = -c;
  68348. }
  68349. else
  68350. {
  68351. const double s2 = sqrt (s);
  68352. rx *= s2;
  68353. ry *= s2;
  68354. rx2 = rx * rx;
  68355. ry2 = ry * ry;
  68356. c = 0;
  68357. }
  68358. const double cpx = ((rx * yp) / ry) * c;
  68359. const double cpy = ((-ry * xp) / rx) * c;
  68360. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68361. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68362. const double ux = (xp - cpx) / rx;
  68363. const double uy = (yp - cpy) / ry;
  68364. const double vx = (-xp - cpx) / rx;
  68365. const double vy = (-yp - cpy) / ry;
  68366. const double length = juce_hypot (ux, uy);
  68367. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68368. if (uy < 0)
  68369. startAngle = -startAngle;
  68370. startAngle += double_Pi * 0.5;
  68371. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68372. / (length * juce_hypot (vx, vy))));
  68373. if ((ux * vy) - (uy * vx) < 0)
  68374. deltaAngle = -deltaAngle;
  68375. if (sweep)
  68376. {
  68377. if (deltaAngle < 0)
  68378. deltaAngle += double_Pi * 2.0;
  68379. }
  68380. else
  68381. {
  68382. if (deltaAngle > 0)
  68383. deltaAngle -= double_Pi * 2.0;
  68384. }
  68385. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68386. }
  68387. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68388. {
  68389. forEachXmlChildElement (*parent, e)
  68390. {
  68391. if (e->compareAttribute ("id", id))
  68392. return e;
  68393. const XmlElement* const found = findElementForId (e, id);
  68394. if (found != 0)
  68395. return found;
  68396. }
  68397. return 0;
  68398. }
  68399. SVGState& operator= (const SVGState&);
  68400. };
  68401. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68402. {
  68403. SVGState state (&svgDocument);
  68404. return state.parseSVGElement (svgDocument);
  68405. }
  68406. END_JUCE_NAMESPACE
  68407. /*** End of inlined file: juce_SVGParser.cpp ***/
  68408. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68409. BEGIN_JUCE_NAMESPACE
  68410. #if JUCE_MSVC
  68411. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68412. #endif
  68413. DropShadowEffect::DropShadowEffect()
  68414. : offsetX (0),
  68415. offsetY (0),
  68416. radius (4),
  68417. opacity (0.6f)
  68418. {
  68419. }
  68420. DropShadowEffect::~DropShadowEffect()
  68421. {
  68422. }
  68423. void DropShadowEffect::setShadowProperties (const float newRadius,
  68424. const float newOpacity,
  68425. const int newShadowOffsetX,
  68426. const int newShadowOffsetY)
  68427. {
  68428. radius = jmax (1.1f, newRadius);
  68429. offsetX = newShadowOffsetX;
  68430. offsetY = newShadowOffsetY;
  68431. opacity = newOpacity;
  68432. }
  68433. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68434. {
  68435. const int w = image.getWidth();
  68436. const int h = image.getHeight();
  68437. Image shadowImage (Image::SingleChannel, w, h, false);
  68438. const Image::BitmapData srcData (image, 0, 0, w, h);
  68439. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68440. const int filter = roundToInt (63.0f / radius);
  68441. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68442. for (int x = w; --x >= 0;)
  68443. {
  68444. int shadowAlpha = 0;
  68445. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68446. uint8* shadowPix = destData.data + x;
  68447. for (int y = h; --y >= 0;)
  68448. {
  68449. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68450. *shadowPix = (uint8) shadowAlpha;
  68451. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68452. shadowPix += destData.lineStride;
  68453. }
  68454. }
  68455. for (int y = h; --y >= 0;)
  68456. {
  68457. int shadowAlpha = 0;
  68458. uint8* shadowPix = destData.getLinePointer (y);
  68459. for (int x = w; --x >= 0;)
  68460. {
  68461. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68462. *shadowPix++ = (uint8) shadowAlpha;
  68463. }
  68464. }
  68465. g.setColour (Colours::black.withAlpha (opacity));
  68466. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68467. g.setOpacity (1.0f);
  68468. g.drawImageAt (&image, 0, 0);
  68469. }
  68470. END_JUCE_NAMESPACE
  68471. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68472. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68473. BEGIN_JUCE_NAMESPACE
  68474. GlowEffect::GlowEffect()
  68475. : radius (2.0f),
  68476. colour (Colours::white)
  68477. {
  68478. }
  68479. GlowEffect::~GlowEffect()
  68480. {
  68481. }
  68482. void GlowEffect::setGlowProperties (const float newRadius,
  68483. const Colour& newColour)
  68484. {
  68485. radius = newRadius;
  68486. colour = newColour;
  68487. }
  68488. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68489. {
  68490. Image temp (image.getFormat(), image.getWidth(), image.getHeight(), true);
  68491. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68492. blurKernel.createGaussianBlur (radius);
  68493. blurKernel.rescaleAllValues (radius);
  68494. blurKernel.applyToImage (temp, &image, image.getBounds());
  68495. g.setColour (colour);
  68496. g.drawImageAt (&temp, 0, 0, true);
  68497. g.setOpacity (1.0f);
  68498. g.drawImageAt (&image, 0, 0, false);
  68499. }
  68500. END_JUCE_NAMESPACE
  68501. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68502. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68503. BEGIN_JUCE_NAMESPACE
  68504. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68505. : opacity (opacity_)
  68506. {
  68507. }
  68508. ReduceOpacityEffect::~ReduceOpacityEffect()
  68509. {
  68510. }
  68511. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  68512. {
  68513. opacity = jlimit (0.0f, 1.0f, newOpacity);
  68514. }
  68515. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  68516. {
  68517. g.setOpacity (opacity);
  68518. g.drawImageAt (&image, 0, 0);
  68519. }
  68520. END_JUCE_NAMESPACE
  68521. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68522. /*** Start of inlined file: juce_Font.cpp ***/
  68523. BEGIN_JUCE_NAMESPACE
  68524. namespace FontValues
  68525. {
  68526. static float limitFontHeight (const float height) throw()
  68527. {
  68528. return jlimit (0.1f, 10000.0f, height);
  68529. }
  68530. static const float defaultFontHeight = 14.0f;
  68531. }
  68532. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  68533. const float kerning_, const float ascent_, const int styleFlags_,
  68534. Typeface* const typeface_) throw()
  68535. : typefaceName (typefaceName_),
  68536. height (height_),
  68537. horizontalScale (horizontalScale_),
  68538. kerning (kerning_),
  68539. ascent (ascent_),
  68540. styleFlags (styleFlags_),
  68541. typeface (typeface_)
  68542. {
  68543. }
  68544. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  68545. : typefaceName (other.typefaceName),
  68546. height (other.height),
  68547. horizontalScale (other.horizontalScale),
  68548. kerning (other.kerning),
  68549. ascent (other.ascent),
  68550. styleFlags (other.styleFlags),
  68551. typeface (other.typeface)
  68552. {
  68553. }
  68554. Font::Font() throw()
  68555. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::defaultFontHeight,
  68556. 1.0f, 0, 0, Font::plain, 0))
  68557. {
  68558. }
  68559. Font::Font (const float fontHeight, const int styleFlags_) throw()
  68560. : font (new SharedFontInternal (getDefaultSansSerifFontName(), FontValues::limitFontHeight (fontHeight),
  68561. 1.0f, 0, 0, styleFlags_, 0))
  68562. {
  68563. }
  68564. Font::Font (const String& typefaceName_,
  68565. const float fontHeight,
  68566. const int styleFlags_) throw()
  68567. : font (new SharedFontInternal (typefaceName_, FontValues::limitFontHeight (fontHeight),
  68568. 1.0f, 0, 0, styleFlags_, 0))
  68569. {
  68570. }
  68571. Font::Font (const Font& other) throw()
  68572. : font (other.font)
  68573. {
  68574. }
  68575. Font& Font::operator= (const Font& other) throw()
  68576. {
  68577. font = other.font;
  68578. return *this;
  68579. }
  68580. Font::~Font() throw()
  68581. {
  68582. }
  68583. Font::Font (const Typeface::Ptr& typeface) throw()
  68584. : font (new SharedFontInternal (typeface->getName(), FontValues::defaultFontHeight,
  68585. 1.0f, 0, 0, Font::plain, typeface))
  68586. {
  68587. }
  68588. bool Font::operator== (const Font& other) const throw()
  68589. {
  68590. return font == other.font
  68591. || (font->height == other.font->height
  68592. && font->styleFlags == other.font->styleFlags
  68593. && font->horizontalScale == other.font->horizontalScale
  68594. && font->kerning == other.font->kerning
  68595. && font->typefaceName == other.font->typefaceName);
  68596. }
  68597. bool Font::operator!= (const Font& other) const throw()
  68598. {
  68599. return ! operator== (other);
  68600. }
  68601. void Font::dupeInternalIfShared() throw()
  68602. {
  68603. if (font->getReferenceCount() > 1)
  68604. font = new SharedFontInternal (*font);
  68605. }
  68606. const String Font::getDefaultSansSerifFontName() throw()
  68607. {
  68608. static const String name ("<Sans-Serif>");
  68609. return name;
  68610. }
  68611. const String Font::getDefaultSerifFontName() throw()
  68612. {
  68613. static const String name ("<Serif>");
  68614. return name;
  68615. }
  68616. const String Font::getDefaultMonospacedFontName() throw()
  68617. {
  68618. static const String name ("<Monospaced>");
  68619. return name;
  68620. }
  68621. void Font::setTypefaceName (const String& faceName) throw()
  68622. {
  68623. if (faceName != font->typefaceName)
  68624. {
  68625. dupeInternalIfShared();
  68626. font->typefaceName = faceName;
  68627. font->typeface = 0;
  68628. font->ascent = 0;
  68629. }
  68630. }
  68631. static String fallbackFont;
  68632. const String Font::getFallbackFontName() throw()
  68633. {
  68634. return fallbackFont;
  68635. }
  68636. void Font::setFallbackFontName (const String& name) throw()
  68637. {
  68638. fallbackFont = name;
  68639. }
  68640. void Font::setHeight (float newHeight) throw()
  68641. {
  68642. newHeight = FontValues::limitFontHeight (newHeight);
  68643. if (font->height != newHeight)
  68644. {
  68645. dupeInternalIfShared();
  68646. font->height = newHeight;
  68647. }
  68648. }
  68649. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  68650. {
  68651. newHeight = FontValues::limitFontHeight (newHeight);
  68652. if (font->height != newHeight)
  68653. {
  68654. dupeInternalIfShared();
  68655. font->horizontalScale *= (font->height / newHeight);
  68656. font->height = newHeight;
  68657. }
  68658. }
  68659. void Font::setStyleFlags (const int newFlags) throw()
  68660. {
  68661. if (font->styleFlags != newFlags)
  68662. {
  68663. dupeInternalIfShared();
  68664. font->styleFlags = newFlags;
  68665. font->typeface = 0;
  68666. font->ascent = 0;
  68667. }
  68668. }
  68669. void Font::setSizeAndStyle (float newHeight,
  68670. const int newStyleFlags,
  68671. const float newHorizontalScale,
  68672. const float newKerningAmount) throw()
  68673. {
  68674. newHeight = FontValues::limitFontHeight (newHeight);
  68675. if (font->height != newHeight
  68676. || font->horizontalScale != newHorizontalScale
  68677. || font->kerning != newKerningAmount)
  68678. {
  68679. dupeInternalIfShared();
  68680. font->height = newHeight;
  68681. font->horizontalScale = newHorizontalScale;
  68682. font->kerning = newKerningAmount;
  68683. }
  68684. setStyleFlags (newStyleFlags);
  68685. }
  68686. void Font::setHorizontalScale (const float scaleFactor) throw()
  68687. {
  68688. dupeInternalIfShared();
  68689. font->horizontalScale = scaleFactor;
  68690. }
  68691. void Font::setExtraKerningFactor (const float extraKerning) throw()
  68692. {
  68693. dupeInternalIfShared();
  68694. font->kerning = extraKerning;
  68695. }
  68696. void Font::setBold (const bool shouldBeBold) throw()
  68697. {
  68698. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  68699. : (font->styleFlags & ~bold));
  68700. }
  68701. bool Font::isBold() const throw()
  68702. {
  68703. return (font->styleFlags & bold) != 0;
  68704. }
  68705. void Font::setItalic (const bool shouldBeItalic) throw()
  68706. {
  68707. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  68708. : (font->styleFlags & ~italic));
  68709. }
  68710. bool Font::isItalic() const throw()
  68711. {
  68712. return (font->styleFlags & italic) != 0;
  68713. }
  68714. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  68715. {
  68716. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  68717. : (font->styleFlags & ~underlined));
  68718. }
  68719. bool Font::isUnderlined() const throw()
  68720. {
  68721. return (font->styleFlags & underlined) != 0;
  68722. }
  68723. float Font::getAscent() const throw()
  68724. {
  68725. if (font->ascent == 0)
  68726. font->ascent = getTypeface()->getAscent();
  68727. return font->height * font->ascent;
  68728. }
  68729. float Font::getDescent() const throw()
  68730. {
  68731. return font->height - getAscent();
  68732. }
  68733. int Font::getStringWidth (const String& text) const throw()
  68734. {
  68735. return roundToInt (getStringWidthFloat (text));
  68736. }
  68737. float Font::getStringWidthFloat (const String& text) const throw()
  68738. {
  68739. float w = getTypeface()->getStringWidth (text);
  68740. if (font->kerning != 0)
  68741. w += font->kerning * text.length();
  68742. return w * font->height * font->horizontalScale;
  68743. }
  68744. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  68745. {
  68746. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  68747. const float scale = font->height * font->horizontalScale;
  68748. const int num = xOffsets.size();
  68749. if (num > 0)
  68750. {
  68751. float* const x = &(xOffsets.getReference(0));
  68752. if (font->kerning != 0)
  68753. {
  68754. for (int i = 0; i < num; ++i)
  68755. x[i] = (x[i] + i * font->kerning) * scale;
  68756. }
  68757. else
  68758. {
  68759. for (int i = 0; i < num; ++i)
  68760. x[i] *= scale;
  68761. }
  68762. }
  68763. }
  68764. void Font::findFonts (Array<Font>& destArray) throw()
  68765. {
  68766. const StringArray names (findAllTypefaceNames());
  68767. for (int i = 0; i < names.size(); ++i)
  68768. destArray.add (Font (names[i], FontValues::defaultFontHeight, Font::plain));
  68769. }
  68770. class TypefaceCache : public DeletedAtShutdown
  68771. {
  68772. public:
  68773. TypefaceCache (int numToCache = 10) throw()
  68774. : counter (1)
  68775. {
  68776. while (--numToCache >= 0)
  68777. faces.add (new CachedFace());
  68778. }
  68779. ~TypefaceCache()
  68780. {
  68781. clearSingletonInstance();
  68782. }
  68783. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  68784. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  68785. {
  68786. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  68787. const String faceName (font.getTypefaceName());
  68788. int i;
  68789. for (i = faces.size(); --i >= 0;)
  68790. {
  68791. CachedFace* const face = faces.getUnchecked(i);
  68792. if (face->flags == flags
  68793. && face->typefaceName == faceName)
  68794. {
  68795. face->lastUsageCount = ++counter;
  68796. return face->typeFace;
  68797. }
  68798. }
  68799. int replaceIndex = 0;
  68800. int bestLastUsageCount = std::numeric_limits<int>::max();
  68801. for (i = faces.size(); --i >= 0;)
  68802. {
  68803. const int lu = faces.getUnchecked(i)->lastUsageCount;
  68804. if (bestLastUsageCount > lu)
  68805. {
  68806. bestLastUsageCount = lu;
  68807. replaceIndex = i;
  68808. }
  68809. }
  68810. CachedFace* const face = faces.getUnchecked (replaceIndex);
  68811. face->typefaceName = faceName;
  68812. face->flags = flags;
  68813. face->lastUsageCount = ++counter;
  68814. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  68815. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  68816. return face->typeFace;
  68817. }
  68818. juce_UseDebuggingNewOperator
  68819. private:
  68820. struct CachedFace
  68821. {
  68822. CachedFace() throw()
  68823. : lastUsageCount (0), flags (-1)
  68824. {
  68825. }
  68826. String typefaceName;
  68827. int lastUsageCount;
  68828. int flags;
  68829. Typeface::Ptr typeFace;
  68830. };
  68831. int counter;
  68832. OwnedArray <CachedFace> faces;
  68833. TypefaceCache (const TypefaceCache&);
  68834. TypefaceCache& operator= (const TypefaceCache&);
  68835. };
  68836. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  68837. Typeface* Font::getTypeface() const throw()
  68838. {
  68839. if (font->typeface == 0)
  68840. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  68841. return font->typeface;
  68842. }
  68843. END_JUCE_NAMESPACE
  68844. /*** End of inlined file: juce_Font.cpp ***/
  68845. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  68846. BEGIN_JUCE_NAMESPACE
  68847. PositionedGlyph::PositionedGlyph (const float x_, const float y_, const float w_, const Font& font_,
  68848. const juce_wchar character_, const int glyph_)
  68849. : x (x_),
  68850. y (y_),
  68851. w (w_),
  68852. font (font_),
  68853. character (character_),
  68854. glyph (glyph_)
  68855. {
  68856. }
  68857. PositionedGlyph::PositionedGlyph (const PositionedGlyph& other)
  68858. : x (other.x),
  68859. y (other.y),
  68860. w (other.w),
  68861. font (other.font),
  68862. character (other.character),
  68863. glyph (other.glyph)
  68864. {
  68865. }
  68866. void PositionedGlyph::draw (const Graphics& g) const
  68867. {
  68868. if (! isWhitespace())
  68869. {
  68870. g.getInternalContext()->setFont (font);
  68871. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  68872. }
  68873. }
  68874. void PositionedGlyph::draw (const Graphics& g,
  68875. const AffineTransform& transform) const
  68876. {
  68877. if (! isWhitespace())
  68878. {
  68879. g.getInternalContext()->setFont (font);
  68880. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  68881. .followedBy (transform));
  68882. }
  68883. }
  68884. void PositionedGlyph::createPath (Path& path) const
  68885. {
  68886. if (! isWhitespace())
  68887. {
  68888. Typeface* const t = font.getTypeface();
  68889. if (t != 0)
  68890. {
  68891. Path p;
  68892. t->getOutlineForGlyph (glyph, p);
  68893. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  68894. .translated (x, y));
  68895. }
  68896. }
  68897. }
  68898. bool PositionedGlyph::hitTest (float px, float py) const
  68899. {
  68900. if (getBounds().contains (px, py) && ! isWhitespace())
  68901. {
  68902. Typeface* const t = font.getTypeface();
  68903. if (t != 0)
  68904. {
  68905. Path p;
  68906. t->getOutlineForGlyph (glyph, p);
  68907. AffineTransform::translation (-x, -y)
  68908. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  68909. .transformPoint (px, py);
  68910. return p.contains (px, py);
  68911. }
  68912. }
  68913. return false;
  68914. }
  68915. void PositionedGlyph::moveBy (const float deltaX,
  68916. const float deltaY)
  68917. {
  68918. x += deltaX;
  68919. y += deltaY;
  68920. }
  68921. GlyphArrangement::GlyphArrangement()
  68922. {
  68923. glyphs.ensureStorageAllocated (128);
  68924. }
  68925. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  68926. {
  68927. addGlyphArrangement (other);
  68928. }
  68929. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  68930. {
  68931. if (this != &other)
  68932. {
  68933. clear();
  68934. addGlyphArrangement (other);
  68935. }
  68936. return *this;
  68937. }
  68938. GlyphArrangement::~GlyphArrangement()
  68939. {
  68940. }
  68941. void GlyphArrangement::clear()
  68942. {
  68943. glyphs.clear();
  68944. }
  68945. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  68946. {
  68947. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  68948. return *glyphs [index];
  68949. }
  68950. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  68951. {
  68952. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  68953. for (int i = 0; i < other.glyphs.size(); ++i)
  68954. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  68955. }
  68956. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  68957. {
  68958. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  68959. }
  68960. void GlyphArrangement::addLineOfText (const Font& font,
  68961. const String& text,
  68962. const float xOffset,
  68963. const float yOffset)
  68964. {
  68965. addCurtailedLineOfText (font, text,
  68966. xOffset, yOffset,
  68967. 1.0e10f, false);
  68968. }
  68969. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  68970. const String& text,
  68971. float xOffset,
  68972. const float yOffset,
  68973. const float maxWidthPixels,
  68974. const bool useEllipsis)
  68975. {
  68976. if (text.isNotEmpty())
  68977. {
  68978. Array <int> newGlyphs;
  68979. Array <float> xOffsets;
  68980. font.getGlyphPositions (text, newGlyphs, xOffsets);
  68981. const int textLen = newGlyphs.size();
  68982. const juce_wchar* const unicodeText = text;
  68983. for (int i = 0; i < textLen; ++i)
  68984. {
  68985. const float thisX = xOffsets.getUnchecked (i);
  68986. const float nextX = xOffsets.getUnchecked (i + 1);
  68987. if (nextX > maxWidthPixels + 1.0f)
  68988. {
  68989. // curtail the string if it's too wide..
  68990. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  68991. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  68992. break;
  68993. }
  68994. else
  68995. {
  68996. glyphs.add (new PositionedGlyph (xOffset + thisX, yOffset, nextX - thisX,
  68997. font, unicodeText[i], newGlyphs.getUnchecked(i)));
  68998. }
  68999. }
  69000. }
  69001. }
  69002. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69003. const int startIndex, int endIndex)
  69004. {
  69005. int numDeleted = 0;
  69006. if (glyphs.size() > 0)
  69007. {
  69008. Array<int> dotGlyphs;
  69009. Array<float> dotXs;
  69010. font.getGlyphPositions ("..", dotGlyphs, dotXs);
  69011. const float dx = dotXs[1];
  69012. float xOffset = 0.0f, yOffset = 0.0f;
  69013. while (endIndex > startIndex)
  69014. {
  69015. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69016. xOffset = pg->x;
  69017. yOffset = pg->y;
  69018. glyphs.remove (endIndex);
  69019. ++numDeleted;
  69020. if (xOffset + dx * 3 <= maxXPos)
  69021. break;
  69022. }
  69023. for (int i = 3; --i >= 0;)
  69024. {
  69025. glyphs.insert (endIndex++, new PositionedGlyph (xOffset, yOffset, dx,
  69026. font, '.', dotGlyphs.getFirst()));
  69027. --numDeleted;
  69028. xOffset += dx;
  69029. if (xOffset > maxXPos)
  69030. break;
  69031. }
  69032. }
  69033. return numDeleted;
  69034. }
  69035. void GlyphArrangement::addJustifiedText (const Font& font,
  69036. const String& text,
  69037. float x, float y,
  69038. const float maxLineWidth,
  69039. const Justification& horizontalLayout)
  69040. {
  69041. int lineStartIndex = glyphs.size();
  69042. addLineOfText (font, text, x, y);
  69043. const float originalY = y;
  69044. while (lineStartIndex < glyphs.size())
  69045. {
  69046. int i = lineStartIndex;
  69047. if (glyphs.getUnchecked(i)->getCharacter() != '\n'
  69048. && glyphs.getUnchecked(i)->getCharacter() != '\r')
  69049. ++i;
  69050. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69051. int lastWordBreakIndex = -1;
  69052. while (i < glyphs.size())
  69053. {
  69054. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69055. const juce_wchar c = pg->getCharacter();
  69056. if (c == '\r' || c == '\n')
  69057. {
  69058. ++i;
  69059. if (c == '\r' && i < glyphs.size()
  69060. && glyphs.getUnchecked(i)->getCharacter() == '\n')
  69061. ++i;
  69062. break;
  69063. }
  69064. else if (pg->isWhitespace())
  69065. {
  69066. lastWordBreakIndex = i + 1;
  69067. }
  69068. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69069. {
  69070. if (lastWordBreakIndex >= 0)
  69071. i = lastWordBreakIndex;
  69072. break;
  69073. }
  69074. ++i;
  69075. }
  69076. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69077. float currentLineEndX = currentLineStartX;
  69078. for (int j = i; --j >= lineStartIndex;)
  69079. {
  69080. if (! glyphs.getUnchecked (j)->isWhitespace())
  69081. {
  69082. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69083. break;
  69084. }
  69085. }
  69086. float deltaX = 0.0f;
  69087. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69088. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69089. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69090. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69091. else if (horizontalLayout.testFlags (Justification::right))
  69092. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69093. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69094. x + deltaX - currentLineStartX, y - originalY);
  69095. lineStartIndex = i;
  69096. y += font.getHeight();
  69097. }
  69098. }
  69099. void GlyphArrangement::addFittedText (const Font& f,
  69100. const String& text,
  69101. const float x, const float y,
  69102. const float width, const float height,
  69103. const Justification& layout,
  69104. int maximumLines,
  69105. const float minimumHorizontalScale)
  69106. {
  69107. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69108. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69109. if (text.containsAnyOf ("\r\n"))
  69110. {
  69111. GlyphArrangement ga;
  69112. ga.addJustifiedText (f, text, x, y, width, layout);
  69113. const Rectangle<float> bb (ga.getBoundingBox (0, -1, false));
  69114. float dy = y - bb.getY();
  69115. if (layout.testFlags (Justification::verticallyCentred))
  69116. dy += (height - bb.getHeight()) * 0.5f;
  69117. else if (layout.testFlags (Justification::bottom))
  69118. dy += height - bb.getHeight();
  69119. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69120. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69121. for (int i = 0; i < ga.glyphs.size(); ++i)
  69122. glyphs.add (ga.glyphs.getUnchecked (i));
  69123. ga.glyphs.clear (false);
  69124. return;
  69125. }
  69126. int startIndex = glyphs.size();
  69127. addLineOfText (f, text.trim(), x, y);
  69128. if (glyphs.size() > startIndex)
  69129. {
  69130. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69131. - glyphs.getUnchecked (startIndex)->getLeft();
  69132. if (lineWidth <= 0)
  69133. return;
  69134. if (lineWidth * minimumHorizontalScale < width)
  69135. {
  69136. if (lineWidth > width)
  69137. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69138. width / lineWidth);
  69139. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69140. x, y, width, height, layout);
  69141. }
  69142. else if (maximumLines <= 1)
  69143. {
  69144. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69145. x, y, width, height, f, layout, minimumHorizontalScale);
  69146. }
  69147. else
  69148. {
  69149. Font font (f);
  69150. String txt (text.trim());
  69151. const int length = txt.length();
  69152. const int originalStartIndex = startIndex;
  69153. int numLines = 1;
  69154. if (length <= 12 && ! txt.containsAnyOf (" -\t\r\n"))
  69155. maximumLines = 1;
  69156. maximumLines = jmin (maximumLines, length);
  69157. while (numLines < maximumLines)
  69158. {
  69159. ++numLines;
  69160. const float newFontHeight = height / (float) numLines;
  69161. if (newFontHeight < font.getHeight())
  69162. {
  69163. font.setHeight (jmax (8.0f, newFontHeight));
  69164. removeRangeOfGlyphs (startIndex, -1);
  69165. addLineOfText (font, txt, x, y);
  69166. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69167. - glyphs.getUnchecked (startIndex)->getLeft();
  69168. }
  69169. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69170. break;
  69171. }
  69172. if (numLines < 1)
  69173. numLines = 1;
  69174. float lineY = y;
  69175. float widthPerLine = lineWidth / numLines;
  69176. int lastLineStartIndex = 0;
  69177. for (int line = 0; line < numLines; ++line)
  69178. {
  69179. int i = startIndex;
  69180. lastLineStartIndex = i;
  69181. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69182. if (line == numLines - 1)
  69183. {
  69184. widthPerLine = width;
  69185. i = glyphs.size();
  69186. }
  69187. else
  69188. {
  69189. while (i < glyphs.size())
  69190. {
  69191. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69192. if (lineWidth > widthPerLine)
  69193. {
  69194. // got to a point where the line's too long, so skip forward to find a
  69195. // good place to break it..
  69196. const int searchStartIndex = i;
  69197. while (i < glyphs.size())
  69198. {
  69199. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69200. {
  69201. if (glyphs.getUnchecked (i)->isWhitespace()
  69202. || glyphs.getUnchecked (i)->getCharacter() == '-')
  69203. {
  69204. ++i;
  69205. break;
  69206. }
  69207. }
  69208. else
  69209. {
  69210. // can't find a suitable break, so try looking backwards..
  69211. i = searchStartIndex;
  69212. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69213. {
  69214. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69215. || glyphs.getUnchecked (i - back)->getCharacter() == '-')
  69216. {
  69217. i -= back - 1;
  69218. break;
  69219. }
  69220. }
  69221. break;
  69222. }
  69223. ++i;
  69224. }
  69225. break;
  69226. }
  69227. ++i;
  69228. }
  69229. int wsStart = i;
  69230. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69231. --wsStart;
  69232. int wsEnd = i;
  69233. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69234. ++wsEnd;
  69235. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69236. i = jmax (wsStart, startIndex + 1);
  69237. }
  69238. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69239. x, lineY, width, font.getHeight(), font,
  69240. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69241. minimumHorizontalScale);
  69242. startIndex = i;
  69243. lineY += font.getHeight();
  69244. if (startIndex >= glyphs.size())
  69245. break;
  69246. }
  69247. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69248. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69249. }
  69250. }
  69251. }
  69252. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69253. const float dx, const float dy)
  69254. {
  69255. jassert (startIndex >= 0);
  69256. if (dx != 0.0f || dy != 0.0f)
  69257. {
  69258. if (num < 0 || startIndex + num > glyphs.size())
  69259. num = glyphs.size() - startIndex;
  69260. while (--num >= 0)
  69261. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69262. }
  69263. }
  69264. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69265. const Justification& justification, float minimumHorizontalScale)
  69266. {
  69267. int numDeleted = 0;
  69268. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69269. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69270. if (lineWidth > w)
  69271. {
  69272. if (minimumHorizontalScale < 1.0f)
  69273. {
  69274. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69275. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69276. }
  69277. if (lineWidth > w)
  69278. {
  69279. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69280. numGlyphs -= numDeleted;
  69281. }
  69282. }
  69283. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69284. return numDeleted;
  69285. }
  69286. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69287. const float horizontalScaleFactor)
  69288. {
  69289. jassert (startIndex >= 0);
  69290. if (num < 0 || startIndex + num > glyphs.size())
  69291. num = glyphs.size() - startIndex;
  69292. if (num > 0)
  69293. {
  69294. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69295. while (--num >= 0)
  69296. {
  69297. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69298. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69299. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69300. pg->w *= horizontalScaleFactor;
  69301. }
  69302. }
  69303. }
  69304. const Rectangle<float> GlyphArrangement::getBoundingBox (int startIndex, int num, const bool includeWhitespace) const
  69305. {
  69306. jassert (startIndex >= 0);
  69307. if (num < 0 || startIndex + num > glyphs.size())
  69308. num = glyphs.size() - startIndex;
  69309. Rectangle<float> result;
  69310. bool isFirst = true;
  69311. while (--num >= 0)
  69312. {
  69313. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69314. if (includeWhitespace || ! pg->isWhitespace())
  69315. {
  69316. if (isFirst)
  69317. {
  69318. isFirst = false;
  69319. result = pg->getBounds();
  69320. }
  69321. else
  69322. {
  69323. result = result.getUnion (pg->getBounds());
  69324. }
  69325. }
  69326. }
  69327. return result;
  69328. }
  69329. void GlyphArrangement::justifyGlyphs (const int startIndex, const int num,
  69330. const float x, const float y, const float width, const float height,
  69331. const Justification& justification)
  69332. {
  69333. jassert (num >= 0 && startIndex >= 0);
  69334. if (glyphs.size() > 0 && num > 0)
  69335. {
  69336. const Rectangle<float> bb (getBoundingBox (startIndex, num, ! justification.testFlags (Justification::horizontallyJustified
  69337. | Justification::horizontallyCentred)));
  69338. float deltaX = 0.0f;
  69339. if (justification.testFlags (Justification::horizontallyJustified))
  69340. deltaX = x - bb.getX();
  69341. else if (justification.testFlags (Justification::horizontallyCentred))
  69342. deltaX = x + (width - bb.getWidth()) * 0.5f - bb.getX();
  69343. else if (justification.testFlags (Justification::right))
  69344. deltaX = (x + width) - bb.getRight();
  69345. else
  69346. deltaX = x - bb.getX();
  69347. float deltaY = 0.0f;
  69348. if (justification.testFlags (Justification::top))
  69349. deltaY = y - bb.getY();
  69350. else if (justification.testFlags (Justification::bottom))
  69351. deltaY = (y + height) - bb.getBottom();
  69352. else
  69353. deltaY = y + (height - bb.getHeight()) * 0.5f - bb.getY();
  69354. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69355. if (justification.testFlags (Justification::horizontallyJustified))
  69356. {
  69357. int lineStart = 0;
  69358. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69359. int i;
  69360. for (i = 0; i < num; ++i)
  69361. {
  69362. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69363. if (glyphY != baseY)
  69364. {
  69365. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69366. lineStart = i;
  69367. baseY = glyphY;
  69368. }
  69369. }
  69370. if (i > lineStart)
  69371. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69372. }
  69373. }
  69374. }
  69375. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69376. {
  69377. if (start + num < glyphs.size()
  69378. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\r'
  69379. && glyphs.getUnchecked (start + num - 1)->getCharacter() != '\n')
  69380. {
  69381. int numSpaces = 0;
  69382. int spacesAtEnd = 0;
  69383. for (int i = 0; i < num; ++i)
  69384. {
  69385. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69386. {
  69387. ++spacesAtEnd;
  69388. ++numSpaces;
  69389. }
  69390. else
  69391. {
  69392. spacesAtEnd = 0;
  69393. }
  69394. }
  69395. numSpaces -= spacesAtEnd;
  69396. if (numSpaces > 0)
  69397. {
  69398. const float startX = glyphs.getUnchecked (start)->getLeft();
  69399. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69400. const float extraPaddingBetweenWords
  69401. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69402. float deltaX = 0.0f;
  69403. for (int i = 0; i < num; ++i)
  69404. {
  69405. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69406. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69407. deltaX += extraPaddingBetweenWords;
  69408. }
  69409. }
  69410. }
  69411. }
  69412. void GlyphArrangement::draw (const Graphics& g) const
  69413. {
  69414. for (int i = 0; i < glyphs.size(); ++i)
  69415. {
  69416. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69417. if (pg->font.isUnderlined())
  69418. {
  69419. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69420. float nextX = pg->x + pg->w;
  69421. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69422. nextX = glyphs.getUnchecked (i + 1)->x;
  69423. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69424. nextX - pg->x, lineThickness);
  69425. }
  69426. pg->draw (g);
  69427. }
  69428. }
  69429. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69430. {
  69431. for (int i = 0; i < glyphs.size(); ++i)
  69432. {
  69433. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69434. if (pg->font.isUnderlined())
  69435. {
  69436. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69437. float nextX = pg->x + pg->w;
  69438. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69439. nextX = glyphs.getUnchecked (i + 1)->x;
  69440. Path p;
  69441. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69442. nextX, pg->y + lineThickness * 2.0f,
  69443. lineThickness);
  69444. g.fillPath (p, transform);
  69445. }
  69446. pg->draw (g, transform);
  69447. }
  69448. }
  69449. void GlyphArrangement::createPath (Path& path) const
  69450. {
  69451. for (int i = 0; i < glyphs.size(); ++i)
  69452. glyphs.getUnchecked (i)->createPath (path);
  69453. }
  69454. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69455. {
  69456. for (int i = 0; i < glyphs.size(); ++i)
  69457. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69458. return i;
  69459. return -1;
  69460. }
  69461. END_JUCE_NAMESPACE
  69462. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69463. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69464. BEGIN_JUCE_NAMESPACE
  69465. class TextLayout::Token
  69466. {
  69467. public:
  69468. String text;
  69469. Font font;
  69470. int x, y, w, h;
  69471. int line, lineHeight;
  69472. bool isWhitespace, isNewLine;
  69473. Token (const String& t,
  69474. const Font& f,
  69475. const bool isWhitespace_)
  69476. : text (t),
  69477. font (f),
  69478. x(0),
  69479. y(0),
  69480. isWhitespace (isWhitespace_)
  69481. {
  69482. w = font.getStringWidth (t);
  69483. h = roundToInt (f.getHeight());
  69484. isNewLine = t.containsChar ('\n') || t.containsChar ('\r');
  69485. }
  69486. Token (const Token& other)
  69487. : text (other.text),
  69488. font (other.font),
  69489. x (other.x),
  69490. y (other.y),
  69491. w (other.w),
  69492. h (other.h),
  69493. line (other.line),
  69494. lineHeight (other.lineHeight),
  69495. isWhitespace (other.isWhitespace),
  69496. isNewLine (other.isNewLine)
  69497. {
  69498. }
  69499. ~Token()
  69500. {
  69501. }
  69502. void draw (Graphics& g,
  69503. const int xOffset,
  69504. const int yOffset)
  69505. {
  69506. if (! isWhitespace)
  69507. {
  69508. g.setFont (font);
  69509. g.drawSingleLineText (text.trimEnd(),
  69510. xOffset + x,
  69511. yOffset + y + (lineHeight - h)
  69512. + roundToInt (font.getAscent()));
  69513. }
  69514. }
  69515. juce_UseDebuggingNewOperator
  69516. };
  69517. TextLayout::TextLayout()
  69518. : totalLines (0)
  69519. {
  69520. tokens.ensureStorageAllocated (64);
  69521. }
  69522. TextLayout::TextLayout (const String& text, const Font& font)
  69523. : totalLines (0)
  69524. {
  69525. tokens.ensureStorageAllocated (64);
  69526. appendText (text, font);
  69527. }
  69528. TextLayout::TextLayout (const TextLayout& other)
  69529. : totalLines (0)
  69530. {
  69531. *this = other;
  69532. }
  69533. TextLayout& TextLayout::operator= (const TextLayout& other)
  69534. {
  69535. if (this != &other)
  69536. {
  69537. clear();
  69538. totalLines = other.totalLines;
  69539. for (int i = 0; i < other.tokens.size(); ++i)
  69540. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  69541. }
  69542. return *this;
  69543. }
  69544. TextLayout::~TextLayout()
  69545. {
  69546. clear();
  69547. }
  69548. void TextLayout::clear()
  69549. {
  69550. tokens.clear();
  69551. totalLines = 0;
  69552. }
  69553. void TextLayout::appendText (const String& text, const Font& font)
  69554. {
  69555. const juce_wchar* t = text;
  69556. String currentString;
  69557. int lastCharType = 0;
  69558. for (;;)
  69559. {
  69560. const juce_wchar c = *t++;
  69561. if (c == 0)
  69562. break;
  69563. int charType;
  69564. if (c == '\r' || c == '\n')
  69565. {
  69566. charType = 0;
  69567. }
  69568. else if (CharacterFunctions::isWhitespace (c))
  69569. {
  69570. charType = 2;
  69571. }
  69572. else
  69573. {
  69574. charType = 1;
  69575. }
  69576. if (charType == 0 || charType != lastCharType)
  69577. {
  69578. if (currentString.isNotEmpty())
  69579. {
  69580. tokens.add (new Token (currentString, font,
  69581. lastCharType == 2 || lastCharType == 0));
  69582. }
  69583. currentString = String::charToString (c);
  69584. if (c == '\r' && *t == '\n')
  69585. currentString += *t++;
  69586. }
  69587. else
  69588. {
  69589. currentString += c;
  69590. }
  69591. lastCharType = charType;
  69592. }
  69593. if (currentString.isNotEmpty())
  69594. tokens.add (new Token (currentString, font, lastCharType == 2));
  69595. }
  69596. void TextLayout::setText (const String& text, const Font& font)
  69597. {
  69598. clear();
  69599. appendText (text, font);
  69600. }
  69601. void TextLayout::layout (int maxWidth,
  69602. const Justification& justification,
  69603. const bool attemptToBalanceLineLengths)
  69604. {
  69605. if (attemptToBalanceLineLengths)
  69606. {
  69607. const int originalW = maxWidth;
  69608. int bestWidth = maxWidth;
  69609. float bestLineProportion = 0.0f;
  69610. while (maxWidth > originalW / 2)
  69611. {
  69612. layout (maxWidth, justification, false);
  69613. if (getNumLines() <= 1)
  69614. return;
  69615. const int lastLineW = getLineWidth (getNumLines() - 1);
  69616. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  69617. const float prop = lastLineW / (float) lastButOneLineW;
  69618. if (prop > 0.9f)
  69619. return;
  69620. if (prop > bestLineProportion)
  69621. {
  69622. bestLineProportion = prop;
  69623. bestWidth = maxWidth;
  69624. }
  69625. maxWidth -= 10;
  69626. }
  69627. layout (bestWidth, justification, false);
  69628. }
  69629. else
  69630. {
  69631. int x = 0;
  69632. int y = 0;
  69633. int h = 0;
  69634. totalLines = 0;
  69635. int i;
  69636. for (i = 0; i < tokens.size(); ++i)
  69637. {
  69638. Token* const t = tokens.getUnchecked(i);
  69639. t->x = x;
  69640. t->y = y;
  69641. t->line = totalLines;
  69642. x += t->w;
  69643. h = jmax (h, t->h);
  69644. const Token* nextTok = tokens [i + 1];
  69645. if (nextTok == 0)
  69646. break;
  69647. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  69648. {
  69649. // finished a line, so go back and update the heights of the things on it
  69650. for (int j = i; j >= 0; --j)
  69651. {
  69652. Token* const tok = tokens.getUnchecked(j);
  69653. if (tok->line == totalLines)
  69654. tok->lineHeight = h;
  69655. else
  69656. break;
  69657. }
  69658. x = 0;
  69659. y += h;
  69660. h = 0;
  69661. ++totalLines;
  69662. }
  69663. }
  69664. // finished a line, so go back and update the heights of the things on it
  69665. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  69666. {
  69667. Token* const t = tokens.getUnchecked(j);
  69668. if (t->line == totalLines)
  69669. t->lineHeight = h;
  69670. else
  69671. break;
  69672. }
  69673. ++totalLines;
  69674. if (! justification.testFlags (Justification::left))
  69675. {
  69676. int totalW = getWidth();
  69677. for (i = totalLines; --i >= 0;)
  69678. {
  69679. const int lineW = getLineWidth (i);
  69680. int dx = 0;
  69681. if (justification.testFlags (Justification::horizontallyCentred))
  69682. dx = (totalW - lineW) / 2;
  69683. else if (justification.testFlags (Justification::right))
  69684. dx = totalW - lineW;
  69685. for (int j = tokens.size(); --j >= 0;)
  69686. {
  69687. Token* const t = tokens.getUnchecked(j);
  69688. if (t->line == i)
  69689. t->x += dx;
  69690. }
  69691. }
  69692. }
  69693. }
  69694. }
  69695. int TextLayout::getLineWidth (const int lineNumber) const
  69696. {
  69697. int maxW = 0;
  69698. for (int i = tokens.size(); --i >= 0;)
  69699. {
  69700. const Token* const t = tokens.getUnchecked(i);
  69701. if (t->line == lineNumber && ! t->isWhitespace)
  69702. maxW = jmax (maxW, t->x + t->w);
  69703. }
  69704. return maxW;
  69705. }
  69706. int TextLayout::getWidth() const
  69707. {
  69708. int maxW = 0;
  69709. for (int i = tokens.size(); --i >= 0;)
  69710. {
  69711. const Token* const t = tokens.getUnchecked(i);
  69712. if (! t->isWhitespace)
  69713. maxW = jmax (maxW, t->x + t->w);
  69714. }
  69715. return maxW;
  69716. }
  69717. int TextLayout::getHeight() const
  69718. {
  69719. int maxH = 0;
  69720. for (int i = tokens.size(); --i >= 0;)
  69721. {
  69722. const Token* const t = tokens.getUnchecked(i);
  69723. if (! t->isWhitespace)
  69724. maxH = jmax (maxH, t->y + t->h);
  69725. }
  69726. return maxH;
  69727. }
  69728. void TextLayout::draw (Graphics& g,
  69729. const int xOffset,
  69730. const int yOffset) const
  69731. {
  69732. for (int i = tokens.size(); --i >= 0;)
  69733. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  69734. }
  69735. void TextLayout::drawWithin (Graphics& g,
  69736. int x, int y, int w, int h,
  69737. const Justification& justification) const
  69738. {
  69739. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  69740. x, y, w, h);
  69741. draw (g, x, y);
  69742. }
  69743. END_JUCE_NAMESPACE
  69744. /*** End of inlined file: juce_TextLayout.cpp ***/
  69745. /*** Start of inlined file: juce_Typeface.cpp ***/
  69746. BEGIN_JUCE_NAMESPACE
  69747. Typeface::Typeface (const String& name_) throw()
  69748. : name (name_)
  69749. {
  69750. }
  69751. Typeface::~Typeface()
  69752. {
  69753. }
  69754. class CustomTypeface::GlyphInfo
  69755. {
  69756. public:
  69757. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  69758. : character (character_), path (path_), width (width_)
  69759. {
  69760. }
  69761. ~GlyphInfo() throw()
  69762. {
  69763. }
  69764. struct KerningPair
  69765. {
  69766. juce_wchar character2;
  69767. float kerningAmount;
  69768. };
  69769. void addKerningPair (const juce_wchar subsequentCharacter,
  69770. const float extraKerningAmount) throw()
  69771. {
  69772. KerningPair kp;
  69773. kp.character2 = subsequentCharacter;
  69774. kp.kerningAmount = extraKerningAmount;
  69775. kerningPairs.add (kp);
  69776. }
  69777. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  69778. {
  69779. if (subsequentCharacter != 0)
  69780. {
  69781. for (int i = kerningPairs.size(); --i >= 0;)
  69782. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  69783. return width + kerningPairs.getReference(i).kerningAmount;
  69784. }
  69785. return width;
  69786. }
  69787. const juce_wchar character;
  69788. const Path path;
  69789. float width;
  69790. Array <KerningPair> kerningPairs;
  69791. juce_UseDebuggingNewOperator
  69792. private:
  69793. GlyphInfo (const GlyphInfo&);
  69794. GlyphInfo& operator= (const GlyphInfo&);
  69795. };
  69796. CustomTypeface::CustomTypeface()
  69797. : Typeface (String::empty)
  69798. {
  69799. clear();
  69800. }
  69801. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  69802. : Typeface (String::empty)
  69803. {
  69804. clear();
  69805. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  69806. BufferedInputStream in (&gzin, 32768, false);
  69807. name = in.readString();
  69808. isBold = in.readBool();
  69809. isItalic = in.readBool();
  69810. ascent = in.readFloat();
  69811. defaultCharacter = (juce_wchar) in.readShort();
  69812. int i, numChars = in.readInt();
  69813. for (i = 0; i < numChars; ++i)
  69814. {
  69815. const juce_wchar c = (juce_wchar) in.readShort();
  69816. const float width = in.readFloat();
  69817. Path p;
  69818. p.loadPathFromStream (in);
  69819. addGlyph (c, p, width);
  69820. }
  69821. const int numKerningPairs = in.readInt();
  69822. for (i = 0; i < numKerningPairs; ++i)
  69823. {
  69824. const juce_wchar char1 = (juce_wchar) in.readShort();
  69825. const juce_wchar char2 = (juce_wchar) in.readShort();
  69826. addKerningPair (char1, char2, in.readFloat());
  69827. }
  69828. }
  69829. CustomTypeface::~CustomTypeface()
  69830. {
  69831. }
  69832. void CustomTypeface::clear()
  69833. {
  69834. defaultCharacter = 0;
  69835. ascent = 1.0f;
  69836. isBold = isItalic = false;
  69837. zeromem (lookupTable, sizeof (lookupTable));
  69838. glyphs.clear();
  69839. }
  69840. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  69841. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  69842. {
  69843. name = name_;
  69844. defaultCharacter = defaultCharacter_;
  69845. ascent = ascent_;
  69846. isBold = isBold_;
  69847. isItalic = isItalic_;
  69848. }
  69849. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  69850. {
  69851. // Check that you're not trying to add the same character twice..
  69852. jassert (findGlyph (character, false) == 0);
  69853. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  69854. lookupTable [character] = (short) glyphs.size();
  69855. glyphs.add (new GlyphInfo (character, path, width));
  69856. }
  69857. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  69858. {
  69859. if (extraAmount != 0)
  69860. {
  69861. GlyphInfo* const g = findGlyph (char1, true);
  69862. jassert (g != 0); // can only add kerning pairs for characters that exist!
  69863. if (g != 0)
  69864. g->addKerningPair (char2, extraAmount);
  69865. }
  69866. }
  69867. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  69868. {
  69869. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  69870. return glyphs [(int) lookupTable [(int) character]];
  69871. for (int i = 0; i < glyphs.size(); ++i)
  69872. {
  69873. GlyphInfo* const g = glyphs.getUnchecked(i);
  69874. if (g->character == character)
  69875. return g;
  69876. }
  69877. if (loadIfNeeded && loadGlyphIfPossible (character))
  69878. return findGlyph (character, false);
  69879. return 0;
  69880. }
  69881. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  69882. {
  69883. GlyphInfo* glyph = findGlyph (character, true);
  69884. if (glyph == 0)
  69885. {
  69886. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  69887. glyph = findGlyph (L' ', true);
  69888. if (glyph == 0)
  69889. {
  69890. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  69891. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  69892. if (fallbackTypeface != 0 && fallbackTypeface != this)
  69893. {
  69894. //xxx
  69895. }
  69896. if (glyph == 0)
  69897. glyph = findGlyph (defaultCharacter, true);
  69898. }
  69899. }
  69900. return glyph;
  69901. }
  69902. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  69903. {
  69904. return false;
  69905. }
  69906. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  69907. {
  69908. setCharacteristics (name, typefaceToCopy.getAscent(), isBold, isItalic, defaultCharacter);
  69909. for (int i = 0; i < numCharacters; ++i)
  69910. {
  69911. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  69912. Array <int> glyphIndexes;
  69913. Array <float> offsets;
  69914. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  69915. const int glyphIndex = glyphIndexes.getFirst();
  69916. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  69917. {
  69918. const float glyphWidth = offsets[1];
  69919. Path p;
  69920. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  69921. addGlyph (c, p, glyphWidth);
  69922. for (int j = glyphs.size() - 1; --j >= 0;)
  69923. {
  69924. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  69925. glyphIndexes.clearQuick();
  69926. offsets.clearQuick();
  69927. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  69928. if (offsets.size() > 1)
  69929. addKerningPair (c, char2, offsets[1] - glyphWidth);
  69930. }
  69931. }
  69932. }
  69933. }
  69934. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  69935. {
  69936. GZIPCompressorOutputStream out (&outputStream);
  69937. out.writeString (name);
  69938. out.writeBool (isBold);
  69939. out.writeBool (isItalic);
  69940. out.writeFloat (ascent);
  69941. out.writeShort ((short) (unsigned short) defaultCharacter);
  69942. out.writeInt (glyphs.size());
  69943. int i, numKerningPairs = 0;
  69944. for (i = 0; i < glyphs.size(); ++i)
  69945. {
  69946. const GlyphInfo* const g = glyphs.getUnchecked (i);
  69947. out.writeShort ((short) (unsigned short) g->character);
  69948. out.writeFloat (g->width);
  69949. g->path.writePathToStream (out);
  69950. numKerningPairs += g->kerningPairs.size();
  69951. }
  69952. out.writeInt (numKerningPairs);
  69953. for (i = 0; i < glyphs.size(); ++i)
  69954. {
  69955. const GlyphInfo* const g = glyphs.getUnchecked (i);
  69956. for (int j = 0; j < g->kerningPairs.size(); ++j)
  69957. {
  69958. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  69959. out.writeShort ((short) (unsigned short) g->character);
  69960. out.writeShort ((short) (unsigned short) p.character2);
  69961. out.writeFloat (p.kerningAmount);
  69962. }
  69963. }
  69964. return true;
  69965. }
  69966. float CustomTypeface::getAscent() const
  69967. {
  69968. return ascent;
  69969. }
  69970. float CustomTypeface::getDescent() const
  69971. {
  69972. return 1.0f - ascent;
  69973. }
  69974. float CustomTypeface::getStringWidth (const String& text)
  69975. {
  69976. float x = 0;
  69977. const juce_wchar* t = text;
  69978. while (*t != 0)
  69979. {
  69980. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  69981. if (glyph != 0)
  69982. x += glyph->getHorizontalSpacing (*t);
  69983. }
  69984. return x;
  69985. }
  69986. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  69987. {
  69988. xOffsets.add (0);
  69989. float x = 0;
  69990. const juce_wchar* t = text;
  69991. while (*t != 0)
  69992. {
  69993. const juce_wchar c = *t++;
  69994. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  69995. if (glyph != 0)
  69996. {
  69997. x += glyph->getHorizontalSpacing (*t);
  69998. resultGlyphs.add ((int) glyph->character);
  69999. xOffsets.add (x);
  70000. }
  70001. }
  70002. }
  70003. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70004. {
  70005. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70006. if (glyph != 0)
  70007. {
  70008. path = glyph->path;
  70009. return true;
  70010. }
  70011. return false;
  70012. }
  70013. END_JUCE_NAMESPACE
  70014. /*** End of inlined file: juce_Typeface.cpp ***/
  70015. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70016. BEGIN_JUCE_NAMESPACE
  70017. AffineTransform::AffineTransform() throw()
  70018. : mat00 (1.0f),
  70019. mat01 (0),
  70020. mat02 (0),
  70021. mat10 (0),
  70022. mat11 (1.0f),
  70023. mat12 (0)
  70024. {
  70025. }
  70026. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70027. : mat00 (other.mat00),
  70028. mat01 (other.mat01),
  70029. mat02 (other.mat02),
  70030. mat10 (other.mat10),
  70031. mat11 (other.mat11),
  70032. mat12 (other.mat12)
  70033. {
  70034. }
  70035. AffineTransform::AffineTransform (const float mat00_,
  70036. const float mat01_,
  70037. const float mat02_,
  70038. const float mat10_,
  70039. const float mat11_,
  70040. const float mat12_) throw()
  70041. : mat00 (mat00_),
  70042. mat01 (mat01_),
  70043. mat02 (mat02_),
  70044. mat10 (mat10_),
  70045. mat11 (mat11_),
  70046. mat12 (mat12_)
  70047. {
  70048. }
  70049. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70050. {
  70051. mat00 = other.mat00;
  70052. mat01 = other.mat01;
  70053. mat02 = other.mat02;
  70054. mat10 = other.mat10;
  70055. mat11 = other.mat11;
  70056. mat12 = other.mat12;
  70057. return *this;
  70058. }
  70059. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70060. {
  70061. return mat00 == other.mat00
  70062. && mat01 == other.mat01
  70063. && mat02 == other.mat02
  70064. && mat10 == other.mat10
  70065. && mat11 == other.mat11
  70066. && mat12 == other.mat12;
  70067. }
  70068. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70069. {
  70070. return ! operator== (other);
  70071. }
  70072. bool AffineTransform::isIdentity() const throw()
  70073. {
  70074. return (mat01 == 0)
  70075. && (mat02 == 0)
  70076. && (mat10 == 0)
  70077. && (mat12 == 0)
  70078. && (mat00 == 1.0f)
  70079. && (mat11 == 1.0f);
  70080. }
  70081. const AffineTransform AffineTransform::identity;
  70082. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70083. {
  70084. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70085. other.mat00 * mat01 + other.mat01 * mat11,
  70086. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70087. other.mat10 * mat00 + other.mat11 * mat10,
  70088. other.mat10 * mat01 + other.mat11 * mat11,
  70089. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70090. }
  70091. const AffineTransform AffineTransform::followedBy (const float omat00,
  70092. const float omat01,
  70093. const float omat02,
  70094. const float omat10,
  70095. const float omat11,
  70096. const float omat12) const throw()
  70097. {
  70098. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70099. omat00 * mat01 + omat01 * mat11,
  70100. omat00 * mat02 + omat01 * mat12 + omat02,
  70101. omat10 * mat00 + omat11 * mat10,
  70102. omat10 * mat01 + omat11 * mat11,
  70103. omat10 * mat02 + omat11 * mat12 + omat12);
  70104. }
  70105. const AffineTransform AffineTransform::translated (const float dx,
  70106. const float dy) const throw()
  70107. {
  70108. return AffineTransform (mat00, mat01, mat02 + dx,
  70109. mat10, mat11, mat12 + dy);
  70110. }
  70111. const AffineTransform AffineTransform::translation (const float dx,
  70112. const float dy) throw()
  70113. {
  70114. return AffineTransform (1.0f, 0, dx,
  70115. 0, 1.0f, dy);
  70116. }
  70117. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70118. {
  70119. const float cosRad = cosf (rad);
  70120. const float sinRad = sinf (rad);
  70121. return followedBy (cosRad, -sinRad, 0,
  70122. sinRad, cosRad, 0);
  70123. }
  70124. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70125. {
  70126. const float cosRad = cosf (rad);
  70127. const float sinRad = sinf (rad);
  70128. return AffineTransform (cosRad, -sinRad, 0,
  70129. sinRad, cosRad, 0);
  70130. }
  70131. const AffineTransform AffineTransform::rotated (const float angle,
  70132. const float pivotX,
  70133. const float pivotY) const throw()
  70134. {
  70135. return translated (-pivotX, -pivotY)
  70136. .rotated (angle)
  70137. .translated (pivotX, pivotY);
  70138. }
  70139. const AffineTransform AffineTransform::rotation (const float angle,
  70140. const float pivotX,
  70141. const float pivotY) throw()
  70142. {
  70143. return translation (-pivotX, -pivotY)
  70144. .rotated (angle)
  70145. .translated (pivotX, pivotY);
  70146. }
  70147. const AffineTransform AffineTransform::scaled (const float factorX,
  70148. const float factorY) const throw()
  70149. {
  70150. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70151. factorY * mat10, factorY * mat11, factorY * mat12);
  70152. }
  70153. const AffineTransform AffineTransform::scale (const float factorX,
  70154. const float factorY) throw()
  70155. {
  70156. return AffineTransform (factorX, 0, 0,
  70157. 0, factorY, 0);
  70158. }
  70159. const AffineTransform AffineTransform::sheared (const float shearX,
  70160. const float shearY) const throw()
  70161. {
  70162. return followedBy (1.0f, shearX, 0,
  70163. shearY, 1.0f, 0);
  70164. }
  70165. const AffineTransform AffineTransform::inverted() const throw()
  70166. {
  70167. double determinant = (mat00 * mat11 - mat10 * mat01);
  70168. if (determinant != 0.0)
  70169. {
  70170. determinant = 1.0 / determinant;
  70171. const float dst00 = (float) (mat11 * determinant);
  70172. const float dst10 = (float) (-mat10 * determinant);
  70173. const float dst01 = (float) (-mat01 * determinant);
  70174. const float dst11 = (float) (mat00 * determinant);
  70175. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70176. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70177. }
  70178. else
  70179. {
  70180. // singularity..
  70181. return *this;
  70182. }
  70183. }
  70184. bool AffineTransform::isSingularity() const throw()
  70185. {
  70186. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70187. }
  70188. bool AffineTransform::isOnlyTranslation() const throw()
  70189. {
  70190. return (mat01 == 0)
  70191. && (mat10 == 0)
  70192. && (mat00 == 1.0f)
  70193. && (mat11 == 1.0f);
  70194. }
  70195. void AffineTransform::transformPoint (float& x,
  70196. float& y) const throw()
  70197. {
  70198. const float oldX = x;
  70199. x = mat00 * oldX + mat01 * y + mat02;
  70200. y = mat10 * oldX + mat11 * y + mat12;
  70201. }
  70202. void AffineTransform::transformPoint (double& x,
  70203. double& y) const throw()
  70204. {
  70205. const double oldX = x;
  70206. x = mat00 * oldX + mat01 * y + mat02;
  70207. y = mat10 * oldX + mat11 * y + mat12;
  70208. }
  70209. END_JUCE_NAMESPACE
  70210. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70211. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70212. BEGIN_JUCE_NAMESPACE
  70213. BorderSize::BorderSize() throw()
  70214. : top (0),
  70215. left (0),
  70216. bottom (0),
  70217. right (0)
  70218. {
  70219. }
  70220. BorderSize::BorderSize (const BorderSize& other) throw()
  70221. : top (other.top),
  70222. left (other.left),
  70223. bottom (other.bottom),
  70224. right (other.right)
  70225. {
  70226. }
  70227. BorderSize::BorderSize (const int topGap,
  70228. const int leftGap,
  70229. const int bottomGap,
  70230. const int rightGap) throw()
  70231. : top (topGap),
  70232. left (leftGap),
  70233. bottom (bottomGap),
  70234. right (rightGap)
  70235. {
  70236. }
  70237. BorderSize::BorderSize (const int allGaps) throw()
  70238. : top (allGaps),
  70239. left (allGaps),
  70240. bottom (allGaps),
  70241. right (allGaps)
  70242. {
  70243. }
  70244. BorderSize::~BorderSize() throw()
  70245. {
  70246. }
  70247. void BorderSize::setTop (const int newTopGap) throw()
  70248. {
  70249. top = newTopGap;
  70250. }
  70251. void BorderSize::setLeft (const int newLeftGap) throw()
  70252. {
  70253. left = newLeftGap;
  70254. }
  70255. void BorderSize::setBottom (const int newBottomGap) throw()
  70256. {
  70257. bottom = newBottomGap;
  70258. }
  70259. void BorderSize::setRight (const int newRightGap) throw()
  70260. {
  70261. right = newRightGap;
  70262. }
  70263. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70264. {
  70265. return Rectangle<int> (r.getX() + left,
  70266. r.getY() + top,
  70267. r.getWidth() - (left + right),
  70268. r.getHeight() - (top + bottom));
  70269. }
  70270. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70271. {
  70272. r.setBounds (r.getX() + left,
  70273. r.getY() + top,
  70274. r.getWidth() - (left + right),
  70275. r.getHeight() - (top + bottom));
  70276. }
  70277. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70278. {
  70279. return Rectangle<int> (r.getX() - left,
  70280. r.getY() - top,
  70281. r.getWidth() + (left + right),
  70282. r.getHeight() + (top + bottom));
  70283. }
  70284. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70285. {
  70286. r.setBounds (r.getX() - left,
  70287. r.getY() - top,
  70288. r.getWidth() + (left + right),
  70289. r.getHeight() + (top + bottom));
  70290. }
  70291. bool BorderSize::operator== (const BorderSize& other) const throw()
  70292. {
  70293. return top == other.top
  70294. && left == other.left
  70295. && bottom == other.bottom
  70296. && right == other.right;
  70297. }
  70298. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70299. {
  70300. return ! operator== (other);
  70301. }
  70302. END_JUCE_NAMESPACE
  70303. /*** End of inlined file: juce_BorderSize.cpp ***/
  70304. /*** Start of inlined file: juce_Line.cpp ***/
  70305. BEGIN_JUCE_NAMESPACE
  70306. static bool juce_lineIntersection (const float x1, const float y1,
  70307. const float x2, const float y2,
  70308. const float x3, const float y3,
  70309. const float x4, const float y4,
  70310. float& intersectionX,
  70311. float& intersectionY) throw()
  70312. {
  70313. if (x2 != x3 || y2 != y3)
  70314. {
  70315. const float dx1 = x2 - x1;
  70316. const float dy1 = y2 - y1;
  70317. const float dx2 = x4 - x3;
  70318. const float dy2 = y4 - y3;
  70319. const float divisor = dx1 * dy2 - dx2 * dy1;
  70320. if (divisor == 0)
  70321. {
  70322. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70323. {
  70324. if (dy1 == 0 && dy2 != 0)
  70325. {
  70326. const float along = (y1 - y3) / dy2;
  70327. intersectionX = x3 + along * dx2;
  70328. intersectionY = y1;
  70329. return along >= 0 && along <= 1.0f;
  70330. }
  70331. else if (dy2 == 0 && dy1 != 0)
  70332. {
  70333. const float along = (y3 - y1) / dy1;
  70334. intersectionX = x1 + along * dx1;
  70335. intersectionY = y3;
  70336. return along >= 0 && along <= 1.0f;
  70337. }
  70338. else if (dx1 == 0 && dx2 != 0)
  70339. {
  70340. const float along = (x1 - x3) / dx2;
  70341. intersectionX = x1;
  70342. intersectionY = y3 + along * dy2;
  70343. return along >= 0 && along <= 1.0f;
  70344. }
  70345. else if (dx2 == 0 && dx1 != 0)
  70346. {
  70347. const float along = (x3 - x1) / dx1;
  70348. intersectionX = x3;
  70349. intersectionY = y1 + along * dy1;
  70350. return along >= 0 && along <= 1.0f;
  70351. }
  70352. }
  70353. intersectionX = 0.5f * (x2 + x3);
  70354. intersectionY = 0.5f * (y2 + y3);
  70355. return false;
  70356. }
  70357. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70358. intersectionX = x1 + along1 * dx1;
  70359. intersectionY = y1 + along1 * dy1;
  70360. if (along1 < 0 || along1 > 1.0f)
  70361. return false;
  70362. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70363. return along2 >= 0 && along2 <= 1.0f;
  70364. }
  70365. intersectionX = x2;
  70366. intersectionY = y2;
  70367. return true;
  70368. }
  70369. Line::Line() throw()
  70370. : startX (0.0f),
  70371. startY (0.0f),
  70372. endX (0.0f),
  70373. endY (0.0f)
  70374. {
  70375. }
  70376. Line::Line (const Line& other) throw()
  70377. : startX (other.startX),
  70378. startY (other.startY),
  70379. endX (other.endX),
  70380. endY (other.endY)
  70381. {
  70382. }
  70383. Line::Line (const float startX_, const float startY_,
  70384. const float endX_, const float endY_) throw()
  70385. : startX (startX_),
  70386. startY (startY_),
  70387. endX (endX_),
  70388. endY (endY_)
  70389. {
  70390. }
  70391. Line::Line (const Point<float>& start,
  70392. const Point<float>& end) throw()
  70393. : startX (start.getX()),
  70394. startY (start.getY()),
  70395. endX (end.getX()),
  70396. endY (end.getY())
  70397. {
  70398. }
  70399. Line& Line::operator= (const Line& other) throw()
  70400. {
  70401. startX = other.startX;
  70402. startY = other.startY;
  70403. endX = other.endX;
  70404. endY = other.endY;
  70405. return *this;
  70406. }
  70407. Line::~Line() throw()
  70408. {
  70409. }
  70410. const Point<float> Line::getStart() const throw()
  70411. {
  70412. return Point<float> (startX, startY);
  70413. }
  70414. const Point<float> Line::getEnd() const throw()
  70415. {
  70416. return Point<float> (endX, endY);
  70417. }
  70418. void Line::setStart (const float newStartX,
  70419. const float newStartY) throw()
  70420. {
  70421. startX = newStartX;
  70422. startY = newStartY;
  70423. }
  70424. void Line::setStart (const Point<float>& newStart) throw()
  70425. {
  70426. startX = newStart.getX();
  70427. startY = newStart.getY();
  70428. }
  70429. void Line::setEnd (const float newEndX,
  70430. const float newEndY) throw()
  70431. {
  70432. endX = newEndX;
  70433. endY = newEndY;
  70434. }
  70435. void Line::setEnd (const Point<float>& newEnd) throw()
  70436. {
  70437. endX = newEnd.getX();
  70438. endY = newEnd.getY();
  70439. }
  70440. bool Line::operator== (const Line& other) const throw()
  70441. {
  70442. return startX == other.startX
  70443. && startY == other.startY
  70444. && endX == other.endX
  70445. && endY == other.endY;
  70446. }
  70447. bool Line::operator!= (const Line& other) const throw()
  70448. {
  70449. return startX != other.startX
  70450. || startY != other.startY
  70451. || endX != other.endX
  70452. || endY != other.endY;
  70453. }
  70454. void Line::applyTransform (const AffineTransform& transform) throw()
  70455. {
  70456. transform.transformPoint (startX, startY);
  70457. transform.transformPoint (endX, endY);
  70458. }
  70459. float Line::getLength() const throw()
  70460. {
  70461. return (float) juce_hypot (startX - endX,
  70462. startY - endY);
  70463. }
  70464. float Line::getAngle() const throw()
  70465. {
  70466. return atan2f (endX - startX,
  70467. endY - startY);
  70468. }
  70469. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70470. {
  70471. const float alpha = distanceFromStart / getLength();
  70472. return Point<float> (startX + (endX - startX) * alpha,
  70473. startY + (endY - startY) * alpha);
  70474. }
  70475. const Point<float> Line::getPointAlongLine (const float offsetX,
  70476. const float offsetY) const throw()
  70477. {
  70478. const float dx = endX - startX;
  70479. const float dy = endY - startY;
  70480. const double length = juce_hypot (dx, dy);
  70481. if (length == 0)
  70482. return Point<float> (startX, startY);
  70483. else
  70484. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70485. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70486. }
  70487. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70488. {
  70489. return Point<float> (startX + (endX - startX) * alpha,
  70490. startY + (endY - startY) * alpha);
  70491. }
  70492. float Line::getDistanceFromLine (const float x,
  70493. const float y) const throw()
  70494. {
  70495. const double dx = endX - startX;
  70496. const double dy = endY - startY;
  70497. const double length = dx * dx + dy * dy;
  70498. if (length > 0)
  70499. {
  70500. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  70501. if (prop >= 0.0f && prop < 1.0f)
  70502. {
  70503. return (float) juce_hypot (x - (startX + prop * dx),
  70504. y - (startY + prop * dy));
  70505. }
  70506. }
  70507. return (float) jmin (juce_hypot (x - startX, y - startY),
  70508. juce_hypot (x - endX, y - endY));
  70509. }
  70510. float Line::findNearestPointTo (const float x,
  70511. const float y) const throw()
  70512. {
  70513. const double dx = endX - startX;
  70514. const double dy = endY - startY;
  70515. const double length = dx * dx + dy * dy;
  70516. if (length <= 0.0)
  70517. return 0.0f;
  70518. return jlimit (0.0f, 1.0f,
  70519. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  70520. }
  70521. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  70522. {
  70523. const float length = getLength();
  70524. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  70525. getEnd());
  70526. }
  70527. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  70528. {
  70529. const float length = getLength();
  70530. return Line (getStart(),
  70531. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  70532. }
  70533. bool Line::clipToPath (const Path& path,
  70534. const bool keepSectionOutsidePath) throw()
  70535. {
  70536. const bool startInside = path.contains (startX, startY);
  70537. const bool endInside = path.contains (endX, endY);
  70538. if (startInside == endInside)
  70539. {
  70540. if (keepSectionOutsidePath != startInside)
  70541. {
  70542. // entirely outside the path
  70543. return false;
  70544. }
  70545. else
  70546. {
  70547. // entirely inside the path
  70548. startX = 0.0f;
  70549. startY = 0.0f;
  70550. endX = 0.0f;
  70551. endY = 0.0f;
  70552. return true;
  70553. }
  70554. }
  70555. else
  70556. {
  70557. bool changed = false;
  70558. PathFlatteningIterator iter (path, AffineTransform::identity);
  70559. while (iter.next())
  70560. {
  70561. float ix, iy;
  70562. if (intersects (Line (iter.x1, iter.y1,
  70563. iter.x2, iter.y2),
  70564. ix, iy))
  70565. {
  70566. if ((startInside && keepSectionOutsidePath)
  70567. || (endInside && ! keepSectionOutsidePath))
  70568. {
  70569. setStart (ix, iy);
  70570. }
  70571. else
  70572. {
  70573. setEnd (ix, iy);
  70574. }
  70575. changed = true;
  70576. }
  70577. }
  70578. return changed;
  70579. }
  70580. }
  70581. bool Line::intersects (const Line& line,
  70582. float& intersectionX,
  70583. float& intersectionY) const throw()
  70584. {
  70585. return juce_lineIntersection (startX, startY,
  70586. endX, endY,
  70587. line.startX, line.startY,
  70588. line.endX, line.endY,
  70589. intersectionX,
  70590. intersectionY);
  70591. }
  70592. bool Line::isVertical() const throw()
  70593. {
  70594. return startX == endX;
  70595. }
  70596. bool Line::isHorizontal() const throw()
  70597. {
  70598. return startY == endY;
  70599. }
  70600. bool Line::isPointAbove (const float x, const float y) const throw()
  70601. {
  70602. return startX != endX
  70603. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  70604. }
  70605. END_JUCE_NAMESPACE
  70606. /*** End of inlined file: juce_Line.cpp ***/
  70607. /*** Start of inlined file: juce_Path.cpp ***/
  70608. BEGIN_JUCE_NAMESPACE
  70609. // tests that some co-ords aren't NaNs
  70610. #define CHECK_COORDS_ARE_VALID(x, y) \
  70611. jassert (x == x && y == y);
  70612. namespace PathHelpers
  70613. {
  70614. static const float ellipseAngularIncrement = 0.05f;
  70615. static void perpendicularOffset (const float x1, const float y1,
  70616. const float x2, const float y2,
  70617. const float offsetX, const float offsetY,
  70618. float& resultX, float& resultY) throw()
  70619. {
  70620. const float dx = x2 - x1;
  70621. const float dy = y2 - y1;
  70622. const float len = juce_hypotf (dx, dy);
  70623. if (len == 0)
  70624. {
  70625. resultX = x1;
  70626. resultY = y1;
  70627. }
  70628. else
  70629. {
  70630. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  70631. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  70632. }
  70633. }
  70634. static const String nextToken (const juce_wchar*& t)
  70635. {
  70636. while (CharacterFunctions::isWhitespace (*t))
  70637. ++t;
  70638. const juce_wchar* const start = t;
  70639. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  70640. ++t;
  70641. const int length = (int) (t - start);
  70642. while (CharacterFunctions::isWhitespace (*t))
  70643. ++t;
  70644. return String (start, length);
  70645. }
  70646. }
  70647. const float Path::lineMarker = 100001.0f;
  70648. const float Path::moveMarker = 100002.0f;
  70649. const float Path::quadMarker = 100003.0f;
  70650. const float Path::cubicMarker = 100004.0f;
  70651. const float Path::closeSubPathMarker = 100005.0f;
  70652. Path::Path()
  70653. : numElements (0),
  70654. pathXMin (0),
  70655. pathXMax (0),
  70656. pathYMin (0),
  70657. pathYMax (0),
  70658. useNonZeroWinding (true)
  70659. {
  70660. }
  70661. Path::~Path()
  70662. {
  70663. }
  70664. Path::Path (const Path& other)
  70665. : numElements (other.numElements),
  70666. pathXMin (other.pathXMin),
  70667. pathXMax (other.pathXMax),
  70668. pathYMin (other.pathYMin),
  70669. pathYMax (other.pathYMax),
  70670. useNonZeroWinding (other.useNonZeroWinding)
  70671. {
  70672. if (numElements > 0)
  70673. {
  70674. data.setAllocatedSize (numElements);
  70675. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70676. }
  70677. }
  70678. Path& Path::operator= (const Path& other)
  70679. {
  70680. if (this != &other)
  70681. {
  70682. data.ensureAllocatedSize (other.numElements);
  70683. numElements = other.numElements;
  70684. pathXMin = other.pathXMin;
  70685. pathXMax = other.pathXMax;
  70686. pathYMin = other.pathYMin;
  70687. pathYMax = other.pathYMax;
  70688. useNonZeroWinding = other.useNonZeroWinding;
  70689. if (numElements > 0)
  70690. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  70691. }
  70692. return *this;
  70693. }
  70694. void Path::clear() throw()
  70695. {
  70696. numElements = 0;
  70697. pathXMin = 0;
  70698. pathYMin = 0;
  70699. pathYMax = 0;
  70700. pathXMax = 0;
  70701. }
  70702. void Path::swapWithPath (Path& other)
  70703. {
  70704. data.swapWith (other.data);
  70705. swapVariables <size_t> (numElements, other.numElements);
  70706. swapVariables <float> (pathXMin, other.pathXMin);
  70707. swapVariables <float> (pathXMax, other.pathXMax);
  70708. swapVariables <float> (pathYMin, other.pathYMin);
  70709. swapVariables <float> (pathYMax, other.pathYMax);
  70710. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  70711. }
  70712. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  70713. {
  70714. useNonZeroWinding = isNonZero;
  70715. }
  70716. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  70717. const bool preserveProportions) throw()
  70718. {
  70719. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  70720. }
  70721. bool Path::isEmpty() const throw()
  70722. {
  70723. size_t i = 0;
  70724. while (i < numElements)
  70725. {
  70726. const float type = data.elements [i++];
  70727. if (type == moveMarker)
  70728. {
  70729. i += 2;
  70730. }
  70731. else if (type == lineMarker
  70732. || type == quadMarker
  70733. || type == cubicMarker)
  70734. {
  70735. return false;
  70736. }
  70737. }
  70738. return true;
  70739. }
  70740. const Rectangle<float> Path::getBounds() const throw()
  70741. {
  70742. return Rectangle<float> (pathXMin, pathYMin,
  70743. pathXMax - pathXMin,
  70744. pathYMax - pathYMin);
  70745. }
  70746. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  70747. {
  70748. return getBounds().transformed (transform);
  70749. }
  70750. void Path::startNewSubPath (const float x, const float y)
  70751. {
  70752. CHECK_COORDS_ARE_VALID (x, y);
  70753. if (numElements == 0)
  70754. {
  70755. pathXMin = pathXMax = x;
  70756. pathYMin = pathYMax = y;
  70757. }
  70758. else
  70759. {
  70760. pathXMin = jmin (pathXMin, x);
  70761. pathXMax = jmax (pathXMax, x);
  70762. pathYMin = jmin (pathYMin, y);
  70763. pathYMax = jmax (pathYMax, y);
  70764. }
  70765. data.ensureAllocatedSize (numElements + 3);
  70766. data.elements [numElements++] = moveMarker;
  70767. data.elements [numElements++] = x;
  70768. data.elements [numElements++] = y;
  70769. }
  70770. void Path::lineTo (const float x, const float y)
  70771. {
  70772. CHECK_COORDS_ARE_VALID (x, y);
  70773. if (numElements == 0)
  70774. startNewSubPath (0, 0);
  70775. data.ensureAllocatedSize (numElements + 3);
  70776. data.elements [numElements++] = lineMarker;
  70777. data.elements [numElements++] = x;
  70778. data.elements [numElements++] = y;
  70779. pathXMin = jmin (pathXMin, x);
  70780. pathXMax = jmax (pathXMax, x);
  70781. pathYMin = jmin (pathYMin, y);
  70782. pathYMax = jmax (pathYMax, y);
  70783. }
  70784. void Path::quadraticTo (const float x1, const float y1,
  70785. const float x2, const float y2)
  70786. {
  70787. CHECK_COORDS_ARE_VALID (x1, y1);
  70788. CHECK_COORDS_ARE_VALID (x2, y2);
  70789. if (numElements == 0)
  70790. startNewSubPath (0, 0);
  70791. data.ensureAllocatedSize (numElements + 5);
  70792. data.elements [numElements++] = quadMarker;
  70793. data.elements [numElements++] = x1;
  70794. data.elements [numElements++] = y1;
  70795. data.elements [numElements++] = x2;
  70796. data.elements [numElements++] = y2;
  70797. pathXMin = jmin (pathXMin, x1, x2);
  70798. pathXMax = jmax (pathXMax, x1, x2);
  70799. pathYMin = jmin (pathYMin, y1, y2);
  70800. pathYMax = jmax (pathYMax, y1, y2);
  70801. }
  70802. void Path::cubicTo (const float x1, const float y1,
  70803. const float x2, const float y2,
  70804. const float x3, const float y3)
  70805. {
  70806. CHECK_COORDS_ARE_VALID (x1, y1);
  70807. CHECK_COORDS_ARE_VALID (x2, y2);
  70808. CHECK_COORDS_ARE_VALID (x3, y3);
  70809. if (numElements == 0)
  70810. startNewSubPath (0, 0);
  70811. data.ensureAllocatedSize (numElements + 7);
  70812. data.elements [numElements++] = cubicMarker;
  70813. data.elements [numElements++] = x1;
  70814. data.elements [numElements++] = y1;
  70815. data.elements [numElements++] = x2;
  70816. data.elements [numElements++] = y2;
  70817. data.elements [numElements++] = x3;
  70818. data.elements [numElements++] = y3;
  70819. pathXMin = jmin (pathXMin, x1, x2, x3);
  70820. pathXMax = jmax (pathXMax, x1, x2, x3);
  70821. pathYMin = jmin (pathYMin, y1, y2, y3);
  70822. pathYMax = jmax (pathYMax, y1, y2, y3);
  70823. }
  70824. void Path::closeSubPath()
  70825. {
  70826. if (numElements > 0
  70827. && data.elements [numElements - 1] != closeSubPathMarker)
  70828. {
  70829. data.ensureAllocatedSize (numElements + 1);
  70830. data.elements [numElements++] = closeSubPathMarker;
  70831. }
  70832. }
  70833. const Point<float> Path::getCurrentPosition() const
  70834. {
  70835. int i = numElements - 1;
  70836. if (i > 0 && data.elements[i] == closeSubPathMarker)
  70837. {
  70838. while (i >= 0)
  70839. {
  70840. if (data.elements[i] == moveMarker)
  70841. {
  70842. i += 2;
  70843. break;
  70844. }
  70845. --i;
  70846. }
  70847. }
  70848. if (i > 0)
  70849. return Point<float> (data.elements [i - 1], data.elements [i]);
  70850. return Point<float>();
  70851. }
  70852. void Path::addRectangle (const float x, const float y,
  70853. const float w, const float h)
  70854. {
  70855. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  70856. if (w < 0)
  70857. swapVariables (x1, x2);
  70858. if (h < 0)
  70859. swapVariables (y1, y2);
  70860. data.ensureAllocatedSize (numElements + 13);
  70861. if (numElements == 0)
  70862. {
  70863. pathXMin = x1;
  70864. pathXMax = x2;
  70865. pathYMin = y1;
  70866. pathYMax = y2;
  70867. }
  70868. else
  70869. {
  70870. pathXMin = jmin (pathXMin, x1);
  70871. pathXMax = jmax (pathXMax, x2);
  70872. pathYMin = jmin (pathYMin, y1);
  70873. pathYMax = jmax (pathYMax, y2);
  70874. }
  70875. data.elements [numElements++] = moveMarker;
  70876. data.elements [numElements++] = x1;
  70877. data.elements [numElements++] = y2;
  70878. data.elements [numElements++] = lineMarker;
  70879. data.elements [numElements++] = x1;
  70880. data.elements [numElements++] = y1;
  70881. data.elements [numElements++] = lineMarker;
  70882. data.elements [numElements++] = x2;
  70883. data.elements [numElements++] = y1;
  70884. data.elements [numElements++] = lineMarker;
  70885. data.elements [numElements++] = x2;
  70886. data.elements [numElements++] = y2;
  70887. data.elements [numElements++] = closeSubPathMarker;
  70888. }
  70889. void Path::addRectangle (const Rectangle<int>& rectangle)
  70890. {
  70891. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  70892. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  70893. }
  70894. void Path::addRoundedRectangle (const float x, const float y,
  70895. const float w, const float h,
  70896. float csx,
  70897. float csy)
  70898. {
  70899. csx = jmin (csx, w * 0.5f);
  70900. csy = jmin (csy, h * 0.5f);
  70901. const float cs45x = csx * 0.45f;
  70902. const float cs45y = csy * 0.45f;
  70903. const float x2 = x + w;
  70904. const float y2 = y + h;
  70905. startNewSubPath (x + csx, y);
  70906. lineTo (x2 - csx, y);
  70907. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  70908. lineTo (x2, y2 - csy);
  70909. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  70910. lineTo (x + csx, y2);
  70911. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  70912. lineTo (x, y + csy);
  70913. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  70914. closeSubPath();
  70915. }
  70916. void Path::addRoundedRectangle (const float x, const float y,
  70917. const float w, const float h,
  70918. float cs)
  70919. {
  70920. addRoundedRectangle (x, y, w, h, cs, cs);
  70921. }
  70922. void Path::addTriangle (const float x1, const float y1,
  70923. const float x2, const float y2,
  70924. const float x3, const float y3)
  70925. {
  70926. startNewSubPath (x1, y1);
  70927. lineTo (x2, y2);
  70928. lineTo (x3, y3);
  70929. closeSubPath();
  70930. }
  70931. void Path::addQuadrilateral (const float x1, const float y1,
  70932. const float x2, const float y2,
  70933. const float x3, const float y3,
  70934. const float x4, const float y4)
  70935. {
  70936. startNewSubPath (x1, y1);
  70937. lineTo (x2, y2);
  70938. lineTo (x3, y3);
  70939. lineTo (x4, y4);
  70940. closeSubPath();
  70941. }
  70942. void Path::addEllipse (const float x, const float y,
  70943. const float w, const float h)
  70944. {
  70945. const float hw = w * 0.5f;
  70946. const float hw55 = hw * 0.55f;
  70947. const float hh = h * 0.5f;
  70948. const float hh45 = hh * 0.55f;
  70949. const float cx = x + hw;
  70950. const float cy = y + hh;
  70951. startNewSubPath (cx, cy - hh);
  70952. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  70953. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  70954. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  70955. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  70956. closeSubPath();
  70957. }
  70958. void Path::addArc (const float x, const float y,
  70959. const float w, const float h,
  70960. const float fromRadians,
  70961. const float toRadians,
  70962. const bool startAsNewSubPath)
  70963. {
  70964. const float radiusX = w / 2.0f;
  70965. const float radiusY = h / 2.0f;
  70966. addCentredArc (x + radiusX,
  70967. y + radiusY,
  70968. radiusX, radiusY,
  70969. 0.0f,
  70970. fromRadians, toRadians,
  70971. startAsNewSubPath);
  70972. }
  70973. void Path::addCentredArc (const float centreX, const float centreY,
  70974. const float radiusX, const float radiusY,
  70975. const float rotationOfEllipse,
  70976. const float fromRadians,
  70977. const float toRadians,
  70978. const bool startAsNewSubPath)
  70979. {
  70980. if (radiusX > 0.0f && radiusY > 0.0f)
  70981. {
  70982. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  70983. float angle = fromRadians;
  70984. if (startAsNewSubPath)
  70985. {
  70986. float x = centreX + radiusX * sinf (angle);
  70987. float y = centreY - radiusY * cosf (angle);
  70988. if (rotationOfEllipse != 0)
  70989. rotation.transformPoint (x, y);
  70990. startNewSubPath (x, y);
  70991. }
  70992. if (fromRadians < toRadians)
  70993. {
  70994. if (startAsNewSubPath)
  70995. angle += PathHelpers::ellipseAngularIncrement;
  70996. while (angle < toRadians)
  70997. {
  70998. float x = centreX + radiusX * sinf (angle);
  70999. float y = centreY - radiusY * cosf (angle);
  71000. if (rotationOfEllipse != 0)
  71001. rotation.transformPoint (x, y);
  71002. lineTo (x, y);
  71003. angle += PathHelpers::ellipseAngularIncrement;
  71004. }
  71005. }
  71006. else
  71007. {
  71008. if (startAsNewSubPath)
  71009. angle -= PathHelpers::ellipseAngularIncrement;
  71010. while (angle > toRadians)
  71011. {
  71012. float x = centreX + radiusX * sinf (angle);
  71013. float y = centreY - radiusY * cosf (angle);
  71014. if (rotationOfEllipse != 0)
  71015. rotation.transformPoint (x, y);
  71016. lineTo (x, y);
  71017. angle -= PathHelpers::ellipseAngularIncrement;
  71018. }
  71019. }
  71020. float x = centreX + radiusX * sinf (toRadians);
  71021. float y = centreY - radiusY * cosf (toRadians);
  71022. if (rotationOfEllipse != 0)
  71023. rotation.transformPoint (x, y);
  71024. lineTo (x, y);
  71025. }
  71026. }
  71027. void Path::addPieSegment (const float x, const float y,
  71028. const float width, const float height,
  71029. const float fromRadians,
  71030. const float toRadians,
  71031. const float innerCircleProportionalSize)
  71032. {
  71033. float hw = width * 0.5f;
  71034. float hh = height * 0.5f;
  71035. const float centreX = x + hw;
  71036. const float centreY = y + hh;
  71037. startNewSubPath (centreX + hw * sinf (fromRadians),
  71038. centreY - hh * cosf (fromRadians));
  71039. addArc (x, y, width, height, fromRadians, toRadians);
  71040. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71041. {
  71042. closeSubPath();
  71043. if (innerCircleProportionalSize > 0)
  71044. {
  71045. hw *= innerCircleProportionalSize;
  71046. hh *= innerCircleProportionalSize;
  71047. startNewSubPath (centreX + hw * sinf (toRadians),
  71048. centreY - hh * cosf (toRadians));
  71049. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71050. toRadians, fromRadians);
  71051. }
  71052. }
  71053. else
  71054. {
  71055. if (innerCircleProportionalSize > 0)
  71056. {
  71057. hw *= innerCircleProportionalSize;
  71058. hh *= innerCircleProportionalSize;
  71059. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71060. toRadians, fromRadians);
  71061. }
  71062. else
  71063. {
  71064. lineTo (centreX, centreY);
  71065. }
  71066. }
  71067. closeSubPath();
  71068. }
  71069. void Path::addLineSegment (const float startX, const float startY,
  71070. const float endX, const float endY,
  71071. float lineThickness)
  71072. {
  71073. lineThickness *= 0.5f;
  71074. float x, y;
  71075. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71076. 0, lineThickness, x, y);
  71077. startNewSubPath (x, y);
  71078. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71079. 0, -lineThickness, x, y);
  71080. lineTo (x, y);
  71081. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71082. 0, lineThickness, x, y);
  71083. lineTo (x, y);
  71084. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71085. 0, -lineThickness, x, y);
  71086. lineTo (x, y);
  71087. closeSubPath();
  71088. }
  71089. void Path::addArrow (const float startX, const float startY,
  71090. const float endX, const float endY,
  71091. float lineThickness,
  71092. float arrowheadWidth,
  71093. float arrowheadLength)
  71094. {
  71095. lineThickness *= 0.5f;
  71096. arrowheadWidth *= 0.5f;
  71097. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71098. startY - endY));
  71099. float x, y;
  71100. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71101. 0, lineThickness, x, y);
  71102. startNewSubPath (x, y);
  71103. PathHelpers::perpendicularOffset (startX, startY, endX, endY,
  71104. 0, -lineThickness, x, y);
  71105. lineTo (x, y);
  71106. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71107. arrowheadLength, lineThickness, x, y);
  71108. lineTo (x, y);
  71109. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71110. arrowheadLength, arrowheadWidth, x, y);
  71111. lineTo (x, y);
  71112. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71113. 0, 0, x, y);
  71114. lineTo (x, y);
  71115. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71116. arrowheadLength, -arrowheadWidth, x, y);
  71117. lineTo (x, y);
  71118. PathHelpers::perpendicularOffset (endX, endY, startX, startY,
  71119. arrowheadLength, -lineThickness, x, y);
  71120. lineTo (x, y);
  71121. closeSubPath();
  71122. }
  71123. void Path::addStar (const float centreX,
  71124. const float centreY,
  71125. const int numberOfPoints,
  71126. const float innerRadius,
  71127. const float outerRadius,
  71128. const float startAngle)
  71129. {
  71130. jassert (numberOfPoints > 1); // this would be silly.
  71131. if (numberOfPoints > 1)
  71132. {
  71133. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71134. for (int i = 0; i < numberOfPoints; ++i)
  71135. {
  71136. float angle = startAngle + i * angleBetweenPoints;
  71137. const float x = centreX + outerRadius * sinf (angle);
  71138. const float y = centreY - outerRadius * cosf (angle);
  71139. if (i == 0)
  71140. startNewSubPath (x, y);
  71141. else
  71142. lineTo (x, y);
  71143. angle += angleBetweenPoints * 0.5f;
  71144. lineTo (centreX + innerRadius * sinf (angle),
  71145. centreY - innerRadius * cosf (angle));
  71146. }
  71147. closeSubPath();
  71148. }
  71149. }
  71150. void Path::addBubble (float x, float y,
  71151. float w, float h,
  71152. float cs,
  71153. float tipX,
  71154. float tipY,
  71155. int whichSide,
  71156. float arrowPos,
  71157. float arrowWidth)
  71158. {
  71159. if (w > 1.0f && h > 1.0f)
  71160. {
  71161. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71162. const float cs2 = 2.0f * cs;
  71163. startNewSubPath (x + cs, y);
  71164. if (whichSide == 0)
  71165. {
  71166. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71167. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71168. lineTo (arrowX1, y);
  71169. lineTo (tipX, tipY);
  71170. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71171. }
  71172. lineTo (x + w - cs, y);
  71173. if (cs > 0.0f)
  71174. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71175. if (whichSide == 3)
  71176. {
  71177. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71178. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71179. lineTo (x + w, arrowY1);
  71180. lineTo (tipX, tipY);
  71181. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71182. }
  71183. lineTo (x + w, y + h - cs);
  71184. if (cs > 0.0f)
  71185. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71186. if (whichSide == 2)
  71187. {
  71188. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71189. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71190. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71191. lineTo (tipX, tipY);
  71192. lineTo (arrowX1, y + h);
  71193. }
  71194. lineTo (x + cs, y + h);
  71195. if (cs > 0.0f)
  71196. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71197. if (whichSide == 1)
  71198. {
  71199. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71200. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71201. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71202. lineTo (tipX, tipY);
  71203. lineTo (x, arrowY1);
  71204. }
  71205. lineTo (x, y + cs);
  71206. if (cs > 0.0f)
  71207. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - PathHelpers::ellipseAngularIncrement);
  71208. closeSubPath();
  71209. }
  71210. }
  71211. void Path::addPath (const Path& other)
  71212. {
  71213. size_t i = 0;
  71214. while (i < other.numElements)
  71215. {
  71216. const float type = other.data.elements [i++];
  71217. if (type == moveMarker)
  71218. {
  71219. startNewSubPath (other.data.elements [i],
  71220. other.data.elements [i + 1]);
  71221. i += 2;
  71222. }
  71223. else if (type == lineMarker)
  71224. {
  71225. lineTo (other.data.elements [i],
  71226. other.data.elements [i + 1]);
  71227. i += 2;
  71228. }
  71229. else if (type == quadMarker)
  71230. {
  71231. quadraticTo (other.data.elements [i],
  71232. other.data.elements [i + 1],
  71233. other.data.elements [i + 2],
  71234. other.data.elements [i + 3]);
  71235. i += 4;
  71236. }
  71237. else if (type == cubicMarker)
  71238. {
  71239. cubicTo (other.data.elements [i],
  71240. other.data.elements [i + 1],
  71241. other.data.elements [i + 2],
  71242. other.data.elements [i + 3],
  71243. other.data.elements [i + 4],
  71244. other.data.elements [i + 5]);
  71245. i += 6;
  71246. }
  71247. else if (type == closeSubPathMarker)
  71248. {
  71249. closeSubPath();
  71250. }
  71251. else
  71252. {
  71253. // something's gone wrong with the element list!
  71254. jassertfalse
  71255. }
  71256. }
  71257. }
  71258. void Path::addPath (const Path& other,
  71259. const AffineTransform& transformToApply)
  71260. {
  71261. size_t i = 0;
  71262. while (i < other.numElements)
  71263. {
  71264. const float type = other.data.elements [i++];
  71265. if (type == closeSubPathMarker)
  71266. {
  71267. closeSubPath();
  71268. }
  71269. else
  71270. {
  71271. float x = other.data.elements [i++];
  71272. float y = other.data.elements [i++];
  71273. transformToApply.transformPoint (x, y);
  71274. if (type == moveMarker)
  71275. {
  71276. startNewSubPath (x, y);
  71277. }
  71278. else if (type == lineMarker)
  71279. {
  71280. lineTo (x, y);
  71281. }
  71282. else if (type == quadMarker)
  71283. {
  71284. float x2 = other.data.elements [i++];
  71285. float y2 = other.data.elements [i++];
  71286. transformToApply.transformPoint (x2, y2);
  71287. quadraticTo (x, y, x2, y2);
  71288. }
  71289. else if (type == cubicMarker)
  71290. {
  71291. float x2 = other.data.elements [i++];
  71292. float y2 = other.data.elements [i++];
  71293. float x3 = other.data.elements [i++];
  71294. float y3 = other.data.elements [i++];
  71295. transformToApply.transformPoint (x2, y2);
  71296. transformToApply.transformPoint (x3, y3);
  71297. cubicTo (x, y, x2, y2, x3, y3);
  71298. }
  71299. else
  71300. {
  71301. // something's gone wrong with the element list!
  71302. jassertfalse
  71303. }
  71304. }
  71305. }
  71306. }
  71307. void Path::applyTransform (const AffineTransform& transform) throw()
  71308. {
  71309. size_t i = 0;
  71310. pathYMin = pathXMin = 0;
  71311. pathYMax = pathXMax = 0;
  71312. bool setMaxMin = false;
  71313. while (i < numElements)
  71314. {
  71315. const float type = data.elements [i++];
  71316. if (type == moveMarker)
  71317. {
  71318. transform.transformPoint (data.elements [i],
  71319. data.elements [i + 1]);
  71320. if (setMaxMin)
  71321. {
  71322. pathXMin = jmin (pathXMin, data.elements [i]);
  71323. pathXMax = jmax (pathXMax, data.elements [i]);
  71324. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71325. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71326. }
  71327. else
  71328. {
  71329. pathXMin = pathXMax = data.elements [i];
  71330. pathYMin = pathYMax = data.elements [i + 1];
  71331. setMaxMin = true;
  71332. }
  71333. i += 2;
  71334. }
  71335. else if (type == lineMarker)
  71336. {
  71337. transform.transformPoint (data.elements [i],
  71338. data.elements [i + 1]);
  71339. pathXMin = jmin (pathXMin, data.elements [i]);
  71340. pathXMax = jmax (pathXMax, data.elements [i]);
  71341. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71342. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71343. i += 2;
  71344. }
  71345. else if (type == quadMarker)
  71346. {
  71347. transform.transformPoint (data.elements [i],
  71348. data.elements [i + 1]);
  71349. transform.transformPoint (data.elements [i + 2],
  71350. data.elements [i + 3]);
  71351. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71352. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71353. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71354. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71355. i += 4;
  71356. }
  71357. else if (type == cubicMarker)
  71358. {
  71359. transform.transformPoint (data.elements [i],
  71360. data.elements [i + 1]);
  71361. transform.transformPoint (data.elements [i + 2],
  71362. data.elements [i + 3]);
  71363. transform.transformPoint (data.elements [i + 4],
  71364. data.elements [i + 5]);
  71365. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71366. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71367. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71368. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71369. i += 6;
  71370. }
  71371. }
  71372. }
  71373. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71374. const float w, const float h,
  71375. const bool preserveProportions,
  71376. const Justification& justification) const
  71377. {
  71378. Rectangle<float> bounds (getBounds());
  71379. if (preserveProportions)
  71380. {
  71381. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71382. return AffineTransform::identity;
  71383. float newW, newH;
  71384. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71385. if (srcRatio > h / w)
  71386. {
  71387. newW = h / srcRatio;
  71388. newH = h;
  71389. }
  71390. else
  71391. {
  71392. newW = w;
  71393. newH = w * srcRatio;
  71394. }
  71395. float newXCentre = x;
  71396. float newYCentre = y;
  71397. if (justification.testFlags (Justification::left))
  71398. newXCentre += newW * 0.5f;
  71399. else if (justification.testFlags (Justification::right))
  71400. newXCentre += w - newW * 0.5f;
  71401. else
  71402. newXCentre += w * 0.5f;
  71403. if (justification.testFlags (Justification::top))
  71404. newYCentre += newH * 0.5f;
  71405. else if (justification.testFlags (Justification::bottom))
  71406. newYCentre += h - newH * 0.5f;
  71407. else
  71408. newYCentre += h * 0.5f;
  71409. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71410. bounds.getHeight() * -0.5f - bounds.getY())
  71411. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71412. .translated (newXCentre, newYCentre);
  71413. }
  71414. else
  71415. {
  71416. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71417. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71418. .translated (x, y);
  71419. }
  71420. }
  71421. bool Path::contains (const float x, const float y, const float tolerence) const
  71422. {
  71423. if (x <= pathXMin || x >= pathXMax
  71424. || y <= pathYMin || y >= pathYMax)
  71425. return false;
  71426. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71427. int positiveCrossings = 0;
  71428. int negativeCrossings = 0;
  71429. while (i.next())
  71430. {
  71431. if ((i.y1 <= y && i.y2 > y)
  71432. || (i.y2 <= y && i.y1 > y))
  71433. {
  71434. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71435. if (intersectX <= x)
  71436. {
  71437. if (i.y1 < i.y2)
  71438. ++positiveCrossings;
  71439. else
  71440. ++negativeCrossings;
  71441. }
  71442. }
  71443. }
  71444. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71445. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71446. }
  71447. bool Path::intersectsLine (const float x1, const float y1,
  71448. const float x2, const float y2,
  71449. const float tolerence)
  71450. {
  71451. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71452. const Line line1 (x1, y1, x2, y2);
  71453. while (i.next())
  71454. {
  71455. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71456. float ix, iy;
  71457. if (line1.intersects (line2, ix, iy))
  71458. return true;
  71459. }
  71460. return false;
  71461. }
  71462. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const
  71463. {
  71464. if (cornerRadius <= 0.01f)
  71465. return *this;
  71466. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71467. size_t n = 0;
  71468. bool lastWasLine = false, firstWasLine = false;
  71469. Path p;
  71470. while (n < numElements)
  71471. {
  71472. const float type = data.elements [n++];
  71473. if (type == moveMarker)
  71474. {
  71475. indexOfPathStart = p.numElements;
  71476. indexOfPathStartThis = n - 1;
  71477. const float x = data.elements [n++];
  71478. const float y = data.elements [n++];
  71479. p.startNewSubPath (x, y);
  71480. lastWasLine = false;
  71481. firstWasLine = (data.elements [n] == lineMarker);
  71482. }
  71483. else if (type == lineMarker || type == closeSubPathMarker)
  71484. {
  71485. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71486. if (type == lineMarker)
  71487. {
  71488. endX = data.elements [n++];
  71489. endY = data.elements [n++];
  71490. if (n > 8)
  71491. {
  71492. startX = data.elements [n - 8];
  71493. startY = data.elements [n - 7];
  71494. joinX = data.elements [n - 5];
  71495. joinY = data.elements [n - 4];
  71496. }
  71497. }
  71498. else
  71499. {
  71500. endX = data.elements [indexOfPathStartThis + 1];
  71501. endY = data.elements [indexOfPathStartThis + 2];
  71502. if (n > 6)
  71503. {
  71504. startX = data.elements [n - 6];
  71505. startY = data.elements [n - 5];
  71506. joinX = data.elements [n - 3];
  71507. joinY = data.elements [n - 2];
  71508. }
  71509. }
  71510. if (lastWasLine)
  71511. {
  71512. const double len1 = juce_hypot (startX - joinX,
  71513. startY - joinY);
  71514. if (len1 > 0)
  71515. {
  71516. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71517. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71518. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71519. }
  71520. const double len2 = juce_hypot (endX - joinX,
  71521. endY - joinY);
  71522. if (len2 > 0)
  71523. {
  71524. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71525. p.quadraticTo (joinX, joinY,
  71526. (float) (joinX + (endX - joinX) * propNeeded),
  71527. (float) (joinY + (endY - joinY) * propNeeded));
  71528. }
  71529. p.lineTo (endX, endY);
  71530. }
  71531. else if (type == lineMarker)
  71532. {
  71533. p.lineTo (endX, endY);
  71534. lastWasLine = true;
  71535. }
  71536. if (type == closeSubPathMarker)
  71537. {
  71538. if (firstWasLine)
  71539. {
  71540. startX = data.elements [n - 3];
  71541. startY = data.elements [n - 2];
  71542. joinX = endX;
  71543. joinY = endY;
  71544. endX = data.elements [indexOfPathStartThis + 4];
  71545. endY = data.elements [indexOfPathStartThis + 5];
  71546. const double len1 = juce_hypot (startX - joinX,
  71547. startY - joinY);
  71548. if (len1 > 0)
  71549. {
  71550. const double propNeeded = jmin (0.5, cornerRadius / len1);
  71551. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  71552. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  71553. }
  71554. const double len2 = juce_hypot (endX - joinX,
  71555. endY - joinY);
  71556. if (len2 > 0)
  71557. {
  71558. const double propNeeded = jmin (0.5, cornerRadius / len2);
  71559. endX = (float) (joinX + (endX - joinX) * propNeeded);
  71560. endY = (float) (joinY + (endY - joinY) * propNeeded);
  71561. p.quadraticTo (joinX, joinY, endX, endY);
  71562. p.data.elements [indexOfPathStart + 1] = endX;
  71563. p.data.elements [indexOfPathStart + 2] = endY;
  71564. }
  71565. }
  71566. p.closeSubPath();
  71567. }
  71568. }
  71569. else if (type == quadMarker)
  71570. {
  71571. lastWasLine = false;
  71572. const float x1 = data.elements [n++];
  71573. const float y1 = data.elements [n++];
  71574. const float x2 = data.elements [n++];
  71575. const float y2 = data.elements [n++];
  71576. p.quadraticTo (x1, y1, x2, y2);
  71577. }
  71578. else if (type == cubicMarker)
  71579. {
  71580. lastWasLine = false;
  71581. const float x1 = data.elements [n++];
  71582. const float y1 = data.elements [n++];
  71583. const float x2 = data.elements [n++];
  71584. const float y2 = data.elements [n++];
  71585. const float x3 = data.elements [n++];
  71586. const float y3 = data.elements [n++];
  71587. p.cubicTo (x1, y1, x2, y2, x3, y3);
  71588. }
  71589. }
  71590. return p;
  71591. }
  71592. void Path::loadPathFromStream (InputStream& source)
  71593. {
  71594. while (! source.isExhausted())
  71595. {
  71596. switch (source.readByte())
  71597. {
  71598. case 'm':
  71599. {
  71600. const float x = source.readFloat();
  71601. const float y = source.readFloat();
  71602. startNewSubPath (x, y);
  71603. break;
  71604. }
  71605. case 'l':
  71606. {
  71607. const float x = source.readFloat();
  71608. const float y = source.readFloat();
  71609. lineTo (x, y);
  71610. break;
  71611. }
  71612. case 'q':
  71613. {
  71614. const float x1 = source.readFloat();
  71615. const float y1 = source.readFloat();
  71616. const float x2 = source.readFloat();
  71617. const float y2 = source.readFloat();
  71618. quadraticTo (x1, y1, x2, y2);
  71619. break;
  71620. }
  71621. case 'b':
  71622. {
  71623. const float x1 = source.readFloat();
  71624. const float y1 = source.readFloat();
  71625. const float x2 = source.readFloat();
  71626. const float y2 = source.readFloat();
  71627. const float x3 = source.readFloat();
  71628. const float y3 = source.readFloat();
  71629. cubicTo (x1, y1, x2, y2, x3, y3);
  71630. break;
  71631. }
  71632. case 'c':
  71633. closeSubPath();
  71634. break;
  71635. case 'n':
  71636. useNonZeroWinding = true;
  71637. break;
  71638. case 'z':
  71639. useNonZeroWinding = false;
  71640. break;
  71641. case 'e':
  71642. return; // end of path marker
  71643. default:
  71644. jassertfalse // illegal char in the stream
  71645. break;
  71646. }
  71647. }
  71648. }
  71649. void Path::loadPathFromData (const void* const data, const int numberOfBytes)
  71650. {
  71651. MemoryInputStream in (data, numberOfBytes, false);
  71652. loadPathFromStream (in);
  71653. }
  71654. void Path::writePathToStream (OutputStream& dest) const
  71655. {
  71656. dest.writeByte (useNonZeroWinding ? 'n' : 'z');
  71657. size_t i = 0;
  71658. while (i < numElements)
  71659. {
  71660. const float type = data.elements [i++];
  71661. if (type == moveMarker)
  71662. {
  71663. dest.writeByte ('m');
  71664. dest.writeFloat (data.elements [i++]);
  71665. dest.writeFloat (data.elements [i++]);
  71666. }
  71667. else if (type == lineMarker)
  71668. {
  71669. dest.writeByte ('l');
  71670. dest.writeFloat (data.elements [i++]);
  71671. dest.writeFloat (data.elements [i++]);
  71672. }
  71673. else if (type == quadMarker)
  71674. {
  71675. dest.writeByte ('q');
  71676. dest.writeFloat (data.elements [i++]);
  71677. dest.writeFloat (data.elements [i++]);
  71678. dest.writeFloat (data.elements [i++]);
  71679. dest.writeFloat (data.elements [i++]);
  71680. }
  71681. else if (type == cubicMarker)
  71682. {
  71683. dest.writeByte ('b');
  71684. dest.writeFloat (data.elements [i++]);
  71685. dest.writeFloat (data.elements [i++]);
  71686. dest.writeFloat (data.elements [i++]);
  71687. dest.writeFloat (data.elements [i++]);
  71688. dest.writeFloat (data.elements [i++]);
  71689. dest.writeFloat (data.elements [i++]);
  71690. }
  71691. else if (type == closeSubPathMarker)
  71692. {
  71693. dest.writeByte ('c');
  71694. }
  71695. }
  71696. dest.writeByte ('e'); // marks the end-of-path
  71697. }
  71698. const String Path::toString() const
  71699. {
  71700. MemoryOutputStream s (2048, 2048);
  71701. if (! useNonZeroWinding)
  71702. s << 'a';
  71703. size_t i = 0;
  71704. float lastMarker = 0.0f;
  71705. while (i < numElements)
  71706. {
  71707. const float marker = data.elements [i++];
  71708. char markerChar = 0;
  71709. int numCoords = 0;
  71710. if (marker == moveMarker)
  71711. {
  71712. markerChar = 'm';
  71713. numCoords = 2;
  71714. }
  71715. else if (marker == lineMarker)
  71716. {
  71717. markerChar = 'l';
  71718. numCoords = 2;
  71719. }
  71720. else if (marker == quadMarker)
  71721. {
  71722. markerChar = 'q';
  71723. numCoords = 4;
  71724. }
  71725. else if (marker == cubicMarker)
  71726. {
  71727. markerChar = 'c';
  71728. numCoords = 6;
  71729. }
  71730. else
  71731. {
  71732. jassert (marker == closeSubPathMarker);
  71733. markerChar = 'z';
  71734. }
  71735. if (marker != lastMarker)
  71736. {
  71737. if (s.getDataSize() != 0)
  71738. s << ' ';
  71739. s << markerChar;
  71740. lastMarker = marker;
  71741. }
  71742. while (--numCoords >= 0 && i < numElements)
  71743. {
  71744. String coord (data.elements [i++], 3);
  71745. while (coord.endsWithChar ('0') && coord != "0")
  71746. coord = coord.dropLastCharacters (1);
  71747. if (coord.endsWithChar ('.'))
  71748. coord = coord.dropLastCharacters (1);
  71749. if (s.getDataSize() != 0)
  71750. s << ' ';
  71751. s << coord;
  71752. }
  71753. }
  71754. return s.toUTF8();
  71755. }
  71756. void Path::restoreFromString (const String& stringVersion)
  71757. {
  71758. clear();
  71759. setUsingNonZeroWinding (true);
  71760. const juce_wchar* t = stringVersion;
  71761. juce_wchar marker = 'm';
  71762. int numValues = 2;
  71763. float values [6];
  71764. while (*t != 0)
  71765. {
  71766. const String token (PathHelpers::nextToken (t));
  71767. const juce_wchar firstChar = token[0];
  71768. int startNum = 0;
  71769. if (firstChar == 'm' || firstChar == 'l')
  71770. {
  71771. marker = firstChar;
  71772. numValues = 2;
  71773. }
  71774. else if (firstChar == 'q')
  71775. {
  71776. marker = firstChar;
  71777. numValues = 4;
  71778. }
  71779. else if (firstChar == 'c')
  71780. {
  71781. marker = firstChar;
  71782. numValues = 6;
  71783. }
  71784. else if (firstChar == 'z')
  71785. {
  71786. marker = firstChar;
  71787. numValues = 0;
  71788. }
  71789. else if (firstChar == 'a')
  71790. {
  71791. setUsingNonZeroWinding (false);
  71792. continue;
  71793. }
  71794. else
  71795. {
  71796. ++startNum;
  71797. values [0] = token.getFloatValue();
  71798. }
  71799. for (int i = startNum; i < numValues; ++i)
  71800. values [i] = PathHelpers::nextToken (t).getFloatValue();
  71801. switch (marker)
  71802. {
  71803. case 'm':
  71804. startNewSubPath (values[0], values[1]);
  71805. break;
  71806. case 'l':
  71807. lineTo (values[0], values[1]);
  71808. break;
  71809. case 'q':
  71810. quadraticTo (values[0], values[1],
  71811. values[2], values[3]);
  71812. break;
  71813. case 'c':
  71814. cubicTo (values[0], values[1],
  71815. values[2], values[3],
  71816. values[4], values[5]);
  71817. break;
  71818. case 'z':
  71819. closeSubPath();
  71820. break;
  71821. default:
  71822. jassertfalse // illegal string format?
  71823. break;
  71824. }
  71825. }
  71826. }
  71827. Path::Iterator::Iterator (const Path& path_)
  71828. : path (path_),
  71829. index (0)
  71830. {
  71831. }
  71832. Path::Iterator::~Iterator()
  71833. {
  71834. }
  71835. bool Path::Iterator::next()
  71836. {
  71837. const float* const elements = path.data.elements;
  71838. if (index < path.numElements)
  71839. {
  71840. const float type = elements [index++];
  71841. if (type == moveMarker)
  71842. {
  71843. elementType = startNewSubPath;
  71844. x1 = elements [index++];
  71845. y1 = elements [index++];
  71846. }
  71847. else if (type == lineMarker)
  71848. {
  71849. elementType = lineTo;
  71850. x1 = elements [index++];
  71851. y1 = elements [index++];
  71852. }
  71853. else if (type == quadMarker)
  71854. {
  71855. elementType = quadraticTo;
  71856. x1 = elements [index++];
  71857. y1 = elements [index++];
  71858. x2 = elements [index++];
  71859. y2 = elements [index++];
  71860. }
  71861. else if (type == cubicMarker)
  71862. {
  71863. elementType = cubicTo;
  71864. x1 = elements [index++];
  71865. y1 = elements [index++];
  71866. x2 = elements [index++];
  71867. y2 = elements [index++];
  71868. x3 = elements [index++];
  71869. y3 = elements [index++];
  71870. }
  71871. else if (type == closeSubPathMarker)
  71872. {
  71873. elementType = closePath;
  71874. }
  71875. return true;
  71876. }
  71877. return false;
  71878. }
  71879. END_JUCE_NAMESPACE
  71880. /*** End of inlined file: juce_Path.cpp ***/
  71881. /*** Start of inlined file: juce_PathIterator.cpp ***/
  71882. BEGIN_JUCE_NAMESPACE
  71883. #if JUCE_MSVC
  71884. #pragma optimize ("t", on)
  71885. #endif
  71886. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  71887. const AffineTransform& transform_,
  71888. float tolerence_)
  71889. : x2 (0),
  71890. y2 (0),
  71891. closesSubPath (false),
  71892. subPathIndex (-1),
  71893. path (path_),
  71894. transform (transform_),
  71895. points (path_.data.elements),
  71896. tolerence (tolerence_ * tolerence_),
  71897. subPathCloseX (0),
  71898. subPathCloseY (0),
  71899. isIdentityTransform (transform_.isIdentity()),
  71900. stackBase (32),
  71901. index (0),
  71902. stackSize (32)
  71903. {
  71904. stackPos = stackBase;
  71905. }
  71906. PathFlatteningIterator::~PathFlatteningIterator()
  71907. {
  71908. }
  71909. bool PathFlatteningIterator::next()
  71910. {
  71911. x1 = x2;
  71912. y1 = y2;
  71913. float x3 = 0;
  71914. float y3 = 0;
  71915. float x4 = 0;
  71916. float y4 = 0;
  71917. float type;
  71918. for (;;)
  71919. {
  71920. if (stackPos == stackBase)
  71921. {
  71922. if (index >= path.numElements)
  71923. {
  71924. return false;
  71925. }
  71926. else
  71927. {
  71928. type = points [index++];
  71929. if (type != Path::closeSubPathMarker)
  71930. {
  71931. x2 = points [index++];
  71932. y2 = points [index++];
  71933. if (! isIdentityTransform)
  71934. transform.transformPoint (x2, y2);
  71935. if (type == Path::quadMarker)
  71936. {
  71937. x3 = points [index++];
  71938. y3 = points [index++];
  71939. if (! isIdentityTransform)
  71940. transform.transformPoint (x3, y3);
  71941. }
  71942. else if (type == Path::cubicMarker)
  71943. {
  71944. x3 = points [index++];
  71945. y3 = points [index++];
  71946. x4 = points [index++];
  71947. y4 = points [index++];
  71948. if (! isIdentityTransform)
  71949. {
  71950. transform.transformPoint (x3, y3);
  71951. transform.transformPoint (x4, y4);
  71952. }
  71953. }
  71954. }
  71955. }
  71956. }
  71957. else
  71958. {
  71959. type = *--stackPos;
  71960. if (type != Path::closeSubPathMarker)
  71961. {
  71962. x2 = *--stackPos;
  71963. y2 = *--stackPos;
  71964. if (type == Path::quadMarker)
  71965. {
  71966. x3 = *--stackPos;
  71967. y3 = *--stackPos;
  71968. }
  71969. else if (type == Path::cubicMarker)
  71970. {
  71971. x3 = *--stackPos;
  71972. y3 = *--stackPos;
  71973. x4 = *--stackPos;
  71974. y4 = *--stackPos;
  71975. }
  71976. }
  71977. }
  71978. if (type == Path::lineMarker)
  71979. {
  71980. ++subPathIndex;
  71981. closesSubPath = (stackPos == stackBase)
  71982. && (index < path.numElements)
  71983. && (points [index] == Path::closeSubPathMarker)
  71984. && x2 == subPathCloseX
  71985. && y2 == subPathCloseY;
  71986. return true;
  71987. }
  71988. else if (type == Path::quadMarker)
  71989. {
  71990. const size_t offset = (size_t) (stackPos - stackBase);
  71991. if (offset >= stackSize - 10)
  71992. {
  71993. stackSize <<= 1;
  71994. stackBase.realloc (stackSize);
  71995. stackPos = stackBase + offset;
  71996. }
  71997. const float dx1 = x1 - x2;
  71998. const float dy1 = y1 - y2;
  71999. const float dx2 = x2 - x3;
  72000. const float dy2 = y2 - y3;
  72001. const float m1x = (x1 + x2) * 0.5f;
  72002. const float m1y = (y1 + y2) * 0.5f;
  72003. const float m2x = (x2 + x3) * 0.5f;
  72004. const float m2y = (y2 + y3) * 0.5f;
  72005. const float m3x = (m1x + m2x) * 0.5f;
  72006. const float m3y = (m1y + m2y) * 0.5f;
  72007. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72008. {
  72009. *stackPos++ = y3;
  72010. *stackPos++ = x3;
  72011. *stackPos++ = m2y;
  72012. *stackPos++ = m2x;
  72013. *stackPos++ = Path::quadMarker;
  72014. *stackPos++ = m3y;
  72015. *stackPos++ = m3x;
  72016. *stackPos++ = m1y;
  72017. *stackPos++ = m1x;
  72018. *stackPos++ = Path::quadMarker;
  72019. }
  72020. else
  72021. {
  72022. *stackPos++ = y3;
  72023. *stackPos++ = x3;
  72024. *stackPos++ = Path::lineMarker;
  72025. *stackPos++ = m3y;
  72026. *stackPos++ = m3x;
  72027. *stackPos++ = Path::lineMarker;
  72028. }
  72029. jassert (stackPos < stackBase + stackSize);
  72030. }
  72031. else if (type == Path::cubicMarker)
  72032. {
  72033. const size_t offset = (size_t) (stackPos - stackBase);
  72034. if (offset >= stackSize - 16)
  72035. {
  72036. stackSize <<= 1;
  72037. stackBase.realloc (stackSize);
  72038. stackPos = stackBase + offset;
  72039. }
  72040. const float dx1 = x1 - x2;
  72041. const float dy1 = y1 - y2;
  72042. const float dx2 = x2 - x3;
  72043. const float dy2 = y2 - y3;
  72044. const float dx3 = x3 - x4;
  72045. const float dy3 = y3 - y4;
  72046. const float m1x = (x1 + x2) * 0.5f;
  72047. const float m1y = (y1 + y2) * 0.5f;
  72048. const float m2x = (x3 + x2) * 0.5f;
  72049. const float m2y = (y3 + y2) * 0.5f;
  72050. const float m3x = (x3 + x4) * 0.5f;
  72051. const float m3y = (y3 + y4) * 0.5f;
  72052. const float m4x = (m1x + m2x) * 0.5f;
  72053. const float m4y = (m1y + m2y) * 0.5f;
  72054. const float m5x = (m3x + m2x) * 0.5f;
  72055. const float m5y = (m3y + m2y) * 0.5f;
  72056. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72057. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72058. {
  72059. *stackPos++ = y4;
  72060. *stackPos++ = x4;
  72061. *stackPos++ = m3y;
  72062. *stackPos++ = m3x;
  72063. *stackPos++ = m5y;
  72064. *stackPos++ = m5x;
  72065. *stackPos++ = Path::cubicMarker;
  72066. *stackPos++ = (m4y + m5y) * 0.5f;
  72067. *stackPos++ = (m4x + m5x) * 0.5f;
  72068. *stackPos++ = m4y;
  72069. *stackPos++ = m4x;
  72070. *stackPos++ = m1y;
  72071. *stackPos++ = m1x;
  72072. *stackPos++ = Path::cubicMarker;
  72073. }
  72074. else
  72075. {
  72076. *stackPos++ = y4;
  72077. *stackPos++ = x4;
  72078. *stackPos++ = Path::lineMarker;
  72079. *stackPos++ = m5y;
  72080. *stackPos++ = m5x;
  72081. *stackPos++ = Path::lineMarker;
  72082. *stackPos++ = m4y;
  72083. *stackPos++ = m4x;
  72084. *stackPos++ = Path::lineMarker;
  72085. }
  72086. }
  72087. else if (type == Path::closeSubPathMarker)
  72088. {
  72089. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72090. {
  72091. x1 = x2;
  72092. y1 = y2;
  72093. x2 = subPathCloseX;
  72094. y2 = subPathCloseY;
  72095. closesSubPath = true;
  72096. return true;
  72097. }
  72098. }
  72099. else
  72100. {
  72101. jassert (type == Path::moveMarker);
  72102. subPathIndex = -1;
  72103. subPathCloseX = x1 = x2;
  72104. subPathCloseY = y1 = y2;
  72105. }
  72106. }
  72107. }
  72108. END_JUCE_NAMESPACE
  72109. /*** End of inlined file: juce_PathIterator.cpp ***/
  72110. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72111. BEGIN_JUCE_NAMESPACE
  72112. PathStrokeType::PathStrokeType (const float strokeThickness,
  72113. const JointStyle jointStyle_,
  72114. const EndCapStyle endStyle_) throw()
  72115. : thickness (strokeThickness),
  72116. jointStyle (jointStyle_),
  72117. endStyle (endStyle_)
  72118. {
  72119. }
  72120. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72121. : thickness (other.thickness),
  72122. jointStyle (other.jointStyle),
  72123. endStyle (other.endStyle)
  72124. {
  72125. }
  72126. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72127. {
  72128. thickness = other.thickness;
  72129. jointStyle = other.jointStyle;
  72130. endStyle = other.endStyle;
  72131. return *this;
  72132. }
  72133. PathStrokeType::~PathStrokeType() throw()
  72134. {
  72135. }
  72136. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72137. {
  72138. return thickness == other.thickness
  72139. && jointStyle == other.jointStyle
  72140. && endStyle == other.endStyle;
  72141. }
  72142. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72143. {
  72144. return ! operator== (other);
  72145. }
  72146. static bool lineIntersection (const float x1, const float y1,
  72147. const float x2, const float y2,
  72148. const float x3, const float y3,
  72149. const float x4, const float y4,
  72150. float& intersectionX,
  72151. float& intersectionY,
  72152. float& distanceBeyondLine1EndSquared) throw()
  72153. {
  72154. if (x2 != x3 || y2 != y3)
  72155. {
  72156. const float dx1 = x2 - x1;
  72157. const float dy1 = y2 - y1;
  72158. const float dx2 = x4 - x3;
  72159. const float dy2 = y4 - y3;
  72160. const float divisor = dx1 * dy2 - dx2 * dy1;
  72161. if (divisor == 0)
  72162. {
  72163. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72164. {
  72165. if (dy1 == 0 && dy2 != 0)
  72166. {
  72167. const float along = (y1 - y3) / dy2;
  72168. intersectionX = x3 + along * dx2;
  72169. intersectionY = y1;
  72170. distanceBeyondLine1EndSquared = intersectionX - x2;
  72171. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72172. if ((x2 > x1) == (intersectionX < x2))
  72173. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72174. return along >= 0 && along <= 1.0f;
  72175. }
  72176. else if (dy2 == 0 && dy1 != 0)
  72177. {
  72178. const float along = (y3 - y1) / dy1;
  72179. intersectionX = x1 + along * dx1;
  72180. intersectionY = y3;
  72181. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72182. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72183. if (along < 1.0f)
  72184. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72185. return along >= 0 && along <= 1.0f;
  72186. }
  72187. else if (dx1 == 0 && dx2 != 0)
  72188. {
  72189. const float along = (x1 - x3) / dx2;
  72190. intersectionX = x1;
  72191. intersectionY = y3 + along * dy2;
  72192. distanceBeyondLine1EndSquared = intersectionY - y2;
  72193. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72194. if ((y2 > y1) == (intersectionY < y2))
  72195. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72196. return along >= 0 && along <= 1.0f;
  72197. }
  72198. else if (dx2 == 0 && dx1 != 0)
  72199. {
  72200. const float along = (x3 - x1) / dx1;
  72201. intersectionX = x3;
  72202. intersectionY = y1 + along * dy1;
  72203. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72204. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72205. if (along < 1.0f)
  72206. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72207. return along >= 0 && along <= 1.0f;
  72208. }
  72209. }
  72210. intersectionX = 0.5f * (x2 + x3);
  72211. intersectionY = 0.5f * (y2 + y3);
  72212. distanceBeyondLine1EndSquared = 0.0f;
  72213. return false;
  72214. }
  72215. else
  72216. {
  72217. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72218. intersectionX = x1 + along1 * dx1;
  72219. intersectionY = y1 + along1 * dy1;
  72220. if (along1 >= 0 && along1 <= 1.0f)
  72221. {
  72222. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72223. if (along2 >= 0 && along2 <= divisor)
  72224. {
  72225. distanceBeyondLine1EndSquared = 0.0f;
  72226. return true;
  72227. }
  72228. }
  72229. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72230. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72231. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72232. if (along1 < 1.0f)
  72233. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72234. return false;
  72235. }
  72236. }
  72237. intersectionX = x2;
  72238. intersectionY = y2;
  72239. distanceBeyondLine1EndSquared = 0.0f;
  72240. return true;
  72241. }
  72242. namespace PathFunctions
  72243. {
  72244. // part of stroke drawing stuff
  72245. static void addEdgeAndJoint (Path& destPath,
  72246. const PathStrokeType::JointStyle style,
  72247. const float maxMiterExtensionSquared, const float width,
  72248. const float x1, const float y1,
  72249. const float x2, const float y2,
  72250. const float x3, const float y3,
  72251. const float x4, const float y4,
  72252. const float midX, const float midY)
  72253. {
  72254. if (style == PathStrokeType::beveled
  72255. || (x3 == x4 && y3 == y4)
  72256. || (x1 == x2 && y1 == y2))
  72257. {
  72258. destPath.lineTo (x2, y2);
  72259. destPath.lineTo (x3, y3);
  72260. }
  72261. else
  72262. {
  72263. float jx, jy, distanceBeyondLine1EndSquared;
  72264. // if they intersect, use this point..
  72265. if (lineIntersection (x1, y1, x2, y2,
  72266. x3, y3, x4, y4,
  72267. jx, jy, distanceBeyondLine1EndSquared))
  72268. {
  72269. destPath.lineTo (jx, jy);
  72270. }
  72271. else
  72272. {
  72273. if (style == PathStrokeType::mitered)
  72274. {
  72275. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72276. && distanceBeyondLine1EndSquared > 0.0f)
  72277. {
  72278. destPath.lineTo (jx, jy);
  72279. }
  72280. else
  72281. {
  72282. // the end sticks out too far, so just use a blunt joint
  72283. destPath.lineTo (x2, y2);
  72284. destPath.lineTo (x3, y3);
  72285. }
  72286. }
  72287. else
  72288. {
  72289. // curved joints
  72290. float angle1 = atan2f (x2 - midX, y2 - midY);
  72291. float angle2 = atan2f (x3 - midX, y3 - midY);
  72292. const float angleIncrement = 0.1f;
  72293. destPath.lineTo (x2, y2);
  72294. if (fabs (angle1 - angle2) > angleIncrement)
  72295. {
  72296. if (angle2 > angle1 + float_Pi
  72297. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72298. {
  72299. if (angle2 > angle1)
  72300. angle2 -= float_Pi * 2.0f;
  72301. jassert (angle1 <= angle2 + float_Pi);
  72302. angle1 -= angleIncrement;
  72303. while (angle1 > angle2)
  72304. {
  72305. destPath.lineTo (midX + width * sinf (angle1),
  72306. midY + width * cosf (angle1));
  72307. angle1 -= angleIncrement;
  72308. }
  72309. }
  72310. else
  72311. {
  72312. if (angle1 > angle2)
  72313. angle1 -= float_Pi * 2.0f;
  72314. jassert (angle1 >= angle2 - float_Pi);
  72315. angle1 += angleIncrement;
  72316. while (angle1 < angle2)
  72317. {
  72318. destPath.lineTo (midX + width * sinf (angle1),
  72319. midY + width * cosf (angle1));
  72320. angle1 += angleIncrement;
  72321. }
  72322. }
  72323. }
  72324. destPath.lineTo (x3, y3);
  72325. }
  72326. }
  72327. }
  72328. }
  72329. static void addLineEnd (Path& destPath,
  72330. const PathStrokeType::EndCapStyle style,
  72331. const float x1, const float y1,
  72332. const float x2, const float y2,
  72333. const float width)
  72334. {
  72335. if (style == PathStrokeType::butt)
  72336. {
  72337. destPath.lineTo (x2, y2);
  72338. }
  72339. else
  72340. {
  72341. float offx1, offy1, offx2, offy2;
  72342. float dx = x2 - x1;
  72343. float dy = y2 - y1;
  72344. const float len = juce_hypotf (dx, dy);
  72345. if (len == 0)
  72346. {
  72347. offx1 = offx2 = x1;
  72348. offy1 = offy2 = y1;
  72349. }
  72350. else
  72351. {
  72352. const float offset = width / len;
  72353. dx *= offset;
  72354. dy *= offset;
  72355. offx1 = x1 + dy;
  72356. offy1 = y1 - dx;
  72357. offx2 = x2 + dy;
  72358. offy2 = y2 - dx;
  72359. }
  72360. if (style == PathStrokeType::square)
  72361. {
  72362. // sqaure ends
  72363. destPath.lineTo (offx1, offy1);
  72364. destPath.lineTo (offx2, offy2);
  72365. destPath.lineTo (x2, y2);
  72366. }
  72367. else
  72368. {
  72369. // rounded ends
  72370. const float midx = (offx1 + offx2) * 0.5f;
  72371. const float midy = (offy1 + offy2) * 0.5f;
  72372. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72373. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72374. midx, midy);
  72375. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72376. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72377. x2, y2);
  72378. }
  72379. }
  72380. }
  72381. struct LineSection
  72382. {
  72383. LineSection() {}
  72384. LineSection (int) {}
  72385. float x1, y1, x2, y2; // original line
  72386. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72387. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72388. };
  72389. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72390. const bool isClosed,
  72391. const float width, const float maxMiterExtensionSquared,
  72392. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72393. {
  72394. jassert (subPath.size() > 0);
  72395. const LineSection& firstLine = subPath.getReference (0);
  72396. float lastX1 = firstLine.lx1;
  72397. float lastY1 = firstLine.ly1;
  72398. float lastX2 = firstLine.lx2;
  72399. float lastY2 = firstLine.ly2;
  72400. if (isClosed)
  72401. {
  72402. destPath.startNewSubPath (lastX1, lastY1);
  72403. }
  72404. else
  72405. {
  72406. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72407. addLineEnd (destPath, endStyle,
  72408. firstLine.rx2, firstLine.ry2,
  72409. lastX1, lastY1,
  72410. width);
  72411. }
  72412. int i;
  72413. for (i = 1; i < subPath.size(); ++i)
  72414. {
  72415. const LineSection& l = subPath.getReference (i);
  72416. addEdgeAndJoint (destPath, jointStyle,
  72417. maxMiterExtensionSquared, width,
  72418. lastX1, lastY1, lastX2, lastY2,
  72419. l.lx1, l.ly1, l.lx2, l.ly2,
  72420. l.x1, l.y1);
  72421. lastX1 = l.lx1;
  72422. lastY1 = l.ly1;
  72423. lastX2 = l.lx2;
  72424. lastY2 = l.ly2;
  72425. }
  72426. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72427. if (isClosed)
  72428. {
  72429. const LineSection& l = subPath.getReference (0);
  72430. addEdgeAndJoint (destPath, jointStyle,
  72431. maxMiterExtensionSquared, width,
  72432. lastX1, lastY1, lastX2, lastY2,
  72433. l.lx1, l.ly1, l.lx2, l.ly2,
  72434. l.x1, l.y1);
  72435. destPath.closeSubPath();
  72436. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72437. }
  72438. else
  72439. {
  72440. destPath.lineTo (lastX2, lastY2);
  72441. addLineEnd (destPath, endStyle,
  72442. lastX2, lastY2,
  72443. lastLine.rx1, lastLine.ry1,
  72444. width);
  72445. }
  72446. lastX1 = lastLine.rx1;
  72447. lastY1 = lastLine.ry1;
  72448. lastX2 = lastLine.rx2;
  72449. lastY2 = lastLine.ry2;
  72450. for (i = subPath.size() - 1; --i >= 0;)
  72451. {
  72452. const LineSection& l = subPath.getReference (i);
  72453. addEdgeAndJoint (destPath, jointStyle,
  72454. maxMiterExtensionSquared, width,
  72455. lastX1, lastY1, lastX2, lastY2,
  72456. l.rx1, l.ry1, l.rx2, l.ry2,
  72457. l.x2, l.y2);
  72458. lastX1 = l.rx1;
  72459. lastY1 = l.ry1;
  72460. lastX2 = l.rx2;
  72461. lastY2 = l.ry2;
  72462. }
  72463. if (isClosed)
  72464. {
  72465. addEdgeAndJoint (destPath, jointStyle,
  72466. maxMiterExtensionSquared, width,
  72467. lastX1, lastY1, lastX2, lastY2,
  72468. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72469. lastLine.x2, lastLine.y2);
  72470. }
  72471. else
  72472. {
  72473. // do the last line
  72474. destPath.lineTo (lastX2, lastY2);
  72475. }
  72476. destPath.closeSubPath();
  72477. }
  72478. }
  72479. void PathStrokeType::createStrokedPath (Path& destPath,
  72480. const Path& source,
  72481. const AffineTransform& transform,
  72482. const float extraAccuracy) const
  72483. {
  72484. if (thickness <= 0)
  72485. {
  72486. destPath.clear();
  72487. return;
  72488. }
  72489. const Path* sourcePath = &source;
  72490. Path temp;
  72491. if (sourcePath == &destPath)
  72492. {
  72493. destPath.swapWithPath (temp);
  72494. sourcePath = &temp;
  72495. }
  72496. else
  72497. {
  72498. destPath.clear();
  72499. }
  72500. destPath.setUsingNonZeroWinding (true);
  72501. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  72502. const float width = 0.5f * thickness;
  72503. // Iterate the path, creating a list of the
  72504. // left/right-hand lines along either side of it...
  72505. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  72506. using namespace PathFunctions;
  72507. Array <LineSection> subPath;
  72508. LineSection l;
  72509. l.x1 = 0;
  72510. l.y1 = 0;
  72511. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  72512. while (it.next())
  72513. {
  72514. if (it.subPathIndex == 0)
  72515. {
  72516. if (subPath.size() > 0)
  72517. {
  72518. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72519. subPath.clearQuick();
  72520. }
  72521. l.x1 = it.x1;
  72522. l.y1 = it.y1;
  72523. }
  72524. l.x2 = it.x2;
  72525. l.y2 = it.y2;
  72526. float dx = l.x2 - l.x1;
  72527. float dy = l.y2 - l.y1;
  72528. const float hypotSquared = dx*dx + dy*dy;
  72529. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  72530. {
  72531. const float len = sqrtf (hypotSquared);
  72532. if (len == 0)
  72533. {
  72534. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  72535. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  72536. }
  72537. else
  72538. {
  72539. const float offset = width / len;
  72540. dx *= offset;
  72541. dy *= offset;
  72542. l.rx2 = l.x1 - dy;
  72543. l.ry2 = l.y1 + dx;
  72544. l.lx1 = l.x1 + dy;
  72545. l.ly1 = l.y1 - dx;
  72546. l.lx2 = l.x2 + dy;
  72547. l.ly2 = l.y2 - dx;
  72548. l.rx1 = l.x2 - dy;
  72549. l.ry1 = l.y2 + dx;
  72550. }
  72551. subPath.add (l);
  72552. if (it.closesSubPath)
  72553. {
  72554. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72555. subPath.clearQuick();
  72556. }
  72557. else
  72558. {
  72559. l.x1 = it.x2;
  72560. l.y1 = it.y2;
  72561. }
  72562. }
  72563. }
  72564. if (subPath.size() > 0)
  72565. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  72566. }
  72567. void PathStrokeType::createDashedStroke (Path& destPath,
  72568. const Path& sourcePath,
  72569. const float* dashLengths,
  72570. int numDashLengths,
  72571. const AffineTransform& transform,
  72572. const float extraAccuracy) const
  72573. {
  72574. if (thickness <= 0)
  72575. return;
  72576. // this should really be an even number..
  72577. jassert ((numDashLengths & 1) == 0);
  72578. Path newDestPath;
  72579. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  72580. bool first = true;
  72581. int dashNum = 0;
  72582. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  72583. float dx = 0.0f, dy = 0.0f;
  72584. for (;;)
  72585. {
  72586. const bool isSolid = ((dashNum & 1) == 0);
  72587. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  72588. jassert (dashLen > 0); // must be a positive increment!
  72589. if (dashLen <= 0)
  72590. break;
  72591. pos += dashLen;
  72592. while (pos > lineEndPos)
  72593. {
  72594. if (! it.next())
  72595. {
  72596. if (isSolid && ! first)
  72597. newDestPath.lineTo (it.x2, it.y2);
  72598. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  72599. return;
  72600. }
  72601. if (isSolid && ! first)
  72602. newDestPath.lineTo (it.x1, it.y1);
  72603. else
  72604. newDestPath.startNewSubPath (it.x1, it.y1);
  72605. dx = it.x2 - it.x1;
  72606. dy = it.y2 - it.y1;
  72607. lineLen = juce_hypotf (dx, dy);
  72608. lineEndPos += lineLen;
  72609. first = it.closesSubPath;
  72610. }
  72611. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  72612. if (isSolid)
  72613. newDestPath.lineTo (it.x1 + dx * alpha,
  72614. it.y1 + dy * alpha);
  72615. else
  72616. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  72617. it.y1 + dy * alpha);
  72618. }
  72619. }
  72620. END_JUCE_NAMESPACE
  72621. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  72622. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  72623. BEGIN_JUCE_NAMESPACE
  72624. PositionedRectangle::PositionedRectangle() throw()
  72625. : x (0.0),
  72626. y (0.0),
  72627. w (0.0),
  72628. h (0.0),
  72629. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72630. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  72631. wMode (absoluteSize),
  72632. hMode (absoluteSize)
  72633. {
  72634. }
  72635. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  72636. : x (other.x),
  72637. y (other.y),
  72638. w (other.w),
  72639. h (other.h),
  72640. xMode (other.xMode),
  72641. yMode (other.yMode),
  72642. wMode (other.wMode),
  72643. hMode (other.hMode)
  72644. {
  72645. }
  72646. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  72647. {
  72648. x = other.x;
  72649. y = other.y;
  72650. w = other.w;
  72651. h = other.h;
  72652. xMode = other.xMode;
  72653. yMode = other.yMode;
  72654. wMode = other.wMode;
  72655. hMode = other.hMode;
  72656. return *this;
  72657. }
  72658. PositionedRectangle::~PositionedRectangle() throw()
  72659. {
  72660. }
  72661. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  72662. {
  72663. return x == other.x
  72664. && y == other.y
  72665. && w == other.w
  72666. && h == other.h
  72667. && xMode == other.xMode
  72668. && yMode == other.yMode
  72669. && wMode == other.wMode
  72670. && hMode == other.hMode;
  72671. }
  72672. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  72673. {
  72674. return ! operator== (other);
  72675. }
  72676. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  72677. {
  72678. StringArray tokens;
  72679. tokens.addTokens (stringVersion, false);
  72680. decodePosString (tokens [0], xMode, x);
  72681. decodePosString (tokens [1], yMode, y);
  72682. decodeSizeString (tokens [2], wMode, w);
  72683. decodeSizeString (tokens [3], hMode, h);
  72684. }
  72685. const String PositionedRectangle::toString() const throw()
  72686. {
  72687. String s;
  72688. s.preallocateStorage (12);
  72689. addPosDescription (s, xMode, x);
  72690. s << ' ';
  72691. addPosDescription (s, yMode, y);
  72692. s << ' ';
  72693. addSizeDescription (s, wMode, w);
  72694. s << ' ';
  72695. addSizeDescription (s, hMode, h);
  72696. return s;
  72697. }
  72698. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  72699. {
  72700. jassert (! target.isEmpty());
  72701. double x_, y_, w_, h_;
  72702. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72703. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72704. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  72705. roundToInt (w_), roundToInt (h_));
  72706. }
  72707. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  72708. double& x_, double& y_,
  72709. double& w_, double& h_) const throw()
  72710. {
  72711. jassert (! target.isEmpty());
  72712. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  72713. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  72714. }
  72715. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  72716. {
  72717. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  72718. }
  72719. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  72720. const Rectangle<int>& target) throw()
  72721. {
  72722. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  72723. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  72724. }
  72725. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  72726. const double newW, const double newH,
  72727. const Rectangle<int>& target) throw()
  72728. {
  72729. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  72730. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  72731. }
  72732. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  72733. {
  72734. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  72735. updateFrom (comp.getBounds(), Rectangle<int>());
  72736. else
  72737. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  72738. }
  72739. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  72740. {
  72741. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72742. }
  72743. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  72744. {
  72745. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  72746. | absoluteFromParentBottomRight
  72747. | absoluteFromParentCentre
  72748. | proportionOfParentSize));
  72749. }
  72750. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  72751. {
  72752. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  72753. }
  72754. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  72755. {
  72756. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  72757. | absoluteFromParentBottomRight
  72758. | absoluteFromParentCentre
  72759. | proportionOfParentSize));
  72760. }
  72761. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  72762. {
  72763. return (SizeMode) wMode;
  72764. }
  72765. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  72766. {
  72767. return (SizeMode) hMode;
  72768. }
  72769. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  72770. const PositionMode xMode_,
  72771. const AnchorPoint yAnchor,
  72772. const PositionMode yMode_,
  72773. const SizeMode widthMode,
  72774. const SizeMode heightMode,
  72775. const Rectangle<int>& target) throw()
  72776. {
  72777. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  72778. {
  72779. double tx, tw;
  72780. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  72781. xMode = (uint8) (xAnchor | xMode_);
  72782. wMode = (uint8) widthMode;
  72783. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  72784. }
  72785. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  72786. {
  72787. double ty, th;
  72788. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  72789. yMode = (uint8) (yAnchor | yMode_);
  72790. hMode = (uint8) heightMode;
  72791. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  72792. }
  72793. }
  72794. bool PositionedRectangle::isPositionAbsolute() const throw()
  72795. {
  72796. return xMode == absoluteFromParentTopLeft
  72797. && yMode == absoluteFromParentTopLeft
  72798. && wMode == absoluteSize
  72799. && hMode == absoluteSize;
  72800. }
  72801. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  72802. {
  72803. if ((mode & proportionOfParentSize) != 0)
  72804. {
  72805. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72806. }
  72807. else
  72808. {
  72809. s << (roundToInt (value * 100.0) / 100.0);
  72810. if ((mode & absoluteFromParentBottomRight) != 0)
  72811. s << 'R';
  72812. else if ((mode & absoluteFromParentCentre) != 0)
  72813. s << 'C';
  72814. }
  72815. if ((mode & anchorAtRightOrBottom) != 0)
  72816. s << 'r';
  72817. else if ((mode & anchorAtCentre) != 0)
  72818. s << 'c';
  72819. }
  72820. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  72821. {
  72822. if (mode == proportionalSize)
  72823. s << (roundToInt (value * 100000.0) / 1000.0) << '%';
  72824. else if (mode == parentSizeMinusAbsolute)
  72825. s << (roundToInt (value * 100.0) / 100.0) << 'M';
  72826. else
  72827. s << (roundToInt (value * 100.0) / 100.0);
  72828. }
  72829. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  72830. {
  72831. if (s.containsChar ('r'))
  72832. mode = anchorAtRightOrBottom;
  72833. else if (s.containsChar ('c'))
  72834. mode = anchorAtCentre;
  72835. else
  72836. mode = anchorAtLeftOrTop;
  72837. if (s.containsChar ('%'))
  72838. {
  72839. mode |= proportionOfParentSize;
  72840. value = s.removeCharacters ("%rcRC").getDoubleValue() / 100.0;
  72841. }
  72842. else
  72843. {
  72844. if (s.containsChar ('R'))
  72845. mode |= absoluteFromParentBottomRight;
  72846. else if (s.containsChar ('C'))
  72847. mode |= absoluteFromParentCentre;
  72848. else
  72849. mode |= absoluteFromParentTopLeft;
  72850. value = s.removeCharacters ("rcRC").getDoubleValue();
  72851. }
  72852. }
  72853. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  72854. {
  72855. if (s.containsChar ('%'))
  72856. {
  72857. mode = proportionalSize;
  72858. value = s.upToFirstOccurrenceOf ("%", false, false).getDoubleValue() / 100.0;
  72859. }
  72860. else if (s.containsChar ('M'))
  72861. {
  72862. mode = parentSizeMinusAbsolute;
  72863. value = s.getDoubleValue();
  72864. }
  72865. else
  72866. {
  72867. mode = absoluteSize;
  72868. value = s.getDoubleValue();
  72869. }
  72870. }
  72871. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  72872. const double x_, const double w_,
  72873. const uint8 xMode_, const uint8 wMode_,
  72874. const int parentPos,
  72875. const int parentSize) const throw()
  72876. {
  72877. if (wMode_ == proportionalSize)
  72878. wOut = roundToInt (w_ * parentSize);
  72879. else if (wMode_ == parentSizeMinusAbsolute)
  72880. wOut = jmax (0, parentSize - roundToInt (w_));
  72881. else
  72882. wOut = roundToInt (w_);
  72883. if ((xMode_ & proportionOfParentSize) != 0)
  72884. xOut = parentPos + x_ * parentSize;
  72885. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72886. xOut = (parentPos + parentSize) - x_;
  72887. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72888. xOut = x_ + (parentPos + parentSize / 2);
  72889. else
  72890. xOut = x_ + parentPos;
  72891. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72892. xOut -= wOut;
  72893. else if ((xMode_ & anchorAtCentre) != 0)
  72894. xOut -= wOut / 2;
  72895. }
  72896. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  72897. double x_, const double w_,
  72898. const uint8 xMode_, const uint8 wMode_,
  72899. const int parentPos,
  72900. const int parentSize) const throw()
  72901. {
  72902. if (wMode_ == proportionalSize)
  72903. {
  72904. if (parentSize > 0)
  72905. wOut = w_ / parentSize;
  72906. }
  72907. else if (wMode_ == parentSizeMinusAbsolute)
  72908. wOut = parentSize - w_;
  72909. else
  72910. wOut = w_;
  72911. if ((xMode_ & anchorAtRightOrBottom) != 0)
  72912. x_ += w_;
  72913. else if ((xMode_ & anchorAtCentre) != 0)
  72914. x_ += w_ / 2;
  72915. if ((xMode_ & proportionOfParentSize) != 0)
  72916. {
  72917. if (parentSize > 0)
  72918. xOut = (x_ - parentPos) / parentSize;
  72919. }
  72920. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  72921. xOut = (parentPos + parentSize) - x_;
  72922. else if ((xMode_ & absoluteFromParentCentre) != 0)
  72923. xOut = x_ - (parentPos + parentSize / 2);
  72924. else
  72925. xOut = x_ - parentPos;
  72926. }
  72927. END_JUCE_NAMESPACE
  72928. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  72929. /*** Start of inlined file: juce_RectangleList.cpp ***/
  72930. BEGIN_JUCE_NAMESPACE
  72931. RectangleList::RectangleList() throw()
  72932. {
  72933. }
  72934. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  72935. {
  72936. if (! rect.isEmpty())
  72937. rects.add (rect);
  72938. }
  72939. RectangleList::RectangleList (const RectangleList& other) throw()
  72940. : rects (other.rects)
  72941. {
  72942. }
  72943. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  72944. {
  72945. rects = other.rects;
  72946. return *this;
  72947. }
  72948. RectangleList::~RectangleList() throw()
  72949. {
  72950. }
  72951. void RectangleList::clear() throw()
  72952. {
  72953. rects.clearQuick();
  72954. }
  72955. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  72956. {
  72957. if (((unsigned int) index) < (unsigned int) rects.size())
  72958. return rects.getReference (index);
  72959. return Rectangle<int>();
  72960. }
  72961. bool RectangleList::isEmpty() const throw()
  72962. {
  72963. return rects.size() == 0;
  72964. }
  72965. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  72966. : current (0),
  72967. owner (list),
  72968. index (list.rects.size())
  72969. {
  72970. }
  72971. RectangleList::Iterator::~Iterator() throw()
  72972. {
  72973. }
  72974. bool RectangleList::Iterator::next() throw()
  72975. {
  72976. if (--index >= 0)
  72977. {
  72978. current = & (owner.rects.getReference (index));
  72979. return true;
  72980. }
  72981. return false;
  72982. }
  72983. void RectangleList::add (const Rectangle<int>& rect) throw()
  72984. {
  72985. if (! rect.isEmpty())
  72986. {
  72987. if (rects.size() == 0)
  72988. {
  72989. rects.add (rect);
  72990. }
  72991. else
  72992. {
  72993. bool anyOverlaps = false;
  72994. int i;
  72995. for (i = rects.size(); --i >= 0;)
  72996. {
  72997. Rectangle<int>& ourRect = rects.getReference (i);
  72998. if (rect.intersects (ourRect))
  72999. {
  73000. if (rect.contains (ourRect))
  73001. rects.remove (i);
  73002. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73003. anyOverlaps = true;
  73004. }
  73005. }
  73006. if (anyOverlaps && rects.size() > 0)
  73007. {
  73008. RectangleList r (rect);
  73009. for (i = rects.size(); --i >= 0;)
  73010. {
  73011. const Rectangle<int>& ourRect = rects.getReference (i);
  73012. if (rect.intersects (ourRect))
  73013. {
  73014. r.subtract (ourRect);
  73015. if (r.rects.size() == 0)
  73016. return;
  73017. }
  73018. }
  73019. for (i = r.getNumRectangles(); --i >= 0;)
  73020. rects.add (r.rects.getReference (i));
  73021. }
  73022. else
  73023. {
  73024. rects.add (rect);
  73025. }
  73026. }
  73027. }
  73028. }
  73029. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73030. {
  73031. rects.add (rect);
  73032. }
  73033. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73034. {
  73035. if (rects.size() == 0)
  73036. {
  73037. if (w > 0 && h > 0)
  73038. rects.add (Rectangle<int> (x, y, w, h));
  73039. }
  73040. else
  73041. {
  73042. add (Rectangle<int> (x, y, w, h));
  73043. }
  73044. }
  73045. void RectangleList::add (const RectangleList& other) throw()
  73046. {
  73047. for (int i = 0; i < other.rects.size(); ++i)
  73048. add (other.rects.getReference (i));
  73049. }
  73050. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73051. {
  73052. const int originalNumRects = rects.size();
  73053. if (originalNumRects > 0)
  73054. {
  73055. const int x1 = rect.x;
  73056. const int y1 = rect.y;
  73057. const int x2 = x1 + rect.w;
  73058. const int y2 = y1 + rect.h;
  73059. for (int i = getNumRectangles(); --i >= 0;)
  73060. {
  73061. Rectangle<int>& r = rects.getReference (i);
  73062. const int rx1 = r.x;
  73063. const int ry1 = r.y;
  73064. const int rx2 = rx1 + r.w;
  73065. const int ry2 = ry1 + r.h;
  73066. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73067. {
  73068. if (x1 > rx1 && x1 < rx2)
  73069. {
  73070. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73071. {
  73072. r.w = x1 - rx1;
  73073. }
  73074. else
  73075. {
  73076. r.x = x1;
  73077. r.w = rx2 - x1;
  73078. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73079. i += 2;
  73080. }
  73081. }
  73082. else if (x2 > rx1 && x2 < rx2)
  73083. {
  73084. r.x = x2;
  73085. r.w = rx2 - x2;
  73086. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73087. {
  73088. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73089. i += 2;
  73090. }
  73091. }
  73092. else if (y1 > ry1 && y1 < ry2)
  73093. {
  73094. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73095. {
  73096. r.h = y1 - ry1;
  73097. }
  73098. else
  73099. {
  73100. r.y = y1;
  73101. r.h = ry2 - y1;
  73102. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73103. i += 2;
  73104. }
  73105. }
  73106. else if (y2 > ry1 && y2 < ry2)
  73107. {
  73108. r.y = y2;
  73109. r.h = ry2 - y2;
  73110. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73111. {
  73112. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73113. i += 2;
  73114. }
  73115. }
  73116. else
  73117. {
  73118. rects.remove (i);
  73119. }
  73120. }
  73121. }
  73122. if (rects.size() > originalNumRects + 10)
  73123. consolidate();
  73124. }
  73125. }
  73126. void RectangleList::subtract (const RectangleList& otherList) throw()
  73127. {
  73128. for (int i = otherList.rects.size(); --i >= 0;)
  73129. subtract (otherList.rects.getReference (i));
  73130. }
  73131. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73132. {
  73133. bool notEmpty = false;
  73134. if (rect.isEmpty())
  73135. {
  73136. clear();
  73137. }
  73138. else
  73139. {
  73140. for (int i = rects.size(); --i >= 0;)
  73141. {
  73142. Rectangle<int>& r = rects.getReference (i);
  73143. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73144. rects.remove (i);
  73145. else
  73146. notEmpty = true;
  73147. }
  73148. }
  73149. return notEmpty;
  73150. }
  73151. bool RectangleList::clipTo (const RectangleList& other) throw()
  73152. {
  73153. if (rects.size() == 0)
  73154. return false;
  73155. RectangleList result;
  73156. for (int j = 0; j < rects.size(); ++j)
  73157. {
  73158. const Rectangle<int>& rect = rects.getReference (j);
  73159. for (int i = other.rects.size(); --i >= 0;)
  73160. {
  73161. Rectangle<int> r (other.rects.getReference (i));
  73162. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73163. result.rects.add (r);
  73164. }
  73165. }
  73166. swapWith (result);
  73167. return ! isEmpty();
  73168. }
  73169. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73170. {
  73171. destRegion.clear();
  73172. if (! rect.isEmpty())
  73173. {
  73174. for (int i = rects.size(); --i >= 0;)
  73175. {
  73176. Rectangle<int> r (rects.getReference (i));
  73177. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73178. destRegion.rects.add (r);
  73179. }
  73180. }
  73181. return destRegion.rects.size() > 0;
  73182. }
  73183. void RectangleList::swapWith (RectangleList& otherList) throw()
  73184. {
  73185. rects.swapWithArray (otherList.rects);
  73186. }
  73187. void RectangleList::consolidate() throw()
  73188. {
  73189. int i;
  73190. for (i = 0; i < getNumRectangles() - 1; ++i)
  73191. {
  73192. Rectangle<int>& r = rects.getReference (i);
  73193. const int rx1 = r.x;
  73194. const int ry1 = r.y;
  73195. const int rx2 = rx1 + r.w;
  73196. const int ry2 = ry1 + r.h;
  73197. for (int j = rects.size(); --j > i;)
  73198. {
  73199. Rectangle<int>& r2 = rects.getReference (j);
  73200. const int jrx1 = r2.x;
  73201. const int jry1 = r2.y;
  73202. const int jrx2 = jrx1 + r2.w;
  73203. const int jry2 = jry1 + r2.h;
  73204. // if the vertical edges of any blocks are touching and their horizontals don't
  73205. // line up, split them horizontally..
  73206. if (jrx1 == rx2 || jrx2 == rx1)
  73207. {
  73208. if (jry1 > ry1 && jry1 < ry2)
  73209. {
  73210. r.h = jry1 - ry1;
  73211. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73212. i = -1;
  73213. break;
  73214. }
  73215. if (jry2 > ry1 && jry2 < ry2)
  73216. {
  73217. r.h = jry2 - ry1;
  73218. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73219. i = -1;
  73220. break;
  73221. }
  73222. else if (ry1 > jry1 && ry1 < jry2)
  73223. {
  73224. r2.h = ry1 - jry1;
  73225. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73226. i = -1;
  73227. break;
  73228. }
  73229. else if (ry2 > jry1 && ry2 < jry2)
  73230. {
  73231. r2.h = ry2 - jry1;
  73232. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73233. i = -1;
  73234. break;
  73235. }
  73236. }
  73237. }
  73238. }
  73239. for (i = 0; i < rects.size() - 1; ++i)
  73240. {
  73241. Rectangle<int>& r = rects.getReference (i);
  73242. for (int j = rects.size(); --j > i;)
  73243. {
  73244. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73245. {
  73246. rects.remove (j);
  73247. i = -1;
  73248. break;
  73249. }
  73250. }
  73251. }
  73252. }
  73253. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73254. {
  73255. for (int i = getNumRectangles(); --i >= 0;)
  73256. if (rects.getReference (i).contains (x, y))
  73257. return true;
  73258. return false;
  73259. }
  73260. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73261. {
  73262. if (rects.size() > 1)
  73263. {
  73264. RectangleList r (rectangleToCheck);
  73265. for (int i = rects.size(); --i >= 0;)
  73266. {
  73267. r.subtract (rects.getReference (i));
  73268. if (r.rects.size() == 0)
  73269. return true;
  73270. }
  73271. }
  73272. else if (rects.size() > 0)
  73273. {
  73274. return rects.getReference (0).contains (rectangleToCheck);
  73275. }
  73276. return false;
  73277. }
  73278. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73279. {
  73280. for (int i = rects.size(); --i >= 0;)
  73281. if (rects.getReference (i).intersects (rectangleToCheck))
  73282. return true;
  73283. return false;
  73284. }
  73285. bool RectangleList::intersects (const RectangleList& other) const throw()
  73286. {
  73287. for (int i = rects.size(); --i >= 0;)
  73288. if (other.intersectsRectangle (rects.getReference (i)))
  73289. return true;
  73290. return false;
  73291. }
  73292. const Rectangle<int> RectangleList::getBounds() const throw()
  73293. {
  73294. if (rects.size() <= 1)
  73295. {
  73296. if (rects.size() == 0)
  73297. return Rectangle<int>();
  73298. else
  73299. return rects.getReference (0);
  73300. }
  73301. else
  73302. {
  73303. const Rectangle<int>& r = rects.getReference (0);
  73304. int minX = r.x;
  73305. int minY = r.y;
  73306. int maxX = minX + r.w;
  73307. int maxY = minY + r.h;
  73308. for (int i = rects.size(); --i > 0;)
  73309. {
  73310. const Rectangle<int>& r2 = rects.getReference (i);
  73311. minX = jmin (minX, r2.x);
  73312. minY = jmin (minY, r2.y);
  73313. maxX = jmax (maxX, r2.getRight());
  73314. maxY = jmax (maxY, r2.getBottom());
  73315. }
  73316. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73317. }
  73318. }
  73319. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73320. {
  73321. for (int i = rects.size(); --i >= 0;)
  73322. {
  73323. Rectangle<int>& r = rects.getReference (i);
  73324. r.x += dx;
  73325. r.y += dy;
  73326. }
  73327. }
  73328. const Path RectangleList::toPath() const throw()
  73329. {
  73330. Path p;
  73331. for (int i = rects.size(); --i >= 0;)
  73332. {
  73333. const Rectangle<int>& r = rects.getReference (i);
  73334. p.addRectangle ((float) r.x,
  73335. (float) r.y,
  73336. (float) r.w,
  73337. (float) r.h);
  73338. }
  73339. return p;
  73340. }
  73341. END_JUCE_NAMESPACE
  73342. /*** End of inlined file: juce_RectangleList.cpp ***/
  73343. /*** Start of inlined file: juce_Image.cpp ***/
  73344. BEGIN_JUCE_NAMESPACE
  73345. static const int fullAlphaThreshold = 253;
  73346. Image::Image (const PixelFormat format_,
  73347. const int imageWidth_,
  73348. const int imageHeight_)
  73349. : format (format_),
  73350. imageWidth (imageWidth_),
  73351. imageHeight (imageHeight_),
  73352. imageData (0)
  73353. {
  73354. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73355. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73356. // actual image will be at least 1x1.
  73357. }
  73358. Image::Image (const PixelFormat format_,
  73359. const int imageWidth_,
  73360. const int imageHeight_,
  73361. const bool clearImage)
  73362. : format (format_),
  73363. imageWidth (imageWidth_),
  73364. imageHeight (imageHeight_)
  73365. {
  73366. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73367. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73368. // actual image will be at least 1x1.
  73369. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73370. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73371. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73372. imageData = imageDataAllocated;
  73373. }
  73374. Image::Image (const Image& other)
  73375. : format (other.format),
  73376. imageWidth (other.imageWidth),
  73377. imageHeight (other.imageHeight)
  73378. {
  73379. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73380. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73381. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73382. imageData = imageDataAllocated;
  73383. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73384. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73385. }
  73386. Image::~Image()
  73387. {
  73388. }
  73389. LowLevelGraphicsContext* Image::createLowLevelContext()
  73390. {
  73391. return new LowLevelGraphicsSoftwareRenderer (*this);
  73392. }
  73393. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73394. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73395. lineStride (image.lineStride),
  73396. pixelStride (image.pixelStride),
  73397. width (w),
  73398. height (h)
  73399. {
  73400. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73401. }
  73402. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73403. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73404. lineStride (image.lineStride),
  73405. pixelStride (image.pixelStride),
  73406. width (w),
  73407. height (h)
  73408. {
  73409. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73410. }
  73411. Image::BitmapData::~BitmapData()
  73412. {
  73413. }
  73414. void Image::setPixelData (int x, int y, int w, int h,
  73415. const uint8* sourcePixelData, int sourceLineStride)
  73416. {
  73417. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73418. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73419. {
  73420. const BitmapData dest (*this, x, y, w, h, true);
  73421. for (int i = 0; i < h; ++i)
  73422. {
  73423. memcpy (dest.getLinePointer(i),
  73424. sourcePixelData + sourceLineStride * i,
  73425. w * dest.pixelStride);
  73426. }
  73427. }
  73428. }
  73429. void Image::clear (int dx, int dy, int dw, int dh, const Colour& colourToClearTo)
  73430. {
  73431. if (Rectangle<int>::intersectRectangles (dx, dy, dw, dh, 0, 0, imageWidth, imageHeight))
  73432. {
  73433. const PixelARGB col (colourToClearTo.getPixelARGB());
  73434. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73435. uint8* dest = destData.data;
  73436. while (--dh >= 0)
  73437. {
  73438. uint8* line = dest;
  73439. dest += destData.lineStride;
  73440. if (isARGB())
  73441. {
  73442. for (int x = dw; --x >= 0;)
  73443. {
  73444. ((PixelARGB*) line)->set (col);
  73445. line += destData.pixelStride;
  73446. }
  73447. }
  73448. else if (isRGB())
  73449. {
  73450. for (int x = dw; --x >= 0;)
  73451. {
  73452. ((PixelRGB*) line)->set (col);
  73453. line += destData.pixelStride;
  73454. }
  73455. }
  73456. else
  73457. {
  73458. for (int x = dw; --x >= 0;)
  73459. {
  73460. *line = col.getAlpha();
  73461. line += destData.pixelStride;
  73462. }
  73463. }
  73464. }
  73465. }
  73466. }
  73467. Image* Image::createCopy (int newWidth, int newHeight,
  73468. const Graphics::ResamplingQuality quality) const
  73469. {
  73470. if (newWidth < 0)
  73471. newWidth = imageWidth;
  73472. if (newHeight < 0)
  73473. newHeight = imageHeight;
  73474. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73475. Graphics g (*newImage);
  73476. g.setImageResamplingQuality (quality);
  73477. g.drawImage (this,
  73478. 0, 0, newWidth, newHeight,
  73479. 0, 0, imageWidth, imageHeight,
  73480. false);
  73481. return newImage;
  73482. }
  73483. Image* Image::createCopyOfAlphaChannel() const
  73484. {
  73485. jassert (format != SingleChannel);
  73486. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73487. if (! hasAlphaChannel())
  73488. {
  73489. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  73490. }
  73491. else
  73492. {
  73493. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  73494. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  73495. for (int y = 0; y < imageHeight; ++y)
  73496. {
  73497. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  73498. uint8* dst = destData.getLinePointer (y);
  73499. for (int x = imageWidth; --x >= 0;)
  73500. {
  73501. *dst++ = src->getAlpha();
  73502. ++src;
  73503. }
  73504. }
  73505. }
  73506. return newImage;
  73507. }
  73508. const Colour Image::getPixelAt (const int x, const int y) const
  73509. {
  73510. Colour c;
  73511. if (((unsigned int) x) < (unsigned int) imageWidth
  73512. && ((unsigned int) y) < (unsigned int) imageHeight)
  73513. {
  73514. const BitmapData srcData (*this, x, y, 1, 1);
  73515. if (isARGB())
  73516. {
  73517. PixelARGB p (*(const PixelARGB*) srcData.data);
  73518. p.unpremultiply();
  73519. c = Colour (p.getARGB());
  73520. }
  73521. else if (isRGB())
  73522. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  73523. else
  73524. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  73525. }
  73526. return c;
  73527. }
  73528. void Image::setPixelAt (const int x, const int y,
  73529. const Colour& colour)
  73530. {
  73531. if (((unsigned int) x) < (unsigned int) imageWidth
  73532. && ((unsigned int) y) < (unsigned int) imageHeight)
  73533. {
  73534. const BitmapData destData (*this, x, y, 1, 1, true);
  73535. const PixelARGB col (colour.getPixelARGB());
  73536. if (isARGB())
  73537. ((PixelARGB*) destData.data)->set (col);
  73538. else if (isRGB())
  73539. ((PixelRGB*) destData.data)->set (col);
  73540. else
  73541. *(destData.data) = col.getAlpha();
  73542. }
  73543. }
  73544. void Image::multiplyAlphaAt (const int x, const int y,
  73545. const float multiplier)
  73546. {
  73547. if (((unsigned int) x) < (unsigned int) imageWidth
  73548. && ((unsigned int) y) < (unsigned int) imageHeight
  73549. && hasAlphaChannel())
  73550. {
  73551. const BitmapData destData (*this, x, y, 1, 1, true);
  73552. if (isARGB())
  73553. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  73554. else
  73555. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  73556. }
  73557. }
  73558. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  73559. {
  73560. if (hasAlphaChannel())
  73561. {
  73562. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73563. if (isARGB())
  73564. {
  73565. for (int y = 0; y < imageHeight; ++y)
  73566. {
  73567. uint8* p = destData.getLinePointer (y);
  73568. for (int x = 0; x < imageWidth; ++x)
  73569. {
  73570. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  73571. p += destData.pixelStride;
  73572. }
  73573. }
  73574. }
  73575. else
  73576. {
  73577. for (int y = 0; y < imageHeight; ++y)
  73578. {
  73579. uint8* p = destData.getLinePointer (y);
  73580. for (int x = 0; x < imageWidth; ++x)
  73581. {
  73582. *p = (uint8) (*p * amountToMultiplyBy);
  73583. p += destData.pixelStride;
  73584. }
  73585. }
  73586. }
  73587. }
  73588. else
  73589. {
  73590. jassertfalse // can't do this without an alpha-channel!
  73591. }
  73592. }
  73593. void Image::desaturate()
  73594. {
  73595. if (isARGB() || isRGB())
  73596. {
  73597. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  73598. if (isARGB())
  73599. {
  73600. for (int y = 0; y < imageHeight; ++y)
  73601. {
  73602. uint8* p = destData.getLinePointer (y);
  73603. for (int x = 0; x < imageWidth; ++x)
  73604. {
  73605. ((PixelARGB*) p)->desaturate();
  73606. p += destData.pixelStride;
  73607. }
  73608. }
  73609. }
  73610. else
  73611. {
  73612. for (int y = 0; y < imageHeight; ++y)
  73613. {
  73614. uint8* p = destData.getLinePointer (y);
  73615. for (int x = 0; x < imageWidth; ++x)
  73616. {
  73617. ((PixelRGB*) p)->desaturate();
  73618. p += destData.pixelStride;
  73619. }
  73620. }
  73621. }
  73622. }
  73623. }
  73624. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  73625. {
  73626. if (hasAlphaChannel())
  73627. {
  73628. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  73629. SparseSet <int> pixelsOnRow;
  73630. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  73631. for (int y = 0; y < imageHeight; ++y)
  73632. {
  73633. pixelsOnRow.clear();
  73634. const uint8* lineData = srcData.getLinePointer (y);
  73635. if (isARGB())
  73636. {
  73637. for (int x = 0; x < imageWidth; ++x)
  73638. {
  73639. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  73640. pixelsOnRow.addRange (x, 1);
  73641. lineData += srcData.pixelStride;
  73642. }
  73643. }
  73644. else
  73645. {
  73646. for (int x = 0; x < imageWidth; ++x)
  73647. {
  73648. if (*lineData >= threshold)
  73649. pixelsOnRow.addRange (x, 1);
  73650. lineData += srcData.pixelStride;
  73651. }
  73652. }
  73653. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  73654. {
  73655. int x, w;
  73656. if (pixelsOnRow.getRange (i, x, w))
  73657. result.add (Rectangle<int> (x, y, w, 1));
  73658. }
  73659. result.consolidate();
  73660. }
  73661. }
  73662. else
  73663. {
  73664. result.add (0, 0, imageWidth, imageHeight);
  73665. }
  73666. }
  73667. void Image::moveImageSection (int dx, int dy,
  73668. int sx, int sy,
  73669. int w, int h)
  73670. {
  73671. if (dx < 0)
  73672. {
  73673. w += dx;
  73674. sx -= dx;
  73675. dx = 0;
  73676. }
  73677. if (dy < 0)
  73678. {
  73679. h += dy;
  73680. sy -= dy;
  73681. dy = 0;
  73682. }
  73683. if (sx < 0)
  73684. {
  73685. w += sx;
  73686. dx -= sx;
  73687. sx = 0;
  73688. }
  73689. if (sy < 0)
  73690. {
  73691. h += sy;
  73692. dy -= sy;
  73693. sy = 0;
  73694. }
  73695. const int minX = jmin (dx, sx);
  73696. const int minY = jmin (dy, sy);
  73697. w = jmin (w, getWidth() - jmax (sx, dx));
  73698. h = jmin (h, getHeight() - jmax (sy, dy));
  73699. if (w > 0 && h > 0)
  73700. {
  73701. const int maxX = jmax (dx, sx) + w;
  73702. const int maxY = jmax (dy, sy) + h;
  73703. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  73704. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  73705. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  73706. const int lineSize = destData.pixelStride * w;
  73707. if (dy > sy)
  73708. {
  73709. while (--h >= 0)
  73710. {
  73711. const int offset = h * destData.lineStride;
  73712. memmove (dst + offset, src + offset, lineSize);
  73713. }
  73714. }
  73715. else if (dst != src)
  73716. {
  73717. while (--h >= 0)
  73718. {
  73719. memmove (dst, src, lineSize);
  73720. dst += destData.lineStride;
  73721. src += destData.lineStride;
  73722. }
  73723. }
  73724. }
  73725. }
  73726. END_JUCE_NAMESPACE
  73727. /*** End of inlined file: juce_Image.cpp ***/
  73728. /*** Start of inlined file: juce_ImageCache.cpp ***/
  73729. BEGIN_JUCE_NAMESPACE
  73730. struct ImageCache::Item
  73731. {
  73732. ScopedPointer <Image> image;
  73733. int64 hashCode;
  73734. int refCount;
  73735. uint32 releaseTime;
  73736. juce_UseDebuggingNewOperator
  73737. };
  73738. ImageCache* ImageCache::instance = 0;
  73739. int ImageCache::cacheTimeout = 5000;
  73740. ImageCache::ImageCache()
  73741. {
  73742. }
  73743. ImageCache::~ImageCache()
  73744. {
  73745. jassert (instance == this);
  73746. instance = 0;
  73747. }
  73748. Image* ImageCache::getFromHashCode (const int64 hashCode)
  73749. {
  73750. if (instance != 0)
  73751. {
  73752. const ScopedLock sl (instance->lock);
  73753. for (int i = instance->images.size(); --i >= 0;)
  73754. {
  73755. Item* const ci = instance->images.getUnchecked(i);
  73756. if (ci->hashCode == hashCode)
  73757. {
  73758. ci->refCount++;
  73759. return ci->image;
  73760. }
  73761. }
  73762. }
  73763. return 0;
  73764. }
  73765. void ImageCache::addImageToCache (Image* const image, const int64 hashCode)
  73766. {
  73767. if (image != 0)
  73768. {
  73769. if (instance == 0)
  73770. instance = new ImageCache();
  73771. Item* const newC = new Item();
  73772. newC->hashCode = hashCode;
  73773. newC->image = image;
  73774. newC->refCount = 1;
  73775. newC->releaseTime = 0;
  73776. const ScopedLock sl (instance->lock);
  73777. instance->images.add (newC);
  73778. }
  73779. }
  73780. void ImageCache::release (Image* const imageToRelease)
  73781. {
  73782. if (imageToRelease != 0 && instance != 0)
  73783. {
  73784. const ScopedLock sl (instance->lock);
  73785. for (int i = instance->images.size(); --i >= 0;)
  73786. {
  73787. Item* const ci = instance->images.getUnchecked(i);
  73788. if (static_cast <Image*> (ci->image) == imageToRelease)
  73789. {
  73790. if (--(ci->refCount) == 0)
  73791. ci->releaseTime = Time::getApproximateMillisecondCounter();
  73792. if (! instance->isTimerRunning())
  73793. instance->startTimer (999);
  73794. break;
  73795. }
  73796. }
  73797. }
  73798. }
  73799. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  73800. {
  73801. if (isImageInCache (imageToRelease))
  73802. release (imageToRelease);
  73803. else
  73804. delete imageToRelease;
  73805. }
  73806. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  73807. {
  73808. if (instance != 0)
  73809. {
  73810. const ScopedLock sl (instance->lock);
  73811. for (int i = instance->images.size(); --i >= 0;)
  73812. if (static_cast <Image*> (instance->images.getUnchecked(i)->image) == imageToLookFor)
  73813. return true;
  73814. }
  73815. return false;
  73816. }
  73817. void ImageCache::incReferenceCount (Image* const image)
  73818. {
  73819. if (instance != 0)
  73820. {
  73821. const ScopedLock sl (instance->lock);
  73822. for (int i = instance->images.size(); --i >= 0;)
  73823. {
  73824. Item* const ci = instance->images.getUnchecked(i);
  73825. if (static_cast <Image*> (ci->image) == image)
  73826. {
  73827. ci->refCount++;
  73828. return;
  73829. }
  73830. }
  73831. }
  73832. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  73833. }
  73834. void ImageCache::timerCallback()
  73835. {
  73836. int numberStillNeedingReleasing = 0;
  73837. const uint32 now = Time::getApproximateMillisecondCounter();
  73838. const ScopedLock sl (lock);
  73839. for (int i = images.size(); --i >= 0;)
  73840. {
  73841. Item* const ci = images.getUnchecked(i);
  73842. if (ci->refCount <= 0)
  73843. {
  73844. if (now > ci->releaseTime + cacheTimeout
  73845. || now < ci->releaseTime - 1000)
  73846. {
  73847. images.remove (i);
  73848. }
  73849. else
  73850. {
  73851. ++numberStillNeedingReleasing;
  73852. }
  73853. }
  73854. }
  73855. if (numberStillNeedingReleasing == 0)
  73856. stopTimer();
  73857. }
  73858. Image* ImageCache::getFromFile (const File& file)
  73859. {
  73860. const int64 hashCode = file.hashCode64();
  73861. Image* image = getFromHashCode (hashCode);
  73862. if (image == 0)
  73863. {
  73864. image = ImageFileFormat::loadFrom (file);
  73865. addImageToCache (image, hashCode);
  73866. }
  73867. return image;
  73868. }
  73869. Image* ImageCache::getFromMemory (const void* imageData, const int dataSize)
  73870. {
  73871. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  73872. Image* image = getFromHashCode (hashCode);
  73873. if (image == 0)
  73874. {
  73875. image = ImageFileFormat::loadFrom (imageData, dataSize);
  73876. addImageToCache (image, hashCode);
  73877. }
  73878. return image;
  73879. }
  73880. void ImageCache::setCacheTimeout (const int millisecs)
  73881. {
  73882. cacheTimeout = millisecs;
  73883. }
  73884. END_JUCE_NAMESPACE
  73885. /*** End of inlined file: juce_ImageCache.cpp ***/
  73886. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  73887. BEGIN_JUCE_NAMESPACE
  73888. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  73889. : values (size_ * size_),
  73890. size (size_)
  73891. {
  73892. clear();
  73893. }
  73894. ImageConvolutionKernel::~ImageConvolutionKernel()
  73895. {
  73896. }
  73897. float ImageConvolutionKernel::getKernelValue (const int x, const int y) const throw()
  73898. {
  73899. if (((unsigned int) x) < (unsigned int) size
  73900. && ((unsigned int) y) < (unsigned int) size)
  73901. {
  73902. return values [x + y * size];
  73903. }
  73904. else
  73905. {
  73906. jassertfalse;
  73907. return 0;
  73908. }
  73909. }
  73910. void ImageConvolutionKernel::setKernelValue (const int x, const int y, const float value) throw()
  73911. {
  73912. if (((unsigned int) x) < (unsigned int) size
  73913. && ((unsigned int) y) < (unsigned int) size)
  73914. {
  73915. values [x + y * size] = value;
  73916. }
  73917. else
  73918. {
  73919. jassertfalse;
  73920. }
  73921. }
  73922. void ImageConvolutionKernel::clear()
  73923. {
  73924. for (int i = size * size; --i >= 0;)
  73925. values[i] = 0;
  73926. }
  73927. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  73928. {
  73929. double currentTotal = 0.0;
  73930. for (int i = size * size; --i >= 0;)
  73931. currentTotal += values[i];
  73932. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  73933. }
  73934. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  73935. {
  73936. for (int i = size * size; --i >= 0;)
  73937. values[i] *= multiplier;
  73938. }
  73939. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  73940. {
  73941. const double radiusFactor = -1.0 / (radius * radius * 2);
  73942. const int centre = size >> 1;
  73943. for (int y = size; --y >= 0;)
  73944. {
  73945. for (int x = size; --x >= 0;)
  73946. {
  73947. const int cx = x - centre;
  73948. const int cy = y - centre;
  73949. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  73950. }
  73951. }
  73952. setOverallSum (1.0f);
  73953. }
  73954. void ImageConvolutionKernel::applyToImage (Image& destImage,
  73955. const Image* sourceImage,
  73956. const Rectangle<int>& destinationArea) const
  73957. {
  73958. ScopedPointer <Image> imageCreated;
  73959. if (sourceImage == 0)
  73960. {
  73961. sourceImage = imageCreated = destImage.createCopy();
  73962. }
  73963. else
  73964. {
  73965. jassert (sourceImage->getWidth() == destImage.getWidth()
  73966. && sourceImage->getHeight() == destImage.getHeight()
  73967. && sourceImage->getFormat() == destImage.getFormat());
  73968. if (sourceImage->getWidth() != destImage.getWidth()
  73969. || sourceImage->getHeight() != destImage.getHeight()
  73970. || sourceImage->getFormat() != destImage.getFormat())
  73971. return;
  73972. }
  73973. const Rectangle<int> area (destinationArea.getIntersection (destImage.getBounds()));
  73974. if (area.isEmpty())
  73975. return;
  73976. const int right = area.getRight();
  73977. const int bottom = area.getBottom();
  73978. const Image::BitmapData destData (destImage, area.getX(), area.getY(), area.getWidth(), area.getHeight(), true);
  73979. uint8* line = destData.data;
  73980. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  73981. if (destData.pixelStride == 4)
  73982. {
  73983. for (int y = area.getY(); y < bottom; ++y)
  73984. {
  73985. uint8* dest = line;
  73986. line += destData.lineStride;
  73987. for (int x = area.getX(); x < right; ++x)
  73988. {
  73989. float c1 = 0;
  73990. float c2 = 0;
  73991. float c3 = 0;
  73992. float c4 = 0;
  73993. for (int yy = 0; yy < size; ++yy)
  73994. {
  73995. const int sy = y + yy - (size >> 1);
  73996. if (sy >= srcData.height)
  73997. break;
  73998. if (sy >= 0)
  73999. {
  74000. int sx = x - (size >> 1);
  74001. const uint8* src = srcData.getPixelPointer (sx, sy);
  74002. for (int xx = 0; xx < size; ++xx)
  74003. {
  74004. if (sx >= srcData.width)
  74005. break;
  74006. if (sx >= 0)
  74007. {
  74008. const float kernelMult = values [xx + yy * size];
  74009. c1 += kernelMult * *src++;
  74010. c2 += kernelMult * *src++;
  74011. c3 += kernelMult * *src++;
  74012. c4 += kernelMult * *src++;
  74013. }
  74014. else
  74015. {
  74016. src += 4;
  74017. }
  74018. ++sx;
  74019. }
  74020. }
  74021. }
  74022. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74023. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74024. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74025. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74026. }
  74027. }
  74028. }
  74029. else if (destData.pixelStride == 3)
  74030. {
  74031. for (int y = area.getY(); y < bottom; ++y)
  74032. {
  74033. uint8* dest = line;
  74034. line += destData.lineStride;
  74035. for (int x = area.getX(); x < right; ++x)
  74036. {
  74037. float c1 = 0;
  74038. float c2 = 0;
  74039. float c3 = 0;
  74040. for (int yy = 0; yy < size; ++yy)
  74041. {
  74042. const int sy = y + yy - (size >> 1);
  74043. if (sy >= srcData.height)
  74044. break;
  74045. if (sy >= 0)
  74046. {
  74047. int sx = x - (size >> 1);
  74048. const uint8* src = srcData.getPixelPointer (sx, sy);
  74049. for (int xx = 0; xx < size; ++xx)
  74050. {
  74051. if (sx >= srcData.width)
  74052. break;
  74053. if (sx >= 0)
  74054. {
  74055. const float kernelMult = values [xx + yy * size];
  74056. c1 += kernelMult * *src++;
  74057. c2 += kernelMult * *src++;
  74058. c3 += kernelMult * *src++;
  74059. }
  74060. else
  74061. {
  74062. src += 3;
  74063. }
  74064. ++sx;
  74065. }
  74066. }
  74067. }
  74068. *dest++ = (uint8) roundToInt (c1);
  74069. *dest++ = (uint8) roundToInt (c2);
  74070. *dest++ = (uint8) roundToInt (c3);
  74071. }
  74072. }
  74073. }
  74074. }
  74075. END_JUCE_NAMESPACE
  74076. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74077. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74078. BEGIN_JUCE_NAMESPACE
  74079. /*** Start of inlined file: juce_GIFLoader.h ***/
  74080. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74081. #define __JUCE_GIFLOADER_JUCEHEADER__
  74082. #ifndef DOXYGEN
  74083. class GIFLoader
  74084. {
  74085. public:
  74086. GIFLoader (InputStream& in);
  74087. ~GIFLoader();
  74088. Image* getImage() const { return image; }
  74089. private:
  74090. Image* image;
  74091. InputStream& input;
  74092. uint8 buffer [300];
  74093. uint8 palette [256][4];
  74094. bool dataBlockIsZero, fresh, finished;
  74095. int currentBit, lastBit, lastByteIndex;
  74096. int codeSize, setCodeSize;
  74097. int maxCode, maxCodeSize;
  74098. int firstcode, oldcode;
  74099. int clearCode, end_code;
  74100. enum { maxGifCode = 1 << 12 };
  74101. int table [2] [maxGifCode];
  74102. int stack [2 * maxGifCode];
  74103. int *sp;
  74104. bool getSizeFromHeader (int& width, int& height);
  74105. bool readPalette (const int numCols);
  74106. int readDataBlock (unsigned char* dest);
  74107. int processExtension (int type, int& transparent);
  74108. int readLZWByte (bool initialise, int input_code_size);
  74109. int getCode (int code_size, bool initialise);
  74110. bool readImage (int width, int height, int interlace, int transparent);
  74111. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74112. GIFLoader (const GIFLoader&);
  74113. GIFLoader& operator= (const GIFLoader&);
  74114. };
  74115. #endif // DOXYGEN
  74116. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74117. /*** End of inlined file: juce_GIFLoader.h ***/
  74118. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74119. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74120. PNGImageFormat::PNGImageFormat() {}
  74121. PNGImageFormat::~PNGImageFormat() {}
  74122. const String PNGImageFormat::getFormatName()
  74123. {
  74124. return "PNG";
  74125. }
  74126. bool PNGImageFormat::canUnderstand (InputStream& in)
  74127. {
  74128. const int bytesNeeded = 4;
  74129. char header [bytesNeeded];
  74130. return in.read (header, bytesNeeded) == bytesNeeded
  74131. && header[1] == 'P'
  74132. && header[2] == 'N'
  74133. && header[3] == 'G';
  74134. }
  74135. Image* PNGImageFormat::decodeImage (InputStream& in)
  74136. {
  74137. return juce_loadPNGImageFromStream (in);
  74138. }
  74139. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74140. OutputStream& destStream)
  74141. {
  74142. return juce_writePNGImageToStream (sourceImage, destStream);
  74143. }
  74144. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74145. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74146. JPEGImageFormat::JPEGImageFormat()
  74147. : quality (-1.0f)
  74148. {
  74149. }
  74150. JPEGImageFormat::~JPEGImageFormat() {}
  74151. void JPEGImageFormat::setQuality (const float newQuality)
  74152. {
  74153. quality = newQuality;
  74154. }
  74155. const String JPEGImageFormat::getFormatName()
  74156. {
  74157. return "JPEG";
  74158. }
  74159. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74160. {
  74161. const int bytesNeeded = 10;
  74162. uint8 header [bytesNeeded];
  74163. if (in.read (header, bytesNeeded) == bytesNeeded)
  74164. {
  74165. return header[0] == 0xff
  74166. && header[1] == 0xd8
  74167. && header[2] == 0xff
  74168. && (header[3] == 0xe0 || header[3] == 0xe1);
  74169. }
  74170. return false;
  74171. }
  74172. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74173. {
  74174. return juce_loadJPEGImageFromStream (in);
  74175. }
  74176. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74177. OutputStream& destStream)
  74178. {
  74179. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74180. }
  74181. class GIFImageFormat : public ImageFileFormat
  74182. {
  74183. public:
  74184. GIFImageFormat() {}
  74185. ~GIFImageFormat() {}
  74186. const String getFormatName()
  74187. {
  74188. return "GIF";
  74189. }
  74190. bool canUnderstand (InputStream& in)
  74191. {
  74192. const int bytesNeeded = 4;
  74193. char header [bytesNeeded];
  74194. return (in.read (header, bytesNeeded) == bytesNeeded)
  74195. && header[0] == 'G'
  74196. && header[1] == 'I'
  74197. && header[2] == 'F';
  74198. }
  74199. Image* decodeImage (InputStream& in)
  74200. {
  74201. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74202. return loader->getImage();
  74203. }
  74204. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74205. {
  74206. return false;
  74207. }
  74208. };
  74209. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74210. {
  74211. static PNGImageFormat png;
  74212. static JPEGImageFormat jpg;
  74213. static GIFImageFormat gif;
  74214. ImageFileFormat* formats[4];
  74215. int numFormats = 0;
  74216. formats [numFormats++] = &png;
  74217. formats [numFormats++] = &jpg;
  74218. formats [numFormats++] = &gif;
  74219. const int64 streamPos = input.getPosition();
  74220. for (int i = 0; i < numFormats; ++i)
  74221. {
  74222. const bool found = formats[i]->canUnderstand (input);
  74223. input.setPosition (streamPos);
  74224. if (found)
  74225. return formats[i];
  74226. }
  74227. return 0;
  74228. }
  74229. Image* ImageFileFormat::loadFrom (InputStream& input)
  74230. {
  74231. ImageFileFormat* const format = findImageFormatForStream (input);
  74232. if (format != 0)
  74233. return format->decodeImage (input);
  74234. return 0;
  74235. }
  74236. Image* ImageFileFormat::loadFrom (const File& file)
  74237. {
  74238. InputStream* const in = file.createInputStream();
  74239. if (in != 0)
  74240. {
  74241. BufferedInputStream b (in, 8192, true);
  74242. return loadFrom (b);
  74243. }
  74244. return 0;
  74245. }
  74246. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74247. {
  74248. if (rawData != 0 && numBytes > 4)
  74249. {
  74250. MemoryInputStream stream (rawData, numBytes, false);
  74251. return loadFrom (stream);
  74252. }
  74253. return 0;
  74254. }
  74255. END_JUCE_NAMESPACE
  74256. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74257. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74258. BEGIN_JUCE_NAMESPACE
  74259. GIFLoader::GIFLoader (InputStream& in)
  74260. : image (0),
  74261. input (in),
  74262. dataBlockIsZero (false),
  74263. fresh (false),
  74264. finished (false)
  74265. {
  74266. currentBit = lastBit = lastByteIndex = 0;
  74267. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74268. firstcode = oldcode = 0;
  74269. clearCode = end_code = 0;
  74270. int imageWidth, imageHeight;
  74271. int transparent = -1;
  74272. if (! getSizeFromHeader (imageWidth, imageHeight))
  74273. return;
  74274. if ((imageWidth <= 0) || (imageHeight <= 0))
  74275. return;
  74276. unsigned char buf [16];
  74277. if (in.read (buf, 3) != 3)
  74278. return;
  74279. int numColours = 2 << (buf[0] & 7);
  74280. if ((buf[0] & 0x80) != 0)
  74281. readPalette (numColours);
  74282. for (;;)
  74283. {
  74284. if (input.read (buf, 1) != 1)
  74285. break;
  74286. if (buf[0] == ';')
  74287. break;
  74288. if (buf[0] == '!')
  74289. {
  74290. if (input.read (buf, 1) != 1)
  74291. break;
  74292. if (processExtension (buf[0], transparent) < 0)
  74293. break;
  74294. continue;
  74295. }
  74296. if (buf[0] != ',')
  74297. continue;
  74298. if (input.read (buf, 9) != 9)
  74299. break;
  74300. imageWidth = makeWord (buf[4], buf[5]);
  74301. imageHeight = makeWord (buf[6], buf[7]);
  74302. numColours = 2 << (buf[8] & 7);
  74303. if ((buf[8] & 0x80) != 0)
  74304. if (! readPalette (numColours))
  74305. break;
  74306. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74307. imageWidth, imageHeight, (transparent >= 0));
  74308. readImage (imageWidth, imageHeight,
  74309. (buf[8] & 0x40) != 0,
  74310. transparent);
  74311. break;
  74312. }
  74313. }
  74314. GIFLoader::~GIFLoader()
  74315. {
  74316. }
  74317. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74318. {
  74319. char b[8];
  74320. if (input.read (b, 6) == 6)
  74321. {
  74322. if ((strncmp ("GIF87a", b, 6) == 0)
  74323. || (strncmp ("GIF89a", b, 6) == 0))
  74324. {
  74325. if (input.read (b, 4) == 4)
  74326. {
  74327. w = makeWord (b[0], b[1]);
  74328. h = makeWord (b[2], b[3]);
  74329. return true;
  74330. }
  74331. }
  74332. }
  74333. return false;
  74334. }
  74335. bool GIFLoader::readPalette (const int numCols)
  74336. {
  74337. unsigned char rgb[4];
  74338. for (int i = 0; i < numCols; ++i)
  74339. {
  74340. input.read (rgb, 3);
  74341. palette [i][0] = rgb[0];
  74342. palette [i][1] = rgb[1];
  74343. palette [i][2] = rgb[2];
  74344. palette [i][3] = 0xff;
  74345. }
  74346. return true;
  74347. }
  74348. int GIFLoader::readDataBlock (unsigned char* const dest)
  74349. {
  74350. unsigned char n;
  74351. if (input.read (&n, 1) == 1)
  74352. {
  74353. dataBlockIsZero = (n == 0);
  74354. if (dataBlockIsZero || (input.read (dest, n) == n))
  74355. return n;
  74356. }
  74357. return -1;
  74358. }
  74359. int GIFLoader::processExtension (const int type, int& transparent)
  74360. {
  74361. unsigned char b [300];
  74362. int n = 0;
  74363. if (type == 0xf9)
  74364. {
  74365. n = readDataBlock (b);
  74366. if (n < 0)
  74367. return 1;
  74368. if ((b[0] & 0x1) != 0)
  74369. transparent = b[3];
  74370. }
  74371. do
  74372. {
  74373. n = readDataBlock (b);
  74374. }
  74375. while (n > 0);
  74376. return n;
  74377. }
  74378. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74379. {
  74380. if (initialise)
  74381. {
  74382. currentBit = 0;
  74383. lastBit = 0;
  74384. finished = false;
  74385. return 0;
  74386. }
  74387. if ((currentBit + codeSize_) >= lastBit)
  74388. {
  74389. if (finished)
  74390. return -1;
  74391. buffer[0] = buffer [lastByteIndex - 2];
  74392. buffer[1] = buffer [lastByteIndex - 1];
  74393. const int n = readDataBlock (&buffer[2]);
  74394. if (n == 0)
  74395. finished = true;
  74396. lastByteIndex = 2 + n;
  74397. currentBit = (currentBit - lastBit) + 16;
  74398. lastBit = (2 + n) * 8 ;
  74399. }
  74400. int result = 0;
  74401. int i = currentBit;
  74402. for (int j = 0; j < codeSize_; ++j)
  74403. {
  74404. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74405. ++i;
  74406. }
  74407. currentBit += codeSize_;
  74408. return result;
  74409. }
  74410. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74411. {
  74412. int code, incode, i;
  74413. if (initialise)
  74414. {
  74415. setCodeSize = inputCodeSize;
  74416. codeSize = setCodeSize + 1;
  74417. clearCode = 1 << setCodeSize;
  74418. end_code = clearCode + 1;
  74419. maxCodeSize = 2 * clearCode;
  74420. maxCode = clearCode + 2;
  74421. getCode (0, true);
  74422. fresh = true;
  74423. for (i = 0; i < clearCode; ++i)
  74424. {
  74425. table[0][i] = 0;
  74426. table[1][i] = i;
  74427. }
  74428. for (; i < maxGifCode; ++i)
  74429. {
  74430. table[0][i] = 0;
  74431. table[1][i] = 0;
  74432. }
  74433. sp = stack;
  74434. return 0;
  74435. }
  74436. else if (fresh)
  74437. {
  74438. fresh = false;
  74439. do
  74440. {
  74441. firstcode = oldcode
  74442. = getCode (codeSize, false);
  74443. }
  74444. while (firstcode == clearCode);
  74445. return firstcode;
  74446. }
  74447. if (sp > stack)
  74448. return *--sp;
  74449. while ((code = getCode (codeSize, false)) >= 0)
  74450. {
  74451. if (code == clearCode)
  74452. {
  74453. for (i = 0; i < clearCode; ++i)
  74454. {
  74455. table[0][i] = 0;
  74456. table[1][i] = i;
  74457. }
  74458. for (; i < maxGifCode; ++i)
  74459. {
  74460. table[0][i] = 0;
  74461. table[1][i] = 0;
  74462. }
  74463. codeSize = setCodeSize + 1;
  74464. maxCodeSize = 2 * clearCode;
  74465. maxCode = clearCode + 2;
  74466. sp = stack;
  74467. firstcode = oldcode = getCode (codeSize, false);
  74468. return firstcode;
  74469. }
  74470. else if (code == end_code)
  74471. {
  74472. if (dataBlockIsZero)
  74473. return -2;
  74474. unsigned char buf [260];
  74475. int n;
  74476. while ((n = readDataBlock (buf)) > 0)
  74477. {}
  74478. if (n != 0)
  74479. return -2;
  74480. }
  74481. incode = code;
  74482. if (code >= maxCode)
  74483. {
  74484. *sp++ = firstcode;
  74485. code = oldcode;
  74486. }
  74487. while (code >= clearCode)
  74488. {
  74489. *sp++ = table[1][code];
  74490. if (code == table[0][code])
  74491. return -2;
  74492. code = table[0][code];
  74493. }
  74494. *sp++ = firstcode = table[1][code];
  74495. if ((code = maxCode) < maxGifCode)
  74496. {
  74497. table[0][code] = oldcode;
  74498. table[1][code] = firstcode;
  74499. ++maxCode;
  74500. if ((maxCode >= maxCodeSize)
  74501. && (maxCodeSize < maxGifCode))
  74502. {
  74503. maxCodeSize <<= 1;
  74504. ++codeSize;
  74505. }
  74506. }
  74507. oldcode = incode;
  74508. if (sp > stack)
  74509. return *--sp;
  74510. }
  74511. return code;
  74512. }
  74513. bool GIFLoader::readImage (const int width, const int height,
  74514. const int interlace, const int transparent)
  74515. {
  74516. unsigned char c;
  74517. if (input.read (&c, 1) != 1
  74518. || readLZWByte (true, c) < 0)
  74519. return false;
  74520. if (transparent >= 0)
  74521. {
  74522. palette [transparent][0] = 0;
  74523. palette [transparent][1] = 0;
  74524. palette [transparent][2] = 0;
  74525. palette [transparent][3] = 0;
  74526. }
  74527. int index;
  74528. int xpos = 0, ypos = 0, pass = 0;
  74529. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  74530. uint8* p = destData.data;
  74531. const bool hasAlpha = image->hasAlphaChannel();
  74532. while ((index = readLZWByte (false, c)) >= 0)
  74533. {
  74534. const uint8* const paletteEntry = palette [index];
  74535. if (hasAlpha)
  74536. {
  74537. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  74538. paletteEntry[0],
  74539. paletteEntry[1],
  74540. paletteEntry[2]);
  74541. ((PixelARGB*) p)->premultiply();
  74542. }
  74543. else
  74544. {
  74545. ((PixelRGB*) p)->setARGB (0,
  74546. paletteEntry[0],
  74547. paletteEntry[1],
  74548. paletteEntry[2]);
  74549. }
  74550. p += destData.pixelStride;
  74551. ++xpos;
  74552. if (xpos == width)
  74553. {
  74554. xpos = 0;
  74555. if (interlace)
  74556. {
  74557. switch (pass)
  74558. {
  74559. case 0:
  74560. case 1:
  74561. ypos += 8;
  74562. break;
  74563. case 2:
  74564. ypos += 4;
  74565. break;
  74566. case 3:
  74567. ypos += 2;
  74568. break;
  74569. }
  74570. while (ypos >= height)
  74571. {
  74572. ++pass;
  74573. switch (pass)
  74574. {
  74575. case 1:
  74576. ypos = 4;
  74577. break;
  74578. case 2:
  74579. ypos = 2;
  74580. break;
  74581. case 3:
  74582. ypos = 1;
  74583. break;
  74584. default:
  74585. return true;
  74586. }
  74587. }
  74588. }
  74589. else
  74590. {
  74591. ++ypos;
  74592. }
  74593. p = destData.getPixelPointer (xpos, ypos);
  74594. }
  74595. if (ypos >= height)
  74596. break;
  74597. }
  74598. return true;
  74599. }
  74600. END_JUCE_NAMESPACE
  74601. /*** End of inlined file: juce_GIFLoader.cpp ***/
  74602. #endif
  74603. //==============================================================================
  74604. // some files include lots of library code, so leave them to the end to avoid cluttering
  74605. // up the build for the clean files.
  74606. #if JUCE_BUILD_CORE
  74607. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  74608. namespace zlibNamespace
  74609. {
  74610. #if JUCE_INCLUDE_ZLIB_CODE
  74611. #undef OS_CODE
  74612. #undef fdopen
  74613. /*** Start of inlined file: zlib.h ***/
  74614. #ifndef ZLIB_H
  74615. #define ZLIB_H
  74616. /*** Start of inlined file: zconf.h ***/
  74617. #ifndef ZCONF_H
  74618. #define ZCONF_H
  74619. // *** Just a few hacks here to make it compile nicely with Juce..
  74620. #define Z_PREFIX 1
  74621. #undef __MACTYPES__
  74622. #ifdef _MSC_VER
  74623. #pragma warning (disable : 4131 4127 4244 4267)
  74624. #endif
  74625. #ifdef Z_PREFIX
  74626. # define deflateInit_ z_deflateInit_
  74627. # define deflate z_deflate
  74628. # define deflateEnd z_deflateEnd
  74629. # define inflateInit_ z_inflateInit_
  74630. # define inflate z_inflate
  74631. # define inflateEnd z_inflateEnd
  74632. # define inflatePrime z_inflatePrime
  74633. # define inflateGetHeader z_inflateGetHeader
  74634. # define adler32_combine z_adler32_combine
  74635. # define crc32_combine z_crc32_combine
  74636. # define deflateInit2_ z_deflateInit2_
  74637. # define deflateSetDictionary z_deflateSetDictionary
  74638. # define deflateCopy z_deflateCopy
  74639. # define deflateReset z_deflateReset
  74640. # define deflateParams z_deflateParams
  74641. # define deflateBound z_deflateBound
  74642. # define deflatePrime z_deflatePrime
  74643. # define inflateInit2_ z_inflateInit2_
  74644. # define inflateSetDictionary z_inflateSetDictionary
  74645. # define inflateSync z_inflateSync
  74646. # define inflateSyncPoint z_inflateSyncPoint
  74647. # define inflateCopy z_inflateCopy
  74648. # define inflateReset z_inflateReset
  74649. # define inflateBack z_inflateBack
  74650. # define inflateBackEnd z_inflateBackEnd
  74651. # define compress z_compress
  74652. # define compress2 z_compress2
  74653. # define compressBound z_compressBound
  74654. # define uncompress z_uncompress
  74655. # define adler32 z_adler32
  74656. # define crc32 z_crc32
  74657. # define get_crc_table z_get_crc_table
  74658. # define zError z_zError
  74659. # define alloc_func z_alloc_func
  74660. # define free_func z_free_func
  74661. # define in_func z_in_func
  74662. # define out_func z_out_func
  74663. # define Byte z_Byte
  74664. # define uInt z_uInt
  74665. # define uLong z_uLong
  74666. # define Bytef z_Bytef
  74667. # define charf z_charf
  74668. # define intf z_intf
  74669. # define uIntf z_uIntf
  74670. # define uLongf z_uLongf
  74671. # define voidpf z_voidpf
  74672. # define voidp z_voidp
  74673. #endif
  74674. #if defined(__MSDOS__) && !defined(MSDOS)
  74675. # define MSDOS
  74676. #endif
  74677. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  74678. # define OS2
  74679. #endif
  74680. #if defined(_WINDOWS) && !defined(WINDOWS)
  74681. # define WINDOWS
  74682. #endif
  74683. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  74684. # ifndef WIN32
  74685. # define WIN32
  74686. # endif
  74687. #endif
  74688. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  74689. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  74690. # ifndef SYS16BIT
  74691. # define SYS16BIT
  74692. # endif
  74693. # endif
  74694. #endif
  74695. #ifdef SYS16BIT
  74696. # define MAXSEG_64K
  74697. #endif
  74698. #ifdef MSDOS
  74699. # define UNALIGNED_OK
  74700. #endif
  74701. #ifdef __STDC_VERSION__
  74702. # ifndef STDC
  74703. # define STDC
  74704. # endif
  74705. # if __STDC_VERSION__ >= 199901L
  74706. # ifndef STDC99
  74707. # define STDC99
  74708. # endif
  74709. # endif
  74710. #endif
  74711. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  74712. # define STDC
  74713. #endif
  74714. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  74715. # define STDC
  74716. #endif
  74717. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  74718. # define STDC
  74719. #endif
  74720. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  74721. # define STDC
  74722. #endif
  74723. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  74724. # define STDC
  74725. #endif
  74726. #ifndef STDC
  74727. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  74728. # define const /* note: need a more gentle solution here */
  74729. # endif
  74730. #endif
  74731. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  74732. # define NO_DUMMY_DECL
  74733. #endif
  74734. #ifndef MAX_MEM_LEVEL
  74735. # ifdef MAXSEG_64K
  74736. # define MAX_MEM_LEVEL 8
  74737. # else
  74738. # define MAX_MEM_LEVEL 9
  74739. # endif
  74740. #endif
  74741. #ifndef MAX_WBITS
  74742. # define MAX_WBITS 15 /* 32K LZ77 window */
  74743. #endif
  74744. #ifndef OF /* function prototypes */
  74745. # ifdef STDC
  74746. # define OF(args) args
  74747. # else
  74748. # define OF(args) ()
  74749. # endif
  74750. #endif
  74751. #ifdef SYS16BIT
  74752. # if defined(M_I86SM) || defined(M_I86MM)
  74753. # define SMALL_MEDIUM
  74754. # ifdef _MSC_VER
  74755. # define FAR _far
  74756. # else
  74757. # define FAR far
  74758. # endif
  74759. # endif
  74760. # if (defined(__SMALL__) || defined(__MEDIUM__))
  74761. # define SMALL_MEDIUM
  74762. # ifdef __BORLANDC__
  74763. # define FAR _far
  74764. # else
  74765. # define FAR far
  74766. # endif
  74767. # endif
  74768. #endif
  74769. #if defined(WINDOWS) || defined(WIN32)
  74770. # ifdef ZLIB_DLL
  74771. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  74772. # ifdef ZLIB_INTERNAL
  74773. # define ZEXTERN extern __declspec(dllexport)
  74774. # else
  74775. # define ZEXTERN extern __declspec(dllimport)
  74776. # endif
  74777. # endif
  74778. # endif /* ZLIB_DLL */
  74779. # ifdef ZLIB_WINAPI
  74780. # ifdef FAR
  74781. # undef FAR
  74782. # endif
  74783. # include <windows.h>
  74784. # define ZEXPORT WINAPI
  74785. # ifdef WIN32
  74786. # define ZEXPORTVA WINAPIV
  74787. # else
  74788. # define ZEXPORTVA FAR CDECL
  74789. # endif
  74790. # endif
  74791. #endif
  74792. #if defined (__BEOS__)
  74793. # ifdef ZLIB_DLL
  74794. # ifdef ZLIB_INTERNAL
  74795. # define ZEXPORT __declspec(dllexport)
  74796. # define ZEXPORTVA __declspec(dllexport)
  74797. # else
  74798. # define ZEXPORT __declspec(dllimport)
  74799. # define ZEXPORTVA __declspec(dllimport)
  74800. # endif
  74801. # endif
  74802. #endif
  74803. #ifndef ZEXTERN
  74804. # define ZEXTERN extern
  74805. #endif
  74806. #ifndef ZEXPORT
  74807. # define ZEXPORT
  74808. #endif
  74809. #ifndef ZEXPORTVA
  74810. # define ZEXPORTVA
  74811. #endif
  74812. #ifndef FAR
  74813. # define FAR
  74814. #endif
  74815. #if !defined(__MACTYPES__)
  74816. typedef unsigned char Byte; /* 8 bits */
  74817. #endif
  74818. typedef unsigned int uInt; /* 16 bits or more */
  74819. typedef unsigned long uLong; /* 32 bits or more */
  74820. #ifdef SMALL_MEDIUM
  74821. # define Bytef Byte FAR
  74822. #else
  74823. typedef Byte FAR Bytef;
  74824. #endif
  74825. typedef char FAR charf;
  74826. typedef int FAR intf;
  74827. typedef uInt FAR uIntf;
  74828. typedef uLong FAR uLongf;
  74829. #ifdef STDC
  74830. typedef void const *voidpc;
  74831. typedef void FAR *voidpf;
  74832. typedef void *voidp;
  74833. #else
  74834. typedef Byte const *voidpc;
  74835. typedef Byte FAR *voidpf;
  74836. typedef Byte *voidp;
  74837. #endif
  74838. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  74839. # include <sys/types.h> /* for off_t */
  74840. # include <unistd.h> /* for SEEK_* and off_t */
  74841. # ifdef VMS
  74842. # include <unixio.h> /* for off_t */
  74843. # endif
  74844. # define z_off_t off_t
  74845. #endif
  74846. #ifndef SEEK_SET
  74847. # define SEEK_SET 0 /* Seek from beginning of file. */
  74848. # define SEEK_CUR 1 /* Seek from current position. */
  74849. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  74850. #endif
  74851. #ifndef z_off_t
  74852. # define z_off_t long
  74853. #endif
  74854. #if defined(__OS400__)
  74855. # define NO_vsnprintf
  74856. #endif
  74857. #if defined(__MVS__)
  74858. # define NO_vsnprintf
  74859. # ifdef FAR
  74860. # undef FAR
  74861. # endif
  74862. #endif
  74863. #if defined(__MVS__)
  74864. # pragma map(deflateInit_,"DEIN")
  74865. # pragma map(deflateInit2_,"DEIN2")
  74866. # pragma map(deflateEnd,"DEEND")
  74867. # pragma map(deflateBound,"DEBND")
  74868. # pragma map(inflateInit_,"ININ")
  74869. # pragma map(inflateInit2_,"ININ2")
  74870. # pragma map(inflateEnd,"INEND")
  74871. # pragma map(inflateSync,"INSY")
  74872. # pragma map(inflateSetDictionary,"INSEDI")
  74873. # pragma map(compressBound,"CMBND")
  74874. # pragma map(inflate_table,"INTABL")
  74875. # pragma map(inflate_fast,"INFA")
  74876. # pragma map(inflate_copyright,"INCOPY")
  74877. #endif
  74878. #endif /* ZCONF_H */
  74879. /*** End of inlined file: zconf.h ***/
  74880. #ifdef __cplusplus
  74881. extern "C" {
  74882. #endif
  74883. #define ZLIB_VERSION "1.2.3"
  74884. #define ZLIB_VERNUM 0x1230
  74885. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  74886. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  74887. struct internal_state;
  74888. typedef struct z_stream_s {
  74889. Bytef *next_in; /* next input byte */
  74890. uInt avail_in; /* number of bytes available at next_in */
  74891. uLong total_in; /* total nb of input bytes read so far */
  74892. Bytef *next_out; /* next output byte should be put there */
  74893. uInt avail_out; /* remaining free space at next_out */
  74894. uLong total_out; /* total nb of bytes output so far */
  74895. char *msg; /* last error message, NULL if no error */
  74896. struct internal_state FAR *state; /* not visible by applications */
  74897. alloc_func zalloc; /* used to allocate the internal state */
  74898. free_func zfree; /* used to free the internal state */
  74899. voidpf opaque; /* private data object passed to zalloc and zfree */
  74900. int data_type; /* best guess about the data type: binary or text */
  74901. uLong adler; /* adler32 value of the uncompressed data */
  74902. uLong reserved; /* reserved for future use */
  74903. } z_stream;
  74904. typedef z_stream FAR *z_streamp;
  74905. typedef struct gz_header_s {
  74906. int text; /* true if compressed data believed to be text */
  74907. uLong time; /* modification time */
  74908. int xflags; /* extra flags (not used when writing a gzip file) */
  74909. int os; /* operating system */
  74910. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  74911. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  74912. uInt extra_max; /* space at extra (only when reading header) */
  74913. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  74914. uInt name_max; /* space at name (only when reading header) */
  74915. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  74916. uInt comm_max; /* space at comment (only when reading header) */
  74917. int hcrc; /* true if there was or will be a header crc */
  74918. int done; /* true when done reading gzip header (not used
  74919. when writing a gzip file) */
  74920. } gz_header;
  74921. typedef gz_header FAR *gz_headerp;
  74922. #define Z_NO_FLUSH 0
  74923. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  74924. #define Z_SYNC_FLUSH 2
  74925. #define Z_FULL_FLUSH 3
  74926. #define Z_FINISH 4
  74927. #define Z_BLOCK 5
  74928. #define Z_OK 0
  74929. #define Z_STREAM_END 1
  74930. #define Z_NEED_DICT 2
  74931. #define Z_ERRNO (-1)
  74932. #define Z_STREAM_ERROR (-2)
  74933. #define Z_DATA_ERROR (-3)
  74934. #define Z_MEM_ERROR (-4)
  74935. #define Z_BUF_ERROR (-5)
  74936. #define Z_VERSION_ERROR (-6)
  74937. #define Z_NO_COMPRESSION 0
  74938. #define Z_BEST_SPEED 1
  74939. #define Z_BEST_COMPRESSION 9
  74940. #define Z_DEFAULT_COMPRESSION (-1)
  74941. #define Z_FILTERED 1
  74942. #define Z_HUFFMAN_ONLY 2
  74943. #define Z_RLE 3
  74944. #define Z_FIXED 4
  74945. #define Z_DEFAULT_STRATEGY 0
  74946. #define Z_BINARY 0
  74947. #define Z_TEXT 1
  74948. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  74949. #define Z_UNKNOWN 2
  74950. #define Z_DEFLATED 8
  74951. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  74952. #define zlib_version zlibVersion()
  74953. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  74954. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  74955. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  74956. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  74957. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  74958. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  74959. const Bytef *dictionary,
  74960. uInt dictLength));
  74961. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  74962. z_streamp source));
  74963. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  74964. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  74965. int level,
  74966. int strategy));
  74967. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  74968. int good_length,
  74969. int max_lazy,
  74970. int nice_length,
  74971. int max_chain));
  74972. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  74973. uLong sourceLen));
  74974. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  74975. int bits,
  74976. int value));
  74977. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  74978. gz_headerp head));
  74979. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  74980. const Bytef *dictionary,
  74981. uInt dictLength));
  74982. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  74983. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  74984. z_streamp source));
  74985. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  74986. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  74987. int bits,
  74988. int value));
  74989. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  74990. gz_headerp head));
  74991. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  74992. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  74993. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  74994. in_func in, void FAR *in_desc,
  74995. out_func out, void FAR *out_desc));
  74996. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  74997. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  74998. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  74999. const Bytef *source, uLong sourceLen));
  75000. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75001. const Bytef *source, uLong sourceLen,
  75002. int level));
  75003. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75004. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75005. const Bytef *source, uLong sourceLen));
  75006. typedef voidp gzFile;
  75007. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75008. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75009. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75010. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75011. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75012. voidpc buf, unsigned len));
  75013. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75014. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75015. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75016. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75017. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75018. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75019. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75020. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75021. z_off_t offset, int whence));
  75022. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75023. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75024. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75025. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75026. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75027. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75028. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75029. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75030. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75031. z_off_t len2));
  75032. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75033. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75034. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75035. const char *version, int stream_size));
  75036. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75037. const char *version, int stream_size));
  75038. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75039. int windowBits, int memLevel,
  75040. int strategy, const char *version,
  75041. int stream_size));
  75042. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75043. const char *version, int stream_size));
  75044. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75045. unsigned char FAR *window,
  75046. const char *version,
  75047. int stream_size));
  75048. #define deflateInit(strm, level) \
  75049. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75050. #define inflateInit(strm) \
  75051. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75052. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75053. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75054. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75055. #define inflateInit2(strm, windowBits) \
  75056. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75057. #define inflateBackInit(strm, windowBits, window) \
  75058. inflateBackInit_((strm), (windowBits), (window), \
  75059. ZLIB_VERSION, sizeof(z_stream))
  75060. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75061. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75062. #endif
  75063. ZEXTERN const char * ZEXPORT zError OF((int));
  75064. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75065. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75066. #ifdef __cplusplus
  75067. }
  75068. #endif
  75069. #endif /* ZLIB_H */
  75070. /*** End of inlined file: zlib.h ***/
  75071. #undef OS_CODE
  75072. #else
  75073. #include <zlib.h>
  75074. #endif
  75075. }
  75076. BEGIN_JUCE_NAMESPACE
  75077. // internal helper object that holds the zlib structures so they don't have to be
  75078. // included publicly.
  75079. class GZIPCompressorHelper
  75080. {
  75081. public:
  75082. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75083. : data (0),
  75084. dataSize (0),
  75085. compLevel (compressionLevel),
  75086. strategy (0),
  75087. setParams (true),
  75088. streamIsValid (false),
  75089. finished (false),
  75090. shouldFinish (false)
  75091. {
  75092. using namespace zlibNamespace;
  75093. zerostruct (stream);
  75094. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75095. nowrap ? -MAX_WBITS : MAX_WBITS,
  75096. 8, strategy) == Z_OK);
  75097. }
  75098. ~GZIPCompressorHelper()
  75099. {
  75100. using namespace zlibNamespace;
  75101. if (streamIsValid)
  75102. deflateEnd (&stream);
  75103. }
  75104. bool needsInput() const throw()
  75105. {
  75106. return dataSize <= 0;
  75107. }
  75108. void setInput (const uint8* const newData, const int size) throw()
  75109. {
  75110. data = newData;
  75111. dataSize = size;
  75112. }
  75113. int doNextBlock (uint8* const dest, const int destSize) throw()
  75114. {
  75115. using namespace zlibNamespace;
  75116. if (streamIsValid)
  75117. {
  75118. stream.next_in = const_cast <uint8*> (data);
  75119. stream.next_out = dest;
  75120. stream.avail_in = dataSize;
  75121. stream.avail_out = destSize;
  75122. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75123. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75124. setParams = false;
  75125. switch (result)
  75126. {
  75127. case Z_STREAM_END:
  75128. finished = true;
  75129. // Deliberate fall-through..
  75130. case Z_OK:
  75131. data += dataSize - stream.avail_in;
  75132. dataSize = stream.avail_in;
  75133. return destSize - stream.avail_out;
  75134. default:
  75135. break;
  75136. }
  75137. }
  75138. return 0;
  75139. }
  75140. private:
  75141. zlibNamespace::z_stream stream;
  75142. const uint8* data;
  75143. int dataSize, compLevel, strategy;
  75144. bool setParams, streamIsValid;
  75145. public:
  75146. bool finished, shouldFinish;
  75147. };
  75148. const int gzipCompBufferSize = 32768;
  75149. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75150. int compressionLevel,
  75151. const bool deleteDestStream,
  75152. const bool noWrap)
  75153. : destStream (destStream_),
  75154. streamToDelete (deleteDestStream ? destStream_ : 0),
  75155. buffer (gzipCompBufferSize)
  75156. {
  75157. if (compressionLevel < 1 || compressionLevel > 9)
  75158. compressionLevel = -1;
  75159. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75160. }
  75161. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75162. {
  75163. flush();
  75164. }
  75165. void GZIPCompressorOutputStream::flush()
  75166. {
  75167. if (! helper->finished)
  75168. {
  75169. helper->shouldFinish = true;
  75170. while (! helper->finished)
  75171. doNextBlock();
  75172. }
  75173. destStream->flush();
  75174. }
  75175. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75176. {
  75177. if (! helper->finished)
  75178. {
  75179. helper->setInput (static_cast <const uint8*> (destBuffer), howMany);
  75180. while (! helper->needsInput())
  75181. {
  75182. if (! doNextBlock())
  75183. return false;
  75184. }
  75185. }
  75186. return true;
  75187. }
  75188. bool GZIPCompressorOutputStream::doNextBlock()
  75189. {
  75190. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75191. if (len > 0)
  75192. return destStream->write (buffer, len);
  75193. else
  75194. return true;
  75195. }
  75196. int64 GZIPCompressorOutputStream::getPosition()
  75197. {
  75198. return destStream->getPosition();
  75199. }
  75200. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75201. {
  75202. jassertfalse // can't do it!
  75203. return false;
  75204. }
  75205. END_JUCE_NAMESPACE
  75206. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75207. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75208. #if JUCE_MSVC
  75209. #pragma warning (push)
  75210. #pragma warning (disable: 4309 4305)
  75211. #endif
  75212. namespace zlibNamespace
  75213. {
  75214. #if JUCE_INCLUDE_ZLIB_CODE
  75215. extern "C"
  75216. {
  75217. #undef OS_CODE
  75218. #undef fdopen
  75219. #define ZLIB_INTERNAL
  75220. #define NO_DUMMY_DECL
  75221. /*** Start of inlined file: adler32.c ***/
  75222. #define ZLIB_INTERNAL
  75223. #define BASE 65521UL /* largest prime smaller than 65536 */
  75224. #define NMAX 5552
  75225. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75226. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75227. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75228. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75229. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75230. #ifdef NO_DIVIDE
  75231. # define MOD(a) \
  75232. do { \
  75233. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75234. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75235. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75236. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75237. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75238. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75239. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75240. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75241. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75242. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75243. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75244. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75245. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75246. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75247. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75248. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75249. if (a >= BASE) a -= BASE; \
  75250. } while (0)
  75251. # define MOD4(a) \
  75252. do { \
  75253. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75254. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75255. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75256. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75257. if (a >= BASE) a -= BASE; \
  75258. } while (0)
  75259. #else
  75260. # define MOD(a) a %= BASE
  75261. # define MOD4(a) a %= BASE
  75262. #endif
  75263. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75264. {
  75265. unsigned long sum2;
  75266. unsigned n;
  75267. sum2 = (adler >> 16) & 0xffff;
  75268. adler &= 0xffff;
  75269. if (len == 1) {
  75270. adler += buf[0];
  75271. if (adler >= BASE)
  75272. adler -= BASE;
  75273. sum2 += adler;
  75274. if (sum2 >= BASE)
  75275. sum2 -= BASE;
  75276. return adler | (sum2 << 16);
  75277. }
  75278. if (buf == Z_NULL)
  75279. return 1L;
  75280. if (len < 16) {
  75281. while (len--) {
  75282. adler += *buf++;
  75283. sum2 += adler;
  75284. }
  75285. if (adler >= BASE)
  75286. adler -= BASE;
  75287. MOD4(sum2); /* only added so many BASE's */
  75288. return adler | (sum2 << 16);
  75289. }
  75290. while (len >= NMAX) {
  75291. len -= NMAX;
  75292. n = NMAX / 16; /* NMAX is divisible by 16 */
  75293. do {
  75294. DO16(buf); /* 16 sums unrolled */
  75295. buf += 16;
  75296. } while (--n);
  75297. MOD(adler);
  75298. MOD(sum2);
  75299. }
  75300. if (len) { /* avoid modulos if none remaining */
  75301. while (len >= 16) {
  75302. len -= 16;
  75303. DO16(buf);
  75304. buf += 16;
  75305. }
  75306. while (len--) {
  75307. adler += *buf++;
  75308. sum2 += adler;
  75309. }
  75310. MOD(adler);
  75311. MOD(sum2);
  75312. }
  75313. return adler | (sum2 << 16);
  75314. }
  75315. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75316. {
  75317. unsigned long sum1;
  75318. unsigned long sum2;
  75319. unsigned rem;
  75320. rem = (unsigned)(len2 % BASE);
  75321. sum1 = adler1 & 0xffff;
  75322. sum2 = rem * sum1;
  75323. MOD(sum2);
  75324. sum1 += (adler2 & 0xffff) + BASE - 1;
  75325. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75326. if (sum1 > BASE) sum1 -= BASE;
  75327. if (sum1 > BASE) sum1 -= BASE;
  75328. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75329. if (sum2 > BASE) sum2 -= BASE;
  75330. return sum1 | (sum2 << 16);
  75331. }
  75332. /*** End of inlined file: adler32.c ***/
  75333. /*** Start of inlined file: compress.c ***/
  75334. #define ZLIB_INTERNAL
  75335. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75336. uLong sourceLen, int level)
  75337. {
  75338. z_stream stream;
  75339. int err;
  75340. stream.next_in = (Bytef*)source;
  75341. stream.avail_in = (uInt)sourceLen;
  75342. #ifdef MAXSEG_64K
  75343. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75344. #endif
  75345. stream.next_out = dest;
  75346. stream.avail_out = (uInt)*destLen;
  75347. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75348. stream.zalloc = (alloc_func)0;
  75349. stream.zfree = (free_func)0;
  75350. stream.opaque = (voidpf)0;
  75351. err = deflateInit(&stream, level);
  75352. if (err != Z_OK) return err;
  75353. err = deflate(&stream, Z_FINISH);
  75354. if (err != Z_STREAM_END) {
  75355. deflateEnd(&stream);
  75356. return err == Z_OK ? Z_BUF_ERROR : err;
  75357. }
  75358. *destLen = stream.total_out;
  75359. err = deflateEnd(&stream);
  75360. return err;
  75361. }
  75362. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75363. {
  75364. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75365. }
  75366. uLong ZEXPORT compressBound (uLong sourceLen)
  75367. {
  75368. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75369. }
  75370. /*** End of inlined file: compress.c ***/
  75371. #undef DO1
  75372. #undef DO8
  75373. /*** Start of inlined file: crc32.c ***/
  75374. #ifdef MAKECRCH
  75375. # include <stdio.h>
  75376. # ifndef DYNAMIC_CRC_TABLE
  75377. # define DYNAMIC_CRC_TABLE
  75378. # endif /* !DYNAMIC_CRC_TABLE */
  75379. #endif /* MAKECRCH */
  75380. /*** Start of inlined file: zutil.h ***/
  75381. #ifndef ZUTIL_H
  75382. #define ZUTIL_H
  75383. #define ZLIB_INTERNAL
  75384. #ifdef STDC
  75385. # ifndef _WIN32_WCE
  75386. # include <stddef.h>
  75387. # endif
  75388. # include <string.h>
  75389. # include <stdlib.h>
  75390. #endif
  75391. #ifdef NO_ERRNO_H
  75392. # ifdef _WIN32_WCE
  75393. # define errno z_errno
  75394. # endif
  75395. extern int errno;
  75396. #else
  75397. # ifndef _WIN32_WCE
  75398. # include <errno.h>
  75399. # endif
  75400. #endif
  75401. #ifndef local
  75402. # define local static
  75403. #endif
  75404. typedef unsigned char uch;
  75405. typedef uch FAR uchf;
  75406. typedef unsigned short ush;
  75407. typedef ush FAR ushf;
  75408. typedef unsigned long ulg;
  75409. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75410. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75411. #define ERR_RETURN(strm,err) \
  75412. return (strm->msg = (char*)ERR_MSG(err), (err))
  75413. #ifndef DEF_WBITS
  75414. # define DEF_WBITS MAX_WBITS
  75415. #endif
  75416. #if MAX_MEM_LEVEL >= 8
  75417. # define DEF_MEM_LEVEL 8
  75418. #else
  75419. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75420. #endif
  75421. #define STORED_BLOCK 0
  75422. #define STATIC_TREES 1
  75423. #define DYN_TREES 2
  75424. #define MIN_MATCH 3
  75425. #define MAX_MATCH 258
  75426. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75427. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75428. # define OS_CODE 0x00
  75429. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75430. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75431. void _Cdecl farfree( void *block );
  75432. void *_Cdecl farmalloc( unsigned long nbytes );
  75433. # else
  75434. # include <alloc.h>
  75435. # endif
  75436. # else /* MSC or DJGPP */
  75437. # include <malloc.h>
  75438. # endif
  75439. #endif
  75440. #ifdef AMIGA
  75441. # define OS_CODE 0x01
  75442. #endif
  75443. #if defined(VAXC) || defined(VMS)
  75444. # define OS_CODE 0x02
  75445. # define F_OPEN(name, mode) \
  75446. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75447. #endif
  75448. #if defined(ATARI) || defined(atarist)
  75449. # define OS_CODE 0x05
  75450. #endif
  75451. #ifdef OS2
  75452. # define OS_CODE 0x06
  75453. # ifdef M_I86
  75454. #include <malloc.h>
  75455. # endif
  75456. #endif
  75457. #if defined(MACOS) || TARGET_OS_MAC
  75458. # define OS_CODE 0x07
  75459. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75460. # include <unix.h> /* for fdopen */
  75461. # else
  75462. # ifndef fdopen
  75463. # define fdopen(fd,mode) NULL /* No fdopen() */
  75464. # endif
  75465. # endif
  75466. #endif
  75467. #ifdef TOPS20
  75468. # define OS_CODE 0x0a
  75469. #endif
  75470. #ifdef WIN32
  75471. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75472. # define OS_CODE 0x0b
  75473. # endif
  75474. #endif
  75475. #ifdef __50SERIES /* Prime/PRIMOS */
  75476. # define OS_CODE 0x0f
  75477. #endif
  75478. #if defined(_BEOS_) || defined(RISCOS)
  75479. # define fdopen(fd,mode) NULL /* No fdopen() */
  75480. #endif
  75481. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75482. # if defined(_WIN32_WCE)
  75483. # define fdopen(fd,mode) NULL /* No fdopen() */
  75484. # ifndef _PTRDIFF_T_DEFINED
  75485. typedef int ptrdiff_t;
  75486. # define _PTRDIFF_T_DEFINED
  75487. # endif
  75488. # else
  75489. # define fdopen(fd,type) _fdopen(fd,type)
  75490. # endif
  75491. #endif
  75492. #ifndef OS_CODE
  75493. # define OS_CODE 0x03 /* assume Unix */
  75494. #endif
  75495. #ifndef F_OPEN
  75496. # define F_OPEN(name, mode) fopen((name), (mode))
  75497. #endif
  75498. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  75499. # ifndef HAVE_VSNPRINTF
  75500. # define HAVE_VSNPRINTF
  75501. # endif
  75502. #endif
  75503. #if defined(__CYGWIN__)
  75504. # ifndef HAVE_VSNPRINTF
  75505. # define HAVE_VSNPRINTF
  75506. # endif
  75507. #endif
  75508. #ifndef HAVE_VSNPRINTF
  75509. # ifdef MSDOS
  75510. # define NO_vsnprintf
  75511. # endif
  75512. # ifdef __TURBOC__
  75513. # define NO_vsnprintf
  75514. # endif
  75515. # ifdef WIN32
  75516. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  75517. # define vsnprintf _vsnprintf
  75518. # endif
  75519. # endif
  75520. # ifdef __SASC
  75521. # define NO_vsnprintf
  75522. # endif
  75523. #endif
  75524. #ifdef VMS
  75525. # define NO_vsnprintf
  75526. #endif
  75527. #if defined(pyr)
  75528. # define NO_MEMCPY
  75529. #endif
  75530. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  75531. # define NO_MEMCPY
  75532. #endif
  75533. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  75534. # define HAVE_MEMCPY
  75535. #endif
  75536. #ifdef HAVE_MEMCPY
  75537. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  75538. # define zmemcpy _fmemcpy
  75539. # define zmemcmp _fmemcmp
  75540. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  75541. # else
  75542. # define zmemcpy memcpy
  75543. # define zmemcmp memcmp
  75544. # define zmemzero(dest, len) memset(dest, 0, len)
  75545. # endif
  75546. #else
  75547. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  75548. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  75549. extern void zmemzero OF((Bytef* dest, uInt len));
  75550. #endif
  75551. #ifdef DEBUG
  75552. # include <stdio.h>
  75553. extern int z_verbose;
  75554. extern void z_error OF((const char *m));
  75555. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  75556. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  75557. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  75558. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  75559. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  75560. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  75561. #else
  75562. # define Assert(cond,msg)
  75563. # define Trace(x)
  75564. # define Tracev(x)
  75565. # define Tracevv(x)
  75566. # define Tracec(c,x)
  75567. # define Tracecv(c,x)
  75568. #endif
  75569. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  75570. void zcfree OF((voidpf opaque, voidpf ptr));
  75571. #define ZALLOC(strm, items, size) \
  75572. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  75573. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  75574. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  75575. #endif /* ZUTIL_H */
  75576. /*** End of inlined file: zutil.h ***/
  75577. /* for STDC and FAR definitions */
  75578. #define local static
  75579. #ifndef NOBYFOUR
  75580. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  75581. # include <limits.h>
  75582. # define BYFOUR
  75583. # if (UINT_MAX == 0xffffffffUL)
  75584. typedef unsigned int u4;
  75585. # else
  75586. # if (ULONG_MAX == 0xffffffffUL)
  75587. typedef unsigned long u4;
  75588. # else
  75589. # if (USHRT_MAX == 0xffffffffUL)
  75590. typedef unsigned short u4;
  75591. # else
  75592. # undef BYFOUR /* can't find a four-byte integer type! */
  75593. # endif
  75594. # endif
  75595. # endif
  75596. # endif /* STDC */
  75597. #endif /* !NOBYFOUR */
  75598. #ifdef BYFOUR
  75599. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  75600. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  75601. local unsigned long crc32_little OF((unsigned long,
  75602. const unsigned char FAR *, unsigned));
  75603. local unsigned long crc32_big OF((unsigned long,
  75604. const unsigned char FAR *, unsigned));
  75605. # define TBLS 8
  75606. #else
  75607. # define TBLS 1
  75608. #endif /* BYFOUR */
  75609. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  75610. unsigned long vec));
  75611. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  75612. #ifdef DYNAMIC_CRC_TABLE
  75613. local volatile int crc_table_empty = 1;
  75614. local unsigned long FAR crc_table[TBLS][256];
  75615. local void make_crc_table OF((void));
  75616. #ifdef MAKECRCH
  75617. local void write_table OF((FILE *, const unsigned long FAR *));
  75618. #endif /* MAKECRCH */
  75619. local void make_crc_table()
  75620. {
  75621. unsigned long c;
  75622. int n, k;
  75623. unsigned long poly; /* polynomial exclusive-or pattern */
  75624. static volatile int first = 1; /* flag to limit concurrent making */
  75625. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  75626. if (first) {
  75627. first = 0;
  75628. poly = 0UL;
  75629. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  75630. poly |= 1UL << (31 - p[n]);
  75631. for (n = 0; n < 256; n++) {
  75632. c = (unsigned long)n;
  75633. for (k = 0; k < 8; k++)
  75634. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  75635. crc_table[0][n] = c;
  75636. }
  75637. #ifdef BYFOUR
  75638. for (n = 0; n < 256; n++) {
  75639. c = crc_table[0][n];
  75640. crc_table[4][n] = REV(c);
  75641. for (k = 1; k < 4; k++) {
  75642. c = crc_table[0][c & 0xff] ^ (c >> 8);
  75643. crc_table[k][n] = c;
  75644. crc_table[k + 4][n] = REV(c);
  75645. }
  75646. }
  75647. #endif /* BYFOUR */
  75648. crc_table_empty = 0;
  75649. }
  75650. else { /* not first */
  75651. while (crc_table_empty)
  75652. ;
  75653. }
  75654. #ifdef MAKECRCH
  75655. {
  75656. FILE *out;
  75657. out = fopen("crc32.h", "w");
  75658. if (out == NULL) return;
  75659. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  75660. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  75661. fprintf(out, "local const unsigned long FAR ");
  75662. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  75663. write_table(out, crc_table[0]);
  75664. # ifdef BYFOUR
  75665. fprintf(out, "#ifdef BYFOUR\n");
  75666. for (k = 1; k < 8; k++) {
  75667. fprintf(out, " },\n {\n");
  75668. write_table(out, crc_table[k]);
  75669. }
  75670. fprintf(out, "#endif\n");
  75671. # endif /* BYFOUR */
  75672. fprintf(out, " }\n};\n");
  75673. fclose(out);
  75674. }
  75675. #endif /* MAKECRCH */
  75676. }
  75677. #ifdef MAKECRCH
  75678. local void write_table(out, table)
  75679. FILE *out;
  75680. const unsigned long FAR *table;
  75681. {
  75682. int n;
  75683. for (n = 0; n < 256; n++)
  75684. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  75685. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  75686. }
  75687. #endif /* MAKECRCH */
  75688. #else /* !DYNAMIC_CRC_TABLE */
  75689. /*** Start of inlined file: crc32.h ***/
  75690. local const unsigned long FAR crc_table[TBLS][256] =
  75691. {
  75692. {
  75693. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  75694. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  75695. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  75696. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  75697. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  75698. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  75699. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  75700. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  75701. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  75702. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  75703. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  75704. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  75705. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  75706. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  75707. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  75708. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  75709. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  75710. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  75711. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  75712. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  75713. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  75714. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  75715. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  75716. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  75717. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  75718. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  75719. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  75720. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  75721. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  75722. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  75723. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  75724. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  75725. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  75726. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  75727. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  75728. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  75729. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  75730. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  75731. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  75732. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  75733. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  75734. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  75735. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  75736. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  75737. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  75738. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  75739. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  75740. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  75741. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  75742. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  75743. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  75744. 0x2d02ef8dUL
  75745. #ifdef BYFOUR
  75746. },
  75747. {
  75748. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  75749. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  75750. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  75751. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  75752. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  75753. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  75754. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  75755. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  75756. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  75757. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  75758. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  75759. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  75760. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  75761. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  75762. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  75763. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  75764. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  75765. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  75766. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  75767. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  75768. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  75769. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  75770. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  75771. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  75772. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  75773. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  75774. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  75775. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  75776. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  75777. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  75778. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  75779. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  75780. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  75781. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  75782. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  75783. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  75784. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  75785. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  75786. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  75787. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  75788. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  75789. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  75790. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  75791. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  75792. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  75793. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  75794. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  75795. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  75796. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  75797. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  75798. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  75799. 0x9324fd72UL
  75800. },
  75801. {
  75802. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  75803. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  75804. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  75805. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  75806. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  75807. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  75808. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  75809. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  75810. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  75811. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  75812. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  75813. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  75814. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  75815. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  75816. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  75817. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  75818. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  75819. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  75820. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  75821. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  75822. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  75823. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  75824. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  75825. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  75826. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  75827. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  75828. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  75829. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  75830. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  75831. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  75832. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  75833. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  75834. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  75835. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  75836. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  75837. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  75838. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  75839. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  75840. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  75841. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  75842. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  75843. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  75844. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  75845. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  75846. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  75847. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  75848. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  75849. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  75850. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  75851. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  75852. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  75853. 0xbe9834edUL
  75854. },
  75855. {
  75856. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  75857. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  75858. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  75859. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  75860. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  75861. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  75862. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  75863. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  75864. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  75865. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  75866. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  75867. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  75868. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  75869. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  75870. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  75871. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  75872. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  75873. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  75874. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  75875. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  75876. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  75877. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  75878. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  75879. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  75880. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  75881. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  75882. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  75883. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  75884. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  75885. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  75886. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  75887. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  75888. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  75889. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  75890. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  75891. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  75892. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  75893. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  75894. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  75895. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  75896. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  75897. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  75898. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  75899. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  75900. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  75901. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  75902. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  75903. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  75904. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  75905. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  75906. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  75907. 0xde0506f1UL
  75908. },
  75909. {
  75910. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  75911. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  75912. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  75913. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  75914. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  75915. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  75916. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  75917. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  75918. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  75919. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  75920. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  75921. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  75922. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  75923. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  75924. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  75925. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  75926. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  75927. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  75928. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  75929. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  75930. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  75931. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  75932. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  75933. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  75934. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  75935. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  75936. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  75937. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  75938. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  75939. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  75940. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  75941. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  75942. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  75943. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  75944. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  75945. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  75946. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  75947. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  75948. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  75949. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  75950. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  75951. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  75952. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  75953. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  75954. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  75955. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  75956. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  75957. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  75958. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  75959. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  75960. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  75961. 0x8def022dUL
  75962. },
  75963. {
  75964. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  75965. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  75966. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  75967. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  75968. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  75969. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  75970. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  75971. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  75972. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  75973. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  75974. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  75975. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  75976. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  75977. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  75978. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  75979. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  75980. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  75981. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  75982. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  75983. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  75984. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  75985. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  75986. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  75987. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  75988. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  75989. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  75990. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  75991. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  75992. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  75993. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  75994. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  75995. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  75996. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  75997. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  75998. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  75999. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76000. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76001. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76002. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76003. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76004. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76005. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76006. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76007. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76008. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76009. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76010. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76011. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76012. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76013. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76014. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76015. 0x72fd2493UL
  76016. },
  76017. {
  76018. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76019. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76020. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76021. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76022. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76023. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76024. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76025. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76026. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76027. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76028. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76029. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76030. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76031. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76032. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76033. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76034. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76035. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76036. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76037. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76038. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76039. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76040. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76041. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76042. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76043. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76044. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76045. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76046. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76047. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76048. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76049. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76050. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76051. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76052. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76053. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76054. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76055. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76056. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76057. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76058. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76059. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76060. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76061. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76062. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76063. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76064. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76065. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76066. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76067. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76068. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76069. 0xed3498beUL
  76070. },
  76071. {
  76072. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76073. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76074. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76075. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76076. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76077. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76078. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76079. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76080. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76081. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76082. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76083. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76084. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76085. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76086. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76087. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76088. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76089. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76090. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76091. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76092. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76093. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76094. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76095. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76096. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76097. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76098. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76099. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76100. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76101. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76102. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76103. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76104. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76105. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76106. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76107. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76108. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76109. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76110. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76111. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76112. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76113. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76114. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76115. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76116. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76117. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76118. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76119. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76120. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76121. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76122. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76123. 0xf10605deUL
  76124. #endif
  76125. }
  76126. };
  76127. /*** End of inlined file: crc32.h ***/
  76128. #endif /* DYNAMIC_CRC_TABLE */
  76129. const unsigned long FAR * ZEXPORT get_crc_table()
  76130. {
  76131. #ifdef DYNAMIC_CRC_TABLE
  76132. if (crc_table_empty)
  76133. make_crc_table();
  76134. #endif /* DYNAMIC_CRC_TABLE */
  76135. return (const unsigned long FAR *)crc_table;
  76136. }
  76137. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76138. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76139. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76140. {
  76141. if (buf == Z_NULL) return 0UL;
  76142. #ifdef DYNAMIC_CRC_TABLE
  76143. if (crc_table_empty)
  76144. make_crc_table();
  76145. #endif /* DYNAMIC_CRC_TABLE */
  76146. #ifdef BYFOUR
  76147. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76148. u4 endian;
  76149. endian = 1;
  76150. if (*((unsigned char *)(&endian)))
  76151. return crc32_little(crc, buf, len);
  76152. else
  76153. return crc32_big(crc, buf, len);
  76154. }
  76155. #endif /* BYFOUR */
  76156. crc = crc ^ 0xffffffffUL;
  76157. while (len >= 8) {
  76158. DO8;
  76159. len -= 8;
  76160. }
  76161. if (len) do {
  76162. DO1;
  76163. } while (--len);
  76164. return crc ^ 0xffffffffUL;
  76165. }
  76166. #ifdef BYFOUR
  76167. #define DOLIT4 c ^= *buf4++; \
  76168. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76169. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76170. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76171. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76172. {
  76173. register u4 c;
  76174. register const u4 FAR *buf4;
  76175. c = (u4)crc;
  76176. c = ~c;
  76177. while (len && ((ptrdiff_t)buf & 3)) {
  76178. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76179. len--;
  76180. }
  76181. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76182. while (len >= 32) {
  76183. DOLIT32;
  76184. len -= 32;
  76185. }
  76186. while (len >= 4) {
  76187. DOLIT4;
  76188. len -= 4;
  76189. }
  76190. buf = (const unsigned char FAR *)buf4;
  76191. if (len) do {
  76192. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76193. } while (--len);
  76194. c = ~c;
  76195. return (unsigned long)c;
  76196. }
  76197. #define DOBIG4 c ^= *++buf4; \
  76198. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76199. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76200. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76201. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76202. {
  76203. register u4 c;
  76204. register const u4 FAR *buf4;
  76205. c = REV((u4)crc);
  76206. c = ~c;
  76207. while (len && ((ptrdiff_t)buf & 3)) {
  76208. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76209. len--;
  76210. }
  76211. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76212. buf4--;
  76213. while (len >= 32) {
  76214. DOBIG32;
  76215. len -= 32;
  76216. }
  76217. while (len >= 4) {
  76218. DOBIG4;
  76219. len -= 4;
  76220. }
  76221. buf4++;
  76222. buf = (const unsigned char FAR *)buf4;
  76223. if (len) do {
  76224. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76225. } while (--len);
  76226. c = ~c;
  76227. return (unsigned long)(REV(c));
  76228. }
  76229. #endif /* BYFOUR */
  76230. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76231. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76232. {
  76233. unsigned long sum;
  76234. sum = 0;
  76235. while (vec) {
  76236. if (vec & 1)
  76237. sum ^= *mat;
  76238. vec >>= 1;
  76239. mat++;
  76240. }
  76241. return sum;
  76242. }
  76243. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76244. {
  76245. int n;
  76246. for (n = 0; n < GF2_DIM; n++)
  76247. square[n] = gf2_matrix_times(mat, mat[n]);
  76248. }
  76249. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76250. {
  76251. int n;
  76252. unsigned long row;
  76253. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76254. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76255. if (len2 == 0)
  76256. return crc1;
  76257. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76258. row = 1;
  76259. for (n = 1; n < GF2_DIM; n++) {
  76260. odd[n] = row;
  76261. row <<= 1;
  76262. }
  76263. gf2_matrix_square(even, odd);
  76264. gf2_matrix_square(odd, even);
  76265. do {
  76266. gf2_matrix_square(even, odd);
  76267. if (len2 & 1)
  76268. crc1 = gf2_matrix_times(even, crc1);
  76269. len2 >>= 1;
  76270. if (len2 == 0)
  76271. break;
  76272. gf2_matrix_square(odd, even);
  76273. if (len2 & 1)
  76274. crc1 = gf2_matrix_times(odd, crc1);
  76275. len2 >>= 1;
  76276. } while (len2 != 0);
  76277. crc1 ^= crc2;
  76278. return crc1;
  76279. }
  76280. /*** End of inlined file: crc32.c ***/
  76281. /*** Start of inlined file: deflate.c ***/
  76282. /*** Start of inlined file: deflate.h ***/
  76283. #ifndef DEFLATE_H
  76284. #define DEFLATE_H
  76285. #ifndef NO_GZIP
  76286. # define GZIP
  76287. #endif
  76288. #define NO_DUMMY_DECL
  76289. #define LENGTH_CODES 29
  76290. #define LITERALS 256
  76291. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76292. #define D_CODES 30
  76293. #define BL_CODES 19
  76294. #define HEAP_SIZE (2*L_CODES+1)
  76295. #define MAX_BITS 15
  76296. #define INIT_STATE 42
  76297. #define EXTRA_STATE 69
  76298. #define NAME_STATE 73
  76299. #define COMMENT_STATE 91
  76300. #define HCRC_STATE 103
  76301. #define BUSY_STATE 113
  76302. #define FINISH_STATE 666
  76303. typedef struct ct_data_s {
  76304. union {
  76305. ush freq; /* frequency count */
  76306. ush code; /* bit string */
  76307. } fc;
  76308. union {
  76309. ush dad; /* father node in Huffman tree */
  76310. ush len; /* length of bit string */
  76311. } dl;
  76312. } FAR ct_data;
  76313. #define Freq fc.freq
  76314. #define Code fc.code
  76315. #define Dad dl.dad
  76316. #define Len dl.len
  76317. typedef struct static_tree_desc_s static_tree_desc;
  76318. typedef struct tree_desc_s {
  76319. ct_data *dyn_tree; /* the dynamic tree */
  76320. int max_code; /* largest code with non zero frequency */
  76321. static_tree_desc *stat_desc; /* the corresponding static tree */
  76322. } FAR tree_desc;
  76323. typedef ush Pos;
  76324. typedef Pos FAR Posf;
  76325. typedef unsigned IPos;
  76326. typedef struct internal_state {
  76327. z_streamp strm; /* pointer back to this zlib stream */
  76328. int status; /* as the name implies */
  76329. Bytef *pending_buf; /* output still pending */
  76330. ulg pending_buf_size; /* size of pending_buf */
  76331. Bytef *pending_out; /* next pending byte to output to the stream */
  76332. uInt pending; /* nb of bytes in the pending buffer */
  76333. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76334. gz_headerp gzhead; /* gzip header information to write */
  76335. uInt gzindex; /* where in extra, name, or comment */
  76336. Byte method; /* STORED (for zip only) or DEFLATED */
  76337. int last_flush; /* value of flush param for previous deflate call */
  76338. uInt w_size; /* LZ77 window size (32K by default) */
  76339. uInt w_bits; /* log2(w_size) (8..16) */
  76340. uInt w_mask; /* w_size - 1 */
  76341. Bytef *window;
  76342. ulg window_size;
  76343. Posf *prev;
  76344. Posf *head; /* Heads of the hash chains or NIL. */
  76345. uInt ins_h; /* hash index of string to be inserted */
  76346. uInt hash_size; /* number of elements in hash table */
  76347. uInt hash_bits; /* log2(hash_size) */
  76348. uInt hash_mask; /* hash_size-1 */
  76349. uInt hash_shift;
  76350. long block_start;
  76351. uInt match_length; /* length of best match */
  76352. IPos prev_match; /* previous match */
  76353. int match_available; /* set if previous match exists */
  76354. uInt strstart; /* start of string to insert */
  76355. uInt match_start; /* start of matching string */
  76356. uInt lookahead; /* number of valid bytes ahead in window */
  76357. uInt prev_length;
  76358. uInt max_chain_length;
  76359. uInt max_lazy_match;
  76360. # define max_insert_length max_lazy_match
  76361. int level; /* compression level (1..9) */
  76362. int strategy; /* favor or force Huffman coding*/
  76363. uInt good_match;
  76364. int nice_match; /* Stop searching when current match exceeds this */
  76365. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76366. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76367. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76368. struct tree_desc_s l_desc; /* desc. for literal tree */
  76369. struct tree_desc_s d_desc; /* desc. for distance tree */
  76370. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76371. ush bl_count[MAX_BITS+1];
  76372. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76373. int heap_len; /* number of elements in the heap */
  76374. int heap_max; /* element of largest frequency */
  76375. uch depth[2*L_CODES+1];
  76376. uchf *l_buf; /* buffer for literals or lengths */
  76377. uInt lit_bufsize;
  76378. uInt last_lit; /* running index in l_buf */
  76379. ushf *d_buf;
  76380. ulg opt_len; /* bit length of current block with optimal trees */
  76381. ulg static_len; /* bit length of current block with static trees */
  76382. uInt matches; /* number of string matches in current block */
  76383. int last_eob_len; /* bit length of EOB code for last block */
  76384. #ifdef DEBUG
  76385. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76386. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76387. #endif
  76388. ush bi_buf;
  76389. int bi_valid;
  76390. } FAR deflate_state;
  76391. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76392. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76393. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76394. void _tr_init OF((deflate_state *s));
  76395. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76396. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76397. int eof));
  76398. void _tr_align OF((deflate_state *s));
  76399. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76400. int eof));
  76401. #define d_code(dist) \
  76402. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76403. #ifndef DEBUG
  76404. #if defined(GEN_TREES_H) || !defined(STDC)
  76405. extern uch _length_code[];
  76406. extern uch _dist_code[];
  76407. #else
  76408. extern const uch _length_code[];
  76409. extern const uch _dist_code[];
  76410. #endif
  76411. # define _tr_tally_lit(s, c, flush) \
  76412. { uch cc = (c); \
  76413. s->d_buf[s->last_lit] = 0; \
  76414. s->l_buf[s->last_lit++] = cc; \
  76415. s->dyn_ltree[cc].Freq++; \
  76416. flush = (s->last_lit == s->lit_bufsize-1); \
  76417. }
  76418. # define _tr_tally_dist(s, distance, length, flush) \
  76419. { uch len = (length); \
  76420. ush dist = (distance); \
  76421. s->d_buf[s->last_lit] = dist; \
  76422. s->l_buf[s->last_lit++] = len; \
  76423. dist--; \
  76424. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76425. s->dyn_dtree[d_code(dist)].Freq++; \
  76426. flush = (s->last_lit == s->lit_bufsize-1); \
  76427. }
  76428. #else
  76429. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76430. # define _tr_tally_dist(s, distance, length, flush) \
  76431. flush = _tr_tally(s, distance, length)
  76432. #endif
  76433. #endif /* DEFLATE_H */
  76434. /*** End of inlined file: deflate.h ***/
  76435. const char deflate_copyright[] =
  76436. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76437. typedef enum {
  76438. need_more, /* block not completed, need more input or more output */
  76439. block_done, /* block flush performed */
  76440. finish_started, /* finish started, need only more output at next deflate */
  76441. finish_done /* finish done, accept no more input or output */
  76442. } block_state;
  76443. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76444. local void fill_window OF((deflate_state *s));
  76445. local block_state deflate_stored OF((deflate_state *s, int flush));
  76446. local block_state deflate_fast OF((deflate_state *s, int flush));
  76447. #ifndef FASTEST
  76448. local block_state deflate_slow OF((deflate_state *s, int flush));
  76449. #endif
  76450. local void lm_init OF((deflate_state *s));
  76451. local void putShortMSB OF((deflate_state *s, uInt b));
  76452. local void flush_pending OF((z_streamp strm));
  76453. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76454. #ifndef FASTEST
  76455. #ifdef ASMV
  76456. void match_init OF((void)); /* asm code initialization */
  76457. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76458. #else
  76459. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76460. #endif
  76461. #endif
  76462. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76463. #ifdef DEBUG
  76464. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76465. int length));
  76466. #endif
  76467. #define NIL 0
  76468. #ifndef TOO_FAR
  76469. # define TOO_FAR 4096
  76470. #endif
  76471. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76472. typedef struct config_s {
  76473. ush good_length; /* reduce lazy search above this match length */
  76474. ush max_lazy; /* do not perform lazy search above this match length */
  76475. ush nice_length; /* quit search above this match length */
  76476. ush max_chain;
  76477. compress_func func;
  76478. } config;
  76479. #ifdef FASTEST
  76480. local const config configuration_table[2] = {
  76481. {0, 0, 0, 0, deflate_stored}, /* store only */
  76482. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76483. #else
  76484. local const config configuration_table[10] = {
  76485. {0, 0, 0, 0, deflate_stored}, /* store only */
  76486. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76487. {4, 5, 16, 8, deflate_fast},
  76488. {4, 6, 32, 32, deflate_fast},
  76489. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76490. {8, 16, 32, 32, deflate_slow},
  76491. {8, 16, 128, 128, deflate_slow},
  76492. {8, 32, 128, 256, deflate_slow},
  76493. {32, 128, 258, 1024, deflate_slow},
  76494. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  76495. #endif
  76496. #define EQUAL 0
  76497. #ifndef NO_DUMMY_DECL
  76498. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  76499. #endif
  76500. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  76501. #ifdef FASTEST
  76502. #define INSERT_STRING(s, str, match_head) \
  76503. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76504. match_head = s->head[s->ins_h], \
  76505. s->head[s->ins_h] = (Pos)(str))
  76506. #else
  76507. #define INSERT_STRING(s, str, match_head) \
  76508. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  76509. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  76510. s->head[s->ins_h] = (Pos)(str))
  76511. #endif
  76512. #define CLEAR_HASH(s) \
  76513. s->head[s->hash_size-1] = NIL; \
  76514. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  76515. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  76516. {
  76517. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  76518. Z_DEFAULT_STRATEGY, version, stream_size);
  76519. }
  76520. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  76521. {
  76522. deflate_state *s;
  76523. int wrap = 1;
  76524. static const char my_version[] = ZLIB_VERSION;
  76525. ushf *overlay;
  76526. if (version == Z_NULL || version[0] != my_version[0] ||
  76527. stream_size != sizeof(z_stream)) {
  76528. return Z_VERSION_ERROR;
  76529. }
  76530. if (strm == Z_NULL) return Z_STREAM_ERROR;
  76531. strm->msg = Z_NULL;
  76532. if (strm->zalloc == (alloc_func)0) {
  76533. strm->zalloc = zcalloc;
  76534. strm->opaque = (voidpf)0;
  76535. }
  76536. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  76537. #ifdef FASTEST
  76538. if (level != 0) level = 1;
  76539. #else
  76540. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76541. #endif
  76542. if (windowBits < 0) { /* suppress zlib wrapper */
  76543. wrap = 0;
  76544. windowBits = -windowBits;
  76545. }
  76546. #ifdef GZIP
  76547. else if (windowBits > 15) {
  76548. wrap = 2; /* write gzip wrapper instead */
  76549. windowBits -= 16;
  76550. }
  76551. #endif
  76552. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  76553. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  76554. strategy < 0 || strategy > Z_FIXED) {
  76555. return Z_STREAM_ERROR;
  76556. }
  76557. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  76558. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  76559. if (s == Z_NULL) return Z_MEM_ERROR;
  76560. strm->state = (struct internal_state FAR *)s;
  76561. s->strm = strm;
  76562. s->wrap = wrap;
  76563. s->gzhead = Z_NULL;
  76564. s->w_bits = windowBits;
  76565. s->w_size = 1 << s->w_bits;
  76566. s->w_mask = s->w_size - 1;
  76567. s->hash_bits = memLevel + 7;
  76568. s->hash_size = 1 << s->hash_bits;
  76569. s->hash_mask = s->hash_size - 1;
  76570. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  76571. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  76572. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  76573. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  76574. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  76575. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  76576. s->pending_buf = (uchf *) overlay;
  76577. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  76578. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  76579. s->pending_buf == Z_NULL) {
  76580. s->status = FINISH_STATE;
  76581. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  76582. deflateEnd (strm);
  76583. return Z_MEM_ERROR;
  76584. }
  76585. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  76586. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  76587. s->level = level;
  76588. s->strategy = strategy;
  76589. s->method = (Byte)method;
  76590. return deflateReset(strm);
  76591. }
  76592. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  76593. {
  76594. deflate_state *s;
  76595. uInt length = dictLength;
  76596. uInt n;
  76597. IPos hash_head = 0;
  76598. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  76599. strm->state->wrap == 2 ||
  76600. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  76601. return Z_STREAM_ERROR;
  76602. s = strm->state;
  76603. if (s->wrap)
  76604. strm->adler = adler32(strm->adler, dictionary, dictLength);
  76605. if (length < MIN_MATCH) return Z_OK;
  76606. if (length > MAX_DIST(s)) {
  76607. length = MAX_DIST(s);
  76608. dictionary += dictLength - length; /* use the tail of the dictionary */
  76609. }
  76610. zmemcpy(s->window, dictionary, length);
  76611. s->strstart = length;
  76612. s->block_start = (long)length;
  76613. s->ins_h = s->window[0];
  76614. UPDATE_HASH(s, s->ins_h, s->window[1]);
  76615. for (n = 0; n <= length - MIN_MATCH; n++) {
  76616. INSERT_STRING(s, n, hash_head);
  76617. }
  76618. if (hash_head) hash_head = 0; /* to make compiler happy */
  76619. return Z_OK;
  76620. }
  76621. int ZEXPORT deflateReset (z_streamp strm)
  76622. {
  76623. deflate_state *s;
  76624. if (strm == Z_NULL || strm->state == Z_NULL ||
  76625. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  76626. return Z_STREAM_ERROR;
  76627. }
  76628. strm->total_in = strm->total_out = 0;
  76629. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  76630. strm->data_type = Z_UNKNOWN;
  76631. s = (deflate_state *)strm->state;
  76632. s->pending = 0;
  76633. s->pending_out = s->pending_buf;
  76634. if (s->wrap < 0) {
  76635. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  76636. }
  76637. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  76638. strm->adler =
  76639. #ifdef GZIP
  76640. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  76641. #endif
  76642. adler32(0L, Z_NULL, 0);
  76643. s->last_flush = Z_NO_FLUSH;
  76644. _tr_init(s);
  76645. lm_init(s);
  76646. return Z_OK;
  76647. }
  76648. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  76649. {
  76650. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76651. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  76652. strm->state->gzhead = head;
  76653. return Z_OK;
  76654. }
  76655. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  76656. {
  76657. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76658. strm->state->bi_valid = bits;
  76659. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  76660. return Z_OK;
  76661. }
  76662. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  76663. {
  76664. deflate_state *s;
  76665. compress_func func;
  76666. int err = Z_OK;
  76667. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76668. s = strm->state;
  76669. #ifdef FASTEST
  76670. if (level != 0) level = 1;
  76671. #else
  76672. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  76673. #endif
  76674. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  76675. return Z_STREAM_ERROR;
  76676. }
  76677. func = configuration_table[s->level].func;
  76678. if (func != configuration_table[level].func && strm->total_in != 0) {
  76679. err = deflate(strm, Z_PARTIAL_FLUSH);
  76680. }
  76681. if (s->level != level) {
  76682. s->level = level;
  76683. s->max_lazy_match = configuration_table[level].max_lazy;
  76684. s->good_match = configuration_table[level].good_length;
  76685. s->nice_match = configuration_table[level].nice_length;
  76686. s->max_chain_length = configuration_table[level].max_chain;
  76687. }
  76688. s->strategy = strategy;
  76689. return err;
  76690. }
  76691. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  76692. {
  76693. deflate_state *s;
  76694. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76695. s = strm->state;
  76696. s->good_match = good_length;
  76697. s->max_lazy_match = max_lazy;
  76698. s->nice_match = nice_length;
  76699. s->max_chain_length = max_chain;
  76700. return Z_OK;
  76701. }
  76702. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  76703. {
  76704. deflate_state *s;
  76705. uLong destLen;
  76706. destLen = sourceLen +
  76707. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  76708. if (strm == Z_NULL || strm->state == Z_NULL)
  76709. return destLen;
  76710. s = strm->state;
  76711. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  76712. return destLen;
  76713. return compressBound(sourceLen);
  76714. }
  76715. local void putShortMSB (deflate_state *s, uInt b)
  76716. {
  76717. put_byte(s, (Byte)(b >> 8));
  76718. put_byte(s, (Byte)(b & 0xff));
  76719. }
  76720. local void flush_pending (z_streamp strm)
  76721. {
  76722. unsigned len = strm->state->pending;
  76723. if (len > strm->avail_out) len = strm->avail_out;
  76724. if (len == 0) return;
  76725. zmemcpy(strm->next_out, strm->state->pending_out, len);
  76726. strm->next_out += len;
  76727. strm->state->pending_out += len;
  76728. strm->total_out += len;
  76729. strm->avail_out -= len;
  76730. strm->state->pending -= len;
  76731. if (strm->state->pending == 0) {
  76732. strm->state->pending_out = strm->state->pending_buf;
  76733. }
  76734. }
  76735. int ZEXPORT deflate (z_streamp strm, int flush)
  76736. {
  76737. int old_flush; /* value of flush param for previous deflate call */
  76738. deflate_state *s;
  76739. if (strm == Z_NULL || strm->state == Z_NULL ||
  76740. flush > Z_FINISH || flush < 0) {
  76741. return Z_STREAM_ERROR;
  76742. }
  76743. s = strm->state;
  76744. if (strm->next_out == Z_NULL ||
  76745. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  76746. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  76747. ERR_RETURN(strm, Z_STREAM_ERROR);
  76748. }
  76749. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  76750. s->strm = strm; /* just in case */
  76751. old_flush = s->last_flush;
  76752. s->last_flush = flush;
  76753. if (s->status == INIT_STATE) {
  76754. #ifdef GZIP
  76755. if (s->wrap == 2) {
  76756. strm->adler = crc32(0L, Z_NULL, 0);
  76757. put_byte(s, 31);
  76758. put_byte(s, 139);
  76759. put_byte(s, 8);
  76760. if (s->gzhead == NULL) {
  76761. put_byte(s, 0);
  76762. put_byte(s, 0);
  76763. put_byte(s, 0);
  76764. put_byte(s, 0);
  76765. put_byte(s, 0);
  76766. put_byte(s, s->level == 9 ? 2 :
  76767. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76768. 4 : 0));
  76769. put_byte(s, OS_CODE);
  76770. s->status = BUSY_STATE;
  76771. }
  76772. else {
  76773. put_byte(s, (s->gzhead->text ? 1 : 0) +
  76774. (s->gzhead->hcrc ? 2 : 0) +
  76775. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  76776. (s->gzhead->name == Z_NULL ? 0 : 8) +
  76777. (s->gzhead->comment == Z_NULL ? 0 : 16)
  76778. );
  76779. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  76780. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  76781. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  76782. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  76783. put_byte(s, s->level == 9 ? 2 :
  76784. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  76785. 4 : 0));
  76786. put_byte(s, s->gzhead->os & 0xff);
  76787. if (s->gzhead->extra != NULL) {
  76788. put_byte(s, s->gzhead->extra_len & 0xff);
  76789. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  76790. }
  76791. if (s->gzhead->hcrc)
  76792. strm->adler = crc32(strm->adler, s->pending_buf,
  76793. s->pending);
  76794. s->gzindex = 0;
  76795. s->status = EXTRA_STATE;
  76796. }
  76797. }
  76798. else
  76799. #endif
  76800. {
  76801. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  76802. uInt level_flags;
  76803. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  76804. level_flags = 0;
  76805. else if (s->level < 6)
  76806. level_flags = 1;
  76807. else if (s->level == 6)
  76808. level_flags = 2;
  76809. else
  76810. level_flags = 3;
  76811. header |= (level_flags << 6);
  76812. if (s->strstart != 0) header |= PRESET_DICT;
  76813. header += 31 - (header % 31);
  76814. s->status = BUSY_STATE;
  76815. putShortMSB(s, header);
  76816. if (s->strstart != 0) {
  76817. putShortMSB(s, (uInt)(strm->adler >> 16));
  76818. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76819. }
  76820. strm->adler = adler32(0L, Z_NULL, 0);
  76821. }
  76822. }
  76823. #ifdef GZIP
  76824. if (s->status == EXTRA_STATE) {
  76825. if (s->gzhead->extra != NULL) {
  76826. uInt beg = s->pending; /* start of bytes to update crc */
  76827. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  76828. if (s->pending == s->pending_buf_size) {
  76829. if (s->gzhead->hcrc && s->pending > beg)
  76830. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76831. s->pending - beg);
  76832. flush_pending(strm);
  76833. beg = s->pending;
  76834. if (s->pending == s->pending_buf_size)
  76835. break;
  76836. }
  76837. put_byte(s, s->gzhead->extra[s->gzindex]);
  76838. s->gzindex++;
  76839. }
  76840. if (s->gzhead->hcrc && s->pending > beg)
  76841. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76842. s->pending - beg);
  76843. if (s->gzindex == s->gzhead->extra_len) {
  76844. s->gzindex = 0;
  76845. s->status = NAME_STATE;
  76846. }
  76847. }
  76848. else
  76849. s->status = NAME_STATE;
  76850. }
  76851. if (s->status == NAME_STATE) {
  76852. if (s->gzhead->name != NULL) {
  76853. uInt beg = s->pending; /* start of bytes to update crc */
  76854. int val;
  76855. do {
  76856. if (s->pending == s->pending_buf_size) {
  76857. if (s->gzhead->hcrc && s->pending > beg)
  76858. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76859. s->pending - beg);
  76860. flush_pending(strm);
  76861. beg = s->pending;
  76862. if (s->pending == s->pending_buf_size) {
  76863. val = 1;
  76864. break;
  76865. }
  76866. }
  76867. val = s->gzhead->name[s->gzindex++];
  76868. put_byte(s, val);
  76869. } while (val != 0);
  76870. if (s->gzhead->hcrc && s->pending > beg)
  76871. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76872. s->pending - beg);
  76873. if (val == 0) {
  76874. s->gzindex = 0;
  76875. s->status = COMMENT_STATE;
  76876. }
  76877. }
  76878. else
  76879. s->status = COMMENT_STATE;
  76880. }
  76881. if (s->status == COMMENT_STATE) {
  76882. if (s->gzhead->comment != NULL) {
  76883. uInt beg = s->pending; /* start of bytes to update crc */
  76884. int val;
  76885. do {
  76886. if (s->pending == s->pending_buf_size) {
  76887. if (s->gzhead->hcrc && s->pending > beg)
  76888. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76889. s->pending - beg);
  76890. flush_pending(strm);
  76891. beg = s->pending;
  76892. if (s->pending == s->pending_buf_size) {
  76893. val = 1;
  76894. break;
  76895. }
  76896. }
  76897. val = s->gzhead->comment[s->gzindex++];
  76898. put_byte(s, val);
  76899. } while (val != 0);
  76900. if (s->gzhead->hcrc && s->pending > beg)
  76901. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  76902. s->pending - beg);
  76903. if (val == 0)
  76904. s->status = HCRC_STATE;
  76905. }
  76906. else
  76907. s->status = HCRC_STATE;
  76908. }
  76909. if (s->status == HCRC_STATE) {
  76910. if (s->gzhead->hcrc) {
  76911. if (s->pending + 2 > s->pending_buf_size)
  76912. flush_pending(strm);
  76913. if (s->pending + 2 <= s->pending_buf_size) {
  76914. put_byte(s, (Byte)(strm->adler & 0xff));
  76915. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  76916. strm->adler = crc32(0L, Z_NULL, 0);
  76917. s->status = BUSY_STATE;
  76918. }
  76919. }
  76920. else
  76921. s->status = BUSY_STATE;
  76922. }
  76923. #endif
  76924. if (s->pending != 0) {
  76925. flush_pending(strm);
  76926. if (strm->avail_out == 0) {
  76927. s->last_flush = -1;
  76928. return Z_OK;
  76929. }
  76930. } else if (strm->avail_in == 0 && flush <= old_flush &&
  76931. flush != Z_FINISH) {
  76932. ERR_RETURN(strm, Z_BUF_ERROR);
  76933. }
  76934. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  76935. ERR_RETURN(strm, Z_BUF_ERROR);
  76936. }
  76937. if (strm->avail_in != 0 || s->lookahead != 0 ||
  76938. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  76939. block_state bstate;
  76940. bstate = (*(configuration_table[s->level].func))(s, flush);
  76941. if (bstate == finish_started || bstate == finish_done) {
  76942. s->status = FINISH_STATE;
  76943. }
  76944. if (bstate == need_more || bstate == finish_started) {
  76945. if (strm->avail_out == 0) {
  76946. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  76947. }
  76948. return Z_OK;
  76949. }
  76950. if (bstate == block_done) {
  76951. if (flush == Z_PARTIAL_FLUSH) {
  76952. _tr_align(s);
  76953. } else { /* FULL_FLUSH or SYNC_FLUSH */
  76954. _tr_stored_block(s, (char*)0, 0L, 0);
  76955. if (flush == Z_FULL_FLUSH) {
  76956. CLEAR_HASH(s); /* forget history */
  76957. }
  76958. }
  76959. flush_pending(strm);
  76960. if (strm->avail_out == 0) {
  76961. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  76962. return Z_OK;
  76963. }
  76964. }
  76965. }
  76966. Assert(strm->avail_out > 0, "bug2");
  76967. if (flush != Z_FINISH) return Z_OK;
  76968. if (s->wrap <= 0) return Z_STREAM_END;
  76969. #ifdef GZIP
  76970. if (s->wrap == 2) {
  76971. put_byte(s, (Byte)(strm->adler & 0xff));
  76972. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  76973. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  76974. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  76975. put_byte(s, (Byte)(strm->total_in & 0xff));
  76976. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  76977. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  76978. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  76979. }
  76980. else
  76981. #endif
  76982. {
  76983. putShortMSB(s, (uInt)(strm->adler >> 16));
  76984. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  76985. }
  76986. flush_pending(strm);
  76987. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  76988. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  76989. }
  76990. int ZEXPORT deflateEnd (z_streamp strm)
  76991. {
  76992. int status;
  76993. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  76994. status = strm->state->status;
  76995. if (status != INIT_STATE &&
  76996. status != EXTRA_STATE &&
  76997. status != NAME_STATE &&
  76998. status != COMMENT_STATE &&
  76999. status != HCRC_STATE &&
  77000. status != BUSY_STATE &&
  77001. status != FINISH_STATE) {
  77002. return Z_STREAM_ERROR;
  77003. }
  77004. TRY_FREE(strm, strm->state->pending_buf);
  77005. TRY_FREE(strm, strm->state->head);
  77006. TRY_FREE(strm, strm->state->prev);
  77007. TRY_FREE(strm, strm->state->window);
  77008. ZFREE(strm, strm->state);
  77009. strm->state = Z_NULL;
  77010. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77011. }
  77012. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77013. {
  77014. #ifdef MAXSEG_64K
  77015. return Z_STREAM_ERROR;
  77016. #else
  77017. deflate_state *ds;
  77018. deflate_state *ss;
  77019. ushf *overlay;
  77020. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77021. return Z_STREAM_ERROR;
  77022. }
  77023. ss = source->state;
  77024. zmemcpy(dest, source, sizeof(z_stream));
  77025. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77026. if (ds == Z_NULL) return Z_MEM_ERROR;
  77027. dest->state = (struct internal_state FAR *) ds;
  77028. zmemcpy(ds, ss, sizeof(deflate_state));
  77029. ds->strm = dest;
  77030. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77031. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77032. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77033. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77034. ds->pending_buf = (uchf *) overlay;
  77035. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77036. ds->pending_buf == Z_NULL) {
  77037. deflateEnd (dest);
  77038. return Z_MEM_ERROR;
  77039. }
  77040. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77041. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77042. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77043. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77044. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77045. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77046. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77047. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77048. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77049. ds->bl_desc.dyn_tree = ds->bl_tree;
  77050. return Z_OK;
  77051. #endif /* MAXSEG_64K */
  77052. }
  77053. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77054. {
  77055. unsigned len = strm->avail_in;
  77056. if (len > size) len = size;
  77057. if (len == 0) return 0;
  77058. strm->avail_in -= len;
  77059. if (strm->state->wrap == 1) {
  77060. strm->adler = adler32(strm->adler, strm->next_in, len);
  77061. }
  77062. #ifdef GZIP
  77063. else if (strm->state->wrap == 2) {
  77064. strm->adler = crc32(strm->adler, strm->next_in, len);
  77065. }
  77066. #endif
  77067. zmemcpy(buf, strm->next_in, len);
  77068. strm->next_in += len;
  77069. strm->total_in += len;
  77070. return (int)len;
  77071. }
  77072. local void lm_init (deflate_state *s)
  77073. {
  77074. s->window_size = (ulg)2L*s->w_size;
  77075. CLEAR_HASH(s);
  77076. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77077. s->good_match = configuration_table[s->level].good_length;
  77078. s->nice_match = configuration_table[s->level].nice_length;
  77079. s->max_chain_length = configuration_table[s->level].max_chain;
  77080. s->strstart = 0;
  77081. s->block_start = 0L;
  77082. s->lookahead = 0;
  77083. s->match_length = s->prev_length = MIN_MATCH-1;
  77084. s->match_available = 0;
  77085. s->ins_h = 0;
  77086. #ifndef FASTEST
  77087. #ifdef ASMV
  77088. match_init(); /* initialize the asm code */
  77089. #endif
  77090. #endif
  77091. }
  77092. #ifndef FASTEST
  77093. #ifndef ASMV
  77094. local uInt longest_match(deflate_state *s, IPos cur_match)
  77095. {
  77096. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77097. register Bytef *scan = s->window + s->strstart; /* current string */
  77098. register Bytef *match; /* matched string */
  77099. register int len; /* length of current match */
  77100. int best_len = s->prev_length; /* best match length so far */
  77101. int nice_match = s->nice_match; /* stop if match long enough */
  77102. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77103. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77104. Posf *prev = s->prev;
  77105. uInt wmask = s->w_mask;
  77106. #ifdef UNALIGNED_OK
  77107. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77108. register ush scan_start = *(ushf*)scan;
  77109. register ush scan_end = *(ushf*)(scan+best_len-1);
  77110. #else
  77111. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77112. register Byte scan_end1 = scan[best_len-1];
  77113. register Byte scan_end = scan[best_len];
  77114. #endif
  77115. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77116. if (s->prev_length >= s->good_match) {
  77117. chain_length >>= 2;
  77118. }
  77119. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77120. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77121. do {
  77122. Assert(cur_match < s->strstart, "no future");
  77123. match = s->window + cur_match;
  77124. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77125. if (*(ushf*)(match+best_len-1) != scan_end ||
  77126. *(ushf*)match != scan_start) continue;
  77127. Assert(scan[2] == match[2], "scan[2]?");
  77128. scan++, match++;
  77129. do {
  77130. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77131. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77132. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77133. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77134. scan < strend);
  77135. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77136. if (*scan == *match) scan++;
  77137. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77138. scan = strend - (MAX_MATCH-1);
  77139. #else /* UNALIGNED_OK */
  77140. if (match[best_len] != scan_end ||
  77141. match[best_len-1] != scan_end1 ||
  77142. *match != *scan ||
  77143. *++match != scan[1]) continue;
  77144. scan += 2, match++;
  77145. Assert(*scan == *match, "match[2]?");
  77146. do {
  77147. } while (*++scan == *++match && *++scan == *++match &&
  77148. *++scan == *++match && *++scan == *++match &&
  77149. *++scan == *++match && *++scan == *++match &&
  77150. *++scan == *++match && *++scan == *++match &&
  77151. scan < strend);
  77152. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77153. len = MAX_MATCH - (int)(strend - scan);
  77154. scan = strend - MAX_MATCH;
  77155. #endif /* UNALIGNED_OK */
  77156. if (len > best_len) {
  77157. s->match_start = cur_match;
  77158. best_len = len;
  77159. if (len >= nice_match) break;
  77160. #ifdef UNALIGNED_OK
  77161. scan_end = *(ushf*)(scan+best_len-1);
  77162. #else
  77163. scan_end1 = scan[best_len-1];
  77164. scan_end = scan[best_len];
  77165. #endif
  77166. }
  77167. } while ((cur_match = prev[cur_match & wmask]) > limit
  77168. && --chain_length != 0);
  77169. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77170. return s->lookahead;
  77171. }
  77172. #endif /* ASMV */
  77173. #endif /* FASTEST */
  77174. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77175. {
  77176. register Bytef *scan = s->window + s->strstart; /* current string */
  77177. register Bytef *match; /* matched string */
  77178. register int len; /* length of current match */
  77179. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77180. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77181. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77182. Assert(cur_match < s->strstart, "no future");
  77183. match = s->window + cur_match;
  77184. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77185. scan += 2, match += 2;
  77186. Assert(*scan == *match, "match[2]?");
  77187. do {
  77188. } while (*++scan == *++match && *++scan == *++match &&
  77189. *++scan == *++match && *++scan == *++match &&
  77190. *++scan == *++match && *++scan == *++match &&
  77191. *++scan == *++match && *++scan == *++match &&
  77192. scan < strend);
  77193. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77194. len = MAX_MATCH - (int)(strend - scan);
  77195. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77196. s->match_start = cur_match;
  77197. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77198. }
  77199. #ifdef DEBUG
  77200. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77201. {
  77202. if (zmemcmp(s->window + match,
  77203. s->window + start, length) != EQUAL) {
  77204. fprintf(stderr, " start %u, match %u, length %d\n",
  77205. start, match, length);
  77206. do {
  77207. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77208. } while (--length != 0);
  77209. z_error("invalid match");
  77210. }
  77211. if (z_verbose > 1) {
  77212. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77213. do { putc(s->window[start++], stderr); } while (--length != 0);
  77214. }
  77215. }
  77216. #else
  77217. # define check_match(s, start, match, length)
  77218. #endif /* DEBUG */
  77219. local void fill_window (deflate_state *s)
  77220. {
  77221. register unsigned n, m;
  77222. register Posf *p;
  77223. unsigned more; /* Amount of free space at the end of the window. */
  77224. uInt wsize = s->w_size;
  77225. do {
  77226. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77227. if (sizeof(int) <= 2) {
  77228. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77229. more = wsize;
  77230. } else if (more == (unsigned)(-1)) {
  77231. more--;
  77232. }
  77233. }
  77234. if (s->strstart >= wsize+MAX_DIST(s)) {
  77235. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77236. s->match_start -= wsize;
  77237. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77238. s->block_start -= (long) wsize;
  77239. n = s->hash_size;
  77240. p = &s->head[n];
  77241. do {
  77242. m = *--p;
  77243. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77244. } while (--n);
  77245. n = wsize;
  77246. #ifndef FASTEST
  77247. p = &s->prev[n];
  77248. do {
  77249. m = *--p;
  77250. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77251. } while (--n);
  77252. #endif
  77253. more += wsize;
  77254. }
  77255. if (s->strm->avail_in == 0) return;
  77256. Assert(more >= 2, "more < 2");
  77257. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77258. s->lookahead += n;
  77259. if (s->lookahead >= MIN_MATCH) {
  77260. s->ins_h = s->window[s->strstart];
  77261. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77262. #if MIN_MATCH != 3
  77263. Call UPDATE_HASH() MIN_MATCH-3 more times
  77264. #endif
  77265. }
  77266. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77267. }
  77268. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77269. _tr_flush_block(s, (s->block_start >= 0L ? \
  77270. (charf *)&s->window[(unsigned)s->block_start] : \
  77271. (charf *)Z_NULL), \
  77272. (ulg)((long)s->strstart - s->block_start), \
  77273. (eof)); \
  77274. s->block_start = s->strstart; \
  77275. flush_pending(s->strm); \
  77276. Tracev((stderr,"[FLUSH]")); \
  77277. }
  77278. #define FLUSH_BLOCK(s, eof) { \
  77279. FLUSH_BLOCK_ONLY(s, eof); \
  77280. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77281. }
  77282. local block_state deflate_stored(deflate_state *s, int flush)
  77283. {
  77284. ulg max_block_size = 0xffff;
  77285. ulg max_start;
  77286. if (max_block_size > s->pending_buf_size - 5) {
  77287. max_block_size = s->pending_buf_size - 5;
  77288. }
  77289. for (;;) {
  77290. if (s->lookahead <= 1) {
  77291. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77292. s->block_start >= (long)s->w_size, "slide too late");
  77293. fill_window(s);
  77294. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77295. if (s->lookahead == 0) break; /* flush the current block */
  77296. }
  77297. Assert(s->block_start >= 0L, "block gone");
  77298. s->strstart += s->lookahead;
  77299. s->lookahead = 0;
  77300. max_start = s->block_start + max_block_size;
  77301. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77302. s->lookahead = (uInt)(s->strstart - max_start);
  77303. s->strstart = (uInt)max_start;
  77304. FLUSH_BLOCK(s, 0);
  77305. }
  77306. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77307. FLUSH_BLOCK(s, 0);
  77308. }
  77309. }
  77310. FLUSH_BLOCK(s, flush == Z_FINISH);
  77311. return flush == Z_FINISH ? finish_done : block_done;
  77312. }
  77313. local block_state deflate_fast(deflate_state *s, int flush)
  77314. {
  77315. IPos hash_head = NIL; /* head of the hash chain */
  77316. int bflush; /* set if current block must be flushed */
  77317. for (;;) {
  77318. if (s->lookahead < MIN_LOOKAHEAD) {
  77319. fill_window(s);
  77320. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77321. return need_more;
  77322. }
  77323. if (s->lookahead == 0) break; /* flush the current block */
  77324. }
  77325. if (s->lookahead >= MIN_MATCH) {
  77326. INSERT_STRING(s, s->strstart, hash_head);
  77327. }
  77328. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77329. #ifdef FASTEST
  77330. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77331. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77332. s->match_length = longest_match_fast (s, hash_head);
  77333. }
  77334. #else
  77335. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77336. s->match_length = longest_match (s, hash_head);
  77337. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77338. s->match_length = longest_match_fast (s, hash_head);
  77339. }
  77340. #endif
  77341. }
  77342. if (s->match_length >= MIN_MATCH) {
  77343. check_match(s, s->strstart, s->match_start, s->match_length);
  77344. _tr_tally_dist(s, s->strstart - s->match_start,
  77345. s->match_length - MIN_MATCH, bflush);
  77346. s->lookahead -= s->match_length;
  77347. #ifndef FASTEST
  77348. if (s->match_length <= s->max_insert_length &&
  77349. s->lookahead >= MIN_MATCH) {
  77350. s->match_length--; /* string at strstart already in table */
  77351. do {
  77352. s->strstart++;
  77353. INSERT_STRING(s, s->strstart, hash_head);
  77354. } while (--s->match_length != 0);
  77355. s->strstart++;
  77356. } else
  77357. #endif
  77358. {
  77359. s->strstart += s->match_length;
  77360. s->match_length = 0;
  77361. s->ins_h = s->window[s->strstart];
  77362. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77363. #if MIN_MATCH != 3
  77364. Call UPDATE_HASH() MIN_MATCH-3 more times
  77365. #endif
  77366. }
  77367. } else {
  77368. Tracevv((stderr,"%c", s->window[s->strstart]));
  77369. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77370. s->lookahead--;
  77371. s->strstart++;
  77372. }
  77373. if (bflush) FLUSH_BLOCK(s, 0);
  77374. }
  77375. FLUSH_BLOCK(s, flush == Z_FINISH);
  77376. return flush == Z_FINISH ? finish_done : block_done;
  77377. }
  77378. #ifndef FASTEST
  77379. local block_state deflate_slow(deflate_state *s, int flush)
  77380. {
  77381. IPos hash_head = NIL; /* head of hash chain */
  77382. int bflush; /* set if current block must be flushed */
  77383. for (;;) {
  77384. if (s->lookahead < MIN_LOOKAHEAD) {
  77385. fill_window(s);
  77386. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77387. return need_more;
  77388. }
  77389. if (s->lookahead == 0) break; /* flush the current block */
  77390. }
  77391. if (s->lookahead >= MIN_MATCH) {
  77392. INSERT_STRING(s, s->strstart, hash_head);
  77393. }
  77394. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77395. s->match_length = MIN_MATCH-1;
  77396. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77397. s->strstart - hash_head <= MAX_DIST(s)) {
  77398. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77399. s->match_length = longest_match (s, hash_head);
  77400. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77401. s->match_length = longest_match_fast (s, hash_head);
  77402. }
  77403. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77404. #if TOO_FAR <= 32767
  77405. || (s->match_length == MIN_MATCH &&
  77406. s->strstart - s->match_start > TOO_FAR)
  77407. #endif
  77408. )) {
  77409. s->match_length = MIN_MATCH-1;
  77410. }
  77411. }
  77412. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77413. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77414. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77415. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77416. s->prev_length - MIN_MATCH, bflush);
  77417. s->lookahead -= s->prev_length-1;
  77418. s->prev_length -= 2;
  77419. do {
  77420. if (++s->strstart <= max_insert) {
  77421. INSERT_STRING(s, s->strstart, hash_head);
  77422. }
  77423. } while (--s->prev_length != 0);
  77424. s->match_available = 0;
  77425. s->match_length = MIN_MATCH-1;
  77426. s->strstart++;
  77427. if (bflush) FLUSH_BLOCK(s, 0);
  77428. } else if (s->match_available) {
  77429. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77430. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77431. if (bflush) {
  77432. FLUSH_BLOCK_ONLY(s, 0);
  77433. }
  77434. s->strstart++;
  77435. s->lookahead--;
  77436. if (s->strm->avail_out == 0) return need_more;
  77437. } else {
  77438. s->match_available = 1;
  77439. s->strstart++;
  77440. s->lookahead--;
  77441. }
  77442. }
  77443. Assert (flush != Z_NO_FLUSH, "no flush?");
  77444. if (s->match_available) {
  77445. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77446. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77447. s->match_available = 0;
  77448. }
  77449. FLUSH_BLOCK(s, flush == Z_FINISH);
  77450. return flush == Z_FINISH ? finish_done : block_done;
  77451. }
  77452. #endif /* FASTEST */
  77453. #if 0
  77454. local block_state deflate_rle(s, flush)
  77455. deflate_state *s;
  77456. int flush;
  77457. {
  77458. int bflush; /* set if current block must be flushed */
  77459. uInt run; /* length of run */
  77460. uInt max; /* maximum length of run */
  77461. uInt prev; /* byte at distance one to match */
  77462. Bytef *scan; /* scan for end of run */
  77463. for (;;) {
  77464. if (s->lookahead < MAX_MATCH) {
  77465. fill_window(s);
  77466. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77467. return need_more;
  77468. }
  77469. if (s->lookahead == 0) break; /* flush the current block */
  77470. }
  77471. run = 0;
  77472. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77473. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77474. scan = s->window + s->strstart - 1;
  77475. prev = *scan++;
  77476. do {
  77477. if (*scan++ != prev)
  77478. break;
  77479. } while (++run < max);
  77480. }
  77481. if (run >= MIN_MATCH) {
  77482. check_match(s, s->strstart, s->strstart - 1, run);
  77483. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77484. s->lookahead -= run;
  77485. s->strstart += run;
  77486. } else {
  77487. Tracevv((stderr,"%c", s->window[s->strstart]));
  77488. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77489. s->lookahead--;
  77490. s->strstart++;
  77491. }
  77492. if (bflush) FLUSH_BLOCK(s, 0);
  77493. }
  77494. FLUSH_BLOCK(s, flush == Z_FINISH);
  77495. return flush == Z_FINISH ? finish_done : block_done;
  77496. }
  77497. #endif
  77498. /*** End of inlined file: deflate.c ***/
  77499. /*** Start of inlined file: inffast.c ***/
  77500. /*** Start of inlined file: inftrees.h ***/
  77501. #ifndef _INFTREES_H_
  77502. #define _INFTREES_H_
  77503. typedef struct {
  77504. unsigned char op; /* operation, extra bits, table bits */
  77505. unsigned char bits; /* bits in this part of the code */
  77506. unsigned short val; /* offset in table or code value */
  77507. } code;
  77508. #define ENOUGH 2048
  77509. #define MAXD 592
  77510. typedef enum {
  77511. CODES,
  77512. LENS,
  77513. DISTS
  77514. } codetype;
  77515. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  77516. unsigned codes, code FAR * FAR *table,
  77517. unsigned FAR *bits, unsigned short FAR *work));
  77518. #endif
  77519. /*** End of inlined file: inftrees.h ***/
  77520. /*** Start of inlined file: inflate.h ***/
  77521. #ifndef _INFLATE_H_
  77522. #define _INFLATE_H_
  77523. #ifndef NO_GZIP
  77524. # define GUNZIP
  77525. #endif
  77526. typedef enum {
  77527. HEAD, /* i: waiting for magic header */
  77528. FLAGS, /* i: waiting for method and flags (gzip) */
  77529. TIME, /* i: waiting for modification time (gzip) */
  77530. OS, /* i: waiting for extra flags and operating system (gzip) */
  77531. EXLEN, /* i: waiting for extra length (gzip) */
  77532. EXTRA, /* i: waiting for extra bytes (gzip) */
  77533. NAME, /* i: waiting for end of file name (gzip) */
  77534. COMMENT, /* i: waiting for end of comment (gzip) */
  77535. HCRC, /* i: waiting for header crc (gzip) */
  77536. DICTID, /* i: waiting for dictionary check value */
  77537. DICT, /* waiting for inflateSetDictionary() call */
  77538. TYPE, /* i: waiting for type bits, including last-flag bit */
  77539. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  77540. STORED, /* i: waiting for stored size (length and complement) */
  77541. COPY, /* i/o: waiting for input or output to copy stored block */
  77542. TABLE, /* i: waiting for dynamic block table lengths */
  77543. LENLENS, /* i: waiting for code length code lengths */
  77544. CODELENS, /* i: waiting for length/lit and distance code lengths */
  77545. LEN, /* i: waiting for length/lit code */
  77546. LENEXT, /* i: waiting for length extra bits */
  77547. DIST, /* i: waiting for distance code */
  77548. DISTEXT, /* i: waiting for distance extra bits */
  77549. MATCH, /* o: waiting for output space to copy string */
  77550. LIT, /* o: waiting for output space to write literal */
  77551. CHECK, /* i: waiting for 32-bit check value */
  77552. LENGTH, /* i: waiting for 32-bit length (gzip) */
  77553. DONE, /* finished check, done -- remain here until reset */
  77554. BAD, /* got a data error -- remain here until reset */
  77555. MEM, /* got an inflate() memory error -- remain here until reset */
  77556. SYNC /* looking for synchronization bytes to restart inflate() */
  77557. } inflate_mode;
  77558. struct inflate_state {
  77559. inflate_mode mode; /* current inflate mode */
  77560. int last; /* true if processing last block */
  77561. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  77562. int havedict; /* true if dictionary provided */
  77563. int flags; /* gzip header method and flags (0 if zlib) */
  77564. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  77565. unsigned long check; /* protected copy of check value */
  77566. unsigned long total; /* protected copy of output count */
  77567. gz_headerp head; /* where to save gzip header information */
  77568. unsigned wbits; /* log base 2 of requested window size */
  77569. unsigned wsize; /* window size or zero if not using window */
  77570. unsigned whave; /* valid bytes in the window */
  77571. unsigned write; /* window write index */
  77572. unsigned char FAR *window; /* allocated sliding window, if needed */
  77573. unsigned long hold; /* input bit accumulator */
  77574. unsigned bits; /* number of bits in "in" */
  77575. unsigned length; /* literal or length of data to copy */
  77576. unsigned offset; /* distance back to copy string from */
  77577. unsigned extra; /* extra bits needed */
  77578. code const FAR *lencode; /* starting table for length/literal codes */
  77579. code const FAR *distcode; /* starting table for distance codes */
  77580. unsigned lenbits; /* index bits for lencode */
  77581. unsigned distbits; /* index bits for distcode */
  77582. unsigned ncode; /* number of code length code lengths */
  77583. unsigned nlen; /* number of length code lengths */
  77584. unsigned ndist; /* number of distance code lengths */
  77585. unsigned have; /* number of code lengths in lens[] */
  77586. code FAR *next; /* next available space in codes[] */
  77587. unsigned short lens[320]; /* temporary storage for code lengths */
  77588. unsigned short work[288]; /* work area for code table building */
  77589. code codes[ENOUGH]; /* space for code tables */
  77590. };
  77591. #endif
  77592. /*** End of inlined file: inflate.h ***/
  77593. /*** Start of inlined file: inffast.h ***/
  77594. void inflate_fast OF((z_streamp strm, unsigned start));
  77595. /*** End of inlined file: inffast.h ***/
  77596. #ifndef ASMINF
  77597. #ifdef POSTINC
  77598. # define OFF 0
  77599. # define PUP(a) *(a)++
  77600. #else
  77601. # define OFF 1
  77602. # define PUP(a) *++(a)
  77603. #endif
  77604. void inflate_fast (z_streamp strm, unsigned start)
  77605. {
  77606. struct inflate_state FAR *state;
  77607. unsigned char FAR *in; /* local strm->next_in */
  77608. unsigned char FAR *last; /* while in < last, enough input available */
  77609. unsigned char FAR *out; /* local strm->next_out */
  77610. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  77611. unsigned char FAR *end; /* while out < end, enough space available */
  77612. #ifdef INFLATE_STRICT
  77613. unsigned dmax; /* maximum distance from zlib header */
  77614. #endif
  77615. unsigned wsize; /* window size or zero if not using window */
  77616. unsigned whave; /* valid bytes in the window */
  77617. unsigned write; /* window write index */
  77618. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  77619. unsigned long hold; /* local strm->hold */
  77620. unsigned bits; /* local strm->bits */
  77621. code const FAR *lcode; /* local strm->lencode */
  77622. code const FAR *dcode; /* local strm->distcode */
  77623. unsigned lmask; /* mask for first level of length codes */
  77624. unsigned dmask; /* mask for first level of distance codes */
  77625. code thisx; /* retrieved table entry */
  77626. unsigned op; /* code bits, operation, extra bits, or */
  77627. unsigned len; /* match length, unused bytes */
  77628. unsigned dist; /* match distance */
  77629. unsigned char FAR *from; /* where to copy match from */
  77630. state = (struct inflate_state FAR *)strm->state;
  77631. in = strm->next_in - OFF;
  77632. last = in + (strm->avail_in - 5);
  77633. out = strm->next_out - OFF;
  77634. beg = out - (start - strm->avail_out);
  77635. end = out + (strm->avail_out - 257);
  77636. #ifdef INFLATE_STRICT
  77637. dmax = state->dmax;
  77638. #endif
  77639. wsize = state->wsize;
  77640. whave = state->whave;
  77641. write = state->write;
  77642. window = state->window;
  77643. hold = state->hold;
  77644. bits = state->bits;
  77645. lcode = state->lencode;
  77646. dcode = state->distcode;
  77647. lmask = (1U << state->lenbits) - 1;
  77648. dmask = (1U << state->distbits) - 1;
  77649. do {
  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 = lcode[hold & lmask];
  77657. dolen:
  77658. op = (unsigned)(thisx.bits);
  77659. hold >>= op;
  77660. bits -= op;
  77661. op = (unsigned)(thisx.op);
  77662. if (op == 0) { /* literal */
  77663. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  77664. "inflate: literal '%c'\n" :
  77665. "inflate: literal 0x%02x\n", thisx.val));
  77666. PUP(out) = (unsigned char)(thisx.val);
  77667. }
  77668. else if (op & 16) { /* length base */
  77669. len = (unsigned)(thisx.val);
  77670. op &= 15; /* number of extra bits */
  77671. if (op) {
  77672. if (bits < op) {
  77673. hold += (unsigned long)(PUP(in)) << bits;
  77674. bits += 8;
  77675. }
  77676. len += (unsigned)hold & ((1U << op) - 1);
  77677. hold >>= op;
  77678. bits -= op;
  77679. }
  77680. Tracevv((stderr, "inflate: length %u\n", len));
  77681. if (bits < 15) {
  77682. hold += (unsigned long)(PUP(in)) << bits;
  77683. bits += 8;
  77684. hold += (unsigned long)(PUP(in)) << bits;
  77685. bits += 8;
  77686. }
  77687. thisx = dcode[hold & dmask];
  77688. dodist:
  77689. op = (unsigned)(thisx.bits);
  77690. hold >>= op;
  77691. bits -= op;
  77692. op = (unsigned)(thisx.op);
  77693. if (op & 16) { /* distance base */
  77694. dist = (unsigned)(thisx.val);
  77695. op &= 15; /* number of extra bits */
  77696. if (bits < op) {
  77697. hold += (unsigned long)(PUP(in)) << bits;
  77698. bits += 8;
  77699. if (bits < op) {
  77700. hold += (unsigned long)(PUP(in)) << bits;
  77701. bits += 8;
  77702. }
  77703. }
  77704. dist += (unsigned)hold & ((1U << op) - 1);
  77705. #ifdef INFLATE_STRICT
  77706. if (dist > dmax) {
  77707. strm->msg = (char *)"invalid distance too far back";
  77708. state->mode = BAD;
  77709. break;
  77710. }
  77711. #endif
  77712. hold >>= op;
  77713. bits -= op;
  77714. Tracevv((stderr, "inflate: distance %u\n", dist));
  77715. op = (unsigned)(out - beg); /* max distance in output */
  77716. if (dist > op) { /* see if copy from window */
  77717. op = dist - op; /* distance back in window */
  77718. if (op > whave) {
  77719. strm->msg = (char *)"invalid distance too far back";
  77720. state->mode = BAD;
  77721. break;
  77722. }
  77723. from = window - OFF;
  77724. if (write == 0) { /* very common case */
  77725. from += wsize - op;
  77726. if (op < len) { /* some from window */
  77727. len -= op;
  77728. do {
  77729. PUP(out) = PUP(from);
  77730. } while (--op);
  77731. from = out - dist; /* rest from output */
  77732. }
  77733. }
  77734. else if (write < op) { /* wrap around window */
  77735. from += wsize + write - op;
  77736. op -= write;
  77737. if (op < len) { /* some from end of window */
  77738. len -= op;
  77739. do {
  77740. PUP(out) = PUP(from);
  77741. } while (--op);
  77742. from = window - OFF;
  77743. if (write < len) { /* some from start of window */
  77744. op = write;
  77745. len -= op;
  77746. do {
  77747. PUP(out) = PUP(from);
  77748. } while (--op);
  77749. from = out - dist; /* rest from output */
  77750. }
  77751. }
  77752. }
  77753. else { /* contiguous in window */
  77754. from += write - op;
  77755. if (op < len) { /* some from window */
  77756. len -= op;
  77757. do {
  77758. PUP(out) = PUP(from);
  77759. } while (--op);
  77760. from = out - dist; /* rest from output */
  77761. }
  77762. }
  77763. while (len > 2) {
  77764. PUP(out) = PUP(from);
  77765. PUP(out) = PUP(from);
  77766. PUP(out) = PUP(from);
  77767. len -= 3;
  77768. }
  77769. if (len) {
  77770. PUP(out) = PUP(from);
  77771. if (len > 1)
  77772. PUP(out) = PUP(from);
  77773. }
  77774. }
  77775. else {
  77776. from = out - dist; /* copy direct from output */
  77777. do { /* minimum length is three */
  77778. PUP(out) = PUP(from);
  77779. PUP(out) = PUP(from);
  77780. PUP(out) = PUP(from);
  77781. len -= 3;
  77782. } while (len > 2);
  77783. if (len) {
  77784. PUP(out) = PUP(from);
  77785. if (len > 1)
  77786. PUP(out) = PUP(from);
  77787. }
  77788. }
  77789. }
  77790. else if ((op & 64) == 0) { /* 2nd level distance code */
  77791. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  77792. goto dodist;
  77793. }
  77794. else {
  77795. strm->msg = (char *)"invalid distance code";
  77796. state->mode = BAD;
  77797. break;
  77798. }
  77799. }
  77800. else if ((op & 64) == 0) { /* 2nd level length code */
  77801. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  77802. goto dolen;
  77803. }
  77804. else if (op & 32) { /* end-of-block */
  77805. Tracevv((stderr, "inflate: end of block\n"));
  77806. state->mode = TYPE;
  77807. break;
  77808. }
  77809. else {
  77810. strm->msg = (char *)"invalid literal/length code";
  77811. state->mode = BAD;
  77812. break;
  77813. }
  77814. } while (in < last && out < end);
  77815. len = bits >> 3;
  77816. in -= len;
  77817. bits -= len << 3;
  77818. hold &= (1U << bits) - 1;
  77819. strm->next_in = in + OFF;
  77820. strm->next_out = out + OFF;
  77821. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  77822. strm->avail_out = (unsigned)(out < end ?
  77823. 257 + (end - out) : 257 - (out - end));
  77824. state->hold = hold;
  77825. state->bits = bits;
  77826. return;
  77827. }
  77828. #endif /* !ASMINF */
  77829. /*** End of inlined file: inffast.c ***/
  77830. #undef PULLBYTE
  77831. #undef LOAD
  77832. #undef RESTORE
  77833. #undef INITBITS
  77834. #undef NEEDBITS
  77835. #undef DROPBITS
  77836. #undef BYTEBITS
  77837. /*** Start of inlined file: inflate.c ***/
  77838. /*** Start of inlined file: inffast.h ***/
  77839. void inflate_fast OF((z_streamp strm, unsigned start));
  77840. /*** End of inlined file: inffast.h ***/
  77841. #ifdef MAKEFIXED
  77842. # ifndef BUILDFIXED
  77843. # define BUILDFIXED
  77844. # endif
  77845. #endif
  77846. local void fixedtables OF((struct inflate_state FAR *state));
  77847. local int updatewindow OF((z_streamp strm, unsigned out));
  77848. #ifdef BUILDFIXED
  77849. void makefixed OF((void));
  77850. #endif
  77851. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  77852. unsigned len));
  77853. int ZEXPORT inflateReset (z_streamp strm)
  77854. {
  77855. struct inflate_state FAR *state;
  77856. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77857. state = (struct inflate_state FAR *)strm->state;
  77858. strm->total_in = strm->total_out = state->total = 0;
  77859. strm->msg = Z_NULL;
  77860. strm->adler = 1; /* to support ill-conceived Java test suite */
  77861. state->mode = HEAD;
  77862. state->last = 0;
  77863. state->havedict = 0;
  77864. state->dmax = 32768U;
  77865. state->head = Z_NULL;
  77866. state->wsize = 0;
  77867. state->whave = 0;
  77868. state->write = 0;
  77869. state->hold = 0;
  77870. state->bits = 0;
  77871. state->lencode = state->distcode = state->next = state->codes;
  77872. Tracev((stderr, "inflate: reset\n"));
  77873. return Z_OK;
  77874. }
  77875. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  77876. {
  77877. struct inflate_state FAR *state;
  77878. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77879. state = (struct inflate_state FAR *)strm->state;
  77880. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  77881. value &= (1L << bits) - 1;
  77882. state->hold += value << state->bits;
  77883. state->bits += bits;
  77884. return Z_OK;
  77885. }
  77886. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  77887. {
  77888. struct inflate_state FAR *state;
  77889. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  77890. stream_size != (int)(sizeof(z_stream)))
  77891. return Z_VERSION_ERROR;
  77892. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77893. strm->msg = Z_NULL; /* in case we return an error */
  77894. if (strm->zalloc == (alloc_func)0) {
  77895. strm->zalloc = zcalloc;
  77896. strm->opaque = (voidpf)0;
  77897. }
  77898. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77899. state = (struct inflate_state FAR *)
  77900. ZALLOC(strm, 1, sizeof(struct inflate_state));
  77901. if (state == Z_NULL) return Z_MEM_ERROR;
  77902. Tracev((stderr, "inflate: allocated\n"));
  77903. strm->state = (struct internal_state FAR *)state;
  77904. if (windowBits < 0) {
  77905. state->wrap = 0;
  77906. windowBits = -windowBits;
  77907. }
  77908. else {
  77909. state->wrap = (windowBits >> 4) + 1;
  77910. #ifdef GUNZIP
  77911. if (windowBits < 48) windowBits &= 15;
  77912. #endif
  77913. }
  77914. if (windowBits < 8 || windowBits > 15) {
  77915. ZFREE(strm, state);
  77916. strm->state = Z_NULL;
  77917. return Z_STREAM_ERROR;
  77918. }
  77919. state->wbits = (unsigned)windowBits;
  77920. state->window = Z_NULL;
  77921. return inflateReset(strm);
  77922. }
  77923. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  77924. {
  77925. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  77926. }
  77927. local void fixedtables (struct inflate_state FAR *state)
  77928. {
  77929. #ifdef BUILDFIXED
  77930. static int virgin = 1;
  77931. static code *lenfix, *distfix;
  77932. static code fixed[544];
  77933. if (virgin) {
  77934. unsigned sym, bits;
  77935. static code *next;
  77936. sym = 0;
  77937. while (sym < 144) state->lens[sym++] = 8;
  77938. while (sym < 256) state->lens[sym++] = 9;
  77939. while (sym < 280) state->lens[sym++] = 7;
  77940. while (sym < 288) state->lens[sym++] = 8;
  77941. next = fixed;
  77942. lenfix = next;
  77943. bits = 9;
  77944. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  77945. sym = 0;
  77946. while (sym < 32) state->lens[sym++] = 5;
  77947. distfix = next;
  77948. bits = 5;
  77949. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  77950. virgin = 0;
  77951. }
  77952. #else /* !BUILDFIXED */
  77953. /*** Start of inlined file: inffixed.h ***/
  77954. static const code lenfix[512] = {
  77955. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  77956. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  77957. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  77958. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  77959. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  77960. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  77961. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  77962. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  77963. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  77964. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  77965. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  77966. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  77967. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  77968. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  77969. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  77970. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  77971. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  77972. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  77973. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  77974. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  77975. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  77976. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  77977. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  77978. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  77979. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  77980. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  77981. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  77982. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  77983. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  77984. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  77985. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  77986. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  77987. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  77988. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  77989. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  77990. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  77991. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  77992. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  77993. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  77994. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  77995. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  77996. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  77997. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  77998. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  77999. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78000. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78001. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78002. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78003. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78004. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78005. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78006. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78007. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78008. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78009. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78010. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78011. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78012. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78013. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78014. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78015. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78016. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78017. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78018. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78019. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78020. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78021. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78022. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78023. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78024. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78025. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78026. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78027. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78028. {0,9,255}
  78029. };
  78030. static const code distfix[32] = {
  78031. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78032. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78033. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78034. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78035. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78036. {22,5,193},{64,5,0}
  78037. };
  78038. /*** End of inlined file: inffixed.h ***/
  78039. #endif /* BUILDFIXED */
  78040. state->lencode = lenfix;
  78041. state->lenbits = 9;
  78042. state->distcode = distfix;
  78043. state->distbits = 5;
  78044. }
  78045. #ifdef MAKEFIXED
  78046. #include <stdio.h>
  78047. void makefixed()
  78048. {
  78049. unsigned low, size;
  78050. struct inflate_state state;
  78051. fixedtables(&state);
  78052. puts(" /* inffixed.h -- table for decoding fixed codes");
  78053. puts(" * Generated automatically by makefixed().");
  78054. puts(" */");
  78055. puts("");
  78056. puts(" /* WARNING: this file should *not* be used by applications.");
  78057. puts(" It is part of the implementation of this library and is");
  78058. puts(" subject to change. Applications should only use zlib.h.");
  78059. puts(" */");
  78060. puts("");
  78061. size = 1U << 9;
  78062. printf(" static const code lenfix[%u] = {", size);
  78063. low = 0;
  78064. for (;;) {
  78065. if ((low % 7) == 0) printf("\n ");
  78066. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78067. state.lencode[low].val);
  78068. if (++low == size) break;
  78069. putchar(',');
  78070. }
  78071. puts("\n };");
  78072. size = 1U << 5;
  78073. printf("\n static const code distfix[%u] = {", size);
  78074. low = 0;
  78075. for (;;) {
  78076. if ((low % 6) == 0) printf("\n ");
  78077. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78078. state.distcode[low].val);
  78079. if (++low == size) break;
  78080. putchar(',');
  78081. }
  78082. puts("\n };");
  78083. }
  78084. #endif /* MAKEFIXED */
  78085. local int updatewindow (z_streamp strm, unsigned out)
  78086. {
  78087. struct inflate_state FAR *state;
  78088. unsigned copy, dist;
  78089. state = (struct inflate_state FAR *)strm->state;
  78090. if (state->window == Z_NULL) {
  78091. state->window = (unsigned char FAR *)
  78092. ZALLOC(strm, 1U << state->wbits,
  78093. sizeof(unsigned char));
  78094. if (state->window == Z_NULL) return 1;
  78095. }
  78096. if (state->wsize == 0) {
  78097. state->wsize = 1U << state->wbits;
  78098. state->write = 0;
  78099. state->whave = 0;
  78100. }
  78101. copy = out - strm->avail_out;
  78102. if (copy >= state->wsize) {
  78103. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78104. state->write = 0;
  78105. state->whave = state->wsize;
  78106. }
  78107. else {
  78108. dist = state->wsize - state->write;
  78109. if (dist > copy) dist = copy;
  78110. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78111. copy -= dist;
  78112. if (copy) {
  78113. zmemcpy(state->window, strm->next_out - copy, copy);
  78114. state->write = copy;
  78115. state->whave = state->wsize;
  78116. }
  78117. else {
  78118. state->write += dist;
  78119. if (state->write == state->wsize) state->write = 0;
  78120. if (state->whave < state->wsize) state->whave += dist;
  78121. }
  78122. }
  78123. return 0;
  78124. }
  78125. #ifdef GUNZIP
  78126. # define UPDATE(check, buf, len) \
  78127. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78128. #else
  78129. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78130. #endif
  78131. #ifdef GUNZIP
  78132. # define CRC2(check, word) \
  78133. do { \
  78134. hbuf[0] = (unsigned char)(word); \
  78135. hbuf[1] = (unsigned char)((word) >> 8); \
  78136. check = crc32(check, hbuf, 2); \
  78137. } while (0)
  78138. # define CRC4(check, word) \
  78139. do { \
  78140. hbuf[0] = (unsigned char)(word); \
  78141. hbuf[1] = (unsigned char)((word) >> 8); \
  78142. hbuf[2] = (unsigned char)((word) >> 16); \
  78143. hbuf[3] = (unsigned char)((word) >> 24); \
  78144. check = crc32(check, hbuf, 4); \
  78145. } while (0)
  78146. #endif
  78147. #define LOAD() \
  78148. do { \
  78149. put = strm->next_out; \
  78150. left = strm->avail_out; \
  78151. next = strm->next_in; \
  78152. have = strm->avail_in; \
  78153. hold = state->hold; \
  78154. bits = state->bits; \
  78155. } while (0)
  78156. #define RESTORE() \
  78157. do { \
  78158. strm->next_out = put; \
  78159. strm->avail_out = left; \
  78160. strm->next_in = next; \
  78161. strm->avail_in = have; \
  78162. state->hold = hold; \
  78163. state->bits = bits; \
  78164. } while (0)
  78165. #define INITBITS() \
  78166. do { \
  78167. hold = 0; \
  78168. bits = 0; \
  78169. } while (0)
  78170. #define PULLBYTE() \
  78171. do { \
  78172. if (have == 0) goto inf_leave; \
  78173. have--; \
  78174. hold += (unsigned long)(*next++) << bits; \
  78175. bits += 8; \
  78176. } while (0)
  78177. #define NEEDBITS(n) \
  78178. do { \
  78179. while (bits < (unsigned)(n)) \
  78180. PULLBYTE(); \
  78181. } while (0)
  78182. #define BITS(n) \
  78183. ((unsigned)hold & ((1U << (n)) - 1))
  78184. #define DROPBITS(n) \
  78185. do { \
  78186. hold >>= (n); \
  78187. bits -= (unsigned)(n); \
  78188. } while (0)
  78189. #define BYTEBITS() \
  78190. do { \
  78191. hold >>= bits & 7; \
  78192. bits -= bits & 7; \
  78193. } while (0)
  78194. #define REVERSE(q) \
  78195. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78196. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78197. int ZEXPORT inflate (z_streamp strm, int flush)
  78198. {
  78199. struct inflate_state FAR *state;
  78200. unsigned char FAR *next; /* next input */
  78201. unsigned char FAR *put; /* next output */
  78202. unsigned have, left; /* available input and output */
  78203. unsigned long hold; /* bit buffer */
  78204. unsigned bits; /* bits in bit buffer */
  78205. unsigned in, out; /* save starting available input and output */
  78206. unsigned copy; /* number of stored or match bytes to copy */
  78207. unsigned char FAR *from; /* where to copy match bytes from */
  78208. code thisx; /* current decoding table entry */
  78209. code last; /* parent table entry */
  78210. unsigned len; /* length to copy for repeats, bits to drop */
  78211. int ret; /* return code */
  78212. #ifdef GUNZIP
  78213. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78214. #endif
  78215. static const unsigned short order[19] = /* permutation of code lengths */
  78216. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78217. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78218. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78219. return Z_STREAM_ERROR;
  78220. state = (struct inflate_state FAR *)strm->state;
  78221. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78222. LOAD();
  78223. in = have;
  78224. out = left;
  78225. ret = Z_OK;
  78226. for (;;)
  78227. switch (state->mode) {
  78228. case HEAD:
  78229. if (state->wrap == 0) {
  78230. state->mode = TYPEDO;
  78231. break;
  78232. }
  78233. NEEDBITS(16);
  78234. #ifdef GUNZIP
  78235. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78236. state->check = crc32(0L, Z_NULL, 0);
  78237. CRC2(state->check, hold);
  78238. INITBITS();
  78239. state->mode = FLAGS;
  78240. break;
  78241. }
  78242. state->flags = 0; /* expect zlib header */
  78243. if (state->head != Z_NULL)
  78244. state->head->done = -1;
  78245. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78246. #else
  78247. if (
  78248. #endif
  78249. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78250. strm->msg = (char *)"incorrect header check";
  78251. state->mode = BAD;
  78252. break;
  78253. }
  78254. if (BITS(4) != Z_DEFLATED) {
  78255. strm->msg = (char *)"unknown compression method";
  78256. state->mode = BAD;
  78257. break;
  78258. }
  78259. DROPBITS(4);
  78260. len = BITS(4) + 8;
  78261. if (len > state->wbits) {
  78262. strm->msg = (char *)"invalid window size";
  78263. state->mode = BAD;
  78264. break;
  78265. }
  78266. state->dmax = 1U << len;
  78267. Tracev((stderr, "inflate: zlib header ok\n"));
  78268. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78269. state->mode = hold & 0x200 ? DICTID : TYPE;
  78270. INITBITS();
  78271. break;
  78272. #ifdef GUNZIP
  78273. case FLAGS:
  78274. NEEDBITS(16);
  78275. state->flags = (int)(hold);
  78276. if ((state->flags & 0xff) != Z_DEFLATED) {
  78277. strm->msg = (char *)"unknown compression method";
  78278. state->mode = BAD;
  78279. break;
  78280. }
  78281. if (state->flags & 0xe000) {
  78282. strm->msg = (char *)"unknown header flags set";
  78283. state->mode = BAD;
  78284. break;
  78285. }
  78286. if (state->head != Z_NULL)
  78287. state->head->text = (int)((hold >> 8) & 1);
  78288. if (state->flags & 0x0200) CRC2(state->check, hold);
  78289. INITBITS();
  78290. state->mode = TIME;
  78291. case TIME:
  78292. NEEDBITS(32);
  78293. if (state->head != Z_NULL)
  78294. state->head->time = hold;
  78295. if (state->flags & 0x0200) CRC4(state->check, hold);
  78296. INITBITS();
  78297. state->mode = OS;
  78298. case OS:
  78299. NEEDBITS(16);
  78300. if (state->head != Z_NULL) {
  78301. state->head->xflags = (int)(hold & 0xff);
  78302. state->head->os = (int)(hold >> 8);
  78303. }
  78304. if (state->flags & 0x0200) CRC2(state->check, hold);
  78305. INITBITS();
  78306. state->mode = EXLEN;
  78307. case EXLEN:
  78308. if (state->flags & 0x0400) {
  78309. NEEDBITS(16);
  78310. state->length = (unsigned)(hold);
  78311. if (state->head != Z_NULL)
  78312. state->head->extra_len = (unsigned)hold;
  78313. if (state->flags & 0x0200) CRC2(state->check, hold);
  78314. INITBITS();
  78315. }
  78316. else if (state->head != Z_NULL)
  78317. state->head->extra = Z_NULL;
  78318. state->mode = EXTRA;
  78319. case EXTRA:
  78320. if (state->flags & 0x0400) {
  78321. copy = state->length;
  78322. if (copy > have) copy = have;
  78323. if (copy) {
  78324. if (state->head != Z_NULL &&
  78325. state->head->extra != Z_NULL) {
  78326. len = state->head->extra_len - state->length;
  78327. zmemcpy(state->head->extra + len, next,
  78328. len + copy > state->head->extra_max ?
  78329. state->head->extra_max - len : copy);
  78330. }
  78331. if (state->flags & 0x0200)
  78332. state->check = crc32(state->check, next, copy);
  78333. have -= copy;
  78334. next += copy;
  78335. state->length -= copy;
  78336. }
  78337. if (state->length) goto inf_leave;
  78338. }
  78339. state->length = 0;
  78340. state->mode = NAME;
  78341. case NAME:
  78342. if (state->flags & 0x0800) {
  78343. if (have == 0) goto inf_leave;
  78344. copy = 0;
  78345. do {
  78346. len = (unsigned)(next[copy++]);
  78347. if (state->head != Z_NULL &&
  78348. state->head->name != Z_NULL &&
  78349. state->length < state->head->name_max)
  78350. state->head->name[state->length++] = len;
  78351. } while (len && copy < have);
  78352. if (state->flags & 0x0200)
  78353. state->check = crc32(state->check, next, copy);
  78354. have -= copy;
  78355. next += copy;
  78356. if (len) goto inf_leave;
  78357. }
  78358. else if (state->head != Z_NULL)
  78359. state->head->name = Z_NULL;
  78360. state->length = 0;
  78361. state->mode = COMMENT;
  78362. case COMMENT:
  78363. if (state->flags & 0x1000) {
  78364. if (have == 0) goto inf_leave;
  78365. copy = 0;
  78366. do {
  78367. len = (unsigned)(next[copy++]);
  78368. if (state->head != Z_NULL &&
  78369. state->head->comment != Z_NULL &&
  78370. state->length < state->head->comm_max)
  78371. state->head->comment[state->length++] = len;
  78372. } while (len && copy < have);
  78373. if (state->flags & 0x0200)
  78374. state->check = crc32(state->check, next, copy);
  78375. have -= copy;
  78376. next += copy;
  78377. if (len) goto inf_leave;
  78378. }
  78379. else if (state->head != Z_NULL)
  78380. state->head->comment = Z_NULL;
  78381. state->mode = HCRC;
  78382. case HCRC:
  78383. if (state->flags & 0x0200) {
  78384. NEEDBITS(16);
  78385. if (hold != (state->check & 0xffff)) {
  78386. strm->msg = (char *)"header crc mismatch";
  78387. state->mode = BAD;
  78388. break;
  78389. }
  78390. INITBITS();
  78391. }
  78392. if (state->head != Z_NULL) {
  78393. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78394. state->head->done = 1;
  78395. }
  78396. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78397. state->mode = TYPE;
  78398. break;
  78399. #endif
  78400. case DICTID:
  78401. NEEDBITS(32);
  78402. strm->adler = state->check = REVERSE(hold);
  78403. INITBITS();
  78404. state->mode = DICT;
  78405. case DICT:
  78406. if (state->havedict == 0) {
  78407. RESTORE();
  78408. return Z_NEED_DICT;
  78409. }
  78410. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78411. state->mode = TYPE;
  78412. case TYPE:
  78413. if (flush == Z_BLOCK) goto inf_leave;
  78414. case TYPEDO:
  78415. if (state->last) {
  78416. BYTEBITS();
  78417. state->mode = CHECK;
  78418. break;
  78419. }
  78420. NEEDBITS(3);
  78421. state->last = BITS(1);
  78422. DROPBITS(1);
  78423. switch (BITS(2)) {
  78424. case 0: /* stored block */
  78425. Tracev((stderr, "inflate: stored block%s\n",
  78426. state->last ? " (last)" : ""));
  78427. state->mode = STORED;
  78428. break;
  78429. case 1: /* fixed block */
  78430. fixedtables(state);
  78431. Tracev((stderr, "inflate: fixed codes block%s\n",
  78432. state->last ? " (last)" : ""));
  78433. state->mode = LEN; /* decode codes */
  78434. break;
  78435. case 2: /* dynamic block */
  78436. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78437. state->last ? " (last)" : ""));
  78438. state->mode = TABLE;
  78439. break;
  78440. case 3:
  78441. strm->msg = (char *)"invalid block type";
  78442. state->mode = BAD;
  78443. }
  78444. DROPBITS(2);
  78445. break;
  78446. case STORED:
  78447. BYTEBITS(); /* go to byte boundary */
  78448. NEEDBITS(32);
  78449. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78450. strm->msg = (char *)"invalid stored block lengths";
  78451. state->mode = BAD;
  78452. break;
  78453. }
  78454. state->length = (unsigned)hold & 0xffff;
  78455. Tracev((stderr, "inflate: stored length %u\n",
  78456. state->length));
  78457. INITBITS();
  78458. state->mode = COPY;
  78459. case COPY:
  78460. copy = state->length;
  78461. if (copy) {
  78462. if (copy > have) copy = have;
  78463. if (copy > left) copy = left;
  78464. if (copy == 0) goto inf_leave;
  78465. zmemcpy(put, next, copy);
  78466. have -= copy;
  78467. next += copy;
  78468. left -= copy;
  78469. put += copy;
  78470. state->length -= copy;
  78471. break;
  78472. }
  78473. Tracev((stderr, "inflate: stored end\n"));
  78474. state->mode = TYPE;
  78475. break;
  78476. case TABLE:
  78477. NEEDBITS(14);
  78478. state->nlen = BITS(5) + 257;
  78479. DROPBITS(5);
  78480. state->ndist = BITS(5) + 1;
  78481. DROPBITS(5);
  78482. state->ncode = BITS(4) + 4;
  78483. DROPBITS(4);
  78484. #ifndef PKZIP_BUG_WORKAROUND
  78485. if (state->nlen > 286 || state->ndist > 30) {
  78486. strm->msg = (char *)"too many length or distance symbols";
  78487. state->mode = BAD;
  78488. break;
  78489. }
  78490. #endif
  78491. Tracev((stderr, "inflate: table sizes ok\n"));
  78492. state->have = 0;
  78493. state->mode = LENLENS;
  78494. case LENLENS:
  78495. while (state->have < state->ncode) {
  78496. NEEDBITS(3);
  78497. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  78498. DROPBITS(3);
  78499. }
  78500. while (state->have < 19)
  78501. state->lens[order[state->have++]] = 0;
  78502. state->next = state->codes;
  78503. state->lencode = (code const FAR *)(state->next);
  78504. state->lenbits = 7;
  78505. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  78506. &(state->lenbits), state->work);
  78507. if (ret) {
  78508. strm->msg = (char *)"invalid code lengths set";
  78509. state->mode = BAD;
  78510. break;
  78511. }
  78512. Tracev((stderr, "inflate: code lengths ok\n"));
  78513. state->have = 0;
  78514. state->mode = CODELENS;
  78515. case CODELENS:
  78516. while (state->have < state->nlen + state->ndist) {
  78517. for (;;) {
  78518. thisx = state->lencode[BITS(state->lenbits)];
  78519. if ((unsigned)(thisx.bits) <= bits) break;
  78520. PULLBYTE();
  78521. }
  78522. if (thisx.val < 16) {
  78523. NEEDBITS(thisx.bits);
  78524. DROPBITS(thisx.bits);
  78525. state->lens[state->have++] = thisx.val;
  78526. }
  78527. else {
  78528. if (thisx.val == 16) {
  78529. NEEDBITS(thisx.bits + 2);
  78530. DROPBITS(thisx.bits);
  78531. if (state->have == 0) {
  78532. strm->msg = (char *)"invalid bit length repeat";
  78533. state->mode = BAD;
  78534. break;
  78535. }
  78536. len = state->lens[state->have - 1];
  78537. copy = 3 + BITS(2);
  78538. DROPBITS(2);
  78539. }
  78540. else if (thisx.val == 17) {
  78541. NEEDBITS(thisx.bits + 3);
  78542. DROPBITS(thisx.bits);
  78543. len = 0;
  78544. copy = 3 + BITS(3);
  78545. DROPBITS(3);
  78546. }
  78547. else {
  78548. NEEDBITS(thisx.bits + 7);
  78549. DROPBITS(thisx.bits);
  78550. len = 0;
  78551. copy = 11 + BITS(7);
  78552. DROPBITS(7);
  78553. }
  78554. if (state->have + copy > state->nlen + state->ndist) {
  78555. strm->msg = (char *)"invalid bit length repeat";
  78556. state->mode = BAD;
  78557. break;
  78558. }
  78559. while (copy--)
  78560. state->lens[state->have++] = (unsigned short)len;
  78561. }
  78562. }
  78563. if (state->mode == BAD) break;
  78564. state->next = state->codes;
  78565. state->lencode = (code const FAR *)(state->next);
  78566. state->lenbits = 9;
  78567. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  78568. &(state->lenbits), state->work);
  78569. if (ret) {
  78570. strm->msg = (char *)"invalid literal/lengths set";
  78571. state->mode = BAD;
  78572. break;
  78573. }
  78574. state->distcode = (code const FAR *)(state->next);
  78575. state->distbits = 6;
  78576. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  78577. &(state->next), &(state->distbits), state->work);
  78578. if (ret) {
  78579. strm->msg = (char *)"invalid distances set";
  78580. state->mode = BAD;
  78581. break;
  78582. }
  78583. Tracev((stderr, "inflate: codes ok\n"));
  78584. state->mode = LEN;
  78585. case LEN:
  78586. if (have >= 6 && left >= 258) {
  78587. RESTORE();
  78588. inflate_fast(strm, out);
  78589. LOAD();
  78590. break;
  78591. }
  78592. for (;;) {
  78593. thisx = state->lencode[BITS(state->lenbits)];
  78594. if ((unsigned)(thisx.bits) <= bits) break;
  78595. PULLBYTE();
  78596. }
  78597. if (thisx.op && (thisx.op & 0xf0) == 0) {
  78598. last = thisx;
  78599. for (;;) {
  78600. thisx = state->lencode[last.val +
  78601. (BITS(last.bits + last.op) >> last.bits)];
  78602. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78603. PULLBYTE();
  78604. }
  78605. DROPBITS(last.bits);
  78606. }
  78607. DROPBITS(thisx.bits);
  78608. state->length = (unsigned)thisx.val;
  78609. if ((int)(thisx.op) == 0) {
  78610. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78611. "inflate: literal '%c'\n" :
  78612. "inflate: literal 0x%02x\n", thisx.val));
  78613. state->mode = LIT;
  78614. break;
  78615. }
  78616. if (thisx.op & 32) {
  78617. Tracevv((stderr, "inflate: end of block\n"));
  78618. state->mode = TYPE;
  78619. break;
  78620. }
  78621. if (thisx.op & 64) {
  78622. strm->msg = (char *)"invalid literal/length code";
  78623. state->mode = BAD;
  78624. break;
  78625. }
  78626. state->extra = (unsigned)(thisx.op) & 15;
  78627. state->mode = LENEXT;
  78628. case LENEXT:
  78629. if (state->extra) {
  78630. NEEDBITS(state->extra);
  78631. state->length += BITS(state->extra);
  78632. DROPBITS(state->extra);
  78633. }
  78634. Tracevv((stderr, "inflate: length %u\n", state->length));
  78635. state->mode = DIST;
  78636. case DIST:
  78637. for (;;) {
  78638. thisx = state->distcode[BITS(state->distbits)];
  78639. if ((unsigned)(thisx.bits) <= bits) break;
  78640. PULLBYTE();
  78641. }
  78642. if ((thisx.op & 0xf0) == 0) {
  78643. last = thisx;
  78644. for (;;) {
  78645. thisx = state->distcode[last.val +
  78646. (BITS(last.bits + last.op) >> last.bits)];
  78647. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  78648. PULLBYTE();
  78649. }
  78650. DROPBITS(last.bits);
  78651. }
  78652. DROPBITS(thisx.bits);
  78653. if (thisx.op & 64) {
  78654. strm->msg = (char *)"invalid distance code";
  78655. state->mode = BAD;
  78656. break;
  78657. }
  78658. state->offset = (unsigned)thisx.val;
  78659. state->extra = (unsigned)(thisx.op) & 15;
  78660. state->mode = DISTEXT;
  78661. case DISTEXT:
  78662. if (state->extra) {
  78663. NEEDBITS(state->extra);
  78664. state->offset += BITS(state->extra);
  78665. DROPBITS(state->extra);
  78666. }
  78667. #ifdef INFLATE_STRICT
  78668. if (state->offset > state->dmax) {
  78669. strm->msg = (char *)"invalid distance too far back";
  78670. state->mode = BAD;
  78671. break;
  78672. }
  78673. #endif
  78674. if (state->offset > state->whave + out - left) {
  78675. strm->msg = (char *)"invalid distance too far back";
  78676. state->mode = BAD;
  78677. break;
  78678. }
  78679. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  78680. state->mode = MATCH;
  78681. case MATCH:
  78682. if (left == 0) goto inf_leave;
  78683. copy = out - left;
  78684. if (state->offset > copy) { /* copy from window */
  78685. copy = state->offset - copy;
  78686. if (copy > state->write) {
  78687. copy -= state->write;
  78688. from = state->window + (state->wsize - copy);
  78689. }
  78690. else
  78691. from = state->window + (state->write - copy);
  78692. if (copy > state->length) copy = state->length;
  78693. }
  78694. else { /* copy from output */
  78695. from = put - state->offset;
  78696. copy = state->length;
  78697. }
  78698. if (copy > left) copy = left;
  78699. left -= copy;
  78700. state->length -= copy;
  78701. do {
  78702. *put++ = *from++;
  78703. } while (--copy);
  78704. if (state->length == 0) state->mode = LEN;
  78705. break;
  78706. case LIT:
  78707. if (left == 0) goto inf_leave;
  78708. *put++ = (unsigned char)(state->length);
  78709. left--;
  78710. state->mode = LEN;
  78711. break;
  78712. case CHECK:
  78713. if (state->wrap) {
  78714. NEEDBITS(32);
  78715. out -= left;
  78716. strm->total_out += out;
  78717. state->total += out;
  78718. if (out)
  78719. strm->adler = state->check =
  78720. UPDATE(state->check, put - out, out);
  78721. out = left;
  78722. if ((
  78723. #ifdef GUNZIP
  78724. state->flags ? hold :
  78725. #endif
  78726. REVERSE(hold)) != state->check) {
  78727. strm->msg = (char *)"incorrect data check";
  78728. state->mode = BAD;
  78729. break;
  78730. }
  78731. INITBITS();
  78732. Tracev((stderr, "inflate: check matches trailer\n"));
  78733. }
  78734. #ifdef GUNZIP
  78735. state->mode = LENGTH;
  78736. case LENGTH:
  78737. if (state->wrap && state->flags) {
  78738. NEEDBITS(32);
  78739. if (hold != (state->total & 0xffffffffUL)) {
  78740. strm->msg = (char *)"incorrect length check";
  78741. state->mode = BAD;
  78742. break;
  78743. }
  78744. INITBITS();
  78745. Tracev((stderr, "inflate: length matches trailer\n"));
  78746. }
  78747. #endif
  78748. state->mode = DONE;
  78749. case DONE:
  78750. ret = Z_STREAM_END;
  78751. goto inf_leave;
  78752. case BAD:
  78753. ret = Z_DATA_ERROR;
  78754. goto inf_leave;
  78755. case MEM:
  78756. return Z_MEM_ERROR;
  78757. case SYNC:
  78758. default:
  78759. return Z_STREAM_ERROR;
  78760. }
  78761. inf_leave:
  78762. RESTORE();
  78763. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  78764. if (updatewindow(strm, out)) {
  78765. state->mode = MEM;
  78766. return Z_MEM_ERROR;
  78767. }
  78768. in -= strm->avail_in;
  78769. out -= strm->avail_out;
  78770. strm->total_in += in;
  78771. strm->total_out += out;
  78772. state->total += out;
  78773. if (state->wrap && out)
  78774. strm->adler = state->check =
  78775. UPDATE(state->check, strm->next_out - out, out);
  78776. strm->data_type = state->bits + (state->last ? 64 : 0) +
  78777. (state->mode == TYPE ? 128 : 0);
  78778. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  78779. ret = Z_BUF_ERROR;
  78780. return ret;
  78781. }
  78782. int ZEXPORT inflateEnd (z_streamp strm)
  78783. {
  78784. struct inflate_state FAR *state;
  78785. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  78786. return Z_STREAM_ERROR;
  78787. state = (struct inflate_state FAR *)strm->state;
  78788. if (state->window != Z_NULL) ZFREE(strm, state->window);
  78789. ZFREE(strm, strm->state);
  78790. strm->state = Z_NULL;
  78791. Tracev((stderr, "inflate: end\n"));
  78792. return Z_OK;
  78793. }
  78794. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  78795. {
  78796. struct inflate_state FAR *state;
  78797. unsigned long id_;
  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 != 0 && state->mode != DICT)
  78801. return Z_STREAM_ERROR;
  78802. if (state->mode == DICT) {
  78803. id_ = adler32(0L, Z_NULL, 0);
  78804. id_ = adler32(id_, dictionary, dictLength);
  78805. if (id_ != state->check)
  78806. return Z_DATA_ERROR;
  78807. }
  78808. if (updatewindow(strm, strm->avail_out)) {
  78809. state->mode = MEM;
  78810. return Z_MEM_ERROR;
  78811. }
  78812. if (dictLength > state->wsize) {
  78813. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  78814. state->wsize);
  78815. state->whave = state->wsize;
  78816. }
  78817. else {
  78818. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  78819. dictLength);
  78820. state->whave = dictLength;
  78821. }
  78822. state->havedict = 1;
  78823. Tracev((stderr, "inflate: dictionary set\n"));
  78824. return Z_OK;
  78825. }
  78826. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  78827. {
  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 ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  78832. state->head = head;
  78833. head->done = 0;
  78834. return Z_OK;
  78835. }
  78836. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  78837. {
  78838. unsigned got;
  78839. unsigned next;
  78840. got = *have;
  78841. next = 0;
  78842. while (next < len && got < 4) {
  78843. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  78844. got++;
  78845. else if (buf[next])
  78846. got = 0;
  78847. else
  78848. got = 4 - got;
  78849. next++;
  78850. }
  78851. *have = got;
  78852. return next;
  78853. }
  78854. int ZEXPORT inflateSync (z_streamp strm)
  78855. {
  78856. unsigned len; /* number of bytes to look at or looked at */
  78857. unsigned long in, out; /* temporary to save total_in and total_out */
  78858. unsigned char buf[4]; /* to restore bit buffer to byte string */
  78859. struct inflate_state FAR *state;
  78860. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78861. state = (struct inflate_state FAR *)strm->state;
  78862. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  78863. if (state->mode != SYNC) {
  78864. state->mode = SYNC;
  78865. state->hold <<= state->bits & 7;
  78866. state->bits -= state->bits & 7;
  78867. len = 0;
  78868. while (state->bits >= 8) {
  78869. buf[len++] = (unsigned char)(state->hold);
  78870. state->hold >>= 8;
  78871. state->bits -= 8;
  78872. }
  78873. state->have = 0;
  78874. syncsearch(&(state->have), buf, len);
  78875. }
  78876. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  78877. strm->avail_in -= len;
  78878. strm->next_in += len;
  78879. strm->total_in += len;
  78880. if (state->have != 4) return Z_DATA_ERROR;
  78881. in = strm->total_in; out = strm->total_out;
  78882. inflateReset(strm);
  78883. strm->total_in = in; strm->total_out = out;
  78884. state->mode = TYPE;
  78885. return Z_OK;
  78886. }
  78887. int ZEXPORT inflateSyncPoint (z_streamp strm)
  78888. {
  78889. struct inflate_state FAR *state;
  78890. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78891. state = (struct inflate_state FAR *)strm->state;
  78892. return state->mode == STORED && state->bits == 0;
  78893. }
  78894. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  78895. {
  78896. struct inflate_state FAR *state;
  78897. struct inflate_state FAR *copy;
  78898. unsigned char FAR *window;
  78899. unsigned wsize;
  78900. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  78901. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  78902. return Z_STREAM_ERROR;
  78903. state = (struct inflate_state FAR *)source->state;
  78904. copy = (struct inflate_state FAR *)
  78905. ZALLOC(source, 1, sizeof(struct inflate_state));
  78906. if (copy == Z_NULL) return Z_MEM_ERROR;
  78907. window = Z_NULL;
  78908. if (state->window != Z_NULL) {
  78909. window = (unsigned char FAR *)
  78910. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  78911. if (window == Z_NULL) {
  78912. ZFREE(source, copy);
  78913. return Z_MEM_ERROR;
  78914. }
  78915. }
  78916. zmemcpy(dest, source, sizeof(z_stream));
  78917. zmemcpy(copy, state, sizeof(struct inflate_state));
  78918. if (state->lencode >= state->codes &&
  78919. state->lencode <= state->codes + ENOUGH - 1) {
  78920. copy->lencode = copy->codes + (state->lencode - state->codes);
  78921. copy->distcode = copy->codes + (state->distcode - state->codes);
  78922. }
  78923. copy->next = copy->codes + (state->next - state->codes);
  78924. if (window != Z_NULL) {
  78925. wsize = 1U << state->wbits;
  78926. zmemcpy(window, state->window, wsize);
  78927. }
  78928. copy->window = window;
  78929. dest->state = (struct internal_state FAR *)copy;
  78930. return Z_OK;
  78931. }
  78932. /*** End of inlined file: inflate.c ***/
  78933. /*** Start of inlined file: inftrees.c ***/
  78934. #define MAXBITS 15
  78935. const char inflate_copyright[] =
  78936. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  78937. int inflate_table (codetype type,
  78938. unsigned short FAR *lens,
  78939. unsigned codes,
  78940. code FAR * FAR *table,
  78941. unsigned FAR *bits,
  78942. unsigned short FAR *work)
  78943. {
  78944. unsigned len; /* a code's length in bits */
  78945. unsigned sym; /* index of code symbols */
  78946. unsigned min, max; /* minimum and maximum code lengths */
  78947. unsigned root; /* number of index bits for root table */
  78948. unsigned curr; /* number of index bits for current table */
  78949. unsigned drop; /* code bits to drop for sub-table */
  78950. int left; /* number of prefix codes available */
  78951. unsigned used; /* code entries in table used */
  78952. unsigned huff; /* Huffman code */
  78953. unsigned incr; /* for incrementing code, index */
  78954. unsigned fill; /* index for replicating entries */
  78955. unsigned low; /* low bits for current root entry */
  78956. unsigned mask; /* mask for low root bits */
  78957. code thisx; /* table entry for duplication */
  78958. code FAR *next; /* next available space in table */
  78959. const unsigned short FAR *base; /* base value table to use */
  78960. const unsigned short FAR *extra; /* extra bits table to use */
  78961. int end; /* use base and extra for symbol > end */
  78962. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  78963. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  78964. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  78965. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  78966. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  78967. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  78968. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  78969. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  78970. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  78971. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  78972. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  78973. 8193, 12289, 16385, 24577, 0, 0};
  78974. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  78975. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  78976. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  78977. 28, 28, 29, 29, 64, 64};
  78978. for (len = 0; len <= MAXBITS; len++)
  78979. count[len] = 0;
  78980. for (sym = 0; sym < codes; sym++)
  78981. count[lens[sym]]++;
  78982. root = *bits;
  78983. for (max = MAXBITS; max >= 1; max--)
  78984. if (count[max] != 0) break;
  78985. if (root > max) root = max;
  78986. if (max == 0) { /* no symbols to code at all */
  78987. thisx.op = (unsigned char)64; /* invalid code marker */
  78988. thisx.bits = (unsigned char)1;
  78989. thisx.val = (unsigned short)0;
  78990. *(*table)++ = thisx; /* make a table to force an error */
  78991. *(*table)++ = thisx;
  78992. *bits = 1;
  78993. return 0; /* no symbols, but wait for decoding to report error */
  78994. }
  78995. for (min = 1; min <= MAXBITS; min++)
  78996. if (count[min] != 0) break;
  78997. if (root < min) root = min;
  78998. left = 1;
  78999. for (len = 1; len <= MAXBITS; len++) {
  79000. left <<= 1;
  79001. left -= count[len];
  79002. if (left < 0) return -1; /* over-subscribed */
  79003. }
  79004. if (left > 0 && (type == CODES || max != 1))
  79005. return -1; /* incomplete set */
  79006. offs[1] = 0;
  79007. for (len = 1; len < MAXBITS; len++)
  79008. offs[len + 1] = offs[len] + count[len];
  79009. for (sym = 0; sym < codes; sym++)
  79010. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79011. switch (type) {
  79012. case CODES:
  79013. base = extra = work; /* dummy value--not used */
  79014. end = 19;
  79015. break;
  79016. case LENS:
  79017. base = lbase;
  79018. base -= 257;
  79019. extra = lext;
  79020. extra -= 257;
  79021. end = 256;
  79022. break;
  79023. default: /* DISTS */
  79024. base = dbase;
  79025. extra = dext;
  79026. end = -1;
  79027. }
  79028. huff = 0; /* starting code */
  79029. sym = 0; /* starting code symbol */
  79030. len = min; /* starting code length */
  79031. next = *table; /* current table to fill in */
  79032. curr = root; /* current table index bits */
  79033. drop = 0; /* current bits to drop from code for index */
  79034. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79035. used = 1U << root; /* use root table entries */
  79036. mask = used - 1; /* mask for comparing low */
  79037. if (type == LENS && used >= ENOUGH - MAXD)
  79038. return 1;
  79039. for (;;) {
  79040. thisx.bits = (unsigned char)(len - drop);
  79041. if ((int)(work[sym]) < end) {
  79042. thisx.op = (unsigned char)0;
  79043. thisx.val = work[sym];
  79044. }
  79045. else if ((int)(work[sym]) > end) {
  79046. thisx.op = (unsigned char)(extra[work[sym]]);
  79047. thisx.val = base[work[sym]];
  79048. }
  79049. else {
  79050. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79051. thisx.val = 0;
  79052. }
  79053. incr = 1U << (len - drop);
  79054. fill = 1U << curr;
  79055. min = fill; /* save offset to next table */
  79056. do {
  79057. fill -= incr;
  79058. next[(huff >> drop) + fill] = thisx;
  79059. } while (fill != 0);
  79060. incr = 1U << (len - 1);
  79061. while (huff & incr)
  79062. incr >>= 1;
  79063. if (incr != 0) {
  79064. huff &= incr - 1;
  79065. huff += incr;
  79066. }
  79067. else
  79068. huff = 0;
  79069. sym++;
  79070. if (--(count[len]) == 0) {
  79071. if (len == max) break;
  79072. len = lens[work[sym]];
  79073. }
  79074. if (len > root && (huff & mask) != low) {
  79075. if (drop == 0)
  79076. drop = root;
  79077. next += min; /* here min is 1 << curr */
  79078. curr = len - drop;
  79079. left = (int)(1 << curr);
  79080. while (curr + drop < max) {
  79081. left -= count[curr + drop];
  79082. if (left <= 0) break;
  79083. curr++;
  79084. left <<= 1;
  79085. }
  79086. used += 1U << curr;
  79087. if (type == LENS && used >= ENOUGH - MAXD)
  79088. return 1;
  79089. low = huff & mask;
  79090. (*table)[low].op = (unsigned char)curr;
  79091. (*table)[low].bits = (unsigned char)root;
  79092. (*table)[low].val = (unsigned short)(next - *table);
  79093. }
  79094. }
  79095. thisx.op = (unsigned char)64; /* invalid code marker */
  79096. thisx.bits = (unsigned char)(len - drop);
  79097. thisx.val = (unsigned short)0;
  79098. while (huff != 0) {
  79099. if (drop != 0 && (huff & mask) != low) {
  79100. drop = 0;
  79101. len = root;
  79102. next = *table;
  79103. thisx.bits = (unsigned char)len;
  79104. }
  79105. next[huff >> drop] = thisx;
  79106. incr = 1U << (len - 1);
  79107. while (huff & incr)
  79108. incr >>= 1;
  79109. if (incr != 0) {
  79110. huff &= incr - 1;
  79111. huff += incr;
  79112. }
  79113. else
  79114. huff = 0;
  79115. }
  79116. *table += used;
  79117. *bits = root;
  79118. return 0;
  79119. }
  79120. /*** End of inlined file: inftrees.c ***/
  79121. /*** Start of inlined file: trees.c ***/
  79122. #ifdef DEBUG
  79123. # include <ctype.h>
  79124. #endif
  79125. #define MAX_BL_BITS 7
  79126. #define END_BLOCK 256
  79127. #define REP_3_6 16
  79128. #define REPZ_3_10 17
  79129. #define REPZ_11_138 18
  79130. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79131. = {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};
  79132. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79133. = {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};
  79134. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79135. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79136. local const uch bl_order[BL_CODES]
  79137. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79138. #define Buf_size (8 * 2*sizeof(char))
  79139. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79140. #if defined(GEN_TREES_H) || !defined(STDC)
  79141. local ct_data static_ltree[L_CODES+2];
  79142. local ct_data static_dtree[D_CODES];
  79143. uch _dist_code[DIST_CODE_LEN];
  79144. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79145. local int base_length[LENGTH_CODES];
  79146. local int base_dist[D_CODES];
  79147. #else
  79148. /*** Start of inlined file: trees.h ***/
  79149. local const ct_data static_ltree[L_CODES+2] = {
  79150. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79151. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79152. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79153. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79154. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79155. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79156. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79157. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79158. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79159. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79160. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79161. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79162. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79163. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79164. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79165. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79166. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79167. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79168. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79169. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79170. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79171. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79172. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79173. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79174. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79175. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79176. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79177. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79178. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79179. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79180. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79181. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79182. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79183. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79184. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79185. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79186. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79187. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79188. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79189. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79190. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79191. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79192. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79193. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79194. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79195. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79196. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79197. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79198. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79199. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79200. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79201. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79202. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79203. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79204. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79205. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79206. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79207. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79208. };
  79209. local const ct_data static_dtree[D_CODES] = {
  79210. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79211. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79212. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79213. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79214. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79215. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79216. };
  79217. const uch _dist_code[DIST_CODE_LEN] = {
  79218. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79219. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79220. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79221. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79222. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79223. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79224. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79225. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79226. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79227. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79228. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79229. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79230. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79231. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79232. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79233. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79234. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79235. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79236. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79237. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79238. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79239. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79240. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79241. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79242. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79243. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79244. };
  79245. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79246. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79247. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79248. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79249. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79250. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79251. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79252. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79253. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79254. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79255. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79256. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79257. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79258. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79259. };
  79260. local const int base_length[LENGTH_CODES] = {
  79261. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79262. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79263. };
  79264. local const int base_dist[D_CODES] = {
  79265. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79266. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79267. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79268. };
  79269. /*** End of inlined file: trees.h ***/
  79270. #endif /* GEN_TREES_H */
  79271. struct static_tree_desc_s {
  79272. const ct_data *static_tree; /* static tree or NULL */
  79273. const intf *extra_bits; /* extra bits for each code or NULL */
  79274. int extra_base; /* base index for extra_bits */
  79275. int elems; /* max number of elements in the tree */
  79276. int max_length; /* max bit length for the codes */
  79277. };
  79278. local static_tree_desc static_l_desc =
  79279. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79280. local static_tree_desc static_d_desc =
  79281. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79282. local static_tree_desc static_bl_desc =
  79283. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79284. local void tr_static_init OF((void));
  79285. local void init_block OF((deflate_state *s));
  79286. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79287. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79288. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79289. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79290. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79291. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79292. local int build_bl_tree OF((deflate_state *s));
  79293. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79294. int blcodes));
  79295. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79296. ct_data *dtree));
  79297. local void set_data_type OF((deflate_state *s));
  79298. local unsigned bi_reverse OF((unsigned value, int length));
  79299. local void bi_windup OF((deflate_state *s));
  79300. local void bi_flush OF((deflate_state *s));
  79301. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79302. int header));
  79303. #ifdef GEN_TREES_H
  79304. local void gen_trees_header OF((void));
  79305. #endif
  79306. #ifndef DEBUG
  79307. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79308. #else /* DEBUG */
  79309. # define send_code(s, c, tree) \
  79310. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79311. send_bits(s, tree[c].Code, tree[c].Len); }
  79312. #endif
  79313. #define put_short(s, w) { \
  79314. put_byte(s, (uch)((w) & 0xff)); \
  79315. put_byte(s, (uch)((ush)(w) >> 8)); \
  79316. }
  79317. #ifdef DEBUG
  79318. local void send_bits OF((deflate_state *s, int value, int length));
  79319. local void send_bits (deflate_state *s, int value, int length)
  79320. {
  79321. Tracevv((stderr," l %2d v %4x ", length, value));
  79322. Assert(length > 0 && length <= 15, "invalid length");
  79323. s->bits_sent += (ulg)length;
  79324. if (s->bi_valid > (int)Buf_size - length) {
  79325. s->bi_buf |= (value << s->bi_valid);
  79326. put_short(s, s->bi_buf);
  79327. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79328. s->bi_valid += length - Buf_size;
  79329. } else {
  79330. s->bi_buf |= value << s->bi_valid;
  79331. s->bi_valid += length;
  79332. }
  79333. }
  79334. #else /* !DEBUG */
  79335. #define send_bits(s, value, length) \
  79336. { int len = length;\
  79337. if (s->bi_valid > (int)Buf_size - len) {\
  79338. int val = value;\
  79339. s->bi_buf |= (val << s->bi_valid);\
  79340. put_short(s, s->bi_buf);\
  79341. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79342. s->bi_valid += len - Buf_size;\
  79343. } else {\
  79344. s->bi_buf |= (value) << s->bi_valid;\
  79345. s->bi_valid += len;\
  79346. }\
  79347. }
  79348. #endif /* DEBUG */
  79349. local void tr_static_init()
  79350. {
  79351. #if defined(GEN_TREES_H) || !defined(STDC)
  79352. static int static_init_done = 0;
  79353. int n; /* iterates over tree elements */
  79354. int bits; /* bit counter */
  79355. int length; /* length value */
  79356. int code; /* code value */
  79357. int dist; /* distance index */
  79358. ush bl_count[MAX_BITS+1];
  79359. if (static_init_done) return;
  79360. static_l_desc.static_tree = static_ltree;
  79361. static_l_desc.extra_bits = extra_lbits;
  79362. static_d_desc.static_tree = static_dtree;
  79363. static_d_desc.extra_bits = extra_dbits;
  79364. static_bl_desc.extra_bits = extra_blbits;
  79365. length = 0;
  79366. for (code = 0; code < LENGTH_CODES-1; code++) {
  79367. base_length[code] = length;
  79368. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79369. _length_code[length++] = (uch)code;
  79370. }
  79371. }
  79372. Assert (length == 256, "tr_static_init: length != 256");
  79373. _length_code[length-1] = (uch)code;
  79374. dist = 0;
  79375. for (code = 0 ; code < 16; code++) {
  79376. base_dist[code] = dist;
  79377. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79378. _dist_code[dist++] = (uch)code;
  79379. }
  79380. }
  79381. Assert (dist == 256, "tr_static_init: dist != 256");
  79382. dist >>= 7; /* from now on, all distances are divided by 128 */
  79383. for ( ; code < D_CODES; code++) {
  79384. base_dist[code] = dist << 7;
  79385. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79386. _dist_code[256 + dist++] = (uch)code;
  79387. }
  79388. }
  79389. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79390. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79391. n = 0;
  79392. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79393. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79394. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79395. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79396. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79397. for (n = 0; n < D_CODES; n++) {
  79398. static_dtree[n].Len = 5;
  79399. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79400. }
  79401. static_init_done = 1;
  79402. # ifdef GEN_TREES_H
  79403. gen_trees_header();
  79404. # endif
  79405. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79406. }
  79407. #ifdef GEN_TREES_H
  79408. # ifndef DEBUG
  79409. # include <stdio.h>
  79410. # endif
  79411. # define SEPARATOR(i, last, width) \
  79412. ((i) == (last)? "\n};\n\n" : \
  79413. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79414. void gen_trees_header()
  79415. {
  79416. FILE *header = fopen("trees.h", "w");
  79417. int i;
  79418. Assert (header != NULL, "Can't open trees.h");
  79419. fprintf(header,
  79420. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79421. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79422. for (i = 0; i < L_CODES+2; i++) {
  79423. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79424. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79425. }
  79426. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79427. for (i = 0; i < D_CODES; i++) {
  79428. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79429. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79430. }
  79431. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79432. for (i = 0; i < DIST_CODE_LEN; i++) {
  79433. fprintf(header, "%2u%s", _dist_code[i],
  79434. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79435. }
  79436. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79437. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79438. fprintf(header, "%2u%s", _length_code[i],
  79439. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79440. }
  79441. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79442. for (i = 0; i < LENGTH_CODES; i++) {
  79443. fprintf(header, "%1u%s", base_length[i],
  79444. SEPARATOR(i, LENGTH_CODES-1, 20));
  79445. }
  79446. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79447. for (i = 0; i < D_CODES; i++) {
  79448. fprintf(header, "%5u%s", base_dist[i],
  79449. SEPARATOR(i, D_CODES-1, 10));
  79450. }
  79451. fclose(header);
  79452. }
  79453. #endif /* GEN_TREES_H */
  79454. void _tr_init(deflate_state *s)
  79455. {
  79456. tr_static_init();
  79457. s->l_desc.dyn_tree = s->dyn_ltree;
  79458. s->l_desc.stat_desc = &static_l_desc;
  79459. s->d_desc.dyn_tree = s->dyn_dtree;
  79460. s->d_desc.stat_desc = &static_d_desc;
  79461. s->bl_desc.dyn_tree = s->bl_tree;
  79462. s->bl_desc.stat_desc = &static_bl_desc;
  79463. s->bi_buf = 0;
  79464. s->bi_valid = 0;
  79465. s->last_eob_len = 8; /* enough lookahead for inflate */
  79466. #ifdef DEBUG
  79467. s->compressed_len = 0L;
  79468. s->bits_sent = 0L;
  79469. #endif
  79470. init_block(s);
  79471. }
  79472. local void init_block (deflate_state *s)
  79473. {
  79474. int n; /* iterates over tree elements */
  79475. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79476. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79477. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79478. s->dyn_ltree[END_BLOCK].Freq = 1;
  79479. s->opt_len = s->static_len = 0L;
  79480. s->last_lit = s->matches = 0;
  79481. }
  79482. #define SMALLEST 1
  79483. #define pqremove(s, tree, top) \
  79484. {\
  79485. top = s->heap[SMALLEST]; \
  79486. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79487. pqdownheap(s, tree, SMALLEST); \
  79488. }
  79489. #define smaller(tree, n, m, depth) \
  79490. (tree[n].Freq < tree[m].Freq || \
  79491. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79492. local void pqdownheap (deflate_state *s,
  79493. ct_data *tree, /* the tree to restore */
  79494. int k) /* node to move down */
  79495. {
  79496. int v = s->heap[k];
  79497. int j = k << 1; /* left son of k */
  79498. while (j <= s->heap_len) {
  79499. if (j < s->heap_len &&
  79500. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  79501. j++;
  79502. }
  79503. if (smaller(tree, v, s->heap[j], s->depth)) break;
  79504. s->heap[k] = s->heap[j]; k = j;
  79505. j <<= 1;
  79506. }
  79507. s->heap[k] = v;
  79508. }
  79509. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  79510. {
  79511. ct_data *tree = desc->dyn_tree;
  79512. int max_code = desc->max_code;
  79513. const ct_data *stree = desc->stat_desc->static_tree;
  79514. const intf *extra = desc->stat_desc->extra_bits;
  79515. int base = desc->stat_desc->extra_base;
  79516. int max_length = desc->stat_desc->max_length;
  79517. int h; /* heap index */
  79518. int n, m; /* iterate over the tree elements */
  79519. int bits; /* bit length */
  79520. int xbits; /* extra bits */
  79521. ush f; /* frequency */
  79522. int overflow = 0; /* number of elements with bit length too large */
  79523. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  79524. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  79525. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  79526. n = s->heap[h];
  79527. bits = tree[tree[n].Dad].Len + 1;
  79528. if (bits > max_length) bits = max_length, overflow++;
  79529. tree[n].Len = (ush)bits;
  79530. if (n > max_code) continue; /* not a leaf node */
  79531. s->bl_count[bits]++;
  79532. xbits = 0;
  79533. if (n >= base) xbits = extra[n-base];
  79534. f = tree[n].Freq;
  79535. s->opt_len += (ulg)f * (bits + xbits);
  79536. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  79537. }
  79538. if (overflow == 0) return;
  79539. Trace((stderr,"\nbit length overflow\n"));
  79540. do {
  79541. bits = max_length-1;
  79542. while (s->bl_count[bits] == 0) bits--;
  79543. s->bl_count[bits]--; /* move one leaf down the tree */
  79544. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  79545. s->bl_count[max_length]--;
  79546. overflow -= 2;
  79547. } while (overflow > 0);
  79548. for (bits = max_length; bits != 0; bits--) {
  79549. n = s->bl_count[bits];
  79550. while (n != 0) {
  79551. m = s->heap[--h];
  79552. if (m > max_code) continue;
  79553. if ((unsigned) tree[m].Len != (unsigned) bits) {
  79554. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  79555. s->opt_len += ((long)bits - (long)tree[m].Len)
  79556. *(long)tree[m].Freq;
  79557. tree[m].Len = (ush)bits;
  79558. }
  79559. n--;
  79560. }
  79561. }
  79562. }
  79563. local void gen_codes (ct_data *tree, /* the tree to decorate */
  79564. int max_code, /* largest code with non zero frequency */
  79565. ushf *bl_count) /* number of codes at each bit length */
  79566. {
  79567. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  79568. ush code = 0; /* running code value */
  79569. int bits; /* bit index */
  79570. int n; /* code index */
  79571. for (bits = 1; bits <= MAX_BITS; bits++) {
  79572. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  79573. }
  79574. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  79575. "inconsistent bit counts");
  79576. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  79577. for (n = 0; n <= max_code; n++) {
  79578. int len = tree[n].Len;
  79579. if (len == 0) continue;
  79580. tree[n].Code = bi_reverse(next_code[len]++, len);
  79581. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  79582. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  79583. }
  79584. }
  79585. local void build_tree (deflate_state *s,
  79586. tree_desc *desc) /* the tree descriptor */
  79587. {
  79588. ct_data *tree = desc->dyn_tree;
  79589. const ct_data *stree = desc->stat_desc->static_tree;
  79590. int elems = desc->stat_desc->elems;
  79591. int n, m; /* iterate over heap elements */
  79592. int max_code = -1; /* largest code with non zero frequency */
  79593. int node; /* new node being created */
  79594. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  79595. for (n = 0; n < elems; n++) {
  79596. if (tree[n].Freq != 0) {
  79597. s->heap[++(s->heap_len)] = max_code = n;
  79598. s->depth[n] = 0;
  79599. } else {
  79600. tree[n].Len = 0;
  79601. }
  79602. }
  79603. while (s->heap_len < 2) {
  79604. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  79605. tree[node].Freq = 1;
  79606. s->depth[node] = 0;
  79607. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  79608. }
  79609. desc->max_code = max_code;
  79610. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  79611. node = elems; /* next internal node of the tree */
  79612. do {
  79613. pqremove(s, tree, n); /* n = node of least frequency */
  79614. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  79615. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  79616. s->heap[--(s->heap_max)] = m;
  79617. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  79618. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  79619. s->depth[n] : s->depth[m]) + 1);
  79620. tree[n].Dad = tree[m].Dad = (ush)node;
  79621. #ifdef DUMP_BL_TREE
  79622. if (tree == s->bl_tree) {
  79623. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  79624. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  79625. }
  79626. #endif
  79627. s->heap[SMALLEST] = node++;
  79628. pqdownheap(s, tree, SMALLEST);
  79629. } while (s->heap_len >= 2);
  79630. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  79631. gen_bitlen(s, (tree_desc *)desc);
  79632. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  79633. }
  79634. local void scan_tree (deflate_state *s,
  79635. ct_data *tree, /* the tree to be scanned */
  79636. int max_code) /* and its largest code of non zero frequency */
  79637. {
  79638. int n; /* iterates over all tree elements */
  79639. int prevlen = -1; /* last emitted length */
  79640. int curlen; /* length of current code */
  79641. int nextlen = tree[0].Len; /* length of next code */
  79642. int count = 0; /* repeat count of the current code */
  79643. int max_count = 7; /* max repeat count */
  79644. int min_count = 4; /* min repeat count */
  79645. if (nextlen == 0) max_count = 138, min_count = 3;
  79646. tree[max_code+1].Len = (ush)0xffff; /* guard */
  79647. for (n = 0; n <= max_code; n++) {
  79648. curlen = nextlen; nextlen = tree[n+1].Len;
  79649. if (++count < max_count && curlen == nextlen) {
  79650. continue;
  79651. } else if (count < min_count) {
  79652. s->bl_tree[curlen].Freq += count;
  79653. } else if (curlen != 0) {
  79654. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  79655. s->bl_tree[REP_3_6].Freq++;
  79656. } else if (count <= 10) {
  79657. s->bl_tree[REPZ_3_10].Freq++;
  79658. } else {
  79659. s->bl_tree[REPZ_11_138].Freq++;
  79660. }
  79661. count = 0; prevlen = curlen;
  79662. if (nextlen == 0) {
  79663. max_count = 138, min_count = 3;
  79664. } else if (curlen == nextlen) {
  79665. max_count = 6, min_count = 3;
  79666. } else {
  79667. max_count = 7, min_count = 4;
  79668. }
  79669. }
  79670. }
  79671. local void send_tree (deflate_state *s,
  79672. ct_data *tree, /* the tree to be scanned */
  79673. int max_code) /* and its largest code of non zero frequency */
  79674. {
  79675. int n; /* iterates over all tree elements */
  79676. int prevlen = -1; /* last emitted length */
  79677. int curlen; /* length of current code */
  79678. int nextlen = tree[0].Len; /* length of next code */
  79679. int count = 0; /* repeat count of the current code */
  79680. int max_count = 7; /* max repeat count */
  79681. int min_count = 4; /* min repeat count */
  79682. /* guard already set */
  79683. if (nextlen == 0) max_count = 138, min_count = 3;
  79684. for (n = 0; n <= max_code; n++) {
  79685. curlen = nextlen; nextlen = tree[n+1].Len;
  79686. if (++count < max_count && curlen == nextlen) {
  79687. continue;
  79688. } else if (count < min_count) {
  79689. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  79690. } else if (curlen != 0) {
  79691. if (curlen != prevlen) {
  79692. send_code(s, curlen, s->bl_tree); count--;
  79693. }
  79694. Assert(count >= 3 && count <= 6, " 3_6?");
  79695. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  79696. } else if (count <= 10) {
  79697. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  79698. } else {
  79699. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  79700. }
  79701. count = 0; prevlen = curlen;
  79702. if (nextlen == 0) {
  79703. max_count = 138, min_count = 3;
  79704. } else if (curlen == nextlen) {
  79705. max_count = 6, min_count = 3;
  79706. } else {
  79707. max_count = 7, min_count = 4;
  79708. }
  79709. }
  79710. }
  79711. local int build_bl_tree (deflate_state *s)
  79712. {
  79713. int max_blindex; /* index of last bit length code of non zero freq */
  79714. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  79715. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  79716. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  79717. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  79718. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  79719. }
  79720. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  79721. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  79722. s->opt_len, s->static_len));
  79723. return max_blindex;
  79724. }
  79725. local void send_all_trees (deflate_state *s,
  79726. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  79727. {
  79728. int rank; /* index in bl_order */
  79729. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  79730. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  79731. "too many codes");
  79732. Tracev((stderr, "\nbl counts: "));
  79733. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  79734. send_bits(s, dcodes-1, 5);
  79735. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  79736. for (rank = 0; rank < blcodes; rank++) {
  79737. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  79738. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  79739. }
  79740. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  79741. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  79742. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  79743. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  79744. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  79745. }
  79746. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  79747. {
  79748. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  79749. #ifdef DEBUG
  79750. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  79751. s->compressed_len += (stored_len + 4) << 3;
  79752. #endif
  79753. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  79754. }
  79755. void _tr_align (deflate_state *s)
  79756. {
  79757. send_bits(s, STATIC_TREES<<1, 3);
  79758. send_code(s, END_BLOCK, static_ltree);
  79759. #ifdef DEBUG
  79760. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  79761. #endif
  79762. bi_flush(s);
  79763. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  79764. send_bits(s, STATIC_TREES<<1, 3);
  79765. send_code(s, END_BLOCK, static_ltree);
  79766. #ifdef DEBUG
  79767. s->compressed_len += 10L;
  79768. #endif
  79769. bi_flush(s);
  79770. }
  79771. s->last_eob_len = 7;
  79772. }
  79773. void _tr_flush_block (deflate_state *s,
  79774. charf *buf, /* input block, or NULL if too old */
  79775. ulg stored_len, /* length of input block */
  79776. int eof) /* true if this is the last block for a file */
  79777. {
  79778. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  79779. int max_blindex = 0; /* index of last bit length code of non zero freq */
  79780. if (s->level > 0) {
  79781. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  79782. set_data_type(s);
  79783. build_tree(s, (tree_desc *)(&(s->l_desc)));
  79784. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  79785. s->static_len));
  79786. build_tree(s, (tree_desc *)(&(s->d_desc)));
  79787. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  79788. s->static_len));
  79789. max_blindex = build_bl_tree(s);
  79790. opt_lenb = (s->opt_len+3+7)>>3;
  79791. static_lenb = (s->static_len+3+7)>>3;
  79792. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  79793. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  79794. s->last_lit));
  79795. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  79796. } else {
  79797. Assert(buf != (char*)0, "lost buf");
  79798. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  79799. }
  79800. #ifdef FORCE_STORED
  79801. if (buf != (char*)0) { /* force stored block */
  79802. #else
  79803. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  79804. #endif
  79805. _tr_stored_block(s, buf, stored_len, eof);
  79806. #ifdef FORCE_STATIC
  79807. } else if (static_lenb >= 0) { /* force static trees */
  79808. #else
  79809. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  79810. #endif
  79811. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  79812. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  79813. #ifdef DEBUG
  79814. s->compressed_len += 3 + s->static_len;
  79815. #endif
  79816. } else {
  79817. send_bits(s, (DYN_TREES<<1)+eof, 3);
  79818. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  79819. max_blindex+1);
  79820. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  79821. #ifdef DEBUG
  79822. s->compressed_len += 3 + s->opt_len;
  79823. #endif
  79824. }
  79825. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  79826. init_block(s);
  79827. if (eof) {
  79828. bi_windup(s);
  79829. #ifdef DEBUG
  79830. s->compressed_len += 7; /* align on byte boundary */
  79831. #endif
  79832. }
  79833. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  79834. s->compressed_len-7*eof));
  79835. }
  79836. int _tr_tally (deflate_state *s,
  79837. unsigned dist, /* distance of matched string */
  79838. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  79839. {
  79840. s->d_buf[s->last_lit] = (ush)dist;
  79841. s->l_buf[s->last_lit++] = (uch)lc;
  79842. if (dist == 0) {
  79843. s->dyn_ltree[lc].Freq++;
  79844. } else {
  79845. s->matches++;
  79846. dist--; /* dist = match distance - 1 */
  79847. Assert((ush)dist < (ush)MAX_DIST(s) &&
  79848. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  79849. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  79850. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  79851. s->dyn_dtree[d_code(dist)].Freq++;
  79852. }
  79853. #ifdef TRUNCATE_BLOCK
  79854. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  79855. ulg out_length = (ulg)s->last_lit*8L;
  79856. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  79857. int dcode;
  79858. for (dcode = 0; dcode < D_CODES; dcode++) {
  79859. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  79860. (5L+extra_dbits[dcode]);
  79861. }
  79862. out_length >>= 3;
  79863. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  79864. s->last_lit, in_length, out_length,
  79865. 100L - out_length*100L/in_length));
  79866. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  79867. }
  79868. #endif
  79869. return (s->last_lit == s->lit_bufsize-1);
  79870. }
  79871. local void compress_block (deflate_state *s,
  79872. ct_data *ltree, /* literal tree */
  79873. ct_data *dtree) /* distance tree */
  79874. {
  79875. unsigned dist; /* distance of matched string */
  79876. int lc; /* match length or unmatched char (if dist == 0) */
  79877. unsigned lx = 0; /* running index in l_buf */
  79878. unsigned code; /* the code to send */
  79879. int extra; /* number of extra bits to send */
  79880. if (s->last_lit != 0) do {
  79881. dist = s->d_buf[lx];
  79882. lc = s->l_buf[lx++];
  79883. if (dist == 0) {
  79884. send_code(s, lc, ltree); /* send a literal byte */
  79885. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  79886. } else {
  79887. code = _length_code[lc];
  79888. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  79889. extra = extra_lbits[code];
  79890. if (extra != 0) {
  79891. lc -= base_length[code];
  79892. send_bits(s, lc, extra); /* send the extra length bits */
  79893. }
  79894. dist--; /* dist is now the match distance - 1 */
  79895. code = d_code(dist);
  79896. Assert (code < D_CODES, "bad d_code");
  79897. send_code(s, code, dtree); /* send the distance code */
  79898. extra = extra_dbits[code];
  79899. if (extra != 0) {
  79900. dist -= base_dist[code];
  79901. send_bits(s, dist, extra); /* send the extra distance bits */
  79902. }
  79903. } /* literal or match pair ? */
  79904. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  79905. "pendingBuf overflow");
  79906. } while (lx < s->last_lit);
  79907. send_code(s, END_BLOCK, ltree);
  79908. s->last_eob_len = ltree[END_BLOCK].Len;
  79909. }
  79910. local void set_data_type (deflate_state *s)
  79911. {
  79912. int n;
  79913. for (n = 0; n < 9; n++)
  79914. if (s->dyn_ltree[n].Freq != 0)
  79915. break;
  79916. if (n == 9)
  79917. for (n = 14; n < 32; n++)
  79918. if (s->dyn_ltree[n].Freq != 0)
  79919. break;
  79920. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  79921. }
  79922. local unsigned bi_reverse (unsigned code, int len)
  79923. {
  79924. register unsigned res = 0;
  79925. do {
  79926. res |= code & 1;
  79927. code >>= 1, res <<= 1;
  79928. } while (--len > 0);
  79929. return res >> 1;
  79930. }
  79931. local void bi_flush (deflate_state *s)
  79932. {
  79933. if (s->bi_valid == 16) {
  79934. put_short(s, s->bi_buf);
  79935. s->bi_buf = 0;
  79936. s->bi_valid = 0;
  79937. } else if (s->bi_valid >= 8) {
  79938. put_byte(s, (Byte)s->bi_buf);
  79939. s->bi_buf >>= 8;
  79940. s->bi_valid -= 8;
  79941. }
  79942. }
  79943. local void bi_windup (deflate_state *s)
  79944. {
  79945. if (s->bi_valid > 8) {
  79946. put_short(s, s->bi_buf);
  79947. } else if (s->bi_valid > 0) {
  79948. put_byte(s, (Byte)s->bi_buf);
  79949. }
  79950. s->bi_buf = 0;
  79951. s->bi_valid = 0;
  79952. #ifdef DEBUG
  79953. s->bits_sent = (s->bits_sent+7) & ~7;
  79954. #endif
  79955. }
  79956. local void copy_block(deflate_state *s,
  79957. charf *buf, /* the input data */
  79958. unsigned len, /* its length */
  79959. int header) /* true if block header must be written */
  79960. {
  79961. bi_windup(s); /* align on byte boundary */
  79962. s->last_eob_len = 8; /* enough lookahead for inflate */
  79963. if (header) {
  79964. put_short(s, (ush)len);
  79965. put_short(s, (ush)~len);
  79966. #ifdef DEBUG
  79967. s->bits_sent += 2*16;
  79968. #endif
  79969. }
  79970. #ifdef DEBUG
  79971. s->bits_sent += (ulg)len<<3;
  79972. #endif
  79973. while (len--) {
  79974. put_byte(s, *buf++);
  79975. }
  79976. }
  79977. /*** End of inlined file: trees.c ***/
  79978. /*** Start of inlined file: zutil.c ***/
  79979. #ifndef NO_DUMMY_DECL
  79980. struct internal_state {int dummy;}; /* for buggy compilers */
  79981. #endif
  79982. const char * const z_errmsg[10] = {
  79983. "need dictionary", /* Z_NEED_DICT 2 */
  79984. "stream end", /* Z_STREAM_END 1 */
  79985. "", /* Z_OK 0 */
  79986. "file error", /* Z_ERRNO (-1) */
  79987. "stream error", /* Z_STREAM_ERROR (-2) */
  79988. "data error", /* Z_DATA_ERROR (-3) */
  79989. "insufficient memory", /* Z_MEM_ERROR (-4) */
  79990. "buffer error", /* Z_BUF_ERROR (-5) */
  79991. "incompatible version",/* Z_VERSION_ERROR (-6) */
  79992. ""};
  79993. #ifdef DEBUG
  79994. # ifndef verbose
  79995. # define verbose 0
  79996. # endif
  79997. int z_verbose = verbose;
  79998. void z_error (const char *m)
  79999. {
  80000. fprintf(stderr, "%s\n", m);
  80001. exit(1);
  80002. }
  80003. #endif
  80004. const char * ZEXPORT zError(int err)
  80005. {
  80006. return ERR_MSG(err);
  80007. }
  80008. #if defined(_WIN32_WCE)
  80009. int errno = 0;
  80010. #endif
  80011. #ifndef HAVE_MEMCPY
  80012. void zmemcpy(dest, source, len)
  80013. Bytef* dest;
  80014. const Bytef* source;
  80015. uInt len;
  80016. {
  80017. if (len == 0) return;
  80018. do {
  80019. *dest++ = *source++; /* ??? to be unrolled */
  80020. } while (--len != 0);
  80021. }
  80022. int zmemcmp(s1, s2, len)
  80023. const Bytef* s1;
  80024. const Bytef* s2;
  80025. uInt len;
  80026. {
  80027. uInt j;
  80028. for (j = 0; j < len; j++) {
  80029. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80030. }
  80031. return 0;
  80032. }
  80033. void zmemzero(dest, len)
  80034. Bytef* dest;
  80035. uInt len;
  80036. {
  80037. if (len == 0) return;
  80038. do {
  80039. *dest++ = 0; /* ??? to be unrolled */
  80040. } while (--len != 0);
  80041. }
  80042. #endif
  80043. #ifdef SYS16BIT
  80044. #ifdef __TURBOC__
  80045. # define MY_ZCALLOC
  80046. #define MAX_PTR 10
  80047. local int next_ptr = 0;
  80048. typedef struct ptr_table_s {
  80049. voidpf org_ptr;
  80050. voidpf new_ptr;
  80051. } ptr_table;
  80052. local ptr_table table[MAX_PTR];
  80053. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80054. {
  80055. voidpf buf = opaque; /* just to make some compilers happy */
  80056. ulg bsize = (ulg)items*size;
  80057. if (bsize < 65520L) {
  80058. buf = farmalloc(bsize);
  80059. if (*(ush*)&buf != 0) return buf;
  80060. } else {
  80061. buf = farmalloc(bsize + 16L);
  80062. }
  80063. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80064. table[next_ptr].org_ptr = buf;
  80065. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80066. *(ush*)&buf = 0;
  80067. table[next_ptr++].new_ptr = buf;
  80068. return buf;
  80069. }
  80070. void zcfree (voidpf opaque, voidpf ptr)
  80071. {
  80072. int n;
  80073. if (*(ush*)&ptr != 0) { /* object < 64K */
  80074. farfree(ptr);
  80075. return;
  80076. }
  80077. for (n = 0; n < next_ptr; n++) {
  80078. if (ptr != table[n].new_ptr) continue;
  80079. farfree(table[n].org_ptr);
  80080. while (++n < next_ptr) {
  80081. table[n-1] = table[n];
  80082. }
  80083. next_ptr--;
  80084. return;
  80085. }
  80086. ptr = opaque; /* just to make some compilers happy */
  80087. Assert(0, "zcfree: ptr not found");
  80088. }
  80089. #endif /* __TURBOC__ */
  80090. #ifdef M_I86
  80091. # define MY_ZCALLOC
  80092. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80093. # define _halloc halloc
  80094. # define _hfree hfree
  80095. #endif
  80096. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80097. {
  80098. if (opaque) opaque = 0; /* to make compiler happy */
  80099. return _halloc((long)items, size);
  80100. }
  80101. void zcfree (voidpf opaque, voidpf ptr)
  80102. {
  80103. if (opaque) opaque = 0; /* to make compiler happy */
  80104. _hfree(ptr);
  80105. }
  80106. #endif /* M_I86 */
  80107. #endif /* SYS16BIT */
  80108. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80109. #ifndef STDC
  80110. extern voidp malloc OF((uInt size));
  80111. extern voidp calloc OF((uInt items, uInt size));
  80112. extern void free OF((voidpf ptr));
  80113. #endif
  80114. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80115. {
  80116. if (opaque) items += size - size; /* make compiler happy */
  80117. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80118. (voidpf)calloc(items, size);
  80119. }
  80120. void zcfree (voidpf opaque, voidpf ptr)
  80121. {
  80122. free(ptr);
  80123. if (opaque) return; /* make compiler happy */
  80124. }
  80125. #endif /* MY_ZCALLOC */
  80126. /*** End of inlined file: zutil.c ***/
  80127. #undef Byte
  80128. }
  80129. #else
  80130. #include <zlib.h>
  80131. #endif
  80132. }
  80133. #if JUCE_MSVC
  80134. #pragma warning (pop)
  80135. #endif
  80136. BEGIN_JUCE_NAMESPACE
  80137. // internal helper object that holds the zlib structures so they don't have to be
  80138. // included publicly.
  80139. class GZIPDecompressHelper
  80140. {
  80141. public:
  80142. GZIPDecompressHelper (const bool noWrap)
  80143. : finished (true),
  80144. needsDictionary (false),
  80145. error (true),
  80146. streamIsValid (false),
  80147. data (0),
  80148. dataSize (0)
  80149. {
  80150. using namespace zlibNamespace;
  80151. zerostruct (stream);
  80152. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80153. finished = error = ! streamIsValid;
  80154. }
  80155. ~GZIPDecompressHelper()
  80156. {
  80157. using namespace zlibNamespace;
  80158. if (streamIsValid)
  80159. inflateEnd (&stream);
  80160. }
  80161. bool needsInput() const throw() { return dataSize <= 0; }
  80162. void setInput (uint8* const data_, const int size) throw()
  80163. {
  80164. data = data_;
  80165. dataSize = size;
  80166. }
  80167. int doNextBlock (uint8* const dest, const int destSize)
  80168. {
  80169. using namespace zlibNamespace;
  80170. if (streamIsValid && data != 0 && ! finished)
  80171. {
  80172. stream.next_in = data;
  80173. stream.next_out = dest;
  80174. stream.avail_in = dataSize;
  80175. stream.avail_out = destSize;
  80176. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80177. {
  80178. case Z_STREAM_END:
  80179. finished = true;
  80180. // deliberate fall-through
  80181. case Z_OK:
  80182. data += dataSize - stream.avail_in;
  80183. dataSize = stream.avail_in;
  80184. return destSize - stream.avail_out;
  80185. case Z_NEED_DICT:
  80186. needsDictionary = true;
  80187. data += dataSize - stream.avail_in;
  80188. dataSize = stream.avail_in;
  80189. break;
  80190. case Z_DATA_ERROR:
  80191. case Z_MEM_ERROR:
  80192. error = true;
  80193. default:
  80194. break;
  80195. }
  80196. }
  80197. return 0;
  80198. }
  80199. bool finished, needsDictionary, error, streamIsValid;
  80200. private:
  80201. zlibNamespace::z_stream stream;
  80202. uint8* data;
  80203. int dataSize;
  80204. GZIPDecompressHelper (const GZIPDecompressHelper&);
  80205. GZIPDecompressHelper& operator= (const GZIPDecompressHelper&);
  80206. };
  80207. const int gzipDecompBufferSize = 32768;
  80208. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80209. const bool deleteSourceWhenDestroyed,
  80210. const bool noWrap_,
  80211. const int64 uncompressedStreamLength_)
  80212. : sourceStream (sourceStream_),
  80213. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80214. uncompressedStreamLength (uncompressedStreamLength_),
  80215. noWrap (noWrap_),
  80216. isEof (false),
  80217. activeBufferSize (0),
  80218. originalSourcePos (sourceStream_->getPosition()),
  80219. currentPos (0),
  80220. buffer (gzipDecompBufferSize),
  80221. helper (new GZIPDecompressHelper (noWrap_))
  80222. {
  80223. }
  80224. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80225. {
  80226. }
  80227. int64 GZIPDecompressorInputStream::getTotalLength()
  80228. {
  80229. return uncompressedStreamLength;
  80230. }
  80231. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80232. {
  80233. if ((howMany > 0) && ! isEof)
  80234. {
  80235. jassert (destBuffer != 0);
  80236. if (destBuffer != 0)
  80237. {
  80238. int numRead = 0;
  80239. uint8* d = static_cast <uint8*> (destBuffer);
  80240. while (! helper->error)
  80241. {
  80242. const int n = helper->doNextBlock (d, howMany);
  80243. currentPos += n;
  80244. if (n == 0)
  80245. {
  80246. if (helper->finished || helper->needsDictionary)
  80247. {
  80248. isEof = true;
  80249. return numRead;
  80250. }
  80251. if (helper->needsInput())
  80252. {
  80253. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80254. if (activeBufferSize > 0)
  80255. {
  80256. helper->setInput (buffer, activeBufferSize);
  80257. }
  80258. else
  80259. {
  80260. isEof = true;
  80261. return numRead;
  80262. }
  80263. }
  80264. }
  80265. else
  80266. {
  80267. numRead += n;
  80268. howMany -= n;
  80269. d += n;
  80270. if (howMany <= 0)
  80271. return numRead;
  80272. }
  80273. }
  80274. }
  80275. }
  80276. return 0;
  80277. }
  80278. bool GZIPDecompressorInputStream::isExhausted()
  80279. {
  80280. return helper->error || isEof;
  80281. }
  80282. int64 GZIPDecompressorInputStream::getPosition()
  80283. {
  80284. return currentPos;
  80285. }
  80286. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80287. {
  80288. if (newPos < currentPos)
  80289. {
  80290. // to go backwards, reset the stream and start again..
  80291. isEof = false;
  80292. activeBufferSize = 0;
  80293. currentPos = 0;
  80294. helper = new GZIPDecompressHelper (noWrap);
  80295. sourceStream->setPosition (originalSourcePos);
  80296. }
  80297. skipNextBytes (newPos - currentPos);
  80298. return true;
  80299. }
  80300. END_JUCE_NAMESPACE
  80301. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80302. #endif
  80303. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80304. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80305. #if JUCE_USE_FLAC
  80306. #if JUCE_WINDOWS
  80307. #include <windows.h>
  80308. #endif
  80309. #ifdef _MSC_VER
  80310. #pragma warning (disable : 4505)
  80311. #pragma warning (push)
  80312. #endif
  80313. namespace FlacNamespace
  80314. {
  80315. #if JUCE_INCLUDE_FLAC_CODE
  80316. #define FLAC__NO_DLL 1
  80317. #if ! defined (SIZE_MAX)
  80318. #define SIZE_MAX 0xffffffff
  80319. #endif
  80320. #define __STDC_LIMIT_MACROS 1
  80321. /*** Start of inlined file: all.h ***/
  80322. #ifndef FLAC__ALL_H
  80323. #define FLAC__ALL_H
  80324. /*** Start of inlined file: export.h ***/
  80325. #ifndef FLAC__EXPORT_H
  80326. #define FLAC__EXPORT_H
  80327. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80328. #define FLAC_API
  80329. #else
  80330. #ifdef FLAC_API_EXPORTS
  80331. #define FLAC_API _declspec(dllexport)
  80332. #else
  80333. #define FLAC_API _declspec(dllimport)
  80334. #endif
  80335. #endif
  80336. #define FLAC_API_VERSION_CURRENT 10
  80337. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80338. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80339. #ifdef __cplusplus
  80340. extern "C" {
  80341. #endif
  80342. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80343. #ifdef __cplusplus
  80344. }
  80345. #endif
  80346. #endif
  80347. /*** End of inlined file: export.h ***/
  80348. /*** Start of inlined file: assert.h ***/
  80349. #ifndef FLAC__ASSERT_H
  80350. #define FLAC__ASSERT_H
  80351. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80352. #ifdef DEBUG
  80353. #include <assert.h>
  80354. #define FLAC__ASSERT(x) assert(x)
  80355. #define FLAC__ASSERT_DECLARATION(x) x
  80356. #else
  80357. #define FLAC__ASSERT(x)
  80358. #define FLAC__ASSERT_DECLARATION(x)
  80359. #endif
  80360. #endif
  80361. /*** End of inlined file: assert.h ***/
  80362. /*** Start of inlined file: callback.h ***/
  80363. #ifndef FLAC__CALLBACK_H
  80364. #define FLAC__CALLBACK_H
  80365. /*** Start of inlined file: ordinals.h ***/
  80366. #ifndef FLAC__ORDINALS_H
  80367. #define FLAC__ORDINALS_H
  80368. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80369. #include <inttypes.h>
  80370. #endif
  80371. typedef signed char FLAC__int8;
  80372. typedef unsigned char FLAC__uint8;
  80373. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80374. typedef __int16 FLAC__int16;
  80375. typedef __int32 FLAC__int32;
  80376. typedef __int64 FLAC__int64;
  80377. typedef unsigned __int16 FLAC__uint16;
  80378. typedef unsigned __int32 FLAC__uint32;
  80379. typedef unsigned __int64 FLAC__uint64;
  80380. #elif defined(__EMX__)
  80381. typedef short FLAC__int16;
  80382. typedef long FLAC__int32;
  80383. typedef long long FLAC__int64;
  80384. typedef unsigned short FLAC__uint16;
  80385. typedef unsigned long FLAC__uint32;
  80386. typedef unsigned long long FLAC__uint64;
  80387. #else
  80388. typedef int16_t FLAC__int16;
  80389. typedef int32_t FLAC__int32;
  80390. typedef int64_t FLAC__int64;
  80391. typedef uint16_t FLAC__uint16;
  80392. typedef uint32_t FLAC__uint32;
  80393. typedef uint64_t FLAC__uint64;
  80394. #endif
  80395. typedef int FLAC__bool;
  80396. typedef FLAC__uint8 FLAC__byte;
  80397. #ifdef true
  80398. #undef true
  80399. #endif
  80400. #ifdef false
  80401. #undef false
  80402. #endif
  80403. #ifndef __cplusplus
  80404. #define true 1
  80405. #define false 0
  80406. #endif
  80407. #endif
  80408. /*** End of inlined file: ordinals.h ***/
  80409. #include <stdlib.h> /* for size_t */
  80410. #ifdef __cplusplus
  80411. extern "C" {
  80412. #endif
  80413. typedef void* FLAC__IOHandle;
  80414. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80415. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80416. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80417. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80418. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80419. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80420. typedef struct {
  80421. FLAC__IOCallback_Read read;
  80422. FLAC__IOCallback_Write write;
  80423. FLAC__IOCallback_Seek seek;
  80424. FLAC__IOCallback_Tell tell;
  80425. FLAC__IOCallback_Eof eof;
  80426. FLAC__IOCallback_Close close;
  80427. } FLAC__IOCallbacks;
  80428. #ifdef __cplusplus
  80429. }
  80430. #endif
  80431. #endif
  80432. /*** End of inlined file: callback.h ***/
  80433. /*** Start of inlined file: format.h ***/
  80434. #ifndef FLAC__FORMAT_H
  80435. #define FLAC__FORMAT_H
  80436. #ifdef __cplusplus
  80437. extern "C" {
  80438. #endif
  80439. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80440. #define FLAC__MIN_BLOCK_SIZE (16u)
  80441. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80442. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80443. #define FLAC__MAX_CHANNELS (8u)
  80444. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80445. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80446. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80447. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80448. #define FLAC__MAX_LPC_ORDER (32u)
  80449. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80450. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80451. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80452. #define FLAC__MAX_FIXED_ORDER (4u)
  80453. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80454. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80455. extern FLAC_API const char *FLAC__VERSION_STRING;
  80456. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80457. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80458. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80459. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80460. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80461. typedef enum {
  80462. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80463. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80464. } FLAC__EntropyCodingMethodType;
  80465. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80466. typedef struct {
  80467. unsigned *parameters;
  80468. unsigned *raw_bits;
  80469. unsigned capacity_by_order;
  80470. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80471. typedef struct {
  80472. unsigned order;
  80473. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80474. } FLAC__EntropyCodingMethod_PartitionedRice;
  80475. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80476. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80477. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80478. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80479. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80480. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80481. typedef struct {
  80482. FLAC__EntropyCodingMethodType type;
  80483. union {
  80484. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80485. } data;
  80486. } FLAC__EntropyCodingMethod;
  80487. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80488. typedef enum {
  80489. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80490. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80491. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80492. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80493. } FLAC__SubframeType;
  80494. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80495. typedef struct {
  80496. FLAC__int32 value; /**< The constant signal value. */
  80497. } FLAC__Subframe_Constant;
  80498. typedef struct {
  80499. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  80500. } FLAC__Subframe_Verbatim;
  80501. typedef struct {
  80502. FLAC__EntropyCodingMethod entropy_coding_method;
  80503. unsigned order;
  80504. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  80505. const FLAC__int32 *residual;
  80506. } FLAC__Subframe_Fixed;
  80507. typedef struct {
  80508. FLAC__EntropyCodingMethod entropy_coding_method;
  80509. unsigned order;
  80510. unsigned qlp_coeff_precision;
  80511. int quantization_level;
  80512. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  80513. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  80514. const FLAC__int32 *residual;
  80515. } FLAC__Subframe_LPC;
  80516. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  80517. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  80518. typedef struct {
  80519. FLAC__SubframeType type;
  80520. union {
  80521. FLAC__Subframe_Constant constant;
  80522. FLAC__Subframe_Fixed fixed;
  80523. FLAC__Subframe_LPC lpc;
  80524. FLAC__Subframe_Verbatim verbatim;
  80525. } data;
  80526. unsigned wasted_bits;
  80527. } FLAC__Subframe;
  80528. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  80529. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  80530. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  80531. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  80532. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  80533. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  80534. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  80535. typedef enum {
  80536. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  80537. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  80538. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  80539. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  80540. } FLAC__ChannelAssignment;
  80541. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  80542. typedef enum {
  80543. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  80544. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  80545. } FLAC__FrameNumberType;
  80546. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  80547. typedef struct {
  80548. unsigned blocksize;
  80549. unsigned sample_rate;
  80550. unsigned channels;
  80551. FLAC__ChannelAssignment channel_assignment;
  80552. unsigned bits_per_sample;
  80553. FLAC__FrameNumberType number_type;
  80554. union {
  80555. FLAC__uint32 frame_number;
  80556. FLAC__uint64 sample_number;
  80557. } number;
  80558. FLAC__uint8 crc;
  80559. } FLAC__FrameHeader;
  80560. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  80561. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  80562. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  80563. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  80564. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  80565. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  80566. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  80567. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  80568. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  80569. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  80570. typedef struct {
  80571. FLAC__uint16 crc;
  80572. } FLAC__FrameFooter;
  80573. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  80574. typedef struct {
  80575. FLAC__FrameHeader header;
  80576. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  80577. FLAC__FrameFooter footer;
  80578. } FLAC__Frame;
  80579. typedef enum {
  80580. FLAC__METADATA_TYPE_STREAMINFO = 0,
  80581. FLAC__METADATA_TYPE_PADDING = 1,
  80582. FLAC__METADATA_TYPE_APPLICATION = 2,
  80583. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  80584. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  80585. FLAC__METADATA_TYPE_CUESHEET = 5,
  80586. FLAC__METADATA_TYPE_PICTURE = 6,
  80587. FLAC__METADATA_TYPE_UNDEFINED = 7
  80588. } FLAC__MetadataType;
  80589. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  80590. typedef struct {
  80591. unsigned min_blocksize, max_blocksize;
  80592. unsigned min_framesize, max_framesize;
  80593. unsigned sample_rate;
  80594. unsigned channels;
  80595. unsigned bits_per_sample;
  80596. FLAC__uint64 total_samples;
  80597. FLAC__byte md5sum[16];
  80598. } FLAC__StreamMetadata_StreamInfo;
  80599. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80600. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  80601. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80602. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  80603. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  80604. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  80605. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  80606. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  80607. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  80608. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  80609. typedef struct {
  80610. int dummy;
  80611. } FLAC__StreamMetadata_Padding;
  80612. typedef struct {
  80613. FLAC__byte id[4];
  80614. FLAC__byte *data;
  80615. } FLAC__StreamMetadata_Application;
  80616. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  80617. typedef struct {
  80618. FLAC__uint64 sample_number;
  80619. FLAC__uint64 stream_offset;
  80620. unsigned frame_samples;
  80621. } FLAC__StreamMetadata_SeekPoint;
  80622. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  80623. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  80624. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  80625. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  80626. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  80627. typedef struct {
  80628. unsigned num_points;
  80629. FLAC__StreamMetadata_SeekPoint *points;
  80630. } FLAC__StreamMetadata_SeekTable;
  80631. typedef struct {
  80632. FLAC__uint32 length;
  80633. FLAC__byte *entry;
  80634. } FLAC__StreamMetadata_VorbisComment_Entry;
  80635. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  80636. typedef struct {
  80637. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  80638. FLAC__uint32 num_comments;
  80639. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  80640. } FLAC__StreamMetadata_VorbisComment;
  80641. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  80642. typedef struct {
  80643. FLAC__uint64 offset;
  80644. FLAC__byte number;
  80645. } FLAC__StreamMetadata_CueSheet_Index;
  80646. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  80647. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  80648. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  80649. typedef struct {
  80650. FLAC__uint64 offset;
  80651. FLAC__byte number;
  80652. char isrc[13];
  80653. unsigned type:1;
  80654. unsigned pre_emphasis:1;
  80655. FLAC__byte num_indices;
  80656. FLAC__StreamMetadata_CueSheet_Index *indices;
  80657. } FLAC__StreamMetadata_CueSheet_Track;
  80658. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  80659. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  80660. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  80661. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  80662. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  80663. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  80664. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  80665. typedef struct {
  80666. char media_catalog_number[129];
  80667. FLAC__uint64 lead_in;
  80668. FLAC__bool is_cd;
  80669. unsigned num_tracks;
  80670. FLAC__StreamMetadata_CueSheet_Track *tracks;
  80671. } FLAC__StreamMetadata_CueSheet;
  80672. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  80673. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  80674. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  80675. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  80676. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  80677. typedef enum {
  80678. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  80679. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  80680. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  80681. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  80682. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  80683. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  80684. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  80685. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  80686. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  80687. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  80688. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  80689. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  80690. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  80691. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  80692. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  80693. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  80694. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  80695. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  80696. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  80697. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  80698. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  80699. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  80700. } FLAC__StreamMetadata_Picture_Type;
  80701. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  80702. typedef struct {
  80703. FLAC__StreamMetadata_Picture_Type type;
  80704. char *mime_type;
  80705. FLAC__byte *description;
  80706. FLAC__uint32 width;
  80707. FLAC__uint32 height;
  80708. FLAC__uint32 depth;
  80709. FLAC__uint32 colors;
  80710. FLAC__uint32 data_length;
  80711. FLAC__byte *data;
  80712. } FLAC__StreamMetadata_Picture;
  80713. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  80714. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  80715. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  80716. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  80717. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  80718. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  80719. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  80720. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  80721. typedef struct {
  80722. FLAC__byte *data;
  80723. } FLAC__StreamMetadata_Unknown;
  80724. typedef struct {
  80725. FLAC__MetadataType type;
  80726. FLAC__bool is_last;
  80727. unsigned length;
  80728. union {
  80729. FLAC__StreamMetadata_StreamInfo stream_info;
  80730. FLAC__StreamMetadata_Padding padding;
  80731. FLAC__StreamMetadata_Application application;
  80732. FLAC__StreamMetadata_SeekTable seek_table;
  80733. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  80734. FLAC__StreamMetadata_CueSheet cue_sheet;
  80735. FLAC__StreamMetadata_Picture picture;
  80736. FLAC__StreamMetadata_Unknown unknown;
  80737. } data;
  80738. } FLAC__StreamMetadata;
  80739. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  80740. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  80741. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  80742. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  80743. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  80744. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  80745. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  80746. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  80747. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  80748. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  80749. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  80750. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  80751. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  80752. #ifdef __cplusplus
  80753. }
  80754. #endif
  80755. #endif
  80756. /*** End of inlined file: format.h ***/
  80757. /*** Start of inlined file: metadata.h ***/
  80758. #ifndef FLAC__METADATA_H
  80759. #define FLAC__METADATA_H
  80760. #include <sys/types.h> /* for off_t */
  80761. #ifdef __cplusplus
  80762. extern "C" {
  80763. #endif
  80764. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  80765. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  80766. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  80767. 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);
  80768. struct FLAC__Metadata_SimpleIterator;
  80769. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  80770. typedef enum {
  80771. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  80772. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  80773. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  80774. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  80775. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  80776. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  80777. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  80778. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  80779. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  80780. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  80781. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  80782. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  80783. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  80784. } FLAC__Metadata_SimpleIteratorStatus;
  80785. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  80786. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  80787. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  80788. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  80789. 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);
  80790. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  80791. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  80792. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  80793. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  80794. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  80795. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  80796. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  80797. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  80798. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  80799. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80800. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  80801. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  80802. struct FLAC__Metadata_Chain;
  80803. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  80804. struct FLAC__Metadata_Iterator;
  80805. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  80806. typedef enum {
  80807. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  80808. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  80809. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  80810. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  80811. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  80812. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  80813. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  80814. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  80815. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  80816. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  80817. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  80818. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  80819. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  80820. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  80821. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  80822. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  80823. } FLAC__Metadata_ChainStatus;
  80824. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  80825. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  80826. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  80827. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  80828. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  80829. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  80830. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80831. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80832. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  80833. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  80834. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  80835. 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);
  80836. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  80837. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  80838. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  80839. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  80840. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  80841. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  80842. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  80843. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  80844. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  80845. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80846. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  80847. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80848. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  80849. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  80850. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  80851. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  80852. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  80853. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  80854. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  80855. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80856. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  80857. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  80858. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  80859. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  80860. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  80861. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  80862. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  80863. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  80864. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  80865. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80866. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  80867. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80868. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80869. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  80870. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  80871. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  80872. 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);
  80873. 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);
  80874. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  80875. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  80876. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  80877. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  80878. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  80879. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  80880. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  80881. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  80882. 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);
  80883. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80884. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  80885. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  80886. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80887. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  80888. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  80889. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  80890. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  80891. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  80892. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  80893. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  80894. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  80895. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  80896. #ifdef __cplusplus
  80897. }
  80898. #endif
  80899. #endif
  80900. /*** End of inlined file: metadata.h ***/
  80901. /*** Start of inlined file: stream_decoder.h ***/
  80902. #ifndef FLAC__STREAM_DECODER_H
  80903. #define FLAC__STREAM_DECODER_H
  80904. #include <stdio.h> /* for FILE */
  80905. #ifdef __cplusplus
  80906. extern "C" {
  80907. #endif
  80908. typedef enum {
  80909. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  80910. FLAC__STREAM_DECODER_READ_METADATA,
  80911. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  80912. FLAC__STREAM_DECODER_READ_FRAME,
  80913. FLAC__STREAM_DECODER_END_OF_STREAM,
  80914. FLAC__STREAM_DECODER_OGG_ERROR,
  80915. FLAC__STREAM_DECODER_SEEK_ERROR,
  80916. FLAC__STREAM_DECODER_ABORTED,
  80917. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  80918. FLAC__STREAM_DECODER_UNINITIALIZED
  80919. } FLAC__StreamDecoderState;
  80920. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  80921. typedef enum {
  80922. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  80923. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  80924. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  80925. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  80926. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  80927. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  80928. } FLAC__StreamDecoderInitStatus;
  80929. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  80930. typedef enum {
  80931. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  80932. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  80933. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  80934. } FLAC__StreamDecoderReadStatus;
  80935. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  80936. typedef enum {
  80937. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  80938. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  80939. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  80940. } FLAC__StreamDecoderSeekStatus;
  80941. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  80942. typedef enum {
  80943. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  80944. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  80945. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  80946. } FLAC__StreamDecoderTellStatus;
  80947. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  80948. typedef enum {
  80949. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  80950. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  80951. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  80952. } FLAC__StreamDecoderLengthStatus;
  80953. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  80954. typedef enum {
  80955. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  80956. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  80957. } FLAC__StreamDecoderWriteStatus;
  80958. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  80959. typedef enum {
  80960. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  80961. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  80962. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  80963. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  80964. } FLAC__StreamDecoderErrorStatus;
  80965. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  80966. struct FLAC__StreamDecoderProtected;
  80967. struct FLAC__StreamDecoderPrivate;
  80968. typedef struct {
  80969. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  80970. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  80971. } FLAC__StreamDecoder;
  80972. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  80973. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  80974. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  80975. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  80976. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  80977. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  80978. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  80979. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  80980. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  80981. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  80982. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  80983. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  80984. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  80985. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  80986. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  80987. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  80988. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  80989. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  80990. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  80991. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  80992. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  80993. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  80994. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  80995. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  80996. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  80997. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  80998. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  80999. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81000. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81001. FLAC__StreamDecoder *decoder,
  81002. FLAC__StreamDecoderReadCallback read_callback,
  81003. FLAC__StreamDecoderSeekCallback seek_callback,
  81004. FLAC__StreamDecoderTellCallback tell_callback,
  81005. FLAC__StreamDecoderLengthCallback length_callback,
  81006. FLAC__StreamDecoderEofCallback eof_callback,
  81007. FLAC__StreamDecoderWriteCallback write_callback,
  81008. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81009. FLAC__StreamDecoderErrorCallback error_callback,
  81010. void *client_data
  81011. );
  81012. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81013. FLAC__StreamDecoder *decoder,
  81014. FLAC__StreamDecoderReadCallback read_callback,
  81015. FLAC__StreamDecoderSeekCallback seek_callback,
  81016. FLAC__StreamDecoderTellCallback tell_callback,
  81017. FLAC__StreamDecoderLengthCallback length_callback,
  81018. FLAC__StreamDecoderEofCallback eof_callback,
  81019. FLAC__StreamDecoderWriteCallback write_callback,
  81020. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81021. FLAC__StreamDecoderErrorCallback error_callback,
  81022. void *client_data
  81023. );
  81024. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81025. FLAC__StreamDecoder *decoder,
  81026. FILE *file,
  81027. FLAC__StreamDecoderWriteCallback write_callback,
  81028. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81029. FLAC__StreamDecoderErrorCallback error_callback,
  81030. void *client_data
  81031. );
  81032. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81033. FLAC__StreamDecoder *decoder,
  81034. FILE *file,
  81035. FLAC__StreamDecoderWriteCallback write_callback,
  81036. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81037. FLAC__StreamDecoderErrorCallback error_callback,
  81038. void *client_data
  81039. );
  81040. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81041. FLAC__StreamDecoder *decoder,
  81042. const char *filename,
  81043. FLAC__StreamDecoderWriteCallback write_callback,
  81044. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81045. FLAC__StreamDecoderErrorCallback error_callback,
  81046. void *client_data
  81047. );
  81048. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81049. FLAC__StreamDecoder *decoder,
  81050. const char *filename,
  81051. FLAC__StreamDecoderWriteCallback write_callback,
  81052. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81053. FLAC__StreamDecoderErrorCallback error_callback,
  81054. void *client_data
  81055. );
  81056. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81057. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81058. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81059. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81060. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81061. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81062. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81063. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81064. #ifdef __cplusplus
  81065. }
  81066. #endif
  81067. #endif
  81068. /*** End of inlined file: stream_decoder.h ***/
  81069. /*** Start of inlined file: stream_encoder.h ***/
  81070. #ifndef FLAC__STREAM_ENCODER_H
  81071. #define FLAC__STREAM_ENCODER_H
  81072. #include <stdio.h> /* for FILE */
  81073. #ifdef __cplusplus
  81074. extern "C" {
  81075. #endif
  81076. typedef enum {
  81077. FLAC__STREAM_ENCODER_OK = 0,
  81078. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81079. FLAC__STREAM_ENCODER_OGG_ERROR,
  81080. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81081. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81082. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81083. FLAC__STREAM_ENCODER_IO_ERROR,
  81084. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81085. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81086. } FLAC__StreamEncoderState;
  81087. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81088. typedef enum {
  81089. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81090. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81091. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81092. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81093. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81094. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81095. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81096. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81097. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81098. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81099. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81100. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81101. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81102. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81103. } FLAC__StreamEncoderInitStatus;
  81104. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81105. typedef enum {
  81106. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81107. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81108. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81109. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81110. } FLAC__StreamEncoderReadStatus;
  81111. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81112. typedef enum {
  81113. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81114. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81115. } FLAC__StreamEncoderWriteStatus;
  81116. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81117. typedef enum {
  81118. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81119. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81120. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81121. } FLAC__StreamEncoderSeekStatus;
  81122. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81123. typedef enum {
  81124. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81125. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81126. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81127. } FLAC__StreamEncoderTellStatus;
  81128. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81129. struct FLAC__StreamEncoderProtected;
  81130. struct FLAC__StreamEncoderPrivate;
  81131. typedef struct {
  81132. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81133. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81134. } FLAC__StreamEncoder;
  81135. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81136. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81137. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81138. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81139. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81140. 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);
  81141. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81142. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81143. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81144. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81145. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81146. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81147. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81148. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81149. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81150. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81151. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81152. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81153. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81154. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81155. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81156. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81157. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81158. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81159. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81160. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81161. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81162. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81163. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81164. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81165. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81166. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81167. 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);
  81168. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81169. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81170. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81171. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81172. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81173. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81174. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81175. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81176. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81177. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81178. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81179. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81180. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81181. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81182. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81183. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81184. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81185. 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);
  81186. 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);
  81187. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81188. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81189. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81190. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81191. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81192. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81193. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81194. #ifdef __cplusplus
  81195. }
  81196. #endif
  81197. #endif
  81198. /*** End of inlined file: stream_encoder.h ***/
  81199. #ifdef _MSC_VER
  81200. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81201. {
  81202. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81203. return (x>>16) | (x<<16);
  81204. }
  81205. #endif
  81206. #if defined(_MSC_VER) && defined(_X86_)
  81207. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81208. {
  81209. __asm {
  81210. mov edx, start
  81211. mov ecx, len
  81212. test ecx, ecx
  81213. loop1:
  81214. jz done1
  81215. mov eax, [edx]
  81216. bswap eax
  81217. mov [edx], eax
  81218. add edx, 4
  81219. dec ecx
  81220. jmp short loop1
  81221. done1:
  81222. }
  81223. }
  81224. #endif
  81225. #endif
  81226. /*** End of inlined file: all.h ***/
  81227. /*** Start of inlined file: bitmath.c ***/
  81228. /*** Start of inlined file: juce_FlacHeader.h ***/
  81229. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81230. // tasks..
  81231. #define VERSION "1.2.1"
  81232. #define FLAC__NO_DLL 1
  81233. #if JUCE_MSVC
  81234. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81235. #endif
  81236. #if JUCE_MAC
  81237. #define FLAC__SYS_DARWIN 1
  81238. #endif
  81239. /*** End of inlined file: juce_FlacHeader.h ***/
  81240. #if JUCE_USE_FLAC
  81241. #if HAVE_CONFIG_H
  81242. # include <config.h>
  81243. #endif
  81244. /*** Start of inlined file: bitmath.h ***/
  81245. #ifndef FLAC__PRIVATE__BITMATH_H
  81246. #define FLAC__PRIVATE__BITMATH_H
  81247. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81248. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81249. unsigned FLAC__bitmath_silog2(int v);
  81250. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81251. #endif
  81252. /*** End of inlined file: bitmath.h ***/
  81253. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81254. {
  81255. unsigned l = 0;
  81256. FLAC__ASSERT(v > 0);
  81257. while(v >>= 1)
  81258. l++;
  81259. return l;
  81260. }
  81261. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81262. {
  81263. unsigned l = 0;
  81264. FLAC__ASSERT(v > 0);
  81265. while(v >>= 1)
  81266. l++;
  81267. return l;
  81268. }
  81269. unsigned FLAC__bitmath_silog2(int v)
  81270. {
  81271. while(1) {
  81272. if(v == 0) {
  81273. return 0;
  81274. }
  81275. else if(v > 0) {
  81276. unsigned l = 0;
  81277. while(v) {
  81278. l++;
  81279. v >>= 1;
  81280. }
  81281. return l+1;
  81282. }
  81283. else if(v == -1) {
  81284. return 2;
  81285. }
  81286. else {
  81287. v++;
  81288. v = -v;
  81289. }
  81290. }
  81291. }
  81292. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81293. {
  81294. while(1) {
  81295. if(v == 0) {
  81296. return 0;
  81297. }
  81298. else if(v > 0) {
  81299. unsigned l = 0;
  81300. while(v) {
  81301. l++;
  81302. v >>= 1;
  81303. }
  81304. return l+1;
  81305. }
  81306. else if(v == -1) {
  81307. return 2;
  81308. }
  81309. else {
  81310. v++;
  81311. v = -v;
  81312. }
  81313. }
  81314. }
  81315. #endif
  81316. /*** End of inlined file: bitmath.c ***/
  81317. /*** Start of inlined file: bitreader.c ***/
  81318. /*** Start of inlined file: juce_FlacHeader.h ***/
  81319. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81320. // tasks..
  81321. #define VERSION "1.2.1"
  81322. #define FLAC__NO_DLL 1
  81323. #if JUCE_MSVC
  81324. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81325. #endif
  81326. #if JUCE_MAC
  81327. #define FLAC__SYS_DARWIN 1
  81328. #endif
  81329. /*** End of inlined file: juce_FlacHeader.h ***/
  81330. #if JUCE_USE_FLAC
  81331. #if HAVE_CONFIG_H
  81332. # include <config.h>
  81333. #endif
  81334. #include <stdlib.h> /* for malloc() */
  81335. #include <string.h> /* for memcpy(), memset() */
  81336. #ifdef _MSC_VER
  81337. #include <winsock.h> /* for ntohl() */
  81338. #elif defined FLAC__SYS_DARWIN
  81339. #include <machine/endian.h> /* for ntohl() */
  81340. #elif defined __MINGW32__
  81341. #include <winsock.h> /* for ntohl() */
  81342. #else
  81343. #include <netinet/in.h> /* for ntohl() */
  81344. #endif
  81345. /*** Start of inlined file: bitreader.h ***/
  81346. #ifndef FLAC__PRIVATE__BITREADER_H
  81347. #define FLAC__PRIVATE__BITREADER_H
  81348. #include <stdio.h> /* for FILE */
  81349. /*** Start of inlined file: cpu.h ***/
  81350. #ifndef FLAC__PRIVATE__CPU_H
  81351. #define FLAC__PRIVATE__CPU_H
  81352. #ifdef HAVE_CONFIG_H
  81353. #include <config.h>
  81354. #endif
  81355. typedef enum {
  81356. FLAC__CPUINFO_TYPE_IA32,
  81357. FLAC__CPUINFO_TYPE_PPC,
  81358. FLAC__CPUINFO_TYPE_UNKNOWN
  81359. } FLAC__CPUInfo_Type;
  81360. typedef struct {
  81361. FLAC__bool cpuid;
  81362. FLAC__bool bswap;
  81363. FLAC__bool cmov;
  81364. FLAC__bool mmx;
  81365. FLAC__bool fxsr;
  81366. FLAC__bool sse;
  81367. FLAC__bool sse2;
  81368. FLAC__bool sse3;
  81369. FLAC__bool ssse3;
  81370. FLAC__bool _3dnow;
  81371. FLAC__bool ext3dnow;
  81372. FLAC__bool extmmx;
  81373. } FLAC__CPUInfo_IA32;
  81374. typedef struct {
  81375. FLAC__bool altivec;
  81376. FLAC__bool ppc64;
  81377. } FLAC__CPUInfo_PPC;
  81378. typedef struct {
  81379. FLAC__bool use_asm;
  81380. FLAC__CPUInfo_Type type;
  81381. union {
  81382. FLAC__CPUInfo_IA32 ia32;
  81383. FLAC__CPUInfo_PPC ppc;
  81384. } data;
  81385. } FLAC__CPUInfo;
  81386. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81387. #ifndef FLAC__NO_ASM
  81388. #ifdef FLAC__CPU_IA32
  81389. #ifdef FLAC__HAS_NASM
  81390. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81391. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81392. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81393. #endif
  81394. #endif
  81395. #endif
  81396. #endif
  81397. /*** End of inlined file: cpu.h ***/
  81398. struct FLAC__BitReader;
  81399. typedef struct FLAC__BitReader FLAC__BitReader;
  81400. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81401. FLAC__BitReader *FLAC__bitreader_new(void);
  81402. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81403. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81404. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81405. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81406. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81407. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81408. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81409. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81410. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81411. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81412. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81413. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81414. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81415. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81416. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81417. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81418. 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! */
  81419. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81420. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81421. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81422. #ifndef FLAC__NO_ASM
  81423. # ifdef FLAC__CPU_IA32
  81424. # ifdef FLAC__HAS_NASM
  81425. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81426. # endif
  81427. # endif
  81428. #endif
  81429. #if 0 /* UNUSED */
  81430. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81431. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81432. #endif
  81433. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81434. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81435. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81436. #endif
  81437. /*** End of inlined file: bitreader.h ***/
  81438. /*** Start of inlined file: crc.h ***/
  81439. #ifndef FLAC__PRIVATE__CRC_H
  81440. #define FLAC__PRIVATE__CRC_H
  81441. extern FLAC__byte const FLAC__crc8_table[256];
  81442. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81443. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81444. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81445. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81446. extern unsigned FLAC__crc16_table[256];
  81447. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81448. #if 0
  81449. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81450. #endif
  81451. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81452. #endif
  81453. /*** End of inlined file: crc.h ***/
  81454. typedef FLAC__uint32 brword;
  81455. #define FLAC__BYTES_PER_WORD 4
  81456. #define FLAC__BITS_PER_WORD 32
  81457. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81458. #if WORDS_BIGENDIAN
  81459. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81460. #else
  81461. #if defined (_MSC_VER) && defined (_X86_)
  81462. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81463. #else
  81464. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81465. #endif
  81466. #endif
  81467. #define COUNT_ZERO_MSBS(word) ( \
  81468. (word) <= 0xffff ? \
  81469. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81470. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81471. )
  81472. #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])) )
  81473. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81474. static const unsigned char byte_to_unary_table[] = {
  81475. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81476. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81477. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81478. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81479. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81480. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81481. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81482. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81491. };
  81492. #ifdef min
  81493. #undef min
  81494. #endif
  81495. #define min(x,y) ((x)<(y)?(x):(y))
  81496. #ifdef max
  81497. #undef max
  81498. #endif
  81499. #define max(x,y) ((x)>(y)?(x):(y))
  81500. #ifdef _MSC_VER
  81501. #define FLAC__U64L(x) x
  81502. #else
  81503. #define FLAC__U64L(x) x##LLU
  81504. #endif
  81505. #ifndef FLaC__INLINE
  81506. #define FLaC__INLINE
  81507. #endif
  81508. struct FLAC__BitReader {
  81509. brword *buffer;
  81510. unsigned capacity; /* in words */
  81511. unsigned words; /* # of completed words in buffer */
  81512. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  81513. unsigned consumed_words; /* #words ... */
  81514. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  81515. unsigned read_crc16; /* the running frame CRC */
  81516. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  81517. FLAC__BitReaderReadCallback read_callback;
  81518. void *client_data;
  81519. FLAC__CPUInfo cpu_info;
  81520. };
  81521. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  81522. {
  81523. register unsigned crc = br->read_crc16;
  81524. #if FLAC__BYTES_PER_WORD == 4
  81525. switch(br->crc16_align) {
  81526. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  81527. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81528. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81529. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81530. }
  81531. #elif FLAC__BYTES_PER_WORD == 8
  81532. switch(br->crc16_align) {
  81533. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  81534. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  81535. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  81536. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  81537. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  81538. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  81539. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  81540. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  81541. }
  81542. #else
  81543. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  81544. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  81545. br->read_crc16 = crc;
  81546. #endif
  81547. br->crc16_align = 0;
  81548. }
  81549. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  81550. {
  81551. unsigned start, end;
  81552. size_t bytes;
  81553. FLAC__byte *target;
  81554. if(br->consumed_words > 0) {
  81555. start = br->consumed_words;
  81556. end = br->words + (br->bytes? 1:0);
  81557. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  81558. br->words -= start;
  81559. br->consumed_words = 0;
  81560. }
  81561. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  81562. if(bytes == 0)
  81563. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  81564. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  81565. #if WORDS_BIGENDIAN
  81566. #else
  81567. if(br->bytes)
  81568. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  81569. #endif
  81570. if(!br->read_callback(target, &bytes, br->client_data))
  81571. return false;
  81572. #if WORDS_BIGENDIAN
  81573. #else
  81574. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  81575. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  81576. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  81577. start = br->words;
  81578. local_swap32_block_(br->buffer + start, end - start);
  81579. }
  81580. else
  81581. # endif
  81582. for(start = br->words; start < end; start++)
  81583. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  81584. #endif
  81585. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  81586. br->words = end / FLAC__BYTES_PER_WORD;
  81587. br->bytes = end % FLAC__BYTES_PER_WORD;
  81588. return true;
  81589. }
  81590. FLAC__BitReader *FLAC__bitreader_new(void)
  81591. {
  81592. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  81593. return br;
  81594. }
  81595. void FLAC__bitreader_delete(FLAC__BitReader *br)
  81596. {
  81597. FLAC__ASSERT(0 != br);
  81598. FLAC__bitreader_free(br);
  81599. free(br);
  81600. }
  81601. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  81602. {
  81603. FLAC__ASSERT(0 != br);
  81604. br->words = br->bytes = 0;
  81605. br->consumed_words = br->consumed_bits = 0;
  81606. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  81607. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  81608. if(br->buffer == 0)
  81609. return false;
  81610. br->read_callback = rcb;
  81611. br->client_data = cd;
  81612. br->cpu_info = cpu;
  81613. return true;
  81614. }
  81615. void FLAC__bitreader_free(FLAC__BitReader *br)
  81616. {
  81617. FLAC__ASSERT(0 != br);
  81618. if(0 != br->buffer)
  81619. free(br->buffer);
  81620. br->buffer = 0;
  81621. br->capacity = 0;
  81622. br->words = br->bytes = 0;
  81623. br->consumed_words = br->consumed_bits = 0;
  81624. br->read_callback = 0;
  81625. br->client_data = 0;
  81626. }
  81627. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  81628. {
  81629. br->words = br->bytes = 0;
  81630. br->consumed_words = br->consumed_bits = 0;
  81631. return true;
  81632. }
  81633. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  81634. {
  81635. unsigned i, j;
  81636. if(br == 0) {
  81637. fprintf(out, "bitreader is NULL\n");
  81638. }
  81639. else {
  81640. 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);
  81641. for(i = 0; i < br->words; i++) {
  81642. fprintf(out, "%08X: ", i);
  81643. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  81644. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81645. fprintf(out, ".");
  81646. else
  81647. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  81648. fprintf(out, "\n");
  81649. }
  81650. if(br->bytes > 0) {
  81651. fprintf(out, "%08X: ", i);
  81652. for(j = 0; j < br->bytes*8; j++)
  81653. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  81654. fprintf(out, ".");
  81655. else
  81656. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  81657. fprintf(out, "\n");
  81658. }
  81659. }
  81660. }
  81661. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  81662. {
  81663. FLAC__ASSERT(0 != br);
  81664. FLAC__ASSERT(0 != br->buffer);
  81665. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81666. br->read_crc16 = (unsigned)seed;
  81667. br->crc16_align = br->consumed_bits;
  81668. }
  81669. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  81670. {
  81671. FLAC__ASSERT(0 != br);
  81672. FLAC__ASSERT(0 != br->buffer);
  81673. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  81674. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  81675. if(br->consumed_bits) {
  81676. const brword tail = br->buffer[br->consumed_words];
  81677. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  81678. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  81679. }
  81680. return br->read_crc16;
  81681. }
  81682. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  81683. {
  81684. return ((br->consumed_bits & 7) == 0);
  81685. }
  81686. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  81687. {
  81688. return 8 - (br->consumed_bits & 7);
  81689. }
  81690. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  81691. {
  81692. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  81693. }
  81694. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  81695. {
  81696. FLAC__ASSERT(0 != br);
  81697. FLAC__ASSERT(0 != br->buffer);
  81698. FLAC__ASSERT(bits <= 32);
  81699. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  81700. FLAC__ASSERT(br->consumed_words <= br->words);
  81701. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  81702. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  81703. *val = 0;
  81704. return true;
  81705. }
  81706. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  81707. if(!bitreader_read_from_client_(br))
  81708. return false;
  81709. }
  81710. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81711. if(br->consumed_bits) {
  81712. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  81713. const brword word = br->buffer[br->consumed_words];
  81714. if(bits < n) {
  81715. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  81716. br->consumed_bits += bits;
  81717. return true;
  81718. }
  81719. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  81720. bits -= n;
  81721. crc16_update_word_(br, word);
  81722. br->consumed_words++;
  81723. br->consumed_bits = 0;
  81724. 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 */
  81725. *val <<= bits;
  81726. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  81727. br->consumed_bits = bits;
  81728. }
  81729. return true;
  81730. }
  81731. else {
  81732. const brword word = br->buffer[br->consumed_words];
  81733. if(bits < FLAC__BITS_PER_WORD) {
  81734. *val = word >> (FLAC__BITS_PER_WORD-bits);
  81735. br->consumed_bits = bits;
  81736. return true;
  81737. }
  81738. *val = word;
  81739. crc16_update_word_(br, word);
  81740. br->consumed_words++;
  81741. return true;
  81742. }
  81743. }
  81744. else {
  81745. if(br->consumed_bits) {
  81746. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  81747. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  81748. br->consumed_bits += bits;
  81749. return true;
  81750. }
  81751. else {
  81752. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  81753. br->consumed_bits += bits;
  81754. return true;
  81755. }
  81756. }
  81757. }
  81758. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  81759. {
  81760. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  81761. return false;
  81762. *val <<= (32-bits);
  81763. *val >>= (32-bits);
  81764. return true;
  81765. }
  81766. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  81767. {
  81768. FLAC__uint32 hi, lo;
  81769. if(bits > 32) {
  81770. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  81771. return false;
  81772. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  81773. return false;
  81774. *val = hi;
  81775. *val <<= 32;
  81776. *val |= lo;
  81777. }
  81778. else {
  81779. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  81780. return false;
  81781. *val = lo;
  81782. }
  81783. return true;
  81784. }
  81785. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  81786. {
  81787. FLAC__uint32 x8, x32 = 0;
  81788. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  81789. return false;
  81790. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81791. return false;
  81792. x32 |= (x8 << 8);
  81793. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81794. return false;
  81795. x32 |= (x8 << 16);
  81796. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  81797. return false;
  81798. x32 |= (x8 << 24);
  81799. *val = x32;
  81800. return true;
  81801. }
  81802. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  81803. {
  81804. FLAC__ASSERT(0 != br);
  81805. FLAC__ASSERT(0 != br->buffer);
  81806. if(bits > 0) {
  81807. const unsigned n = br->consumed_bits & 7;
  81808. unsigned m;
  81809. FLAC__uint32 x;
  81810. if(n != 0) {
  81811. m = min(8-n, bits);
  81812. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  81813. return false;
  81814. bits -= m;
  81815. }
  81816. m = bits / 8;
  81817. if(m > 0) {
  81818. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  81819. return false;
  81820. bits %= 8;
  81821. }
  81822. if(bits > 0) {
  81823. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  81824. return false;
  81825. }
  81826. }
  81827. return true;
  81828. }
  81829. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  81830. {
  81831. FLAC__uint32 x;
  81832. FLAC__ASSERT(0 != br);
  81833. FLAC__ASSERT(0 != br->buffer);
  81834. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81835. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81836. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81837. return false;
  81838. nvals--;
  81839. }
  81840. if(0 == nvals)
  81841. return true;
  81842. while(nvals >= FLAC__BYTES_PER_WORD) {
  81843. if(br->consumed_words < br->words) {
  81844. br->consumed_words++;
  81845. nvals -= FLAC__BYTES_PER_WORD;
  81846. }
  81847. else if(!bitreader_read_from_client_(br))
  81848. return false;
  81849. }
  81850. while(nvals) {
  81851. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81852. return false;
  81853. nvals--;
  81854. }
  81855. return true;
  81856. }
  81857. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  81858. {
  81859. FLAC__uint32 x;
  81860. FLAC__ASSERT(0 != br);
  81861. FLAC__ASSERT(0 != br->buffer);
  81862. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  81863. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  81864. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81865. return false;
  81866. *val++ = (FLAC__byte)x;
  81867. nvals--;
  81868. }
  81869. if(0 == nvals)
  81870. return true;
  81871. while(nvals >= FLAC__BYTES_PER_WORD) {
  81872. if(br->consumed_words < br->words) {
  81873. const brword word = br->buffer[br->consumed_words++];
  81874. #if FLAC__BYTES_PER_WORD == 4
  81875. val[0] = (FLAC__byte)(word >> 24);
  81876. val[1] = (FLAC__byte)(word >> 16);
  81877. val[2] = (FLAC__byte)(word >> 8);
  81878. val[3] = (FLAC__byte)word;
  81879. #elif FLAC__BYTES_PER_WORD == 8
  81880. val[0] = (FLAC__byte)(word >> 56);
  81881. val[1] = (FLAC__byte)(word >> 48);
  81882. val[2] = (FLAC__byte)(word >> 40);
  81883. val[3] = (FLAC__byte)(word >> 32);
  81884. val[4] = (FLAC__byte)(word >> 24);
  81885. val[5] = (FLAC__byte)(word >> 16);
  81886. val[6] = (FLAC__byte)(word >> 8);
  81887. val[7] = (FLAC__byte)word;
  81888. #else
  81889. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  81890. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  81891. #endif
  81892. val += FLAC__BYTES_PER_WORD;
  81893. nvals -= FLAC__BYTES_PER_WORD;
  81894. }
  81895. else if(!bitreader_read_from_client_(br))
  81896. return false;
  81897. }
  81898. while(nvals) {
  81899. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  81900. return false;
  81901. *val++ = (FLAC__byte)x;
  81902. nvals--;
  81903. }
  81904. return true;
  81905. }
  81906. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  81907. #if 0 /* slow but readable version */
  81908. {
  81909. unsigned bit;
  81910. FLAC__ASSERT(0 != br);
  81911. FLAC__ASSERT(0 != br->buffer);
  81912. *val = 0;
  81913. while(1) {
  81914. if(!FLAC__bitreader_read_bit(br, &bit))
  81915. return false;
  81916. if(bit)
  81917. break;
  81918. else
  81919. *val++;
  81920. }
  81921. return true;
  81922. }
  81923. #else
  81924. {
  81925. unsigned i;
  81926. FLAC__ASSERT(0 != br);
  81927. FLAC__ASSERT(0 != br->buffer);
  81928. *val = 0;
  81929. while(1) {
  81930. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  81931. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  81932. if(b) {
  81933. i = COUNT_ZERO_MSBS(b);
  81934. *val += i;
  81935. i++;
  81936. br->consumed_bits += i;
  81937. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  81938. crc16_update_word_(br, br->buffer[br->consumed_words]);
  81939. br->consumed_words++;
  81940. br->consumed_bits = 0;
  81941. }
  81942. return true;
  81943. }
  81944. else {
  81945. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  81946. crc16_update_word_(br, br->buffer[br->consumed_words]);
  81947. br->consumed_words++;
  81948. br->consumed_bits = 0;
  81949. }
  81950. }
  81951. if(br->bytes) {
  81952. const unsigned end = br->bytes * 8;
  81953. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  81954. if(b) {
  81955. i = COUNT_ZERO_MSBS(b);
  81956. *val += i;
  81957. i++;
  81958. br->consumed_bits += i;
  81959. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  81960. return true;
  81961. }
  81962. else {
  81963. *val += end - br->consumed_bits;
  81964. br->consumed_bits += end;
  81965. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  81966. }
  81967. }
  81968. if(!bitreader_read_from_client_(br))
  81969. return false;
  81970. }
  81971. }
  81972. #endif
  81973. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  81974. {
  81975. FLAC__uint32 lsbs = 0, msbs = 0;
  81976. unsigned uval;
  81977. FLAC__ASSERT(0 != br);
  81978. FLAC__ASSERT(0 != br->buffer);
  81979. FLAC__ASSERT(parameter <= 31);
  81980. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  81981. return false;
  81982. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  81983. return false;
  81984. uval = (msbs << parameter) | lsbs;
  81985. if(uval & 1)
  81986. *val = -((int)(uval >> 1)) - 1;
  81987. else
  81988. *val = (int)(uval >> 1);
  81989. return true;
  81990. }
  81991. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  81992. #ifdef _MSC_VER
  81993. {
  81994. unsigned i;
  81995. unsigned uval = 0;
  81996. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  81997. register unsigned cwords;
  81998. register unsigned cbits;
  81999. FLAC__ASSERT(0 != br);
  82000. FLAC__ASSERT(0 != br->buffer);
  82001. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82002. FLAC__ASSERT(parameter < 32);
  82003. if(nvals == 0)
  82004. return true;
  82005. cbits = br->consumed_bits;
  82006. cwords = br->consumed_words;
  82007. while(1) {
  82008. while(1) {
  82009. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82010. brword b = br->buffer[cwords] << cbits;
  82011. if(b) {
  82012. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82013. __asm {
  82014. bsr eax, b
  82015. not eax
  82016. and eax, 31
  82017. mov i, eax
  82018. }
  82019. #else
  82020. i = COUNT_ZERO_MSBS(b);
  82021. #endif
  82022. uval += i;
  82023. bits = parameter;
  82024. i++;
  82025. cbits += i;
  82026. if(cbits == FLAC__BITS_PER_WORD) {
  82027. crc16_update_word_(br, br->buffer[cwords]);
  82028. cwords++;
  82029. cbits = 0;
  82030. }
  82031. goto break1;
  82032. }
  82033. else {
  82034. uval += FLAC__BITS_PER_WORD - cbits;
  82035. crc16_update_word_(br, br->buffer[cwords]);
  82036. cwords++;
  82037. cbits = 0;
  82038. }
  82039. }
  82040. if(br->bytes) {
  82041. const unsigned end = br->bytes * 8;
  82042. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82043. if(b) {
  82044. i = COUNT_ZERO_MSBS(b);
  82045. uval += i;
  82046. bits = parameter;
  82047. i++;
  82048. cbits += i;
  82049. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82050. goto break1;
  82051. }
  82052. else {
  82053. uval += end - cbits;
  82054. cbits += end;
  82055. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82056. }
  82057. }
  82058. br->consumed_bits = cbits;
  82059. br->consumed_words = cwords;
  82060. if(!bitreader_read_from_client_(br))
  82061. return false;
  82062. cwords = br->consumed_words;
  82063. }
  82064. break1:
  82065. FLAC__ASSERT(cwords <= br->words);
  82066. if(bits) {
  82067. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82068. br->consumed_bits = cbits;
  82069. br->consumed_words = cwords;
  82070. if(!bitreader_read_from_client_(br))
  82071. return false;
  82072. cwords = br->consumed_words;
  82073. }
  82074. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82075. if(cbits) {
  82076. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82077. const brword word = br->buffer[cwords];
  82078. if(bits < n) {
  82079. uval <<= bits;
  82080. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82081. cbits += bits;
  82082. goto break2;
  82083. }
  82084. uval <<= n;
  82085. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82086. bits -= n;
  82087. crc16_update_word_(br, word);
  82088. cwords++;
  82089. cbits = 0;
  82090. 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 */
  82091. uval <<= bits;
  82092. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82093. cbits = bits;
  82094. }
  82095. goto break2;
  82096. }
  82097. else {
  82098. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82099. uval <<= bits;
  82100. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82101. cbits = bits;
  82102. goto break2;
  82103. }
  82104. }
  82105. else {
  82106. uval <<= bits;
  82107. if(cbits) {
  82108. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82109. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82110. cbits += bits;
  82111. goto break2;
  82112. }
  82113. else {
  82114. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82115. cbits += bits;
  82116. goto break2;
  82117. }
  82118. }
  82119. }
  82120. break2:
  82121. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82122. --nvals;
  82123. if(nvals == 0) {
  82124. br->consumed_bits = cbits;
  82125. br->consumed_words = cwords;
  82126. return true;
  82127. }
  82128. uval = 0;
  82129. ++vals;
  82130. }
  82131. }
  82132. #else
  82133. {
  82134. unsigned i;
  82135. unsigned uval = 0;
  82136. register unsigned cwords;
  82137. register unsigned cbits;
  82138. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82139. FLAC__ASSERT(0 != br);
  82140. FLAC__ASSERT(0 != br->buffer);
  82141. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82142. FLAC__ASSERT(parameter < 32);
  82143. if(nvals == 0)
  82144. return true;
  82145. cbits = br->consumed_bits;
  82146. cwords = br->consumed_words;
  82147. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82148. while(1) {
  82149. while(1) {
  82150. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82151. brword b = br->buffer[cwords] << cbits;
  82152. if(b) {
  82153. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82154. asm volatile (
  82155. "bsrl %1, %0;"
  82156. "notl %0;"
  82157. "andl $31, %0;"
  82158. : "=r"(i)
  82159. : "r"(b)
  82160. );
  82161. #else
  82162. i = COUNT_ZERO_MSBS(b);
  82163. #endif
  82164. uval += i;
  82165. cbits += i;
  82166. cbits++; /* skip over stop bit */
  82167. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82168. crc16_update_word_(br, br->buffer[cwords]);
  82169. cwords++;
  82170. cbits = 0;
  82171. }
  82172. goto break1;
  82173. }
  82174. else {
  82175. uval += FLAC__BITS_PER_WORD - cbits;
  82176. crc16_update_word_(br, br->buffer[cwords]);
  82177. cwords++;
  82178. cbits = 0;
  82179. }
  82180. }
  82181. if(br->bytes) {
  82182. const unsigned end = br->bytes * 8;
  82183. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82184. if(b) {
  82185. i = COUNT_ZERO_MSBS(b);
  82186. uval += i;
  82187. cbits += i;
  82188. cbits++; /* skip over stop bit */
  82189. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82190. goto break1;
  82191. }
  82192. else {
  82193. uval += end - cbits;
  82194. cbits += end;
  82195. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82196. }
  82197. }
  82198. br->consumed_bits = cbits;
  82199. br->consumed_words = cwords;
  82200. if(!bitreader_read_from_client_(br))
  82201. return false;
  82202. cwords = br->consumed_words;
  82203. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82204. }
  82205. break1:
  82206. ucbits -= uval;
  82207. ucbits--; /* account for stop bit */
  82208. FLAC__ASSERT(cwords <= br->words);
  82209. if(parameter) {
  82210. while(ucbits < parameter) {
  82211. br->consumed_bits = cbits;
  82212. br->consumed_words = cwords;
  82213. if(!bitreader_read_from_client_(br))
  82214. return false;
  82215. cwords = br->consumed_words;
  82216. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82217. }
  82218. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82219. if(cbits) {
  82220. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82221. const brword word = br->buffer[cwords];
  82222. if(parameter < n) {
  82223. uval <<= parameter;
  82224. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82225. cbits += parameter;
  82226. }
  82227. else {
  82228. uval <<= n;
  82229. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82230. crc16_update_word_(br, word);
  82231. cwords++;
  82232. cbits = parameter - n;
  82233. 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 */
  82234. uval <<= cbits;
  82235. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82236. }
  82237. }
  82238. }
  82239. else {
  82240. cbits = parameter;
  82241. uval <<= parameter;
  82242. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82243. }
  82244. }
  82245. else {
  82246. uval <<= parameter;
  82247. if(cbits) {
  82248. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82249. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82250. cbits += parameter;
  82251. }
  82252. else {
  82253. cbits = parameter;
  82254. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82255. }
  82256. }
  82257. }
  82258. ucbits -= parameter;
  82259. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82260. --nvals;
  82261. if(nvals == 0) {
  82262. br->consumed_bits = cbits;
  82263. br->consumed_words = cwords;
  82264. return true;
  82265. }
  82266. uval = 0;
  82267. ++vals;
  82268. }
  82269. }
  82270. #endif
  82271. #if 0 /* UNUSED */
  82272. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82273. {
  82274. FLAC__uint32 lsbs = 0, msbs = 0;
  82275. unsigned bit, uval, 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. uval = (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. uval = msbs * parameter + lsbs;
  82296. }
  82297. if(uval & 1)
  82298. *val = -((int)(uval >> 1)) - 1;
  82299. else
  82300. *val = (int)(uval >> 1);
  82301. return true;
  82302. }
  82303. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82304. {
  82305. FLAC__uint32 lsbs, msbs = 0;
  82306. unsigned bit, k;
  82307. FLAC__ASSERT(0 != br);
  82308. FLAC__ASSERT(0 != br->buffer);
  82309. k = FLAC__bitmath_ilog2(parameter);
  82310. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82311. return false;
  82312. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82313. return false;
  82314. if(parameter == 1u<<k) {
  82315. *val = (msbs << k) | lsbs;
  82316. }
  82317. else {
  82318. unsigned d = (1 << (k+1)) - parameter;
  82319. if(lsbs >= d) {
  82320. if(!FLAC__bitreader_read_bit(br, &bit))
  82321. return false;
  82322. lsbs <<= 1;
  82323. lsbs |= bit;
  82324. lsbs -= d;
  82325. }
  82326. *val = msbs * parameter + lsbs;
  82327. }
  82328. return true;
  82329. }
  82330. #endif /* UNUSED */
  82331. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82332. {
  82333. FLAC__uint32 v = 0;
  82334. FLAC__uint32 x;
  82335. unsigned i;
  82336. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82337. return false;
  82338. if(raw)
  82339. raw[(*rawlen)++] = (FLAC__byte)x;
  82340. if(!(x & 0x80)) { /* 0xxxxxxx */
  82341. v = x;
  82342. i = 0;
  82343. }
  82344. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82345. v = x & 0x1F;
  82346. i = 1;
  82347. }
  82348. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82349. v = x & 0x0F;
  82350. i = 2;
  82351. }
  82352. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82353. v = x & 0x07;
  82354. i = 3;
  82355. }
  82356. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82357. v = x & 0x03;
  82358. i = 4;
  82359. }
  82360. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82361. v = x & 0x01;
  82362. i = 5;
  82363. }
  82364. else {
  82365. *val = 0xffffffff;
  82366. return true;
  82367. }
  82368. for( ; i; i--) {
  82369. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82370. return false;
  82371. if(raw)
  82372. raw[(*rawlen)++] = (FLAC__byte)x;
  82373. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82374. *val = 0xffffffff;
  82375. return true;
  82376. }
  82377. v <<= 6;
  82378. v |= (x & 0x3F);
  82379. }
  82380. *val = v;
  82381. return true;
  82382. }
  82383. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82384. {
  82385. FLAC__uint64 v = 0;
  82386. FLAC__uint32 x;
  82387. unsigned i;
  82388. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82389. return false;
  82390. if(raw)
  82391. raw[(*rawlen)++] = (FLAC__byte)x;
  82392. if(!(x & 0x80)) { /* 0xxxxxxx */
  82393. v = x;
  82394. i = 0;
  82395. }
  82396. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82397. v = x & 0x1F;
  82398. i = 1;
  82399. }
  82400. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82401. v = x & 0x0F;
  82402. i = 2;
  82403. }
  82404. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82405. v = x & 0x07;
  82406. i = 3;
  82407. }
  82408. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82409. v = x & 0x03;
  82410. i = 4;
  82411. }
  82412. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82413. v = x & 0x01;
  82414. i = 5;
  82415. }
  82416. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82417. v = 0;
  82418. i = 6;
  82419. }
  82420. else {
  82421. *val = FLAC__U64L(0xffffffffffffffff);
  82422. return true;
  82423. }
  82424. for( ; i; i--) {
  82425. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82426. return false;
  82427. if(raw)
  82428. raw[(*rawlen)++] = (FLAC__byte)x;
  82429. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82430. *val = FLAC__U64L(0xffffffffffffffff);
  82431. return true;
  82432. }
  82433. v <<= 6;
  82434. v |= (x & 0x3F);
  82435. }
  82436. *val = v;
  82437. return true;
  82438. }
  82439. #endif
  82440. /*** End of inlined file: bitreader.c ***/
  82441. /*** Start of inlined file: bitwriter.c ***/
  82442. /*** Start of inlined file: juce_FlacHeader.h ***/
  82443. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82444. // tasks..
  82445. #define VERSION "1.2.1"
  82446. #define FLAC__NO_DLL 1
  82447. #if JUCE_MSVC
  82448. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82449. #endif
  82450. #if JUCE_MAC
  82451. #define FLAC__SYS_DARWIN 1
  82452. #endif
  82453. /*** End of inlined file: juce_FlacHeader.h ***/
  82454. #if JUCE_USE_FLAC
  82455. #if HAVE_CONFIG_H
  82456. # include <config.h>
  82457. #endif
  82458. #include <stdlib.h> /* for malloc() */
  82459. #include <string.h> /* for memcpy(), memset() */
  82460. #ifdef _MSC_VER
  82461. #include <winsock.h> /* for ntohl() */
  82462. #elif defined FLAC__SYS_DARWIN
  82463. #include <machine/endian.h> /* for ntohl() */
  82464. #elif defined __MINGW32__
  82465. #include <winsock.h> /* for ntohl() */
  82466. #else
  82467. #include <netinet/in.h> /* for ntohl() */
  82468. #endif
  82469. #if 0 /* UNUSED */
  82470. #endif
  82471. /*** Start of inlined file: bitwriter.h ***/
  82472. #ifndef FLAC__PRIVATE__BITWRITER_H
  82473. #define FLAC__PRIVATE__BITWRITER_H
  82474. #include <stdio.h> /* for FILE */
  82475. struct FLAC__BitWriter;
  82476. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82477. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82478. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82479. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82480. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82481. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82482. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82483. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82484. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82485. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82486. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82487. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82488. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82489. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82490. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82491. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82492. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82493. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82494. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82495. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82496. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82497. #if 0 /* UNUSED */
  82498. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  82499. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  82500. #endif
  82501. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  82502. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  82503. #if 0 /* UNUSED */
  82504. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  82505. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  82506. #endif
  82507. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  82508. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  82509. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  82510. #endif
  82511. /*** End of inlined file: bitwriter.h ***/
  82512. /*** Start of inlined file: alloc.h ***/
  82513. #ifndef FLAC__SHARE__ALLOC_H
  82514. #define FLAC__SHARE__ALLOC_H
  82515. #if HAVE_CONFIG_H
  82516. # include <config.h>
  82517. #endif
  82518. #include <limits.h> /* for SIZE_MAX */
  82519. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  82520. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  82521. #endif
  82522. #include <stdlib.h> /* for size_t, malloc(), etc */
  82523. #ifndef SIZE_MAX
  82524. # ifndef SIZE_T_MAX
  82525. # ifdef _MSC_VER
  82526. # define SIZE_T_MAX UINT_MAX
  82527. # else
  82528. # error
  82529. # endif
  82530. # endif
  82531. # define SIZE_MAX SIZE_T_MAX
  82532. #endif
  82533. #ifndef FLaC__INLINE
  82534. #define FLaC__INLINE
  82535. #endif
  82536. static FLaC__INLINE void *safe_malloc_(size_t size)
  82537. {
  82538. if(!size)
  82539. size++;
  82540. return malloc(size);
  82541. }
  82542. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  82543. {
  82544. if(!nmemb || !size)
  82545. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82546. return calloc(nmemb, size);
  82547. }
  82548. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  82549. {
  82550. size2 += size1;
  82551. if(size2 < size1)
  82552. return 0;
  82553. return safe_malloc_(size2);
  82554. }
  82555. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  82556. {
  82557. size2 += size1;
  82558. if(size2 < size1)
  82559. return 0;
  82560. size3 += size2;
  82561. if(size3 < size2)
  82562. return 0;
  82563. return safe_malloc_(size3);
  82564. }
  82565. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  82566. {
  82567. size2 += size1;
  82568. if(size2 < size1)
  82569. return 0;
  82570. size3 += size2;
  82571. if(size3 < size2)
  82572. return 0;
  82573. size4 += size3;
  82574. if(size4 < size3)
  82575. return 0;
  82576. return safe_malloc_(size4);
  82577. }
  82578. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  82579. #if 0
  82580. needs support for cases where sizeof(size_t) != 4
  82581. {
  82582. if(sizeof(size_t) == 4) {
  82583. if ((double)size1 * (double)size2 < 4294967296.0)
  82584. return malloc(size1*size2);
  82585. }
  82586. return 0;
  82587. }
  82588. #else
  82589. {
  82590. if(!size1 || !size2)
  82591. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82592. if(size1 > SIZE_MAX / size2)
  82593. return 0;
  82594. return malloc(size1*size2);
  82595. }
  82596. #endif
  82597. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  82598. {
  82599. if(!size1 || !size2 || !size3)
  82600. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82601. if(size1 > SIZE_MAX / size2)
  82602. return 0;
  82603. size1 *= size2;
  82604. if(size1 > SIZE_MAX / size3)
  82605. return 0;
  82606. return malloc(size1*size3);
  82607. }
  82608. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  82609. {
  82610. if(!size1 || !size2)
  82611. return safe_malloc_(size3);
  82612. if(size1 > SIZE_MAX / size2)
  82613. return 0;
  82614. return safe_malloc_add_2op_(size1*size2, size3);
  82615. }
  82616. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  82617. {
  82618. if(!size1 || (!size2 && !size3))
  82619. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  82620. size2 += size3;
  82621. if(size2 < size3)
  82622. return 0;
  82623. return safe_malloc_mul_2op_(size1, size2);
  82624. }
  82625. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  82626. {
  82627. size2 += size1;
  82628. if(size2 < size1)
  82629. return 0;
  82630. return realloc(ptr, size2);
  82631. }
  82632. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  82633. {
  82634. size2 += size1;
  82635. if(size2 < size1)
  82636. return 0;
  82637. size3 += size2;
  82638. if(size3 < size2)
  82639. return 0;
  82640. return realloc(ptr, size3);
  82641. }
  82642. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  82643. {
  82644. size2 += size1;
  82645. if(size2 < size1)
  82646. return 0;
  82647. size3 += size2;
  82648. if(size3 < size2)
  82649. return 0;
  82650. size4 += size3;
  82651. if(size4 < size3)
  82652. return 0;
  82653. return realloc(ptr, size4);
  82654. }
  82655. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  82656. {
  82657. if(!size1 || !size2)
  82658. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82659. if(size1 > SIZE_MAX / size2)
  82660. return 0;
  82661. return realloc(ptr, size1*size2);
  82662. }
  82663. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  82664. {
  82665. if(!size1 || (!size2 && !size3))
  82666. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  82667. size2 += size3;
  82668. if(size2 < size3)
  82669. return 0;
  82670. return safe_realloc_mul_2op_(ptr, size1, size2);
  82671. }
  82672. #endif
  82673. /*** End of inlined file: alloc.h ***/
  82674. typedef FLAC__uint32 bwword;
  82675. #define FLAC__BYTES_PER_WORD 4
  82676. #define FLAC__BITS_PER_WORD 32
  82677. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  82678. #if WORDS_BIGENDIAN
  82679. #define SWAP_BE_WORD_TO_HOST(x) (x)
  82680. #else
  82681. #ifdef _MSC_VER
  82682. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  82683. #else
  82684. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  82685. #endif
  82686. #endif
  82687. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  82688. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  82689. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  82690. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  82691. #ifdef min
  82692. #undef min
  82693. #endif
  82694. #define min(x,y) ((x)<(y)?(x):(y))
  82695. #ifdef _MSC_VER
  82696. #define FLAC__U64L(x) x
  82697. #else
  82698. #define FLAC__U64L(x) x##LLU
  82699. #endif
  82700. #ifndef FLaC__INLINE
  82701. #define FLaC__INLINE
  82702. #endif
  82703. struct FLAC__BitWriter {
  82704. bwword *buffer;
  82705. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  82706. unsigned capacity; /* capacity of buffer in words */
  82707. unsigned words; /* # of complete words in buffer */
  82708. unsigned bits; /* # of used bits in accum */
  82709. };
  82710. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  82711. {
  82712. unsigned new_capacity;
  82713. bwword *new_buffer;
  82714. FLAC__ASSERT(0 != bw);
  82715. FLAC__ASSERT(0 != bw->buffer);
  82716. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  82717. if(bw->capacity >= new_capacity)
  82718. return true;
  82719. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  82720. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82721. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  82722. FLAC__ASSERT(new_capacity > bw->capacity);
  82723. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  82724. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  82725. if(new_buffer == 0)
  82726. return false;
  82727. bw->buffer = new_buffer;
  82728. bw->capacity = new_capacity;
  82729. return true;
  82730. }
  82731. FLAC__BitWriter *FLAC__bitwriter_new(void)
  82732. {
  82733. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  82734. return bw;
  82735. }
  82736. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  82737. {
  82738. FLAC__ASSERT(0 != bw);
  82739. FLAC__bitwriter_free(bw);
  82740. free(bw);
  82741. }
  82742. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  82743. {
  82744. FLAC__ASSERT(0 != bw);
  82745. bw->words = bw->bits = 0;
  82746. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  82747. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  82748. if(bw->buffer == 0)
  82749. return false;
  82750. return true;
  82751. }
  82752. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  82753. {
  82754. FLAC__ASSERT(0 != bw);
  82755. if(0 != bw->buffer)
  82756. free(bw->buffer);
  82757. bw->buffer = 0;
  82758. bw->capacity = 0;
  82759. bw->words = bw->bits = 0;
  82760. }
  82761. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  82762. {
  82763. bw->words = bw->bits = 0;
  82764. }
  82765. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  82766. {
  82767. unsigned i, j;
  82768. if(bw == 0) {
  82769. fprintf(out, "bitwriter is NULL\n");
  82770. }
  82771. else {
  82772. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  82773. for(i = 0; i < bw->words; i++) {
  82774. fprintf(out, "%08X: ", i);
  82775. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82776. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82777. fprintf(out, "\n");
  82778. }
  82779. if(bw->bits > 0) {
  82780. fprintf(out, "%08X: ", i);
  82781. for(j = 0; j < bw->bits; j++)
  82782. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  82783. fprintf(out, "\n");
  82784. }
  82785. }
  82786. }
  82787. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  82788. {
  82789. const FLAC__byte *buffer;
  82790. size_t bytes;
  82791. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82792. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82793. return false;
  82794. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  82795. FLAC__bitwriter_release_buffer(bw);
  82796. return true;
  82797. }
  82798. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  82799. {
  82800. const FLAC__byte *buffer;
  82801. size_t bytes;
  82802. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  82803. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  82804. return false;
  82805. *crc = FLAC__crc8(buffer, bytes);
  82806. FLAC__bitwriter_release_buffer(bw);
  82807. return true;
  82808. }
  82809. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  82810. {
  82811. return ((bw->bits & 7) == 0);
  82812. }
  82813. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  82814. {
  82815. return FLAC__TOTAL_BITS(bw);
  82816. }
  82817. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  82818. {
  82819. FLAC__ASSERT((bw->bits & 7) == 0);
  82820. if(bw->bits & 7)
  82821. return false;
  82822. if(bw->bits) {
  82823. FLAC__ASSERT(bw->words <= bw->capacity);
  82824. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  82825. return false;
  82826. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  82827. }
  82828. *buffer = (FLAC__byte*)bw->buffer;
  82829. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  82830. return true;
  82831. }
  82832. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  82833. {
  82834. (void)bw;
  82835. }
  82836. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  82837. {
  82838. unsigned n;
  82839. FLAC__ASSERT(0 != bw);
  82840. FLAC__ASSERT(0 != bw->buffer);
  82841. if(bits == 0)
  82842. return true;
  82843. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82844. return false;
  82845. if(bw->bits) {
  82846. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  82847. bw->accum <<= n;
  82848. bits -= n;
  82849. bw->bits += n;
  82850. if(bw->bits == FLAC__BITS_PER_WORD) {
  82851. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82852. bw->bits = 0;
  82853. }
  82854. else
  82855. return true;
  82856. }
  82857. while(bits >= FLAC__BITS_PER_WORD) {
  82858. bw->buffer[bw->words++] = 0;
  82859. bits -= FLAC__BITS_PER_WORD;
  82860. }
  82861. if(bits > 0) {
  82862. bw->accum = 0;
  82863. bw->bits = bits;
  82864. }
  82865. return true;
  82866. }
  82867. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  82868. {
  82869. register unsigned left;
  82870. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82871. FLAC__ASSERT(0 != bw);
  82872. FLAC__ASSERT(0 != bw->buffer);
  82873. FLAC__ASSERT(bits <= 32);
  82874. if(bits == 0)
  82875. return true;
  82876. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  82877. return false;
  82878. left = FLAC__BITS_PER_WORD - bw->bits;
  82879. if(bits < left) {
  82880. bw->accum <<= bits;
  82881. bw->accum |= val;
  82882. bw->bits += bits;
  82883. }
  82884. 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 */
  82885. bw->accum <<= left;
  82886. bw->accum |= val >> (bw->bits = bits - left);
  82887. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  82888. bw->accum = val;
  82889. }
  82890. else {
  82891. bw->accum = val;
  82892. bw->bits = 0;
  82893. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  82894. }
  82895. return true;
  82896. }
  82897. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  82898. {
  82899. if(bits < 32)
  82900. val &= (~(0xffffffff << bits));
  82901. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82902. }
  82903. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  82904. {
  82905. if(bits > 32) {
  82906. return
  82907. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  82908. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  82909. }
  82910. else
  82911. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  82912. }
  82913. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  82914. {
  82915. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  82916. return false;
  82917. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  82918. return false;
  82919. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  82920. return false;
  82921. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  82922. return false;
  82923. return true;
  82924. }
  82925. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  82926. {
  82927. unsigned i;
  82928. for(i = 0; i < nvals; i++) {
  82929. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  82930. return false;
  82931. }
  82932. return true;
  82933. }
  82934. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  82935. {
  82936. if(val < 32)
  82937. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  82938. else
  82939. return
  82940. FLAC__bitwriter_write_zeroes(bw, val) &&
  82941. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  82942. }
  82943. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  82944. {
  82945. FLAC__uint32 uval;
  82946. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  82947. uval = (val<<1) ^ (val>>31);
  82948. return 1 + parameter + (uval >> parameter);
  82949. }
  82950. #if 0 /* UNUSED */
  82951. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  82952. {
  82953. unsigned bits, msbs, uval;
  82954. unsigned k;
  82955. FLAC__ASSERT(parameter > 0);
  82956. if(val < 0)
  82957. uval = (unsigned)(((-(++val)) << 1) + 1);
  82958. else
  82959. uval = (unsigned)(val << 1);
  82960. k = FLAC__bitmath_ilog2(parameter);
  82961. if(parameter == 1u<<k) {
  82962. FLAC__ASSERT(k <= 30);
  82963. msbs = uval >> k;
  82964. bits = 1 + k + msbs;
  82965. }
  82966. else {
  82967. unsigned q, r, d;
  82968. d = (1 << (k+1)) - parameter;
  82969. q = uval / parameter;
  82970. r = uval - (q * parameter);
  82971. bits = 1 + q + k;
  82972. if(r >= d)
  82973. bits++;
  82974. }
  82975. return bits;
  82976. }
  82977. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  82978. {
  82979. unsigned bits, msbs;
  82980. unsigned k;
  82981. FLAC__ASSERT(parameter > 0);
  82982. k = FLAC__bitmath_ilog2(parameter);
  82983. if(parameter == 1u<<k) {
  82984. FLAC__ASSERT(k <= 30);
  82985. msbs = uval >> k;
  82986. bits = 1 + k + msbs;
  82987. }
  82988. else {
  82989. unsigned q, r, d;
  82990. d = (1 << (k+1)) - parameter;
  82991. q = uval / parameter;
  82992. r = uval - (q * parameter);
  82993. bits = 1 + q + k;
  82994. if(r >= d)
  82995. bits++;
  82996. }
  82997. return bits;
  82998. }
  82999. #endif /* UNUSED */
  83000. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83001. {
  83002. unsigned total_bits, interesting_bits, msbs;
  83003. FLAC__uint32 uval, pattern;
  83004. FLAC__ASSERT(0 != bw);
  83005. FLAC__ASSERT(0 != bw->buffer);
  83006. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83007. uval = (val<<1) ^ (val>>31);
  83008. msbs = uval >> parameter;
  83009. interesting_bits = 1 + parameter;
  83010. total_bits = interesting_bits + msbs;
  83011. pattern = 1 << parameter; /* the unary end bit */
  83012. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83013. if(total_bits <= 32)
  83014. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83015. else
  83016. return
  83017. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83018. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83019. }
  83020. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83021. {
  83022. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83023. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83024. FLAC__uint32 uval;
  83025. unsigned left;
  83026. const unsigned lsbits = 1 + parameter;
  83027. unsigned msbits;
  83028. FLAC__ASSERT(0 != bw);
  83029. FLAC__ASSERT(0 != bw->buffer);
  83030. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83031. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83032. while(nvals) {
  83033. uval = (*vals<<1) ^ (*vals>>31);
  83034. msbits = uval >> parameter;
  83035. #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) */
  83036. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83037. bw->bits = bw->bits + msbits + lsbits;
  83038. uval |= mask1; /* set stop bit */
  83039. uval &= mask2; /* mask off unused top bits */
  83040. bw->accum <<= msbits;
  83041. bw->accum <<= lsbits;
  83042. bw->accum |= uval;
  83043. if(bw->bits == FLAC__BITS_PER_WORD) {
  83044. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83045. bw->bits = 0;
  83046. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83047. FLAC__ASSERT(bw->capacity == bw->words);
  83048. return false;
  83049. }
  83050. }
  83051. }
  83052. else {
  83053. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83054. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83055. bw->bits = bw->bits + msbits + lsbits;
  83056. uval |= mask1; /* set stop bit */
  83057. uval &= mask2; /* mask off unused top bits */
  83058. bw->accum <<= msbits + lsbits;
  83059. bw->accum |= uval;
  83060. }
  83061. else {
  83062. #endif
  83063. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83064. return false;
  83065. if(msbits) {
  83066. if(bw->bits) {
  83067. left = FLAC__BITS_PER_WORD - bw->bits;
  83068. if(msbits < left) {
  83069. bw->accum <<= msbits;
  83070. bw->bits += msbits;
  83071. goto break1;
  83072. }
  83073. else {
  83074. bw->accum <<= left;
  83075. msbits -= left;
  83076. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83077. bw->bits = 0;
  83078. }
  83079. }
  83080. while(msbits >= FLAC__BITS_PER_WORD) {
  83081. bw->buffer[bw->words++] = 0;
  83082. msbits -= FLAC__BITS_PER_WORD;
  83083. }
  83084. if(msbits > 0) {
  83085. bw->accum = 0;
  83086. bw->bits = msbits;
  83087. }
  83088. }
  83089. break1:
  83090. uval |= mask1; /* set stop bit */
  83091. uval &= mask2; /* mask off unused top bits */
  83092. left = FLAC__BITS_PER_WORD - bw->bits;
  83093. if(lsbits < left) {
  83094. bw->accum <<= lsbits;
  83095. bw->accum |= uval;
  83096. bw->bits += lsbits;
  83097. }
  83098. else {
  83099. FLAC__ASSERT(bw->bits);
  83100. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83101. bw->accum <<= left;
  83102. bw->accum |= uval >> (bw->bits = lsbits - left);
  83103. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83104. bw->accum = uval;
  83105. }
  83106. #if 1
  83107. }
  83108. #endif
  83109. vals++;
  83110. nvals--;
  83111. }
  83112. return true;
  83113. }
  83114. #if 0 /* UNUSED */
  83115. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83116. {
  83117. unsigned total_bits, msbs, uval;
  83118. unsigned k;
  83119. FLAC__ASSERT(0 != bw);
  83120. FLAC__ASSERT(0 != bw->buffer);
  83121. FLAC__ASSERT(parameter > 0);
  83122. if(val < 0)
  83123. uval = (unsigned)(((-(++val)) << 1) + 1);
  83124. else
  83125. uval = (unsigned)(val << 1);
  83126. k = FLAC__bitmath_ilog2(parameter);
  83127. if(parameter == 1u<<k) {
  83128. unsigned pattern;
  83129. FLAC__ASSERT(k <= 30);
  83130. msbs = uval >> k;
  83131. total_bits = 1 + k + msbs;
  83132. pattern = 1 << k; /* the unary end bit */
  83133. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83134. if(total_bits <= 32) {
  83135. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83136. return false;
  83137. }
  83138. else {
  83139. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83140. return false;
  83141. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83142. return false;
  83143. }
  83144. }
  83145. else {
  83146. unsigned q, r, d;
  83147. d = (1 << (k+1)) - parameter;
  83148. q = uval / parameter;
  83149. r = uval - (q * parameter);
  83150. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83151. return false;
  83152. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83153. return false;
  83154. if(r >= d) {
  83155. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83156. return false;
  83157. }
  83158. else {
  83159. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83160. return false;
  83161. }
  83162. }
  83163. return true;
  83164. }
  83165. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83166. {
  83167. unsigned total_bits, msbs;
  83168. unsigned k;
  83169. FLAC__ASSERT(0 != bw);
  83170. FLAC__ASSERT(0 != bw->buffer);
  83171. FLAC__ASSERT(parameter > 0);
  83172. k = FLAC__bitmath_ilog2(parameter);
  83173. if(parameter == 1u<<k) {
  83174. unsigned pattern;
  83175. FLAC__ASSERT(k <= 30);
  83176. msbs = uval >> k;
  83177. total_bits = 1 + k + msbs;
  83178. pattern = 1 << k; /* the unary end bit */
  83179. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83180. if(total_bits <= 32) {
  83181. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83182. return false;
  83183. }
  83184. else {
  83185. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83186. return false;
  83187. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83188. return false;
  83189. }
  83190. }
  83191. else {
  83192. unsigned q, r, d;
  83193. d = (1 << (k+1)) - parameter;
  83194. q = uval / parameter;
  83195. r = uval - (q * parameter);
  83196. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83197. return false;
  83198. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83199. return false;
  83200. if(r >= d) {
  83201. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83202. return false;
  83203. }
  83204. else {
  83205. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83206. return false;
  83207. }
  83208. }
  83209. return true;
  83210. }
  83211. #endif /* UNUSED */
  83212. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83213. {
  83214. FLAC__bool ok = 1;
  83215. FLAC__ASSERT(0 != bw);
  83216. FLAC__ASSERT(0 != bw->buffer);
  83217. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83218. if(val < 0x80) {
  83219. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83220. }
  83221. else if(val < 0x800) {
  83222. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83223. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83224. }
  83225. else if(val < 0x10000) {
  83226. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83227. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83228. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83229. }
  83230. else if(val < 0x200000) {
  83231. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83232. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83233. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83234. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83235. }
  83236. else if(val < 0x4000000) {
  83237. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83238. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83239. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83240. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83241. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83242. }
  83243. else {
  83244. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83245. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83246. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83247. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83248. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83249. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83250. }
  83251. return ok;
  83252. }
  83253. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83254. {
  83255. FLAC__bool ok = 1;
  83256. FLAC__ASSERT(0 != bw);
  83257. FLAC__ASSERT(0 != bw->buffer);
  83258. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83259. if(val < 0x80) {
  83260. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83261. }
  83262. else if(val < 0x800) {
  83263. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83264. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83265. }
  83266. else if(val < 0x10000) {
  83267. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83268. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83269. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83270. }
  83271. else if(val < 0x200000) {
  83272. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83273. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83274. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83275. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83276. }
  83277. else if(val < 0x4000000) {
  83278. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83279. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83280. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83281. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83282. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83283. }
  83284. else if(val < 0x80000000) {
  83285. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83286. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83287. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83288. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83289. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83290. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83291. }
  83292. else {
  83293. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83294. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83295. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83296. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83297. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83298. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83299. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83300. }
  83301. return ok;
  83302. }
  83303. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83304. {
  83305. if(bw->bits & 7u)
  83306. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83307. else
  83308. return true;
  83309. }
  83310. #endif
  83311. /*** End of inlined file: bitwriter.c ***/
  83312. /*** Start of inlined file: cpu.c ***/
  83313. /*** Start of inlined file: juce_FlacHeader.h ***/
  83314. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83315. // tasks..
  83316. #define VERSION "1.2.1"
  83317. #define FLAC__NO_DLL 1
  83318. #if JUCE_MSVC
  83319. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83320. #endif
  83321. #if JUCE_MAC
  83322. #define FLAC__SYS_DARWIN 1
  83323. #endif
  83324. /*** End of inlined file: juce_FlacHeader.h ***/
  83325. #if JUCE_USE_FLAC
  83326. #if HAVE_CONFIG_H
  83327. # include <config.h>
  83328. #endif
  83329. #include <stdlib.h>
  83330. #include <stdio.h>
  83331. #if defined FLAC__CPU_IA32
  83332. # include <signal.h>
  83333. #elif defined FLAC__CPU_PPC
  83334. # if !defined FLAC__NO_ASM
  83335. # if defined FLAC__SYS_DARWIN
  83336. # include <sys/sysctl.h>
  83337. # include <mach/mach.h>
  83338. # include <mach/mach_host.h>
  83339. # include <mach/host_info.h>
  83340. # include <mach/machine.h>
  83341. # ifndef CPU_SUBTYPE_POWERPC_970
  83342. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83343. # endif
  83344. # else /* FLAC__SYS_DARWIN */
  83345. # include <signal.h>
  83346. # include <setjmp.h>
  83347. static sigjmp_buf jmpbuf;
  83348. static volatile sig_atomic_t canjump = 0;
  83349. static void sigill_handler (int sig)
  83350. {
  83351. if (!canjump) {
  83352. signal (sig, SIG_DFL);
  83353. raise (sig);
  83354. }
  83355. canjump = 0;
  83356. siglongjmp (jmpbuf, 1);
  83357. }
  83358. # endif /* FLAC__SYS_DARWIN */
  83359. # endif /* FLAC__NO_ASM */
  83360. #endif /* FLAC__CPU_PPC */
  83361. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83362. #include <sys/param.h>
  83363. #include <sys/sysctl.h>
  83364. #include <machine/cpu.h>
  83365. #endif
  83366. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83367. #include <sys/types.h>
  83368. #include <sys/sysctl.h>
  83369. #endif
  83370. #if defined(__APPLE__)
  83371. #endif
  83372. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83373. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83374. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83375. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83376. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83377. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83378. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83379. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83380. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83381. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83382. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83383. # if defined(__linux__)
  83384. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83385. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83386. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83387. {
  83388. (void)signal;
  83389. sc.eip += 3 + 3 + 6;
  83390. }
  83391. # else
  83392. # include <sys/ucontext.h>
  83393. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83394. {
  83395. (void)signal, (void)si;
  83396. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83397. }
  83398. # endif
  83399. # elif defined(_MSC_VER)
  83400. # include <windows.h>
  83401. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83402. # ifdef USE_TRY_CATCH_FLAVOR
  83403. # else
  83404. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83405. {
  83406. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83407. ep->ContextRecord->Eip += 3 + 3 + 6;
  83408. return EXCEPTION_CONTINUE_EXECUTION;
  83409. }
  83410. return EXCEPTION_CONTINUE_SEARCH;
  83411. }
  83412. # endif
  83413. # endif
  83414. #endif
  83415. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83416. {
  83417. #ifdef FLAC__CPU_IA32
  83418. info->type = FLAC__CPUINFO_TYPE_IA32;
  83419. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83420. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83421. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83422. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83423. info->data.ia32.cmov = false;
  83424. info->data.ia32.mmx = false;
  83425. info->data.ia32.fxsr = false;
  83426. info->data.ia32.sse = false;
  83427. info->data.ia32.sse2 = false;
  83428. info->data.ia32.sse3 = false;
  83429. info->data.ia32.ssse3 = false;
  83430. info->data.ia32._3dnow = false;
  83431. info->data.ia32.ext3dnow = false;
  83432. info->data.ia32.extmmx = false;
  83433. if(info->data.ia32.cpuid) {
  83434. FLAC__uint32 flags_edx, flags_ecx;
  83435. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83436. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83437. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83438. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83439. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83440. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83441. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83442. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83443. #ifdef FLAC__USE_3DNOW
  83444. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83445. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83446. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83447. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83448. #else
  83449. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83450. #endif
  83451. #ifdef DEBUG
  83452. fprintf(stderr, "CPU info (IA-32):\n");
  83453. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83454. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83455. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83456. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83457. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83458. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83459. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83460. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83461. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83462. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83463. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83464. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83465. #endif
  83466. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83467. #if defined FLAC__NO_SSE_OS
  83468. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83469. #elif defined FLAC__SSE_OS
  83470. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83471. int sse = 0;
  83472. size_t len;
  83473. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83474. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83475. if(!sse)
  83476. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83477. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83478. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83479. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83480. size_t len = sizeof(val);
  83481. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83482. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83483. else { /* double-check SSE2 */
  83484. mib[1] = CPU_SSE2;
  83485. len = sizeof(val);
  83486. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83487. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83488. }
  83489. # else
  83490. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83491. # endif
  83492. #elif defined(__linux__)
  83493. int sse = 0;
  83494. struct sigaction sigill_save;
  83495. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83496. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83497. #else
  83498. struct sigaction sigill_sse;
  83499. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  83500. __sigemptyset(&sigill_sse.sa_mask);
  83501. 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 */
  83502. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  83503. #endif
  83504. {
  83505. asm volatile (
  83506. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  83507. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  83508. "incl %0\n\t" /* SIGILL handler will jump over this */
  83509. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  83510. "nop\n\t"
  83511. "nop\n\t"
  83512. "nop\n\t"
  83513. "nop\n\t"
  83514. "nop\n\t"
  83515. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  83516. "nop\n\t"
  83517. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  83518. : "=r"(sse)
  83519. : "r"(sse)
  83520. );
  83521. sigaction(SIGILL, &sigill_save, NULL);
  83522. }
  83523. if(!sse)
  83524. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83525. #elif defined(_MSC_VER)
  83526. # ifdef USE_TRY_CATCH_FLAVOR
  83527. _try {
  83528. __asm {
  83529. # if _MSC_VER <= 1200
  83530. _emit 0x0F
  83531. _emit 0x57
  83532. _emit 0xC0
  83533. # else
  83534. xorps xmm0,xmm0
  83535. # endif
  83536. }
  83537. }
  83538. _except(EXCEPTION_EXECUTE_HANDLER) {
  83539. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  83540. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83541. }
  83542. # else
  83543. int sse = 0;
  83544. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  83545. __asm {
  83546. # if _MSC_VER <= 1200
  83547. _emit 0x0F
  83548. _emit 0x57
  83549. _emit 0xC0
  83550. # else
  83551. xorps xmm0,xmm0
  83552. # endif
  83553. inc sse
  83554. nop
  83555. nop
  83556. nop
  83557. nop
  83558. nop
  83559. nop
  83560. nop
  83561. nop
  83562. nop
  83563. }
  83564. SetUnhandledExceptionFilter(save);
  83565. if(!sse)
  83566. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83567. # endif
  83568. #else
  83569. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83570. #endif
  83571. #ifdef DEBUG
  83572. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83573. #endif
  83574. }
  83575. }
  83576. #else
  83577. info->use_asm = false;
  83578. #endif
  83579. #elif defined FLAC__CPU_PPC
  83580. info->type = FLAC__CPUINFO_TYPE_PPC;
  83581. # if !defined FLAC__NO_ASM
  83582. info->use_asm = true;
  83583. # ifdef FLAC__USE_ALTIVEC
  83584. # if defined FLAC__SYS_DARWIN
  83585. {
  83586. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  83587. size_t len = sizeof(val);
  83588. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  83589. }
  83590. {
  83591. host_basic_info_data_t hostInfo;
  83592. mach_msg_type_number_t infoCount;
  83593. infoCount = HOST_BASIC_INFO_COUNT;
  83594. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  83595. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  83596. }
  83597. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  83598. {
  83599. info->data.ppc.altivec = 0;
  83600. info->data.ppc.ppc64 = 0;
  83601. signal (SIGILL, sigill_handler);
  83602. canjump = 0;
  83603. if (!sigsetjmp (jmpbuf, 1)) {
  83604. canjump = 1;
  83605. asm volatile (
  83606. "mtspr 256, %0\n\t"
  83607. "vand %%v0, %%v0, %%v0"
  83608. :
  83609. : "r" (-1)
  83610. );
  83611. info->data.ppc.altivec = 1;
  83612. }
  83613. canjump = 0;
  83614. if (!sigsetjmp (jmpbuf, 1)) {
  83615. int x = 0;
  83616. canjump = 1;
  83617. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  83618. info->data.ppc.ppc64 = 1;
  83619. }
  83620. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  83621. }
  83622. # endif
  83623. # else /* !FLAC__USE_ALTIVEC */
  83624. info->data.ppc.altivec = 0;
  83625. info->data.ppc.ppc64 = 0;
  83626. # endif
  83627. # else
  83628. info->use_asm = false;
  83629. # endif
  83630. #else
  83631. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  83632. info->use_asm = false;
  83633. #endif
  83634. }
  83635. #endif
  83636. /*** End of inlined file: cpu.c ***/
  83637. /*** Start of inlined file: crc.c ***/
  83638. /*** Start of inlined file: juce_FlacHeader.h ***/
  83639. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83640. // tasks..
  83641. #define VERSION "1.2.1"
  83642. #define FLAC__NO_DLL 1
  83643. #if JUCE_MSVC
  83644. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83645. #endif
  83646. #if JUCE_MAC
  83647. #define FLAC__SYS_DARWIN 1
  83648. #endif
  83649. /*** End of inlined file: juce_FlacHeader.h ***/
  83650. #if JUCE_USE_FLAC
  83651. #if HAVE_CONFIG_H
  83652. # include <config.h>
  83653. #endif
  83654. FLAC__byte const FLAC__crc8_table[256] = {
  83655. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  83656. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  83657. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  83658. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  83659. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  83660. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  83661. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  83662. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  83663. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  83664. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  83665. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  83666. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  83667. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  83668. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  83669. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  83670. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  83671. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  83672. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  83673. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  83674. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  83675. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  83676. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  83677. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  83678. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  83679. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  83680. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  83681. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  83682. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  83683. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  83684. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  83685. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  83686. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  83687. };
  83688. unsigned FLAC__crc16_table[256] = {
  83689. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  83690. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  83691. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  83692. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  83693. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  83694. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  83695. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  83696. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  83697. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  83698. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  83699. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  83700. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  83701. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  83702. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  83703. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  83704. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  83705. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  83706. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  83707. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  83708. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  83709. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  83710. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  83711. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  83712. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  83713. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  83714. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  83715. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  83716. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  83717. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  83718. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  83719. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  83720. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  83721. };
  83722. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  83723. {
  83724. *crc = FLAC__crc8_table[*crc ^ data];
  83725. }
  83726. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  83727. {
  83728. while(len--)
  83729. *crc = FLAC__crc8_table[*crc ^ *data++];
  83730. }
  83731. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  83732. {
  83733. FLAC__uint8 crc = 0;
  83734. while(len--)
  83735. crc = FLAC__crc8_table[crc ^ *data++];
  83736. return crc;
  83737. }
  83738. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  83739. {
  83740. unsigned crc = 0;
  83741. while(len--)
  83742. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  83743. return crc;
  83744. }
  83745. #endif
  83746. /*** End of inlined file: crc.c ***/
  83747. /*** Start of inlined file: fixed.c ***/
  83748. /*** Start of inlined file: juce_FlacHeader.h ***/
  83749. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83750. // tasks..
  83751. #define VERSION "1.2.1"
  83752. #define FLAC__NO_DLL 1
  83753. #if JUCE_MSVC
  83754. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83755. #endif
  83756. #if JUCE_MAC
  83757. #define FLAC__SYS_DARWIN 1
  83758. #endif
  83759. /*** End of inlined file: juce_FlacHeader.h ***/
  83760. #if JUCE_USE_FLAC
  83761. #if HAVE_CONFIG_H
  83762. # include <config.h>
  83763. #endif
  83764. #include <math.h>
  83765. #include <string.h>
  83766. /*** Start of inlined file: fixed.h ***/
  83767. #ifndef FLAC__PRIVATE__FIXED_H
  83768. #define FLAC__PRIVATE__FIXED_H
  83769. #ifdef HAVE_CONFIG_H
  83770. #include <config.h>
  83771. #endif
  83772. /*** Start of inlined file: float.h ***/
  83773. #ifndef FLAC__PRIVATE__FLOAT_H
  83774. #define FLAC__PRIVATE__FLOAT_H
  83775. #ifdef HAVE_CONFIG_H
  83776. #include <config.h>
  83777. #endif
  83778. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83779. typedef double FLAC__double;
  83780. typedef float FLAC__float;
  83781. typedef float FLAC__real;
  83782. #else
  83783. typedef FLAC__int32 FLAC__fixedpoint;
  83784. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  83785. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  83786. extern const FLAC__fixedpoint FLAC__FP_ONE;
  83787. extern const FLAC__fixedpoint FLAC__FP_LN2;
  83788. extern const FLAC__fixedpoint FLAC__FP_E;
  83789. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  83790. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  83791. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  83792. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  83793. #endif
  83794. #endif
  83795. /*** End of inlined file: float.h ***/
  83796. /*** Start of inlined file: format.h ***/
  83797. #ifndef FLAC__PRIVATE__FORMAT_H
  83798. #define FLAC__PRIVATE__FORMAT_H
  83799. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  83800. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  83801. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  83802. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83803. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  83804. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  83805. #endif
  83806. /*** End of inlined file: format.h ***/
  83807. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83808. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83809. # ifndef FLAC__NO_ASM
  83810. # ifdef FLAC__CPU_IA32
  83811. # ifdef FLAC__HAS_NASM
  83812. 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]);
  83813. # endif
  83814. # endif
  83815. # endif
  83816. 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]);
  83817. #else
  83818. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  83819. 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]);
  83820. #endif
  83821. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  83822. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  83823. #endif
  83824. /*** End of inlined file: fixed.h ***/
  83825. #ifndef M_LN2
  83826. #define M_LN2 0.69314718055994530942
  83827. #endif
  83828. #ifdef min
  83829. #undef min
  83830. #endif
  83831. #define min(x,y) ((x) < (y)? (x) : (y))
  83832. #ifdef local_abs
  83833. #undef local_abs
  83834. #endif
  83835. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  83836. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  83837. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  83838. {
  83839. FLAC__uint32 rbps;
  83840. unsigned bits; /* the number of bits required to represent a number */
  83841. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83842. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83843. FLAC__ASSERT(err > 0);
  83844. FLAC__ASSERT(n > 0);
  83845. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83846. if(err <= n)
  83847. return 0;
  83848. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  83849. err <<= fracbits;
  83850. err /= n;
  83851. FLAC__ASSERT(err > 0);
  83852. bits = FLAC__bitmath_ilog2(err)+1;
  83853. if(bits > 16) {
  83854. err >>= (bits-16);
  83855. fracbits -= (bits-16);
  83856. }
  83857. rbps = (FLAC__uint32)err;
  83858. rbps *= FLAC__FP_LN2;
  83859. fracbits += 16;
  83860. FLAC__ASSERT(fracbits >= 0);
  83861. {
  83862. const int f = fracbits & 3;
  83863. if(f) {
  83864. rbps >>= f;
  83865. fracbits -= f;
  83866. }
  83867. }
  83868. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83869. if(rbps == 0)
  83870. return 0;
  83871. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83872. FLAC__ASSERT(fracbits >= -3);
  83873. if(fracbits < 16)
  83874. return rbps << (16-fracbits);
  83875. else if(fracbits > 16)
  83876. return rbps >> (fracbits-16);
  83877. else
  83878. return rbps;
  83879. }
  83880. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  83881. {
  83882. FLAC__uint32 rbps;
  83883. unsigned bits; /* the number of bits required to represent a number */
  83884. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  83885. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  83886. FLAC__ASSERT(err > 0);
  83887. FLAC__ASSERT(n > 0);
  83888. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  83889. if(err <= n)
  83890. return 0;
  83891. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  83892. err <<= fracbits;
  83893. err /= n;
  83894. FLAC__ASSERT(err > 0);
  83895. bits = FLAC__bitmath_ilog2_wide(err)+1;
  83896. if(bits > 16) {
  83897. err >>= (bits-16);
  83898. fracbits -= (bits-16);
  83899. }
  83900. rbps = (FLAC__uint32)err;
  83901. rbps *= FLAC__FP_LN2;
  83902. fracbits += 16;
  83903. FLAC__ASSERT(fracbits >= 0);
  83904. {
  83905. const int f = fracbits & 3;
  83906. if(f) {
  83907. rbps >>= f;
  83908. fracbits -= f;
  83909. }
  83910. }
  83911. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  83912. if(rbps == 0)
  83913. return 0;
  83914. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  83915. FLAC__ASSERT(fracbits >= -3);
  83916. if(fracbits < 16)
  83917. return rbps << (16-fracbits);
  83918. else if(fracbits > 16)
  83919. return rbps >> (fracbits-16);
  83920. else
  83921. return rbps;
  83922. }
  83923. #endif
  83924. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83925. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83926. #else
  83927. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  83928. #endif
  83929. {
  83930. FLAC__int32 last_error_0 = data[-1];
  83931. FLAC__int32 last_error_1 = data[-1] - data[-2];
  83932. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  83933. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  83934. FLAC__int32 error, save;
  83935. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  83936. unsigned i, order;
  83937. for(i = 0; i < data_len; i++) {
  83938. error = data[i] ; total_error_0 += local_abs(error); save = error;
  83939. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  83940. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  83941. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  83942. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  83943. }
  83944. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  83945. order = 0;
  83946. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  83947. order = 1;
  83948. else if(total_error_2 < min(total_error_3, total_error_4))
  83949. order = 2;
  83950. else if(total_error_3 < total_error_4)
  83951. order = 3;
  83952. else
  83953. order = 4;
  83954. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  83955. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  83956. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  83957. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  83958. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  83959. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83960. 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);
  83961. 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);
  83962. 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);
  83963. 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);
  83964. 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);
  83965. #else
  83966. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  83967. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  83968. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  83969. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  83970. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  83971. #endif
  83972. return order;
  83973. }
  83974. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  83975. 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])
  83976. #else
  83977. 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])
  83978. #endif
  83979. {
  83980. FLAC__int32 last_error_0 = data[-1];
  83981. FLAC__int32 last_error_1 = data[-1] - data[-2];
  83982. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  83983. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  83984. FLAC__int32 error, save;
  83985. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  83986. unsigned i, order;
  83987. for(i = 0; i < data_len; i++) {
  83988. error = data[i] ; total_error_0 += local_abs(error); save = error;
  83989. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  83990. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  83991. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  83992. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  83993. }
  83994. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  83995. order = 0;
  83996. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  83997. order = 1;
  83998. else if(total_error_2 < min(total_error_3, total_error_4))
  83999. order = 2;
  84000. else if(total_error_3 < total_error_4)
  84001. order = 3;
  84002. else
  84003. order = 4;
  84004. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84005. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84006. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84007. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84008. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84009. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84010. #if defined _MSC_VER || defined __MINGW32__
  84011. 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);
  84012. 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);
  84013. 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);
  84014. 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);
  84015. 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);
  84016. #else
  84017. 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);
  84018. 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);
  84019. 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);
  84020. 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);
  84021. 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);
  84022. #endif
  84023. #else
  84024. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84025. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84026. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84027. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84028. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84029. #endif
  84030. return order;
  84031. }
  84032. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84033. {
  84034. const int idata_len = (int)data_len;
  84035. int i;
  84036. switch(order) {
  84037. case 0:
  84038. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84039. memcpy(residual, data, sizeof(residual[0])*data_len);
  84040. break;
  84041. case 1:
  84042. for(i = 0; i < idata_len; i++)
  84043. residual[i] = data[i] - data[i-1];
  84044. break;
  84045. case 2:
  84046. for(i = 0; i < idata_len; i++)
  84047. #if 1 /* OPT: may be faster with some compilers on some systems */
  84048. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84049. #else
  84050. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84051. #endif
  84052. break;
  84053. case 3:
  84054. for(i = 0; i < idata_len; i++)
  84055. #if 1 /* OPT: may be faster with some compilers on some systems */
  84056. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84057. #else
  84058. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84059. #endif
  84060. break;
  84061. case 4:
  84062. for(i = 0; i < idata_len; i++)
  84063. #if 1 /* OPT: may be faster with some compilers on some systems */
  84064. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84065. #else
  84066. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84067. #endif
  84068. break;
  84069. default:
  84070. FLAC__ASSERT(0);
  84071. }
  84072. }
  84073. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84074. {
  84075. int i, idata_len = (int)data_len;
  84076. switch(order) {
  84077. case 0:
  84078. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84079. memcpy(data, residual, sizeof(residual[0])*data_len);
  84080. break;
  84081. case 1:
  84082. for(i = 0; i < idata_len; i++)
  84083. data[i] = residual[i] + data[i-1];
  84084. break;
  84085. case 2:
  84086. for(i = 0; i < idata_len; i++)
  84087. #if 1 /* OPT: may be faster with some compilers on some systems */
  84088. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84089. #else
  84090. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84091. #endif
  84092. break;
  84093. case 3:
  84094. for(i = 0; i < idata_len; i++)
  84095. #if 1 /* OPT: may be faster with some compilers on some systems */
  84096. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84097. #else
  84098. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84099. #endif
  84100. break;
  84101. case 4:
  84102. for(i = 0; i < idata_len; i++)
  84103. #if 1 /* OPT: may be faster with some compilers on some systems */
  84104. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84105. #else
  84106. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84107. #endif
  84108. break;
  84109. default:
  84110. FLAC__ASSERT(0);
  84111. }
  84112. }
  84113. #endif
  84114. /*** End of inlined file: fixed.c ***/
  84115. /*** Start of inlined file: float.c ***/
  84116. /*** Start of inlined file: juce_FlacHeader.h ***/
  84117. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84118. // tasks..
  84119. #define VERSION "1.2.1"
  84120. #define FLAC__NO_DLL 1
  84121. #if JUCE_MSVC
  84122. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84123. #endif
  84124. #if JUCE_MAC
  84125. #define FLAC__SYS_DARWIN 1
  84126. #endif
  84127. /*** End of inlined file: juce_FlacHeader.h ***/
  84128. #if JUCE_USE_FLAC
  84129. #if HAVE_CONFIG_H
  84130. # include <config.h>
  84131. #endif
  84132. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84133. #ifdef _MSC_VER
  84134. #define FLAC__U64L(x) x
  84135. #else
  84136. #define FLAC__U64L(x) x##LLU
  84137. #endif
  84138. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84139. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84140. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84141. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84142. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84143. #define LOG2_LOOKUP_PRECISION 16
  84144. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84145. {
  84146. 0x00000000,
  84147. 0x00000001,
  84148. 0x00000000,
  84149. 0x00000000,
  84150. 0x00000000,
  84151. 0x00000000,
  84152. 0x00000000,
  84153. 0x00000000,
  84154. 0x00000000,
  84155. 0x00000000,
  84156. 0x00000000,
  84157. 0x00000000,
  84158. 0x00000000,
  84159. 0x00000000,
  84160. 0x00000000,
  84161. 0x00000000
  84162. },
  84163. {
  84164. 0x00000000,
  84165. 0x00000010,
  84166. 0x00000007,
  84167. 0x00000003,
  84168. 0x00000001,
  84169. 0x00000001,
  84170. 0x00000000,
  84171. 0x00000000,
  84172. 0x00000000,
  84173. 0x00000000,
  84174. 0x00000000,
  84175. 0x00000000,
  84176. 0x00000000,
  84177. 0x00000000,
  84178. 0x00000000,
  84179. 0x00000000
  84180. },
  84181. {
  84182. 0x00000000,
  84183. 0x00000100,
  84184. 0x0000006a,
  84185. 0x00000031,
  84186. 0x00000018,
  84187. 0x0000000c,
  84188. 0x00000006,
  84189. 0x00000003,
  84190. 0x00000001,
  84191. 0x00000001,
  84192. 0x00000000,
  84193. 0x00000000,
  84194. 0x00000000,
  84195. 0x00000000,
  84196. 0x00000000,
  84197. 0x00000000
  84198. },
  84199. {
  84200. 0x00000000,
  84201. 0x00001000,
  84202. 0x000006a4,
  84203. 0x00000315,
  84204. 0x0000017d,
  84205. 0x000000bc,
  84206. 0x0000005d,
  84207. 0x0000002e,
  84208. 0x00000017,
  84209. 0x0000000c,
  84210. 0x00000006,
  84211. 0x00000003,
  84212. 0x00000001,
  84213. 0x00000001,
  84214. 0x00000000,
  84215. 0x00000000
  84216. },
  84217. {
  84218. 0x00000000,
  84219. 0x00010000,
  84220. 0x00006a40,
  84221. 0x00003151,
  84222. 0x000017d6,
  84223. 0x00000bba,
  84224. 0x000005d1,
  84225. 0x000002e6,
  84226. 0x00000172,
  84227. 0x000000b9,
  84228. 0x0000005c,
  84229. 0x0000002e,
  84230. 0x00000017,
  84231. 0x0000000c,
  84232. 0x00000006,
  84233. 0x00000003
  84234. },
  84235. {
  84236. 0x00000000,
  84237. 0x00100000,
  84238. 0x0006a3fe,
  84239. 0x00031513,
  84240. 0x00017d60,
  84241. 0x0000bb9d,
  84242. 0x00005d10,
  84243. 0x00002e59,
  84244. 0x00001721,
  84245. 0x00000b8e,
  84246. 0x000005c6,
  84247. 0x000002e3,
  84248. 0x00000171,
  84249. 0x000000b9,
  84250. 0x0000005c,
  84251. 0x0000002e
  84252. },
  84253. {
  84254. 0x00000000,
  84255. 0x01000000,
  84256. 0x006a3fe6,
  84257. 0x00315130,
  84258. 0x0017d605,
  84259. 0x000bb9ca,
  84260. 0x0005d0fc,
  84261. 0x0002e58f,
  84262. 0x0001720e,
  84263. 0x0000b8d8,
  84264. 0x00005c61,
  84265. 0x00002e2d,
  84266. 0x00001716,
  84267. 0x00000b8b,
  84268. 0x000005c5,
  84269. 0x000002e3
  84270. },
  84271. {
  84272. 0x00000000,
  84273. 0x10000000,
  84274. 0x06a3fe5c,
  84275. 0x03151301,
  84276. 0x017d6049,
  84277. 0x00bb9ca6,
  84278. 0x005d0fba,
  84279. 0x002e58f7,
  84280. 0x001720da,
  84281. 0x000b8d87,
  84282. 0x0005c60b,
  84283. 0x0002e2d7,
  84284. 0x00017160,
  84285. 0x0000b8ad,
  84286. 0x00005c56,
  84287. 0x00002e2b
  84288. }
  84289. };
  84290. #if 0
  84291. static const FLAC__uint64 log2_lookup_wide[] = {
  84292. {
  84293. 0x00000000,
  84294. FLAC__U64L(0x100000000),
  84295. FLAC__U64L(0x6a3fe5c6),
  84296. FLAC__U64L(0x31513015),
  84297. FLAC__U64L(0x17d60497),
  84298. FLAC__U64L(0x0bb9ca65),
  84299. FLAC__U64L(0x05d0fba2),
  84300. FLAC__U64L(0x02e58f74),
  84301. FLAC__U64L(0x01720d9c),
  84302. FLAC__U64L(0x00b8d875),
  84303. FLAC__U64L(0x005c60aa),
  84304. FLAC__U64L(0x002e2d72),
  84305. FLAC__U64L(0x00171600),
  84306. FLAC__U64L(0x000b8ad2),
  84307. FLAC__U64L(0x0005c55d),
  84308. FLAC__U64L(0x0002e2ac)
  84309. },
  84310. {
  84311. 0x00000000,
  84312. FLAC__U64L(0x1000000000000),
  84313. FLAC__U64L(0x6a3fe5c60429),
  84314. FLAC__U64L(0x315130157f7a),
  84315. FLAC__U64L(0x17d60496cfbb),
  84316. FLAC__U64L(0xbb9ca64ecac),
  84317. FLAC__U64L(0x5d0fba187cd),
  84318. FLAC__U64L(0x2e58f7441ee),
  84319. FLAC__U64L(0x1720d9c06a8),
  84320. FLAC__U64L(0xb8d8752173),
  84321. FLAC__U64L(0x5c60aa252e),
  84322. FLAC__U64L(0x2e2d71b0d8),
  84323. FLAC__U64L(0x1716001719),
  84324. FLAC__U64L(0xb8ad1de1b),
  84325. FLAC__U64L(0x5c55d640d),
  84326. FLAC__U64L(0x2e2abcf52)
  84327. }
  84328. };
  84329. #endif
  84330. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84331. {
  84332. const FLAC__uint32 ONE = (1u << fracbits);
  84333. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84334. FLAC__ASSERT(fracbits < 32);
  84335. FLAC__ASSERT((fracbits & 0x3) == 0);
  84336. if(x < ONE)
  84337. return 0;
  84338. if(precision > LOG2_LOOKUP_PRECISION)
  84339. precision = LOG2_LOOKUP_PRECISION;
  84340. {
  84341. FLAC__uint32 y = 0;
  84342. FLAC__uint32 z = x >> 1, k = 1;
  84343. while (x > ONE && k < precision) {
  84344. if (x - z >= ONE) {
  84345. x -= z;
  84346. z = x >> k;
  84347. y += table[k];
  84348. }
  84349. else {
  84350. z >>= 1;
  84351. k++;
  84352. }
  84353. }
  84354. return y;
  84355. }
  84356. }
  84357. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84358. #endif
  84359. /*** End of inlined file: float.c ***/
  84360. /*** Start of inlined file: format.c ***/
  84361. /*** Start of inlined file: juce_FlacHeader.h ***/
  84362. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84363. // tasks..
  84364. #define VERSION "1.2.1"
  84365. #define FLAC__NO_DLL 1
  84366. #if JUCE_MSVC
  84367. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84368. #endif
  84369. #if JUCE_MAC
  84370. #define FLAC__SYS_DARWIN 1
  84371. #endif
  84372. /*** End of inlined file: juce_FlacHeader.h ***/
  84373. #if JUCE_USE_FLAC
  84374. #if HAVE_CONFIG_H
  84375. # include <config.h>
  84376. #endif
  84377. #include <stdio.h>
  84378. #include <stdlib.h> /* for qsort() */
  84379. #include <string.h> /* for memset() */
  84380. #ifndef FLaC__INLINE
  84381. #define FLaC__INLINE
  84382. #endif
  84383. #ifdef min
  84384. #undef min
  84385. #endif
  84386. #define min(a,b) ((a)<(b)?(a):(b))
  84387. #ifdef _MSC_VER
  84388. #define FLAC__U64L(x) x
  84389. #else
  84390. #define FLAC__U64L(x) x##LLU
  84391. #endif
  84392. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84393. ;
  84394. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84395. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84396. #else
  84397. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84398. #endif
  84399. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84400. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84401. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84402. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84403. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84404. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84405. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84406. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84407. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84408. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84409. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84410. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84411. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84412. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84413. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84414. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84415. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84416. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84417. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84418. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84419. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84420. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84421. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84422. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84423. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84424. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84425. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84426. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84427. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84428. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84429. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84430. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84431. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84432. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84433. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84434. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84435. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84436. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84437. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84438. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84439. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84440. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84441. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84442. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84443. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84444. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84445. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84446. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84447. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84448. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84449. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84450. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84451. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84452. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84453. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84454. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84455. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84456. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84457. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84458. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84459. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84460. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84461. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84462. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84463. "PARTITIONED_RICE",
  84464. "PARTITIONED_RICE2"
  84465. };
  84466. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84467. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84468. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84469. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84470. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84471. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84472. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84473. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84474. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84475. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84476. "CONSTANT",
  84477. "VERBATIM",
  84478. "FIXED",
  84479. "LPC"
  84480. };
  84481. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84482. "INDEPENDENT",
  84483. "LEFT_SIDE",
  84484. "RIGHT_SIDE",
  84485. "MID_SIDE"
  84486. };
  84487. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84488. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84489. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84490. };
  84491. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84492. "STREAMINFO",
  84493. "PADDING",
  84494. "APPLICATION",
  84495. "SEEKTABLE",
  84496. "VORBIS_COMMENT",
  84497. "CUESHEET",
  84498. "PICTURE"
  84499. };
  84500. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  84501. "Other",
  84502. "32x32 pixels 'file icon' (PNG only)",
  84503. "Other file icon",
  84504. "Cover (front)",
  84505. "Cover (back)",
  84506. "Leaflet page",
  84507. "Media (e.g. label side of CD)",
  84508. "Lead artist/lead performer/soloist",
  84509. "Artist/performer",
  84510. "Conductor",
  84511. "Band/Orchestra",
  84512. "Composer",
  84513. "Lyricist/text writer",
  84514. "Recording Location",
  84515. "During recording",
  84516. "During performance",
  84517. "Movie/video screen capture",
  84518. "A bright coloured fish",
  84519. "Illustration",
  84520. "Band/artist logotype",
  84521. "Publisher/Studio logotype"
  84522. };
  84523. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  84524. {
  84525. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  84526. return false;
  84527. }
  84528. else
  84529. return true;
  84530. }
  84531. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  84532. {
  84533. if(
  84534. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  84535. (
  84536. sample_rate >= (1u << 16) &&
  84537. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  84538. )
  84539. ) {
  84540. return false;
  84541. }
  84542. else
  84543. return true;
  84544. }
  84545. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  84546. {
  84547. unsigned i;
  84548. FLAC__uint64 prev_sample_number = 0;
  84549. FLAC__bool got_prev = false;
  84550. FLAC__ASSERT(0 != seek_table);
  84551. for(i = 0; i < seek_table->num_points; i++) {
  84552. if(got_prev) {
  84553. if(
  84554. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  84555. seek_table->points[i].sample_number <= prev_sample_number
  84556. )
  84557. return false;
  84558. }
  84559. prev_sample_number = seek_table->points[i].sample_number;
  84560. got_prev = true;
  84561. }
  84562. return true;
  84563. }
  84564. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  84565. {
  84566. if(l->sample_number == r->sample_number)
  84567. return 0;
  84568. else if(l->sample_number < r->sample_number)
  84569. return -1;
  84570. else
  84571. return 1;
  84572. }
  84573. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  84574. {
  84575. unsigned i, j;
  84576. FLAC__bool first;
  84577. FLAC__ASSERT(0 != seek_table);
  84578. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  84579. first = true;
  84580. for(i = j = 0; i < seek_table->num_points; i++) {
  84581. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  84582. if(!first) {
  84583. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  84584. continue;
  84585. }
  84586. }
  84587. first = false;
  84588. seek_table->points[j++] = seek_table->points[i];
  84589. }
  84590. for(i = j; i < seek_table->num_points; i++) {
  84591. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  84592. seek_table->points[i].stream_offset = 0;
  84593. seek_table->points[i].frame_samples = 0;
  84594. }
  84595. return j;
  84596. }
  84597. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  84598. {
  84599. FLAC__ASSERT(0 != utf8);
  84600. if ((utf8[0] & 0x80) == 0) {
  84601. return 1;
  84602. }
  84603. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  84604. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  84605. return 0;
  84606. return 2;
  84607. }
  84608. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  84609. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  84610. return 0;
  84611. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  84612. return 0;
  84613. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  84614. return 0;
  84615. return 3;
  84616. }
  84617. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  84618. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  84619. return 0;
  84620. return 4;
  84621. }
  84622. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  84623. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  84624. return 0;
  84625. return 5;
  84626. }
  84627. 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) {
  84628. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  84629. return 0;
  84630. return 6;
  84631. }
  84632. else {
  84633. return 0;
  84634. }
  84635. }
  84636. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  84637. {
  84638. char c;
  84639. for(c = *name; c; c = *(++name))
  84640. if(c < 0x20 || c == 0x3d || c > 0x7d)
  84641. return false;
  84642. return true;
  84643. }
  84644. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  84645. {
  84646. if(length == (unsigned)(-1)) {
  84647. while(*value) {
  84648. unsigned n = utf8len_(value);
  84649. if(n == 0)
  84650. return false;
  84651. value += n;
  84652. }
  84653. }
  84654. else {
  84655. const FLAC__byte *end = value + length;
  84656. while(value < end) {
  84657. unsigned n = utf8len_(value);
  84658. if(n == 0)
  84659. return false;
  84660. value += n;
  84661. }
  84662. if(value != end)
  84663. return false;
  84664. }
  84665. return true;
  84666. }
  84667. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  84668. {
  84669. const FLAC__byte *s, *end;
  84670. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  84671. if(*s < 0x20 || *s > 0x7D)
  84672. return false;
  84673. }
  84674. if(s == end)
  84675. return false;
  84676. s++; /* skip '=' */
  84677. while(s < end) {
  84678. unsigned n = utf8len_(s);
  84679. if(n == 0)
  84680. return false;
  84681. s += n;
  84682. }
  84683. if(s != end)
  84684. return false;
  84685. return true;
  84686. }
  84687. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  84688. {
  84689. unsigned i, j;
  84690. if(check_cd_da_subset) {
  84691. if(cue_sheet->lead_in < 2 * 44100) {
  84692. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  84693. return false;
  84694. }
  84695. if(cue_sheet->lead_in % 588 != 0) {
  84696. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  84697. return false;
  84698. }
  84699. }
  84700. if(cue_sheet->num_tracks == 0) {
  84701. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  84702. return false;
  84703. }
  84704. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  84705. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  84706. return false;
  84707. }
  84708. for(i = 0; i < cue_sheet->num_tracks; i++) {
  84709. if(cue_sheet->tracks[i].number == 0) {
  84710. if(violation) *violation = "cue sheet may not have a track number 0";
  84711. return false;
  84712. }
  84713. if(check_cd_da_subset) {
  84714. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  84715. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  84716. return false;
  84717. }
  84718. }
  84719. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  84720. if(violation) {
  84721. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  84722. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  84723. else
  84724. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  84725. }
  84726. return false;
  84727. }
  84728. if(i < cue_sheet->num_tracks - 1) {
  84729. if(cue_sheet->tracks[i].num_indices == 0) {
  84730. if(violation) *violation = "cue sheet track must have at least one index point";
  84731. return false;
  84732. }
  84733. if(cue_sheet->tracks[i].indices[0].number > 1) {
  84734. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  84735. return false;
  84736. }
  84737. }
  84738. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  84739. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  84740. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  84741. return false;
  84742. }
  84743. if(j > 0) {
  84744. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  84745. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  84746. return false;
  84747. }
  84748. }
  84749. }
  84750. }
  84751. return true;
  84752. }
  84753. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  84754. {
  84755. char *p;
  84756. FLAC__byte *b;
  84757. for(p = picture->mime_type; *p; p++) {
  84758. if(*p < 0x20 || *p > 0x7e) {
  84759. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  84760. return false;
  84761. }
  84762. }
  84763. for(b = picture->description; *b; ) {
  84764. unsigned n = utf8len_(b);
  84765. if(n == 0) {
  84766. if(violation) *violation = "description string must be valid UTF-8";
  84767. return false;
  84768. }
  84769. b += n;
  84770. }
  84771. return true;
  84772. }
  84773. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  84774. {
  84775. return
  84776. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  84777. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  84778. blocksize,
  84779. predictor_order
  84780. );
  84781. }
  84782. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  84783. {
  84784. unsigned max_rice_partition_order = 0;
  84785. while(!(blocksize & 1)) {
  84786. max_rice_partition_order++;
  84787. blocksize >>= 1;
  84788. }
  84789. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  84790. }
  84791. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  84792. {
  84793. unsigned max_rice_partition_order = limit;
  84794. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  84795. max_rice_partition_order--;
  84796. FLAC__ASSERT(
  84797. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  84798. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  84799. );
  84800. return max_rice_partition_order;
  84801. }
  84802. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84803. {
  84804. FLAC__ASSERT(0 != object);
  84805. object->parameters = 0;
  84806. object->raw_bits = 0;
  84807. object->capacity_by_order = 0;
  84808. }
  84809. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  84810. {
  84811. FLAC__ASSERT(0 != object);
  84812. if(0 != object->parameters)
  84813. free(object->parameters);
  84814. if(0 != object->raw_bits)
  84815. free(object->raw_bits);
  84816. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  84817. }
  84818. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  84819. {
  84820. FLAC__ASSERT(0 != object);
  84821. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  84822. if(object->capacity_by_order < max_partition_order) {
  84823. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  84824. return false;
  84825. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  84826. return false;
  84827. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  84828. object->capacity_by_order = max_partition_order;
  84829. }
  84830. return true;
  84831. }
  84832. #endif
  84833. /*** End of inlined file: format.c ***/
  84834. /*** Start of inlined file: lpc_flac.c ***/
  84835. /*** Start of inlined file: juce_FlacHeader.h ***/
  84836. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84837. // tasks..
  84838. #define VERSION "1.2.1"
  84839. #define FLAC__NO_DLL 1
  84840. #if JUCE_MSVC
  84841. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84842. #endif
  84843. #if JUCE_MAC
  84844. #define FLAC__SYS_DARWIN 1
  84845. #endif
  84846. /*** End of inlined file: juce_FlacHeader.h ***/
  84847. #if JUCE_USE_FLAC
  84848. #if HAVE_CONFIG_H
  84849. # include <config.h>
  84850. #endif
  84851. #include <math.h>
  84852. /*** Start of inlined file: lpc.h ***/
  84853. #ifndef FLAC__PRIVATE__LPC_H
  84854. #define FLAC__PRIVATE__LPC_H
  84855. #ifdef HAVE_CONFIG_H
  84856. #include <config.h>
  84857. #endif
  84858. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84859. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  84860. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84861. #ifndef FLAC__NO_ASM
  84862. # ifdef FLAC__CPU_IA32
  84863. # ifdef FLAC__HAS_NASM
  84864. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84865. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84866. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84867. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84868. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  84869. # endif
  84870. # endif
  84871. #endif
  84872. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  84873. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  84874. 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[]);
  84875. 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[]);
  84876. #ifndef FLAC__NO_ASM
  84877. # ifdef FLAC__CPU_IA32
  84878. # ifdef FLAC__HAS_NASM
  84879. 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[]);
  84880. 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[]);
  84881. # endif
  84882. # endif
  84883. #endif
  84884. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84885. 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[]);
  84886. 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[]);
  84887. #ifndef FLAC__NO_ASM
  84888. # ifdef FLAC__CPU_IA32
  84889. # ifdef FLAC__HAS_NASM
  84890. 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[]);
  84891. 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[]);
  84892. # endif /* FLAC__HAS_NASM */
  84893. # elif defined FLAC__CPU_PPC
  84894. 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[]);
  84895. 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[]);
  84896. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  84897. #endif /* FLAC__NO_ASM */
  84898. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84899. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  84900. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  84901. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  84902. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  84903. #endif
  84904. /*** End of inlined file: lpc.h ***/
  84905. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  84906. #include <stdio.h>
  84907. #endif
  84908. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84909. #ifndef M_LN2
  84910. #define M_LN2 0.69314718055994530942
  84911. #endif
  84912. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  84913. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  84914. {
  84915. unsigned i;
  84916. for(i = 0; i < data_len; i++)
  84917. out[i] = in[i] * window[i];
  84918. }
  84919. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  84920. {
  84921. #if 0
  84922. FLAC__real d;
  84923. unsigned i;
  84924. FLAC__ASSERT(lag > 0);
  84925. FLAC__ASSERT(lag <= data_len);
  84926. while(lag--) {
  84927. for(i = lag, d = 0.0; i < data_len; i++)
  84928. d += data[i] * data[i - lag];
  84929. autoc[lag] = d;
  84930. }
  84931. #endif
  84932. FLAC__real d;
  84933. unsigned sample, coeff;
  84934. const unsigned limit = data_len - lag;
  84935. FLAC__ASSERT(lag > 0);
  84936. FLAC__ASSERT(lag <= data_len);
  84937. for(coeff = 0; coeff < lag; coeff++)
  84938. autoc[coeff] = 0.0;
  84939. for(sample = 0; sample <= limit; sample++) {
  84940. d = data[sample];
  84941. for(coeff = 0; coeff < lag; coeff++)
  84942. autoc[coeff] += d * data[sample+coeff];
  84943. }
  84944. for(; sample < data_len; sample++) {
  84945. d = data[sample];
  84946. for(coeff = 0; coeff < data_len - sample; coeff++)
  84947. autoc[coeff] += d * data[sample+coeff];
  84948. }
  84949. }
  84950. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  84951. {
  84952. unsigned i, j;
  84953. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  84954. FLAC__ASSERT(0 != max_order);
  84955. FLAC__ASSERT(0 < *max_order);
  84956. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  84957. FLAC__ASSERT(autoc[0] != 0.0);
  84958. err = autoc[0];
  84959. for(i = 0; i < *max_order; i++) {
  84960. r = -autoc[i+1];
  84961. for(j = 0; j < i; j++)
  84962. r -= lpc[j] * autoc[i-j];
  84963. ref[i] = (r/=err);
  84964. lpc[i]=r;
  84965. for(j = 0; j < (i>>1); j++) {
  84966. FLAC__double tmp = lpc[j];
  84967. lpc[j] += r * lpc[i-1-j];
  84968. lpc[i-1-j] += r * tmp;
  84969. }
  84970. if(i & 1)
  84971. lpc[j] += lpc[j] * r;
  84972. err *= (1.0 - r * r);
  84973. for(j = 0; j <= i; j++)
  84974. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  84975. error[i] = err;
  84976. if(err == 0.0) {
  84977. *max_order = i+1;
  84978. return;
  84979. }
  84980. }
  84981. }
  84982. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  84983. {
  84984. unsigned i;
  84985. FLAC__double cmax;
  84986. FLAC__int32 qmax, qmin;
  84987. FLAC__ASSERT(precision > 0);
  84988. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  84989. precision--;
  84990. qmax = 1 << precision;
  84991. qmin = -qmax;
  84992. qmax--;
  84993. cmax = 0.0;
  84994. for(i = 0; i < order; i++) {
  84995. const FLAC__double d = fabs(lp_coeff[i]);
  84996. if(d > cmax)
  84997. cmax = d;
  84998. }
  84999. if(cmax <= 0.0) {
  85000. return 2;
  85001. }
  85002. else {
  85003. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85004. const int min_shiftlimit = -max_shiftlimit - 1;
  85005. int log2cmax;
  85006. (void)frexp(cmax, &log2cmax);
  85007. log2cmax--;
  85008. *shift = (int)precision - log2cmax - 1;
  85009. if(*shift > max_shiftlimit)
  85010. *shift = max_shiftlimit;
  85011. else if(*shift < min_shiftlimit)
  85012. return 1;
  85013. }
  85014. if(*shift >= 0) {
  85015. FLAC__double error = 0.0;
  85016. FLAC__int32 q;
  85017. for(i = 0; i < order; i++) {
  85018. error += lp_coeff[i] * (1 << *shift);
  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. }
  85041. else {
  85042. const int nshift = -(*shift);
  85043. FLAC__double error = 0.0;
  85044. FLAC__int32 q;
  85045. #ifdef DEBUG
  85046. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85047. #endif
  85048. for(i = 0; i < order; i++) {
  85049. error += lp_coeff[i] / (1 << nshift);
  85050. #if 1 /* unfortunately lround() is C99 */
  85051. if(error >= 0.0)
  85052. q = (FLAC__int32)(error + 0.5);
  85053. else
  85054. q = (FLAC__int32)(error - 0.5);
  85055. #else
  85056. q = lround(error);
  85057. #endif
  85058. #ifdef FLAC__OVERFLOW_DETECT
  85059. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85060. 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]);
  85061. else if(q < qmin)
  85062. 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]);
  85063. #endif
  85064. if(q > qmax)
  85065. q = qmax;
  85066. else if(q < qmin)
  85067. q = qmin;
  85068. error -= q;
  85069. qlp_coeff[i] = q;
  85070. }
  85071. *shift = 0;
  85072. }
  85073. return 0;
  85074. }
  85075. 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[])
  85076. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85077. {
  85078. FLAC__int64 sumo;
  85079. unsigned i, j;
  85080. FLAC__int32 sum;
  85081. const FLAC__int32 *history;
  85082. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85083. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85084. for(i=0;i<order;i++)
  85085. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85086. fprintf(stderr,"\n");
  85087. #endif
  85088. FLAC__ASSERT(order > 0);
  85089. for(i = 0; i < data_len; i++) {
  85090. sumo = 0;
  85091. sum = 0;
  85092. history = data;
  85093. for(j = 0; j < order; j++) {
  85094. sum += qlp_coeff[j] * (*(--history));
  85095. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85096. #if defined _MSC_VER
  85097. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85098. 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);
  85099. #else
  85100. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85101. 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);
  85102. #endif
  85103. }
  85104. *(residual++) = *(data++) - (sum >> lp_quantization);
  85105. }
  85106. }
  85107. #else /* fully unrolled version for normal use */
  85108. {
  85109. int i;
  85110. FLAC__int32 sum;
  85111. FLAC__ASSERT(order > 0);
  85112. FLAC__ASSERT(order <= 32);
  85113. if(order <= 12) {
  85114. if(order > 8) {
  85115. if(order > 10) {
  85116. if(order == 12) {
  85117. for(i = 0; i < (int)data_len; i++) {
  85118. sum = 0;
  85119. sum += qlp_coeff[11] * data[i-12];
  85120. sum += qlp_coeff[10] * data[i-11];
  85121. sum += qlp_coeff[9] * data[i-10];
  85122. sum += qlp_coeff[8] * data[i-9];
  85123. sum += qlp_coeff[7] * data[i-8];
  85124. sum += qlp_coeff[6] * data[i-7];
  85125. sum += qlp_coeff[5] * data[i-6];
  85126. sum += qlp_coeff[4] * data[i-5];
  85127. sum += qlp_coeff[3] * data[i-4];
  85128. sum += qlp_coeff[2] * data[i-3];
  85129. sum += qlp_coeff[1] * data[i-2];
  85130. sum += qlp_coeff[0] * data[i-1];
  85131. residual[i] = data[i] - (sum >> lp_quantization);
  85132. }
  85133. }
  85134. else { /* order == 11 */
  85135. for(i = 0; i < (int)data_len; i++) {
  85136. sum = 0;
  85137. sum += qlp_coeff[10] * data[i-11];
  85138. sum += qlp_coeff[9] * data[i-10];
  85139. sum += qlp_coeff[8] * data[i-9];
  85140. sum += qlp_coeff[7] * data[i-8];
  85141. sum += qlp_coeff[6] * data[i-7];
  85142. sum += qlp_coeff[5] * data[i-6];
  85143. sum += qlp_coeff[4] * data[i-5];
  85144. sum += qlp_coeff[3] * data[i-4];
  85145. sum += qlp_coeff[2] * data[i-3];
  85146. sum += qlp_coeff[1] * data[i-2];
  85147. sum += qlp_coeff[0] * data[i-1];
  85148. residual[i] = data[i] - (sum >> lp_quantization);
  85149. }
  85150. }
  85151. }
  85152. else {
  85153. if(order == 10) {
  85154. for(i = 0; i < (int)data_len; i++) {
  85155. sum = 0;
  85156. sum += qlp_coeff[9] * data[i-10];
  85157. sum += qlp_coeff[8] * data[i-9];
  85158. sum += qlp_coeff[7] * data[i-8];
  85159. sum += qlp_coeff[6] * data[i-7];
  85160. sum += qlp_coeff[5] * data[i-6];
  85161. sum += qlp_coeff[4] * data[i-5];
  85162. sum += qlp_coeff[3] * data[i-4];
  85163. sum += qlp_coeff[2] * data[i-3];
  85164. sum += qlp_coeff[1] * data[i-2];
  85165. sum += qlp_coeff[0] * data[i-1];
  85166. residual[i] = data[i] - (sum >> lp_quantization);
  85167. }
  85168. }
  85169. else { /* order == 9 */
  85170. for(i = 0; i < (int)data_len; i++) {
  85171. sum = 0;
  85172. sum += qlp_coeff[8] * data[i-9];
  85173. sum += qlp_coeff[7] * data[i-8];
  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. }
  85186. else if(order > 4) {
  85187. if(order > 6) {
  85188. if(order == 8) {
  85189. for(i = 0; i < (int)data_len; i++) {
  85190. sum = 0;
  85191. sum += qlp_coeff[7] * data[i-8];
  85192. sum += qlp_coeff[6] * data[i-7];
  85193. sum += qlp_coeff[5] * data[i-6];
  85194. sum += qlp_coeff[4] * data[i-5];
  85195. sum += qlp_coeff[3] * data[i-4];
  85196. sum += qlp_coeff[2] * data[i-3];
  85197. sum += qlp_coeff[1] * data[i-2];
  85198. sum += qlp_coeff[0] * data[i-1];
  85199. residual[i] = data[i] - (sum >> lp_quantization);
  85200. }
  85201. }
  85202. else { /* order == 7 */
  85203. for(i = 0; i < (int)data_len; i++) {
  85204. sum = 0;
  85205. sum += qlp_coeff[6] * data[i-7];
  85206. sum += qlp_coeff[5] * data[i-6];
  85207. sum += qlp_coeff[4] * data[i-5];
  85208. sum += qlp_coeff[3] * data[i-4];
  85209. sum += qlp_coeff[2] * data[i-3];
  85210. sum += qlp_coeff[1] * data[i-2];
  85211. sum += qlp_coeff[0] * data[i-1];
  85212. residual[i] = data[i] - (sum >> lp_quantization);
  85213. }
  85214. }
  85215. }
  85216. else {
  85217. if(order == 6) {
  85218. for(i = 0; i < (int)data_len; i++) {
  85219. sum = 0;
  85220. sum += qlp_coeff[5] * data[i-6];
  85221. sum += qlp_coeff[4] * data[i-5];
  85222. sum += qlp_coeff[3] * data[i-4];
  85223. sum += qlp_coeff[2] * data[i-3];
  85224. sum += qlp_coeff[1] * data[i-2];
  85225. sum += qlp_coeff[0] * data[i-1];
  85226. residual[i] = data[i] - (sum >> lp_quantization);
  85227. }
  85228. }
  85229. else { /* order == 5 */
  85230. for(i = 0; i < (int)data_len; i++) {
  85231. sum = 0;
  85232. sum += qlp_coeff[4] * data[i-5];
  85233. sum += qlp_coeff[3] * data[i-4];
  85234. sum += qlp_coeff[2] * data[i-3];
  85235. sum += qlp_coeff[1] * data[i-2];
  85236. sum += qlp_coeff[0] * data[i-1];
  85237. residual[i] = data[i] - (sum >> lp_quantization);
  85238. }
  85239. }
  85240. }
  85241. }
  85242. else {
  85243. if(order > 2) {
  85244. if(order == 4) {
  85245. for(i = 0; i < (int)data_len; i++) {
  85246. sum = 0;
  85247. sum += qlp_coeff[3] * data[i-4];
  85248. sum += qlp_coeff[2] * data[i-3];
  85249. sum += qlp_coeff[1] * data[i-2];
  85250. sum += qlp_coeff[0] * data[i-1];
  85251. residual[i] = data[i] - (sum >> lp_quantization);
  85252. }
  85253. }
  85254. else { /* order == 3 */
  85255. for(i = 0; i < (int)data_len; i++) {
  85256. sum = 0;
  85257. sum += qlp_coeff[2] * data[i-3];
  85258. sum += qlp_coeff[1] * data[i-2];
  85259. sum += qlp_coeff[0] * data[i-1];
  85260. residual[i] = data[i] - (sum >> lp_quantization);
  85261. }
  85262. }
  85263. }
  85264. else {
  85265. if(order == 2) {
  85266. for(i = 0; i < (int)data_len; i++) {
  85267. sum = 0;
  85268. sum += qlp_coeff[1] * data[i-2];
  85269. sum += qlp_coeff[0] * data[i-1];
  85270. residual[i] = data[i] - (sum >> lp_quantization);
  85271. }
  85272. }
  85273. else { /* order == 1 */
  85274. for(i = 0; i < (int)data_len; i++)
  85275. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85276. }
  85277. }
  85278. }
  85279. }
  85280. else { /* order > 12 */
  85281. for(i = 0; i < (int)data_len; i++) {
  85282. sum = 0;
  85283. switch(order) {
  85284. case 32: sum += qlp_coeff[31] * data[i-32];
  85285. case 31: sum += qlp_coeff[30] * data[i-31];
  85286. case 30: sum += qlp_coeff[29] * data[i-30];
  85287. case 29: sum += qlp_coeff[28] * data[i-29];
  85288. case 28: sum += qlp_coeff[27] * data[i-28];
  85289. case 27: sum += qlp_coeff[26] * data[i-27];
  85290. case 26: sum += qlp_coeff[25] * data[i-26];
  85291. case 25: sum += qlp_coeff[24] * data[i-25];
  85292. case 24: sum += qlp_coeff[23] * data[i-24];
  85293. case 23: sum += qlp_coeff[22] * data[i-23];
  85294. case 22: sum += qlp_coeff[21] * data[i-22];
  85295. case 21: sum += qlp_coeff[20] * data[i-21];
  85296. case 20: sum += qlp_coeff[19] * data[i-20];
  85297. case 19: sum += qlp_coeff[18] * data[i-19];
  85298. case 18: sum += qlp_coeff[17] * data[i-18];
  85299. case 17: sum += qlp_coeff[16] * data[i-17];
  85300. case 16: sum += qlp_coeff[15] * data[i-16];
  85301. case 15: sum += qlp_coeff[14] * data[i-15];
  85302. case 14: sum += qlp_coeff[13] * data[i-14];
  85303. case 13: sum += qlp_coeff[12] * data[i-13];
  85304. sum += qlp_coeff[11] * data[i-12];
  85305. sum += qlp_coeff[10] * data[i-11];
  85306. sum += qlp_coeff[ 9] * data[i-10];
  85307. sum += qlp_coeff[ 8] * data[i- 9];
  85308. sum += qlp_coeff[ 7] * data[i- 8];
  85309. sum += qlp_coeff[ 6] * data[i- 7];
  85310. sum += qlp_coeff[ 5] * data[i- 6];
  85311. sum += qlp_coeff[ 4] * data[i- 5];
  85312. sum += qlp_coeff[ 3] * data[i- 4];
  85313. sum += qlp_coeff[ 2] * data[i- 3];
  85314. sum += qlp_coeff[ 1] * data[i- 2];
  85315. sum += qlp_coeff[ 0] * data[i- 1];
  85316. }
  85317. residual[i] = data[i] - (sum >> lp_quantization);
  85318. }
  85319. }
  85320. }
  85321. #endif
  85322. 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[])
  85323. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85324. {
  85325. unsigned i, j;
  85326. FLAC__int64 sum;
  85327. const FLAC__int32 *history;
  85328. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85329. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85330. for(i=0;i<order;i++)
  85331. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85332. fprintf(stderr,"\n");
  85333. #endif
  85334. FLAC__ASSERT(order > 0);
  85335. for(i = 0; i < data_len; i++) {
  85336. sum = 0;
  85337. history = data;
  85338. for(j = 0; j < order; j++)
  85339. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85340. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85341. #if defined _MSC_VER
  85342. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85343. #else
  85344. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85345. #endif
  85346. break;
  85347. }
  85348. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85349. #if defined _MSC_VER
  85350. 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));
  85351. #else
  85352. 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)));
  85353. #endif
  85354. break;
  85355. }
  85356. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85357. }
  85358. }
  85359. #else /* fully unrolled version for normal use */
  85360. {
  85361. int i;
  85362. FLAC__int64 sum;
  85363. FLAC__ASSERT(order > 0);
  85364. FLAC__ASSERT(order <= 32);
  85365. if(order <= 12) {
  85366. if(order > 8) {
  85367. if(order > 10) {
  85368. if(order == 12) {
  85369. for(i = 0; i < (int)data_len; i++) {
  85370. sum = 0;
  85371. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85372. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85373. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85374. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85375. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85376. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85377. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85378. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85379. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85380. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85381. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85382. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85383. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85384. }
  85385. }
  85386. else { /* order == 11 */
  85387. for(i = 0; i < (int)data_len; i++) {
  85388. sum = 0;
  85389. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85390. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85391. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85392. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85393. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85394. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85395. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85396. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85397. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85398. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85399. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85400. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85401. }
  85402. }
  85403. }
  85404. else {
  85405. if(order == 10) {
  85406. for(i = 0; i < (int)data_len; i++) {
  85407. sum = 0;
  85408. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85409. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85410. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85411. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85412. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85413. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85414. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85415. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85416. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85417. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85418. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85419. }
  85420. }
  85421. else { /* order == 9 */
  85422. for(i = 0; i < (int)data_len; i++) {
  85423. sum = 0;
  85424. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85425. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  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. }
  85438. else if(order > 4) {
  85439. if(order > 6) {
  85440. if(order == 8) {
  85441. for(i = 0; i < (int)data_len; i++) {
  85442. sum = 0;
  85443. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85444. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85445. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85446. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85447. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85448. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85449. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85450. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85451. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85452. }
  85453. }
  85454. else { /* order == 7 */
  85455. for(i = 0; i < (int)data_len; i++) {
  85456. sum = 0;
  85457. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85458. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85459. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85460. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85461. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85462. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85463. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85464. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85465. }
  85466. }
  85467. }
  85468. else {
  85469. if(order == 6) {
  85470. for(i = 0; i < (int)data_len; i++) {
  85471. sum = 0;
  85472. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85473. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85474. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85475. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85476. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85477. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85478. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85479. }
  85480. }
  85481. else { /* order == 5 */
  85482. for(i = 0; i < (int)data_len; i++) {
  85483. sum = 0;
  85484. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85485. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85486. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85487. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85488. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85489. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85490. }
  85491. }
  85492. }
  85493. }
  85494. else {
  85495. if(order > 2) {
  85496. if(order == 4) {
  85497. for(i = 0; i < (int)data_len; i++) {
  85498. sum = 0;
  85499. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85500. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85501. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85502. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85503. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85504. }
  85505. }
  85506. else { /* order == 3 */
  85507. for(i = 0; i < (int)data_len; i++) {
  85508. sum = 0;
  85509. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85510. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85511. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85512. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85513. }
  85514. }
  85515. }
  85516. else {
  85517. if(order == 2) {
  85518. for(i = 0; i < (int)data_len; i++) {
  85519. sum = 0;
  85520. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85521. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85522. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85523. }
  85524. }
  85525. else { /* order == 1 */
  85526. for(i = 0; i < (int)data_len; i++)
  85527. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  85528. }
  85529. }
  85530. }
  85531. }
  85532. else { /* order > 12 */
  85533. for(i = 0; i < (int)data_len; i++) {
  85534. sum = 0;
  85535. switch(order) {
  85536. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  85537. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  85538. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  85539. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  85540. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  85541. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  85542. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  85543. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  85544. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  85545. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  85546. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  85547. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  85548. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  85549. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  85550. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  85551. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  85552. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  85553. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  85554. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  85555. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  85556. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85557. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85558. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  85559. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  85560. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  85561. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  85562. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  85563. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  85564. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  85565. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  85566. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  85567. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  85568. }
  85569. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85570. }
  85571. }
  85572. }
  85573. #endif
  85574. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85575. 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[])
  85576. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85577. {
  85578. FLAC__int64 sumo;
  85579. unsigned i, j;
  85580. FLAC__int32 sum;
  85581. const FLAC__int32 *r = residual, *history;
  85582. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85583. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85584. for(i=0;i<order;i++)
  85585. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85586. fprintf(stderr,"\n");
  85587. #endif
  85588. FLAC__ASSERT(order > 0);
  85589. for(i = 0; i < data_len; i++) {
  85590. sumo = 0;
  85591. sum = 0;
  85592. history = data;
  85593. for(j = 0; j < order; j++) {
  85594. sum += qlp_coeff[j] * (*(--history));
  85595. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85596. #if defined _MSC_VER
  85597. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85598. 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);
  85599. #else
  85600. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85601. 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);
  85602. #endif
  85603. }
  85604. *(data++) = *(r++) + (sum >> lp_quantization);
  85605. }
  85606. }
  85607. #else /* fully unrolled version for normal use */
  85608. {
  85609. int i;
  85610. FLAC__int32 sum;
  85611. FLAC__ASSERT(order > 0);
  85612. FLAC__ASSERT(order <= 32);
  85613. if(order <= 12) {
  85614. if(order > 8) {
  85615. if(order > 10) {
  85616. if(order == 12) {
  85617. for(i = 0; i < (int)data_len; i++) {
  85618. sum = 0;
  85619. sum += qlp_coeff[11] * data[i-12];
  85620. sum += qlp_coeff[10] * data[i-11];
  85621. sum += qlp_coeff[9] * data[i-10];
  85622. sum += qlp_coeff[8] * data[i-9];
  85623. sum += qlp_coeff[7] * data[i-8];
  85624. sum += qlp_coeff[6] * data[i-7];
  85625. sum += qlp_coeff[5] * data[i-6];
  85626. sum += qlp_coeff[4] * data[i-5];
  85627. sum += qlp_coeff[3] * data[i-4];
  85628. sum += qlp_coeff[2] * data[i-3];
  85629. sum += qlp_coeff[1] * data[i-2];
  85630. sum += qlp_coeff[0] * data[i-1];
  85631. data[i] = residual[i] + (sum >> lp_quantization);
  85632. }
  85633. }
  85634. else { /* order == 11 */
  85635. for(i = 0; i < (int)data_len; i++) {
  85636. sum = 0;
  85637. sum += qlp_coeff[10] * data[i-11];
  85638. sum += qlp_coeff[9] * data[i-10];
  85639. sum += qlp_coeff[8] * data[i-9];
  85640. sum += qlp_coeff[7] * data[i-8];
  85641. sum += qlp_coeff[6] * data[i-7];
  85642. sum += qlp_coeff[5] * data[i-6];
  85643. sum += qlp_coeff[4] * data[i-5];
  85644. sum += qlp_coeff[3] * data[i-4];
  85645. sum += qlp_coeff[2] * data[i-3];
  85646. sum += qlp_coeff[1] * data[i-2];
  85647. sum += qlp_coeff[0] * data[i-1];
  85648. data[i] = residual[i] + (sum >> lp_quantization);
  85649. }
  85650. }
  85651. }
  85652. else {
  85653. if(order == 10) {
  85654. for(i = 0; i < (int)data_len; i++) {
  85655. sum = 0;
  85656. sum += qlp_coeff[9] * data[i-10];
  85657. sum += qlp_coeff[8] * data[i-9];
  85658. sum += qlp_coeff[7] * data[i-8];
  85659. sum += qlp_coeff[6] * data[i-7];
  85660. sum += qlp_coeff[5] * data[i-6];
  85661. sum += qlp_coeff[4] * data[i-5];
  85662. sum += qlp_coeff[3] * data[i-4];
  85663. sum += qlp_coeff[2] * data[i-3];
  85664. sum += qlp_coeff[1] * data[i-2];
  85665. sum += qlp_coeff[0] * data[i-1];
  85666. data[i] = residual[i] + (sum >> lp_quantization);
  85667. }
  85668. }
  85669. else { /* order == 9 */
  85670. for(i = 0; i < (int)data_len; i++) {
  85671. sum = 0;
  85672. sum += qlp_coeff[8] * data[i-9];
  85673. sum += qlp_coeff[7] * data[i-8];
  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. }
  85686. else if(order > 4) {
  85687. if(order > 6) {
  85688. if(order == 8) {
  85689. for(i = 0; i < (int)data_len; i++) {
  85690. sum = 0;
  85691. sum += qlp_coeff[7] * data[i-8];
  85692. sum += qlp_coeff[6] * data[i-7];
  85693. sum += qlp_coeff[5] * data[i-6];
  85694. sum += qlp_coeff[4] * data[i-5];
  85695. sum += qlp_coeff[3] * data[i-4];
  85696. sum += qlp_coeff[2] * data[i-3];
  85697. sum += qlp_coeff[1] * data[i-2];
  85698. sum += qlp_coeff[0] * data[i-1];
  85699. data[i] = residual[i] + (sum >> lp_quantization);
  85700. }
  85701. }
  85702. else { /* order == 7 */
  85703. for(i = 0; i < (int)data_len; i++) {
  85704. sum = 0;
  85705. sum += qlp_coeff[6] * data[i-7];
  85706. sum += qlp_coeff[5] * data[i-6];
  85707. sum += qlp_coeff[4] * data[i-5];
  85708. sum += qlp_coeff[3] * data[i-4];
  85709. sum += qlp_coeff[2] * data[i-3];
  85710. sum += qlp_coeff[1] * data[i-2];
  85711. sum += qlp_coeff[0] * data[i-1];
  85712. data[i] = residual[i] + (sum >> lp_quantization);
  85713. }
  85714. }
  85715. }
  85716. else {
  85717. if(order == 6) {
  85718. for(i = 0; i < (int)data_len; i++) {
  85719. sum = 0;
  85720. sum += qlp_coeff[5] * data[i-6];
  85721. sum += qlp_coeff[4] * data[i-5];
  85722. sum += qlp_coeff[3] * data[i-4];
  85723. sum += qlp_coeff[2] * data[i-3];
  85724. sum += qlp_coeff[1] * data[i-2];
  85725. sum += qlp_coeff[0] * data[i-1];
  85726. data[i] = residual[i] + (sum >> lp_quantization);
  85727. }
  85728. }
  85729. else { /* order == 5 */
  85730. for(i = 0; i < (int)data_len; i++) {
  85731. sum = 0;
  85732. sum += qlp_coeff[4] * data[i-5];
  85733. sum += qlp_coeff[3] * data[i-4];
  85734. sum += qlp_coeff[2] * data[i-3];
  85735. sum += qlp_coeff[1] * data[i-2];
  85736. sum += qlp_coeff[0] * data[i-1];
  85737. data[i] = residual[i] + (sum >> lp_quantization);
  85738. }
  85739. }
  85740. }
  85741. }
  85742. else {
  85743. if(order > 2) {
  85744. if(order == 4) {
  85745. for(i = 0; i < (int)data_len; i++) {
  85746. sum = 0;
  85747. sum += qlp_coeff[3] * data[i-4];
  85748. sum += qlp_coeff[2] * data[i-3];
  85749. sum += qlp_coeff[1] * data[i-2];
  85750. sum += qlp_coeff[0] * data[i-1];
  85751. data[i] = residual[i] + (sum >> lp_quantization);
  85752. }
  85753. }
  85754. else { /* order == 3 */
  85755. for(i = 0; i < (int)data_len; i++) {
  85756. sum = 0;
  85757. sum += qlp_coeff[2] * data[i-3];
  85758. sum += qlp_coeff[1] * data[i-2];
  85759. sum += qlp_coeff[0] * data[i-1];
  85760. data[i] = residual[i] + (sum >> lp_quantization);
  85761. }
  85762. }
  85763. }
  85764. else {
  85765. if(order == 2) {
  85766. for(i = 0; i < (int)data_len; i++) {
  85767. sum = 0;
  85768. sum += qlp_coeff[1] * data[i-2];
  85769. sum += qlp_coeff[0] * data[i-1];
  85770. data[i] = residual[i] + (sum >> lp_quantization);
  85771. }
  85772. }
  85773. else { /* order == 1 */
  85774. for(i = 0; i < (int)data_len; i++)
  85775. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85776. }
  85777. }
  85778. }
  85779. }
  85780. else { /* order > 12 */
  85781. for(i = 0; i < (int)data_len; i++) {
  85782. sum = 0;
  85783. switch(order) {
  85784. case 32: sum += qlp_coeff[31] * data[i-32];
  85785. case 31: sum += qlp_coeff[30] * data[i-31];
  85786. case 30: sum += qlp_coeff[29] * data[i-30];
  85787. case 29: sum += qlp_coeff[28] * data[i-29];
  85788. case 28: sum += qlp_coeff[27] * data[i-28];
  85789. case 27: sum += qlp_coeff[26] * data[i-27];
  85790. case 26: sum += qlp_coeff[25] * data[i-26];
  85791. case 25: sum += qlp_coeff[24] * data[i-25];
  85792. case 24: sum += qlp_coeff[23] * data[i-24];
  85793. case 23: sum += qlp_coeff[22] * data[i-23];
  85794. case 22: sum += qlp_coeff[21] * data[i-22];
  85795. case 21: sum += qlp_coeff[20] * data[i-21];
  85796. case 20: sum += qlp_coeff[19] * data[i-20];
  85797. case 19: sum += qlp_coeff[18] * data[i-19];
  85798. case 18: sum += qlp_coeff[17] * data[i-18];
  85799. case 17: sum += qlp_coeff[16] * data[i-17];
  85800. case 16: sum += qlp_coeff[15] * data[i-16];
  85801. case 15: sum += qlp_coeff[14] * data[i-15];
  85802. case 14: sum += qlp_coeff[13] * data[i-14];
  85803. case 13: sum += qlp_coeff[12] * data[i-13];
  85804. sum += qlp_coeff[11] * data[i-12];
  85805. sum += qlp_coeff[10] * data[i-11];
  85806. sum += qlp_coeff[ 9] * data[i-10];
  85807. sum += qlp_coeff[ 8] * data[i- 9];
  85808. sum += qlp_coeff[ 7] * data[i- 8];
  85809. sum += qlp_coeff[ 6] * data[i- 7];
  85810. sum += qlp_coeff[ 5] * data[i- 6];
  85811. sum += qlp_coeff[ 4] * data[i- 5];
  85812. sum += qlp_coeff[ 3] * data[i- 4];
  85813. sum += qlp_coeff[ 2] * data[i- 3];
  85814. sum += qlp_coeff[ 1] * data[i- 2];
  85815. sum += qlp_coeff[ 0] * data[i- 1];
  85816. }
  85817. data[i] = residual[i] + (sum >> lp_quantization);
  85818. }
  85819. }
  85820. }
  85821. #endif
  85822. 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[])
  85823. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85824. {
  85825. unsigned i, j;
  85826. FLAC__int64 sum;
  85827. const FLAC__int32 *r = residual, *history;
  85828. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85829. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85830. for(i=0;i<order;i++)
  85831. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85832. fprintf(stderr,"\n");
  85833. #endif
  85834. FLAC__ASSERT(order > 0);
  85835. for(i = 0; i < data_len; i++) {
  85836. sum = 0;
  85837. history = data;
  85838. for(j = 0; j < order; j++)
  85839. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85840. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85841. #ifdef _MSC_VER
  85842. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85843. #else
  85844. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85845. #endif
  85846. break;
  85847. }
  85848. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  85849. #ifdef _MSC_VER
  85850. 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));
  85851. #else
  85852. 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)));
  85853. #endif
  85854. break;
  85855. }
  85856. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  85857. }
  85858. }
  85859. #else /* fully unrolled version for normal use */
  85860. {
  85861. int i;
  85862. FLAC__int64 sum;
  85863. FLAC__ASSERT(order > 0);
  85864. FLAC__ASSERT(order <= 32);
  85865. if(order <= 12) {
  85866. if(order > 8) {
  85867. if(order > 10) {
  85868. if(order == 12) {
  85869. for(i = 0; i < (int)data_len; i++) {
  85870. sum = 0;
  85871. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85872. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85873. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85874. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85875. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85876. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85877. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85878. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85879. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85880. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85881. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85882. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85883. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85884. }
  85885. }
  85886. else { /* order == 11 */
  85887. for(i = 0; i < (int)data_len; i++) {
  85888. sum = 0;
  85889. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85890. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85891. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85892. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85893. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85894. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85895. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85896. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85897. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85898. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85899. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85900. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85901. }
  85902. }
  85903. }
  85904. else {
  85905. if(order == 10) {
  85906. for(i = 0; i < (int)data_len; i++) {
  85907. sum = 0;
  85908. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85909. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85910. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85911. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85912. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85913. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85914. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85915. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85916. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85917. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85918. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85919. }
  85920. }
  85921. else { /* order == 9 */
  85922. for(i = 0; i < (int)data_len; i++) {
  85923. sum = 0;
  85924. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85925. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  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. }
  85938. else if(order > 4) {
  85939. if(order > 6) {
  85940. if(order == 8) {
  85941. for(i = 0; i < (int)data_len; i++) {
  85942. sum = 0;
  85943. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85944. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85945. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85946. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85947. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85948. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85949. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85950. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85951. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85952. }
  85953. }
  85954. else { /* order == 7 */
  85955. for(i = 0; i < (int)data_len; i++) {
  85956. sum = 0;
  85957. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85958. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85959. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85960. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85961. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85962. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85963. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85964. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85965. }
  85966. }
  85967. }
  85968. else {
  85969. if(order == 6) {
  85970. for(i = 0; i < (int)data_len; i++) {
  85971. sum = 0;
  85972. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85973. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85974. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85975. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85976. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85977. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85978. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85979. }
  85980. }
  85981. else { /* order == 5 */
  85982. for(i = 0; i < (int)data_len; i++) {
  85983. sum = 0;
  85984. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85985. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85986. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85987. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85988. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85989. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  85990. }
  85991. }
  85992. }
  85993. }
  85994. else {
  85995. if(order > 2) {
  85996. if(order == 4) {
  85997. for(i = 0; i < (int)data_len; i++) {
  85998. sum = 0;
  85999. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86000. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86001. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86002. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86003. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86004. }
  86005. }
  86006. else { /* order == 3 */
  86007. for(i = 0; i < (int)data_len; i++) {
  86008. sum = 0;
  86009. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86010. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86011. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86012. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86013. }
  86014. }
  86015. }
  86016. else {
  86017. if(order == 2) {
  86018. for(i = 0; i < (int)data_len; i++) {
  86019. sum = 0;
  86020. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86021. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86022. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86023. }
  86024. }
  86025. else { /* order == 1 */
  86026. for(i = 0; i < (int)data_len; i++)
  86027. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86028. }
  86029. }
  86030. }
  86031. }
  86032. else { /* order > 12 */
  86033. for(i = 0; i < (int)data_len; i++) {
  86034. sum = 0;
  86035. switch(order) {
  86036. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86037. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86038. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86039. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86040. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86041. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86042. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86043. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86044. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86045. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86046. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86047. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86048. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86049. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86050. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86051. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86052. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86053. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86054. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86055. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86056. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86057. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86058. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86059. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86060. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86061. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86062. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86063. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86064. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86065. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86066. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86067. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86068. }
  86069. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86070. }
  86071. }
  86072. }
  86073. #endif
  86074. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86075. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86076. {
  86077. FLAC__double error_scale;
  86078. FLAC__ASSERT(total_samples > 0);
  86079. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86080. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86081. }
  86082. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86083. {
  86084. if(lpc_error > 0.0) {
  86085. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86086. if(bps >= 0.0)
  86087. return bps;
  86088. else
  86089. return 0.0;
  86090. }
  86091. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86092. return 1e32;
  86093. }
  86094. else {
  86095. return 0.0;
  86096. }
  86097. }
  86098. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86099. {
  86100. 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 */
  86101. FLAC__double bits, best_bits, error_scale;
  86102. FLAC__ASSERT(max_order > 0);
  86103. FLAC__ASSERT(total_samples > 0);
  86104. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86105. best_index = 0;
  86106. best_bits = (unsigned)(-1);
  86107. for(index = 0, order = 1; index < max_order; index++, order++) {
  86108. 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);
  86109. if(bits < best_bits) {
  86110. best_index = index;
  86111. best_bits = bits;
  86112. }
  86113. }
  86114. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86115. }
  86116. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86117. #endif
  86118. /*** End of inlined file: lpc_flac.c ***/
  86119. /*** Start of inlined file: md5.c ***/
  86120. /*** Start of inlined file: juce_FlacHeader.h ***/
  86121. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86122. // tasks..
  86123. #define VERSION "1.2.1"
  86124. #define FLAC__NO_DLL 1
  86125. #if JUCE_MSVC
  86126. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86127. #endif
  86128. #if JUCE_MAC
  86129. #define FLAC__SYS_DARWIN 1
  86130. #endif
  86131. /*** End of inlined file: juce_FlacHeader.h ***/
  86132. #if JUCE_USE_FLAC
  86133. #if HAVE_CONFIG_H
  86134. # include <config.h>
  86135. #endif
  86136. #include <stdlib.h> /* for malloc() */
  86137. #include <string.h> /* for memcpy() */
  86138. /*** Start of inlined file: md5.h ***/
  86139. #ifndef FLAC__PRIVATE__MD5_H
  86140. #define FLAC__PRIVATE__MD5_H
  86141. typedef struct {
  86142. FLAC__uint32 in[16];
  86143. FLAC__uint32 buf[4];
  86144. FLAC__uint32 bytes[2];
  86145. FLAC__byte *internal_buf;
  86146. size_t capacity;
  86147. } FLAC__MD5Context;
  86148. void FLAC__MD5Init(FLAC__MD5Context *context);
  86149. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86150. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86151. #endif
  86152. /*** End of inlined file: md5.h ***/
  86153. #ifndef FLaC__INLINE
  86154. #define FLaC__INLINE
  86155. #endif
  86156. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86157. #define F2(x, y, z) F1(z, x, y)
  86158. #define F3(x, y, z) (x ^ y ^ z)
  86159. #define F4(x, y, z) (y ^ (x | ~z))
  86160. #define MD5STEP(f,w,x,y,z,in,s) \
  86161. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86162. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86163. {
  86164. register FLAC__uint32 a, b, c, d;
  86165. a = buf[0];
  86166. b = buf[1];
  86167. c = buf[2];
  86168. d = buf[3];
  86169. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86170. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86171. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86172. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86173. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86174. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86175. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86176. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86177. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86178. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86179. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86180. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86181. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86182. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86183. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86184. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86185. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86186. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86187. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86188. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86189. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86190. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86191. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86192. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86193. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86194. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86195. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86196. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86197. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86198. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86199. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86200. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86201. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86202. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86203. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86204. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86205. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86206. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86207. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86208. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86209. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86210. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86211. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86212. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86213. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86214. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86215. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86216. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86217. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86218. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86219. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86220. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86221. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86222. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86223. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86224. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86225. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86226. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86227. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86228. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86229. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86230. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86231. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86232. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86233. buf[0] += a;
  86234. buf[1] += b;
  86235. buf[2] += c;
  86236. buf[3] += d;
  86237. }
  86238. #if WORDS_BIGENDIAN
  86239. //@@@@@@ OPT: use bswap/intrinsics
  86240. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86241. {
  86242. register FLAC__uint32 x;
  86243. do {
  86244. x = *buf;
  86245. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86246. *buf++ = (x >> 16) | (x << 16);
  86247. } while (--words);
  86248. }
  86249. static void byteSwapX16(FLAC__uint32 *buf)
  86250. {
  86251. register FLAC__uint32 x;
  86252. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86253. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86254. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86255. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86256. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86257. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86258. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86259. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86260. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86261. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86262. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86263. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86264. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86265. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86266. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86267. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86268. }
  86269. #else
  86270. #define byteSwap(buf, words)
  86271. #define byteSwapX16(buf)
  86272. #endif
  86273. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86274. {
  86275. FLAC__uint32 t;
  86276. t = ctx->bytes[0];
  86277. if ((ctx->bytes[0] = t + len) < t)
  86278. ctx->bytes[1]++; /* Carry from low to high */
  86279. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86280. if (t > len) {
  86281. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86282. return;
  86283. }
  86284. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86285. byteSwapX16(ctx->in);
  86286. FLAC__MD5Transform(ctx->buf, ctx->in);
  86287. buf += t;
  86288. len -= t;
  86289. while (len >= 64) {
  86290. memcpy(ctx->in, buf, 64);
  86291. byteSwapX16(ctx->in);
  86292. FLAC__MD5Transform(ctx->buf, ctx->in);
  86293. buf += 64;
  86294. len -= 64;
  86295. }
  86296. memcpy(ctx->in, buf, len);
  86297. }
  86298. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86299. {
  86300. ctx->buf[0] = 0x67452301;
  86301. ctx->buf[1] = 0xefcdab89;
  86302. ctx->buf[2] = 0x98badcfe;
  86303. ctx->buf[3] = 0x10325476;
  86304. ctx->bytes[0] = 0;
  86305. ctx->bytes[1] = 0;
  86306. ctx->internal_buf = 0;
  86307. ctx->capacity = 0;
  86308. }
  86309. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86310. {
  86311. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86312. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86313. *p++ = 0x80;
  86314. count = 56 - 1 - count;
  86315. if (count < 0) { /* Padding forces an extra block */
  86316. memset(p, 0, count + 8);
  86317. byteSwapX16(ctx->in);
  86318. FLAC__MD5Transform(ctx->buf, ctx->in);
  86319. p = (FLAC__byte *)ctx->in;
  86320. count = 56;
  86321. }
  86322. memset(p, 0, count);
  86323. byteSwap(ctx->in, 14);
  86324. ctx->in[14] = ctx->bytes[0] << 3;
  86325. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86326. FLAC__MD5Transform(ctx->buf, ctx->in);
  86327. byteSwap(ctx->buf, 4);
  86328. memcpy(digest, ctx->buf, 16);
  86329. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86330. if(0 != ctx->internal_buf) {
  86331. free(ctx->internal_buf);
  86332. ctx->internal_buf = 0;
  86333. ctx->capacity = 0;
  86334. }
  86335. }
  86336. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86337. {
  86338. unsigned channel, sample;
  86339. register FLAC__int32 a_word;
  86340. register FLAC__byte *buf_ = buf;
  86341. #if WORDS_BIGENDIAN
  86342. #else
  86343. if(channels == 2 && bytes_per_sample == 2) {
  86344. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86345. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86346. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86347. *buf1_ = (FLAC__int16)signal[1][sample];
  86348. }
  86349. else if(channels == 1 && bytes_per_sample == 2) {
  86350. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86351. for(sample = 0; sample < samples; sample++)
  86352. *buf1_++ = (FLAC__int16)signal[0][sample];
  86353. }
  86354. else
  86355. #endif
  86356. if(bytes_per_sample == 2) {
  86357. if(channels == 2) {
  86358. for(sample = 0; sample < samples; sample++) {
  86359. a_word = signal[0][sample];
  86360. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86361. *buf_++ = (FLAC__byte)a_word;
  86362. a_word = signal[1][sample];
  86363. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86364. *buf_++ = (FLAC__byte)a_word;
  86365. }
  86366. }
  86367. else if(channels == 1) {
  86368. for(sample = 0; sample < samples; sample++) {
  86369. a_word = signal[0][sample];
  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;
  86380. }
  86381. }
  86382. }
  86383. }
  86384. else if(bytes_per_sample == 3) {
  86385. if(channels == 2) {
  86386. for(sample = 0; sample < samples; sample++) {
  86387. a_word = signal[0][sample];
  86388. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86389. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86390. *buf_++ = (FLAC__byte)a_word;
  86391. a_word = signal[1][sample];
  86392. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86393. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86394. *buf_++ = (FLAC__byte)a_word;
  86395. }
  86396. }
  86397. else if(channels == 1) {
  86398. for(sample = 0; sample < samples; sample++) {
  86399. a_word = signal[0][sample];
  86400. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86401. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86402. *buf_++ = (FLAC__byte)a_word;
  86403. }
  86404. }
  86405. else {
  86406. for(sample = 0; sample < samples; sample++) {
  86407. for(channel = 0; channel < channels; channel++) {
  86408. a_word = signal[channel][sample];
  86409. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86410. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86411. *buf_++ = (FLAC__byte)a_word;
  86412. }
  86413. }
  86414. }
  86415. }
  86416. else if(bytes_per_sample == 1) {
  86417. if(channels == 2) {
  86418. for(sample = 0; sample < samples; sample++) {
  86419. a_word = signal[0][sample];
  86420. *buf_++ = (FLAC__byte)a_word;
  86421. a_word = signal[1][sample];
  86422. *buf_++ = (FLAC__byte)a_word;
  86423. }
  86424. }
  86425. else if(channels == 1) {
  86426. for(sample = 0; sample < samples; sample++) {
  86427. a_word = signal[0][sample];
  86428. *buf_++ = (FLAC__byte)a_word;
  86429. }
  86430. }
  86431. else {
  86432. for(sample = 0; sample < samples; sample++) {
  86433. for(channel = 0; channel < channels; channel++) {
  86434. a_word = signal[channel][sample];
  86435. *buf_++ = (FLAC__byte)a_word;
  86436. }
  86437. }
  86438. }
  86439. }
  86440. else { /* bytes_per_sample == 4, maybe optimize more later */
  86441. for(sample = 0; sample < samples; sample++) {
  86442. for(channel = 0; channel < channels; channel++) {
  86443. a_word = signal[channel][sample];
  86444. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86445. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86446. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86447. *buf_++ = (FLAC__byte)a_word;
  86448. }
  86449. }
  86450. }
  86451. }
  86452. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86453. {
  86454. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86455. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86456. return false;
  86457. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86458. return false;
  86459. if(ctx->capacity < bytes_needed) {
  86460. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86461. if(0 == tmp) {
  86462. free(ctx->internal_buf);
  86463. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86464. return false;
  86465. }
  86466. ctx->internal_buf = tmp;
  86467. ctx->capacity = bytes_needed;
  86468. }
  86469. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86470. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86471. return true;
  86472. }
  86473. #endif
  86474. /*** End of inlined file: md5.c ***/
  86475. /*** Start of inlined file: memory.c ***/
  86476. /*** Start of inlined file: juce_FlacHeader.h ***/
  86477. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86478. // tasks..
  86479. #define VERSION "1.2.1"
  86480. #define FLAC__NO_DLL 1
  86481. #if JUCE_MSVC
  86482. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86483. #endif
  86484. #if JUCE_MAC
  86485. #define FLAC__SYS_DARWIN 1
  86486. #endif
  86487. /*** End of inlined file: juce_FlacHeader.h ***/
  86488. #if JUCE_USE_FLAC
  86489. #if HAVE_CONFIG_H
  86490. # include <config.h>
  86491. #endif
  86492. /*** Start of inlined file: memory.h ***/
  86493. #ifndef FLAC__PRIVATE__MEMORY_H
  86494. #define FLAC__PRIVATE__MEMORY_H
  86495. #ifdef HAVE_CONFIG_H
  86496. #include <config.h>
  86497. #endif
  86498. #include <stdlib.h> /* for size_t */
  86499. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  86500. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  86501. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  86502. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  86503. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  86504. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86505. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  86506. #endif
  86507. #endif
  86508. /*** End of inlined file: memory.h ***/
  86509. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  86510. {
  86511. void *x;
  86512. FLAC__ASSERT(0 != aligned_address);
  86513. #ifdef FLAC__ALIGN_MALLOC_DATA
  86514. x = safe_malloc_add_2op_(bytes, /*+*/31);
  86515. #ifdef SIZEOF_VOIDP
  86516. #if SIZEOF_VOIDP == 4
  86517. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86518. #elif SIZEOF_VOIDP == 8
  86519. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86520. #else
  86521. # error Unsupported sizeof(void*)
  86522. #endif
  86523. #else
  86524. if(sizeof(void*) == sizeof(unsigned))
  86525. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  86526. else if(sizeof(void*) == sizeof(FLAC__uint64))
  86527. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  86528. else
  86529. return 0;
  86530. #endif
  86531. #else
  86532. x = safe_malloc_(bytes);
  86533. *aligned_address = x;
  86534. #endif
  86535. return x;
  86536. }
  86537. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  86538. {
  86539. FLAC__int32 *pu; /* unaligned pointer */
  86540. union { /* union needed to comply with C99 pointer aliasing rules */
  86541. FLAC__int32 *pa; /* aligned pointer */
  86542. void *pv; /* aligned pointer alias */
  86543. } u;
  86544. FLAC__ASSERT(elements > 0);
  86545. FLAC__ASSERT(0 != unaligned_pointer);
  86546. FLAC__ASSERT(0 != aligned_pointer);
  86547. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86548. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  86549. if(0 == pu) {
  86550. return false;
  86551. }
  86552. else {
  86553. if(*unaligned_pointer != 0)
  86554. free(*unaligned_pointer);
  86555. *unaligned_pointer = pu;
  86556. *aligned_pointer = u.pa;
  86557. return true;
  86558. }
  86559. }
  86560. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  86561. {
  86562. FLAC__uint32 *pu; /* unaligned pointer */
  86563. union { /* union needed to comply with C99 pointer aliasing rules */
  86564. FLAC__uint32 *pa; /* aligned pointer */
  86565. void *pv; /* aligned pointer alias */
  86566. } u;
  86567. FLAC__ASSERT(elements > 0);
  86568. FLAC__ASSERT(0 != unaligned_pointer);
  86569. FLAC__ASSERT(0 != aligned_pointer);
  86570. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86571. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86572. if(0 == pu) {
  86573. return false;
  86574. }
  86575. else {
  86576. if(*unaligned_pointer != 0)
  86577. free(*unaligned_pointer);
  86578. *unaligned_pointer = pu;
  86579. *aligned_pointer = u.pa;
  86580. return true;
  86581. }
  86582. }
  86583. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  86584. {
  86585. FLAC__uint64 *pu; /* unaligned pointer */
  86586. union { /* union needed to comply with C99 pointer aliasing rules */
  86587. FLAC__uint64 *pa; /* aligned pointer */
  86588. void *pv; /* aligned pointer alias */
  86589. } u;
  86590. FLAC__ASSERT(elements > 0);
  86591. FLAC__ASSERT(0 != unaligned_pointer);
  86592. FLAC__ASSERT(0 != aligned_pointer);
  86593. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86594. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86595. if(0 == pu) {
  86596. return false;
  86597. }
  86598. else {
  86599. if(*unaligned_pointer != 0)
  86600. free(*unaligned_pointer);
  86601. *unaligned_pointer = pu;
  86602. *aligned_pointer = u.pa;
  86603. return true;
  86604. }
  86605. }
  86606. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  86607. {
  86608. unsigned *pu; /* unaligned pointer */
  86609. union { /* union needed to comply with C99 pointer aliasing rules */
  86610. unsigned *pa; /* aligned pointer */
  86611. void *pv; /* aligned pointer alias */
  86612. } u;
  86613. FLAC__ASSERT(elements > 0);
  86614. FLAC__ASSERT(0 != unaligned_pointer);
  86615. FLAC__ASSERT(0 != aligned_pointer);
  86616. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86617. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86618. if(0 == pu) {
  86619. return false;
  86620. }
  86621. else {
  86622. if(*unaligned_pointer != 0)
  86623. free(*unaligned_pointer);
  86624. *unaligned_pointer = pu;
  86625. *aligned_pointer = u.pa;
  86626. return true;
  86627. }
  86628. }
  86629. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86630. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  86631. {
  86632. FLAC__real *pu; /* unaligned pointer */
  86633. union { /* union needed to comply with C99 pointer aliasing rules */
  86634. FLAC__real *pa; /* aligned pointer */
  86635. void *pv; /* aligned pointer alias */
  86636. } u;
  86637. FLAC__ASSERT(elements > 0);
  86638. FLAC__ASSERT(0 != unaligned_pointer);
  86639. FLAC__ASSERT(0 != aligned_pointer);
  86640. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  86641. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  86642. if(0 == pu) {
  86643. return false;
  86644. }
  86645. else {
  86646. if(*unaligned_pointer != 0)
  86647. free(*unaligned_pointer);
  86648. *unaligned_pointer = pu;
  86649. *aligned_pointer = u.pa;
  86650. return true;
  86651. }
  86652. }
  86653. #endif
  86654. #endif
  86655. /*** End of inlined file: memory.c ***/
  86656. /*** Start of inlined file: stream_decoder.c ***/
  86657. /*** Start of inlined file: juce_FlacHeader.h ***/
  86658. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86659. // tasks..
  86660. #define VERSION "1.2.1"
  86661. #define FLAC__NO_DLL 1
  86662. #if JUCE_MSVC
  86663. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86664. #endif
  86665. #if JUCE_MAC
  86666. #define FLAC__SYS_DARWIN 1
  86667. #endif
  86668. /*** End of inlined file: juce_FlacHeader.h ***/
  86669. #if JUCE_USE_FLAC
  86670. #if HAVE_CONFIG_H
  86671. # include <config.h>
  86672. #endif
  86673. #if defined _MSC_VER || defined __MINGW32__
  86674. #include <io.h> /* for _setmode() */
  86675. #include <fcntl.h> /* for _O_BINARY */
  86676. #endif
  86677. #if defined __CYGWIN__ || defined __EMX__
  86678. #include <io.h> /* for setmode(), O_BINARY */
  86679. #include <fcntl.h> /* for _O_BINARY */
  86680. #endif
  86681. #include <stdio.h>
  86682. #include <stdlib.h> /* for malloc() */
  86683. #include <string.h> /* for memset/memcpy() */
  86684. #include <sys/stat.h> /* for stat() */
  86685. #include <sys/types.h> /* for off_t */
  86686. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  86687. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  86688. #define fseeko fseek
  86689. #define ftello ftell
  86690. #endif
  86691. #endif
  86692. /*** Start of inlined file: stream_decoder.h ***/
  86693. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  86694. #define FLAC__PROTECTED__STREAM_DECODER_H
  86695. #if FLAC__HAS_OGG
  86696. #include "include/private/ogg_decoder_aspect.h"
  86697. #endif
  86698. typedef struct FLAC__StreamDecoderProtected {
  86699. FLAC__StreamDecoderState state;
  86700. unsigned channels;
  86701. FLAC__ChannelAssignment channel_assignment;
  86702. unsigned bits_per_sample;
  86703. unsigned sample_rate; /* in Hz */
  86704. unsigned blocksize; /* in samples (per channel) */
  86705. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  86706. #if FLAC__HAS_OGG
  86707. FLAC__OggDecoderAspect ogg_decoder_aspect;
  86708. #endif
  86709. } FLAC__StreamDecoderProtected;
  86710. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  86711. #endif
  86712. /*** End of inlined file: stream_decoder.h ***/
  86713. #ifdef max
  86714. #undef max
  86715. #endif
  86716. #define max(a,b) ((a)>(b)?(a):(b))
  86717. #ifdef _MSC_VER
  86718. #define FLAC__U64L(x) x
  86719. #else
  86720. #define FLAC__U64L(x) x##LLU
  86721. #endif
  86722. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  86723. #if FLAC__HAS_OGG
  86724. 1
  86725. #else
  86726. 0
  86727. #endif
  86728. ;
  86729. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  86730. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  86731. static FILE *get_binary_stdin_(void);
  86732. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  86733. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  86734. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  86735. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  86736. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86737. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  86738. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  86739. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  86740. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  86741. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  86742. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  86743. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  86744. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  86745. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86746. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86747. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86748. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  86749. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  86750. 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);
  86751. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  86752. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  86753. #if FLAC__HAS_OGG
  86754. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  86755. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86756. #endif
  86757. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  86758. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  86759. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86760. #if FLAC__HAS_OGG
  86761. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  86762. #endif
  86763. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  86764. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  86765. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  86766. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  86767. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  86768. typedef struct FLAC__StreamDecoderPrivate {
  86769. #if FLAC__HAS_OGG
  86770. FLAC__bool is_ogg;
  86771. #endif
  86772. FLAC__StreamDecoderReadCallback read_callback;
  86773. FLAC__StreamDecoderSeekCallback seek_callback;
  86774. FLAC__StreamDecoderTellCallback tell_callback;
  86775. FLAC__StreamDecoderLengthCallback length_callback;
  86776. FLAC__StreamDecoderEofCallback eof_callback;
  86777. FLAC__StreamDecoderWriteCallback write_callback;
  86778. FLAC__StreamDecoderMetadataCallback metadata_callback;
  86779. FLAC__StreamDecoderErrorCallback error_callback;
  86780. 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[]);
  86781. 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[]);
  86782. 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[]);
  86783. 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[]);
  86784. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  86785. void *client_data;
  86786. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  86787. FLAC__BitReader *input;
  86788. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  86789. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  86790. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  86791. unsigned output_capacity, output_channels;
  86792. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  86793. FLAC__uint64 samples_decoded;
  86794. FLAC__bool has_stream_info, has_seek_table;
  86795. FLAC__StreamMetadata stream_info;
  86796. FLAC__StreamMetadata seek_table;
  86797. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  86798. FLAC__byte *metadata_filter_ids;
  86799. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  86800. FLAC__Frame frame;
  86801. FLAC__bool cached; /* true if there is a byte in lookahead */
  86802. FLAC__CPUInfo cpuinfo;
  86803. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  86804. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  86805. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  86806. 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 */
  86807. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  86808. FLAC__bool is_seeking;
  86809. FLAC__MD5Context md5context;
  86810. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  86811. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  86812. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  86813. FLAC__uint64 target_sample;
  86814. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  86815. #if FLAC__HAS_OGG
  86816. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  86817. #endif
  86818. } FLAC__StreamDecoderPrivate;
  86819. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  86820. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  86821. "FLAC__STREAM_DECODER_READ_METADATA",
  86822. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  86823. "FLAC__STREAM_DECODER_READ_FRAME",
  86824. "FLAC__STREAM_DECODER_END_OF_STREAM",
  86825. "FLAC__STREAM_DECODER_OGG_ERROR",
  86826. "FLAC__STREAM_DECODER_SEEK_ERROR",
  86827. "FLAC__STREAM_DECODER_ABORTED",
  86828. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  86829. "FLAC__STREAM_DECODER_UNINITIALIZED"
  86830. };
  86831. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  86832. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  86833. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  86834. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  86835. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  86836. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  86837. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  86838. };
  86839. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  86840. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  86841. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  86842. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  86843. };
  86844. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  86845. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  86846. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  86847. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  86848. };
  86849. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  86850. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  86851. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  86852. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  86853. };
  86854. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  86855. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  86856. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  86857. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  86858. };
  86859. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  86860. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  86861. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  86862. };
  86863. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  86864. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  86865. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  86866. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  86867. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  86868. };
  86869. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  86870. {
  86871. FLAC__StreamDecoder *decoder;
  86872. unsigned i;
  86873. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  86874. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  86875. if(decoder == 0) {
  86876. return 0;
  86877. }
  86878. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  86879. if(decoder->protected_ == 0) {
  86880. free(decoder);
  86881. return 0;
  86882. }
  86883. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  86884. if(decoder->private_ == 0) {
  86885. free(decoder->protected_);
  86886. free(decoder);
  86887. return 0;
  86888. }
  86889. decoder->private_->input = FLAC__bitreader_new();
  86890. if(decoder->private_->input == 0) {
  86891. free(decoder->private_);
  86892. free(decoder->protected_);
  86893. free(decoder);
  86894. return 0;
  86895. }
  86896. decoder->private_->metadata_filter_ids_capacity = 16;
  86897. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  86898. FLAC__bitreader_delete(decoder->private_->input);
  86899. free(decoder->private_);
  86900. free(decoder->protected_);
  86901. free(decoder);
  86902. return 0;
  86903. }
  86904. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  86905. decoder->private_->output[i] = 0;
  86906. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  86907. }
  86908. decoder->private_->output_capacity = 0;
  86909. decoder->private_->output_channels = 0;
  86910. decoder->private_->has_seek_table = false;
  86911. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  86912. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  86913. decoder->private_->file = 0;
  86914. set_defaults_dec(decoder);
  86915. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  86916. return decoder;
  86917. }
  86918. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  86919. {
  86920. unsigned i;
  86921. FLAC__ASSERT(0 != decoder);
  86922. FLAC__ASSERT(0 != decoder->protected_);
  86923. FLAC__ASSERT(0 != decoder->private_);
  86924. FLAC__ASSERT(0 != decoder->private_->input);
  86925. (void)FLAC__stream_decoder_finish(decoder);
  86926. if(0 != decoder->private_->metadata_filter_ids)
  86927. free(decoder->private_->metadata_filter_ids);
  86928. FLAC__bitreader_delete(decoder->private_->input);
  86929. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  86930. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  86931. free(decoder->private_);
  86932. free(decoder->protected_);
  86933. free(decoder);
  86934. }
  86935. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  86936. FLAC__StreamDecoder *decoder,
  86937. FLAC__StreamDecoderReadCallback read_callback,
  86938. FLAC__StreamDecoderSeekCallback seek_callback,
  86939. FLAC__StreamDecoderTellCallback tell_callback,
  86940. FLAC__StreamDecoderLengthCallback length_callback,
  86941. FLAC__StreamDecoderEofCallback eof_callback,
  86942. FLAC__StreamDecoderWriteCallback write_callback,
  86943. FLAC__StreamDecoderMetadataCallback metadata_callback,
  86944. FLAC__StreamDecoderErrorCallback error_callback,
  86945. void *client_data,
  86946. FLAC__bool is_ogg
  86947. )
  86948. {
  86949. FLAC__ASSERT(0 != decoder);
  86950. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  86951. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  86952. #if !FLAC__HAS_OGG
  86953. if(is_ogg)
  86954. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  86955. #endif
  86956. if(
  86957. 0 == read_callback ||
  86958. 0 == write_callback ||
  86959. 0 == error_callback ||
  86960. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  86961. )
  86962. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  86963. #if FLAC__HAS_OGG
  86964. decoder->private_->is_ogg = is_ogg;
  86965. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  86966. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  86967. #endif
  86968. FLAC__cpu_info(&decoder->private_->cpuinfo);
  86969. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  86970. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  86971. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  86972. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  86973. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  86974. #ifndef FLAC__NO_ASM
  86975. if(decoder->private_->cpuinfo.use_asm) {
  86976. #ifdef FLAC__CPU_IA32
  86977. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  86978. #ifdef FLAC__HAS_NASM
  86979. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  86980. if(decoder->private_->cpuinfo.data.ia32.bswap)
  86981. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  86982. #endif
  86983. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  86984. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  86985. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  86986. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  86987. }
  86988. else {
  86989. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  86990. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  86991. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  86992. }
  86993. #endif
  86994. #elif defined FLAC__CPU_PPC
  86995. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  86996. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  86997. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  86998. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  86999. }
  87000. #endif
  87001. }
  87002. #endif
  87003. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87004. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87005. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87006. }
  87007. decoder->private_->read_callback = read_callback;
  87008. decoder->private_->seek_callback = seek_callback;
  87009. decoder->private_->tell_callback = tell_callback;
  87010. decoder->private_->length_callback = length_callback;
  87011. decoder->private_->eof_callback = eof_callback;
  87012. decoder->private_->write_callback = write_callback;
  87013. decoder->private_->metadata_callback = metadata_callback;
  87014. decoder->private_->error_callback = error_callback;
  87015. decoder->private_->client_data = client_data;
  87016. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87017. decoder->private_->samples_decoded = 0;
  87018. decoder->private_->has_stream_info = false;
  87019. decoder->private_->cached = false;
  87020. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87021. decoder->private_->is_seeking = false;
  87022. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87023. if(!FLAC__stream_decoder_reset(decoder)) {
  87024. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87025. }
  87026. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87027. }
  87028. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87029. FLAC__StreamDecoder *decoder,
  87030. FLAC__StreamDecoderReadCallback read_callback,
  87031. FLAC__StreamDecoderSeekCallback seek_callback,
  87032. FLAC__StreamDecoderTellCallback tell_callback,
  87033. FLAC__StreamDecoderLengthCallback length_callback,
  87034. FLAC__StreamDecoderEofCallback eof_callback,
  87035. FLAC__StreamDecoderWriteCallback write_callback,
  87036. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87037. FLAC__StreamDecoderErrorCallback error_callback,
  87038. void *client_data
  87039. )
  87040. {
  87041. return init_stream_internal_dec(
  87042. decoder,
  87043. read_callback,
  87044. seek_callback,
  87045. tell_callback,
  87046. length_callback,
  87047. eof_callback,
  87048. write_callback,
  87049. metadata_callback,
  87050. error_callback,
  87051. client_data,
  87052. false
  87053. );
  87054. }
  87055. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87056. FLAC__StreamDecoder *decoder,
  87057. FLAC__StreamDecoderReadCallback read_callback,
  87058. FLAC__StreamDecoderSeekCallback seek_callback,
  87059. FLAC__StreamDecoderTellCallback tell_callback,
  87060. FLAC__StreamDecoderLengthCallback length_callback,
  87061. FLAC__StreamDecoderEofCallback eof_callback,
  87062. FLAC__StreamDecoderWriteCallback write_callback,
  87063. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87064. FLAC__StreamDecoderErrorCallback error_callback,
  87065. void *client_data
  87066. )
  87067. {
  87068. return init_stream_internal_dec(
  87069. decoder,
  87070. read_callback,
  87071. seek_callback,
  87072. tell_callback,
  87073. length_callback,
  87074. eof_callback,
  87075. write_callback,
  87076. metadata_callback,
  87077. error_callback,
  87078. client_data,
  87079. true
  87080. );
  87081. }
  87082. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87083. FLAC__StreamDecoder *decoder,
  87084. FILE *file,
  87085. FLAC__StreamDecoderWriteCallback write_callback,
  87086. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87087. FLAC__StreamDecoderErrorCallback error_callback,
  87088. void *client_data,
  87089. FLAC__bool is_ogg
  87090. )
  87091. {
  87092. FLAC__ASSERT(0 != decoder);
  87093. FLAC__ASSERT(0 != file);
  87094. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87095. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87096. if(0 == write_callback || 0 == error_callback)
  87097. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87098. if(file == stdin)
  87099. file = get_binary_stdin_(); /* just to be safe */
  87100. decoder->private_->file = file;
  87101. return init_stream_internal_dec(
  87102. decoder,
  87103. file_read_callback_dec,
  87104. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87105. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87106. decoder->private_->file == stdin? 0: file_length_callback_,
  87107. file_eof_callback_,
  87108. write_callback,
  87109. metadata_callback,
  87110. error_callback,
  87111. client_data,
  87112. is_ogg
  87113. );
  87114. }
  87115. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87116. FLAC__StreamDecoder *decoder,
  87117. FILE *file,
  87118. FLAC__StreamDecoderWriteCallback write_callback,
  87119. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87120. FLAC__StreamDecoderErrorCallback error_callback,
  87121. void *client_data
  87122. )
  87123. {
  87124. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87125. }
  87126. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87127. FLAC__StreamDecoder *decoder,
  87128. FILE *file,
  87129. FLAC__StreamDecoderWriteCallback write_callback,
  87130. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87131. FLAC__StreamDecoderErrorCallback error_callback,
  87132. void *client_data
  87133. )
  87134. {
  87135. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87136. }
  87137. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87138. FLAC__StreamDecoder *decoder,
  87139. const char *filename,
  87140. FLAC__StreamDecoderWriteCallback write_callback,
  87141. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87142. FLAC__StreamDecoderErrorCallback error_callback,
  87143. void *client_data,
  87144. FLAC__bool is_ogg
  87145. )
  87146. {
  87147. FILE *file;
  87148. FLAC__ASSERT(0 != decoder);
  87149. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87150. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87151. if(0 == write_callback || 0 == error_callback)
  87152. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87153. file = filename? fopen(filename, "rb") : stdin;
  87154. if(0 == file)
  87155. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87156. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87157. }
  87158. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87159. FLAC__StreamDecoder *decoder,
  87160. const char *filename,
  87161. FLAC__StreamDecoderWriteCallback write_callback,
  87162. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87163. FLAC__StreamDecoderErrorCallback error_callback,
  87164. void *client_data
  87165. )
  87166. {
  87167. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87168. }
  87169. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87170. FLAC__StreamDecoder *decoder,
  87171. const char *filename,
  87172. FLAC__StreamDecoderWriteCallback write_callback,
  87173. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87174. FLAC__StreamDecoderErrorCallback error_callback,
  87175. void *client_data
  87176. )
  87177. {
  87178. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87179. }
  87180. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87181. {
  87182. FLAC__bool md5_failed = false;
  87183. unsigned i;
  87184. FLAC__ASSERT(0 != decoder);
  87185. FLAC__ASSERT(0 != decoder->private_);
  87186. FLAC__ASSERT(0 != decoder->protected_);
  87187. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87188. return true;
  87189. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87190. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87191. free(decoder->private_->seek_table.data.seek_table.points);
  87192. decoder->private_->seek_table.data.seek_table.points = 0;
  87193. decoder->private_->has_seek_table = false;
  87194. }
  87195. FLAC__bitreader_free(decoder->private_->input);
  87196. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87197. if(0 != decoder->private_->output[i]) {
  87198. free(decoder->private_->output[i]-4);
  87199. decoder->private_->output[i] = 0;
  87200. }
  87201. if(0 != decoder->private_->residual_unaligned[i]) {
  87202. free(decoder->private_->residual_unaligned[i]);
  87203. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87204. }
  87205. }
  87206. decoder->private_->output_capacity = 0;
  87207. decoder->private_->output_channels = 0;
  87208. #if FLAC__HAS_OGG
  87209. if(decoder->private_->is_ogg)
  87210. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87211. #endif
  87212. if(0 != decoder->private_->file) {
  87213. if(decoder->private_->file != stdin)
  87214. fclose(decoder->private_->file);
  87215. decoder->private_->file = 0;
  87216. }
  87217. if(decoder->private_->do_md5_checking) {
  87218. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87219. md5_failed = true;
  87220. }
  87221. decoder->private_->is_seeking = false;
  87222. set_defaults_dec(decoder);
  87223. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87224. return !md5_failed;
  87225. }
  87226. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87227. {
  87228. FLAC__ASSERT(0 != decoder);
  87229. FLAC__ASSERT(0 != decoder->private_);
  87230. FLAC__ASSERT(0 != decoder->protected_);
  87231. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87232. return false;
  87233. #if FLAC__HAS_OGG
  87234. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87235. return true;
  87236. #else
  87237. (void)value;
  87238. return false;
  87239. #endif
  87240. }
  87241. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87242. {
  87243. FLAC__ASSERT(0 != decoder);
  87244. FLAC__ASSERT(0 != decoder->protected_);
  87245. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87246. return false;
  87247. decoder->protected_->md5_checking = value;
  87248. return true;
  87249. }
  87250. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87251. {
  87252. FLAC__ASSERT(0 != decoder);
  87253. FLAC__ASSERT(0 != decoder->private_);
  87254. FLAC__ASSERT(0 != decoder->protected_);
  87255. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87256. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87257. return false;
  87258. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87259. return false;
  87260. decoder->private_->metadata_filter[type] = true;
  87261. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87262. decoder->private_->metadata_filter_ids_count = 0;
  87263. return true;
  87264. }
  87265. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87266. {
  87267. FLAC__ASSERT(0 != decoder);
  87268. FLAC__ASSERT(0 != decoder->private_);
  87269. FLAC__ASSERT(0 != decoder->protected_);
  87270. FLAC__ASSERT(0 != id);
  87271. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87272. return false;
  87273. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87274. return true;
  87275. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87276. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87277. 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))) {
  87278. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87279. return false;
  87280. }
  87281. decoder->private_->metadata_filter_ids_capacity *= 2;
  87282. }
  87283. 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));
  87284. decoder->private_->metadata_filter_ids_count++;
  87285. return true;
  87286. }
  87287. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87288. {
  87289. unsigned i;
  87290. FLAC__ASSERT(0 != decoder);
  87291. FLAC__ASSERT(0 != decoder->private_);
  87292. FLAC__ASSERT(0 != decoder->protected_);
  87293. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87294. return false;
  87295. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87296. decoder->private_->metadata_filter[i] = true;
  87297. decoder->private_->metadata_filter_ids_count = 0;
  87298. return true;
  87299. }
  87300. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87301. {
  87302. FLAC__ASSERT(0 != decoder);
  87303. FLAC__ASSERT(0 != decoder->private_);
  87304. FLAC__ASSERT(0 != decoder->protected_);
  87305. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87306. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87307. return false;
  87308. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87309. return false;
  87310. decoder->private_->metadata_filter[type] = false;
  87311. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87312. decoder->private_->metadata_filter_ids_count = 0;
  87313. return true;
  87314. }
  87315. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87316. {
  87317. FLAC__ASSERT(0 != decoder);
  87318. FLAC__ASSERT(0 != decoder->private_);
  87319. FLAC__ASSERT(0 != decoder->protected_);
  87320. FLAC__ASSERT(0 != id);
  87321. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87322. return false;
  87323. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87324. return true;
  87325. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87326. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87327. 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))) {
  87328. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87329. return false;
  87330. }
  87331. decoder->private_->metadata_filter_ids_capacity *= 2;
  87332. }
  87333. 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));
  87334. decoder->private_->metadata_filter_ids_count++;
  87335. return true;
  87336. }
  87337. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87338. {
  87339. FLAC__ASSERT(0 != decoder);
  87340. FLAC__ASSERT(0 != decoder->private_);
  87341. FLAC__ASSERT(0 != decoder->protected_);
  87342. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87343. return false;
  87344. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87345. decoder->private_->metadata_filter_ids_count = 0;
  87346. return true;
  87347. }
  87348. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87349. {
  87350. FLAC__ASSERT(0 != decoder);
  87351. FLAC__ASSERT(0 != decoder->protected_);
  87352. return decoder->protected_->state;
  87353. }
  87354. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87355. {
  87356. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87357. }
  87358. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87359. {
  87360. FLAC__ASSERT(0 != decoder);
  87361. FLAC__ASSERT(0 != decoder->protected_);
  87362. return decoder->protected_->md5_checking;
  87363. }
  87364. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87365. {
  87366. FLAC__ASSERT(0 != decoder);
  87367. FLAC__ASSERT(0 != decoder->protected_);
  87368. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87369. }
  87370. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87371. {
  87372. FLAC__ASSERT(0 != decoder);
  87373. FLAC__ASSERT(0 != decoder->protected_);
  87374. return decoder->protected_->channels;
  87375. }
  87376. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87377. {
  87378. FLAC__ASSERT(0 != decoder);
  87379. FLAC__ASSERT(0 != decoder->protected_);
  87380. return decoder->protected_->channel_assignment;
  87381. }
  87382. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87383. {
  87384. FLAC__ASSERT(0 != decoder);
  87385. FLAC__ASSERT(0 != decoder->protected_);
  87386. return decoder->protected_->bits_per_sample;
  87387. }
  87388. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87389. {
  87390. FLAC__ASSERT(0 != decoder);
  87391. FLAC__ASSERT(0 != decoder->protected_);
  87392. return decoder->protected_->sample_rate;
  87393. }
  87394. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87395. {
  87396. FLAC__ASSERT(0 != decoder);
  87397. FLAC__ASSERT(0 != decoder->protected_);
  87398. return decoder->protected_->blocksize;
  87399. }
  87400. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87401. {
  87402. FLAC__ASSERT(0 != decoder);
  87403. FLAC__ASSERT(0 != decoder->private_);
  87404. FLAC__ASSERT(0 != position);
  87405. #if FLAC__HAS_OGG
  87406. if(decoder->private_->is_ogg)
  87407. return false;
  87408. #endif
  87409. if(0 == decoder->private_->tell_callback)
  87410. return false;
  87411. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87412. return false;
  87413. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87414. return false;
  87415. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87416. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87417. return true;
  87418. }
  87419. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87420. {
  87421. FLAC__ASSERT(0 != decoder);
  87422. FLAC__ASSERT(0 != decoder->private_);
  87423. FLAC__ASSERT(0 != decoder->protected_);
  87424. decoder->private_->samples_decoded = 0;
  87425. decoder->private_->do_md5_checking = false;
  87426. #if FLAC__HAS_OGG
  87427. if(decoder->private_->is_ogg)
  87428. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87429. #endif
  87430. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87431. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87432. return false;
  87433. }
  87434. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87435. return true;
  87436. }
  87437. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87438. {
  87439. FLAC__ASSERT(0 != decoder);
  87440. FLAC__ASSERT(0 != decoder->private_);
  87441. FLAC__ASSERT(0 != decoder->protected_);
  87442. if(!FLAC__stream_decoder_flush(decoder)) {
  87443. return false;
  87444. }
  87445. #if FLAC__HAS_OGG
  87446. if(decoder->private_->is_ogg)
  87447. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87448. #endif
  87449. if(!decoder->private_->internal_reset_hack) {
  87450. if(decoder->private_->file == stdin)
  87451. return false; /* can't rewind stdin, reset fails */
  87452. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87453. return false; /* seekable and seek fails, reset fails */
  87454. }
  87455. else
  87456. decoder->private_->internal_reset_hack = false;
  87457. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87458. decoder->private_->has_stream_info = false;
  87459. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87460. free(decoder->private_->seek_table.data.seek_table.points);
  87461. decoder->private_->seek_table.data.seek_table.points = 0;
  87462. decoder->private_->has_seek_table = false;
  87463. }
  87464. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87465. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87466. FLAC__MD5Init(&decoder->private_->md5context);
  87467. decoder->private_->first_frame_offset = 0;
  87468. decoder->private_->unparseable_frame_count = 0;
  87469. return true;
  87470. }
  87471. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87472. {
  87473. FLAC__bool got_a_frame;
  87474. FLAC__ASSERT(0 != decoder);
  87475. FLAC__ASSERT(0 != decoder->protected_);
  87476. while(1) {
  87477. switch(decoder->protected_->state) {
  87478. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87479. if(!find_metadata_(decoder))
  87480. return false; /* above function sets the status for us */
  87481. break;
  87482. case FLAC__STREAM_DECODER_READ_METADATA:
  87483. if(!read_metadata_(decoder))
  87484. return false; /* above function sets the status for us */
  87485. else
  87486. return true;
  87487. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87488. if(!frame_sync_(decoder))
  87489. return true; /* above function sets the status for us */
  87490. break;
  87491. case FLAC__STREAM_DECODER_READ_FRAME:
  87492. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87493. return false; /* above function sets the status for us */
  87494. if(got_a_frame)
  87495. return true; /* above function sets the status for us */
  87496. break;
  87497. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87498. case FLAC__STREAM_DECODER_ABORTED:
  87499. return true;
  87500. default:
  87501. FLAC__ASSERT(0);
  87502. return false;
  87503. }
  87504. }
  87505. }
  87506. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  87507. {
  87508. FLAC__ASSERT(0 != decoder);
  87509. FLAC__ASSERT(0 != decoder->protected_);
  87510. while(1) {
  87511. switch(decoder->protected_->state) {
  87512. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87513. if(!find_metadata_(decoder))
  87514. return false; /* above function sets the status for us */
  87515. break;
  87516. case FLAC__STREAM_DECODER_READ_METADATA:
  87517. if(!read_metadata_(decoder))
  87518. return false; /* above function sets the status for us */
  87519. break;
  87520. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87521. case FLAC__STREAM_DECODER_READ_FRAME:
  87522. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87523. case FLAC__STREAM_DECODER_ABORTED:
  87524. return true;
  87525. default:
  87526. FLAC__ASSERT(0);
  87527. return false;
  87528. }
  87529. }
  87530. }
  87531. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  87532. {
  87533. FLAC__bool dummy;
  87534. FLAC__ASSERT(0 != decoder);
  87535. FLAC__ASSERT(0 != decoder->protected_);
  87536. while(1) {
  87537. switch(decoder->protected_->state) {
  87538. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87539. if(!find_metadata_(decoder))
  87540. return false; /* above function sets the status for us */
  87541. break;
  87542. case FLAC__STREAM_DECODER_READ_METADATA:
  87543. if(!read_metadata_(decoder))
  87544. return false; /* above function sets the status for us */
  87545. break;
  87546. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87547. if(!frame_sync_(decoder))
  87548. return true; /* above function sets the status for us */
  87549. break;
  87550. case FLAC__STREAM_DECODER_READ_FRAME:
  87551. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  87552. return false; /* above function sets the status for us */
  87553. break;
  87554. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87555. case FLAC__STREAM_DECODER_ABORTED:
  87556. return true;
  87557. default:
  87558. FLAC__ASSERT(0);
  87559. return false;
  87560. }
  87561. }
  87562. }
  87563. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  87564. {
  87565. FLAC__bool got_a_frame;
  87566. FLAC__ASSERT(0 != decoder);
  87567. FLAC__ASSERT(0 != decoder->protected_);
  87568. while(1) {
  87569. switch(decoder->protected_->state) {
  87570. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87571. case FLAC__STREAM_DECODER_READ_METADATA:
  87572. return false; /* above function sets the status for us */
  87573. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87574. if(!frame_sync_(decoder))
  87575. return true; /* above function sets the status for us */
  87576. break;
  87577. case FLAC__STREAM_DECODER_READ_FRAME:
  87578. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  87579. return false; /* above function sets the status for us */
  87580. if(got_a_frame)
  87581. return true; /* above function sets the status for us */
  87582. break;
  87583. case FLAC__STREAM_DECODER_END_OF_STREAM:
  87584. case FLAC__STREAM_DECODER_ABORTED:
  87585. return true;
  87586. default:
  87587. FLAC__ASSERT(0);
  87588. return false;
  87589. }
  87590. }
  87591. }
  87592. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  87593. {
  87594. FLAC__uint64 length;
  87595. FLAC__ASSERT(0 != decoder);
  87596. if(
  87597. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  87598. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  87599. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  87600. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  87601. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  87602. )
  87603. return false;
  87604. if(0 == decoder->private_->seek_callback)
  87605. return false;
  87606. FLAC__ASSERT(decoder->private_->seek_callback);
  87607. FLAC__ASSERT(decoder->private_->tell_callback);
  87608. FLAC__ASSERT(decoder->private_->length_callback);
  87609. FLAC__ASSERT(decoder->private_->eof_callback);
  87610. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  87611. return false;
  87612. decoder->private_->is_seeking = true;
  87613. decoder->private_->do_md5_checking = false;
  87614. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  87615. decoder->private_->is_seeking = false;
  87616. return false;
  87617. }
  87618. if(
  87619. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  87620. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  87621. ) {
  87622. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  87623. decoder->private_->is_seeking = false;
  87624. return false;
  87625. }
  87626. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  87627. decoder->private_->is_seeking = false;
  87628. return false;
  87629. }
  87630. }
  87631. {
  87632. const FLAC__bool ok =
  87633. #if FLAC__HAS_OGG
  87634. decoder->private_->is_ogg?
  87635. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  87636. #endif
  87637. seek_to_absolute_sample_(decoder, length, sample)
  87638. ;
  87639. decoder->private_->is_seeking = false;
  87640. return ok;
  87641. }
  87642. }
  87643. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  87644. {
  87645. FLAC__ASSERT(0 != decoder);
  87646. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87647. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  87648. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  87649. }
  87650. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  87651. {
  87652. #if FLAC__HAS_OGG
  87653. decoder->private_->is_ogg = false;
  87654. #endif
  87655. decoder->private_->read_callback = 0;
  87656. decoder->private_->seek_callback = 0;
  87657. decoder->private_->tell_callback = 0;
  87658. decoder->private_->length_callback = 0;
  87659. decoder->private_->eof_callback = 0;
  87660. decoder->private_->write_callback = 0;
  87661. decoder->private_->metadata_callback = 0;
  87662. decoder->private_->error_callback = 0;
  87663. decoder->private_->client_data = 0;
  87664. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87665. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  87666. decoder->private_->metadata_filter_ids_count = 0;
  87667. decoder->protected_->md5_checking = false;
  87668. #if FLAC__HAS_OGG
  87669. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  87670. #endif
  87671. }
  87672. FILE *get_binary_stdin_(void)
  87673. {
  87674. #if defined _MSC_VER || defined __MINGW32__
  87675. _setmode(_fileno(stdin), _O_BINARY);
  87676. #elif defined __CYGWIN__
  87677. setmode(_fileno(stdin), _O_BINARY);
  87678. #elif defined __EMX__
  87679. setmode(fileno(stdin), O_BINARY);
  87680. #endif
  87681. return stdin;
  87682. }
  87683. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  87684. {
  87685. unsigned i;
  87686. FLAC__int32 *tmp;
  87687. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  87688. return true;
  87689. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87690. if(0 != decoder->private_->output[i]) {
  87691. free(decoder->private_->output[i]-4);
  87692. decoder->private_->output[i] = 0;
  87693. }
  87694. if(0 != decoder->private_->residual_unaligned[i]) {
  87695. free(decoder->private_->residual_unaligned[i]);
  87696. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87697. }
  87698. }
  87699. for(i = 0; i < channels; i++) {
  87700. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  87701. if(tmp == 0) {
  87702. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87703. return false;
  87704. }
  87705. memset(tmp, 0, sizeof(FLAC__int32)*4);
  87706. decoder->private_->output[i] = tmp + 4;
  87707. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  87708. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87709. return false;
  87710. }
  87711. }
  87712. decoder->private_->output_capacity = size;
  87713. decoder->private_->output_channels = channels;
  87714. return true;
  87715. }
  87716. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  87717. {
  87718. size_t i;
  87719. FLAC__ASSERT(0 != decoder);
  87720. FLAC__ASSERT(0 != decoder->private_);
  87721. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  87722. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  87723. return true;
  87724. return false;
  87725. }
  87726. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  87727. {
  87728. FLAC__uint32 x;
  87729. unsigned i, id_;
  87730. FLAC__bool first = true;
  87731. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87732. for(i = id_ = 0; i < 4; ) {
  87733. if(decoder->private_->cached) {
  87734. x = (FLAC__uint32)decoder->private_->lookahead;
  87735. decoder->private_->cached = false;
  87736. }
  87737. else {
  87738. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87739. return false; /* read_callback_ sets the state for us */
  87740. }
  87741. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  87742. first = true;
  87743. i++;
  87744. id_ = 0;
  87745. continue;
  87746. }
  87747. if(x == ID3V2_TAG_[id_]) {
  87748. id_++;
  87749. i = 0;
  87750. if(id_ == 3) {
  87751. if(!skip_id3v2_tag_(decoder))
  87752. return false; /* skip_id3v2_tag_ sets the state for us */
  87753. }
  87754. continue;
  87755. }
  87756. id_ = 0;
  87757. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87758. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  87759. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  87760. return false; /* read_callback_ sets the state for us */
  87761. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  87762. decoder->private_->lookahead = (FLAC__byte)x;
  87763. decoder->private_->cached = true;
  87764. }
  87765. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  87766. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  87767. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  87768. return true;
  87769. }
  87770. }
  87771. i = 0;
  87772. if(first) {
  87773. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  87774. first = false;
  87775. }
  87776. }
  87777. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  87778. return true;
  87779. }
  87780. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  87781. {
  87782. FLAC__bool is_last;
  87783. FLAC__uint32 i, x, type, length;
  87784. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87785. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  87786. return false; /* read_callback_ sets the state for us */
  87787. is_last = x? true : false;
  87788. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  87789. return false; /* read_callback_ sets the state for us */
  87790. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  87791. return false; /* read_callback_ sets the state for us */
  87792. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  87793. if(!read_metadata_streaminfo_(decoder, is_last, length))
  87794. return false;
  87795. decoder->private_->has_stream_info = true;
  87796. 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))
  87797. decoder->private_->do_md5_checking = false;
  87798. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  87799. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  87800. }
  87801. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  87802. if(!read_metadata_seektable_(decoder, is_last, length))
  87803. return false;
  87804. decoder->private_->has_seek_table = true;
  87805. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  87806. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  87807. }
  87808. else {
  87809. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  87810. unsigned real_length = length;
  87811. FLAC__StreamMetadata block;
  87812. block.is_last = is_last;
  87813. block.type = (FLAC__MetadataType)type;
  87814. block.length = length;
  87815. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  87816. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  87817. return false; /* read_callback_ sets the state for us */
  87818. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  87819. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  87820. return false;
  87821. }
  87822. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  87823. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  87824. skip_it = !skip_it;
  87825. }
  87826. if(skip_it) {
  87827. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87828. return false; /* read_callback_ sets the state for us */
  87829. }
  87830. else {
  87831. switch(type) {
  87832. case FLAC__METADATA_TYPE_PADDING:
  87833. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  87834. return false; /* read_callback_ sets the state for us */
  87835. break;
  87836. case FLAC__METADATA_TYPE_APPLICATION:
  87837. if(real_length > 0) {
  87838. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  87839. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87840. return false;
  87841. }
  87842. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  87843. return false; /* read_callback_ sets the state for us */
  87844. }
  87845. else
  87846. block.data.application.data = 0;
  87847. break;
  87848. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87849. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  87850. return false;
  87851. break;
  87852. case FLAC__METADATA_TYPE_CUESHEET:
  87853. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  87854. return false;
  87855. break;
  87856. case FLAC__METADATA_TYPE_PICTURE:
  87857. if(!read_metadata_picture_(decoder, &block.data.picture))
  87858. return false;
  87859. break;
  87860. case FLAC__METADATA_TYPE_STREAMINFO:
  87861. case FLAC__METADATA_TYPE_SEEKTABLE:
  87862. FLAC__ASSERT(0);
  87863. break;
  87864. default:
  87865. if(real_length > 0) {
  87866. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  87867. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87868. return false;
  87869. }
  87870. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  87871. return false; /* read_callback_ sets the state for us */
  87872. }
  87873. else
  87874. block.data.unknown.data = 0;
  87875. break;
  87876. }
  87877. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  87878. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  87879. switch(type) {
  87880. case FLAC__METADATA_TYPE_PADDING:
  87881. break;
  87882. case FLAC__METADATA_TYPE_APPLICATION:
  87883. if(0 != block.data.application.data)
  87884. free(block.data.application.data);
  87885. break;
  87886. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  87887. if(0 != block.data.vorbis_comment.vendor_string.entry)
  87888. free(block.data.vorbis_comment.vendor_string.entry);
  87889. if(block.data.vorbis_comment.num_comments > 0)
  87890. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  87891. if(0 != block.data.vorbis_comment.comments[i].entry)
  87892. free(block.data.vorbis_comment.comments[i].entry);
  87893. if(0 != block.data.vorbis_comment.comments)
  87894. free(block.data.vorbis_comment.comments);
  87895. break;
  87896. case FLAC__METADATA_TYPE_CUESHEET:
  87897. if(block.data.cue_sheet.num_tracks > 0)
  87898. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  87899. if(0 != block.data.cue_sheet.tracks[i].indices)
  87900. free(block.data.cue_sheet.tracks[i].indices);
  87901. if(0 != block.data.cue_sheet.tracks)
  87902. free(block.data.cue_sheet.tracks);
  87903. break;
  87904. case FLAC__METADATA_TYPE_PICTURE:
  87905. if(0 != block.data.picture.mime_type)
  87906. free(block.data.picture.mime_type);
  87907. if(0 != block.data.picture.description)
  87908. free(block.data.picture.description);
  87909. if(0 != block.data.picture.data)
  87910. free(block.data.picture.data);
  87911. break;
  87912. case FLAC__METADATA_TYPE_STREAMINFO:
  87913. case FLAC__METADATA_TYPE_SEEKTABLE:
  87914. FLAC__ASSERT(0);
  87915. default:
  87916. if(0 != block.data.unknown.data)
  87917. free(block.data.unknown.data);
  87918. break;
  87919. }
  87920. }
  87921. }
  87922. if(is_last) {
  87923. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  87924. decoder->private_->first_frame_offset = 0;
  87925. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87926. }
  87927. return true;
  87928. }
  87929. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  87930. {
  87931. FLAC__uint32 x;
  87932. unsigned bits, used_bits = 0;
  87933. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87934. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  87935. decoder->private_->stream_info.is_last = is_last;
  87936. decoder->private_->stream_info.length = length;
  87937. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  87938. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  87939. return false; /* read_callback_ sets the state for us */
  87940. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  87941. used_bits += bits;
  87942. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  87943. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  87944. return false; /* read_callback_ sets the state for us */
  87945. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  87946. used_bits += bits;
  87947. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  87948. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  87949. return false; /* read_callback_ sets the state for us */
  87950. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  87951. used_bits += bits;
  87952. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  87953. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  87954. return false; /* read_callback_ sets the state for us */
  87955. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  87956. used_bits += bits;
  87957. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  87958. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  87959. return false; /* read_callback_ sets the state for us */
  87960. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  87961. used_bits += bits;
  87962. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  87963. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  87964. return false; /* read_callback_ sets the state for us */
  87965. decoder->private_->stream_info.data.stream_info.channels = x+1;
  87966. used_bits += bits;
  87967. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  87968. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  87969. return false; /* read_callback_ sets the state for us */
  87970. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  87971. used_bits += bits;
  87972. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  87973. 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))
  87974. return false; /* read_callback_ sets the state for us */
  87975. used_bits += bits;
  87976. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  87977. return false; /* read_callback_ sets the state for us */
  87978. used_bits += 16*8;
  87979. FLAC__ASSERT(used_bits % 8 == 0);
  87980. length -= (used_bits / 8);
  87981. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  87982. return false; /* read_callback_ sets the state for us */
  87983. return true;
  87984. }
  87985. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  87986. {
  87987. FLAC__uint32 i, x;
  87988. FLAC__uint64 xx;
  87989. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  87990. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  87991. decoder->private_->seek_table.is_last = is_last;
  87992. decoder->private_->seek_table.length = length;
  87993. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  87994. 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)))) {
  87995. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87996. return false;
  87997. }
  87998. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  87999. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88000. return false; /* read_callback_ sets the state for us */
  88001. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88002. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88003. return false; /* read_callback_ sets the state for us */
  88004. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88005. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88006. return false; /* read_callback_ sets the state for us */
  88007. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88008. }
  88009. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88010. if(length > 0) {
  88011. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88012. return false; /* read_callback_ sets the state for us */
  88013. }
  88014. return true;
  88015. }
  88016. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88017. {
  88018. FLAC__uint32 i;
  88019. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88020. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88021. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88022. return false; /* read_callback_ sets the state for us */
  88023. if(obj->vendor_string.length > 0) {
  88024. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88025. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88026. return false;
  88027. }
  88028. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88029. return false; /* read_callback_ sets the state for us */
  88030. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88031. }
  88032. else
  88033. obj->vendor_string.entry = 0;
  88034. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88035. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88036. return false; /* read_callback_ sets the state for us */
  88037. if(obj->num_comments > 0) {
  88038. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88039. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88040. return false;
  88041. }
  88042. for(i = 0; i < obj->num_comments; i++) {
  88043. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88044. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88045. return false; /* read_callback_ sets the state for us */
  88046. if(obj->comments[i].length > 0) {
  88047. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88048. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88049. return false;
  88050. }
  88051. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88052. return false; /* read_callback_ sets the state for us */
  88053. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88054. }
  88055. else
  88056. obj->comments[i].entry = 0;
  88057. }
  88058. }
  88059. else {
  88060. obj->comments = 0;
  88061. }
  88062. return true;
  88063. }
  88064. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88065. {
  88066. FLAC__uint32 i, j, x;
  88067. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88068. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88069. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88070. 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))
  88071. return false; /* read_callback_ sets the state for us */
  88072. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_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_IS_CD_LEN))
  88075. return false; /* read_callback_ sets the state for us */
  88076. obj->is_cd = x? true : false;
  88077. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88078. return false; /* read_callback_ sets the state for us */
  88079. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88080. return false; /* read_callback_ sets the state for us */
  88081. obj->num_tracks = x;
  88082. if(obj->num_tracks > 0) {
  88083. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88084. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88085. return false;
  88086. }
  88087. for(i = 0; i < obj->num_tracks; i++) {
  88088. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88089. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88090. return false; /* read_callback_ sets the state for us */
  88091. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88092. return false; /* read_callback_ sets the state for us */
  88093. track->number = (FLAC__byte)x;
  88094. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88095. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88096. return false; /* read_callback_ sets the state for us */
  88097. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88098. return false; /* read_callback_ sets the state for us */
  88099. track->type = x;
  88100. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88101. return false; /* read_callback_ sets the state for us */
  88102. track->pre_emphasis = x;
  88103. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88104. return false; /* read_callback_ sets the state for us */
  88105. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88106. return false; /* read_callback_ sets the state for us */
  88107. track->num_indices = (FLAC__byte)x;
  88108. if(track->num_indices > 0) {
  88109. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88110. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88111. return false;
  88112. }
  88113. for(j = 0; j < track->num_indices; j++) {
  88114. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88115. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88116. return false; /* read_callback_ sets the state for us */
  88117. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88118. return false; /* read_callback_ sets the state for us */
  88119. index->number = (FLAC__byte)x;
  88120. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88121. return false; /* read_callback_ sets the state for us */
  88122. }
  88123. }
  88124. }
  88125. }
  88126. return true;
  88127. }
  88128. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88129. {
  88130. FLAC__uint32 x;
  88131. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88132. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88133. return false; /* read_callback_ sets the state for us */
  88134. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88135. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88136. return false; /* read_callback_ sets the state for us */
  88137. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88138. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88139. return false;
  88140. }
  88141. if(x > 0) {
  88142. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88143. return false; /* read_callback_ sets the state for us */
  88144. }
  88145. obj->mime_type[x] = '\0';
  88146. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88147. return false; /* read_callback_ sets the state for us */
  88148. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88149. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88150. return false;
  88151. }
  88152. if(x > 0) {
  88153. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88154. return false; /* read_callback_ sets the state for us */
  88155. }
  88156. obj->description[x] = '\0';
  88157. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88158. return false; /* read_callback_ sets the state for us */
  88159. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88160. return false; /* read_callback_ sets the state for us */
  88161. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88162. return false; /* read_callback_ sets the state for us */
  88163. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88164. return false; /* read_callback_ sets the state for us */
  88165. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88166. return false; /* read_callback_ sets the state for us */
  88167. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88168. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88169. return false;
  88170. }
  88171. if(obj->data_length > 0) {
  88172. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88173. return false; /* read_callback_ sets the state for us */
  88174. }
  88175. return true;
  88176. }
  88177. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88178. {
  88179. FLAC__uint32 x;
  88180. unsigned i, skip;
  88181. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88182. return false; /* read_callback_ sets the state for us */
  88183. skip = 0;
  88184. for(i = 0; i < 4; i++) {
  88185. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88186. return false; /* read_callback_ sets the state for us */
  88187. skip <<= 7;
  88188. skip |= (x & 0x7f);
  88189. }
  88190. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88191. return false; /* read_callback_ sets the state for us */
  88192. return true;
  88193. }
  88194. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88195. {
  88196. FLAC__uint32 x;
  88197. FLAC__bool first = true;
  88198. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88199. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88200. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88201. return true;
  88202. }
  88203. }
  88204. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88205. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88206. return false; /* read_callback_ sets the state for us */
  88207. }
  88208. while(1) {
  88209. if(decoder->private_->cached) {
  88210. x = (FLAC__uint32)decoder->private_->lookahead;
  88211. decoder->private_->cached = false;
  88212. }
  88213. else {
  88214. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88215. return false; /* read_callback_ sets the state for us */
  88216. }
  88217. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88218. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88219. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88220. return false; /* read_callback_ sets the state for us */
  88221. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88222. decoder->private_->lookahead = (FLAC__byte)x;
  88223. decoder->private_->cached = true;
  88224. }
  88225. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88226. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88227. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88228. return true;
  88229. }
  88230. }
  88231. if(first) {
  88232. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88233. first = false;
  88234. }
  88235. }
  88236. return true;
  88237. }
  88238. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88239. {
  88240. unsigned channel;
  88241. unsigned i;
  88242. FLAC__int32 mid, side;
  88243. unsigned frame_crc; /* the one we calculate from the input stream */
  88244. FLAC__uint32 x;
  88245. *got_a_frame = false;
  88246. frame_crc = 0;
  88247. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88248. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88249. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88250. if(!read_frame_header_(decoder))
  88251. return false;
  88252. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88253. return true;
  88254. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88255. return false;
  88256. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88257. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88258. switch(decoder->private_->frame.header.channel_assignment) {
  88259. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88260. break;
  88261. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88262. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88263. if(channel == 1)
  88264. bps++;
  88265. break;
  88266. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88267. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88268. if(channel == 0)
  88269. bps++;
  88270. break;
  88271. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88272. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88273. if(channel == 1)
  88274. bps++;
  88275. break;
  88276. default:
  88277. FLAC__ASSERT(0);
  88278. }
  88279. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88280. return false;
  88281. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88282. return true;
  88283. }
  88284. if(!read_zero_padding_(decoder))
  88285. return false;
  88286. 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) */
  88287. return true;
  88288. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88289. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88290. return false; /* read_callback_ sets the state for us */
  88291. if(frame_crc == x) {
  88292. if(do_full_decode) {
  88293. switch(decoder->private_->frame.header.channel_assignment) {
  88294. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88295. break;
  88296. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88297. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88298. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88299. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88300. break;
  88301. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88302. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88303. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88304. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88305. break;
  88306. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88307. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88308. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88309. #if 1
  88310. mid = decoder->private_->output[0][i];
  88311. side = decoder->private_->output[1][i];
  88312. mid <<= 1;
  88313. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88314. decoder->private_->output[0][i] = (mid + side) >> 1;
  88315. decoder->private_->output[1][i] = (mid - side) >> 1;
  88316. #else
  88317. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88318. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88319. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88320. #endif
  88321. }
  88322. break;
  88323. default:
  88324. FLAC__ASSERT(0);
  88325. break;
  88326. }
  88327. }
  88328. }
  88329. else {
  88330. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88331. if(do_full_decode) {
  88332. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88333. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88334. }
  88335. }
  88336. }
  88337. *got_a_frame = true;
  88338. if(decoder->private_->next_fixed_block_size)
  88339. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88340. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88341. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88342. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88343. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88344. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88345. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88346. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88347. if(do_full_decode) {
  88348. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88349. return false;
  88350. }
  88351. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88352. return true;
  88353. }
  88354. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88355. {
  88356. FLAC__uint32 x;
  88357. FLAC__uint64 xx;
  88358. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88359. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88360. unsigned raw_header_len;
  88361. FLAC__bool is_unparseable = false;
  88362. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88363. raw_header[0] = decoder->private_->header_warmup[0];
  88364. raw_header[1] = decoder->private_->header_warmup[1];
  88365. raw_header_len = 2;
  88366. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88367. is_unparseable = true;
  88368. for(i = 0; i < 2; i++) {
  88369. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88370. return false; /* read_callback_ sets the state for us */
  88371. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88372. decoder->private_->lookahead = (FLAC__byte)x;
  88373. decoder->private_->cached = true;
  88374. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88375. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88376. return true;
  88377. }
  88378. raw_header[raw_header_len++] = (FLAC__byte)x;
  88379. }
  88380. switch(x = raw_header[2] >> 4) {
  88381. case 0:
  88382. is_unparseable = true;
  88383. break;
  88384. case 1:
  88385. decoder->private_->frame.header.blocksize = 192;
  88386. break;
  88387. case 2:
  88388. case 3:
  88389. case 4:
  88390. case 5:
  88391. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88392. break;
  88393. case 6:
  88394. case 7:
  88395. blocksize_hint = x;
  88396. break;
  88397. case 8:
  88398. case 9:
  88399. case 10:
  88400. case 11:
  88401. case 12:
  88402. case 13:
  88403. case 14:
  88404. case 15:
  88405. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88406. break;
  88407. default:
  88408. FLAC__ASSERT(0);
  88409. break;
  88410. }
  88411. switch(x = raw_header[2] & 0x0f) {
  88412. case 0:
  88413. if(decoder->private_->has_stream_info)
  88414. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88415. else
  88416. is_unparseable = true;
  88417. break;
  88418. case 1:
  88419. decoder->private_->frame.header.sample_rate = 88200;
  88420. break;
  88421. case 2:
  88422. decoder->private_->frame.header.sample_rate = 176400;
  88423. break;
  88424. case 3:
  88425. decoder->private_->frame.header.sample_rate = 192000;
  88426. break;
  88427. case 4:
  88428. decoder->private_->frame.header.sample_rate = 8000;
  88429. break;
  88430. case 5:
  88431. decoder->private_->frame.header.sample_rate = 16000;
  88432. break;
  88433. case 6:
  88434. decoder->private_->frame.header.sample_rate = 22050;
  88435. break;
  88436. case 7:
  88437. decoder->private_->frame.header.sample_rate = 24000;
  88438. break;
  88439. case 8:
  88440. decoder->private_->frame.header.sample_rate = 32000;
  88441. break;
  88442. case 9:
  88443. decoder->private_->frame.header.sample_rate = 44100;
  88444. break;
  88445. case 10:
  88446. decoder->private_->frame.header.sample_rate = 48000;
  88447. break;
  88448. case 11:
  88449. decoder->private_->frame.header.sample_rate = 96000;
  88450. break;
  88451. case 12:
  88452. case 13:
  88453. case 14:
  88454. sample_rate_hint = x;
  88455. break;
  88456. case 15:
  88457. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88458. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88459. return true;
  88460. default:
  88461. FLAC__ASSERT(0);
  88462. }
  88463. x = (unsigned)(raw_header[3] >> 4);
  88464. if(x & 8) {
  88465. decoder->private_->frame.header.channels = 2;
  88466. switch(x & 7) {
  88467. case 0:
  88468. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88469. break;
  88470. case 1:
  88471. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88472. break;
  88473. case 2:
  88474. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88475. break;
  88476. default:
  88477. is_unparseable = true;
  88478. break;
  88479. }
  88480. }
  88481. else {
  88482. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88483. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88484. }
  88485. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88486. case 0:
  88487. if(decoder->private_->has_stream_info)
  88488. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88489. else
  88490. is_unparseable = true;
  88491. break;
  88492. case 1:
  88493. decoder->private_->frame.header.bits_per_sample = 8;
  88494. break;
  88495. case 2:
  88496. decoder->private_->frame.header.bits_per_sample = 12;
  88497. break;
  88498. case 4:
  88499. decoder->private_->frame.header.bits_per_sample = 16;
  88500. break;
  88501. case 5:
  88502. decoder->private_->frame.header.bits_per_sample = 20;
  88503. break;
  88504. case 6:
  88505. decoder->private_->frame.header.bits_per_sample = 24;
  88506. break;
  88507. case 3:
  88508. case 7:
  88509. is_unparseable = true;
  88510. break;
  88511. default:
  88512. FLAC__ASSERT(0);
  88513. break;
  88514. }
  88515. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  88516. is_unparseable = true;
  88517. if(
  88518. raw_header[1] & 0x01 ||
  88519. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  88520. ) { /* variable blocksize */
  88521. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  88522. return false; /* read_callback_ sets the state for us */
  88523. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  88524. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88525. decoder->private_->cached = true;
  88526. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88527. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88528. return true;
  88529. }
  88530. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88531. decoder->private_->frame.header.number.sample_number = xx;
  88532. }
  88533. else { /* fixed blocksize */
  88534. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  88535. return false; /* read_callback_ sets the state for us */
  88536. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  88537. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  88538. decoder->private_->cached = true;
  88539. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88540. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88541. return true;
  88542. }
  88543. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  88544. decoder->private_->frame.header.number.frame_number = x;
  88545. }
  88546. if(blocksize_hint) {
  88547. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88548. return false; /* read_callback_ sets the state for us */
  88549. raw_header[raw_header_len++] = (FLAC__byte)x;
  88550. if(blocksize_hint == 7) {
  88551. FLAC__uint32 _x;
  88552. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88553. return false; /* read_callback_ sets the state for us */
  88554. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88555. x = (x << 8) | _x;
  88556. }
  88557. decoder->private_->frame.header.blocksize = x+1;
  88558. }
  88559. if(sample_rate_hint) {
  88560. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88561. return false; /* read_callback_ sets the state for us */
  88562. raw_header[raw_header_len++] = (FLAC__byte)x;
  88563. if(sample_rate_hint != 12) {
  88564. FLAC__uint32 _x;
  88565. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  88566. return false; /* read_callback_ sets the state for us */
  88567. raw_header[raw_header_len++] = (FLAC__byte)_x;
  88568. x = (x << 8) | _x;
  88569. }
  88570. if(sample_rate_hint == 12)
  88571. decoder->private_->frame.header.sample_rate = x*1000;
  88572. else if(sample_rate_hint == 13)
  88573. decoder->private_->frame.header.sample_rate = x;
  88574. else
  88575. decoder->private_->frame.header.sample_rate = x*10;
  88576. }
  88577. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88578. return false; /* read_callback_ sets the state for us */
  88579. crc8 = (FLAC__byte)x;
  88580. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  88581. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88582. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88583. return true;
  88584. }
  88585. decoder->private_->next_fixed_block_size = 0;
  88586. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  88587. x = decoder->private_->frame.header.number.frame_number;
  88588. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  88589. if(decoder->private_->fixed_block_size)
  88590. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  88591. else if(decoder->private_->has_stream_info) {
  88592. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  88593. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  88594. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  88595. }
  88596. else
  88597. is_unparseable = true;
  88598. }
  88599. else if(x == 0) {
  88600. decoder->private_->frame.header.number.sample_number = 0;
  88601. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  88602. }
  88603. else {
  88604. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  88605. }
  88606. }
  88607. if(is_unparseable) {
  88608. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88609. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88610. return true;
  88611. }
  88612. return true;
  88613. }
  88614. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88615. {
  88616. FLAC__uint32 x;
  88617. FLAC__bool wasted_bits;
  88618. unsigned i;
  88619. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  88620. return false; /* read_callback_ sets the state for us */
  88621. wasted_bits = (x & 1);
  88622. x &= 0xfe;
  88623. if(wasted_bits) {
  88624. unsigned u;
  88625. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  88626. return false; /* read_callback_ sets the state for us */
  88627. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  88628. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  88629. }
  88630. else
  88631. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  88632. if(x & 0x80) {
  88633. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88634. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88635. return true;
  88636. }
  88637. else if(x == 0) {
  88638. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  88639. return false;
  88640. }
  88641. else if(x == 2) {
  88642. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  88643. return false;
  88644. }
  88645. else if(x < 16) {
  88646. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88647. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88648. return true;
  88649. }
  88650. else if(x <= 24) {
  88651. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  88652. return false;
  88653. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88654. return true;
  88655. }
  88656. else if(x < 64) {
  88657. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88658. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88659. return true;
  88660. }
  88661. else {
  88662. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  88663. return false;
  88664. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88665. return true;
  88666. }
  88667. if(wasted_bits && do_full_decode) {
  88668. x = decoder->private_->frame.subframes[channel].wasted_bits;
  88669. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88670. decoder->private_->output[channel][i] <<= x;
  88671. }
  88672. return true;
  88673. }
  88674. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88675. {
  88676. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  88677. FLAC__int32 x;
  88678. unsigned i;
  88679. FLAC__int32 *output = decoder->private_->output[channel];
  88680. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  88681. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88682. return false; /* read_callback_ sets the state for us */
  88683. subframe->value = x;
  88684. if(do_full_decode) {
  88685. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88686. output[i] = x;
  88687. }
  88688. return true;
  88689. }
  88690. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88691. {
  88692. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  88693. FLAC__int32 i32;
  88694. FLAC__uint32 u32;
  88695. unsigned u;
  88696. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  88697. subframe->residual = decoder->private_->residual[channel];
  88698. subframe->order = order;
  88699. for(u = 0; u < order; u++) {
  88700. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88701. return false; /* read_callback_ sets the state for us */
  88702. subframe->warmup[u] = i32;
  88703. }
  88704. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88705. return false; /* read_callback_ sets the state for us */
  88706. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88707. switch(subframe->entropy_coding_method.type) {
  88708. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88709. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88710. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88711. return false; /* read_callback_ sets the state for us */
  88712. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88713. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88714. break;
  88715. default:
  88716. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88717. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88718. return true;
  88719. }
  88720. switch(subframe->entropy_coding_method.type) {
  88721. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88722. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88723. 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))
  88724. return false;
  88725. break;
  88726. default:
  88727. FLAC__ASSERT(0);
  88728. }
  88729. if(do_full_decode) {
  88730. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88731. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  88732. }
  88733. return true;
  88734. }
  88735. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  88736. {
  88737. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  88738. FLAC__int32 i32;
  88739. FLAC__uint32 u32;
  88740. unsigned u;
  88741. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  88742. subframe->residual = decoder->private_->residual[channel];
  88743. subframe->order = order;
  88744. for(u = 0; u < order; u++) {
  88745. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  88746. return false; /* read_callback_ sets the state for us */
  88747. subframe->warmup[u] = i32;
  88748. }
  88749. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  88750. return false; /* read_callback_ sets the state for us */
  88751. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  88752. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88753. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88754. return true;
  88755. }
  88756. subframe->qlp_coeff_precision = u32+1;
  88757. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  88758. return false; /* read_callback_ sets the state for us */
  88759. subframe->quantization_level = i32;
  88760. for(u = 0; u < order; u++) {
  88761. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  88762. return false; /* read_callback_ sets the state for us */
  88763. subframe->qlp_coeff[u] = i32;
  88764. }
  88765. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  88766. return false; /* read_callback_ sets the state for us */
  88767. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  88768. switch(subframe->entropy_coding_method.type) {
  88769. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88770. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88771. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  88772. return false; /* read_callback_ sets the state for us */
  88773. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  88774. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  88775. break;
  88776. default:
  88777. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  88778. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88779. return true;
  88780. }
  88781. switch(subframe->entropy_coding_method.type) {
  88782. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  88783. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  88784. 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))
  88785. return false;
  88786. break;
  88787. default:
  88788. FLAC__ASSERT(0);
  88789. }
  88790. if(do_full_decode) {
  88791. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  88792. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  88793. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  88794. if(order <= 8)
  88795. 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);
  88796. else
  88797. 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);
  88798. }
  88799. else
  88800. 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);
  88801. else
  88802. 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);
  88803. }
  88804. return true;
  88805. }
  88806. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  88807. {
  88808. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  88809. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  88810. unsigned i;
  88811. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  88812. subframe->data = residual;
  88813. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88814. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  88815. return false; /* read_callback_ sets the state for us */
  88816. residual[i] = x;
  88817. }
  88818. if(do_full_decode)
  88819. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88820. return true;
  88821. }
  88822. 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)
  88823. {
  88824. FLAC__uint32 rice_parameter;
  88825. int i;
  88826. unsigned partition, sample, u;
  88827. const unsigned partitions = 1u << partition_order;
  88828. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  88829. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  88830. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  88831. if(partition_order == 0) {
  88832. if(decoder->private_->frame.header.blocksize < predictor_order) {
  88833. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88834. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88835. return true;
  88836. }
  88837. }
  88838. else {
  88839. if(partition_samples < predictor_order) {
  88840. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88841. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88842. return true;
  88843. }
  88844. }
  88845. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  88846. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88847. return false;
  88848. }
  88849. sample = 0;
  88850. for(partition = 0; partition < partitions; partition++) {
  88851. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  88852. return false; /* read_callback_ sets the state for us */
  88853. partitioned_rice_contents->parameters[partition] = rice_parameter;
  88854. if(rice_parameter < pesc) {
  88855. partitioned_rice_contents->raw_bits[partition] = 0;
  88856. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  88857. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  88858. return false; /* read_callback_ sets the state for us */
  88859. sample += u;
  88860. }
  88861. else {
  88862. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  88863. return false; /* read_callback_ sets the state for us */
  88864. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  88865. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  88866. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  88867. return false; /* read_callback_ sets the state for us */
  88868. residual[sample] = i;
  88869. }
  88870. }
  88871. }
  88872. return true;
  88873. }
  88874. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  88875. {
  88876. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88877. FLAC__uint32 zero = 0;
  88878. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88879. return false; /* read_callback_ sets the state for us */
  88880. if(zero != 0) {
  88881. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88882. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88883. }
  88884. }
  88885. return true;
  88886. }
  88887. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  88888. {
  88889. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  88890. if(
  88891. #if FLAC__HAS_OGG
  88892. !decoder->private_->is_ogg &&
  88893. #endif
  88894. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88895. ) {
  88896. *bytes = 0;
  88897. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88898. return false;
  88899. }
  88900. else if(*bytes > 0) {
  88901. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  88902. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88903. return false;
  88904. }
  88905. else {
  88906. const FLAC__StreamDecoderReadStatus status =
  88907. #if FLAC__HAS_OGG
  88908. decoder->private_->is_ogg?
  88909. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  88910. #endif
  88911. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  88912. ;
  88913. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  88914. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88915. return false;
  88916. }
  88917. else if(*bytes == 0) {
  88918. if(
  88919. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  88920. (
  88921. #if FLAC__HAS_OGG
  88922. !decoder->private_->is_ogg &&
  88923. #endif
  88924. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  88925. )
  88926. ) {
  88927. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88928. return false;
  88929. }
  88930. else
  88931. return true;
  88932. }
  88933. else
  88934. return true;
  88935. }
  88936. }
  88937. else {
  88938. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  88939. return false;
  88940. }
  88941. }
  88942. #if FLAC__HAS_OGG
  88943. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  88944. {
  88945. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  88946. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  88947. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  88948. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  88949. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  88950. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  88951. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  88952. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  88953. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  88954. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  88955. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  88956. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  88957. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  88958. default:
  88959. FLAC__ASSERT(0);
  88960. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  88961. }
  88962. }
  88963. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  88964. {
  88965. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  88966. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  88967. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  88968. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  88969. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  88970. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  88971. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  88972. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  88973. default:
  88974. FLAC__ASSERT(0);
  88975. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  88976. }
  88977. }
  88978. #endif
  88979. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  88980. {
  88981. if(decoder->private_->is_seeking) {
  88982. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  88983. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  88984. FLAC__uint64 target_sample = decoder->private_->target_sample;
  88985. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88986. #if FLAC__HAS_OGG
  88987. decoder->private_->got_a_frame = true;
  88988. #endif
  88989. decoder->private_->last_frame = *frame; /* save the frame */
  88990. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  88991. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  88992. decoder->private_->is_seeking = false;
  88993. if(delta > 0) {
  88994. unsigned channel;
  88995. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  88996. for(channel = 0; channel < frame->header.channels; channel++)
  88997. newbuffer[channel] = buffer[channel] + delta;
  88998. decoder->private_->last_frame.header.blocksize -= delta;
  88999. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89000. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89001. }
  89002. else {
  89003. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89004. }
  89005. }
  89006. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89007. }
  89008. if(!decoder->private_->has_stream_info)
  89009. decoder->private_->do_md5_checking = false;
  89010. if(decoder->private_->do_md5_checking) {
  89011. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89012. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89013. }
  89014. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89015. }
  89016. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89017. {
  89018. if(!decoder->private_->is_seeking)
  89019. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89020. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89021. decoder->private_->unparseable_frame_count++;
  89022. }
  89023. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89024. {
  89025. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89026. FLAC__int64 pos = -1;
  89027. int i;
  89028. unsigned approx_bytes_per_frame;
  89029. FLAC__bool first_seek = true;
  89030. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89031. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89032. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89033. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89034. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89035. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89036. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89037. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89038. if(channels == 0)
  89039. channels = decoder->private_->stream_info.data.stream_info.channels;
  89040. if(bps == 0)
  89041. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89042. if(max_framesize > 0)
  89043. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89044. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89045. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89046. }
  89047. else
  89048. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89049. lower_bound = first_frame_offset;
  89050. lower_bound_sample = 0;
  89051. upper_bound = stream_length;
  89052. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89053. if(seek_table) {
  89054. FLAC__uint64 new_lower_bound = lower_bound;
  89055. FLAC__uint64 new_upper_bound = upper_bound;
  89056. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89057. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89058. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89059. if(
  89060. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89061. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89062. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89063. seek_table->points[i].sample_number <= target_sample
  89064. )
  89065. break;
  89066. }
  89067. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89068. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89069. new_lower_bound_sample = seek_table->points[i].sample_number;
  89070. }
  89071. for(i = 0; i < (int)seek_table->num_points; i++) {
  89072. if(
  89073. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89074. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89075. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89076. seek_table->points[i].sample_number > target_sample
  89077. )
  89078. break;
  89079. }
  89080. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89081. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89082. new_upper_bound_sample = seek_table->points[i].sample_number;
  89083. }
  89084. if(new_upper_bound >= new_lower_bound) {
  89085. lower_bound = new_lower_bound;
  89086. upper_bound = new_upper_bound;
  89087. lower_bound_sample = new_lower_bound_sample;
  89088. upper_bound_sample = new_upper_bound_sample;
  89089. }
  89090. }
  89091. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89092. if(upper_bound_sample == lower_bound_sample)
  89093. upper_bound_sample++;
  89094. decoder->private_->target_sample = target_sample;
  89095. while(1) {
  89096. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89097. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89098. return false;
  89099. }
  89100. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89101. #if defined _MSC_VER || defined __MINGW32__
  89102. 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;
  89103. #else
  89104. 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;
  89105. #endif
  89106. #else
  89107. if(upper_bound - lower_bound < 0xffffffff)
  89108. 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;
  89109. else /* @@@ WATCHOUT, ~2TB limit */
  89110. 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;
  89111. #endif
  89112. if(pos >= (FLAC__int64)upper_bound)
  89113. pos = (FLAC__int64)upper_bound - 1;
  89114. if(pos < (FLAC__int64)lower_bound)
  89115. pos = (FLAC__int64)lower_bound;
  89116. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89117. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89118. return false;
  89119. }
  89120. if(!FLAC__stream_decoder_flush(decoder)) {
  89121. return false;
  89122. }
  89123. decoder->private_->unparseable_frame_count = 0;
  89124. if(!FLAC__stream_decoder_process_single(decoder)) {
  89125. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89126. return false;
  89127. }
  89128. #if 0
  89129. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89130. break;
  89131. #endif
  89132. if(!decoder->private_->is_seeking)
  89133. break;
  89134. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89135. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89136. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89137. if (pos == (FLAC__int64)lower_bound) {
  89138. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89139. return false;
  89140. }
  89141. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89142. continue;
  89143. }
  89144. first_seek = false;
  89145. if (this_frame_sample < lower_bound_sample) {
  89146. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89147. return false;
  89148. }
  89149. if(target_sample < this_frame_sample) {
  89150. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89151. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89152. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89153. return false;
  89154. }
  89155. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89156. }
  89157. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89158. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89159. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89160. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89161. return false;
  89162. }
  89163. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89164. }
  89165. }
  89166. return true;
  89167. }
  89168. #if FLAC__HAS_OGG
  89169. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89170. {
  89171. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89172. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89173. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89174. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89175. FLAC__bool did_a_seek;
  89176. unsigned iteration = 0;
  89177. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89178. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89179. if(right_sample == 0) {
  89180. right_sample = (FLAC__uint64)(-1);
  89181. BINARY_SEARCH_AFTER_ITERATION = 0;
  89182. }
  89183. decoder->private_->target_sample = target_sample;
  89184. for( ; ; iteration++) {
  89185. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89186. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89187. pos = (right_pos + left_pos) / 2;
  89188. }
  89189. else {
  89190. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89191. #if defined _MSC_VER || defined __MINGW32__
  89192. 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));
  89193. #else
  89194. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89195. #endif
  89196. #else
  89197. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89198. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89199. else /* @@@ WATCHOUT, ~2TB limit */
  89200. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89201. #endif
  89202. }
  89203. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89204. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89205. return false;
  89206. }
  89207. if(!FLAC__stream_decoder_flush(decoder)) {
  89208. return false;
  89209. }
  89210. did_a_seek = true;
  89211. }
  89212. else
  89213. did_a_seek = false;
  89214. decoder->private_->got_a_frame = false;
  89215. if(!FLAC__stream_decoder_process_single(decoder)) {
  89216. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89217. return false;
  89218. }
  89219. if(!decoder->private_->got_a_frame) {
  89220. if(did_a_seek) {
  89221. right_pos = pos;
  89222. BINARY_SEARCH_AFTER_ITERATION = 0;
  89223. }
  89224. else {
  89225. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89226. return false;
  89227. }
  89228. }
  89229. else if(!decoder->private_->is_seeking) {
  89230. break;
  89231. }
  89232. else {
  89233. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89234. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89235. if (did_a_seek) {
  89236. if (this_frame_sample <= target_sample) {
  89237. FLAC__ASSERT(this_frame_sample != target_sample);
  89238. left_sample = this_frame_sample;
  89239. if (left_pos == pos) {
  89240. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89241. return false;
  89242. }
  89243. left_pos = pos;
  89244. }
  89245. else if(this_frame_sample > target_sample) {
  89246. right_sample = this_frame_sample;
  89247. if (right_pos == pos) {
  89248. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89249. return false;
  89250. }
  89251. right_pos = pos;
  89252. }
  89253. }
  89254. }
  89255. }
  89256. return true;
  89257. }
  89258. #endif
  89259. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89260. {
  89261. (void)client_data;
  89262. if(*bytes > 0) {
  89263. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89264. if(ferror(decoder->private_->file))
  89265. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89266. else if(*bytes == 0)
  89267. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89268. else
  89269. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89270. }
  89271. else
  89272. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89273. }
  89274. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89275. {
  89276. (void)client_data;
  89277. if(decoder->private_->file == stdin)
  89278. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89279. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89280. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89281. else
  89282. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89283. }
  89284. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89285. {
  89286. off_t pos;
  89287. (void)client_data;
  89288. if(decoder->private_->file == stdin)
  89289. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89290. else if((pos = ftello(decoder->private_->file)) < 0)
  89291. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89292. else {
  89293. *absolute_byte_offset = (FLAC__uint64)pos;
  89294. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89295. }
  89296. }
  89297. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89298. {
  89299. struct stat filestats;
  89300. (void)client_data;
  89301. if(decoder->private_->file == stdin)
  89302. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89303. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89304. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89305. else {
  89306. *stream_length = (FLAC__uint64)filestats.st_size;
  89307. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89308. }
  89309. }
  89310. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89311. {
  89312. (void)client_data;
  89313. return feof(decoder->private_->file)? true : false;
  89314. }
  89315. #endif
  89316. /*** End of inlined file: stream_decoder.c ***/
  89317. /*** Start of inlined file: stream_encoder.c ***/
  89318. /*** Start of inlined file: juce_FlacHeader.h ***/
  89319. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89320. // tasks..
  89321. #define VERSION "1.2.1"
  89322. #define FLAC__NO_DLL 1
  89323. #if JUCE_MSVC
  89324. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89325. #endif
  89326. #if JUCE_MAC
  89327. #define FLAC__SYS_DARWIN 1
  89328. #endif
  89329. /*** End of inlined file: juce_FlacHeader.h ***/
  89330. #if JUCE_USE_FLAC
  89331. #if HAVE_CONFIG_H
  89332. # include <config.h>
  89333. #endif
  89334. #if defined _MSC_VER || defined __MINGW32__
  89335. #include <io.h> /* for _setmode() */
  89336. #include <fcntl.h> /* for _O_BINARY */
  89337. #endif
  89338. #if defined __CYGWIN__ || defined __EMX__
  89339. #include <io.h> /* for setmode(), O_BINARY */
  89340. #include <fcntl.h> /* for _O_BINARY */
  89341. #endif
  89342. #include <limits.h>
  89343. #include <stdio.h>
  89344. #include <stdlib.h> /* for malloc() */
  89345. #include <string.h> /* for memcpy() */
  89346. #include <sys/types.h> /* for off_t */
  89347. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89348. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89349. #define fseeko fseek
  89350. #define ftello ftell
  89351. #endif
  89352. #endif
  89353. /*** Start of inlined file: stream_encoder.h ***/
  89354. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89355. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89356. #if FLAC__HAS_OGG
  89357. #include "private/ogg_encoder_aspect.h"
  89358. #endif
  89359. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89360. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89361. typedef enum {
  89362. FLAC__APODIZATION_BARTLETT,
  89363. FLAC__APODIZATION_BARTLETT_HANN,
  89364. FLAC__APODIZATION_BLACKMAN,
  89365. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89366. FLAC__APODIZATION_CONNES,
  89367. FLAC__APODIZATION_FLATTOP,
  89368. FLAC__APODIZATION_GAUSS,
  89369. FLAC__APODIZATION_HAMMING,
  89370. FLAC__APODIZATION_HANN,
  89371. FLAC__APODIZATION_KAISER_BESSEL,
  89372. FLAC__APODIZATION_NUTTALL,
  89373. FLAC__APODIZATION_RECTANGLE,
  89374. FLAC__APODIZATION_TRIANGLE,
  89375. FLAC__APODIZATION_TUKEY,
  89376. FLAC__APODIZATION_WELCH
  89377. } FLAC__ApodizationFunction;
  89378. typedef struct {
  89379. FLAC__ApodizationFunction type;
  89380. union {
  89381. struct {
  89382. FLAC__real stddev;
  89383. } gauss;
  89384. struct {
  89385. FLAC__real p;
  89386. } tukey;
  89387. } parameters;
  89388. } FLAC__ApodizationSpecification;
  89389. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89390. typedef struct FLAC__StreamEncoderProtected {
  89391. FLAC__StreamEncoderState state;
  89392. FLAC__bool verify;
  89393. FLAC__bool streamable_subset;
  89394. FLAC__bool do_md5;
  89395. FLAC__bool do_mid_side_stereo;
  89396. FLAC__bool loose_mid_side_stereo;
  89397. unsigned channels;
  89398. unsigned bits_per_sample;
  89399. unsigned sample_rate;
  89400. unsigned blocksize;
  89401. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89402. unsigned num_apodizations;
  89403. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89404. #endif
  89405. unsigned max_lpc_order;
  89406. unsigned qlp_coeff_precision;
  89407. FLAC__bool do_qlp_coeff_prec_search;
  89408. FLAC__bool do_exhaustive_model_search;
  89409. FLAC__bool do_escape_coding;
  89410. unsigned min_residual_partition_order;
  89411. unsigned max_residual_partition_order;
  89412. unsigned rice_parameter_search_dist;
  89413. FLAC__uint64 total_samples_estimate;
  89414. FLAC__StreamMetadata **metadata;
  89415. unsigned num_metadata_blocks;
  89416. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89417. #if FLAC__HAS_OGG
  89418. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89419. #endif
  89420. } FLAC__StreamEncoderProtected;
  89421. #endif
  89422. /*** End of inlined file: stream_encoder.h ***/
  89423. #if FLAC__HAS_OGG
  89424. #include "include/private/ogg_helper.h"
  89425. #include "include/private/ogg_mapping.h"
  89426. #endif
  89427. /*** Start of inlined file: stream_encoder_framing.h ***/
  89428. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89429. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89430. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89431. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89432. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89433. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89434. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89435. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89436. #endif
  89437. /*** End of inlined file: stream_encoder_framing.h ***/
  89438. /*** Start of inlined file: window.h ***/
  89439. #ifndef FLAC__PRIVATE__WINDOW_H
  89440. #define FLAC__PRIVATE__WINDOW_H
  89441. #ifdef HAVE_CONFIG_H
  89442. #include <config.h>
  89443. #endif
  89444. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89445. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89446. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89447. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89448. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89449. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89450. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89451. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89452. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89453. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89454. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89455. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89456. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89457. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89458. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89459. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89460. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89461. #endif
  89462. /*** End of inlined file: window.h ***/
  89463. #ifndef FLaC__INLINE
  89464. #define FLaC__INLINE
  89465. #endif
  89466. #ifdef min
  89467. #undef min
  89468. #endif
  89469. #define min(x,y) ((x)<(y)?(x):(y))
  89470. #ifdef max
  89471. #undef max
  89472. #endif
  89473. #define max(x,y) ((x)>(y)?(x):(y))
  89474. #undef EXACT_RICE_BITS_CALCULATION
  89475. #undef ENABLE_RICE_PARAMETER_SEARCH
  89476. typedef struct {
  89477. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89478. unsigned size; /* of each data[] in samples */
  89479. unsigned tail;
  89480. } verify_input_fifo;
  89481. typedef struct {
  89482. const FLAC__byte *data;
  89483. unsigned capacity;
  89484. unsigned bytes;
  89485. } verify_output;
  89486. typedef enum {
  89487. ENCODER_IN_MAGIC = 0,
  89488. ENCODER_IN_METADATA = 1,
  89489. ENCODER_IN_AUDIO = 2
  89490. } EncoderStateHint;
  89491. static struct CompressionLevels {
  89492. FLAC__bool do_mid_side_stereo;
  89493. FLAC__bool loose_mid_side_stereo;
  89494. unsigned max_lpc_order;
  89495. unsigned qlp_coeff_precision;
  89496. FLAC__bool do_qlp_coeff_prec_search;
  89497. FLAC__bool do_escape_coding;
  89498. FLAC__bool do_exhaustive_model_search;
  89499. unsigned min_residual_partition_order;
  89500. unsigned max_residual_partition_order;
  89501. unsigned rice_parameter_search_dist;
  89502. } compression_levels_[] = {
  89503. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  89504. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  89505. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  89506. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  89507. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  89508. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  89509. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  89510. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  89511. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  89512. };
  89513. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  89514. static void free_(FLAC__StreamEncoder *encoder);
  89515. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  89516. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  89517. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  89518. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  89519. #if FLAC__HAS_OGG
  89520. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  89521. #endif
  89522. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  89523. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  89524. static FLAC__bool process_subframe_(
  89525. FLAC__StreamEncoder *encoder,
  89526. unsigned min_partition_order,
  89527. unsigned max_partition_order,
  89528. const FLAC__FrameHeader *frame_header,
  89529. unsigned subframe_bps,
  89530. const FLAC__int32 integer_signal[],
  89531. FLAC__Subframe *subframe[2],
  89532. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  89533. FLAC__int32 *residual[2],
  89534. unsigned *best_subframe,
  89535. unsigned *best_bits
  89536. );
  89537. static FLAC__bool add_subframe_(
  89538. FLAC__StreamEncoder *encoder,
  89539. unsigned blocksize,
  89540. unsigned subframe_bps,
  89541. const FLAC__Subframe *subframe,
  89542. FLAC__BitWriter *frame
  89543. );
  89544. static unsigned evaluate_constant_subframe_(
  89545. FLAC__StreamEncoder *encoder,
  89546. const FLAC__int32 signal,
  89547. unsigned blocksize,
  89548. unsigned subframe_bps,
  89549. FLAC__Subframe *subframe
  89550. );
  89551. static unsigned evaluate_fixed_subframe_(
  89552. FLAC__StreamEncoder *encoder,
  89553. const FLAC__int32 signal[],
  89554. FLAC__int32 residual[],
  89555. FLAC__uint64 abs_residual_partition_sums[],
  89556. unsigned raw_bits_per_partition[],
  89557. unsigned blocksize,
  89558. unsigned subframe_bps,
  89559. unsigned order,
  89560. unsigned rice_parameter,
  89561. unsigned rice_parameter_limit,
  89562. unsigned min_partition_order,
  89563. unsigned max_partition_order,
  89564. FLAC__bool do_escape_coding,
  89565. unsigned rice_parameter_search_dist,
  89566. FLAC__Subframe *subframe,
  89567. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89568. );
  89569. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89570. static unsigned evaluate_lpc_subframe_(
  89571. FLAC__StreamEncoder *encoder,
  89572. const FLAC__int32 signal[],
  89573. FLAC__int32 residual[],
  89574. FLAC__uint64 abs_residual_partition_sums[],
  89575. unsigned raw_bits_per_partition[],
  89576. const FLAC__real lp_coeff[],
  89577. unsigned blocksize,
  89578. unsigned subframe_bps,
  89579. unsigned order,
  89580. unsigned qlp_coeff_precision,
  89581. unsigned rice_parameter,
  89582. unsigned rice_parameter_limit,
  89583. unsigned min_partition_order,
  89584. unsigned max_partition_order,
  89585. FLAC__bool do_escape_coding,
  89586. unsigned rice_parameter_search_dist,
  89587. FLAC__Subframe *subframe,
  89588. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  89589. );
  89590. #endif
  89591. static unsigned evaluate_verbatim_subframe_(
  89592. FLAC__StreamEncoder *encoder,
  89593. const FLAC__int32 signal[],
  89594. unsigned blocksize,
  89595. unsigned subframe_bps,
  89596. FLAC__Subframe *subframe
  89597. );
  89598. static unsigned find_best_partition_order_(
  89599. struct FLAC__StreamEncoderPrivate *private_,
  89600. const FLAC__int32 residual[],
  89601. FLAC__uint64 abs_residual_partition_sums[],
  89602. unsigned raw_bits_per_partition[],
  89603. unsigned residual_samples,
  89604. unsigned predictor_order,
  89605. unsigned rice_parameter,
  89606. unsigned rice_parameter_limit,
  89607. unsigned min_partition_order,
  89608. unsigned max_partition_order,
  89609. unsigned bps,
  89610. FLAC__bool do_escape_coding,
  89611. unsigned rice_parameter_search_dist,
  89612. FLAC__EntropyCodingMethod *best_ecm
  89613. );
  89614. static void precompute_partition_info_sums_(
  89615. const FLAC__int32 residual[],
  89616. FLAC__uint64 abs_residual_partition_sums[],
  89617. unsigned residual_samples,
  89618. unsigned predictor_order,
  89619. unsigned min_partition_order,
  89620. unsigned max_partition_order,
  89621. unsigned bps
  89622. );
  89623. static void precompute_partition_info_escapes_(
  89624. const FLAC__int32 residual[],
  89625. unsigned raw_bits_per_partition[],
  89626. unsigned residual_samples,
  89627. unsigned predictor_order,
  89628. unsigned min_partition_order,
  89629. unsigned max_partition_order
  89630. );
  89631. static FLAC__bool set_partitioned_rice_(
  89632. #ifdef EXACT_RICE_BITS_CALCULATION
  89633. const FLAC__int32 residual[],
  89634. #endif
  89635. const FLAC__uint64 abs_residual_partition_sums[],
  89636. const unsigned raw_bits_per_partition[],
  89637. const unsigned residual_samples,
  89638. const unsigned predictor_order,
  89639. const unsigned suggested_rice_parameter,
  89640. const unsigned rice_parameter_limit,
  89641. const unsigned rice_parameter_search_dist,
  89642. const unsigned partition_order,
  89643. const FLAC__bool search_for_escapes,
  89644. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  89645. unsigned *bits
  89646. );
  89647. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  89648. static void append_to_verify_fifo_(
  89649. verify_input_fifo *fifo,
  89650. const FLAC__int32 * const input[],
  89651. unsigned input_offset,
  89652. unsigned channels,
  89653. unsigned wide_samples
  89654. );
  89655. static void append_to_verify_fifo_interleaved_(
  89656. verify_input_fifo *fifo,
  89657. const FLAC__int32 input[],
  89658. unsigned input_offset,
  89659. unsigned channels,
  89660. unsigned wide_samples
  89661. );
  89662. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89663. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  89664. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  89665. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  89666. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  89667. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  89668. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  89669. 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);
  89670. static FILE *get_binary_stdout_(void);
  89671. typedef struct FLAC__StreamEncoderPrivate {
  89672. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  89673. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  89674. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  89675. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89676. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  89677. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  89678. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  89679. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  89680. #endif
  89681. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  89682. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  89683. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  89684. FLAC__int32 *residual_workspace_mid_side[2][2];
  89685. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  89686. FLAC__Subframe subframe_workspace_mid_side[2][2];
  89687. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89688. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  89689. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  89690. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  89691. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  89692. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  89693. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  89694. unsigned best_subframe_mid_side[2];
  89695. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  89696. unsigned best_subframe_bits_mid_side[2];
  89697. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  89698. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  89699. FLAC__BitWriter *frame; /* the current frame being worked on */
  89700. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  89701. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  89702. FLAC__ChannelAssignment last_channel_assignment;
  89703. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  89704. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  89705. unsigned current_sample_number;
  89706. unsigned current_frame_number;
  89707. FLAC__MD5Context md5context;
  89708. FLAC__CPUInfo cpuinfo;
  89709. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89710. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89711. #else
  89712. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  89713. #endif
  89714. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89715. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  89716. 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[]);
  89717. 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[]);
  89718. 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[]);
  89719. #endif
  89720. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  89721. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  89722. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  89723. FLAC__bool disable_constant_subframes;
  89724. FLAC__bool disable_fixed_subframes;
  89725. FLAC__bool disable_verbatim_subframes;
  89726. #if FLAC__HAS_OGG
  89727. FLAC__bool is_ogg;
  89728. #endif
  89729. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  89730. FLAC__StreamEncoderSeekCallback seek_callback;
  89731. FLAC__StreamEncoderTellCallback tell_callback;
  89732. FLAC__StreamEncoderWriteCallback write_callback;
  89733. FLAC__StreamEncoderMetadataCallback metadata_callback;
  89734. FLAC__StreamEncoderProgressCallback progress_callback;
  89735. void *client_data;
  89736. unsigned first_seekpoint_to_check;
  89737. FILE *file; /* only used when encoding to a file */
  89738. FLAC__uint64 bytes_written;
  89739. FLAC__uint64 samples_written;
  89740. unsigned frames_written;
  89741. unsigned total_frames_estimate;
  89742. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  89743. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  89744. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89745. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  89746. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  89747. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  89748. FLAC__real *windowed_signal_unaligned;
  89749. #endif
  89750. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  89751. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  89752. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  89753. unsigned *raw_bits_per_partition_unaligned;
  89754. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89755. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  89756. #endif
  89757. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  89758. struct {
  89759. FLAC__StreamDecoder *decoder;
  89760. EncoderStateHint state_hint;
  89761. FLAC__bool needs_magic_hack;
  89762. verify_input_fifo input_fifo;
  89763. verify_output output;
  89764. struct {
  89765. FLAC__uint64 absolute_sample;
  89766. unsigned frame_number;
  89767. unsigned channel;
  89768. unsigned sample;
  89769. FLAC__int32 expected;
  89770. FLAC__int32 got;
  89771. } error_stats;
  89772. } verify;
  89773. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  89774. } FLAC__StreamEncoderPrivate;
  89775. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  89776. "FLAC__STREAM_ENCODER_OK",
  89777. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  89778. "FLAC__STREAM_ENCODER_OGG_ERROR",
  89779. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  89780. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  89781. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  89782. "FLAC__STREAM_ENCODER_IO_ERROR",
  89783. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  89784. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  89785. };
  89786. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  89787. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  89788. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  89789. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  89790. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  89791. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  89792. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  89793. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  89794. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  89795. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  89796. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  89797. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  89798. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  89799. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  89800. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  89801. };
  89802. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  89803. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  89804. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  89805. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  89806. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  89807. };
  89808. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  89809. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  89810. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  89811. };
  89812. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  89813. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  89814. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  89815. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  89816. };
  89817. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  89818. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  89819. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  89820. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  89821. };
  89822. static const unsigned OVERREAD_ = 1;
  89823. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  89824. {
  89825. FLAC__StreamEncoder *encoder;
  89826. unsigned i;
  89827. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  89828. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  89829. if(encoder == 0) {
  89830. return 0;
  89831. }
  89832. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  89833. if(encoder->protected_ == 0) {
  89834. free(encoder);
  89835. return 0;
  89836. }
  89837. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  89838. if(encoder->private_ == 0) {
  89839. free(encoder->protected_);
  89840. free(encoder);
  89841. return 0;
  89842. }
  89843. encoder->private_->frame = FLAC__bitwriter_new();
  89844. if(encoder->private_->frame == 0) {
  89845. free(encoder->private_);
  89846. free(encoder->protected_);
  89847. free(encoder);
  89848. return 0;
  89849. }
  89850. encoder->private_->file = 0;
  89851. set_defaults_enc(encoder);
  89852. encoder->private_->is_being_deleted = false;
  89853. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89854. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  89855. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  89856. }
  89857. for(i = 0; i < 2; i++) {
  89858. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  89859. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  89860. }
  89861. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89862. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  89863. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  89864. }
  89865. for(i = 0; i < 2; i++) {
  89866. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  89867. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  89868. }
  89869. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89870. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89871. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89872. }
  89873. for(i = 0; i < 2; i++) {
  89874. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89875. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89876. }
  89877. for(i = 0; i < 2; i++)
  89878. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  89879. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  89880. return encoder;
  89881. }
  89882. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  89883. {
  89884. unsigned i;
  89885. FLAC__ASSERT(0 != encoder);
  89886. FLAC__ASSERT(0 != encoder->protected_);
  89887. FLAC__ASSERT(0 != encoder->private_);
  89888. FLAC__ASSERT(0 != encoder->private_->frame);
  89889. encoder->private_->is_being_deleted = true;
  89890. (void)FLAC__stream_encoder_finish(encoder);
  89891. if(0 != encoder->private_->verify.decoder)
  89892. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  89893. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  89894. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  89895. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  89896. }
  89897. for(i = 0; i < 2; i++) {
  89898. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  89899. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  89900. }
  89901. for(i = 0; i < 2; i++)
  89902. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  89903. FLAC__bitwriter_delete(encoder->private_->frame);
  89904. free(encoder->private_);
  89905. free(encoder->protected_);
  89906. free(encoder);
  89907. }
  89908. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  89909. FLAC__StreamEncoder *encoder,
  89910. FLAC__StreamEncoderReadCallback read_callback,
  89911. FLAC__StreamEncoderWriteCallback write_callback,
  89912. FLAC__StreamEncoderSeekCallback seek_callback,
  89913. FLAC__StreamEncoderTellCallback tell_callback,
  89914. FLAC__StreamEncoderMetadataCallback metadata_callback,
  89915. void *client_data,
  89916. FLAC__bool is_ogg
  89917. )
  89918. {
  89919. unsigned i;
  89920. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  89921. FLAC__ASSERT(0 != encoder);
  89922. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  89923. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  89924. #if !FLAC__HAS_OGG
  89925. if(is_ogg)
  89926. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  89927. #endif
  89928. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  89929. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  89930. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  89931. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  89932. if(encoder->protected_->channels != 2) {
  89933. encoder->protected_->do_mid_side_stereo = false;
  89934. encoder->protected_->loose_mid_side_stereo = false;
  89935. }
  89936. else if(!encoder->protected_->do_mid_side_stereo)
  89937. encoder->protected_->loose_mid_side_stereo = false;
  89938. if(encoder->protected_->bits_per_sample >= 32)
  89939. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  89940. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  89941. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  89942. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  89943. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  89944. if(encoder->protected_->blocksize == 0) {
  89945. if(encoder->protected_->max_lpc_order == 0)
  89946. encoder->protected_->blocksize = 1152;
  89947. else
  89948. encoder->protected_->blocksize = 4096;
  89949. }
  89950. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  89951. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  89952. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  89953. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  89954. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  89955. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  89956. if(encoder->protected_->qlp_coeff_precision == 0) {
  89957. if(encoder->protected_->bits_per_sample < 16) {
  89958. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  89959. }
  89960. else if(encoder->protected_->bits_per_sample == 16) {
  89961. if(encoder->protected_->blocksize <= 192)
  89962. encoder->protected_->qlp_coeff_precision = 7;
  89963. else if(encoder->protected_->blocksize <= 384)
  89964. encoder->protected_->qlp_coeff_precision = 8;
  89965. else if(encoder->protected_->blocksize <= 576)
  89966. encoder->protected_->qlp_coeff_precision = 9;
  89967. else if(encoder->protected_->blocksize <= 1152)
  89968. encoder->protected_->qlp_coeff_precision = 10;
  89969. else if(encoder->protected_->blocksize <= 2304)
  89970. encoder->protected_->qlp_coeff_precision = 11;
  89971. else if(encoder->protected_->blocksize <= 4608)
  89972. encoder->protected_->qlp_coeff_precision = 12;
  89973. else
  89974. encoder->protected_->qlp_coeff_precision = 13;
  89975. }
  89976. else {
  89977. if(encoder->protected_->blocksize <= 384)
  89978. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  89979. else if(encoder->protected_->blocksize <= 1152)
  89980. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  89981. else
  89982. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  89983. }
  89984. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  89985. }
  89986. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  89987. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  89988. if(encoder->protected_->streamable_subset) {
  89989. if(
  89990. encoder->protected_->blocksize != 192 &&
  89991. encoder->protected_->blocksize != 576 &&
  89992. encoder->protected_->blocksize != 1152 &&
  89993. encoder->protected_->blocksize != 2304 &&
  89994. encoder->protected_->blocksize != 4608 &&
  89995. encoder->protected_->blocksize != 256 &&
  89996. encoder->protected_->blocksize != 512 &&
  89997. encoder->protected_->blocksize != 1024 &&
  89998. encoder->protected_->blocksize != 2048 &&
  89999. encoder->protected_->blocksize != 4096 &&
  90000. encoder->protected_->blocksize != 8192 &&
  90001. encoder->protected_->blocksize != 16384
  90002. )
  90003. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90004. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90005. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90006. if(
  90007. encoder->protected_->bits_per_sample != 8 &&
  90008. encoder->protected_->bits_per_sample != 12 &&
  90009. encoder->protected_->bits_per_sample != 16 &&
  90010. encoder->protected_->bits_per_sample != 20 &&
  90011. encoder->protected_->bits_per_sample != 24
  90012. )
  90013. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90014. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90015. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90016. if(
  90017. encoder->protected_->sample_rate <= 48000 &&
  90018. (
  90019. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90020. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90021. )
  90022. ) {
  90023. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90024. }
  90025. }
  90026. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90027. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90028. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90029. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90030. #if FLAC__HAS_OGG
  90031. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90032. unsigned i;
  90033. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90034. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90035. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90036. for( ; i > 0; i--)
  90037. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90038. encoder->protected_->metadata[0] = vc;
  90039. break;
  90040. }
  90041. }
  90042. }
  90043. #endif
  90044. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90045. unsigned i;
  90046. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90047. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90048. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90049. break; /* take only the first one */
  90050. }
  90051. }
  90052. }
  90053. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90054. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90055. metadata_has_seektable = false;
  90056. metadata_has_vorbis_comment = false;
  90057. metadata_picture_has_type1 = false;
  90058. metadata_picture_has_type2 = false;
  90059. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90060. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90061. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90062. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90063. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90064. if(metadata_has_seektable) /* only one is allowed */
  90065. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90066. metadata_has_seektable = true;
  90067. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90068. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90069. }
  90070. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90071. if(metadata_has_vorbis_comment) /* only one is allowed */
  90072. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90073. metadata_has_vorbis_comment = true;
  90074. }
  90075. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90076. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90077. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90078. }
  90079. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90080. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90081. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90082. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90083. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90084. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90085. metadata_picture_has_type1 = true;
  90086. if(
  90087. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90088. (
  90089. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90090. m->data.picture.width != 32 ||
  90091. m->data.picture.height != 32
  90092. )
  90093. )
  90094. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90095. }
  90096. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90097. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90098. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90099. metadata_picture_has_type2 = true;
  90100. }
  90101. }
  90102. }
  90103. encoder->private_->input_capacity = 0;
  90104. for(i = 0; i < encoder->protected_->channels; i++) {
  90105. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90106. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90107. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90108. #endif
  90109. }
  90110. for(i = 0; i < 2; i++) {
  90111. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90112. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90113. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90114. #endif
  90115. }
  90116. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90117. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90118. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90119. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90120. #endif
  90121. for(i = 0; i < encoder->protected_->channels; i++) {
  90122. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90123. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90124. encoder->private_->best_subframe[i] = 0;
  90125. }
  90126. for(i = 0; i < 2; i++) {
  90127. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90128. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90129. encoder->private_->best_subframe_mid_side[i] = 0;
  90130. }
  90131. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90132. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90133. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90134. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90135. #else
  90136. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90137. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90138. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90139. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90140. 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);
  90141. #endif
  90142. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90143. encoder->private_->loose_mid_side_stereo_frames = 1;
  90144. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90145. encoder->private_->current_sample_number = 0;
  90146. encoder->private_->current_frame_number = 0;
  90147. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90148. 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? */
  90149. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90150. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90151. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90152. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90153. #endif
  90154. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90155. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90156. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90157. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90158. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90159. #endif
  90160. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90161. # ifndef FLAC__NO_ASM
  90162. if(encoder->private_->cpuinfo.use_asm) {
  90163. # ifdef FLAC__CPU_IA32
  90164. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90165. # ifdef FLAC__HAS_NASM
  90166. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90167. if(encoder->protected_->max_lpc_order < 4)
  90168. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90169. else if(encoder->protected_->max_lpc_order < 8)
  90170. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90171. else if(encoder->protected_->max_lpc_order < 12)
  90172. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90173. else
  90174. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90175. }
  90176. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90177. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90178. else
  90179. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90180. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90181. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90182. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90183. }
  90184. else {
  90185. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90186. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90187. }
  90188. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90189. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90190. # endif /* FLAC__HAS_NASM */
  90191. # endif /* FLAC__CPU_IA32 */
  90192. }
  90193. # endif /* !FLAC__NO_ASM */
  90194. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90195. if(encoder->private_->use_wide_by_block) {
  90196. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90197. }
  90198. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90199. #if FLAC__HAS_OGG
  90200. encoder->private_->is_ogg = is_ogg;
  90201. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90202. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90203. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90204. }
  90205. #endif
  90206. encoder->private_->read_callback = read_callback;
  90207. encoder->private_->write_callback = write_callback;
  90208. encoder->private_->seek_callback = seek_callback;
  90209. encoder->private_->tell_callback = tell_callback;
  90210. encoder->private_->metadata_callback = metadata_callback;
  90211. encoder->private_->client_data = client_data;
  90212. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90213. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90214. }
  90215. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90216. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90217. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90218. }
  90219. if(encoder->protected_->verify) {
  90220. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90221. for(i = 0; i < encoder->protected_->channels; i++) {
  90222. 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))) {
  90223. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90224. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90225. }
  90226. }
  90227. encoder->private_->verify.input_fifo.tail = 0;
  90228. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90229. if(0 == encoder->private_->verify.decoder) {
  90230. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90231. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90232. }
  90233. 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) {
  90234. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90235. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90236. }
  90237. }
  90238. encoder->private_->verify.error_stats.absolute_sample = 0;
  90239. encoder->private_->verify.error_stats.frame_number = 0;
  90240. encoder->private_->verify.error_stats.channel = 0;
  90241. encoder->private_->verify.error_stats.sample = 0;
  90242. encoder->private_->verify.error_stats.expected = 0;
  90243. encoder->private_->verify.error_stats.got = 0;
  90244. encoder->private_->first_seekpoint_to_check = 0;
  90245. encoder->private_->samples_written = 0;
  90246. encoder->protected_->streaminfo_offset = 0;
  90247. encoder->protected_->seektable_offset = 0;
  90248. encoder->protected_->audio_offset = 0;
  90249. if(encoder->protected_->verify)
  90250. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90251. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90252. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90253. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90254. }
  90255. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90256. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90257. }
  90258. if(encoder->protected_->verify)
  90259. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90260. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90261. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90262. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90263. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90264. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90265. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90266. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90267. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90268. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90269. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90270. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90271. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90272. if(encoder->protected_->do_md5)
  90273. FLAC__MD5Init(&encoder->private_->md5context);
  90274. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90275. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90276. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90277. }
  90278. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90279. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90280. }
  90281. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90282. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90283. if(!metadata_has_vorbis_comment) {
  90284. FLAC__StreamMetadata vorbis_comment;
  90285. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90286. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90287. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90288. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90289. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90290. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90291. vorbis_comment.data.vorbis_comment.comments = 0;
  90292. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90293. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90294. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90295. }
  90296. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90297. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90298. }
  90299. }
  90300. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90301. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90302. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90303. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90304. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90305. }
  90306. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90307. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90308. }
  90309. }
  90310. 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 */
  90311. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90312. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90313. }
  90314. if(encoder->protected_->verify)
  90315. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90316. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90317. }
  90318. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90319. FLAC__StreamEncoder *encoder,
  90320. FLAC__StreamEncoderWriteCallback write_callback,
  90321. FLAC__StreamEncoderSeekCallback seek_callback,
  90322. FLAC__StreamEncoderTellCallback tell_callback,
  90323. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90324. void *client_data
  90325. )
  90326. {
  90327. return init_stream_internal_enc(
  90328. encoder,
  90329. 0,
  90330. write_callback,
  90331. seek_callback,
  90332. tell_callback,
  90333. metadata_callback,
  90334. client_data,
  90335. false
  90336. );
  90337. }
  90338. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90339. FLAC__StreamEncoder *encoder,
  90340. FLAC__StreamEncoderReadCallback read_callback,
  90341. FLAC__StreamEncoderWriteCallback write_callback,
  90342. FLAC__StreamEncoderSeekCallback seek_callback,
  90343. FLAC__StreamEncoderTellCallback tell_callback,
  90344. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90345. void *client_data
  90346. )
  90347. {
  90348. return init_stream_internal_enc(
  90349. encoder,
  90350. read_callback,
  90351. write_callback,
  90352. seek_callback,
  90353. tell_callback,
  90354. metadata_callback,
  90355. client_data,
  90356. true
  90357. );
  90358. }
  90359. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90360. FLAC__StreamEncoder *encoder,
  90361. FILE *file,
  90362. FLAC__StreamEncoderProgressCallback progress_callback,
  90363. void *client_data,
  90364. FLAC__bool is_ogg
  90365. )
  90366. {
  90367. FLAC__StreamEncoderInitStatus init_status;
  90368. FLAC__ASSERT(0 != encoder);
  90369. FLAC__ASSERT(0 != file);
  90370. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90371. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90372. if(file == 0) {
  90373. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90374. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90375. }
  90376. if(file == stdout)
  90377. file = get_binary_stdout_(); /* just to be safe */
  90378. encoder->private_->file = file;
  90379. encoder->private_->progress_callback = progress_callback;
  90380. encoder->private_->bytes_written = 0;
  90381. encoder->private_->samples_written = 0;
  90382. encoder->private_->frames_written = 0;
  90383. init_status = init_stream_internal_enc(
  90384. encoder,
  90385. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90386. file_write_callback_,
  90387. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90388. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90389. 0,
  90390. client_data,
  90391. is_ogg
  90392. );
  90393. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90394. return init_status;
  90395. }
  90396. {
  90397. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90398. FLAC__ASSERT(blocksize != 0);
  90399. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90400. }
  90401. return init_status;
  90402. }
  90403. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90404. FLAC__StreamEncoder *encoder,
  90405. FILE *file,
  90406. FLAC__StreamEncoderProgressCallback progress_callback,
  90407. void *client_data
  90408. )
  90409. {
  90410. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90411. }
  90412. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90413. FLAC__StreamEncoder *encoder,
  90414. FILE *file,
  90415. FLAC__StreamEncoderProgressCallback progress_callback,
  90416. void *client_data
  90417. )
  90418. {
  90419. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90420. }
  90421. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90422. FLAC__StreamEncoder *encoder,
  90423. const char *filename,
  90424. FLAC__StreamEncoderProgressCallback progress_callback,
  90425. void *client_data,
  90426. FLAC__bool is_ogg
  90427. )
  90428. {
  90429. FILE *file;
  90430. FLAC__ASSERT(0 != encoder);
  90431. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90432. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90433. file = filename? fopen(filename, "w+b") : stdout;
  90434. if(file == 0) {
  90435. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90436. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90437. }
  90438. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90439. }
  90440. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90441. FLAC__StreamEncoder *encoder,
  90442. const char *filename,
  90443. FLAC__StreamEncoderProgressCallback progress_callback,
  90444. void *client_data
  90445. )
  90446. {
  90447. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90448. }
  90449. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90450. FLAC__StreamEncoder *encoder,
  90451. const char *filename,
  90452. FLAC__StreamEncoderProgressCallback progress_callback,
  90453. void *client_data
  90454. )
  90455. {
  90456. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90457. }
  90458. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90459. {
  90460. FLAC__bool error = false;
  90461. FLAC__ASSERT(0 != encoder);
  90462. FLAC__ASSERT(0 != encoder->private_);
  90463. FLAC__ASSERT(0 != encoder->protected_);
  90464. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90465. return true;
  90466. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90467. if(encoder->private_->current_sample_number != 0) {
  90468. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90469. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90470. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90471. error = true;
  90472. }
  90473. }
  90474. if(encoder->protected_->do_md5)
  90475. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90476. if(!encoder->private_->is_being_deleted) {
  90477. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90478. if(encoder->private_->seek_callback) {
  90479. #if FLAC__HAS_OGG
  90480. if(encoder->private_->is_ogg)
  90481. update_ogg_metadata_(encoder);
  90482. else
  90483. #endif
  90484. update_metadata_(encoder);
  90485. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90486. error = true;
  90487. }
  90488. if(encoder->private_->metadata_callback)
  90489. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90490. }
  90491. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90492. if(!error)
  90493. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90494. error = true;
  90495. }
  90496. }
  90497. if(0 != encoder->private_->file) {
  90498. if(encoder->private_->file != stdout)
  90499. fclose(encoder->private_->file);
  90500. encoder->private_->file = 0;
  90501. }
  90502. #if FLAC__HAS_OGG
  90503. if(encoder->private_->is_ogg)
  90504. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  90505. #endif
  90506. free_(encoder);
  90507. set_defaults_enc(encoder);
  90508. if(!error)
  90509. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90510. return !error;
  90511. }
  90512. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  90513. {
  90514. FLAC__ASSERT(0 != encoder);
  90515. FLAC__ASSERT(0 != encoder->private_);
  90516. FLAC__ASSERT(0 != encoder->protected_);
  90517. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90518. return false;
  90519. #if FLAC__HAS_OGG
  90520. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  90521. return true;
  90522. #else
  90523. (void)value;
  90524. return false;
  90525. #endif
  90526. }
  90527. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90528. {
  90529. FLAC__ASSERT(0 != encoder);
  90530. FLAC__ASSERT(0 != encoder->private_);
  90531. FLAC__ASSERT(0 != encoder->protected_);
  90532. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90533. return false;
  90534. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  90535. encoder->protected_->verify = value;
  90536. #endif
  90537. return true;
  90538. }
  90539. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90540. {
  90541. FLAC__ASSERT(0 != encoder);
  90542. FLAC__ASSERT(0 != encoder->private_);
  90543. FLAC__ASSERT(0 != encoder->protected_);
  90544. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90545. return false;
  90546. encoder->protected_->streamable_subset = value;
  90547. return true;
  90548. }
  90549. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90550. {
  90551. FLAC__ASSERT(0 != encoder);
  90552. FLAC__ASSERT(0 != encoder->private_);
  90553. FLAC__ASSERT(0 != encoder->protected_);
  90554. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90555. return false;
  90556. encoder->protected_->do_md5 = value;
  90557. return true;
  90558. }
  90559. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  90560. {
  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. encoder->protected_->channels = value;
  90567. return true;
  90568. }
  90569. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  90570. {
  90571. FLAC__ASSERT(0 != encoder);
  90572. FLAC__ASSERT(0 != encoder->private_);
  90573. FLAC__ASSERT(0 != encoder->protected_);
  90574. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90575. return false;
  90576. encoder->protected_->bits_per_sample = value;
  90577. return true;
  90578. }
  90579. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  90580. {
  90581. FLAC__ASSERT(0 != encoder);
  90582. FLAC__ASSERT(0 != encoder->private_);
  90583. FLAC__ASSERT(0 != encoder->protected_);
  90584. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90585. return false;
  90586. encoder->protected_->sample_rate = value;
  90587. return true;
  90588. }
  90589. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  90590. {
  90591. FLAC__bool ok = true;
  90592. FLAC__ASSERT(0 != encoder);
  90593. FLAC__ASSERT(0 != encoder->private_);
  90594. FLAC__ASSERT(0 != encoder->protected_);
  90595. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90596. return false;
  90597. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  90598. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  90599. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  90600. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  90601. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90602. #if 0
  90603. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  90604. #else
  90605. encoder->protected_->num_apodizations = 1;
  90606. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90607. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90608. #endif
  90609. #endif
  90610. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  90611. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  90612. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  90613. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  90614. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  90615. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  90616. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  90617. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  90618. return ok;
  90619. }
  90620. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  90621. {
  90622. FLAC__ASSERT(0 != encoder);
  90623. FLAC__ASSERT(0 != encoder->private_);
  90624. FLAC__ASSERT(0 != encoder->protected_);
  90625. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90626. return false;
  90627. encoder->protected_->blocksize = value;
  90628. return true;
  90629. }
  90630. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90631. {
  90632. FLAC__ASSERT(0 != encoder);
  90633. FLAC__ASSERT(0 != encoder->private_);
  90634. FLAC__ASSERT(0 != encoder->protected_);
  90635. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90636. return false;
  90637. encoder->protected_->do_mid_side_stereo = value;
  90638. return true;
  90639. }
  90640. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90641. {
  90642. FLAC__ASSERT(0 != encoder);
  90643. FLAC__ASSERT(0 != encoder->private_);
  90644. FLAC__ASSERT(0 != encoder->protected_);
  90645. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90646. return false;
  90647. encoder->protected_->loose_mid_side_stereo = value;
  90648. return true;
  90649. }
  90650. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  90651. {
  90652. FLAC__ASSERT(0 != encoder);
  90653. FLAC__ASSERT(0 != encoder->private_);
  90654. FLAC__ASSERT(0 != encoder->protected_);
  90655. FLAC__ASSERT(0 != specification);
  90656. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90657. return false;
  90658. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  90659. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  90660. #else
  90661. encoder->protected_->num_apodizations = 0;
  90662. while(1) {
  90663. const char *s = strchr(specification, ';');
  90664. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  90665. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  90666. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  90667. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  90668. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  90669. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  90670. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  90671. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  90672. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  90673. else if(n==6 && 0 == strncmp("connes" , specification, n))
  90674. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  90675. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  90676. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  90677. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  90678. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  90679. if (stddev > 0.0 && stddev <= 0.5) {
  90680. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  90681. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  90682. }
  90683. }
  90684. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  90685. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  90686. else if(n==4 && 0 == strncmp("hann" , specification, n))
  90687. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  90688. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  90689. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  90690. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  90691. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  90692. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  90693. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  90694. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  90695. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  90696. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  90697. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  90698. if (p >= 0.0 && p <= 1.0) {
  90699. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  90700. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  90701. }
  90702. }
  90703. else if(n==5 && 0 == strncmp("welch" , specification, n))
  90704. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  90705. if (encoder->protected_->num_apodizations == 32)
  90706. break;
  90707. if (s)
  90708. specification = s+1;
  90709. else
  90710. break;
  90711. }
  90712. if(encoder->protected_->num_apodizations == 0) {
  90713. encoder->protected_->num_apodizations = 1;
  90714. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  90715. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  90716. }
  90717. #endif
  90718. return true;
  90719. }
  90720. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  90721. {
  90722. FLAC__ASSERT(0 != encoder);
  90723. FLAC__ASSERT(0 != encoder->private_);
  90724. FLAC__ASSERT(0 != encoder->protected_);
  90725. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90726. return false;
  90727. encoder->protected_->max_lpc_order = value;
  90728. return true;
  90729. }
  90730. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  90731. {
  90732. FLAC__ASSERT(0 != encoder);
  90733. FLAC__ASSERT(0 != encoder->private_);
  90734. FLAC__ASSERT(0 != encoder->protected_);
  90735. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90736. return false;
  90737. encoder->protected_->qlp_coeff_precision = value;
  90738. return true;
  90739. }
  90740. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90741. {
  90742. FLAC__ASSERT(0 != encoder);
  90743. FLAC__ASSERT(0 != encoder->private_);
  90744. FLAC__ASSERT(0 != encoder->protected_);
  90745. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90746. return false;
  90747. encoder->protected_->do_qlp_coeff_prec_search = value;
  90748. return true;
  90749. }
  90750. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90751. {
  90752. FLAC__ASSERT(0 != encoder);
  90753. FLAC__ASSERT(0 != encoder->private_);
  90754. FLAC__ASSERT(0 != encoder->protected_);
  90755. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90756. return false;
  90757. #if 0
  90758. encoder->protected_->do_escape_coding = value;
  90759. #else
  90760. (void)value;
  90761. #endif
  90762. return true;
  90763. }
  90764. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90765. {
  90766. FLAC__ASSERT(0 != encoder);
  90767. FLAC__ASSERT(0 != encoder->private_);
  90768. FLAC__ASSERT(0 != encoder->protected_);
  90769. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90770. return false;
  90771. encoder->protected_->do_exhaustive_model_search = value;
  90772. return true;
  90773. }
  90774. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90775. {
  90776. FLAC__ASSERT(0 != encoder);
  90777. FLAC__ASSERT(0 != encoder->private_);
  90778. FLAC__ASSERT(0 != encoder->protected_);
  90779. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90780. return false;
  90781. encoder->protected_->min_residual_partition_order = value;
  90782. return true;
  90783. }
  90784. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  90785. {
  90786. FLAC__ASSERT(0 != encoder);
  90787. FLAC__ASSERT(0 != encoder->private_);
  90788. FLAC__ASSERT(0 != encoder->protected_);
  90789. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90790. return false;
  90791. encoder->protected_->max_residual_partition_order = value;
  90792. return true;
  90793. }
  90794. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  90795. {
  90796. FLAC__ASSERT(0 != encoder);
  90797. FLAC__ASSERT(0 != encoder->private_);
  90798. FLAC__ASSERT(0 != encoder->protected_);
  90799. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90800. return false;
  90801. #if 0
  90802. encoder->protected_->rice_parameter_search_dist = value;
  90803. #else
  90804. (void)value;
  90805. #endif
  90806. return true;
  90807. }
  90808. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  90809. {
  90810. FLAC__ASSERT(0 != encoder);
  90811. FLAC__ASSERT(0 != encoder->private_);
  90812. FLAC__ASSERT(0 != encoder->protected_);
  90813. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90814. return false;
  90815. encoder->protected_->total_samples_estimate = value;
  90816. return true;
  90817. }
  90818. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  90819. {
  90820. FLAC__ASSERT(0 != encoder);
  90821. FLAC__ASSERT(0 != encoder->private_);
  90822. FLAC__ASSERT(0 != encoder->protected_);
  90823. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90824. return false;
  90825. if(0 == metadata)
  90826. num_blocks = 0;
  90827. if(0 == num_blocks)
  90828. metadata = 0;
  90829. if(encoder->protected_->metadata) {
  90830. free(encoder->protected_->metadata);
  90831. encoder->protected_->metadata = 0;
  90832. encoder->protected_->num_metadata_blocks = 0;
  90833. }
  90834. if(num_blocks) {
  90835. FLAC__StreamMetadata **m;
  90836. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  90837. return false;
  90838. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  90839. encoder->protected_->metadata = m;
  90840. encoder->protected_->num_metadata_blocks = num_blocks;
  90841. }
  90842. #if FLAC__HAS_OGG
  90843. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  90844. return false;
  90845. #endif
  90846. return true;
  90847. }
  90848. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90849. {
  90850. FLAC__ASSERT(0 != encoder);
  90851. FLAC__ASSERT(0 != encoder->private_);
  90852. FLAC__ASSERT(0 != encoder->protected_);
  90853. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90854. return false;
  90855. encoder->private_->disable_constant_subframes = value;
  90856. return true;
  90857. }
  90858. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90859. {
  90860. FLAC__ASSERT(0 != encoder);
  90861. FLAC__ASSERT(0 != encoder->private_);
  90862. FLAC__ASSERT(0 != encoder->protected_);
  90863. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90864. return false;
  90865. encoder->private_->disable_fixed_subframes = value;
  90866. return true;
  90867. }
  90868. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  90869. {
  90870. FLAC__ASSERT(0 != encoder);
  90871. FLAC__ASSERT(0 != encoder->private_);
  90872. FLAC__ASSERT(0 != encoder->protected_);
  90873. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90874. return false;
  90875. encoder->private_->disable_verbatim_subframes = value;
  90876. return true;
  90877. }
  90878. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  90879. {
  90880. FLAC__ASSERT(0 != encoder);
  90881. FLAC__ASSERT(0 != encoder->private_);
  90882. FLAC__ASSERT(0 != encoder->protected_);
  90883. return encoder->protected_->state;
  90884. }
  90885. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  90886. {
  90887. FLAC__ASSERT(0 != encoder);
  90888. FLAC__ASSERT(0 != encoder->private_);
  90889. FLAC__ASSERT(0 != encoder->protected_);
  90890. if(encoder->protected_->verify)
  90891. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  90892. else
  90893. return FLAC__STREAM_DECODER_UNINITIALIZED;
  90894. }
  90895. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  90896. {
  90897. FLAC__ASSERT(0 != encoder);
  90898. FLAC__ASSERT(0 != encoder->private_);
  90899. FLAC__ASSERT(0 != encoder->protected_);
  90900. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  90901. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  90902. else
  90903. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  90904. }
  90905. 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)
  90906. {
  90907. FLAC__ASSERT(0 != encoder);
  90908. FLAC__ASSERT(0 != encoder->private_);
  90909. FLAC__ASSERT(0 != encoder->protected_);
  90910. if(0 != absolute_sample)
  90911. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  90912. if(0 != frame_number)
  90913. *frame_number = encoder->private_->verify.error_stats.frame_number;
  90914. if(0 != channel)
  90915. *channel = encoder->private_->verify.error_stats.channel;
  90916. if(0 != sample)
  90917. *sample = encoder->private_->verify.error_stats.sample;
  90918. if(0 != expected)
  90919. *expected = encoder->private_->verify.error_stats.expected;
  90920. if(0 != got)
  90921. *got = encoder->private_->verify.error_stats.got;
  90922. }
  90923. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  90924. {
  90925. FLAC__ASSERT(0 != encoder);
  90926. FLAC__ASSERT(0 != encoder->private_);
  90927. FLAC__ASSERT(0 != encoder->protected_);
  90928. return encoder->protected_->verify;
  90929. }
  90930. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  90931. {
  90932. FLAC__ASSERT(0 != encoder);
  90933. FLAC__ASSERT(0 != encoder->private_);
  90934. FLAC__ASSERT(0 != encoder->protected_);
  90935. return encoder->protected_->streamable_subset;
  90936. }
  90937. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  90938. {
  90939. FLAC__ASSERT(0 != encoder);
  90940. FLAC__ASSERT(0 != encoder->private_);
  90941. FLAC__ASSERT(0 != encoder->protected_);
  90942. return encoder->protected_->do_md5;
  90943. }
  90944. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  90945. {
  90946. FLAC__ASSERT(0 != encoder);
  90947. FLAC__ASSERT(0 != encoder->private_);
  90948. FLAC__ASSERT(0 != encoder->protected_);
  90949. return encoder->protected_->channels;
  90950. }
  90951. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  90952. {
  90953. FLAC__ASSERT(0 != encoder);
  90954. FLAC__ASSERT(0 != encoder->private_);
  90955. FLAC__ASSERT(0 != encoder->protected_);
  90956. return encoder->protected_->bits_per_sample;
  90957. }
  90958. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  90959. {
  90960. FLAC__ASSERT(0 != encoder);
  90961. FLAC__ASSERT(0 != encoder->private_);
  90962. FLAC__ASSERT(0 != encoder->protected_);
  90963. return encoder->protected_->sample_rate;
  90964. }
  90965. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  90966. {
  90967. FLAC__ASSERT(0 != encoder);
  90968. FLAC__ASSERT(0 != encoder->private_);
  90969. FLAC__ASSERT(0 != encoder->protected_);
  90970. return encoder->protected_->blocksize;
  90971. }
  90972. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  90973. {
  90974. FLAC__ASSERT(0 != encoder);
  90975. FLAC__ASSERT(0 != encoder->private_);
  90976. FLAC__ASSERT(0 != encoder->protected_);
  90977. return encoder->protected_->do_mid_side_stereo;
  90978. }
  90979. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  90980. {
  90981. FLAC__ASSERT(0 != encoder);
  90982. FLAC__ASSERT(0 != encoder->private_);
  90983. FLAC__ASSERT(0 != encoder->protected_);
  90984. return encoder->protected_->loose_mid_side_stereo;
  90985. }
  90986. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  90987. {
  90988. FLAC__ASSERT(0 != encoder);
  90989. FLAC__ASSERT(0 != encoder->private_);
  90990. FLAC__ASSERT(0 != encoder->protected_);
  90991. return encoder->protected_->max_lpc_order;
  90992. }
  90993. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  90994. {
  90995. FLAC__ASSERT(0 != encoder);
  90996. FLAC__ASSERT(0 != encoder->private_);
  90997. FLAC__ASSERT(0 != encoder->protected_);
  90998. return encoder->protected_->qlp_coeff_precision;
  90999. }
  91000. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91001. {
  91002. FLAC__ASSERT(0 != encoder);
  91003. FLAC__ASSERT(0 != encoder->private_);
  91004. FLAC__ASSERT(0 != encoder->protected_);
  91005. return encoder->protected_->do_qlp_coeff_prec_search;
  91006. }
  91007. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91008. {
  91009. FLAC__ASSERT(0 != encoder);
  91010. FLAC__ASSERT(0 != encoder->private_);
  91011. FLAC__ASSERT(0 != encoder->protected_);
  91012. return encoder->protected_->do_escape_coding;
  91013. }
  91014. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91015. {
  91016. FLAC__ASSERT(0 != encoder);
  91017. FLAC__ASSERT(0 != encoder->private_);
  91018. FLAC__ASSERT(0 != encoder->protected_);
  91019. return encoder->protected_->do_exhaustive_model_search;
  91020. }
  91021. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91022. {
  91023. FLAC__ASSERT(0 != encoder);
  91024. FLAC__ASSERT(0 != encoder->private_);
  91025. FLAC__ASSERT(0 != encoder->protected_);
  91026. return encoder->protected_->min_residual_partition_order;
  91027. }
  91028. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91029. {
  91030. FLAC__ASSERT(0 != encoder);
  91031. FLAC__ASSERT(0 != encoder->private_);
  91032. FLAC__ASSERT(0 != encoder->protected_);
  91033. return encoder->protected_->max_residual_partition_order;
  91034. }
  91035. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91036. {
  91037. FLAC__ASSERT(0 != encoder);
  91038. FLAC__ASSERT(0 != encoder->private_);
  91039. FLAC__ASSERT(0 != encoder->protected_);
  91040. return encoder->protected_->rice_parameter_search_dist;
  91041. }
  91042. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91043. {
  91044. FLAC__ASSERT(0 != encoder);
  91045. FLAC__ASSERT(0 != encoder->private_);
  91046. FLAC__ASSERT(0 != encoder->protected_);
  91047. return encoder->protected_->total_samples_estimate;
  91048. }
  91049. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91050. {
  91051. unsigned i, j = 0, channel;
  91052. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91053. FLAC__ASSERT(0 != encoder);
  91054. FLAC__ASSERT(0 != encoder->private_);
  91055. FLAC__ASSERT(0 != encoder->protected_);
  91056. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91057. do {
  91058. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91059. if(encoder->protected_->verify)
  91060. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91061. for(channel = 0; channel < channels; channel++)
  91062. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91063. if(encoder->protected_->do_mid_side_stereo) {
  91064. FLAC__ASSERT(channels == 2);
  91065. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91066. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91067. 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' ! */
  91068. }
  91069. }
  91070. else
  91071. j += n;
  91072. encoder->private_->current_sample_number += n;
  91073. if(encoder->private_->current_sample_number > blocksize) {
  91074. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91075. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91076. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91077. return false;
  91078. for(channel = 0; channel < channels; channel++)
  91079. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91080. if(encoder->protected_->do_mid_side_stereo) {
  91081. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91082. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91083. }
  91084. encoder->private_->current_sample_number = 1;
  91085. }
  91086. } while(j < samples);
  91087. return true;
  91088. }
  91089. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91090. {
  91091. unsigned i, j, k, channel;
  91092. FLAC__int32 x, mid, side;
  91093. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91094. FLAC__ASSERT(0 != encoder);
  91095. FLAC__ASSERT(0 != encoder->private_);
  91096. FLAC__ASSERT(0 != encoder->protected_);
  91097. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91098. j = k = 0;
  91099. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91100. do {
  91101. if(encoder->protected_->verify)
  91102. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91103. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91104. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91105. x = buffer[k++];
  91106. encoder->private_->integer_signal[1][i] = x;
  91107. mid += x;
  91108. side -= x;
  91109. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91110. encoder->private_->integer_signal_mid_side[1][i] = side;
  91111. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91112. }
  91113. encoder->private_->current_sample_number = i;
  91114. if(i > blocksize) {
  91115. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91116. return false;
  91117. /* move unprocessed overread samples to beginnings of arrays */
  91118. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91119. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91120. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91121. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91122. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91123. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91124. encoder->private_->current_sample_number = 1;
  91125. }
  91126. } while(j < samples);
  91127. }
  91128. else {
  91129. do {
  91130. if(encoder->protected_->verify)
  91131. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91132. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91133. for(channel = 0; channel < channels; channel++)
  91134. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91135. }
  91136. encoder->private_->current_sample_number = i;
  91137. if(i > blocksize) {
  91138. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91139. return false;
  91140. /* move unprocessed overread samples to beginnings of arrays */
  91141. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91142. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91143. for(channel = 0; channel < channels; channel++)
  91144. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91145. encoder->private_->current_sample_number = 1;
  91146. }
  91147. } while(j < samples);
  91148. }
  91149. return true;
  91150. }
  91151. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91152. {
  91153. FLAC__ASSERT(0 != encoder);
  91154. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91155. encoder->protected_->verify = true;
  91156. #else
  91157. encoder->protected_->verify = false;
  91158. #endif
  91159. encoder->protected_->streamable_subset = true;
  91160. encoder->protected_->do_md5 = true;
  91161. encoder->protected_->do_mid_side_stereo = false;
  91162. encoder->protected_->loose_mid_side_stereo = false;
  91163. encoder->protected_->channels = 2;
  91164. encoder->protected_->bits_per_sample = 16;
  91165. encoder->protected_->sample_rate = 44100;
  91166. encoder->protected_->blocksize = 0;
  91167. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91168. encoder->protected_->num_apodizations = 1;
  91169. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91170. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91171. #endif
  91172. encoder->protected_->max_lpc_order = 0;
  91173. encoder->protected_->qlp_coeff_precision = 0;
  91174. encoder->protected_->do_qlp_coeff_prec_search = false;
  91175. encoder->protected_->do_exhaustive_model_search = false;
  91176. encoder->protected_->do_escape_coding = false;
  91177. encoder->protected_->min_residual_partition_order = 0;
  91178. encoder->protected_->max_residual_partition_order = 0;
  91179. encoder->protected_->rice_parameter_search_dist = 0;
  91180. encoder->protected_->total_samples_estimate = 0;
  91181. encoder->protected_->metadata = 0;
  91182. encoder->protected_->num_metadata_blocks = 0;
  91183. encoder->private_->seek_table = 0;
  91184. encoder->private_->disable_constant_subframes = false;
  91185. encoder->private_->disable_fixed_subframes = false;
  91186. encoder->private_->disable_verbatim_subframes = false;
  91187. #if FLAC__HAS_OGG
  91188. encoder->private_->is_ogg = false;
  91189. #endif
  91190. encoder->private_->read_callback = 0;
  91191. encoder->private_->write_callback = 0;
  91192. encoder->private_->seek_callback = 0;
  91193. encoder->private_->tell_callback = 0;
  91194. encoder->private_->metadata_callback = 0;
  91195. encoder->private_->progress_callback = 0;
  91196. encoder->private_->client_data = 0;
  91197. #if FLAC__HAS_OGG
  91198. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91199. #endif
  91200. }
  91201. void free_(FLAC__StreamEncoder *encoder)
  91202. {
  91203. unsigned i, channel;
  91204. FLAC__ASSERT(0 != encoder);
  91205. if(encoder->protected_->metadata) {
  91206. free(encoder->protected_->metadata);
  91207. encoder->protected_->metadata = 0;
  91208. encoder->protected_->num_metadata_blocks = 0;
  91209. }
  91210. for(i = 0; i < encoder->protected_->channels; i++) {
  91211. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91212. free(encoder->private_->integer_signal_unaligned[i]);
  91213. encoder->private_->integer_signal_unaligned[i] = 0;
  91214. }
  91215. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91216. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91217. free(encoder->private_->real_signal_unaligned[i]);
  91218. encoder->private_->real_signal_unaligned[i] = 0;
  91219. }
  91220. #endif
  91221. }
  91222. for(i = 0; i < 2; i++) {
  91223. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91224. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91225. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91226. }
  91227. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91228. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91229. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91230. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91231. }
  91232. #endif
  91233. }
  91234. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91235. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91236. if(0 != encoder->private_->window_unaligned[i]) {
  91237. free(encoder->private_->window_unaligned[i]);
  91238. encoder->private_->window_unaligned[i] = 0;
  91239. }
  91240. }
  91241. if(0 != encoder->private_->windowed_signal_unaligned) {
  91242. free(encoder->private_->windowed_signal_unaligned);
  91243. encoder->private_->windowed_signal_unaligned = 0;
  91244. }
  91245. #endif
  91246. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91247. for(i = 0; i < 2; i++) {
  91248. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91249. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91250. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91251. }
  91252. }
  91253. }
  91254. for(channel = 0; channel < 2; channel++) {
  91255. for(i = 0; i < 2; i++) {
  91256. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91257. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91258. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91259. }
  91260. }
  91261. }
  91262. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91263. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91264. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91265. }
  91266. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91267. free(encoder->private_->raw_bits_per_partition_unaligned);
  91268. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91269. }
  91270. if(encoder->protected_->verify) {
  91271. for(i = 0; i < encoder->protected_->channels; i++) {
  91272. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91273. free(encoder->private_->verify.input_fifo.data[i]);
  91274. encoder->private_->verify.input_fifo.data[i] = 0;
  91275. }
  91276. }
  91277. }
  91278. FLAC__bitwriter_free(encoder->private_->frame);
  91279. }
  91280. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91281. {
  91282. FLAC__bool ok;
  91283. unsigned i, channel;
  91284. FLAC__ASSERT(new_blocksize > 0);
  91285. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91286. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91287. if(new_blocksize <= encoder->private_->input_capacity)
  91288. return true;
  91289. ok = true;
  91290. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91291. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91292. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91293. encoder->private_->integer_signal[i] += 4;
  91294. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91295. #if 0 /* @@@ currently unused */
  91296. if(encoder->protected_->max_lpc_order > 0)
  91297. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91298. #endif
  91299. #endif
  91300. }
  91301. for(i = 0; ok && i < 2; i++) {
  91302. 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]);
  91303. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91304. encoder->private_->integer_signal_mid_side[i] += 4;
  91305. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91306. #if 0 /* @@@ currently unused */
  91307. if(encoder->protected_->max_lpc_order > 0)
  91308. 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]);
  91309. #endif
  91310. #endif
  91311. }
  91312. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91313. if(ok && encoder->protected_->max_lpc_order > 0) {
  91314. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91315. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91316. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91317. }
  91318. #endif
  91319. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91320. for(i = 0; ok && i < 2; i++) {
  91321. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91322. }
  91323. }
  91324. for(channel = 0; ok && channel < 2; channel++) {
  91325. for(i = 0; ok && i < 2; i++) {
  91326. 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]);
  91327. }
  91328. }
  91329. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91330. if(encoder->protected_->do_escape_coding)
  91331. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91332. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91333. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91334. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91335. switch(encoder->protected_->apodizations[i].type) {
  91336. case FLAC__APODIZATION_BARTLETT:
  91337. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91338. break;
  91339. case FLAC__APODIZATION_BARTLETT_HANN:
  91340. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91341. break;
  91342. case FLAC__APODIZATION_BLACKMAN:
  91343. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91344. break;
  91345. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91346. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91347. break;
  91348. case FLAC__APODIZATION_CONNES:
  91349. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91350. break;
  91351. case FLAC__APODIZATION_FLATTOP:
  91352. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91353. break;
  91354. case FLAC__APODIZATION_GAUSS:
  91355. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91356. break;
  91357. case FLAC__APODIZATION_HAMMING:
  91358. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91359. break;
  91360. case FLAC__APODIZATION_HANN:
  91361. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91362. break;
  91363. case FLAC__APODIZATION_KAISER_BESSEL:
  91364. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91365. break;
  91366. case FLAC__APODIZATION_NUTTALL:
  91367. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91368. break;
  91369. case FLAC__APODIZATION_RECTANGLE:
  91370. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91371. break;
  91372. case FLAC__APODIZATION_TRIANGLE:
  91373. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91374. break;
  91375. case FLAC__APODIZATION_TUKEY:
  91376. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91377. break;
  91378. case FLAC__APODIZATION_WELCH:
  91379. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91380. break;
  91381. default:
  91382. FLAC__ASSERT(0);
  91383. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91384. break;
  91385. }
  91386. }
  91387. }
  91388. #endif
  91389. if(ok)
  91390. encoder->private_->input_capacity = new_blocksize;
  91391. else
  91392. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91393. return ok;
  91394. }
  91395. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91396. {
  91397. const FLAC__byte *buffer;
  91398. size_t bytes;
  91399. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91400. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91401. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91402. return false;
  91403. }
  91404. if(encoder->protected_->verify) {
  91405. encoder->private_->verify.output.data = buffer;
  91406. encoder->private_->verify.output.bytes = bytes;
  91407. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91408. encoder->private_->verify.needs_magic_hack = true;
  91409. }
  91410. else {
  91411. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91412. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91413. FLAC__bitwriter_clear(encoder->private_->frame);
  91414. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91415. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91416. return false;
  91417. }
  91418. }
  91419. }
  91420. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91421. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91422. FLAC__bitwriter_clear(encoder->private_->frame);
  91423. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91424. return false;
  91425. }
  91426. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91427. FLAC__bitwriter_clear(encoder->private_->frame);
  91428. if(samples > 0) {
  91429. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91430. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91431. }
  91432. return true;
  91433. }
  91434. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91435. {
  91436. FLAC__StreamEncoderWriteStatus status;
  91437. FLAC__uint64 output_position = 0;
  91438. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91439. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91440. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91441. }
  91442. if(samples == 0) {
  91443. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91444. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91445. encoder->protected_->streaminfo_offset = output_position;
  91446. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91447. encoder->protected_->seektable_offset = output_position;
  91448. }
  91449. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91450. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91451. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91452. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91453. FLAC__uint64 test_sample;
  91454. unsigned i;
  91455. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91456. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91457. if(test_sample > frame_last_sample) {
  91458. break;
  91459. }
  91460. else if(test_sample >= frame_first_sample) {
  91461. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91462. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91463. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91464. encoder->private_->first_seekpoint_to_check++;
  91465. }
  91466. else {
  91467. encoder->private_->first_seekpoint_to_check++;
  91468. }
  91469. }
  91470. }
  91471. #if FLAC__HAS_OGG
  91472. if(encoder->private_->is_ogg) {
  91473. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91474. &encoder->protected_->ogg_encoder_aspect,
  91475. buffer,
  91476. bytes,
  91477. samples,
  91478. encoder->private_->current_frame_number,
  91479. is_last_block,
  91480. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91481. encoder,
  91482. encoder->private_->client_data
  91483. );
  91484. }
  91485. else
  91486. #endif
  91487. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91488. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91489. encoder->private_->bytes_written += bytes;
  91490. encoder->private_->samples_written += samples;
  91491. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91492. }
  91493. else
  91494. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91495. return status;
  91496. }
  91497. void update_metadata_(const FLAC__StreamEncoder *encoder)
  91498. {
  91499. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91500. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91501. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91502. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91503. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91504. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  91505. FLAC__StreamEncoderSeekStatus seek_status;
  91506. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91507. {
  91508. const unsigned md5_offset =
  91509. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91510. (
  91511. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91512. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91513. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91514. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91515. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91516. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91517. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91518. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91519. ) / 8;
  91520. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  91521. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91522. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91523. return;
  91524. }
  91525. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91526. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91527. return;
  91528. }
  91529. }
  91530. {
  91531. const unsigned total_samples_byte_offset =
  91532. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91533. (
  91534. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91535. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91536. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91537. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91538. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91539. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91540. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91541. - 4
  91542. ) / 8;
  91543. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  91544. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91545. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91546. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91547. b[4] = (FLAC__byte)(samples & 0xFF);
  91548. 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) {
  91549. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91550. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91551. return;
  91552. }
  91553. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91554. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91555. return;
  91556. }
  91557. }
  91558. {
  91559. const unsigned min_framesize_offset =
  91560. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91561. (
  91562. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91563. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91564. ) / 8;
  91565. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91566. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91567. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91568. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91569. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91570. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91571. 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) {
  91572. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91573. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91574. return;
  91575. }
  91576. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91577. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91578. return;
  91579. }
  91580. }
  91581. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91582. unsigned i;
  91583. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91584. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91585. 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) {
  91586. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  91587. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91588. return;
  91589. }
  91590. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  91591. FLAC__uint64 xx;
  91592. unsigned x;
  91593. xx = encoder->private_->seek_table->points[i].sample_number;
  91594. b[7] = (FLAC__byte)xx; xx >>= 8;
  91595. b[6] = (FLAC__byte)xx; xx >>= 8;
  91596. b[5] = (FLAC__byte)xx; xx >>= 8;
  91597. b[4] = (FLAC__byte)xx; xx >>= 8;
  91598. b[3] = (FLAC__byte)xx; xx >>= 8;
  91599. b[2] = (FLAC__byte)xx; xx >>= 8;
  91600. b[1] = (FLAC__byte)xx; xx >>= 8;
  91601. b[0] = (FLAC__byte)xx; xx >>= 8;
  91602. xx = encoder->private_->seek_table->points[i].stream_offset;
  91603. b[15] = (FLAC__byte)xx; xx >>= 8;
  91604. b[14] = (FLAC__byte)xx; xx >>= 8;
  91605. b[13] = (FLAC__byte)xx; xx >>= 8;
  91606. b[12] = (FLAC__byte)xx; xx >>= 8;
  91607. b[11] = (FLAC__byte)xx; xx >>= 8;
  91608. b[10] = (FLAC__byte)xx; xx >>= 8;
  91609. b[9] = (FLAC__byte)xx; xx >>= 8;
  91610. b[8] = (FLAC__byte)xx; xx >>= 8;
  91611. x = encoder->private_->seek_table->points[i].frame_samples;
  91612. b[17] = (FLAC__byte)x; x >>= 8;
  91613. b[16] = (FLAC__byte)x; x >>= 8;
  91614. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91615. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91616. return;
  91617. }
  91618. }
  91619. }
  91620. }
  91621. #if FLAC__HAS_OGG
  91622. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  91623. {
  91624. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  91625. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  91626. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  91627. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  91628. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  91629. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  91630. FLAC__STREAM_SYNC_LENGTH
  91631. ;
  91632. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  91633. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  91634. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  91635. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  91636. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  91637. ogg_page page;
  91638. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  91639. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  91640. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  91641. return;
  91642. simple_ogg_page__init(&page);
  91643. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91644. simple_ogg_page__clear(&page);
  91645. return; /* state already set */
  91646. }
  91647. {
  91648. const unsigned md5_offset =
  91649. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91650. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91651. (
  91652. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91653. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91654. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91655. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91656. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91657. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91658. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  91659. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  91660. ) / 8;
  91661. if(md5_offset + 16 > (unsigned)page.body_len) {
  91662. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91663. simple_ogg_page__clear(&page);
  91664. return;
  91665. }
  91666. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  91667. }
  91668. {
  91669. const unsigned total_samples_byte_offset =
  91670. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91671. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91672. (
  91673. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91674. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  91675. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  91676. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  91677. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  91678. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  91679. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  91680. - 4
  91681. ) / 8;
  91682. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  91683. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91684. simple_ogg_page__clear(&page);
  91685. return;
  91686. }
  91687. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  91688. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  91689. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  91690. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  91691. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  91692. b[4] = (FLAC__byte)(samples & 0xFF);
  91693. memcpy(page.body + total_samples_byte_offset, b, 5);
  91694. }
  91695. {
  91696. const unsigned min_framesize_offset =
  91697. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  91698. FLAC__STREAM_METADATA_HEADER_LENGTH +
  91699. (
  91700. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  91701. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  91702. ) / 8;
  91703. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  91704. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91705. simple_ogg_page__clear(&page);
  91706. return;
  91707. }
  91708. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  91709. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  91710. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  91711. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  91712. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  91713. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  91714. memcpy(page.body + min_framesize_offset, b, 6);
  91715. }
  91716. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91717. simple_ogg_page__clear(&page);
  91718. return; /* state already set */
  91719. }
  91720. simple_ogg_page__clear(&page);
  91721. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  91722. unsigned i;
  91723. FLAC__byte *p;
  91724. FLAC__format_seektable_sort(encoder->private_->seek_table);
  91725. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  91726. simple_ogg_page__init(&page);
  91727. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  91728. simple_ogg_page__clear(&page);
  91729. return; /* state already set */
  91730. }
  91731. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  91732. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  91733. simple_ogg_page__clear(&page);
  91734. return;
  91735. }
  91736. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  91737. FLAC__uint64 xx;
  91738. unsigned x;
  91739. xx = encoder->private_->seek_table->points[i].sample_number;
  91740. b[7] = (FLAC__byte)xx; xx >>= 8;
  91741. b[6] = (FLAC__byte)xx; xx >>= 8;
  91742. b[5] = (FLAC__byte)xx; xx >>= 8;
  91743. b[4] = (FLAC__byte)xx; xx >>= 8;
  91744. b[3] = (FLAC__byte)xx; xx >>= 8;
  91745. b[2] = (FLAC__byte)xx; xx >>= 8;
  91746. b[1] = (FLAC__byte)xx; xx >>= 8;
  91747. b[0] = (FLAC__byte)xx; xx >>= 8;
  91748. xx = encoder->private_->seek_table->points[i].stream_offset;
  91749. b[15] = (FLAC__byte)xx; xx >>= 8;
  91750. b[14] = (FLAC__byte)xx; xx >>= 8;
  91751. b[13] = (FLAC__byte)xx; xx >>= 8;
  91752. b[12] = (FLAC__byte)xx; xx >>= 8;
  91753. b[11] = (FLAC__byte)xx; xx >>= 8;
  91754. b[10] = (FLAC__byte)xx; xx >>= 8;
  91755. b[9] = (FLAC__byte)xx; xx >>= 8;
  91756. b[8] = (FLAC__byte)xx; xx >>= 8;
  91757. x = encoder->private_->seek_table->points[i].frame_samples;
  91758. b[17] = (FLAC__byte)x; x >>= 8;
  91759. b[16] = (FLAC__byte)x; x >>= 8;
  91760. memcpy(p, b, 18);
  91761. }
  91762. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  91763. simple_ogg_page__clear(&page);
  91764. return; /* state already set */
  91765. }
  91766. simple_ogg_page__clear(&page);
  91767. }
  91768. }
  91769. #endif
  91770. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  91771. {
  91772. FLAC__uint16 crc;
  91773. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91774. 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)) {
  91775. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91776. return false;
  91777. }
  91778. if(!process_subframes_(encoder, is_fractional_block)) {
  91779. return false;
  91780. }
  91781. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  91782. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91783. return false;
  91784. }
  91785. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91786. if(
  91787. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  91788. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  91789. ) {
  91790. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91791. return false;
  91792. }
  91793. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  91794. return false;
  91795. }
  91796. encoder->private_->current_sample_number = 0;
  91797. encoder->private_->current_frame_number++;
  91798. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  91799. return true;
  91800. }
  91801. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  91802. {
  91803. FLAC__FrameHeader frame_header;
  91804. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  91805. FLAC__bool do_independent, do_mid_side;
  91806. if(is_fractional_block) {
  91807. max_partition_order = 0;
  91808. }
  91809. else {
  91810. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  91811. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  91812. }
  91813. min_partition_order = min(min_partition_order, max_partition_order);
  91814. frame_header.blocksize = encoder->protected_->blocksize;
  91815. frame_header.sample_rate = encoder->protected_->sample_rate;
  91816. frame_header.channels = encoder->protected_->channels;
  91817. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  91818. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  91819. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  91820. frame_header.number.frame_number = encoder->private_->current_frame_number;
  91821. if(encoder->protected_->do_mid_side_stereo) {
  91822. if(encoder->protected_->loose_mid_side_stereo) {
  91823. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  91824. do_independent = true;
  91825. do_mid_side = true;
  91826. }
  91827. else {
  91828. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  91829. do_mid_side = !do_independent;
  91830. }
  91831. }
  91832. else {
  91833. do_independent = true;
  91834. do_mid_side = true;
  91835. }
  91836. }
  91837. else {
  91838. do_independent = true;
  91839. do_mid_side = false;
  91840. }
  91841. FLAC__ASSERT(do_independent || do_mid_side);
  91842. if(do_independent) {
  91843. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91844. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  91845. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  91846. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  91847. }
  91848. }
  91849. if(do_mid_side) {
  91850. FLAC__ASSERT(encoder->protected_->channels == 2);
  91851. for(channel = 0; channel < 2; channel++) {
  91852. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  91853. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  91854. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  91855. }
  91856. }
  91857. if(do_independent) {
  91858. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91859. if(!
  91860. process_subframe_(
  91861. encoder,
  91862. min_partition_order,
  91863. max_partition_order,
  91864. &frame_header,
  91865. encoder->private_->subframe_bps[channel],
  91866. encoder->private_->integer_signal[channel],
  91867. encoder->private_->subframe_workspace_ptr[channel],
  91868. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  91869. encoder->private_->residual_workspace[channel],
  91870. encoder->private_->best_subframe+channel,
  91871. encoder->private_->best_subframe_bits+channel
  91872. )
  91873. )
  91874. return false;
  91875. }
  91876. }
  91877. if(do_mid_side) {
  91878. FLAC__ASSERT(encoder->protected_->channels == 2);
  91879. for(channel = 0; channel < 2; channel++) {
  91880. if(!
  91881. process_subframe_(
  91882. encoder,
  91883. min_partition_order,
  91884. max_partition_order,
  91885. &frame_header,
  91886. encoder->private_->subframe_bps_mid_side[channel],
  91887. encoder->private_->integer_signal_mid_side[channel],
  91888. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  91889. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  91890. encoder->private_->residual_workspace_mid_side[channel],
  91891. encoder->private_->best_subframe_mid_side+channel,
  91892. encoder->private_->best_subframe_bits_mid_side+channel
  91893. )
  91894. )
  91895. return false;
  91896. }
  91897. }
  91898. if(do_mid_side) {
  91899. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  91900. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  91901. FLAC__ChannelAssignment channel_assignment;
  91902. FLAC__ASSERT(encoder->protected_->channels == 2);
  91903. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  91904. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  91905. }
  91906. else {
  91907. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  91908. unsigned min_bits;
  91909. int ca;
  91910. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  91911. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  91912. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  91913. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  91914. FLAC__ASSERT(do_independent && do_mid_side);
  91915. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  91916. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  91917. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  91918. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  91919. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  91920. min_bits = bits[channel_assignment];
  91921. for(ca = 1; ca <= 3; ca++) {
  91922. if(bits[ca] < min_bits) {
  91923. min_bits = bits[ca];
  91924. channel_assignment = (FLAC__ChannelAssignment)ca;
  91925. }
  91926. }
  91927. }
  91928. frame_header.channel_assignment = channel_assignment;
  91929. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  91930. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91931. return false;
  91932. }
  91933. switch(channel_assignment) {
  91934. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  91935. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  91936. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  91937. break;
  91938. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  91939. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  91940. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91941. break;
  91942. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  91943. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91944. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  91945. break;
  91946. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  91947. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  91948. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  91949. break;
  91950. default:
  91951. FLAC__ASSERT(0);
  91952. }
  91953. switch(channel_assignment) {
  91954. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  91955. left_bps = encoder->private_->subframe_bps [0];
  91956. right_bps = encoder->private_->subframe_bps [1];
  91957. break;
  91958. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  91959. left_bps = encoder->private_->subframe_bps [0];
  91960. right_bps = encoder->private_->subframe_bps_mid_side[1];
  91961. break;
  91962. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  91963. left_bps = encoder->private_->subframe_bps_mid_side[1];
  91964. right_bps = encoder->private_->subframe_bps [1];
  91965. break;
  91966. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  91967. left_bps = encoder->private_->subframe_bps_mid_side[0];
  91968. right_bps = encoder->private_->subframe_bps_mid_side[1];
  91969. break;
  91970. default:
  91971. FLAC__ASSERT(0);
  91972. }
  91973. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  91974. return false;
  91975. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  91976. return false;
  91977. }
  91978. else {
  91979. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  91980. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  91981. return false;
  91982. }
  91983. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91984. 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)) {
  91985. return false;
  91986. }
  91987. }
  91988. }
  91989. if(encoder->protected_->loose_mid_side_stereo) {
  91990. encoder->private_->loose_mid_side_stereo_frame_count++;
  91991. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  91992. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  91993. }
  91994. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  91995. return true;
  91996. }
  91997. FLAC__bool process_subframe_(
  91998. FLAC__StreamEncoder *encoder,
  91999. unsigned min_partition_order,
  92000. unsigned max_partition_order,
  92001. const FLAC__FrameHeader *frame_header,
  92002. unsigned subframe_bps,
  92003. const FLAC__int32 integer_signal[],
  92004. FLAC__Subframe *subframe[2],
  92005. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92006. FLAC__int32 *residual[2],
  92007. unsigned *best_subframe,
  92008. unsigned *best_bits
  92009. )
  92010. {
  92011. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92012. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92013. #else
  92014. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92015. #endif
  92016. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92017. FLAC__double lpc_residual_bits_per_sample;
  92018. 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 */
  92019. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92020. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92021. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92022. #endif
  92023. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92024. unsigned rice_parameter;
  92025. unsigned _candidate_bits, _best_bits;
  92026. unsigned _best_subframe;
  92027. 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;
  92028. FLAC__ASSERT(frame_header->blocksize > 0);
  92029. _best_subframe = 0;
  92030. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92031. _best_bits = UINT_MAX;
  92032. else
  92033. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92034. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92035. unsigned signal_is_constant = false;
  92036. 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);
  92037. if(
  92038. !encoder->private_->disable_constant_subframes &&
  92039. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92040. fixed_residual_bits_per_sample[1] == 0.0
  92041. #else
  92042. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92043. #endif
  92044. ) {
  92045. unsigned i;
  92046. signal_is_constant = true;
  92047. for(i = 1; i < frame_header->blocksize; i++) {
  92048. if(integer_signal[0] != integer_signal[i]) {
  92049. signal_is_constant = false;
  92050. break;
  92051. }
  92052. }
  92053. }
  92054. if(signal_is_constant) {
  92055. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92056. if(_candidate_bits < _best_bits) {
  92057. _best_subframe = !_best_subframe;
  92058. _best_bits = _candidate_bits;
  92059. }
  92060. }
  92061. else {
  92062. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92063. if(encoder->protected_->do_exhaustive_model_search) {
  92064. min_fixed_order = 0;
  92065. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92066. }
  92067. else {
  92068. min_fixed_order = max_fixed_order = guess_fixed_order;
  92069. }
  92070. if(max_fixed_order >= frame_header->blocksize)
  92071. max_fixed_order = frame_header->blocksize - 1;
  92072. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92073. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92074. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92075. continue; /* don't even try */
  92076. 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 */
  92077. #else
  92078. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92079. continue; /* don't even try */
  92080. 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 */
  92081. #endif
  92082. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92083. if(rice_parameter >= rice_parameter_limit) {
  92084. #ifdef DEBUG_VERBOSE
  92085. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92086. #endif
  92087. rice_parameter = rice_parameter_limit - 1;
  92088. }
  92089. _candidate_bits =
  92090. evaluate_fixed_subframe_(
  92091. encoder,
  92092. integer_signal,
  92093. residual[!_best_subframe],
  92094. encoder->private_->abs_residual_partition_sums,
  92095. encoder->private_->raw_bits_per_partition,
  92096. frame_header->blocksize,
  92097. subframe_bps,
  92098. fixed_order,
  92099. rice_parameter,
  92100. rice_parameter_limit,
  92101. min_partition_order,
  92102. max_partition_order,
  92103. encoder->protected_->do_escape_coding,
  92104. encoder->protected_->rice_parameter_search_dist,
  92105. subframe[!_best_subframe],
  92106. partitioned_rice_contents[!_best_subframe]
  92107. );
  92108. if(_candidate_bits < _best_bits) {
  92109. _best_subframe = !_best_subframe;
  92110. _best_bits = _candidate_bits;
  92111. }
  92112. }
  92113. }
  92114. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92115. if(encoder->protected_->max_lpc_order > 0) {
  92116. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92117. max_lpc_order = frame_header->blocksize-1;
  92118. else
  92119. max_lpc_order = encoder->protected_->max_lpc_order;
  92120. if(max_lpc_order > 0) {
  92121. unsigned a;
  92122. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92123. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92124. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92125. if(autoc[0] != 0.0) {
  92126. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92127. if(encoder->protected_->do_exhaustive_model_search) {
  92128. min_lpc_order = 1;
  92129. }
  92130. else {
  92131. const unsigned guess_lpc_order =
  92132. FLAC__lpc_compute_best_order(
  92133. lpc_error,
  92134. max_lpc_order,
  92135. frame_header->blocksize,
  92136. subframe_bps + (
  92137. encoder->protected_->do_qlp_coeff_prec_search?
  92138. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92139. encoder->protected_->qlp_coeff_precision
  92140. )
  92141. );
  92142. min_lpc_order = max_lpc_order = guess_lpc_order;
  92143. }
  92144. if(max_lpc_order >= frame_header->blocksize)
  92145. max_lpc_order = frame_header->blocksize - 1;
  92146. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92147. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92148. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92149. continue; /* don't even try */
  92150. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92151. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92152. if(rice_parameter >= rice_parameter_limit) {
  92153. #ifdef DEBUG_VERBOSE
  92154. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92155. #endif
  92156. rice_parameter = rice_parameter_limit - 1;
  92157. }
  92158. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92159. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92160. if(subframe_bps <= 17) {
  92161. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92162. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92163. }
  92164. else
  92165. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92166. }
  92167. else {
  92168. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92169. }
  92170. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92171. _candidate_bits =
  92172. evaluate_lpc_subframe_(
  92173. encoder,
  92174. integer_signal,
  92175. residual[!_best_subframe],
  92176. encoder->private_->abs_residual_partition_sums,
  92177. encoder->private_->raw_bits_per_partition,
  92178. encoder->private_->lp_coeff[lpc_order-1],
  92179. frame_header->blocksize,
  92180. subframe_bps,
  92181. lpc_order,
  92182. qlp_coeff_precision,
  92183. rice_parameter,
  92184. rice_parameter_limit,
  92185. min_partition_order,
  92186. max_partition_order,
  92187. encoder->protected_->do_escape_coding,
  92188. encoder->protected_->rice_parameter_search_dist,
  92189. subframe[!_best_subframe],
  92190. partitioned_rice_contents[!_best_subframe]
  92191. );
  92192. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92193. if(_candidate_bits < _best_bits) {
  92194. _best_subframe = !_best_subframe;
  92195. _best_bits = _candidate_bits;
  92196. }
  92197. }
  92198. }
  92199. }
  92200. }
  92201. }
  92202. }
  92203. }
  92204. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92205. }
  92206. }
  92207. if(_best_bits == UINT_MAX) {
  92208. FLAC__ASSERT(_best_subframe == 0);
  92209. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92210. }
  92211. *best_subframe = _best_subframe;
  92212. *best_bits = _best_bits;
  92213. return true;
  92214. }
  92215. FLAC__bool add_subframe_(
  92216. FLAC__StreamEncoder *encoder,
  92217. unsigned blocksize,
  92218. unsigned subframe_bps,
  92219. const FLAC__Subframe *subframe,
  92220. FLAC__BitWriter *frame
  92221. )
  92222. {
  92223. switch(subframe->type) {
  92224. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92225. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92226. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92227. return false;
  92228. }
  92229. break;
  92230. case FLAC__SUBFRAME_TYPE_FIXED:
  92231. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92232. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92233. return false;
  92234. }
  92235. break;
  92236. case FLAC__SUBFRAME_TYPE_LPC:
  92237. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92238. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92239. return false;
  92240. }
  92241. break;
  92242. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92243. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92244. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92245. return false;
  92246. }
  92247. break;
  92248. default:
  92249. FLAC__ASSERT(0);
  92250. }
  92251. return true;
  92252. }
  92253. #define SPOTCHECK_ESTIMATE 0
  92254. #if SPOTCHECK_ESTIMATE
  92255. static void spotcheck_subframe_estimate_(
  92256. FLAC__StreamEncoder *encoder,
  92257. unsigned blocksize,
  92258. unsigned subframe_bps,
  92259. const FLAC__Subframe *subframe,
  92260. unsigned estimate
  92261. )
  92262. {
  92263. FLAC__bool ret;
  92264. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92265. if(frame == 0) {
  92266. fprintf(stderr, "EST: can't allocate frame\n");
  92267. return;
  92268. }
  92269. if(!FLAC__bitwriter_init(frame)) {
  92270. fprintf(stderr, "EST: can't init frame\n");
  92271. return;
  92272. }
  92273. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92274. FLAC__ASSERT(ret);
  92275. {
  92276. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92277. if(estimate != actual)
  92278. 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);
  92279. }
  92280. FLAC__bitwriter_delete(frame);
  92281. }
  92282. #endif
  92283. unsigned evaluate_constant_subframe_(
  92284. FLAC__StreamEncoder *encoder,
  92285. const FLAC__int32 signal,
  92286. unsigned blocksize,
  92287. unsigned subframe_bps,
  92288. FLAC__Subframe *subframe
  92289. )
  92290. {
  92291. unsigned estimate;
  92292. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92293. subframe->data.constant.value = signal;
  92294. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92295. #if SPOTCHECK_ESTIMATE
  92296. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92297. #else
  92298. (void)encoder, (void)blocksize;
  92299. #endif
  92300. return estimate;
  92301. }
  92302. unsigned evaluate_fixed_subframe_(
  92303. FLAC__StreamEncoder *encoder,
  92304. const FLAC__int32 signal[],
  92305. FLAC__int32 residual[],
  92306. FLAC__uint64 abs_residual_partition_sums[],
  92307. unsigned raw_bits_per_partition[],
  92308. unsigned blocksize,
  92309. unsigned subframe_bps,
  92310. unsigned order,
  92311. unsigned rice_parameter,
  92312. unsigned rice_parameter_limit,
  92313. unsigned min_partition_order,
  92314. unsigned max_partition_order,
  92315. FLAC__bool do_escape_coding,
  92316. unsigned rice_parameter_search_dist,
  92317. FLAC__Subframe *subframe,
  92318. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92319. )
  92320. {
  92321. unsigned i, residual_bits, estimate;
  92322. const unsigned residual_samples = blocksize - order;
  92323. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92324. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92325. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92326. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92327. subframe->data.fixed.residual = residual;
  92328. residual_bits =
  92329. find_best_partition_order_(
  92330. encoder->private_,
  92331. residual,
  92332. abs_residual_partition_sums,
  92333. raw_bits_per_partition,
  92334. residual_samples,
  92335. order,
  92336. rice_parameter,
  92337. rice_parameter_limit,
  92338. min_partition_order,
  92339. max_partition_order,
  92340. subframe_bps,
  92341. do_escape_coding,
  92342. rice_parameter_search_dist,
  92343. &subframe->data.fixed.entropy_coding_method
  92344. );
  92345. subframe->data.fixed.order = order;
  92346. for(i = 0; i < order; i++)
  92347. subframe->data.fixed.warmup[i] = signal[i];
  92348. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92349. #if SPOTCHECK_ESTIMATE
  92350. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92351. #endif
  92352. return estimate;
  92353. }
  92354. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92355. unsigned evaluate_lpc_subframe_(
  92356. FLAC__StreamEncoder *encoder,
  92357. const FLAC__int32 signal[],
  92358. FLAC__int32 residual[],
  92359. FLAC__uint64 abs_residual_partition_sums[],
  92360. unsigned raw_bits_per_partition[],
  92361. const FLAC__real lp_coeff[],
  92362. unsigned blocksize,
  92363. unsigned subframe_bps,
  92364. unsigned order,
  92365. unsigned qlp_coeff_precision,
  92366. unsigned rice_parameter,
  92367. unsigned rice_parameter_limit,
  92368. unsigned min_partition_order,
  92369. unsigned max_partition_order,
  92370. FLAC__bool do_escape_coding,
  92371. unsigned rice_parameter_search_dist,
  92372. FLAC__Subframe *subframe,
  92373. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92374. )
  92375. {
  92376. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92377. unsigned i, residual_bits, estimate;
  92378. int quantization, ret;
  92379. const unsigned residual_samples = blocksize - order;
  92380. if(subframe_bps <= 16) {
  92381. FLAC__ASSERT(order > 0);
  92382. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92383. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92384. }
  92385. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92386. if(ret != 0)
  92387. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92388. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92389. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92390. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92391. else
  92392. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92393. else
  92394. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92395. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92396. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92397. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92398. subframe->data.lpc.residual = residual;
  92399. residual_bits =
  92400. find_best_partition_order_(
  92401. encoder->private_,
  92402. residual,
  92403. abs_residual_partition_sums,
  92404. raw_bits_per_partition,
  92405. residual_samples,
  92406. order,
  92407. rice_parameter,
  92408. rice_parameter_limit,
  92409. min_partition_order,
  92410. max_partition_order,
  92411. subframe_bps,
  92412. do_escape_coding,
  92413. rice_parameter_search_dist,
  92414. &subframe->data.lpc.entropy_coding_method
  92415. );
  92416. subframe->data.lpc.order = order;
  92417. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92418. subframe->data.lpc.quantization_level = quantization;
  92419. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92420. for(i = 0; i < order; i++)
  92421. subframe->data.lpc.warmup[i] = signal[i];
  92422. 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;
  92423. #if SPOTCHECK_ESTIMATE
  92424. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92425. #endif
  92426. return estimate;
  92427. }
  92428. #endif
  92429. unsigned evaluate_verbatim_subframe_(
  92430. FLAC__StreamEncoder *encoder,
  92431. const FLAC__int32 signal[],
  92432. unsigned blocksize,
  92433. unsigned subframe_bps,
  92434. FLAC__Subframe *subframe
  92435. )
  92436. {
  92437. unsigned estimate;
  92438. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92439. subframe->data.verbatim.data = signal;
  92440. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92441. #if SPOTCHECK_ESTIMATE
  92442. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92443. #else
  92444. (void)encoder;
  92445. #endif
  92446. return estimate;
  92447. }
  92448. unsigned find_best_partition_order_(
  92449. FLAC__StreamEncoderPrivate *private_,
  92450. const FLAC__int32 residual[],
  92451. FLAC__uint64 abs_residual_partition_sums[],
  92452. unsigned raw_bits_per_partition[],
  92453. unsigned residual_samples,
  92454. unsigned predictor_order,
  92455. unsigned rice_parameter,
  92456. unsigned rice_parameter_limit,
  92457. unsigned min_partition_order,
  92458. unsigned max_partition_order,
  92459. unsigned bps,
  92460. FLAC__bool do_escape_coding,
  92461. unsigned rice_parameter_search_dist,
  92462. FLAC__EntropyCodingMethod *best_ecm
  92463. )
  92464. {
  92465. unsigned residual_bits, best_residual_bits = 0;
  92466. unsigned best_parameters_index = 0;
  92467. unsigned best_partition_order = 0;
  92468. const unsigned blocksize = residual_samples + predictor_order;
  92469. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92470. min_partition_order = min(min_partition_order, max_partition_order);
  92471. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92472. if(do_escape_coding)
  92473. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92474. {
  92475. int partition_order;
  92476. unsigned sum;
  92477. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92478. if(!
  92479. set_partitioned_rice_(
  92480. #ifdef EXACT_RICE_BITS_CALCULATION
  92481. residual,
  92482. #endif
  92483. abs_residual_partition_sums+sum,
  92484. raw_bits_per_partition+sum,
  92485. residual_samples,
  92486. predictor_order,
  92487. rice_parameter,
  92488. rice_parameter_limit,
  92489. rice_parameter_search_dist,
  92490. (unsigned)partition_order,
  92491. do_escape_coding,
  92492. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92493. &residual_bits
  92494. )
  92495. )
  92496. {
  92497. FLAC__ASSERT(best_residual_bits != 0);
  92498. break;
  92499. }
  92500. sum += 1u << partition_order;
  92501. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  92502. best_residual_bits = residual_bits;
  92503. best_parameters_index = !best_parameters_index;
  92504. best_partition_order = partition_order;
  92505. }
  92506. }
  92507. }
  92508. best_ecm->data.partitioned_rice.order = best_partition_order;
  92509. {
  92510. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  92511. unsigned partition;
  92512. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  92513. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  92514. if(do_escape_coding)
  92515. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  92516. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  92517. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  92518. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  92519. break;
  92520. }
  92521. }
  92522. }
  92523. return best_residual_bits;
  92524. }
  92525. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92526. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  92527. const FLAC__int32 residual[],
  92528. FLAC__uint64 abs_residual_partition_sums[],
  92529. unsigned blocksize,
  92530. unsigned predictor_order,
  92531. unsigned min_partition_order,
  92532. unsigned max_partition_order
  92533. );
  92534. #endif
  92535. void precompute_partition_info_sums_(
  92536. const FLAC__int32 residual[],
  92537. FLAC__uint64 abs_residual_partition_sums[],
  92538. unsigned residual_samples,
  92539. unsigned predictor_order,
  92540. unsigned min_partition_order,
  92541. unsigned max_partition_order,
  92542. unsigned bps
  92543. )
  92544. {
  92545. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  92546. unsigned partitions = 1u << max_partition_order;
  92547. FLAC__ASSERT(default_partition_samples > predictor_order);
  92548. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  92549. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92550. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  92551. return;
  92552. }
  92553. #endif
  92554. {
  92555. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  92556. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  92557. FLAC__uint32 abs_residual_partition_sum;
  92558. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92559. end += default_partition_samples;
  92560. abs_residual_partition_sum = 0;
  92561. for( ; residual_sample < end; residual_sample++)
  92562. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92563. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92564. }
  92565. }
  92566. else { /* have to pessimistically use 64 bits for accumulator */
  92567. FLAC__uint64 abs_residual_partition_sum;
  92568. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92569. end += default_partition_samples;
  92570. abs_residual_partition_sum = 0;
  92571. for( ; residual_sample < end; residual_sample++)
  92572. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  92573. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  92574. }
  92575. }
  92576. }
  92577. {
  92578. unsigned from_partition = 0, to_partition = partitions;
  92579. int partition_order;
  92580. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  92581. unsigned i;
  92582. partitions >>= 1;
  92583. for(i = 0; i < partitions; i++) {
  92584. abs_residual_partition_sums[to_partition++] =
  92585. abs_residual_partition_sums[from_partition ] +
  92586. abs_residual_partition_sums[from_partition+1];
  92587. from_partition += 2;
  92588. }
  92589. }
  92590. }
  92591. }
  92592. void precompute_partition_info_escapes_(
  92593. const FLAC__int32 residual[],
  92594. unsigned raw_bits_per_partition[],
  92595. unsigned residual_samples,
  92596. unsigned predictor_order,
  92597. unsigned min_partition_order,
  92598. unsigned max_partition_order
  92599. )
  92600. {
  92601. int partition_order;
  92602. unsigned from_partition, to_partition = 0;
  92603. const unsigned blocksize = residual_samples + predictor_order;
  92604. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  92605. FLAC__int32 r;
  92606. FLAC__uint32 rmax;
  92607. unsigned partition, partition_sample, partition_samples, residual_sample;
  92608. const unsigned partitions = 1u << partition_order;
  92609. const unsigned default_partition_samples = blocksize >> partition_order;
  92610. FLAC__ASSERT(default_partition_samples > predictor_order);
  92611. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92612. partition_samples = default_partition_samples;
  92613. if(partition == 0)
  92614. partition_samples -= predictor_order;
  92615. rmax = 0;
  92616. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  92617. r = residual[residual_sample++];
  92618. if(r < 0)
  92619. rmax |= ~r;
  92620. else
  92621. rmax |= r;
  92622. }
  92623. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  92624. }
  92625. to_partition = partitions;
  92626. break; /*@@@ yuck, should remove the 'for' loop instead */
  92627. }
  92628. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  92629. unsigned m;
  92630. unsigned i;
  92631. const unsigned partitions = 1u << partition_order;
  92632. for(i = 0; i < partitions; i++) {
  92633. m = raw_bits_per_partition[from_partition];
  92634. from_partition++;
  92635. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  92636. from_partition++;
  92637. to_partition++;
  92638. }
  92639. }
  92640. }
  92641. #ifdef EXACT_RICE_BITS_CALCULATION
  92642. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92643. const unsigned rice_parameter,
  92644. const unsigned partition_samples,
  92645. const FLAC__int32 *residual
  92646. )
  92647. {
  92648. unsigned i, partition_bits =
  92649. 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 */
  92650. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  92651. ;
  92652. for(i = 0; i < partition_samples; i++)
  92653. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  92654. return partition_bits;
  92655. }
  92656. #else
  92657. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  92658. const unsigned rice_parameter,
  92659. const unsigned partition_samples,
  92660. const FLAC__uint64 abs_residual_partition_sum
  92661. )
  92662. {
  92663. return
  92664. 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 */
  92665. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  92666. (
  92667. rice_parameter?
  92668. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  92669. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  92670. )
  92671. - (partition_samples >> 1)
  92672. ;
  92673. }
  92674. #endif
  92675. FLAC__bool set_partitioned_rice_(
  92676. #ifdef EXACT_RICE_BITS_CALCULATION
  92677. const FLAC__int32 residual[],
  92678. #endif
  92679. const FLAC__uint64 abs_residual_partition_sums[],
  92680. const unsigned raw_bits_per_partition[],
  92681. const unsigned residual_samples,
  92682. const unsigned predictor_order,
  92683. const unsigned suggested_rice_parameter,
  92684. const unsigned rice_parameter_limit,
  92685. const unsigned rice_parameter_search_dist,
  92686. const unsigned partition_order,
  92687. const FLAC__bool search_for_escapes,
  92688. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  92689. unsigned *bits
  92690. )
  92691. {
  92692. unsigned rice_parameter, partition_bits;
  92693. unsigned best_partition_bits, best_rice_parameter = 0;
  92694. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  92695. unsigned *parameters, *raw_bits;
  92696. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92697. unsigned min_rice_parameter, max_rice_parameter;
  92698. #else
  92699. (void)rice_parameter_search_dist;
  92700. #endif
  92701. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92702. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  92703. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  92704. parameters = partitioned_rice_contents->parameters;
  92705. raw_bits = partitioned_rice_contents->raw_bits;
  92706. if(partition_order == 0) {
  92707. best_partition_bits = (unsigned)(-1);
  92708. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92709. if(rice_parameter_search_dist) {
  92710. if(suggested_rice_parameter < rice_parameter_search_dist)
  92711. min_rice_parameter = 0;
  92712. else
  92713. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  92714. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  92715. if(max_rice_parameter >= rice_parameter_limit) {
  92716. #ifdef DEBUG_VERBOSE
  92717. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  92718. #endif
  92719. max_rice_parameter = rice_parameter_limit - 1;
  92720. }
  92721. }
  92722. else
  92723. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  92724. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92725. #else
  92726. rice_parameter = suggested_rice_parameter;
  92727. #endif
  92728. #ifdef EXACT_RICE_BITS_CALCULATION
  92729. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  92730. #else
  92731. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  92732. #endif
  92733. if(partition_bits < best_partition_bits) {
  92734. best_rice_parameter = rice_parameter;
  92735. best_partition_bits = partition_bits;
  92736. }
  92737. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92738. }
  92739. #endif
  92740. if(search_for_escapes) {
  92741. 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;
  92742. if(partition_bits <= best_partition_bits) {
  92743. raw_bits[0] = raw_bits_per_partition[0];
  92744. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92745. best_partition_bits = partition_bits;
  92746. }
  92747. else
  92748. raw_bits[0] = 0;
  92749. }
  92750. parameters[0] = best_rice_parameter;
  92751. bits_ += best_partition_bits;
  92752. }
  92753. else {
  92754. unsigned partition, residual_sample;
  92755. unsigned partition_samples;
  92756. FLAC__uint64 mean, k;
  92757. const unsigned partitions = 1u << partition_order;
  92758. for(partition = residual_sample = 0; partition < partitions; partition++) {
  92759. partition_samples = (residual_samples+predictor_order) >> partition_order;
  92760. if(partition == 0) {
  92761. if(partition_samples <= predictor_order)
  92762. return false;
  92763. else
  92764. partition_samples -= predictor_order;
  92765. }
  92766. mean = abs_residual_partition_sums[partition];
  92767. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  92768. ;
  92769. if(rice_parameter >= rice_parameter_limit) {
  92770. #ifdef DEBUG_VERBOSE
  92771. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  92772. #endif
  92773. rice_parameter = rice_parameter_limit - 1;
  92774. }
  92775. best_partition_bits = (unsigned)(-1);
  92776. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92777. if(rice_parameter_search_dist) {
  92778. if(rice_parameter < rice_parameter_search_dist)
  92779. min_rice_parameter = 0;
  92780. else
  92781. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  92782. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  92783. if(max_rice_parameter >= rice_parameter_limit) {
  92784. #ifdef DEBUG_VERBOSE
  92785. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  92786. #endif
  92787. max_rice_parameter = rice_parameter_limit - 1;
  92788. }
  92789. }
  92790. else
  92791. min_rice_parameter = max_rice_parameter = rice_parameter;
  92792. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  92793. #endif
  92794. #ifdef EXACT_RICE_BITS_CALCULATION
  92795. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  92796. #else
  92797. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  92798. #endif
  92799. if(partition_bits < best_partition_bits) {
  92800. best_rice_parameter = rice_parameter;
  92801. best_partition_bits = partition_bits;
  92802. }
  92803. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  92804. }
  92805. #endif
  92806. if(search_for_escapes) {
  92807. 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;
  92808. if(partition_bits <= best_partition_bits) {
  92809. raw_bits[partition] = raw_bits_per_partition[partition];
  92810. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  92811. best_partition_bits = partition_bits;
  92812. }
  92813. else
  92814. raw_bits[partition] = 0;
  92815. }
  92816. parameters[partition] = best_rice_parameter;
  92817. bits_ += best_partition_bits;
  92818. residual_sample += partition_samples;
  92819. }
  92820. }
  92821. *bits = bits_;
  92822. return true;
  92823. }
  92824. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  92825. {
  92826. unsigned i, shift;
  92827. FLAC__int32 x = 0;
  92828. for(i = 0; i < samples && !(x&1); i++)
  92829. x |= signal[i];
  92830. if(x == 0) {
  92831. shift = 0;
  92832. }
  92833. else {
  92834. for(shift = 0; !(x&1); shift++)
  92835. x >>= 1;
  92836. }
  92837. if(shift > 0) {
  92838. for(i = 0; i < samples; i++)
  92839. signal[i] >>= shift;
  92840. }
  92841. return shift;
  92842. }
  92843. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92844. {
  92845. unsigned channel;
  92846. for(channel = 0; channel < channels; channel++)
  92847. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  92848. fifo->tail += wide_samples;
  92849. FLAC__ASSERT(fifo->tail <= fifo->size);
  92850. }
  92851. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  92852. {
  92853. unsigned channel;
  92854. unsigned sample, wide_sample;
  92855. unsigned tail = fifo->tail;
  92856. sample = input_offset * channels;
  92857. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  92858. for(channel = 0; channel < channels; channel++)
  92859. fifo->data[channel][tail] = input[sample++];
  92860. tail++;
  92861. }
  92862. fifo->tail = tail;
  92863. FLAC__ASSERT(fifo->tail <= fifo->size);
  92864. }
  92865. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92866. {
  92867. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92868. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  92869. (void)decoder;
  92870. if(encoder->private_->verify.needs_magic_hack) {
  92871. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  92872. *bytes = FLAC__STREAM_SYNC_LENGTH;
  92873. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  92874. encoder->private_->verify.needs_magic_hack = false;
  92875. }
  92876. else {
  92877. if(encoded_bytes == 0) {
  92878. FLAC__ASSERT(0);
  92879. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  92880. }
  92881. else if(encoded_bytes < *bytes)
  92882. *bytes = encoded_bytes;
  92883. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  92884. encoder->private_->verify.output.data += *bytes;
  92885. encoder->private_->verify.output.bytes -= *bytes;
  92886. }
  92887. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  92888. }
  92889. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  92890. {
  92891. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  92892. unsigned channel;
  92893. const unsigned channels = frame->header.channels;
  92894. const unsigned blocksize = frame->header.blocksize;
  92895. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  92896. (void)decoder;
  92897. for(channel = 0; channel < channels; channel++) {
  92898. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  92899. unsigned i, sample = 0;
  92900. FLAC__int32 expect = 0, got = 0;
  92901. for(i = 0; i < blocksize; i++) {
  92902. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  92903. sample = i;
  92904. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  92905. got = (FLAC__int32)buffer[channel][i];
  92906. break;
  92907. }
  92908. }
  92909. FLAC__ASSERT(i < blocksize);
  92910. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  92911. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  92912. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  92913. encoder->private_->verify.error_stats.channel = channel;
  92914. encoder->private_->verify.error_stats.sample = sample;
  92915. encoder->private_->verify.error_stats.expected = expect;
  92916. encoder->private_->verify.error_stats.got = got;
  92917. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  92918. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  92919. }
  92920. }
  92921. encoder->private_->verify.input_fifo.tail -= blocksize;
  92922. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  92923. for(channel = 0; channel < channels; channel++)
  92924. 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]));
  92925. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  92926. }
  92927. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  92928. {
  92929. (void)decoder, (void)metadata, (void)client_data;
  92930. }
  92931. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  92932. {
  92933. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  92934. (void)decoder, (void)status;
  92935. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  92936. }
  92937. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  92938. {
  92939. (void)client_data;
  92940. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  92941. if (*bytes == 0) {
  92942. if (feof(encoder->private_->file))
  92943. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  92944. else if (ferror(encoder->private_->file))
  92945. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  92946. }
  92947. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  92948. }
  92949. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  92950. {
  92951. (void)client_data;
  92952. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  92953. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  92954. else
  92955. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  92956. }
  92957. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  92958. {
  92959. off_t offset;
  92960. (void)client_data;
  92961. offset = ftello(encoder->private_->file);
  92962. if(offset < 0) {
  92963. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  92964. }
  92965. else {
  92966. *absolute_byte_offset = (FLAC__uint64)offset;
  92967. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  92968. }
  92969. }
  92970. #ifdef FLAC__VALGRIND_TESTING
  92971. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  92972. {
  92973. size_t ret = fwrite(ptr, size, nmemb, stream);
  92974. if(!ferror(stream))
  92975. fflush(stream);
  92976. return ret;
  92977. }
  92978. #else
  92979. #define local__fwrite fwrite
  92980. #endif
  92981. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  92982. {
  92983. (void)client_data, (void)current_frame;
  92984. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  92985. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  92986. #if FLAC__HAS_OGG
  92987. encoder->private_->is_ogg? true :
  92988. #endif
  92989. samples > 0
  92990. );
  92991. if(call_it) {
  92992. 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);
  92993. }
  92994. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  92995. }
  92996. else
  92997. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  92998. }
  92999. FILE *get_binary_stdout_(void)
  93000. {
  93001. #if defined _MSC_VER || defined __MINGW32__
  93002. _setmode(_fileno(stdout), _O_BINARY);
  93003. #elif defined __CYGWIN__
  93004. setmode(_fileno(stdout), _O_BINARY);
  93005. #elif defined __EMX__
  93006. setmode(fileno(stdout), O_BINARY);
  93007. #endif
  93008. return stdout;
  93009. }
  93010. #endif
  93011. /*** End of inlined file: stream_encoder.c ***/
  93012. /*** Start of inlined file: stream_encoder_framing.c ***/
  93013. /*** Start of inlined file: juce_FlacHeader.h ***/
  93014. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93015. // tasks..
  93016. #define VERSION "1.2.1"
  93017. #define FLAC__NO_DLL 1
  93018. #if JUCE_MSVC
  93019. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93020. #endif
  93021. #if JUCE_MAC
  93022. #define FLAC__SYS_DARWIN 1
  93023. #endif
  93024. /*** End of inlined file: juce_FlacHeader.h ***/
  93025. #if JUCE_USE_FLAC
  93026. #if HAVE_CONFIG_H
  93027. # include <config.h>
  93028. #endif
  93029. #include <stdio.h>
  93030. #include <string.h> /* for strlen() */
  93031. #ifdef max
  93032. #undef max
  93033. #endif
  93034. #define max(x,y) ((x)>(y)?(x):(y))
  93035. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93036. 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);
  93037. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93038. {
  93039. unsigned i, j;
  93040. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93041. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93042. return false;
  93043. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93044. return false;
  93045. i = metadata->length;
  93046. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93047. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93048. i -= metadata->data.vorbis_comment.vendor_string.length;
  93049. i += vendor_string_length;
  93050. }
  93051. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93052. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93053. return false;
  93054. switch(metadata->type) {
  93055. case FLAC__METADATA_TYPE_STREAMINFO:
  93056. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93057. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93058. return false;
  93059. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93060. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93061. return false;
  93062. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93063. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93064. return false;
  93065. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93066. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93067. return false;
  93068. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93069. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93070. return false;
  93071. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93072. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93073. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93074. return false;
  93075. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93076. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93077. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93078. return false;
  93079. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93080. return false;
  93081. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93082. return false;
  93083. break;
  93084. case FLAC__METADATA_TYPE_PADDING:
  93085. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93086. return false;
  93087. break;
  93088. case FLAC__METADATA_TYPE_APPLICATION:
  93089. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93090. return false;
  93091. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93092. return false;
  93093. break;
  93094. case FLAC__METADATA_TYPE_SEEKTABLE:
  93095. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93096. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93097. return false;
  93098. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93099. return false;
  93100. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93101. return false;
  93102. }
  93103. break;
  93104. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93105. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93106. return false;
  93107. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93108. return false;
  93109. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93110. return false;
  93111. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93112. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93113. return false;
  93114. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93115. return false;
  93116. }
  93117. break;
  93118. case FLAC__METADATA_TYPE_CUESHEET:
  93119. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93120. 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))
  93121. return false;
  93122. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93123. return false;
  93124. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93125. return false;
  93126. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93127. return false;
  93128. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93129. return false;
  93130. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93131. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93132. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93133. return false;
  93134. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93135. return false;
  93136. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93137. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93138. return false;
  93139. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93140. return false;
  93141. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93142. return false;
  93143. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93144. return false;
  93145. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93146. return false;
  93147. for(j = 0; j < track->num_indices; j++) {
  93148. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93149. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93150. return false;
  93151. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93152. return false;
  93153. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93154. return false;
  93155. }
  93156. }
  93157. break;
  93158. case FLAC__METADATA_TYPE_PICTURE:
  93159. {
  93160. size_t len;
  93161. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93162. return false;
  93163. len = strlen(metadata->data.picture.mime_type);
  93164. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93165. return false;
  93166. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93167. return false;
  93168. len = strlen((const char *)metadata->data.picture.description);
  93169. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93170. return false;
  93171. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93172. return false;
  93173. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93174. return false;
  93175. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93176. return false;
  93177. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93178. return false;
  93179. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93180. return false;
  93181. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93182. return false;
  93183. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93184. return false;
  93185. }
  93186. break;
  93187. default:
  93188. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93189. return false;
  93190. break;
  93191. }
  93192. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93193. return true;
  93194. }
  93195. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93196. {
  93197. unsigned u, blocksize_hint, sample_rate_hint;
  93198. FLAC__byte crc;
  93199. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93200. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93201. return false;
  93202. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93203. return false;
  93204. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93205. return false;
  93206. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93207. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93208. blocksize_hint = 0;
  93209. switch(header->blocksize) {
  93210. case 192: u = 1; break;
  93211. case 576: u = 2; break;
  93212. case 1152: u = 3; break;
  93213. case 2304: u = 4; break;
  93214. case 4608: u = 5; break;
  93215. case 256: u = 8; break;
  93216. case 512: u = 9; break;
  93217. case 1024: u = 10; break;
  93218. case 2048: u = 11; break;
  93219. case 4096: u = 12; break;
  93220. case 8192: u = 13; break;
  93221. case 16384: u = 14; break;
  93222. case 32768: u = 15; break;
  93223. default:
  93224. if(header->blocksize <= 0x100)
  93225. blocksize_hint = u = 6;
  93226. else
  93227. blocksize_hint = u = 7;
  93228. break;
  93229. }
  93230. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93231. return false;
  93232. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93233. sample_rate_hint = 0;
  93234. switch(header->sample_rate) {
  93235. case 88200: u = 1; break;
  93236. case 176400: u = 2; break;
  93237. case 192000: u = 3; break;
  93238. case 8000: u = 4; break;
  93239. case 16000: u = 5; break;
  93240. case 22050: u = 6; break;
  93241. case 24000: u = 7; break;
  93242. case 32000: u = 8; break;
  93243. case 44100: u = 9; break;
  93244. case 48000: u = 10; break;
  93245. case 96000: u = 11; break;
  93246. default:
  93247. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93248. sample_rate_hint = u = 12;
  93249. else if(header->sample_rate % 10 == 0)
  93250. sample_rate_hint = u = 14;
  93251. else if(header->sample_rate <= 0xffff)
  93252. sample_rate_hint = u = 13;
  93253. else
  93254. u = 0;
  93255. break;
  93256. }
  93257. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93258. return false;
  93259. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93260. switch(header->channel_assignment) {
  93261. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93262. u = header->channels - 1;
  93263. break;
  93264. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93265. FLAC__ASSERT(header->channels == 2);
  93266. u = 8;
  93267. break;
  93268. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93269. FLAC__ASSERT(header->channels == 2);
  93270. u = 9;
  93271. break;
  93272. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93273. FLAC__ASSERT(header->channels == 2);
  93274. u = 10;
  93275. break;
  93276. default:
  93277. FLAC__ASSERT(0);
  93278. }
  93279. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93280. return false;
  93281. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93282. switch(header->bits_per_sample) {
  93283. case 8 : u = 1; break;
  93284. case 12: u = 2; break;
  93285. case 16: u = 4; break;
  93286. case 20: u = 5; break;
  93287. case 24: u = 6; break;
  93288. default: u = 0; break;
  93289. }
  93290. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93291. return false;
  93292. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93293. return false;
  93294. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93295. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93296. return false;
  93297. }
  93298. else {
  93299. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93300. return false;
  93301. }
  93302. if(blocksize_hint)
  93303. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93304. return false;
  93305. switch(sample_rate_hint) {
  93306. case 12:
  93307. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93308. return false;
  93309. break;
  93310. case 13:
  93311. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93312. return false;
  93313. break;
  93314. case 14:
  93315. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93316. return false;
  93317. break;
  93318. }
  93319. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93320. return false;
  93321. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93322. return false;
  93323. return true;
  93324. }
  93325. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93326. {
  93327. FLAC__bool ok;
  93328. ok =
  93329. 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) &&
  93330. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93331. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93332. ;
  93333. return ok;
  93334. }
  93335. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93336. {
  93337. unsigned i;
  93338. 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))
  93339. return false;
  93340. if(wasted_bits)
  93341. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93342. return false;
  93343. for(i = 0; i < subframe->order; i++)
  93344. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93345. return false;
  93346. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93347. return false;
  93348. switch(subframe->entropy_coding_method.type) {
  93349. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93350. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93351. if(!add_residual_partitioned_rice_(
  93352. bw,
  93353. subframe->residual,
  93354. residual_samples,
  93355. subframe->order,
  93356. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93357. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93358. subframe->entropy_coding_method.data.partitioned_rice.order,
  93359. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93360. ))
  93361. return false;
  93362. break;
  93363. default:
  93364. FLAC__ASSERT(0);
  93365. }
  93366. return true;
  93367. }
  93368. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93369. {
  93370. unsigned i;
  93371. 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))
  93372. return false;
  93373. if(wasted_bits)
  93374. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93375. return false;
  93376. for(i = 0; i < subframe->order; i++)
  93377. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93378. return false;
  93379. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93380. return false;
  93381. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93382. return false;
  93383. for(i = 0; i < subframe->order; i++)
  93384. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93385. return false;
  93386. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93387. return false;
  93388. switch(subframe->entropy_coding_method.type) {
  93389. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93390. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93391. if(!add_residual_partitioned_rice_(
  93392. bw,
  93393. subframe->residual,
  93394. residual_samples,
  93395. subframe->order,
  93396. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93397. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93398. subframe->entropy_coding_method.data.partitioned_rice.order,
  93399. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93400. ))
  93401. return false;
  93402. break;
  93403. default:
  93404. FLAC__ASSERT(0);
  93405. }
  93406. return true;
  93407. }
  93408. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93409. {
  93410. unsigned i;
  93411. const FLAC__int32 *signal = subframe->data;
  93412. 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))
  93413. return false;
  93414. if(wasted_bits)
  93415. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93416. return false;
  93417. for(i = 0; i < samples; i++)
  93418. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93419. return false;
  93420. return true;
  93421. }
  93422. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93423. {
  93424. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93425. return false;
  93426. switch(method->type) {
  93427. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93428. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93429. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93430. return false;
  93431. break;
  93432. default:
  93433. FLAC__ASSERT(0);
  93434. }
  93435. return true;
  93436. }
  93437. 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)
  93438. {
  93439. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93440. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93441. if(partition_order == 0) {
  93442. unsigned i;
  93443. if(raw_bits[0] == 0) {
  93444. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93445. return false;
  93446. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93447. return false;
  93448. }
  93449. else {
  93450. FLAC__ASSERT(rice_parameters[0] == 0);
  93451. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93452. return false;
  93453. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93454. return false;
  93455. for(i = 0; i < residual_samples; i++) {
  93456. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93457. return false;
  93458. }
  93459. }
  93460. return true;
  93461. }
  93462. else {
  93463. unsigned i, j, k = 0, k_last = 0;
  93464. unsigned partition_samples;
  93465. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93466. for(i = 0; i < (1u<<partition_order); i++) {
  93467. partition_samples = default_partition_samples;
  93468. if(i == 0)
  93469. partition_samples -= predictor_order;
  93470. k += partition_samples;
  93471. if(raw_bits[i] == 0) {
  93472. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93473. return false;
  93474. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93475. return false;
  93476. }
  93477. else {
  93478. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93479. return false;
  93480. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93481. return false;
  93482. for(j = k_last; j < k; j++) {
  93483. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93484. return false;
  93485. }
  93486. }
  93487. k_last = k;
  93488. }
  93489. return true;
  93490. }
  93491. }
  93492. #endif
  93493. /*** End of inlined file: stream_encoder_framing.c ***/
  93494. /*** Start of inlined file: window_flac.c ***/
  93495. /*** Start of inlined file: juce_FlacHeader.h ***/
  93496. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93497. // tasks..
  93498. #define VERSION "1.2.1"
  93499. #define FLAC__NO_DLL 1
  93500. #if JUCE_MSVC
  93501. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93502. #endif
  93503. #if JUCE_MAC
  93504. #define FLAC__SYS_DARWIN 1
  93505. #endif
  93506. /*** End of inlined file: juce_FlacHeader.h ***/
  93507. #if JUCE_USE_FLAC
  93508. #if HAVE_CONFIG_H
  93509. # include <config.h>
  93510. #endif
  93511. #include <math.h>
  93512. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  93513. #ifndef M_PI
  93514. #define M_PI 3.14159265358979323846
  93515. #endif
  93516. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  93517. {
  93518. const FLAC__int32 N = L - 1;
  93519. FLAC__int32 n;
  93520. if (L & 1) {
  93521. for (n = 0; n <= N/2; n++)
  93522. window[n] = 2.0f * n / (float)N;
  93523. for (; n <= N; n++)
  93524. window[n] = 2.0f - 2.0f * n / (float)N;
  93525. }
  93526. else {
  93527. for (n = 0; n <= L/2-1; n++)
  93528. window[n] = 2.0f * n / (float)N;
  93529. for (; n <= N; n++)
  93530. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  93531. }
  93532. }
  93533. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  93534. {
  93535. const FLAC__int32 N = L - 1;
  93536. FLAC__int32 n;
  93537. for (n = 0; n < L; n++)
  93538. 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)));
  93539. }
  93540. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  93541. {
  93542. const FLAC__int32 N = L - 1;
  93543. FLAC__int32 n;
  93544. for (n = 0; n < L; n++)
  93545. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  93546. }
  93547. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  93548. {
  93549. const FLAC__int32 N = L - 1;
  93550. FLAC__int32 n;
  93551. for (n = 0; n <= N; n++)
  93552. 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));
  93553. }
  93554. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  93555. {
  93556. const FLAC__int32 N = L - 1;
  93557. const double N2 = (double)N / 2.;
  93558. FLAC__int32 n;
  93559. for (n = 0; n <= N; n++) {
  93560. double k = ((double)n - N2) / N2;
  93561. k = 1.0f - k * k;
  93562. window[n] = (FLAC__real)(k * k);
  93563. }
  93564. }
  93565. void FLAC__window_flattop(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)(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));
  93571. }
  93572. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  93573. {
  93574. const FLAC__int32 N = L - 1;
  93575. const double N2 = (double)N / 2.;
  93576. FLAC__int32 n;
  93577. for (n = 0; n <= N; n++) {
  93578. const double k = ((double)n - N2) / (stddev * N2);
  93579. window[n] = (FLAC__real)exp(-0.5f * k * k);
  93580. }
  93581. }
  93582. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  93583. {
  93584. const FLAC__int32 N = L - 1;
  93585. FLAC__int32 n;
  93586. for (n = 0; n < L; n++)
  93587. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  93588. }
  93589. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  93590. {
  93591. const FLAC__int32 N = L - 1;
  93592. FLAC__int32 n;
  93593. for (n = 0; n < L; n++)
  93594. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  93595. }
  93596. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  93597. {
  93598. const FLAC__int32 N = L - 1;
  93599. FLAC__int32 n;
  93600. for (n = 0; n < L; n++)
  93601. 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));
  93602. }
  93603. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  93604. {
  93605. const FLAC__int32 N = L - 1;
  93606. FLAC__int32 n;
  93607. for (n = 0; n < L; n++)
  93608. 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));
  93609. }
  93610. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  93611. {
  93612. FLAC__int32 n;
  93613. for (n = 0; n < L; n++)
  93614. window[n] = 1.0f;
  93615. }
  93616. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  93617. {
  93618. FLAC__int32 n;
  93619. if (L & 1) {
  93620. for (n = 1; n <= L+1/2; n++)
  93621. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  93622. for (; n <= L; n++)
  93623. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  93624. }
  93625. else {
  93626. for (n = 1; n <= L/2; n++)
  93627. window[n-1] = 2.0f * n / (float)L;
  93628. for (; n <= L; n++)
  93629. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  93630. }
  93631. }
  93632. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  93633. {
  93634. if (p <= 0.0)
  93635. FLAC__window_rectangle(window, L);
  93636. else if (p >= 1.0)
  93637. FLAC__window_hann(window, L);
  93638. else {
  93639. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  93640. FLAC__int32 n;
  93641. FLAC__window_rectangle(window, L);
  93642. if (Np > 0) {
  93643. for (n = 0; n <= Np; n++) {
  93644. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  93645. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  93646. }
  93647. }
  93648. }
  93649. }
  93650. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  93651. {
  93652. const FLAC__int32 N = L - 1;
  93653. const double N2 = (double)N / 2.;
  93654. FLAC__int32 n;
  93655. for (n = 0; n <= N; n++) {
  93656. const double k = ((double)n - N2) / N2;
  93657. window[n] = (FLAC__real)(1.0f - k * k);
  93658. }
  93659. }
  93660. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  93661. #endif
  93662. /*** End of inlined file: window_flac.c ***/
  93663. #else
  93664. #include <FLAC/all.h>
  93665. #endif
  93666. }
  93667. #undef max
  93668. #undef min
  93669. #ifdef _MSC_VER
  93670. #pragma warning (pop)
  93671. #endif
  93672. BEGIN_JUCE_NAMESPACE
  93673. static const char* const flacFormatName = "FLAC file";
  93674. static const juce_wchar* const flacExtensions[] = { T(".flac"), 0 };
  93675. class FlacReader : public AudioFormatReader
  93676. {
  93677. public:
  93678. FlacReader (InputStream* const in)
  93679. : AudioFormatReader (in, TRANS (flacFormatName)),
  93680. reservoir (2, 0),
  93681. reservoirStart (0),
  93682. samplesInReservoir (0),
  93683. scanningForLength (false)
  93684. {
  93685. using namespace FlacNamespace;
  93686. lengthInSamples = 0;
  93687. decoder = FLAC__stream_decoder_new();
  93688. ok = FLAC__stream_decoder_init_stream (decoder,
  93689. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  93690. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  93691. this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  93692. if (ok)
  93693. {
  93694. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93695. if (lengthInSamples == 0 && sampleRate > 0)
  93696. {
  93697. // the length hasn't been stored in the metadata, so we'll need to
  93698. // work it out the length the hard way, by scanning the whole file..
  93699. scanningForLength = true;
  93700. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  93701. scanningForLength = false;
  93702. const int64 tempLength = lengthInSamples;
  93703. FLAC__stream_decoder_reset (decoder);
  93704. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  93705. lengthInSamples = tempLength;
  93706. }
  93707. }
  93708. }
  93709. ~FlacReader()
  93710. {
  93711. FlacNamespace::FLAC__stream_decoder_delete (decoder);
  93712. }
  93713. void useMetadata (const FlacNamespace::FLAC__StreamMetadata_StreamInfo& info)
  93714. {
  93715. sampleRate = info.sample_rate;
  93716. bitsPerSample = info.bits_per_sample;
  93717. lengthInSamples = (unsigned int) info.total_samples;
  93718. numChannels = info.channels;
  93719. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  93720. }
  93721. // returns the number of samples read
  93722. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  93723. int64 startSampleInFile, int numSamples)
  93724. {
  93725. using namespace FlacNamespace;
  93726. if (! ok)
  93727. return false;
  93728. while (numSamples > 0)
  93729. {
  93730. if (startSampleInFile >= reservoirStart
  93731. && startSampleInFile < reservoirStart + samplesInReservoir)
  93732. {
  93733. const int num = (int) jmin ((int64) numSamples,
  93734. reservoirStart + samplesInReservoir - startSampleInFile);
  93735. jassert (num > 0);
  93736. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  93737. if (destSamples[i] != 0)
  93738. memcpy (destSamples[i] + startOffsetInDestBuffer,
  93739. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  93740. sizeof (int) * num);
  93741. startOffsetInDestBuffer += num;
  93742. startSampleInFile += num;
  93743. numSamples -= num;
  93744. }
  93745. else
  93746. {
  93747. if (startSampleInFile >= (int) lengthInSamples)
  93748. {
  93749. samplesInReservoir = 0;
  93750. }
  93751. else if (startSampleInFile < reservoirStart
  93752. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  93753. {
  93754. // had some problems with flac crashing if the read pos is aligned more
  93755. // accurately than this. Probably fixed in newer versions of the library, though.
  93756. reservoirStart = (int) (startSampleInFile & ~511);
  93757. samplesInReservoir = 0;
  93758. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  93759. }
  93760. else
  93761. {
  93762. reservoirStart += samplesInReservoir;
  93763. samplesInReservoir = 0;
  93764. FLAC__stream_decoder_process_single (decoder);
  93765. }
  93766. if (samplesInReservoir == 0)
  93767. break;
  93768. }
  93769. }
  93770. if (numSamples > 0)
  93771. {
  93772. for (int i = numDestChannels; --i >= 0;)
  93773. if (destSamples[i] != 0)
  93774. zeromem (destSamples[i] + startOffsetInDestBuffer,
  93775. sizeof (int) * numSamples);
  93776. }
  93777. return true;
  93778. }
  93779. void useSamples (const FlacNamespace::FLAC__int32* const buffer[], int numSamples)
  93780. {
  93781. if (scanningForLength)
  93782. {
  93783. lengthInSamples += numSamples;
  93784. }
  93785. else
  93786. {
  93787. if (numSamples > reservoir.getNumSamples())
  93788. reservoir.setSize (numChannels, numSamples, false, false, true);
  93789. const int bitsToShift = 32 - bitsPerSample;
  93790. for (int i = 0; i < (int) numChannels; ++i)
  93791. {
  93792. const FlacNamespace::FLAC__int32* src = buffer[i];
  93793. int n = i;
  93794. while (src == 0 && n > 0)
  93795. src = buffer [--n];
  93796. if (src != 0)
  93797. {
  93798. int* dest = (int*) reservoir.getSampleData(i);
  93799. for (int j = 0; j < numSamples; ++j)
  93800. dest[j] = src[j] << bitsToShift;
  93801. }
  93802. }
  93803. samplesInReservoir = numSamples;
  93804. }
  93805. }
  93806. static FlacNamespace::FLAC__StreamDecoderReadStatus readCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__byte buffer[], size_t* bytes, void* client_data)
  93807. {
  93808. using namespace FlacNamespace;
  93809. *bytes = (size_t) static_cast <const FlacReader*> (client_data)->input->read (buffer, (int) *bytes);
  93810. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93811. }
  93812. static FlacNamespace::FLAC__StreamDecoderSeekStatus seekCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64 absolute_byte_offset, void* client_data)
  93813. {
  93814. using namespace FlacNamespace;
  93815. static_cast <const FlacReader*> (client_data)->input->setPosition ((int) absolute_byte_offset);
  93816. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  93817. }
  93818. static FlacNamespace::FLAC__StreamDecoderTellStatus tellCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93819. {
  93820. using namespace FlacNamespace;
  93821. *absolute_byte_offset = static_cast <const FlacReader*> (client_data)->input->getPosition();
  93822. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  93823. }
  93824. static FlacNamespace::FLAC__StreamDecoderLengthStatus lengthCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__uint64* stream_length, void* client_data)
  93825. {
  93826. using namespace FlacNamespace;
  93827. *stream_length = static_cast <const FlacReader*> (client_data)->input->getTotalLength();
  93828. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  93829. }
  93830. static FlacNamespace::FLAC__bool eofCallback_ (const FlacNamespace::FLAC__StreamDecoder*, void* client_data)
  93831. {
  93832. return static_cast <const FlacReader*> (client_data)->input->isExhausted();
  93833. }
  93834. static FlacNamespace::FLAC__StreamDecoderWriteStatus writeCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93835. const FlacNamespace::FLAC__Frame* frame,
  93836. const FlacNamespace::FLAC__int32* const buffer[],
  93837. void* client_data)
  93838. {
  93839. using namespace FlacNamespace;
  93840. static_cast <FlacReader*> (client_data)->useSamples (buffer, frame->header.blocksize);
  93841. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93842. }
  93843. static void metadataCallback_ (const FlacNamespace::FLAC__StreamDecoder*,
  93844. const FlacNamespace::FLAC__StreamMetadata* metadata,
  93845. void* client_data)
  93846. {
  93847. static_cast <FlacReader*> (client_data)->useMetadata (metadata->data.stream_info);
  93848. }
  93849. static void errorCallback_ (const FlacNamespace::FLAC__StreamDecoder*, FlacNamespace::FLAC__StreamDecoderErrorStatus, void*)
  93850. {
  93851. }
  93852. juce_UseDebuggingNewOperator
  93853. private:
  93854. FlacNamespace::FLAC__StreamDecoder* decoder;
  93855. AudioSampleBuffer reservoir;
  93856. int reservoirStart, samplesInReservoir;
  93857. bool ok, scanningForLength;
  93858. FlacReader (const FlacReader&);
  93859. FlacReader& operator= (const FlacReader&);
  93860. };
  93861. class FlacWriter : public AudioFormatWriter
  93862. {
  93863. public:
  93864. FlacWriter (OutputStream* const out,
  93865. const double sampleRate_,
  93866. const int numChannels_,
  93867. const int bitsPerSample_)
  93868. : AudioFormatWriter (out, TRANS (flacFormatName),
  93869. sampleRate_,
  93870. numChannels_,
  93871. bitsPerSample_)
  93872. {
  93873. using namespace FlacNamespace;
  93874. encoder = FLAC__stream_encoder_new();
  93875. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  93876. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  93877. FLAC__stream_encoder_set_channels (encoder, numChannels);
  93878. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  93879. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  93880. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  93881. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  93882. ok = FLAC__stream_encoder_init_stream (encoder,
  93883. encodeWriteCallback, encodeSeekCallback,
  93884. encodeTellCallback, encodeMetadataCallback,
  93885. this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  93886. }
  93887. ~FlacWriter()
  93888. {
  93889. if (ok)
  93890. {
  93891. FlacNamespace::FLAC__stream_encoder_finish (encoder);
  93892. output->flush();
  93893. }
  93894. else
  93895. {
  93896. output = 0; // to stop the base class deleting this, as it needs to be returned
  93897. // to the caller of createWriter()
  93898. }
  93899. FlacNamespace::FLAC__stream_encoder_delete (encoder);
  93900. }
  93901. bool write (const int** samplesToWrite, int numSamples)
  93902. {
  93903. using namespace FlacNamespace;
  93904. if (! ok)
  93905. return false;
  93906. int* buf[3];
  93907. const int bitsToShift = 32 - bitsPerSample;
  93908. if (bitsToShift > 0)
  93909. {
  93910. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  93911. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  93912. buf[0] = (int*) temp.getData();
  93913. buf[1] = buf[0] + numSamples;
  93914. buf[2] = 0;
  93915. for (int i = numChannelsToWrite; --i >= 0;)
  93916. {
  93917. if (samplesToWrite[i] != 0)
  93918. {
  93919. for (int j = 0; j < numSamples; ++j)
  93920. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  93921. }
  93922. }
  93923. samplesToWrite = (const int**) buf;
  93924. }
  93925. return FLAC__stream_encoder_process (encoder,
  93926. (const FLAC__int32**) samplesToWrite,
  93927. numSamples) != 0;
  93928. }
  93929. bool writeData (const void* const data, const int size) const
  93930. {
  93931. return output->write (data, size);
  93932. }
  93933. static void packUint32 (FlacNamespace::FLAC__uint32 val, FlacNamespace::FLAC__byte* b, const int bytes)
  93934. {
  93935. using namespace FlacNamespace;
  93936. b += bytes;
  93937. for (int i = 0; i < bytes; ++i)
  93938. {
  93939. *(--b) = (FLAC__byte) (val & 0xff);
  93940. val >>= 8;
  93941. }
  93942. }
  93943. void writeMetaData (const FlacNamespace::FLAC__StreamMetadata* metadata)
  93944. {
  93945. using namespace FlacNamespace;
  93946. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  93947. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  93948. const unsigned int channelsMinus1 = info.channels - 1;
  93949. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  93950. packUint32 (info.min_blocksize, buffer, 2);
  93951. packUint32 (info.max_blocksize, buffer + 2, 2);
  93952. packUint32 (info.min_framesize, buffer + 4, 3);
  93953. packUint32 (info.max_framesize, buffer + 7, 3);
  93954. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  93955. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  93956. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  93957. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  93958. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  93959. memcpy (buffer + 18, info.md5sum, 16);
  93960. const bool seekOk = output->setPosition (4);
  93961. (void) seekOk;
  93962. // if this fails, you've given it an output stream that can't seek! It needs
  93963. // to be able to seek back to write the header
  93964. jassert (seekOk);
  93965. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  93966. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  93967. }
  93968. static FlacNamespace::FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FlacNamespace::FLAC__StreamEncoder*,
  93969. const FlacNamespace::FLAC__byte buffer[],
  93970. size_t bytes,
  93971. unsigned int /*samples*/,
  93972. unsigned int /*current_frame*/,
  93973. void* client_data)
  93974. {
  93975. using namespace FlacNamespace;
  93976. return static_cast <FlacWriter*> (client_data)->writeData (buffer, (int) bytes)
  93977. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  93978. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93979. }
  93980. static FlacNamespace::FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64, void*)
  93981. {
  93982. using namespace FlacNamespace;
  93983. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  93984. }
  93985. static FlacNamespace::FLAC__StreamEncoderTellStatus encodeTellCallback (const FlacNamespace::FLAC__StreamEncoder*, FlacNamespace::FLAC__uint64* absolute_byte_offset, void* client_data)
  93986. {
  93987. using namespace FlacNamespace;
  93988. if (client_data == 0)
  93989. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  93990. *absolute_byte_offset = (FLAC__uint64) static_cast <FlacWriter*> (client_data)->output->getPosition();
  93991. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93992. }
  93993. static void encodeMetadataCallback (const FlacNamespace::FLAC__StreamEncoder*, const FlacNamespace::FLAC__StreamMetadata* metadata, void* client_data)
  93994. {
  93995. static_cast <FlacWriter*> (client_data)->writeMetaData (metadata);
  93996. }
  93997. juce_UseDebuggingNewOperator
  93998. bool ok;
  93999. private:
  94000. FlacNamespace::FLAC__StreamEncoder* encoder;
  94001. MemoryBlock temp;
  94002. FlacWriter (const FlacWriter&);
  94003. FlacWriter& operator= (const FlacWriter&);
  94004. };
  94005. FlacAudioFormat::FlacAudioFormat()
  94006. : AudioFormat (TRANS (flacFormatName), (const juce_wchar**) flacExtensions)
  94007. {
  94008. }
  94009. FlacAudioFormat::~FlacAudioFormat()
  94010. {
  94011. }
  94012. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94013. {
  94014. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94015. return Array <int> (rates);
  94016. }
  94017. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94018. {
  94019. const int depths[] = { 16, 24, 0 };
  94020. return Array <int> (depths);
  94021. }
  94022. bool FlacAudioFormat::canDoStereo()
  94023. {
  94024. return true;
  94025. }
  94026. bool FlacAudioFormat::canDoMono()
  94027. {
  94028. return true;
  94029. }
  94030. bool FlacAudioFormat::isCompressed()
  94031. {
  94032. return true;
  94033. }
  94034. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94035. const bool deleteStreamIfOpeningFails)
  94036. {
  94037. ScopedPointer<FlacReader> r (new FlacReader (in));
  94038. if (r->sampleRate != 0)
  94039. return r.release();
  94040. if (! deleteStreamIfOpeningFails)
  94041. r->input = 0;
  94042. return 0;
  94043. }
  94044. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94045. double sampleRate,
  94046. unsigned int numberOfChannels,
  94047. int bitsPerSample,
  94048. const StringPairArray& /*metadataValues*/,
  94049. int /*qualityOptionIndex*/)
  94050. {
  94051. if (getPossibleBitDepths().contains (bitsPerSample))
  94052. {
  94053. ScopedPointer<FlacWriter> w (new FlacWriter (out, sampleRate, numberOfChannels, bitsPerSample));
  94054. if (w->ok)
  94055. return w.release();
  94056. }
  94057. return 0;
  94058. }
  94059. END_JUCE_NAMESPACE
  94060. #endif
  94061. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94062. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94063. #if JUCE_USE_OGGVORBIS
  94064. #if JUCE_MAC
  94065. #define __MACOSX__ 1
  94066. #endif
  94067. namespace OggVorbisNamespace
  94068. {
  94069. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94070. /*** Start of inlined file: vorbisenc.h ***/
  94071. #ifndef _OV_ENC_H_
  94072. #define _OV_ENC_H_
  94073. #ifdef __cplusplus
  94074. extern "C"
  94075. {
  94076. #endif /* __cplusplus */
  94077. /*** Start of inlined file: codec.h ***/
  94078. #ifndef _vorbis_codec_h_
  94079. #define _vorbis_codec_h_
  94080. #ifdef __cplusplus
  94081. extern "C"
  94082. {
  94083. #endif /* __cplusplus */
  94084. /*** Start of inlined file: ogg.h ***/
  94085. #ifndef _OGG_H
  94086. #define _OGG_H
  94087. #ifdef __cplusplus
  94088. extern "C" {
  94089. #endif
  94090. /*** Start of inlined file: os_types.h ***/
  94091. #ifndef _OS_TYPES_H
  94092. #define _OS_TYPES_H
  94093. #define _ogg_malloc malloc
  94094. #define _ogg_calloc calloc
  94095. #define _ogg_realloc realloc
  94096. #define _ogg_free free
  94097. #if defined(_WIN32)
  94098. # if defined(__CYGWIN__)
  94099. # include <_G_config.h>
  94100. typedef _G_int64_t ogg_int64_t;
  94101. typedef _G_int32_t ogg_int32_t;
  94102. typedef _G_uint32_t ogg_uint32_t;
  94103. typedef _G_int16_t ogg_int16_t;
  94104. typedef _G_uint16_t ogg_uint16_t;
  94105. # elif defined(__MINGW32__)
  94106. typedef short ogg_int16_t;
  94107. typedef unsigned short ogg_uint16_t;
  94108. typedef int ogg_int32_t;
  94109. typedef unsigned int ogg_uint32_t;
  94110. typedef long long ogg_int64_t;
  94111. typedef unsigned long long ogg_uint64_t;
  94112. # elif defined(__MWERKS__)
  94113. typedef long long ogg_int64_t;
  94114. typedef int ogg_int32_t;
  94115. typedef unsigned int ogg_uint32_t;
  94116. typedef short ogg_int16_t;
  94117. typedef unsigned short ogg_uint16_t;
  94118. # else
  94119. typedef __int64 ogg_int64_t;
  94120. typedef __int32 ogg_int32_t;
  94121. typedef unsigned __int32 ogg_uint32_t;
  94122. typedef __int16 ogg_int16_t;
  94123. typedef unsigned __int16 ogg_uint16_t;
  94124. # endif
  94125. #elif defined(__MACOS__)
  94126. # include <sys/types.h>
  94127. typedef SInt16 ogg_int16_t;
  94128. typedef UInt16 ogg_uint16_t;
  94129. typedef SInt32 ogg_int32_t;
  94130. typedef UInt32 ogg_uint32_t;
  94131. typedef SInt64 ogg_int64_t;
  94132. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94133. # include <sys/types.h>
  94134. typedef int16_t ogg_int16_t;
  94135. typedef u_int16_t ogg_uint16_t;
  94136. typedef int32_t ogg_int32_t;
  94137. typedef u_int32_t ogg_uint32_t;
  94138. typedef int64_t ogg_int64_t;
  94139. #elif defined(__BEOS__)
  94140. # include <inttypes.h>
  94141. typedef int16_t ogg_int16_t;
  94142. typedef u_int16_t ogg_uint16_t;
  94143. typedef int32_t ogg_int32_t;
  94144. typedef u_int32_t ogg_uint32_t;
  94145. typedef int64_t ogg_int64_t;
  94146. #elif defined (__EMX__)
  94147. typedef short ogg_int16_t;
  94148. typedef unsigned short ogg_uint16_t;
  94149. typedef int ogg_int32_t;
  94150. typedef unsigned int ogg_uint32_t;
  94151. typedef long long ogg_int64_t;
  94152. #elif defined (DJGPP)
  94153. typedef short ogg_int16_t;
  94154. typedef int ogg_int32_t;
  94155. typedef unsigned int ogg_uint32_t;
  94156. typedef long long ogg_int64_t;
  94157. #elif defined(R5900)
  94158. typedef long ogg_int64_t;
  94159. typedef int ogg_int32_t;
  94160. typedef unsigned ogg_uint32_t;
  94161. typedef short ogg_int16_t;
  94162. #elif defined(__SYMBIAN32__)
  94163. typedef signed short ogg_int16_t;
  94164. typedef unsigned short ogg_uint16_t;
  94165. typedef signed int ogg_int32_t;
  94166. typedef unsigned int ogg_uint32_t;
  94167. typedef long long int ogg_int64_t;
  94168. #else
  94169. # include <sys/types.h>
  94170. /*** Start of inlined file: config_types.h ***/
  94171. #ifndef __CONFIG_TYPES_H__
  94172. #define __CONFIG_TYPES_H__
  94173. typedef int16_t ogg_int16_t;
  94174. typedef unsigned short ogg_uint16_t;
  94175. typedef int32_t ogg_int32_t;
  94176. typedef unsigned int ogg_uint32_t;
  94177. typedef int64_t ogg_int64_t;
  94178. #endif
  94179. /*** End of inlined file: config_types.h ***/
  94180. #endif
  94181. #endif /* _OS_TYPES_H */
  94182. /*** End of inlined file: os_types.h ***/
  94183. typedef struct {
  94184. long endbyte;
  94185. int endbit;
  94186. unsigned char *buffer;
  94187. unsigned char *ptr;
  94188. long storage;
  94189. } oggpack_buffer;
  94190. typedef struct {
  94191. unsigned char *header;
  94192. long header_len;
  94193. unsigned char *body;
  94194. long body_len;
  94195. } ogg_page;
  94196. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94197. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94198. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94199. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94200. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94201. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94202. }
  94203. typedef struct {
  94204. unsigned char *body_data; /* bytes from packet bodies */
  94205. long body_storage; /* storage elements allocated */
  94206. long body_fill; /* elements stored; fill mark */
  94207. long body_returned; /* elements of fill returned */
  94208. int *lacing_vals; /* The values that will go to the segment table */
  94209. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94210. this way, but it is simple coupled to the
  94211. lacing fifo */
  94212. long lacing_storage;
  94213. long lacing_fill;
  94214. long lacing_packet;
  94215. long lacing_returned;
  94216. unsigned char header[282]; /* working space for header encode */
  94217. int header_fill;
  94218. int e_o_s; /* set when we have buffered the last packet in the
  94219. logical bitstream */
  94220. int b_o_s; /* set after we've written the initial page
  94221. of a logical bitstream */
  94222. long serialno;
  94223. long pageno;
  94224. ogg_int64_t packetno; /* sequence number for decode; the framing
  94225. knows where there's a hole in the data,
  94226. but we need coupling so that the codec
  94227. (which is in a seperate abstraction
  94228. layer) also knows about the gap */
  94229. ogg_int64_t granulepos;
  94230. } ogg_stream_state;
  94231. typedef struct {
  94232. unsigned char *packet;
  94233. long bytes;
  94234. long b_o_s;
  94235. long e_o_s;
  94236. ogg_int64_t granulepos;
  94237. ogg_int64_t packetno; /* sequence number for decode; the framing
  94238. knows where there's a hole in the data,
  94239. but we need coupling so that the codec
  94240. (which is in a seperate abstraction
  94241. layer) also knows about the gap */
  94242. } ogg_packet;
  94243. typedef struct {
  94244. unsigned char *data;
  94245. int storage;
  94246. int fill;
  94247. int returned;
  94248. int unsynced;
  94249. int headerbytes;
  94250. int bodybytes;
  94251. } ogg_sync_state;
  94252. extern void oggpack_writeinit(oggpack_buffer *b);
  94253. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94254. extern void oggpack_writealign(oggpack_buffer *b);
  94255. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94256. extern void oggpack_reset(oggpack_buffer *b);
  94257. extern void oggpack_writeclear(oggpack_buffer *b);
  94258. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94259. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94260. extern long oggpack_look(oggpack_buffer *b,int bits);
  94261. extern long oggpack_look1(oggpack_buffer *b);
  94262. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94263. extern void oggpack_adv1(oggpack_buffer *b);
  94264. extern long oggpack_read(oggpack_buffer *b,int bits);
  94265. extern long oggpack_read1(oggpack_buffer *b);
  94266. extern long oggpack_bytes(oggpack_buffer *b);
  94267. extern long oggpack_bits(oggpack_buffer *b);
  94268. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94269. extern void oggpackB_writeinit(oggpack_buffer *b);
  94270. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94271. extern void oggpackB_writealign(oggpack_buffer *b);
  94272. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94273. extern void oggpackB_reset(oggpack_buffer *b);
  94274. extern void oggpackB_writeclear(oggpack_buffer *b);
  94275. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94276. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94277. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94278. extern long oggpackB_look1(oggpack_buffer *b);
  94279. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94280. extern void oggpackB_adv1(oggpack_buffer *b);
  94281. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94282. extern long oggpackB_read1(oggpack_buffer *b);
  94283. extern long oggpackB_bytes(oggpack_buffer *b);
  94284. extern long oggpackB_bits(oggpack_buffer *b);
  94285. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94286. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94287. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94288. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94289. extern int ogg_sync_init(ogg_sync_state *oy);
  94290. extern int ogg_sync_clear(ogg_sync_state *oy);
  94291. extern int ogg_sync_reset(ogg_sync_state *oy);
  94292. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94293. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94294. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94295. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94296. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94297. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94298. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94299. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94300. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94301. extern int ogg_stream_clear(ogg_stream_state *os);
  94302. extern int ogg_stream_reset(ogg_stream_state *os);
  94303. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94304. extern int ogg_stream_destroy(ogg_stream_state *os);
  94305. extern int ogg_stream_eos(ogg_stream_state *os);
  94306. extern void ogg_page_checksum_set(ogg_page *og);
  94307. extern int ogg_page_version(ogg_page *og);
  94308. extern int ogg_page_continued(ogg_page *og);
  94309. extern int ogg_page_bos(ogg_page *og);
  94310. extern int ogg_page_eos(ogg_page *og);
  94311. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94312. extern int ogg_page_serialno(ogg_page *og);
  94313. extern long ogg_page_pageno(ogg_page *og);
  94314. extern int ogg_page_packets(ogg_page *og);
  94315. extern void ogg_packet_clear(ogg_packet *op);
  94316. #ifdef __cplusplus
  94317. }
  94318. #endif
  94319. #endif /* _OGG_H */
  94320. /*** End of inlined file: ogg.h ***/
  94321. typedef struct vorbis_info{
  94322. int version;
  94323. int channels;
  94324. long rate;
  94325. long bitrate_upper;
  94326. long bitrate_nominal;
  94327. long bitrate_lower;
  94328. long bitrate_window;
  94329. void *codec_setup;
  94330. } vorbis_info;
  94331. typedef struct vorbis_dsp_state{
  94332. int analysisp;
  94333. vorbis_info *vi;
  94334. float **pcm;
  94335. float **pcmret;
  94336. int pcm_storage;
  94337. int pcm_current;
  94338. int pcm_returned;
  94339. int preextrapolate;
  94340. int eofflag;
  94341. long lW;
  94342. long W;
  94343. long nW;
  94344. long centerW;
  94345. ogg_int64_t granulepos;
  94346. ogg_int64_t sequence;
  94347. ogg_int64_t glue_bits;
  94348. ogg_int64_t time_bits;
  94349. ogg_int64_t floor_bits;
  94350. ogg_int64_t res_bits;
  94351. void *backend_state;
  94352. } vorbis_dsp_state;
  94353. typedef struct vorbis_block{
  94354. float **pcm; /* this is a pointer into local storage */
  94355. oggpack_buffer opb;
  94356. long lW;
  94357. long W;
  94358. long nW;
  94359. int pcmend;
  94360. int mode;
  94361. int eofflag;
  94362. ogg_int64_t granulepos;
  94363. ogg_int64_t sequence;
  94364. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94365. void *localstore;
  94366. long localtop;
  94367. long localalloc;
  94368. long totaluse;
  94369. struct alloc_chain *reap;
  94370. long glue_bits;
  94371. long time_bits;
  94372. long floor_bits;
  94373. long res_bits;
  94374. void *internal;
  94375. } vorbis_block;
  94376. struct alloc_chain{
  94377. void *ptr;
  94378. struct alloc_chain *next;
  94379. };
  94380. typedef struct vorbis_comment{
  94381. char **user_comments;
  94382. int *comment_lengths;
  94383. int comments;
  94384. char *vendor;
  94385. } vorbis_comment;
  94386. extern void vorbis_info_init(vorbis_info *vi);
  94387. extern void vorbis_info_clear(vorbis_info *vi);
  94388. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94389. extern void vorbis_comment_init(vorbis_comment *vc);
  94390. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94391. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94392. const char *tag, char *contents);
  94393. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94394. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94395. extern void vorbis_comment_clear(vorbis_comment *vc);
  94396. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94397. extern int vorbis_block_clear(vorbis_block *vb);
  94398. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94399. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94400. ogg_int64_t granulepos);
  94401. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94402. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94403. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94404. vorbis_comment *vc,
  94405. ogg_packet *op,
  94406. ogg_packet *op_comm,
  94407. ogg_packet *op_code);
  94408. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94409. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94410. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94411. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94412. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94413. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94414. ogg_packet *op);
  94415. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94416. ogg_packet *op);
  94417. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94418. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94419. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94420. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94421. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94422. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94423. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94424. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94425. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94426. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94427. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94428. #define OV_FALSE -1
  94429. #define OV_EOF -2
  94430. #define OV_HOLE -3
  94431. #define OV_EREAD -128
  94432. #define OV_EFAULT -129
  94433. #define OV_EIMPL -130
  94434. #define OV_EINVAL -131
  94435. #define OV_ENOTVORBIS -132
  94436. #define OV_EBADHEADER -133
  94437. #define OV_EVERSION -134
  94438. #define OV_ENOTAUDIO -135
  94439. #define OV_EBADPACKET -136
  94440. #define OV_EBADLINK -137
  94441. #define OV_ENOSEEK -138
  94442. #ifdef __cplusplus
  94443. }
  94444. #endif /* __cplusplus */
  94445. #endif
  94446. /*** End of inlined file: codec.h ***/
  94447. extern int vorbis_encode_init(vorbis_info *vi,
  94448. long channels,
  94449. long rate,
  94450. long max_bitrate,
  94451. long nominal_bitrate,
  94452. long min_bitrate);
  94453. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94454. long channels,
  94455. long rate,
  94456. long max_bitrate,
  94457. long nominal_bitrate,
  94458. long min_bitrate);
  94459. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94460. long channels,
  94461. long rate,
  94462. float quality /* quality level from 0. (lo) to 1. (hi) */
  94463. );
  94464. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94465. long channels,
  94466. long rate,
  94467. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94468. );
  94469. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94470. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94471. #define OV_ECTL_RATEMANAGE_GET 0x10
  94472. #define OV_ECTL_RATEMANAGE_SET 0x11
  94473. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94474. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94475. struct ovectl_ratemanage_arg {
  94476. int management_active;
  94477. long bitrate_hard_min;
  94478. long bitrate_hard_max;
  94479. double bitrate_hard_window;
  94480. long bitrate_av_lo;
  94481. long bitrate_av_hi;
  94482. double bitrate_av_window;
  94483. double bitrate_av_window_center;
  94484. };
  94485. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94486. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94487. struct ovectl_ratemanage2_arg {
  94488. int management_active;
  94489. long bitrate_limit_min_kbps;
  94490. long bitrate_limit_max_kbps;
  94491. long bitrate_limit_reservoir_bits;
  94492. double bitrate_limit_reservoir_bias;
  94493. long bitrate_average_kbps;
  94494. double bitrate_average_damping;
  94495. };
  94496. #define OV_ECTL_LOWPASS_GET 0x20
  94497. #define OV_ECTL_LOWPASS_SET 0x21
  94498. #define OV_ECTL_IBLOCK_GET 0x30
  94499. #define OV_ECTL_IBLOCK_SET 0x31
  94500. #ifdef __cplusplus
  94501. }
  94502. #endif /* __cplusplus */
  94503. #endif
  94504. /*** End of inlined file: vorbisenc.h ***/
  94505. /*** Start of inlined file: vorbisfile.h ***/
  94506. #ifndef _OV_FILE_H_
  94507. #define _OV_FILE_H_
  94508. #ifdef __cplusplus
  94509. extern "C"
  94510. {
  94511. #endif /* __cplusplus */
  94512. #include <stdio.h>
  94513. typedef struct {
  94514. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  94515. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  94516. int (*close_func) (void *datasource);
  94517. long (*tell_func) (void *datasource);
  94518. } ov_callbacks;
  94519. #define NOTOPEN 0
  94520. #define PARTOPEN 1
  94521. #define OPENED 2
  94522. #define STREAMSET 3
  94523. #define INITSET 4
  94524. typedef struct OggVorbis_File {
  94525. void *datasource; /* Pointer to a FILE *, etc. */
  94526. int seekable;
  94527. ogg_int64_t offset;
  94528. ogg_int64_t end;
  94529. ogg_sync_state oy;
  94530. int links;
  94531. ogg_int64_t *offsets;
  94532. ogg_int64_t *dataoffsets;
  94533. long *serialnos;
  94534. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  94535. compatability; x2 size, stores both
  94536. beginning and end values */
  94537. vorbis_info *vi;
  94538. vorbis_comment *vc;
  94539. ogg_int64_t pcm_offset;
  94540. int ready_state;
  94541. long current_serialno;
  94542. int current_link;
  94543. double bittrack;
  94544. double samptrack;
  94545. ogg_stream_state os; /* take physical pages, weld into a logical
  94546. stream of packets */
  94547. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  94548. vorbis_block vb; /* local working space for packet->PCM decode */
  94549. ov_callbacks callbacks;
  94550. } OggVorbis_File;
  94551. extern int ov_clear(OggVorbis_File *vf);
  94552. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94553. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  94554. char *initial, long ibytes, ov_callbacks callbacks);
  94555. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  94556. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  94557. char *initial, long ibytes, ov_callbacks callbacks);
  94558. extern int ov_test_open(OggVorbis_File *vf);
  94559. extern long ov_bitrate(OggVorbis_File *vf,int i);
  94560. extern long ov_bitrate_instant(OggVorbis_File *vf);
  94561. extern long ov_streams(OggVorbis_File *vf);
  94562. extern long ov_seekable(OggVorbis_File *vf);
  94563. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  94564. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  94565. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  94566. extern double ov_time_total(OggVorbis_File *vf,int i);
  94567. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94568. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  94569. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  94570. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  94571. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  94572. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94573. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94574. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  94575. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  94576. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  94577. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  94578. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  94579. extern double ov_time_tell(OggVorbis_File *vf);
  94580. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  94581. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  94582. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  94583. int *bitstream);
  94584. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  94585. int bigendianp,int word,int sgned,int *bitstream);
  94586. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  94587. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  94588. extern int ov_halfrate_p(OggVorbis_File *vf);
  94589. #ifdef __cplusplus
  94590. }
  94591. #endif /* __cplusplus */
  94592. #endif
  94593. /*** End of inlined file: vorbisfile.h ***/
  94594. /*** Start of inlined file: bitwise.c ***/
  94595. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  94596. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  94597. // tasks..
  94598. #if JUCE_MSVC
  94599. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  94600. #endif
  94601. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  94602. #if JUCE_USE_OGGVORBIS
  94603. #include <string.h>
  94604. #include <stdlib.h>
  94605. #define BUFFER_INCREMENT 256
  94606. static const unsigned long mask[]=
  94607. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  94608. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  94609. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  94610. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  94611. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  94612. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  94613. 0x3fffffff,0x7fffffff,0xffffffff };
  94614. static const unsigned int mask8B[]=
  94615. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  94616. void oggpack_writeinit(oggpack_buffer *b){
  94617. memset(b,0,sizeof(*b));
  94618. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  94619. b->buffer[0]='\0';
  94620. b->storage=BUFFER_INCREMENT;
  94621. }
  94622. void oggpackB_writeinit(oggpack_buffer *b){
  94623. oggpack_writeinit(b);
  94624. }
  94625. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  94626. long bytes=bits>>3;
  94627. bits-=bytes*8;
  94628. b->ptr=b->buffer+bytes;
  94629. b->endbit=bits;
  94630. b->endbyte=bytes;
  94631. *b->ptr&=mask[bits];
  94632. }
  94633. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  94634. long bytes=bits>>3;
  94635. bits-=bytes*8;
  94636. b->ptr=b->buffer+bytes;
  94637. b->endbit=bits;
  94638. b->endbyte=bytes;
  94639. *b->ptr&=mask8B[bits];
  94640. }
  94641. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  94642. if(b->endbyte+4>=b->storage){
  94643. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94644. b->storage+=BUFFER_INCREMENT;
  94645. b->ptr=b->buffer+b->endbyte;
  94646. }
  94647. value&=mask[bits];
  94648. bits+=b->endbit;
  94649. b->ptr[0]|=value<<b->endbit;
  94650. if(bits>=8){
  94651. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  94652. if(bits>=16){
  94653. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  94654. if(bits>=24){
  94655. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  94656. if(bits>=32){
  94657. if(b->endbit)
  94658. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  94659. else
  94660. b->ptr[4]=0;
  94661. }
  94662. }
  94663. }
  94664. }
  94665. b->endbyte+=bits/8;
  94666. b->ptr+=bits/8;
  94667. b->endbit=bits&7;
  94668. }
  94669. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  94670. if(b->endbyte+4>=b->storage){
  94671. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  94672. b->storage+=BUFFER_INCREMENT;
  94673. b->ptr=b->buffer+b->endbyte;
  94674. }
  94675. value=(value&mask[bits])<<(32-bits);
  94676. bits+=b->endbit;
  94677. b->ptr[0]|=value>>(24+b->endbit);
  94678. if(bits>=8){
  94679. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  94680. if(bits>=16){
  94681. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  94682. if(bits>=24){
  94683. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  94684. if(bits>=32){
  94685. if(b->endbit)
  94686. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  94687. else
  94688. b->ptr[4]=0;
  94689. }
  94690. }
  94691. }
  94692. }
  94693. b->endbyte+=bits/8;
  94694. b->ptr+=bits/8;
  94695. b->endbit=bits&7;
  94696. }
  94697. void oggpack_writealign(oggpack_buffer *b){
  94698. int bits=8-b->endbit;
  94699. if(bits<8)
  94700. oggpack_write(b,0,bits);
  94701. }
  94702. void oggpackB_writealign(oggpack_buffer *b){
  94703. int bits=8-b->endbit;
  94704. if(bits<8)
  94705. oggpackB_write(b,0,bits);
  94706. }
  94707. static void oggpack_writecopy_helper(oggpack_buffer *b,
  94708. void *source,
  94709. long bits,
  94710. void (*w)(oggpack_buffer *,
  94711. unsigned long,
  94712. int),
  94713. int msb){
  94714. unsigned char *ptr=(unsigned char *)source;
  94715. long bytes=bits/8;
  94716. bits-=bytes*8;
  94717. if(b->endbit){
  94718. int i;
  94719. for(i=0;i<bytes;i++)
  94720. w(b,(unsigned long)(ptr[i]),8);
  94721. }else{
  94722. if(b->endbyte+bytes+1>=b->storage){
  94723. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  94724. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  94725. b->ptr=b->buffer+b->endbyte;
  94726. }
  94727. memmove(b->ptr,source,bytes);
  94728. b->ptr+=bytes;
  94729. b->endbyte+=bytes;
  94730. *b->ptr=0;
  94731. }
  94732. if(bits){
  94733. if(msb)
  94734. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  94735. else
  94736. w(b,(unsigned long)(ptr[bytes]),bits);
  94737. }
  94738. }
  94739. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  94740. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  94741. }
  94742. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  94743. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  94744. }
  94745. void oggpack_reset(oggpack_buffer *b){
  94746. b->ptr=b->buffer;
  94747. b->buffer[0]=0;
  94748. b->endbit=b->endbyte=0;
  94749. }
  94750. void oggpackB_reset(oggpack_buffer *b){
  94751. oggpack_reset(b);
  94752. }
  94753. void oggpack_writeclear(oggpack_buffer *b){
  94754. _ogg_free(b->buffer);
  94755. memset(b,0,sizeof(*b));
  94756. }
  94757. void oggpackB_writeclear(oggpack_buffer *b){
  94758. oggpack_writeclear(b);
  94759. }
  94760. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94761. memset(b,0,sizeof(*b));
  94762. b->buffer=b->ptr=buf;
  94763. b->storage=bytes;
  94764. }
  94765. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  94766. oggpack_readinit(b,buf,bytes);
  94767. }
  94768. long oggpack_look(oggpack_buffer *b,int bits){
  94769. unsigned long ret;
  94770. unsigned long m=mask[bits];
  94771. bits+=b->endbit;
  94772. if(b->endbyte+4>=b->storage){
  94773. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94774. }
  94775. ret=b->ptr[0]>>b->endbit;
  94776. if(bits>8){
  94777. ret|=b->ptr[1]<<(8-b->endbit);
  94778. if(bits>16){
  94779. ret|=b->ptr[2]<<(16-b->endbit);
  94780. if(bits>24){
  94781. ret|=b->ptr[3]<<(24-b->endbit);
  94782. if(bits>32 && b->endbit)
  94783. ret|=b->ptr[4]<<(32-b->endbit);
  94784. }
  94785. }
  94786. }
  94787. return(m&ret);
  94788. }
  94789. long oggpackB_look(oggpack_buffer *b,int bits){
  94790. unsigned long ret;
  94791. int m=32-bits;
  94792. bits+=b->endbit;
  94793. if(b->endbyte+4>=b->storage){
  94794. if(b->endbyte*8+bits>b->storage*8)return(-1);
  94795. }
  94796. ret=b->ptr[0]<<(24+b->endbit);
  94797. if(bits>8){
  94798. ret|=b->ptr[1]<<(16+b->endbit);
  94799. if(bits>16){
  94800. ret|=b->ptr[2]<<(8+b->endbit);
  94801. if(bits>24){
  94802. ret|=b->ptr[3]<<(b->endbit);
  94803. if(bits>32 && b->endbit)
  94804. ret|=b->ptr[4]>>(8-b->endbit);
  94805. }
  94806. }
  94807. }
  94808. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  94809. }
  94810. long oggpack_look1(oggpack_buffer *b){
  94811. if(b->endbyte>=b->storage)return(-1);
  94812. return((b->ptr[0]>>b->endbit)&1);
  94813. }
  94814. long oggpackB_look1(oggpack_buffer *b){
  94815. if(b->endbyte>=b->storage)return(-1);
  94816. return((b->ptr[0]>>(7-b->endbit))&1);
  94817. }
  94818. void oggpack_adv(oggpack_buffer *b,int bits){
  94819. bits+=b->endbit;
  94820. b->ptr+=bits/8;
  94821. b->endbyte+=bits/8;
  94822. b->endbit=bits&7;
  94823. }
  94824. void oggpackB_adv(oggpack_buffer *b,int bits){
  94825. oggpack_adv(b,bits);
  94826. }
  94827. void oggpack_adv1(oggpack_buffer *b){
  94828. if(++(b->endbit)>7){
  94829. b->endbit=0;
  94830. b->ptr++;
  94831. b->endbyte++;
  94832. }
  94833. }
  94834. void oggpackB_adv1(oggpack_buffer *b){
  94835. oggpack_adv1(b);
  94836. }
  94837. long oggpack_read(oggpack_buffer *b,int bits){
  94838. long ret;
  94839. unsigned long m=mask[bits];
  94840. bits+=b->endbit;
  94841. if(b->endbyte+4>=b->storage){
  94842. ret=-1L;
  94843. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94844. }
  94845. ret=b->ptr[0]>>b->endbit;
  94846. if(bits>8){
  94847. ret|=b->ptr[1]<<(8-b->endbit);
  94848. if(bits>16){
  94849. ret|=b->ptr[2]<<(16-b->endbit);
  94850. if(bits>24){
  94851. ret|=b->ptr[3]<<(24-b->endbit);
  94852. if(bits>32 && b->endbit){
  94853. ret|=b->ptr[4]<<(32-b->endbit);
  94854. }
  94855. }
  94856. }
  94857. }
  94858. ret&=m;
  94859. overflow:
  94860. b->ptr+=bits/8;
  94861. b->endbyte+=bits/8;
  94862. b->endbit=bits&7;
  94863. return(ret);
  94864. }
  94865. long oggpackB_read(oggpack_buffer *b,int bits){
  94866. long ret;
  94867. long m=32-bits;
  94868. bits+=b->endbit;
  94869. if(b->endbyte+4>=b->storage){
  94870. ret=-1L;
  94871. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  94872. }
  94873. ret=b->ptr[0]<<(24+b->endbit);
  94874. if(bits>8){
  94875. ret|=b->ptr[1]<<(16+b->endbit);
  94876. if(bits>16){
  94877. ret|=b->ptr[2]<<(8+b->endbit);
  94878. if(bits>24){
  94879. ret|=b->ptr[3]<<(b->endbit);
  94880. if(bits>32 && b->endbit)
  94881. ret|=b->ptr[4]>>(8-b->endbit);
  94882. }
  94883. }
  94884. }
  94885. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  94886. overflow:
  94887. b->ptr+=bits/8;
  94888. b->endbyte+=bits/8;
  94889. b->endbit=bits&7;
  94890. return(ret);
  94891. }
  94892. long oggpack_read1(oggpack_buffer *b){
  94893. long ret;
  94894. if(b->endbyte>=b->storage){
  94895. ret=-1L;
  94896. goto overflow;
  94897. }
  94898. ret=(b->ptr[0]>>b->endbit)&1;
  94899. overflow:
  94900. b->endbit++;
  94901. if(b->endbit>7){
  94902. b->endbit=0;
  94903. b->ptr++;
  94904. b->endbyte++;
  94905. }
  94906. return(ret);
  94907. }
  94908. long oggpackB_read1(oggpack_buffer *b){
  94909. long ret;
  94910. if(b->endbyte>=b->storage){
  94911. ret=-1L;
  94912. goto overflow;
  94913. }
  94914. ret=(b->ptr[0]>>(7-b->endbit))&1;
  94915. overflow:
  94916. b->endbit++;
  94917. if(b->endbit>7){
  94918. b->endbit=0;
  94919. b->ptr++;
  94920. b->endbyte++;
  94921. }
  94922. return(ret);
  94923. }
  94924. long oggpack_bytes(oggpack_buffer *b){
  94925. return(b->endbyte+(b->endbit+7)/8);
  94926. }
  94927. long oggpack_bits(oggpack_buffer *b){
  94928. return(b->endbyte*8+b->endbit);
  94929. }
  94930. long oggpackB_bytes(oggpack_buffer *b){
  94931. return oggpack_bytes(b);
  94932. }
  94933. long oggpackB_bits(oggpack_buffer *b){
  94934. return oggpack_bits(b);
  94935. }
  94936. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  94937. return(b->buffer);
  94938. }
  94939. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  94940. return oggpack_get_buffer(b);
  94941. }
  94942. #ifdef _V_SELFTEST
  94943. #include <stdio.h>
  94944. static int ilog(unsigned int v){
  94945. int ret=0;
  94946. while(v){
  94947. ret++;
  94948. v>>=1;
  94949. }
  94950. return(ret);
  94951. }
  94952. oggpack_buffer o;
  94953. oggpack_buffer r;
  94954. void report(char *in){
  94955. fprintf(stderr,"%s",in);
  94956. exit(1);
  94957. }
  94958. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  94959. long bytes,i;
  94960. unsigned char *buffer;
  94961. oggpack_reset(&o);
  94962. for(i=0;i<vals;i++)
  94963. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  94964. buffer=oggpack_get_buffer(&o);
  94965. bytes=oggpack_bytes(&o);
  94966. if(bytes!=compsize)report("wrong number of bytes!\n");
  94967. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  94968. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  94969. report("wrote incorrect value!\n");
  94970. }
  94971. oggpack_readinit(&r,buffer,bytes);
  94972. for(i=0;i<vals;i++){
  94973. int tbit=bits?bits:ilog(b[i]);
  94974. if(oggpack_look(&r,tbit)==-1)
  94975. report("out of data!\n");
  94976. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  94977. report("looked at incorrect value!\n");
  94978. if(tbit==1)
  94979. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  94980. report("looked at single bit incorrect value!\n");
  94981. if(tbit==1){
  94982. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  94983. report("read incorrect single bit value!\n");
  94984. }else{
  94985. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  94986. report("read incorrect value!\n");
  94987. }
  94988. }
  94989. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  94990. }
  94991. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  94992. long bytes,i;
  94993. unsigned char *buffer;
  94994. oggpackB_reset(&o);
  94995. for(i=0;i<vals;i++)
  94996. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  94997. buffer=oggpackB_get_buffer(&o);
  94998. bytes=oggpackB_bytes(&o);
  94999. if(bytes!=compsize)report("wrong number of bytes!\n");
  95000. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95001. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95002. report("wrote incorrect value!\n");
  95003. }
  95004. oggpackB_readinit(&r,buffer,bytes);
  95005. for(i=0;i<vals;i++){
  95006. int tbit=bits?bits:ilog(b[i]);
  95007. if(oggpackB_look(&r,tbit)==-1)
  95008. report("out of data!\n");
  95009. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95010. report("looked at incorrect value!\n");
  95011. if(tbit==1)
  95012. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95013. report("looked at single bit incorrect value!\n");
  95014. if(tbit==1){
  95015. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95016. report("read incorrect single bit value!\n");
  95017. }else{
  95018. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95019. report("read incorrect value!\n");
  95020. }
  95021. }
  95022. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95023. }
  95024. int main(void){
  95025. unsigned char *buffer;
  95026. long bytes,i;
  95027. static unsigned long testbuffer1[]=
  95028. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95029. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95030. int test1size=43;
  95031. static unsigned long testbuffer2[]=
  95032. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95033. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95034. 85525151,0,12321,1,349528352};
  95035. int test2size=21;
  95036. static unsigned long testbuffer3[]=
  95037. {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,
  95038. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95039. int test3size=56;
  95040. static unsigned long large[]=
  95041. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95042. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95043. 85525151,0,12321,1,2146528352};
  95044. int onesize=33;
  95045. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95046. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95047. 223,4};
  95048. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95049. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95050. 245,251,128};
  95051. int twosize=6;
  95052. static int two[6]={61,255,255,251,231,29};
  95053. static int twoB[6]={247,63,255,253,249,120};
  95054. int threesize=54;
  95055. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95056. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95057. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95058. 100,52,4,14,18,86,77,1};
  95059. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95060. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95061. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95062. 200,20,254,4,58,106,176,144,0};
  95063. int foursize=38;
  95064. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95065. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95066. 28,2,133,0,1};
  95067. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95068. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95069. 129,10,4,32};
  95070. int fivesize=45;
  95071. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95072. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95073. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95074. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95075. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95076. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95077. int sixsize=7;
  95078. static int six[7]={17,177,170,242,169,19,148};
  95079. static int sixB[7]={136,141,85,79,149,200,41};
  95080. oggpack_writeinit(&o);
  95081. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95082. cliptest(testbuffer1,test1size,0,one,onesize);
  95083. fprintf(stderr,"ok.");
  95084. fprintf(stderr,"\nNull bit call (LSb): ");
  95085. cliptest(testbuffer3,test3size,0,two,twosize);
  95086. fprintf(stderr,"ok.");
  95087. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95088. cliptest(testbuffer2,test2size,0,three,threesize);
  95089. fprintf(stderr,"ok.");
  95090. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95091. oggpack_reset(&o);
  95092. for(i=0;i<test2size;i++)
  95093. oggpack_write(&o,large[i],32);
  95094. buffer=oggpack_get_buffer(&o);
  95095. bytes=oggpack_bytes(&o);
  95096. oggpack_readinit(&r,buffer,bytes);
  95097. for(i=0;i<test2size;i++){
  95098. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95099. if(oggpack_look(&r,32)!=large[i]){
  95100. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95101. oggpack_look(&r,32),large[i]);
  95102. report("read incorrect value!\n");
  95103. }
  95104. oggpack_adv(&r,32);
  95105. }
  95106. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95107. fprintf(stderr,"ok.");
  95108. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95109. cliptest(testbuffer1,test1size,7,four,foursize);
  95110. fprintf(stderr,"ok.");
  95111. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95112. cliptest(testbuffer2,test2size,17,five,fivesize);
  95113. fprintf(stderr,"ok.");
  95114. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95115. cliptest(testbuffer3,test3size,1,six,sixsize);
  95116. fprintf(stderr,"ok.");
  95117. fprintf(stderr,"\nTesting read past end (LSb): ");
  95118. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95119. for(i=0;i<64;i++){
  95120. if(oggpack_read(&r,1)!=0){
  95121. fprintf(stderr,"failed; got -1 prematurely.\n");
  95122. exit(1);
  95123. }
  95124. }
  95125. if(oggpack_look(&r,1)!=-1 ||
  95126. oggpack_read(&r,1)!=-1){
  95127. fprintf(stderr,"failed; read past end without -1.\n");
  95128. exit(1);
  95129. }
  95130. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95131. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95132. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95133. exit(1);
  95134. }
  95135. if(oggpack_look(&r,18)!=0 ||
  95136. oggpack_look(&r,18)!=0){
  95137. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95138. exit(1);
  95139. }
  95140. if(oggpack_look(&r,19)!=-1 ||
  95141. oggpack_look(&r,19)!=-1){
  95142. fprintf(stderr,"failed; read past end without -1.\n");
  95143. exit(1);
  95144. }
  95145. if(oggpack_look(&r,32)!=-1 ||
  95146. oggpack_look(&r,32)!=-1){
  95147. fprintf(stderr,"failed; read past end without -1.\n");
  95148. exit(1);
  95149. }
  95150. oggpack_writeclear(&o);
  95151. fprintf(stderr,"ok.\n");
  95152. oggpackB_writeinit(&o);
  95153. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95154. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95155. fprintf(stderr,"ok.");
  95156. fprintf(stderr,"\nNull bit call (MSb): ");
  95157. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95158. fprintf(stderr,"ok.");
  95159. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95160. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95161. fprintf(stderr,"ok.");
  95162. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95163. oggpackB_reset(&o);
  95164. for(i=0;i<test2size;i++)
  95165. oggpackB_write(&o,large[i],32);
  95166. buffer=oggpackB_get_buffer(&o);
  95167. bytes=oggpackB_bytes(&o);
  95168. oggpackB_readinit(&r,buffer,bytes);
  95169. for(i=0;i<test2size;i++){
  95170. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95171. if(oggpackB_look(&r,32)!=large[i]){
  95172. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95173. oggpackB_look(&r,32),large[i]);
  95174. report("read incorrect value!\n");
  95175. }
  95176. oggpackB_adv(&r,32);
  95177. }
  95178. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95179. fprintf(stderr,"ok.");
  95180. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95181. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95182. fprintf(stderr,"ok.");
  95183. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95184. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95185. fprintf(stderr,"ok.");
  95186. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95187. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95188. fprintf(stderr,"ok.");
  95189. fprintf(stderr,"\nTesting read past end (MSb): ");
  95190. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95191. for(i=0;i<64;i++){
  95192. if(oggpackB_read(&r,1)!=0){
  95193. fprintf(stderr,"failed; got -1 prematurely.\n");
  95194. exit(1);
  95195. }
  95196. }
  95197. if(oggpackB_look(&r,1)!=-1 ||
  95198. oggpackB_read(&r,1)!=-1){
  95199. fprintf(stderr,"failed; read past end without -1.\n");
  95200. exit(1);
  95201. }
  95202. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95203. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95204. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95205. exit(1);
  95206. }
  95207. if(oggpackB_look(&r,18)!=0 ||
  95208. oggpackB_look(&r,18)!=0){
  95209. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95210. exit(1);
  95211. }
  95212. if(oggpackB_look(&r,19)!=-1 ||
  95213. oggpackB_look(&r,19)!=-1){
  95214. fprintf(stderr,"failed; read past end without -1.\n");
  95215. exit(1);
  95216. }
  95217. if(oggpackB_look(&r,32)!=-1 ||
  95218. oggpackB_look(&r,32)!=-1){
  95219. fprintf(stderr,"failed; read past end without -1.\n");
  95220. exit(1);
  95221. }
  95222. oggpackB_writeclear(&o);
  95223. fprintf(stderr,"ok.\n\n");
  95224. return(0);
  95225. }
  95226. #endif /* _V_SELFTEST */
  95227. #undef BUFFER_INCREMENT
  95228. #endif
  95229. /*** End of inlined file: bitwise.c ***/
  95230. /*** Start of inlined file: framing.c ***/
  95231. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95232. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95233. // tasks..
  95234. #if JUCE_MSVC
  95235. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95236. #endif
  95237. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95238. #if JUCE_USE_OGGVORBIS
  95239. #include <stdlib.h>
  95240. #include <string.h>
  95241. int ogg_page_version(ogg_page *og){
  95242. return((int)(og->header[4]));
  95243. }
  95244. int ogg_page_continued(ogg_page *og){
  95245. return((int)(og->header[5]&0x01));
  95246. }
  95247. int ogg_page_bos(ogg_page *og){
  95248. return((int)(og->header[5]&0x02));
  95249. }
  95250. int ogg_page_eos(ogg_page *og){
  95251. return((int)(og->header[5]&0x04));
  95252. }
  95253. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95254. unsigned char *page=og->header;
  95255. ogg_int64_t granulepos=page[13]&(0xff);
  95256. granulepos= (granulepos<<8)|(page[12]&0xff);
  95257. granulepos= (granulepos<<8)|(page[11]&0xff);
  95258. granulepos= (granulepos<<8)|(page[10]&0xff);
  95259. granulepos= (granulepos<<8)|(page[9]&0xff);
  95260. granulepos= (granulepos<<8)|(page[8]&0xff);
  95261. granulepos= (granulepos<<8)|(page[7]&0xff);
  95262. granulepos= (granulepos<<8)|(page[6]&0xff);
  95263. return(granulepos);
  95264. }
  95265. int ogg_page_serialno(ogg_page *og){
  95266. return(og->header[14] |
  95267. (og->header[15]<<8) |
  95268. (og->header[16]<<16) |
  95269. (og->header[17]<<24));
  95270. }
  95271. long ogg_page_pageno(ogg_page *og){
  95272. return(og->header[18] |
  95273. (og->header[19]<<8) |
  95274. (og->header[20]<<16) |
  95275. (og->header[21]<<24));
  95276. }
  95277. int ogg_page_packets(ogg_page *og){
  95278. int i,n=og->header[26],count=0;
  95279. for(i=0;i<n;i++)
  95280. if(og->header[27+i]<255)count++;
  95281. return(count);
  95282. }
  95283. #if 0
  95284. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95285. int i;
  95286. unsigned long r;
  95287. r = index << 24;
  95288. for (i=0; i<8; i++)
  95289. if (r & 0x80000000UL)
  95290. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95291. polynomial, although we use an
  95292. unreflected alg and an init/final
  95293. of 0, not 0xffffffff */
  95294. else
  95295. r<<=1;
  95296. return (r & 0xffffffffUL);
  95297. }
  95298. #endif
  95299. static const ogg_uint32_t crc_lookup[256]={
  95300. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95301. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95302. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95303. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95304. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95305. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95306. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95307. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95308. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95309. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95310. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95311. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95312. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95313. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95314. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95315. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95316. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95317. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95318. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95319. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95320. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95321. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95322. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95323. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95324. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95325. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95326. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95327. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95328. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95329. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95330. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95331. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95332. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95333. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95334. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95335. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95336. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95337. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95338. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95339. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95340. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95341. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95342. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95343. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95344. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95345. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95346. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95347. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95348. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95349. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95350. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95351. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95352. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95353. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95354. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95355. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95356. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95357. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95358. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95359. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95360. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95361. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95362. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95363. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95364. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95365. if(os){
  95366. memset(os,0,sizeof(*os));
  95367. os->body_storage=16*1024;
  95368. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95369. os->lacing_storage=1024;
  95370. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95371. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95372. os->serialno=serialno;
  95373. return(0);
  95374. }
  95375. return(-1);
  95376. }
  95377. int ogg_stream_clear(ogg_stream_state *os){
  95378. if(os){
  95379. if(os->body_data)_ogg_free(os->body_data);
  95380. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95381. if(os->granule_vals)_ogg_free(os->granule_vals);
  95382. memset(os,0,sizeof(*os));
  95383. }
  95384. return(0);
  95385. }
  95386. int ogg_stream_destroy(ogg_stream_state *os){
  95387. if(os){
  95388. ogg_stream_clear(os);
  95389. _ogg_free(os);
  95390. }
  95391. return(0);
  95392. }
  95393. static void _os_body_expand(ogg_stream_state *os,int needed){
  95394. if(os->body_storage<=os->body_fill+needed){
  95395. os->body_storage+=(needed+1024);
  95396. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95397. }
  95398. }
  95399. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95400. if(os->lacing_storage<=os->lacing_fill+needed){
  95401. os->lacing_storage+=(needed+32);
  95402. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95403. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95404. }
  95405. }
  95406. void ogg_page_checksum_set(ogg_page *og){
  95407. if(og){
  95408. ogg_uint32_t crc_reg=0;
  95409. int i;
  95410. og->header[22]=0;
  95411. og->header[23]=0;
  95412. og->header[24]=0;
  95413. og->header[25]=0;
  95414. for(i=0;i<og->header_len;i++)
  95415. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95416. for(i=0;i<og->body_len;i++)
  95417. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95418. og->header[22]=(unsigned char)(crc_reg&0xff);
  95419. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95420. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95421. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95422. }
  95423. }
  95424. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95425. int lacing_vals=op->bytes/255+1,i;
  95426. if(os->body_returned){
  95427. os->body_fill-=os->body_returned;
  95428. if(os->body_fill)
  95429. memmove(os->body_data,os->body_data+os->body_returned,
  95430. os->body_fill);
  95431. os->body_returned=0;
  95432. }
  95433. _os_body_expand(os,op->bytes);
  95434. _os_lacing_expand(os,lacing_vals);
  95435. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95436. os->body_fill+=op->bytes;
  95437. for(i=0;i<lacing_vals-1;i++){
  95438. os->lacing_vals[os->lacing_fill+i]=255;
  95439. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95440. }
  95441. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95442. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95443. os->lacing_vals[os->lacing_fill]|= 0x100;
  95444. os->lacing_fill+=lacing_vals;
  95445. os->packetno++;
  95446. if(op->e_o_s)os->e_o_s=1;
  95447. return(0);
  95448. }
  95449. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95450. int i;
  95451. int vals=0;
  95452. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95453. int bytes=0;
  95454. long acc=0;
  95455. ogg_int64_t granule_pos=-1;
  95456. if(maxvals==0)return(0);
  95457. if(os->b_o_s==0){ /* 'initial header page' case */
  95458. granule_pos=0;
  95459. for(vals=0;vals<maxvals;vals++){
  95460. if((os->lacing_vals[vals]&0x0ff)<255){
  95461. vals++;
  95462. break;
  95463. }
  95464. }
  95465. }else{
  95466. for(vals=0;vals<maxvals;vals++){
  95467. if(acc>4096)break;
  95468. acc+=os->lacing_vals[vals]&0x0ff;
  95469. if((os->lacing_vals[vals]&0xff)<255)
  95470. granule_pos=os->granule_vals[vals];
  95471. }
  95472. }
  95473. memcpy(os->header,"OggS",4);
  95474. os->header[4]=0x00;
  95475. os->header[5]=0x00;
  95476. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95477. if(os->b_o_s==0)os->header[5]|=0x02;
  95478. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95479. os->b_o_s=1;
  95480. for(i=6;i<14;i++){
  95481. os->header[i]=(unsigned char)(granule_pos&0xff);
  95482. granule_pos>>=8;
  95483. }
  95484. {
  95485. long serialno=os->serialno;
  95486. for(i=14;i<18;i++){
  95487. os->header[i]=(unsigned char)(serialno&0xff);
  95488. serialno>>=8;
  95489. }
  95490. }
  95491. if(os->pageno==-1)os->pageno=0; /* because someone called
  95492. stream_reset; this would be a
  95493. strange thing to do in an
  95494. encode stream, but it has
  95495. plausible uses */
  95496. {
  95497. long pageno=os->pageno++;
  95498. for(i=18;i<22;i++){
  95499. os->header[i]=(unsigned char)(pageno&0xff);
  95500. pageno>>=8;
  95501. }
  95502. }
  95503. os->header[22]=0;
  95504. os->header[23]=0;
  95505. os->header[24]=0;
  95506. os->header[25]=0;
  95507. os->header[26]=(unsigned char)(vals&0xff);
  95508. for(i=0;i<vals;i++)
  95509. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  95510. og->header=os->header;
  95511. og->header_len=os->header_fill=vals+27;
  95512. og->body=os->body_data+os->body_returned;
  95513. og->body_len=bytes;
  95514. os->lacing_fill-=vals;
  95515. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  95516. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  95517. os->body_returned+=bytes;
  95518. ogg_page_checksum_set(og);
  95519. return(1);
  95520. }
  95521. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  95522. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  95523. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  95524. os->lacing_fill>=255 || /* 'segment table full' case */
  95525. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  95526. return(ogg_stream_flush(os,og));
  95527. }
  95528. return(0);
  95529. }
  95530. int ogg_stream_eos(ogg_stream_state *os){
  95531. return os->e_o_s;
  95532. }
  95533. int ogg_sync_init(ogg_sync_state *oy){
  95534. if(oy){
  95535. memset(oy,0,sizeof(*oy));
  95536. }
  95537. return(0);
  95538. }
  95539. int ogg_sync_clear(ogg_sync_state *oy){
  95540. if(oy){
  95541. if(oy->data)_ogg_free(oy->data);
  95542. ogg_sync_init(oy);
  95543. }
  95544. return(0);
  95545. }
  95546. int ogg_sync_destroy(ogg_sync_state *oy){
  95547. if(oy){
  95548. ogg_sync_clear(oy);
  95549. _ogg_free(oy);
  95550. }
  95551. return(0);
  95552. }
  95553. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  95554. if(oy->returned){
  95555. oy->fill-=oy->returned;
  95556. if(oy->fill>0)
  95557. memmove(oy->data,oy->data+oy->returned,oy->fill);
  95558. oy->returned=0;
  95559. }
  95560. if(size>oy->storage-oy->fill){
  95561. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  95562. if(oy->data)
  95563. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  95564. else
  95565. oy->data=(unsigned char*) _ogg_malloc(newsize);
  95566. oy->storage=newsize;
  95567. }
  95568. return((char *)oy->data+oy->fill);
  95569. }
  95570. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  95571. if(oy->fill+bytes>oy->storage)return(-1);
  95572. oy->fill+=bytes;
  95573. return(0);
  95574. }
  95575. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  95576. unsigned char *page=oy->data+oy->returned;
  95577. unsigned char *next;
  95578. long bytes=oy->fill-oy->returned;
  95579. if(oy->headerbytes==0){
  95580. int headerbytes,i;
  95581. if(bytes<27)return(0); /* not enough for a header */
  95582. if(memcmp(page,"OggS",4))goto sync_fail;
  95583. headerbytes=page[26]+27;
  95584. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  95585. for(i=0;i<page[26];i++)
  95586. oy->bodybytes+=page[27+i];
  95587. oy->headerbytes=headerbytes;
  95588. }
  95589. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  95590. {
  95591. char chksum[4];
  95592. ogg_page log;
  95593. memcpy(chksum,page+22,4);
  95594. memset(page+22,0,4);
  95595. log.header=page;
  95596. log.header_len=oy->headerbytes;
  95597. log.body=page+oy->headerbytes;
  95598. log.body_len=oy->bodybytes;
  95599. ogg_page_checksum_set(&log);
  95600. if(memcmp(chksum,page+22,4)){
  95601. memcpy(page+22,chksum,4);
  95602. goto sync_fail;
  95603. }
  95604. }
  95605. {
  95606. unsigned char *page=oy->data+oy->returned;
  95607. long bytes;
  95608. if(og){
  95609. og->header=page;
  95610. og->header_len=oy->headerbytes;
  95611. og->body=page+oy->headerbytes;
  95612. og->body_len=oy->bodybytes;
  95613. }
  95614. oy->unsynced=0;
  95615. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  95616. oy->headerbytes=0;
  95617. oy->bodybytes=0;
  95618. return(bytes);
  95619. }
  95620. sync_fail:
  95621. oy->headerbytes=0;
  95622. oy->bodybytes=0;
  95623. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  95624. if(!next)
  95625. next=oy->data+oy->fill;
  95626. oy->returned=next-oy->data;
  95627. return(-(next-page));
  95628. }
  95629. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  95630. for(;;){
  95631. long ret=ogg_sync_pageseek(oy,og);
  95632. if(ret>0){
  95633. return(1);
  95634. }
  95635. if(ret==0){
  95636. return(0);
  95637. }
  95638. if(!oy->unsynced){
  95639. oy->unsynced=1;
  95640. return(-1);
  95641. }
  95642. }
  95643. }
  95644. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  95645. unsigned char *header=og->header;
  95646. unsigned char *body=og->body;
  95647. long bodysize=og->body_len;
  95648. int segptr=0;
  95649. int version=ogg_page_version(og);
  95650. int continued=ogg_page_continued(og);
  95651. int bos=ogg_page_bos(og);
  95652. int eos=ogg_page_eos(og);
  95653. ogg_int64_t granulepos=ogg_page_granulepos(og);
  95654. int serialno=ogg_page_serialno(og);
  95655. long pageno=ogg_page_pageno(og);
  95656. int segments=header[26];
  95657. {
  95658. long lr=os->lacing_returned;
  95659. long br=os->body_returned;
  95660. if(br){
  95661. os->body_fill-=br;
  95662. if(os->body_fill)
  95663. memmove(os->body_data,os->body_data+br,os->body_fill);
  95664. os->body_returned=0;
  95665. }
  95666. if(lr){
  95667. if(os->lacing_fill-lr){
  95668. memmove(os->lacing_vals,os->lacing_vals+lr,
  95669. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  95670. memmove(os->granule_vals,os->granule_vals+lr,
  95671. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  95672. }
  95673. os->lacing_fill-=lr;
  95674. os->lacing_packet-=lr;
  95675. os->lacing_returned=0;
  95676. }
  95677. }
  95678. if(serialno!=os->serialno)return(-1);
  95679. if(version>0)return(-1);
  95680. _os_lacing_expand(os,segments+1);
  95681. if(pageno!=os->pageno){
  95682. int i;
  95683. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  95684. os->body_fill-=os->lacing_vals[i]&0xff;
  95685. os->lacing_fill=os->lacing_packet;
  95686. if(os->pageno!=-1){
  95687. os->lacing_vals[os->lacing_fill++]=0x400;
  95688. os->lacing_packet++;
  95689. }
  95690. }
  95691. if(continued){
  95692. if(os->lacing_fill<1 ||
  95693. os->lacing_vals[os->lacing_fill-1]==0x400){
  95694. bos=0;
  95695. for(;segptr<segments;segptr++){
  95696. int val=header[27+segptr];
  95697. body+=val;
  95698. bodysize-=val;
  95699. if(val<255){
  95700. segptr++;
  95701. break;
  95702. }
  95703. }
  95704. }
  95705. }
  95706. if(bodysize){
  95707. _os_body_expand(os,bodysize);
  95708. memcpy(os->body_data+os->body_fill,body,bodysize);
  95709. os->body_fill+=bodysize;
  95710. }
  95711. {
  95712. int saved=-1;
  95713. while(segptr<segments){
  95714. int val=header[27+segptr];
  95715. os->lacing_vals[os->lacing_fill]=val;
  95716. os->granule_vals[os->lacing_fill]=-1;
  95717. if(bos){
  95718. os->lacing_vals[os->lacing_fill]|=0x100;
  95719. bos=0;
  95720. }
  95721. if(val<255)saved=os->lacing_fill;
  95722. os->lacing_fill++;
  95723. segptr++;
  95724. if(val<255)os->lacing_packet=os->lacing_fill;
  95725. }
  95726. if(saved!=-1){
  95727. os->granule_vals[saved]=granulepos;
  95728. }
  95729. }
  95730. if(eos){
  95731. os->e_o_s=1;
  95732. if(os->lacing_fill>0)
  95733. os->lacing_vals[os->lacing_fill-1]|=0x200;
  95734. }
  95735. os->pageno=pageno+1;
  95736. return(0);
  95737. }
  95738. int ogg_sync_reset(ogg_sync_state *oy){
  95739. oy->fill=0;
  95740. oy->returned=0;
  95741. oy->unsynced=0;
  95742. oy->headerbytes=0;
  95743. oy->bodybytes=0;
  95744. return(0);
  95745. }
  95746. int ogg_stream_reset(ogg_stream_state *os){
  95747. os->body_fill=0;
  95748. os->body_returned=0;
  95749. os->lacing_fill=0;
  95750. os->lacing_packet=0;
  95751. os->lacing_returned=0;
  95752. os->header_fill=0;
  95753. os->e_o_s=0;
  95754. os->b_o_s=0;
  95755. os->pageno=-1;
  95756. os->packetno=0;
  95757. os->granulepos=0;
  95758. return(0);
  95759. }
  95760. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  95761. ogg_stream_reset(os);
  95762. os->serialno=serialno;
  95763. return(0);
  95764. }
  95765. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  95766. int ptr=os->lacing_returned;
  95767. if(os->lacing_packet<=ptr)return(0);
  95768. if(os->lacing_vals[ptr]&0x400){
  95769. os->lacing_returned++;
  95770. os->packetno++;
  95771. return(-1);
  95772. }
  95773. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  95774. to ask if there's a whole packet
  95775. waiting */
  95776. {
  95777. int size=os->lacing_vals[ptr]&0xff;
  95778. int bytes=size;
  95779. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  95780. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  95781. while(size==255){
  95782. int val=os->lacing_vals[++ptr];
  95783. size=val&0xff;
  95784. if(val&0x200)eos=0x200;
  95785. bytes+=size;
  95786. }
  95787. if(op){
  95788. op->e_o_s=eos;
  95789. op->b_o_s=bos;
  95790. op->packet=os->body_data+os->body_returned;
  95791. op->packetno=os->packetno;
  95792. op->granulepos=os->granule_vals[ptr];
  95793. op->bytes=bytes;
  95794. }
  95795. if(adv){
  95796. os->body_returned+=bytes;
  95797. os->lacing_returned=ptr+1;
  95798. os->packetno++;
  95799. }
  95800. }
  95801. return(1);
  95802. }
  95803. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  95804. return _packetout(os,op,1);
  95805. }
  95806. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  95807. return _packetout(os,op,0);
  95808. }
  95809. void ogg_packet_clear(ogg_packet *op) {
  95810. _ogg_free(op->packet);
  95811. memset(op, 0, sizeof(*op));
  95812. }
  95813. #ifdef _V_SELFTEST
  95814. #include <stdio.h>
  95815. ogg_stream_state os_en, os_de;
  95816. ogg_sync_state oy;
  95817. void checkpacket(ogg_packet *op,int len, int no, int pos){
  95818. long j;
  95819. static int sequence=0;
  95820. static int lastno=0;
  95821. if(op->bytes!=len){
  95822. fprintf(stderr,"incorrect packet length!\n");
  95823. exit(1);
  95824. }
  95825. if(op->granulepos!=pos){
  95826. fprintf(stderr,"incorrect packet position!\n");
  95827. exit(1);
  95828. }
  95829. if(no==0){
  95830. sequence=0;
  95831. }else{
  95832. sequence++;
  95833. if(no>lastno+1)
  95834. sequence++;
  95835. }
  95836. lastno=no;
  95837. if(op->packetno!=sequence){
  95838. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  95839. (long)(op->packetno),sequence);
  95840. exit(1);
  95841. }
  95842. for(j=0;j<op->bytes;j++)
  95843. if(op->packet[j]!=((j+no)&0xff)){
  95844. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  95845. j,op->packet[j],(j+no)&0xff);
  95846. exit(1);
  95847. }
  95848. }
  95849. void check_page(unsigned char *data,const int *header,ogg_page *og){
  95850. long j;
  95851. for(j=0;j<og->body_len;j++)
  95852. if(og->body[j]!=data[j]){
  95853. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  95854. j,data[j],og->body[j]);
  95855. exit(1);
  95856. }
  95857. for(j=0;j<og->header_len;j++){
  95858. if(og->header[j]!=header[j]){
  95859. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  95860. for(j=0;j<header[26]+27;j++)
  95861. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  95862. fprintf(stderr,"\n");
  95863. exit(1);
  95864. }
  95865. }
  95866. if(og->header_len!=header[26]+27){
  95867. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  95868. og->header_len,header[26]+27);
  95869. exit(1);
  95870. }
  95871. }
  95872. void print_header(ogg_page *og){
  95873. int j;
  95874. fprintf(stderr,"\nHEADER:\n");
  95875. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  95876. og->header[0],og->header[1],og->header[2],og->header[3],
  95877. (int)og->header[4],(int)og->header[5]);
  95878. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  95879. (og->header[9]<<24)|(og->header[8]<<16)|
  95880. (og->header[7]<<8)|og->header[6],
  95881. (og->header[17]<<24)|(og->header[16]<<16)|
  95882. (og->header[15]<<8)|og->header[14],
  95883. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  95884. (og->header[19]<<8)|og->header[18]);
  95885. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  95886. (int)og->header[22],(int)og->header[23],
  95887. (int)og->header[24],(int)og->header[25],
  95888. (int)og->header[26]);
  95889. for(j=27;j<og->header_len;j++)
  95890. fprintf(stderr,"%d ",(int)og->header[j]);
  95891. fprintf(stderr,")\n\n");
  95892. }
  95893. void copy_page(ogg_page *og){
  95894. unsigned char *temp=_ogg_malloc(og->header_len);
  95895. memcpy(temp,og->header,og->header_len);
  95896. og->header=temp;
  95897. temp=_ogg_malloc(og->body_len);
  95898. memcpy(temp,og->body,og->body_len);
  95899. og->body=temp;
  95900. }
  95901. void free_page(ogg_page *og){
  95902. _ogg_free (og->header);
  95903. _ogg_free (og->body);
  95904. }
  95905. void error(void){
  95906. fprintf(stderr,"error!\n");
  95907. exit(1);
  95908. }
  95909. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  95910. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95911. 0x01,0x02,0x03,0x04,0,0,0,0,
  95912. 0x15,0xed,0xec,0x91,
  95913. 1,
  95914. 17};
  95915. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95916. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95917. 0x01,0x02,0x03,0x04,0,0,0,0,
  95918. 0x59,0x10,0x6c,0x2c,
  95919. 1,
  95920. 17};
  95921. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95922. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  95923. 0x01,0x02,0x03,0x04,1,0,0,0,
  95924. 0x89,0x33,0x85,0xce,
  95925. 13,
  95926. 254,255,0,255,1,255,245,255,255,0,
  95927. 255,255,90};
  95928. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95929. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95930. 0x01,0x02,0x03,0x04,0,0,0,0,
  95931. 0xff,0x7b,0x23,0x17,
  95932. 1,
  95933. 0};
  95934. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95935. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  95936. 0x01,0x02,0x03,0x04,1,0,0,0,
  95937. 0x5c,0x3f,0x66,0xcb,
  95938. 17,
  95939. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  95940. 255,255,90,0};
  95941. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95942. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95943. 0x01,0x02,0x03,0x04,0,0,0,0,
  95944. 0x01,0x27,0x31,0xaa,
  95945. 18,
  95946. 255,255,255,255,255,255,255,255,
  95947. 255,255,255,255,255,255,255,255,255,10};
  95948. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  95949. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  95950. 0x01,0x02,0x03,0x04,1,0,0,0,
  95951. 0x7f,0x4e,0x8a,0xd2,
  95952. 4,
  95953. 255,4,255,0};
  95954. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95955. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95956. 0x01,0x02,0x03,0x04,0,0,0,0,
  95957. 0xff,0x7b,0x23,0x17,
  95958. 1,
  95959. 0};
  95960. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95961. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  95962. 0x01,0x02,0x03,0x04,1,0,0,0,
  95963. 0x54,0x05,0x51,0xc8,
  95964. 17,
  95965. 255,255,255,255,255,255,255,255,
  95966. 255,255,255,255,255,255,255,255,255};
  95967. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  95968. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  95969. 0x01,0x02,0x03,0x04,2,0,0,0,
  95970. 0xc8,0xc3,0xcb,0xed,
  95971. 5,
  95972. 10,255,4,255,0};
  95973. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  95974. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  95975. 0x01,0x02,0x03,0x04,0,0,0,0,
  95976. 0xff,0x7b,0x23,0x17,
  95977. 1,
  95978. 0};
  95979. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  95980. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  95981. 0x01,0x02,0x03,0x04,1,0,0,0,
  95982. 0xed,0x2a,0x2e,0xa7,
  95983. 255,
  95984. 10,10,10,10,10,10,10,10,
  95985. 10,10,10,10,10,10,10,10,
  95986. 10,10,10,10,10,10,10,10,
  95987. 10,10,10,10,10,10,10,10,
  95988. 10,10,10,10,10,10,10,10,
  95989. 10,10,10,10,10,10,10,10,
  95990. 10,10,10,10,10,10,10,10,
  95991. 10,10,10,10,10,10,10,10,
  95992. 10,10,10,10,10,10,10,10,
  95993. 10,10,10,10,10,10,10,10,
  95994. 10,10,10,10,10,10,10,10,
  95995. 10,10,10,10,10,10,10,10,
  95996. 10,10,10,10,10,10,10,10,
  95997. 10,10,10,10,10,10,10,10,
  95998. 10,10,10,10,10,10,10,10,
  95999. 10,10,10,10,10,10,10,10,
  96000. 10,10,10,10,10,10,10,10,
  96001. 10,10,10,10,10,10,10,10,
  96002. 10,10,10,10,10,10,10,10,
  96003. 10,10,10,10,10,10,10,10,
  96004. 10,10,10,10,10,10,10,10,
  96005. 10,10,10,10,10,10,10,10,
  96006. 10,10,10,10,10,10,10,10,
  96007. 10,10,10,10,10,10,10,10,
  96008. 10,10,10,10,10,10,10,10,
  96009. 10,10,10,10,10,10,10,10,
  96010. 10,10,10,10,10,10,10,10,
  96011. 10,10,10,10,10,10,10,10,
  96012. 10,10,10,10,10,10,10,10,
  96013. 10,10,10,10,10,10,10,10,
  96014. 10,10,10,10,10,10,10,10,
  96015. 10,10,10,10,10,10,10};
  96016. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96017. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96018. 0x01,0x02,0x03,0x04,2,0,0,0,
  96019. 0x6c,0x3b,0x82,0x3d,
  96020. 1,
  96021. 50};
  96022. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96023. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96024. 0x01,0x02,0x03,0x04,0,0,0,0,
  96025. 0xff,0x7b,0x23,0x17,
  96026. 1,
  96027. 0};
  96028. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96029. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96030. 0x01,0x02,0x03,0x04,1,0,0,0,
  96031. 0x3c,0xd9,0x4d,0x3f,
  96032. 17,
  96033. 100,255,255,255,255,255,255,255,255,
  96034. 255,255,255,255,255,255,255,255};
  96035. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96036. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96037. 0x01,0x02,0x03,0x04,2,0,0,0,
  96038. 0x01,0xd2,0xe5,0xe5,
  96039. 17,
  96040. 255,255,255,255,255,255,255,255,
  96041. 255,255,255,255,255,255,255,255,255};
  96042. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96043. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96044. 0x01,0x02,0x03,0x04,3,0,0,0,
  96045. 0xef,0xdd,0x88,0xde,
  96046. 7,
  96047. 255,255,75,255,4,255,0};
  96048. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96049. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96050. 0x01,0x02,0x03,0x04,0,0,0,0,
  96051. 0xff,0x7b,0x23,0x17,
  96052. 1,
  96053. 0};
  96054. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96055. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96056. 0x01,0x02,0x03,0x04,1,0,0,0,
  96057. 0x3c,0xd9,0x4d,0x3f,
  96058. 17,
  96059. 100,255,255,255,255,255,255,255,255,
  96060. 255,255,255,255,255,255,255,255};
  96061. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96062. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96063. 0x01,0x02,0x03,0x04,2,0,0,0,
  96064. 0xd4,0xe0,0x60,0xe5,
  96065. 1,0};
  96066. void test_pack(const int *pl, const int **headers, int byteskip,
  96067. int pageskip, int packetskip){
  96068. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96069. long inptr=0;
  96070. long outptr=0;
  96071. long deptr=0;
  96072. long depacket=0;
  96073. long granule_pos=7,pageno=0;
  96074. int i,j,packets,pageout=pageskip;
  96075. int eosflag=0;
  96076. int bosflag=0;
  96077. int byteskipcount=0;
  96078. ogg_stream_reset(&os_en);
  96079. ogg_stream_reset(&os_de);
  96080. ogg_sync_reset(&oy);
  96081. for(packets=0;packets<packetskip;packets++)
  96082. depacket+=pl[packets];
  96083. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96084. for(i=0;i<packets;i++){
  96085. ogg_packet op;
  96086. int len=pl[i];
  96087. op.packet=data+inptr;
  96088. op.bytes=len;
  96089. op.e_o_s=(pl[i+1]<0?1:0);
  96090. op.granulepos=granule_pos;
  96091. granule_pos+=1024;
  96092. for(j=0;j<len;j++)data[inptr++]=i+j;
  96093. ogg_stream_packetin(&os_en,&op);
  96094. {
  96095. ogg_page og;
  96096. while(ogg_stream_pageout(&os_en,&og)){
  96097. fprintf(stderr,"%ld, ",pageno);
  96098. if(headers[pageno]==NULL){
  96099. fprintf(stderr,"coded too many pages!\n");
  96100. exit(1);
  96101. }
  96102. check_page(data+outptr,headers[pageno],&og);
  96103. outptr+=og.body_len;
  96104. pageno++;
  96105. if(pageskip){
  96106. bosflag=1;
  96107. pageskip--;
  96108. deptr+=og.body_len;
  96109. }
  96110. {
  96111. ogg_page og_de;
  96112. ogg_packet op_de,op_de2;
  96113. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96114. char *next=buf;
  96115. byteskipcount+=og.header_len;
  96116. if(byteskipcount>byteskip){
  96117. memcpy(next,og.header,byteskipcount-byteskip);
  96118. next+=byteskipcount-byteskip;
  96119. byteskipcount=byteskip;
  96120. }
  96121. byteskipcount+=og.body_len;
  96122. if(byteskipcount>byteskip){
  96123. memcpy(next,og.body,byteskipcount-byteskip);
  96124. next+=byteskipcount-byteskip;
  96125. byteskipcount=byteskip;
  96126. }
  96127. ogg_sync_wrote(&oy,next-buf);
  96128. while(1){
  96129. int ret=ogg_sync_pageout(&oy,&og_de);
  96130. if(ret==0)break;
  96131. if(ret<0)continue;
  96132. fprintf(stderr,"(%ld), ",pageout);
  96133. check_page(data+deptr,headers[pageout],&og_de);
  96134. deptr+=og_de.body_len;
  96135. pageout++;
  96136. ogg_stream_pagein(&os_de,&og_de);
  96137. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96138. ogg_stream_packetpeek(&os_de,NULL);
  96139. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96140. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96141. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96142. depacket);
  96143. exit(1);
  96144. }
  96145. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96146. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96147. depacket);
  96148. exit(1);
  96149. }
  96150. if(bosflag==0 && op_de.b_o_s==0){
  96151. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96152. exit(1);
  96153. }
  96154. if(bosflag && op_de.b_o_s){
  96155. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96156. exit(1);
  96157. }
  96158. bosflag=1;
  96159. depacket+=op_de.bytes;
  96160. if(eosflag){
  96161. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96162. exit(1);
  96163. }
  96164. if(op_de.e_o_s)eosflag=1;
  96165. if(op_de.granulepos!=-1){
  96166. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96167. }
  96168. }
  96169. }
  96170. }
  96171. }
  96172. }
  96173. }
  96174. _ogg_free(data);
  96175. if(headers[pageno]!=NULL){
  96176. fprintf(stderr,"did not write last page!\n");
  96177. exit(1);
  96178. }
  96179. if(headers[pageout]!=NULL){
  96180. fprintf(stderr,"did not decode last page!\n");
  96181. exit(1);
  96182. }
  96183. if(inptr!=outptr){
  96184. fprintf(stderr,"encoded page data incomplete!\n");
  96185. exit(1);
  96186. }
  96187. if(inptr!=deptr){
  96188. fprintf(stderr,"decoded page data incomplete!\n");
  96189. exit(1);
  96190. }
  96191. if(inptr!=depacket){
  96192. fprintf(stderr,"decoded packet data incomplete!\n");
  96193. exit(1);
  96194. }
  96195. if(!eosflag){
  96196. fprintf(stderr,"Never got a packet with EOS set!\n");
  96197. exit(1);
  96198. }
  96199. fprintf(stderr,"ok.\n");
  96200. }
  96201. int main(void){
  96202. ogg_stream_init(&os_en,0x04030201);
  96203. ogg_stream_init(&os_de,0x04030201);
  96204. ogg_sync_init(&oy);
  96205. {
  96206. const int packets[]={17, -1};
  96207. const int *headret[]={head1_0,NULL};
  96208. fprintf(stderr,"testing single page encoding... ");
  96209. test_pack(packets,headret,0,0,0);
  96210. }
  96211. {
  96212. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96213. const int *headret[]={head1_1,head2_1,NULL};
  96214. fprintf(stderr,"testing basic page encoding... ");
  96215. test_pack(packets,headret,0,0,0);
  96216. }
  96217. {
  96218. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96219. const int *headret[]={head1_2,head2_2,NULL};
  96220. fprintf(stderr,"testing basic nil packets... ");
  96221. test_pack(packets,headret,0,0,0);
  96222. }
  96223. {
  96224. const int packets[]={4345,259,255,-1};
  96225. const int *headret[]={head1_3,head2_3,NULL};
  96226. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96227. test_pack(packets,headret,0,0,0);
  96228. }
  96229. {
  96230. const int packets[]={0,4345,259,255,-1};
  96231. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96232. fprintf(stderr,"testing single packet page span... ");
  96233. test_pack(packets,headret,0,0,0);
  96234. }
  96235. {
  96236. const int packets[]={0,10,10,10,10,10,10,10,10,
  96237. 10,10,10,10,10,10,10,10,
  96238. 10,10,10,10,10,10,10,10,
  96239. 10,10,10,10,10,10,10,10,
  96240. 10,10,10,10,10,10,10,10,
  96241. 10,10,10,10,10,10,10,10,
  96242. 10,10,10,10,10,10,10,10,
  96243. 10,10,10,10,10,10,10,10,
  96244. 10,10,10,10,10,10,10,10,
  96245. 10,10,10,10,10,10,10,10,
  96246. 10,10,10,10,10,10,10,10,
  96247. 10,10,10,10,10,10,10,10,
  96248. 10,10,10,10,10,10,10,10,
  96249. 10,10,10,10,10,10,10,10,
  96250. 10,10,10,10,10,10,10,10,
  96251. 10,10,10,10,10,10,10,10,
  96252. 10,10,10,10,10,10,10,10,
  96253. 10,10,10,10,10,10,10,10,
  96254. 10,10,10,10,10,10,10,10,
  96255. 10,10,10,10,10,10,10,10,
  96256. 10,10,10,10,10,10,10,10,
  96257. 10,10,10,10,10,10,10,10,
  96258. 10,10,10,10,10,10,10,10,
  96259. 10,10,10,10,10,10,10,10,
  96260. 10,10,10,10,10,10,10,10,
  96261. 10,10,10,10,10,10,10,10,
  96262. 10,10,10,10,10,10,10,10,
  96263. 10,10,10,10,10,10,10,10,
  96264. 10,10,10,10,10,10,10,10,
  96265. 10,10,10,10,10,10,10,10,
  96266. 10,10,10,10,10,10,10,10,
  96267. 10,10,10,10,10,10,10,50,-1};
  96268. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96269. fprintf(stderr,"testing max packet segments... ");
  96270. test_pack(packets,headret,0,0,0);
  96271. }
  96272. {
  96273. const int packets[]={0,100,9000,259,255,-1};
  96274. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96275. fprintf(stderr,"testing very large packets... ");
  96276. test_pack(packets,headret,0,0,0);
  96277. }
  96278. {
  96279. const int packets[]={0,100,9000,259,255,-1};
  96280. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96281. fprintf(stderr,"testing continuation resync in very large packets... ");
  96282. test_pack(packets,headret,100,2,3);
  96283. }
  96284. {
  96285. const int packets[]={0,100,4080,-1};
  96286. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96287. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96288. test_pack(packets,headret,0,0,0);
  96289. }
  96290. {
  96291. unsigned char *data=_ogg_malloc(1024*1024);
  96292. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96293. int inptr=0,i,j;
  96294. ogg_page og[5];
  96295. ogg_stream_reset(&os_en);
  96296. for(i=0;pl[i]!=-1;i++){
  96297. ogg_packet op;
  96298. int len=pl[i];
  96299. op.packet=data+inptr;
  96300. op.bytes=len;
  96301. op.e_o_s=(pl[i+1]<0?1:0);
  96302. op.granulepos=(i+1)*1000;
  96303. for(j=0;j<len;j++)data[inptr++]=i+j;
  96304. ogg_stream_packetin(&os_en,&op);
  96305. }
  96306. _ogg_free(data);
  96307. for(i=0;i<5;i++){
  96308. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96309. fprintf(stderr,"Too few pages output building sync tests!\n");
  96310. exit(1);
  96311. }
  96312. copy_page(&og[i]);
  96313. }
  96314. {
  96315. ogg_page temp;
  96316. ogg_packet test;
  96317. fprintf(stderr,"Testing loss of pages... ");
  96318. ogg_sync_reset(&oy);
  96319. ogg_stream_reset(&os_de);
  96320. for(i=0;i<5;i++){
  96321. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96322. og[i].header_len);
  96323. ogg_sync_wrote(&oy,og[i].header_len);
  96324. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96325. ogg_sync_wrote(&oy,og[i].body_len);
  96326. }
  96327. ogg_sync_pageout(&oy,&temp);
  96328. ogg_stream_pagein(&os_de,&temp);
  96329. ogg_sync_pageout(&oy,&temp);
  96330. ogg_stream_pagein(&os_de,&temp);
  96331. ogg_sync_pageout(&oy,&temp);
  96332. ogg_sync_pageout(&oy,&temp);
  96333. ogg_stream_pagein(&os_de,&temp);
  96334. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96335. checkpacket(&test,0,0,0);
  96336. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96337. checkpacket(&test,100,1,-1);
  96338. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96339. checkpacket(&test,4079,2,3000);
  96340. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96341. fprintf(stderr,"Error: loss of page did not return error\n");
  96342. exit(1);
  96343. }
  96344. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96345. checkpacket(&test,76,5,-1);
  96346. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96347. checkpacket(&test,34,6,-1);
  96348. fprintf(stderr,"ok.\n");
  96349. }
  96350. {
  96351. ogg_page temp;
  96352. ogg_packet test;
  96353. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96354. ogg_sync_reset(&oy);
  96355. ogg_stream_reset(&os_de);
  96356. for(i=0;i<5;i++){
  96357. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96358. og[i].header_len);
  96359. ogg_sync_wrote(&oy,og[i].header_len);
  96360. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96361. ogg_sync_wrote(&oy,og[i].body_len);
  96362. }
  96363. ogg_sync_pageout(&oy,&temp);
  96364. ogg_stream_pagein(&os_de,&temp);
  96365. ogg_sync_pageout(&oy,&temp);
  96366. ogg_stream_pagein(&os_de,&temp);
  96367. ogg_sync_pageout(&oy,&temp);
  96368. ogg_stream_pagein(&os_de,&temp);
  96369. ogg_sync_pageout(&oy,&temp);
  96370. ogg_sync_pageout(&oy,&temp);
  96371. ogg_stream_pagein(&os_de,&temp);
  96372. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96373. checkpacket(&test,0,0,0);
  96374. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96375. checkpacket(&test,100,1,-1);
  96376. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96377. checkpacket(&test,4079,2,3000);
  96378. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96379. checkpacket(&test,2956,3,4000);
  96380. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96381. fprintf(stderr,"Error: loss of page did not return error\n");
  96382. exit(1);
  96383. }
  96384. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96385. checkpacket(&test,300,13,14000);
  96386. fprintf(stderr,"ok.\n");
  96387. }
  96388. {
  96389. ogg_page og_de;
  96390. fprintf(stderr,"Testing sync on partial inputs... ");
  96391. ogg_sync_reset(&oy);
  96392. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96393. 3);
  96394. ogg_sync_wrote(&oy,3);
  96395. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96396. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96397. 20);
  96398. ogg_sync_wrote(&oy,20);
  96399. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96400. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96401. 5);
  96402. ogg_sync_wrote(&oy,5);
  96403. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96404. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96405. og[1].header_len-28);
  96406. ogg_sync_wrote(&oy,og[1].header_len-28);
  96407. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96408. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96409. ogg_sync_wrote(&oy,1000);
  96410. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96411. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96412. og[1].body_len-1000);
  96413. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96414. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96415. fprintf(stderr,"ok.\n");
  96416. }
  96417. {
  96418. ogg_page og_de;
  96419. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96420. ogg_sync_reset(&oy);
  96421. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96422. og[1].header_len);
  96423. ogg_sync_wrote(&oy,og[1].header_len);
  96424. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96425. og[1].body_len);
  96426. ogg_sync_wrote(&oy,og[1].body_len);
  96427. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96428. 20);
  96429. ogg_sync_wrote(&oy,20);
  96430. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96431. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96432. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96433. og[1].header_len-20);
  96434. ogg_sync_wrote(&oy,og[1].header_len-20);
  96435. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96436. og[1].body_len);
  96437. ogg_sync_wrote(&oy,og[1].body_len);
  96438. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96439. fprintf(stderr,"ok.\n");
  96440. }
  96441. {
  96442. ogg_page og_de;
  96443. fprintf(stderr,"Testing search for capture... ");
  96444. ogg_sync_reset(&oy);
  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[1].header_len),og[1].header,
  96449. og[1].header_len);
  96450. ogg_sync_wrote(&oy,og[1].header_len);
  96451. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96452. og[1].body_len);
  96453. ogg_sync_wrote(&oy,og[1].body_len);
  96454. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96455. 20);
  96456. ogg_sync_wrote(&oy,20);
  96457. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96458. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96459. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96460. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96461. og[2].header_len-20);
  96462. ogg_sync_wrote(&oy,og[2].header_len-20);
  96463. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96464. og[2].body_len);
  96465. ogg_sync_wrote(&oy,og[2].body_len);
  96466. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96467. fprintf(stderr,"ok.\n");
  96468. }
  96469. {
  96470. ogg_page og_de;
  96471. fprintf(stderr,"Testing recapture... ");
  96472. ogg_sync_reset(&oy);
  96473. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96474. og[1].header_len);
  96475. ogg_sync_wrote(&oy,og[1].header_len);
  96476. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96477. og[1].body_len);
  96478. ogg_sync_wrote(&oy,og[1].body_len);
  96479. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96480. og[2].header_len);
  96481. ogg_sync_wrote(&oy,og[2].header_len);
  96482. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96483. og[2].header_len);
  96484. ogg_sync_wrote(&oy,og[2].header_len);
  96485. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96486. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96487. og[2].body_len-5);
  96488. ogg_sync_wrote(&oy,og[2].body_len-5);
  96489. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96490. og[3].header_len);
  96491. ogg_sync_wrote(&oy,og[3].header_len);
  96492. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96493. og[3].body_len);
  96494. ogg_sync_wrote(&oy,og[3].body_len);
  96495. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96496. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96497. fprintf(stderr,"ok.\n");
  96498. }
  96499. {
  96500. for(i=0;i<5;i++){
  96501. free_page(&og[i]);
  96502. }
  96503. }
  96504. }
  96505. return(0);
  96506. }
  96507. #endif
  96508. #endif
  96509. /*** End of inlined file: framing.c ***/
  96510. /*** Start of inlined file: analysis.c ***/
  96511. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  96512. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  96513. // tasks..
  96514. #if JUCE_MSVC
  96515. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  96516. #endif
  96517. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  96518. #if JUCE_USE_OGGVORBIS
  96519. #include <stdio.h>
  96520. #include <string.h>
  96521. #include <math.h>
  96522. /*** Start of inlined file: codec_internal.h ***/
  96523. #ifndef _V_CODECI_H_
  96524. #define _V_CODECI_H_
  96525. /*** Start of inlined file: envelope.h ***/
  96526. #ifndef _V_ENVELOPE_
  96527. #define _V_ENVELOPE_
  96528. /*** Start of inlined file: mdct.h ***/
  96529. #ifndef _OGG_mdct_H_
  96530. #define _OGG_mdct_H_
  96531. #ifdef MDCT_INTEGERIZED
  96532. #define DATA_TYPE int
  96533. #define REG_TYPE register int
  96534. #define TRIGBITS 14
  96535. #define cPI3_8 6270
  96536. #define cPI2_8 11585
  96537. #define cPI1_8 15137
  96538. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  96539. #define MULT_NORM(x) ((x)>>TRIGBITS)
  96540. #define HALVE(x) ((x)>>1)
  96541. #else
  96542. #define DATA_TYPE float
  96543. #define REG_TYPE float
  96544. #define cPI3_8 .38268343236508977175F
  96545. #define cPI2_8 .70710678118654752441F
  96546. #define cPI1_8 .92387953251128675613F
  96547. #define FLOAT_CONV(x) (x)
  96548. #define MULT_NORM(x) (x)
  96549. #define HALVE(x) ((x)*.5f)
  96550. #endif
  96551. typedef struct {
  96552. int n;
  96553. int log2n;
  96554. DATA_TYPE *trig;
  96555. int *bitrev;
  96556. DATA_TYPE scale;
  96557. } mdct_lookup;
  96558. extern void mdct_init(mdct_lookup *lookup,int n);
  96559. extern void mdct_clear(mdct_lookup *l);
  96560. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96561. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  96562. #endif
  96563. /*** End of inlined file: mdct.h ***/
  96564. #define VE_PRE 16
  96565. #define VE_WIN 4
  96566. #define VE_POST 2
  96567. #define VE_AMP (VE_PRE+VE_POST-1)
  96568. #define VE_BANDS 7
  96569. #define VE_NEARDC 15
  96570. #define VE_MINSTRETCH 2 /* a bit less than short block */
  96571. #define VE_MAXSTRETCH 12 /* one-third full block */
  96572. typedef struct {
  96573. float ampbuf[VE_AMP];
  96574. int ampptr;
  96575. float nearDC[VE_NEARDC];
  96576. float nearDC_acc;
  96577. float nearDC_partialacc;
  96578. int nearptr;
  96579. } envelope_filter_state;
  96580. typedef struct {
  96581. int begin;
  96582. int end;
  96583. float *window;
  96584. float total;
  96585. } envelope_band;
  96586. typedef struct {
  96587. int ch;
  96588. int winlength;
  96589. int searchstep;
  96590. float minenergy;
  96591. mdct_lookup mdct;
  96592. float *mdct_win;
  96593. envelope_band band[VE_BANDS];
  96594. envelope_filter_state *filter;
  96595. int stretch;
  96596. int *mark;
  96597. long storage;
  96598. long current;
  96599. long curmark;
  96600. long cursor;
  96601. } envelope_lookup;
  96602. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  96603. extern void _ve_envelope_clear(envelope_lookup *e);
  96604. extern long _ve_envelope_search(vorbis_dsp_state *v);
  96605. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  96606. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  96607. #endif
  96608. /*** End of inlined file: envelope.h ***/
  96609. /*** Start of inlined file: codebook.h ***/
  96610. #ifndef _V_CODEBOOK_H_
  96611. #define _V_CODEBOOK_H_
  96612. typedef struct static_codebook{
  96613. long dim; /* codebook dimensions (elements per vector) */
  96614. long entries; /* codebook entries */
  96615. long *lengthlist; /* codeword lengths in bits */
  96616. int maptype; /* 0=none
  96617. 1=implicitly populated values from map column
  96618. 2=listed arbitrary values */
  96619. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  96620. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  96621. int q_quant; /* bits: 0 < quant <= 16 */
  96622. int q_sequencep; /* bitflag */
  96623. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  96624. map == 2: list of dim*entries quantized entry vals
  96625. */
  96626. struct encode_aux_nearestmatch *nearest_tree;
  96627. struct encode_aux_threshmatch *thresh_tree;
  96628. struct encode_aux_pigeonhole *pigeon_tree;
  96629. int allocedp;
  96630. } static_codebook;
  96631. typedef struct encode_aux_nearestmatch{
  96632. long *ptr0;
  96633. long *ptr1;
  96634. long *p; /* decision points (each is an entry) */
  96635. long *q; /* decision points (each is an entry) */
  96636. long aux; /* number of tree entries */
  96637. long alloc;
  96638. } encode_aux_nearestmatch;
  96639. typedef struct encode_aux_threshmatch{
  96640. float *quantthresh;
  96641. long *quantmap;
  96642. int quantvals;
  96643. int threshvals;
  96644. } encode_aux_threshmatch;
  96645. typedef struct encode_aux_pigeonhole{
  96646. float min;
  96647. float del;
  96648. int mapentries;
  96649. int quantvals;
  96650. long *pigeonmap;
  96651. long fittotal;
  96652. long *fitlist;
  96653. long *fitmap;
  96654. long *fitlength;
  96655. } encode_aux_pigeonhole;
  96656. typedef struct codebook{
  96657. long dim; /* codebook dimensions (elements per vector) */
  96658. long entries; /* codebook entries */
  96659. long used_entries; /* populated codebook entries */
  96660. const static_codebook *c;
  96661. float *valuelist; /* list of dim*entries actual entry values */
  96662. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  96663. int *dec_index; /* only used if sparseness collapsed */
  96664. char *dec_codelengths;
  96665. ogg_uint32_t *dec_firsttable;
  96666. int dec_firsttablen;
  96667. int dec_maxlength;
  96668. } codebook;
  96669. extern void vorbis_staticbook_clear(static_codebook *b);
  96670. extern void vorbis_staticbook_destroy(static_codebook *b);
  96671. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  96672. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  96673. extern void vorbis_book_clear(codebook *b);
  96674. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  96675. extern float *_book_logdist(const static_codebook *b,float *vals);
  96676. extern float _float32_unpack(long val);
  96677. extern long _float32_pack(float val);
  96678. extern int _best(codebook *book, float *a, int step);
  96679. extern int _ilog(unsigned int v);
  96680. extern long _book_maptype1_quantvals(const static_codebook *b);
  96681. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  96682. extern long vorbis_book_codeword(codebook *book,int entry);
  96683. extern long vorbis_book_codelen(codebook *book,int entry);
  96684. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  96685. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  96686. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  96687. extern int vorbis_book_errorv(codebook *book, float *a);
  96688. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  96689. oggpack_buffer *b);
  96690. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  96691. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  96692. oggpack_buffer *b,int n);
  96693. extern long vorbis_book_decodev_set(codebook *book, float *a,
  96694. oggpack_buffer *b,int n);
  96695. extern long vorbis_book_decodev_add(codebook *book, float *a,
  96696. oggpack_buffer *b,int n);
  96697. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  96698. long off,int ch,
  96699. oggpack_buffer *b,int n);
  96700. #endif
  96701. /*** End of inlined file: codebook.h ***/
  96702. #define BLOCKTYPE_IMPULSE 0
  96703. #define BLOCKTYPE_PADDING 1
  96704. #define BLOCKTYPE_TRANSITION 0
  96705. #define BLOCKTYPE_LONG 1
  96706. #define PACKETBLOBS 15
  96707. typedef struct vorbis_block_internal{
  96708. float **pcmdelay; /* this is a pointer into local storage */
  96709. float ampmax;
  96710. int blocktype;
  96711. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  96712. blob [PACKETBLOBS/2] points to
  96713. the oggpack_buffer in the
  96714. main vorbis_block */
  96715. } vorbis_block_internal;
  96716. typedef void vorbis_look_floor;
  96717. typedef void vorbis_look_residue;
  96718. typedef void vorbis_look_transform;
  96719. typedef struct {
  96720. int blockflag;
  96721. int windowtype;
  96722. int transformtype;
  96723. int mapping;
  96724. } vorbis_info_mode;
  96725. typedef void vorbis_info_floor;
  96726. typedef void vorbis_info_residue;
  96727. typedef void vorbis_info_mapping;
  96728. /*** Start of inlined file: psy.h ***/
  96729. #ifndef _V_PSY_H_
  96730. #define _V_PSY_H_
  96731. /*** Start of inlined file: smallft.h ***/
  96732. #ifndef _V_SMFT_H_
  96733. #define _V_SMFT_H_
  96734. typedef struct {
  96735. int n;
  96736. float *trigcache;
  96737. int *splitcache;
  96738. } drft_lookup;
  96739. extern void drft_forward(drft_lookup *l,float *data);
  96740. extern void drft_backward(drft_lookup *l,float *data);
  96741. extern void drft_init(drft_lookup *l,int n);
  96742. extern void drft_clear(drft_lookup *l);
  96743. #endif
  96744. /*** End of inlined file: smallft.h ***/
  96745. /*** Start of inlined file: backends.h ***/
  96746. #ifndef _vorbis_backend_h_
  96747. #define _vorbis_backend_h_
  96748. typedef struct{
  96749. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  96750. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  96751. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  96752. void (*free_info) (vorbis_info_floor *);
  96753. void (*free_look) (vorbis_look_floor *);
  96754. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  96755. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  96756. void *buffer,float *);
  96757. } vorbis_func_floor;
  96758. typedef struct{
  96759. int order;
  96760. long rate;
  96761. long barkmap;
  96762. int ampbits;
  96763. int ampdB;
  96764. int numbooks; /* <= 16 */
  96765. int books[16];
  96766. float lessthan; /* encode-only config setting hacks for libvorbis */
  96767. float greaterthan; /* encode-only config setting hacks for libvorbis */
  96768. } vorbis_info_floor0;
  96769. #define VIF_POSIT 63
  96770. #define VIF_CLASS 16
  96771. #define VIF_PARTS 31
  96772. typedef struct{
  96773. int partitions; /* 0 to 31 */
  96774. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  96775. int class_dim[VIF_CLASS]; /* 1 to 8 */
  96776. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  96777. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  96778. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  96779. int mult; /* 1 2 3 or 4 */
  96780. int postlist[VIF_POSIT+2]; /* first two implicit */
  96781. float maxover;
  96782. float maxunder;
  96783. float maxerr;
  96784. float twofitweight;
  96785. float twofitatten;
  96786. int n;
  96787. } vorbis_info_floor1;
  96788. typedef struct{
  96789. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  96790. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  96791. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  96792. vorbis_info_residue *);
  96793. void (*free_info) (vorbis_info_residue *);
  96794. void (*free_look) (vorbis_look_residue *);
  96795. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  96796. float **,int *,int);
  96797. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  96798. vorbis_look_residue *,
  96799. float **,float **,int *,int,long **);
  96800. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  96801. float **,int *,int);
  96802. } vorbis_func_residue;
  96803. typedef struct vorbis_info_residue0{
  96804. long begin;
  96805. long end;
  96806. int grouping; /* group n vectors per partition */
  96807. int partitions; /* possible codebooks for a partition */
  96808. int groupbook; /* huffbook for partitioning */
  96809. int secondstages[64]; /* expanded out to pointers in lookup */
  96810. int booklist[256]; /* list of second stage books */
  96811. float classmetric1[64];
  96812. float classmetric2[64];
  96813. } vorbis_info_residue0;
  96814. typedef struct{
  96815. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  96816. oggpack_buffer *);
  96817. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  96818. void (*free_info) (vorbis_info_mapping *);
  96819. int (*forward) (struct vorbis_block *vb);
  96820. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  96821. } vorbis_func_mapping;
  96822. typedef struct vorbis_info_mapping0{
  96823. int submaps; /* <= 16 */
  96824. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  96825. int floorsubmap[16]; /* [mux] submap to floors */
  96826. int residuesubmap[16]; /* [mux] submap to residue */
  96827. int coupling_steps;
  96828. int coupling_mag[256];
  96829. int coupling_ang[256];
  96830. } vorbis_info_mapping0;
  96831. #endif
  96832. /*** End of inlined file: backends.h ***/
  96833. #ifndef EHMER_MAX
  96834. #define EHMER_MAX 56
  96835. #endif
  96836. #define P_BANDS 17 /* 62Hz to 16kHz */
  96837. #define P_LEVELS 8 /* 30dB to 100dB */
  96838. #define P_LEVEL_0 30. /* 30 dB */
  96839. #define P_NOISECURVES 3
  96840. #define NOISE_COMPAND_LEVELS 40
  96841. typedef struct vorbis_info_psy{
  96842. int blockflag;
  96843. float ath_adjatt;
  96844. float ath_maxatt;
  96845. float tone_masteratt[P_NOISECURVES];
  96846. float tone_centerboost;
  96847. float tone_decay;
  96848. float tone_abs_limit;
  96849. float toneatt[P_BANDS];
  96850. int noisemaskp;
  96851. float noisemaxsupp;
  96852. float noisewindowlo;
  96853. float noisewindowhi;
  96854. int noisewindowlomin;
  96855. int noisewindowhimin;
  96856. int noisewindowfixed;
  96857. float noiseoff[P_NOISECURVES][P_BANDS];
  96858. float noisecompand[NOISE_COMPAND_LEVELS];
  96859. float max_curve_dB;
  96860. int normal_channel_p;
  96861. int normal_point_p;
  96862. int normal_start;
  96863. int normal_partition;
  96864. double normal_thresh;
  96865. } vorbis_info_psy;
  96866. typedef struct{
  96867. int eighth_octave_lines;
  96868. float preecho_thresh[VE_BANDS];
  96869. float postecho_thresh[VE_BANDS];
  96870. float stretch_penalty;
  96871. float preecho_minenergy;
  96872. float ampmax_att_per_sec;
  96873. int coupling_pkHz[PACKETBLOBS];
  96874. int coupling_pointlimit[2][PACKETBLOBS];
  96875. int coupling_prepointamp[PACKETBLOBS];
  96876. int coupling_postpointamp[PACKETBLOBS];
  96877. int sliding_lowpass[2][PACKETBLOBS];
  96878. } vorbis_info_psy_global;
  96879. typedef struct {
  96880. float ampmax;
  96881. int channels;
  96882. vorbis_info_psy_global *gi;
  96883. int coupling_pointlimit[2][P_NOISECURVES];
  96884. } vorbis_look_psy_global;
  96885. typedef struct {
  96886. int n;
  96887. struct vorbis_info_psy *vi;
  96888. float ***tonecurves;
  96889. float **noiseoffset;
  96890. float *ath;
  96891. long *octave; /* in n.ocshift format */
  96892. long *bark;
  96893. long firstoc;
  96894. long shiftoc;
  96895. int eighth_octave_lines; /* power of two, please */
  96896. int total_octave_lines;
  96897. long rate; /* cache it */
  96898. float m_val; /* Masking compensation value */
  96899. } vorbis_look_psy;
  96900. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  96901. vorbis_info_psy_global *gi,int n,long rate);
  96902. extern void _vp_psy_clear(vorbis_look_psy *p);
  96903. extern void *_vi_psy_dup(void *source);
  96904. extern void _vi_psy_free(vorbis_info_psy *i);
  96905. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  96906. extern void _vp_remove_floor(vorbis_look_psy *p,
  96907. float *mdct,
  96908. int *icodedflr,
  96909. float *residue,
  96910. int sliding_lowpass);
  96911. extern void _vp_noisemask(vorbis_look_psy *p,
  96912. float *logmdct,
  96913. float *logmask);
  96914. extern void _vp_tonemask(vorbis_look_psy *p,
  96915. float *logfft,
  96916. float *logmask,
  96917. float global_specmax,
  96918. float local_specmax);
  96919. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  96920. float *noise,
  96921. float *tone,
  96922. int offset_select,
  96923. float *logmask,
  96924. float *mdct,
  96925. float *logmdct);
  96926. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  96927. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  96928. vorbis_info_psy_global *g,
  96929. vorbis_look_psy *p,
  96930. vorbis_info_mapping0 *vi,
  96931. float **mdct);
  96932. extern void _vp_couple(int blobno,
  96933. vorbis_info_psy_global *g,
  96934. vorbis_look_psy *p,
  96935. vorbis_info_mapping0 *vi,
  96936. float **res,
  96937. float **mag_memo,
  96938. int **mag_sort,
  96939. int **ifloor,
  96940. int *nonzero,
  96941. int sliding_lowpass);
  96942. extern void _vp_noise_normalize(vorbis_look_psy *p,
  96943. float *in,float *out,int *sortedindex);
  96944. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  96945. float *magnitudes,int *sortedindex);
  96946. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  96947. vorbis_look_psy *p,
  96948. vorbis_info_mapping0 *vi,
  96949. float **mags);
  96950. extern void hf_reduction(vorbis_info_psy_global *g,
  96951. vorbis_look_psy *p,
  96952. vorbis_info_mapping0 *vi,
  96953. float **mdct);
  96954. #endif
  96955. /*** End of inlined file: psy.h ***/
  96956. /*** Start of inlined file: bitrate.h ***/
  96957. #ifndef _V_BITRATE_H_
  96958. #define _V_BITRATE_H_
  96959. /*** Start of inlined file: os.h ***/
  96960. #ifndef _OS_H
  96961. #define _OS_H
  96962. #ifdef HAVE_CONFIG_H
  96963. #include "config.h"
  96964. #endif
  96965. #include <math.h>
  96966. /*** Start of inlined file: misc.h ***/
  96967. #ifndef _V_RANDOM_H_
  96968. #define _V_RANDOM_H_
  96969. extern int analysis_noisy;
  96970. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  96971. extern void _vorbis_block_ripcord(vorbis_block *vb);
  96972. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  96973. ogg_int64_t off);
  96974. #ifdef DEBUG_MALLOC
  96975. #define _VDBG_GRAPHFILE "malloc.m"
  96976. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  96977. extern void _VDBG_free(void *ptr,char *file,long line);
  96978. #ifndef MISC_C
  96979. #undef _ogg_malloc
  96980. #undef _ogg_calloc
  96981. #undef _ogg_realloc
  96982. #undef _ogg_free
  96983. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  96984. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  96985. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  96986. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  96987. #endif
  96988. #endif
  96989. #endif
  96990. /*** End of inlined file: misc.h ***/
  96991. #ifndef _V_IFDEFJAIL_H_
  96992. # define _V_IFDEFJAIL_H_
  96993. # ifdef __GNUC__
  96994. # define STIN static __inline__
  96995. # elif _WIN32
  96996. # define STIN static __inline
  96997. # else
  96998. # define STIN static
  96999. # endif
  97000. #ifdef DJGPP
  97001. # define rint(x) (floor((x)+0.5f))
  97002. #endif
  97003. #ifndef M_PI
  97004. # define M_PI (3.1415926536f)
  97005. #endif
  97006. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97007. # include <malloc.h>
  97008. # define rint(x) (floor((x)+0.5f))
  97009. # define NO_FLOAT_MATH_LIB
  97010. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97011. #endif
  97012. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97013. void *_alloca(size_t size);
  97014. # define alloca _alloca
  97015. #endif
  97016. #ifndef FAST_HYPOT
  97017. # define FAST_HYPOT hypot
  97018. #endif
  97019. #endif
  97020. #ifdef HAVE_ALLOCA_H
  97021. # include <alloca.h>
  97022. #endif
  97023. #ifdef USE_MEMORY_H
  97024. # include <memory.h>
  97025. #endif
  97026. #ifndef min
  97027. # define min(x,y) ((x)>(y)?(y):(x))
  97028. #endif
  97029. #ifndef max
  97030. # define max(x,y) ((x)<(y)?(y):(x))
  97031. #endif
  97032. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97033. # define VORBIS_FPU_CONTROL
  97034. typedef ogg_int16_t vorbis_fpu_control;
  97035. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97036. ogg_int16_t ret;
  97037. ogg_int16_t temp;
  97038. __asm__ __volatile__("fnstcw %0\n\t"
  97039. "movw %0,%%dx\n\t"
  97040. "orw $62463,%%dx\n\t"
  97041. "movw %%dx,%1\n\t"
  97042. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97043. *fpu=ret;
  97044. }
  97045. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97046. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97047. }
  97048. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97049. we get extra fst/fld to
  97050. truncate precision */
  97051. int i;
  97052. __asm__("fistl %0": "=m"(i) : "t"(f));
  97053. return(i);
  97054. }
  97055. #endif
  97056. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97057. # define VORBIS_FPU_CONTROL
  97058. typedef ogg_int16_t vorbis_fpu_control;
  97059. static __inline int vorbis_ftoi(double f){
  97060. int i;
  97061. __asm{
  97062. fld f
  97063. fistp i
  97064. }
  97065. return i;
  97066. }
  97067. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97068. }
  97069. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97070. }
  97071. #endif
  97072. #ifndef VORBIS_FPU_CONTROL
  97073. typedef int vorbis_fpu_control;
  97074. static int vorbis_ftoi(double f){
  97075. return (int)(f+.5);
  97076. }
  97077. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97078. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97079. #endif
  97080. #endif /* _OS_H */
  97081. /*** End of inlined file: os.h ***/
  97082. typedef struct bitrate_manager_state {
  97083. int managed;
  97084. long avg_reservoir;
  97085. long minmax_reservoir;
  97086. long avg_bitsper;
  97087. long min_bitsper;
  97088. long max_bitsper;
  97089. long short_per_long;
  97090. double avgfloat;
  97091. vorbis_block *vb;
  97092. int choice;
  97093. } bitrate_manager_state;
  97094. typedef struct bitrate_manager_info{
  97095. long avg_rate;
  97096. long min_rate;
  97097. long max_rate;
  97098. long reservoir_bits;
  97099. double reservoir_bias;
  97100. double slew_damp;
  97101. } bitrate_manager_info;
  97102. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97103. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97104. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97105. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97106. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97107. #endif
  97108. /*** End of inlined file: bitrate.h ***/
  97109. static int ilog(unsigned int v){
  97110. int ret=0;
  97111. while(v){
  97112. ret++;
  97113. v>>=1;
  97114. }
  97115. return(ret);
  97116. }
  97117. static int ilog2(unsigned int v){
  97118. int ret=0;
  97119. if(v)--v;
  97120. while(v){
  97121. ret++;
  97122. v>>=1;
  97123. }
  97124. return(ret);
  97125. }
  97126. typedef struct private_state {
  97127. envelope_lookup *ve; /* envelope lookup */
  97128. int window[2];
  97129. vorbis_look_transform **transform[2]; /* block, type */
  97130. drft_lookup fft_look[2];
  97131. int modebits;
  97132. vorbis_look_floor **flr;
  97133. vorbis_look_residue **residue;
  97134. vorbis_look_psy *psy;
  97135. vorbis_look_psy_global *psy_g_look;
  97136. unsigned char *header;
  97137. unsigned char *header1;
  97138. unsigned char *header2;
  97139. bitrate_manager_state bms;
  97140. ogg_int64_t sample_count;
  97141. } private_state;
  97142. /*** Start of inlined file: highlevel.h ***/
  97143. typedef struct highlevel_byblocktype {
  97144. double tone_mask_setting;
  97145. double tone_peaklimit_setting;
  97146. double noise_bias_setting;
  97147. double noise_compand_setting;
  97148. } highlevel_byblocktype;
  97149. typedef struct highlevel_encode_setup {
  97150. void *setup;
  97151. int set_in_stone;
  97152. double base_setting;
  97153. double long_setting;
  97154. double short_setting;
  97155. double impulse_noisetune;
  97156. int managed;
  97157. long bitrate_min;
  97158. long bitrate_av;
  97159. double bitrate_av_damp;
  97160. long bitrate_max;
  97161. long bitrate_reservoir;
  97162. double bitrate_reservoir_bias;
  97163. int impulse_block_p;
  97164. int noise_normalize_p;
  97165. double stereo_point_setting;
  97166. double lowpass_kHz;
  97167. double ath_floating_dB;
  97168. double ath_absolute_dB;
  97169. double amplitude_track_dBpersec;
  97170. double trigger_setting;
  97171. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97172. } highlevel_encode_setup;
  97173. /*** End of inlined file: highlevel.h ***/
  97174. typedef struct codec_setup_info {
  97175. long blocksizes[2];
  97176. int modes;
  97177. int maps;
  97178. int floors;
  97179. int residues;
  97180. int books;
  97181. int psys; /* encode only */
  97182. vorbis_info_mode *mode_param[64];
  97183. int map_type[64];
  97184. vorbis_info_mapping *map_param[64];
  97185. int floor_type[64];
  97186. vorbis_info_floor *floor_param[64];
  97187. int residue_type[64];
  97188. vorbis_info_residue *residue_param[64];
  97189. static_codebook *book_param[256];
  97190. codebook *fullbooks;
  97191. vorbis_info_psy *psy_param[4]; /* encode only */
  97192. vorbis_info_psy_global psy_g_param;
  97193. bitrate_manager_info bi;
  97194. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97195. highly redundant structure, but
  97196. improves clarity of program flow. */
  97197. int halfrate_flag; /* painless downsample for decode */
  97198. } codec_setup_info;
  97199. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97200. extern void _vp_global_free(vorbis_look_psy_global *look);
  97201. #endif
  97202. /*** End of inlined file: codec_internal.h ***/
  97203. /*** Start of inlined file: registry.h ***/
  97204. #ifndef _V_REG_H_
  97205. #define _V_REG_H_
  97206. #define VI_TRANSFORMB 1
  97207. #define VI_WINDOWB 1
  97208. #define VI_TIMEB 1
  97209. #define VI_FLOORB 2
  97210. #define VI_RESB 3
  97211. #define VI_MAPB 1
  97212. extern vorbis_func_floor *_floor_P[];
  97213. extern vorbis_func_residue *_residue_P[];
  97214. extern vorbis_func_mapping *_mapping_P[];
  97215. #endif
  97216. /*** End of inlined file: registry.h ***/
  97217. /*** Start of inlined file: scales.h ***/
  97218. #ifndef _V_SCALES_H_
  97219. #define _V_SCALES_H_
  97220. #include <math.h>
  97221. #define VORBIS_IEEE_FLOAT32 1
  97222. #ifdef VORBIS_IEEE_FLOAT32
  97223. static float unitnorm(float x){
  97224. union {
  97225. ogg_uint32_t i;
  97226. float f;
  97227. } ix;
  97228. ix.f = x;
  97229. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97230. return ix.f;
  97231. }
  97232. static float todB(const float *x){
  97233. union {
  97234. ogg_uint32_t i;
  97235. float f;
  97236. } ix;
  97237. ix.f = *x;
  97238. ix.i = ix.i&0x7fffffff;
  97239. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97240. }
  97241. #define todB_nn(x) todB(x)
  97242. #else
  97243. static float unitnorm(float x){
  97244. if(x<0)return(-1.f);
  97245. return(1.f);
  97246. }
  97247. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97248. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97249. #endif
  97250. #define fromdB(x) (exp((x)*.11512925f))
  97251. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97252. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97253. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97254. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97255. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97256. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97257. #endif
  97258. /*** End of inlined file: scales.h ***/
  97259. int analysis_noisy=1;
  97260. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97261. int ret,i;
  97262. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97263. vb->glue_bits=0;
  97264. vb->time_bits=0;
  97265. vb->floor_bits=0;
  97266. vb->res_bits=0;
  97267. for(i=0;i<PACKETBLOBS;i++)
  97268. oggpack_reset(vbi->packetblob[i]);
  97269. if((ret=_mapping_P[0]->forward(vb)))
  97270. return(ret);
  97271. if(op){
  97272. if(vorbis_bitrate_managed(vb))
  97273. return(OV_EINVAL);
  97274. op->packet=oggpack_get_buffer(&vb->opb);
  97275. op->bytes=oggpack_bytes(&vb->opb);
  97276. op->b_o_s=0;
  97277. op->e_o_s=vb->eofflag;
  97278. op->granulepos=vb->granulepos;
  97279. op->packetno=vb->sequence; /* for sake of completeness */
  97280. }
  97281. return(0);
  97282. }
  97283. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97284. int j;
  97285. FILE *of;
  97286. char buffer[80];
  97287. sprintf(buffer,"%s_%d.m",base,i);
  97288. of=fopen(buffer,"w");
  97289. if(!of)perror("failed to open data dump file");
  97290. for(j=0;j<n;j++){
  97291. if(bark){
  97292. float b=toBARK((4000.f*j/n)+.25);
  97293. fprintf(of,"%f ",b);
  97294. }else
  97295. if(off!=0)
  97296. fprintf(of,"%f ",(double)(j+off)/8000.);
  97297. else
  97298. fprintf(of,"%f ",(double)j);
  97299. if(dB){
  97300. float val;
  97301. if(v[j]==0.)
  97302. val=-140.;
  97303. else
  97304. val=todB(v+j);
  97305. fprintf(of,"%f\n",val);
  97306. }else{
  97307. fprintf(of,"%f\n",v[j]);
  97308. }
  97309. }
  97310. fclose(of);
  97311. }
  97312. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97313. ogg_int64_t off){
  97314. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97315. }
  97316. #endif
  97317. /*** End of inlined file: analysis.c ***/
  97318. /*** Start of inlined file: bitrate.c ***/
  97319. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97320. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97321. // tasks..
  97322. #if JUCE_MSVC
  97323. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97324. #endif
  97325. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97326. #if JUCE_USE_OGGVORBIS
  97327. #include <stdlib.h>
  97328. #include <string.h>
  97329. #include <math.h>
  97330. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97331. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97332. bitrate_manager_info *bi=&ci->bi;
  97333. memset(bm,0,sizeof(*bm));
  97334. if(bi && (bi->reservoir_bits>0)){
  97335. long ratesamples=vi->rate;
  97336. int halfsamples=ci->blocksizes[0]>>1;
  97337. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97338. bm->managed=1;
  97339. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97340. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97341. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97342. bm->avgfloat=PACKETBLOBS/2;
  97343. {
  97344. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97345. bm->minmax_reservoir=desired_fill;
  97346. bm->avg_reservoir=desired_fill;
  97347. }
  97348. }
  97349. }
  97350. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97351. memset(bm,0,sizeof(*bm));
  97352. return;
  97353. }
  97354. int vorbis_bitrate_managed(vorbis_block *vb){
  97355. vorbis_dsp_state *vd=vb->vd;
  97356. private_state *b=(private_state*)vd->backend_state;
  97357. bitrate_manager_state *bm=&b->bms;
  97358. if(bm && bm->managed)return(1);
  97359. return(0);
  97360. }
  97361. int vorbis_bitrate_addblock(vorbis_block *vb){
  97362. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97363. vorbis_dsp_state *vd=vb->vd;
  97364. private_state *b=(private_state*)vd->backend_state;
  97365. bitrate_manager_state *bm=&b->bms;
  97366. vorbis_info *vi=vd->vi;
  97367. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97368. bitrate_manager_info *bi=&ci->bi;
  97369. int choice=rint(bm->avgfloat);
  97370. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97371. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97372. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97373. int samples=ci->blocksizes[vb->W]>>1;
  97374. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97375. if(!bm->managed){
  97376. if(bm->vb)return(-1); /* one has been submitted without
  97377. being claimed */
  97378. bm->vb=vb;
  97379. return(0);
  97380. }
  97381. bm->vb=vb;
  97382. if(bm->avg_bitsper>0){
  97383. double slew=0.;
  97384. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97385. double slewlimit= 15./bi->slew_damp;
  97386. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97387. while(choice>0 && this_bits>avg_target_bits &&
  97388. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97389. choice--;
  97390. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97391. }
  97392. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97393. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97394. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97395. choice++;
  97396. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97397. }
  97398. }
  97399. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97400. if(slew<-slewlimit)slew=-slewlimit;
  97401. if(slew>slewlimit)slew=slewlimit;
  97402. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97403. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97404. }
  97405. if(bm->min_bitsper>0){
  97406. if(this_bits<min_target_bits){
  97407. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97408. choice++;
  97409. if(choice>=PACKETBLOBS)break;
  97410. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97411. }
  97412. }
  97413. }
  97414. if(bm->max_bitsper>0){
  97415. if(this_bits>max_target_bits){
  97416. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97417. choice--;
  97418. if(choice<0)break;
  97419. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97420. }
  97421. }
  97422. }
  97423. if(choice<0){
  97424. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97425. bm->choice=choice=0;
  97426. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97427. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97428. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97429. }
  97430. }else{
  97431. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97432. if(choice>=PACKETBLOBS)
  97433. choice=PACKETBLOBS-1;
  97434. bm->choice=choice;
  97435. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97436. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97437. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97438. }
  97439. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97440. if(max_target_bits>0 && this_bits>max_target_bits){
  97441. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97442. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97443. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97444. }else{
  97445. if(bm->minmax_reservoir>desired_fill){
  97446. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97447. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97448. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97449. }else{
  97450. bm->minmax_reservoir=desired_fill;
  97451. }
  97452. }else{
  97453. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97454. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97455. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97456. }else{
  97457. bm->minmax_reservoir=desired_fill;
  97458. }
  97459. }
  97460. }
  97461. }
  97462. if(bm->avg_bitsper>0){
  97463. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97464. bm->avg_reservoir+=this_bits-avg_target_bits;
  97465. }
  97466. return(0);
  97467. }
  97468. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97469. private_state *b=(private_state*)vd->backend_state;
  97470. bitrate_manager_state *bm=&b->bms;
  97471. vorbis_block *vb=bm->vb;
  97472. int choice=PACKETBLOBS/2;
  97473. if(!vb)return 0;
  97474. if(op){
  97475. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97476. if(vorbis_bitrate_managed(vb))
  97477. choice=bm->choice;
  97478. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97479. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97480. op->b_o_s=0;
  97481. op->e_o_s=vb->eofflag;
  97482. op->granulepos=vb->granulepos;
  97483. op->packetno=vb->sequence; /* for sake of completeness */
  97484. }
  97485. bm->vb=0;
  97486. return(1);
  97487. }
  97488. #endif
  97489. /*** End of inlined file: bitrate.c ***/
  97490. /*** Start of inlined file: block.c ***/
  97491. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97492. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97493. // tasks..
  97494. #if JUCE_MSVC
  97495. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97496. #endif
  97497. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97498. #if JUCE_USE_OGGVORBIS
  97499. #include <stdio.h>
  97500. #include <stdlib.h>
  97501. #include <string.h>
  97502. /*** Start of inlined file: window.h ***/
  97503. #ifndef _V_WINDOW_
  97504. #define _V_WINDOW_
  97505. extern float *_vorbis_window_get(int n);
  97506. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97507. int lW,int W,int nW);
  97508. #endif
  97509. /*** End of inlined file: window.h ***/
  97510. /*** Start of inlined file: lpc.h ***/
  97511. #ifndef _V_LPC_H_
  97512. #define _V_LPC_H_
  97513. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  97514. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  97515. float *data,long n);
  97516. #endif
  97517. /*** End of inlined file: lpc.h ***/
  97518. #ifndef WORD_ALIGN
  97519. #define WORD_ALIGN 8
  97520. #endif
  97521. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  97522. int i;
  97523. memset(vb,0,sizeof(*vb));
  97524. vb->vd=v;
  97525. vb->localalloc=0;
  97526. vb->localstore=NULL;
  97527. if(v->analysisp){
  97528. vorbis_block_internal *vbi=(vorbis_block_internal*)
  97529. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  97530. vbi->ampmax=-9999;
  97531. for(i=0;i<PACKETBLOBS;i++){
  97532. if(i==PACKETBLOBS/2){
  97533. vbi->packetblob[i]=&vb->opb;
  97534. }else{
  97535. vbi->packetblob[i]=
  97536. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  97537. }
  97538. oggpack_writeinit(vbi->packetblob[i]);
  97539. }
  97540. }
  97541. return(0);
  97542. }
  97543. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  97544. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  97545. if(bytes+vb->localtop>vb->localalloc){
  97546. if(vb->localstore){
  97547. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  97548. vb->totaluse+=vb->localtop;
  97549. link->next=vb->reap;
  97550. link->ptr=vb->localstore;
  97551. vb->reap=link;
  97552. }
  97553. vb->localalloc=bytes;
  97554. vb->localstore=_ogg_malloc(vb->localalloc);
  97555. vb->localtop=0;
  97556. }
  97557. {
  97558. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  97559. vb->localtop+=bytes;
  97560. return ret;
  97561. }
  97562. }
  97563. void _vorbis_block_ripcord(vorbis_block *vb){
  97564. struct alloc_chain *reap=vb->reap;
  97565. while(reap){
  97566. struct alloc_chain *next=reap->next;
  97567. _ogg_free(reap->ptr);
  97568. memset(reap,0,sizeof(*reap));
  97569. _ogg_free(reap);
  97570. reap=next;
  97571. }
  97572. if(vb->totaluse){
  97573. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  97574. vb->localalloc+=vb->totaluse;
  97575. vb->totaluse=0;
  97576. }
  97577. vb->localtop=0;
  97578. vb->reap=NULL;
  97579. }
  97580. int vorbis_block_clear(vorbis_block *vb){
  97581. int i;
  97582. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97583. _vorbis_block_ripcord(vb);
  97584. if(vb->localstore)_ogg_free(vb->localstore);
  97585. if(vbi){
  97586. for(i=0;i<PACKETBLOBS;i++){
  97587. oggpack_writeclear(vbi->packetblob[i]);
  97588. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  97589. }
  97590. _ogg_free(vbi);
  97591. }
  97592. memset(vb,0,sizeof(*vb));
  97593. return(0);
  97594. }
  97595. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  97596. int i;
  97597. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97598. private_state *b=NULL;
  97599. int hs;
  97600. if(ci==NULL) return 1;
  97601. hs=ci->halfrate_flag;
  97602. memset(v,0,sizeof(*v));
  97603. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  97604. v->vi=vi;
  97605. b->modebits=ilog2(ci->modes);
  97606. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  97607. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  97608. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97609. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  97610. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  97611. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  97612. b->window[0]=ilog2(ci->blocksizes[0])-6;
  97613. b->window[1]=ilog2(ci->blocksizes[1])-6;
  97614. if(encp){ /* encode/decode differ here */
  97615. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  97616. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  97617. if(!ci->fullbooks){
  97618. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97619. for(i=0;i<ci->books;i++)
  97620. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  97621. }
  97622. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  97623. for(i=0;i<ci->psys;i++){
  97624. _vp_psy_init(b->psy+i,
  97625. ci->psy_param[i],
  97626. &ci->psy_g_param,
  97627. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  97628. vi->rate);
  97629. }
  97630. v->analysisp=1;
  97631. }else{
  97632. if(!ci->fullbooks){
  97633. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  97634. for(i=0;i<ci->books;i++){
  97635. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  97636. vorbis_staticbook_destroy(ci->book_param[i]);
  97637. ci->book_param[i]=NULL;
  97638. }
  97639. }
  97640. }
  97641. v->pcm_storage=ci->blocksizes[1];
  97642. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  97643. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  97644. {
  97645. int i;
  97646. for(i=0;i<vi->channels;i++)
  97647. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  97648. }
  97649. v->lW=0; /* previous window size */
  97650. v->W=0; /* current window size */
  97651. v->centerW=ci->blocksizes[1]/2;
  97652. v->pcm_current=v->centerW;
  97653. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  97654. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  97655. for(i=0;i<ci->floors;i++)
  97656. b->flr[i]=_floor_P[ci->floor_type[i]]->
  97657. look(v,ci->floor_param[i]);
  97658. for(i=0;i<ci->residues;i++)
  97659. b->residue[i]=_residue_P[ci->residue_type[i]]->
  97660. look(v,ci->residue_param[i]);
  97661. return 0;
  97662. }
  97663. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97664. private_state *b=NULL;
  97665. if(_vds_shared_init(v,vi,1))return 1;
  97666. b=(private_state*)v->backend_state;
  97667. b->psy_g_look=_vp_global_look(vi);
  97668. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  97669. _ve_envelope_init(b->ve,vi);
  97670. vorbis_bitrate_init(vi,&b->bms);
  97671. v->sequence=3;
  97672. return(0);
  97673. }
  97674. void vorbis_dsp_clear(vorbis_dsp_state *v){
  97675. int i;
  97676. if(v){
  97677. vorbis_info *vi=v->vi;
  97678. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  97679. private_state *b=(private_state*)v->backend_state;
  97680. if(b){
  97681. if(b->ve){
  97682. _ve_envelope_clear(b->ve);
  97683. _ogg_free(b->ve);
  97684. }
  97685. if(b->transform[0]){
  97686. mdct_clear((mdct_lookup*) b->transform[0][0]);
  97687. _ogg_free(b->transform[0][0]);
  97688. _ogg_free(b->transform[0]);
  97689. }
  97690. if(b->transform[1]){
  97691. mdct_clear((mdct_lookup*) b->transform[1][0]);
  97692. _ogg_free(b->transform[1][0]);
  97693. _ogg_free(b->transform[1]);
  97694. }
  97695. if(b->flr){
  97696. for(i=0;i<ci->floors;i++)
  97697. _floor_P[ci->floor_type[i]]->
  97698. free_look(b->flr[i]);
  97699. _ogg_free(b->flr);
  97700. }
  97701. if(b->residue){
  97702. for(i=0;i<ci->residues;i++)
  97703. _residue_P[ci->residue_type[i]]->
  97704. free_look(b->residue[i]);
  97705. _ogg_free(b->residue);
  97706. }
  97707. if(b->psy){
  97708. for(i=0;i<ci->psys;i++)
  97709. _vp_psy_clear(b->psy+i);
  97710. _ogg_free(b->psy);
  97711. }
  97712. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  97713. vorbis_bitrate_clear(&b->bms);
  97714. drft_clear(&b->fft_look[0]);
  97715. drft_clear(&b->fft_look[1]);
  97716. }
  97717. if(v->pcm){
  97718. for(i=0;i<vi->channels;i++)
  97719. if(v->pcm[i])_ogg_free(v->pcm[i]);
  97720. _ogg_free(v->pcm);
  97721. if(v->pcmret)_ogg_free(v->pcmret);
  97722. }
  97723. if(b){
  97724. if(b->header)_ogg_free(b->header);
  97725. if(b->header1)_ogg_free(b->header1);
  97726. if(b->header2)_ogg_free(b->header2);
  97727. _ogg_free(b);
  97728. }
  97729. memset(v,0,sizeof(*v));
  97730. }
  97731. }
  97732. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  97733. int i;
  97734. vorbis_info *vi=v->vi;
  97735. private_state *b=(private_state*)v->backend_state;
  97736. if(b->header)_ogg_free(b->header);b->header=NULL;
  97737. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  97738. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  97739. if(v->pcm_current+vals>=v->pcm_storage){
  97740. v->pcm_storage=v->pcm_current+vals*2;
  97741. for(i=0;i<vi->channels;i++){
  97742. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  97743. }
  97744. }
  97745. for(i=0;i<vi->channels;i++)
  97746. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  97747. return(v->pcmret);
  97748. }
  97749. static void _preextrapolate_helper(vorbis_dsp_state *v){
  97750. int i;
  97751. int order=32;
  97752. float *lpc=(float*)alloca(order*sizeof(*lpc));
  97753. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  97754. long j;
  97755. v->preextrapolate=1;
  97756. if(v->pcm_current-v->centerW>order*2){ /* safety */
  97757. for(i=0;i<v->vi->channels;i++){
  97758. for(j=0;j<v->pcm_current;j++)
  97759. work[j]=v->pcm[i][v->pcm_current-j-1];
  97760. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  97761. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  97762. order,
  97763. work+v->pcm_current-v->centerW,
  97764. v->centerW);
  97765. for(j=0;j<v->pcm_current;j++)
  97766. v->pcm[i][v->pcm_current-j-1]=work[j];
  97767. }
  97768. }
  97769. }
  97770. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  97771. vorbis_info *vi=v->vi;
  97772. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97773. if(vals<=0){
  97774. int order=32;
  97775. int i;
  97776. float *lpc=(float*) alloca(order*sizeof(*lpc));
  97777. if(!v->preextrapolate)
  97778. _preextrapolate_helper(v);
  97779. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  97780. v->eofflag=v->pcm_current;
  97781. v->pcm_current+=ci->blocksizes[1]*3;
  97782. for(i=0;i<vi->channels;i++){
  97783. if(v->eofflag>order*2){
  97784. long n;
  97785. n=v->eofflag;
  97786. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  97787. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  97788. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  97789. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  97790. }else{
  97791. memset(v->pcm[i]+v->eofflag,0,
  97792. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  97793. }
  97794. }
  97795. }else{
  97796. if(v->pcm_current+vals>v->pcm_storage)
  97797. return(OV_EINVAL);
  97798. v->pcm_current+=vals;
  97799. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  97800. _preextrapolate_helper(v);
  97801. }
  97802. return(0);
  97803. }
  97804. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  97805. int i;
  97806. vorbis_info *vi=v->vi;
  97807. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97808. private_state *b=(private_state*)v->backend_state;
  97809. vorbis_look_psy_global *g=b->psy_g_look;
  97810. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  97811. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97812. if(!v->preextrapolate)return(0);
  97813. if(v->eofflag==-1)return(0);
  97814. {
  97815. long bp=_ve_envelope_search(v);
  97816. if(bp==-1){
  97817. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  97818. full long block */
  97819. v->nW=0;
  97820. }else{
  97821. if(ci->blocksizes[0]==ci->blocksizes[1])
  97822. v->nW=0;
  97823. else
  97824. v->nW=bp;
  97825. }
  97826. }
  97827. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  97828. {
  97829. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  97830. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  97831. although this check is
  97832. less strict that the
  97833. _ve_envelope_search,
  97834. the search is not run
  97835. if we only use one
  97836. block size */
  97837. }
  97838. _vorbis_block_ripcord(vb);
  97839. vb->lW=v->lW;
  97840. vb->W=v->W;
  97841. vb->nW=v->nW;
  97842. if(v->W){
  97843. if(!v->lW || !v->nW){
  97844. vbi->blocktype=BLOCKTYPE_TRANSITION;
  97845. }else{
  97846. vbi->blocktype=BLOCKTYPE_LONG;
  97847. }
  97848. }else{
  97849. if(_ve_envelope_mark(v)){
  97850. vbi->blocktype=BLOCKTYPE_IMPULSE;
  97851. }else{
  97852. vbi->blocktype=BLOCKTYPE_PADDING;
  97853. }
  97854. }
  97855. vb->vd=v;
  97856. vb->sequence=v->sequence++;
  97857. vb->granulepos=v->granulepos;
  97858. vb->pcmend=ci->blocksizes[v->W];
  97859. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  97860. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  97861. vbi->ampmax=g->ampmax;
  97862. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  97863. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  97864. for(i=0;i<vi->channels;i++){
  97865. vbi->pcmdelay[i]=
  97866. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97867. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  97868. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  97869. }
  97870. if(v->eofflag){
  97871. if(v->centerW>=v->eofflag){
  97872. v->eofflag=-1;
  97873. vb->eofflag=1;
  97874. return(1);
  97875. }
  97876. }
  97877. {
  97878. int new_centerNext=ci->blocksizes[1]/2;
  97879. int movementW=centerNext-new_centerNext;
  97880. if(movementW>0){
  97881. _ve_envelope_shift(b->ve,movementW);
  97882. v->pcm_current-=movementW;
  97883. for(i=0;i<vi->channels;i++)
  97884. memmove(v->pcm[i],v->pcm[i]+movementW,
  97885. v->pcm_current*sizeof(*v->pcm[i]));
  97886. v->lW=v->W;
  97887. v->W=v->nW;
  97888. v->centerW=new_centerNext;
  97889. if(v->eofflag){
  97890. v->eofflag-=movementW;
  97891. if(v->eofflag<=0)v->eofflag=-1;
  97892. if(v->centerW>=v->eofflag){
  97893. v->granulepos+=movementW-(v->centerW-v->eofflag);
  97894. }else{
  97895. v->granulepos+=movementW;
  97896. }
  97897. }else{
  97898. v->granulepos+=movementW;
  97899. }
  97900. }
  97901. }
  97902. return(1);
  97903. }
  97904. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  97905. vorbis_info *vi=v->vi;
  97906. codec_setup_info *ci;
  97907. int hs;
  97908. if(!v->backend_state)return -1;
  97909. if(!vi)return -1;
  97910. ci=(codec_setup_info*) vi->codec_setup;
  97911. if(!ci)return -1;
  97912. hs=ci->halfrate_flag;
  97913. v->centerW=ci->blocksizes[1]>>(hs+1);
  97914. v->pcm_current=v->centerW>>hs;
  97915. v->pcm_returned=-1;
  97916. v->granulepos=-1;
  97917. v->sequence=-1;
  97918. v->eofflag=0;
  97919. ((private_state *)(v->backend_state))->sample_count=-1;
  97920. return(0);
  97921. }
  97922. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  97923. if(_vds_shared_init(v,vi,0)) return 1;
  97924. vorbis_synthesis_restart(v);
  97925. return 0;
  97926. }
  97927. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  97928. vorbis_info *vi=v->vi;
  97929. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97930. private_state *b=(private_state*)v->backend_state;
  97931. int hs=ci->halfrate_flag;
  97932. int i,j;
  97933. if(!vb)return(OV_EINVAL);
  97934. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  97935. v->lW=v->W;
  97936. v->W=vb->W;
  97937. v->nW=-1;
  97938. if((v->sequence==-1)||
  97939. (v->sequence+1 != vb->sequence)){
  97940. v->granulepos=-1; /* out of sequence; lose count */
  97941. b->sample_count=-1;
  97942. }
  97943. v->sequence=vb->sequence;
  97944. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  97945. was called on block */
  97946. int n=ci->blocksizes[v->W]>>(hs+1);
  97947. int n0=ci->blocksizes[0]>>(hs+1);
  97948. int n1=ci->blocksizes[1]>>(hs+1);
  97949. int thisCenter;
  97950. int prevCenter;
  97951. v->glue_bits+=vb->glue_bits;
  97952. v->time_bits+=vb->time_bits;
  97953. v->floor_bits+=vb->floor_bits;
  97954. v->res_bits+=vb->res_bits;
  97955. if(v->centerW){
  97956. thisCenter=n1;
  97957. prevCenter=0;
  97958. }else{
  97959. thisCenter=0;
  97960. prevCenter=n1;
  97961. }
  97962. for(j=0;j<vi->channels;j++){
  97963. if(v->lW){
  97964. if(v->W){
  97965. float *w=_vorbis_window_get(b->window[1]-hs);
  97966. float *pcm=v->pcm[j]+prevCenter;
  97967. float *p=vb->pcm[j];
  97968. for(i=0;i<n1;i++)
  97969. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  97970. }else{
  97971. float *w=_vorbis_window_get(b->window[0]-hs);
  97972. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  97973. float *p=vb->pcm[j];
  97974. for(i=0;i<n0;i++)
  97975. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97976. }
  97977. }else{
  97978. if(v->W){
  97979. float *w=_vorbis_window_get(b->window[0]-hs);
  97980. float *pcm=v->pcm[j]+prevCenter;
  97981. float *p=vb->pcm[j]+n1/2-n0/2;
  97982. for(i=0;i<n0;i++)
  97983. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97984. for(;i<n1/2+n0/2;i++)
  97985. pcm[i]=p[i];
  97986. }else{
  97987. float *w=_vorbis_window_get(b->window[0]-hs);
  97988. float *pcm=v->pcm[j]+prevCenter;
  97989. float *p=vb->pcm[j];
  97990. for(i=0;i<n0;i++)
  97991. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  97992. }
  97993. }
  97994. {
  97995. float *pcm=v->pcm[j]+thisCenter;
  97996. float *p=vb->pcm[j]+n;
  97997. for(i=0;i<n;i++)
  97998. pcm[i]=p[i];
  97999. }
  98000. }
  98001. if(v->centerW)
  98002. v->centerW=0;
  98003. else
  98004. v->centerW=n1;
  98005. if(v->pcm_returned==-1){
  98006. v->pcm_returned=thisCenter;
  98007. v->pcm_current=thisCenter;
  98008. }else{
  98009. v->pcm_returned=prevCenter;
  98010. v->pcm_current=prevCenter+
  98011. ((ci->blocksizes[v->lW]/4+
  98012. ci->blocksizes[v->W]/4)>>hs);
  98013. }
  98014. }
  98015. if(b->sample_count==-1){
  98016. b->sample_count=0;
  98017. }else{
  98018. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98019. }
  98020. if(v->granulepos==-1){
  98021. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98022. v->granulepos=vb->granulepos;
  98023. if(b->sample_count>v->granulepos){
  98024. if(vb->eofflag){
  98025. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98026. }else{
  98027. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98028. if(v->pcm_returned>v->pcm_current)
  98029. v->pcm_returned=v->pcm_current;
  98030. }
  98031. }
  98032. }
  98033. }else{
  98034. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98035. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98036. if(v->granulepos>vb->granulepos){
  98037. long extra=v->granulepos-vb->granulepos;
  98038. if(extra)
  98039. if(vb->eofflag){
  98040. v->pcm_current-=extra>>hs;
  98041. } /* else {Shouldn't happen *unless* the bitstream is out of
  98042. spec. Either way, believe the bitstream } */
  98043. } /* else {Shouldn't happen *unless* the bitstream is out of
  98044. spec. Either way, believe the bitstream } */
  98045. v->granulepos=vb->granulepos;
  98046. }
  98047. }
  98048. if(vb->eofflag)v->eofflag=1;
  98049. return(0);
  98050. }
  98051. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98052. vorbis_info *vi=v->vi;
  98053. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98054. if(pcm){
  98055. int i;
  98056. for(i=0;i<vi->channels;i++)
  98057. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98058. *pcm=v->pcmret;
  98059. }
  98060. return(v->pcm_current-v->pcm_returned);
  98061. }
  98062. return(0);
  98063. }
  98064. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98065. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98066. v->pcm_returned+=n;
  98067. return(0);
  98068. }
  98069. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98070. vorbis_info *vi=v->vi;
  98071. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98072. int hs=ci->halfrate_flag;
  98073. int n=ci->blocksizes[v->W]>>(hs+1);
  98074. int n0=ci->blocksizes[0]>>(hs+1);
  98075. int n1=ci->blocksizes[1]>>(hs+1);
  98076. int i,j;
  98077. if(v->pcm_returned<0)return 0;
  98078. if(v->centerW==n1){
  98079. for(j=0;j<vi->channels;j++){
  98080. float *p=v->pcm[j];
  98081. for(i=0;i<n1;i++){
  98082. float temp=p[i];
  98083. p[i]=p[i+n1];
  98084. p[i+n1]=temp;
  98085. }
  98086. }
  98087. v->pcm_current-=n1;
  98088. v->pcm_returned-=n1;
  98089. v->centerW=0;
  98090. }
  98091. if((v->lW^v->W)==1){
  98092. for(j=0;j<vi->channels;j++){
  98093. float *s=v->pcm[j];
  98094. float *d=v->pcm[j]+(n1-n0)/2;
  98095. for(i=(n1+n0)/2-1;i>=0;--i)
  98096. d[i]=s[i];
  98097. }
  98098. v->pcm_returned+=(n1-n0)/2;
  98099. v->pcm_current+=(n1-n0)/2;
  98100. }else{
  98101. if(v->lW==0){
  98102. for(j=0;j<vi->channels;j++){
  98103. float *s=v->pcm[j];
  98104. float *d=v->pcm[j]+n1-n0;
  98105. for(i=n0-1;i>=0;--i)
  98106. d[i]=s[i];
  98107. }
  98108. v->pcm_returned+=n1-n0;
  98109. v->pcm_current+=n1-n0;
  98110. }
  98111. }
  98112. if(pcm){
  98113. int i;
  98114. for(i=0;i<vi->channels;i++)
  98115. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98116. *pcm=v->pcmret;
  98117. }
  98118. return(n1+n-v->pcm_returned);
  98119. }
  98120. float *vorbis_window(vorbis_dsp_state *v,int W){
  98121. vorbis_info *vi=v->vi;
  98122. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98123. int hs=ci->halfrate_flag;
  98124. private_state *b=(private_state*)v->backend_state;
  98125. if(b->window[W]-1<0)return NULL;
  98126. return _vorbis_window_get(b->window[W]-hs);
  98127. }
  98128. #endif
  98129. /*** End of inlined file: block.c ***/
  98130. /*** Start of inlined file: codebook.c ***/
  98131. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98132. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98133. // tasks..
  98134. #if JUCE_MSVC
  98135. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98136. #endif
  98137. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98138. #if JUCE_USE_OGGVORBIS
  98139. #include <stdlib.h>
  98140. #include <string.h>
  98141. #include <math.h>
  98142. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98143. long i,j;
  98144. int ordered=0;
  98145. oggpack_write(opb,0x564342,24);
  98146. oggpack_write(opb,c->dim,16);
  98147. oggpack_write(opb,c->entries,24);
  98148. for(i=1;i<c->entries;i++)
  98149. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98150. if(i==c->entries)ordered=1;
  98151. if(ordered){
  98152. long count=0;
  98153. oggpack_write(opb,1,1); /* ordered */
  98154. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98155. for(i=1;i<c->entries;i++){
  98156. long thisx=c->lengthlist[i];
  98157. long last=c->lengthlist[i-1];
  98158. if(thisx>last){
  98159. for(j=last;j<thisx;j++){
  98160. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98161. count=i;
  98162. }
  98163. }
  98164. }
  98165. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98166. }else{
  98167. oggpack_write(opb,0,1); /* unordered */
  98168. for(i=0;i<c->entries;i++)
  98169. if(c->lengthlist[i]==0)break;
  98170. if(i==c->entries){
  98171. oggpack_write(opb,0,1); /* no unused entries */
  98172. for(i=0;i<c->entries;i++)
  98173. oggpack_write(opb,c->lengthlist[i]-1,5);
  98174. }else{
  98175. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98176. for(i=0;i<c->entries;i++){
  98177. if(c->lengthlist[i]==0){
  98178. oggpack_write(opb,0,1);
  98179. }else{
  98180. oggpack_write(opb,1,1);
  98181. oggpack_write(opb,c->lengthlist[i]-1,5);
  98182. }
  98183. }
  98184. }
  98185. }
  98186. oggpack_write(opb,c->maptype,4);
  98187. switch(c->maptype){
  98188. case 0:
  98189. break;
  98190. case 1:case 2:
  98191. if(!c->quantlist){
  98192. return(-1);
  98193. }
  98194. oggpack_write(opb,c->q_min,32);
  98195. oggpack_write(opb,c->q_delta,32);
  98196. oggpack_write(opb,c->q_quant-1,4);
  98197. oggpack_write(opb,c->q_sequencep,1);
  98198. {
  98199. int quantvals;
  98200. switch(c->maptype){
  98201. case 1:
  98202. quantvals=_book_maptype1_quantvals(c);
  98203. break;
  98204. case 2:
  98205. quantvals=c->entries*c->dim;
  98206. break;
  98207. default: /* NOT_REACHABLE */
  98208. quantvals=-1;
  98209. }
  98210. for(i=0;i<quantvals;i++)
  98211. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98212. }
  98213. break;
  98214. default:
  98215. return(-1);
  98216. }
  98217. return(0);
  98218. }
  98219. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98220. long i,j;
  98221. memset(s,0,sizeof(*s));
  98222. s->allocedp=1;
  98223. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98224. s->dim=oggpack_read(opb,16);
  98225. s->entries=oggpack_read(opb,24);
  98226. if(s->entries==-1)goto _eofout;
  98227. switch((int)oggpack_read(opb,1)){
  98228. case 0:
  98229. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98230. if(oggpack_read(opb,1)){
  98231. for(i=0;i<s->entries;i++){
  98232. if(oggpack_read(opb,1)){
  98233. long num=oggpack_read(opb,5);
  98234. if(num==-1)goto _eofout;
  98235. s->lengthlist[i]=num+1;
  98236. }else
  98237. s->lengthlist[i]=0;
  98238. }
  98239. }else{
  98240. for(i=0;i<s->entries;i++){
  98241. long num=oggpack_read(opb,5);
  98242. if(num==-1)goto _eofout;
  98243. s->lengthlist[i]=num+1;
  98244. }
  98245. }
  98246. break;
  98247. case 1:
  98248. {
  98249. long length=oggpack_read(opb,5)+1;
  98250. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98251. for(i=0;i<s->entries;){
  98252. long num=oggpack_read(opb,_ilog(s->entries-i));
  98253. if(num==-1)goto _eofout;
  98254. for(j=0;j<num && i<s->entries;j++,i++)
  98255. s->lengthlist[i]=length;
  98256. length++;
  98257. }
  98258. }
  98259. break;
  98260. default:
  98261. return(-1);
  98262. }
  98263. switch((s->maptype=oggpack_read(opb,4))){
  98264. case 0:
  98265. break;
  98266. case 1: case 2:
  98267. s->q_min=oggpack_read(opb,32);
  98268. s->q_delta=oggpack_read(opb,32);
  98269. s->q_quant=oggpack_read(opb,4)+1;
  98270. s->q_sequencep=oggpack_read(opb,1);
  98271. {
  98272. int quantvals=0;
  98273. switch(s->maptype){
  98274. case 1:
  98275. quantvals=_book_maptype1_quantvals(s);
  98276. break;
  98277. case 2:
  98278. quantvals=s->entries*s->dim;
  98279. break;
  98280. }
  98281. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98282. for(i=0;i<quantvals;i++)
  98283. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98284. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98285. }
  98286. break;
  98287. default:
  98288. goto _errout;
  98289. }
  98290. return(0);
  98291. _errout:
  98292. _eofout:
  98293. vorbis_staticbook_clear(s);
  98294. return(-1);
  98295. }
  98296. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98297. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98298. return(book->c->lengthlist[a]);
  98299. }
  98300. int vorbis_book_errorv(codebook *book,float *a){
  98301. int dim=book->dim,k;
  98302. int best=_best(book,a,1);
  98303. for(k=0;k<dim;k++)
  98304. a[k]=(book->valuelist+best*dim)[k];
  98305. return(best);
  98306. }
  98307. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98308. int k,dim=book->dim;
  98309. for(k=0;k<dim;k++)
  98310. a[k]=(book->valuelist+best*dim)[k];
  98311. return(vorbis_book_encode(book,best,b));
  98312. }
  98313. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98314. int read=book->dec_maxlength;
  98315. long lo,hi;
  98316. long lok = oggpack_look(b,book->dec_firsttablen);
  98317. if (lok >= 0) {
  98318. long entry = book->dec_firsttable[lok];
  98319. if(entry&0x80000000UL){
  98320. lo=(entry>>15)&0x7fff;
  98321. hi=book->used_entries-(entry&0x7fff);
  98322. }else{
  98323. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98324. return(entry-1);
  98325. }
  98326. }else{
  98327. lo=0;
  98328. hi=book->used_entries;
  98329. }
  98330. lok = oggpack_look(b, read);
  98331. while(lok<0 && read>1)
  98332. lok = oggpack_look(b, --read);
  98333. if(lok<0)return -1;
  98334. {
  98335. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98336. while(hi-lo>1){
  98337. long p=(hi-lo)>>1;
  98338. long test=book->codelist[lo+p]>testword;
  98339. lo+=p&(test-1);
  98340. hi-=p&(-test);
  98341. }
  98342. if(book->dec_codelengths[lo]<=read){
  98343. oggpack_adv(b, book->dec_codelengths[lo]);
  98344. return(lo);
  98345. }
  98346. }
  98347. oggpack_adv(b, read);
  98348. return(-1);
  98349. }
  98350. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98351. long packed_entry=decode_packed_entry_number(book,b);
  98352. if(packed_entry>=0)
  98353. return(book->dec_index[packed_entry]);
  98354. return(packed_entry);
  98355. }
  98356. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98357. int step=n/book->dim;
  98358. long *entry = (long*)alloca(sizeof(*entry)*step);
  98359. float **t = (float**)alloca(sizeof(*t)*step);
  98360. int i,j,o;
  98361. for (i = 0; i < step; i++) {
  98362. entry[i]=decode_packed_entry_number(book,b);
  98363. if(entry[i]==-1)return(-1);
  98364. t[i] = book->valuelist+entry[i]*book->dim;
  98365. }
  98366. for(i=0,o=0;i<book->dim;i++,o+=step)
  98367. for (j=0;j<step;j++)
  98368. a[o+j]+=t[j][i];
  98369. return(0);
  98370. }
  98371. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98372. int i,j,entry;
  98373. float *t;
  98374. if(book->dim>8){
  98375. for(i=0;i<n;){
  98376. entry = decode_packed_entry_number(book,b);
  98377. if(entry==-1)return(-1);
  98378. t = book->valuelist+entry*book->dim;
  98379. for (j=0;j<book->dim;)
  98380. a[i++]+=t[j++];
  98381. }
  98382. }else{
  98383. for(i=0;i<n;){
  98384. entry = decode_packed_entry_number(book,b);
  98385. if(entry==-1)return(-1);
  98386. t = book->valuelist+entry*book->dim;
  98387. j=0;
  98388. switch((int)book->dim){
  98389. case 8:
  98390. a[i++]+=t[j++];
  98391. case 7:
  98392. a[i++]+=t[j++];
  98393. case 6:
  98394. a[i++]+=t[j++];
  98395. case 5:
  98396. a[i++]+=t[j++];
  98397. case 4:
  98398. a[i++]+=t[j++];
  98399. case 3:
  98400. a[i++]+=t[j++];
  98401. case 2:
  98402. a[i++]+=t[j++];
  98403. case 1:
  98404. a[i++]+=t[j++];
  98405. case 0:
  98406. break;
  98407. }
  98408. }
  98409. }
  98410. return(0);
  98411. }
  98412. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98413. int i,j,entry;
  98414. float *t;
  98415. for(i=0;i<n;){
  98416. entry = decode_packed_entry_number(book,b);
  98417. if(entry==-1)return(-1);
  98418. t = book->valuelist+entry*book->dim;
  98419. for (j=0;j<book->dim;)
  98420. a[i++]=t[j++];
  98421. }
  98422. return(0);
  98423. }
  98424. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98425. oggpack_buffer *b,int n){
  98426. long i,j,entry;
  98427. int chptr=0;
  98428. for(i=offset/ch;i<(offset+n)/ch;){
  98429. entry = decode_packed_entry_number(book,b);
  98430. if(entry==-1)return(-1);
  98431. {
  98432. const float *t = book->valuelist+entry*book->dim;
  98433. for (j=0;j<book->dim;j++){
  98434. a[chptr++][i]+=t[j];
  98435. if(chptr==ch){
  98436. chptr=0;
  98437. i++;
  98438. }
  98439. }
  98440. }
  98441. }
  98442. return(0);
  98443. }
  98444. #ifdef _V_SELFTEST
  98445. #include <stdio.h>
  98446. #include "vorbis/book/lsp20_0.vqh"
  98447. #include "vorbis/book/res0a_13.vqh"
  98448. #define TESTSIZE 40
  98449. float test1[TESTSIZE]={
  98450. 0.105939f,
  98451. 0.215373f,
  98452. 0.429117f,
  98453. 0.587974f,
  98454. 0.181173f,
  98455. 0.296583f,
  98456. 0.515707f,
  98457. 0.715261f,
  98458. 0.162327f,
  98459. 0.263834f,
  98460. 0.342876f,
  98461. 0.406025f,
  98462. 0.103571f,
  98463. 0.223561f,
  98464. 0.368513f,
  98465. 0.540313f,
  98466. 0.136672f,
  98467. 0.395882f,
  98468. 0.587183f,
  98469. 0.652476f,
  98470. 0.114338f,
  98471. 0.417300f,
  98472. 0.525486f,
  98473. 0.698679f,
  98474. 0.147492f,
  98475. 0.324481f,
  98476. 0.643089f,
  98477. 0.757582f,
  98478. 0.139556f,
  98479. 0.215795f,
  98480. 0.324559f,
  98481. 0.399387f,
  98482. 0.120236f,
  98483. 0.267420f,
  98484. 0.446940f,
  98485. 0.608760f,
  98486. 0.115587f,
  98487. 0.287234f,
  98488. 0.571081f,
  98489. 0.708603f,
  98490. };
  98491. float test3[TESTSIZE]={
  98492. 0,1,-2,3,4,-5,6,7,8,9,
  98493. 8,-2,7,-1,4,6,8,3,1,-9,
  98494. 10,11,12,13,14,15,26,17,18,19,
  98495. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98496. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98497. &_vq_book_res0a_13,NULL};
  98498. float *testvec[]={test1,test3};
  98499. int main(){
  98500. oggpack_buffer write;
  98501. oggpack_buffer read;
  98502. long ptr=0,i;
  98503. oggpack_writeinit(&write);
  98504. fprintf(stderr,"Testing codebook abstraction...:\n");
  98505. while(testlist[ptr]){
  98506. codebook c;
  98507. static_codebook s;
  98508. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  98509. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  98510. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  98511. memset(iv,0,sizeof(*iv)*TESTSIZE);
  98512. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  98513. oggpack_reset(&write);
  98514. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  98515. we can write */
  98516. vorbis_staticbook_pack(testlist[ptr],&write);
  98517. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  98518. for(i=0;i<TESTSIZE;i+=c.dim){
  98519. int best=_best(&c,qv+i,1);
  98520. vorbis_book_encodev(&c,best,qv+i,&write);
  98521. }
  98522. vorbis_book_clear(&c);
  98523. fprintf(stderr,"OK.\n");
  98524. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  98525. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  98526. if(vorbis_staticbook_unpack(&read,&s)){
  98527. fprintf(stderr,"Error unpacking codebook.\n");
  98528. exit(1);
  98529. }
  98530. if(vorbis_book_init_decode(&c,&s)){
  98531. fprintf(stderr,"Error initializing codebook.\n");
  98532. exit(1);
  98533. }
  98534. for(i=0;i<TESTSIZE;i+=c.dim)
  98535. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  98536. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  98537. exit(1);
  98538. }
  98539. for(i=0;i<TESTSIZE;i++)
  98540. if(fabs(qv[i]-iv[i])>.000001){
  98541. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  98542. iv[i],qv[i],i);
  98543. exit(1);
  98544. }
  98545. fprintf(stderr,"OK\n");
  98546. ptr++;
  98547. }
  98548. exit(0);
  98549. }
  98550. #endif
  98551. #endif
  98552. /*** End of inlined file: codebook.c ***/
  98553. /*** Start of inlined file: envelope.c ***/
  98554. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98555. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98556. // tasks..
  98557. #if JUCE_MSVC
  98558. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98559. #endif
  98560. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98561. #if JUCE_USE_OGGVORBIS
  98562. #include <stdlib.h>
  98563. #include <string.h>
  98564. #include <stdio.h>
  98565. #include <math.h>
  98566. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  98567. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98568. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98569. int ch=vi->channels;
  98570. int i,j;
  98571. int n=e->winlength=128;
  98572. e->searchstep=64; /* not random */
  98573. e->minenergy=gi->preecho_minenergy;
  98574. e->ch=ch;
  98575. e->storage=128;
  98576. e->cursor=ci->blocksizes[1]/2;
  98577. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  98578. mdct_init(&e->mdct,n);
  98579. for(i=0;i<n;i++){
  98580. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  98581. e->mdct_win[i]*=e->mdct_win[i];
  98582. }
  98583. e->band[0].begin=2; e->band[0].end=4;
  98584. e->band[1].begin=4; e->band[1].end=5;
  98585. e->band[2].begin=6; e->band[2].end=6;
  98586. e->band[3].begin=9; e->band[3].end=8;
  98587. e->band[4].begin=13; e->band[4].end=8;
  98588. e->band[5].begin=17; e->band[5].end=8;
  98589. e->band[6].begin=22; e->band[6].end=8;
  98590. for(j=0;j<VE_BANDS;j++){
  98591. n=e->band[j].end;
  98592. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  98593. for(i=0;i<n;i++){
  98594. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  98595. e->band[j].total+=e->band[j].window[i];
  98596. }
  98597. e->band[j].total=1./e->band[j].total;
  98598. }
  98599. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  98600. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  98601. }
  98602. void _ve_envelope_clear(envelope_lookup *e){
  98603. int i;
  98604. mdct_clear(&e->mdct);
  98605. for(i=0;i<VE_BANDS;i++)
  98606. _ogg_free(e->band[i].window);
  98607. _ogg_free(e->mdct_win);
  98608. _ogg_free(e->filter);
  98609. _ogg_free(e->mark);
  98610. memset(e,0,sizeof(*e));
  98611. }
  98612. static int _ve_amp(envelope_lookup *ve,
  98613. vorbis_info_psy_global *gi,
  98614. float *data,
  98615. envelope_band *bands,
  98616. envelope_filter_state *filters,
  98617. long pos){
  98618. long n=ve->winlength;
  98619. int ret=0;
  98620. long i,j;
  98621. float decay;
  98622. float minV=ve->minenergy;
  98623. float *vec=(float*) alloca(n*sizeof(*vec));
  98624. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  98625. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  98626. if(penalty<0.f)penalty=0.f;
  98627. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  98628. for(i=0;i<n;i++)
  98629. vec[i]=data[i]*ve->mdct_win[i];
  98630. mdct_forward(&ve->mdct,vec,vec);
  98631. {
  98632. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  98633. int ptr=filters->nearptr;
  98634. if(ptr==0){
  98635. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  98636. filters->nearDC_partialacc=temp;
  98637. }else{
  98638. decay=filters->nearDC_acc+=temp;
  98639. filters->nearDC_partialacc+=temp;
  98640. }
  98641. filters->nearDC_acc-=filters->nearDC[ptr];
  98642. filters->nearDC[ptr]=temp;
  98643. decay*=(1./(VE_NEARDC+1));
  98644. filters->nearptr++;
  98645. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  98646. decay=todB(&decay)*.5-15.f;
  98647. }
  98648. for(i=0;i<n/2;i+=2){
  98649. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  98650. val=todB(&val)*.5f;
  98651. if(val<decay)val=decay;
  98652. if(val<minV)val=minV;
  98653. vec[i>>1]=val;
  98654. decay-=8.;
  98655. }
  98656. for(j=0;j<VE_BANDS;j++){
  98657. float acc=0.;
  98658. float valmax,valmin;
  98659. for(i=0;i<bands[j].end;i++)
  98660. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  98661. acc*=bands[j].total;
  98662. {
  98663. int p,thisx=filters[j].ampptr;
  98664. float postmax,postmin,premax=-99999.f,premin=99999.f;
  98665. p=thisx;
  98666. p--;
  98667. if(p<0)p+=VE_AMP;
  98668. postmax=max(acc,filters[j].ampbuf[p]);
  98669. postmin=min(acc,filters[j].ampbuf[p]);
  98670. for(i=0;i<stretch;i++){
  98671. p--;
  98672. if(p<0)p+=VE_AMP;
  98673. premax=max(premax,filters[j].ampbuf[p]);
  98674. premin=min(premin,filters[j].ampbuf[p]);
  98675. }
  98676. valmin=postmin-premin;
  98677. valmax=postmax-premax;
  98678. filters[j].ampbuf[thisx]=acc;
  98679. filters[j].ampptr++;
  98680. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  98681. }
  98682. if(valmax>gi->preecho_thresh[j]+penalty){
  98683. ret|=1;
  98684. ret|=4;
  98685. }
  98686. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  98687. }
  98688. return(ret);
  98689. }
  98690. #if 0
  98691. static int seq=0;
  98692. static ogg_int64_t totalshift=-1024;
  98693. #endif
  98694. long _ve_envelope_search(vorbis_dsp_state *v){
  98695. vorbis_info *vi=v->vi;
  98696. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98697. vorbis_info_psy_global *gi=&ci->psy_g_param;
  98698. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98699. long i,j;
  98700. int first=ve->current/ve->searchstep;
  98701. int last=v->pcm_current/ve->searchstep-VE_WIN;
  98702. if(first<0)first=0;
  98703. if(last+VE_WIN+VE_POST>ve->storage){
  98704. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  98705. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  98706. }
  98707. for(j=first;j<last;j++){
  98708. int ret=0;
  98709. ve->stretch++;
  98710. if(ve->stretch>VE_MAXSTRETCH*2)
  98711. ve->stretch=VE_MAXSTRETCH*2;
  98712. for(i=0;i<ve->ch;i++){
  98713. float *pcm=v->pcm[i]+ve->searchstep*(j);
  98714. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  98715. }
  98716. ve->mark[j+VE_POST]=0;
  98717. if(ret&1){
  98718. ve->mark[j]=1;
  98719. ve->mark[j+1]=1;
  98720. }
  98721. if(ret&2){
  98722. ve->mark[j]=1;
  98723. if(j>0)ve->mark[j-1]=1;
  98724. }
  98725. if(ret&4)ve->stretch=-1;
  98726. }
  98727. ve->current=last*ve->searchstep;
  98728. {
  98729. long centerW=v->centerW;
  98730. long testW=
  98731. centerW+
  98732. ci->blocksizes[v->W]/4+
  98733. ci->blocksizes[1]/2+
  98734. ci->blocksizes[0]/4;
  98735. j=ve->cursor;
  98736. while(j<ve->current-(ve->searchstep)){/* account for postecho
  98737. working back one window */
  98738. if(j>=testW)return(1);
  98739. ve->cursor=j;
  98740. if(ve->mark[j/ve->searchstep]){
  98741. if(j>centerW){
  98742. #if 0
  98743. if(j>ve->curmark){
  98744. float *marker=alloca(v->pcm_current*sizeof(*marker));
  98745. int l,m;
  98746. memset(marker,0,sizeof(*marker)*v->pcm_current);
  98747. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  98748. seq,
  98749. (totalshift+ve->cursor)/44100.,
  98750. (totalshift+j)/44100.);
  98751. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  98752. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  98753. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  98754. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  98755. for(m=0;m<VE_BANDS;m++){
  98756. char buf[80];
  98757. sprintf(buf,"delL%d",m);
  98758. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  98759. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98760. }
  98761. for(m=0;m<VE_BANDS;m++){
  98762. char buf[80];
  98763. sprintf(buf,"delR%d",m);
  98764. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  98765. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  98766. }
  98767. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  98768. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  98769. seq++;
  98770. }
  98771. #endif
  98772. ve->curmark=j;
  98773. if(j>=testW)return(1);
  98774. return(0);
  98775. }
  98776. }
  98777. j+=ve->searchstep;
  98778. }
  98779. }
  98780. return(-1);
  98781. }
  98782. int _ve_envelope_mark(vorbis_dsp_state *v){
  98783. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  98784. vorbis_info *vi=v->vi;
  98785. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98786. long centerW=v->centerW;
  98787. long beginW=centerW-ci->blocksizes[v->W]/4;
  98788. long endW=centerW+ci->blocksizes[v->W]/4;
  98789. if(v->W){
  98790. beginW-=ci->blocksizes[v->lW]/4;
  98791. endW+=ci->blocksizes[v->nW]/4;
  98792. }else{
  98793. beginW-=ci->blocksizes[0]/4;
  98794. endW+=ci->blocksizes[0]/4;
  98795. }
  98796. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  98797. {
  98798. long first=beginW/ve->searchstep;
  98799. long last=endW/ve->searchstep;
  98800. long i;
  98801. for(i=first;i<last;i++)
  98802. if(ve->mark[i])return(1);
  98803. }
  98804. return(0);
  98805. }
  98806. void _ve_envelope_shift(envelope_lookup *e,long shift){
  98807. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  98808. ahead of ve->current */
  98809. int smallshift=shift/e->searchstep;
  98810. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  98811. #if 0
  98812. for(i=0;i<VE_BANDS*e->ch;i++)
  98813. memmove(e->filter[i].markers,
  98814. e->filter[i].markers+smallshift,
  98815. (1024-smallshift)*sizeof(*(*e->filter).markers));
  98816. totalshift+=shift;
  98817. #endif
  98818. e->current-=shift;
  98819. if(e->curmark>=0)
  98820. e->curmark-=shift;
  98821. e->cursor-=shift;
  98822. }
  98823. #endif
  98824. /*** End of inlined file: envelope.c ***/
  98825. /*** Start of inlined file: floor0.c ***/
  98826. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98827. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98828. // tasks..
  98829. #if JUCE_MSVC
  98830. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98831. #endif
  98832. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98833. #if JUCE_USE_OGGVORBIS
  98834. #include <stdlib.h>
  98835. #include <string.h>
  98836. #include <math.h>
  98837. /*** Start of inlined file: lsp.h ***/
  98838. #ifndef _V_LSP_H_
  98839. #define _V_LSP_H_
  98840. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  98841. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  98842. float *lsp,int m,
  98843. float amp,float ampoffset);
  98844. #endif
  98845. /*** End of inlined file: lsp.h ***/
  98846. #include <stdio.h>
  98847. typedef struct {
  98848. int ln;
  98849. int m;
  98850. int **linearmap;
  98851. int n[2];
  98852. vorbis_info_floor0 *vi;
  98853. long bits;
  98854. long frames;
  98855. } vorbis_look_floor0;
  98856. static void floor0_free_info(vorbis_info_floor *i){
  98857. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  98858. if(info){
  98859. memset(info,0,sizeof(*info));
  98860. _ogg_free(info);
  98861. }
  98862. }
  98863. static void floor0_free_look(vorbis_look_floor *i){
  98864. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98865. if(look){
  98866. if(look->linearmap){
  98867. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  98868. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  98869. _ogg_free(look->linearmap);
  98870. }
  98871. memset(look,0,sizeof(*look));
  98872. _ogg_free(look);
  98873. }
  98874. }
  98875. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  98876. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98877. int j;
  98878. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  98879. info->order=oggpack_read(opb,8);
  98880. info->rate=oggpack_read(opb,16);
  98881. info->barkmap=oggpack_read(opb,16);
  98882. info->ampbits=oggpack_read(opb,6);
  98883. info->ampdB=oggpack_read(opb,8);
  98884. info->numbooks=oggpack_read(opb,4)+1;
  98885. if(info->order<1)goto err_out;
  98886. if(info->rate<1)goto err_out;
  98887. if(info->barkmap<1)goto err_out;
  98888. if(info->numbooks<1)goto err_out;
  98889. for(j=0;j<info->numbooks;j++){
  98890. info->books[j]=oggpack_read(opb,8);
  98891. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  98892. }
  98893. return(info);
  98894. err_out:
  98895. floor0_free_info(info);
  98896. return(NULL);
  98897. }
  98898. static void floor0_map_lazy_init(vorbis_block *vb,
  98899. vorbis_info_floor *infoX,
  98900. vorbis_look_floor0 *look){
  98901. if(!look->linearmap[vb->W]){
  98902. vorbis_dsp_state *vd=vb->vd;
  98903. vorbis_info *vi=vd->vi;
  98904. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98905. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  98906. int W=vb->W;
  98907. int n=ci->blocksizes[W]/2,j;
  98908. float scale=look->ln/toBARK(info->rate/2.f);
  98909. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  98910. for(j=0;j<n;j++){
  98911. int val=floor( toBARK((info->rate/2.f)/n*j)
  98912. *scale); /* bark numbers represent band edges */
  98913. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  98914. look->linearmap[W][j]=val;
  98915. }
  98916. look->linearmap[W][j]=-1;
  98917. look->n[W]=n;
  98918. }
  98919. }
  98920. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  98921. vorbis_info_floor *i){
  98922. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  98923. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  98924. look->m=info->order;
  98925. look->ln=info->barkmap;
  98926. look->vi=info;
  98927. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  98928. return look;
  98929. }
  98930. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  98931. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98932. vorbis_info_floor0 *info=look->vi;
  98933. int j,k;
  98934. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  98935. if(ampraw>0){ /* also handles the -1 out of data case */
  98936. long maxval=(1<<info->ampbits)-1;
  98937. float amp=(float)ampraw/maxval*info->ampdB;
  98938. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  98939. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  98940. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  98941. codebook *b=ci->fullbooks+info->books[booknum];
  98942. float last=0.f;
  98943. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  98944. for(j=0;j<look->m;j+=b->dim)
  98945. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  98946. for(j=0;j<look->m;){
  98947. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  98948. last=lsp[j-1];
  98949. }
  98950. lsp[look->m]=amp;
  98951. return(lsp);
  98952. }
  98953. }
  98954. eop:
  98955. return(NULL);
  98956. }
  98957. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  98958. void *memo,float *out){
  98959. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  98960. vorbis_info_floor0 *info=look->vi;
  98961. floor0_map_lazy_init(vb,info,look);
  98962. if(memo){
  98963. float *lsp=(float *)memo;
  98964. float amp=lsp[look->m];
  98965. vorbis_lsp_to_curve(out,
  98966. look->linearmap[vb->W],
  98967. look->n[vb->W],
  98968. look->ln,
  98969. lsp,look->m,amp,(float)info->ampdB);
  98970. return(1);
  98971. }
  98972. memset(out,0,sizeof(*out)*look->n[vb->W]);
  98973. return(0);
  98974. }
  98975. vorbis_func_floor floor0_exportbundle={
  98976. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  98977. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  98978. };
  98979. #endif
  98980. /*** End of inlined file: floor0.c ***/
  98981. /*** Start of inlined file: floor1.c ***/
  98982. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98983. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98984. // tasks..
  98985. #if JUCE_MSVC
  98986. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98987. #endif
  98988. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98989. #if JUCE_USE_OGGVORBIS
  98990. #include <stdlib.h>
  98991. #include <string.h>
  98992. #include <math.h>
  98993. #include <stdio.h>
  98994. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  98995. typedef struct {
  98996. int sorted_index[VIF_POSIT+2];
  98997. int forward_index[VIF_POSIT+2];
  98998. int reverse_index[VIF_POSIT+2];
  98999. int hineighbor[VIF_POSIT];
  99000. int loneighbor[VIF_POSIT];
  99001. int posts;
  99002. int n;
  99003. int quant_q;
  99004. vorbis_info_floor1 *vi;
  99005. long phrasebits;
  99006. long postbits;
  99007. long frames;
  99008. } vorbis_look_floor1;
  99009. typedef struct lsfit_acc{
  99010. long x0;
  99011. long x1;
  99012. long xa;
  99013. long ya;
  99014. long x2a;
  99015. long y2a;
  99016. long xya;
  99017. long an;
  99018. } lsfit_acc;
  99019. static void floor1_free_info(vorbis_info_floor *i){
  99020. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99021. if(info){
  99022. memset(info,0,sizeof(*info));
  99023. _ogg_free(info);
  99024. }
  99025. }
  99026. static void floor1_free_look(vorbis_look_floor *i){
  99027. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99028. if(look){
  99029. memset(look,0,sizeof(*look));
  99030. _ogg_free(look);
  99031. }
  99032. }
  99033. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99034. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99035. int j,k;
  99036. int count=0;
  99037. int rangebits;
  99038. int maxposit=info->postlist[1];
  99039. int maxclass=-1;
  99040. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99041. for(j=0;j<info->partitions;j++){
  99042. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99043. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99044. }
  99045. for(j=0;j<maxclass+1;j++){
  99046. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99047. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99048. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99049. for(k=0;k<(1<<info->class_subs[j]);k++)
  99050. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99051. }
  99052. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99053. oggpack_write(opb,ilog2(maxposit),4);
  99054. rangebits=ilog2(maxposit);
  99055. for(j=0,k=0;j<info->partitions;j++){
  99056. count+=info->class_dim[info->partitionclass[j]];
  99057. for(;k<count;k++)
  99058. oggpack_write(opb,info->postlist[k+2],rangebits);
  99059. }
  99060. }
  99061. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99062. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99063. int j,k,count=0,maxclass=-1,rangebits;
  99064. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99065. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99066. for(j=0;j<info->partitions;j++){
  99067. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99068. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99069. }
  99070. for(j=0;j<maxclass+1;j++){
  99071. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99072. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99073. if(info->class_subs[j]<0)
  99074. goto err_out;
  99075. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99076. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99077. goto err_out;
  99078. for(k=0;k<(1<<info->class_subs[j]);k++){
  99079. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99080. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99081. goto err_out;
  99082. }
  99083. }
  99084. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99085. rangebits=oggpack_read(opb,4);
  99086. for(j=0,k=0;j<info->partitions;j++){
  99087. count+=info->class_dim[info->partitionclass[j]];
  99088. for(;k<count;k++){
  99089. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99090. if(t<0 || t>=(1<<rangebits))
  99091. goto err_out;
  99092. }
  99093. }
  99094. info->postlist[0]=0;
  99095. info->postlist[1]=1<<rangebits;
  99096. return(info);
  99097. err_out:
  99098. floor1_free_info(info);
  99099. return(NULL);
  99100. }
  99101. static int icomp(const void *a,const void *b){
  99102. return(**(int **)a-**(int **)b);
  99103. }
  99104. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99105. vorbis_info_floor *in){
  99106. int *sortpointer[VIF_POSIT+2];
  99107. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99108. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99109. int i,j,n=0;
  99110. look->vi=info;
  99111. look->n=info->postlist[1];
  99112. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99113. n+=2;
  99114. look->posts=n;
  99115. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99116. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99117. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99118. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99119. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99120. switch(info->mult){
  99121. case 1: /* 1024 -> 256 */
  99122. look->quant_q=256;
  99123. break;
  99124. case 2: /* 1024 -> 128 */
  99125. look->quant_q=128;
  99126. break;
  99127. case 3: /* 1024 -> 86 */
  99128. look->quant_q=86;
  99129. break;
  99130. case 4: /* 1024 -> 64 */
  99131. look->quant_q=64;
  99132. break;
  99133. }
  99134. for(i=0;i<n-2;i++){
  99135. int lo=0;
  99136. int hi=1;
  99137. int lx=0;
  99138. int hx=look->n;
  99139. int currentx=info->postlist[i+2];
  99140. for(j=0;j<i+2;j++){
  99141. int x=info->postlist[j];
  99142. if(x>lx && x<currentx){
  99143. lo=j;
  99144. lx=x;
  99145. }
  99146. if(x<hx && x>currentx){
  99147. hi=j;
  99148. hx=x;
  99149. }
  99150. }
  99151. look->loneighbor[i]=lo;
  99152. look->hineighbor[i]=hi;
  99153. }
  99154. return(look);
  99155. }
  99156. static int render_point(int x0,int x1,int y0,int y1,int x){
  99157. y0&=0x7fff; /* mask off flag */
  99158. y1&=0x7fff;
  99159. {
  99160. int dy=y1-y0;
  99161. int adx=x1-x0;
  99162. int ady=abs(dy);
  99163. int err=ady*(x-x0);
  99164. int off=err/adx;
  99165. if(dy<0)return(y0-off);
  99166. return(y0+off);
  99167. }
  99168. }
  99169. static int vorbis_dBquant(const float *x){
  99170. int i= *x*7.3142857f+1023.5f;
  99171. if(i>1023)return(1023);
  99172. if(i<0)return(0);
  99173. return i;
  99174. }
  99175. static float FLOOR1_fromdB_LOOKUP[256]={
  99176. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99177. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99178. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99179. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99180. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99181. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99182. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99183. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99184. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99185. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99186. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99187. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99188. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99189. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99190. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99191. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99192. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99193. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99194. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99195. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99196. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99197. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99198. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99199. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99200. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99201. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99202. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99203. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99204. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99205. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99206. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99207. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99208. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99209. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99210. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99211. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99212. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99213. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99214. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99215. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99216. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99217. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99218. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99219. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99220. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99221. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99222. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99223. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99224. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99225. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99226. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99227. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99228. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99229. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99230. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99231. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99232. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99233. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99234. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99235. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99236. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99237. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99238. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99239. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99240. };
  99241. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99242. int dy=y1-y0;
  99243. int adx=x1-x0;
  99244. int ady=abs(dy);
  99245. int base=dy/adx;
  99246. int sy=(dy<0?base-1:base+1);
  99247. int x=x0;
  99248. int y=y0;
  99249. int err=0;
  99250. ady-=abs(base*adx);
  99251. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99252. while(++x<x1){
  99253. err=err+ady;
  99254. if(err>=adx){
  99255. err-=adx;
  99256. y+=sy;
  99257. }else{
  99258. y+=base;
  99259. }
  99260. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99261. }
  99262. }
  99263. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99264. int dy=y1-y0;
  99265. int adx=x1-x0;
  99266. int ady=abs(dy);
  99267. int base=dy/adx;
  99268. int sy=(dy<0?base-1:base+1);
  99269. int x=x0;
  99270. int y=y0;
  99271. int err=0;
  99272. ady-=abs(base*adx);
  99273. d[x]=y;
  99274. while(++x<x1){
  99275. err=err+ady;
  99276. if(err>=adx){
  99277. err-=adx;
  99278. y+=sy;
  99279. }else{
  99280. y+=base;
  99281. }
  99282. d[x]=y;
  99283. }
  99284. }
  99285. static int accumulate_fit(const float *flr,const float *mdct,
  99286. int x0, int x1,lsfit_acc *a,
  99287. int n,vorbis_info_floor1 *info){
  99288. long i;
  99289. 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;
  99290. memset(a,0,sizeof(*a));
  99291. a->x0=x0;
  99292. a->x1=x1;
  99293. if(x1>=n)x1=n-1;
  99294. for(i=x0;i<=x1;i++){
  99295. int quantized=vorbis_dBquant(flr+i);
  99296. if(quantized){
  99297. if(mdct[i]+info->twofitatten>=flr[i]){
  99298. xa += i;
  99299. ya += quantized;
  99300. x2a += i*i;
  99301. y2a += quantized*quantized;
  99302. xya += i*quantized;
  99303. na++;
  99304. }else{
  99305. xb += i;
  99306. yb += quantized;
  99307. x2b += i*i;
  99308. y2b += quantized*quantized;
  99309. xyb += i*quantized;
  99310. nb++;
  99311. }
  99312. }
  99313. }
  99314. xb+=xa;
  99315. yb+=ya;
  99316. x2b+=x2a;
  99317. y2b+=y2a;
  99318. xyb+=xya;
  99319. nb+=na;
  99320. {
  99321. int weight=nb*info->twofitweight/(na+1);
  99322. a->xa=xa*weight+xb;
  99323. a->ya=ya*weight+yb;
  99324. a->x2a=x2a*weight+x2b;
  99325. a->y2a=y2a*weight+y2b;
  99326. a->xya=xya*weight+xyb;
  99327. a->an=na*weight+nb;
  99328. }
  99329. return(na);
  99330. }
  99331. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99332. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99333. long x0=a[0].x0;
  99334. long x1=a[fits-1].x1;
  99335. for(i=0;i<fits;i++){
  99336. x+=a[i].xa;
  99337. y+=a[i].ya;
  99338. x2+=a[i].x2a;
  99339. y2+=a[i].y2a;
  99340. xy+=a[i].xya;
  99341. an+=a[i].an;
  99342. }
  99343. if(*y0>=0){
  99344. x+= x0;
  99345. y+= *y0;
  99346. x2+= x0 * x0;
  99347. y2+= *y0 * *y0;
  99348. xy+= *y0 * x0;
  99349. an++;
  99350. }
  99351. if(*y1>=0){
  99352. x+= x1;
  99353. y+= *y1;
  99354. x2+= x1 * x1;
  99355. y2+= *y1 * *y1;
  99356. xy+= *y1 * x1;
  99357. an++;
  99358. }
  99359. if(an){
  99360. double fx=x;
  99361. double fy=y;
  99362. double fx2=x2;
  99363. double fxy=xy;
  99364. double denom=1./(an*fx2-fx*fx);
  99365. double a=(fy*fx2-fxy*fx)*denom;
  99366. double b=(an*fxy-fx*fy)*denom;
  99367. *y0=rint(a+b*x0);
  99368. *y1=rint(a+b*x1);
  99369. if(*y0>1023)*y0=1023;
  99370. if(*y1>1023)*y1=1023;
  99371. if(*y0<0)*y0=0;
  99372. if(*y1<0)*y1=0;
  99373. }else{
  99374. *y0=0;
  99375. *y1=0;
  99376. }
  99377. }
  99378. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99379. const float *mdct,
  99380. vorbis_info_floor1 *info){
  99381. int dy=y1-y0;
  99382. int adx=x1-x0;
  99383. int ady=abs(dy);
  99384. int base=dy/adx;
  99385. int sy=(dy<0?base-1:base+1);
  99386. int x=x0;
  99387. int y=y0;
  99388. int err=0;
  99389. int val=vorbis_dBquant(mask+x);
  99390. int mse=0;
  99391. int n=0;
  99392. ady-=abs(base*adx);
  99393. mse=(y-val);
  99394. mse*=mse;
  99395. n++;
  99396. if(mdct[x]+info->twofitatten>=mask[x]){
  99397. if(y+info->maxover<val)return(1);
  99398. if(y-info->maxunder>val)return(1);
  99399. }
  99400. while(++x<x1){
  99401. err=err+ady;
  99402. if(err>=adx){
  99403. err-=adx;
  99404. y+=sy;
  99405. }else{
  99406. y+=base;
  99407. }
  99408. val=vorbis_dBquant(mask+x);
  99409. mse+=((y-val)*(y-val));
  99410. n++;
  99411. if(mdct[x]+info->twofitatten>=mask[x]){
  99412. if(val){
  99413. if(y+info->maxover<val)return(1);
  99414. if(y-info->maxunder>val)return(1);
  99415. }
  99416. }
  99417. }
  99418. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99419. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99420. if(mse/n>info->maxerr)return(1);
  99421. return(0);
  99422. }
  99423. static int post_Y(int *A,int *B,int pos){
  99424. if(A[pos]<0)
  99425. return B[pos];
  99426. if(B[pos]<0)
  99427. return A[pos];
  99428. return (A[pos]+B[pos])>>1;
  99429. }
  99430. int *floor1_fit(vorbis_block *vb,void *look_,
  99431. const float *logmdct, /* in */
  99432. const float *logmask){
  99433. long i,j;
  99434. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99435. vorbis_info_floor1 *info=look->vi;
  99436. long n=look->n;
  99437. long posts=look->posts;
  99438. long nonzero=0;
  99439. lsfit_acc fits[VIF_POSIT+1];
  99440. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99441. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99442. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99443. int hineighbor[VIF_POSIT+2];
  99444. int *output=NULL;
  99445. int memo[VIF_POSIT+2];
  99446. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99447. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99448. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99449. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99450. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99451. if(posts==0){
  99452. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99453. }else{
  99454. for(i=0;i<posts-1;i++)
  99455. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99456. look->sorted_index[i+1],fits+i,
  99457. n,info);
  99458. }
  99459. if(nonzero){
  99460. int y0=-200;
  99461. int y1=-200;
  99462. fit_line(fits,posts-1,&y0,&y1);
  99463. fit_valueA[0]=y0;
  99464. fit_valueB[0]=y0;
  99465. fit_valueB[1]=y1;
  99466. fit_valueA[1]=y1;
  99467. for(i=2;i<posts;i++){
  99468. int sortpos=look->reverse_index[i];
  99469. int ln=loneighbor[sortpos];
  99470. int hn=hineighbor[sortpos];
  99471. if(memo[ln]!=hn){
  99472. int lsortpos=look->reverse_index[ln];
  99473. int hsortpos=look->reverse_index[hn];
  99474. memo[ln]=hn;
  99475. {
  99476. int lx=info->postlist[ln];
  99477. int hx=info->postlist[hn];
  99478. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99479. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99480. if(ly==-1 || hy==-1){
  99481. exit(1);
  99482. }
  99483. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99484. int ly0=-200;
  99485. int ly1=-200;
  99486. int hy0=-200;
  99487. int hy1=-200;
  99488. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99489. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99490. fit_valueB[ln]=ly0;
  99491. if(ln==0)fit_valueA[ln]=ly0;
  99492. fit_valueA[i]=ly1;
  99493. fit_valueB[i]=hy0;
  99494. fit_valueA[hn]=hy1;
  99495. if(hn==1)fit_valueB[hn]=hy1;
  99496. if(ly1>=0 || hy0>=0){
  99497. for(j=sortpos-1;j>=0;j--)
  99498. if(hineighbor[j]==hn)
  99499. hineighbor[j]=i;
  99500. else
  99501. break;
  99502. for(j=sortpos+1;j<posts;j++)
  99503. if(loneighbor[j]==ln)
  99504. loneighbor[j]=i;
  99505. else
  99506. break;
  99507. }
  99508. }else{
  99509. fit_valueA[i]=-200;
  99510. fit_valueB[i]=-200;
  99511. }
  99512. }
  99513. }
  99514. }
  99515. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99516. output[0]=post_Y(fit_valueA,fit_valueB,0);
  99517. output[1]=post_Y(fit_valueA,fit_valueB,1);
  99518. for(i=2;i<posts;i++){
  99519. int ln=look->loneighbor[i-2];
  99520. int hn=look->hineighbor[i-2];
  99521. int x0=info->postlist[ln];
  99522. int x1=info->postlist[hn];
  99523. int y0=output[ln];
  99524. int y1=output[hn];
  99525. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99526. int vx=post_Y(fit_valueA,fit_valueB,i);
  99527. if(vx>=0 && predicted!=vx){
  99528. output[i]=vx;
  99529. }else{
  99530. output[i]= predicted|0x8000;
  99531. }
  99532. }
  99533. }
  99534. return(output);
  99535. }
  99536. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  99537. int *A,int *B,
  99538. int del){
  99539. long i;
  99540. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  99541. long posts=look->posts;
  99542. int *output=NULL;
  99543. if(A && B){
  99544. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  99545. for(i=0;i<posts;i++){
  99546. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  99547. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  99548. }
  99549. }
  99550. return(output);
  99551. }
  99552. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  99553. void*look_,
  99554. int *post,int *ilogmask){
  99555. long i,j;
  99556. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  99557. vorbis_info_floor1 *info=look->vi;
  99558. long posts=look->posts;
  99559. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99560. int out[VIF_POSIT+2];
  99561. static_codebook **sbooks=ci->book_param;
  99562. codebook *books=ci->fullbooks;
  99563. static long seq=0;
  99564. if(post){
  99565. for(i=0;i<posts;i++){
  99566. int val=post[i]&0x7fff;
  99567. switch(info->mult){
  99568. case 1: /* 1024 -> 256 */
  99569. val>>=2;
  99570. break;
  99571. case 2: /* 1024 -> 128 */
  99572. val>>=3;
  99573. break;
  99574. case 3: /* 1024 -> 86 */
  99575. val/=12;
  99576. break;
  99577. case 4: /* 1024 -> 64 */
  99578. val>>=4;
  99579. break;
  99580. }
  99581. post[i]=val | (post[i]&0x8000);
  99582. }
  99583. out[0]=post[0];
  99584. out[1]=post[1];
  99585. for(i=2;i<posts;i++){
  99586. int ln=look->loneighbor[i-2];
  99587. int hn=look->hineighbor[i-2];
  99588. int x0=info->postlist[ln];
  99589. int x1=info->postlist[hn];
  99590. int y0=post[ln];
  99591. int y1=post[hn];
  99592. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  99593. if((post[i]&0x8000) || (predicted==post[i])){
  99594. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  99595. in interpolation */
  99596. out[i]=0;
  99597. }else{
  99598. int headroom=(look->quant_q-predicted<predicted?
  99599. look->quant_q-predicted:predicted);
  99600. int val=post[i]-predicted;
  99601. if(val<0)
  99602. if(val<-headroom)
  99603. val=headroom-val-1;
  99604. else
  99605. val=-1-(val<<1);
  99606. else
  99607. if(val>=headroom)
  99608. val= val+headroom;
  99609. else
  99610. val<<=1;
  99611. out[i]=val;
  99612. post[ln]&=0x7fff;
  99613. post[hn]&=0x7fff;
  99614. }
  99615. }
  99616. oggpack_write(opb,1,1);
  99617. look->frames++;
  99618. look->postbits+=ilog(look->quant_q-1)*2;
  99619. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  99620. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  99621. for(i=0,j=2;i<info->partitions;i++){
  99622. int classx=info->partitionclass[i];
  99623. int cdim=info->class_dim[classx];
  99624. int csubbits=info->class_subs[classx];
  99625. int csub=1<<csubbits;
  99626. int bookas[8]={0,0,0,0,0,0,0,0};
  99627. int cval=0;
  99628. int cshift=0;
  99629. int k,l;
  99630. if(csubbits){
  99631. int maxval[8];
  99632. for(k=0;k<csub;k++){
  99633. int booknum=info->class_subbook[classx][k];
  99634. if(booknum<0){
  99635. maxval[k]=1;
  99636. }else{
  99637. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  99638. }
  99639. }
  99640. for(k=0;k<cdim;k++){
  99641. for(l=0;l<csub;l++){
  99642. int val=out[j+k];
  99643. if(val<maxval[l]){
  99644. bookas[k]=l;
  99645. break;
  99646. }
  99647. }
  99648. cval|= bookas[k]<<cshift;
  99649. cshift+=csubbits;
  99650. }
  99651. look->phrasebits+=
  99652. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  99653. #ifdef TRAIN_FLOOR1
  99654. {
  99655. FILE *of;
  99656. char buffer[80];
  99657. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  99658. vb->pcmend/2,posts-2,class);
  99659. of=fopen(buffer,"a");
  99660. fprintf(of,"%d\n",cval);
  99661. fclose(of);
  99662. }
  99663. #endif
  99664. }
  99665. for(k=0;k<cdim;k++){
  99666. int book=info->class_subbook[classx][bookas[k]];
  99667. if(book>=0){
  99668. if(out[j+k]<(books+book)->entries)
  99669. look->postbits+=vorbis_book_encode(books+book,
  99670. out[j+k],opb);
  99671. #ifdef TRAIN_FLOOR1
  99672. {
  99673. FILE *of;
  99674. char buffer[80];
  99675. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  99676. vb->pcmend/2,posts-2,class,bookas[k]);
  99677. of=fopen(buffer,"a");
  99678. fprintf(of,"%d\n",out[j+k]);
  99679. fclose(of);
  99680. }
  99681. #endif
  99682. }
  99683. }
  99684. j+=cdim;
  99685. }
  99686. {
  99687. int hx=0;
  99688. int lx=0;
  99689. int ly=post[0]*info->mult;
  99690. for(j=1;j<look->posts;j++){
  99691. int current=look->forward_index[j];
  99692. int hy=post[current]&0x7fff;
  99693. if(hy==post[current]){
  99694. hy*=info->mult;
  99695. hx=info->postlist[current];
  99696. render_line0(lx,hx,ly,hy,ilogmask);
  99697. lx=hx;
  99698. ly=hy;
  99699. }
  99700. }
  99701. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  99702. seq++;
  99703. return(1);
  99704. }
  99705. }else{
  99706. oggpack_write(opb,0,1);
  99707. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  99708. seq++;
  99709. return(0);
  99710. }
  99711. }
  99712. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  99713. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99714. vorbis_info_floor1 *info=look->vi;
  99715. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99716. int i,j,k;
  99717. codebook *books=ci->fullbooks;
  99718. if(oggpack_read(&vb->opb,1)==1){
  99719. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  99720. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99721. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  99722. for(i=0,j=2;i<info->partitions;i++){
  99723. int classx=info->partitionclass[i];
  99724. int cdim=info->class_dim[classx];
  99725. int csubbits=info->class_subs[classx];
  99726. int csub=1<<csubbits;
  99727. int cval=0;
  99728. if(csubbits){
  99729. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  99730. if(cval==-1)goto eop;
  99731. }
  99732. for(k=0;k<cdim;k++){
  99733. int book=info->class_subbook[classx][cval&(csub-1)];
  99734. cval>>=csubbits;
  99735. if(book>=0){
  99736. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  99737. goto eop;
  99738. }else{
  99739. fit_value[j+k]=0;
  99740. }
  99741. }
  99742. j+=cdim;
  99743. }
  99744. for(i=2;i<look->posts;i++){
  99745. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  99746. info->postlist[look->hineighbor[i-2]],
  99747. fit_value[look->loneighbor[i-2]],
  99748. fit_value[look->hineighbor[i-2]],
  99749. info->postlist[i]);
  99750. int hiroom=look->quant_q-predicted;
  99751. int loroom=predicted;
  99752. int room=(hiroom<loroom?hiroom:loroom)<<1;
  99753. int val=fit_value[i];
  99754. if(val){
  99755. if(val>=room){
  99756. if(hiroom>loroom){
  99757. val = val-loroom;
  99758. }else{
  99759. val = -1-(val-hiroom);
  99760. }
  99761. }else{
  99762. if(val&1){
  99763. val= -((val+1)>>1);
  99764. }else{
  99765. val>>=1;
  99766. }
  99767. }
  99768. fit_value[i]=val+predicted;
  99769. fit_value[look->loneighbor[i-2]]&=0x7fff;
  99770. fit_value[look->hineighbor[i-2]]&=0x7fff;
  99771. }else{
  99772. fit_value[i]=predicted|0x8000;
  99773. }
  99774. }
  99775. return(fit_value);
  99776. }
  99777. eop:
  99778. return(NULL);
  99779. }
  99780. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  99781. float *out){
  99782. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  99783. vorbis_info_floor1 *info=look->vi;
  99784. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  99785. int n=ci->blocksizes[vb->W]/2;
  99786. int j;
  99787. if(memo){
  99788. int *fit_value=(int *)memo;
  99789. int hx=0;
  99790. int lx=0;
  99791. int ly=fit_value[0]*info->mult;
  99792. for(j=1;j<look->posts;j++){
  99793. int current=look->forward_index[j];
  99794. int hy=fit_value[current]&0x7fff;
  99795. if(hy==fit_value[current]){
  99796. hy*=info->mult;
  99797. hx=info->postlist[current];
  99798. render_line(lx,hx,ly,hy,out);
  99799. lx=hx;
  99800. ly=hy;
  99801. }
  99802. }
  99803. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  99804. return(1);
  99805. }
  99806. memset(out,0,sizeof(*out)*n);
  99807. return(0);
  99808. }
  99809. vorbis_func_floor floor1_exportbundle={
  99810. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  99811. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  99812. };
  99813. #endif
  99814. /*** End of inlined file: floor1.c ***/
  99815. /*** Start of inlined file: info.c ***/
  99816. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99817. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99818. // tasks..
  99819. #if JUCE_MSVC
  99820. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99821. #endif
  99822. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99823. #if JUCE_USE_OGGVORBIS
  99824. #include <stdlib.h>
  99825. #include <string.h>
  99826. #include <ctype.h>
  99827. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  99828. while(bytes--){
  99829. oggpack_write(o,*s++,8);
  99830. }
  99831. }
  99832. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  99833. while(bytes--){
  99834. *buf++=oggpack_read(o,8);
  99835. }
  99836. }
  99837. void vorbis_comment_init(vorbis_comment *vc){
  99838. memset(vc,0,sizeof(*vc));
  99839. }
  99840. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  99841. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  99842. (vc->comments+2)*sizeof(*vc->user_comments));
  99843. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  99844. (vc->comments+2)*sizeof(*vc->comment_lengths));
  99845. vc->comment_lengths[vc->comments]=strlen(comment);
  99846. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  99847. strcpy(vc->user_comments[vc->comments], comment);
  99848. vc->comments++;
  99849. vc->user_comments[vc->comments]=NULL;
  99850. }
  99851. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  99852. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  99853. strcpy(comment, tag);
  99854. strcat(comment, "=");
  99855. strcat(comment, contents);
  99856. vorbis_comment_add(vc, comment);
  99857. }
  99858. static int tagcompare(const char *s1, const char *s2, int n){
  99859. int c=0;
  99860. while(c < n){
  99861. if(toupper(s1[c]) != toupper(s2[c]))
  99862. return !0;
  99863. c++;
  99864. }
  99865. return 0;
  99866. }
  99867. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  99868. long i;
  99869. int found = 0;
  99870. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99871. char *fulltag = (char*)alloca(taglen+ 1);
  99872. strcpy(fulltag, tag);
  99873. strcat(fulltag, "=");
  99874. for(i=0;i<vc->comments;i++){
  99875. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  99876. if(count == found)
  99877. return vc->user_comments[i] + taglen;
  99878. else
  99879. found++;
  99880. }
  99881. }
  99882. return NULL; /* didn't find anything */
  99883. }
  99884. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  99885. int i,count=0;
  99886. int taglen = strlen(tag)+1; /* +1 for the = we append */
  99887. char *fulltag = (char*)alloca(taglen+1);
  99888. strcpy(fulltag,tag);
  99889. strcat(fulltag, "=");
  99890. for(i=0;i<vc->comments;i++){
  99891. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  99892. count++;
  99893. }
  99894. return count;
  99895. }
  99896. void vorbis_comment_clear(vorbis_comment *vc){
  99897. if(vc){
  99898. long i;
  99899. for(i=0;i<vc->comments;i++)
  99900. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  99901. if(vc->user_comments)_ogg_free(vc->user_comments);
  99902. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  99903. if(vc->vendor)_ogg_free(vc->vendor);
  99904. }
  99905. memset(vc,0,sizeof(*vc));
  99906. }
  99907. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  99908. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  99909. return ci ? ci->blocksizes[zo] : -1;
  99910. }
  99911. void vorbis_info_init(vorbis_info *vi){
  99912. memset(vi,0,sizeof(*vi));
  99913. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  99914. }
  99915. void vorbis_info_clear(vorbis_info *vi){
  99916. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99917. int i;
  99918. if(ci){
  99919. for(i=0;i<ci->modes;i++)
  99920. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  99921. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  99922. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  99923. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  99924. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  99925. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  99926. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  99927. for(i=0;i<ci->books;i++){
  99928. if(ci->book_param[i]){
  99929. vorbis_staticbook_destroy(ci->book_param[i]);
  99930. }
  99931. if(ci->fullbooks)
  99932. vorbis_book_clear(ci->fullbooks+i);
  99933. }
  99934. if(ci->fullbooks)
  99935. _ogg_free(ci->fullbooks);
  99936. for(i=0;i<ci->psys;i++)
  99937. _vi_psy_free(ci->psy_param[i]);
  99938. _ogg_free(ci);
  99939. }
  99940. memset(vi,0,sizeof(*vi));
  99941. }
  99942. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  99943. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99944. if(!ci)return(OV_EFAULT);
  99945. vi->version=oggpack_read(opb,32);
  99946. if(vi->version!=0)return(OV_EVERSION);
  99947. vi->channels=oggpack_read(opb,8);
  99948. vi->rate=oggpack_read(opb,32);
  99949. vi->bitrate_upper=oggpack_read(opb,32);
  99950. vi->bitrate_nominal=oggpack_read(opb,32);
  99951. vi->bitrate_lower=oggpack_read(opb,32);
  99952. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  99953. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  99954. if(vi->rate<1)goto err_out;
  99955. if(vi->channels<1)goto err_out;
  99956. if(ci->blocksizes[0]<8)goto err_out;
  99957. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  99958. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  99959. return(0);
  99960. err_out:
  99961. vorbis_info_clear(vi);
  99962. return(OV_EBADHEADER);
  99963. }
  99964. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  99965. int i;
  99966. int vendorlen=oggpack_read(opb,32);
  99967. if(vendorlen<0)goto err_out;
  99968. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  99969. _v_readstring(opb,vc->vendor,vendorlen);
  99970. vc->comments=oggpack_read(opb,32);
  99971. if(vc->comments<0)goto err_out;
  99972. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  99973. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  99974. for(i=0;i<vc->comments;i++){
  99975. int len=oggpack_read(opb,32);
  99976. if(len<0)goto err_out;
  99977. vc->comment_lengths[i]=len;
  99978. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  99979. _v_readstring(opb,vc->user_comments[i],len);
  99980. }
  99981. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  99982. return(0);
  99983. err_out:
  99984. vorbis_comment_clear(vc);
  99985. return(OV_EBADHEADER);
  99986. }
  99987. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  99988. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99989. int i;
  99990. if(!ci)return(OV_EFAULT);
  99991. ci->books=oggpack_read(opb,8)+1;
  99992. for(i=0;i<ci->books;i++){
  99993. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  99994. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  99995. }
  99996. {
  99997. int times=oggpack_read(opb,6)+1;
  99998. for(i=0;i<times;i++){
  99999. int test=oggpack_read(opb,16);
  100000. if(test<0 || test>=VI_TIMEB)goto err_out;
  100001. }
  100002. }
  100003. ci->floors=oggpack_read(opb,6)+1;
  100004. for(i=0;i<ci->floors;i++){
  100005. ci->floor_type[i]=oggpack_read(opb,16);
  100006. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100007. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100008. if(!ci->floor_param[i])goto err_out;
  100009. }
  100010. ci->residues=oggpack_read(opb,6)+1;
  100011. for(i=0;i<ci->residues;i++){
  100012. ci->residue_type[i]=oggpack_read(opb,16);
  100013. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100014. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100015. if(!ci->residue_param[i])goto err_out;
  100016. }
  100017. ci->maps=oggpack_read(opb,6)+1;
  100018. for(i=0;i<ci->maps;i++){
  100019. ci->map_type[i]=oggpack_read(opb,16);
  100020. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100021. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100022. if(!ci->map_param[i])goto err_out;
  100023. }
  100024. ci->modes=oggpack_read(opb,6)+1;
  100025. for(i=0;i<ci->modes;i++){
  100026. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100027. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100028. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100029. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100030. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100031. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100032. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100033. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100034. }
  100035. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100036. return(0);
  100037. err_out:
  100038. vorbis_info_clear(vi);
  100039. return(OV_EBADHEADER);
  100040. }
  100041. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100042. oggpack_buffer opb;
  100043. if(op){
  100044. oggpack_readinit(&opb,op->packet,op->bytes);
  100045. {
  100046. char buffer[6];
  100047. int packtype=oggpack_read(&opb,8);
  100048. memset(buffer,0,6);
  100049. _v_readstring(&opb,buffer,6);
  100050. if(memcmp(buffer,"vorbis",6)){
  100051. return(OV_ENOTVORBIS);
  100052. }
  100053. switch(packtype){
  100054. case 0x01: /* least significant *bit* is read first */
  100055. if(!op->b_o_s){
  100056. return(OV_EBADHEADER);
  100057. }
  100058. if(vi->rate!=0){
  100059. return(OV_EBADHEADER);
  100060. }
  100061. return(_vorbis_unpack_info(vi,&opb));
  100062. case 0x03: /* least significant *bit* is read first */
  100063. if(vi->rate==0){
  100064. return(OV_EBADHEADER);
  100065. }
  100066. return(_vorbis_unpack_comment(vc,&opb));
  100067. case 0x05: /* least significant *bit* is read first */
  100068. if(vi->rate==0 || vc->vendor==NULL){
  100069. return(OV_EBADHEADER);
  100070. }
  100071. return(_vorbis_unpack_books(vi,&opb));
  100072. default:
  100073. return(OV_EBADHEADER);
  100074. break;
  100075. }
  100076. }
  100077. }
  100078. return(OV_EBADHEADER);
  100079. }
  100080. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100081. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100082. if(!ci)return(OV_EFAULT);
  100083. oggpack_write(opb,0x01,8);
  100084. _v_writestring(opb,"vorbis", 6);
  100085. oggpack_write(opb,0x00,32);
  100086. oggpack_write(opb,vi->channels,8);
  100087. oggpack_write(opb,vi->rate,32);
  100088. oggpack_write(opb,vi->bitrate_upper,32);
  100089. oggpack_write(opb,vi->bitrate_nominal,32);
  100090. oggpack_write(opb,vi->bitrate_lower,32);
  100091. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100092. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100093. oggpack_write(opb,1,1);
  100094. return(0);
  100095. }
  100096. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100097. char temp[]="Xiph.Org libVorbis I 20050304";
  100098. int bytes = strlen(temp);
  100099. oggpack_write(opb,0x03,8);
  100100. _v_writestring(opb,"vorbis", 6);
  100101. oggpack_write(opb,bytes,32);
  100102. _v_writestring(opb,temp, bytes);
  100103. oggpack_write(opb,vc->comments,32);
  100104. if(vc->comments){
  100105. int i;
  100106. for(i=0;i<vc->comments;i++){
  100107. if(vc->user_comments[i]){
  100108. oggpack_write(opb,vc->comment_lengths[i],32);
  100109. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100110. }else{
  100111. oggpack_write(opb,0,32);
  100112. }
  100113. }
  100114. }
  100115. oggpack_write(opb,1,1);
  100116. return(0);
  100117. }
  100118. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100119. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100120. int i;
  100121. if(!ci)return(OV_EFAULT);
  100122. oggpack_write(opb,0x05,8);
  100123. _v_writestring(opb,"vorbis", 6);
  100124. oggpack_write(opb,ci->books-1,8);
  100125. for(i=0;i<ci->books;i++)
  100126. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100127. oggpack_write(opb,0,6);
  100128. oggpack_write(opb,0,16);
  100129. oggpack_write(opb,ci->floors-1,6);
  100130. for(i=0;i<ci->floors;i++){
  100131. oggpack_write(opb,ci->floor_type[i],16);
  100132. if(_floor_P[ci->floor_type[i]]->pack)
  100133. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100134. else
  100135. goto err_out;
  100136. }
  100137. oggpack_write(opb,ci->residues-1,6);
  100138. for(i=0;i<ci->residues;i++){
  100139. oggpack_write(opb,ci->residue_type[i],16);
  100140. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100141. }
  100142. oggpack_write(opb,ci->maps-1,6);
  100143. for(i=0;i<ci->maps;i++){
  100144. oggpack_write(opb,ci->map_type[i],16);
  100145. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100146. }
  100147. oggpack_write(opb,ci->modes-1,6);
  100148. for(i=0;i<ci->modes;i++){
  100149. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100150. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100151. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100152. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100153. }
  100154. oggpack_write(opb,1,1);
  100155. return(0);
  100156. err_out:
  100157. return(-1);
  100158. }
  100159. int vorbis_commentheader_out(vorbis_comment *vc,
  100160. ogg_packet *op){
  100161. oggpack_buffer opb;
  100162. oggpack_writeinit(&opb);
  100163. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100164. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100165. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100166. op->bytes=oggpack_bytes(&opb);
  100167. op->b_o_s=0;
  100168. op->e_o_s=0;
  100169. op->granulepos=0;
  100170. op->packetno=1;
  100171. return 0;
  100172. }
  100173. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100174. vorbis_comment *vc,
  100175. ogg_packet *op,
  100176. ogg_packet *op_comm,
  100177. ogg_packet *op_code){
  100178. int ret=OV_EIMPL;
  100179. vorbis_info *vi=v->vi;
  100180. oggpack_buffer opb;
  100181. private_state *b=(private_state*)v->backend_state;
  100182. if(!b){
  100183. ret=OV_EFAULT;
  100184. goto err_out;
  100185. }
  100186. oggpack_writeinit(&opb);
  100187. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100188. if(b->header)_ogg_free(b->header);
  100189. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100190. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100191. op->packet=b->header;
  100192. op->bytes=oggpack_bytes(&opb);
  100193. op->b_o_s=1;
  100194. op->e_o_s=0;
  100195. op->granulepos=0;
  100196. op->packetno=0;
  100197. oggpack_reset(&opb);
  100198. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100199. if(b->header1)_ogg_free(b->header1);
  100200. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100201. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100202. op_comm->packet=b->header1;
  100203. op_comm->bytes=oggpack_bytes(&opb);
  100204. op_comm->b_o_s=0;
  100205. op_comm->e_o_s=0;
  100206. op_comm->granulepos=0;
  100207. op_comm->packetno=1;
  100208. oggpack_reset(&opb);
  100209. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100210. if(b->header2)_ogg_free(b->header2);
  100211. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100212. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100213. op_code->packet=b->header2;
  100214. op_code->bytes=oggpack_bytes(&opb);
  100215. op_code->b_o_s=0;
  100216. op_code->e_o_s=0;
  100217. op_code->granulepos=0;
  100218. op_code->packetno=2;
  100219. oggpack_writeclear(&opb);
  100220. return(0);
  100221. err_out:
  100222. oggpack_writeclear(&opb);
  100223. memset(op,0,sizeof(*op));
  100224. memset(op_comm,0,sizeof(*op_comm));
  100225. memset(op_code,0,sizeof(*op_code));
  100226. if(b->header)_ogg_free(b->header);
  100227. if(b->header1)_ogg_free(b->header1);
  100228. if(b->header2)_ogg_free(b->header2);
  100229. b->header=NULL;
  100230. b->header1=NULL;
  100231. b->header2=NULL;
  100232. return(ret);
  100233. }
  100234. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100235. if(granulepos>=0)
  100236. return((double)granulepos/v->vi->rate);
  100237. return(-1);
  100238. }
  100239. #endif
  100240. /*** End of inlined file: info.c ***/
  100241. /*** Start of inlined file: lpc.c ***/
  100242. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100243. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100244. // tasks..
  100245. #if JUCE_MSVC
  100246. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100247. #endif
  100248. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100249. #if JUCE_USE_OGGVORBIS
  100250. #include <stdlib.h>
  100251. #include <string.h>
  100252. #include <math.h>
  100253. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100254. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100255. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100256. double error;
  100257. int i,j;
  100258. j=m+1;
  100259. while(j--){
  100260. double d=0; /* double needed for accumulator depth */
  100261. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100262. aut[j]=d;
  100263. }
  100264. error=aut[0];
  100265. for(i=0;i<m;i++){
  100266. double r= -aut[i+1];
  100267. if(error==0){
  100268. memset(lpci,0,m*sizeof(*lpci));
  100269. return 0;
  100270. }
  100271. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100272. r/=error;
  100273. lpc[i]=r;
  100274. for(j=0;j<i/2;j++){
  100275. double tmp=lpc[j];
  100276. lpc[j]+=r*lpc[i-1-j];
  100277. lpc[i-1-j]+=r*tmp;
  100278. }
  100279. if(i%2)lpc[j]+=lpc[j]*r;
  100280. error*=1.f-r*r;
  100281. }
  100282. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100283. return error;
  100284. }
  100285. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100286. float *data,long n){
  100287. long i,j,o,p;
  100288. float y;
  100289. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100290. if(!prime)
  100291. for(i=0;i<m;i++)
  100292. work[i]=0.f;
  100293. else
  100294. for(i=0;i<m;i++)
  100295. work[i]=prime[i];
  100296. for(i=0;i<n;i++){
  100297. y=0;
  100298. o=i;
  100299. p=m;
  100300. for(j=0;j<m;j++)
  100301. y-=work[o++]*coeff[--p];
  100302. data[i]=work[o]=y;
  100303. }
  100304. }
  100305. #endif
  100306. /*** End of inlined file: lpc.c ***/
  100307. /*** Start of inlined file: lsp.c ***/
  100308. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100309. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100310. // tasks..
  100311. #if JUCE_MSVC
  100312. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100313. #endif
  100314. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100315. #if JUCE_USE_OGGVORBIS
  100316. #include <math.h>
  100317. #include <string.h>
  100318. #include <stdlib.h>
  100319. /*** Start of inlined file: lookup.h ***/
  100320. #ifndef _V_LOOKUP_H_
  100321. #ifdef FLOAT_LOOKUP
  100322. extern float vorbis_coslook(float a);
  100323. extern float vorbis_invsqlook(float a);
  100324. extern float vorbis_invsq2explook(int a);
  100325. extern float vorbis_fromdBlook(float a);
  100326. #endif
  100327. #ifdef INT_LOOKUP
  100328. extern long vorbis_invsqlook_i(long a,long e);
  100329. extern long vorbis_coslook_i(long a);
  100330. extern float vorbis_fromdBlook_i(long a);
  100331. #endif
  100332. #endif
  100333. /*** End of inlined file: lookup.h ***/
  100334. #define FLOAT_LOOKUP
  100335. #undef INT_LOOKUP
  100336. #ifdef FLOAT_LOOKUP
  100337. /*** Start of inlined file: lookup.c ***/
  100338. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100339. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100340. // tasks..
  100341. #if JUCE_MSVC
  100342. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100343. #endif
  100344. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100345. #if JUCE_USE_OGGVORBIS
  100346. #include <math.h>
  100347. /*** Start of inlined file: lookup.h ***/
  100348. #ifndef _V_LOOKUP_H_
  100349. #ifdef FLOAT_LOOKUP
  100350. extern float vorbis_coslook(float a);
  100351. extern float vorbis_invsqlook(float a);
  100352. extern float vorbis_invsq2explook(int a);
  100353. extern float vorbis_fromdBlook(float a);
  100354. #endif
  100355. #ifdef INT_LOOKUP
  100356. extern long vorbis_invsqlook_i(long a,long e);
  100357. extern long vorbis_coslook_i(long a);
  100358. extern float vorbis_fromdBlook_i(long a);
  100359. #endif
  100360. #endif
  100361. /*** End of inlined file: lookup.h ***/
  100362. /*** Start of inlined file: lookup_data.h ***/
  100363. #ifndef _V_LOOKUP_DATA_H_
  100364. #ifdef FLOAT_LOOKUP
  100365. #define COS_LOOKUP_SZ 128
  100366. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100367. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100368. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100369. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100370. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100371. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100372. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100373. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100374. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100375. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100376. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100377. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100378. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100379. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100380. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100381. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100382. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100383. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100384. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100385. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100386. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100387. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100388. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100389. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100390. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100391. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100392. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100393. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100394. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100395. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100396. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100397. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100398. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100399. -1.0000000000000f,
  100400. };
  100401. #define INVSQ_LOOKUP_SZ 32
  100402. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100403. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100404. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100405. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100406. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100407. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100408. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100409. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100410. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100411. 1.000000000000f,
  100412. };
  100413. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100414. #define INVSQ2EXP_LOOKUP_MAX 32
  100415. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100416. INVSQ2EXP_LOOKUP_MIN+1]={
  100417. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100418. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100419. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100420. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100421. 256.f, 181.019336f, 128.f, 90.50966799f,
  100422. 64.f, 45.254834f, 32.f, 22.627417f,
  100423. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100424. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100425. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100426. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100427. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100428. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100429. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100430. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100431. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100432. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100433. 1.525878906e-05f,
  100434. };
  100435. #endif
  100436. #define FROMdB_LOOKUP_SZ 35
  100437. #define FROMdB2_LOOKUP_SZ 32
  100438. #define FROMdB_SHIFT 5
  100439. #define FROMdB2_SHIFT 3
  100440. #define FROMdB2_MASK 31
  100441. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100442. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100443. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100444. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100445. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100446. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100447. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100448. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100449. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100450. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100451. };
  100452. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100453. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100454. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100455. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100456. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100457. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100458. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100459. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100460. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100461. };
  100462. #ifdef INT_LOOKUP
  100463. #define INVSQ_LOOKUP_I_SHIFT 10
  100464. #define INVSQ_LOOKUP_I_MASK 1023
  100465. static long INVSQ_LOOKUP_I[64+1]={
  100466. 92682l, 91966l, 91267l, 90583l,
  100467. 89915l, 89261l, 88621l, 87995l,
  100468. 87381l, 86781l, 86192l, 85616l,
  100469. 85051l, 84497l, 83953l, 83420l,
  100470. 82897l, 82384l, 81880l, 81385l,
  100471. 80899l, 80422l, 79953l, 79492l,
  100472. 79039l, 78594l, 78156l, 77726l,
  100473. 77302l, 76885l, 76475l, 76072l,
  100474. 75674l, 75283l, 74898l, 74519l,
  100475. 74146l, 73778l, 73415l, 73058l,
  100476. 72706l, 72359l, 72016l, 71679l,
  100477. 71347l, 71019l, 70695l, 70376l,
  100478. 70061l, 69750l, 69444l, 69141l,
  100479. 68842l, 68548l, 68256l, 67969l,
  100480. 67685l, 67405l, 67128l, 66855l,
  100481. 66585l, 66318l, 66054l, 65794l,
  100482. 65536l,
  100483. };
  100484. #define COS_LOOKUP_I_SHIFT 9
  100485. #define COS_LOOKUP_I_MASK 511
  100486. #define COS_LOOKUP_I_SZ 128
  100487. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100488. 16384l, 16379l, 16364l, 16340l,
  100489. 16305l, 16261l, 16207l, 16143l,
  100490. 16069l, 15986l, 15893l, 15791l,
  100491. 15679l, 15557l, 15426l, 15286l,
  100492. 15137l, 14978l, 14811l, 14635l,
  100493. 14449l, 14256l, 14053l, 13842l,
  100494. 13623l, 13395l, 13160l, 12916l,
  100495. 12665l, 12406l, 12140l, 11866l,
  100496. 11585l, 11297l, 11003l, 10702l,
  100497. 10394l, 10080l, 9760l, 9434l,
  100498. 9102l, 8765l, 8423l, 8076l,
  100499. 7723l, 7366l, 7005l, 6639l,
  100500. 6270l, 5897l, 5520l, 5139l,
  100501. 4756l, 4370l, 3981l, 3590l,
  100502. 3196l, 2801l, 2404l, 2006l,
  100503. 1606l, 1205l, 804l, 402l,
  100504. 0l, -401l, -803l, -1204l,
  100505. -1605l, -2005l, -2403l, -2800l,
  100506. -3195l, -3589l, -3980l, -4369l,
  100507. -4755l, -5138l, -5519l, -5896l,
  100508. -6269l, -6638l, -7004l, -7365l,
  100509. -7722l, -8075l, -8422l, -8764l,
  100510. -9101l, -9433l, -9759l, -10079l,
  100511. -10393l, -10701l, -11002l, -11296l,
  100512. -11584l, -11865l, -12139l, -12405l,
  100513. -12664l, -12915l, -13159l, -13394l,
  100514. -13622l, -13841l, -14052l, -14255l,
  100515. -14448l, -14634l, -14810l, -14977l,
  100516. -15136l, -15285l, -15425l, -15556l,
  100517. -15678l, -15790l, -15892l, -15985l,
  100518. -16068l, -16142l, -16206l, -16260l,
  100519. -16304l, -16339l, -16363l, -16378l,
  100520. -16383l,
  100521. };
  100522. #endif
  100523. #endif
  100524. /*** End of inlined file: lookup_data.h ***/
  100525. #ifdef FLOAT_LOOKUP
  100526. float vorbis_coslook(float a){
  100527. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100528. int i=vorbis_ftoi(d-.5);
  100529. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100530. }
  100531. float vorbis_invsqlook(float a){
  100532. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100533. int i=vorbis_ftoi(d-.5f);
  100534. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100535. }
  100536. float vorbis_invsq2explook(int a){
  100537. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100538. }
  100539. #include <stdio.h>
  100540. float vorbis_fromdBlook(float a){
  100541. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100542. return (i<0)?1.f:
  100543. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100544. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100545. }
  100546. #endif
  100547. #ifdef INT_LOOKUP
  100548. long vorbis_invsqlook_i(long a,long e){
  100549. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100550. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100551. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100552. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100553. d)>>16); /* result 1.16 */
  100554. e+=32;
  100555. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100556. e=(e>>1)-8;
  100557. return(val>>e);
  100558. }
  100559. float vorbis_fromdBlook_i(long a){
  100560. int i=(-a)>>(12-FROMdB2_SHIFT);
  100561. return (i<0)?1.f:
  100562. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100563. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100564. }
  100565. long vorbis_coslook_i(long a){
  100566. int i=a>>COS_LOOKUP_I_SHIFT;
  100567. int d=a&COS_LOOKUP_I_MASK;
  100568. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100569. COS_LOOKUP_I_SHIFT);
  100570. }
  100571. #endif
  100572. #endif
  100573. /*** End of inlined file: lookup.c ***/
  100574. /* catch this in the build system; we #include for
  100575. compilers (like gcc) that can't inline across
  100576. modules */
  100577. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100578. float amp,float ampoffset){
  100579. int i;
  100580. float wdel=M_PI/ln;
  100581. vorbis_fpu_control fpu;
  100582. (void) fpu; // to avoid an unused variable warning
  100583. vorbis_fpu_setround(&fpu);
  100584. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  100585. i=0;
  100586. while(i<n){
  100587. int k=map[i];
  100588. int qexp;
  100589. float p=.7071067812f;
  100590. float q=.7071067812f;
  100591. float w=vorbis_coslook(wdel*k);
  100592. float *ftmp=lsp;
  100593. int c=m>>1;
  100594. do{
  100595. q*=ftmp[0]-w;
  100596. p*=ftmp[1]-w;
  100597. ftmp+=2;
  100598. }while(--c);
  100599. if(m&1){
  100600. q*=ftmp[0]-w;
  100601. q*=q;
  100602. p*=p*(1.f-w*w);
  100603. }else{
  100604. q*=q*(1.f+w);
  100605. p*=p*(1.f-w);
  100606. }
  100607. q=frexp(p+q,&qexp);
  100608. q=vorbis_fromdBlook(amp*
  100609. vorbis_invsqlook(q)*
  100610. vorbis_invsq2explook(qexp+m)-
  100611. ampoffset);
  100612. do{
  100613. curve[i++]*=q;
  100614. }while(map[i]==k);
  100615. }
  100616. vorbis_fpu_restore(fpu);
  100617. }
  100618. #else
  100619. #ifdef INT_LOOKUP
  100620. /*** Start of inlined file: lookup.c ***/
  100621. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100622. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100623. // tasks..
  100624. #if JUCE_MSVC
  100625. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100626. #endif
  100627. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100628. #if JUCE_USE_OGGVORBIS
  100629. #include <math.h>
  100630. /*** Start of inlined file: lookup.h ***/
  100631. #ifndef _V_LOOKUP_H_
  100632. #ifdef FLOAT_LOOKUP
  100633. extern float vorbis_coslook(float a);
  100634. extern float vorbis_invsqlook(float a);
  100635. extern float vorbis_invsq2explook(int a);
  100636. extern float vorbis_fromdBlook(float a);
  100637. #endif
  100638. #ifdef INT_LOOKUP
  100639. extern long vorbis_invsqlook_i(long a,long e);
  100640. extern long vorbis_coslook_i(long a);
  100641. extern float vorbis_fromdBlook_i(long a);
  100642. #endif
  100643. #endif
  100644. /*** End of inlined file: lookup.h ***/
  100645. /*** Start of inlined file: lookup_data.h ***/
  100646. #ifndef _V_LOOKUP_DATA_H_
  100647. #ifdef FLOAT_LOOKUP
  100648. #define COS_LOOKUP_SZ 128
  100649. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100650. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100651. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100652. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100653. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100654. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100655. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100656. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100657. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100658. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100659. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100660. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100661. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100662. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100663. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100664. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100665. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100666. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100667. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100668. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100669. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100670. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100671. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100672. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100673. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100674. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100675. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100676. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100677. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100678. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100679. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100680. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100681. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100682. -1.0000000000000f,
  100683. };
  100684. #define INVSQ_LOOKUP_SZ 32
  100685. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100686. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100687. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100688. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100689. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100690. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100691. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100692. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100693. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100694. 1.000000000000f,
  100695. };
  100696. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100697. #define INVSQ2EXP_LOOKUP_MAX 32
  100698. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100699. INVSQ2EXP_LOOKUP_MIN+1]={
  100700. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100701. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100702. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100703. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100704. 256.f, 181.019336f, 128.f, 90.50966799f,
  100705. 64.f, 45.254834f, 32.f, 22.627417f,
  100706. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100707. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100708. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100709. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100710. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100711. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100712. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100713. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100714. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100715. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100716. 1.525878906e-05f,
  100717. };
  100718. #endif
  100719. #define FROMdB_LOOKUP_SZ 35
  100720. #define FROMdB2_LOOKUP_SZ 32
  100721. #define FROMdB_SHIFT 5
  100722. #define FROMdB2_SHIFT 3
  100723. #define FROMdB2_MASK 31
  100724. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100725. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100726. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100727. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100728. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100729. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100730. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100731. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100732. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100733. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100734. };
  100735. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100736. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100737. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100738. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100739. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100740. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100741. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100742. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100743. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100744. };
  100745. #ifdef INT_LOOKUP
  100746. #define INVSQ_LOOKUP_I_SHIFT 10
  100747. #define INVSQ_LOOKUP_I_MASK 1023
  100748. static long INVSQ_LOOKUP_I[64+1]={
  100749. 92682l, 91966l, 91267l, 90583l,
  100750. 89915l, 89261l, 88621l, 87995l,
  100751. 87381l, 86781l, 86192l, 85616l,
  100752. 85051l, 84497l, 83953l, 83420l,
  100753. 82897l, 82384l, 81880l, 81385l,
  100754. 80899l, 80422l, 79953l, 79492l,
  100755. 79039l, 78594l, 78156l, 77726l,
  100756. 77302l, 76885l, 76475l, 76072l,
  100757. 75674l, 75283l, 74898l, 74519l,
  100758. 74146l, 73778l, 73415l, 73058l,
  100759. 72706l, 72359l, 72016l, 71679l,
  100760. 71347l, 71019l, 70695l, 70376l,
  100761. 70061l, 69750l, 69444l, 69141l,
  100762. 68842l, 68548l, 68256l, 67969l,
  100763. 67685l, 67405l, 67128l, 66855l,
  100764. 66585l, 66318l, 66054l, 65794l,
  100765. 65536l,
  100766. };
  100767. #define COS_LOOKUP_I_SHIFT 9
  100768. #define COS_LOOKUP_I_MASK 511
  100769. #define COS_LOOKUP_I_SZ 128
  100770. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100771. 16384l, 16379l, 16364l, 16340l,
  100772. 16305l, 16261l, 16207l, 16143l,
  100773. 16069l, 15986l, 15893l, 15791l,
  100774. 15679l, 15557l, 15426l, 15286l,
  100775. 15137l, 14978l, 14811l, 14635l,
  100776. 14449l, 14256l, 14053l, 13842l,
  100777. 13623l, 13395l, 13160l, 12916l,
  100778. 12665l, 12406l, 12140l, 11866l,
  100779. 11585l, 11297l, 11003l, 10702l,
  100780. 10394l, 10080l, 9760l, 9434l,
  100781. 9102l, 8765l, 8423l, 8076l,
  100782. 7723l, 7366l, 7005l, 6639l,
  100783. 6270l, 5897l, 5520l, 5139l,
  100784. 4756l, 4370l, 3981l, 3590l,
  100785. 3196l, 2801l, 2404l, 2006l,
  100786. 1606l, 1205l, 804l, 402l,
  100787. 0l, -401l, -803l, -1204l,
  100788. -1605l, -2005l, -2403l, -2800l,
  100789. -3195l, -3589l, -3980l, -4369l,
  100790. -4755l, -5138l, -5519l, -5896l,
  100791. -6269l, -6638l, -7004l, -7365l,
  100792. -7722l, -8075l, -8422l, -8764l,
  100793. -9101l, -9433l, -9759l, -10079l,
  100794. -10393l, -10701l, -11002l, -11296l,
  100795. -11584l, -11865l, -12139l, -12405l,
  100796. -12664l, -12915l, -13159l, -13394l,
  100797. -13622l, -13841l, -14052l, -14255l,
  100798. -14448l, -14634l, -14810l, -14977l,
  100799. -15136l, -15285l, -15425l, -15556l,
  100800. -15678l, -15790l, -15892l, -15985l,
  100801. -16068l, -16142l, -16206l, -16260l,
  100802. -16304l, -16339l, -16363l, -16378l,
  100803. -16383l,
  100804. };
  100805. #endif
  100806. #endif
  100807. /*** End of inlined file: lookup_data.h ***/
  100808. #ifdef FLOAT_LOOKUP
  100809. float vorbis_coslook(float a){
  100810. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  100811. int i=vorbis_ftoi(d-.5);
  100812. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  100813. }
  100814. float vorbis_invsqlook(float a){
  100815. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  100816. int i=vorbis_ftoi(d-.5f);
  100817. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  100818. }
  100819. float vorbis_invsq2explook(int a){
  100820. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  100821. }
  100822. #include <stdio.h>
  100823. float vorbis_fromdBlook(float a){
  100824. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  100825. return (i<0)?1.f:
  100826. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100827. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100828. }
  100829. #endif
  100830. #ifdef INT_LOOKUP
  100831. long vorbis_invsqlook_i(long a,long e){
  100832. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  100833. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  100834. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  100835. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  100836. d)>>16); /* result 1.16 */
  100837. e+=32;
  100838. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  100839. e=(e>>1)-8;
  100840. return(val>>e);
  100841. }
  100842. float vorbis_fromdBlook_i(long a){
  100843. int i=(-a)>>(12-FROMdB2_SHIFT);
  100844. return (i<0)?1.f:
  100845. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  100846. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  100847. }
  100848. long vorbis_coslook_i(long a){
  100849. int i=a>>COS_LOOKUP_I_SHIFT;
  100850. int d=a&COS_LOOKUP_I_MASK;
  100851. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  100852. COS_LOOKUP_I_SHIFT);
  100853. }
  100854. #endif
  100855. #endif
  100856. /*** End of inlined file: lookup.c ***/
  100857. /* catch this in the build system; we #include for
  100858. compilers (like gcc) that can't inline across
  100859. modules */
  100860. static int MLOOP_1[64]={
  100861. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  100862. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  100863. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100864. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  100865. };
  100866. static int MLOOP_2[64]={
  100867. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  100868. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  100869. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100870. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  100871. };
  100872. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  100873. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100874. float amp,float ampoffset){
  100875. int i;
  100876. int ampoffseti=rint(ampoffset*4096.f);
  100877. int ampi=rint(amp*16.f);
  100878. long *ilsp=alloca(m*sizeof(*ilsp));
  100879. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  100880. i=0;
  100881. while(i<n){
  100882. int j,k=map[i];
  100883. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  100884. unsigned long qi=46341;
  100885. int qexp=0,shift;
  100886. long wi=vorbis_coslook_i(k*65536/ln);
  100887. qi*=labs(ilsp[0]-wi);
  100888. pi*=labs(ilsp[1]-wi);
  100889. for(j=3;j<m;j+=2){
  100890. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100891. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100892. shift=MLOOP_3[(pi|qi)>>16];
  100893. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100894. pi=(pi>>shift)*labs(ilsp[j]-wi);
  100895. qexp+=shift;
  100896. }
  100897. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100898. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100899. shift=MLOOP_3[(pi|qi)>>16];
  100900. if(m&1){
  100901. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  100902. pi=(pi>>shift)<<14;
  100903. qexp+=shift;
  100904. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  100905. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  100906. shift=MLOOP_3[(pi|qi)>>16];
  100907. pi>>=shift;
  100908. qi>>=shift;
  100909. qexp+=shift-14*((m+1)>>1);
  100910. pi=((pi*pi)>>16);
  100911. qi=((qi*qi)>>16);
  100912. qexp=qexp*2+m;
  100913. pi*=(1<<14)-((wi*wi)>>14);
  100914. qi+=pi>>14;
  100915. }else{
  100916. pi>>=shift;
  100917. qi>>=shift;
  100918. qexp+=shift-7*m;
  100919. pi=((pi*pi)>>16);
  100920. qi=((qi*qi)>>16);
  100921. qexp=qexp*2+m;
  100922. pi*=(1<<14)-wi;
  100923. qi*=(1<<14)+wi;
  100924. qi=(qi+pi)>>14;
  100925. }
  100926. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  100927. qi>>=1; qexp++;
  100928. }else
  100929. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  100930. qi<<=1; qexp--;
  100931. }
  100932. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  100933. vorbis_invsqlook_i(qi,qexp)-
  100934. ampoffseti); /* 8.12[0] */
  100935. curve[i]*=amp;
  100936. while(map[++i]==k)curve[i]*=amp;
  100937. }
  100938. }
  100939. #else
  100940. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  100941. float amp,float ampoffset){
  100942. int i;
  100943. float wdel=M_PI/ln;
  100944. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  100945. i=0;
  100946. while(i<n){
  100947. int j,k=map[i];
  100948. float p=.5f;
  100949. float q=.5f;
  100950. float w=2.f*cos(wdel*k);
  100951. for(j=1;j<m;j+=2){
  100952. q *= w-lsp[j-1];
  100953. p *= w-lsp[j];
  100954. }
  100955. if(j==m){
  100956. q*=w-lsp[j-1];
  100957. p*=p*(4.f-w*w);
  100958. q*=q;
  100959. }else{
  100960. p*=p*(2.f-w);
  100961. q*=q*(2.f+w);
  100962. }
  100963. q=fromdB(amp/sqrt(p+q)-ampoffset);
  100964. curve[i]*=q;
  100965. while(map[++i]==k)curve[i]*=q;
  100966. }
  100967. }
  100968. #endif
  100969. #endif
  100970. static void cheby(float *g, int ord) {
  100971. int i, j;
  100972. g[0] *= .5f;
  100973. for(i=2; i<= ord; i++) {
  100974. for(j=ord; j >= i; j--) {
  100975. g[j-2] -= g[j];
  100976. g[j] += g[j];
  100977. }
  100978. }
  100979. }
  100980. static int comp(const void *a,const void *b){
  100981. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  100982. }
  100983. #define EPSILON 10e-7
  100984. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  100985. int i,m;
  100986. double lastdelta=0.f;
  100987. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  100988. for(i=0;i<=ord;i++)defl[i]=a[i];
  100989. for(m=ord;m>0;m--){
  100990. double newx=0.f,delta;
  100991. while(1){
  100992. double p=defl[m],pp=0.f,ppp=0.f,denom;
  100993. for(i=m;i>0;i--){
  100994. ppp = newx*ppp + pp;
  100995. pp = newx*pp + p;
  100996. p = newx*p + defl[i-1];
  100997. }
  100998. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  100999. if(denom<0)
  101000. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101001. if(pp>0){
  101002. denom = pp + sqrt(denom);
  101003. if(denom<EPSILON)denom=EPSILON;
  101004. }else{
  101005. denom = pp - sqrt(denom);
  101006. if(denom>-(EPSILON))denom=-(EPSILON);
  101007. }
  101008. delta = m*p/denom;
  101009. newx -= delta;
  101010. if(delta<0.f)delta*=-1;
  101011. if(fabs(delta/newx)<10e-12)break;
  101012. lastdelta=delta;
  101013. }
  101014. r[m-1]=newx;
  101015. for(i=m;i>0;i--)
  101016. defl[i-1]+=newx*defl[i];
  101017. defl++;
  101018. }
  101019. return(0);
  101020. }
  101021. static int Newton_Raphson(float *a,int ord,float *r){
  101022. int i, k, count=0;
  101023. double error=1.f;
  101024. double *root=(double*)alloca(ord*sizeof(*root));
  101025. for(i=0; i<ord;i++) root[i] = r[i];
  101026. while(error>1e-20){
  101027. error=0;
  101028. for(i=0; i<ord; i++) { /* Update each point. */
  101029. double pp=0.,delta;
  101030. double rooti=root[i];
  101031. double p=a[ord];
  101032. for(k=ord-1; k>= 0; k--) {
  101033. pp= pp* rooti + p;
  101034. p = p * rooti + a[k];
  101035. }
  101036. delta = p/pp;
  101037. root[i] -= delta;
  101038. error+= delta*delta;
  101039. }
  101040. if(count>40)return(-1);
  101041. count++;
  101042. }
  101043. for(i=0; i<ord;i++) r[i] = root[i];
  101044. return(0);
  101045. }
  101046. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101047. int order2=(m+1)>>1;
  101048. int g1_order,g2_order;
  101049. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101050. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101051. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101052. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101053. int i;
  101054. g1_order=(m+1)>>1;
  101055. g2_order=(m) >>1;
  101056. g1[g1_order] = 1.f;
  101057. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101058. g2[g2_order] = 1.f;
  101059. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101060. if(g1_order>g2_order){
  101061. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101062. }else{
  101063. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101064. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101065. }
  101066. cheby(g1,g1_order);
  101067. cheby(g2,g2_order);
  101068. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101069. Laguerre_With_Deflation(g2,g2_order,g2r))
  101070. return(-1);
  101071. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101072. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101073. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101074. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101075. for(i=0;i<g1_order;i++)
  101076. lsp[i*2] = acos(g1r[i]);
  101077. for(i=0;i<g2_order;i++)
  101078. lsp[i*2+1] = acos(g2r[i]);
  101079. return(0);
  101080. }
  101081. #endif
  101082. /*** End of inlined file: lsp.c ***/
  101083. /*** Start of inlined file: mapping0.c ***/
  101084. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101085. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101086. // tasks..
  101087. #if JUCE_MSVC
  101088. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101089. #endif
  101090. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101091. #if JUCE_USE_OGGVORBIS
  101092. #include <stdlib.h>
  101093. #include <stdio.h>
  101094. #include <string.h>
  101095. #include <math.h>
  101096. static void mapping0_free_info(vorbis_info_mapping *i){
  101097. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101098. if(info){
  101099. memset(info,0,sizeof(*info));
  101100. _ogg_free(info);
  101101. }
  101102. }
  101103. static int ilog3(unsigned int v){
  101104. int ret=0;
  101105. if(v)--v;
  101106. while(v){
  101107. ret++;
  101108. v>>=1;
  101109. }
  101110. return(ret);
  101111. }
  101112. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101113. oggpack_buffer *opb){
  101114. int i;
  101115. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101116. if(info->submaps>1){
  101117. oggpack_write(opb,1,1);
  101118. oggpack_write(opb,info->submaps-1,4);
  101119. }else
  101120. oggpack_write(opb,0,1);
  101121. if(info->coupling_steps>0){
  101122. oggpack_write(opb,1,1);
  101123. oggpack_write(opb,info->coupling_steps-1,8);
  101124. for(i=0;i<info->coupling_steps;i++){
  101125. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101126. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101127. }
  101128. }else
  101129. oggpack_write(opb,0,1);
  101130. oggpack_write(opb,0,2); /* 2,3:reserved */
  101131. if(info->submaps>1){
  101132. for(i=0;i<vi->channels;i++)
  101133. oggpack_write(opb,info->chmuxlist[i],4);
  101134. }
  101135. for(i=0;i<info->submaps;i++){
  101136. oggpack_write(opb,0,8); /* time submap unused */
  101137. oggpack_write(opb,info->floorsubmap[i],8);
  101138. oggpack_write(opb,info->residuesubmap[i],8);
  101139. }
  101140. }
  101141. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101142. int i;
  101143. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101144. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101145. memset(info,0,sizeof(*info));
  101146. if(oggpack_read(opb,1))
  101147. info->submaps=oggpack_read(opb,4)+1;
  101148. else
  101149. info->submaps=1;
  101150. if(oggpack_read(opb,1)){
  101151. info->coupling_steps=oggpack_read(opb,8)+1;
  101152. for(i=0;i<info->coupling_steps;i++){
  101153. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101154. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101155. if(testM<0 ||
  101156. testA<0 ||
  101157. testM==testA ||
  101158. testM>=vi->channels ||
  101159. testA>=vi->channels) goto err_out;
  101160. }
  101161. }
  101162. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101163. if(info->submaps>1){
  101164. for(i=0;i<vi->channels;i++){
  101165. info->chmuxlist[i]=oggpack_read(opb,4);
  101166. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101167. }
  101168. }
  101169. for(i=0;i<info->submaps;i++){
  101170. oggpack_read(opb,8); /* time submap unused */
  101171. info->floorsubmap[i]=oggpack_read(opb,8);
  101172. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101173. info->residuesubmap[i]=oggpack_read(opb,8);
  101174. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101175. }
  101176. return info;
  101177. err_out:
  101178. mapping0_free_info(info);
  101179. return(NULL);
  101180. }
  101181. #if 0
  101182. static long seq=0;
  101183. static ogg_int64_t total=0;
  101184. static float FLOOR1_fromdB_LOOKUP[256]={
  101185. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101186. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101187. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101188. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101189. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101190. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101191. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101192. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101193. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101194. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101195. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101196. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101197. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101198. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101199. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101200. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101201. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101202. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101203. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101204. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101205. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101206. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101207. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101208. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101209. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101210. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101211. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101212. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101213. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101214. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101215. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101216. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101217. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101218. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101219. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101220. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101221. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101222. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101223. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101224. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101225. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101226. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101227. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101228. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101229. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101230. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101231. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101232. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101233. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101234. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101235. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101236. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101237. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101238. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101239. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101240. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101241. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101242. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101243. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101244. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101245. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101246. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101247. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101248. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101249. };
  101250. #endif
  101251. extern int *floor1_fit(vorbis_block *vb,void *look,
  101252. const float *logmdct, /* in */
  101253. const float *logmask);
  101254. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101255. int *A,int *B,
  101256. int del);
  101257. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101258. void*look,
  101259. int *post,int *ilogmask);
  101260. static int mapping0_forward(vorbis_block *vb){
  101261. vorbis_dsp_state *vd=vb->vd;
  101262. vorbis_info *vi=vd->vi;
  101263. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101264. private_state *b=(private_state*)vb->vd->backend_state;
  101265. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101266. int n=vb->pcmend;
  101267. int i,j,k;
  101268. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101269. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101270. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101271. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101272. float global_ampmax=vbi->ampmax;
  101273. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101274. int blocktype=vbi->blocktype;
  101275. int modenumber=vb->W;
  101276. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101277. vorbis_look_psy *psy_look=
  101278. b->psy+blocktype+(vb->W?2:0);
  101279. vb->mode=modenumber;
  101280. for(i=0;i<vi->channels;i++){
  101281. float scale=4.f/n;
  101282. float scale_dB;
  101283. float *pcm =vb->pcm[i];
  101284. float *logfft =pcm;
  101285. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101286. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101287. todB estimation used on IEEE 754
  101288. compliant machines had a bug that
  101289. returned dB values about a third
  101290. of a decibel too high. The bug
  101291. was harmless because tunings
  101292. 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. #if 0
  101301. if(vi->channels==2)
  101302. if(i==0)
  101303. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101304. else
  101305. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101306. #endif
  101307. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101308. #if 0
  101309. if(vi->channels==2)
  101310. if(i==0)
  101311. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101312. else
  101313. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101314. #endif
  101315. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101316. drft_forward(&b->fft_look[vb->W],pcm);
  101317. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101318. original todB estimation used on
  101319. IEEE 754 compliant machines had a
  101320. bug that returned dB values about
  101321. a third of a decibel too high.
  101322. The bug was harmless because
  101323. tunings implicitly took that into
  101324. account. However, fixing the bug
  101325. in the estimator requires
  101326. changing all the tunings as well.
  101327. For now, it's easier to sync
  101328. things back up here, and
  101329. recalibrate the tunings in the
  101330. next major model upgrade. */
  101331. local_ampmax[i]=logfft[0];
  101332. for(j=1;j<n-1;j+=2){
  101333. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101334. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101335. .345 is a hack; the original todB
  101336. estimation used on IEEE 754
  101337. compliant machines had a bug that
  101338. returned dB values about a third
  101339. of a decibel too high. The bug
  101340. was harmless because tunings
  101341. implicitly took that into
  101342. account. However, fixing the bug
  101343. in the estimator requires
  101344. changing all the tunings as well.
  101345. For now, it's easier to sync
  101346. things back up here, and
  101347. recalibrate the tunings in the
  101348. next major model upgrade. */
  101349. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101350. }
  101351. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101352. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101353. #if 0
  101354. if(vi->channels==2){
  101355. if(i==0){
  101356. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101357. }else{
  101358. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101359. }
  101360. }
  101361. #endif
  101362. }
  101363. {
  101364. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101365. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101366. for(i=0;i<vi->channels;i++){
  101367. int submap=info->chmuxlist[i];
  101368. float *mdct =gmdct[i];
  101369. float *logfft =vb->pcm[i];
  101370. float *logmdct =logfft+n/2;
  101371. float *logmask =logfft;
  101372. vb->mode=modenumber;
  101373. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101374. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101375. for(j=0;j<n/2;j++)
  101376. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101377. todB estimation used on IEEE 754
  101378. compliant machines had a bug that
  101379. returned dB values about a third
  101380. of a decibel too high. The bug
  101381. was harmless because tunings
  101382. implicitly took that into
  101383. account. However, fixing the bug
  101384. in the estimator requires
  101385. changing all the tunings as well.
  101386. For now, it's easier to sync
  101387. things back up here, and
  101388. recalibrate the tunings in the
  101389. next major model upgrade. */
  101390. #if 0
  101391. if(vi->channels==2){
  101392. if(i==0)
  101393. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101394. else
  101395. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101396. }else{
  101397. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101398. }
  101399. #endif
  101400. _vp_noisemask(psy_look,
  101401. logmdct,
  101402. noise); /* noise does not have by-frequency offset
  101403. bias applied yet */
  101404. #if 0
  101405. if(vi->channels==2){
  101406. if(i==0)
  101407. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101408. else
  101409. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101410. }
  101411. #endif
  101412. _vp_tonemask(psy_look,
  101413. logfft,
  101414. tone,
  101415. global_ampmax,
  101416. local_ampmax[i]);
  101417. #if 0
  101418. if(vi->channels==2){
  101419. if(i==0)
  101420. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101421. else
  101422. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101423. }
  101424. #endif
  101425. #if 0
  101426. {
  101427. float aotuv[psy_look->n];
  101428. #endif
  101429. _vp_offset_and_mix(psy_look,
  101430. noise,
  101431. tone,
  101432. 1,
  101433. logmask,
  101434. mdct,
  101435. logmdct);
  101436. #if 0
  101437. if(vi->channels==2){
  101438. if(i==0)
  101439. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101440. else
  101441. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101442. }
  101443. }
  101444. #endif
  101445. #if 0
  101446. if(vi->channels==2){
  101447. if(i==0)
  101448. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101449. else
  101450. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101451. }
  101452. #endif
  101453. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101454. floor_posts[i][PACKETBLOBS/2]=
  101455. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101456. logmdct,
  101457. logmask);
  101458. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101459. _vp_offset_and_mix(psy_look,
  101460. noise,
  101461. tone,
  101462. 2,
  101463. logmask,
  101464. mdct,
  101465. logmdct);
  101466. #if 0
  101467. if(vi->channels==2){
  101468. if(i==0)
  101469. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101470. else
  101471. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101472. }
  101473. #endif
  101474. floor_posts[i][PACKETBLOBS-1]=
  101475. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101476. logmdct,
  101477. logmask);
  101478. _vp_offset_and_mix(psy_look,
  101479. noise,
  101480. tone,
  101481. 0,
  101482. logmask,
  101483. mdct,
  101484. logmdct);
  101485. #if 0
  101486. if(vi->channels==2)
  101487. if(i==0)
  101488. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101489. else
  101490. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101491. #endif
  101492. floor_posts[i][0]=
  101493. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101494. logmdct,
  101495. logmask);
  101496. for(k=1;k<PACKETBLOBS/2;k++)
  101497. floor_posts[i][k]=
  101498. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101499. floor_posts[i][0],
  101500. floor_posts[i][PACKETBLOBS/2],
  101501. k*65536/(PACKETBLOBS/2));
  101502. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101503. floor_posts[i][k]=
  101504. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101505. floor_posts[i][PACKETBLOBS/2],
  101506. floor_posts[i][PACKETBLOBS-1],
  101507. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101508. }
  101509. }
  101510. }
  101511. vbi->ampmax=global_ampmax;
  101512. {
  101513. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  101514. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  101515. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101516. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  101517. float **mag_memo;
  101518. int **mag_sort;
  101519. if(info->coupling_steps){
  101520. mag_memo=_vp_quantize_couple_memo(vb,
  101521. &ci->psy_g_param,
  101522. psy_look,
  101523. info,
  101524. gmdct);
  101525. mag_sort=_vp_quantize_couple_sort(vb,
  101526. psy_look,
  101527. info,
  101528. mag_memo);
  101529. hf_reduction(&ci->psy_g_param,
  101530. psy_look,
  101531. info,
  101532. mag_memo);
  101533. }
  101534. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  101535. if(psy_look->vi->normal_channel_p){
  101536. for(i=0;i<vi->channels;i++){
  101537. float *mdct =gmdct[i];
  101538. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  101539. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  101540. }
  101541. }
  101542. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  101543. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  101544. k++){
  101545. oggpack_buffer *opb=vbi->packetblob[k];
  101546. oggpack_write(opb,0,1);
  101547. oggpack_write(opb,modenumber,b->modebits);
  101548. if(vb->W){
  101549. oggpack_write(opb,vb->lW,1);
  101550. oggpack_write(opb,vb->nW,1);
  101551. }
  101552. for(i=0;i<vi->channels;i++){
  101553. int submap=info->chmuxlist[i];
  101554. float *mdct =gmdct[i];
  101555. float *res =vb->pcm[i];
  101556. int *ilogmask=ilogmaskch[i]=
  101557. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101558. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  101559. floor_posts[i][k],
  101560. ilogmask);
  101561. #if 0
  101562. {
  101563. char buf[80];
  101564. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  101565. float work[n/2];
  101566. for(j=0;j<n/2;j++)
  101567. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  101568. _analysis_output(buf,seq,work,n/2,1,1,0);
  101569. }
  101570. #endif
  101571. _vp_remove_floor(psy_look,
  101572. mdct,
  101573. ilogmask,
  101574. res,
  101575. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101576. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  101577. #if 0
  101578. {
  101579. char buf[80];
  101580. float work[n/2];
  101581. for(j=0;j<n/2;j++)
  101582. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  101583. sprintf(buf,"resI%c%d",i?'R':'L',k);
  101584. _analysis_output(buf,seq,work,n/2,1,1,0);
  101585. }
  101586. #endif
  101587. }
  101588. if(info->coupling_steps){
  101589. _vp_couple(k,
  101590. &ci->psy_g_param,
  101591. psy_look,
  101592. info,
  101593. vb->pcm,
  101594. mag_memo,
  101595. mag_sort,
  101596. ilogmaskch,
  101597. nonzero,
  101598. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  101599. }
  101600. for(i=0;i<info->submaps;i++){
  101601. int ch_in_bundle=0;
  101602. long **classifications;
  101603. int resnum=info->residuesubmap[i];
  101604. for(j=0;j<vi->channels;j++){
  101605. if(info->chmuxlist[j]==i){
  101606. zerobundle[ch_in_bundle]=0;
  101607. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  101608. res_bundle[ch_in_bundle]=vb->pcm[j];
  101609. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  101610. }
  101611. }
  101612. classifications=_residue_P[ci->residue_type[resnum]]->
  101613. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  101614. _residue_P[ci->residue_type[resnum]]->
  101615. forward(opb,vb,b->residue[resnum],
  101616. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  101617. }
  101618. }
  101619. }
  101620. #if 0
  101621. seq++;
  101622. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  101623. #endif
  101624. return(0);
  101625. }
  101626. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  101627. vorbis_dsp_state *vd=vb->vd;
  101628. vorbis_info *vi=vd->vi;
  101629. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  101630. private_state *b=(private_state*)vd->backend_state;
  101631. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  101632. int i,j;
  101633. long n=vb->pcmend=ci->blocksizes[vb->W];
  101634. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  101635. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  101636. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  101637. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  101638. for(i=0;i<vi->channels;i++){
  101639. int submap=info->chmuxlist[i];
  101640. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101641. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  101642. if(floormemo[i])
  101643. nonzero[i]=1;
  101644. else
  101645. nonzero[i]=0;
  101646. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  101647. }
  101648. for(i=0;i<info->coupling_steps;i++){
  101649. if(nonzero[info->coupling_mag[i]] ||
  101650. nonzero[info->coupling_ang[i]]){
  101651. nonzero[info->coupling_mag[i]]=1;
  101652. nonzero[info->coupling_ang[i]]=1;
  101653. }
  101654. }
  101655. for(i=0;i<info->submaps;i++){
  101656. int ch_in_bundle=0;
  101657. for(j=0;j<vi->channels;j++){
  101658. if(info->chmuxlist[j]==i){
  101659. if(nonzero[j])
  101660. zerobundle[ch_in_bundle]=1;
  101661. else
  101662. zerobundle[ch_in_bundle]=0;
  101663. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  101664. }
  101665. }
  101666. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  101667. inverse(vb,b->residue[info->residuesubmap[i]],
  101668. pcmbundle,zerobundle,ch_in_bundle);
  101669. }
  101670. for(i=info->coupling_steps-1;i>=0;i--){
  101671. float *pcmM=vb->pcm[info->coupling_mag[i]];
  101672. float *pcmA=vb->pcm[info->coupling_ang[i]];
  101673. for(j=0;j<n/2;j++){
  101674. float mag=pcmM[j];
  101675. float ang=pcmA[j];
  101676. if(mag>0)
  101677. if(ang>0){
  101678. pcmM[j]=mag;
  101679. pcmA[j]=mag-ang;
  101680. }else{
  101681. pcmA[j]=mag;
  101682. pcmM[j]=mag+ang;
  101683. }
  101684. else
  101685. if(ang>0){
  101686. pcmM[j]=mag;
  101687. pcmA[j]=mag+ang;
  101688. }else{
  101689. pcmA[j]=mag;
  101690. pcmM[j]=mag-ang;
  101691. }
  101692. }
  101693. }
  101694. for(i=0;i<vi->channels;i++){
  101695. float *pcm=vb->pcm[i];
  101696. int submap=info->chmuxlist[i];
  101697. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  101698. inverse2(vb,b->flr[info->floorsubmap[submap]],
  101699. floormemo[i],pcm);
  101700. }
  101701. for(i=0;i<vi->channels;i++){
  101702. float *pcm=vb->pcm[i];
  101703. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  101704. }
  101705. return(0);
  101706. }
  101707. vorbis_func_mapping mapping0_exportbundle={
  101708. &mapping0_pack,
  101709. &mapping0_unpack,
  101710. &mapping0_free_info,
  101711. &mapping0_forward,
  101712. &mapping0_inverse
  101713. };
  101714. #endif
  101715. /*** End of inlined file: mapping0.c ***/
  101716. /*** Start of inlined file: mdct.c ***/
  101717. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101718. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101719. // tasks..
  101720. #if JUCE_MSVC
  101721. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101722. #endif
  101723. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101724. #if JUCE_USE_OGGVORBIS
  101725. #include <stdio.h>
  101726. #include <stdlib.h>
  101727. #include <string.h>
  101728. #include <math.h>
  101729. void mdct_init(mdct_lookup *lookup,int n){
  101730. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  101731. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  101732. int i;
  101733. int n2=n>>1;
  101734. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  101735. lookup->n=n;
  101736. lookup->trig=T;
  101737. lookup->bitrev=bitrev;
  101738. for(i=0;i<n/4;i++){
  101739. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  101740. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  101741. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  101742. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  101743. }
  101744. for(i=0;i<n/8;i++){
  101745. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  101746. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  101747. }
  101748. {
  101749. int mask=(1<<(log2n-1))-1,i,j;
  101750. int msb=1<<(log2n-2);
  101751. for(i=0;i<n/8;i++){
  101752. int acc=0;
  101753. for(j=0;msb>>j;j++)
  101754. if((msb>>j)&i)acc|=1<<j;
  101755. bitrev[i*2]=((~acc)&mask)-1;
  101756. bitrev[i*2+1]=acc;
  101757. }
  101758. }
  101759. lookup->scale=FLOAT_CONV(4.f/n);
  101760. }
  101761. STIN void mdct_butterfly_8(DATA_TYPE *x){
  101762. REG_TYPE r0 = x[6] + x[2];
  101763. REG_TYPE r1 = x[6] - x[2];
  101764. REG_TYPE r2 = x[4] + x[0];
  101765. REG_TYPE r3 = x[4] - x[0];
  101766. x[6] = r0 + r2;
  101767. x[4] = r0 - r2;
  101768. r0 = x[5] - x[1];
  101769. r2 = x[7] - x[3];
  101770. x[0] = r1 + r0;
  101771. x[2] = r1 - r0;
  101772. r0 = x[5] + x[1];
  101773. r1 = x[7] + x[3];
  101774. x[3] = r2 + r3;
  101775. x[1] = r2 - r3;
  101776. x[7] = r1 + r0;
  101777. x[5] = r1 - r0;
  101778. }
  101779. STIN void mdct_butterfly_16(DATA_TYPE *x){
  101780. REG_TYPE r0 = x[1] - x[9];
  101781. REG_TYPE r1 = x[0] - x[8];
  101782. x[8] += x[0];
  101783. x[9] += x[1];
  101784. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  101785. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  101786. r0 = x[3] - x[11];
  101787. r1 = x[10] - x[2];
  101788. x[10] += x[2];
  101789. x[11] += x[3];
  101790. x[2] = r0;
  101791. x[3] = r1;
  101792. r0 = x[12] - x[4];
  101793. r1 = x[13] - x[5];
  101794. x[12] += x[4];
  101795. x[13] += x[5];
  101796. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  101797. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  101798. r0 = x[14] - x[6];
  101799. r1 = x[15] - x[7];
  101800. x[14] += x[6];
  101801. x[15] += x[7];
  101802. x[6] = r0;
  101803. x[7] = r1;
  101804. mdct_butterfly_8(x);
  101805. mdct_butterfly_8(x+8);
  101806. }
  101807. STIN void mdct_butterfly_32(DATA_TYPE *x){
  101808. REG_TYPE r0 = x[30] - x[14];
  101809. REG_TYPE r1 = x[31] - x[15];
  101810. x[30] += x[14];
  101811. x[31] += x[15];
  101812. x[14] = r0;
  101813. x[15] = r1;
  101814. r0 = x[28] - x[12];
  101815. r1 = x[29] - x[13];
  101816. x[28] += x[12];
  101817. x[29] += x[13];
  101818. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  101819. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  101820. r0 = x[26] - x[10];
  101821. r1 = x[27] - x[11];
  101822. x[26] += x[10];
  101823. x[27] += x[11];
  101824. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  101825. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  101826. r0 = x[24] - x[8];
  101827. r1 = x[25] - x[9];
  101828. x[24] += x[8];
  101829. x[25] += x[9];
  101830. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  101831. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101832. r0 = x[22] - x[6];
  101833. r1 = x[7] - x[23];
  101834. x[22] += x[6];
  101835. x[23] += x[7];
  101836. x[6] = r1;
  101837. x[7] = r0;
  101838. r0 = x[4] - x[20];
  101839. r1 = x[5] - x[21];
  101840. x[20] += x[4];
  101841. x[21] += x[5];
  101842. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  101843. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  101844. r0 = x[2] - x[18];
  101845. r1 = x[3] - x[19];
  101846. x[18] += x[2];
  101847. x[19] += x[3];
  101848. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  101849. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  101850. r0 = x[0] - x[16];
  101851. r1 = x[1] - x[17];
  101852. x[16] += x[0];
  101853. x[17] += x[1];
  101854. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  101855. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  101856. mdct_butterfly_16(x);
  101857. mdct_butterfly_16(x+16);
  101858. }
  101859. STIN void mdct_butterfly_first(DATA_TYPE *T,
  101860. DATA_TYPE *x,
  101861. int points){
  101862. DATA_TYPE *x1 = x + points - 8;
  101863. DATA_TYPE *x2 = x + (points>>1) - 8;
  101864. REG_TYPE r0;
  101865. REG_TYPE r1;
  101866. do{
  101867. r0 = x1[6] - x2[6];
  101868. r1 = x1[7] - x2[7];
  101869. x1[6] += x2[6];
  101870. x1[7] += x2[7];
  101871. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101872. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101873. r0 = x1[4] - x2[4];
  101874. r1 = x1[5] - x2[5];
  101875. x1[4] += x2[4];
  101876. x1[5] += x2[5];
  101877. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  101878. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  101879. r0 = x1[2] - x2[2];
  101880. r1 = x1[3] - x2[3];
  101881. x1[2] += x2[2];
  101882. x1[3] += x2[3];
  101883. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  101884. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  101885. r0 = x1[0] - x2[0];
  101886. r1 = x1[1] - x2[1];
  101887. x1[0] += x2[0];
  101888. x1[1] += x2[1];
  101889. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  101890. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  101891. x1-=8;
  101892. x2-=8;
  101893. T+=16;
  101894. }while(x2>=x);
  101895. }
  101896. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  101897. DATA_TYPE *x,
  101898. int points,
  101899. int trigint){
  101900. DATA_TYPE *x1 = x + points - 8;
  101901. DATA_TYPE *x2 = x + (points>>1) - 8;
  101902. REG_TYPE r0;
  101903. REG_TYPE r1;
  101904. do{
  101905. r0 = x1[6] - x2[6];
  101906. r1 = x1[7] - x2[7];
  101907. x1[6] += x2[6];
  101908. x1[7] += x2[7];
  101909. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101910. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101911. T+=trigint;
  101912. r0 = x1[4] - x2[4];
  101913. r1 = x1[5] - x2[5];
  101914. x1[4] += x2[4];
  101915. x1[5] += x2[5];
  101916. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101917. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101918. T+=trigint;
  101919. r0 = x1[2] - x2[2];
  101920. r1 = x1[3] - x2[3];
  101921. x1[2] += x2[2];
  101922. x1[3] += x2[3];
  101923. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101924. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101925. T+=trigint;
  101926. r0 = x1[0] - x2[0];
  101927. r1 = x1[1] - x2[1];
  101928. x1[0] += x2[0];
  101929. x1[1] += x2[1];
  101930. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  101931. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  101932. T+=trigint;
  101933. x1-=8;
  101934. x2-=8;
  101935. }while(x2>=x);
  101936. }
  101937. STIN void mdct_butterflies(mdct_lookup *init,
  101938. DATA_TYPE *x,
  101939. int points){
  101940. DATA_TYPE *T=init->trig;
  101941. int stages=init->log2n-5;
  101942. int i,j;
  101943. if(--stages>0){
  101944. mdct_butterfly_first(T,x,points);
  101945. }
  101946. for(i=1;--stages>0;i++){
  101947. for(j=0;j<(1<<i);j++)
  101948. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  101949. }
  101950. for(j=0;j<points;j+=32)
  101951. mdct_butterfly_32(x+j);
  101952. }
  101953. void mdct_clear(mdct_lookup *l){
  101954. if(l){
  101955. if(l->trig)_ogg_free(l->trig);
  101956. if(l->bitrev)_ogg_free(l->bitrev);
  101957. memset(l,0,sizeof(*l));
  101958. }
  101959. }
  101960. STIN void mdct_bitreverse(mdct_lookup *init,
  101961. DATA_TYPE *x){
  101962. int n = init->n;
  101963. int *bit = init->bitrev;
  101964. DATA_TYPE *w0 = x;
  101965. DATA_TYPE *w1 = x = w0+(n>>1);
  101966. DATA_TYPE *T = init->trig+n;
  101967. do{
  101968. DATA_TYPE *x0 = x+bit[0];
  101969. DATA_TYPE *x1 = x+bit[1];
  101970. REG_TYPE r0 = x0[1] - x1[1];
  101971. REG_TYPE r1 = x0[0] + x1[0];
  101972. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  101973. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  101974. w1 -= 4;
  101975. r0 = HALVE(x0[1] + x1[1]);
  101976. r1 = HALVE(x0[0] - x1[0]);
  101977. w0[0] = r0 + r2;
  101978. w1[2] = r0 - r2;
  101979. w0[1] = r1 + r3;
  101980. w1[3] = r3 - r1;
  101981. x0 = x+bit[2];
  101982. x1 = x+bit[3];
  101983. r0 = x0[1] - x1[1];
  101984. r1 = x0[0] + x1[0];
  101985. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  101986. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  101987. r0 = HALVE(x0[1] + x1[1]);
  101988. r1 = HALVE(x0[0] - x1[0]);
  101989. w0[2] = r0 + r2;
  101990. w1[0] = r0 - r2;
  101991. w0[3] = r1 + r3;
  101992. w1[1] = r3 - r1;
  101993. T += 4;
  101994. bit += 4;
  101995. w0 += 4;
  101996. }while(w0<w1);
  101997. }
  101998. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  101999. int n=init->n;
  102000. int n2=n>>1;
  102001. int n4=n>>2;
  102002. DATA_TYPE *iX = in+n2-7;
  102003. DATA_TYPE *oX = out+n2+n4;
  102004. DATA_TYPE *T = init->trig+n4;
  102005. do{
  102006. oX -= 4;
  102007. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102008. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102009. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102010. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102011. iX -= 8;
  102012. T += 4;
  102013. }while(iX>=in);
  102014. iX = in+n2-8;
  102015. oX = out+n2+n4;
  102016. T = init->trig+n4;
  102017. do{
  102018. T -= 4;
  102019. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102020. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102021. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102022. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102023. iX -= 8;
  102024. oX += 4;
  102025. }while(iX>=in);
  102026. mdct_butterflies(init,out+n2,n2);
  102027. mdct_bitreverse(init,out);
  102028. {
  102029. DATA_TYPE *oX1=out+n2+n4;
  102030. DATA_TYPE *oX2=out+n2+n4;
  102031. DATA_TYPE *iX =out;
  102032. T =init->trig+n2;
  102033. do{
  102034. oX1-=4;
  102035. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102036. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102037. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102038. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102039. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102040. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102041. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102042. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102043. oX2+=4;
  102044. iX += 8;
  102045. T += 8;
  102046. }while(iX<oX1);
  102047. iX=out+n2+n4;
  102048. oX1=out+n4;
  102049. oX2=oX1;
  102050. do{
  102051. oX1-=4;
  102052. iX-=4;
  102053. oX2[0] = -(oX1[3] = iX[3]);
  102054. oX2[1] = -(oX1[2] = iX[2]);
  102055. oX2[2] = -(oX1[1] = iX[1]);
  102056. oX2[3] = -(oX1[0] = iX[0]);
  102057. oX2+=4;
  102058. }while(oX2<iX);
  102059. iX=out+n2+n4;
  102060. oX1=out+n2+n4;
  102061. oX2=out+n2;
  102062. do{
  102063. oX1-=4;
  102064. oX1[0]= iX[3];
  102065. oX1[1]= iX[2];
  102066. oX1[2]= iX[1];
  102067. oX1[3]= iX[0];
  102068. iX+=4;
  102069. }while(oX1>oX2);
  102070. }
  102071. }
  102072. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102073. int n=init->n;
  102074. int n2=n>>1;
  102075. int n4=n>>2;
  102076. int n8=n>>3;
  102077. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102078. DATA_TYPE *w2=w+n2;
  102079. REG_TYPE r0;
  102080. REG_TYPE r1;
  102081. DATA_TYPE *x0=in+n2+n4;
  102082. DATA_TYPE *x1=x0+1;
  102083. DATA_TYPE *T=init->trig+n2;
  102084. int i=0;
  102085. for(i=0;i<n8;i+=2){
  102086. x0 -=4;
  102087. T-=2;
  102088. r0= x0[2] + x1[0];
  102089. r1= x0[0] + x1[2];
  102090. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102091. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102092. x1 +=4;
  102093. }
  102094. x1=in+1;
  102095. for(;i<n2-n8;i+=2){
  102096. T-=2;
  102097. x0 -=4;
  102098. r0= x0[2] - x1[0];
  102099. r1= x0[0] - x1[2];
  102100. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102101. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102102. x1 +=4;
  102103. }
  102104. x0=in+n;
  102105. for(;i<n2;i+=2){
  102106. T-=2;
  102107. x0 -=4;
  102108. r0= -x0[2] - x1[0];
  102109. r1= -x0[0] - x1[2];
  102110. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102111. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102112. x1 +=4;
  102113. }
  102114. mdct_butterflies(init,w+n2,n2);
  102115. mdct_bitreverse(init,w);
  102116. T=init->trig+n2;
  102117. x0=out+n2;
  102118. for(i=0;i<n4;i++){
  102119. x0--;
  102120. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102121. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102122. w+=2;
  102123. T+=2;
  102124. }
  102125. }
  102126. #endif
  102127. /*** End of inlined file: mdct.c ***/
  102128. /*** Start of inlined file: psy.c ***/
  102129. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102130. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102131. // tasks..
  102132. #if JUCE_MSVC
  102133. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102134. #endif
  102135. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102136. #if JUCE_USE_OGGVORBIS
  102137. #include <stdlib.h>
  102138. #include <math.h>
  102139. #include <string.h>
  102140. /*** Start of inlined file: masking.h ***/
  102141. #ifndef _V_MASKING_H_
  102142. #define _V_MASKING_H_
  102143. #define MAX_ATH 88
  102144. static float ATH[]={
  102145. -51, -52, -53, -54, -55, -56, -57, -58,
  102146. -59, -60, -61, -62, -63, -64, -65, -66,
  102147. -67, -68, -69, -70, -71, -72, -73, -74,
  102148. -75, -76, -77, -78, -80, -81, -82, -83,
  102149. -84, -85, -86, -87, -88, -88, -89, -89,
  102150. -90, -91, -91, -92, -93, -94, -95, -96,
  102151. -96, -97, -98, -98, -99, -99,-100,-100,
  102152. -101,-102,-103,-104,-106,-107,-107,-107,
  102153. -107,-105,-103,-102,-101, -99, -98, -96,
  102154. -95, -95, -96, -97, -96, -95, -93, -90,
  102155. -80, -70, -50, -40, -30, -30, -30, -30
  102156. };
  102157. #define EHMER_OFFSET 16
  102158. #define EHMER_MAX 56
  102159. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102160. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102161. -60, -60, -60, -60, -62, -62, -65, -73,
  102162. -69, -68, -68, -67, -70, -70, -72, -74,
  102163. -75, -79, -79, -80, -83, -88, -93, -100,
  102164. -110, -999, -999, -999, -999, -999, -999, -999,
  102165. -999, -999, -999, -999, -999, -999, -999, -999,
  102166. -999, -999, -999, -999, -999, -999, -999, -999},
  102167. { -48, -48, -48, -48, -48, -48, -48, -48,
  102168. -48, -48, -48, -48, -48, -53, -61, -66,
  102169. -66, -68, -67, -70, -76, -76, -72, -73,
  102170. -75, -76, -78, -79, -83, -88, -93, -100,
  102171. -110, -999, -999, -999, -999, -999, -999, -999,
  102172. -999, -999, -999, -999, -999, -999, -999, -999,
  102173. -999, -999, -999, -999, -999, -999, -999, -999},
  102174. { -37, -37, -37, -37, -37, -37, -37, -37,
  102175. -38, -40, -42, -46, -48, -53, -55, -62,
  102176. -65, -58, -56, -56, -61, -60, -65, -67,
  102177. -69, -71, -77, -77, -78, -80, -82, -84,
  102178. -88, -93, -98, -106, -112, -999, -999, -999,
  102179. -999, -999, -999, -999, -999, -999, -999, -999,
  102180. -999, -999, -999, -999, -999, -999, -999, -999},
  102181. { -25, -25, -25, -25, -25, -25, -25, -25,
  102182. -25, -26, -27, -29, -32, -38, -48, -52,
  102183. -52, -50, -48, -48, -51, -52, -54, -60,
  102184. -67, -67, -66, -68, -69, -73, -73, -76,
  102185. -80, -81, -81, -85, -85, -86, -88, -93,
  102186. -100, -110, -999, -999, -999, -999, -999, -999,
  102187. -999, -999, -999, -999, -999, -999, -999, -999},
  102188. { -16, -16, -16, -16, -16, -16, -16, -16,
  102189. -17, -19, -20, -22, -26, -28, -31, -40,
  102190. -47, -39, -39, -40, -42, -43, -47, -51,
  102191. -57, -52, -55, -55, -60, -58, -62, -63,
  102192. -70, -67, -69, -72, -73, -77, -80, -82,
  102193. -83, -87, -90, -94, -98, -104, -115, -999,
  102194. -999, -999, -999, -999, -999, -999, -999, -999},
  102195. { -8, -8, -8, -8, -8, -8, -8, -8,
  102196. -8, -8, -10, -11, -15, -19, -25, -30,
  102197. -34, -31, -30, -31, -29, -32, -35, -42,
  102198. -48, -42, -44, -46, -50, -50, -51, -52,
  102199. -59, -54, -55, -55, -58, -62, -63, -66,
  102200. -72, -73, -76, -75, -78, -80, -80, -81,
  102201. -84, -88, -90, -94, -98, -101, -106, -110}},
  102202. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102203. -66, -66, -66, -66, -66, -67, -67, -67,
  102204. -76, -72, -71, -74, -76, -76, -75, -78,
  102205. -79, -79, -81, -83, -86, -89, -93, -97,
  102206. -100, -105, -110, -999, -999, -999, -999, -999,
  102207. -999, -999, -999, -999, -999, -999, -999, -999,
  102208. -999, -999, -999, -999, -999, -999, -999, -999},
  102209. { -47, -47, -47, -47, -47, -47, -47, -47,
  102210. -47, -47, -47, -48, -51, -55, -59, -66,
  102211. -66, -66, -67, -66, -68, -69, -70, -74,
  102212. -79, -77, -77, -78, -80, -81, -82, -84,
  102213. -86, -88, -91, -95, -100, -108, -116, -999,
  102214. -999, -999, -999, -999, -999, -999, -999, -999,
  102215. -999, -999, -999, -999, -999, -999, -999, -999},
  102216. { -36, -36, -36, -36, -36, -36, -36, -36,
  102217. -36, -37, -37, -41, -44, -48, -51, -58,
  102218. -62, -60, -57, -59, -59, -60, -63, -65,
  102219. -72, -71, -70, -72, -74, -77, -76, -78,
  102220. -81, -81, -80, -83, -86, -91, -96, -100,
  102221. -105, -110, -999, -999, -999, -999, -999, -999,
  102222. -999, -999, -999, -999, -999, -999, -999, -999},
  102223. { -28, -28, -28, -28, -28, -28, -28, -28,
  102224. -28, -30, -32, -32, -33, -35, -41, -49,
  102225. -50, -49, -47, -48, -48, -52, -51, -57,
  102226. -65, -61, -59, -61, -64, -69, -70, -74,
  102227. -77, -77, -78, -81, -84, -85, -87, -90,
  102228. -92, -96, -100, -107, -112, -999, -999, -999,
  102229. -999, -999, -999, -999, -999, -999, -999, -999},
  102230. { -19, -19, -19, -19, -19, -19, -19, -19,
  102231. -20, -21, -23, -27, -30, -35, -36, -41,
  102232. -46, -44, -42, -40, -41, -41, -43, -48,
  102233. -55, -53, -52, -53, -56, -59, -58, -60,
  102234. -67, -66, -69, -71, -72, -75, -79, -81,
  102235. -84, -87, -90, -93, -97, -101, -107, -114,
  102236. -999, -999, -999, -999, -999, -999, -999, -999},
  102237. { -9, -9, -9, -9, -9, -9, -9, -9,
  102238. -11, -12, -12, -15, -16, -20, -23, -30,
  102239. -37, -34, -33, -34, -31, -32, -32, -38,
  102240. -47, -44, -41, -40, -47, -49, -46, -46,
  102241. -58, -50, -50, -54, -58, -62, -64, -67,
  102242. -67, -70, -72, -76, -79, -83, -87, -91,
  102243. -96, -100, -104, -110, -999, -999, -999, -999}},
  102244. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102245. -62, -62, -63, -64, -66, -67, -66, -68,
  102246. -75, -72, -76, -75, -76, -78, -79, -82,
  102247. -84, -85, -90, -94, -101, -110, -999, -999,
  102248. -999, -999, -999, -999, -999, -999, -999, -999,
  102249. -999, -999, -999, -999, -999, -999, -999, -999,
  102250. -999, -999, -999, -999, -999, -999, -999, -999},
  102251. { -59, -59, -59, -59, -59, -59, -59, -59,
  102252. -59, -59, -59, -60, -60, -61, -63, -66,
  102253. -71, -68, -70, -70, -71, -72, -72, -75,
  102254. -81, -78, -79, -82, -83, -86, -90, -97,
  102255. -103, -113, -999, -999, -999, -999, -999, -999,
  102256. -999, -999, -999, -999, -999, -999, -999, -999,
  102257. -999, -999, -999, -999, -999, -999, -999, -999},
  102258. { -53, -53, -53, -53, -53, -53, -53, -53,
  102259. -53, -54, -55, -57, -56, -57, -55, -61,
  102260. -65, -60, -60, -62, -63, -63, -66, -68,
  102261. -74, -73, -75, -75, -78, -80, -80, -82,
  102262. -85, -90, -96, -101, -108, -999, -999, -999,
  102263. -999, -999, -999, -999, -999, -999, -999, -999,
  102264. -999, -999, -999, -999, -999, -999, -999, -999},
  102265. { -46, -46, -46, -46, -46, -46, -46, -46,
  102266. -46, -46, -47, -47, -47, -47, -48, -51,
  102267. -57, -51, -49, -50, -51, -53, -54, -59,
  102268. -66, -60, -62, -67, -67, -70, -72, -75,
  102269. -76, -78, -81, -85, -88, -94, -97, -104,
  102270. -112, -999, -999, -999, -999, -999, -999, -999,
  102271. -999, -999, -999, -999, -999, -999, -999, -999},
  102272. { -36, -36, -36, -36, -36, -36, -36, -36,
  102273. -39, -41, -42, -42, -39, -38, -41, -43,
  102274. -52, -44, -40, -39, -37, -37, -40, -47,
  102275. -54, -50, -48, -50, -55, -61, -59, -62,
  102276. -66, -66, -66, -69, -69, -73, -74, -74,
  102277. -75, -77, -79, -82, -87, -91, -95, -100,
  102278. -108, -115, -999, -999, -999, -999, -999, -999},
  102279. { -28, -26, -24, -22, -20, -20, -23, -29,
  102280. -30, -31, -28, -27, -28, -28, -28, -35,
  102281. -40, -33, -32, -29, -30, -30, -30, -37,
  102282. -45, -41, -37, -38, -45, -47, -47, -48,
  102283. -53, -49, -48, -50, -49, -49, -51, -52,
  102284. -58, -56, -57, -56, -60, -61, -62, -70,
  102285. -72, -74, -78, -83, -88, -93, -100, -106}},
  102286. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102287. -999, -110, -105, -100, -95, -91, -87, -83,
  102288. -80, -78, -76, -78, -78, -81, -83, -85,
  102289. -86, -85, -86, -87, -90, -97, -107, -999,
  102290. -999, -999, -999, -999, -999, -999, -999, -999,
  102291. -999, -999, -999, -999, -999, -999, -999, -999,
  102292. -999, -999, -999, -999, -999, -999, -999, -999},
  102293. {-999, -999, -999, -110, -105, -100, -95, -90,
  102294. -85, -81, -77, -73, -70, -67, -67, -68,
  102295. -75, -73, -70, -69, -70, -72, -75, -79,
  102296. -84, -83, -84, -86, -88, -89, -89, -93,
  102297. -98, -105, -112, -999, -999, -999, -999, -999,
  102298. -999, -999, -999, -999, -999, -999, -999, -999,
  102299. -999, -999, -999, -999, -999, -999, -999, -999},
  102300. {-105, -100, -95, -90, -85, -80, -76, -71,
  102301. -68, -68, -65, -63, -63, -62, -62, -64,
  102302. -65, -64, -61, -62, -63, -64, -66, -68,
  102303. -73, -73, -74, -75, -76, -81, -83, -85,
  102304. -88, -89, -92, -95, -100, -108, -999, -999,
  102305. -999, -999, -999, -999, -999, -999, -999, -999,
  102306. -999, -999, -999, -999, -999, -999, -999, -999},
  102307. { -80, -75, -71, -68, -65, -63, -62, -61,
  102308. -61, -61, -61, -59, -56, -57, -53, -50,
  102309. -58, -52, -50, -50, -52, -53, -54, -58,
  102310. -67, -63, -67, -68, -72, -75, -78, -80,
  102311. -81, -81, -82, -85, -89, -90, -93, -97,
  102312. -101, -107, -114, -999, -999, -999, -999, -999,
  102313. -999, -999, -999, -999, -999, -999, -999, -999},
  102314. { -65, -61, -59, -57, -56, -55, -55, -56,
  102315. -56, -57, -55, -53, -52, -47, -44, -44,
  102316. -50, -44, -41, -39, -39, -42, -40, -46,
  102317. -51, -49, -50, -53, -54, -63, -60, -61,
  102318. -62, -66, -66, -66, -70, -73, -74, -75,
  102319. -76, -75, -79, -85, -89, -91, -96, -102,
  102320. -110, -999, -999, -999, -999, -999, -999, -999},
  102321. { -52, -50, -49, -49, -48, -48, -48, -49,
  102322. -50, -50, -49, -46, -43, -39, -35, -33,
  102323. -38, -36, -32, -29, -32, -32, -32, -35,
  102324. -44, -39, -38, -38, -46, -50, -45, -46,
  102325. -53, -50, -50, -50, -54, -54, -53, -53,
  102326. -56, -57, -59, -66, -70, -72, -74, -79,
  102327. -83, -85, -90, -97, -114, -999, -999, -999}},
  102328. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102329. -100, -95, -90, -86, -80, -75, -75, -79,
  102330. -80, -79, -80, -81, -82, -88, -95, -103,
  102331. -110, -999, -999, -999, -999, -999, -999, -999,
  102332. -999, -999, -999, -999, -999, -999, -999, -999,
  102333. -999, -999, -999, -999, -999, -999, -999, -999,
  102334. -999, -999, -999, -999, -999, -999, -999, -999},
  102335. {-999, -999, -999, -999, -108, -103, -98, -93,
  102336. -88, -83, -79, -78, -75, -71, -67, -68,
  102337. -73, -73, -72, -73, -75, -77, -80, -82,
  102338. -88, -93, -100, -107, -114, -999, -999, -999,
  102339. -999, -999, -999, -999, -999, -999, -999, -999,
  102340. -999, -999, -999, -999, -999, -999, -999, -999,
  102341. -999, -999, -999, -999, -999, -999, -999, -999},
  102342. {-999, -999, -999, -110, -105, -101, -96, -90,
  102343. -86, -81, -77, -73, -69, -66, -61, -62,
  102344. -66, -64, -62, -65, -66, -70, -72, -76,
  102345. -81, -80, -84, -90, -95, -102, -110, -999,
  102346. -999, -999, -999, -999, -999, -999, -999, -999,
  102347. -999, -999, -999, -999, -999, -999, -999, -999,
  102348. -999, -999, -999, -999, -999, -999, -999, -999},
  102349. {-999, -999, -999, -107, -103, -97, -92, -88,
  102350. -83, -79, -74, -70, -66, -59, -53, -58,
  102351. -62, -55, -54, -54, -54, -58, -61, -62,
  102352. -72, -70, -72, -75, -78, -80, -81, -80,
  102353. -83, -83, -88, -93, -100, -107, -115, -999,
  102354. -999, -999, -999, -999, -999, -999, -999, -999,
  102355. -999, -999, -999, -999, -999, -999, -999, -999},
  102356. {-999, -999, -999, -105, -100, -95, -90, -85,
  102357. -80, -75, -70, -66, -62, -56, -48, -44,
  102358. -48, -46, -46, -43, -46, -48, -48, -51,
  102359. -58, -58, -59, -60, -62, -62, -61, -61,
  102360. -65, -64, -65, -68, -70, -74, -75, -78,
  102361. -81, -86, -95, -110, -999, -999, -999, -999,
  102362. -999, -999, -999, -999, -999, -999, -999, -999},
  102363. {-999, -999, -105, -100, -95, -90, -85, -80,
  102364. -75, -70, -65, -61, -55, -49, -39, -33,
  102365. -40, -35, -32, -38, -40, -33, -35, -37,
  102366. -46, -41, -45, -44, -46, -42, -45, -46,
  102367. -52, -50, -50, -50, -54, -54, -55, -57,
  102368. -62, -64, -66, -68, -70, -76, -81, -90,
  102369. -100, -110, -999, -999, -999, -999, -999, -999}},
  102370. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102371. -105, -98, -90, -85, -82, -83, -80, -78,
  102372. -84, -79, -80, -83, -87, -89, -91, -93,
  102373. -99, -106, -117, -999, -999, -999, -999, -999,
  102374. -999, -999, -999, -999, -999, -999, -999, -999,
  102375. -999, -999, -999, -999, -999, -999, -999, -999,
  102376. -999, -999, -999, -999, -999, -999, -999, -999},
  102377. {-999, -999, -999, -999, -999, -999, -999, -999,
  102378. -105, -98, -90, -85, -80, -75, -70, -68,
  102379. -74, -72, -74, -77, -80, -82, -85, -87,
  102380. -92, -89, -91, -95, -100, -106, -112, -999,
  102381. -999, -999, -999, -999, -999, -999, -999, -999,
  102382. -999, -999, -999, -999, -999, -999, -999, -999,
  102383. -999, -999, -999, -999, -999, -999, -999, -999},
  102384. {-999, -999, -999, -999, -999, -999, -999, -999,
  102385. -105, -98, -90, -83, -75, -71, -63, -64,
  102386. -67, -62, -64, -67, -70, -73, -77, -81,
  102387. -84, -83, -85, -89, -90, -93, -98, -104,
  102388. -109, -114, -999, -999, -999, -999, -999, -999,
  102389. -999, -999, -999, -999, -999, -999, -999, -999,
  102390. -999, -999, -999, -999, -999, -999, -999, -999},
  102391. {-999, -999, -999, -999, -999, -999, -999, -999,
  102392. -103, -96, -88, -81, -75, -68, -58, -54,
  102393. -56, -54, -56, -56, -58, -60, -63, -66,
  102394. -74, -69, -72, -72, -75, -74, -77, -81,
  102395. -81, -82, -84, -87, -93, -96, -99, -104,
  102396. -110, -999, -999, -999, -999, -999, -999, -999,
  102397. -999, -999, -999, -999, -999, -999, -999, -999},
  102398. {-999, -999, -999, -999, -999, -108, -102, -96,
  102399. -91, -85, -80, -74, -68, -60, -51, -46,
  102400. -48, -46, -43, -45, -47, -47, -49, -48,
  102401. -56, -53, -55, -58, -57, -63, -58, -60,
  102402. -66, -64, -67, -70, -70, -74, -77, -84,
  102403. -86, -89, -91, -93, -94, -101, -109, -118,
  102404. -999, -999, -999, -999, -999, -999, -999, -999},
  102405. {-999, -999, -999, -108, -103, -98, -93, -88,
  102406. -83, -78, -73, -68, -60, -53, -44, -35,
  102407. -38, -38, -34, -34, -36, -40, -41, -44,
  102408. -51, -45, -46, -47, -46, -54, -50, -49,
  102409. -50, -50, -50, -51, -54, -57, -58, -60,
  102410. -66, -66, -66, -64, -65, -68, -77, -82,
  102411. -87, -95, -110, -999, -999, -999, -999, -999}},
  102412. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102413. -107, -102, -97, -92, -87, -83, -78, -75,
  102414. -82, -79, -83, -85, -89, -92, -95, -98,
  102415. -101, -105, -109, -113, -999, -999, -999, -999,
  102416. -999, -999, -999, -999, -999, -999, -999, -999,
  102417. -999, -999, -999, -999, -999, -999, -999, -999,
  102418. -999, -999, -999, -999, -999, -999, -999, -999},
  102419. {-999, -999, -999, -999, -999, -999, -999, -106,
  102420. -100, -95, -90, -86, -81, -78, -74, -69,
  102421. -74, -74, -76, -79, -83, -84, -86, -89,
  102422. -92, -97, -93, -100, -103, -107, -110, -999,
  102423. -999, -999, -999, -999, -999, -999, -999, -999,
  102424. -999, -999, -999, -999, -999, -999, -999, -999,
  102425. -999, -999, -999, -999, -999, -999, -999, -999},
  102426. {-999, -999, -999, -999, -999, -999, -106, -100,
  102427. -95, -90, -87, -83, -80, -75, -69, -60,
  102428. -66, -66, -68, -70, -74, -78, -79, -81,
  102429. -81, -83, -84, -87, -93, -96, -99, -103,
  102430. -107, -110, -999, -999, -999, -999, -999, -999,
  102431. -999, -999, -999, -999, -999, -999, -999, -999,
  102432. -999, -999, -999, -999, -999, -999, -999, -999},
  102433. {-999, -999, -999, -999, -999, -108, -103, -98,
  102434. -93, -89, -85, -82, -78, -71, -62, -55,
  102435. -58, -58, -54, -54, -55, -59, -61, -62,
  102436. -70, -66, -66, -67, -70, -72, -75, -78,
  102437. -84, -84, -84, -88, -91, -90, -95, -98,
  102438. -102, -103, -106, -110, -999, -999, -999, -999,
  102439. -999, -999, -999, -999, -999, -999, -999, -999},
  102440. {-999, -999, -999, -999, -108, -103, -98, -94,
  102441. -90, -87, -82, -79, -73, -67, -58, -47,
  102442. -50, -45, -41, -45, -48, -44, -44, -49,
  102443. -54, -51, -48, -47, -49, -50, -51, -57,
  102444. -58, -60, -63, -69, -70, -69, -71, -74,
  102445. -78, -82, -90, -95, -101, -105, -110, -999,
  102446. -999, -999, -999, -999, -999, -999, -999, -999},
  102447. {-999, -999, -999, -105, -101, -97, -93, -90,
  102448. -85, -80, -77, -72, -65, -56, -48, -37,
  102449. -40, -36, -34, -40, -50, -47, -38, -41,
  102450. -47, -38, -35, -39, -38, -43, -40, -45,
  102451. -50, -45, -44, -47, -50, -55, -48, -48,
  102452. -52, -66, -70, -76, -82, -90, -97, -105,
  102453. -110, -999, -999, -999, -999, -999, -999, -999}},
  102454. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102455. -999, -108, -103, -98, -93, -86, -79, -76,
  102456. -83, -81, -85, -87, -89, -93, -98, -102,
  102457. -107, -112, -999, -999, -999, -999, -999, -999,
  102458. -999, -999, -999, -999, -999, -999, -999, -999,
  102459. -999, -999, -999, -999, -999, -999, -999, -999,
  102460. -999, -999, -999, -999, -999, -999, -999, -999},
  102461. {-999, -999, -999, -999, -999, -999, -999, -999,
  102462. -999, -108, -103, -98, -93, -86, -79, -71,
  102463. -77, -74, -77, -79, -81, -84, -85, -90,
  102464. -92, -93, -92, -98, -101, -108, -112, -999,
  102465. -999, -999, -999, -999, -999, -999, -999, -999,
  102466. -999, -999, -999, -999, -999, -999, -999, -999,
  102467. -999, -999, -999, -999, -999, -999, -999, -999},
  102468. {-999, -999, -999, -999, -999, -999, -999, -999,
  102469. -108, -103, -98, -93, -87, -78, -68, -65,
  102470. -66, -62, -65, -67, -70, -73, -75, -78,
  102471. -82, -82, -83, -84, -91, -93, -98, -102,
  102472. -106, -110, -999, -999, -999, -999, -999, -999,
  102473. -999, -999, -999, -999, -999, -999, -999, -999,
  102474. -999, -999, -999, -999, -999, -999, -999, -999},
  102475. {-999, -999, -999, -999, -999, -999, -999, -999,
  102476. -105, -100, -95, -90, -82, -74, -62, -57,
  102477. -58, -56, -51, -52, -52, -54, -54, -58,
  102478. -66, -59, -60, -63, -66, -69, -73, -79,
  102479. -83, -84, -80, -81, -81, -82, -88, -92,
  102480. -98, -105, -113, -999, -999, -999, -999, -999,
  102481. -999, -999, -999, -999, -999, -999, -999, -999},
  102482. {-999, -999, -999, -999, -999, -999, -999, -107,
  102483. -102, -97, -92, -84, -79, -69, -57, -47,
  102484. -52, -47, -44, -45, -50, -52, -42, -42,
  102485. -53, -43, -43, -48, -51, -56, -55, -52,
  102486. -57, -59, -61, -62, -67, -71, -78, -83,
  102487. -86, -94, -98, -103, -110, -999, -999, -999,
  102488. -999, -999, -999, -999, -999, -999, -999, -999},
  102489. {-999, -999, -999, -999, -999, -999, -105, -100,
  102490. -95, -90, -84, -78, -70, -61, -51, -41,
  102491. -40, -38, -40, -46, -52, -51, -41, -40,
  102492. -46, -40, -38, -38, -41, -46, -41, -46,
  102493. -47, -43, -43, -45, -41, -45, -56, -67,
  102494. -68, -83, -87, -90, -95, -102, -107, -113,
  102495. -999, -999, -999, -999, -999, -999, -999, -999}},
  102496. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102497. -999, -109, -105, -101, -96, -91, -84, -77,
  102498. -82, -82, -85, -89, -94, -100, -106, -110,
  102499. -999, -999, -999, -999, -999, -999, -999, -999,
  102500. -999, -999, -999, -999, -999, -999, -999, -999,
  102501. -999, -999, -999, -999, -999, -999, -999, -999,
  102502. -999, -999, -999, -999, -999, -999, -999, -999},
  102503. {-999, -999, -999, -999, -999, -999, -999, -999,
  102504. -999, -106, -103, -98, -92, -85, -80, -71,
  102505. -75, -72, -76, -80, -84, -86, -89, -93,
  102506. -100, -107, -113, -999, -999, -999, -999, -999,
  102507. -999, -999, -999, -999, -999, -999, -999, -999,
  102508. -999, -999, -999, -999, -999, -999, -999, -999,
  102509. -999, -999, -999, -999, -999, -999, -999, -999},
  102510. {-999, -999, -999, -999, -999, -999, -999, -107,
  102511. -104, -101, -97, -92, -88, -84, -80, -64,
  102512. -66, -63, -64, -66, -69, -73, -77, -83,
  102513. -83, -86, -91, -98, -104, -111, -999, -999,
  102514. -999, -999, -999, -999, -999, -999, -999, -999,
  102515. -999, -999, -999, -999, -999, -999, -999, -999,
  102516. -999, -999, -999, -999, -999, -999, -999, -999},
  102517. {-999, -999, -999, -999, -999, -999, -999, -107,
  102518. -104, -101, -97, -92, -90, -84, -74, -57,
  102519. -58, -52, -55, -54, -50, -52, -50, -52,
  102520. -63, -62, -69, -76, -77, -78, -78, -79,
  102521. -82, -88, -94, -100, -106, -111, -999, -999,
  102522. -999, -999, -999, -999, -999, -999, -999, -999,
  102523. -999, -999, -999, -999, -999, -999, -999, -999},
  102524. {-999, -999, -999, -999, -999, -999, -106, -102,
  102525. -98, -95, -90, -85, -83, -78, -70, -50,
  102526. -50, -41, -44, -49, -47, -50, -50, -44,
  102527. -55, -46, -47, -48, -48, -54, -49, -49,
  102528. -58, -62, -71, -81, -87, -92, -97, -102,
  102529. -108, -114, -999, -999, -999, -999, -999, -999,
  102530. -999, -999, -999, -999, -999, -999, -999, -999},
  102531. {-999, -999, -999, -999, -999, -999, -106, -102,
  102532. -98, -95, -90, -85, -83, -78, -70, -45,
  102533. -43, -41, -47, -50, -51, -50, -49, -45,
  102534. -47, -41, -44, -41, -39, -43, -38, -37,
  102535. -40, -41, -44, -50, -58, -65, -73, -79,
  102536. -85, -92, -97, -101, -105, -109, -113, -999,
  102537. -999, -999, -999, -999, -999, -999, -999, -999}},
  102538. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102539. -999, -999, -999, -107, -100, -95, -87, -81,
  102540. -85, -83, -88, -93, -100, -107, -114, -999,
  102541. -999, -999, -999, -999, -999, -999, -999, -999,
  102542. -999, -999, -999, -999, -999, -999, -999, -999,
  102543. -999, -999, -999, -999, -999, -999, -999, -999,
  102544. -999, -999, -999, -999, -999, -999, -999, -999},
  102545. {-999, -999, -999, -999, -999, -999, -999, -999,
  102546. -999, -999, -107, -101, -95, -88, -83, -76,
  102547. -73, -72, -79, -84, -90, -95, -100, -105,
  102548. -110, -115, -999, -999, -999, -999, -999, -999,
  102549. -999, -999, -999, -999, -999, -999, -999, -999,
  102550. -999, -999, -999, -999, -999, -999, -999, -999,
  102551. -999, -999, -999, -999, -999, -999, -999, -999},
  102552. {-999, -999, -999, -999, -999, -999, -999, -999,
  102553. -999, -999, -104, -98, -92, -87, -81, -70,
  102554. -65, -62, -67, -71, -74, -80, -85, -91,
  102555. -95, -99, -103, -108, -111, -114, -999, -999,
  102556. -999, -999, -999, -999, -999, -999, -999, -999,
  102557. -999, -999, -999, -999, -999, -999, -999, -999,
  102558. -999, -999, -999, -999, -999, -999, -999, -999},
  102559. {-999, -999, -999, -999, -999, -999, -999, -999,
  102560. -999, -999, -103, -97, -90, -85, -76, -60,
  102561. -56, -54, -60, -62, -61, -56, -63, -65,
  102562. -73, -74, -77, -75, -78, -81, -86, -87,
  102563. -88, -91, -94, -98, -103, -110, -999, -999,
  102564. -999, -999, -999, -999, -999, -999, -999, -999,
  102565. -999, -999, -999, -999, -999, -999, -999, -999},
  102566. {-999, -999, -999, -999, -999, -999, -999, -105,
  102567. -100, -97, -92, -86, -81, -79, -70, -57,
  102568. -51, -47, -51, -58, -60, -56, -53, -50,
  102569. -58, -52, -50, -50, -53, -55, -64, -69,
  102570. -71, -85, -82, -78, -81, -85, -95, -102,
  102571. -112, -999, -999, -999, -999, -999, -999, -999,
  102572. -999, -999, -999, -999, -999, -999, -999, -999},
  102573. {-999, -999, -999, -999, -999, -999, -999, -105,
  102574. -100, -97, -92, -85, -83, -79, -72, -49,
  102575. -40, -43, -43, -54, -56, -51, -50, -40,
  102576. -43, -38, -36, -35, -37, -38, -37, -44,
  102577. -54, -60, -57, -60, -70, -75, -84, -92,
  102578. -103, -112, -999, -999, -999, -999, -999, -999,
  102579. -999, -999, -999, -999, -999, -999, -999, -999}},
  102580. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102581. -999, -999, -999, -110, -102, -95, -89, -82,
  102582. -83, -84, -90, -92, -99, -107, -113, -999,
  102583. -999, -999, -999, -999, -999, -999, -999, -999,
  102584. -999, -999, -999, -999, -999, -999, -999, -999,
  102585. -999, -999, -999, -999, -999, -999, -999, -999,
  102586. -999, -999, -999, -999, -999, -999, -999, -999},
  102587. {-999, -999, -999, -999, -999, -999, -999, -999,
  102588. -999, -999, -107, -101, -95, -89, -83, -72,
  102589. -74, -78, -85, -88, -88, -90, -92, -98,
  102590. -105, -111, -999, -999, -999, -999, -999, -999,
  102591. -999, -999, -999, -999, -999, -999, -999, -999,
  102592. -999, -999, -999, -999, -999, -999, -999, -999,
  102593. -999, -999, -999, -999, -999, -999, -999, -999},
  102594. {-999, -999, -999, -999, -999, -999, -999, -999,
  102595. -999, -109, -103, -97, -93, -87, -81, -70,
  102596. -70, -67, -75, -73, -76, -79, -81, -83,
  102597. -88, -89, -97, -103, -110, -999, -999, -999,
  102598. -999, -999, -999, -999, -999, -999, -999, -999,
  102599. -999, -999, -999, -999, -999, -999, -999, -999,
  102600. -999, -999, -999, -999, -999, -999, -999, -999},
  102601. {-999, -999, -999, -999, -999, -999, -999, -999,
  102602. -999, -107, -100, -94, -88, -83, -75, -63,
  102603. -59, -59, -63, -66, -60, -62, -67, -67,
  102604. -77, -76, -81, -88, -86, -92, -96, -102,
  102605. -109, -116, -999, -999, -999, -999, -999, -999,
  102606. -999, -999, -999, -999, -999, -999, -999, -999,
  102607. -999, -999, -999, -999, -999, -999, -999, -999},
  102608. {-999, -999, -999, -999, -999, -999, -999, -999,
  102609. -999, -105, -98, -92, -86, -81, -73, -56,
  102610. -52, -47, -55, -60, -58, -52, -51, -45,
  102611. -49, -50, -53, -54, -61, -71, -70, -69,
  102612. -78, -79, -87, -90, -96, -104, -112, -999,
  102613. -999, -999, -999, -999, -999, -999, -999, -999,
  102614. -999, -999, -999, -999, -999, -999, -999, -999},
  102615. {-999, -999, -999, -999, -999, -999, -999, -999,
  102616. -999, -103, -96, -90, -86, -78, -70, -51,
  102617. -42, -47, -48, -55, -54, -54, -53, -42,
  102618. -35, -28, -33, -38, -37, -44, -47, -49,
  102619. -54, -63, -68, -78, -82, -89, -94, -99,
  102620. -104, -109, -114, -999, -999, -999, -999, -999,
  102621. -999, -999, -999, -999, -999, -999, -999, -999}},
  102622. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102623. -999, -999, -999, -999, -110, -100, -90, -79,
  102624. -85, -81, -82, -82, -89, -94, -99, -103,
  102625. -109, -115, -999, -999, -999, -999, -999, -999,
  102626. -999, -999, -999, -999, -999, -999, -999, -999,
  102627. -999, -999, -999, -999, -999, -999, -999, -999,
  102628. -999, -999, -999, -999, -999, -999, -999, -999},
  102629. {-999, -999, -999, -999, -999, -999, -999, -999,
  102630. -999, -999, -999, -999, -105, -97, -85, -72,
  102631. -74, -70, -70, -70, -76, -85, -91, -93,
  102632. -97, -103, -109, -115, -999, -999, -999, -999,
  102633. -999, -999, -999, -999, -999, -999, -999, -999,
  102634. -999, -999, -999, -999, -999, -999, -999, -999,
  102635. -999, -999, -999, -999, -999, -999, -999, -999},
  102636. {-999, -999, -999, -999, -999, -999, -999, -999,
  102637. -999, -999, -999, -999, -112, -93, -81, -68,
  102638. -62, -60, -60, -57, -63, -70, -77, -82,
  102639. -90, -93, -98, -104, -109, -113, -999, -999,
  102640. -999, -999, -999, -999, -999, -999, -999, -999,
  102641. -999, -999, -999, -999, -999, -999, -999, -999,
  102642. -999, -999, -999, -999, -999, -999, -999, -999},
  102643. {-999, -999, -999, -999, -999, -999, -999, -999,
  102644. -999, -999, -999, -113, -100, -93, -84, -63,
  102645. -58, -48, -53, -54, -52, -52, -57, -64,
  102646. -66, -76, -83, -81, -85, -85, -90, -95,
  102647. -98, -101, -103, -106, -108, -111, -999, -999,
  102648. -999, -999, -999, -999, -999, -999, -999, -999,
  102649. -999, -999, -999, -999, -999, -999, -999, -999},
  102650. {-999, -999, -999, -999, -999, -999, -999, -999,
  102651. -999, -999, -999, -105, -95, -86, -74, -53,
  102652. -50, -38, -43, -49, -43, -42, -39, -39,
  102653. -46, -52, -57, -56, -72, -69, -74, -81,
  102654. -87, -92, -94, -97, -99, -102, -105, -108,
  102655. -999, -999, -999, -999, -999, -999, -999, -999,
  102656. -999, -999, -999, -999, -999, -999, -999, -999},
  102657. {-999, -999, -999, -999, -999, -999, -999, -999,
  102658. -999, -999, -108, -99, -90, -76, -66, -45,
  102659. -43, -41, -44, -47, -43, -47, -40, -30,
  102660. -31, -31, -39, -33, -40, -41, -43, -53,
  102661. -59, -70, -73, -77, -79, -82, -84, -87,
  102662. -999, -999, -999, -999, -999, -999, -999, -999,
  102663. -999, -999, -999, -999, -999, -999, -999, -999}},
  102664. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102665. -999, -999, -999, -999, -999, -110, -91, -76,
  102666. -75, -85, -93, -98, -104, -110, -999, -999,
  102667. -999, -999, -999, -999, -999, -999, -999, -999,
  102668. -999, -999, -999, -999, -999, -999, -999, -999,
  102669. -999, -999, -999, -999, -999, -999, -999, -999,
  102670. -999, -999, -999, -999, -999, -999, -999, -999},
  102671. {-999, -999, -999, -999, -999, -999, -999, -999,
  102672. -999, -999, -999, -999, -999, -110, -91, -70,
  102673. -70, -75, -86, -89, -94, -98, -101, -106,
  102674. -110, -999, -999, -999, -999, -999, -999, -999,
  102675. -999, -999, -999, -999, -999, -999, -999, -999,
  102676. -999, -999, -999, -999, -999, -999, -999, -999,
  102677. -999, -999, -999, -999, -999, -999, -999, -999},
  102678. {-999, -999, -999, -999, -999, -999, -999, -999,
  102679. -999, -999, -999, -999, -110, -95, -80, -60,
  102680. -65, -64, -74, -83, -88, -91, -95, -99,
  102681. -103, -107, -110, -999, -999, -999, -999, -999,
  102682. -999, -999, -999, -999, -999, -999, -999, -999,
  102683. -999, -999, -999, -999, -999, -999, -999, -999,
  102684. -999, -999, -999, -999, -999, -999, -999, -999},
  102685. {-999, -999, -999, -999, -999, -999, -999, -999,
  102686. -999, -999, -999, -999, -110, -95, -80, -58,
  102687. -55, -49, -66, -68, -71, -78, -78, -80,
  102688. -88, -85, -89, -97, -100, -105, -110, -999,
  102689. -999, -999, -999, -999, -999, -999, -999, -999,
  102690. -999, -999, -999, -999, -999, -999, -999, -999,
  102691. -999, -999, -999, -999, -999, -999, -999, -999},
  102692. {-999, -999, -999, -999, -999, -999, -999, -999,
  102693. -999, -999, -999, -999, -110, -95, -80, -53,
  102694. -52, -41, -59, -59, -49, -58, -56, -63,
  102695. -86, -79, -90, -93, -98, -103, -107, -112,
  102696. -999, -999, -999, -999, -999, -999, -999, -999,
  102697. -999, -999, -999, -999, -999, -999, -999, -999,
  102698. -999, -999, -999, -999, -999, -999, -999, -999},
  102699. {-999, -999, -999, -999, -999, -999, -999, -999,
  102700. -999, -999, -999, -110, -97, -91, -73, -45,
  102701. -40, -33, -53, -61, -49, -54, -50, -50,
  102702. -60, -52, -67, -74, -81, -92, -96, -100,
  102703. -105, -110, -999, -999, -999, -999, -999, -999,
  102704. -999, -999, -999, -999, -999, -999, -999, -999,
  102705. -999, -999, -999, -999, -999, -999, -999, -999}},
  102706. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102707. -999, -999, -999, -113, -106, -99, -92, -77,
  102708. -80, -88, -97, -106, -115, -999, -999, -999,
  102709. -999, -999, -999, -999, -999, -999, -999, -999,
  102710. -999, -999, -999, -999, -999, -999, -999, -999,
  102711. -999, -999, -999, -999, -999, -999, -999, -999,
  102712. -999, -999, -999, -999, -999, -999, -999, -999},
  102713. {-999, -999, -999, -999, -999, -999, -999, -999,
  102714. -999, -999, -116, -109, -102, -95, -89, -74,
  102715. -72, -88, -87, -95, -102, -109, -116, -999,
  102716. -999, -999, -999, -999, -999, -999, -999, -999,
  102717. -999, -999, -999, -999, -999, -999, -999, -999,
  102718. -999, -999, -999, -999, -999, -999, -999, -999,
  102719. -999, -999, -999, -999, -999, -999, -999, -999},
  102720. {-999, -999, -999, -999, -999, -999, -999, -999,
  102721. -999, -999, -116, -109, -102, -95, -89, -75,
  102722. -66, -74, -77, -78, -86, -87, -90, -96,
  102723. -105, -115, -999, -999, -999, -999, -999, -999,
  102724. -999, -999, -999, -999, -999, -999, -999, -999,
  102725. -999, -999, -999, -999, -999, -999, -999, -999,
  102726. -999, -999, -999, -999, -999, -999, -999, -999},
  102727. {-999, -999, -999, -999, -999, -999, -999, -999,
  102728. -999, -999, -115, -108, -101, -94, -88, -66,
  102729. -56, -61, -70, -65, -78, -72, -83, -84,
  102730. -93, -98, -105, -110, -999, -999, -999, -999,
  102731. -999, -999, -999, -999, -999, -999, -999, -999,
  102732. -999, -999, -999, -999, -999, -999, -999, -999,
  102733. -999, -999, -999, -999, -999, -999, -999, -999},
  102734. {-999, -999, -999, -999, -999, -999, -999, -999,
  102735. -999, -999, -110, -105, -95, -89, -82, -57,
  102736. -52, -52, -59, -56, -59, -58, -69, -67,
  102737. -88, -82, -82, -89, -94, -100, -108, -999,
  102738. -999, -999, -999, -999, -999, -999, -999, -999,
  102739. -999, -999, -999, -999, -999, -999, -999, -999,
  102740. -999, -999, -999, -999, -999, -999, -999, -999},
  102741. {-999, -999, -999, -999, -999, -999, -999, -999,
  102742. -999, -110, -101, -96, -90, -83, -77, -54,
  102743. -43, -38, -50, -48, -52, -48, -42, -42,
  102744. -51, -52, -53, -59, -65, -71, -78, -85,
  102745. -95, -999, -999, -999, -999, -999, -999, -999,
  102746. -999, -999, -999, -999, -999, -999, -999, -999,
  102747. -999, -999, -999, -999, -999, -999, -999, -999}},
  102748. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102749. -999, -999, -999, -999, -120, -105, -86, -68,
  102750. -78, -79, -90, -100, -110, -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, -999, -999, -999, -999, -999,
  102754. -999, -999, -999, -999, -999, -999, -999, -999},
  102755. {-999, -999, -999, -999, -999, -999, -999, -999,
  102756. -999, -999, -999, -999, -120, -105, -86, -66,
  102757. -73, -77, -88, -96, -105, -115, -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, -999, -999, -999,
  102761. -999, -999, -999, -999, -999, -999, -999, -999},
  102762. {-999, -999, -999, -999, -999, -999, -999, -999,
  102763. -999, -999, -999, -120, -105, -92, -80, -61,
  102764. -64, -68, -80, -87, -92, -100, -110, -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, -999, -999, -999,
  102768. -999, -999, -999, -999, -999, -999, -999, -999},
  102769. {-999, -999, -999, -999, -999, -999, -999, -999,
  102770. -999, -999, -999, -120, -104, -91, -79, -52,
  102771. -60, -54, -64, -69, -77, -80, -82, -84,
  102772. -85, -87, -88, -90, -999, -999, -999, -999,
  102773. -999, -999, -999, -999, -999, -999, -999, -999,
  102774. -999, -999, -999, -999, -999, -999, -999, -999,
  102775. -999, -999, -999, -999, -999, -999, -999, -999},
  102776. {-999, -999, -999, -999, -999, -999, -999, -999,
  102777. -999, -999, -999, -118, -100, -87, -77, -49,
  102778. -50, -44, -58, -61, -61, -67, -65, -62,
  102779. -62, -62, -65, -68, -999, -999, -999, -999,
  102780. -999, -999, -999, -999, -999, -999, -999, -999,
  102781. -999, -999, -999, -999, -999, -999, -999, -999,
  102782. -999, -999, -999, -999, -999, -999, -999, -999},
  102783. {-999, -999, -999, -999, -999, -999, -999, -999,
  102784. -999, -999, -999, -115, -98, -84, -62, -49,
  102785. -44, -38, -46, -49, -49, -46, -39, -37,
  102786. -39, -40, -42, -43, -999, -999, -999, -999,
  102787. -999, -999, -999, -999, -999, -999, -999, -999,
  102788. -999, -999, -999, -999, -999, -999, -999, -999,
  102789. -999, -999, -999, -999, -999, -999, -999, -999}},
  102790. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102791. -999, -999, -999, -999, -999, -110, -88, -74,
  102792. -77, -82, -82, -85, -90, -94, -99, -104,
  102793. -999, -999, -999, -999, -999, -999, -999, -999,
  102794. -999, -999, -999, -999, -999, -999, -999, -999,
  102795. -999, -999, -999, -999, -999, -999, -999, -999,
  102796. -999, -999, -999, -999, -999, -999, -999, -999},
  102797. {-999, -999, -999, -999, -999, -999, -999, -999,
  102798. -999, -999, -999, -999, -999, -110, -88, -66,
  102799. -70, -81, -80, -81, -84, -88, -91, -93,
  102800. -999, -999, -999, -999, -999, -999, -999, -999,
  102801. -999, -999, -999, -999, -999, -999, -999, -999,
  102802. -999, -999, -999, -999, -999, -999, -999, -999,
  102803. -999, -999, -999, -999, -999, -999, -999, -999},
  102804. {-999, -999, -999, -999, -999, -999, -999, -999,
  102805. -999, -999, -999, -999, -999, -110, -88, -61,
  102806. -63, -70, -71, -74, -77, -80, -83, -85,
  102807. -999, -999, -999, -999, -999, -999, -999, -999,
  102808. -999, -999, -999, -999, -999, -999, -999, -999,
  102809. -999, -999, -999, -999, -999, -999, -999, -999,
  102810. -999, -999, -999, -999, -999, -999, -999, -999},
  102811. {-999, -999, -999, -999, -999, -999, -999, -999,
  102812. -999, -999, -999, -999, -999, -110, -86, -62,
  102813. -63, -62, -62, -58, -52, -50, -50, -52,
  102814. -54, -999, -999, -999, -999, -999, -999, -999,
  102815. -999, -999, -999, -999, -999, -999, -999, -999,
  102816. -999, -999, -999, -999, -999, -999, -999, -999,
  102817. -999, -999, -999, -999, -999, -999, -999, -999},
  102818. {-999, -999, -999, -999, -999, -999, -999, -999,
  102819. -999, -999, -999, -999, -118, -108, -84, -53,
  102820. -50, -50, -50, -55, -47, -45, -40, -40,
  102821. -40, -999, -999, -999, -999, -999, -999, -999,
  102822. -999, -999, -999, -999, -999, -999, -999, -999,
  102823. -999, -999, -999, -999, -999, -999, -999, -999,
  102824. -999, -999, -999, -999, -999, -999, -999, -999},
  102825. {-999, -999, -999, -999, -999, -999, -999, -999,
  102826. -999, -999, -999, -999, -118, -100, -73, -43,
  102827. -37, -42, -43, -53, -38, -37, -35, -35,
  102828. -38, -999, -999, -999, -999, -999, -999, -999,
  102829. -999, -999, -999, -999, -999, -999, -999, -999,
  102830. -999, -999, -999, -999, -999, -999, -999, -999,
  102831. -999, -999, -999, -999, -999, -999, -999, -999}},
  102832. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102833. -999, -999, -999, -110, -100, -91, -84, -74,
  102834. -80, -80, -80, -80, -80, -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, -999, -999, -999, -999, -999,
  102838. -999, -999, -999, -999, -999, -999, -999, -999},
  102839. {-999, -999, -999, -999, -999, -999, -999, -999,
  102840. -999, -999, -999, -110, -100, -91, -84, -74,
  102841. -68, -68, -68, -68, -68, -999, -999, -999,
  102842. -999, -999, -999, -999, -999, -999, -999, -999,
  102843. -999, -999, -999, -999, -999, -999, -999, -999,
  102844. -999, -999, -999, -999, -999, -999, -999, -999,
  102845. -999, -999, -999, -999, -999, -999, -999, -999},
  102846. {-999, -999, -999, -999, -999, -999, -999, -999,
  102847. -999, -999, -999, -110, -100, -86, -78, -70,
  102848. -60, -45, -30, -21, -999, -999, -999, -999,
  102849. -999, -999, -999, -999, -999, -999, -999, -999,
  102850. -999, -999, -999, -999, -999, -999, -999, -999,
  102851. -999, -999, -999, -999, -999, -999, -999, -999,
  102852. -999, -999, -999, -999, -999, -999, -999, -999},
  102853. {-999, -999, -999, -999, -999, -999, -999, -999,
  102854. -999, -999, -999, -110, -100, -87, -78, -67,
  102855. -48, -38, -29, -21, -999, -999, -999, -999,
  102856. -999, -999, -999, -999, -999, -999, -999, -999,
  102857. -999, -999, -999, -999, -999, -999, -999, -999,
  102858. -999, -999, -999, -999, -999, -999, -999, -999,
  102859. -999, -999, -999, -999, -999, -999, -999, -999},
  102860. {-999, -999, -999, -999, -999, -999, -999, -999,
  102861. -999, -999, -999, -110, -100, -86, -69, -56,
  102862. -45, -35, -33, -29, -999, -999, -999, -999,
  102863. -999, -999, -999, -999, -999, -999, -999, -999,
  102864. -999, -999, -999, -999, -999, -999, -999, -999,
  102865. -999, -999, -999, -999, -999, -999, -999, -999,
  102866. -999, -999, -999, -999, -999, -999, -999, -999},
  102867. {-999, -999, -999, -999, -999, -999, -999, -999,
  102868. -999, -999, -999, -110, -100, -83, -71, -48,
  102869. -27, -38, -37, -34, -999, -999, -999, -999,
  102870. -999, -999, -999, -999, -999, -999, -999, -999,
  102871. -999, -999, -999, -999, -999, -999, -999, -999,
  102872. -999, -999, -999, -999, -999, -999, -999, -999,
  102873. -999, -999, -999, -999, -999, -999, -999, -999}}
  102874. };
  102875. #endif
  102876. /*** End of inlined file: masking.h ***/
  102877. #define NEGINF -9999.f
  102878. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  102879. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  102880. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  102881. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  102882. vorbis_info_psy_global *gi=&ci->psy_g_param;
  102883. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  102884. look->channels=vi->channels;
  102885. look->ampmax=-9999.;
  102886. look->gi=gi;
  102887. return(look);
  102888. }
  102889. void _vp_global_free(vorbis_look_psy_global *look){
  102890. if(look){
  102891. memset(look,0,sizeof(*look));
  102892. _ogg_free(look);
  102893. }
  102894. }
  102895. void _vi_gpsy_free(vorbis_info_psy_global *i){
  102896. if(i){
  102897. memset(i,0,sizeof(*i));
  102898. _ogg_free(i);
  102899. }
  102900. }
  102901. void _vi_psy_free(vorbis_info_psy *i){
  102902. if(i){
  102903. memset(i,0,sizeof(*i));
  102904. _ogg_free(i);
  102905. }
  102906. }
  102907. static void min_curve(float *c,
  102908. float *c2){
  102909. int i;
  102910. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  102911. }
  102912. static void max_curve(float *c,
  102913. float *c2){
  102914. int i;
  102915. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  102916. }
  102917. static void attenuate_curve(float *c,float att){
  102918. int i;
  102919. for(i=0;i<EHMER_MAX;i++)
  102920. c[i]+=att;
  102921. }
  102922. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  102923. float center_boost, float center_decay_rate){
  102924. int i,j,k,m;
  102925. float ath[EHMER_MAX];
  102926. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  102927. float athc[P_LEVELS][EHMER_MAX];
  102928. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  102929. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  102930. memset(workc,0,sizeof(workc));
  102931. for(i=0;i<P_BANDS;i++){
  102932. int ath_offset=i*4;
  102933. for(j=0;j<EHMER_MAX;j++){
  102934. float min=999.;
  102935. for(k=0;k<4;k++)
  102936. if(j+k+ath_offset<MAX_ATH){
  102937. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  102938. }else{
  102939. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  102940. }
  102941. ath[j]=min;
  102942. }
  102943. for(j=0;j<6;j++)
  102944. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  102945. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  102946. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  102947. for(j=0;j<P_LEVELS;j++){
  102948. for(k=0;k<EHMER_MAX;k++){
  102949. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  102950. if(adj<0. && center_boost>0)adj=0.;
  102951. if(adj>0. && center_boost<0)adj=0.;
  102952. workc[i][j][k]+=adj;
  102953. }
  102954. }
  102955. for(j=0;j<P_LEVELS;j++){
  102956. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  102957. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  102958. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  102959. max_curve(athc[j],workc[i][j]);
  102960. }
  102961. for(j=1;j<P_LEVELS;j++){
  102962. min_curve(athc[j],athc[j-1]);
  102963. min_curve(workc[i][j],athc[j]);
  102964. }
  102965. }
  102966. for(i=0;i<P_BANDS;i++){
  102967. int hi_curve,lo_curve,bin;
  102968. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  102969. bin=floor(fromOC(i*.5)/binHz);
  102970. lo_curve= ceil(toOC(bin*binHz+1)*2);
  102971. hi_curve= floor(toOC((bin+1)*binHz)*2);
  102972. if(lo_curve>i)lo_curve=i;
  102973. if(lo_curve<0)lo_curve=0;
  102974. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  102975. for(m=0;m<P_LEVELS;m++){
  102976. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  102977. for(j=0;j<n;j++)brute_buffer[j]=999.;
  102978. for(k=lo_curve;k<=hi_curve;k++){
  102979. int l=0;
  102980. for(j=0;j<EHMER_MAX;j++){
  102981. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  102982. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  102983. if(lo_bin<0)lo_bin=0;
  102984. if(lo_bin>n)lo_bin=n;
  102985. if(lo_bin<l)l=lo_bin;
  102986. if(hi_bin<0)hi_bin=0;
  102987. if(hi_bin>n)hi_bin=n;
  102988. for(;l<hi_bin && l<n;l++)
  102989. if(brute_buffer[l]>workc[k][m][j])
  102990. brute_buffer[l]=workc[k][m][j];
  102991. }
  102992. for(;l<n;l++)
  102993. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  102994. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  102995. }
  102996. if(i+1<P_BANDS){
  102997. int l=0;
  102998. k=i+1;
  102999. for(j=0;j<EHMER_MAX;j++){
  103000. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103001. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103002. if(lo_bin<0)lo_bin=0;
  103003. if(lo_bin>n)lo_bin=n;
  103004. if(lo_bin<l)l=lo_bin;
  103005. if(hi_bin<0)hi_bin=0;
  103006. if(hi_bin>n)hi_bin=n;
  103007. for(;l<hi_bin && l<n;l++)
  103008. if(brute_buffer[l]>workc[k][m][j])
  103009. brute_buffer[l]=workc[k][m][j];
  103010. }
  103011. for(;l<n;l++)
  103012. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103013. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103014. }
  103015. for(j=0;j<EHMER_MAX;j++){
  103016. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103017. if(bin<0){
  103018. ret[i][m][j+2]=-999.;
  103019. }else{
  103020. if(bin>=n){
  103021. ret[i][m][j+2]=-999.;
  103022. }else{
  103023. ret[i][m][j+2]=brute_buffer[bin];
  103024. }
  103025. }
  103026. }
  103027. for(j=0;j<EHMER_OFFSET;j++)
  103028. if(ret[i][m][j+2]>-200.f)break;
  103029. ret[i][m][0]=j;
  103030. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103031. if(ret[i][m][j+2]>-200.f)
  103032. break;
  103033. ret[i][m][1]=j;
  103034. }
  103035. }
  103036. return(ret);
  103037. }
  103038. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103039. vorbis_info_psy_global *gi,int n,long rate){
  103040. long i,j,lo=-99,hi=1;
  103041. long maxoc;
  103042. memset(p,0,sizeof(*p));
  103043. p->eighth_octave_lines=gi->eighth_octave_lines;
  103044. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103045. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103046. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103047. p->total_octave_lines=maxoc-p->firstoc+1;
  103048. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103049. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103050. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103051. p->vi=vi;
  103052. p->n=n;
  103053. p->rate=rate;
  103054. p->m_val = 1.;
  103055. if(rate < 26000) p->m_val = 0;
  103056. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103057. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103058. for(i=0,j=0;i<MAX_ATH-1;i++){
  103059. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103060. float base=ATH[i];
  103061. if(j<endpos){
  103062. float delta=(ATH[i+1]-base)/(endpos-j);
  103063. for(;j<endpos && j<n;j++){
  103064. p->ath[j]=base+100.;
  103065. base+=delta;
  103066. }
  103067. }
  103068. }
  103069. for(i=0;i<n;i++){
  103070. float bark=toBARK(rate/(2*n)*i);
  103071. for(;lo+vi->noisewindowlomin<i &&
  103072. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103073. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103074. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103075. p->bark[i]=((lo-1)<<16)+(hi-1);
  103076. }
  103077. for(i=0;i<n;i++)
  103078. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103079. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103080. vi->tone_centerboost,vi->tone_decay);
  103081. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103082. for(i=0;i<P_NOISECURVES;i++)
  103083. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103084. for(i=0;i<n;i++){
  103085. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103086. int inthalfoc;
  103087. float del;
  103088. if(halfoc<0)halfoc=0;
  103089. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103090. inthalfoc=(int)halfoc;
  103091. del=halfoc-inthalfoc;
  103092. for(j=0;j<P_NOISECURVES;j++)
  103093. p->noiseoffset[j][i]=
  103094. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103095. p->vi->noiseoff[j][inthalfoc+1]*del;
  103096. }
  103097. #if 0
  103098. {
  103099. static int ls=0;
  103100. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103101. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103102. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103103. }
  103104. #endif
  103105. }
  103106. void _vp_psy_clear(vorbis_look_psy *p){
  103107. int i,j;
  103108. if(p){
  103109. if(p->ath)_ogg_free(p->ath);
  103110. if(p->octave)_ogg_free(p->octave);
  103111. if(p->bark)_ogg_free(p->bark);
  103112. if(p->tonecurves){
  103113. for(i=0;i<P_BANDS;i++){
  103114. for(j=0;j<P_LEVELS;j++){
  103115. _ogg_free(p->tonecurves[i][j]);
  103116. }
  103117. _ogg_free(p->tonecurves[i]);
  103118. }
  103119. _ogg_free(p->tonecurves);
  103120. }
  103121. if(p->noiseoffset){
  103122. for(i=0;i<P_NOISECURVES;i++){
  103123. _ogg_free(p->noiseoffset[i]);
  103124. }
  103125. _ogg_free(p->noiseoffset);
  103126. }
  103127. memset(p,0,sizeof(*p));
  103128. }
  103129. }
  103130. static void seed_curve(float *seed,
  103131. const float **curves,
  103132. float amp,
  103133. int oc, int n,
  103134. int linesper,float dBoffset){
  103135. int i,post1;
  103136. int seedptr;
  103137. const float *posts,*curve;
  103138. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103139. choice=max(choice,0);
  103140. choice=min(choice,P_LEVELS-1);
  103141. posts=curves[choice];
  103142. curve=posts+2;
  103143. post1=(int)posts[1];
  103144. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103145. for(i=posts[0];i<post1;i++){
  103146. if(seedptr>0){
  103147. float lin=amp+curve[i];
  103148. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103149. }
  103150. seedptr+=linesper;
  103151. if(seedptr>=n)break;
  103152. }
  103153. }
  103154. static void seed_loop(vorbis_look_psy *p,
  103155. const float ***curves,
  103156. const float *f,
  103157. const float *flr,
  103158. float *seed,
  103159. float specmax){
  103160. vorbis_info_psy *vi=p->vi;
  103161. long n=p->n,i;
  103162. float dBoffset=vi->max_curve_dB-specmax;
  103163. for(i=0;i<n;i++){
  103164. float max=f[i];
  103165. long oc=p->octave[i];
  103166. while(i+1<n && p->octave[i+1]==oc){
  103167. i++;
  103168. if(f[i]>max)max=f[i];
  103169. }
  103170. if(max+6.f>flr[i]){
  103171. oc=oc>>p->shiftoc;
  103172. if(oc>=P_BANDS)oc=P_BANDS-1;
  103173. if(oc<0)oc=0;
  103174. seed_curve(seed,
  103175. curves[oc],
  103176. max,
  103177. p->octave[i]-p->firstoc,
  103178. p->total_octave_lines,
  103179. p->eighth_octave_lines,
  103180. dBoffset);
  103181. }
  103182. }
  103183. }
  103184. static void seed_chase(float *seeds, int linesper, long n){
  103185. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103186. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103187. long stack=0;
  103188. long pos=0;
  103189. long i;
  103190. for(i=0;i<n;i++){
  103191. if(stack<2){
  103192. posstack[stack]=i;
  103193. ampstack[stack++]=seeds[i];
  103194. }else{
  103195. while(1){
  103196. if(seeds[i]<ampstack[stack-1]){
  103197. posstack[stack]=i;
  103198. ampstack[stack++]=seeds[i];
  103199. break;
  103200. }else{
  103201. if(i<posstack[stack-1]+linesper){
  103202. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103203. i<posstack[stack-2]+linesper){
  103204. stack--;
  103205. continue;
  103206. }
  103207. }
  103208. posstack[stack]=i;
  103209. ampstack[stack++]=seeds[i];
  103210. break;
  103211. }
  103212. }
  103213. }
  103214. }
  103215. for(i=0;i<stack;i++){
  103216. long endpos;
  103217. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103218. endpos=posstack[i+1];
  103219. }else{
  103220. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103221. discarded in short frames */
  103222. }
  103223. if(endpos>n)endpos=n;
  103224. for(;pos<endpos;pos++)
  103225. seeds[pos]=ampstack[i];
  103226. }
  103227. }
  103228. #include<stdio.h>
  103229. static void max_seeds(vorbis_look_psy *p,
  103230. float *seed,
  103231. float *flr){
  103232. long n=p->total_octave_lines;
  103233. int linesper=p->eighth_octave_lines;
  103234. long linpos=0;
  103235. long pos;
  103236. seed_chase(seed,linesper,n); /* for masking */
  103237. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103238. while(linpos+1<p->n){
  103239. float minV=seed[pos];
  103240. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103241. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103242. while(pos+1<=end){
  103243. pos++;
  103244. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103245. minV=seed[pos];
  103246. }
  103247. end=pos+p->firstoc;
  103248. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103249. if(flr[linpos]<minV)flr[linpos]=minV;
  103250. }
  103251. {
  103252. float minV=seed[p->total_octave_lines-1];
  103253. for(;linpos<p->n;linpos++)
  103254. if(flr[linpos]<minV)flr[linpos]=minV;
  103255. }
  103256. }
  103257. static void bark_noise_hybridmp(int n,const long *b,
  103258. const float *f,
  103259. float *noise,
  103260. const float offset,
  103261. const int fixed){
  103262. float *N=(float*) alloca(n*sizeof(*N));
  103263. float *X=(float*) alloca(n*sizeof(*N));
  103264. float *XX=(float*) alloca(n*sizeof(*N));
  103265. float *Y=(float*) alloca(n*sizeof(*N));
  103266. float *XY=(float*) alloca(n*sizeof(*N));
  103267. float tN, tX, tXX, tY, tXY;
  103268. int i;
  103269. int lo, hi;
  103270. float R, A, B, D;
  103271. float w, x, y;
  103272. tN = tX = tXX = tY = tXY = 0.f;
  103273. y = f[0] + offset;
  103274. if (y < 1.f) y = 1.f;
  103275. w = y * y * .5;
  103276. tN += w;
  103277. tX += w;
  103278. tY += w * y;
  103279. N[0] = tN;
  103280. X[0] = tX;
  103281. XX[0] = tXX;
  103282. Y[0] = tY;
  103283. XY[0] = tXY;
  103284. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103285. y = f[i] + offset;
  103286. if (y < 1.f) y = 1.f;
  103287. w = y * y;
  103288. tN += w;
  103289. tX += w * x;
  103290. tXX += w * x * x;
  103291. tY += w * y;
  103292. tXY += w * x * y;
  103293. N[i] = tN;
  103294. X[i] = tX;
  103295. XX[i] = tXX;
  103296. Y[i] = tY;
  103297. XY[i] = tXY;
  103298. }
  103299. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103300. lo = b[i] >> 16;
  103301. if( lo>=0 ) break;
  103302. hi = b[i] & 0xffff;
  103303. tN = N[hi] + N[-lo];
  103304. tX = X[hi] - X[-lo];
  103305. tXX = XX[hi] + XX[-lo];
  103306. tY = Y[hi] + Y[-lo];
  103307. tXY = XY[hi] - XY[-lo];
  103308. A = tY * tXX - tX * tXY;
  103309. B = tN * tXY - tX * tY;
  103310. D = tN * tXX - tX * tX;
  103311. R = (A + x * B) / D;
  103312. if (R < 0.f)
  103313. R = 0.f;
  103314. noise[i] = R - offset;
  103315. }
  103316. for ( ;; i++, x += 1.f) {
  103317. lo = b[i] >> 16;
  103318. hi = b[i] & 0xffff;
  103319. if(hi>=n)break;
  103320. tN = N[hi] - N[lo];
  103321. tX = X[hi] - X[lo];
  103322. tXX = XX[hi] - XX[lo];
  103323. tY = Y[hi] - Y[lo];
  103324. tXY = XY[hi] - XY[lo];
  103325. A = tY * tXX - tX * tXY;
  103326. B = tN * tXY - tX * tY;
  103327. D = tN * tXX - tX * tX;
  103328. R = (A + x * B) / D;
  103329. if (R < 0.f) R = 0.f;
  103330. noise[i] = R - offset;
  103331. }
  103332. for ( ; i < n; i++, x += 1.f) {
  103333. R = (A + x * B) / D;
  103334. if (R < 0.f) R = 0.f;
  103335. noise[i] = R - offset;
  103336. }
  103337. if (fixed <= 0) return;
  103338. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103339. hi = i + fixed / 2;
  103340. lo = hi - fixed;
  103341. if(lo>=0)break;
  103342. tN = N[hi] + N[-lo];
  103343. tX = X[hi] - X[-lo];
  103344. tXX = XX[hi] + XX[-lo];
  103345. tY = Y[hi] + Y[-lo];
  103346. tXY = XY[hi] - XY[-lo];
  103347. A = tY * tXX - tX * tXY;
  103348. B = tN * tXY - tX * tY;
  103349. D = tN * tXX - tX * tX;
  103350. R = (A + x * B) / D;
  103351. if (R - offset < noise[i]) noise[i] = R - offset;
  103352. }
  103353. for ( ;; i++, x += 1.f) {
  103354. hi = i + fixed / 2;
  103355. lo = hi - fixed;
  103356. if(hi>=n)break;
  103357. tN = N[hi] - N[lo];
  103358. tX = X[hi] - X[lo];
  103359. tXX = XX[hi] - XX[lo];
  103360. tY = Y[hi] - Y[lo];
  103361. tXY = XY[hi] - XY[lo];
  103362. A = tY * tXX - tX * tXY;
  103363. B = tN * tXY - tX * tY;
  103364. D = tN * tXX - tX * tX;
  103365. R = (A + x * B) / D;
  103366. if (R - offset < noise[i]) noise[i] = R - offset;
  103367. }
  103368. for ( ; i < n; i++, x += 1.f) {
  103369. R = (A + x * B) / D;
  103370. if (R - offset < noise[i]) noise[i] = R - offset;
  103371. }
  103372. }
  103373. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103374. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103375. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103376. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103377. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103378. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103379. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103380. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103381. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103382. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103383. 973377.F, 913981.F, 858210.F, 805842.F,
  103384. 756669.F, 710497.F, 667142.F, 626433.F,
  103385. 588208.F, 552316.F, 518613.F, 486967.F,
  103386. 457252.F, 429351.F, 403152.F, 378551.F,
  103387. 355452.F, 333762.F, 313396.F, 294273.F,
  103388. 276316.F, 259455.F, 243623.F, 228757.F,
  103389. 214798.F, 201691.F, 189384.F, 177828.F,
  103390. 166977.F, 156788.F, 147221.F, 138237.F,
  103391. 129802.F, 121881.F, 114444.F, 107461.F,
  103392. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103393. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103394. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103395. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103396. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103397. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103398. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103399. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103400. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103401. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103402. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103403. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103404. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103405. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103406. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103407. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103408. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103409. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103410. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103411. 842.910F, 791.475F, 743.179F, 697.830F,
  103412. 655.249F, 615.265F, 577.722F, 542.469F,
  103413. 509.367F, 478.286F, 449.101F, 421.696F,
  103414. 395.964F, 371.803F, 349.115F, 327.812F,
  103415. 307.809F, 289.026F, 271.390F, 254.830F,
  103416. 239.280F, 224.679F, 210.969F, 198.096F,
  103417. 186.008F, 174.658F, 164.000F, 153.993F,
  103418. 144.596F, 135.773F, 127.488F, 119.708F,
  103419. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103420. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103421. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103422. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103423. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103424. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103425. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103426. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103427. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103428. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103429. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103430. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103431. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103432. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103433. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103434. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103435. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103436. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103437. 1.20790F, 1.13419F, 1.06499F, 1.F
  103438. };
  103439. void _vp_remove_floor(vorbis_look_psy *p,
  103440. float *mdct,
  103441. int *codedflr,
  103442. float *residue,
  103443. int sliding_lowpass){
  103444. int i,n=p->n;
  103445. if(sliding_lowpass>n)sliding_lowpass=n;
  103446. for(i=0;i<sliding_lowpass;i++){
  103447. residue[i]=
  103448. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103449. }
  103450. for(;i<n;i++)
  103451. residue[i]=0.;
  103452. }
  103453. void _vp_noisemask(vorbis_look_psy *p,
  103454. float *logmdct,
  103455. float *logmask){
  103456. int i,n=p->n;
  103457. float *work=(float*) alloca(n*sizeof(*work));
  103458. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103459. 140.,-1);
  103460. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103461. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103462. p->vi->noisewindowfixed);
  103463. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103464. #if 0
  103465. {
  103466. static int seq=0;
  103467. float work2[n];
  103468. for(i=0;i<n;i++){
  103469. work2[i]=logmask[i]+work[i];
  103470. }
  103471. if(seq&1)
  103472. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103473. else
  103474. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103475. if(seq&1)
  103476. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103477. else
  103478. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103479. seq++;
  103480. }
  103481. #endif
  103482. for(i=0;i<n;i++){
  103483. int dB=logmask[i]+.5;
  103484. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103485. if(dB<0)dB=0;
  103486. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103487. }
  103488. }
  103489. void _vp_tonemask(vorbis_look_psy *p,
  103490. float *logfft,
  103491. float *logmask,
  103492. float global_specmax,
  103493. float local_specmax){
  103494. int i,n=p->n;
  103495. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103496. float att=local_specmax+p->vi->ath_adjatt;
  103497. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103498. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103499. for(i=0;i<n;i++)
  103500. logmask[i]=p->ath[i]+att;
  103501. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103502. max_seeds(p,seed,logmask);
  103503. }
  103504. void _vp_offset_and_mix(vorbis_look_psy *p,
  103505. float *noise,
  103506. float *tone,
  103507. int offset_select,
  103508. float *logmask,
  103509. float *mdct,
  103510. float *logmdct){
  103511. int i,n=p->n;
  103512. float de, coeffi, cx;/* AoTuV */
  103513. float toneatt=p->vi->tone_masteratt[offset_select];
  103514. cx = p->m_val;
  103515. for(i=0;i<n;i++){
  103516. float val= noise[i]+p->noiseoffset[offset_select][i];
  103517. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  103518. logmask[i]=max(val,tone[i]+toneatt);
  103519. if(offset_select == 1) {
  103520. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  103521. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  103522. if(val > coeffi){
  103523. de = 1.0-((val-coeffi)*0.005*cx);
  103524. if(de < 0) de = 0.0001;
  103525. }else
  103526. de = 1.0-((val-coeffi)*0.0003*cx);
  103527. mdct[i] *= de;
  103528. }
  103529. }
  103530. }
  103531. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  103532. vorbis_info *vi=vd->vi;
  103533. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103534. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103535. int n=ci->blocksizes[vd->W]/2;
  103536. float secs=(float)n/vi->rate;
  103537. amp+=secs*gi->ampmax_att_per_sec;
  103538. if(amp<-9999)amp=-9999;
  103539. return(amp);
  103540. }
  103541. static void couple_lossless(float A, float B,
  103542. float *qA, float *qB){
  103543. int test1=fabs(*qA)>fabs(*qB);
  103544. test1-= fabs(*qA)<fabs(*qB);
  103545. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  103546. if(test1==1){
  103547. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  103548. }else{
  103549. float temp=*qB;
  103550. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  103551. *qA=temp;
  103552. }
  103553. if(*qB>fabs(*qA)*1.9999f){
  103554. *qB= -fabs(*qA)*2.f;
  103555. *qA= -*qA;
  103556. }
  103557. }
  103558. static float hypot_lookup[32]={
  103559. -0.009935, -0.011245, -0.012726, -0.014397,
  103560. -0.016282, -0.018407, -0.020800, -0.023494,
  103561. -0.026522, -0.029923, -0.033737, -0.038010,
  103562. -0.042787, -0.048121, -0.054064, -0.060671,
  103563. -0.068000, -0.076109, -0.085054, -0.094892,
  103564. -0.105675, -0.117451, -0.130260, -0.144134,
  103565. -0.159093, -0.175146, -0.192286, -0.210490,
  103566. -0.229718, -0.249913, -0.271001, -0.292893};
  103567. static void precomputed_couple_point(float premag,
  103568. int floorA,int floorB,
  103569. float *mag, float *ang){
  103570. int test=(floorA>floorB)-1;
  103571. int offset=31-abs(floorA-floorB);
  103572. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  103573. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  103574. *mag=premag*floormag;
  103575. *ang=0.f;
  103576. }
  103577. static float dipole_hypot(float a, float b){
  103578. if(a>0.){
  103579. if(b>0.)return sqrt(a*a+b*b);
  103580. if(a>-b)return sqrt(a*a-b*b);
  103581. return -sqrt(b*b-a*a);
  103582. }
  103583. if(b<0.)return -sqrt(a*a+b*b);
  103584. if(-a>b)return -sqrt(a*a-b*b);
  103585. return sqrt(b*b-a*a);
  103586. }
  103587. static float round_hypot(float a, float b){
  103588. if(a>0.){
  103589. if(b>0.)return sqrt(a*a+b*b);
  103590. if(a>-b)return sqrt(a*a+b*b);
  103591. return -sqrt(b*b+a*a);
  103592. }
  103593. if(b<0.)return -sqrt(a*a+b*b);
  103594. if(-a>b)return -sqrt(a*a+b*b);
  103595. return sqrt(b*b+a*a);
  103596. }
  103597. float **_vp_quantize_couple_memo(vorbis_block *vb,
  103598. vorbis_info_psy_global *g,
  103599. vorbis_look_psy *p,
  103600. vorbis_info_mapping0 *vi,
  103601. float **mdct){
  103602. int i,j,n=p->n;
  103603. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103604. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103605. for(i=0;i<vi->coupling_steps;i++){
  103606. float *mdctM=mdct[vi->coupling_mag[i]];
  103607. float *mdctA=mdct[vi->coupling_ang[i]];
  103608. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103609. for(j=0;j<limit;j++)
  103610. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  103611. for(;j<n;j++)
  103612. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  103613. }
  103614. return(ret);
  103615. }
  103616. static int apsort(const void *a, const void *b){
  103617. float f1=fabs(**(float**)a);
  103618. float f2=fabs(**(float**)b);
  103619. return (f1<f2)-(f1>f2);
  103620. }
  103621. int **_vp_quantize_couple_sort(vorbis_block *vb,
  103622. vorbis_look_psy *p,
  103623. vorbis_info_mapping0 *vi,
  103624. float **mags){
  103625. if(p->vi->normal_point_p){
  103626. int i,j,k,n=p->n;
  103627. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  103628. int partition=p->vi->normal_partition;
  103629. float **work=(float**) alloca(sizeof(*work)*partition);
  103630. for(i=0;i<vi->coupling_steps;i++){
  103631. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  103632. for(j=0;j<n;j+=partition){
  103633. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  103634. qsort(work,partition,sizeof(*work),apsort);
  103635. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  103636. }
  103637. }
  103638. return(ret);
  103639. }
  103640. return(NULL);
  103641. }
  103642. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  103643. float *magnitudes,int *sortedindex){
  103644. int i,j,n=p->n;
  103645. vorbis_info_psy *vi=p->vi;
  103646. int partition=vi->normal_partition;
  103647. float **work=(float**) alloca(sizeof(*work)*partition);
  103648. int start=vi->normal_start;
  103649. for(j=start;j<n;j+=partition){
  103650. if(j+partition>n)partition=n-j;
  103651. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  103652. qsort(work,partition,sizeof(*work),apsort);
  103653. for(i=0;i<partition;i++){
  103654. sortedindex[i+j-start]=work[i]-magnitudes;
  103655. }
  103656. }
  103657. }
  103658. void _vp_noise_normalize(vorbis_look_psy *p,
  103659. float *in,float *out,int *sortedindex){
  103660. int flag=0,i,j=0,n=p->n;
  103661. vorbis_info_psy *vi=p->vi;
  103662. int partition=vi->normal_partition;
  103663. int start=vi->normal_start;
  103664. if(start>n)start=n;
  103665. if(vi->normal_channel_p){
  103666. for(;j<start;j++)
  103667. out[j]=rint(in[j]);
  103668. for(;j+partition<=n;j+=partition){
  103669. float acc=0.;
  103670. int k;
  103671. for(i=j;i<j+partition;i++)
  103672. acc+=in[i]*in[i];
  103673. for(i=0;i<partition;i++){
  103674. k=sortedindex[i+j-start];
  103675. if(in[k]*in[k]>=.25f){
  103676. out[k]=rint(in[k]);
  103677. acc-=in[k]*in[k];
  103678. flag=1;
  103679. }else{
  103680. if(acc<vi->normal_thresh)break;
  103681. out[k]=unitnorm(in[k]);
  103682. acc-=1.;
  103683. }
  103684. }
  103685. for(;i<partition;i++){
  103686. k=sortedindex[i+j-start];
  103687. out[k]=0.;
  103688. }
  103689. }
  103690. }
  103691. for(;j<n;j++)
  103692. out[j]=rint(in[j]);
  103693. }
  103694. void _vp_couple(int blobno,
  103695. vorbis_info_psy_global *g,
  103696. vorbis_look_psy *p,
  103697. vorbis_info_mapping0 *vi,
  103698. float **res,
  103699. float **mag_memo,
  103700. int **mag_sort,
  103701. int **ifloor,
  103702. int *nonzero,
  103703. int sliding_lowpass){
  103704. int i,j,k,n=p->n;
  103705. for(i=0;i<vi->coupling_steps;i++){
  103706. if(nonzero[vi->coupling_mag[i]] ||
  103707. nonzero[vi->coupling_ang[i]]){
  103708. float *rM=res[vi->coupling_mag[i]];
  103709. float *rA=res[vi->coupling_ang[i]];
  103710. float *qM=rM+n;
  103711. float *qA=rA+n;
  103712. int *floorM=ifloor[vi->coupling_mag[i]];
  103713. int *floorA=ifloor[vi->coupling_ang[i]];
  103714. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  103715. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  103716. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  103717. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  103718. int pointlimit=limit;
  103719. nonzero[vi->coupling_mag[i]]=1;
  103720. nonzero[vi->coupling_ang[i]]=1;
  103721. if(n > 1000)
  103722. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  103723. for(j=0;j<p->n;j+=partition){
  103724. float acc=0.f;
  103725. for(k=0;k<partition;k++){
  103726. int l=k+j;
  103727. if(l<sliding_lowpass){
  103728. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  103729. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  103730. precomputed_couple_point(mag_memo[i][l],
  103731. floorM[l],floorA[l],
  103732. qM+l,qA+l);
  103733. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  103734. }else{
  103735. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  103736. }
  103737. }else{
  103738. qM[l]=0.;
  103739. qA[l]=0.;
  103740. }
  103741. }
  103742. if(p->vi->normal_point_p){
  103743. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  103744. int l=mag_sort[i][j+k];
  103745. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  103746. qM[l]=unitnorm(qM[l]);
  103747. acc-=1.f;
  103748. }
  103749. }
  103750. }
  103751. }
  103752. }
  103753. }
  103754. }
  103755. void hf_reduction(vorbis_info_psy_global *g,
  103756. vorbis_look_psy *p,
  103757. vorbis_info_mapping0 *vi,
  103758. float **mdct){
  103759. int i,j,n=p->n, de=0.3*p->m_val;
  103760. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  103761. for(i=0; i<vi->coupling_steps; i++){
  103762. for(j=limit; j<n; j++)
  103763. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  103764. }
  103765. }
  103766. #endif
  103767. /*** End of inlined file: psy.c ***/
  103768. /*** Start of inlined file: registry.c ***/
  103769. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103770. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103771. // tasks..
  103772. #if JUCE_MSVC
  103773. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103774. #endif
  103775. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103776. #if JUCE_USE_OGGVORBIS
  103777. extern vorbis_func_floor floor0_exportbundle;
  103778. extern vorbis_func_floor floor1_exportbundle;
  103779. extern vorbis_func_residue residue0_exportbundle;
  103780. extern vorbis_func_residue residue1_exportbundle;
  103781. extern vorbis_func_residue residue2_exportbundle;
  103782. extern vorbis_func_mapping mapping0_exportbundle;
  103783. vorbis_func_floor *_floor_P[]={
  103784. &floor0_exportbundle,
  103785. &floor1_exportbundle,
  103786. };
  103787. vorbis_func_residue *_residue_P[]={
  103788. &residue0_exportbundle,
  103789. &residue1_exportbundle,
  103790. &residue2_exportbundle,
  103791. };
  103792. vorbis_func_mapping *_mapping_P[]={
  103793. &mapping0_exportbundle,
  103794. };
  103795. #endif
  103796. /*** End of inlined file: registry.c ***/
  103797. /*** Start of inlined file: res0.c ***/
  103798. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  103799. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  103800. // tasks..
  103801. #if JUCE_MSVC
  103802. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  103803. #endif
  103804. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  103805. #if JUCE_USE_OGGVORBIS
  103806. #include <stdlib.h>
  103807. #include <string.h>
  103808. #include <math.h>
  103809. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103810. #include <stdio.h>
  103811. #endif
  103812. typedef struct {
  103813. vorbis_info_residue0 *info;
  103814. int parts;
  103815. int stages;
  103816. codebook *fullbooks;
  103817. codebook *phrasebook;
  103818. codebook ***partbooks;
  103819. int partvals;
  103820. int **decodemap;
  103821. long postbits;
  103822. long phrasebits;
  103823. long frames;
  103824. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  103825. int train_seq;
  103826. long *training_data[8][64];
  103827. float training_max[8][64];
  103828. float training_min[8][64];
  103829. float tmin;
  103830. float tmax;
  103831. #endif
  103832. } vorbis_look_residue0;
  103833. void res0_free_info(vorbis_info_residue *i){
  103834. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  103835. if(info){
  103836. memset(info,0,sizeof(*info));
  103837. _ogg_free(info);
  103838. }
  103839. }
  103840. void res0_free_look(vorbis_look_residue *i){
  103841. int j;
  103842. if(i){
  103843. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  103844. #ifdef TRAIN_RES
  103845. {
  103846. int j,k,l;
  103847. for(j=0;j<look->parts;j++){
  103848. for(k=0;k<8;k++)
  103849. if(look->training_data[k][j]){
  103850. char buffer[80];
  103851. FILE *of;
  103852. codebook *statebook=look->partbooks[j][k];
  103853. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  103854. of=fopen(buffer,"a");
  103855. for(l=0;l<statebook->entries;l++)
  103856. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  103857. fclose(of);
  103858. _ogg_free(look->training_data[k][j]);
  103859. look->training_data[k][j]=NULL;
  103860. }
  103861. }
  103862. }
  103863. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  103864. #endif
  103865. for(j=0;j<look->parts;j++)
  103866. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  103867. _ogg_free(look->partbooks);
  103868. for(j=0;j<look->partvals;j++)
  103869. _ogg_free(look->decodemap[j]);
  103870. _ogg_free(look->decodemap);
  103871. memset(look,0,sizeof(*look));
  103872. _ogg_free(look);
  103873. }
  103874. }
  103875. static int icount(unsigned int v){
  103876. int ret=0;
  103877. while(v){
  103878. ret+=v&1;
  103879. v>>=1;
  103880. }
  103881. return(ret);
  103882. }
  103883. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  103884. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103885. int j,acc=0;
  103886. oggpack_write(opb,info->begin,24);
  103887. oggpack_write(opb,info->end,24);
  103888. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  103889. code with a partitioned book */
  103890. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  103891. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  103892. for(j=0;j<info->partitions;j++){
  103893. if(ilog(info->secondstages[j])>3){
  103894. oggpack_write(opb,info->secondstages[j],3);
  103895. oggpack_write(opb,1,1);
  103896. oggpack_write(opb,info->secondstages[j]>>3,5);
  103897. }else
  103898. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  103899. acc+=icount(info->secondstages[j]);
  103900. }
  103901. for(j=0;j<acc;j++)
  103902. oggpack_write(opb,info->booklist[j],8);
  103903. }
  103904. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  103905. int j,acc=0;
  103906. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  103907. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  103908. info->begin=oggpack_read(opb,24);
  103909. info->end=oggpack_read(opb,24);
  103910. info->grouping=oggpack_read(opb,24)+1;
  103911. info->partitions=oggpack_read(opb,6)+1;
  103912. info->groupbook=oggpack_read(opb,8);
  103913. for(j=0;j<info->partitions;j++){
  103914. int cascade=oggpack_read(opb,3);
  103915. if(oggpack_read(opb,1))
  103916. cascade|=(oggpack_read(opb,5)<<3);
  103917. info->secondstages[j]=cascade;
  103918. acc+=icount(cascade);
  103919. }
  103920. for(j=0;j<acc;j++)
  103921. info->booklist[j]=oggpack_read(opb,8);
  103922. if(info->groupbook>=ci->books)goto errout;
  103923. for(j=0;j<acc;j++)
  103924. if(info->booklist[j]>=ci->books)goto errout;
  103925. return(info);
  103926. errout:
  103927. res0_free_info(info);
  103928. return(NULL);
  103929. }
  103930. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  103931. vorbis_info_residue *vr){
  103932. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  103933. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  103934. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  103935. int j,k,acc=0;
  103936. int dim;
  103937. int maxstage=0;
  103938. look->info=info;
  103939. look->parts=info->partitions;
  103940. look->fullbooks=ci->fullbooks;
  103941. look->phrasebook=ci->fullbooks+info->groupbook;
  103942. dim=look->phrasebook->dim;
  103943. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  103944. for(j=0;j<look->parts;j++){
  103945. int stages=ilog(info->secondstages[j]);
  103946. if(stages){
  103947. if(stages>maxstage)maxstage=stages;
  103948. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  103949. for(k=0;k<stages;k++)
  103950. if(info->secondstages[j]&(1<<k)){
  103951. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  103952. #ifdef TRAIN_RES
  103953. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  103954. sizeof(***look->training_data));
  103955. #endif
  103956. }
  103957. }
  103958. }
  103959. look->partvals=rint(pow((float)look->parts,(float)dim));
  103960. look->stages=maxstage;
  103961. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  103962. for(j=0;j<look->partvals;j++){
  103963. long val=j;
  103964. long mult=look->partvals/look->parts;
  103965. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  103966. for(k=0;k<dim;k++){
  103967. long deco=val/mult;
  103968. val-=deco*mult;
  103969. mult/=look->parts;
  103970. look->decodemap[j][k]=deco;
  103971. }
  103972. }
  103973. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  103974. {
  103975. static int train_seq=0;
  103976. look->train_seq=train_seq++;
  103977. }
  103978. #endif
  103979. return(look);
  103980. }
  103981. static int local_book_besterror(codebook *book,float *a){
  103982. int dim=book->dim,i,k,o;
  103983. int best=0;
  103984. encode_aux_threshmatch *tt=book->c->thresh_tree;
  103985. for(k=0,o=dim;k<dim;++k){
  103986. float val=a[--o];
  103987. i=tt->threshvals>>1;
  103988. if(val<tt->quantthresh[i]){
  103989. if(val<tt->quantthresh[i-1]){
  103990. for(--i;i>0;--i)
  103991. if(val>=tt->quantthresh[i-1])
  103992. break;
  103993. }
  103994. }else{
  103995. for(++i;i<tt->threshvals-1;++i)
  103996. if(val<tt->quantthresh[i])break;
  103997. }
  103998. best=(best*tt->quantvals)+tt->quantmap[i];
  103999. }
  104000. if(book->c->lengthlist[best]<=0){
  104001. const static_codebook *c=book->c;
  104002. int i,j;
  104003. float bestf=0.f;
  104004. float *e=book->valuelist;
  104005. best=-1;
  104006. for(i=0;i<book->entries;i++){
  104007. if(c->lengthlist[i]>0){
  104008. float thisx=0.f;
  104009. for(j=0;j<dim;j++){
  104010. float val=(e[j]-a[j]);
  104011. thisx+=val*val;
  104012. }
  104013. if(best==-1 || thisx<bestf){
  104014. bestf=thisx;
  104015. best=i;
  104016. }
  104017. }
  104018. e+=dim;
  104019. }
  104020. }
  104021. {
  104022. float *ptr=book->valuelist+best*dim;
  104023. for(i=0;i<dim;i++)
  104024. *a++ -= *ptr++;
  104025. }
  104026. return(best);
  104027. }
  104028. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104029. codebook *book,long *acc){
  104030. int i,bits=0;
  104031. int dim=book->dim;
  104032. int step=n/dim;
  104033. for(i=0;i<step;i++){
  104034. int entry=local_book_besterror(book,vec+i*dim);
  104035. #ifdef TRAIN_RES
  104036. acc[entry]++;
  104037. #endif
  104038. bits+=vorbis_book_encode(book,entry,opb);
  104039. }
  104040. return(bits);
  104041. }
  104042. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104043. float **in,int ch){
  104044. long i,j,k;
  104045. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104046. vorbis_info_residue0 *info=look->info;
  104047. int samples_per_partition=info->grouping;
  104048. int possible_partitions=info->partitions;
  104049. int n=info->end-info->begin;
  104050. int partvals=n/samples_per_partition;
  104051. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104052. float scale=100./samples_per_partition;
  104053. for(i=0;i<ch;i++){
  104054. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104055. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104056. }
  104057. for(i=0;i<partvals;i++){
  104058. int offset=i*samples_per_partition+info->begin;
  104059. for(j=0;j<ch;j++){
  104060. float max=0.;
  104061. float ent=0.;
  104062. for(k=0;k<samples_per_partition;k++){
  104063. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104064. ent+=fabs(rint(in[j][offset+k]));
  104065. }
  104066. ent*=scale;
  104067. for(k=0;k<possible_partitions-1;k++)
  104068. if(max<=info->classmetric1[k] &&
  104069. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104070. break;
  104071. partword[j][i]=k;
  104072. }
  104073. }
  104074. #ifdef TRAIN_RESAUX
  104075. {
  104076. FILE *of;
  104077. char buffer[80];
  104078. for(i=0;i<ch;i++){
  104079. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104080. of=fopen(buffer,"a");
  104081. for(j=0;j<partvals;j++)
  104082. fprintf(of,"%ld, ",partword[i][j]);
  104083. fprintf(of,"\n");
  104084. fclose(of);
  104085. }
  104086. }
  104087. #endif
  104088. look->frames++;
  104089. return(partword);
  104090. }
  104091. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104092. int ch){
  104093. long i,j,k,l;
  104094. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104095. vorbis_info_residue0 *info=look->info;
  104096. int samples_per_partition=info->grouping;
  104097. int possible_partitions=info->partitions;
  104098. int n=info->end-info->begin;
  104099. int partvals=n/samples_per_partition;
  104100. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104101. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104102. FILE *of;
  104103. char buffer[80];
  104104. #endif
  104105. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104106. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104107. for(i=0,l=info->begin/ch;i<partvals;i++){
  104108. float magmax=0.f;
  104109. float angmax=0.f;
  104110. for(j=0;j<samples_per_partition;j+=ch){
  104111. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104112. for(k=1;k<ch;k++)
  104113. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104114. l++;
  104115. }
  104116. for(j=0;j<possible_partitions-1;j++)
  104117. if(magmax<=info->classmetric1[j] &&
  104118. angmax<=info->classmetric2[j])
  104119. break;
  104120. partword[0][i]=j;
  104121. }
  104122. #ifdef TRAIN_RESAUX
  104123. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104124. of=fopen(buffer,"a");
  104125. for(i=0;i<partvals;i++)
  104126. fprintf(of,"%ld, ",partword[0][i]);
  104127. fprintf(of,"\n");
  104128. fclose(of);
  104129. #endif
  104130. look->frames++;
  104131. return(partword);
  104132. }
  104133. static int _01forward(oggpack_buffer *opb,
  104134. vorbis_block *vb,vorbis_look_residue *vl,
  104135. float **in,int ch,
  104136. long **partword,
  104137. int (*encode)(oggpack_buffer *,float *,int,
  104138. codebook *,long *)){
  104139. long i,j,k,s;
  104140. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104141. vorbis_info_residue0 *info=look->info;
  104142. int samples_per_partition=info->grouping;
  104143. int possible_partitions=info->partitions;
  104144. int partitions_per_word=look->phrasebook->dim;
  104145. int n=info->end-info->begin;
  104146. int partvals=n/samples_per_partition;
  104147. long resbits[128];
  104148. long resvals[128];
  104149. #ifdef TRAIN_RES
  104150. for(i=0;i<ch;i++)
  104151. for(j=info->begin;j<info->end;j++){
  104152. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104153. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104154. }
  104155. #endif
  104156. memset(resbits,0,sizeof(resbits));
  104157. memset(resvals,0,sizeof(resvals));
  104158. for(s=0;s<look->stages;s++){
  104159. for(i=0;i<partvals;){
  104160. if(s==0){
  104161. for(j=0;j<ch;j++){
  104162. long val=partword[j][i];
  104163. for(k=1;k<partitions_per_word;k++){
  104164. val*=possible_partitions;
  104165. if(i+k<partvals)
  104166. val+=partword[j][i+k];
  104167. }
  104168. if(val<look->phrasebook->entries)
  104169. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104170. #if 0 /*def TRAIN_RES*/
  104171. else
  104172. fprintf(stderr,"!");
  104173. #endif
  104174. }
  104175. }
  104176. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104177. long offset=i*samples_per_partition+info->begin;
  104178. for(j=0;j<ch;j++){
  104179. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104180. if(info->secondstages[partword[j][i]]&(1<<s)){
  104181. codebook *statebook=look->partbooks[partword[j][i]][s];
  104182. if(statebook){
  104183. int ret;
  104184. long *accumulator=NULL;
  104185. #ifdef TRAIN_RES
  104186. accumulator=look->training_data[s][partword[j][i]];
  104187. {
  104188. int l;
  104189. float *samples=in[j]+offset;
  104190. for(l=0;l<samples_per_partition;l++){
  104191. if(samples[l]<look->training_min[s][partword[j][i]])
  104192. look->training_min[s][partword[j][i]]=samples[l];
  104193. if(samples[l]>look->training_max[s][partword[j][i]])
  104194. look->training_max[s][partword[j][i]]=samples[l];
  104195. }
  104196. }
  104197. #endif
  104198. ret=encode(opb,in[j]+offset,samples_per_partition,
  104199. statebook,accumulator);
  104200. look->postbits+=ret;
  104201. resbits[partword[j][i]]+=ret;
  104202. }
  104203. }
  104204. }
  104205. }
  104206. }
  104207. }
  104208. return(0);
  104209. }
  104210. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104211. float **in,int ch,
  104212. long (*decodepart)(codebook *, float *,
  104213. oggpack_buffer *,int)){
  104214. long i,j,k,l,s;
  104215. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104216. vorbis_info_residue0 *info=look->info;
  104217. int samples_per_partition=info->grouping;
  104218. int partitions_per_word=look->phrasebook->dim;
  104219. int n=info->end-info->begin;
  104220. int partvals=n/samples_per_partition;
  104221. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104222. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104223. for(j=0;j<ch;j++)
  104224. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104225. for(s=0;s<look->stages;s++){
  104226. for(i=0,l=0;i<partvals;l++){
  104227. if(s==0){
  104228. for(j=0;j<ch;j++){
  104229. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104230. if(temp==-1)goto eopbreak;
  104231. partword[j][l]=look->decodemap[temp];
  104232. if(partword[j][l]==NULL)goto errout;
  104233. }
  104234. }
  104235. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104236. for(j=0;j<ch;j++){
  104237. long offset=info->begin+i*samples_per_partition;
  104238. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104239. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104240. if(stagebook){
  104241. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104242. samples_per_partition)==-1)goto eopbreak;
  104243. }
  104244. }
  104245. }
  104246. }
  104247. }
  104248. errout:
  104249. eopbreak:
  104250. return(0);
  104251. }
  104252. #if 0
  104253. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104254. float **in,int *nonzero,int ch){
  104255. int i,used=0;
  104256. for(i=0;i<ch;i++)
  104257. if(nonzero[i])
  104258. in[used++]=in[i];
  104259. if(used)
  104260. return(_01class(vb,vl,in,used));
  104261. else
  104262. return(0);
  104263. }
  104264. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104265. float **in,float **out,int *nonzero,int ch,
  104266. long **partword){
  104267. int i,j,used=0,n=vb->pcmend/2;
  104268. for(i=0;i<ch;i++)
  104269. if(nonzero[i]){
  104270. if(out)
  104271. for(j=0;j<n;j++)
  104272. out[i][j]+=in[i][j];
  104273. in[used++]=in[i];
  104274. }
  104275. if(used){
  104276. int ret=_01forward(vb,vl,in,used,partword,
  104277. _interleaved_encodepart);
  104278. if(out){
  104279. used=0;
  104280. for(i=0;i<ch;i++)
  104281. if(nonzero[i]){
  104282. for(j=0;j<n;j++)
  104283. out[i][j]-=in[used][j];
  104284. used++;
  104285. }
  104286. }
  104287. return(ret);
  104288. }else{
  104289. return(0);
  104290. }
  104291. }
  104292. #endif
  104293. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104294. float **in,int *nonzero,int ch){
  104295. int i,used=0;
  104296. for(i=0;i<ch;i++)
  104297. if(nonzero[i])
  104298. in[used++]=in[i];
  104299. if(used)
  104300. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104301. else
  104302. return(0);
  104303. }
  104304. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104305. float **in,float **out,int *nonzero,int ch,
  104306. long **partword){
  104307. int i,j,used=0,n=vb->pcmend/2;
  104308. for(i=0;i<ch;i++)
  104309. if(nonzero[i]){
  104310. if(out)
  104311. for(j=0;j<n;j++)
  104312. out[i][j]+=in[i][j];
  104313. in[used++]=in[i];
  104314. }
  104315. if(used){
  104316. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104317. if(out){
  104318. used=0;
  104319. for(i=0;i<ch;i++)
  104320. if(nonzero[i]){
  104321. for(j=0;j<n;j++)
  104322. out[i][j]-=in[used][j];
  104323. used++;
  104324. }
  104325. }
  104326. return(ret);
  104327. }else{
  104328. return(0);
  104329. }
  104330. }
  104331. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104332. float **in,int *nonzero,int ch){
  104333. int i,used=0;
  104334. for(i=0;i<ch;i++)
  104335. if(nonzero[i])
  104336. in[used++]=in[i];
  104337. if(used)
  104338. return(_01class(vb,vl,in,used));
  104339. else
  104340. return(0);
  104341. }
  104342. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104343. float **in,int *nonzero,int ch){
  104344. int i,used=0;
  104345. for(i=0;i<ch;i++)
  104346. if(nonzero[i])
  104347. in[used++]=in[i];
  104348. if(used)
  104349. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104350. else
  104351. return(0);
  104352. }
  104353. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104354. float **in,int *nonzero,int ch){
  104355. int i,used=0;
  104356. for(i=0;i<ch;i++)
  104357. if(nonzero[i])used++;
  104358. if(used)
  104359. return(_2class(vb,vl,in,ch));
  104360. else
  104361. return(0);
  104362. }
  104363. int res2_forward(oggpack_buffer *opb,
  104364. vorbis_block *vb,vorbis_look_residue *vl,
  104365. float **in,float **out,int *nonzero,int ch,
  104366. long **partword){
  104367. long i,j,k,n=vb->pcmend/2,used=0;
  104368. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104369. for(i=0;i<ch;i++){
  104370. float *pcm=in[i];
  104371. if(nonzero[i])used++;
  104372. for(j=0,k=i;j<n;j++,k+=ch)
  104373. work[k]=pcm[j];
  104374. }
  104375. if(used){
  104376. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104377. if(out){
  104378. for(i=0;i<ch;i++){
  104379. float *pcm=in[i];
  104380. float *sofar=out[i];
  104381. for(j=0,k=i;j<n;j++,k+=ch)
  104382. sofar[j]+=pcm[j]-work[k];
  104383. }
  104384. }
  104385. return(ret);
  104386. }else{
  104387. return(0);
  104388. }
  104389. }
  104390. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104391. float **in,int *nonzero,int ch){
  104392. long i,k,l,s;
  104393. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104394. vorbis_info_residue0 *info=look->info;
  104395. int samples_per_partition=info->grouping;
  104396. int partitions_per_word=look->phrasebook->dim;
  104397. int n=info->end-info->begin;
  104398. int partvals=n/samples_per_partition;
  104399. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104400. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104401. for(i=0;i<ch;i++)if(nonzero[i])break;
  104402. if(i==ch)return(0); /* no nonzero vectors */
  104403. for(s=0;s<look->stages;s++){
  104404. for(i=0,l=0;i<partvals;l++){
  104405. if(s==0){
  104406. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104407. if(temp==-1)goto eopbreak;
  104408. partword[l]=look->decodemap[temp];
  104409. if(partword[l]==NULL)goto errout;
  104410. }
  104411. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104412. if(info->secondstages[partword[l][k]]&(1<<s)){
  104413. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104414. if(stagebook){
  104415. if(vorbis_book_decodevv_add(stagebook,in,
  104416. i*samples_per_partition+info->begin,ch,
  104417. &vb->opb,samples_per_partition)==-1)
  104418. goto eopbreak;
  104419. }
  104420. }
  104421. }
  104422. }
  104423. errout:
  104424. eopbreak:
  104425. return(0);
  104426. }
  104427. vorbis_func_residue residue0_exportbundle={
  104428. NULL,
  104429. &res0_unpack,
  104430. &res0_look,
  104431. &res0_free_info,
  104432. &res0_free_look,
  104433. NULL,
  104434. NULL,
  104435. &res0_inverse
  104436. };
  104437. vorbis_func_residue residue1_exportbundle={
  104438. &res0_pack,
  104439. &res0_unpack,
  104440. &res0_look,
  104441. &res0_free_info,
  104442. &res0_free_look,
  104443. &res1_class,
  104444. &res1_forward,
  104445. &res1_inverse
  104446. };
  104447. vorbis_func_residue residue2_exportbundle={
  104448. &res0_pack,
  104449. &res0_unpack,
  104450. &res0_look,
  104451. &res0_free_info,
  104452. &res0_free_look,
  104453. &res2_class,
  104454. &res2_forward,
  104455. &res2_inverse
  104456. };
  104457. #endif
  104458. /*** End of inlined file: res0.c ***/
  104459. /*** Start of inlined file: sharedbook.c ***/
  104460. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104461. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104462. // tasks..
  104463. #if JUCE_MSVC
  104464. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104465. #endif
  104466. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104467. #if JUCE_USE_OGGVORBIS
  104468. #include <stdlib.h>
  104469. #include <math.h>
  104470. #include <string.h>
  104471. int _ilog(unsigned int v){
  104472. int ret=0;
  104473. while(v){
  104474. ret++;
  104475. v>>=1;
  104476. }
  104477. return(ret);
  104478. }
  104479. #define VQ_FEXP 10
  104480. #define VQ_FMAN 21
  104481. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104482. long _float32_pack(float val){
  104483. int sign=0;
  104484. long exp;
  104485. long mant;
  104486. if(val<0){
  104487. sign=0x80000000;
  104488. val= -val;
  104489. }
  104490. exp= floor(log(val)/log(2.f));
  104491. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104492. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104493. return(sign|exp|mant);
  104494. }
  104495. float _float32_unpack(long val){
  104496. double mant=val&0x1fffff;
  104497. int sign=val&0x80000000;
  104498. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104499. if(sign)mant= -mant;
  104500. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104501. }
  104502. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104503. long i,j,count=0;
  104504. ogg_uint32_t marker[33];
  104505. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104506. memset(marker,0,sizeof(marker));
  104507. for(i=0;i<n;i++){
  104508. long length=l[i];
  104509. if(length>0){
  104510. ogg_uint32_t entry=marker[length];
  104511. if(length<32 && (entry>>length)){
  104512. _ogg_free(r);
  104513. return(NULL);
  104514. }
  104515. r[count++]=entry;
  104516. {
  104517. for(j=length;j>0;j--){
  104518. if(marker[j]&1){
  104519. if(j==1)
  104520. marker[1]++;
  104521. else
  104522. marker[j]=marker[j-1]<<1;
  104523. break; /* invariant says next upper marker would already
  104524. have been moved if it was on the same path */
  104525. }
  104526. marker[j]++;
  104527. }
  104528. }
  104529. for(j=length+1;j<33;j++)
  104530. if((marker[j]>>1) == entry){
  104531. entry=marker[j];
  104532. marker[j]=marker[j-1]<<1;
  104533. }else
  104534. break;
  104535. }else
  104536. if(sparsecount==0)count++;
  104537. }
  104538. for(i=0,count=0;i<n;i++){
  104539. ogg_uint32_t temp=0;
  104540. for(j=0;j<l[i];j++){
  104541. temp<<=1;
  104542. temp|=(r[count]>>j)&1;
  104543. }
  104544. if(sparsecount){
  104545. if(l[i])
  104546. r[count++]=temp;
  104547. }else
  104548. r[count++]=temp;
  104549. }
  104550. return(r);
  104551. }
  104552. long _book_maptype1_quantvals(const static_codebook *b){
  104553. long vals=floor(pow((float)b->entries,1.f/b->dim));
  104554. while(1){
  104555. long acc=1;
  104556. long acc1=1;
  104557. int i;
  104558. for(i=0;i<b->dim;i++){
  104559. acc*=vals;
  104560. acc1*=vals+1;
  104561. }
  104562. if(acc<=b->entries && acc1>b->entries){
  104563. return(vals);
  104564. }else{
  104565. if(acc>b->entries){
  104566. vals--;
  104567. }else{
  104568. vals++;
  104569. }
  104570. }
  104571. }
  104572. }
  104573. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  104574. long j,k,count=0;
  104575. if(b->maptype==1 || b->maptype==2){
  104576. int quantvals;
  104577. float mindel=_float32_unpack(b->q_min);
  104578. float delta=_float32_unpack(b->q_delta);
  104579. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  104580. switch(b->maptype){
  104581. case 1:
  104582. quantvals=_book_maptype1_quantvals(b);
  104583. for(j=0;j<b->entries;j++){
  104584. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104585. float last=0.f;
  104586. int indexdiv=1;
  104587. for(k=0;k<b->dim;k++){
  104588. int index= (j/indexdiv)%quantvals;
  104589. float val=b->quantlist[index];
  104590. val=fabs(val)*delta+mindel+last;
  104591. if(b->q_sequencep)last=val;
  104592. if(sparsemap)
  104593. r[sparsemap[count]*b->dim+k]=val;
  104594. else
  104595. r[count*b->dim+k]=val;
  104596. indexdiv*=quantvals;
  104597. }
  104598. count++;
  104599. }
  104600. }
  104601. break;
  104602. case 2:
  104603. for(j=0;j<b->entries;j++){
  104604. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  104605. float last=0.f;
  104606. for(k=0;k<b->dim;k++){
  104607. float val=b->quantlist[j*b->dim+k];
  104608. val=fabs(val)*delta+mindel+last;
  104609. if(b->q_sequencep)last=val;
  104610. if(sparsemap)
  104611. r[sparsemap[count]*b->dim+k]=val;
  104612. else
  104613. r[count*b->dim+k]=val;
  104614. }
  104615. count++;
  104616. }
  104617. }
  104618. break;
  104619. }
  104620. return(r);
  104621. }
  104622. return(NULL);
  104623. }
  104624. void vorbis_staticbook_clear(static_codebook *b){
  104625. if(b->allocedp){
  104626. if(b->quantlist)_ogg_free(b->quantlist);
  104627. if(b->lengthlist)_ogg_free(b->lengthlist);
  104628. if(b->nearest_tree){
  104629. _ogg_free(b->nearest_tree->ptr0);
  104630. _ogg_free(b->nearest_tree->ptr1);
  104631. _ogg_free(b->nearest_tree->p);
  104632. _ogg_free(b->nearest_tree->q);
  104633. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  104634. _ogg_free(b->nearest_tree);
  104635. }
  104636. if(b->thresh_tree){
  104637. _ogg_free(b->thresh_tree->quantthresh);
  104638. _ogg_free(b->thresh_tree->quantmap);
  104639. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  104640. _ogg_free(b->thresh_tree);
  104641. }
  104642. memset(b,0,sizeof(*b));
  104643. }
  104644. }
  104645. void vorbis_staticbook_destroy(static_codebook *b){
  104646. if(b->allocedp){
  104647. vorbis_staticbook_clear(b);
  104648. _ogg_free(b);
  104649. }
  104650. }
  104651. void vorbis_book_clear(codebook *b){
  104652. if(b->valuelist)_ogg_free(b->valuelist);
  104653. if(b->codelist)_ogg_free(b->codelist);
  104654. if(b->dec_index)_ogg_free(b->dec_index);
  104655. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  104656. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  104657. memset(b,0,sizeof(*b));
  104658. }
  104659. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  104660. memset(c,0,sizeof(*c));
  104661. c->c=s;
  104662. c->entries=s->entries;
  104663. c->used_entries=s->entries;
  104664. c->dim=s->dim;
  104665. c->codelist=_make_words(s->lengthlist,s->entries,0);
  104666. c->valuelist=_book_unquantize(s,s->entries,NULL);
  104667. return(0);
  104668. }
  104669. static int sort32a(const void *a,const void *b){
  104670. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  104671. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  104672. }
  104673. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  104674. int i,j,n=0,tabn;
  104675. int *sortindex;
  104676. memset(c,0,sizeof(*c));
  104677. for(i=0;i<s->entries;i++)
  104678. if(s->lengthlist[i]>0)
  104679. n++;
  104680. c->entries=s->entries;
  104681. c->used_entries=n;
  104682. c->dim=s->dim;
  104683. {
  104684. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  104685. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  104686. if(codes==NULL)goto err_out;
  104687. for(i=0;i<n;i++){
  104688. codes[i]=ogg_bitreverse(codes[i]);
  104689. codep[i]=codes+i;
  104690. }
  104691. qsort(codep,n,sizeof(*codep),sort32a);
  104692. sortindex=(int*)alloca(n*sizeof(*sortindex));
  104693. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  104694. for(i=0;i<n;i++){
  104695. int position=codep[i]-codes;
  104696. sortindex[position]=i;
  104697. }
  104698. for(i=0;i<n;i++)
  104699. c->codelist[sortindex[i]]=codes[i];
  104700. _ogg_free(codes);
  104701. }
  104702. c->valuelist=_book_unquantize(s,n,sortindex);
  104703. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  104704. for(n=0,i=0;i<s->entries;i++)
  104705. if(s->lengthlist[i]>0)
  104706. c->dec_index[sortindex[n++]]=i;
  104707. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  104708. for(n=0,i=0;i<s->entries;i++)
  104709. if(s->lengthlist[i]>0)
  104710. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  104711. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  104712. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  104713. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  104714. tabn=1<<c->dec_firsttablen;
  104715. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  104716. c->dec_maxlength=0;
  104717. for(i=0;i<n;i++){
  104718. if(c->dec_maxlength<c->dec_codelengths[i])
  104719. c->dec_maxlength=c->dec_codelengths[i];
  104720. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  104721. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  104722. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  104723. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  104724. }
  104725. }
  104726. {
  104727. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  104728. long lo=0,hi=0;
  104729. for(i=0;i<tabn;i++){
  104730. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  104731. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  104732. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  104733. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  104734. {
  104735. unsigned long loval=lo;
  104736. unsigned long hival=n-hi;
  104737. if(loval>0x7fff)loval=0x7fff;
  104738. if(hival>0x7fff)hival=0x7fff;
  104739. c->dec_firsttable[ogg_bitreverse(word)]=
  104740. 0x80000000UL | (loval<<15) | hival;
  104741. }
  104742. }
  104743. }
  104744. }
  104745. return(0);
  104746. err_out:
  104747. vorbis_book_clear(c);
  104748. return(-1);
  104749. }
  104750. static float _dist(int el,float *ref, float *b,int step){
  104751. int i;
  104752. float acc=0.f;
  104753. for(i=0;i<el;i++){
  104754. float val=(ref[i]-b[i*step]);
  104755. acc+=val*val;
  104756. }
  104757. return(acc);
  104758. }
  104759. int _best(codebook *book, float *a, int step){
  104760. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104761. #if 0
  104762. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  104763. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  104764. #endif
  104765. int dim=book->dim;
  104766. int k,o;
  104767. if(tt){
  104768. int index=0,i;
  104769. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104770. i=tt->threshvals>>1;
  104771. if(a[o]<tt->quantthresh[i]){
  104772. for(;i>0;i--)
  104773. if(a[o]>=tt->quantthresh[i-1])
  104774. break;
  104775. }else{
  104776. for(i++;i<tt->threshvals-1;i++)
  104777. if(a[o]<tt->quantthresh[i])break;
  104778. }
  104779. index=(index*tt->quantvals)+tt->quantmap[i];
  104780. }
  104781. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  104782. use a decision tree after all
  104783. and fall through*/
  104784. return(index);
  104785. }
  104786. #if 0
  104787. if(pt){
  104788. const static_codebook *c=book->c;
  104789. int i,besti=-1;
  104790. float best=0.f;
  104791. int entry=0;
  104792. if(c->q_sequencep){
  104793. int pv;
  104794. long mul=1;
  104795. float qlast=0;
  104796. for(k=0,o=0;k<dim;k++,o+=step){
  104797. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  104798. if(pv<0 || pv>=pt->mapentries)break;
  104799. entry+=pt->pigeonmap[pv]*mul;
  104800. mul*=pt->quantvals;
  104801. qlast+=pv*pt->del+pt->min;
  104802. }
  104803. }else{
  104804. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  104805. int pv=(int)((a[o]-pt->min)/pt->del);
  104806. if(pv<0 || pv>=pt->mapentries)break;
  104807. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  104808. }
  104809. }
  104810. if(k==dim && pt->fitlength[entry]){
  104811. long *list=pt->fitlist+pt->fitmap[entry];
  104812. for(i=0;i<pt->fitlength[entry];i++){
  104813. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  104814. if(besti==-1 || this<best){
  104815. best=this;
  104816. besti=list[i];
  104817. }
  104818. }
  104819. return(besti);
  104820. }
  104821. }
  104822. if(nt){
  104823. while(1){
  104824. float c=0.f;
  104825. float *p=book->valuelist+nt->p[ptr];
  104826. float *q=book->valuelist+nt->q[ptr];
  104827. for(k=0,o=0;k<dim;k++,o+=step)
  104828. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  104829. if(c>0.f) /* in A */
  104830. ptr= -nt->ptr0[ptr];
  104831. else /* in B */
  104832. ptr= -nt->ptr1[ptr];
  104833. if(ptr<=0)break;
  104834. }
  104835. return(-ptr);
  104836. }
  104837. #endif
  104838. {
  104839. const static_codebook *c=book->c;
  104840. int i,besti=-1;
  104841. float best=0.f;
  104842. float *e=book->valuelist;
  104843. for(i=0;i<book->entries;i++){
  104844. if(c->lengthlist[i]>0){
  104845. float thisx=_dist(dim,e,a,step);
  104846. if(besti==-1 || thisx<best){
  104847. best=thisx;
  104848. besti=i;
  104849. }
  104850. }
  104851. e+=dim;
  104852. }
  104853. return(besti);
  104854. }
  104855. }
  104856. long vorbis_book_codeword(codebook *book,int entry){
  104857. if(book->c) /* only use with encode; decode optimizations are
  104858. allowed to break this */
  104859. return book->codelist[entry];
  104860. return -1;
  104861. }
  104862. long vorbis_book_codelen(codebook *book,int entry){
  104863. if(book->c) /* only use with encode; decode optimizations are
  104864. allowed to break this */
  104865. return book->c->lengthlist[entry];
  104866. return -1;
  104867. }
  104868. #ifdef _V_SELFTEST
  104869. #include <stdio.h>
  104870. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  104871. static long partial_quantlist1[]={0,7,2};
  104872. static_codebook test1={
  104873. 4,16,
  104874. NULL,
  104875. 0,
  104876. 0,0,0,0,
  104877. NULL,
  104878. NULL,NULL
  104879. };
  104880. static float *test1_result=NULL;
  104881. static_codebook test2={
  104882. 4,3,
  104883. NULL,
  104884. 2,
  104885. -533200896,1611661312,4,0,
  104886. full_quantlist1,
  104887. NULL,NULL
  104888. };
  104889. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  104890. static_codebook test3={
  104891. 4,3,
  104892. NULL,
  104893. 2,
  104894. -533200896,1611661312,4,1,
  104895. full_quantlist1,
  104896. NULL,NULL
  104897. };
  104898. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  104899. static_codebook test4={
  104900. 3,27,
  104901. NULL,
  104902. 1,
  104903. -533200896,1611661312,4,0,
  104904. partial_quantlist1,
  104905. NULL,NULL
  104906. };
  104907. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  104908. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  104909. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  104910. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  104911. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  104912. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  104913. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  104914. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  104915. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  104916. static_codebook test5={
  104917. 3,27,
  104918. NULL,
  104919. 1,
  104920. -533200896,1611661312,4,1,
  104921. partial_quantlist1,
  104922. NULL,NULL
  104923. };
  104924. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  104925. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  104926. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  104927. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  104928. -3, 1, 5, 4, 8,12, -1, 3, 7,
  104929. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  104930. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  104931. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  104932. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  104933. void run_test(static_codebook *b,float *comp){
  104934. float *out=_book_unquantize(b,b->entries,NULL);
  104935. int i;
  104936. if(comp){
  104937. if(!out){
  104938. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  104939. exit(1);
  104940. }
  104941. for(i=0;i<b->entries*b->dim;i++)
  104942. if(fabs(out[i]-comp[i])>.0001){
  104943. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  104944. "position %d, %g != %g\n",i,out[i],comp[i]);
  104945. exit(1);
  104946. }
  104947. }else{
  104948. if(out){
  104949. fprintf(stderr,"_book_unquantize returned a value array: \n"
  104950. " correct result should have been NULL\n");
  104951. exit(1);
  104952. }
  104953. }
  104954. }
  104955. int main(){
  104956. fprintf(stderr,"Dequant test 1... ");
  104957. run_test(&test1,test1_result);
  104958. fprintf(stderr,"OK\nDequant test 2... ");
  104959. run_test(&test2,test2_result);
  104960. fprintf(stderr,"OK\nDequant test 3... ");
  104961. run_test(&test3,test3_result);
  104962. fprintf(stderr,"OK\nDequant test 4... ");
  104963. run_test(&test4,test4_result);
  104964. fprintf(stderr,"OK\nDequant test 5... ");
  104965. run_test(&test5,test5_result);
  104966. fprintf(stderr,"OK\n\n");
  104967. return(0);
  104968. }
  104969. #endif
  104970. #endif
  104971. /*** End of inlined file: sharedbook.c ***/
  104972. /*** Start of inlined file: smallft.c ***/
  104973. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104974. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104975. // tasks..
  104976. #if JUCE_MSVC
  104977. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104978. #endif
  104979. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104980. #if JUCE_USE_OGGVORBIS
  104981. #include <stdlib.h>
  104982. #include <string.h>
  104983. #include <math.h>
  104984. static void drfti1(int n, float *wa, int *ifac){
  104985. static int ntryh[4] = { 4,2,3,5 };
  104986. static float tpi = 6.28318530717958648f;
  104987. float arg,argh,argld,fi;
  104988. int ntry=0,i,j=-1;
  104989. int k1, l1, l2, ib;
  104990. int ld, ii, ip, is, nq, nr;
  104991. int ido, ipm, nfm1;
  104992. int nl=n;
  104993. int nf=0;
  104994. L101:
  104995. j++;
  104996. if (j < 4)
  104997. ntry=ntryh[j];
  104998. else
  104999. ntry+=2;
  105000. L104:
  105001. nq=nl/ntry;
  105002. nr=nl-ntry*nq;
  105003. if (nr!=0) goto L101;
  105004. nf++;
  105005. ifac[nf+1]=ntry;
  105006. nl=nq;
  105007. if(ntry!=2)goto L107;
  105008. if(nf==1)goto L107;
  105009. for (i=1;i<nf;i++){
  105010. ib=nf-i+1;
  105011. ifac[ib+1]=ifac[ib];
  105012. }
  105013. ifac[2] = 2;
  105014. L107:
  105015. if(nl!=1)goto L104;
  105016. ifac[0]=n;
  105017. ifac[1]=nf;
  105018. argh=tpi/n;
  105019. is=0;
  105020. nfm1=nf-1;
  105021. l1=1;
  105022. if(nfm1==0)return;
  105023. for (k1=0;k1<nfm1;k1++){
  105024. ip=ifac[k1+2];
  105025. ld=0;
  105026. l2=l1*ip;
  105027. ido=n/l2;
  105028. ipm=ip-1;
  105029. for (j=0;j<ipm;j++){
  105030. ld+=l1;
  105031. i=is;
  105032. argld=(float)ld*argh;
  105033. fi=0.f;
  105034. for (ii=2;ii<ido;ii+=2){
  105035. fi+=1.f;
  105036. arg=fi*argld;
  105037. wa[i++]=cos(arg);
  105038. wa[i++]=sin(arg);
  105039. }
  105040. is+=ido;
  105041. }
  105042. l1=l2;
  105043. }
  105044. }
  105045. static void fdrffti(int n, float *wsave, int *ifac){
  105046. if (n == 1) return;
  105047. drfti1(n, wsave+n, ifac);
  105048. }
  105049. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105050. int i,k;
  105051. float ti2,tr2;
  105052. int t0,t1,t2,t3,t4,t5,t6;
  105053. t1=0;
  105054. t0=(t2=l1*ido);
  105055. t3=ido<<1;
  105056. for(k=0;k<l1;k++){
  105057. ch[t1<<1]=cc[t1]+cc[t2];
  105058. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105059. t1+=ido;
  105060. t2+=ido;
  105061. }
  105062. if(ido<2)return;
  105063. if(ido==2)goto L105;
  105064. t1=0;
  105065. t2=t0;
  105066. for(k=0;k<l1;k++){
  105067. t3=t2;
  105068. t4=(t1<<1)+(ido<<1);
  105069. t5=t1;
  105070. t6=t1+t1;
  105071. for(i=2;i<ido;i+=2){
  105072. t3+=2;
  105073. t4-=2;
  105074. t5+=2;
  105075. t6+=2;
  105076. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105077. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105078. ch[t6]=cc[t5]+ti2;
  105079. ch[t4]=ti2-cc[t5];
  105080. ch[t6-1]=cc[t5-1]+tr2;
  105081. ch[t4-1]=cc[t5-1]-tr2;
  105082. }
  105083. t1+=ido;
  105084. t2+=ido;
  105085. }
  105086. if(ido%2==1)return;
  105087. L105:
  105088. t3=(t2=(t1=ido)-1);
  105089. t2+=t0;
  105090. for(k=0;k<l1;k++){
  105091. ch[t1]=-cc[t2];
  105092. ch[t1-1]=cc[t3];
  105093. t1+=ido<<1;
  105094. t2+=ido;
  105095. t3+=ido;
  105096. }
  105097. }
  105098. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105099. float *wa2,float *wa3){
  105100. static float hsqt2 = .70710678118654752f;
  105101. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105102. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105103. t0=l1*ido;
  105104. t1=t0;
  105105. t4=t1<<1;
  105106. t2=t1+(t1<<1);
  105107. t3=0;
  105108. for(k=0;k<l1;k++){
  105109. tr1=cc[t1]+cc[t2];
  105110. tr2=cc[t3]+cc[t4];
  105111. ch[t5=t3<<2]=tr1+tr2;
  105112. ch[(ido<<2)+t5-1]=tr2-tr1;
  105113. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105114. ch[t5]=cc[t2]-cc[t1];
  105115. t1+=ido;
  105116. t2+=ido;
  105117. t3+=ido;
  105118. t4+=ido;
  105119. }
  105120. if(ido<2)return;
  105121. if(ido==2)goto L105;
  105122. t1=0;
  105123. for(k=0;k<l1;k++){
  105124. t2=t1;
  105125. t4=t1<<2;
  105126. t5=(t6=ido<<1)+t4;
  105127. for(i=2;i<ido;i+=2){
  105128. t3=(t2+=2);
  105129. t4+=2;
  105130. t5-=2;
  105131. t3+=t0;
  105132. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105133. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105134. t3+=t0;
  105135. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105136. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105137. t3+=t0;
  105138. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105139. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105140. tr1=cr2+cr4;
  105141. tr4=cr4-cr2;
  105142. ti1=ci2+ci4;
  105143. ti4=ci2-ci4;
  105144. ti2=cc[t2]+ci3;
  105145. ti3=cc[t2]-ci3;
  105146. tr2=cc[t2-1]+cr3;
  105147. tr3=cc[t2-1]-cr3;
  105148. ch[t4-1]=tr1+tr2;
  105149. ch[t4]=ti1+ti2;
  105150. ch[t5-1]=tr3-ti4;
  105151. ch[t5]=tr4-ti3;
  105152. ch[t4+t6-1]=ti4+tr3;
  105153. ch[t4+t6]=tr4+ti3;
  105154. ch[t5+t6-1]=tr2-tr1;
  105155. ch[t5+t6]=ti1-ti2;
  105156. }
  105157. t1+=ido;
  105158. }
  105159. if(ido&1)return;
  105160. L105:
  105161. t2=(t1=t0+ido-1)+(t0<<1);
  105162. t3=ido<<2;
  105163. t4=ido;
  105164. t5=ido<<1;
  105165. t6=ido;
  105166. for(k=0;k<l1;k++){
  105167. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105168. tr1=hsqt2*(cc[t1]-cc[t2]);
  105169. ch[t4-1]=tr1+cc[t6-1];
  105170. ch[t4+t5-1]=cc[t6-1]-tr1;
  105171. ch[t4]=ti1-cc[t1+t0];
  105172. ch[t4+t5]=ti1+cc[t1+t0];
  105173. t1+=ido;
  105174. t2+=ido;
  105175. t4+=t3;
  105176. t6+=ido;
  105177. }
  105178. }
  105179. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105180. float *c2,float *ch,float *ch2,float *wa){
  105181. static float tpi=6.283185307179586f;
  105182. int idij,ipph,i,j,k,l,ic,ik,is;
  105183. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105184. float dc2,ai1,ai2,ar1,ar2,ds2;
  105185. int nbd;
  105186. float dcp,arg,dsp,ar1h,ar2h;
  105187. int idp2,ipp2;
  105188. arg=tpi/(float)ip;
  105189. dcp=cos(arg);
  105190. dsp=sin(arg);
  105191. ipph=(ip+1)>>1;
  105192. ipp2=ip;
  105193. idp2=ido;
  105194. nbd=(ido-1)>>1;
  105195. t0=l1*ido;
  105196. t10=ip*ido;
  105197. if(ido==1)goto L119;
  105198. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105199. t1=0;
  105200. for(j=1;j<ip;j++){
  105201. t1+=t0;
  105202. t2=t1;
  105203. for(k=0;k<l1;k++){
  105204. ch[t2]=c1[t2];
  105205. t2+=ido;
  105206. }
  105207. }
  105208. is=-ido;
  105209. t1=0;
  105210. if(nbd>l1){
  105211. for(j=1;j<ip;j++){
  105212. t1+=t0;
  105213. is+=ido;
  105214. t2= -ido+t1;
  105215. for(k=0;k<l1;k++){
  105216. idij=is-1;
  105217. t2+=ido;
  105218. t3=t2;
  105219. for(i=2;i<ido;i+=2){
  105220. idij+=2;
  105221. t3+=2;
  105222. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105223. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105224. }
  105225. }
  105226. }
  105227. }else{
  105228. for(j=1;j<ip;j++){
  105229. is+=ido;
  105230. idij=is-1;
  105231. t1+=t0;
  105232. t2=t1;
  105233. for(i=2;i<ido;i+=2){
  105234. idij+=2;
  105235. t2+=2;
  105236. t3=t2;
  105237. for(k=0;k<l1;k++){
  105238. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105239. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105240. t3+=ido;
  105241. }
  105242. }
  105243. }
  105244. }
  105245. t1=0;
  105246. t2=ipp2*t0;
  105247. if(nbd<l1){
  105248. for(j=1;j<ipph;j++){
  105249. t1+=t0;
  105250. t2-=t0;
  105251. t3=t1;
  105252. t4=t2;
  105253. for(i=2;i<ido;i+=2){
  105254. t3+=2;
  105255. t4+=2;
  105256. t5=t3-ido;
  105257. t6=t4-ido;
  105258. for(k=0;k<l1;k++){
  105259. t5+=ido;
  105260. t6+=ido;
  105261. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105262. c1[t6-1]=ch[t5]-ch[t6];
  105263. c1[t5]=ch[t5]+ch[t6];
  105264. c1[t6]=ch[t6-1]-ch[t5-1];
  105265. }
  105266. }
  105267. }
  105268. }else{
  105269. for(j=1;j<ipph;j++){
  105270. t1+=t0;
  105271. t2-=t0;
  105272. t3=t1;
  105273. t4=t2;
  105274. for(k=0;k<l1;k++){
  105275. t5=t3;
  105276. t6=t4;
  105277. for(i=2;i<ido;i+=2){
  105278. t5+=2;
  105279. t6+=2;
  105280. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105281. c1[t6-1]=ch[t5]-ch[t6];
  105282. c1[t5]=ch[t5]+ch[t6];
  105283. c1[t6]=ch[t6-1]-ch[t5-1];
  105284. }
  105285. t3+=ido;
  105286. t4+=ido;
  105287. }
  105288. }
  105289. }
  105290. L119:
  105291. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105292. t1=0;
  105293. t2=ipp2*idl1;
  105294. for(j=1;j<ipph;j++){
  105295. t1+=t0;
  105296. t2-=t0;
  105297. t3=t1-ido;
  105298. t4=t2-ido;
  105299. for(k=0;k<l1;k++){
  105300. t3+=ido;
  105301. t4+=ido;
  105302. c1[t3]=ch[t3]+ch[t4];
  105303. c1[t4]=ch[t4]-ch[t3];
  105304. }
  105305. }
  105306. ar1=1.f;
  105307. ai1=0.f;
  105308. t1=0;
  105309. t2=ipp2*idl1;
  105310. t3=(ip-1)*idl1;
  105311. for(l=1;l<ipph;l++){
  105312. t1+=idl1;
  105313. t2-=idl1;
  105314. ar1h=dcp*ar1-dsp*ai1;
  105315. ai1=dcp*ai1+dsp*ar1;
  105316. ar1=ar1h;
  105317. t4=t1;
  105318. t5=t2;
  105319. t6=t3;
  105320. t7=idl1;
  105321. for(ik=0;ik<idl1;ik++){
  105322. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105323. ch2[t5++]=ai1*c2[t6++];
  105324. }
  105325. dc2=ar1;
  105326. ds2=ai1;
  105327. ar2=ar1;
  105328. ai2=ai1;
  105329. t4=idl1;
  105330. t5=(ipp2-1)*idl1;
  105331. for(j=2;j<ipph;j++){
  105332. t4+=idl1;
  105333. t5-=idl1;
  105334. ar2h=dc2*ar2-ds2*ai2;
  105335. ai2=dc2*ai2+ds2*ar2;
  105336. ar2=ar2h;
  105337. t6=t1;
  105338. t7=t2;
  105339. t8=t4;
  105340. t9=t5;
  105341. for(ik=0;ik<idl1;ik++){
  105342. ch2[t6++]+=ar2*c2[t8++];
  105343. ch2[t7++]+=ai2*c2[t9++];
  105344. }
  105345. }
  105346. }
  105347. t1=0;
  105348. for(j=1;j<ipph;j++){
  105349. t1+=idl1;
  105350. t2=t1;
  105351. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105352. }
  105353. if(ido<l1)goto L132;
  105354. t1=0;
  105355. t2=0;
  105356. for(k=0;k<l1;k++){
  105357. t3=t1;
  105358. t4=t2;
  105359. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105360. t1+=ido;
  105361. t2+=t10;
  105362. }
  105363. goto L135;
  105364. L132:
  105365. for(i=0;i<ido;i++){
  105366. t1=i;
  105367. t2=i;
  105368. for(k=0;k<l1;k++){
  105369. cc[t2]=ch[t1];
  105370. t1+=ido;
  105371. t2+=t10;
  105372. }
  105373. }
  105374. L135:
  105375. t1=0;
  105376. t2=ido<<1;
  105377. t3=0;
  105378. t4=ipp2*t0;
  105379. for(j=1;j<ipph;j++){
  105380. t1+=t2;
  105381. t3+=t0;
  105382. t4-=t0;
  105383. t5=t1;
  105384. t6=t3;
  105385. t7=t4;
  105386. for(k=0;k<l1;k++){
  105387. cc[t5-1]=ch[t6];
  105388. cc[t5]=ch[t7];
  105389. t5+=t10;
  105390. t6+=ido;
  105391. t7+=ido;
  105392. }
  105393. }
  105394. if(ido==1)return;
  105395. if(nbd<l1)goto L141;
  105396. t1=-ido;
  105397. t3=0;
  105398. t4=0;
  105399. t5=ipp2*t0;
  105400. for(j=1;j<ipph;j++){
  105401. t1+=t2;
  105402. t3+=t2;
  105403. t4+=t0;
  105404. t5-=t0;
  105405. t6=t1;
  105406. t7=t3;
  105407. t8=t4;
  105408. t9=t5;
  105409. for(k=0;k<l1;k++){
  105410. for(i=2;i<ido;i+=2){
  105411. ic=idp2-i;
  105412. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105413. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105414. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105415. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105416. }
  105417. t6+=t10;
  105418. t7+=t10;
  105419. t8+=ido;
  105420. t9+=ido;
  105421. }
  105422. }
  105423. return;
  105424. L141:
  105425. t1=-ido;
  105426. t3=0;
  105427. t4=0;
  105428. t5=ipp2*t0;
  105429. for(j=1;j<ipph;j++){
  105430. t1+=t2;
  105431. t3+=t2;
  105432. t4+=t0;
  105433. t5-=t0;
  105434. for(i=2;i<ido;i+=2){
  105435. t6=idp2+t1-i;
  105436. t7=i+t3;
  105437. t8=i+t4;
  105438. t9=i+t5;
  105439. for(k=0;k<l1;k++){
  105440. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105441. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105442. cc[t7]=ch[t8]+ch[t9];
  105443. cc[t6]=ch[t9]-ch[t8];
  105444. t6+=t10;
  105445. t7+=t10;
  105446. t8+=ido;
  105447. t9+=ido;
  105448. }
  105449. }
  105450. }
  105451. }
  105452. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105453. int i,k1,l1,l2;
  105454. int na,kh,nf;
  105455. int ip,iw,ido,idl1,ix2,ix3;
  105456. nf=ifac[1];
  105457. na=1;
  105458. l2=n;
  105459. iw=n;
  105460. for(k1=0;k1<nf;k1++){
  105461. kh=nf-k1;
  105462. ip=ifac[kh+1];
  105463. l1=l2/ip;
  105464. ido=n/l2;
  105465. idl1=ido*l1;
  105466. iw-=(ip-1)*ido;
  105467. na=1-na;
  105468. if(ip!=4)goto L102;
  105469. ix2=iw+ido;
  105470. ix3=ix2+ido;
  105471. if(na!=0)
  105472. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105473. else
  105474. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105475. goto L110;
  105476. L102:
  105477. if(ip!=2)goto L104;
  105478. if(na!=0)goto L103;
  105479. dradf2(ido,l1,c,ch,wa+iw-1);
  105480. goto L110;
  105481. L103:
  105482. dradf2(ido,l1,ch,c,wa+iw-1);
  105483. goto L110;
  105484. L104:
  105485. if(ido==1)na=1-na;
  105486. if(na!=0)goto L109;
  105487. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105488. na=1;
  105489. goto L110;
  105490. L109:
  105491. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105492. na=0;
  105493. L110:
  105494. l2=l1;
  105495. }
  105496. if(na==1)return;
  105497. for(i=0;i<n;i++)c[i]=ch[i];
  105498. }
  105499. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105500. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105501. float ti2,tr2;
  105502. t0=l1*ido;
  105503. t1=0;
  105504. t2=0;
  105505. t3=(ido<<1)-1;
  105506. for(k=0;k<l1;k++){
  105507. ch[t1]=cc[t2]+cc[t3+t2];
  105508. ch[t1+t0]=cc[t2]-cc[t3+t2];
  105509. t2=(t1+=ido)<<1;
  105510. }
  105511. if(ido<2)return;
  105512. if(ido==2)goto L105;
  105513. t1=0;
  105514. t2=0;
  105515. for(k=0;k<l1;k++){
  105516. t3=t1;
  105517. t5=(t4=t2)+(ido<<1);
  105518. t6=t0+t1;
  105519. for(i=2;i<ido;i+=2){
  105520. t3+=2;
  105521. t4+=2;
  105522. t5-=2;
  105523. t6+=2;
  105524. ch[t3-1]=cc[t4-1]+cc[t5-1];
  105525. tr2=cc[t4-1]-cc[t5-1];
  105526. ch[t3]=cc[t4]-cc[t5];
  105527. ti2=cc[t4]+cc[t5];
  105528. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  105529. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  105530. }
  105531. t2=(t1+=ido)<<1;
  105532. }
  105533. if(ido%2==1)return;
  105534. L105:
  105535. t1=ido-1;
  105536. t2=ido-1;
  105537. for(k=0;k<l1;k++){
  105538. ch[t1]=cc[t2]+cc[t2];
  105539. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  105540. t1+=ido;
  105541. t2+=ido<<1;
  105542. }
  105543. }
  105544. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  105545. float *wa2){
  105546. static float taur = -.5f;
  105547. static float taui = .8660254037844386f;
  105548. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105549. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  105550. t0=l1*ido;
  105551. t1=0;
  105552. t2=t0<<1;
  105553. t3=ido<<1;
  105554. t4=ido+(ido<<1);
  105555. t5=0;
  105556. for(k=0;k<l1;k++){
  105557. tr2=cc[t3-1]+cc[t3-1];
  105558. cr2=cc[t5]+(taur*tr2);
  105559. ch[t1]=cc[t5]+tr2;
  105560. ci3=taui*(cc[t3]+cc[t3]);
  105561. ch[t1+t0]=cr2-ci3;
  105562. ch[t1+t2]=cr2+ci3;
  105563. t1+=ido;
  105564. t3+=t4;
  105565. t5+=t4;
  105566. }
  105567. if(ido==1)return;
  105568. t1=0;
  105569. t3=ido<<1;
  105570. for(k=0;k<l1;k++){
  105571. t7=t1+(t1<<1);
  105572. t6=(t5=t7+t3);
  105573. t8=t1;
  105574. t10=(t9=t1+t0)+t0;
  105575. for(i=2;i<ido;i+=2){
  105576. t5+=2;
  105577. t6-=2;
  105578. t7+=2;
  105579. t8+=2;
  105580. t9+=2;
  105581. t10+=2;
  105582. tr2=cc[t5-1]+cc[t6-1];
  105583. cr2=cc[t7-1]+(taur*tr2);
  105584. ch[t8-1]=cc[t7-1]+tr2;
  105585. ti2=cc[t5]-cc[t6];
  105586. ci2=cc[t7]+(taur*ti2);
  105587. ch[t8]=cc[t7]+ti2;
  105588. cr3=taui*(cc[t5-1]-cc[t6-1]);
  105589. ci3=taui*(cc[t5]+cc[t6]);
  105590. dr2=cr2-ci3;
  105591. dr3=cr2+ci3;
  105592. di2=ci2+cr3;
  105593. di3=ci2-cr3;
  105594. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  105595. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  105596. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  105597. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  105598. }
  105599. t1+=ido;
  105600. }
  105601. }
  105602. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  105603. float *wa2,float *wa3){
  105604. static float sqrt2=1.414213562373095f;
  105605. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  105606. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105607. t0=l1*ido;
  105608. t1=0;
  105609. t2=ido<<2;
  105610. t3=0;
  105611. t6=ido<<1;
  105612. for(k=0;k<l1;k++){
  105613. t4=t3+t6;
  105614. t5=t1;
  105615. tr3=cc[t4-1]+cc[t4-1];
  105616. tr4=cc[t4]+cc[t4];
  105617. tr1=cc[t3]-cc[(t4+=t6)-1];
  105618. tr2=cc[t3]+cc[t4-1];
  105619. ch[t5]=tr2+tr3;
  105620. ch[t5+=t0]=tr1-tr4;
  105621. ch[t5+=t0]=tr2-tr3;
  105622. ch[t5+=t0]=tr1+tr4;
  105623. t1+=ido;
  105624. t3+=t2;
  105625. }
  105626. if(ido<2)return;
  105627. if(ido==2)goto L105;
  105628. t1=0;
  105629. for(k=0;k<l1;k++){
  105630. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  105631. t7=t1;
  105632. for(i=2;i<ido;i+=2){
  105633. t2+=2;
  105634. t3+=2;
  105635. t4-=2;
  105636. t5-=2;
  105637. t7+=2;
  105638. ti1=cc[t2]+cc[t5];
  105639. ti2=cc[t2]-cc[t5];
  105640. ti3=cc[t3]-cc[t4];
  105641. tr4=cc[t3]+cc[t4];
  105642. tr1=cc[t2-1]-cc[t5-1];
  105643. tr2=cc[t2-1]+cc[t5-1];
  105644. ti4=cc[t3-1]-cc[t4-1];
  105645. tr3=cc[t3-1]+cc[t4-1];
  105646. ch[t7-1]=tr2+tr3;
  105647. cr3=tr2-tr3;
  105648. ch[t7]=ti2+ti3;
  105649. ci3=ti2-ti3;
  105650. cr2=tr1-tr4;
  105651. cr4=tr1+tr4;
  105652. ci2=ti1+ti4;
  105653. ci4=ti1-ti4;
  105654. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  105655. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  105656. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  105657. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  105658. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  105659. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  105660. }
  105661. t1+=ido;
  105662. }
  105663. if(ido%2 == 1)return;
  105664. L105:
  105665. t1=ido;
  105666. t2=ido<<2;
  105667. t3=ido-1;
  105668. t4=ido+(ido<<1);
  105669. for(k=0;k<l1;k++){
  105670. t5=t3;
  105671. ti1=cc[t1]+cc[t4];
  105672. ti2=cc[t4]-cc[t1];
  105673. tr1=cc[t1-1]-cc[t4-1];
  105674. tr2=cc[t1-1]+cc[t4-1];
  105675. ch[t5]=tr2+tr2;
  105676. ch[t5+=t0]=sqrt2*(tr1-ti1);
  105677. ch[t5+=t0]=ti2+ti2;
  105678. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  105679. t3+=ido;
  105680. t1+=t2;
  105681. t4+=t2;
  105682. }
  105683. }
  105684. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105685. float *c2,float *ch,float *ch2,float *wa){
  105686. static float tpi=6.283185307179586f;
  105687. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  105688. t11,t12;
  105689. float dc2,ai1,ai2,ar1,ar2,ds2;
  105690. int nbd;
  105691. float dcp,arg,dsp,ar1h,ar2h;
  105692. int ipp2;
  105693. t10=ip*ido;
  105694. t0=l1*ido;
  105695. arg=tpi/(float)ip;
  105696. dcp=cos(arg);
  105697. dsp=sin(arg);
  105698. nbd=(ido-1)>>1;
  105699. ipp2=ip;
  105700. ipph=(ip+1)>>1;
  105701. if(ido<l1)goto L103;
  105702. t1=0;
  105703. t2=0;
  105704. for(k=0;k<l1;k++){
  105705. t3=t1;
  105706. t4=t2;
  105707. for(i=0;i<ido;i++){
  105708. ch[t3]=cc[t4];
  105709. t3++;
  105710. t4++;
  105711. }
  105712. t1+=ido;
  105713. t2+=t10;
  105714. }
  105715. goto L106;
  105716. L103:
  105717. t1=0;
  105718. for(i=0;i<ido;i++){
  105719. t2=t1;
  105720. t3=t1;
  105721. for(k=0;k<l1;k++){
  105722. ch[t2]=cc[t3];
  105723. t2+=ido;
  105724. t3+=t10;
  105725. }
  105726. t1++;
  105727. }
  105728. L106:
  105729. t1=0;
  105730. t2=ipp2*t0;
  105731. t7=(t5=ido<<1);
  105732. for(j=1;j<ipph;j++){
  105733. t1+=t0;
  105734. t2-=t0;
  105735. t3=t1;
  105736. t4=t2;
  105737. t6=t5;
  105738. for(k=0;k<l1;k++){
  105739. ch[t3]=cc[t6-1]+cc[t6-1];
  105740. ch[t4]=cc[t6]+cc[t6];
  105741. t3+=ido;
  105742. t4+=ido;
  105743. t6+=t10;
  105744. }
  105745. t5+=t7;
  105746. }
  105747. if (ido == 1)goto L116;
  105748. if(nbd<l1)goto L112;
  105749. t1=0;
  105750. t2=ipp2*t0;
  105751. t7=0;
  105752. for(j=1;j<ipph;j++){
  105753. t1+=t0;
  105754. t2-=t0;
  105755. t3=t1;
  105756. t4=t2;
  105757. t7+=(ido<<1);
  105758. t8=t7;
  105759. for(k=0;k<l1;k++){
  105760. t5=t3;
  105761. t6=t4;
  105762. t9=t8;
  105763. t11=t8;
  105764. for(i=2;i<ido;i+=2){
  105765. t5+=2;
  105766. t6+=2;
  105767. t9+=2;
  105768. t11-=2;
  105769. ch[t5-1]=cc[t9-1]+cc[t11-1];
  105770. ch[t6-1]=cc[t9-1]-cc[t11-1];
  105771. ch[t5]=cc[t9]-cc[t11];
  105772. ch[t6]=cc[t9]+cc[t11];
  105773. }
  105774. t3+=ido;
  105775. t4+=ido;
  105776. t8+=t10;
  105777. }
  105778. }
  105779. goto L116;
  105780. L112:
  105781. t1=0;
  105782. t2=ipp2*t0;
  105783. t7=0;
  105784. for(j=1;j<ipph;j++){
  105785. t1+=t0;
  105786. t2-=t0;
  105787. t3=t1;
  105788. t4=t2;
  105789. t7+=(ido<<1);
  105790. t8=t7;
  105791. t9=t7;
  105792. for(i=2;i<ido;i+=2){
  105793. t3+=2;
  105794. t4+=2;
  105795. t8+=2;
  105796. t9-=2;
  105797. t5=t3;
  105798. t6=t4;
  105799. t11=t8;
  105800. t12=t9;
  105801. for(k=0;k<l1;k++){
  105802. ch[t5-1]=cc[t11-1]+cc[t12-1];
  105803. ch[t6-1]=cc[t11-1]-cc[t12-1];
  105804. ch[t5]=cc[t11]-cc[t12];
  105805. ch[t6]=cc[t11]+cc[t12];
  105806. t5+=ido;
  105807. t6+=ido;
  105808. t11+=t10;
  105809. t12+=t10;
  105810. }
  105811. }
  105812. }
  105813. L116:
  105814. ar1=1.f;
  105815. ai1=0.f;
  105816. t1=0;
  105817. t9=(t2=ipp2*idl1);
  105818. t3=(ip-1)*idl1;
  105819. for(l=1;l<ipph;l++){
  105820. t1+=idl1;
  105821. t2-=idl1;
  105822. ar1h=dcp*ar1-dsp*ai1;
  105823. ai1=dcp*ai1+dsp*ar1;
  105824. ar1=ar1h;
  105825. t4=t1;
  105826. t5=t2;
  105827. t6=0;
  105828. t7=idl1;
  105829. t8=t3;
  105830. for(ik=0;ik<idl1;ik++){
  105831. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  105832. c2[t5++]=ai1*ch2[t8++];
  105833. }
  105834. dc2=ar1;
  105835. ds2=ai1;
  105836. ar2=ar1;
  105837. ai2=ai1;
  105838. t6=idl1;
  105839. t7=t9-idl1;
  105840. for(j=2;j<ipph;j++){
  105841. t6+=idl1;
  105842. t7-=idl1;
  105843. ar2h=dc2*ar2-ds2*ai2;
  105844. ai2=dc2*ai2+ds2*ar2;
  105845. ar2=ar2h;
  105846. t4=t1;
  105847. t5=t2;
  105848. t11=t6;
  105849. t12=t7;
  105850. for(ik=0;ik<idl1;ik++){
  105851. c2[t4++]+=ar2*ch2[t11++];
  105852. c2[t5++]+=ai2*ch2[t12++];
  105853. }
  105854. }
  105855. }
  105856. t1=0;
  105857. for(j=1;j<ipph;j++){
  105858. t1+=idl1;
  105859. t2=t1;
  105860. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  105861. }
  105862. t1=0;
  105863. t2=ipp2*t0;
  105864. for(j=1;j<ipph;j++){
  105865. t1+=t0;
  105866. t2-=t0;
  105867. t3=t1;
  105868. t4=t2;
  105869. for(k=0;k<l1;k++){
  105870. ch[t3]=c1[t3]-c1[t4];
  105871. ch[t4]=c1[t3]+c1[t4];
  105872. t3+=ido;
  105873. t4+=ido;
  105874. }
  105875. }
  105876. if(ido==1)goto L132;
  105877. if(nbd<l1)goto L128;
  105878. t1=0;
  105879. t2=ipp2*t0;
  105880. for(j=1;j<ipph;j++){
  105881. t1+=t0;
  105882. t2-=t0;
  105883. t3=t1;
  105884. t4=t2;
  105885. for(k=0;k<l1;k++){
  105886. t5=t3;
  105887. t6=t4;
  105888. for(i=2;i<ido;i+=2){
  105889. t5+=2;
  105890. t6+=2;
  105891. ch[t5-1]=c1[t5-1]-c1[t6];
  105892. ch[t6-1]=c1[t5-1]+c1[t6];
  105893. ch[t5]=c1[t5]+c1[t6-1];
  105894. ch[t6]=c1[t5]-c1[t6-1];
  105895. }
  105896. t3+=ido;
  105897. t4+=ido;
  105898. }
  105899. }
  105900. goto L132;
  105901. L128:
  105902. t1=0;
  105903. t2=ipp2*t0;
  105904. for(j=1;j<ipph;j++){
  105905. t1+=t0;
  105906. t2-=t0;
  105907. t3=t1;
  105908. t4=t2;
  105909. for(i=2;i<ido;i+=2){
  105910. t3+=2;
  105911. t4+=2;
  105912. t5=t3;
  105913. t6=t4;
  105914. for(k=0;k<l1;k++){
  105915. ch[t5-1]=c1[t5-1]-c1[t6];
  105916. ch[t6-1]=c1[t5-1]+c1[t6];
  105917. ch[t5]=c1[t5]+c1[t6-1];
  105918. ch[t6]=c1[t5]-c1[t6-1];
  105919. t5+=ido;
  105920. t6+=ido;
  105921. }
  105922. }
  105923. }
  105924. L132:
  105925. if(ido==1)return;
  105926. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105927. t1=0;
  105928. for(j=1;j<ip;j++){
  105929. t2=(t1+=t0);
  105930. for(k=0;k<l1;k++){
  105931. c1[t2]=ch[t2];
  105932. t2+=ido;
  105933. }
  105934. }
  105935. if(nbd>l1)goto L139;
  105936. is= -ido-1;
  105937. t1=0;
  105938. for(j=1;j<ip;j++){
  105939. is+=ido;
  105940. t1+=t0;
  105941. idij=is;
  105942. t2=t1;
  105943. for(i=2;i<ido;i+=2){
  105944. t2+=2;
  105945. idij+=2;
  105946. t3=t2;
  105947. for(k=0;k<l1;k++){
  105948. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  105949. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  105950. t3+=ido;
  105951. }
  105952. }
  105953. }
  105954. return;
  105955. L139:
  105956. is= -ido-1;
  105957. t1=0;
  105958. for(j=1;j<ip;j++){
  105959. is+=ido;
  105960. t1+=t0;
  105961. t2=t1;
  105962. for(k=0;k<l1;k++){
  105963. idij=is;
  105964. t3=t2;
  105965. for(i=2;i<ido;i+=2){
  105966. idij+=2;
  105967. t3+=2;
  105968. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  105969. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  105970. }
  105971. t2+=ido;
  105972. }
  105973. }
  105974. }
  105975. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  105976. int i,k1,l1,l2;
  105977. int na;
  105978. int nf,ip,iw,ix2,ix3,ido,idl1;
  105979. nf=ifac[1];
  105980. na=0;
  105981. l1=1;
  105982. iw=1;
  105983. for(k1=0;k1<nf;k1++){
  105984. ip=ifac[k1 + 2];
  105985. l2=ip*l1;
  105986. ido=n/l2;
  105987. idl1=ido*l1;
  105988. if(ip!=4)goto L103;
  105989. ix2=iw+ido;
  105990. ix3=ix2+ido;
  105991. if(na!=0)
  105992. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105993. else
  105994. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105995. na=1-na;
  105996. goto L115;
  105997. L103:
  105998. if(ip!=2)goto L106;
  105999. if(na!=0)
  106000. dradb2(ido,l1,ch,c,wa+iw-1);
  106001. else
  106002. dradb2(ido,l1,c,ch,wa+iw-1);
  106003. na=1-na;
  106004. goto L115;
  106005. L106:
  106006. if(ip!=3)goto L109;
  106007. ix2=iw+ido;
  106008. if(na!=0)
  106009. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106010. else
  106011. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106012. na=1-na;
  106013. goto L115;
  106014. L109:
  106015. if(na!=0)
  106016. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106017. else
  106018. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106019. if(ido==1)na=1-na;
  106020. L115:
  106021. l1=l2;
  106022. iw+=(ip-1)*ido;
  106023. }
  106024. if(na==0)return;
  106025. for(i=0;i<n;i++)c[i]=ch[i];
  106026. }
  106027. void drft_forward(drft_lookup *l,float *data){
  106028. if(l->n==1)return;
  106029. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106030. }
  106031. void drft_backward(drft_lookup *l,float *data){
  106032. if (l->n==1)return;
  106033. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106034. }
  106035. void drft_init(drft_lookup *l,int n){
  106036. l->n=n;
  106037. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106038. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106039. fdrffti(n, l->trigcache, l->splitcache);
  106040. }
  106041. void drft_clear(drft_lookup *l){
  106042. if(l){
  106043. if(l->trigcache)_ogg_free(l->trigcache);
  106044. if(l->splitcache)_ogg_free(l->splitcache);
  106045. memset(l,0,sizeof(*l));
  106046. }
  106047. }
  106048. #endif
  106049. /*** End of inlined file: smallft.c ***/
  106050. /*** Start of inlined file: synthesis.c ***/
  106051. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106052. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106053. // tasks..
  106054. #if JUCE_MSVC
  106055. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106056. #endif
  106057. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106058. #if JUCE_USE_OGGVORBIS
  106059. #include <stdio.h>
  106060. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106061. vorbis_dsp_state *vd=vb->vd;
  106062. private_state *b=(private_state*)vd->backend_state;
  106063. vorbis_info *vi=vd->vi;
  106064. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106065. oggpack_buffer *opb=&vb->opb;
  106066. int type,mode,i;
  106067. _vorbis_block_ripcord(vb);
  106068. oggpack_readinit(opb,op->packet,op->bytes);
  106069. if(oggpack_read(opb,1)!=0){
  106070. return(OV_ENOTAUDIO);
  106071. }
  106072. mode=oggpack_read(opb,b->modebits);
  106073. if(mode==-1)return(OV_EBADPACKET);
  106074. vb->mode=mode;
  106075. vb->W=ci->mode_param[mode]->blockflag;
  106076. if(vb->W){
  106077. vb->lW=oggpack_read(opb,1);
  106078. vb->nW=oggpack_read(opb,1);
  106079. if(vb->nW==-1) return(OV_EBADPACKET);
  106080. }else{
  106081. vb->lW=0;
  106082. vb->nW=0;
  106083. }
  106084. vb->granulepos=op->granulepos;
  106085. vb->sequence=op->packetno;
  106086. vb->eofflag=op->e_o_s;
  106087. vb->pcmend=ci->blocksizes[vb->W];
  106088. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106089. for(i=0;i<vi->channels;i++)
  106090. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106091. type=ci->map_type[ci->mode_param[mode]->mapping];
  106092. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106093. mapping]));
  106094. }
  106095. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106096. vorbis_dsp_state *vd=vb->vd;
  106097. private_state *b=(private_state*)vd->backend_state;
  106098. vorbis_info *vi=vd->vi;
  106099. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106100. oggpack_buffer *opb=&vb->opb;
  106101. int mode;
  106102. _vorbis_block_ripcord(vb);
  106103. oggpack_readinit(opb,op->packet,op->bytes);
  106104. if(oggpack_read(opb,1)!=0){
  106105. return(OV_ENOTAUDIO);
  106106. }
  106107. mode=oggpack_read(opb,b->modebits);
  106108. if(mode==-1)return(OV_EBADPACKET);
  106109. vb->mode=mode;
  106110. vb->W=ci->mode_param[mode]->blockflag;
  106111. if(vb->W){
  106112. vb->lW=oggpack_read(opb,1);
  106113. vb->nW=oggpack_read(opb,1);
  106114. if(vb->nW==-1) return(OV_EBADPACKET);
  106115. }else{
  106116. vb->lW=0;
  106117. vb->nW=0;
  106118. }
  106119. vb->granulepos=op->granulepos;
  106120. vb->sequence=op->packetno;
  106121. vb->eofflag=op->e_o_s;
  106122. vb->pcmend=0;
  106123. vb->pcm=NULL;
  106124. return(0);
  106125. }
  106126. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106127. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106128. oggpack_buffer opb;
  106129. int mode;
  106130. oggpack_readinit(&opb,op->packet,op->bytes);
  106131. if(oggpack_read(&opb,1)!=0){
  106132. return(OV_ENOTAUDIO);
  106133. }
  106134. {
  106135. int modebits=0;
  106136. int v=ci->modes;
  106137. while(v>1){
  106138. modebits++;
  106139. v>>=1;
  106140. }
  106141. mode=oggpack_read(&opb,modebits);
  106142. }
  106143. if(mode==-1)return(OV_EBADPACKET);
  106144. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106145. }
  106146. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106147. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106148. if(ci->blocksizes[0]<=64 && flag)return -1;
  106149. ci->halfrate_flag=(flag?1:0);
  106150. return 0;
  106151. }
  106152. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106153. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106154. return ci->halfrate_flag;
  106155. }
  106156. #endif
  106157. /*** End of inlined file: synthesis.c ***/
  106158. /*** Start of inlined file: vorbisenc.c ***/
  106159. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106160. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106161. // tasks..
  106162. #if JUCE_MSVC
  106163. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106164. #endif
  106165. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106166. #if JUCE_USE_OGGVORBIS
  106167. #include <stdlib.h>
  106168. #include <string.h>
  106169. #include <math.h>
  106170. typedef struct {
  106171. static_codebook *books[12][3];
  106172. } static_bookblock;
  106173. typedef struct {
  106174. int res_type;
  106175. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106176. vorbis_info_residue0 *res;
  106177. static_codebook *book_aux;
  106178. static_codebook *book_aux_managed;
  106179. static_bookblock *books_base;
  106180. static_bookblock *books_base_managed;
  106181. } vorbis_residue_template;
  106182. typedef struct {
  106183. vorbis_info_mapping0 *map;
  106184. vorbis_residue_template *res;
  106185. } vorbis_mapping_template;
  106186. typedef struct vp_adjblock{
  106187. int block[P_BANDS];
  106188. } vp_adjblock;
  106189. typedef struct {
  106190. int data[NOISE_COMPAND_LEVELS];
  106191. } compandblock;
  106192. typedef struct {
  106193. int att[P_NOISECURVES];
  106194. float boost;
  106195. float decay;
  106196. } att3;
  106197. typedef struct { int data[P_NOISECURVES]; } adj3;
  106198. typedef struct {
  106199. int pre[PACKETBLOBS];
  106200. int post[PACKETBLOBS];
  106201. float kHz[PACKETBLOBS];
  106202. float lowpasskHz[PACKETBLOBS];
  106203. } adj_stereo;
  106204. typedef struct {
  106205. int lo;
  106206. int hi;
  106207. int fixed;
  106208. } noiseguard;
  106209. typedef struct {
  106210. int data[P_NOISECURVES][17];
  106211. } noise3;
  106212. typedef struct {
  106213. int mappings;
  106214. double *rate_mapping;
  106215. double *quality_mapping;
  106216. int coupling_restriction;
  106217. long samplerate_min_restriction;
  106218. long samplerate_max_restriction;
  106219. int *blocksize_short;
  106220. int *blocksize_long;
  106221. att3 *psy_tone_masteratt;
  106222. int *psy_tone_0dB;
  106223. int *psy_tone_dBsuppress;
  106224. vp_adjblock *psy_tone_adj_impulse;
  106225. vp_adjblock *psy_tone_adj_long;
  106226. vp_adjblock *psy_tone_adj_other;
  106227. noiseguard *psy_noiseguards;
  106228. noise3 *psy_noise_bias_impulse;
  106229. noise3 *psy_noise_bias_padding;
  106230. noise3 *psy_noise_bias_trans;
  106231. noise3 *psy_noise_bias_long;
  106232. int *psy_noise_dBsuppress;
  106233. compandblock *psy_noise_compand;
  106234. double *psy_noise_compand_short_mapping;
  106235. double *psy_noise_compand_long_mapping;
  106236. int *psy_noise_normal_start[2];
  106237. int *psy_noise_normal_partition[2];
  106238. double *psy_noise_normal_thresh;
  106239. int *psy_ath_float;
  106240. int *psy_ath_abs;
  106241. double *psy_lowpass;
  106242. vorbis_info_psy_global *global_params;
  106243. double *global_mapping;
  106244. adj_stereo *stereo_modes;
  106245. static_codebook ***floor_books;
  106246. vorbis_info_floor1 *floor_params;
  106247. int *floor_short_mapping;
  106248. int *floor_long_mapping;
  106249. vorbis_mapping_template *maps;
  106250. } ve_setup_data_template;
  106251. static vorbis_info_mode _mode_template[2]={
  106252. {0,0,0,0},
  106253. {1,0,0,1}
  106254. };
  106255. static vorbis_info_mapping0 _map_nominal[2]={
  106256. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106257. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106258. };
  106259. /*** Start of inlined file: setup_44.h ***/
  106260. /*** Start of inlined file: floor_all.h ***/
  106261. /*** Start of inlined file: floor_books.h ***/
  106262. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106263. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106264. };
  106265. static static_codebook _huff_book_line_256x7_0sub1 = {
  106266. 1, 9,
  106267. _huff_lengthlist_line_256x7_0sub1,
  106268. 0, 0, 0, 0, 0,
  106269. NULL,
  106270. NULL,
  106271. NULL,
  106272. NULL,
  106273. 0
  106274. };
  106275. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106277. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106278. };
  106279. static static_codebook _huff_book_line_256x7_0sub2 = {
  106280. 1, 25,
  106281. _huff_lengthlist_line_256x7_0sub2,
  106282. 0, 0, 0, 0, 0,
  106283. NULL,
  106284. NULL,
  106285. NULL,
  106286. NULL,
  106287. 0
  106288. };
  106289. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106292. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106293. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106294. };
  106295. static static_codebook _huff_book_line_256x7_0sub3 = {
  106296. 1, 64,
  106297. _huff_lengthlist_line_256x7_0sub3,
  106298. 0, 0, 0, 0, 0,
  106299. NULL,
  106300. NULL,
  106301. NULL,
  106302. NULL,
  106303. 0
  106304. };
  106305. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106306. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106307. };
  106308. static static_codebook _huff_book_line_256x7_1sub1 = {
  106309. 1, 9,
  106310. _huff_lengthlist_line_256x7_1sub1,
  106311. 0, 0, 0, 0, 0,
  106312. NULL,
  106313. NULL,
  106314. NULL,
  106315. NULL,
  106316. 0
  106317. };
  106318. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106320. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106321. };
  106322. static static_codebook _huff_book_line_256x7_1sub2 = {
  106323. 1, 25,
  106324. _huff_lengthlist_line_256x7_1sub2,
  106325. 0, 0, 0, 0, 0,
  106326. NULL,
  106327. NULL,
  106328. NULL,
  106329. NULL,
  106330. 0
  106331. };
  106332. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106335. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106336. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106337. };
  106338. static static_codebook _huff_book_line_256x7_1sub3 = {
  106339. 1, 64,
  106340. _huff_lengthlist_line_256x7_1sub3,
  106341. 0, 0, 0, 0, 0,
  106342. NULL,
  106343. NULL,
  106344. NULL,
  106345. NULL,
  106346. 0
  106347. };
  106348. static long _huff_lengthlist_line_256x7_class0[] = {
  106349. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106350. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106351. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106352. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106353. };
  106354. static static_codebook _huff_book_line_256x7_class0 = {
  106355. 1, 64,
  106356. _huff_lengthlist_line_256x7_class0,
  106357. 0, 0, 0, 0, 0,
  106358. NULL,
  106359. NULL,
  106360. NULL,
  106361. NULL,
  106362. 0
  106363. };
  106364. static long _huff_lengthlist_line_256x7_class1[] = {
  106365. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106366. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106367. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106368. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106369. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106370. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106371. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106372. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106373. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106374. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106375. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106376. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106377. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106378. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106379. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106380. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106381. };
  106382. static static_codebook _huff_book_line_256x7_class1 = {
  106383. 1, 256,
  106384. _huff_lengthlist_line_256x7_class1,
  106385. 0, 0, 0, 0, 0,
  106386. NULL,
  106387. NULL,
  106388. NULL,
  106389. NULL,
  106390. 0
  106391. };
  106392. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106393. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106394. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106395. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106396. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106397. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106398. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106399. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106400. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106401. };
  106402. static static_codebook _huff_book_line_512x17_0sub0 = {
  106403. 1, 128,
  106404. _huff_lengthlist_line_512x17_0sub0,
  106405. 0, 0, 0, 0, 0,
  106406. NULL,
  106407. NULL,
  106408. NULL,
  106409. NULL,
  106410. 0
  106411. };
  106412. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106413. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106414. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106415. };
  106416. static static_codebook _huff_book_line_512x17_1sub0 = {
  106417. 1, 32,
  106418. _huff_lengthlist_line_512x17_1sub0,
  106419. 0, 0, 0, 0, 0,
  106420. NULL,
  106421. NULL,
  106422. NULL,
  106423. NULL,
  106424. 0
  106425. };
  106426. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106429. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106430. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106431. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106432. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106433. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106434. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106435. };
  106436. static static_codebook _huff_book_line_512x17_1sub1 = {
  106437. 1, 128,
  106438. _huff_lengthlist_line_512x17_1sub1,
  106439. 0, 0, 0, 0, 0,
  106440. NULL,
  106441. NULL,
  106442. NULL,
  106443. NULL,
  106444. 0
  106445. };
  106446. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106447. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106448. 5, 3,
  106449. };
  106450. static static_codebook _huff_book_line_512x17_2sub1 = {
  106451. 1, 18,
  106452. _huff_lengthlist_line_512x17_2sub1,
  106453. 0, 0, 0, 0, 0,
  106454. NULL,
  106455. NULL,
  106456. NULL,
  106457. NULL,
  106458. 0
  106459. };
  106460. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106462. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106463. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106464. 9, 8,
  106465. };
  106466. static static_codebook _huff_book_line_512x17_2sub2 = {
  106467. 1, 50,
  106468. _huff_lengthlist_line_512x17_2sub2,
  106469. 0, 0, 0, 0, 0,
  106470. NULL,
  106471. NULL,
  106472. NULL,
  106473. NULL,
  106474. 0
  106475. };
  106476. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106480. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106481. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106482. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106483. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106484. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106485. };
  106486. static static_codebook _huff_book_line_512x17_2sub3 = {
  106487. 1, 128,
  106488. _huff_lengthlist_line_512x17_2sub3,
  106489. 0, 0, 0, 0, 0,
  106490. NULL,
  106491. NULL,
  106492. NULL,
  106493. NULL,
  106494. 0
  106495. };
  106496. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106497. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106498. 5, 5,
  106499. };
  106500. static static_codebook _huff_book_line_512x17_3sub1 = {
  106501. 1, 18,
  106502. _huff_lengthlist_line_512x17_3sub1,
  106503. 0, 0, 0, 0, 0,
  106504. NULL,
  106505. NULL,
  106506. NULL,
  106507. NULL,
  106508. 0
  106509. };
  106510. static long _huff_lengthlist_line_512x17_3sub2[] = {
  106511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106512. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  106513. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  106514. 11,14,
  106515. };
  106516. static static_codebook _huff_book_line_512x17_3sub2 = {
  106517. 1, 50,
  106518. _huff_lengthlist_line_512x17_3sub2,
  106519. 0, 0, 0, 0, 0,
  106520. NULL,
  106521. NULL,
  106522. NULL,
  106523. NULL,
  106524. 0
  106525. };
  106526. static long _huff_lengthlist_line_512x17_3sub3[] = {
  106527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106530. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  106531. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106532. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106533. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106534. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  106535. };
  106536. static static_codebook _huff_book_line_512x17_3sub3 = {
  106537. 1, 128,
  106538. _huff_lengthlist_line_512x17_3sub3,
  106539. 0, 0, 0, 0, 0,
  106540. NULL,
  106541. NULL,
  106542. NULL,
  106543. NULL,
  106544. 0
  106545. };
  106546. static long _huff_lengthlist_line_512x17_class1[] = {
  106547. 1, 2, 3, 6, 5, 4, 7, 7,
  106548. };
  106549. static static_codebook _huff_book_line_512x17_class1 = {
  106550. 1, 8,
  106551. _huff_lengthlist_line_512x17_class1,
  106552. 0, 0, 0, 0, 0,
  106553. NULL,
  106554. NULL,
  106555. NULL,
  106556. NULL,
  106557. 0
  106558. };
  106559. static long _huff_lengthlist_line_512x17_class2[] = {
  106560. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  106561. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  106562. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  106563. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  106564. };
  106565. static static_codebook _huff_book_line_512x17_class2 = {
  106566. 1, 64,
  106567. _huff_lengthlist_line_512x17_class2,
  106568. 0, 0, 0, 0, 0,
  106569. NULL,
  106570. NULL,
  106571. NULL,
  106572. NULL,
  106573. 0
  106574. };
  106575. static long _huff_lengthlist_line_512x17_class3[] = {
  106576. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  106577. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  106578. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  106579. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  106580. };
  106581. static static_codebook _huff_book_line_512x17_class3 = {
  106582. 1, 64,
  106583. _huff_lengthlist_line_512x17_class3,
  106584. 0, 0, 0, 0, 0,
  106585. NULL,
  106586. NULL,
  106587. NULL,
  106588. NULL,
  106589. 0
  106590. };
  106591. static long _huff_lengthlist_line_128x4_class0[] = {
  106592. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  106593. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  106594. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  106595. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  106596. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  106597. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  106598. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  106599. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  106600. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  106601. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  106602. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  106603. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  106604. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  106605. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  106606. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  106607. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  106608. };
  106609. static static_codebook _huff_book_line_128x4_class0 = {
  106610. 1, 256,
  106611. _huff_lengthlist_line_128x4_class0,
  106612. 0, 0, 0, 0, 0,
  106613. NULL,
  106614. NULL,
  106615. NULL,
  106616. NULL,
  106617. 0
  106618. };
  106619. static long _huff_lengthlist_line_128x4_0sub0[] = {
  106620. 2, 2, 2, 2,
  106621. };
  106622. static static_codebook _huff_book_line_128x4_0sub0 = {
  106623. 1, 4,
  106624. _huff_lengthlist_line_128x4_0sub0,
  106625. 0, 0, 0, 0, 0,
  106626. NULL,
  106627. NULL,
  106628. NULL,
  106629. NULL,
  106630. 0
  106631. };
  106632. static long _huff_lengthlist_line_128x4_0sub1[] = {
  106633. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  106634. };
  106635. static static_codebook _huff_book_line_128x4_0sub1 = {
  106636. 1, 10,
  106637. _huff_lengthlist_line_128x4_0sub1,
  106638. 0, 0, 0, 0, 0,
  106639. NULL,
  106640. NULL,
  106641. NULL,
  106642. NULL,
  106643. 0
  106644. };
  106645. static long _huff_lengthlist_line_128x4_0sub2[] = {
  106646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  106647. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  106648. };
  106649. static static_codebook _huff_book_line_128x4_0sub2 = {
  106650. 1, 25,
  106651. _huff_lengthlist_line_128x4_0sub2,
  106652. 0, 0, 0, 0, 0,
  106653. NULL,
  106654. NULL,
  106655. NULL,
  106656. NULL,
  106657. 0
  106658. };
  106659. static long _huff_lengthlist_line_128x4_0sub3[] = {
  106660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106662. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  106663. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  106664. };
  106665. static static_codebook _huff_book_line_128x4_0sub3 = {
  106666. 1, 64,
  106667. _huff_lengthlist_line_128x4_0sub3,
  106668. 0, 0, 0, 0, 0,
  106669. NULL,
  106670. NULL,
  106671. NULL,
  106672. NULL,
  106673. 0
  106674. };
  106675. static long _huff_lengthlist_line_256x4_class0[] = {
  106676. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  106677. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  106678. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  106679. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  106680. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  106681. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  106682. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  106683. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  106684. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  106685. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  106686. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  106687. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  106688. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  106689. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  106690. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  106691. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  106692. };
  106693. static static_codebook _huff_book_line_256x4_class0 = {
  106694. 1, 256,
  106695. _huff_lengthlist_line_256x4_class0,
  106696. 0, 0, 0, 0, 0,
  106697. NULL,
  106698. NULL,
  106699. NULL,
  106700. NULL,
  106701. 0
  106702. };
  106703. static long _huff_lengthlist_line_256x4_0sub0[] = {
  106704. 2, 2, 2, 2,
  106705. };
  106706. static static_codebook _huff_book_line_256x4_0sub0 = {
  106707. 1, 4,
  106708. _huff_lengthlist_line_256x4_0sub0,
  106709. 0, 0, 0, 0, 0,
  106710. NULL,
  106711. NULL,
  106712. NULL,
  106713. NULL,
  106714. 0
  106715. };
  106716. static long _huff_lengthlist_line_256x4_0sub1[] = {
  106717. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  106718. };
  106719. static static_codebook _huff_book_line_256x4_0sub1 = {
  106720. 1, 10,
  106721. _huff_lengthlist_line_256x4_0sub1,
  106722. 0, 0, 0, 0, 0,
  106723. NULL,
  106724. NULL,
  106725. NULL,
  106726. NULL,
  106727. 0
  106728. };
  106729. static long _huff_lengthlist_line_256x4_0sub2[] = {
  106730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  106731. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  106732. };
  106733. static static_codebook _huff_book_line_256x4_0sub2 = {
  106734. 1, 25,
  106735. _huff_lengthlist_line_256x4_0sub2,
  106736. 0, 0, 0, 0, 0,
  106737. NULL,
  106738. NULL,
  106739. NULL,
  106740. NULL,
  106741. 0
  106742. };
  106743. static long _huff_lengthlist_line_256x4_0sub3[] = {
  106744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  106746. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  106747. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  106748. };
  106749. static static_codebook _huff_book_line_256x4_0sub3 = {
  106750. 1, 64,
  106751. _huff_lengthlist_line_256x4_0sub3,
  106752. 0, 0, 0, 0, 0,
  106753. NULL,
  106754. NULL,
  106755. NULL,
  106756. NULL,
  106757. 0
  106758. };
  106759. static long _huff_lengthlist_line_128x7_class0[] = {
  106760. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  106761. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  106762. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  106763. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  106764. };
  106765. static static_codebook _huff_book_line_128x7_class0 = {
  106766. 1, 64,
  106767. _huff_lengthlist_line_128x7_class0,
  106768. 0, 0, 0, 0, 0,
  106769. NULL,
  106770. NULL,
  106771. NULL,
  106772. NULL,
  106773. 0
  106774. };
  106775. static long _huff_lengthlist_line_128x7_class1[] = {
  106776. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  106777. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  106778. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  106779. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106780. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  106781. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  106782. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  106783. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  106784. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  106785. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  106786. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  106787. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  106788. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  106789. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  106790. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  106791. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  106792. };
  106793. static static_codebook _huff_book_line_128x7_class1 = {
  106794. 1, 256,
  106795. _huff_lengthlist_line_128x7_class1,
  106796. 0, 0, 0, 0, 0,
  106797. NULL,
  106798. NULL,
  106799. NULL,
  106800. NULL,
  106801. 0
  106802. };
  106803. static long _huff_lengthlist_line_128x7_0sub1[] = {
  106804. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  106805. };
  106806. static static_codebook _huff_book_line_128x7_0sub1 = {
  106807. 1, 9,
  106808. _huff_lengthlist_line_128x7_0sub1,
  106809. 0, 0, 0, 0, 0,
  106810. NULL,
  106811. NULL,
  106812. NULL,
  106813. NULL,
  106814. 0
  106815. };
  106816. static long _huff_lengthlist_line_128x7_0sub2[] = {
  106817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  106818. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  106819. };
  106820. static static_codebook _huff_book_line_128x7_0sub2 = {
  106821. 1, 25,
  106822. _huff_lengthlist_line_128x7_0sub2,
  106823. 0, 0, 0, 0, 0,
  106824. NULL,
  106825. NULL,
  106826. NULL,
  106827. NULL,
  106828. 0
  106829. };
  106830. static long _huff_lengthlist_line_128x7_0sub3[] = {
  106831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  106833. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106834. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  106835. };
  106836. static static_codebook _huff_book_line_128x7_0sub3 = {
  106837. 1, 64,
  106838. _huff_lengthlist_line_128x7_0sub3,
  106839. 0, 0, 0, 0, 0,
  106840. NULL,
  106841. NULL,
  106842. NULL,
  106843. NULL,
  106844. 0
  106845. };
  106846. static long _huff_lengthlist_line_128x7_1sub1[] = {
  106847. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  106848. };
  106849. static static_codebook _huff_book_line_128x7_1sub1 = {
  106850. 1, 9,
  106851. _huff_lengthlist_line_128x7_1sub1,
  106852. 0, 0, 0, 0, 0,
  106853. NULL,
  106854. NULL,
  106855. NULL,
  106856. NULL,
  106857. 0
  106858. };
  106859. static long _huff_lengthlist_line_128x7_1sub2[] = {
  106860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  106861. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  106862. };
  106863. static static_codebook _huff_book_line_128x7_1sub2 = {
  106864. 1, 25,
  106865. _huff_lengthlist_line_128x7_1sub2,
  106866. 0, 0, 0, 0, 0,
  106867. NULL,
  106868. NULL,
  106869. NULL,
  106870. NULL,
  106871. 0
  106872. };
  106873. static long _huff_lengthlist_line_128x7_1sub3[] = {
  106874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  106876. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  106877. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  106878. };
  106879. static static_codebook _huff_book_line_128x7_1sub3 = {
  106880. 1, 64,
  106881. _huff_lengthlist_line_128x7_1sub3,
  106882. 0, 0, 0, 0, 0,
  106883. NULL,
  106884. NULL,
  106885. NULL,
  106886. NULL,
  106887. 0
  106888. };
  106889. static long _huff_lengthlist_line_128x11_class1[] = {
  106890. 1, 6, 3, 7, 2, 4, 5, 7,
  106891. };
  106892. static static_codebook _huff_book_line_128x11_class1 = {
  106893. 1, 8,
  106894. _huff_lengthlist_line_128x11_class1,
  106895. 0, 0, 0, 0, 0,
  106896. NULL,
  106897. NULL,
  106898. NULL,
  106899. NULL,
  106900. 0
  106901. };
  106902. static long _huff_lengthlist_line_128x11_class2[] = {
  106903. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  106904. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  106905. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  106906. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  106907. };
  106908. static static_codebook _huff_book_line_128x11_class2 = {
  106909. 1, 64,
  106910. _huff_lengthlist_line_128x11_class2,
  106911. 0, 0, 0, 0, 0,
  106912. NULL,
  106913. NULL,
  106914. NULL,
  106915. NULL,
  106916. 0
  106917. };
  106918. static long _huff_lengthlist_line_128x11_class3[] = {
  106919. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  106920. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  106921. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  106922. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  106923. };
  106924. static static_codebook _huff_book_line_128x11_class3 = {
  106925. 1, 64,
  106926. _huff_lengthlist_line_128x11_class3,
  106927. 0, 0, 0, 0, 0,
  106928. NULL,
  106929. NULL,
  106930. NULL,
  106931. NULL,
  106932. 0
  106933. };
  106934. static long _huff_lengthlist_line_128x11_0sub0[] = {
  106935. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  106936. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  106937. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  106938. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  106939. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  106940. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  106941. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  106942. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  106943. };
  106944. static static_codebook _huff_book_line_128x11_0sub0 = {
  106945. 1, 128,
  106946. _huff_lengthlist_line_128x11_0sub0,
  106947. 0, 0, 0, 0, 0,
  106948. NULL,
  106949. NULL,
  106950. NULL,
  106951. NULL,
  106952. 0
  106953. };
  106954. static long _huff_lengthlist_line_128x11_1sub0[] = {
  106955. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  106956. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  106957. };
  106958. static static_codebook _huff_book_line_128x11_1sub0 = {
  106959. 1, 32,
  106960. _huff_lengthlist_line_128x11_1sub0,
  106961. 0, 0, 0, 0, 0,
  106962. NULL,
  106963. NULL,
  106964. NULL,
  106965. NULL,
  106966. 0
  106967. };
  106968. static long _huff_lengthlist_line_128x11_1sub1[] = {
  106969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106971. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  106972. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  106973. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  106974. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  106975. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  106976. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  106977. };
  106978. static static_codebook _huff_book_line_128x11_1sub1 = {
  106979. 1, 128,
  106980. _huff_lengthlist_line_128x11_1sub1,
  106981. 0, 0, 0, 0, 0,
  106982. NULL,
  106983. NULL,
  106984. NULL,
  106985. NULL,
  106986. 0
  106987. };
  106988. static long _huff_lengthlist_line_128x11_2sub1[] = {
  106989. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  106990. 5, 5,
  106991. };
  106992. static static_codebook _huff_book_line_128x11_2sub1 = {
  106993. 1, 18,
  106994. _huff_lengthlist_line_128x11_2sub1,
  106995. 0, 0, 0, 0, 0,
  106996. NULL,
  106997. NULL,
  106998. NULL,
  106999. NULL,
  107000. 0
  107001. };
  107002. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107004. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107005. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107006. 8,11,
  107007. };
  107008. static static_codebook _huff_book_line_128x11_2sub2 = {
  107009. 1, 50,
  107010. _huff_lengthlist_line_128x11_2sub2,
  107011. 0, 0, 0, 0, 0,
  107012. NULL,
  107013. NULL,
  107014. NULL,
  107015. NULL,
  107016. 0
  107017. };
  107018. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107022. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107023. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107024. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107025. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107026. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107027. };
  107028. static static_codebook _huff_book_line_128x11_2sub3 = {
  107029. 1, 128,
  107030. _huff_lengthlist_line_128x11_2sub3,
  107031. 0, 0, 0, 0, 0,
  107032. NULL,
  107033. NULL,
  107034. NULL,
  107035. NULL,
  107036. 0
  107037. };
  107038. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107039. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107040. 5, 4,
  107041. };
  107042. static static_codebook _huff_book_line_128x11_3sub1 = {
  107043. 1, 18,
  107044. _huff_lengthlist_line_128x11_3sub1,
  107045. 0, 0, 0, 0, 0,
  107046. NULL,
  107047. NULL,
  107048. NULL,
  107049. NULL,
  107050. 0
  107051. };
  107052. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107054. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107055. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107056. 12, 6,
  107057. };
  107058. static static_codebook _huff_book_line_128x11_3sub2 = {
  107059. 1, 50,
  107060. _huff_lengthlist_line_128x11_3sub2,
  107061. 0, 0, 0, 0, 0,
  107062. NULL,
  107063. NULL,
  107064. NULL,
  107065. NULL,
  107066. 0
  107067. };
  107068. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107072. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107073. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107074. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107075. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107076. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107077. };
  107078. static static_codebook _huff_book_line_128x11_3sub3 = {
  107079. 1, 128,
  107080. _huff_lengthlist_line_128x11_3sub3,
  107081. 0, 0, 0, 0, 0,
  107082. NULL,
  107083. NULL,
  107084. NULL,
  107085. NULL,
  107086. 0
  107087. };
  107088. static long _huff_lengthlist_line_128x17_class1[] = {
  107089. 1, 3, 4, 7, 2, 5, 6, 7,
  107090. };
  107091. static static_codebook _huff_book_line_128x17_class1 = {
  107092. 1, 8,
  107093. _huff_lengthlist_line_128x17_class1,
  107094. 0, 0, 0, 0, 0,
  107095. NULL,
  107096. NULL,
  107097. NULL,
  107098. NULL,
  107099. 0
  107100. };
  107101. static long _huff_lengthlist_line_128x17_class2[] = {
  107102. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107103. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107104. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107105. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107106. };
  107107. static static_codebook _huff_book_line_128x17_class2 = {
  107108. 1, 64,
  107109. _huff_lengthlist_line_128x17_class2,
  107110. 0, 0, 0, 0, 0,
  107111. NULL,
  107112. NULL,
  107113. NULL,
  107114. NULL,
  107115. 0
  107116. };
  107117. static long _huff_lengthlist_line_128x17_class3[] = {
  107118. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107119. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107120. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107121. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107122. };
  107123. static static_codebook _huff_book_line_128x17_class3 = {
  107124. 1, 64,
  107125. _huff_lengthlist_line_128x17_class3,
  107126. 0, 0, 0, 0, 0,
  107127. NULL,
  107128. NULL,
  107129. NULL,
  107130. NULL,
  107131. 0
  107132. };
  107133. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107134. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107135. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107136. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107137. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107138. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107139. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107140. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107141. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107142. };
  107143. static static_codebook _huff_book_line_128x17_0sub0 = {
  107144. 1, 128,
  107145. _huff_lengthlist_line_128x17_0sub0,
  107146. 0, 0, 0, 0, 0,
  107147. NULL,
  107148. NULL,
  107149. NULL,
  107150. NULL,
  107151. 0
  107152. };
  107153. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107154. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107155. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107156. };
  107157. static static_codebook _huff_book_line_128x17_1sub0 = {
  107158. 1, 32,
  107159. _huff_lengthlist_line_128x17_1sub0,
  107160. 0, 0, 0, 0, 0,
  107161. NULL,
  107162. NULL,
  107163. NULL,
  107164. NULL,
  107165. 0
  107166. };
  107167. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107170. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107171. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107172. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107173. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107174. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107175. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107176. };
  107177. static static_codebook _huff_book_line_128x17_1sub1 = {
  107178. 1, 128,
  107179. _huff_lengthlist_line_128x17_1sub1,
  107180. 0, 0, 0, 0, 0,
  107181. NULL,
  107182. NULL,
  107183. NULL,
  107184. NULL,
  107185. 0
  107186. };
  107187. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107188. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107189. 9, 4,
  107190. };
  107191. static static_codebook _huff_book_line_128x17_2sub1 = {
  107192. 1, 18,
  107193. _huff_lengthlist_line_128x17_2sub1,
  107194. 0, 0, 0, 0, 0,
  107195. NULL,
  107196. NULL,
  107197. NULL,
  107198. NULL,
  107199. 0
  107200. };
  107201. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107203. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107204. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107205. 13,13,
  107206. };
  107207. static static_codebook _huff_book_line_128x17_2sub2 = {
  107208. 1, 50,
  107209. _huff_lengthlist_line_128x17_2sub2,
  107210. 0, 0, 0, 0, 0,
  107211. NULL,
  107212. NULL,
  107213. NULL,
  107214. NULL,
  107215. 0
  107216. };
  107217. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107221. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107222. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107223. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107224. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107225. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107226. };
  107227. static static_codebook _huff_book_line_128x17_2sub3 = {
  107228. 1, 128,
  107229. _huff_lengthlist_line_128x17_2sub3,
  107230. 0, 0, 0, 0, 0,
  107231. NULL,
  107232. NULL,
  107233. NULL,
  107234. NULL,
  107235. 0
  107236. };
  107237. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107238. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107239. 6, 4,
  107240. };
  107241. static static_codebook _huff_book_line_128x17_3sub1 = {
  107242. 1, 18,
  107243. _huff_lengthlist_line_128x17_3sub1,
  107244. 0, 0, 0, 0, 0,
  107245. NULL,
  107246. NULL,
  107247. NULL,
  107248. NULL,
  107249. 0
  107250. };
  107251. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107253. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107254. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107255. 10, 8,
  107256. };
  107257. static static_codebook _huff_book_line_128x17_3sub2 = {
  107258. 1, 50,
  107259. _huff_lengthlist_line_128x17_3sub2,
  107260. 0, 0, 0, 0, 0,
  107261. NULL,
  107262. NULL,
  107263. NULL,
  107264. NULL,
  107265. 0
  107266. };
  107267. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107271. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107272. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107273. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107274. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107275. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107276. };
  107277. static static_codebook _huff_book_line_128x17_3sub3 = {
  107278. 1, 128,
  107279. _huff_lengthlist_line_128x17_3sub3,
  107280. 0, 0, 0, 0, 0,
  107281. NULL,
  107282. NULL,
  107283. NULL,
  107284. NULL,
  107285. 0
  107286. };
  107287. static long _huff_lengthlist_line_1024x27_class1[] = {
  107288. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107289. };
  107290. static static_codebook _huff_book_line_1024x27_class1 = {
  107291. 1, 16,
  107292. _huff_lengthlist_line_1024x27_class1,
  107293. 0, 0, 0, 0, 0,
  107294. NULL,
  107295. NULL,
  107296. NULL,
  107297. NULL,
  107298. 0
  107299. };
  107300. static long _huff_lengthlist_line_1024x27_class2[] = {
  107301. 1, 4, 2, 6, 3, 7, 5, 7,
  107302. };
  107303. static static_codebook _huff_book_line_1024x27_class2 = {
  107304. 1, 8,
  107305. _huff_lengthlist_line_1024x27_class2,
  107306. 0, 0, 0, 0, 0,
  107307. NULL,
  107308. NULL,
  107309. NULL,
  107310. NULL,
  107311. 0
  107312. };
  107313. static long _huff_lengthlist_line_1024x27_class3[] = {
  107314. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107315. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107316. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107317. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107318. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107319. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107320. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107321. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107322. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107323. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107324. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107325. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107326. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107327. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107328. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107329. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107330. };
  107331. static static_codebook _huff_book_line_1024x27_class3 = {
  107332. 1, 256,
  107333. _huff_lengthlist_line_1024x27_class3,
  107334. 0, 0, 0, 0, 0,
  107335. NULL,
  107336. NULL,
  107337. NULL,
  107338. NULL,
  107339. 0
  107340. };
  107341. static long _huff_lengthlist_line_1024x27_class4[] = {
  107342. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107343. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107344. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107345. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107346. };
  107347. static static_codebook _huff_book_line_1024x27_class4 = {
  107348. 1, 64,
  107349. _huff_lengthlist_line_1024x27_class4,
  107350. 0, 0, 0, 0, 0,
  107351. NULL,
  107352. NULL,
  107353. NULL,
  107354. NULL,
  107355. 0
  107356. };
  107357. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107358. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107359. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107360. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107361. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107362. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107363. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107364. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107365. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107366. };
  107367. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107368. 1, 128,
  107369. _huff_lengthlist_line_1024x27_0sub0,
  107370. 0, 0, 0, 0, 0,
  107371. NULL,
  107372. NULL,
  107373. NULL,
  107374. NULL,
  107375. 0
  107376. };
  107377. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107378. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107379. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107380. };
  107381. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107382. 1, 32,
  107383. _huff_lengthlist_line_1024x27_1sub0,
  107384. 0, 0, 0, 0, 0,
  107385. NULL,
  107386. NULL,
  107387. NULL,
  107388. NULL,
  107389. 0
  107390. };
  107391. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107394. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107395. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107396. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107397. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107398. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107399. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107400. };
  107401. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107402. 1, 128,
  107403. _huff_lengthlist_line_1024x27_1sub1,
  107404. 0, 0, 0, 0, 0,
  107405. NULL,
  107406. NULL,
  107407. NULL,
  107408. NULL,
  107409. 0
  107410. };
  107411. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107412. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107413. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107414. };
  107415. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107416. 1, 32,
  107417. _huff_lengthlist_line_1024x27_2sub0,
  107418. 0, 0, 0, 0, 0,
  107419. NULL,
  107420. NULL,
  107421. NULL,
  107422. NULL,
  107423. 0
  107424. };
  107425. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107428. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107429. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107430. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107431. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107432. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107433. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107434. };
  107435. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107436. 1, 128,
  107437. _huff_lengthlist_line_1024x27_2sub1,
  107438. 0, 0, 0, 0, 0,
  107439. NULL,
  107440. NULL,
  107441. NULL,
  107442. NULL,
  107443. 0
  107444. };
  107445. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107446. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107447. 5, 5,
  107448. };
  107449. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107450. 1, 18,
  107451. _huff_lengthlist_line_1024x27_3sub1,
  107452. 0, 0, 0, 0, 0,
  107453. NULL,
  107454. NULL,
  107455. NULL,
  107456. NULL,
  107457. 0
  107458. };
  107459. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107461. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107462. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107463. 9,11,
  107464. };
  107465. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107466. 1, 50,
  107467. _huff_lengthlist_line_1024x27_3sub2,
  107468. 0, 0, 0, 0, 0,
  107469. NULL,
  107470. NULL,
  107471. NULL,
  107472. NULL,
  107473. 0
  107474. };
  107475. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107479. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107480. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107481. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107482. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107483. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107484. };
  107485. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107486. 1, 128,
  107487. _huff_lengthlist_line_1024x27_3sub3,
  107488. 0, 0, 0, 0, 0,
  107489. NULL,
  107490. NULL,
  107491. NULL,
  107492. NULL,
  107493. 0
  107494. };
  107495. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107496. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107497. 5, 4,
  107498. };
  107499. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107500. 1, 18,
  107501. _huff_lengthlist_line_1024x27_4sub1,
  107502. 0, 0, 0, 0, 0,
  107503. NULL,
  107504. NULL,
  107505. NULL,
  107506. NULL,
  107507. 0
  107508. };
  107509. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  107510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107511. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  107512. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  107513. 9,12,
  107514. };
  107515. static static_codebook _huff_book_line_1024x27_4sub2 = {
  107516. 1, 50,
  107517. _huff_lengthlist_line_1024x27_4sub2,
  107518. 0, 0, 0, 0, 0,
  107519. NULL,
  107520. NULL,
  107521. NULL,
  107522. NULL,
  107523. 0
  107524. };
  107525. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  107526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107529. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  107530. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  107531. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107532. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107533. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  107534. };
  107535. static static_codebook _huff_book_line_1024x27_4sub3 = {
  107536. 1, 128,
  107537. _huff_lengthlist_line_1024x27_4sub3,
  107538. 0, 0, 0, 0, 0,
  107539. NULL,
  107540. NULL,
  107541. NULL,
  107542. NULL,
  107543. 0
  107544. };
  107545. static long _huff_lengthlist_line_2048x27_class1[] = {
  107546. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  107547. };
  107548. static static_codebook _huff_book_line_2048x27_class1 = {
  107549. 1, 16,
  107550. _huff_lengthlist_line_2048x27_class1,
  107551. 0, 0, 0, 0, 0,
  107552. NULL,
  107553. NULL,
  107554. NULL,
  107555. NULL,
  107556. 0
  107557. };
  107558. static long _huff_lengthlist_line_2048x27_class2[] = {
  107559. 1, 2, 3, 6, 4, 7, 5, 7,
  107560. };
  107561. static static_codebook _huff_book_line_2048x27_class2 = {
  107562. 1, 8,
  107563. _huff_lengthlist_line_2048x27_class2,
  107564. 0, 0, 0, 0, 0,
  107565. NULL,
  107566. NULL,
  107567. NULL,
  107568. NULL,
  107569. 0
  107570. };
  107571. static long _huff_lengthlist_line_2048x27_class3[] = {
  107572. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  107573. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  107574. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  107575. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  107576. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  107577. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  107578. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  107579. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  107580. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  107581. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  107582. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  107583. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107584. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  107585. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  107586. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107587. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  107588. };
  107589. static static_codebook _huff_book_line_2048x27_class3 = {
  107590. 1, 256,
  107591. _huff_lengthlist_line_2048x27_class3,
  107592. 0, 0, 0, 0, 0,
  107593. NULL,
  107594. NULL,
  107595. NULL,
  107596. NULL,
  107597. 0
  107598. };
  107599. static long _huff_lengthlist_line_2048x27_class4[] = {
  107600. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  107601. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  107602. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  107603. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  107604. };
  107605. static static_codebook _huff_book_line_2048x27_class4 = {
  107606. 1, 64,
  107607. _huff_lengthlist_line_2048x27_class4,
  107608. 0, 0, 0, 0, 0,
  107609. NULL,
  107610. NULL,
  107611. NULL,
  107612. NULL,
  107613. 0
  107614. };
  107615. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  107616. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107617. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  107618. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  107619. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  107620. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  107621. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  107622. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  107623. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  107624. };
  107625. static static_codebook _huff_book_line_2048x27_0sub0 = {
  107626. 1, 128,
  107627. _huff_lengthlist_line_2048x27_0sub0,
  107628. 0, 0, 0, 0, 0,
  107629. NULL,
  107630. NULL,
  107631. NULL,
  107632. NULL,
  107633. 0
  107634. };
  107635. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  107636. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107637. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  107638. };
  107639. static static_codebook _huff_book_line_2048x27_1sub0 = {
  107640. 1, 32,
  107641. _huff_lengthlist_line_2048x27_1sub0,
  107642. 0, 0, 0, 0, 0,
  107643. NULL,
  107644. NULL,
  107645. NULL,
  107646. NULL,
  107647. 0
  107648. };
  107649. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  107650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107652. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  107653. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  107654. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  107655. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  107656. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  107657. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  107658. };
  107659. static static_codebook _huff_book_line_2048x27_1sub1 = {
  107660. 1, 128,
  107661. _huff_lengthlist_line_2048x27_1sub1,
  107662. 0, 0, 0, 0, 0,
  107663. NULL,
  107664. NULL,
  107665. NULL,
  107666. NULL,
  107667. 0
  107668. };
  107669. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  107670. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107671. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  107672. };
  107673. static static_codebook _huff_book_line_2048x27_2sub0 = {
  107674. 1, 32,
  107675. _huff_lengthlist_line_2048x27_2sub0,
  107676. 0, 0, 0, 0, 0,
  107677. NULL,
  107678. NULL,
  107679. NULL,
  107680. NULL,
  107681. 0
  107682. };
  107683. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  107684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107686. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  107687. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  107688. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  107689. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  107690. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  107691. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107692. };
  107693. static static_codebook _huff_book_line_2048x27_2sub1 = {
  107694. 1, 128,
  107695. _huff_lengthlist_line_2048x27_2sub1,
  107696. 0, 0, 0, 0, 0,
  107697. NULL,
  107698. NULL,
  107699. NULL,
  107700. NULL,
  107701. 0
  107702. };
  107703. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  107704. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  107705. 5, 5,
  107706. };
  107707. static static_codebook _huff_book_line_2048x27_3sub1 = {
  107708. 1, 18,
  107709. _huff_lengthlist_line_2048x27_3sub1,
  107710. 0, 0, 0, 0, 0,
  107711. NULL,
  107712. NULL,
  107713. NULL,
  107714. NULL,
  107715. 0
  107716. };
  107717. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  107718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107719. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  107720. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  107721. 10,12,
  107722. };
  107723. static static_codebook _huff_book_line_2048x27_3sub2 = {
  107724. 1, 50,
  107725. _huff_lengthlist_line_2048x27_3sub2,
  107726. 0, 0, 0, 0, 0,
  107727. NULL,
  107728. NULL,
  107729. NULL,
  107730. NULL,
  107731. 0
  107732. };
  107733. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  107734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107737. 0, 0, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  107738. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107739. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107740. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107741. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107742. };
  107743. static static_codebook _huff_book_line_2048x27_3sub3 = {
  107744. 1, 128,
  107745. _huff_lengthlist_line_2048x27_3sub3,
  107746. 0, 0, 0, 0, 0,
  107747. NULL,
  107748. NULL,
  107749. NULL,
  107750. NULL,
  107751. 0
  107752. };
  107753. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  107754. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  107755. 4, 5,
  107756. };
  107757. static static_codebook _huff_book_line_2048x27_4sub1 = {
  107758. 1, 18,
  107759. _huff_lengthlist_line_2048x27_4sub1,
  107760. 0, 0, 0, 0, 0,
  107761. NULL,
  107762. NULL,
  107763. NULL,
  107764. NULL,
  107765. 0
  107766. };
  107767. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  107768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107769. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  107770. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  107771. 10,10,
  107772. };
  107773. static static_codebook _huff_book_line_2048x27_4sub2 = {
  107774. 1, 50,
  107775. _huff_lengthlist_line_2048x27_4sub2,
  107776. 0, 0, 0, 0, 0,
  107777. NULL,
  107778. NULL,
  107779. NULL,
  107780. NULL,
  107781. 0
  107782. };
  107783. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  107784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107787. 0, 0, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  107788. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  107789. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107790. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107791. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107792. };
  107793. static static_codebook _huff_book_line_2048x27_4sub3 = {
  107794. 1, 128,
  107795. _huff_lengthlist_line_2048x27_4sub3,
  107796. 0, 0, 0, 0, 0,
  107797. NULL,
  107798. NULL,
  107799. NULL,
  107800. NULL,
  107801. 0
  107802. };
  107803. static long _huff_lengthlist_line_256x4low_class0[] = {
  107804. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  107805. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  107806. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  107807. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  107808. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  107809. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  107810. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  107811. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  107812. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  107813. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  107814. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  107815. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  107816. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  107817. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  107818. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  107819. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  107820. };
  107821. static static_codebook _huff_book_line_256x4low_class0 = {
  107822. 1, 256,
  107823. _huff_lengthlist_line_256x4low_class0,
  107824. 0, 0, 0, 0, 0,
  107825. NULL,
  107826. NULL,
  107827. NULL,
  107828. NULL,
  107829. 0
  107830. };
  107831. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  107832. 1, 3, 2, 3,
  107833. };
  107834. static static_codebook _huff_book_line_256x4low_0sub0 = {
  107835. 1, 4,
  107836. _huff_lengthlist_line_256x4low_0sub0,
  107837. 0, 0, 0, 0, 0,
  107838. NULL,
  107839. NULL,
  107840. NULL,
  107841. NULL,
  107842. 0
  107843. };
  107844. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  107845. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  107846. };
  107847. static static_codebook _huff_book_line_256x4low_0sub1 = {
  107848. 1, 10,
  107849. _huff_lengthlist_line_256x4low_0sub1,
  107850. 0, 0, 0, 0, 0,
  107851. NULL,
  107852. NULL,
  107853. NULL,
  107854. NULL,
  107855. 0
  107856. };
  107857. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  107858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  107859. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  107860. };
  107861. static static_codebook _huff_book_line_256x4low_0sub2 = {
  107862. 1, 25,
  107863. _huff_lengthlist_line_256x4low_0sub2,
  107864. 0, 0, 0, 0, 0,
  107865. NULL,
  107866. NULL,
  107867. NULL,
  107868. NULL,
  107869. 0
  107870. };
  107871. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  107872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 2, 4, 3, 5, 4,
  107874. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  107875. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  107876. };
  107877. static static_codebook _huff_book_line_256x4low_0sub3 = {
  107878. 1, 64,
  107879. _huff_lengthlist_line_256x4low_0sub3,
  107880. 0, 0, 0, 0, 0,
  107881. NULL,
  107882. NULL,
  107883. NULL,
  107884. NULL,
  107885. 0
  107886. };
  107887. /*** End of inlined file: floor_books.h ***/
  107888. static static_codebook *_floor_128x4_books[]={
  107889. &_huff_book_line_128x4_class0,
  107890. &_huff_book_line_128x4_0sub0,
  107891. &_huff_book_line_128x4_0sub1,
  107892. &_huff_book_line_128x4_0sub2,
  107893. &_huff_book_line_128x4_0sub3,
  107894. };
  107895. static static_codebook *_floor_256x4_books[]={
  107896. &_huff_book_line_256x4_class0,
  107897. &_huff_book_line_256x4_0sub0,
  107898. &_huff_book_line_256x4_0sub1,
  107899. &_huff_book_line_256x4_0sub2,
  107900. &_huff_book_line_256x4_0sub3,
  107901. };
  107902. static static_codebook *_floor_128x7_books[]={
  107903. &_huff_book_line_128x7_class0,
  107904. &_huff_book_line_128x7_class1,
  107905. &_huff_book_line_128x7_0sub1,
  107906. &_huff_book_line_128x7_0sub2,
  107907. &_huff_book_line_128x7_0sub3,
  107908. &_huff_book_line_128x7_1sub1,
  107909. &_huff_book_line_128x7_1sub2,
  107910. &_huff_book_line_128x7_1sub3,
  107911. };
  107912. static static_codebook *_floor_256x7_books[]={
  107913. &_huff_book_line_256x7_class0,
  107914. &_huff_book_line_256x7_class1,
  107915. &_huff_book_line_256x7_0sub1,
  107916. &_huff_book_line_256x7_0sub2,
  107917. &_huff_book_line_256x7_0sub3,
  107918. &_huff_book_line_256x7_1sub1,
  107919. &_huff_book_line_256x7_1sub2,
  107920. &_huff_book_line_256x7_1sub3,
  107921. };
  107922. static static_codebook *_floor_128x11_books[]={
  107923. &_huff_book_line_128x11_class1,
  107924. &_huff_book_line_128x11_class2,
  107925. &_huff_book_line_128x11_class3,
  107926. &_huff_book_line_128x11_0sub0,
  107927. &_huff_book_line_128x11_1sub0,
  107928. &_huff_book_line_128x11_1sub1,
  107929. &_huff_book_line_128x11_2sub1,
  107930. &_huff_book_line_128x11_2sub2,
  107931. &_huff_book_line_128x11_2sub3,
  107932. &_huff_book_line_128x11_3sub1,
  107933. &_huff_book_line_128x11_3sub2,
  107934. &_huff_book_line_128x11_3sub3,
  107935. };
  107936. static static_codebook *_floor_128x17_books[]={
  107937. &_huff_book_line_128x17_class1,
  107938. &_huff_book_line_128x17_class2,
  107939. &_huff_book_line_128x17_class3,
  107940. &_huff_book_line_128x17_0sub0,
  107941. &_huff_book_line_128x17_1sub0,
  107942. &_huff_book_line_128x17_1sub1,
  107943. &_huff_book_line_128x17_2sub1,
  107944. &_huff_book_line_128x17_2sub2,
  107945. &_huff_book_line_128x17_2sub3,
  107946. &_huff_book_line_128x17_3sub1,
  107947. &_huff_book_line_128x17_3sub2,
  107948. &_huff_book_line_128x17_3sub3,
  107949. };
  107950. static static_codebook *_floor_256x4low_books[]={
  107951. &_huff_book_line_256x4low_class0,
  107952. &_huff_book_line_256x4low_0sub0,
  107953. &_huff_book_line_256x4low_0sub1,
  107954. &_huff_book_line_256x4low_0sub2,
  107955. &_huff_book_line_256x4low_0sub3,
  107956. };
  107957. static static_codebook *_floor_1024x27_books[]={
  107958. &_huff_book_line_1024x27_class1,
  107959. &_huff_book_line_1024x27_class2,
  107960. &_huff_book_line_1024x27_class3,
  107961. &_huff_book_line_1024x27_class4,
  107962. &_huff_book_line_1024x27_0sub0,
  107963. &_huff_book_line_1024x27_1sub0,
  107964. &_huff_book_line_1024x27_1sub1,
  107965. &_huff_book_line_1024x27_2sub0,
  107966. &_huff_book_line_1024x27_2sub1,
  107967. &_huff_book_line_1024x27_3sub1,
  107968. &_huff_book_line_1024x27_3sub2,
  107969. &_huff_book_line_1024x27_3sub3,
  107970. &_huff_book_line_1024x27_4sub1,
  107971. &_huff_book_line_1024x27_4sub2,
  107972. &_huff_book_line_1024x27_4sub3,
  107973. };
  107974. static static_codebook *_floor_2048x27_books[]={
  107975. &_huff_book_line_2048x27_class1,
  107976. &_huff_book_line_2048x27_class2,
  107977. &_huff_book_line_2048x27_class3,
  107978. &_huff_book_line_2048x27_class4,
  107979. &_huff_book_line_2048x27_0sub0,
  107980. &_huff_book_line_2048x27_1sub0,
  107981. &_huff_book_line_2048x27_1sub1,
  107982. &_huff_book_line_2048x27_2sub0,
  107983. &_huff_book_line_2048x27_2sub1,
  107984. &_huff_book_line_2048x27_3sub1,
  107985. &_huff_book_line_2048x27_3sub2,
  107986. &_huff_book_line_2048x27_3sub3,
  107987. &_huff_book_line_2048x27_4sub1,
  107988. &_huff_book_line_2048x27_4sub2,
  107989. &_huff_book_line_2048x27_4sub3,
  107990. };
  107991. static static_codebook *_floor_512x17_books[]={
  107992. &_huff_book_line_512x17_class1,
  107993. &_huff_book_line_512x17_class2,
  107994. &_huff_book_line_512x17_class3,
  107995. &_huff_book_line_512x17_0sub0,
  107996. &_huff_book_line_512x17_1sub0,
  107997. &_huff_book_line_512x17_1sub1,
  107998. &_huff_book_line_512x17_2sub1,
  107999. &_huff_book_line_512x17_2sub2,
  108000. &_huff_book_line_512x17_2sub3,
  108001. &_huff_book_line_512x17_3sub1,
  108002. &_huff_book_line_512x17_3sub2,
  108003. &_huff_book_line_512x17_3sub3,
  108004. };
  108005. static static_codebook **_floor_books[10]={
  108006. _floor_128x4_books,
  108007. _floor_256x4_books,
  108008. _floor_128x7_books,
  108009. _floor_256x7_books,
  108010. _floor_128x11_books,
  108011. _floor_128x17_books,
  108012. _floor_256x4low_books,
  108013. _floor_1024x27_books,
  108014. _floor_2048x27_books,
  108015. _floor_512x17_books,
  108016. };
  108017. static vorbis_info_floor1 _floor[10]={
  108018. {
  108019. 1,{0},{4},{2},{0},
  108020. {{1,2,3,4}},
  108021. 4,{0,128, 33,8,16,70},
  108022. 60,30,500, 1.,18., -1
  108023. },
  108024. {
  108025. 1,{0},{4},{2},{0},
  108026. {{1,2,3,4}},
  108027. 4,{0,256, 66,16,32,140},
  108028. 60,30,500, 1.,18., -1
  108029. },
  108030. {
  108031. 2,{0,1},{3,4},{2,2},{0,1},
  108032. {{-1,2,3,4},{-1,5,6,7}},
  108033. 4,{0,128, 14,4,58, 2,8,28,90},
  108034. 60,30,500, 1.,18., -1
  108035. },
  108036. {
  108037. 2,{0,1},{3,4},{2,2},{0,1},
  108038. {{-1,2,3,4},{-1,5,6,7}},
  108039. 4,{0,256, 28,8,116, 4,16,56,180},
  108040. 60,30,500, 1.,18., -1
  108041. },
  108042. {
  108043. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108044. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108045. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108046. 60,30,500, 1,18., -1
  108047. },
  108048. {
  108049. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108050. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108051. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108052. 60,30,500, 1,18., -1
  108053. },
  108054. {
  108055. 1,{0},{4},{2},{0},
  108056. {{1,2,3,4}},
  108057. 4,{0,256, 66,16,32,140},
  108058. 60,30,500, 1.,18., -1
  108059. },
  108060. {
  108061. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108062. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108063. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108064. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108065. 60,30,500, 3,18., -1 /* lowpass */
  108066. },
  108067. {
  108068. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108069. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108070. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108071. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108072. 60,30,500, 3,18., -1 /* lowpass */
  108073. },
  108074. {
  108075. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108076. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108077. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108078. 7,23,39, 55,79,110, 156,232,360},
  108079. 60,30,500, 1,18., -1 /* lowpass! */
  108080. },
  108081. };
  108082. /*** End of inlined file: floor_all.h ***/
  108083. /*** Start of inlined file: residue_44.h ***/
  108084. /*** Start of inlined file: res_books_stereo.h ***/
  108085. static long _vq_quantlist__16c0_s_p1_0[] = {
  108086. 1,
  108087. 0,
  108088. 2,
  108089. };
  108090. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108091. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108092. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108097. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108102. 0, 0, 0, 0, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  108106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  108111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  108116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 8, 0, 0, 0, 0,
  108137. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0,
  108142. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 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, 7,10,10, 0, 0,
  108147. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108152. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108157. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108183. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108188. 0, 0, 0, 0, 0, 9,10,12, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108193. 0, 0, 0, 0, 0, 0, 9,12, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108501. 0,
  108502. };
  108503. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108504. -0.5, 0.5,
  108505. };
  108506. static long _vq_quantmap__16c0_s_p1_0[] = {
  108507. 1, 0, 2,
  108508. };
  108509. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  108510. _vq_quantthresh__16c0_s_p1_0,
  108511. _vq_quantmap__16c0_s_p1_0,
  108512. 3,
  108513. 3
  108514. };
  108515. static static_codebook _16c0_s_p1_0 = {
  108516. 8, 6561,
  108517. _vq_lengthlist__16c0_s_p1_0,
  108518. 1, -535822336, 1611661312, 2, 0,
  108519. _vq_quantlist__16c0_s_p1_0,
  108520. NULL,
  108521. &_vq_auxt__16c0_s_p1_0,
  108522. NULL,
  108523. 0
  108524. };
  108525. static long _vq_quantlist__16c0_s_p2_0[] = {
  108526. 2,
  108527. 1,
  108528. 3,
  108529. 0,
  108530. 4,
  108531. };
  108532. static long _vq_lengthlist__16c0_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108572. 0,
  108573. };
  108574. static float _vq_quantthresh__16c0_s_p2_0[] = {
  108575. -1.5, -0.5, 0.5, 1.5,
  108576. };
  108577. static long _vq_quantmap__16c0_s_p2_0[] = {
  108578. 3, 1, 0, 2, 4,
  108579. };
  108580. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  108581. _vq_quantthresh__16c0_s_p2_0,
  108582. _vq_quantmap__16c0_s_p2_0,
  108583. 5,
  108584. 5
  108585. };
  108586. static static_codebook _16c0_s_p2_0 = {
  108587. 4, 625,
  108588. _vq_lengthlist__16c0_s_p2_0,
  108589. 1, -533725184, 1611661312, 3, 0,
  108590. _vq_quantlist__16c0_s_p2_0,
  108591. NULL,
  108592. &_vq_auxt__16c0_s_p2_0,
  108593. NULL,
  108594. 0
  108595. };
  108596. static long _vq_quantlist__16c0_s_p3_0[] = {
  108597. 2,
  108598. 1,
  108599. 3,
  108600. 0,
  108601. 4,
  108602. };
  108603. static long _vq_lengthlist__16c0_s_p3_0[] = {
  108604. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  108609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108610. 0, 0, 0, 0, 6, 6, 6, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108643. 0,
  108644. };
  108645. static float _vq_quantthresh__16c0_s_p3_0[] = {
  108646. -1.5, -0.5, 0.5, 1.5,
  108647. };
  108648. static long _vq_quantmap__16c0_s_p3_0[] = {
  108649. 3, 1, 0, 2, 4,
  108650. };
  108651. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  108652. _vq_quantthresh__16c0_s_p3_0,
  108653. _vq_quantmap__16c0_s_p3_0,
  108654. 5,
  108655. 5
  108656. };
  108657. static static_codebook _16c0_s_p3_0 = {
  108658. 4, 625,
  108659. _vq_lengthlist__16c0_s_p3_0,
  108660. 1, -533725184, 1611661312, 3, 0,
  108661. _vq_quantlist__16c0_s_p3_0,
  108662. NULL,
  108663. &_vq_auxt__16c0_s_p3_0,
  108664. NULL,
  108665. 0
  108666. };
  108667. static long _vq_quantlist__16c0_s_p4_0[] = {
  108668. 4,
  108669. 3,
  108670. 5,
  108671. 2,
  108672. 6,
  108673. 1,
  108674. 7,
  108675. 0,
  108676. 8,
  108677. };
  108678. static long _vq_lengthlist__16c0_s_p4_0[] = {
  108679. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  108680. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  108681. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  108682. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  108683. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108684. 0,
  108685. };
  108686. static float _vq_quantthresh__16c0_s_p4_0[] = {
  108687. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108688. };
  108689. static long _vq_quantmap__16c0_s_p4_0[] = {
  108690. 7, 5, 3, 1, 0, 2, 4, 6,
  108691. 8,
  108692. };
  108693. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  108694. _vq_quantthresh__16c0_s_p4_0,
  108695. _vq_quantmap__16c0_s_p4_0,
  108696. 9,
  108697. 9
  108698. };
  108699. static static_codebook _16c0_s_p4_0 = {
  108700. 2, 81,
  108701. _vq_lengthlist__16c0_s_p4_0,
  108702. 1, -531628032, 1611661312, 4, 0,
  108703. _vq_quantlist__16c0_s_p4_0,
  108704. NULL,
  108705. &_vq_auxt__16c0_s_p4_0,
  108706. NULL,
  108707. 0
  108708. };
  108709. static long _vq_quantlist__16c0_s_p5_0[] = {
  108710. 4,
  108711. 3,
  108712. 5,
  108713. 2,
  108714. 6,
  108715. 1,
  108716. 7,
  108717. 0,
  108718. 8,
  108719. };
  108720. static long _vq_lengthlist__16c0_s_p5_0[] = {
  108721. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  108722. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  108723. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  108724. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  108725. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  108726. 10,
  108727. };
  108728. static float _vq_quantthresh__16c0_s_p5_0[] = {
  108729. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  108730. };
  108731. static long _vq_quantmap__16c0_s_p5_0[] = {
  108732. 7, 5, 3, 1, 0, 2, 4, 6,
  108733. 8,
  108734. };
  108735. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  108736. _vq_quantthresh__16c0_s_p5_0,
  108737. _vq_quantmap__16c0_s_p5_0,
  108738. 9,
  108739. 9
  108740. };
  108741. static static_codebook _16c0_s_p5_0 = {
  108742. 2, 81,
  108743. _vq_lengthlist__16c0_s_p5_0,
  108744. 1, -531628032, 1611661312, 4, 0,
  108745. _vq_quantlist__16c0_s_p5_0,
  108746. NULL,
  108747. &_vq_auxt__16c0_s_p5_0,
  108748. NULL,
  108749. 0
  108750. };
  108751. static long _vq_quantlist__16c0_s_p6_0[] = {
  108752. 8,
  108753. 7,
  108754. 9,
  108755. 6,
  108756. 10,
  108757. 5,
  108758. 11,
  108759. 4,
  108760. 12,
  108761. 3,
  108762. 13,
  108763. 2,
  108764. 14,
  108765. 1,
  108766. 15,
  108767. 0,
  108768. 16,
  108769. };
  108770. static long _vq_lengthlist__16c0_s_p6_0[] = {
  108771. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  108772. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  108773. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  108774. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  108775. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  108776. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  108777. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  108778. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  108779. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  108780. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  108781. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  108782. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  108783. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  108784. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  108785. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  108786. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  108787. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  108788. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  108789. 14,
  108790. };
  108791. static float _vq_quantthresh__16c0_s_p6_0[] = {
  108792. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  108793. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  108794. };
  108795. static long _vq_quantmap__16c0_s_p6_0[] = {
  108796. 15, 13, 11, 9, 7, 5, 3, 1,
  108797. 0, 2, 4, 6, 8, 10, 12, 14,
  108798. 16,
  108799. };
  108800. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  108801. _vq_quantthresh__16c0_s_p6_0,
  108802. _vq_quantmap__16c0_s_p6_0,
  108803. 17,
  108804. 17
  108805. };
  108806. static static_codebook _16c0_s_p6_0 = {
  108807. 2, 289,
  108808. _vq_lengthlist__16c0_s_p6_0,
  108809. 1, -529530880, 1611661312, 5, 0,
  108810. _vq_quantlist__16c0_s_p6_0,
  108811. NULL,
  108812. &_vq_auxt__16c0_s_p6_0,
  108813. NULL,
  108814. 0
  108815. };
  108816. static long _vq_quantlist__16c0_s_p7_0[] = {
  108817. 1,
  108818. 0,
  108819. 2,
  108820. };
  108821. static long _vq_lengthlist__16c0_s_p7_0[] = {
  108822. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  108823. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  108824. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  108825. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  108826. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  108827. 13,
  108828. };
  108829. static float _vq_quantthresh__16c0_s_p7_0[] = {
  108830. -5.5, 5.5,
  108831. };
  108832. static long _vq_quantmap__16c0_s_p7_0[] = {
  108833. 1, 0, 2,
  108834. };
  108835. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  108836. _vq_quantthresh__16c0_s_p7_0,
  108837. _vq_quantmap__16c0_s_p7_0,
  108838. 3,
  108839. 3
  108840. };
  108841. static static_codebook _16c0_s_p7_0 = {
  108842. 4, 81,
  108843. _vq_lengthlist__16c0_s_p7_0,
  108844. 1, -529137664, 1618345984, 2, 0,
  108845. _vq_quantlist__16c0_s_p7_0,
  108846. NULL,
  108847. &_vq_auxt__16c0_s_p7_0,
  108848. NULL,
  108849. 0
  108850. };
  108851. static long _vq_quantlist__16c0_s_p7_1[] = {
  108852. 5,
  108853. 4,
  108854. 6,
  108855. 3,
  108856. 7,
  108857. 2,
  108858. 8,
  108859. 1,
  108860. 9,
  108861. 0,
  108862. 10,
  108863. };
  108864. static long _vq_lengthlist__16c0_s_p7_1[] = {
  108865. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  108866. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  108867. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  108868. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  108869. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  108870. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  108871. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  108872. 11,11,11, 9, 9, 9, 9,10,10,
  108873. };
  108874. static float _vq_quantthresh__16c0_s_p7_1[] = {
  108875. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  108876. 3.5, 4.5,
  108877. };
  108878. static long _vq_quantmap__16c0_s_p7_1[] = {
  108879. 9, 7, 5, 3, 1, 0, 2, 4,
  108880. 6, 8, 10,
  108881. };
  108882. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  108883. _vq_quantthresh__16c0_s_p7_1,
  108884. _vq_quantmap__16c0_s_p7_1,
  108885. 11,
  108886. 11
  108887. };
  108888. static static_codebook _16c0_s_p7_1 = {
  108889. 2, 121,
  108890. _vq_lengthlist__16c0_s_p7_1,
  108891. 1, -531365888, 1611661312, 4, 0,
  108892. _vq_quantlist__16c0_s_p7_1,
  108893. NULL,
  108894. &_vq_auxt__16c0_s_p7_1,
  108895. NULL,
  108896. 0
  108897. };
  108898. static long _vq_quantlist__16c0_s_p8_0[] = {
  108899. 6,
  108900. 5,
  108901. 7,
  108902. 4,
  108903. 8,
  108904. 3,
  108905. 9,
  108906. 2,
  108907. 10,
  108908. 1,
  108909. 11,
  108910. 0,
  108911. 12,
  108912. };
  108913. static long _vq_lengthlist__16c0_s_p8_0[] = {
  108914. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  108915. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  108916. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  108917. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  108918. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  108919. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  108920. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  108921. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  108922. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  108923. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  108924. 0,12,13,13,12,13,14,14,14,
  108925. };
  108926. static float _vq_quantthresh__16c0_s_p8_0[] = {
  108927. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  108928. 12.5, 17.5, 22.5, 27.5,
  108929. };
  108930. static long _vq_quantmap__16c0_s_p8_0[] = {
  108931. 11, 9, 7, 5, 3, 1, 0, 2,
  108932. 4, 6, 8, 10, 12,
  108933. };
  108934. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  108935. _vq_quantthresh__16c0_s_p8_0,
  108936. _vq_quantmap__16c0_s_p8_0,
  108937. 13,
  108938. 13
  108939. };
  108940. static static_codebook _16c0_s_p8_0 = {
  108941. 2, 169,
  108942. _vq_lengthlist__16c0_s_p8_0,
  108943. 1, -526516224, 1616117760, 4, 0,
  108944. _vq_quantlist__16c0_s_p8_0,
  108945. NULL,
  108946. &_vq_auxt__16c0_s_p8_0,
  108947. NULL,
  108948. 0
  108949. };
  108950. static long _vq_quantlist__16c0_s_p8_1[] = {
  108951. 2,
  108952. 1,
  108953. 3,
  108954. 0,
  108955. 4,
  108956. };
  108957. static long _vq_lengthlist__16c0_s_p8_1[] = {
  108958. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  108959. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  108960. };
  108961. static float _vq_quantthresh__16c0_s_p8_1[] = {
  108962. -1.5, -0.5, 0.5, 1.5,
  108963. };
  108964. static long _vq_quantmap__16c0_s_p8_1[] = {
  108965. 3, 1, 0, 2, 4,
  108966. };
  108967. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  108968. _vq_quantthresh__16c0_s_p8_1,
  108969. _vq_quantmap__16c0_s_p8_1,
  108970. 5,
  108971. 5
  108972. };
  108973. static static_codebook _16c0_s_p8_1 = {
  108974. 2, 25,
  108975. _vq_lengthlist__16c0_s_p8_1,
  108976. 1, -533725184, 1611661312, 3, 0,
  108977. _vq_quantlist__16c0_s_p8_1,
  108978. NULL,
  108979. &_vq_auxt__16c0_s_p8_1,
  108980. NULL,
  108981. 0
  108982. };
  108983. static long _vq_quantlist__16c0_s_p9_0[] = {
  108984. 1,
  108985. 0,
  108986. 2,
  108987. };
  108988. static long _vq_lengthlist__16c0_s_p9_0[] = {
  108989. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  108990. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  108991. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108992. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108993. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108994. 7,
  108995. };
  108996. static float _vq_quantthresh__16c0_s_p9_0[] = {
  108997. -157.5, 157.5,
  108998. };
  108999. static long _vq_quantmap__16c0_s_p9_0[] = {
  109000. 1, 0, 2,
  109001. };
  109002. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109003. _vq_quantthresh__16c0_s_p9_0,
  109004. _vq_quantmap__16c0_s_p9_0,
  109005. 3,
  109006. 3
  109007. };
  109008. static static_codebook _16c0_s_p9_0 = {
  109009. 4, 81,
  109010. _vq_lengthlist__16c0_s_p9_0,
  109011. 1, -518803456, 1628680192, 2, 0,
  109012. _vq_quantlist__16c0_s_p9_0,
  109013. NULL,
  109014. &_vq_auxt__16c0_s_p9_0,
  109015. NULL,
  109016. 0
  109017. };
  109018. static long _vq_quantlist__16c0_s_p9_1[] = {
  109019. 7,
  109020. 6,
  109021. 8,
  109022. 5,
  109023. 9,
  109024. 4,
  109025. 10,
  109026. 3,
  109027. 11,
  109028. 2,
  109029. 12,
  109030. 1,
  109031. 13,
  109032. 0,
  109033. 14,
  109034. };
  109035. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109036. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109037. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109038. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109039. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109040. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109041. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109042. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109043. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109044. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109045. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109046. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109047. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109048. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109049. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109050. 10,
  109051. };
  109052. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109053. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109054. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109055. };
  109056. static long _vq_quantmap__16c0_s_p9_1[] = {
  109057. 13, 11, 9, 7, 5, 3, 1, 0,
  109058. 2, 4, 6, 8, 10, 12, 14,
  109059. };
  109060. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109061. _vq_quantthresh__16c0_s_p9_1,
  109062. _vq_quantmap__16c0_s_p9_1,
  109063. 15,
  109064. 15
  109065. };
  109066. static static_codebook _16c0_s_p9_1 = {
  109067. 2, 225,
  109068. _vq_lengthlist__16c0_s_p9_1,
  109069. 1, -520986624, 1620377600, 4, 0,
  109070. _vq_quantlist__16c0_s_p9_1,
  109071. NULL,
  109072. &_vq_auxt__16c0_s_p9_1,
  109073. NULL,
  109074. 0
  109075. };
  109076. static long _vq_quantlist__16c0_s_p9_2[] = {
  109077. 10,
  109078. 9,
  109079. 11,
  109080. 8,
  109081. 12,
  109082. 7,
  109083. 13,
  109084. 6,
  109085. 14,
  109086. 5,
  109087. 15,
  109088. 4,
  109089. 16,
  109090. 3,
  109091. 17,
  109092. 2,
  109093. 18,
  109094. 1,
  109095. 19,
  109096. 0,
  109097. 20,
  109098. };
  109099. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109100. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109101. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109102. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109103. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109104. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109105. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109106. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109107. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109108. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109109. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109110. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109111. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109112. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109113. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109114. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109115. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109116. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109117. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109118. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109119. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109120. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109121. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109122. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109123. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109124. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109125. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109126. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109127. 10,11,10,10,11, 9,10,10,10,
  109128. };
  109129. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109130. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109131. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109132. 6.5, 7.5, 8.5, 9.5,
  109133. };
  109134. static long _vq_quantmap__16c0_s_p9_2[] = {
  109135. 19, 17, 15, 13, 11, 9, 7, 5,
  109136. 3, 1, 0, 2, 4, 6, 8, 10,
  109137. 12, 14, 16, 18, 20,
  109138. };
  109139. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109140. _vq_quantthresh__16c0_s_p9_2,
  109141. _vq_quantmap__16c0_s_p9_2,
  109142. 21,
  109143. 21
  109144. };
  109145. static static_codebook _16c0_s_p9_2 = {
  109146. 2, 441,
  109147. _vq_lengthlist__16c0_s_p9_2,
  109148. 1, -529268736, 1611661312, 5, 0,
  109149. _vq_quantlist__16c0_s_p9_2,
  109150. NULL,
  109151. &_vq_auxt__16c0_s_p9_2,
  109152. NULL,
  109153. 0
  109154. };
  109155. static long _huff_lengthlist__16c0_s_single[] = {
  109156. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109157. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109158. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109159. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109160. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109161. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109162. 16,16,18,18,
  109163. };
  109164. static static_codebook _huff_book__16c0_s_single = {
  109165. 2, 100,
  109166. _huff_lengthlist__16c0_s_single,
  109167. 0, 0, 0, 0, 0,
  109168. NULL,
  109169. NULL,
  109170. NULL,
  109171. NULL,
  109172. 0
  109173. };
  109174. static long _huff_lengthlist__16c1_s_long[] = {
  109175. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109176. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109177. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109178. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109179. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109180. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109181. 12,11,11,13,
  109182. };
  109183. static static_codebook _huff_book__16c1_s_long = {
  109184. 2, 100,
  109185. _huff_lengthlist__16c1_s_long,
  109186. 0, 0, 0, 0, 0,
  109187. NULL,
  109188. NULL,
  109189. NULL,
  109190. NULL,
  109191. 0
  109192. };
  109193. static long _vq_quantlist__16c1_s_p1_0[] = {
  109194. 1,
  109195. 0,
  109196. 2,
  109197. };
  109198. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109199. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109200. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109205. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109210. 0, 0, 0, 0, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  109214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  109219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  109224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 7, 0, 0, 0, 0,
  109245. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  109250. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  109255. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109260. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109265. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109291. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109296. 0, 0, 0, 0, 0, 8, 9,11, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109301. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109609. 0,
  109610. };
  109611. static float _vq_quantthresh__16c1_s_p1_0[] = {
  109612. -0.5, 0.5,
  109613. };
  109614. static long _vq_quantmap__16c1_s_p1_0[] = {
  109615. 1, 0, 2,
  109616. };
  109617. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  109618. _vq_quantthresh__16c1_s_p1_0,
  109619. _vq_quantmap__16c1_s_p1_0,
  109620. 3,
  109621. 3
  109622. };
  109623. static static_codebook _16c1_s_p1_0 = {
  109624. 8, 6561,
  109625. _vq_lengthlist__16c1_s_p1_0,
  109626. 1, -535822336, 1611661312, 2, 0,
  109627. _vq_quantlist__16c1_s_p1_0,
  109628. NULL,
  109629. &_vq_auxt__16c1_s_p1_0,
  109630. NULL,
  109631. 0
  109632. };
  109633. static long _vq_quantlist__16c1_s_p2_0[] = {
  109634. 2,
  109635. 1,
  109636. 3,
  109637. 0,
  109638. 4,
  109639. };
  109640. static long _vq_lengthlist__16c1_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109680. 0,
  109681. };
  109682. static float _vq_quantthresh__16c1_s_p2_0[] = {
  109683. -1.5, -0.5, 0.5, 1.5,
  109684. };
  109685. static long _vq_quantmap__16c1_s_p2_0[] = {
  109686. 3, 1, 0, 2, 4,
  109687. };
  109688. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  109689. _vq_quantthresh__16c1_s_p2_0,
  109690. _vq_quantmap__16c1_s_p2_0,
  109691. 5,
  109692. 5
  109693. };
  109694. static static_codebook _16c1_s_p2_0 = {
  109695. 4, 625,
  109696. _vq_lengthlist__16c1_s_p2_0,
  109697. 1, -533725184, 1611661312, 3, 0,
  109698. _vq_quantlist__16c1_s_p2_0,
  109699. NULL,
  109700. &_vq_auxt__16c1_s_p2_0,
  109701. NULL,
  109702. 0
  109703. };
  109704. static long _vq_quantlist__16c1_s_p3_0[] = {
  109705. 2,
  109706. 1,
  109707. 3,
  109708. 0,
  109709. 4,
  109710. };
  109711. static long _vq_lengthlist__16c1_s_p3_0[] = {
  109712. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  109714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109715. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  109717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109718. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109751. 0,
  109752. };
  109753. static float _vq_quantthresh__16c1_s_p3_0[] = {
  109754. -1.5, -0.5, 0.5, 1.5,
  109755. };
  109756. static long _vq_quantmap__16c1_s_p3_0[] = {
  109757. 3, 1, 0, 2, 4,
  109758. };
  109759. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  109760. _vq_quantthresh__16c1_s_p3_0,
  109761. _vq_quantmap__16c1_s_p3_0,
  109762. 5,
  109763. 5
  109764. };
  109765. static static_codebook _16c1_s_p3_0 = {
  109766. 4, 625,
  109767. _vq_lengthlist__16c1_s_p3_0,
  109768. 1, -533725184, 1611661312, 3, 0,
  109769. _vq_quantlist__16c1_s_p3_0,
  109770. NULL,
  109771. &_vq_auxt__16c1_s_p3_0,
  109772. NULL,
  109773. 0
  109774. };
  109775. static long _vq_quantlist__16c1_s_p4_0[] = {
  109776. 4,
  109777. 3,
  109778. 5,
  109779. 2,
  109780. 6,
  109781. 1,
  109782. 7,
  109783. 0,
  109784. 8,
  109785. };
  109786. static long _vq_lengthlist__16c1_s_p4_0[] = {
  109787. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109788. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109789. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109790. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  109791. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109792. 0,
  109793. };
  109794. static float _vq_quantthresh__16c1_s_p4_0[] = {
  109795. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109796. };
  109797. static long _vq_quantmap__16c1_s_p4_0[] = {
  109798. 7, 5, 3, 1, 0, 2, 4, 6,
  109799. 8,
  109800. };
  109801. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  109802. _vq_quantthresh__16c1_s_p4_0,
  109803. _vq_quantmap__16c1_s_p4_0,
  109804. 9,
  109805. 9
  109806. };
  109807. static static_codebook _16c1_s_p4_0 = {
  109808. 2, 81,
  109809. _vq_lengthlist__16c1_s_p4_0,
  109810. 1, -531628032, 1611661312, 4, 0,
  109811. _vq_quantlist__16c1_s_p4_0,
  109812. NULL,
  109813. &_vq_auxt__16c1_s_p4_0,
  109814. NULL,
  109815. 0
  109816. };
  109817. static long _vq_quantlist__16c1_s_p5_0[] = {
  109818. 4,
  109819. 3,
  109820. 5,
  109821. 2,
  109822. 6,
  109823. 1,
  109824. 7,
  109825. 0,
  109826. 8,
  109827. };
  109828. static long _vq_lengthlist__16c1_s_p5_0[] = {
  109829. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109830. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  109831. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  109832. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  109833. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109834. 10,
  109835. };
  109836. static float _vq_quantthresh__16c1_s_p5_0[] = {
  109837. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109838. };
  109839. static long _vq_quantmap__16c1_s_p5_0[] = {
  109840. 7, 5, 3, 1, 0, 2, 4, 6,
  109841. 8,
  109842. };
  109843. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  109844. _vq_quantthresh__16c1_s_p5_0,
  109845. _vq_quantmap__16c1_s_p5_0,
  109846. 9,
  109847. 9
  109848. };
  109849. static static_codebook _16c1_s_p5_0 = {
  109850. 2, 81,
  109851. _vq_lengthlist__16c1_s_p5_0,
  109852. 1, -531628032, 1611661312, 4, 0,
  109853. _vq_quantlist__16c1_s_p5_0,
  109854. NULL,
  109855. &_vq_auxt__16c1_s_p5_0,
  109856. NULL,
  109857. 0
  109858. };
  109859. static long _vq_quantlist__16c1_s_p6_0[] = {
  109860. 8,
  109861. 7,
  109862. 9,
  109863. 6,
  109864. 10,
  109865. 5,
  109866. 11,
  109867. 4,
  109868. 12,
  109869. 3,
  109870. 13,
  109871. 2,
  109872. 14,
  109873. 1,
  109874. 15,
  109875. 0,
  109876. 16,
  109877. };
  109878. static long _vq_lengthlist__16c1_s_p6_0[] = {
  109879. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  109880. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  109881. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  109882. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  109883. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  109884. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109885. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109886. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109887. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  109888. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109889. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  109890. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  109891. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  109892. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  109893. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  109894. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  109895. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  109896. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  109897. 14,
  109898. };
  109899. static float _vq_quantthresh__16c1_s_p6_0[] = {
  109900. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109901. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109902. };
  109903. static long _vq_quantmap__16c1_s_p6_0[] = {
  109904. 15, 13, 11, 9, 7, 5, 3, 1,
  109905. 0, 2, 4, 6, 8, 10, 12, 14,
  109906. 16,
  109907. };
  109908. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  109909. _vq_quantthresh__16c1_s_p6_0,
  109910. _vq_quantmap__16c1_s_p6_0,
  109911. 17,
  109912. 17
  109913. };
  109914. static static_codebook _16c1_s_p6_0 = {
  109915. 2, 289,
  109916. _vq_lengthlist__16c1_s_p6_0,
  109917. 1, -529530880, 1611661312, 5, 0,
  109918. _vq_quantlist__16c1_s_p6_0,
  109919. NULL,
  109920. &_vq_auxt__16c1_s_p6_0,
  109921. NULL,
  109922. 0
  109923. };
  109924. static long _vq_quantlist__16c1_s_p7_0[] = {
  109925. 1,
  109926. 0,
  109927. 2,
  109928. };
  109929. static long _vq_lengthlist__16c1_s_p7_0[] = {
  109930. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  109931. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109932. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  109933. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  109934. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  109935. 11,
  109936. };
  109937. static float _vq_quantthresh__16c1_s_p7_0[] = {
  109938. -5.5, 5.5,
  109939. };
  109940. static long _vq_quantmap__16c1_s_p7_0[] = {
  109941. 1, 0, 2,
  109942. };
  109943. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  109944. _vq_quantthresh__16c1_s_p7_0,
  109945. _vq_quantmap__16c1_s_p7_0,
  109946. 3,
  109947. 3
  109948. };
  109949. static static_codebook _16c1_s_p7_0 = {
  109950. 4, 81,
  109951. _vq_lengthlist__16c1_s_p7_0,
  109952. 1, -529137664, 1618345984, 2, 0,
  109953. _vq_quantlist__16c1_s_p7_0,
  109954. NULL,
  109955. &_vq_auxt__16c1_s_p7_0,
  109956. NULL,
  109957. 0
  109958. };
  109959. static long _vq_quantlist__16c1_s_p7_1[] = {
  109960. 5,
  109961. 4,
  109962. 6,
  109963. 3,
  109964. 7,
  109965. 2,
  109966. 8,
  109967. 1,
  109968. 9,
  109969. 0,
  109970. 10,
  109971. };
  109972. static long _vq_lengthlist__16c1_s_p7_1[] = {
  109973. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  109974. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  109975. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  109976. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  109977. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  109978. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  109979. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  109980. 10,10,10, 8, 8, 8, 8, 9, 9,
  109981. };
  109982. static float _vq_quantthresh__16c1_s_p7_1[] = {
  109983. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109984. 3.5, 4.5,
  109985. };
  109986. static long _vq_quantmap__16c1_s_p7_1[] = {
  109987. 9, 7, 5, 3, 1, 0, 2, 4,
  109988. 6, 8, 10,
  109989. };
  109990. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  109991. _vq_quantthresh__16c1_s_p7_1,
  109992. _vq_quantmap__16c1_s_p7_1,
  109993. 11,
  109994. 11
  109995. };
  109996. static static_codebook _16c1_s_p7_1 = {
  109997. 2, 121,
  109998. _vq_lengthlist__16c1_s_p7_1,
  109999. 1, -531365888, 1611661312, 4, 0,
  110000. _vq_quantlist__16c1_s_p7_1,
  110001. NULL,
  110002. &_vq_auxt__16c1_s_p7_1,
  110003. NULL,
  110004. 0
  110005. };
  110006. static long _vq_quantlist__16c1_s_p8_0[] = {
  110007. 6,
  110008. 5,
  110009. 7,
  110010. 4,
  110011. 8,
  110012. 3,
  110013. 9,
  110014. 2,
  110015. 10,
  110016. 1,
  110017. 11,
  110018. 0,
  110019. 12,
  110020. };
  110021. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110022. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110023. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110024. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110025. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110026. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110027. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110028. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110029. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110030. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110031. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110032. 0,12,12,12,12,13,13,14,15,
  110033. };
  110034. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110035. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110036. 12.5, 17.5, 22.5, 27.5,
  110037. };
  110038. static long _vq_quantmap__16c1_s_p8_0[] = {
  110039. 11, 9, 7, 5, 3, 1, 0, 2,
  110040. 4, 6, 8, 10, 12,
  110041. };
  110042. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110043. _vq_quantthresh__16c1_s_p8_0,
  110044. _vq_quantmap__16c1_s_p8_0,
  110045. 13,
  110046. 13
  110047. };
  110048. static static_codebook _16c1_s_p8_0 = {
  110049. 2, 169,
  110050. _vq_lengthlist__16c1_s_p8_0,
  110051. 1, -526516224, 1616117760, 4, 0,
  110052. _vq_quantlist__16c1_s_p8_0,
  110053. NULL,
  110054. &_vq_auxt__16c1_s_p8_0,
  110055. NULL,
  110056. 0
  110057. };
  110058. static long _vq_quantlist__16c1_s_p8_1[] = {
  110059. 2,
  110060. 1,
  110061. 3,
  110062. 0,
  110063. 4,
  110064. };
  110065. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110066. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110067. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110068. };
  110069. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110070. -1.5, -0.5, 0.5, 1.5,
  110071. };
  110072. static long _vq_quantmap__16c1_s_p8_1[] = {
  110073. 3, 1, 0, 2, 4,
  110074. };
  110075. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110076. _vq_quantthresh__16c1_s_p8_1,
  110077. _vq_quantmap__16c1_s_p8_1,
  110078. 5,
  110079. 5
  110080. };
  110081. static static_codebook _16c1_s_p8_1 = {
  110082. 2, 25,
  110083. _vq_lengthlist__16c1_s_p8_1,
  110084. 1, -533725184, 1611661312, 3, 0,
  110085. _vq_quantlist__16c1_s_p8_1,
  110086. NULL,
  110087. &_vq_auxt__16c1_s_p8_1,
  110088. NULL,
  110089. 0
  110090. };
  110091. static long _vq_quantlist__16c1_s_p9_0[] = {
  110092. 6,
  110093. 5,
  110094. 7,
  110095. 4,
  110096. 8,
  110097. 3,
  110098. 9,
  110099. 2,
  110100. 10,
  110101. 1,
  110102. 11,
  110103. 0,
  110104. 12,
  110105. };
  110106. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110107. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110108. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110109. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110110. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110111. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110112. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110113. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110114. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110115. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110116. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110117. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110118. };
  110119. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110120. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110121. 787.5, 1102.5, 1417.5, 1732.5,
  110122. };
  110123. static long _vq_quantmap__16c1_s_p9_0[] = {
  110124. 11, 9, 7, 5, 3, 1, 0, 2,
  110125. 4, 6, 8, 10, 12,
  110126. };
  110127. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110128. _vq_quantthresh__16c1_s_p9_0,
  110129. _vq_quantmap__16c1_s_p9_0,
  110130. 13,
  110131. 13
  110132. };
  110133. static static_codebook _16c1_s_p9_0 = {
  110134. 2, 169,
  110135. _vq_lengthlist__16c1_s_p9_0,
  110136. 1, -513964032, 1628680192, 4, 0,
  110137. _vq_quantlist__16c1_s_p9_0,
  110138. NULL,
  110139. &_vq_auxt__16c1_s_p9_0,
  110140. NULL,
  110141. 0
  110142. };
  110143. static long _vq_quantlist__16c1_s_p9_1[] = {
  110144. 7,
  110145. 6,
  110146. 8,
  110147. 5,
  110148. 9,
  110149. 4,
  110150. 10,
  110151. 3,
  110152. 11,
  110153. 2,
  110154. 12,
  110155. 1,
  110156. 13,
  110157. 0,
  110158. 14,
  110159. };
  110160. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110161. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110162. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110163. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110164. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110165. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110166. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110167. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110168. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110169. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110170. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110171. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110172. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110173. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110174. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110175. 13,
  110176. };
  110177. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110178. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110179. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110180. };
  110181. static long _vq_quantmap__16c1_s_p9_1[] = {
  110182. 13, 11, 9, 7, 5, 3, 1, 0,
  110183. 2, 4, 6, 8, 10, 12, 14,
  110184. };
  110185. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110186. _vq_quantthresh__16c1_s_p9_1,
  110187. _vq_quantmap__16c1_s_p9_1,
  110188. 15,
  110189. 15
  110190. };
  110191. static static_codebook _16c1_s_p9_1 = {
  110192. 2, 225,
  110193. _vq_lengthlist__16c1_s_p9_1,
  110194. 1, -520986624, 1620377600, 4, 0,
  110195. _vq_quantlist__16c1_s_p9_1,
  110196. NULL,
  110197. &_vq_auxt__16c1_s_p9_1,
  110198. NULL,
  110199. 0
  110200. };
  110201. static long _vq_quantlist__16c1_s_p9_2[] = {
  110202. 10,
  110203. 9,
  110204. 11,
  110205. 8,
  110206. 12,
  110207. 7,
  110208. 13,
  110209. 6,
  110210. 14,
  110211. 5,
  110212. 15,
  110213. 4,
  110214. 16,
  110215. 3,
  110216. 17,
  110217. 2,
  110218. 18,
  110219. 1,
  110220. 19,
  110221. 0,
  110222. 20,
  110223. };
  110224. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110225. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110226. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110227. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110228. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110229. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110230. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110231. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110232. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110233. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110234. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110235. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110236. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110237. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110238. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110239. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110240. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110241. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110242. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110243. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110244. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110245. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110246. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110247. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110248. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110249. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110250. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110251. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110252. 11,11,11,11,12,11,11,12,11,
  110253. };
  110254. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110255. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110256. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110257. 6.5, 7.5, 8.5, 9.5,
  110258. };
  110259. static long _vq_quantmap__16c1_s_p9_2[] = {
  110260. 19, 17, 15, 13, 11, 9, 7, 5,
  110261. 3, 1, 0, 2, 4, 6, 8, 10,
  110262. 12, 14, 16, 18, 20,
  110263. };
  110264. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110265. _vq_quantthresh__16c1_s_p9_2,
  110266. _vq_quantmap__16c1_s_p9_2,
  110267. 21,
  110268. 21
  110269. };
  110270. static static_codebook _16c1_s_p9_2 = {
  110271. 2, 441,
  110272. _vq_lengthlist__16c1_s_p9_2,
  110273. 1, -529268736, 1611661312, 5, 0,
  110274. _vq_quantlist__16c1_s_p9_2,
  110275. NULL,
  110276. &_vq_auxt__16c1_s_p9_2,
  110277. NULL,
  110278. 0
  110279. };
  110280. static long _huff_lengthlist__16c1_s_short[] = {
  110281. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110282. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110283. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110284. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110285. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110286. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110287. 9, 9,10,13,
  110288. };
  110289. static static_codebook _huff_book__16c1_s_short = {
  110290. 2, 100,
  110291. _huff_lengthlist__16c1_s_short,
  110292. 0, 0, 0, 0, 0,
  110293. NULL,
  110294. NULL,
  110295. NULL,
  110296. NULL,
  110297. 0
  110298. };
  110299. static long _huff_lengthlist__16c2_s_long[] = {
  110300. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110301. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110302. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110303. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110304. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110305. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110306. 14,14,16,18,
  110307. };
  110308. static static_codebook _huff_book__16c2_s_long = {
  110309. 2, 100,
  110310. _huff_lengthlist__16c2_s_long,
  110311. 0, 0, 0, 0, 0,
  110312. NULL,
  110313. NULL,
  110314. NULL,
  110315. NULL,
  110316. 0
  110317. };
  110318. static long _vq_quantlist__16c2_s_p1_0[] = {
  110319. 1,
  110320. 0,
  110321. 2,
  110322. };
  110323. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110324. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110325. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110329. 0,
  110330. };
  110331. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110332. -0.5, 0.5,
  110333. };
  110334. static long _vq_quantmap__16c2_s_p1_0[] = {
  110335. 1, 0, 2,
  110336. };
  110337. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110338. _vq_quantthresh__16c2_s_p1_0,
  110339. _vq_quantmap__16c2_s_p1_0,
  110340. 3,
  110341. 3
  110342. };
  110343. static static_codebook _16c2_s_p1_0 = {
  110344. 4, 81,
  110345. _vq_lengthlist__16c2_s_p1_0,
  110346. 1, -535822336, 1611661312, 2, 0,
  110347. _vq_quantlist__16c2_s_p1_0,
  110348. NULL,
  110349. &_vq_auxt__16c2_s_p1_0,
  110350. NULL,
  110351. 0
  110352. };
  110353. static long _vq_quantlist__16c2_s_p2_0[] = {
  110354. 2,
  110355. 1,
  110356. 3,
  110357. 0,
  110358. 4,
  110359. };
  110360. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110361. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110362. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110363. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110364. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110365. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110366. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110367. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110368. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110373. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110374. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110375. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110376. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110381. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110382. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110383. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110384. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110389. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110390. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110391. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110392. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110397. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110398. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110399. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110400. 13,
  110401. };
  110402. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110403. -1.5, -0.5, 0.5, 1.5,
  110404. };
  110405. static long _vq_quantmap__16c2_s_p2_0[] = {
  110406. 3, 1, 0, 2, 4,
  110407. };
  110408. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110409. _vq_quantthresh__16c2_s_p2_0,
  110410. _vq_quantmap__16c2_s_p2_0,
  110411. 5,
  110412. 5
  110413. };
  110414. static static_codebook _16c2_s_p2_0 = {
  110415. 4, 625,
  110416. _vq_lengthlist__16c2_s_p2_0,
  110417. 1, -533725184, 1611661312, 3, 0,
  110418. _vq_quantlist__16c2_s_p2_0,
  110419. NULL,
  110420. &_vq_auxt__16c2_s_p2_0,
  110421. NULL,
  110422. 0
  110423. };
  110424. static long _vq_quantlist__16c2_s_p3_0[] = {
  110425. 4,
  110426. 3,
  110427. 5,
  110428. 2,
  110429. 6,
  110430. 1,
  110431. 7,
  110432. 0,
  110433. 8,
  110434. };
  110435. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110436. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110437. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110438. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110439. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110441. 0,
  110442. };
  110443. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110444. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110445. };
  110446. static long _vq_quantmap__16c2_s_p3_0[] = {
  110447. 7, 5, 3, 1, 0, 2, 4, 6,
  110448. 8,
  110449. };
  110450. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110451. _vq_quantthresh__16c2_s_p3_0,
  110452. _vq_quantmap__16c2_s_p3_0,
  110453. 9,
  110454. 9
  110455. };
  110456. static static_codebook _16c2_s_p3_0 = {
  110457. 2, 81,
  110458. _vq_lengthlist__16c2_s_p3_0,
  110459. 1, -531628032, 1611661312, 4, 0,
  110460. _vq_quantlist__16c2_s_p3_0,
  110461. NULL,
  110462. &_vq_auxt__16c2_s_p3_0,
  110463. NULL,
  110464. 0
  110465. };
  110466. static long _vq_quantlist__16c2_s_p4_0[] = {
  110467. 8,
  110468. 7,
  110469. 9,
  110470. 6,
  110471. 10,
  110472. 5,
  110473. 11,
  110474. 4,
  110475. 12,
  110476. 3,
  110477. 13,
  110478. 2,
  110479. 14,
  110480. 1,
  110481. 15,
  110482. 0,
  110483. 16,
  110484. };
  110485. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110486. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110487. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110488. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110489. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110490. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110491. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110492. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110493. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110494. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110495. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110504. 0,
  110505. };
  110506. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110507. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110508. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110509. };
  110510. static long _vq_quantmap__16c2_s_p4_0[] = {
  110511. 15, 13, 11, 9, 7, 5, 3, 1,
  110512. 0, 2, 4, 6, 8, 10, 12, 14,
  110513. 16,
  110514. };
  110515. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  110516. _vq_quantthresh__16c2_s_p4_0,
  110517. _vq_quantmap__16c2_s_p4_0,
  110518. 17,
  110519. 17
  110520. };
  110521. static static_codebook _16c2_s_p4_0 = {
  110522. 2, 289,
  110523. _vq_lengthlist__16c2_s_p4_0,
  110524. 1, -529530880, 1611661312, 5, 0,
  110525. _vq_quantlist__16c2_s_p4_0,
  110526. NULL,
  110527. &_vq_auxt__16c2_s_p4_0,
  110528. NULL,
  110529. 0
  110530. };
  110531. static long _vq_quantlist__16c2_s_p5_0[] = {
  110532. 1,
  110533. 0,
  110534. 2,
  110535. };
  110536. static long _vq_lengthlist__16c2_s_p5_0[] = {
  110537. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  110538. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  110539. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  110540. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  110541. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  110542. 12,
  110543. };
  110544. static float _vq_quantthresh__16c2_s_p5_0[] = {
  110545. -5.5, 5.5,
  110546. };
  110547. static long _vq_quantmap__16c2_s_p5_0[] = {
  110548. 1, 0, 2,
  110549. };
  110550. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  110551. _vq_quantthresh__16c2_s_p5_0,
  110552. _vq_quantmap__16c2_s_p5_0,
  110553. 3,
  110554. 3
  110555. };
  110556. static static_codebook _16c2_s_p5_0 = {
  110557. 4, 81,
  110558. _vq_lengthlist__16c2_s_p5_0,
  110559. 1, -529137664, 1618345984, 2, 0,
  110560. _vq_quantlist__16c2_s_p5_0,
  110561. NULL,
  110562. &_vq_auxt__16c2_s_p5_0,
  110563. NULL,
  110564. 0
  110565. };
  110566. static long _vq_quantlist__16c2_s_p5_1[] = {
  110567. 5,
  110568. 4,
  110569. 6,
  110570. 3,
  110571. 7,
  110572. 2,
  110573. 8,
  110574. 1,
  110575. 9,
  110576. 0,
  110577. 10,
  110578. };
  110579. static long _vq_lengthlist__16c2_s_p5_1[] = {
  110580. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  110581. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  110582. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  110583. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  110584. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  110585. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  110586. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  110587. 11,11,11, 7, 7, 8, 8, 8, 8,
  110588. };
  110589. static float _vq_quantthresh__16c2_s_p5_1[] = {
  110590. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110591. 3.5, 4.5,
  110592. };
  110593. static long _vq_quantmap__16c2_s_p5_1[] = {
  110594. 9, 7, 5, 3, 1, 0, 2, 4,
  110595. 6, 8, 10,
  110596. };
  110597. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  110598. _vq_quantthresh__16c2_s_p5_1,
  110599. _vq_quantmap__16c2_s_p5_1,
  110600. 11,
  110601. 11
  110602. };
  110603. static static_codebook _16c2_s_p5_1 = {
  110604. 2, 121,
  110605. _vq_lengthlist__16c2_s_p5_1,
  110606. 1, -531365888, 1611661312, 4, 0,
  110607. _vq_quantlist__16c2_s_p5_1,
  110608. NULL,
  110609. &_vq_auxt__16c2_s_p5_1,
  110610. NULL,
  110611. 0
  110612. };
  110613. static long _vq_quantlist__16c2_s_p6_0[] = {
  110614. 6,
  110615. 5,
  110616. 7,
  110617. 4,
  110618. 8,
  110619. 3,
  110620. 9,
  110621. 2,
  110622. 10,
  110623. 1,
  110624. 11,
  110625. 0,
  110626. 12,
  110627. };
  110628. static long _vq_lengthlist__16c2_s_p6_0[] = {
  110629. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110630. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  110631. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  110632. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  110633. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  110634. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  110635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110639. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110640. };
  110641. static float _vq_quantthresh__16c2_s_p6_0[] = {
  110642. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110643. 12.5, 17.5, 22.5, 27.5,
  110644. };
  110645. static long _vq_quantmap__16c2_s_p6_0[] = {
  110646. 11, 9, 7, 5, 3, 1, 0, 2,
  110647. 4, 6, 8, 10, 12,
  110648. };
  110649. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  110650. _vq_quantthresh__16c2_s_p6_0,
  110651. _vq_quantmap__16c2_s_p6_0,
  110652. 13,
  110653. 13
  110654. };
  110655. static static_codebook _16c2_s_p6_0 = {
  110656. 2, 169,
  110657. _vq_lengthlist__16c2_s_p6_0,
  110658. 1, -526516224, 1616117760, 4, 0,
  110659. _vq_quantlist__16c2_s_p6_0,
  110660. NULL,
  110661. &_vq_auxt__16c2_s_p6_0,
  110662. NULL,
  110663. 0
  110664. };
  110665. static long _vq_quantlist__16c2_s_p6_1[] = {
  110666. 2,
  110667. 1,
  110668. 3,
  110669. 0,
  110670. 4,
  110671. };
  110672. static long _vq_lengthlist__16c2_s_p6_1[] = {
  110673. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110674. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110675. };
  110676. static float _vq_quantthresh__16c2_s_p6_1[] = {
  110677. -1.5, -0.5, 0.5, 1.5,
  110678. };
  110679. static long _vq_quantmap__16c2_s_p6_1[] = {
  110680. 3, 1, 0, 2, 4,
  110681. };
  110682. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  110683. _vq_quantthresh__16c2_s_p6_1,
  110684. _vq_quantmap__16c2_s_p6_1,
  110685. 5,
  110686. 5
  110687. };
  110688. static static_codebook _16c2_s_p6_1 = {
  110689. 2, 25,
  110690. _vq_lengthlist__16c2_s_p6_1,
  110691. 1, -533725184, 1611661312, 3, 0,
  110692. _vq_quantlist__16c2_s_p6_1,
  110693. NULL,
  110694. &_vq_auxt__16c2_s_p6_1,
  110695. NULL,
  110696. 0
  110697. };
  110698. static long _vq_quantlist__16c2_s_p7_0[] = {
  110699. 6,
  110700. 5,
  110701. 7,
  110702. 4,
  110703. 8,
  110704. 3,
  110705. 9,
  110706. 2,
  110707. 10,
  110708. 1,
  110709. 11,
  110710. 0,
  110711. 12,
  110712. };
  110713. static long _vq_lengthlist__16c2_s_p7_0[] = {
  110714. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  110715. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  110716. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  110717. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  110718. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  110719. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  110720. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  110721. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  110722. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  110723. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  110724. 18,13,14,13,13,14,13,15,14,
  110725. };
  110726. static float _vq_quantthresh__16c2_s_p7_0[] = {
  110727. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  110728. 27.5, 38.5, 49.5, 60.5,
  110729. };
  110730. static long _vq_quantmap__16c2_s_p7_0[] = {
  110731. 11, 9, 7, 5, 3, 1, 0, 2,
  110732. 4, 6, 8, 10, 12,
  110733. };
  110734. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  110735. _vq_quantthresh__16c2_s_p7_0,
  110736. _vq_quantmap__16c2_s_p7_0,
  110737. 13,
  110738. 13
  110739. };
  110740. static static_codebook _16c2_s_p7_0 = {
  110741. 2, 169,
  110742. _vq_lengthlist__16c2_s_p7_0,
  110743. 1, -523206656, 1618345984, 4, 0,
  110744. _vq_quantlist__16c2_s_p7_0,
  110745. NULL,
  110746. &_vq_auxt__16c2_s_p7_0,
  110747. NULL,
  110748. 0
  110749. };
  110750. static long _vq_quantlist__16c2_s_p7_1[] = {
  110751. 5,
  110752. 4,
  110753. 6,
  110754. 3,
  110755. 7,
  110756. 2,
  110757. 8,
  110758. 1,
  110759. 9,
  110760. 0,
  110761. 10,
  110762. };
  110763. static long _vq_lengthlist__16c2_s_p7_1[] = {
  110764. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  110765. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  110766. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  110767. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110768. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  110769. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  110770. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  110771. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  110772. };
  110773. static float _vq_quantthresh__16c2_s_p7_1[] = {
  110774. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110775. 3.5, 4.5,
  110776. };
  110777. static long _vq_quantmap__16c2_s_p7_1[] = {
  110778. 9, 7, 5, 3, 1, 0, 2, 4,
  110779. 6, 8, 10,
  110780. };
  110781. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  110782. _vq_quantthresh__16c2_s_p7_1,
  110783. _vq_quantmap__16c2_s_p7_1,
  110784. 11,
  110785. 11
  110786. };
  110787. static static_codebook _16c2_s_p7_1 = {
  110788. 2, 121,
  110789. _vq_lengthlist__16c2_s_p7_1,
  110790. 1, -531365888, 1611661312, 4, 0,
  110791. _vq_quantlist__16c2_s_p7_1,
  110792. NULL,
  110793. &_vq_auxt__16c2_s_p7_1,
  110794. NULL,
  110795. 0
  110796. };
  110797. static long _vq_quantlist__16c2_s_p8_0[] = {
  110798. 7,
  110799. 6,
  110800. 8,
  110801. 5,
  110802. 9,
  110803. 4,
  110804. 10,
  110805. 3,
  110806. 11,
  110807. 2,
  110808. 12,
  110809. 1,
  110810. 13,
  110811. 0,
  110812. 14,
  110813. };
  110814. static long _vq_lengthlist__16c2_s_p8_0[] = {
  110815. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  110816. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  110817. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  110818. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  110819. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  110820. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  110821. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  110822. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  110823. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  110824. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  110825. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  110826. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  110827. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  110828. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  110829. 13,
  110830. };
  110831. static float _vq_quantthresh__16c2_s_p8_0[] = {
  110832. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110833. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110834. };
  110835. static long _vq_quantmap__16c2_s_p8_0[] = {
  110836. 13, 11, 9, 7, 5, 3, 1, 0,
  110837. 2, 4, 6, 8, 10, 12, 14,
  110838. };
  110839. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  110840. _vq_quantthresh__16c2_s_p8_0,
  110841. _vq_quantmap__16c2_s_p8_0,
  110842. 15,
  110843. 15
  110844. };
  110845. static static_codebook _16c2_s_p8_0 = {
  110846. 2, 225,
  110847. _vq_lengthlist__16c2_s_p8_0,
  110848. 1, -520986624, 1620377600, 4, 0,
  110849. _vq_quantlist__16c2_s_p8_0,
  110850. NULL,
  110851. &_vq_auxt__16c2_s_p8_0,
  110852. NULL,
  110853. 0
  110854. };
  110855. static long _vq_quantlist__16c2_s_p8_1[] = {
  110856. 10,
  110857. 9,
  110858. 11,
  110859. 8,
  110860. 12,
  110861. 7,
  110862. 13,
  110863. 6,
  110864. 14,
  110865. 5,
  110866. 15,
  110867. 4,
  110868. 16,
  110869. 3,
  110870. 17,
  110871. 2,
  110872. 18,
  110873. 1,
  110874. 19,
  110875. 0,
  110876. 20,
  110877. };
  110878. static long _vq_lengthlist__16c2_s_p8_1[] = {
  110879. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  110880. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  110881. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  110882. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  110883. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  110884. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  110885. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  110886. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  110887. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  110888. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  110889. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  110890. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  110891. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  110892. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  110893. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  110894. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  110895. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  110896. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  110897. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  110898. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  110899. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  110900. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  110901. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  110902. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  110903. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  110904. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  110905. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  110906. 10,11,10,10,10,10,10,10,10,
  110907. };
  110908. static float _vq_quantthresh__16c2_s_p8_1[] = {
  110909. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110910. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110911. 6.5, 7.5, 8.5, 9.5,
  110912. };
  110913. static long _vq_quantmap__16c2_s_p8_1[] = {
  110914. 19, 17, 15, 13, 11, 9, 7, 5,
  110915. 3, 1, 0, 2, 4, 6, 8, 10,
  110916. 12, 14, 16, 18, 20,
  110917. };
  110918. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  110919. _vq_quantthresh__16c2_s_p8_1,
  110920. _vq_quantmap__16c2_s_p8_1,
  110921. 21,
  110922. 21
  110923. };
  110924. static static_codebook _16c2_s_p8_1 = {
  110925. 2, 441,
  110926. _vq_lengthlist__16c2_s_p8_1,
  110927. 1, -529268736, 1611661312, 5, 0,
  110928. _vq_quantlist__16c2_s_p8_1,
  110929. NULL,
  110930. &_vq_auxt__16c2_s_p8_1,
  110931. NULL,
  110932. 0
  110933. };
  110934. static long _vq_quantlist__16c2_s_p9_0[] = {
  110935. 6,
  110936. 5,
  110937. 7,
  110938. 4,
  110939. 8,
  110940. 3,
  110941. 9,
  110942. 2,
  110943. 10,
  110944. 1,
  110945. 11,
  110946. 0,
  110947. 12,
  110948. };
  110949. static long _vq_lengthlist__16c2_s_p9_0[] = {
  110950. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110951. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110952. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110953. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110954. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110955. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110956. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110957. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110958. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110959. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110960. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110961. };
  110962. static float _vq_quantthresh__16c2_s_p9_0[] = {
  110963. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  110964. 2327.5, 3258.5, 4189.5, 5120.5,
  110965. };
  110966. static long _vq_quantmap__16c2_s_p9_0[] = {
  110967. 11, 9, 7, 5, 3, 1, 0, 2,
  110968. 4, 6, 8, 10, 12,
  110969. };
  110970. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  110971. _vq_quantthresh__16c2_s_p9_0,
  110972. _vq_quantmap__16c2_s_p9_0,
  110973. 13,
  110974. 13
  110975. };
  110976. static static_codebook _16c2_s_p9_0 = {
  110977. 2, 169,
  110978. _vq_lengthlist__16c2_s_p9_0,
  110979. 1, -510275072, 1631393792, 4, 0,
  110980. _vq_quantlist__16c2_s_p9_0,
  110981. NULL,
  110982. &_vq_auxt__16c2_s_p9_0,
  110983. NULL,
  110984. 0
  110985. };
  110986. static long _vq_quantlist__16c2_s_p9_1[] = {
  110987. 8,
  110988. 7,
  110989. 9,
  110990. 6,
  110991. 10,
  110992. 5,
  110993. 11,
  110994. 4,
  110995. 12,
  110996. 3,
  110997. 13,
  110998. 2,
  110999. 14,
  111000. 1,
  111001. 15,
  111002. 0,
  111003. 16,
  111004. };
  111005. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111006. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111007. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111008. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111009. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111010. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111011. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111012. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111013. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111014. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111015. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111016. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111017. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111018. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111019. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111020. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111021. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111022. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111023. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111024. 10,
  111025. };
  111026. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111027. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111028. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111029. };
  111030. static long _vq_quantmap__16c2_s_p9_1[] = {
  111031. 15, 13, 11, 9, 7, 5, 3, 1,
  111032. 0, 2, 4, 6, 8, 10, 12, 14,
  111033. 16,
  111034. };
  111035. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111036. _vq_quantthresh__16c2_s_p9_1,
  111037. _vq_quantmap__16c2_s_p9_1,
  111038. 17,
  111039. 17
  111040. };
  111041. static static_codebook _16c2_s_p9_1 = {
  111042. 2, 289,
  111043. _vq_lengthlist__16c2_s_p9_1,
  111044. 1, -518488064, 1622704128, 5, 0,
  111045. _vq_quantlist__16c2_s_p9_1,
  111046. NULL,
  111047. &_vq_auxt__16c2_s_p9_1,
  111048. NULL,
  111049. 0
  111050. };
  111051. static long _vq_quantlist__16c2_s_p9_2[] = {
  111052. 13,
  111053. 12,
  111054. 14,
  111055. 11,
  111056. 15,
  111057. 10,
  111058. 16,
  111059. 9,
  111060. 17,
  111061. 8,
  111062. 18,
  111063. 7,
  111064. 19,
  111065. 6,
  111066. 20,
  111067. 5,
  111068. 21,
  111069. 4,
  111070. 22,
  111071. 3,
  111072. 23,
  111073. 2,
  111074. 24,
  111075. 1,
  111076. 25,
  111077. 0,
  111078. 26,
  111079. };
  111080. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111081. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111082. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111083. };
  111084. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111085. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111086. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111087. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111088. 11.5, 12.5,
  111089. };
  111090. static long _vq_quantmap__16c2_s_p9_2[] = {
  111091. 25, 23, 21, 19, 17, 15, 13, 11,
  111092. 9, 7, 5, 3, 1, 0, 2, 4,
  111093. 6, 8, 10, 12, 14, 16, 18, 20,
  111094. 22, 24, 26,
  111095. };
  111096. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111097. _vq_quantthresh__16c2_s_p9_2,
  111098. _vq_quantmap__16c2_s_p9_2,
  111099. 27,
  111100. 27
  111101. };
  111102. static static_codebook _16c2_s_p9_2 = {
  111103. 1, 27,
  111104. _vq_lengthlist__16c2_s_p9_2,
  111105. 1, -528875520, 1611661312, 5, 0,
  111106. _vq_quantlist__16c2_s_p9_2,
  111107. NULL,
  111108. &_vq_auxt__16c2_s_p9_2,
  111109. NULL,
  111110. 0
  111111. };
  111112. static long _huff_lengthlist__16c2_s_short[] = {
  111113. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111114. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111115. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111116. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111117. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111118. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111119. 15,12,14,14,
  111120. };
  111121. static static_codebook _huff_book__16c2_s_short = {
  111122. 2, 100,
  111123. _huff_lengthlist__16c2_s_short,
  111124. 0, 0, 0, 0, 0,
  111125. NULL,
  111126. NULL,
  111127. NULL,
  111128. NULL,
  111129. 0
  111130. };
  111131. static long _vq_quantlist__8c0_s_p1_0[] = {
  111132. 1,
  111133. 0,
  111134. 2,
  111135. };
  111136. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111137. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111138. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111143. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111148. 0, 0, 0, 0, 7, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  111152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  111157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  111162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 8, 0, 0, 0, 0,
  111183. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  111188. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 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, 7, 9,10, 0, 0,
  111193. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111198. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111203. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111229. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111234. 0, 0, 0, 0, 0, 9,10,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111239. 0, 0, 0, 0, 0, 0, 8,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111547. 0,
  111548. };
  111549. static float _vq_quantthresh__8c0_s_p1_0[] = {
  111550. -0.5, 0.5,
  111551. };
  111552. static long _vq_quantmap__8c0_s_p1_0[] = {
  111553. 1, 0, 2,
  111554. };
  111555. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  111556. _vq_quantthresh__8c0_s_p1_0,
  111557. _vq_quantmap__8c0_s_p1_0,
  111558. 3,
  111559. 3
  111560. };
  111561. static static_codebook _8c0_s_p1_0 = {
  111562. 8, 6561,
  111563. _vq_lengthlist__8c0_s_p1_0,
  111564. 1, -535822336, 1611661312, 2, 0,
  111565. _vq_quantlist__8c0_s_p1_0,
  111566. NULL,
  111567. &_vq_auxt__8c0_s_p1_0,
  111568. NULL,
  111569. 0
  111570. };
  111571. static long _vq_quantlist__8c0_s_p2_0[] = {
  111572. 2,
  111573. 1,
  111574. 3,
  111575. 0,
  111576. 4,
  111577. };
  111578. static long _vq_lengthlist__8c0_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111618. 0,
  111619. };
  111620. static float _vq_quantthresh__8c0_s_p2_0[] = {
  111621. -1.5, -0.5, 0.5, 1.5,
  111622. };
  111623. static long _vq_quantmap__8c0_s_p2_0[] = {
  111624. 3, 1, 0, 2, 4,
  111625. };
  111626. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  111627. _vq_quantthresh__8c0_s_p2_0,
  111628. _vq_quantmap__8c0_s_p2_0,
  111629. 5,
  111630. 5
  111631. };
  111632. static static_codebook _8c0_s_p2_0 = {
  111633. 4, 625,
  111634. _vq_lengthlist__8c0_s_p2_0,
  111635. 1, -533725184, 1611661312, 3, 0,
  111636. _vq_quantlist__8c0_s_p2_0,
  111637. NULL,
  111638. &_vq_auxt__8c0_s_p2_0,
  111639. NULL,
  111640. 0
  111641. };
  111642. static long _vq_quantlist__8c0_s_p3_0[] = {
  111643. 2,
  111644. 1,
  111645. 3,
  111646. 0,
  111647. 4,
  111648. };
  111649. static long _vq_lengthlist__8c0_s_p3_0[] = {
  111650. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  111652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111653. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  111655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111656. 0, 0, 0, 0, 6, 7, 7, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111689. 0,
  111690. };
  111691. static float _vq_quantthresh__8c0_s_p3_0[] = {
  111692. -1.5, -0.5, 0.5, 1.5,
  111693. };
  111694. static long _vq_quantmap__8c0_s_p3_0[] = {
  111695. 3, 1, 0, 2, 4,
  111696. };
  111697. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  111698. _vq_quantthresh__8c0_s_p3_0,
  111699. _vq_quantmap__8c0_s_p3_0,
  111700. 5,
  111701. 5
  111702. };
  111703. static static_codebook _8c0_s_p3_0 = {
  111704. 4, 625,
  111705. _vq_lengthlist__8c0_s_p3_0,
  111706. 1, -533725184, 1611661312, 3, 0,
  111707. _vq_quantlist__8c0_s_p3_0,
  111708. NULL,
  111709. &_vq_auxt__8c0_s_p3_0,
  111710. NULL,
  111711. 0
  111712. };
  111713. static long _vq_quantlist__8c0_s_p4_0[] = {
  111714. 4,
  111715. 3,
  111716. 5,
  111717. 2,
  111718. 6,
  111719. 1,
  111720. 7,
  111721. 0,
  111722. 8,
  111723. };
  111724. static long _vq_lengthlist__8c0_s_p4_0[] = {
  111725. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  111726. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  111727. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  111728. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  111729. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111730. 0,
  111731. };
  111732. static float _vq_quantthresh__8c0_s_p4_0[] = {
  111733. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111734. };
  111735. static long _vq_quantmap__8c0_s_p4_0[] = {
  111736. 7, 5, 3, 1, 0, 2, 4, 6,
  111737. 8,
  111738. };
  111739. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  111740. _vq_quantthresh__8c0_s_p4_0,
  111741. _vq_quantmap__8c0_s_p4_0,
  111742. 9,
  111743. 9
  111744. };
  111745. static static_codebook _8c0_s_p4_0 = {
  111746. 2, 81,
  111747. _vq_lengthlist__8c0_s_p4_0,
  111748. 1, -531628032, 1611661312, 4, 0,
  111749. _vq_quantlist__8c0_s_p4_0,
  111750. NULL,
  111751. &_vq_auxt__8c0_s_p4_0,
  111752. NULL,
  111753. 0
  111754. };
  111755. static long _vq_quantlist__8c0_s_p5_0[] = {
  111756. 4,
  111757. 3,
  111758. 5,
  111759. 2,
  111760. 6,
  111761. 1,
  111762. 7,
  111763. 0,
  111764. 8,
  111765. };
  111766. static long _vq_lengthlist__8c0_s_p5_0[] = {
  111767. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  111768. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  111769. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  111770. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  111771. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  111772. 10,
  111773. };
  111774. static float _vq_quantthresh__8c0_s_p5_0[] = {
  111775. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  111776. };
  111777. static long _vq_quantmap__8c0_s_p5_0[] = {
  111778. 7, 5, 3, 1, 0, 2, 4, 6,
  111779. 8,
  111780. };
  111781. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  111782. _vq_quantthresh__8c0_s_p5_0,
  111783. _vq_quantmap__8c0_s_p5_0,
  111784. 9,
  111785. 9
  111786. };
  111787. static static_codebook _8c0_s_p5_0 = {
  111788. 2, 81,
  111789. _vq_lengthlist__8c0_s_p5_0,
  111790. 1, -531628032, 1611661312, 4, 0,
  111791. _vq_quantlist__8c0_s_p5_0,
  111792. NULL,
  111793. &_vq_auxt__8c0_s_p5_0,
  111794. NULL,
  111795. 0
  111796. };
  111797. static long _vq_quantlist__8c0_s_p6_0[] = {
  111798. 8,
  111799. 7,
  111800. 9,
  111801. 6,
  111802. 10,
  111803. 5,
  111804. 11,
  111805. 4,
  111806. 12,
  111807. 3,
  111808. 13,
  111809. 2,
  111810. 14,
  111811. 1,
  111812. 15,
  111813. 0,
  111814. 16,
  111815. };
  111816. static long _vq_lengthlist__8c0_s_p6_0[] = {
  111817. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  111818. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  111819. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  111820. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  111821. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  111822. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  111823. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  111824. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  111825. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  111826. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  111827. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  111828. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  111829. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  111830. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  111831. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  111832. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  111833. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  111834. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  111835. 14,
  111836. };
  111837. static float _vq_quantthresh__8c0_s_p6_0[] = {
  111838. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  111839. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111840. };
  111841. static long _vq_quantmap__8c0_s_p6_0[] = {
  111842. 15, 13, 11, 9, 7, 5, 3, 1,
  111843. 0, 2, 4, 6, 8, 10, 12, 14,
  111844. 16,
  111845. };
  111846. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  111847. _vq_quantthresh__8c0_s_p6_0,
  111848. _vq_quantmap__8c0_s_p6_0,
  111849. 17,
  111850. 17
  111851. };
  111852. static static_codebook _8c0_s_p6_0 = {
  111853. 2, 289,
  111854. _vq_lengthlist__8c0_s_p6_0,
  111855. 1, -529530880, 1611661312, 5, 0,
  111856. _vq_quantlist__8c0_s_p6_0,
  111857. NULL,
  111858. &_vq_auxt__8c0_s_p6_0,
  111859. NULL,
  111860. 0
  111861. };
  111862. static long _vq_quantlist__8c0_s_p7_0[] = {
  111863. 1,
  111864. 0,
  111865. 2,
  111866. };
  111867. static long _vq_lengthlist__8c0_s_p7_0[] = {
  111868. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  111869. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  111870. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  111871. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  111872. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  111873. 10,
  111874. };
  111875. static float _vq_quantthresh__8c0_s_p7_0[] = {
  111876. -5.5, 5.5,
  111877. };
  111878. static long _vq_quantmap__8c0_s_p7_0[] = {
  111879. 1, 0, 2,
  111880. };
  111881. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  111882. _vq_quantthresh__8c0_s_p7_0,
  111883. _vq_quantmap__8c0_s_p7_0,
  111884. 3,
  111885. 3
  111886. };
  111887. static static_codebook _8c0_s_p7_0 = {
  111888. 4, 81,
  111889. _vq_lengthlist__8c0_s_p7_0,
  111890. 1, -529137664, 1618345984, 2, 0,
  111891. _vq_quantlist__8c0_s_p7_0,
  111892. NULL,
  111893. &_vq_auxt__8c0_s_p7_0,
  111894. NULL,
  111895. 0
  111896. };
  111897. static long _vq_quantlist__8c0_s_p7_1[] = {
  111898. 5,
  111899. 4,
  111900. 6,
  111901. 3,
  111902. 7,
  111903. 2,
  111904. 8,
  111905. 1,
  111906. 9,
  111907. 0,
  111908. 10,
  111909. };
  111910. static long _vq_lengthlist__8c0_s_p7_1[] = {
  111911. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  111912. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  111913. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  111914. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  111915. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  111916. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  111917. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  111918. 10,10,10, 9, 9, 9,10,10,10,
  111919. };
  111920. static float _vq_quantthresh__8c0_s_p7_1[] = {
  111921. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111922. 3.5, 4.5,
  111923. };
  111924. static long _vq_quantmap__8c0_s_p7_1[] = {
  111925. 9, 7, 5, 3, 1, 0, 2, 4,
  111926. 6, 8, 10,
  111927. };
  111928. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  111929. _vq_quantthresh__8c0_s_p7_1,
  111930. _vq_quantmap__8c0_s_p7_1,
  111931. 11,
  111932. 11
  111933. };
  111934. static static_codebook _8c0_s_p7_1 = {
  111935. 2, 121,
  111936. _vq_lengthlist__8c0_s_p7_1,
  111937. 1, -531365888, 1611661312, 4, 0,
  111938. _vq_quantlist__8c0_s_p7_1,
  111939. NULL,
  111940. &_vq_auxt__8c0_s_p7_1,
  111941. NULL,
  111942. 0
  111943. };
  111944. static long _vq_quantlist__8c0_s_p8_0[] = {
  111945. 6,
  111946. 5,
  111947. 7,
  111948. 4,
  111949. 8,
  111950. 3,
  111951. 9,
  111952. 2,
  111953. 10,
  111954. 1,
  111955. 11,
  111956. 0,
  111957. 12,
  111958. };
  111959. static long _vq_lengthlist__8c0_s_p8_0[] = {
  111960. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  111961. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  111962. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  111963. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  111964. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  111965. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  111966. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  111967. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  111968. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  111969. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  111970. 0, 0,13,13,11,13,13,11,12,
  111971. };
  111972. static float _vq_quantthresh__8c0_s_p8_0[] = {
  111973. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111974. 12.5, 17.5, 22.5, 27.5,
  111975. };
  111976. static long _vq_quantmap__8c0_s_p8_0[] = {
  111977. 11, 9, 7, 5, 3, 1, 0, 2,
  111978. 4, 6, 8, 10, 12,
  111979. };
  111980. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  111981. _vq_quantthresh__8c0_s_p8_0,
  111982. _vq_quantmap__8c0_s_p8_0,
  111983. 13,
  111984. 13
  111985. };
  111986. static static_codebook _8c0_s_p8_0 = {
  111987. 2, 169,
  111988. _vq_lengthlist__8c0_s_p8_0,
  111989. 1, -526516224, 1616117760, 4, 0,
  111990. _vq_quantlist__8c0_s_p8_0,
  111991. NULL,
  111992. &_vq_auxt__8c0_s_p8_0,
  111993. NULL,
  111994. 0
  111995. };
  111996. static long _vq_quantlist__8c0_s_p8_1[] = {
  111997. 2,
  111998. 1,
  111999. 3,
  112000. 0,
  112001. 4,
  112002. };
  112003. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112004. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112005. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112006. };
  112007. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112008. -1.5, -0.5, 0.5, 1.5,
  112009. };
  112010. static long _vq_quantmap__8c0_s_p8_1[] = {
  112011. 3, 1, 0, 2, 4,
  112012. };
  112013. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112014. _vq_quantthresh__8c0_s_p8_1,
  112015. _vq_quantmap__8c0_s_p8_1,
  112016. 5,
  112017. 5
  112018. };
  112019. static static_codebook _8c0_s_p8_1 = {
  112020. 2, 25,
  112021. _vq_lengthlist__8c0_s_p8_1,
  112022. 1, -533725184, 1611661312, 3, 0,
  112023. _vq_quantlist__8c0_s_p8_1,
  112024. NULL,
  112025. &_vq_auxt__8c0_s_p8_1,
  112026. NULL,
  112027. 0
  112028. };
  112029. static long _vq_quantlist__8c0_s_p9_0[] = {
  112030. 1,
  112031. 0,
  112032. 2,
  112033. };
  112034. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112035. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112036. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112037. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112038. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112039. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112040. 7,
  112041. };
  112042. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112043. -157.5, 157.5,
  112044. };
  112045. static long _vq_quantmap__8c0_s_p9_0[] = {
  112046. 1, 0, 2,
  112047. };
  112048. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112049. _vq_quantthresh__8c0_s_p9_0,
  112050. _vq_quantmap__8c0_s_p9_0,
  112051. 3,
  112052. 3
  112053. };
  112054. static static_codebook _8c0_s_p9_0 = {
  112055. 4, 81,
  112056. _vq_lengthlist__8c0_s_p9_0,
  112057. 1, -518803456, 1628680192, 2, 0,
  112058. _vq_quantlist__8c0_s_p9_0,
  112059. NULL,
  112060. &_vq_auxt__8c0_s_p9_0,
  112061. NULL,
  112062. 0
  112063. };
  112064. static long _vq_quantlist__8c0_s_p9_1[] = {
  112065. 7,
  112066. 6,
  112067. 8,
  112068. 5,
  112069. 9,
  112070. 4,
  112071. 10,
  112072. 3,
  112073. 11,
  112074. 2,
  112075. 12,
  112076. 1,
  112077. 13,
  112078. 0,
  112079. 14,
  112080. };
  112081. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112082. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112083. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112084. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112085. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112086. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112087. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112088. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112089. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112090. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112091. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112092. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112093. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112094. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112095. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112096. 11,
  112097. };
  112098. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112099. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112100. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112101. };
  112102. static long _vq_quantmap__8c0_s_p9_1[] = {
  112103. 13, 11, 9, 7, 5, 3, 1, 0,
  112104. 2, 4, 6, 8, 10, 12, 14,
  112105. };
  112106. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112107. _vq_quantthresh__8c0_s_p9_1,
  112108. _vq_quantmap__8c0_s_p9_1,
  112109. 15,
  112110. 15
  112111. };
  112112. static static_codebook _8c0_s_p9_1 = {
  112113. 2, 225,
  112114. _vq_lengthlist__8c0_s_p9_1,
  112115. 1, -520986624, 1620377600, 4, 0,
  112116. _vq_quantlist__8c0_s_p9_1,
  112117. NULL,
  112118. &_vq_auxt__8c0_s_p9_1,
  112119. NULL,
  112120. 0
  112121. };
  112122. static long _vq_quantlist__8c0_s_p9_2[] = {
  112123. 10,
  112124. 9,
  112125. 11,
  112126. 8,
  112127. 12,
  112128. 7,
  112129. 13,
  112130. 6,
  112131. 14,
  112132. 5,
  112133. 15,
  112134. 4,
  112135. 16,
  112136. 3,
  112137. 17,
  112138. 2,
  112139. 18,
  112140. 1,
  112141. 19,
  112142. 0,
  112143. 20,
  112144. };
  112145. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112146. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112147. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112148. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112149. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112150. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112151. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112152. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112153. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112154. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112155. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112156. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112157. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112158. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112159. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112160. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112161. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112162. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112163. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112164. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112165. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112166. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112167. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112168. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112169. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112170. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112171. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112172. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112173. 10,11, 9,11,10, 9,10, 9,10,
  112174. };
  112175. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112176. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112177. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112178. 6.5, 7.5, 8.5, 9.5,
  112179. };
  112180. static long _vq_quantmap__8c0_s_p9_2[] = {
  112181. 19, 17, 15, 13, 11, 9, 7, 5,
  112182. 3, 1, 0, 2, 4, 6, 8, 10,
  112183. 12, 14, 16, 18, 20,
  112184. };
  112185. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112186. _vq_quantthresh__8c0_s_p9_2,
  112187. _vq_quantmap__8c0_s_p9_2,
  112188. 21,
  112189. 21
  112190. };
  112191. static static_codebook _8c0_s_p9_2 = {
  112192. 2, 441,
  112193. _vq_lengthlist__8c0_s_p9_2,
  112194. 1, -529268736, 1611661312, 5, 0,
  112195. _vq_quantlist__8c0_s_p9_2,
  112196. NULL,
  112197. &_vq_auxt__8c0_s_p9_2,
  112198. NULL,
  112199. 0
  112200. };
  112201. static long _huff_lengthlist__8c0_s_single[] = {
  112202. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112203. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112204. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112205. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112206. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112207. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112208. 17,16,17,17,
  112209. };
  112210. static static_codebook _huff_book__8c0_s_single = {
  112211. 2, 100,
  112212. _huff_lengthlist__8c0_s_single,
  112213. 0, 0, 0, 0, 0,
  112214. NULL,
  112215. NULL,
  112216. NULL,
  112217. NULL,
  112218. 0
  112219. };
  112220. static long _vq_quantlist__8c1_s_p1_0[] = {
  112221. 1,
  112222. 0,
  112223. 2,
  112224. };
  112225. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112226. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112227. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112232. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112237. 0, 0, 0, 0, 7, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  112241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  112246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  112251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 8, 0, 0, 0, 0,
  112272. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  112277. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  112282. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112287. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112292. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112318. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112323. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112328. 0, 0, 0, 0, 0, 0, 8,10, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112628. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112636. 0,
  112637. };
  112638. static float _vq_quantthresh__8c1_s_p1_0[] = {
  112639. -0.5, 0.5,
  112640. };
  112641. static long _vq_quantmap__8c1_s_p1_0[] = {
  112642. 1, 0, 2,
  112643. };
  112644. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  112645. _vq_quantthresh__8c1_s_p1_0,
  112646. _vq_quantmap__8c1_s_p1_0,
  112647. 3,
  112648. 3
  112649. };
  112650. static static_codebook _8c1_s_p1_0 = {
  112651. 8, 6561,
  112652. _vq_lengthlist__8c1_s_p1_0,
  112653. 1, -535822336, 1611661312, 2, 0,
  112654. _vq_quantlist__8c1_s_p1_0,
  112655. NULL,
  112656. &_vq_auxt__8c1_s_p1_0,
  112657. NULL,
  112658. 0
  112659. };
  112660. static long _vq_quantlist__8c1_s_p2_0[] = {
  112661. 2,
  112662. 1,
  112663. 3,
  112664. 0,
  112665. 4,
  112666. };
  112667. static long _vq_lengthlist__8c1_s_p2_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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112707. 0,
  112708. };
  112709. static float _vq_quantthresh__8c1_s_p2_0[] = {
  112710. -1.5, -0.5, 0.5, 1.5,
  112711. };
  112712. static long _vq_quantmap__8c1_s_p2_0[] = {
  112713. 3, 1, 0, 2, 4,
  112714. };
  112715. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  112716. _vq_quantthresh__8c1_s_p2_0,
  112717. _vq_quantmap__8c1_s_p2_0,
  112718. 5,
  112719. 5
  112720. };
  112721. static static_codebook _8c1_s_p2_0 = {
  112722. 4, 625,
  112723. _vq_lengthlist__8c1_s_p2_0,
  112724. 1, -533725184, 1611661312, 3, 0,
  112725. _vq_quantlist__8c1_s_p2_0,
  112726. NULL,
  112727. &_vq_auxt__8c1_s_p2_0,
  112728. NULL,
  112729. 0
  112730. };
  112731. static long _vq_quantlist__8c1_s_p3_0[] = {
  112732. 2,
  112733. 1,
  112734. 3,
  112735. 0,
  112736. 4,
  112737. };
  112738. static long _vq_lengthlist__8c1_s_p3_0[] = {
  112739. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  112741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112742. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  112744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112745. 0, 0, 0, 0, 6, 6, 6, 7, 7, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112778. 0,
  112779. };
  112780. static float _vq_quantthresh__8c1_s_p3_0[] = {
  112781. -1.5, -0.5, 0.5, 1.5,
  112782. };
  112783. static long _vq_quantmap__8c1_s_p3_0[] = {
  112784. 3, 1, 0, 2, 4,
  112785. };
  112786. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  112787. _vq_quantthresh__8c1_s_p3_0,
  112788. _vq_quantmap__8c1_s_p3_0,
  112789. 5,
  112790. 5
  112791. };
  112792. static static_codebook _8c1_s_p3_0 = {
  112793. 4, 625,
  112794. _vq_lengthlist__8c1_s_p3_0,
  112795. 1, -533725184, 1611661312, 3, 0,
  112796. _vq_quantlist__8c1_s_p3_0,
  112797. NULL,
  112798. &_vq_auxt__8c1_s_p3_0,
  112799. NULL,
  112800. 0
  112801. };
  112802. static long _vq_quantlist__8c1_s_p4_0[] = {
  112803. 4,
  112804. 3,
  112805. 5,
  112806. 2,
  112807. 6,
  112808. 1,
  112809. 7,
  112810. 0,
  112811. 8,
  112812. };
  112813. static long _vq_lengthlist__8c1_s_p4_0[] = {
  112814. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112815. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112816. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112817. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112818. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112819. 0,
  112820. };
  112821. static float _vq_quantthresh__8c1_s_p4_0[] = {
  112822. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112823. };
  112824. static long _vq_quantmap__8c1_s_p4_0[] = {
  112825. 7, 5, 3, 1, 0, 2, 4, 6,
  112826. 8,
  112827. };
  112828. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  112829. _vq_quantthresh__8c1_s_p4_0,
  112830. _vq_quantmap__8c1_s_p4_0,
  112831. 9,
  112832. 9
  112833. };
  112834. static static_codebook _8c1_s_p4_0 = {
  112835. 2, 81,
  112836. _vq_lengthlist__8c1_s_p4_0,
  112837. 1, -531628032, 1611661312, 4, 0,
  112838. _vq_quantlist__8c1_s_p4_0,
  112839. NULL,
  112840. &_vq_auxt__8c1_s_p4_0,
  112841. NULL,
  112842. 0
  112843. };
  112844. static long _vq_quantlist__8c1_s_p5_0[] = {
  112845. 4,
  112846. 3,
  112847. 5,
  112848. 2,
  112849. 6,
  112850. 1,
  112851. 7,
  112852. 0,
  112853. 8,
  112854. };
  112855. static long _vq_lengthlist__8c1_s_p5_0[] = {
  112856. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  112857. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  112858. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  112859. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  112860. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112861. 10,
  112862. };
  112863. static float _vq_quantthresh__8c1_s_p5_0[] = {
  112864. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112865. };
  112866. static long _vq_quantmap__8c1_s_p5_0[] = {
  112867. 7, 5, 3, 1, 0, 2, 4, 6,
  112868. 8,
  112869. };
  112870. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  112871. _vq_quantthresh__8c1_s_p5_0,
  112872. _vq_quantmap__8c1_s_p5_0,
  112873. 9,
  112874. 9
  112875. };
  112876. static static_codebook _8c1_s_p5_0 = {
  112877. 2, 81,
  112878. _vq_lengthlist__8c1_s_p5_0,
  112879. 1, -531628032, 1611661312, 4, 0,
  112880. _vq_quantlist__8c1_s_p5_0,
  112881. NULL,
  112882. &_vq_auxt__8c1_s_p5_0,
  112883. NULL,
  112884. 0
  112885. };
  112886. static long _vq_quantlist__8c1_s_p6_0[] = {
  112887. 8,
  112888. 7,
  112889. 9,
  112890. 6,
  112891. 10,
  112892. 5,
  112893. 11,
  112894. 4,
  112895. 12,
  112896. 3,
  112897. 13,
  112898. 2,
  112899. 14,
  112900. 1,
  112901. 15,
  112902. 0,
  112903. 16,
  112904. };
  112905. static long _vq_lengthlist__8c1_s_p6_0[] = {
  112906. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  112907. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112908. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  112909. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  112910. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  112911. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  112912. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  112913. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  112914. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  112915. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112916. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  112917. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  112918. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  112919. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  112920. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  112921. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  112922. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  112923. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  112924. 14,
  112925. };
  112926. static float _vq_quantthresh__8c1_s_p6_0[] = {
  112927. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112928. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112929. };
  112930. static long _vq_quantmap__8c1_s_p6_0[] = {
  112931. 15, 13, 11, 9, 7, 5, 3, 1,
  112932. 0, 2, 4, 6, 8, 10, 12, 14,
  112933. 16,
  112934. };
  112935. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  112936. _vq_quantthresh__8c1_s_p6_0,
  112937. _vq_quantmap__8c1_s_p6_0,
  112938. 17,
  112939. 17
  112940. };
  112941. static static_codebook _8c1_s_p6_0 = {
  112942. 2, 289,
  112943. _vq_lengthlist__8c1_s_p6_0,
  112944. 1, -529530880, 1611661312, 5, 0,
  112945. _vq_quantlist__8c1_s_p6_0,
  112946. NULL,
  112947. &_vq_auxt__8c1_s_p6_0,
  112948. NULL,
  112949. 0
  112950. };
  112951. static long _vq_quantlist__8c1_s_p7_0[] = {
  112952. 1,
  112953. 0,
  112954. 2,
  112955. };
  112956. static long _vq_lengthlist__8c1_s_p7_0[] = {
  112957. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  112958. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  112959. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  112960. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  112961. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  112962. 9,
  112963. };
  112964. static float _vq_quantthresh__8c1_s_p7_0[] = {
  112965. -5.5, 5.5,
  112966. };
  112967. static long _vq_quantmap__8c1_s_p7_0[] = {
  112968. 1, 0, 2,
  112969. };
  112970. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  112971. _vq_quantthresh__8c1_s_p7_0,
  112972. _vq_quantmap__8c1_s_p7_0,
  112973. 3,
  112974. 3
  112975. };
  112976. static static_codebook _8c1_s_p7_0 = {
  112977. 4, 81,
  112978. _vq_lengthlist__8c1_s_p7_0,
  112979. 1, -529137664, 1618345984, 2, 0,
  112980. _vq_quantlist__8c1_s_p7_0,
  112981. NULL,
  112982. &_vq_auxt__8c1_s_p7_0,
  112983. NULL,
  112984. 0
  112985. };
  112986. static long _vq_quantlist__8c1_s_p7_1[] = {
  112987. 5,
  112988. 4,
  112989. 6,
  112990. 3,
  112991. 7,
  112992. 2,
  112993. 8,
  112994. 1,
  112995. 9,
  112996. 0,
  112997. 10,
  112998. };
  112999. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113000. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113001. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113002. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113003. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113004. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113005. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113006. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113007. 10,10,10, 8, 8, 8, 8, 8, 8,
  113008. };
  113009. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113010. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113011. 3.5, 4.5,
  113012. };
  113013. static long _vq_quantmap__8c1_s_p7_1[] = {
  113014. 9, 7, 5, 3, 1, 0, 2, 4,
  113015. 6, 8, 10,
  113016. };
  113017. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113018. _vq_quantthresh__8c1_s_p7_1,
  113019. _vq_quantmap__8c1_s_p7_1,
  113020. 11,
  113021. 11
  113022. };
  113023. static static_codebook _8c1_s_p7_1 = {
  113024. 2, 121,
  113025. _vq_lengthlist__8c1_s_p7_1,
  113026. 1, -531365888, 1611661312, 4, 0,
  113027. _vq_quantlist__8c1_s_p7_1,
  113028. NULL,
  113029. &_vq_auxt__8c1_s_p7_1,
  113030. NULL,
  113031. 0
  113032. };
  113033. static long _vq_quantlist__8c1_s_p8_0[] = {
  113034. 6,
  113035. 5,
  113036. 7,
  113037. 4,
  113038. 8,
  113039. 3,
  113040. 9,
  113041. 2,
  113042. 10,
  113043. 1,
  113044. 11,
  113045. 0,
  113046. 12,
  113047. };
  113048. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113049. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113050. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113051. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113052. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113053. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113054. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113055. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113056. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113057. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113058. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113059. 0,12,12,11,10,12,11,13,12,
  113060. };
  113061. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113062. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113063. 12.5, 17.5, 22.5, 27.5,
  113064. };
  113065. static long _vq_quantmap__8c1_s_p8_0[] = {
  113066. 11, 9, 7, 5, 3, 1, 0, 2,
  113067. 4, 6, 8, 10, 12,
  113068. };
  113069. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113070. _vq_quantthresh__8c1_s_p8_0,
  113071. _vq_quantmap__8c1_s_p8_0,
  113072. 13,
  113073. 13
  113074. };
  113075. static static_codebook _8c1_s_p8_0 = {
  113076. 2, 169,
  113077. _vq_lengthlist__8c1_s_p8_0,
  113078. 1, -526516224, 1616117760, 4, 0,
  113079. _vq_quantlist__8c1_s_p8_0,
  113080. NULL,
  113081. &_vq_auxt__8c1_s_p8_0,
  113082. NULL,
  113083. 0
  113084. };
  113085. static long _vq_quantlist__8c1_s_p8_1[] = {
  113086. 2,
  113087. 1,
  113088. 3,
  113089. 0,
  113090. 4,
  113091. };
  113092. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113093. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113094. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113095. };
  113096. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113097. -1.5, -0.5, 0.5, 1.5,
  113098. };
  113099. static long _vq_quantmap__8c1_s_p8_1[] = {
  113100. 3, 1, 0, 2, 4,
  113101. };
  113102. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113103. _vq_quantthresh__8c1_s_p8_1,
  113104. _vq_quantmap__8c1_s_p8_1,
  113105. 5,
  113106. 5
  113107. };
  113108. static static_codebook _8c1_s_p8_1 = {
  113109. 2, 25,
  113110. _vq_lengthlist__8c1_s_p8_1,
  113111. 1, -533725184, 1611661312, 3, 0,
  113112. _vq_quantlist__8c1_s_p8_1,
  113113. NULL,
  113114. &_vq_auxt__8c1_s_p8_1,
  113115. NULL,
  113116. 0
  113117. };
  113118. static long _vq_quantlist__8c1_s_p9_0[] = {
  113119. 6,
  113120. 5,
  113121. 7,
  113122. 4,
  113123. 8,
  113124. 3,
  113125. 9,
  113126. 2,
  113127. 10,
  113128. 1,
  113129. 11,
  113130. 0,
  113131. 12,
  113132. };
  113133. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113134. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113135. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113136. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113137. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113138. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113139. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113140. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113141. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113142. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113143. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113144. 10,10,10,10,10, 9, 9, 9, 9,
  113145. };
  113146. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113147. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113148. 787.5, 1102.5, 1417.5, 1732.5,
  113149. };
  113150. static long _vq_quantmap__8c1_s_p9_0[] = {
  113151. 11, 9, 7, 5, 3, 1, 0, 2,
  113152. 4, 6, 8, 10, 12,
  113153. };
  113154. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113155. _vq_quantthresh__8c1_s_p9_0,
  113156. _vq_quantmap__8c1_s_p9_0,
  113157. 13,
  113158. 13
  113159. };
  113160. static static_codebook _8c1_s_p9_0 = {
  113161. 2, 169,
  113162. _vq_lengthlist__8c1_s_p9_0,
  113163. 1, -513964032, 1628680192, 4, 0,
  113164. _vq_quantlist__8c1_s_p9_0,
  113165. NULL,
  113166. &_vq_auxt__8c1_s_p9_0,
  113167. NULL,
  113168. 0
  113169. };
  113170. static long _vq_quantlist__8c1_s_p9_1[] = {
  113171. 7,
  113172. 6,
  113173. 8,
  113174. 5,
  113175. 9,
  113176. 4,
  113177. 10,
  113178. 3,
  113179. 11,
  113180. 2,
  113181. 12,
  113182. 1,
  113183. 13,
  113184. 0,
  113185. 14,
  113186. };
  113187. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113188. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113189. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113190. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113191. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113192. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113193. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113194. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113195. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113196. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113197. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113198. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113199. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113200. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113201. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113202. 15,
  113203. };
  113204. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113205. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113206. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113207. };
  113208. static long _vq_quantmap__8c1_s_p9_1[] = {
  113209. 13, 11, 9, 7, 5, 3, 1, 0,
  113210. 2, 4, 6, 8, 10, 12, 14,
  113211. };
  113212. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113213. _vq_quantthresh__8c1_s_p9_1,
  113214. _vq_quantmap__8c1_s_p9_1,
  113215. 15,
  113216. 15
  113217. };
  113218. static static_codebook _8c1_s_p9_1 = {
  113219. 2, 225,
  113220. _vq_lengthlist__8c1_s_p9_1,
  113221. 1, -520986624, 1620377600, 4, 0,
  113222. _vq_quantlist__8c1_s_p9_1,
  113223. NULL,
  113224. &_vq_auxt__8c1_s_p9_1,
  113225. NULL,
  113226. 0
  113227. };
  113228. static long _vq_quantlist__8c1_s_p9_2[] = {
  113229. 10,
  113230. 9,
  113231. 11,
  113232. 8,
  113233. 12,
  113234. 7,
  113235. 13,
  113236. 6,
  113237. 14,
  113238. 5,
  113239. 15,
  113240. 4,
  113241. 16,
  113242. 3,
  113243. 17,
  113244. 2,
  113245. 18,
  113246. 1,
  113247. 19,
  113248. 0,
  113249. 20,
  113250. };
  113251. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113252. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113253. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113254. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113255. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113256. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113257. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113258. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113259. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113260. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113261. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113262. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113263. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113264. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113265. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113266. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113267. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113268. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113269. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113270. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113271. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113272. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113273. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113274. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113275. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113276. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113277. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113278. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113279. 10,10,10,10,10,10,10,10,10,
  113280. };
  113281. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113282. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113283. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113284. 6.5, 7.5, 8.5, 9.5,
  113285. };
  113286. static long _vq_quantmap__8c1_s_p9_2[] = {
  113287. 19, 17, 15, 13, 11, 9, 7, 5,
  113288. 3, 1, 0, 2, 4, 6, 8, 10,
  113289. 12, 14, 16, 18, 20,
  113290. };
  113291. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113292. _vq_quantthresh__8c1_s_p9_2,
  113293. _vq_quantmap__8c1_s_p9_2,
  113294. 21,
  113295. 21
  113296. };
  113297. static static_codebook _8c1_s_p9_2 = {
  113298. 2, 441,
  113299. _vq_lengthlist__8c1_s_p9_2,
  113300. 1, -529268736, 1611661312, 5, 0,
  113301. _vq_quantlist__8c1_s_p9_2,
  113302. NULL,
  113303. &_vq_auxt__8c1_s_p9_2,
  113304. NULL,
  113305. 0
  113306. };
  113307. static long _huff_lengthlist__8c1_s_single[] = {
  113308. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113309. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113310. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113311. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113312. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113313. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113314. 9, 7, 7, 8,
  113315. };
  113316. static static_codebook _huff_book__8c1_s_single = {
  113317. 2, 100,
  113318. _huff_lengthlist__8c1_s_single,
  113319. 0, 0, 0, 0, 0,
  113320. NULL,
  113321. NULL,
  113322. NULL,
  113323. NULL,
  113324. 0
  113325. };
  113326. static long _huff_lengthlist__44c2_s_long[] = {
  113327. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113328. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113329. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113330. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113331. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113332. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113333. 10, 8, 8, 9,
  113334. };
  113335. static static_codebook _huff_book__44c2_s_long = {
  113336. 2, 100,
  113337. _huff_lengthlist__44c2_s_long,
  113338. 0, 0, 0, 0, 0,
  113339. NULL,
  113340. NULL,
  113341. NULL,
  113342. NULL,
  113343. 0
  113344. };
  113345. static long _vq_quantlist__44c2_s_p1_0[] = {
  113346. 1,
  113347. 0,
  113348. 2,
  113349. };
  113350. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113351. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113352. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113357. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113362. 0, 0, 0, 0, 7, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  113366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  113371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  113376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 7, 7, 0, 0, 0, 0,
  113397. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  113402. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  113407. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113412. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113417. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113443. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113448. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113453. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113761. 0,
  113762. };
  113763. static float _vq_quantthresh__44c2_s_p1_0[] = {
  113764. -0.5, 0.5,
  113765. };
  113766. static long _vq_quantmap__44c2_s_p1_0[] = {
  113767. 1, 0, 2,
  113768. };
  113769. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  113770. _vq_quantthresh__44c2_s_p1_0,
  113771. _vq_quantmap__44c2_s_p1_0,
  113772. 3,
  113773. 3
  113774. };
  113775. static static_codebook _44c2_s_p1_0 = {
  113776. 8, 6561,
  113777. _vq_lengthlist__44c2_s_p1_0,
  113778. 1, -535822336, 1611661312, 2, 0,
  113779. _vq_quantlist__44c2_s_p1_0,
  113780. NULL,
  113781. &_vq_auxt__44c2_s_p1_0,
  113782. NULL,
  113783. 0
  113784. };
  113785. static long _vq_quantlist__44c2_s_p2_0[] = {
  113786. 2,
  113787. 1,
  113788. 3,
  113789. 0,
  113790. 4,
  113791. };
  113792. static long _vq_lengthlist__44c2_s_p2_0[] = {
  113793. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  113794. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  113795. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  113796. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  113797. 0, 0, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113802. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  113803. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  113804. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  113805. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113810. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  113811. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  113812. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  113813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113818. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  113819. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  113820. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  113821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113832. 0,
  113833. };
  113834. static float _vq_quantthresh__44c2_s_p2_0[] = {
  113835. -1.5, -0.5, 0.5, 1.5,
  113836. };
  113837. static long _vq_quantmap__44c2_s_p2_0[] = {
  113838. 3, 1, 0, 2, 4,
  113839. };
  113840. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  113841. _vq_quantthresh__44c2_s_p2_0,
  113842. _vq_quantmap__44c2_s_p2_0,
  113843. 5,
  113844. 5
  113845. };
  113846. static static_codebook _44c2_s_p2_0 = {
  113847. 4, 625,
  113848. _vq_lengthlist__44c2_s_p2_0,
  113849. 1, -533725184, 1611661312, 3, 0,
  113850. _vq_quantlist__44c2_s_p2_0,
  113851. NULL,
  113852. &_vq_auxt__44c2_s_p2_0,
  113853. NULL,
  113854. 0
  113855. };
  113856. static long _vq_quantlist__44c2_s_p3_0[] = {
  113857. 2,
  113858. 1,
  113859. 3,
  113860. 0,
  113861. 4,
  113862. };
  113863. static long _vq_lengthlist__44c2_s_p3_0[] = {
  113864. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113867. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  113869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113870. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113903. 0,
  113904. };
  113905. static float _vq_quantthresh__44c2_s_p3_0[] = {
  113906. -1.5, -0.5, 0.5, 1.5,
  113907. };
  113908. static long _vq_quantmap__44c2_s_p3_0[] = {
  113909. 3, 1, 0, 2, 4,
  113910. };
  113911. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  113912. _vq_quantthresh__44c2_s_p3_0,
  113913. _vq_quantmap__44c2_s_p3_0,
  113914. 5,
  113915. 5
  113916. };
  113917. static static_codebook _44c2_s_p3_0 = {
  113918. 4, 625,
  113919. _vq_lengthlist__44c2_s_p3_0,
  113920. 1, -533725184, 1611661312, 3, 0,
  113921. _vq_quantlist__44c2_s_p3_0,
  113922. NULL,
  113923. &_vq_auxt__44c2_s_p3_0,
  113924. NULL,
  113925. 0
  113926. };
  113927. static long _vq_quantlist__44c2_s_p4_0[] = {
  113928. 4,
  113929. 3,
  113930. 5,
  113931. 2,
  113932. 6,
  113933. 1,
  113934. 7,
  113935. 0,
  113936. 8,
  113937. };
  113938. static long _vq_lengthlist__44c2_s_p4_0[] = {
  113939. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  113940. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  113941. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  113942. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  113943. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113944. 0,
  113945. };
  113946. static float _vq_quantthresh__44c2_s_p4_0[] = {
  113947. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113948. };
  113949. static long _vq_quantmap__44c2_s_p4_0[] = {
  113950. 7, 5, 3, 1, 0, 2, 4, 6,
  113951. 8,
  113952. };
  113953. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  113954. _vq_quantthresh__44c2_s_p4_0,
  113955. _vq_quantmap__44c2_s_p4_0,
  113956. 9,
  113957. 9
  113958. };
  113959. static static_codebook _44c2_s_p4_0 = {
  113960. 2, 81,
  113961. _vq_lengthlist__44c2_s_p4_0,
  113962. 1, -531628032, 1611661312, 4, 0,
  113963. _vq_quantlist__44c2_s_p4_0,
  113964. NULL,
  113965. &_vq_auxt__44c2_s_p4_0,
  113966. NULL,
  113967. 0
  113968. };
  113969. static long _vq_quantlist__44c2_s_p5_0[] = {
  113970. 4,
  113971. 3,
  113972. 5,
  113973. 2,
  113974. 6,
  113975. 1,
  113976. 7,
  113977. 0,
  113978. 8,
  113979. };
  113980. static long _vq_lengthlist__44c2_s_p5_0[] = {
  113981. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  113982. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  113983. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  113984. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  113985. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  113986. 11,
  113987. };
  113988. static float _vq_quantthresh__44c2_s_p5_0[] = {
  113989. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113990. };
  113991. static long _vq_quantmap__44c2_s_p5_0[] = {
  113992. 7, 5, 3, 1, 0, 2, 4, 6,
  113993. 8,
  113994. };
  113995. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  113996. _vq_quantthresh__44c2_s_p5_0,
  113997. _vq_quantmap__44c2_s_p5_0,
  113998. 9,
  113999. 9
  114000. };
  114001. static static_codebook _44c2_s_p5_0 = {
  114002. 2, 81,
  114003. _vq_lengthlist__44c2_s_p5_0,
  114004. 1, -531628032, 1611661312, 4, 0,
  114005. _vq_quantlist__44c2_s_p5_0,
  114006. NULL,
  114007. &_vq_auxt__44c2_s_p5_0,
  114008. NULL,
  114009. 0
  114010. };
  114011. static long _vq_quantlist__44c2_s_p6_0[] = {
  114012. 8,
  114013. 7,
  114014. 9,
  114015. 6,
  114016. 10,
  114017. 5,
  114018. 11,
  114019. 4,
  114020. 12,
  114021. 3,
  114022. 13,
  114023. 2,
  114024. 14,
  114025. 1,
  114026. 15,
  114027. 0,
  114028. 16,
  114029. };
  114030. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114031. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114032. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114033. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114034. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114035. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114036. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114037. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114038. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114039. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114040. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114041. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114042. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114043. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114044. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114045. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114046. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114047. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114048. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114049. 14,
  114050. };
  114051. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114052. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114053. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114054. };
  114055. static long _vq_quantmap__44c2_s_p6_0[] = {
  114056. 15, 13, 11, 9, 7, 5, 3, 1,
  114057. 0, 2, 4, 6, 8, 10, 12, 14,
  114058. 16,
  114059. };
  114060. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114061. _vq_quantthresh__44c2_s_p6_0,
  114062. _vq_quantmap__44c2_s_p6_0,
  114063. 17,
  114064. 17
  114065. };
  114066. static static_codebook _44c2_s_p6_0 = {
  114067. 2, 289,
  114068. _vq_lengthlist__44c2_s_p6_0,
  114069. 1, -529530880, 1611661312, 5, 0,
  114070. _vq_quantlist__44c2_s_p6_0,
  114071. NULL,
  114072. &_vq_auxt__44c2_s_p6_0,
  114073. NULL,
  114074. 0
  114075. };
  114076. static long _vq_quantlist__44c2_s_p7_0[] = {
  114077. 1,
  114078. 0,
  114079. 2,
  114080. };
  114081. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114082. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114083. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114084. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114085. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114086. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114087. 11,
  114088. };
  114089. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114090. -5.5, 5.5,
  114091. };
  114092. static long _vq_quantmap__44c2_s_p7_0[] = {
  114093. 1, 0, 2,
  114094. };
  114095. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114096. _vq_quantthresh__44c2_s_p7_0,
  114097. _vq_quantmap__44c2_s_p7_0,
  114098. 3,
  114099. 3
  114100. };
  114101. static static_codebook _44c2_s_p7_0 = {
  114102. 4, 81,
  114103. _vq_lengthlist__44c2_s_p7_0,
  114104. 1, -529137664, 1618345984, 2, 0,
  114105. _vq_quantlist__44c2_s_p7_0,
  114106. NULL,
  114107. &_vq_auxt__44c2_s_p7_0,
  114108. NULL,
  114109. 0
  114110. };
  114111. static long _vq_quantlist__44c2_s_p7_1[] = {
  114112. 5,
  114113. 4,
  114114. 6,
  114115. 3,
  114116. 7,
  114117. 2,
  114118. 8,
  114119. 1,
  114120. 9,
  114121. 0,
  114122. 10,
  114123. };
  114124. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114125. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114126. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114127. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114128. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114129. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114130. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114131. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114132. 10,10,10, 8, 8, 8, 8, 8, 8,
  114133. };
  114134. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114135. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114136. 3.5, 4.5,
  114137. };
  114138. static long _vq_quantmap__44c2_s_p7_1[] = {
  114139. 9, 7, 5, 3, 1, 0, 2, 4,
  114140. 6, 8, 10,
  114141. };
  114142. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114143. _vq_quantthresh__44c2_s_p7_1,
  114144. _vq_quantmap__44c2_s_p7_1,
  114145. 11,
  114146. 11
  114147. };
  114148. static static_codebook _44c2_s_p7_1 = {
  114149. 2, 121,
  114150. _vq_lengthlist__44c2_s_p7_1,
  114151. 1, -531365888, 1611661312, 4, 0,
  114152. _vq_quantlist__44c2_s_p7_1,
  114153. NULL,
  114154. &_vq_auxt__44c2_s_p7_1,
  114155. NULL,
  114156. 0
  114157. };
  114158. static long _vq_quantlist__44c2_s_p8_0[] = {
  114159. 6,
  114160. 5,
  114161. 7,
  114162. 4,
  114163. 8,
  114164. 3,
  114165. 9,
  114166. 2,
  114167. 10,
  114168. 1,
  114169. 11,
  114170. 0,
  114171. 12,
  114172. };
  114173. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114174. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114175. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114176. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114177. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114178. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114179. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114180. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114181. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114182. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114183. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114184. 0,12,12,12,12,13,12,14,14,
  114185. };
  114186. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114187. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114188. 12.5, 17.5, 22.5, 27.5,
  114189. };
  114190. static long _vq_quantmap__44c2_s_p8_0[] = {
  114191. 11, 9, 7, 5, 3, 1, 0, 2,
  114192. 4, 6, 8, 10, 12,
  114193. };
  114194. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114195. _vq_quantthresh__44c2_s_p8_0,
  114196. _vq_quantmap__44c2_s_p8_0,
  114197. 13,
  114198. 13
  114199. };
  114200. static static_codebook _44c2_s_p8_0 = {
  114201. 2, 169,
  114202. _vq_lengthlist__44c2_s_p8_0,
  114203. 1, -526516224, 1616117760, 4, 0,
  114204. _vq_quantlist__44c2_s_p8_0,
  114205. NULL,
  114206. &_vq_auxt__44c2_s_p8_0,
  114207. NULL,
  114208. 0
  114209. };
  114210. static long _vq_quantlist__44c2_s_p8_1[] = {
  114211. 2,
  114212. 1,
  114213. 3,
  114214. 0,
  114215. 4,
  114216. };
  114217. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114218. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114219. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114220. };
  114221. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114222. -1.5, -0.5, 0.5, 1.5,
  114223. };
  114224. static long _vq_quantmap__44c2_s_p8_1[] = {
  114225. 3, 1, 0, 2, 4,
  114226. };
  114227. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114228. _vq_quantthresh__44c2_s_p8_1,
  114229. _vq_quantmap__44c2_s_p8_1,
  114230. 5,
  114231. 5
  114232. };
  114233. static static_codebook _44c2_s_p8_1 = {
  114234. 2, 25,
  114235. _vq_lengthlist__44c2_s_p8_1,
  114236. 1, -533725184, 1611661312, 3, 0,
  114237. _vq_quantlist__44c2_s_p8_1,
  114238. NULL,
  114239. &_vq_auxt__44c2_s_p8_1,
  114240. NULL,
  114241. 0
  114242. };
  114243. static long _vq_quantlist__44c2_s_p9_0[] = {
  114244. 6,
  114245. 5,
  114246. 7,
  114247. 4,
  114248. 8,
  114249. 3,
  114250. 9,
  114251. 2,
  114252. 10,
  114253. 1,
  114254. 11,
  114255. 0,
  114256. 12,
  114257. };
  114258. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114259. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114260. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114261. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114262. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114263. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114264. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114265. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114266. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114267. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114268. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114269. 11,11,11,11,11,11,11,11,11,
  114270. };
  114271. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114272. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114273. 552.5, 773.5, 994.5, 1215.5,
  114274. };
  114275. static long _vq_quantmap__44c2_s_p9_0[] = {
  114276. 11, 9, 7, 5, 3, 1, 0, 2,
  114277. 4, 6, 8, 10, 12,
  114278. };
  114279. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114280. _vq_quantthresh__44c2_s_p9_0,
  114281. _vq_quantmap__44c2_s_p9_0,
  114282. 13,
  114283. 13
  114284. };
  114285. static static_codebook _44c2_s_p9_0 = {
  114286. 2, 169,
  114287. _vq_lengthlist__44c2_s_p9_0,
  114288. 1, -514541568, 1627103232, 4, 0,
  114289. _vq_quantlist__44c2_s_p9_0,
  114290. NULL,
  114291. &_vq_auxt__44c2_s_p9_0,
  114292. NULL,
  114293. 0
  114294. };
  114295. static long _vq_quantlist__44c2_s_p9_1[] = {
  114296. 6,
  114297. 5,
  114298. 7,
  114299. 4,
  114300. 8,
  114301. 3,
  114302. 9,
  114303. 2,
  114304. 10,
  114305. 1,
  114306. 11,
  114307. 0,
  114308. 12,
  114309. };
  114310. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114311. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114312. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114313. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114314. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114315. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114316. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114317. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114318. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114319. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114320. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114321. 17,13,12,12,10,13,11,14,14,
  114322. };
  114323. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114324. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114325. 42.5, 59.5, 76.5, 93.5,
  114326. };
  114327. static long _vq_quantmap__44c2_s_p9_1[] = {
  114328. 11, 9, 7, 5, 3, 1, 0, 2,
  114329. 4, 6, 8, 10, 12,
  114330. };
  114331. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114332. _vq_quantthresh__44c2_s_p9_1,
  114333. _vq_quantmap__44c2_s_p9_1,
  114334. 13,
  114335. 13
  114336. };
  114337. static static_codebook _44c2_s_p9_1 = {
  114338. 2, 169,
  114339. _vq_lengthlist__44c2_s_p9_1,
  114340. 1, -522616832, 1620115456, 4, 0,
  114341. _vq_quantlist__44c2_s_p9_1,
  114342. NULL,
  114343. &_vq_auxt__44c2_s_p9_1,
  114344. NULL,
  114345. 0
  114346. };
  114347. static long _vq_quantlist__44c2_s_p9_2[] = {
  114348. 8,
  114349. 7,
  114350. 9,
  114351. 6,
  114352. 10,
  114353. 5,
  114354. 11,
  114355. 4,
  114356. 12,
  114357. 3,
  114358. 13,
  114359. 2,
  114360. 14,
  114361. 1,
  114362. 15,
  114363. 0,
  114364. 16,
  114365. };
  114366. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114367. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114368. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114369. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114370. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114371. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114372. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114373. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114374. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114375. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114376. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114377. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114378. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114379. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114380. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114381. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114382. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114383. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114384. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114385. 10,
  114386. };
  114387. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114388. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114389. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114390. };
  114391. static long _vq_quantmap__44c2_s_p9_2[] = {
  114392. 15, 13, 11, 9, 7, 5, 3, 1,
  114393. 0, 2, 4, 6, 8, 10, 12, 14,
  114394. 16,
  114395. };
  114396. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114397. _vq_quantthresh__44c2_s_p9_2,
  114398. _vq_quantmap__44c2_s_p9_2,
  114399. 17,
  114400. 17
  114401. };
  114402. static static_codebook _44c2_s_p9_2 = {
  114403. 2, 289,
  114404. _vq_lengthlist__44c2_s_p9_2,
  114405. 1, -529530880, 1611661312, 5, 0,
  114406. _vq_quantlist__44c2_s_p9_2,
  114407. NULL,
  114408. &_vq_auxt__44c2_s_p9_2,
  114409. NULL,
  114410. 0
  114411. };
  114412. static long _huff_lengthlist__44c2_s_short[] = {
  114413. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114414. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114415. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114416. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114417. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114418. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114419. 6, 8, 9,12,
  114420. };
  114421. static static_codebook _huff_book__44c2_s_short = {
  114422. 2, 100,
  114423. _huff_lengthlist__44c2_s_short,
  114424. 0, 0, 0, 0, 0,
  114425. NULL,
  114426. NULL,
  114427. NULL,
  114428. NULL,
  114429. 0
  114430. };
  114431. static long _huff_lengthlist__44c3_s_long[] = {
  114432. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114433. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114434. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114435. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114436. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114437. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114438. 9, 8, 8, 8,
  114439. };
  114440. static static_codebook _huff_book__44c3_s_long = {
  114441. 2, 100,
  114442. _huff_lengthlist__44c3_s_long,
  114443. 0, 0, 0, 0, 0,
  114444. NULL,
  114445. NULL,
  114446. NULL,
  114447. NULL,
  114448. 0
  114449. };
  114450. static long _vq_quantlist__44c3_s_p1_0[] = {
  114451. 1,
  114452. 0,
  114453. 2,
  114454. };
  114455. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114456. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114457. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114462. 0, 0, 0, 6, 7, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114467. 0, 0, 0, 0, 7, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  114471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  114476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  114481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 7, 7, 0, 0, 0, 0,
  114502. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  114507. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  114512. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114517. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114522. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114548. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114553. 0, 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  114558. 0, 0, 0, 0, 0, 0, 8, 9, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114866. 0,
  114867. };
  114868. static float _vq_quantthresh__44c3_s_p1_0[] = {
  114869. -0.5, 0.5,
  114870. };
  114871. static long _vq_quantmap__44c3_s_p1_0[] = {
  114872. 1, 0, 2,
  114873. };
  114874. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  114875. _vq_quantthresh__44c3_s_p1_0,
  114876. _vq_quantmap__44c3_s_p1_0,
  114877. 3,
  114878. 3
  114879. };
  114880. static static_codebook _44c3_s_p1_0 = {
  114881. 8, 6561,
  114882. _vq_lengthlist__44c3_s_p1_0,
  114883. 1, -535822336, 1611661312, 2, 0,
  114884. _vq_quantlist__44c3_s_p1_0,
  114885. NULL,
  114886. &_vq_auxt__44c3_s_p1_0,
  114887. NULL,
  114888. 0
  114889. };
  114890. static long _vq_quantlist__44c3_s_p2_0[] = {
  114891. 2,
  114892. 1,
  114893. 3,
  114894. 0,
  114895. 4,
  114896. };
  114897. static long _vq_lengthlist__44c3_s_p2_0[] = {
  114898. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  114899. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  114900. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  114901. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  114902. 0, 0,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114907. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  114908. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  114909. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  114910. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114915. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  114916. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  114917. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  114918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114923. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  114924. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  114925. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  114926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114937. 0,
  114938. };
  114939. static float _vq_quantthresh__44c3_s_p2_0[] = {
  114940. -1.5, -0.5, 0.5, 1.5,
  114941. };
  114942. static long _vq_quantmap__44c3_s_p2_0[] = {
  114943. 3, 1, 0, 2, 4,
  114944. };
  114945. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  114946. _vq_quantthresh__44c3_s_p2_0,
  114947. _vq_quantmap__44c3_s_p2_0,
  114948. 5,
  114949. 5
  114950. };
  114951. static static_codebook _44c3_s_p2_0 = {
  114952. 4, 625,
  114953. _vq_lengthlist__44c3_s_p2_0,
  114954. 1, -533725184, 1611661312, 3, 0,
  114955. _vq_quantlist__44c3_s_p2_0,
  114956. NULL,
  114957. &_vq_auxt__44c3_s_p2_0,
  114958. NULL,
  114959. 0
  114960. };
  114961. static long _vq_quantlist__44c3_s_p3_0[] = {
  114962. 2,
  114963. 1,
  114964. 3,
  114965. 0,
  114966. 4,
  114967. };
  114968. static long _vq_lengthlist__44c3_s_p3_0[] = {
  114969. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114972. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114975. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115008. 0,
  115009. };
  115010. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115011. -1.5, -0.5, 0.5, 1.5,
  115012. };
  115013. static long _vq_quantmap__44c3_s_p3_0[] = {
  115014. 3, 1, 0, 2, 4,
  115015. };
  115016. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115017. _vq_quantthresh__44c3_s_p3_0,
  115018. _vq_quantmap__44c3_s_p3_0,
  115019. 5,
  115020. 5
  115021. };
  115022. static static_codebook _44c3_s_p3_0 = {
  115023. 4, 625,
  115024. _vq_lengthlist__44c3_s_p3_0,
  115025. 1, -533725184, 1611661312, 3, 0,
  115026. _vq_quantlist__44c3_s_p3_0,
  115027. NULL,
  115028. &_vq_auxt__44c3_s_p3_0,
  115029. NULL,
  115030. 0
  115031. };
  115032. static long _vq_quantlist__44c3_s_p4_0[] = {
  115033. 4,
  115034. 3,
  115035. 5,
  115036. 2,
  115037. 6,
  115038. 1,
  115039. 7,
  115040. 0,
  115041. 8,
  115042. };
  115043. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115044. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115045. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115046. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115047. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115048. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115049. 0,
  115050. };
  115051. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115052. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115053. };
  115054. static long _vq_quantmap__44c3_s_p4_0[] = {
  115055. 7, 5, 3, 1, 0, 2, 4, 6,
  115056. 8,
  115057. };
  115058. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115059. _vq_quantthresh__44c3_s_p4_0,
  115060. _vq_quantmap__44c3_s_p4_0,
  115061. 9,
  115062. 9
  115063. };
  115064. static static_codebook _44c3_s_p4_0 = {
  115065. 2, 81,
  115066. _vq_lengthlist__44c3_s_p4_0,
  115067. 1, -531628032, 1611661312, 4, 0,
  115068. _vq_quantlist__44c3_s_p4_0,
  115069. NULL,
  115070. &_vq_auxt__44c3_s_p4_0,
  115071. NULL,
  115072. 0
  115073. };
  115074. static long _vq_quantlist__44c3_s_p5_0[] = {
  115075. 4,
  115076. 3,
  115077. 5,
  115078. 2,
  115079. 6,
  115080. 1,
  115081. 7,
  115082. 0,
  115083. 8,
  115084. };
  115085. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115086. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115087. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115088. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115089. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115090. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115091. 11,
  115092. };
  115093. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115094. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115095. };
  115096. static long _vq_quantmap__44c3_s_p5_0[] = {
  115097. 7, 5, 3, 1, 0, 2, 4, 6,
  115098. 8,
  115099. };
  115100. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115101. _vq_quantthresh__44c3_s_p5_0,
  115102. _vq_quantmap__44c3_s_p5_0,
  115103. 9,
  115104. 9
  115105. };
  115106. static static_codebook _44c3_s_p5_0 = {
  115107. 2, 81,
  115108. _vq_lengthlist__44c3_s_p5_0,
  115109. 1, -531628032, 1611661312, 4, 0,
  115110. _vq_quantlist__44c3_s_p5_0,
  115111. NULL,
  115112. &_vq_auxt__44c3_s_p5_0,
  115113. NULL,
  115114. 0
  115115. };
  115116. static long _vq_quantlist__44c3_s_p6_0[] = {
  115117. 8,
  115118. 7,
  115119. 9,
  115120. 6,
  115121. 10,
  115122. 5,
  115123. 11,
  115124. 4,
  115125. 12,
  115126. 3,
  115127. 13,
  115128. 2,
  115129. 14,
  115130. 1,
  115131. 15,
  115132. 0,
  115133. 16,
  115134. };
  115135. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115136. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115137. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115138. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115139. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115140. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115141. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115142. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115143. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115144. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115145. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115146. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115147. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115148. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115149. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115150. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115151. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115152. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115153. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115154. 13,
  115155. };
  115156. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115157. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115158. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115159. };
  115160. static long _vq_quantmap__44c3_s_p6_0[] = {
  115161. 15, 13, 11, 9, 7, 5, 3, 1,
  115162. 0, 2, 4, 6, 8, 10, 12, 14,
  115163. 16,
  115164. };
  115165. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115166. _vq_quantthresh__44c3_s_p6_0,
  115167. _vq_quantmap__44c3_s_p6_0,
  115168. 17,
  115169. 17
  115170. };
  115171. static static_codebook _44c3_s_p6_0 = {
  115172. 2, 289,
  115173. _vq_lengthlist__44c3_s_p6_0,
  115174. 1, -529530880, 1611661312, 5, 0,
  115175. _vq_quantlist__44c3_s_p6_0,
  115176. NULL,
  115177. &_vq_auxt__44c3_s_p6_0,
  115178. NULL,
  115179. 0
  115180. };
  115181. static long _vq_quantlist__44c3_s_p7_0[] = {
  115182. 1,
  115183. 0,
  115184. 2,
  115185. };
  115186. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115187. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115188. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115189. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115190. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115191. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115192. 10,
  115193. };
  115194. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115195. -5.5, 5.5,
  115196. };
  115197. static long _vq_quantmap__44c3_s_p7_0[] = {
  115198. 1, 0, 2,
  115199. };
  115200. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115201. _vq_quantthresh__44c3_s_p7_0,
  115202. _vq_quantmap__44c3_s_p7_0,
  115203. 3,
  115204. 3
  115205. };
  115206. static static_codebook _44c3_s_p7_0 = {
  115207. 4, 81,
  115208. _vq_lengthlist__44c3_s_p7_0,
  115209. 1, -529137664, 1618345984, 2, 0,
  115210. _vq_quantlist__44c3_s_p7_0,
  115211. NULL,
  115212. &_vq_auxt__44c3_s_p7_0,
  115213. NULL,
  115214. 0
  115215. };
  115216. static long _vq_quantlist__44c3_s_p7_1[] = {
  115217. 5,
  115218. 4,
  115219. 6,
  115220. 3,
  115221. 7,
  115222. 2,
  115223. 8,
  115224. 1,
  115225. 9,
  115226. 0,
  115227. 10,
  115228. };
  115229. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115230. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115231. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115232. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115233. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115234. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115235. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115236. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115237. 10,10,10, 8, 8, 8, 8, 8, 8,
  115238. };
  115239. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115240. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115241. 3.5, 4.5,
  115242. };
  115243. static long _vq_quantmap__44c3_s_p7_1[] = {
  115244. 9, 7, 5, 3, 1, 0, 2, 4,
  115245. 6, 8, 10,
  115246. };
  115247. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115248. _vq_quantthresh__44c3_s_p7_1,
  115249. _vq_quantmap__44c3_s_p7_1,
  115250. 11,
  115251. 11
  115252. };
  115253. static static_codebook _44c3_s_p7_1 = {
  115254. 2, 121,
  115255. _vq_lengthlist__44c3_s_p7_1,
  115256. 1, -531365888, 1611661312, 4, 0,
  115257. _vq_quantlist__44c3_s_p7_1,
  115258. NULL,
  115259. &_vq_auxt__44c3_s_p7_1,
  115260. NULL,
  115261. 0
  115262. };
  115263. static long _vq_quantlist__44c3_s_p8_0[] = {
  115264. 6,
  115265. 5,
  115266. 7,
  115267. 4,
  115268. 8,
  115269. 3,
  115270. 9,
  115271. 2,
  115272. 10,
  115273. 1,
  115274. 11,
  115275. 0,
  115276. 12,
  115277. };
  115278. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115279. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115280. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115281. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115282. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115283. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115284. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115285. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115286. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115287. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115288. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115289. 0,13,13,12,12,13,12,14,13,
  115290. };
  115291. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115292. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115293. 12.5, 17.5, 22.5, 27.5,
  115294. };
  115295. static long _vq_quantmap__44c3_s_p8_0[] = {
  115296. 11, 9, 7, 5, 3, 1, 0, 2,
  115297. 4, 6, 8, 10, 12,
  115298. };
  115299. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115300. _vq_quantthresh__44c3_s_p8_0,
  115301. _vq_quantmap__44c3_s_p8_0,
  115302. 13,
  115303. 13
  115304. };
  115305. static static_codebook _44c3_s_p8_0 = {
  115306. 2, 169,
  115307. _vq_lengthlist__44c3_s_p8_0,
  115308. 1, -526516224, 1616117760, 4, 0,
  115309. _vq_quantlist__44c3_s_p8_0,
  115310. NULL,
  115311. &_vq_auxt__44c3_s_p8_0,
  115312. NULL,
  115313. 0
  115314. };
  115315. static long _vq_quantlist__44c3_s_p8_1[] = {
  115316. 2,
  115317. 1,
  115318. 3,
  115319. 0,
  115320. 4,
  115321. };
  115322. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115323. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115324. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115325. };
  115326. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115327. -1.5, -0.5, 0.5, 1.5,
  115328. };
  115329. static long _vq_quantmap__44c3_s_p8_1[] = {
  115330. 3, 1, 0, 2, 4,
  115331. };
  115332. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115333. _vq_quantthresh__44c3_s_p8_1,
  115334. _vq_quantmap__44c3_s_p8_1,
  115335. 5,
  115336. 5
  115337. };
  115338. static static_codebook _44c3_s_p8_1 = {
  115339. 2, 25,
  115340. _vq_lengthlist__44c3_s_p8_1,
  115341. 1, -533725184, 1611661312, 3, 0,
  115342. _vq_quantlist__44c3_s_p8_1,
  115343. NULL,
  115344. &_vq_auxt__44c3_s_p8_1,
  115345. NULL,
  115346. 0
  115347. };
  115348. static long _vq_quantlist__44c3_s_p9_0[] = {
  115349. 6,
  115350. 5,
  115351. 7,
  115352. 4,
  115353. 8,
  115354. 3,
  115355. 9,
  115356. 2,
  115357. 10,
  115358. 1,
  115359. 11,
  115360. 0,
  115361. 12,
  115362. };
  115363. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115364. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115365. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115366. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115367. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115368. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115369. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115370. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115371. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115372. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115373. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115374. 11,11,11,11,11,11,11,11,11,
  115375. };
  115376. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115377. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115378. 637.5, 892.5, 1147.5, 1402.5,
  115379. };
  115380. static long _vq_quantmap__44c3_s_p9_0[] = {
  115381. 11, 9, 7, 5, 3, 1, 0, 2,
  115382. 4, 6, 8, 10, 12,
  115383. };
  115384. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115385. _vq_quantthresh__44c3_s_p9_0,
  115386. _vq_quantmap__44c3_s_p9_0,
  115387. 13,
  115388. 13
  115389. };
  115390. static static_codebook _44c3_s_p9_0 = {
  115391. 2, 169,
  115392. _vq_lengthlist__44c3_s_p9_0,
  115393. 1, -514332672, 1627381760, 4, 0,
  115394. _vq_quantlist__44c3_s_p9_0,
  115395. NULL,
  115396. &_vq_auxt__44c3_s_p9_0,
  115397. NULL,
  115398. 0
  115399. };
  115400. static long _vq_quantlist__44c3_s_p9_1[] = {
  115401. 7,
  115402. 6,
  115403. 8,
  115404. 5,
  115405. 9,
  115406. 4,
  115407. 10,
  115408. 3,
  115409. 11,
  115410. 2,
  115411. 12,
  115412. 1,
  115413. 13,
  115414. 0,
  115415. 14,
  115416. };
  115417. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115418. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115419. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115420. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115421. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115422. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115423. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115424. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115425. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115426. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115427. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115428. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115429. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115430. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115431. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115432. 15,
  115433. };
  115434. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115435. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115436. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115437. };
  115438. static long _vq_quantmap__44c3_s_p9_1[] = {
  115439. 13, 11, 9, 7, 5, 3, 1, 0,
  115440. 2, 4, 6, 8, 10, 12, 14,
  115441. };
  115442. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115443. _vq_quantthresh__44c3_s_p9_1,
  115444. _vq_quantmap__44c3_s_p9_1,
  115445. 15,
  115446. 15
  115447. };
  115448. static static_codebook _44c3_s_p9_1 = {
  115449. 2, 225,
  115450. _vq_lengthlist__44c3_s_p9_1,
  115451. 1, -522338304, 1620115456, 4, 0,
  115452. _vq_quantlist__44c3_s_p9_1,
  115453. NULL,
  115454. &_vq_auxt__44c3_s_p9_1,
  115455. NULL,
  115456. 0
  115457. };
  115458. static long _vq_quantlist__44c3_s_p9_2[] = {
  115459. 8,
  115460. 7,
  115461. 9,
  115462. 6,
  115463. 10,
  115464. 5,
  115465. 11,
  115466. 4,
  115467. 12,
  115468. 3,
  115469. 13,
  115470. 2,
  115471. 14,
  115472. 1,
  115473. 15,
  115474. 0,
  115475. 16,
  115476. };
  115477. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115478. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115479. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115480. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115481. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115482. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115483. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115484. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115485. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115486. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115487. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115488. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115489. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115490. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115491. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115492. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115493. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115494. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115495. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115496. 10,
  115497. };
  115498. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115499. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115500. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115501. };
  115502. static long _vq_quantmap__44c3_s_p9_2[] = {
  115503. 15, 13, 11, 9, 7, 5, 3, 1,
  115504. 0, 2, 4, 6, 8, 10, 12, 14,
  115505. 16,
  115506. };
  115507. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115508. _vq_quantthresh__44c3_s_p9_2,
  115509. _vq_quantmap__44c3_s_p9_2,
  115510. 17,
  115511. 17
  115512. };
  115513. static static_codebook _44c3_s_p9_2 = {
  115514. 2, 289,
  115515. _vq_lengthlist__44c3_s_p9_2,
  115516. 1, -529530880, 1611661312, 5, 0,
  115517. _vq_quantlist__44c3_s_p9_2,
  115518. NULL,
  115519. &_vq_auxt__44c3_s_p9_2,
  115520. NULL,
  115521. 0
  115522. };
  115523. static long _huff_lengthlist__44c3_s_short[] = {
  115524. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  115525. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  115526. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  115527. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  115528. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  115529. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  115530. 6, 8, 9,11,
  115531. };
  115532. static static_codebook _huff_book__44c3_s_short = {
  115533. 2, 100,
  115534. _huff_lengthlist__44c3_s_short,
  115535. 0, 0, 0, 0, 0,
  115536. NULL,
  115537. NULL,
  115538. NULL,
  115539. NULL,
  115540. 0
  115541. };
  115542. static long _huff_lengthlist__44c4_s_long[] = {
  115543. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  115544. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  115545. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  115546. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  115547. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  115548. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  115549. 9, 8, 7, 7,
  115550. };
  115551. static static_codebook _huff_book__44c4_s_long = {
  115552. 2, 100,
  115553. _huff_lengthlist__44c4_s_long,
  115554. 0, 0, 0, 0, 0,
  115555. NULL,
  115556. NULL,
  115557. NULL,
  115558. NULL,
  115559. 0
  115560. };
  115561. static long _vq_quantlist__44c4_s_p1_0[] = {
  115562. 1,
  115563. 0,
  115564. 2,
  115565. };
  115566. static long _vq_lengthlist__44c4_s_p1_0[] = {
  115567. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  115568. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  115573. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  115578. 0, 0, 0, 0, 7, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  115582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  115587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  115592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 7, 7, 0, 0, 0, 0,
  115613. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  115618. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  115623. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115628. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115633. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115659. 0, 0, 0, 0, 7, 8, 8, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115664. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115669. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115977. 0,
  115978. };
  115979. static float _vq_quantthresh__44c4_s_p1_0[] = {
  115980. -0.5, 0.5,
  115981. };
  115982. static long _vq_quantmap__44c4_s_p1_0[] = {
  115983. 1, 0, 2,
  115984. };
  115985. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  115986. _vq_quantthresh__44c4_s_p1_0,
  115987. _vq_quantmap__44c4_s_p1_0,
  115988. 3,
  115989. 3
  115990. };
  115991. static static_codebook _44c4_s_p1_0 = {
  115992. 8, 6561,
  115993. _vq_lengthlist__44c4_s_p1_0,
  115994. 1, -535822336, 1611661312, 2, 0,
  115995. _vq_quantlist__44c4_s_p1_0,
  115996. NULL,
  115997. &_vq_auxt__44c4_s_p1_0,
  115998. NULL,
  115999. 0
  116000. };
  116001. static long _vq_quantlist__44c4_s_p2_0[] = {
  116002. 2,
  116003. 1,
  116004. 3,
  116005. 0,
  116006. 4,
  116007. };
  116008. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116009. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116010. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116011. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116012. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116013. 0, 0,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116018. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116019. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116020. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116021. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116026. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116027. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116028. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116034. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116035. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116036. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116048. 0,
  116049. };
  116050. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116051. -1.5, -0.5, 0.5, 1.5,
  116052. };
  116053. static long _vq_quantmap__44c4_s_p2_0[] = {
  116054. 3, 1, 0, 2, 4,
  116055. };
  116056. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116057. _vq_quantthresh__44c4_s_p2_0,
  116058. _vq_quantmap__44c4_s_p2_0,
  116059. 5,
  116060. 5
  116061. };
  116062. static static_codebook _44c4_s_p2_0 = {
  116063. 4, 625,
  116064. _vq_lengthlist__44c4_s_p2_0,
  116065. 1, -533725184, 1611661312, 3, 0,
  116066. _vq_quantlist__44c4_s_p2_0,
  116067. NULL,
  116068. &_vq_auxt__44c4_s_p2_0,
  116069. NULL,
  116070. 0
  116071. };
  116072. static long _vq_quantlist__44c4_s_p3_0[] = {
  116073. 2,
  116074. 1,
  116075. 3,
  116076. 0,
  116077. 4,
  116078. };
  116079. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116080. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116083. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116086. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116119. 0,
  116120. };
  116121. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116122. -1.5, -0.5, 0.5, 1.5,
  116123. };
  116124. static long _vq_quantmap__44c4_s_p3_0[] = {
  116125. 3, 1, 0, 2, 4,
  116126. };
  116127. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116128. _vq_quantthresh__44c4_s_p3_0,
  116129. _vq_quantmap__44c4_s_p3_0,
  116130. 5,
  116131. 5
  116132. };
  116133. static static_codebook _44c4_s_p3_0 = {
  116134. 4, 625,
  116135. _vq_lengthlist__44c4_s_p3_0,
  116136. 1, -533725184, 1611661312, 3, 0,
  116137. _vq_quantlist__44c4_s_p3_0,
  116138. NULL,
  116139. &_vq_auxt__44c4_s_p3_0,
  116140. NULL,
  116141. 0
  116142. };
  116143. static long _vq_quantlist__44c4_s_p4_0[] = {
  116144. 4,
  116145. 3,
  116146. 5,
  116147. 2,
  116148. 6,
  116149. 1,
  116150. 7,
  116151. 0,
  116152. 8,
  116153. };
  116154. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116155. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116156. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116157. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116158. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116159. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116160. 0,
  116161. };
  116162. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116163. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116164. };
  116165. static long _vq_quantmap__44c4_s_p4_0[] = {
  116166. 7, 5, 3, 1, 0, 2, 4, 6,
  116167. 8,
  116168. };
  116169. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116170. _vq_quantthresh__44c4_s_p4_0,
  116171. _vq_quantmap__44c4_s_p4_0,
  116172. 9,
  116173. 9
  116174. };
  116175. static static_codebook _44c4_s_p4_0 = {
  116176. 2, 81,
  116177. _vq_lengthlist__44c4_s_p4_0,
  116178. 1, -531628032, 1611661312, 4, 0,
  116179. _vq_quantlist__44c4_s_p4_0,
  116180. NULL,
  116181. &_vq_auxt__44c4_s_p4_0,
  116182. NULL,
  116183. 0
  116184. };
  116185. static long _vq_quantlist__44c4_s_p5_0[] = {
  116186. 4,
  116187. 3,
  116188. 5,
  116189. 2,
  116190. 6,
  116191. 1,
  116192. 7,
  116193. 0,
  116194. 8,
  116195. };
  116196. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116197. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116198. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116199. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116200. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116201. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116202. 10,
  116203. };
  116204. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116205. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116206. };
  116207. static long _vq_quantmap__44c4_s_p5_0[] = {
  116208. 7, 5, 3, 1, 0, 2, 4, 6,
  116209. 8,
  116210. };
  116211. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116212. _vq_quantthresh__44c4_s_p5_0,
  116213. _vq_quantmap__44c4_s_p5_0,
  116214. 9,
  116215. 9
  116216. };
  116217. static static_codebook _44c4_s_p5_0 = {
  116218. 2, 81,
  116219. _vq_lengthlist__44c4_s_p5_0,
  116220. 1, -531628032, 1611661312, 4, 0,
  116221. _vq_quantlist__44c4_s_p5_0,
  116222. NULL,
  116223. &_vq_auxt__44c4_s_p5_0,
  116224. NULL,
  116225. 0
  116226. };
  116227. static long _vq_quantlist__44c4_s_p6_0[] = {
  116228. 8,
  116229. 7,
  116230. 9,
  116231. 6,
  116232. 10,
  116233. 5,
  116234. 11,
  116235. 4,
  116236. 12,
  116237. 3,
  116238. 13,
  116239. 2,
  116240. 14,
  116241. 1,
  116242. 15,
  116243. 0,
  116244. 16,
  116245. };
  116246. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116247. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116248. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116249. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116250. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116251. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116252. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116253. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116254. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116255. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116256. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116257. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116258. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116259. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116260. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116261. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116262. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116263. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116264. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116265. 13,
  116266. };
  116267. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116268. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116269. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116270. };
  116271. static long _vq_quantmap__44c4_s_p6_0[] = {
  116272. 15, 13, 11, 9, 7, 5, 3, 1,
  116273. 0, 2, 4, 6, 8, 10, 12, 14,
  116274. 16,
  116275. };
  116276. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116277. _vq_quantthresh__44c4_s_p6_0,
  116278. _vq_quantmap__44c4_s_p6_0,
  116279. 17,
  116280. 17
  116281. };
  116282. static static_codebook _44c4_s_p6_0 = {
  116283. 2, 289,
  116284. _vq_lengthlist__44c4_s_p6_0,
  116285. 1, -529530880, 1611661312, 5, 0,
  116286. _vq_quantlist__44c4_s_p6_0,
  116287. NULL,
  116288. &_vq_auxt__44c4_s_p6_0,
  116289. NULL,
  116290. 0
  116291. };
  116292. static long _vq_quantlist__44c4_s_p7_0[] = {
  116293. 1,
  116294. 0,
  116295. 2,
  116296. };
  116297. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116298. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116299. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116300. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116301. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116302. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116303. 10,
  116304. };
  116305. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116306. -5.5, 5.5,
  116307. };
  116308. static long _vq_quantmap__44c4_s_p7_0[] = {
  116309. 1, 0, 2,
  116310. };
  116311. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116312. _vq_quantthresh__44c4_s_p7_0,
  116313. _vq_quantmap__44c4_s_p7_0,
  116314. 3,
  116315. 3
  116316. };
  116317. static static_codebook _44c4_s_p7_0 = {
  116318. 4, 81,
  116319. _vq_lengthlist__44c4_s_p7_0,
  116320. 1, -529137664, 1618345984, 2, 0,
  116321. _vq_quantlist__44c4_s_p7_0,
  116322. NULL,
  116323. &_vq_auxt__44c4_s_p7_0,
  116324. NULL,
  116325. 0
  116326. };
  116327. static long _vq_quantlist__44c4_s_p7_1[] = {
  116328. 5,
  116329. 4,
  116330. 6,
  116331. 3,
  116332. 7,
  116333. 2,
  116334. 8,
  116335. 1,
  116336. 9,
  116337. 0,
  116338. 10,
  116339. };
  116340. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116341. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116342. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116343. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116344. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116345. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116346. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116347. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116348. 10,10,10, 8, 8, 8, 8, 9, 9,
  116349. };
  116350. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116351. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116352. 3.5, 4.5,
  116353. };
  116354. static long _vq_quantmap__44c4_s_p7_1[] = {
  116355. 9, 7, 5, 3, 1, 0, 2, 4,
  116356. 6, 8, 10,
  116357. };
  116358. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116359. _vq_quantthresh__44c4_s_p7_1,
  116360. _vq_quantmap__44c4_s_p7_1,
  116361. 11,
  116362. 11
  116363. };
  116364. static static_codebook _44c4_s_p7_1 = {
  116365. 2, 121,
  116366. _vq_lengthlist__44c4_s_p7_1,
  116367. 1, -531365888, 1611661312, 4, 0,
  116368. _vq_quantlist__44c4_s_p7_1,
  116369. NULL,
  116370. &_vq_auxt__44c4_s_p7_1,
  116371. NULL,
  116372. 0
  116373. };
  116374. static long _vq_quantlist__44c4_s_p8_0[] = {
  116375. 6,
  116376. 5,
  116377. 7,
  116378. 4,
  116379. 8,
  116380. 3,
  116381. 9,
  116382. 2,
  116383. 10,
  116384. 1,
  116385. 11,
  116386. 0,
  116387. 12,
  116388. };
  116389. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116390. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116391. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116392. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116393. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116394. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116395. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116396. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116397. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116398. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116399. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116400. 0,13,12,12,12,12,12,13,13,
  116401. };
  116402. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116403. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116404. 12.5, 17.5, 22.5, 27.5,
  116405. };
  116406. static long _vq_quantmap__44c4_s_p8_0[] = {
  116407. 11, 9, 7, 5, 3, 1, 0, 2,
  116408. 4, 6, 8, 10, 12,
  116409. };
  116410. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116411. _vq_quantthresh__44c4_s_p8_0,
  116412. _vq_quantmap__44c4_s_p8_0,
  116413. 13,
  116414. 13
  116415. };
  116416. static static_codebook _44c4_s_p8_0 = {
  116417. 2, 169,
  116418. _vq_lengthlist__44c4_s_p8_0,
  116419. 1, -526516224, 1616117760, 4, 0,
  116420. _vq_quantlist__44c4_s_p8_0,
  116421. NULL,
  116422. &_vq_auxt__44c4_s_p8_0,
  116423. NULL,
  116424. 0
  116425. };
  116426. static long _vq_quantlist__44c4_s_p8_1[] = {
  116427. 2,
  116428. 1,
  116429. 3,
  116430. 0,
  116431. 4,
  116432. };
  116433. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116434. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116435. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116436. };
  116437. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116438. -1.5, -0.5, 0.5, 1.5,
  116439. };
  116440. static long _vq_quantmap__44c4_s_p8_1[] = {
  116441. 3, 1, 0, 2, 4,
  116442. };
  116443. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116444. _vq_quantthresh__44c4_s_p8_1,
  116445. _vq_quantmap__44c4_s_p8_1,
  116446. 5,
  116447. 5
  116448. };
  116449. static static_codebook _44c4_s_p8_1 = {
  116450. 2, 25,
  116451. _vq_lengthlist__44c4_s_p8_1,
  116452. 1, -533725184, 1611661312, 3, 0,
  116453. _vq_quantlist__44c4_s_p8_1,
  116454. NULL,
  116455. &_vq_auxt__44c4_s_p8_1,
  116456. NULL,
  116457. 0
  116458. };
  116459. static long _vq_quantlist__44c4_s_p9_0[] = {
  116460. 6,
  116461. 5,
  116462. 7,
  116463. 4,
  116464. 8,
  116465. 3,
  116466. 9,
  116467. 2,
  116468. 10,
  116469. 1,
  116470. 11,
  116471. 0,
  116472. 12,
  116473. };
  116474. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116475. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116476. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116477. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116478. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116479. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116480. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116481. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116482. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116483. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116484. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116485. 12,12,12,12,12,12,12,12,12,
  116486. };
  116487. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116488. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116489. 787.5, 1102.5, 1417.5, 1732.5,
  116490. };
  116491. static long _vq_quantmap__44c4_s_p9_0[] = {
  116492. 11, 9, 7, 5, 3, 1, 0, 2,
  116493. 4, 6, 8, 10, 12,
  116494. };
  116495. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116496. _vq_quantthresh__44c4_s_p9_0,
  116497. _vq_quantmap__44c4_s_p9_0,
  116498. 13,
  116499. 13
  116500. };
  116501. static static_codebook _44c4_s_p9_0 = {
  116502. 2, 169,
  116503. _vq_lengthlist__44c4_s_p9_0,
  116504. 1, -513964032, 1628680192, 4, 0,
  116505. _vq_quantlist__44c4_s_p9_0,
  116506. NULL,
  116507. &_vq_auxt__44c4_s_p9_0,
  116508. NULL,
  116509. 0
  116510. };
  116511. static long _vq_quantlist__44c4_s_p9_1[] = {
  116512. 7,
  116513. 6,
  116514. 8,
  116515. 5,
  116516. 9,
  116517. 4,
  116518. 10,
  116519. 3,
  116520. 11,
  116521. 2,
  116522. 12,
  116523. 1,
  116524. 13,
  116525. 0,
  116526. 14,
  116527. };
  116528. static long _vq_lengthlist__44c4_s_p9_1[] = {
  116529. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  116530. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  116531. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  116532. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  116533. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  116534. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  116535. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  116536. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  116537. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  116538. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  116539. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  116540. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  116541. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  116542. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  116543. 15,
  116544. };
  116545. static float _vq_quantthresh__44c4_s_p9_1[] = {
  116546. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  116547. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  116548. };
  116549. static long _vq_quantmap__44c4_s_p9_1[] = {
  116550. 13, 11, 9, 7, 5, 3, 1, 0,
  116551. 2, 4, 6, 8, 10, 12, 14,
  116552. };
  116553. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  116554. _vq_quantthresh__44c4_s_p9_1,
  116555. _vq_quantmap__44c4_s_p9_1,
  116556. 15,
  116557. 15
  116558. };
  116559. static static_codebook _44c4_s_p9_1 = {
  116560. 2, 225,
  116561. _vq_lengthlist__44c4_s_p9_1,
  116562. 1, -520986624, 1620377600, 4, 0,
  116563. _vq_quantlist__44c4_s_p9_1,
  116564. NULL,
  116565. &_vq_auxt__44c4_s_p9_1,
  116566. NULL,
  116567. 0
  116568. };
  116569. static long _vq_quantlist__44c4_s_p9_2[] = {
  116570. 10,
  116571. 9,
  116572. 11,
  116573. 8,
  116574. 12,
  116575. 7,
  116576. 13,
  116577. 6,
  116578. 14,
  116579. 5,
  116580. 15,
  116581. 4,
  116582. 16,
  116583. 3,
  116584. 17,
  116585. 2,
  116586. 18,
  116587. 1,
  116588. 19,
  116589. 0,
  116590. 20,
  116591. };
  116592. static long _vq_lengthlist__44c4_s_p9_2[] = {
  116593. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  116594. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  116595. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  116596. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  116597. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  116598. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  116599. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  116600. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  116601. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  116602. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  116603. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  116604. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  116605. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  116606. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  116607. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  116608. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  116609. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  116610. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  116611. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  116612. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  116613. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  116614. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  116615. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  116616. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  116617. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  116618. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  116619. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  116620. 10,10,10,10,10,10,10,10,10,
  116621. };
  116622. static float _vq_quantthresh__44c4_s_p9_2[] = {
  116623. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  116624. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  116625. 6.5, 7.5, 8.5, 9.5,
  116626. };
  116627. static long _vq_quantmap__44c4_s_p9_2[] = {
  116628. 19, 17, 15, 13, 11, 9, 7, 5,
  116629. 3, 1, 0, 2, 4, 6, 8, 10,
  116630. 12, 14, 16, 18, 20,
  116631. };
  116632. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  116633. _vq_quantthresh__44c4_s_p9_2,
  116634. _vq_quantmap__44c4_s_p9_2,
  116635. 21,
  116636. 21
  116637. };
  116638. static static_codebook _44c4_s_p9_2 = {
  116639. 2, 441,
  116640. _vq_lengthlist__44c4_s_p9_2,
  116641. 1, -529268736, 1611661312, 5, 0,
  116642. _vq_quantlist__44c4_s_p9_2,
  116643. NULL,
  116644. &_vq_auxt__44c4_s_p9_2,
  116645. NULL,
  116646. 0
  116647. };
  116648. static long _huff_lengthlist__44c4_s_short[] = {
  116649. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  116650. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  116651. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  116652. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  116653. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  116654. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  116655. 7, 9,12,17,
  116656. };
  116657. static static_codebook _huff_book__44c4_s_short = {
  116658. 2, 100,
  116659. _huff_lengthlist__44c4_s_short,
  116660. 0, 0, 0, 0, 0,
  116661. NULL,
  116662. NULL,
  116663. NULL,
  116664. NULL,
  116665. 0
  116666. };
  116667. static long _huff_lengthlist__44c5_s_long[] = {
  116668. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  116669. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  116670. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  116671. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  116672. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  116673. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  116674. 9, 8, 7, 7,
  116675. };
  116676. static static_codebook _huff_book__44c5_s_long = {
  116677. 2, 100,
  116678. _huff_lengthlist__44c5_s_long,
  116679. 0, 0, 0, 0, 0,
  116680. NULL,
  116681. NULL,
  116682. NULL,
  116683. NULL,
  116684. 0
  116685. };
  116686. static long _vq_quantlist__44c5_s_p1_0[] = {
  116687. 1,
  116688. 0,
  116689. 2,
  116690. };
  116691. static long _vq_lengthlist__44c5_s_p1_0[] = {
  116692. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  116693. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  116698. 0, 0, 0, 7, 8, 9, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  116703. 0, 0, 0, 0, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  116707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  116712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  116717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 4, 7, 7, 0, 0, 0, 0,
  116738. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  116743. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  116748. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116753. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116758. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  116784. 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  116789. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  116794. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117102. 0,
  117103. };
  117104. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117105. -0.5, 0.5,
  117106. };
  117107. static long _vq_quantmap__44c5_s_p1_0[] = {
  117108. 1, 0, 2,
  117109. };
  117110. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117111. _vq_quantthresh__44c5_s_p1_0,
  117112. _vq_quantmap__44c5_s_p1_0,
  117113. 3,
  117114. 3
  117115. };
  117116. static static_codebook _44c5_s_p1_0 = {
  117117. 8, 6561,
  117118. _vq_lengthlist__44c5_s_p1_0,
  117119. 1, -535822336, 1611661312, 2, 0,
  117120. _vq_quantlist__44c5_s_p1_0,
  117121. NULL,
  117122. &_vq_auxt__44c5_s_p1_0,
  117123. NULL,
  117124. 0
  117125. };
  117126. static long _vq_quantlist__44c5_s_p2_0[] = {
  117127. 2,
  117128. 1,
  117129. 3,
  117130. 0,
  117131. 4,
  117132. };
  117133. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117134. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117135. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117136. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117137. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117138. 0, 0,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117143. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117144. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117145. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117146. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117151. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117152. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117153. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117159. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117160. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117161. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117173. 0,
  117174. };
  117175. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117176. -1.5, -0.5, 0.5, 1.5,
  117177. };
  117178. static long _vq_quantmap__44c5_s_p2_0[] = {
  117179. 3, 1, 0, 2, 4,
  117180. };
  117181. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117182. _vq_quantthresh__44c5_s_p2_0,
  117183. _vq_quantmap__44c5_s_p2_0,
  117184. 5,
  117185. 5
  117186. };
  117187. static static_codebook _44c5_s_p2_0 = {
  117188. 4, 625,
  117189. _vq_lengthlist__44c5_s_p2_0,
  117190. 1, -533725184, 1611661312, 3, 0,
  117191. _vq_quantlist__44c5_s_p2_0,
  117192. NULL,
  117193. &_vq_auxt__44c5_s_p2_0,
  117194. NULL,
  117195. 0
  117196. };
  117197. static long _vq_quantlist__44c5_s_p3_0[] = {
  117198. 2,
  117199. 1,
  117200. 3,
  117201. 0,
  117202. 4,
  117203. };
  117204. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117205. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117208. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117211. 0, 0, 0, 0, 5, 6, 6, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117244. 0,
  117245. };
  117246. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117247. -1.5, -0.5, 0.5, 1.5,
  117248. };
  117249. static long _vq_quantmap__44c5_s_p3_0[] = {
  117250. 3, 1, 0, 2, 4,
  117251. };
  117252. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117253. _vq_quantthresh__44c5_s_p3_0,
  117254. _vq_quantmap__44c5_s_p3_0,
  117255. 5,
  117256. 5
  117257. };
  117258. static static_codebook _44c5_s_p3_0 = {
  117259. 4, 625,
  117260. _vq_lengthlist__44c5_s_p3_0,
  117261. 1, -533725184, 1611661312, 3, 0,
  117262. _vq_quantlist__44c5_s_p3_0,
  117263. NULL,
  117264. &_vq_auxt__44c5_s_p3_0,
  117265. NULL,
  117266. 0
  117267. };
  117268. static long _vq_quantlist__44c5_s_p4_0[] = {
  117269. 4,
  117270. 3,
  117271. 5,
  117272. 2,
  117273. 6,
  117274. 1,
  117275. 7,
  117276. 0,
  117277. 8,
  117278. };
  117279. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117280. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117281. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117282. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117283. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117284. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117285. 0,
  117286. };
  117287. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117288. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117289. };
  117290. static long _vq_quantmap__44c5_s_p4_0[] = {
  117291. 7, 5, 3, 1, 0, 2, 4, 6,
  117292. 8,
  117293. };
  117294. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117295. _vq_quantthresh__44c5_s_p4_0,
  117296. _vq_quantmap__44c5_s_p4_0,
  117297. 9,
  117298. 9
  117299. };
  117300. static static_codebook _44c5_s_p4_0 = {
  117301. 2, 81,
  117302. _vq_lengthlist__44c5_s_p4_0,
  117303. 1, -531628032, 1611661312, 4, 0,
  117304. _vq_quantlist__44c5_s_p4_0,
  117305. NULL,
  117306. &_vq_auxt__44c5_s_p4_0,
  117307. NULL,
  117308. 0
  117309. };
  117310. static long _vq_quantlist__44c5_s_p5_0[] = {
  117311. 4,
  117312. 3,
  117313. 5,
  117314. 2,
  117315. 6,
  117316. 1,
  117317. 7,
  117318. 0,
  117319. 8,
  117320. };
  117321. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117322. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117323. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117324. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117325. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117326. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117327. 10,
  117328. };
  117329. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117330. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117331. };
  117332. static long _vq_quantmap__44c5_s_p5_0[] = {
  117333. 7, 5, 3, 1, 0, 2, 4, 6,
  117334. 8,
  117335. };
  117336. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117337. _vq_quantthresh__44c5_s_p5_0,
  117338. _vq_quantmap__44c5_s_p5_0,
  117339. 9,
  117340. 9
  117341. };
  117342. static static_codebook _44c5_s_p5_0 = {
  117343. 2, 81,
  117344. _vq_lengthlist__44c5_s_p5_0,
  117345. 1, -531628032, 1611661312, 4, 0,
  117346. _vq_quantlist__44c5_s_p5_0,
  117347. NULL,
  117348. &_vq_auxt__44c5_s_p5_0,
  117349. NULL,
  117350. 0
  117351. };
  117352. static long _vq_quantlist__44c5_s_p6_0[] = {
  117353. 8,
  117354. 7,
  117355. 9,
  117356. 6,
  117357. 10,
  117358. 5,
  117359. 11,
  117360. 4,
  117361. 12,
  117362. 3,
  117363. 13,
  117364. 2,
  117365. 14,
  117366. 1,
  117367. 15,
  117368. 0,
  117369. 16,
  117370. };
  117371. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117372. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117373. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117374. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117375. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117376. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117377. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117378. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117379. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117380. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117381. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117382. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117383. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117384. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117385. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117386. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117387. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117388. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117389. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117390. 13,
  117391. };
  117392. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117393. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117394. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117395. };
  117396. static long _vq_quantmap__44c5_s_p6_0[] = {
  117397. 15, 13, 11, 9, 7, 5, 3, 1,
  117398. 0, 2, 4, 6, 8, 10, 12, 14,
  117399. 16,
  117400. };
  117401. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117402. _vq_quantthresh__44c5_s_p6_0,
  117403. _vq_quantmap__44c5_s_p6_0,
  117404. 17,
  117405. 17
  117406. };
  117407. static static_codebook _44c5_s_p6_0 = {
  117408. 2, 289,
  117409. _vq_lengthlist__44c5_s_p6_0,
  117410. 1, -529530880, 1611661312, 5, 0,
  117411. _vq_quantlist__44c5_s_p6_0,
  117412. NULL,
  117413. &_vq_auxt__44c5_s_p6_0,
  117414. NULL,
  117415. 0
  117416. };
  117417. static long _vq_quantlist__44c5_s_p7_0[] = {
  117418. 1,
  117419. 0,
  117420. 2,
  117421. };
  117422. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117423. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117424. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117425. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117426. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117427. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117428. 10,
  117429. };
  117430. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117431. -5.5, 5.5,
  117432. };
  117433. static long _vq_quantmap__44c5_s_p7_0[] = {
  117434. 1, 0, 2,
  117435. };
  117436. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117437. _vq_quantthresh__44c5_s_p7_0,
  117438. _vq_quantmap__44c5_s_p7_0,
  117439. 3,
  117440. 3
  117441. };
  117442. static static_codebook _44c5_s_p7_0 = {
  117443. 4, 81,
  117444. _vq_lengthlist__44c5_s_p7_0,
  117445. 1, -529137664, 1618345984, 2, 0,
  117446. _vq_quantlist__44c5_s_p7_0,
  117447. NULL,
  117448. &_vq_auxt__44c5_s_p7_0,
  117449. NULL,
  117450. 0
  117451. };
  117452. static long _vq_quantlist__44c5_s_p7_1[] = {
  117453. 5,
  117454. 4,
  117455. 6,
  117456. 3,
  117457. 7,
  117458. 2,
  117459. 8,
  117460. 1,
  117461. 9,
  117462. 0,
  117463. 10,
  117464. };
  117465. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117466. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117467. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117468. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117469. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117470. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117471. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117472. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117473. 10,10,10, 8, 8, 8, 8, 8, 8,
  117474. };
  117475. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117476. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117477. 3.5, 4.5,
  117478. };
  117479. static long _vq_quantmap__44c5_s_p7_1[] = {
  117480. 9, 7, 5, 3, 1, 0, 2, 4,
  117481. 6, 8, 10,
  117482. };
  117483. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117484. _vq_quantthresh__44c5_s_p7_1,
  117485. _vq_quantmap__44c5_s_p7_1,
  117486. 11,
  117487. 11
  117488. };
  117489. static static_codebook _44c5_s_p7_1 = {
  117490. 2, 121,
  117491. _vq_lengthlist__44c5_s_p7_1,
  117492. 1, -531365888, 1611661312, 4, 0,
  117493. _vq_quantlist__44c5_s_p7_1,
  117494. NULL,
  117495. &_vq_auxt__44c5_s_p7_1,
  117496. NULL,
  117497. 0
  117498. };
  117499. static long _vq_quantlist__44c5_s_p8_0[] = {
  117500. 6,
  117501. 5,
  117502. 7,
  117503. 4,
  117504. 8,
  117505. 3,
  117506. 9,
  117507. 2,
  117508. 10,
  117509. 1,
  117510. 11,
  117511. 0,
  117512. 12,
  117513. };
  117514. static long _vq_lengthlist__44c5_s_p8_0[] = {
  117515. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  117516. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  117517. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  117518. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  117519. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  117520. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  117521. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  117522. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  117523. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  117524. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  117525. 0,12,12,12,12,12,12,13,13,
  117526. };
  117527. static float _vq_quantthresh__44c5_s_p8_0[] = {
  117528. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  117529. 12.5, 17.5, 22.5, 27.5,
  117530. };
  117531. static long _vq_quantmap__44c5_s_p8_0[] = {
  117532. 11, 9, 7, 5, 3, 1, 0, 2,
  117533. 4, 6, 8, 10, 12,
  117534. };
  117535. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  117536. _vq_quantthresh__44c5_s_p8_0,
  117537. _vq_quantmap__44c5_s_p8_0,
  117538. 13,
  117539. 13
  117540. };
  117541. static static_codebook _44c5_s_p8_0 = {
  117542. 2, 169,
  117543. _vq_lengthlist__44c5_s_p8_0,
  117544. 1, -526516224, 1616117760, 4, 0,
  117545. _vq_quantlist__44c5_s_p8_0,
  117546. NULL,
  117547. &_vq_auxt__44c5_s_p8_0,
  117548. NULL,
  117549. 0
  117550. };
  117551. static long _vq_quantlist__44c5_s_p8_1[] = {
  117552. 2,
  117553. 1,
  117554. 3,
  117555. 0,
  117556. 4,
  117557. };
  117558. static long _vq_lengthlist__44c5_s_p8_1[] = {
  117559. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  117560. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  117561. };
  117562. static float _vq_quantthresh__44c5_s_p8_1[] = {
  117563. -1.5, -0.5, 0.5, 1.5,
  117564. };
  117565. static long _vq_quantmap__44c5_s_p8_1[] = {
  117566. 3, 1, 0, 2, 4,
  117567. };
  117568. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  117569. _vq_quantthresh__44c5_s_p8_1,
  117570. _vq_quantmap__44c5_s_p8_1,
  117571. 5,
  117572. 5
  117573. };
  117574. static static_codebook _44c5_s_p8_1 = {
  117575. 2, 25,
  117576. _vq_lengthlist__44c5_s_p8_1,
  117577. 1, -533725184, 1611661312, 3, 0,
  117578. _vq_quantlist__44c5_s_p8_1,
  117579. NULL,
  117580. &_vq_auxt__44c5_s_p8_1,
  117581. NULL,
  117582. 0
  117583. };
  117584. static long _vq_quantlist__44c5_s_p9_0[] = {
  117585. 7,
  117586. 6,
  117587. 8,
  117588. 5,
  117589. 9,
  117590. 4,
  117591. 10,
  117592. 3,
  117593. 11,
  117594. 2,
  117595. 12,
  117596. 1,
  117597. 13,
  117598. 0,
  117599. 14,
  117600. };
  117601. static long _vq_lengthlist__44c5_s_p9_0[] = {
  117602. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  117603. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  117604. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117605. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117606. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117607. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117608. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117609. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117610. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117611. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117612. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117613. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117614. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  117615. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  117616. 12,
  117617. };
  117618. static float _vq_quantthresh__44c5_s_p9_0[] = {
  117619. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  117620. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  117621. };
  117622. static long _vq_quantmap__44c5_s_p9_0[] = {
  117623. 13, 11, 9, 7, 5, 3, 1, 0,
  117624. 2, 4, 6, 8, 10, 12, 14,
  117625. };
  117626. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  117627. _vq_quantthresh__44c5_s_p9_0,
  117628. _vq_quantmap__44c5_s_p9_0,
  117629. 15,
  117630. 15
  117631. };
  117632. static static_codebook _44c5_s_p9_0 = {
  117633. 2, 225,
  117634. _vq_lengthlist__44c5_s_p9_0,
  117635. 1, -512522752, 1628852224, 4, 0,
  117636. _vq_quantlist__44c5_s_p9_0,
  117637. NULL,
  117638. &_vq_auxt__44c5_s_p9_0,
  117639. NULL,
  117640. 0
  117641. };
  117642. static long _vq_quantlist__44c5_s_p9_1[] = {
  117643. 8,
  117644. 7,
  117645. 9,
  117646. 6,
  117647. 10,
  117648. 5,
  117649. 11,
  117650. 4,
  117651. 12,
  117652. 3,
  117653. 13,
  117654. 2,
  117655. 14,
  117656. 1,
  117657. 15,
  117658. 0,
  117659. 16,
  117660. };
  117661. static long _vq_lengthlist__44c5_s_p9_1[] = {
  117662. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  117663. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  117664. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  117665. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  117666. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  117667. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  117668. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  117669. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  117670. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  117671. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  117672. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  117673. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  117674. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  117675. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  117676. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  117677. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  117678. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  117679. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  117680. 15,
  117681. };
  117682. static float _vq_quantthresh__44c5_s_p9_1[] = {
  117683. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  117684. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  117685. };
  117686. static long _vq_quantmap__44c5_s_p9_1[] = {
  117687. 15, 13, 11, 9, 7, 5, 3, 1,
  117688. 0, 2, 4, 6, 8, 10, 12, 14,
  117689. 16,
  117690. };
  117691. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  117692. _vq_quantthresh__44c5_s_p9_1,
  117693. _vq_quantmap__44c5_s_p9_1,
  117694. 17,
  117695. 17
  117696. };
  117697. static static_codebook _44c5_s_p9_1 = {
  117698. 2, 289,
  117699. _vq_lengthlist__44c5_s_p9_1,
  117700. 1, -520814592, 1620377600, 5, 0,
  117701. _vq_quantlist__44c5_s_p9_1,
  117702. NULL,
  117703. &_vq_auxt__44c5_s_p9_1,
  117704. NULL,
  117705. 0
  117706. };
  117707. static long _vq_quantlist__44c5_s_p9_2[] = {
  117708. 10,
  117709. 9,
  117710. 11,
  117711. 8,
  117712. 12,
  117713. 7,
  117714. 13,
  117715. 6,
  117716. 14,
  117717. 5,
  117718. 15,
  117719. 4,
  117720. 16,
  117721. 3,
  117722. 17,
  117723. 2,
  117724. 18,
  117725. 1,
  117726. 19,
  117727. 0,
  117728. 20,
  117729. };
  117730. static long _vq_lengthlist__44c5_s_p9_2[] = {
  117731. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117732. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  117733. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  117734. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  117735. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  117736. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  117737. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  117738. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  117739. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  117740. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  117741. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117742. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  117743. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  117744. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  117745. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  117746. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  117747. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117748. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117749. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  117750. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  117751. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117752. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117753. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  117754. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  117755. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  117756. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117757. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  117758. 10,10,10,10,10,10,10,10,10,
  117759. };
  117760. static float _vq_quantthresh__44c5_s_p9_2[] = {
  117761. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117762. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117763. 6.5, 7.5, 8.5, 9.5,
  117764. };
  117765. static long _vq_quantmap__44c5_s_p9_2[] = {
  117766. 19, 17, 15, 13, 11, 9, 7, 5,
  117767. 3, 1, 0, 2, 4, 6, 8, 10,
  117768. 12, 14, 16, 18, 20,
  117769. };
  117770. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  117771. _vq_quantthresh__44c5_s_p9_2,
  117772. _vq_quantmap__44c5_s_p9_2,
  117773. 21,
  117774. 21
  117775. };
  117776. static static_codebook _44c5_s_p9_2 = {
  117777. 2, 441,
  117778. _vq_lengthlist__44c5_s_p9_2,
  117779. 1, -529268736, 1611661312, 5, 0,
  117780. _vq_quantlist__44c5_s_p9_2,
  117781. NULL,
  117782. &_vq_auxt__44c5_s_p9_2,
  117783. NULL,
  117784. 0
  117785. };
  117786. static long _huff_lengthlist__44c5_s_short[] = {
  117787. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  117788. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  117789. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  117790. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  117791. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  117792. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  117793. 6, 8,11,16,
  117794. };
  117795. static static_codebook _huff_book__44c5_s_short = {
  117796. 2, 100,
  117797. _huff_lengthlist__44c5_s_short,
  117798. 0, 0, 0, 0, 0,
  117799. NULL,
  117800. NULL,
  117801. NULL,
  117802. NULL,
  117803. 0
  117804. };
  117805. static long _huff_lengthlist__44c6_s_long[] = {
  117806. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  117807. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  117808. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  117809. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  117810. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  117811. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  117812. 11,10,10,12,
  117813. };
  117814. static static_codebook _huff_book__44c6_s_long = {
  117815. 2, 100,
  117816. _huff_lengthlist__44c6_s_long,
  117817. 0, 0, 0, 0, 0,
  117818. NULL,
  117819. NULL,
  117820. NULL,
  117821. NULL,
  117822. 0
  117823. };
  117824. static long _vq_quantlist__44c6_s_p1_0[] = {
  117825. 1,
  117826. 0,
  117827. 2,
  117828. };
  117829. static long _vq_lengthlist__44c6_s_p1_0[] = {
  117830. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  117831. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  117832. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  117833. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  117834. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  117835. 8,
  117836. };
  117837. static float _vq_quantthresh__44c6_s_p1_0[] = {
  117838. -0.5, 0.5,
  117839. };
  117840. static long _vq_quantmap__44c6_s_p1_0[] = {
  117841. 1, 0, 2,
  117842. };
  117843. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  117844. _vq_quantthresh__44c6_s_p1_0,
  117845. _vq_quantmap__44c6_s_p1_0,
  117846. 3,
  117847. 3
  117848. };
  117849. static static_codebook _44c6_s_p1_0 = {
  117850. 4, 81,
  117851. _vq_lengthlist__44c6_s_p1_0,
  117852. 1, -535822336, 1611661312, 2, 0,
  117853. _vq_quantlist__44c6_s_p1_0,
  117854. NULL,
  117855. &_vq_auxt__44c6_s_p1_0,
  117856. NULL,
  117857. 0
  117858. };
  117859. static long _vq_quantlist__44c6_s_p2_0[] = {
  117860. 2,
  117861. 1,
  117862. 3,
  117863. 0,
  117864. 4,
  117865. };
  117866. static long _vq_lengthlist__44c6_s_p2_0[] = {
  117867. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  117868. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  117869. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  117870. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  117871. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  117872. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  117873. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  117874. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  117875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117876. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  117877. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  117878. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  117879. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  117880. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  117881. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  117882. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  117883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117884. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  117885. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  117886. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  117887. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  117888. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  117889. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  117890. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117892. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  117893. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  117894. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  117895. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  117896. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  117897. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  117898. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  117903. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  117904. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  117905. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  117906. 13,
  117907. };
  117908. static float _vq_quantthresh__44c6_s_p2_0[] = {
  117909. -1.5, -0.5, 0.5, 1.5,
  117910. };
  117911. static long _vq_quantmap__44c6_s_p2_0[] = {
  117912. 3, 1, 0, 2, 4,
  117913. };
  117914. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  117915. _vq_quantthresh__44c6_s_p2_0,
  117916. _vq_quantmap__44c6_s_p2_0,
  117917. 5,
  117918. 5
  117919. };
  117920. static static_codebook _44c6_s_p2_0 = {
  117921. 4, 625,
  117922. _vq_lengthlist__44c6_s_p2_0,
  117923. 1, -533725184, 1611661312, 3, 0,
  117924. _vq_quantlist__44c6_s_p2_0,
  117925. NULL,
  117926. &_vq_auxt__44c6_s_p2_0,
  117927. NULL,
  117928. 0
  117929. };
  117930. static long _vq_quantlist__44c6_s_p3_0[] = {
  117931. 4,
  117932. 3,
  117933. 5,
  117934. 2,
  117935. 6,
  117936. 1,
  117937. 7,
  117938. 0,
  117939. 8,
  117940. };
  117941. static long _vq_lengthlist__44c6_s_p3_0[] = {
  117942. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117943. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  117944. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  117945. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  117946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117947. 0,
  117948. };
  117949. static float _vq_quantthresh__44c6_s_p3_0[] = {
  117950. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117951. };
  117952. static long _vq_quantmap__44c6_s_p3_0[] = {
  117953. 7, 5, 3, 1, 0, 2, 4, 6,
  117954. 8,
  117955. };
  117956. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  117957. _vq_quantthresh__44c6_s_p3_0,
  117958. _vq_quantmap__44c6_s_p3_0,
  117959. 9,
  117960. 9
  117961. };
  117962. static static_codebook _44c6_s_p3_0 = {
  117963. 2, 81,
  117964. _vq_lengthlist__44c6_s_p3_0,
  117965. 1, -531628032, 1611661312, 4, 0,
  117966. _vq_quantlist__44c6_s_p3_0,
  117967. NULL,
  117968. &_vq_auxt__44c6_s_p3_0,
  117969. NULL,
  117970. 0
  117971. };
  117972. static long _vq_quantlist__44c6_s_p4_0[] = {
  117973. 8,
  117974. 7,
  117975. 9,
  117976. 6,
  117977. 10,
  117978. 5,
  117979. 11,
  117980. 4,
  117981. 12,
  117982. 3,
  117983. 13,
  117984. 2,
  117985. 14,
  117986. 1,
  117987. 15,
  117988. 0,
  117989. 16,
  117990. };
  117991. static long _vq_lengthlist__44c6_s_p4_0[] = {
  117992. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  117993. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  117994. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  117995. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117996. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117997. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117998. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  117999. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118000. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118001. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118010. 0,
  118011. };
  118012. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118013. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118014. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118015. };
  118016. static long _vq_quantmap__44c6_s_p4_0[] = {
  118017. 15, 13, 11, 9, 7, 5, 3, 1,
  118018. 0, 2, 4, 6, 8, 10, 12, 14,
  118019. 16,
  118020. };
  118021. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118022. _vq_quantthresh__44c6_s_p4_0,
  118023. _vq_quantmap__44c6_s_p4_0,
  118024. 17,
  118025. 17
  118026. };
  118027. static static_codebook _44c6_s_p4_0 = {
  118028. 2, 289,
  118029. _vq_lengthlist__44c6_s_p4_0,
  118030. 1, -529530880, 1611661312, 5, 0,
  118031. _vq_quantlist__44c6_s_p4_0,
  118032. NULL,
  118033. &_vq_auxt__44c6_s_p4_0,
  118034. NULL,
  118035. 0
  118036. };
  118037. static long _vq_quantlist__44c6_s_p5_0[] = {
  118038. 1,
  118039. 0,
  118040. 2,
  118041. };
  118042. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118043. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118044. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118045. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118046. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118047. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118048. 12,
  118049. };
  118050. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118051. -5.5, 5.5,
  118052. };
  118053. static long _vq_quantmap__44c6_s_p5_0[] = {
  118054. 1, 0, 2,
  118055. };
  118056. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118057. _vq_quantthresh__44c6_s_p5_0,
  118058. _vq_quantmap__44c6_s_p5_0,
  118059. 3,
  118060. 3
  118061. };
  118062. static static_codebook _44c6_s_p5_0 = {
  118063. 4, 81,
  118064. _vq_lengthlist__44c6_s_p5_0,
  118065. 1, -529137664, 1618345984, 2, 0,
  118066. _vq_quantlist__44c6_s_p5_0,
  118067. NULL,
  118068. &_vq_auxt__44c6_s_p5_0,
  118069. NULL,
  118070. 0
  118071. };
  118072. static long _vq_quantlist__44c6_s_p5_1[] = {
  118073. 5,
  118074. 4,
  118075. 6,
  118076. 3,
  118077. 7,
  118078. 2,
  118079. 8,
  118080. 1,
  118081. 9,
  118082. 0,
  118083. 10,
  118084. };
  118085. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118086. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118087. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118088. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118089. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118090. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118091. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118092. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118093. 11,10,10, 7, 7, 8, 8, 8, 8,
  118094. };
  118095. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118096. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118097. 3.5, 4.5,
  118098. };
  118099. static long _vq_quantmap__44c6_s_p5_1[] = {
  118100. 9, 7, 5, 3, 1, 0, 2, 4,
  118101. 6, 8, 10,
  118102. };
  118103. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118104. _vq_quantthresh__44c6_s_p5_1,
  118105. _vq_quantmap__44c6_s_p5_1,
  118106. 11,
  118107. 11
  118108. };
  118109. static static_codebook _44c6_s_p5_1 = {
  118110. 2, 121,
  118111. _vq_lengthlist__44c6_s_p5_1,
  118112. 1, -531365888, 1611661312, 4, 0,
  118113. _vq_quantlist__44c6_s_p5_1,
  118114. NULL,
  118115. &_vq_auxt__44c6_s_p5_1,
  118116. NULL,
  118117. 0
  118118. };
  118119. static long _vq_quantlist__44c6_s_p6_0[] = {
  118120. 6,
  118121. 5,
  118122. 7,
  118123. 4,
  118124. 8,
  118125. 3,
  118126. 9,
  118127. 2,
  118128. 10,
  118129. 1,
  118130. 11,
  118131. 0,
  118132. 12,
  118133. };
  118134. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118135. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118136. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118137. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118138. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118139. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118140. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118145. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118146. };
  118147. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118148. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118149. 12.5, 17.5, 22.5, 27.5,
  118150. };
  118151. static long _vq_quantmap__44c6_s_p6_0[] = {
  118152. 11, 9, 7, 5, 3, 1, 0, 2,
  118153. 4, 6, 8, 10, 12,
  118154. };
  118155. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118156. _vq_quantthresh__44c6_s_p6_0,
  118157. _vq_quantmap__44c6_s_p6_0,
  118158. 13,
  118159. 13
  118160. };
  118161. static static_codebook _44c6_s_p6_0 = {
  118162. 2, 169,
  118163. _vq_lengthlist__44c6_s_p6_0,
  118164. 1, -526516224, 1616117760, 4, 0,
  118165. _vq_quantlist__44c6_s_p6_0,
  118166. NULL,
  118167. &_vq_auxt__44c6_s_p6_0,
  118168. NULL,
  118169. 0
  118170. };
  118171. static long _vq_quantlist__44c6_s_p6_1[] = {
  118172. 2,
  118173. 1,
  118174. 3,
  118175. 0,
  118176. 4,
  118177. };
  118178. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118179. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118180. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118181. };
  118182. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118183. -1.5, -0.5, 0.5, 1.5,
  118184. };
  118185. static long _vq_quantmap__44c6_s_p6_1[] = {
  118186. 3, 1, 0, 2, 4,
  118187. };
  118188. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118189. _vq_quantthresh__44c6_s_p6_1,
  118190. _vq_quantmap__44c6_s_p6_1,
  118191. 5,
  118192. 5
  118193. };
  118194. static static_codebook _44c6_s_p6_1 = {
  118195. 2, 25,
  118196. _vq_lengthlist__44c6_s_p6_1,
  118197. 1, -533725184, 1611661312, 3, 0,
  118198. _vq_quantlist__44c6_s_p6_1,
  118199. NULL,
  118200. &_vq_auxt__44c6_s_p6_1,
  118201. NULL,
  118202. 0
  118203. };
  118204. static long _vq_quantlist__44c6_s_p7_0[] = {
  118205. 6,
  118206. 5,
  118207. 7,
  118208. 4,
  118209. 8,
  118210. 3,
  118211. 9,
  118212. 2,
  118213. 10,
  118214. 1,
  118215. 11,
  118216. 0,
  118217. 12,
  118218. };
  118219. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118220. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118221. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118222. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118223. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118224. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118225. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118226. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118227. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118228. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118229. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118230. 20,13,13,13,13,13,13,14,14,
  118231. };
  118232. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118233. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118234. 27.5, 38.5, 49.5, 60.5,
  118235. };
  118236. static long _vq_quantmap__44c6_s_p7_0[] = {
  118237. 11, 9, 7, 5, 3, 1, 0, 2,
  118238. 4, 6, 8, 10, 12,
  118239. };
  118240. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118241. _vq_quantthresh__44c6_s_p7_0,
  118242. _vq_quantmap__44c6_s_p7_0,
  118243. 13,
  118244. 13
  118245. };
  118246. static static_codebook _44c6_s_p7_0 = {
  118247. 2, 169,
  118248. _vq_lengthlist__44c6_s_p7_0,
  118249. 1, -523206656, 1618345984, 4, 0,
  118250. _vq_quantlist__44c6_s_p7_0,
  118251. NULL,
  118252. &_vq_auxt__44c6_s_p7_0,
  118253. NULL,
  118254. 0
  118255. };
  118256. static long _vq_quantlist__44c6_s_p7_1[] = {
  118257. 5,
  118258. 4,
  118259. 6,
  118260. 3,
  118261. 7,
  118262. 2,
  118263. 8,
  118264. 1,
  118265. 9,
  118266. 0,
  118267. 10,
  118268. };
  118269. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118270. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118271. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118272. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118273. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118274. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118275. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118276. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118277. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118278. };
  118279. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118280. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118281. 3.5, 4.5,
  118282. };
  118283. static long _vq_quantmap__44c6_s_p7_1[] = {
  118284. 9, 7, 5, 3, 1, 0, 2, 4,
  118285. 6, 8, 10,
  118286. };
  118287. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118288. _vq_quantthresh__44c6_s_p7_1,
  118289. _vq_quantmap__44c6_s_p7_1,
  118290. 11,
  118291. 11
  118292. };
  118293. static static_codebook _44c6_s_p7_1 = {
  118294. 2, 121,
  118295. _vq_lengthlist__44c6_s_p7_1,
  118296. 1, -531365888, 1611661312, 4, 0,
  118297. _vq_quantlist__44c6_s_p7_1,
  118298. NULL,
  118299. &_vq_auxt__44c6_s_p7_1,
  118300. NULL,
  118301. 0
  118302. };
  118303. static long _vq_quantlist__44c6_s_p8_0[] = {
  118304. 7,
  118305. 6,
  118306. 8,
  118307. 5,
  118308. 9,
  118309. 4,
  118310. 10,
  118311. 3,
  118312. 11,
  118313. 2,
  118314. 12,
  118315. 1,
  118316. 13,
  118317. 0,
  118318. 14,
  118319. };
  118320. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118321. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118322. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118323. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118324. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118325. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118326. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118327. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118328. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118329. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118330. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118331. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118332. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118333. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118334. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118335. 14,
  118336. };
  118337. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118338. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118339. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118340. };
  118341. static long _vq_quantmap__44c6_s_p8_0[] = {
  118342. 13, 11, 9, 7, 5, 3, 1, 0,
  118343. 2, 4, 6, 8, 10, 12, 14,
  118344. };
  118345. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118346. _vq_quantthresh__44c6_s_p8_0,
  118347. _vq_quantmap__44c6_s_p8_0,
  118348. 15,
  118349. 15
  118350. };
  118351. static static_codebook _44c6_s_p8_0 = {
  118352. 2, 225,
  118353. _vq_lengthlist__44c6_s_p8_0,
  118354. 1, -520986624, 1620377600, 4, 0,
  118355. _vq_quantlist__44c6_s_p8_0,
  118356. NULL,
  118357. &_vq_auxt__44c6_s_p8_0,
  118358. NULL,
  118359. 0
  118360. };
  118361. static long _vq_quantlist__44c6_s_p8_1[] = {
  118362. 10,
  118363. 9,
  118364. 11,
  118365. 8,
  118366. 12,
  118367. 7,
  118368. 13,
  118369. 6,
  118370. 14,
  118371. 5,
  118372. 15,
  118373. 4,
  118374. 16,
  118375. 3,
  118376. 17,
  118377. 2,
  118378. 18,
  118379. 1,
  118380. 19,
  118381. 0,
  118382. 20,
  118383. };
  118384. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118385. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118386. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118387. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118388. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118389. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118390. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118391. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118392. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118393. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118394. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118395. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118396. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118397. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118398. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118399. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118400. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118401. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118402. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118403. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118404. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118405. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118406. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118407. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118408. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118409. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118410. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118411. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118412. 10,10,10,10,10,10,10,10,10,
  118413. };
  118414. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118415. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118416. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118417. 6.5, 7.5, 8.5, 9.5,
  118418. };
  118419. static long _vq_quantmap__44c6_s_p8_1[] = {
  118420. 19, 17, 15, 13, 11, 9, 7, 5,
  118421. 3, 1, 0, 2, 4, 6, 8, 10,
  118422. 12, 14, 16, 18, 20,
  118423. };
  118424. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118425. _vq_quantthresh__44c6_s_p8_1,
  118426. _vq_quantmap__44c6_s_p8_1,
  118427. 21,
  118428. 21
  118429. };
  118430. static static_codebook _44c6_s_p8_1 = {
  118431. 2, 441,
  118432. _vq_lengthlist__44c6_s_p8_1,
  118433. 1, -529268736, 1611661312, 5, 0,
  118434. _vq_quantlist__44c6_s_p8_1,
  118435. NULL,
  118436. &_vq_auxt__44c6_s_p8_1,
  118437. NULL,
  118438. 0
  118439. };
  118440. static long _vq_quantlist__44c6_s_p9_0[] = {
  118441. 6,
  118442. 5,
  118443. 7,
  118444. 4,
  118445. 8,
  118446. 3,
  118447. 9,
  118448. 2,
  118449. 10,
  118450. 1,
  118451. 11,
  118452. 0,
  118453. 12,
  118454. };
  118455. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118456. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118457. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118458. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118459. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118460. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118461. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118462. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118463. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118464. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118465. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118466. 10,10,10,10,10,10,10,10,10,
  118467. };
  118468. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118469. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118470. 1592.5, 2229.5, 2866.5, 3503.5,
  118471. };
  118472. static long _vq_quantmap__44c6_s_p9_0[] = {
  118473. 11, 9, 7, 5, 3, 1, 0, 2,
  118474. 4, 6, 8, 10, 12,
  118475. };
  118476. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118477. _vq_quantthresh__44c6_s_p9_0,
  118478. _vq_quantmap__44c6_s_p9_0,
  118479. 13,
  118480. 13
  118481. };
  118482. static static_codebook _44c6_s_p9_0 = {
  118483. 2, 169,
  118484. _vq_lengthlist__44c6_s_p9_0,
  118485. 1, -511845376, 1630791680, 4, 0,
  118486. _vq_quantlist__44c6_s_p9_0,
  118487. NULL,
  118488. &_vq_auxt__44c6_s_p9_0,
  118489. NULL,
  118490. 0
  118491. };
  118492. static long _vq_quantlist__44c6_s_p9_1[] = {
  118493. 6,
  118494. 5,
  118495. 7,
  118496. 4,
  118497. 8,
  118498. 3,
  118499. 9,
  118500. 2,
  118501. 10,
  118502. 1,
  118503. 11,
  118504. 0,
  118505. 12,
  118506. };
  118507. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118508. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  118509. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  118510. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  118511. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  118512. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  118513. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  118514. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  118515. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  118516. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  118517. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  118518. 15,12,10,11,11,13,11,12,13,
  118519. };
  118520. static float _vq_quantthresh__44c6_s_p9_1[] = {
  118521. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  118522. 122.5, 171.5, 220.5, 269.5,
  118523. };
  118524. static long _vq_quantmap__44c6_s_p9_1[] = {
  118525. 11, 9, 7, 5, 3, 1, 0, 2,
  118526. 4, 6, 8, 10, 12,
  118527. };
  118528. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  118529. _vq_quantthresh__44c6_s_p9_1,
  118530. _vq_quantmap__44c6_s_p9_1,
  118531. 13,
  118532. 13
  118533. };
  118534. static static_codebook _44c6_s_p9_1 = {
  118535. 2, 169,
  118536. _vq_lengthlist__44c6_s_p9_1,
  118537. 1, -518889472, 1622704128, 4, 0,
  118538. _vq_quantlist__44c6_s_p9_1,
  118539. NULL,
  118540. &_vq_auxt__44c6_s_p9_1,
  118541. NULL,
  118542. 0
  118543. };
  118544. static long _vq_quantlist__44c6_s_p9_2[] = {
  118545. 24,
  118546. 23,
  118547. 25,
  118548. 22,
  118549. 26,
  118550. 21,
  118551. 27,
  118552. 20,
  118553. 28,
  118554. 19,
  118555. 29,
  118556. 18,
  118557. 30,
  118558. 17,
  118559. 31,
  118560. 16,
  118561. 32,
  118562. 15,
  118563. 33,
  118564. 14,
  118565. 34,
  118566. 13,
  118567. 35,
  118568. 12,
  118569. 36,
  118570. 11,
  118571. 37,
  118572. 10,
  118573. 38,
  118574. 9,
  118575. 39,
  118576. 8,
  118577. 40,
  118578. 7,
  118579. 41,
  118580. 6,
  118581. 42,
  118582. 5,
  118583. 43,
  118584. 4,
  118585. 44,
  118586. 3,
  118587. 45,
  118588. 2,
  118589. 46,
  118590. 1,
  118591. 47,
  118592. 0,
  118593. 48,
  118594. };
  118595. static long _vq_lengthlist__44c6_s_p9_2[] = {
  118596. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  118597. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118598. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  118599. 7,
  118600. };
  118601. static float _vq_quantthresh__44c6_s_p9_2[] = {
  118602. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  118603. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  118604. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118605. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118606. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  118607. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  118608. };
  118609. static long _vq_quantmap__44c6_s_p9_2[] = {
  118610. 47, 45, 43, 41, 39, 37, 35, 33,
  118611. 31, 29, 27, 25, 23, 21, 19, 17,
  118612. 15, 13, 11, 9, 7, 5, 3, 1,
  118613. 0, 2, 4, 6, 8, 10, 12, 14,
  118614. 16, 18, 20, 22, 24, 26, 28, 30,
  118615. 32, 34, 36, 38, 40, 42, 44, 46,
  118616. 48,
  118617. };
  118618. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  118619. _vq_quantthresh__44c6_s_p9_2,
  118620. _vq_quantmap__44c6_s_p9_2,
  118621. 49,
  118622. 49
  118623. };
  118624. static static_codebook _44c6_s_p9_2 = {
  118625. 1, 49,
  118626. _vq_lengthlist__44c6_s_p9_2,
  118627. 1, -526909440, 1611661312, 6, 0,
  118628. _vq_quantlist__44c6_s_p9_2,
  118629. NULL,
  118630. &_vq_auxt__44c6_s_p9_2,
  118631. NULL,
  118632. 0
  118633. };
  118634. static long _huff_lengthlist__44c6_s_short[] = {
  118635. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  118636. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  118637. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  118638. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  118639. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  118640. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  118641. 9,10,17,18,
  118642. };
  118643. static static_codebook _huff_book__44c6_s_short = {
  118644. 2, 100,
  118645. _huff_lengthlist__44c6_s_short,
  118646. 0, 0, 0, 0, 0,
  118647. NULL,
  118648. NULL,
  118649. NULL,
  118650. NULL,
  118651. 0
  118652. };
  118653. static long _huff_lengthlist__44c7_s_long[] = {
  118654. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  118655. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  118656. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  118657. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  118658. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  118659. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  118660. 11,10,10,12,
  118661. };
  118662. static static_codebook _huff_book__44c7_s_long = {
  118663. 2, 100,
  118664. _huff_lengthlist__44c7_s_long,
  118665. 0, 0, 0, 0, 0,
  118666. NULL,
  118667. NULL,
  118668. NULL,
  118669. NULL,
  118670. 0
  118671. };
  118672. static long _vq_quantlist__44c7_s_p1_0[] = {
  118673. 1,
  118674. 0,
  118675. 2,
  118676. };
  118677. static long _vq_lengthlist__44c7_s_p1_0[] = {
  118678. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118679. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118680. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118681. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118682. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  118683. 8,
  118684. };
  118685. static float _vq_quantthresh__44c7_s_p1_0[] = {
  118686. -0.5, 0.5,
  118687. };
  118688. static long _vq_quantmap__44c7_s_p1_0[] = {
  118689. 1, 0, 2,
  118690. };
  118691. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  118692. _vq_quantthresh__44c7_s_p1_0,
  118693. _vq_quantmap__44c7_s_p1_0,
  118694. 3,
  118695. 3
  118696. };
  118697. static static_codebook _44c7_s_p1_0 = {
  118698. 4, 81,
  118699. _vq_lengthlist__44c7_s_p1_0,
  118700. 1, -535822336, 1611661312, 2, 0,
  118701. _vq_quantlist__44c7_s_p1_0,
  118702. NULL,
  118703. &_vq_auxt__44c7_s_p1_0,
  118704. NULL,
  118705. 0
  118706. };
  118707. static long _vq_quantlist__44c7_s_p2_0[] = {
  118708. 2,
  118709. 1,
  118710. 3,
  118711. 0,
  118712. 4,
  118713. };
  118714. static long _vq_lengthlist__44c7_s_p2_0[] = {
  118715. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118716. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118717. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118718. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118719. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  118720. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118721. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  118722. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118724. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118725. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118726. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118727. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118728. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118729. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  118730. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118732. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118733. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  118734. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  118735. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  118736. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  118737. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118738. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118740. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  118741. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118742. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118743. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  118744. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118745. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  118746. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118751. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  118752. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  118753. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118754. 13,
  118755. };
  118756. static float _vq_quantthresh__44c7_s_p2_0[] = {
  118757. -1.5, -0.5, 0.5, 1.5,
  118758. };
  118759. static long _vq_quantmap__44c7_s_p2_0[] = {
  118760. 3, 1, 0, 2, 4,
  118761. };
  118762. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  118763. _vq_quantthresh__44c7_s_p2_0,
  118764. _vq_quantmap__44c7_s_p2_0,
  118765. 5,
  118766. 5
  118767. };
  118768. static static_codebook _44c7_s_p2_0 = {
  118769. 4, 625,
  118770. _vq_lengthlist__44c7_s_p2_0,
  118771. 1, -533725184, 1611661312, 3, 0,
  118772. _vq_quantlist__44c7_s_p2_0,
  118773. NULL,
  118774. &_vq_auxt__44c7_s_p2_0,
  118775. NULL,
  118776. 0
  118777. };
  118778. static long _vq_quantlist__44c7_s_p3_0[] = {
  118779. 4,
  118780. 3,
  118781. 5,
  118782. 2,
  118783. 6,
  118784. 1,
  118785. 7,
  118786. 0,
  118787. 8,
  118788. };
  118789. static long _vq_lengthlist__44c7_s_p3_0[] = {
  118790. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118791. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  118792. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  118793. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  118794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118795. 0,
  118796. };
  118797. static float _vq_quantthresh__44c7_s_p3_0[] = {
  118798. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118799. };
  118800. static long _vq_quantmap__44c7_s_p3_0[] = {
  118801. 7, 5, 3, 1, 0, 2, 4, 6,
  118802. 8,
  118803. };
  118804. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  118805. _vq_quantthresh__44c7_s_p3_0,
  118806. _vq_quantmap__44c7_s_p3_0,
  118807. 9,
  118808. 9
  118809. };
  118810. static static_codebook _44c7_s_p3_0 = {
  118811. 2, 81,
  118812. _vq_lengthlist__44c7_s_p3_0,
  118813. 1, -531628032, 1611661312, 4, 0,
  118814. _vq_quantlist__44c7_s_p3_0,
  118815. NULL,
  118816. &_vq_auxt__44c7_s_p3_0,
  118817. NULL,
  118818. 0
  118819. };
  118820. static long _vq_quantlist__44c7_s_p4_0[] = {
  118821. 8,
  118822. 7,
  118823. 9,
  118824. 6,
  118825. 10,
  118826. 5,
  118827. 11,
  118828. 4,
  118829. 12,
  118830. 3,
  118831. 13,
  118832. 2,
  118833. 14,
  118834. 1,
  118835. 15,
  118836. 0,
  118837. 16,
  118838. };
  118839. static long _vq_lengthlist__44c7_s_p4_0[] = {
  118840. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  118841. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  118842. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  118843. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  118844. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  118845. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  118846. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  118847. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118848. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  118849. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  118850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118858. 0,
  118859. };
  118860. static float _vq_quantthresh__44c7_s_p4_0[] = {
  118861. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118862. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118863. };
  118864. static long _vq_quantmap__44c7_s_p4_0[] = {
  118865. 15, 13, 11, 9, 7, 5, 3, 1,
  118866. 0, 2, 4, 6, 8, 10, 12, 14,
  118867. 16,
  118868. };
  118869. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  118870. _vq_quantthresh__44c7_s_p4_0,
  118871. _vq_quantmap__44c7_s_p4_0,
  118872. 17,
  118873. 17
  118874. };
  118875. static static_codebook _44c7_s_p4_0 = {
  118876. 2, 289,
  118877. _vq_lengthlist__44c7_s_p4_0,
  118878. 1, -529530880, 1611661312, 5, 0,
  118879. _vq_quantlist__44c7_s_p4_0,
  118880. NULL,
  118881. &_vq_auxt__44c7_s_p4_0,
  118882. NULL,
  118883. 0
  118884. };
  118885. static long _vq_quantlist__44c7_s_p5_0[] = {
  118886. 1,
  118887. 0,
  118888. 2,
  118889. };
  118890. static long _vq_lengthlist__44c7_s_p5_0[] = {
  118891. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  118892. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  118893. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  118894. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118895. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  118896. 12,
  118897. };
  118898. static float _vq_quantthresh__44c7_s_p5_0[] = {
  118899. -5.5, 5.5,
  118900. };
  118901. static long _vq_quantmap__44c7_s_p5_0[] = {
  118902. 1, 0, 2,
  118903. };
  118904. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  118905. _vq_quantthresh__44c7_s_p5_0,
  118906. _vq_quantmap__44c7_s_p5_0,
  118907. 3,
  118908. 3
  118909. };
  118910. static static_codebook _44c7_s_p5_0 = {
  118911. 4, 81,
  118912. _vq_lengthlist__44c7_s_p5_0,
  118913. 1, -529137664, 1618345984, 2, 0,
  118914. _vq_quantlist__44c7_s_p5_0,
  118915. NULL,
  118916. &_vq_auxt__44c7_s_p5_0,
  118917. NULL,
  118918. 0
  118919. };
  118920. static long _vq_quantlist__44c7_s_p5_1[] = {
  118921. 5,
  118922. 4,
  118923. 6,
  118924. 3,
  118925. 7,
  118926. 2,
  118927. 8,
  118928. 1,
  118929. 9,
  118930. 0,
  118931. 10,
  118932. };
  118933. static long _vq_lengthlist__44c7_s_p5_1[] = {
  118934. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118935. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  118936. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  118937. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  118938. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  118939. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  118940. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  118941. 11,11,11, 7, 7, 8, 8, 8, 8,
  118942. };
  118943. static float _vq_quantthresh__44c7_s_p5_1[] = {
  118944. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118945. 3.5, 4.5,
  118946. };
  118947. static long _vq_quantmap__44c7_s_p5_1[] = {
  118948. 9, 7, 5, 3, 1, 0, 2, 4,
  118949. 6, 8, 10,
  118950. };
  118951. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  118952. _vq_quantthresh__44c7_s_p5_1,
  118953. _vq_quantmap__44c7_s_p5_1,
  118954. 11,
  118955. 11
  118956. };
  118957. static static_codebook _44c7_s_p5_1 = {
  118958. 2, 121,
  118959. _vq_lengthlist__44c7_s_p5_1,
  118960. 1, -531365888, 1611661312, 4, 0,
  118961. _vq_quantlist__44c7_s_p5_1,
  118962. NULL,
  118963. &_vq_auxt__44c7_s_p5_1,
  118964. NULL,
  118965. 0
  118966. };
  118967. static long _vq_quantlist__44c7_s_p6_0[] = {
  118968. 6,
  118969. 5,
  118970. 7,
  118971. 4,
  118972. 8,
  118973. 3,
  118974. 9,
  118975. 2,
  118976. 10,
  118977. 1,
  118978. 11,
  118979. 0,
  118980. 12,
  118981. };
  118982. static long _vq_lengthlist__44c7_s_p6_0[] = {
  118983. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  118984. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  118985. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  118986. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  118987. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  118988. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  118989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118993. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118994. };
  118995. static float _vq_quantthresh__44c7_s_p6_0[] = {
  118996. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118997. 12.5, 17.5, 22.5, 27.5,
  118998. };
  118999. static long _vq_quantmap__44c7_s_p6_0[] = {
  119000. 11, 9, 7, 5, 3, 1, 0, 2,
  119001. 4, 6, 8, 10, 12,
  119002. };
  119003. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119004. _vq_quantthresh__44c7_s_p6_0,
  119005. _vq_quantmap__44c7_s_p6_0,
  119006. 13,
  119007. 13
  119008. };
  119009. static static_codebook _44c7_s_p6_0 = {
  119010. 2, 169,
  119011. _vq_lengthlist__44c7_s_p6_0,
  119012. 1, -526516224, 1616117760, 4, 0,
  119013. _vq_quantlist__44c7_s_p6_0,
  119014. NULL,
  119015. &_vq_auxt__44c7_s_p6_0,
  119016. NULL,
  119017. 0
  119018. };
  119019. static long _vq_quantlist__44c7_s_p6_1[] = {
  119020. 2,
  119021. 1,
  119022. 3,
  119023. 0,
  119024. 4,
  119025. };
  119026. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119027. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119028. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119029. };
  119030. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119031. -1.5, -0.5, 0.5, 1.5,
  119032. };
  119033. static long _vq_quantmap__44c7_s_p6_1[] = {
  119034. 3, 1, 0, 2, 4,
  119035. };
  119036. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119037. _vq_quantthresh__44c7_s_p6_1,
  119038. _vq_quantmap__44c7_s_p6_1,
  119039. 5,
  119040. 5
  119041. };
  119042. static static_codebook _44c7_s_p6_1 = {
  119043. 2, 25,
  119044. _vq_lengthlist__44c7_s_p6_1,
  119045. 1, -533725184, 1611661312, 3, 0,
  119046. _vq_quantlist__44c7_s_p6_1,
  119047. NULL,
  119048. &_vq_auxt__44c7_s_p6_1,
  119049. NULL,
  119050. 0
  119051. };
  119052. static long _vq_quantlist__44c7_s_p7_0[] = {
  119053. 6,
  119054. 5,
  119055. 7,
  119056. 4,
  119057. 8,
  119058. 3,
  119059. 9,
  119060. 2,
  119061. 10,
  119062. 1,
  119063. 11,
  119064. 0,
  119065. 12,
  119066. };
  119067. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119068. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119069. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119070. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119071. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119072. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119073. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119074. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119075. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119076. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119077. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119078. 19,13,13,13,13,14,14,15,15,
  119079. };
  119080. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119081. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119082. 27.5, 38.5, 49.5, 60.5,
  119083. };
  119084. static long _vq_quantmap__44c7_s_p7_0[] = {
  119085. 11, 9, 7, 5, 3, 1, 0, 2,
  119086. 4, 6, 8, 10, 12,
  119087. };
  119088. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119089. _vq_quantthresh__44c7_s_p7_0,
  119090. _vq_quantmap__44c7_s_p7_0,
  119091. 13,
  119092. 13
  119093. };
  119094. static static_codebook _44c7_s_p7_0 = {
  119095. 2, 169,
  119096. _vq_lengthlist__44c7_s_p7_0,
  119097. 1, -523206656, 1618345984, 4, 0,
  119098. _vq_quantlist__44c7_s_p7_0,
  119099. NULL,
  119100. &_vq_auxt__44c7_s_p7_0,
  119101. NULL,
  119102. 0
  119103. };
  119104. static long _vq_quantlist__44c7_s_p7_1[] = {
  119105. 5,
  119106. 4,
  119107. 6,
  119108. 3,
  119109. 7,
  119110. 2,
  119111. 8,
  119112. 1,
  119113. 9,
  119114. 0,
  119115. 10,
  119116. };
  119117. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119118. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119119. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119120. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119121. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119122. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119123. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119124. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119125. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119126. };
  119127. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119128. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119129. 3.5, 4.5,
  119130. };
  119131. static long _vq_quantmap__44c7_s_p7_1[] = {
  119132. 9, 7, 5, 3, 1, 0, 2, 4,
  119133. 6, 8, 10,
  119134. };
  119135. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119136. _vq_quantthresh__44c7_s_p7_1,
  119137. _vq_quantmap__44c7_s_p7_1,
  119138. 11,
  119139. 11
  119140. };
  119141. static static_codebook _44c7_s_p7_1 = {
  119142. 2, 121,
  119143. _vq_lengthlist__44c7_s_p7_1,
  119144. 1, -531365888, 1611661312, 4, 0,
  119145. _vq_quantlist__44c7_s_p7_1,
  119146. NULL,
  119147. &_vq_auxt__44c7_s_p7_1,
  119148. NULL,
  119149. 0
  119150. };
  119151. static long _vq_quantlist__44c7_s_p8_0[] = {
  119152. 7,
  119153. 6,
  119154. 8,
  119155. 5,
  119156. 9,
  119157. 4,
  119158. 10,
  119159. 3,
  119160. 11,
  119161. 2,
  119162. 12,
  119163. 1,
  119164. 13,
  119165. 0,
  119166. 14,
  119167. };
  119168. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119169. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119170. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119171. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119172. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119173. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119174. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119175. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119176. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119177. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119178. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119179. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119180. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119181. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119182. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119183. 14,
  119184. };
  119185. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119186. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119187. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119188. };
  119189. static long _vq_quantmap__44c7_s_p8_0[] = {
  119190. 13, 11, 9, 7, 5, 3, 1, 0,
  119191. 2, 4, 6, 8, 10, 12, 14,
  119192. };
  119193. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119194. _vq_quantthresh__44c7_s_p8_0,
  119195. _vq_quantmap__44c7_s_p8_0,
  119196. 15,
  119197. 15
  119198. };
  119199. static static_codebook _44c7_s_p8_0 = {
  119200. 2, 225,
  119201. _vq_lengthlist__44c7_s_p8_0,
  119202. 1, -520986624, 1620377600, 4, 0,
  119203. _vq_quantlist__44c7_s_p8_0,
  119204. NULL,
  119205. &_vq_auxt__44c7_s_p8_0,
  119206. NULL,
  119207. 0
  119208. };
  119209. static long _vq_quantlist__44c7_s_p8_1[] = {
  119210. 10,
  119211. 9,
  119212. 11,
  119213. 8,
  119214. 12,
  119215. 7,
  119216. 13,
  119217. 6,
  119218. 14,
  119219. 5,
  119220. 15,
  119221. 4,
  119222. 16,
  119223. 3,
  119224. 17,
  119225. 2,
  119226. 18,
  119227. 1,
  119228. 19,
  119229. 0,
  119230. 20,
  119231. };
  119232. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119233. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119234. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119235. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119236. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119237. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119238. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119239. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119240. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119241. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119242. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119243. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119244. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119245. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119246. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119247. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119248. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119249. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119250. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119251. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119252. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119253. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119254. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119255. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119256. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119257. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119258. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119259. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119260. 10,10,10,10,10,10,10,10,10,
  119261. };
  119262. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119263. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119264. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119265. 6.5, 7.5, 8.5, 9.5,
  119266. };
  119267. static long _vq_quantmap__44c7_s_p8_1[] = {
  119268. 19, 17, 15, 13, 11, 9, 7, 5,
  119269. 3, 1, 0, 2, 4, 6, 8, 10,
  119270. 12, 14, 16, 18, 20,
  119271. };
  119272. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119273. _vq_quantthresh__44c7_s_p8_1,
  119274. _vq_quantmap__44c7_s_p8_1,
  119275. 21,
  119276. 21
  119277. };
  119278. static static_codebook _44c7_s_p8_1 = {
  119279. 2, 441,
  119280. _vq_lengthlist__44c7_s_p8_1,
  119281. 1, -529268736, 1611661312, 5, 0,
  119282. _vq_quantlist__44c7_s_p8_1,
  119283. NULL,
  119284. &_vq_auxt__44c7_s_p8_1,
  119285. NULL,
  119286. 0
  119287. };
  119288. static long _vq_quantlist__44c7_s_p9_0[] = {
  119289. 6,
  119290. 5,
  119291. 7,
  119292. 4,
  119293. 8,
  119294. 3,
  119295. 9,
  119296. 2,
  119297. 10,
  119298. 1,
  119299. 11,
  119300. 0,
  119301. 12,
  119302. };
  119303. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119304. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119305. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119306. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119307. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119308. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119309. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119310. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119311. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119312. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119313. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119314. 11,11,11,11,11,11,11,11,11,
  119315. };
  119316. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119317. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119318. 1592.5, 2229.5, 2866.5, 3503.5,
  119319. };
  119320. static long _vq_quantmap__44c7_s_p9_0[] = {
  119321. 11, 9, 7, 5, 3, 1, 0, 2,
  119322. 4, 6, 8, 10, 12,
  119323. };
  119324. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119325. _vq_quantthresh__44c7_s_p9_0,
  119326. _vq_quantmap__44c7_s_p9_0,
  119327. 13,
  119328. 13
  119329. };
  119330. static static_codebook _44c7_s_p9_0 = {
  119331. 2, 169,
  119332. _vq_lengthlist__44c7_s_p9_0,
  119333. 1, -511845376, 1630791680, 4, 0,
  119334. _vq_quantlist__44c7_s_p9_0,
  119335. NULL,
  119336. &_vq_auxt__44c7_s_p9_0,
  119337. NULL,
  119338. 0
  119339. };
  119340. static long _vq_quantlist__44c7_s_p9_1[] = {
  119341. 6,
  119342. 5,
  119343. 7,
  119344. 4,
  119345. 8,
  119346. 3,
  119347. 9,
  119348. 2,
  119349. 10,
  119350. 1,
  119351. 11,
  119352. 0,
  119353. 12,
  119354. };
  119355. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119356. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119357. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119358. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119359. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119360. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119361. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119362. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119363. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119364. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119365. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119366. 15,11,11,10,10,12,12,12,12,
  119367. };
  119368. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119369. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119370. 122.5, 171.5, 220.5, 269.5,
  119371. };
  119372. static long _vq_quantmap__44c7_s_p9_1[] = {
  119373. 11, 9, 7, 5, 3, 1, 0, 2,
  119374. 4, 6, 8, 10, 12,
  119375. };
  119376. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119377. _vq_quantthresh__44c7_s_p9_1,
  119378. _vq_quantmap__44c7_s_p9_1,
  119379. 13,
  119380. 13
  119381. };
  119382. static static_codebook _44c7_s_p9_1 = {
  119383. 2, 169,
  119384. _vq_lengthlist__44c7_s_p9_1,
  119385. 1, -518889472, 1622704128, 4, 0,
  119386. _vq_quantlist__44c7_s_p9_1,
  119387. NULL,
  119388. &_vq_auxt__44c7_s_p9_1,
  119389. NULL,
  119390. 0
  119391. };
  119392. static long _vq_quantlist__44c7_s_p9_2[] = {
  119393. 24,
  119394. 23,
  119395. 25,
  119396. 22,
  119397. 26,
  119398. 21,
  119399. 27,
  119400. 20,
  119401. 28,
  119402. 19,
  119403. 29,
  119404. 18,
  119405. 30,
  119406. 17,
  119407. 31,
  119408. 16,
  119409. 32,
  119410. 15,
  119411. 33,
  119412. 14,
  119413. 34,
  119414. 13,
  119415. 35,
  119416. 12,
  119417. 36,
  119418. 11,
  119419. 37,
  119420. 10,
  119421. 38,
  119422. 9,
  119423. 39,
  119424. 8,
  119425. 40,
  119426. 7,
  119427. 41,
  119428. 6,
  119429. 42,
  119430. 5,
  119431. 43,
  119432. 4,
  119433. 44,
  119434. 3,
  119435. 45,
  119436. 2,
  119437. 46,
  119438. 1,
  119439. 47,
  119440. 0,
  119441. 48,
  119442. };
  119443. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119444. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119445. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119446. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119447. 7,
  119448. };
  119449. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119450. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119451. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119452. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119453. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119454. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119455. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119456. };
  119457. static long _vq_quantmap__44c7_s_p9_2[] = {
  119458. 47, 45, 43, 41, 39, 37, 35, 33,
  119459. 31, 29, 27, 25, 23, 21, 19, 17,
  119460. 15, 13, 11, 9, 7, 5, 3, 1,
  119461. 0, 2, 4, 6, 8, 10, 12, 14,
  119462. 16, 18, 20, 22, 24, 26, 28, 30,
  119463. 32, 34, 36, 38, 40, 42, 44, 46,
  119464. 48,
  119465. };
  119466. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119467. _vq_quantthresh__44c7_s_p9_2,
  119468. _vq_quantmap__44c7_s_p9_2,
  119469. 49,
  119470. 49
  119471. };
  119472. static static_codebook _44c7_s_p9_2 = {
  119473. 1, 49,
  119474. _vq_lengthlist__44c7_s_p9_2,
  119475. 1, -526909440, 1611661312, 6, 0,
  119476. _vq_quantlist__44c7_s_p9_2,
  119477. NULL,
  119478. &_vq_auxt__44c7_s_p9_2,
  119479. NULL,
  119480. 0
  119481. };
  119482. static long _huff_lengthlist__44c7_s_short[] = {
  119483. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119484. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119485. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119486. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119487. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119488. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119489. 10, 9,11,14,
  119490. };
  119491. static static_codebook _huff_book__44c7_s_short = {
  119492. 2, 100,
  119493. _huff_lengthlist__44c7_s_short,
  119494. 0, 0, 0, 0, 0,
  119495. NULL,
  119496. NULL,
  119497. NULL,
  119498. NULL,
  119499. 0
  119500. };
  119501. static long _huff_lengthlist__44c8_s_long[] = {
  119502. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119503. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119504. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119505. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119506. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119507. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119508. 11, 9, 9,10,
  119509. };
  119510. static static_codebook _huff_book__44c8_s_long = {
  119511. 2, 100,
  119512. _huff_lengthlist__44c8_s_long,
  119513. 0, 0, 0, 0, 0,
  119514. NULL,
  119515. NULL,
  119516. NULL,
  119517. NULL,
  119518. 0
  119519. };
  119520. static long _vq_quantlist__44c8_s_p1_0[] = {
  119521. 1,
  119522. 0,
  119523. 2,
  119524. };
  119525. static long _vq_lengthlist__44c8_s_p1_0[] = {
  119526. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  119527. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119528. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119529. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119530. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119531. 8,
  119532. };
  119533. static float _vq_quantthresh__44c8_s_p1_0[] = {
  119534. -0.5, 0.5,
  119535. };
  119536. static long _vq_quantmap__44c8_s_p1_0[] = {
  119537. 1, 0, 2,
  119538. };
  119539. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  119540. _vq_quantthresh__44c8_s_p1_0,
  119541. _vq_quantmap__44c8_s_p1_0,
  119542. 3,
  119543. 3
  119544. };
  119545. static static_codebook _44c8_s_p1_0 = {
  119546. 4, 81,
  119547. _vq_lengthlist__44c8_s_p1_0,
  119548. 1, -535822336, 1611661312, 2, 0,
  119549. _vq_quantlist__44c8_s_p1_0,
  119550. NULL,
  119551. &_vq_auxt__44c8_s_p1_0,
  119552. NULL,
  119553. 0
  119554. };
  119555. static long _vq_quantlist__44c8_s_p2_0[] = {
  119556. 2,
  119557. 1,
  119558. 3,
  119559. 0,
  119560. 4,
  119561. };
  119562. static long _vq_lengthlist__44c8_s_p2_0[] = {
  119563. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119564. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119565. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119566. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  119567. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119568. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  119569. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  119570. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119572. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119573. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  119574. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119575. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  119576. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  119577. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  119578. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  119579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119580. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  119581. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  119582. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  119583. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  119584. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  119585. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  119586. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119588. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119589. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  119590. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119591. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  119592. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  119593. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  119594. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119599. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  119600. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119601. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  119602. 13,
  119603. };
  119604. static float _vq_quantthresh__44c8_s_p2_0[] = {
  119605. -1.5, -0.5, 0.5, 1.5,
  119606. };
  119607. static long _vq_quantmap__44c8_s_p2_0[] = {
  119608. 3, 1, 0, 2, 4,
  119609. };
  119610. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  119611. _vq_quantthresh__44c8_s_p2_0,
  119612. _vq_quantmap__44c8_s_p2_0,
  119613. 5,
  119614. 5
  119615. };
  119616. static static_codebook _44c8_s_p2_0 = {
  119617. 4, 625,
  119618. _vq_lengthlist__44c8_s_p2_0,
  119619. 1, -533725184, 1611661312, 3, 0,
  119620. _vq_quantlist__44c8_s_p2_0,
  119621. NULL,
  119622. &_vq_auxt__44c8_s_p2_0,
  119623. NULL,
  119624. 0
  119625. };
  119626. static long _vq_quantlist__44c8_s_p3_0[] = {
  119627. 4,
  119628. 3,
  119629. 5,
  119630. 2,
  119631. 6,
  119632. 1,
  119633. 7,
  119634. 0,
  119635. 8,
  119636. };
  119637. static long _vq_lengthlist__44c8_s_p3_0[] = {
  119638. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119639. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119640. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119641. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119643. 0,
  119644. };
  119645. static float _vq_quantthresh__44c8_s_p3_0[] = {
  119646. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119647. };
  119648. static long _vq_quantmap__44c8_s_p3_0[] = {
  119649. 7, 5, 3, 1, 0, 2, 4, 6,
  119650. 8,
  119651. };
  119652. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  119653. _vq_quantthresh__44c8_s_p3_0,
  119654. _vq_quantmap__44c8_s_p3_0,
  119655. 9,
  119656. 9
  119657. };
  119658. static static_codebook _44c8_s_p3_0 = {
  119659. 2, 81,
  119660. _vq_lengthlist__44c8_s_p3_0,
  119661. 1, -531628032, 1611661312, 4, 0,
  119662. _vq_quantlist__44c8_s_p3_0,
  119663. NULL,
  119664. &_vq_auxt__44c8_s_p3_0,
  119665. NULL,
  119666. 0
  119667. };
  119668. static long _vq_quantlist__44c8_s_p4_0[] = {
  119669. 8,
  119670. 7,
  119671. 9,
  119672. 6,
  119673. 10,
  119674. 5,
  119675. 11,
  119676. 4,
  119677. 12,
  119678. 3,
  119679. 13,
  119680. 2,
  119681. 14,
  119682. 1,
  119683. 15,
  119684. 0,
  119685. 16,
  119686. };
  119687. static long _vq_lengthlist__44c8_s_p4_0[] = {
  119688. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119689. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  119690. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119691. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  119692. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  119693. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119694. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119695. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119696. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119697. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119706. 0,
  119707. };
  119708. static float _vq_quantthresh__44c8_s_p4_0[] = {
  119709. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119710. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119711. };
  119712. static long _vq_quantmap__44c8_s_p4_0[] = {
  119713. 15, 13, 11, 9, 7, 5, 3, 1,
  119714. 0, 2, 4, 6, 8, 10, 12, 14,
  119715. 16,
  119716. };
  119717. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  119718. _vq_quantthresh__44c8_s_p4_0,
  119719. _vq_quantmap__44c8_s_p4_0,
  119720. 17,
  119721. 17
  119722. };
  119723. static static_codebook _44c8_s_p4_0 = {
  119724. 2, 289,
  119725. _vq_lengthlist__44c8_s_p4_0,
  119726. 1, -529530880, 1611661312, 5, 0,
  119727. _vq_quantlist__44c8_s_p4_0,
  119728. NULL,
  119729. &_vq_auxt__44c8_s_p4_0,
  119730. NULL,
  119731. 0
  119732. };
  119733. static long _vq_quantlist__44c8_s_p5_0[] = {
  119734. 1,
  119735. 0,
  119736. 2,
  119737. };
  119738. static long _vq_lengthlist__44c8_s_p5_0[] = {
  119739. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  119740. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119741. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119742. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  119743. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  119744. 12,
  119745. };
  119746. static float _vq_quantthresh__44c8_s_p5_0[] = {
  119747. -5.5, 5.5,
  119748. };
  119749. static long _vq_quantmap__44c8_s_p5_0[] = {
  119750. 1, 0, 2,
  119751. };
  119752. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  119753. _vq_quantthresh__44c8_s_p5_0,
  119754. _vq_quantmap__44c8_s_p5_0,
  119755. 3,
  119756. 3
  119757. };
  119758. static static_codebook _44c8_s_p5_0 = {
  119759. 4, 81,
  119760. _vq_lengthlist__44c8_s_p5_0,
  119761. 1, -529137664, 1618345984, 2, 0,
  119762. _vq_quantlist__44c8_s_p5_0,
  119763. NULL,
  119764. &_vq_auxt__44c8_s_p5_0,
  119765. NULL,
  119766. 0
  119767. };
  119768. static long _vq_quantlist__44c8_s_p5_1[] = {
  119769. 5,
  119770. 4,
  119771. 6,
  119772. 3,
  119773. 7,
  119774. 2,
  119775. 8,
  119776. 1,
  119777. 9,
  119778. 0,
  119779. 10,
  119780. };
  119781. static long _vq_lengthlist__44c8_s_p5_1[] = {
  119782. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  119783. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  119784. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  119785. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  119786. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  119787. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  119788. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  119789. 11,11,11, 7, 7, 7, 7, 8, 8,
  119790. };
  119791. static float _vq_quantthresh__44c8_s_p5_1[] = {
  119792. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119793. 3.5, 4.5,
  119794. };
  119795. static long _vq_quantmap__44c8_s_p5_1[] = {
  119796. 9, 7, 5, 3, 1, 0, 2, 4,
  119797. 6, 8, 10,
  119798. };
  119799. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  119800. _vq_quantthresh__44c8_s_p5_1,
  119801. _vq_quantmap__44c8_s_p5_1,
  119802. 11,
  119803. 11
  119804. };
  119805. static static_codebook _44c8_s_p5_1 = {
  119806. 2, 121,
  119807. _vq_lengthlist__44c8_s_p5_1,
  119808. 1, -531365888, 1611661312, 4, 0,
  119809. _vq_quantlist__44c8_s_p5_1,
  119810. NULL,
  119811. &_vq_auxt__44c8_s_p5_1,
  119812. NULL,
  119813. 0
  119814. };
  119815. static long _vq_quantlist__44c8_s_p6_0[] = {
  119816. 6,
  119817. 5,
  119818. 7,
  119819. 4,
  119820. 8,
  119821. 3,
  119822. 9,
  119823. 2,
  119824. 10,
  119825. 1,
  119826. 11,
  119827. 0,
  119828. 12,
  119829. };
  119830. static long _vq_lengthlist__44c8_s_p6_0[] = {
  119831. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  119832. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  119833. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  119834. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  119835. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  119836. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  119837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119841. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119842. };
  119843. static float _vq_quantthresh__44c8_s_p6_0[] = {
  119844. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119845. 12.5, 17.5, 22.5, 27.5,
  119846. };
  119847. static long _vq_quantmap__44c8_s_p6_0[] = {
  119848. 11, 9, 7, 5, 3, 1, 0, 2,
  119849. 4, 6, 8, 10, 12,
  119850. };
  119851. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  119852. _vq_quantthresh__44c8_s_p6_0,
  119853. _vq_quantmap__44c8_s_p6_0,
  119854. 13,
  119855. 13
  119856. };
  119857. static static_codebook _44c8_s_p6_0 = {
  119858. 2, 169,
  119859. _vq_lengthlist__44c8_s_p6_0,
  119860. 1, -526516224, 1616117760, 4, 0,
  119861. _vq_quantlist__44c8_s_p6_0,
  119862. NULL,
  119863. &_vq_auxt__44c8_s_p6_0,
  119864. NULL,
  119865. 0
  119866. };
  119867. static long _vq_quantlist__44c8_s_p6_1[] = {
  119868. 2,
  119869. 1,
  119870. 3,
  119871. 0,
  119872. 4,
  119873. };
  119874. static long _vq_lengthlist__44c8_s_p6_1[] = {
  119875. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119876. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119877. };
  119878. static float _vq_quantthresh__44c8_s_p6_1[] = {
  119879. -1.5, -0.5, 0.5, 1.5,
  119880. };
  119881. static long _vq_quantmap__44c8_s_p6_1[] = {
  119882. 3, 1, 0, 2, 4,
  119883. };
  119884. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  119885. _vq_quantthresh__44c8_s_p6_1,
  119886. _vq_quantmap__44c8_s_p6_1,
  119887. 5,
  119888. 5
  119889. };
  119890. static static_codebook _44c8_s_p6_1 = {
  119891. 2, 25,
  119892. _vq_lengthlist__44c8_s_p6_1,
  119893. 1, -533725184, 1611661312, 3, 0,
  119894. _vq_quantlist__44c8_s_p6_1,
  119895. NULL,
  119896. &_vq_auxt__44c8_s_p6_1,
  119897. NULL,
  119898. 0
  119899. };
  119900. static long _vq_quantlist__44c8_s_p7_0[] = {
  119901. 6,
  119902. 5,
  119903. 7,
  119904. 4,
  119905. 8,
  119906. 3,
  119907. 9,
  119908. 2,
  119909. 10,
  119910. 1,
  119911. 11,
  119912. 0,
  119913. 12,
  119914. };
  119915. static long _vq_lengthlist__44c8_s_p7_0[] = {
  119916. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  119917. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119918. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  119919. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  119920. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  119921. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  119922. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  119923. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  119924. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  119925. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  119926. 20,13,13,13,13,14,13,15,15,
  119927. };
  119928. static float _vq_quantthresh__44c8_s_p7_0[] = {
  119929. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119930. 27.5, 38.5, 49.5, 60.5,
  119931. };
  119932. static long _vq_quantmap__44c8_s_p7_0[] = {
  119933. 11, 9, 7, 5, 3, 1, 0, 2,
  119934. 4, 6, 8, 10, 12,
  119935. };
  119936. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  119937. _vq_quantthresh__44c8_s_p7_0,
  119938. _vq_quantmap__44c8_s_p7_0,
  119939. 13,
  119940. 13
  119941. };
  119942. static static_codebook _44c8_s_p7_0 = {
  119943. 2, 169,
  119944. _vq_lengthlist__44c8_s_p7_0,
  119945. 1, -523206656, 1618345984, 4, 0,
  119946. _vq_quantlist__44c8_s_p7_0,
  119947. NULL,
  119948. &_vq_auxt__44c8_s_p7_0,
  119949. NULL,
  119950. 0
  119951. };
  119952. static long _vq_quantlist__44c8_s_p7_1[] = {
  119953. 5,
  119954. 4,
  119955. 6,
  119956. 3,
  119957. 7,
  119958. 2,
  119959. 8,
  119960. 1,
  119961. 9,
  119962. 0,
  119963. 10,
  119964. };
  119965. static long _vq_lengthlist__44c8_s_p7_1[] = {
  119966. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  119967. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  119968. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119969. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119970. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119971. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119972. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119973. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119974. };
  119975. static float _vq_quantthresh__44c8_s_p7_1[] = {
  119976. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119977. 3.5, 4.5,
  119978. };
  119979. static long _vq_quantmap__44c8_s_p7_1[] = {
  119980. 9, 7, 5, 3, 1, 0, 2, 4,
  119981. 6, 8, 10,
  119982. };
  119983. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  119984. _vq_quantthresh__44c8_s_p7_1,
  119985. _vq_quantmap__44c8_s_p7_1,
  119986. 11,
  119987. 11
  119988. };
  119989. static static_codebook _44c8_s_p7_1 = {
  119990. 2, 121,
  119991. _vq_lengthlist__44c8_s_p7_1,
  119992. 1, -531365888, 1611661312, 4, 0,
  119993. _vq_quantlist__44c8_s_p7_1,
  119994. NULL,
  119995. &_vq_auxt__44c8_s_p7_1,
  119996. NULL,
  119997. 0
  119998. };
  119999. static long _vq_quantlist__44c8_s_p8_0[] = {
  120000. 7,
  120001. 6,
  120002. 8,
  120003. 5,
  120004. 9,
  120005. 4,
  120006. 10,
  120007. 3,
  120008. 11,
  120009. 2,
  120010. 12,
  120011. 1,
  120012. 13,
  120013. 0,
  120014. 14,
  120015. };
  120016. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120017. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120018. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120019. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120020. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120021. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120022. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120023. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120024. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120025. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120026. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120027. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120028. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120029. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120030. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120031. 15,
  120032. };
  120033. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120034. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120035. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120036. };
  120037. static long _vq_quantmap__44c8_s_p8_0[] = {
  120038. 13, 11, 9, 7, 5, 3, 1, 0,
  120039. 2, 4, 6, 8, 10, 12, 14,
  120040. };
  120041. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120042. _vq_quantthresh__44c8_s_p8_0,
  120043. _vq_quantmap__44c8_s_p8_0,
  120044. 15,
  120045. 15
  120046. };
  120047. static static_codebook _44c8_s_p8_0 = {
  120048. 2, 225,
  120049. _vq_lengthlist__44c8_s_p8_0,
  120050. 1, -520986624, 1620377600, 4, 0,
  120051. _vq_quantlist__44c8_s_p8_0,
  120052. NULL,
  120053. &_vq_auxt__44c8_s_p8_0,
  120054. NULL,
  120055. 0
  120056. };
  120057. static long _vq_quantlist__44c8_s_p8_1[] = {
  120058. 10,
  120059. 9,
  120060. 11,
  120061. 8,
  120062. 12,
  120063. 7,
  120064. 13,
  120065. 6,
  120066. 14,
  120067. 5,
  120068. 15,
  120069. 4,
  120070. 16,
  120071. 3,
  120072. 17,
  120073. 2,
  120074. 18,
  120075. 1,
  120076. 19,
  120077. 0,
  120078. 20,
  120079. };
  120080. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120081. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120082. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120083. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120084. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120085. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120086. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120087. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120088. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120089. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120090. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120091. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120092. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120093. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120094. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120095. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120096. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120097. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120098. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120099. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120100. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120101. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120102. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120103. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120104. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120105. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120106. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120107. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120108. 10, 9, 9,10,10, 9,10, 9, 9,
  120109. };
  120110. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120111. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120112. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120113. 6.5, 7.5, 8.5, 9.5,
  120114. };
  120115. static long _vq_quantmap__44c8_s_p8_1[] = {
  120116. 19, 17, 15, 13, 11, 9, 7, 5,
  120117. 3, 1, 0, 2, 4, 6, 8, 10,
  120118. 12, 14, 16, 18, 20,
  120119. };
  120120. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120121. _vq_quantthresh__44c8_s_p8_1,
  120122. _vq_quantmap__44c8_s_p8_1,
  120123. 21,
  120124. 21
  120125. };
  120126. static static_codebook _44c8_s_p8_1 = {
  120127. 2, 441,
  120128. _vq_lengthlist__44c8_s_p8_1,
  120129. 1, -529268736, 1611661312, 5, 0,
  120130. _vq_quantlist__44c8_s_p8_1,
  120131. NULL,
  120132. &_vq_auxt__44c8_s_p8_1,
  120133. NULL,
  120134. 0
  120135. };
  120136. static long _vq_quantlist__44c8_s_p9_0[] = {
  120137. 8,
  120138. 7,
  120139. 9,
  120140. 6,
  120141. 10,
  120142. 5,
  120143. 11,
  120144. 4,
  120145. 12,
  120146. 3,
  120147. 13,
  120148. 2,
  120149. 14,
  120150. 1,
  120151. 15,
  120152. 0,
  120153. 16,
  120154. };
  120155. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120156. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120157. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120158. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120159. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120160. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120161. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120162. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120163. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120164. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120165. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120166. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120167. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120168. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120169. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120170. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120171. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120172. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120173. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120174. 10,
  120175. };
  120176. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120177. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120178. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120179. };
  120180. static long _vq_quantmap__44c8_s_p9_0[] = {
  120181. 15, 13, 11, 9, 7, 5, 3, 1,
  120182. 0, 2, 4, 6, 8, 10, 12, 14,
  120183. 16,
  120184. };
  120185. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120186. _vq_quantthresh__44c8_s_p9_0,
  120187. _vq_quantmap__44c8_s_p9_0,
  120188. 17,
  120189. 17
  120190. };
  120191. static static_codebook _44c8_s_p9_0 = {
  120192. 2, 289,
  120193. _vq_lengthlist__44c8_s_p9_0,
  120194. 1, -509798400, 1631393792, 5, 0,
  120195. _vq_quantlist__44c8_s_p9_0,
  120196. NULL,
  120197. &_vq_auxt__44c8_s_p9_0,
  120198. NULL,
  120199. 0
  120200. };
  120201. static long _vq_quantlist__44c8_s_p9_1[] = {
  120202. 9,
  120203. 8,
  120204. 10,
  120205. 7,
  120206. 11,
  120207. 6,
  120208. 12,
  120209. 5,
  120210. 13,
  120211. 4,
  120212. 14,
  120213. 3,
  120214. 15,
  120215. 2,
  120216. 16,
  120217. 1,
  120218. 17,
  120219. 0,
  120220. 18,
  120221. };
  120222. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120223. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120224. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120225. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120226. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120227. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120228. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120229. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120230. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120231. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120232. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120233. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120234. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120235. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120236. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120237. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120238. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120239. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120240. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120241. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120242. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120243. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120244. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120245. 14,13,13,14,14,15,14,15,14,
  120246. };
  120247. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120248. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120249. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120250. 367.5, 416.5,
  120251. };
  120252. static long _vq_quantmap__44c8_s_p9_1[] = {
  120253. 17, 15, 13, 11, 9, 7, 5, 3,
  120254. 1, 0, 2, 4, 6, 8, 10, 12,
  120255. 14, 16, 18,
  120256. };
  120257. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120258. _vq_quantthresh__44c8_s_p9_1,
  120259. _vq_quantmap__44c8_s_p9_1,
  120260. 19,
  120261. 19
  120262. };
  120263. static static_codebook _44c8_s_p9_1 = {
  120264. 2, 361,
  120265. _vq_lengthlist__44c8_s_p9_1,
  120266. 1, -518287360, 1622704128, 5, 0,
  120267. _vq_quantlist__44c8_s_p9_1,
  120268. NULL,
  120269. &_vq_auxt__44c8_s_p9_1,
  120270. NULL,
  120271. 0
  120272. };
  120273. static long _vq_quantlist__44c8_s_p9_2[] = {
  120274. 24,
  120275. 23,
  120276. 25,
  120277. 22,
  120278. 26,
  120279. 21,
  120280. 27,
  120281. 20,
  120282. 28,
  120283. 19,
  120284. 29,
  120285. 18,
  120286. 30,
  120287. 17,
  120288. 31,
  120289. 16,
  120290. 32,
  120291. 15,
  120292. 33,
  120293. 14,
  120294. 34,
  120295. 13,
  120296. 35,
  120297. 12,
  120298. 36,
  120299. 11,
  120300. 37,
  120301. 10,
  120302. 38,
  120303. 9,
  120304. 39,
  120305. 8,
  120306. 40,
  120307. 7,
  120308. 41,
  120309. 6,
  120310. 42,
  120311. 5,
  120312. 43,
  120313. 4,
  120314. 44,
  120315. 3,
  120316. 45,
  120317. 2,
  120318. 46,
  120319. 1,
  120320. 47,
  120321. 0,
  120322. 48,
  120323. };
  120324. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120325. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120326. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120327. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120328. 7,
  120329. };
  120330. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120331. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120332. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120333. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120334. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120335. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120336. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120337. };
  120338. static long _vq_quantmap__44c8_s_p9_2[] = {
  120339. 47, 45, 43, 41, 39, 37, 35, 33,
  120340. 31, 29, 27, 25, 23, 21, 19, 17,
  120341. 15, 13, 11, 9, 7, 5, 3, 1,
  120342. 0, 2, 4, 6, 8, 10, 12, 14,
  120343. 16, 18, 20, 22, 24, 26, 28, 30,
  120344. 32, 34, 36, 38, 40, 42, 44, 46,
  120345. 48,
  120346. };
  120347. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120348. _vq_quantthresh__44c8_s_p9_2,
  120349. _vq_quantmap__44c8_s_p9_2,
  120350. 49,
  120351. 49
  120352. };
  120353. static static_codebook _44c8_s_p9_2 = {
  120354. 1, 49,
  120355. _vq_lengthlist__44c8_s_p9_2,
  120356. 1, -526909440, 1611661312, 6, 0,
  120357. _vq_quantlist__44c8_s_p9_2,
  120358. NULL,
  120359. &_vq_auxt__44c8_s_p9_2,
  120360. NULL,
  120361. 0
  120362. };
  120363. static long _huff_lengthlist__44c8_s_short[] = {
  120364. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120365. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120366. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120367. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120368. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120369. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120370. 10, 9,11,14,
  120371. };
  120372. static static_codebook _huff_book__44c8_s_short = {
  120373. 2, 100,
  120374. _huff_lengthlist__44c8_s_short,
  120375. 0, 0, 0, 0, 0,
  120376. NULL,
  120377. NULL,
  120378. NULL,
  120379. NULL,
  120380. 0
  120381. };
  120382. static long _huff_lengthlist__44c9_s_long[] = {
  120383. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120384. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120385. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120386. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120387. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120388. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120389. 10, 9, 8, 9,
  120390. };
  120391. static static_codebook _huff_book__44c9_s_long = {
  120392. 2, 100,
  120393. _huff_lengthlist__44c9_s_long,
  120394. 0, 0, 0, 0, 0,
  120395. NULL,
  120396. NULL,
  120397. NULL,
  120398. NULL,
  120399. 0
  120400. };
  120401. static long _vq_quantlist__44c9_s_p1_0[] = {
  120402. 1,
  120403. 0,
  120404. 2,
  120405. };
  120406. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120407. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120408. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120409. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120410. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120411. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120412. 7,
  120413. };
  120414. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120415. -0.5, 0.5,
  120416. };
  120417. static long _vq_quantmap__44c9_s_p1_0[] = {
  120418. 1, 0, 2,
  120419. };
  120420. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120421. _vq_quantthresh__44c9_s_p1_0,
  120422. _vq_quantmap__44c9_s_p1_0,
  120423. 3,
  120424. 3
  120425. };
  120426. static static_codebook _44c9_s_p1_0 = {
  120427. 4, 81,
  120428. _vq_lengthlist__44c9_s_p1_0,
  120429. 1, -535822336, 1611661312, 2, 0,
  120430. _vq_quantlist__44c9_s_p1_0,
  120431. NULL,
  120432. &_vq_auxt__44c9_s_p1_0,
  120433. NULL,
  120434. 0
  120435. };
  120436. static long _vq_quantlist__44c9_s_p2_0[] = {
  120437. 2,
  120438. 1,
  120439. 3,
  120440. 0,
  120441. 4,
  120442. };
  120443. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120444. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120445. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120446. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120447. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120448. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120449. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120450. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120451. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120453. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120454. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120455. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120456. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120457. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120458. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120459. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120461. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120462. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120463. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120464. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120465. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120466. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120467. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120469. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120470. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120471. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120472. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120473. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120474. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120475. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120480. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120481. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120482. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120483. 12,
  120484. };
  120485. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120486. -1.5, -0.5, 0.5, 1.5,
  120487. };
  120488. static long _vq_quantmap__44c9_s_p2_0[] = {
  120489. 3, 1, 0, 2, 4,
  120490. };
  120491. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120492. _vq_quantthresh__44c9_s_p2_0,
  120493. _vq_quantmap__44c9_s_p2_0,
  120494. 5,
  120495. 5
  120496. };
  120497. static static_codebook _44c9_s_p2_0 = {
  120498. 4, 625,
  120499. _vq_lengthlist__44c9_s_p2_0,
  120500. 1, -533725184, 1611661312, 3, 0,
  120501. _vq_quantlist__44c9_s_p2_0,
  120502. NULL,
  120503. &_vq_auxt__44c9_s_p2_0,
  120504. NULL,
  120505. 0
  120506. };
  120507. static long _vq_quantlist__44c9_s_p3_0[] = {
  120508. 4,
  120509. 3,
  120510. 5,
  120511. 2,
  120512. 6,
  120513. 1,
  120514. 7,
  120515. 0,
  120516. 8,
  120517. };
  120518. static long _vq_lengthlist__44c9_s_p3_0[] = {
  120519. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  120520. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  120521. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  120522. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  120523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120524. 0,
  120525. };
  120526. static float _vq_quantthresh__44c9_s_p3_0[] = {
  120527. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120528. };
  120529. static long _vq_quantmap__44c9_s_p3_0[] = {
  120530. 7, 5, 3, 1, 0, 2, 4, 6,
  120531. 8,
  120532. };
  120533. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  120534. _vq_quantthresh__44c9_s_p3_0,
  120535. _vq_quantmap__44c9_s_p3_0,
  120536. 9,
  120537. 9
  120538. };
  120539. static static_codebook _44c9_s_p3_0 = {
  120540. 2, 81,
  120541. _vq_lengthlist__44c9_s_p3_0,
  120542. 1, -531628032, 1611661312, 4, 0,
  120543. _vq_quantlist__44c9_s_p3_0,
  120544. NULL,
  120545. &_vq_auxt__44c9_s_p3_0,
  120546. NULL,
  120547. 0
  120548. };
  120549. static long _vq_quantlist__44c9_s_p4_0[] = {
  120550. 8,
  120551. 7,
  120552. 9,
  120553. 6,
  120554. 10,
  120555. 5,
  120556. 11,
  120557. 4,
  120558. 12,
  120559. 3,
  120560. 13,
  120561. 2,
  120562. 14,
  120563. 1,
  120564. 15,
  120565. 0,
  120566. 16,
  120567. };
  120568. static long _vq_lengthlist__44c9_s_p4_0[] = {
  120569. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  120570. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  120571. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  120572. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  120573. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  120574. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  120575. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  120576. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120577. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120578. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  120579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120587. 0,
  120588. };
  120589. static float _vq_quantthresh__44c9_s_p4_0[] = {
  120590. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120591. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120592. };
  120593. static long _vq_quantmap__44c9_s_p4_0[] = {
  120594. 15, 13, 11, 9, 7, 5, 3, 1,
  120595. 0, 2, 4, 6, 8, 10, 12, 14,
  120596. 16,
  120597. };
  120598. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  120599. _vq_quantthresh__44c9_s_p4_0,
  120600. _vq_quantmap__44c9_s_p4_0,
  120601. 17,
  120602. 17
  120603. };
  120604. static static_codebook _44c9_s_p4_0 = {
  120605. 2, 289,
  120606. _vq_lengthlist__44c9_s_p4_0,
  120607. 1, -529530880, 1611661312, 5, 0,
  120608. _vq_quantlist__44c9_s_p4_0,
  120609. NULL,
  120610. &_vq_auxt__44c9_s_p4_0,
  120611. NULL,
  120612. 0
  120613. };
  120614. static long _vq_quantlist__44c9_s_p5_0[] = {
  120615. 1,
  120616. 0,
  120617. 2,
  120618. };
  120619. static long _vq_lengthlist__44c9_s_p5_0[] = {
  120620. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  120621. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  120622. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  120623. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  120624. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  120625. 12,
  120626. };
  120627. static float _vq_quantthresh__44c9_s_p5_0[] = {
  120628. -5.5, 5.5,
  120629. };
  120630. static long _vq_quantmap__44c9_s_p5_0[] = {
  120631. 1, 0, 2,
  120632. };
  120633. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  120634. _vq_quantthresh__44c9_s_p5_0,
  120635. _vq_quantmap__44c9_s_p5_0,
  120636. 3,
  120637. 3
  120638. };
  120639. static static_codebook _44c9_s_p5_0 = {
  120640. 4, 81,
  120641. _vq_lengthlist__44c9_s_p5_0,
  120642. 1, -529137664, 1618345984, 2, 0,
  120643. _vq_quantlist__44c9_s_p5_0,
  120644. NULL,
  120645. &_vq_auxt__44c9_s_p5_0,
  120646. NULL,
  120647. 0
  120648. };
  120649. static long _vq_quantlist__44c9_s_p5_1[] = {
  120650. 5,
  120651. 4,
  120652. 6,
  120653. 3,
  120654. 7,
  120655. 2,
  120656. 8,
  120657. 1,
  120658. 9,
  120659. 0,
  120660. 10,
  120661. };
  120662. static long _vq_lengthlist__44c9_s_p5_1[] = {
  120663. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  120664. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  120665. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  120666. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  120667. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  120668. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  120669. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  120670. 11,11,11, 7, 7, 7, 7, 7, 7,
  120671. };
  120672. static float _vq_quantthresh__44c9_s_p5_1[] = {
  120673. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120674. 3.5, 4.5,
  120675. };
  120676. static long _vq_quantmap__44c9_s_p5_1[] = {
  120677. 9, 7, 5, 3, 1, 0, 2, 4,
  120678. 6, 8, 10,
  120679. };
  120680. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  120681. _vq_quantthresh__44c9_s_p5_1,
  120682. _vq_quantmap__44c9_s_p5_1,
  120683. 11,
  120684. 11
  120685. };
  120686. static static_codebook _44c9_s_p5_1 = {
  120687. 2, 121,
  120688. _vq_lengthlist__44c9_s_p5_1,
  120689. 1, -531365888, 1611661312, 4, 0,
  120690. _vq_quantlist__44c9_s_p5_1,
  120691. NULL,
  120692. &_vq_auxt__44c9_s_p5_1,
  120693. NULL,
  120694. 0
  120695. };
  120696. static long _vq_quantlist__44c9_s_p6_0[] = {
  120697. 6,
  120698. 5,
  120699. 7,
  120700. 4,
  120701. 8,
  120702. 3,
  120703. 9,
  120704. 2,
  120705. 10,
  120706. 1,
  120707. 11,
  120708. 0,
  120709. 12,
  120710. };
  120711. static long _vq_lengthlist__44c9_s_p6_0[] = {
  120712. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  120713. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  120714. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  120715. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120716. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  120717. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  120718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120722. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120723. };
  120724. static float _vq_quantthresh__44c9_s_p6_0[] = {
  120725. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120726. 12.5, 17.5, 22.5, 27.5,
  120727. };
  120728. static long _vq_quantmap__44c9_s_p6_0[] = {
  120729. 11, 9, 7, 5, 3, 1, 0, 2,
  120730. 4, 6, 8, 10, 12,
  120731. };
  120732. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  120733. _vq_quantthresh__44c9_s_p6_0,
  120734. _vq_quantmap__44c9_s_p6_0,
  120735. 13,
  120736. 13
  120737. };
  120738. static static_codebook _44c9_s_p6_0 = {
  120739. 2, 169,
  120740. _vq_lengthlist__44c9_s_p6_0,
  120741. 1, -526516224, 1616117760, 4, 0,
  120742. _vq_quantlist__44c9_s_p6_0,
  120743. NULL,
  120744. &_vq_auxt__44c9_s_p6_0,
  120745. NULL,
  120746. 0
  120747. };
  120748. static long _vq_quantlist__44c9_s_p6_1[] = {
  120749. 2,
  120750. 1,
  120751. 3,
  120752. 0,
  120753. 4,
  120754. };
  120755. static long _vq_lengthlist__44c9_s_p6_1[] = {
  120756. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  120757. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  120758. };
  120759. static float _vq_quantthresh__44c9_s_p6_1[] = {
  120760. -1.5, -0.5, 0.5, 1.5,
  120761. };
  120762. static long _vq_quantmap__44c9_s_p6_1[] = {
  120763. 3, 1, 0, 2, 4,
  120764. };
  120765. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  120766. _vq_quantthresh__44c9_s_p6_1,
  120767. _vq_quantmap__44c9_s_p6_1,
  120768. 5,
  120769. 5
  120770. };
  120771. static static_codebook _44c9_s_p6_1 = {
  120772. 2, 25,
  120773. _vq_lengthlist__44c9_s_p6_1,
  120774. 1, -533725184, 1611661312, 3, 0,
  120775. _vq_quantlist__44c9_s_p6_1,
  120776. NULL,
  120777. &_vq_auxt__44c9_s_p6_1,
  120778. NULL,
  120779. 0
  120780. };
  120781. static long _vq_quantlist__44c9_s_p7_0[] = {
  120782. 6,
  120783. 5,
  120784. 7,
  120785. 4,
  120786. 8,
  120787. 3,
  120788. 9,
  120789. 2,
  120790. 10,
  120791. 1,
  120792. 11,
  120793. 0,
  120794. 12,
  120795. };
  120796. static long _vq_lengthlist__44c9_s_p7_0[] = {
  120797. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  120798. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  120799. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  120800. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  120801. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  120802. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  120803. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  120804. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  120805. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  120806. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  120807. 19,12,12,12,12,13,13,14,14,
  120808. };
  120809. static float _vq_quantthresh__44c9_s_p7_0[] = {
  120810. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120811. 27.5, 38.5, 49.5, 60.5,
  120812. };
  120813. static long _vq_quantmap__44c9_s_p7_0[] = {
  120814. 11, 9, 7, 5, 3, 1, 0, 2,
  120815. 4, 6, 8, 10, 12,
  120816. };
  120817. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  120818. _vq_quantthresh__44c9_s_p7_0,
  120819. _vq_quantmap__44c9_s_p7_0,
  120820. 13,
  120821. 13
  120822. };
  120823. static static_codebook _44c9_s_p7_0 = {
  120824. 2, 169,
  120825. _vq_lengthlist__44c9_s_p7_0,
  120826. 1, -523206656, 1618345984, 4, 0,
  120827. _vq_quantlist__44c9_s_p7_0,
  120828. NULL,
  120829. &_vq_auxt__44c9_s_p7_0,
  120830. NULL,
  120831. 0
  120832. };
  120833. static long _vq_quantlist__44c9_s_p7_1[] = {
  120834. 5,
  120835. 4,
  120836. 6,
  120837. 3,
  120838. 7,
  120839. 2,
  120840. 8,
  120841. 1,
  120842. 9,
  120843. 0,
  120844. 10,
  120845. };
  120846. static long _vq_lengthlist__44c9_s_p7_1[] = {
  120847. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  120848. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120849. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  120850. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120851. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120852. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120853. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120854. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120855. };
  120856. static float _vq_quantthresh__44c9_s_p7_1[] = {
  120857. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120858. 3.5, 4.5,
  120859. };
  120860. static long _vq_quantmap__44c9_s_p7_1[] = {
  120861. 9, 7, 5, 3, 1, 0, 2, 4,
  120862. 6, 8, 10,
  120863. };
  120864. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  120865. _vq_quantthresh__44c9_s_p7_1,
  120866. _vq_quantmap__44c9_s_p7_1,
  120867. 11,
  120868. 11
  120869. };
  120870. static static_codebook _44c9_s_p7_1 = {
  120871. 2, 121,
  120872. _vq_lengthlist__44c9_s_p7_1,
  120873. 1, -531365888, 1611661312, 4, 0,
  120874. _vq_quantlist__44c9_s_p7_1,
  120875. NULL,
  120876. &_vq_auxt__44c9_s_p7_1,
  120877. NULL,
  120878. 0
  120879. };
  120880. static long _vq_quantlist__44c9_s_p8_0[] = {
  120881. 7,
  120882. 6,
  120883. 8,
  120884. 5,
  120885. 9,
  120886. 4,
  120887. 10,
  120888. 3,
  120889. 11,
  120890. 2,
  120891. 12,
  120892. 1,
  120893. 13,
  120894. 0,
  120895. 14,
  120896. };
  120897. static long _vq_lengthlist__44c9_s_p8_0[] = {
  120898. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  120899. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  120900. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  120901. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  120902. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  120903. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  120904. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  120905. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  120906. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  120907. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  120908. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  120909. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  120910. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  120911. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  120912. 14,
  120913. };
  120914. static float _vq_quantthresh__44c9_s_p8_0[] = {
  120915. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120916. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120917. };
  120918. static long _vq_quantmap__44c9_s_p8_0[] = {
  120919. 13, 11, 9, 7, 5, 3, 1, 0,
  120920. 2, 4, 6, 8, 10, 12, 14,
  120921. };
  120922. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  120923. _vq_quantthresh__44c9_s_p8_0,
  120924. _vq_quantmap__44c9_s_p8_0,
  120925. 15,
  120926. 15
  120927. };
  120928. static static_codebook _44c9_s_p8_0 = {
  120929. 2, 225,
  120930. _vq_lengthlist__44c9_s_p8_0,
  120931. 1, -520986624, 1620377600, 4, 0,
  120932. _vq_quantlist__44c9_s_p8_0,
  120933. NULL,
  120934. &_vq_auxt__44c9_s_p8_0,
  120935. NULL,
  120936. 0
  120937. };
  120938. static long _vq_quantlist__44c9_s_p8_1[] = {
  120939. 10,
  120940. 9,
  120941. 11,
  120942. 8,
  120943. 12,
  120944. 7,
  120945. 13,
  120946. 6,
  120947. 14,
  120948. 5,
  120949. 15,
  120950. 4,
  120951. 16,
  120952. 3,
  120953. 17,
  120954. 2,
  120955. 18,
  120956. 1,
  120957. 19,
  120958. 0,
  120959. 20,
  120960. };
  120961. static long _vq_lengthlist__44c9_s_p8_1[] = {
  120962. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120963. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120964. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120965. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120966. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120967. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120968. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  120969. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120970. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120971. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120972. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120973. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120974. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120975. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120976. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120977. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  120978. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  120979. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  120980. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  120981. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  120982. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  120983. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  120984. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  120985. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  120986. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  120987. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  120988. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  120989. 9, 9, 9,10, 9, 9, 9, 9, 9,
  120990. };
  120991. static float _vq_quantthresh__44c9_s_p8_1[] = {
  120992. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120993. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120994. 6.5, 7.5, 8.5, 9.5,
  120995. };
  120996. static long _vq_quantmap__44c9_s_p8_1[] = {
  120997. 19, 17, 15, 13, 11, 9, 7, 5,
  120998. 3, 1, 0, 2, 4, 6, 8, 10,
  120999. 12, 14, 16, 18, 20,
  121000. };
  121001. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121002. _vq_quantthresh__44c9_s_p8_1,
  121003. _vq_quantmap__44c9_s_p8_1,
  121004. 21,
  121005. 21
  121006. };
  121007. static static_codebook _44c9_s_p8_1 = {
  121008. 2, 441,
  121009. _vq_lengthlist__44c9_s_p8_1,
  121010. 1, -529268736, 1611661312, 5, 0,
  121011. _vq_quantlist__44c9_s_p8_1,
  121012. NULL,
  121013. &_vq_auxt__44c9_s_p8_1,
  121014. NULL,
  121015. 0
  121016. };
  121017. static long _vq_quantlist__44c9_s_p9_0[] = {
  121018. 9,
  121019. 8,
  121020. 10,
  121021. 7,
  121022. 11,
  121023. 6,
  121024. 12,
  121025. 5,
  121026. 13,
  121027. 4,
  121028. 14,
  121029. 3,
  121030. 15,
  121031. 2,
  121032. 16,
  121033. 1,
  121034. 17,
  121035. 0,
  121036. 18,
  121037. };
  121038. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121039. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121040. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121041. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121042. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121043. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121044. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121045. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121046. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121047. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121048. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121049. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121050. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121051. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121052. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121053. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121054. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121055. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121056. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121057. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121058. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121059. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121060. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121061. 11,11,11,11,11,11,11,11,11,
  121062. };
  121063. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121064. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121065. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121066. 6982.5, 7913.5,
  121067. };
  121068. static long _vq_quantmap__44c9_s_p9_0[] = {
  121069. 17, 15, 13, 11, 9, 7, 5, 3,
  121070. 1, 0, 2, 4, 6, 8, 10, 12,
  121071. 14, 16, 18,
  121072. };
  121073. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121074. _vq_quantthresh__44c9_s_p9_0,
  121075. _vq_quantmap__44c9_s_p9_0,
  121076. 19,
  121077. 19
  121078. };
  121079. static static_codebook _44c9_s_p9_0 = {
  121080. 2, 361,
  121081. _vq_lengthlist__44c9_s_p9_0,
  121082. 1, -508535424, 1631393792, 5, 0,
  121083. _vq_quantlist__44c9_s_p9_0,
  121084. NULL,
  121085. &_vq_auxt__44c9_s_p9_0,
  121086. NULL,
  121087. 0
  121088. };
  121089. static long _vq_quantlist__44c9_s_p9_1[] = {
  121090. 9,
  121091. 8,
  121092. 10,
  121093. 7,
  121094. 11,
  121095. 6,
  121096. 12,
  121097. 5,
  121098. 13,
  121099. 4,
  121100. 14,
  121101. 3,
  121102. 15,
  121103. 2,
  121104. 16,
  121105. 1,
  121106. 17,
  121107. 0,
  121108. 18,
  121109. };
  121110. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121111. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121112. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121113. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121114. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121115. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121116. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121117. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121118. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121119. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121120. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121121. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121122. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121123. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121124. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121125. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121126. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121127. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121128. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121129. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121130. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121131. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121132. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121133. 13,13,13,14,13,14,15,15,15,
  121134. };
  121135. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121136. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121137. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121138. 367.5, 416.5,
  121139. };
  121140. static long _vq_quantmap__44c9_s_p9_1[] = {
  121141. 17, 15, 13, 11, 9, 7, 5, 3,
  121142. 1, 0, 2, 4, 6, 8, 10, 12,
  121143. 14, 16, 18,
  121144. };
  121145. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121146. _vq_quantthresh__44c9_s_p9_1,
  121147. _vq_quantmap__44c9_s_p9_1,
  121148. 19,
  121149. 19
  121150. };
  121151. static static_codebook _44c9_s_p9_1 = {
  121152. 2, 361,
  121153. _vq_lengthlist__44c9_s_p9_1,
  121154. 1, -518287360, 1622704128, 5, 0,
  121155. _vq_quantlist__44c9_s_p9_1,
  121156. NULL,
  121157. &_vq_auxt__44c9_s_p9_1,
  121158. NULL,
  121159. 0
  121160. };
  121161. static long _vq_quantlist__44c9_s_p9_2[] = {
  121162. 24,
  121163. 23,
  121164. 25,
  121165. 22,
  121166. 26,
  121167. 21,
  121168. 27,
  121169. 20,
  121170. 28,
  121171. 19,
  121172. 29,
  121173. 18,
  121174. 30,
  121175. 17,
  121176. 31,
  121177. 16,
  121178. 32,
  121179. 15,
  121180. 33,
  121181. 14,
  121182. 34,
  121183. 13,
  121184. 35,
  121185. 12,
  121186. 36,
  121187. 11,
  121188. 37,
  121189. 10,
  121190. 38,
  121191. 9,
  121192. 39,
  121193. 8,
  121194. 40,
  121195. 7,
  121196. 41,
  121197. 6,
  121198. 42,
  121199. 5,
  121200. 43,
  121201. 4,
  121202. 44,
  121203. 3,
  121204. 45,
  121205. 2,
  121206. 46,
  121207. 1,
  121208. 47,
  121209. 0,
  121210. 48,
  121211. };
  121212. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121213. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121214. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121215. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121216. 7,
  121217. };
  121218. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121219. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121220. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121221. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121222. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121223. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121224. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121225. };
  121226. static long _vq_quantmap__44c9_s_p9_2[] = {
  121227. 47, 45, 43, 41, 39, 37, 35, 33,
  121228. 31, 29, 27, 25, 23, 21, 19, 17,
  121229. 15, 13, 11, 9, 7, 5, 3, 1,
  121230. 0, 2, 4, 6, 8, 10, 12, 14,
  121231. 16, 18, 20, 22, 24, 26, 28, 30,
  121232. 32, 34, 36, 38, 40, 42, 44, 46,
  121233. 48,
  121234. };
  121235. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121236. _vq_quantthresh__44c9_s_p9_2,
  121237. _vq_quantmap__44c9_s_p9_2,
  121238. 49,
  121239. 49
  121240. };
  121241. static static_codebook _44c9_s_p9_2 = {
  121242. 1, 49,
  121243. _vq_lengthlist__44c9_s_p9_2,
  121244. 1, -526909440, 1611661312, 6, 0,
  121245. _vq_quantlist__44c9_s_p9_2,
  121246. NULL,
  121247. &_vq_auxt__44c9_s_p9_2,
  121248. NULL,
  121249. 0
  121250. };
  121251. static long _huff_lengthlist__44c9_s_short[] = {
  121252. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121253. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121254. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121255. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121256. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121257. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121258. 9, 8,10,13,
  121259. };
  121260. static static_codebook _huff_book__44c9_s_short = {
  121261. 2, 100,
  121262. _huff_lengthlist__44c9_s_short,
  121263. 0, 0, 0, 0, 0,
  121264. NULL,
  121265. NULL,
  121266. NULL,
  121267. NULL,
  121268. 0
  121269. };
  121270. static long _huff_lengthlist__44c0_s_long[] = {
  121271. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121272. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121273. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121274. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121275. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121276. 12,
  121277. };
  121278. static static_codebook _huff_book__44c0_s_long = {
  121279. 2, 81,
  121280. _huff_lengthlist__44c0_s_long,
  121281. 0, 0, 0, 0, 0,
  121282. NULL,
  121283. NULL,
  121284. NULL,
  121285. NULL,
  121286. 0
  121287. };
  121288. static long _vq_quantlist__44c0_s_p1_0[] = {
  121289. 1,
  121290. 0,
  121291. 2,
  121292. };
  121293. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121294. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121295. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121300. 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121305. 0, 0, 0, 0, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  121309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  121314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  121319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 7, 7, 0, 0, 0, 0,
  121340. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  121345. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 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, 7, 9, 9, 0, 0,
  121350. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121355. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121360. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121386. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121391. 0, 0, 0, 0, 0, 9, 9,11, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121396. 0, 0, 0, 0, 0, 0, 9,11,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121674. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121679. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121684. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121704. 0,
  121705. };
  121706. static float _vq_quantthresh__44c0_s_p1_0[] = {
  121707. -0.5, 0.5,
  121708. };
  121709. static long _vq_quantmap__44c0_s_p1_0[] = {
  121710. 1, 0, 2,
  121711. };
  121712. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  121713. _vq_quantthresh__44c0_s_p1_0,
  121714. _vq_quantmap__44c0_s_p1_0,
  121715. 3,
  121716. 3
  121717. };
  121718. static static_codebook _44c0_s_p1_0 = {
  121719. 8, 6561,
  121720. _vq_lengthlist__44c0_s_p1_0,
  121721. 1, -535822336, 1611661312, 2, 0,
  121722. _vq_quantlist__44c0_s_p1_0,
  121723. NULL,
  121724. &_vq_auxt__44c0_s_p1_0,
  121725. NULL,
  121726. 0
  121727. };
  121728. static long _vq_quantlist__44c0_s_p2_0[] = {
  121729. 2,
  121730. 1,
  121731. 3,
  121732. 0,
  121733. 4,
  121734. };
  121735. static long _vq_lengthlist__44c0_s_p2_0[] = {
  121736. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  121738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121739. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  121741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121742. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121775. 0,
  121776. };
  121777. static float _vq_quantthresh__44c0_s_p2_0[] = {
  121778. -1.5, -0.5, 0.5, 1.5,
  121779. };
  121780. static long _vq_quantmap__44c0_s_p2_0[] = {
  121781. 3, 1, 0, 2, 4,
  121782. };
  121783. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  121784. _vq_quantthresh__44c0_s_p2_0,
  121785. _vq_quantmap__44c0_s_p2_0,
  121786. 5,
  121787. 5
  121788. };
  121789. static static_codebook _44c0_s_p2_0 = {
  121790. 4, 625,
  121791. _vq_lengthlist__44c0_s_p2_0,
  121792. 1, -533725184, 1611661312, 3, 0,
  121793. _vq_quantlist__44c0_s_p2_0,
  121794. NULL,
  121795. &_vq_auxt__44c0_s_p2_0,
  121796. NULL,
  121797. 0
  121798. };
  121799. static long _vq_quantlist__44c0_s_p3_0[] = {
  121800. 4,
  121801. 3,
  121802. 5,
  121803. 2,
  121804. 6,
  121805. 1,
  121806. 7,
  121807. 0,
  121808. 8,
  121809. };
  121810. static long _vq_lengthlist__44c0_s_p3_0[] = {
  121811. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  121812. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  121813. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  121814. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  121815. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121816. 0,
  121817. };
  121818. static float _vq_quantthresh__44c0_s_p3_0[] = {
  121819. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121820. };
  121821. static long _vq_quantmap__44c0_s_p3_0[] = {
  121822. 7, 5, 3, 1, 0, 2, 4, 6,
  121823. 8,
  121824. };
  121825. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  121826. _vq_quantthresh__44c0_s_p3_0,
  121827. _vq_quantmap__44c0_s_p3_0,
  121828. 9,
  121829. 9
  121830. };
  121831. static static_codebook _44c0_s_p3_0 = {
  121832. 2, 81,
  121833. _vq_lengthlist__44c0_s_p3_0,
  121834. 1, -531628032, 1611661312, 4, 0,
  121835. _vq_quantlist__44c0_s_p3_0,
  121836. NULL,
  121837. &_vq_auxt__44c0_s_p3_0,
  121838. NULL,
  121839. 0
  121840. };
  121841. static long _vq_quantlist__44c0_s_p4_0[] = {
  121842. 4,
  121843. 3,
  121844. 5,
  121845. 2,
  121846. 6,
  121847. 1,
  121848. 7,
  121849. 0,
  121850. 8,
  121851. };
  121852. static long _vq_lengthlist__44c0_s_p4_0[] = {
  121853. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  121854. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  121855. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  121856. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  121857. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  121858. 10,
  121859. };
  121860. static float _vq_quantthresh__44c0_s_p4_0[] = {
  121861. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121862. };
  121863. static long _vq_quantmap__44c0_s_p4_0[] = {
  121864. 7, 5, 3, 1, 0, 2, 4, 6,
  121865. 8,
  121866. };
  121867. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  121868. _vq_quantthresh__44c0_s_p4_0,
  121869. _vq_quantmap__44c0_s_p4_0,
  121870. 9,
  121871. 9
  121872. };
  121873. static static_codebook _44c0_s_p4_0 = {
  121874. 2, 81,
  121875. _vq_lengthlist__44c0_s_p4_0,
  121876. 1, -531628032, 1611661312, 4, 0,
  121877. _vq_quantlist__44c0_s_p4_0,
  121878. NULL,
  121879. &_vq_auxt__44c0_s_p4_0,
  121880. NULL,
  121881. 0
  121882. };
  121883. static long _vq_quantlist__44c0_s_p5_0[] = {
  121884. 8,
  121885. 7,
  121886. 9,
  121887. 6,
  121888. 10,
  121889. 5,
  121890. 11,
  121891. 4,
  121892. 12,
  121893. 3,
  121894. 13,
  121895. 2,
  121896. 14,
  121897. 1,
  121898. 15,
  121899. 0,
  121900. 16,
  121901. };
  121902. static long _vq_lengthlist__44c0_s_p5_0[] = {
  121903. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  121904. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  121905. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  121906. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  121907. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  121908. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  121909. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  121910. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  121911. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  121912. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  121913. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  121914. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  121915. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  121916. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  121917. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  121918. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  121919. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  121920. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  121921. 14,
  121922. };
  121923. static float _vq_quantthresh__44c0_s_p5_0[] = {
  121924. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121925. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121926. };
  121927. static long _vq_quantmap__44c0_s_p5_0[] = {
  121928. 15, 13, 11, 9, 7, 5, 3, 1,
  121929. 0, 2, 4, 6, 8, 10, 12, 14,
  121930. 16,
  121931. };
  121932. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  121933. _vq_quantthresh__44c0_s_p5_0,
  121934. _vq_quantmap__44c0_s_p5_0,
  121935. 17,
  121936. 17
  121937. };
  121938. static static_codebook _44c0_s_p5_0 = {
  121939. 2, 289,
  121940. _vq_lengthlist__44c0_s_p5_0,
  121941. 1, -529530880, 1611661312, 5, 0,
  121942. _vq_quantlist__44c0_s_p5_0,
  121943. NULL,
  121944. &_vq_auxt__44c0_s_p5_0,
  121945. NULL,
  121946. 0
  121947. };
  121948. static long _vq_quantlist__44c0_s_p6_0[] = {
  121949. 1,
  121950. 0,
  121951. 2,
  121952. };
  121953. static long _vq_lengthlist__44c0_s_p6_0[] = {
  121954. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  121955. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  121956. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  121957. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  121958. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  121959. 10,
  121960. };
  121961. static float _vq_quantthresh__44c0_s_p6_0[] = {
  121962. -5.5, 5.5,
  121963. };
  121964. static long _vq_quantmap__44c0_s_p6_0[] = {
  121965. 1, 0, 2,
  121966. };
  121967. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  121968. _vq_quantthresh__44c0_s_p6_0,
  121969. _vq_quantmap__44c0_s_p6_0,
  121970. 3,
  121971. 3
  121972. };
  121973. static static_codebook _44c0_s_p6_0 = {
  121974. 4, 81,
  121975. _vq_lengthlist__44c0_s_p6_0,
  121976. 1, -529137664, 1618345984, 2, 0,
  121977. _vq_quantlist__44c0_s_p6_0,
  121978. NULL,
  121979. &_vq_auxt__44c0_s_p6_0,
  121980. NULL,
  121981. 0
  121982. };
  121983. static long _vq_quantlist__44c0_s_p6_1[] = {
  121984. 5,
  121985. 4,
  121986. 6,
  121987. 3,
  121988. 7,
  121989. 2,
  121990. 8,
  121991. 1,
  121992. 9,
  121993. 0,
  121994. 10,
  121995. };
  121996. static long _vq_lengthlist__44c0_s_p6_1[] = {
  121997. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  121998. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  121999. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122000. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122001. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122002. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122003. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122004. 10,10,10, 8, 8, 8, 8, 8, 8,
  122005. };
  122006. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122007. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122008. 3.5, 4.5,
  122009. };
  122010. static long _vq_quantmap__44c0_s_p6_1[] = {
  122011. 9, 7, 5, 3, 1, 0, 2, 4,
  122012. 6, 8, 10,
  122013. };
  122014. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122015. _vq_quantthresh__44c0_s_p6_1,
  122016. _vq_quantmap__44c0_s_p6_1,
  122017. 11,
  122018. 11
  122019. };
  122020. static static_codebook _44c0_s_p6_1 = {
  122021. 2, 121,
  122022. _vq_lengthlist__44c0_s_p6_1,
  122023. 1, -531365888, 1611661312, 4, 0,
  122024. _vq_quantlist__44c0_s_p6_1,
  122025. NULL,
  122026. &_vq_auxt__44c0_s_p6_1,
  122027. NULL,
  122028. 0
  122029. };
  122030. static long _vq_quantlist__44c0_s_p7_0[] = {
  122031. 6,
  122032. 5,
  122033. 7,
  122034. 4,
  122035. 8,
  122036. 3,
  122037. 9,
  122038. 2,
  122039. 10,
  122040. 1,
  122041. 11,
  122042. 0,
  122043. 12,
  122044. };
  122045. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122046. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122047. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122048. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122049. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122050. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122051. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122052. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122053. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122054. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122055. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122056. 0,12,12,11,11,12,12,13,13,
  122057. };
  122058. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122059. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122060. 12.5, 17.5, 22.5, 27.5,
  122061. };
  122062. static long _vq_quantmap__44c0_s_p7_0[] = {
  122063. 11, 9, 7, 5, 3, 1, 0, 2,
  122064. 4, 6, 8, 10, 12,
  122065. };
  122066. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122067. _vq_quantthresh__44c0_s_p7_0,
  122068. _vq_quantmap__44c0_s_p7_0,
  122069. 13,
  122070. 13
  122071. };
  122072. static static_codebook _44c0_s_p7_0 = {
  122073. 2, 169,
  122074. _vq_lengthlist__44c0_s_p7_0,
  122075. 1, -526516224, 1616117760, 4, 0,
  122076. _vq_quantlist__44c0_s_p7_0,
  122077. NULL,
  122078. &_vq_auxt__44c0_s_p7_0,
  122079. NULL,
  122080. 0
  122081. };
  122082. static long _vq_quantlist__44c0_s_p7_1[] = {
  122083. 2,
  122084. 1,
  122085. 3,
  122086. 0,
  122087. 4,
  122088. };
  122089. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122090. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122091. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122092. };
  122093. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122094. -1.5, -0.5, 0.5, 1.5,
  122095. };
  122096. static long _vq_quantmap__44c0_s_p7_1[] = {
  122097. 3, 1, 0, 2, 4,
  122098. };
  122099. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122100. _vq_quantthresh__44c0_s_p7_1,
  122101. _vq_quantmap__44c0_s_p7_1,
  122102. 5,
  122103. 5
  122104. };
  122105. static static_codebook _44c0_s_p7_1 = {
  122106. 2, 25,
  122107. _vq_lengthlist__44c0_s_p7_1,
  122108. 1, -533725184, 1611661312, 3, 0,
  122109. _vq_quantlist__44c0_s_p7_1,
  122110. NULL,
  122111. &_vq_auxt__44c0_s_p7_1,
  122112. NULL,
  122113. 0
  122114. };
  122115. static long _vq_quantlist__44c0_s_p8_0[] = {
  122116. 2,
  122117. 1,
  122118. 3,
  122119. 0,
  122120. 4,
  122121. };
  122122. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122123. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122124. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122125. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122126. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122127. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122128. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122129. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122130. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122131. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122132. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122133. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122134. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122135. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122136. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122137. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122138. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122139. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122140. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122141. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122142. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122143. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122144. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122145. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122146. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122147. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122148. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122149. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122150. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122151. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122152. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122153. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122154. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122155. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122156. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122157. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122158. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122159. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122160. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122161. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122162. 11,
  122163. };
  122164. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122165. -331.5, -110.5, 110.5, 331.5,
  122166. };
  122167. static long _vq_quantmap__44c0_s_p8_0[] = {
  122168. 3, 1, 0, 2, 4,
  122169. };
  122170. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122171. _vq_quantthresh__44c0_s_p8_0,
  122172. _vq_quantmap__44c0_s_p8_0,
  122173. 5,
  122174. 5
  122175. };
  122176. static static_codebook _44c0_s_p8_0 = {
  122177. 4, 625,
  122178. _vq_lengthlist__44c0_s_p8_0,
  122179. 1, -518283264, 1627103232, 3, 0,
  122180. _vq_quantlist__44c0_s_p8_0,
  122181. NULL,
  122182. &_vq_auxt__44c0_s_p8_0,
  122183. NULL,
  122184. 0
  122185. };
  122186. static long _vq_quantlist__44c0_s_p8_1[] = {
  122187. 6,
  122188. 5,
  122189. 7,
  122190. 4,
  122191. 8,
  122192. 3,
  122193. 9,
  122194. 2,
  122195. 10,
  122196. 1,
  122197. 11,
  122198. 0,
  122199. 12,
  122200. };
  122201. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122202. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122203. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122204. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122205. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122206. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122207. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122208. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122209. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122210. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122211. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122212. 16,13,13,12,12,14,14,15,13,
  122213. };
  122214. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122215. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122216. 42.5, 59.5, 76.5, 93.5,
  122217. };
  122218. static long _vq_quantmap__44c0_s_p8_1[] = {
  122219. 11, 9, 7, 5, 3, 1, 0, 2,
  122220. 4, 6, 8, 10, 12,
  122221. };
  122222. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122223. _vq_quantthresh__44c0_s_p8_1,
  122224. _vq_quantmap__44c0_s_p8_1,
  122225. 13,
  122226. 13
  122227. };
  122228. static static_codebook _44c0_s_p8_1 = {
  122229. 2, 169,
  122230. _vq_lengthlist__44c0_s_p8_1,
  122231. 1, -522616832, 1620115456, 4, 0,
  122232. _vq_quantlist__44c0_s_p8_1,
  122233. NULL,
  122234. &_vq_auxt__44c0_s_p8_1,
  122235. NULL,
  122236. 0
  122237. };
  122238. static long _vq_quantlist__44c0_s_p8_2[] = {
  122239. 8,
  122240. 7,
  122241. 9,
  122242. 6,
  122243. 10,
  122244. 5,
  122245. 11,
  122246. 4,
  122247. 12,
  122248. 3,
  122249. 13,
  122250. 2,
  122251. 14,
  122252. 1,
  122253. 15,
  122254. 0,
  122255. 16,
  122256. };
  122257. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122258. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122259. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122260. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122261. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122262. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122263. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122264. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122265. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122266. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122267. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122268. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122269. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122270. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122271. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122272. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122273. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122274. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122275. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122276. 10,
  122277. };
  122278. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122279. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122280. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122281. };
  122282. static long _vq_quantmap__44c0_s_p8_2[] = {
  122283. 15, 13, 11, 9, 7, 5, 3, 1,
  122284. 0, 2, 4, 6, 8, 10, 12, 14,
  122285. 16,
  122286. };
  122287. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122288. _vq_quantthresh__44c0_s_p8_2,
  122289. _vq_quantmap__44c0_s_p8_2,
  122290. 17,
  122291. 17
  122292. };
  122293. static static_codebook _44c0_s_p8_2 = {
  122294. 2, 289,
  122295. _vq_lengthlist__44c0_s_p8_2,
  122296. 1, -529530880, 1611661312, 5, 0,
  122297. _vq_quantlist__44c0_s_p8_2,
  122298. NULL,
  122299. &_vq_auxt__44c0_s_p8_2,
  122300. NULL,
  122301. 0
  122302. };
  122303. static long _huff_lengthlist__44c0_s_short[] = {
  122304. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122305. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122306. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122307. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122308. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122309. 12,
  122310. };
  122311. static static_codebook _huff_book__44c0_s_short = {
  122312. 2, 81,
  122313. _huff_lengthlist__44c0_s_short,
  122314. 0, 0, 0, 0, 0,
  122315. NULL,
  122316. NULL,
  122317. NULL,
  122318. NULL,
  122319. 0
  122320. };
  122321. static long _huff_lengthlist__44c0_sm_long[] = {
  122322. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122323. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122324. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122325. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122326. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122327. 13,
  122328. };
  122329. static static_codebook _huff_book__44c0_sm_long = {
  122330. 2, 81,
  122331. _huff_lengthlist__44c0_sm_long,
  122332. 0, 0, 0, 0, 0,
  122333. NULL,
  122334. NULL,
  122335. NULL,
  122336. NULL,
  122337. 0
  122338. };
  122339. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122340. 1,
  122341. 0,
  122342. 2,
  122343. };
  122344. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122345. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122346. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122351. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122356. 0, 0, 0, 0, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  122360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  122365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  122370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 7, 0, 0, 0, 0,
  122391. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  122396. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  122401. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122406. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122411. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122437. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122442. 0, 0, 0, 0, 0, 9, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122447. 0, 0, 0, 0, 0, 0, 9,10,10, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122755. 0,
  122756. };
  122757. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  122758. -0.5, 0.5,
  122759. };
  122760. static long _vq_quantmap__44c0_sm_p1_0[] = {
  122761. 1, 0, 2,
  122762. };
  122763. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  122764. _vq_quantthresh__44c0_sm_p1_0,
  122765. _vq_quantmap__44c0_sm_p1_0,
  122766. 3,
  122767. 3
  122768. };
  122769. static static_codebook _44c0_sm_p1_0 = {
  122770. 8, 6561,
  122771. _vq_lengthlist__44c0_sm_p1_0,
  122772. 1, -535822336, 1611661312, 2, 0,
  122773. _vq_quantlist__44c0_sm_p1_0,
  122774. NULL,
  122775. &_vq_auxt__44c0_sm_p1_0,
  122776. NULL,
  122777. 0
  122778. };
  122779. static long _vq_quantlist__44c0_sm_p2_0[] = {
  122780. 2,
  122781. 1,
  122782. 3,
  122783. 0,
  122784. 4,
  122785. };
  122786. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  122787. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  122789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122790. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122793. 0, 0, 0, 0, 7, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122826. 0,
  122827. };
  122828. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  122829. -1.5, -0.5, 0.5, 1.5,
  122830. };
  122831. static long _vq_quantmap__44c0_sm_p2_0[] = {
  122832. 3, 1, 0, 2, 4,
  122833. };
  122834. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  122835. _vq_quantthresh__44c0_sm_p2_0,
  122836. _vq_quantmap__44c0_sm_p2_0,
  122837. 5,
  122838. 5
  122839. };
  122840. static static_codebook _44c0_sm_p2_0 = {
  122841. 4, 625,
  122842. _vq_lengthlist__44c0_sm_p2_0,
  122843. 1, -533725184, 1611661312, 3, 0,
  122844. _vq_quantlist__44c0_sm_p2_0,
  122845. NULL,
  122846. &_vq_auxt__44c0_sm_p2_0,
  122847. NULL,
  122848. 0
  122849. };
  122850. static long _vq_quantlist__44c0_sm_p3_0[] = {
  122851. 4,
  122852. 3,
  122853. 5,
  122854. 2,
  122855. 6,
  122856. 1,
  122857. 7,
  122858. 0,
  122859. 8,
  122860. };
  122861. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  122862. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  122863. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  122864. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  122865. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  122866. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122867. 0,
  122868. };
  122869. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  122870. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122871. };
  122872. static long _vq_quantmap__44c0_sm_p3_0[] = {
  122873. 7, 5, 3, 1, 0, 2, 4, 6,
  122874. 8,
  122875. };
  122876. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  122877. _vq_quantthresh__44c0_sm_p3_0,
  122878. _vq_quantmap__44c0_sm_p3_0,
  122879. 9,
  122880. 9
  122881. };
  122882. static static_codebook _44c0_sm_p3_0 = {
  122883. 2, 81,
  122884. _vq_lengthlist__44c0_sm_p3_0,
  122885. 1, -531628032, 1611661312, 4, 0,
  122886. _vq_quantlist__44c0_sm_p3_0,
  122887. NULL,
  122888. &_vq_auxt__44c0_sm_p3_0,
  122889. NULL,
  122890. 0
  122891. };
  122892. static long _vq_quantlist__44c0_sm_p4_0[] = {
  122893. 4,
  122894. 3,
  122895. 5,
  122896. 2,
  122897. 6,
  122898. 1,
  122899. 7,
  122900. 0,
  122901. 8,
  122902. };
  122903. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  122904. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  122905. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  122906. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  122907. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  122908. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  122909. 11,
  122910. };
  122911. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  122912. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122913. };
  122914. static long _vq_quantmap__44c0_sm_p4_0[] = {
  122915. 7, 5, 3, 1, 0, 2, 4, 6,
  122916. 8,
  122917. };
  122918. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  122919. _vq_quantthresh__44c0_sm_p4_0,
  122920. _vq_quantmap__44c0_sm_p4_0,
  122921. 9,
  122922. 9
  122923. };
  122924. static static_codebook _44c0_sm_p4_0 = {
  122925. 2, 81,
  122926. _vq_lengthlist__44c0_sm_p4_0,
  122927. 1, -531628032, 1611661312, 4, 0,
  122928. _vq_quantlist__44c0_sm_p4_0,
  122929. NULL,
  122930. &_vq_auxt__44c0_sm_p4_0,
  122931. NULL,
  122932. 0
  122933. };
  122934. static long _vq_quantlist__44c0_sm_p5_0[] = {
  122935. 8,
  122936. 7,
  122937. 9,
  122938. 6,
  122939. 10,
  122940. 5,
  122941. 11,
  122942. 4,
  122943. 12,
  122944. 3,
  122945. 13,
  122946. 2,
  122947. 14,
  122948. 1,
  122949. 15,
  122950. 0,
  122951. 16,
  122952. };
  122953. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  122954. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  122955. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  122956. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122957. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  122958. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  122959. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  122960. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  122961. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122962. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  122963. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  122964. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122965. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122966. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  122967. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  122968. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  122969. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  122970. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  122971. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122972. 14,
  122973. };
  122974. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  122975. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122976. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122977. };
  122978. static long _vq_quantmap__44c0_sm_p5_0[] = {
  122979. 15, 13, 11, 9, 7, 5, 3, 1,
  122980. 0, 2, 4, 6, 8, 10, 12, 14,
  122981. 16,
  122982. };
  122983. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  122984. _vq_quantthresh__44c0_sm_p5_0,
  122985. _vq_quantmap__44c0_sm_p5_0,
  122986. 17,
  122987. 17
  122988. };
  122989. static static_codebook _44c0_sm_p5_0 = {
  122990. 2, 289,
  122991. _vq_lengthlist__44c0_sm_p5_0,
  122992. 1, -529530880, 1611661312, 5, 0,
  122993. _vq_quantlist__44c0_sm_p5_0,
  122994. NULL,
  122995. &_vq_auxt__44c0_sm_p5_0,
  122996. NULL,
  122997. 0
  122998. };
  122999. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123000. 1,
  123001. 0,
  123002. 2,
  123003. };
  123004. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123005. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123006. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123007. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123008. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123009. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123010. 11,
  123011. };
  123012. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123013. -5.5, 5.5,
  123014. };
  123015. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123016. 1, 0, 2,
  123017. };
  123018. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123019. _vq_quantthresh__44c0_sm_p6_0,
  123020. _vq_quantmap__44c0_sm_p6_0,
  123021. 3,
  123022. 3
  123023. };
  123024. static static_codebook _44c0_sm_p6_0 = {
  123025. 4, 81,
  123026. _vq_lengthlist__44c0_sm_p6_0,
  123027. 1, -529137664, 1618345984, 2, 0,
  123028. _vq_quantlist__44c0_sm_p6_0,
  123029. NULL,
  123030. &_vq_auxt__44c0_sm_p6_0,
  123031. NULL,
  123032. 0
  123033. };
  123034. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123035. 5,
  123036. 4,
  123037. 6,
  123038. 3,
  123039. 7,
  123040. 2,
  123041. 8,
  123042. 1,
  123043. 9,
  123044. 0,
  123045. 10,
  123046. };
  123047. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123048. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123049. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123050. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123051. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123052. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123053. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123054. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123055. 10,10,10, 8, 8, 8, 8, 8, 8,
  123056. };
  123057. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123058. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123059. 3.5, 4.5,
  123060. };
  123061. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123062. 9, 7, 5, 3, 1, 0, 2, 4,
  123063. 6, 8, 10,
  123064. };
  123065. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123066. _vq_quantthresh__44c0_sm_p6_1,
  123067. _vq_quantmap__44c0_sm_p6_1,
  123068. 11,
  123069. 11
  123070. };
  123071. static static_codebook _44c0_sm_p6_1 = {
  123072. 2, 121,
  123073. _vq_lengthlist__44c0_sm_p6_1,
  123074. 1, -531365888, 1611661312, 4, 0,
  123075. _vq_quantlist__44c0_sm_p6_1,
  123076. NULL,
  123077. &_vq_auxt__44c0_sm_p6_1,
  123078. NULL,
  123079. 0
  123080. };
  123081. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123082. 6,
  123083. 5,
  123084. 7,
  123085. 4,
  123086. 8,
  123087. 3,
  123088. 9,
  123089. 2,
  123090. 10,
  123091. 1,
  123092. 11,
  123093. 0,
  123094. 12,
  123095. };
  123096. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123097. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123098. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123099. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123100. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123101. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123102. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123103. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123104. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123105. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123106. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123107. 0,12,12,11,11,13,12,14,14,
  123108. };
  123109. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123110. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123111. 12.5, 17.5, 22.5, 27.5,
  123112. };
  123113. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123114. 11, 9, 7, 5, 3, 1, 0, 2,
  123115. 4, 6, 8, 10, 12,
  123116. };
  123117. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123118. _vq_quantthresh__44c0_sm_p7_0,
  123119. _vq_quantmap__44c0_sm_p7_0,
  123120. 13,
  123121. 13
  123122. };
  123123. static static_codebook _44c0_sm_p7_0 = {
  123124. 2, 169,
  123125. _vq_lengthlist__44c0_sm_p7_0,
  123126. 1, -526516224, 1616117760, 4, 0,
  123127. _vq_quantlist__44c0_sm_p7_0,
  123128. NULL,
  123129. &_vq_auxt__44c0_sm_p7_0,
  123130. NULL,
  123131. 0
  123132. };
  123133. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123134. 2,
  123135. 1,
  123136. 3,
  123137. 0,
  123138. 4,
  123139. };
  123140. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123141. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123142. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123143. };
  123144. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123145. -1.5, -0.5, 0.5, 1.5,
  123146. };
  123147. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123148. 3, 1, 0, 2, 4,
  123149. };
  123150. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123151. _vq_quantthresh__44c0_sm_p7_1,
  123152. _vq_quantmap__44c0_sm_p7_1,
  123153. 5,
  123154. 5
  123155. };
  123156. static static_codebook _44c0_sm_p7_1 = {
  123157. 2, 25,
  123158. _vq_lengthlist__44c0_sm_p7_1,
  123159. 1, -533725184, 1611661312, 3, 0,
  123160. _vq_quantlist__44c0_sm_p7_1,
  123161. NULL,
  123162. &_vq_auxt__44c0_sm_p7_1,
  123163. NULL,
  123164. 0
  123165. };
  123166. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123167. 4,
  123168. 3,
  123169. 5,
  123170. 2,
  123171. 6,
  123172. 1,
  123173. 7,
  123174. 0,
  123175. 8,
  123176. };
  123177. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123178. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123179. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123180. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123181. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123182. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123183. 12,
  123184. };
  123185. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123186. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123187. };
  123188. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123189. 7, 5, 3, 1, 0, 2, 4, 6,
  123190. 8,
  123191. };
  123192. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123193. _vq_quantthresh__44c0_sm_p8_0,
  123194. _vq_quantmap__44c0_sm_p8_0,
  123195. 9,
  123196. 9
  123197. };
  123198. static static_codebook _44c0_sm_p8_0 = {
  123199. 2, 81,
  123200. _vq_lengthlist__44c0_sm_p8_0,
  123201. 1, -516186112, 1627103232, 4, 0,
  123202. _vq_quantlist__44c0_sm_p8_0,
  123203. NULL,
  123204. &_vq_auxt__44c0_sm_p8_0,
  123205. NULL,
  123206. 0
  123207. };
  123208. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123209. 6,
  123210. 5,
  123211. 7,
  123212. 4,
  123213. 8,
  123214. 3,
  123215. 9,
  123216. 2,
  123217. 10,
  123218. 1,
  123219. 11,
  123220. 0,
  123221. 12,
  123222. };
  123223. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123224. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123225. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123226. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123227. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123228. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123229. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123230. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123231. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123232. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123233. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123234. 20,13,13,12,12,16,13,15,13,
  123235. };
  123236. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123237. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123238. 42.5, 59.5, 76.5, 93.5,
  123239. };
  123240. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123241. 11, 9, 7, 5, 3, 1, 0, 2,
  123242. 4, 6, 8, 10, 12,
  123243. };
  123244. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123245. _vq_quantthresh__44c0_sm_p8_1,
  123246. _vq_quantmap__44c0_sm_p8_1,
  123247. 13,
  123248. 13
  123249. };
  123250. static static_codebook _44c0_sm_p8_1 = {
  123251. 2, 169,
  123252. _vq_lengthlist__44c0_sm_p8_1,
  123253. 1, -522616832, 1620115456, 4, 0,
  123254. _vq_quantlist__44c0_sm_p8_1,
  123255. NULL,
  123256. &_vq_auxt__44c0_sm_p8_1,
  123257. NULL,
  123258. 0
  123259. };
  123260. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123261. 8,
  123262. 7,
  123263. 9,
  123264. 6,
  123265. 10,
  123266. 5,
  123267. 11,
  123268. 4,
  123269. 12,
  123270. 3,
  123271. 13,
  123272. 2,
  123273. 14,
  123274. 1,
  123275. 15,
  123276. 0,
  123277. 16,
  123278. };
  123279. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123280. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123281. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123282. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123283. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123284. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123285. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123286. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123287. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123288. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123289. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123290. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123291. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123292. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123293. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123294. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123295. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123296. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123297. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123298. 9,
  123299. };
  123300. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123301. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123302. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123303. };
  123304. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123305. 15, 13, 11, 9, 7, 5, 3, 1,
  123306. 0, 2, 4, 6, 8, 10, 12, 14,
  123307. 16,
  123308. };
  123309. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123310. _vq_quantthresh__44c0_sm_p8_2,
  123311. _vq_quantmap__44c0_sm_p8_2,
  123312. 17,
  123313. 17
  123314. };
  123315. static static_codebook _44c0_sm_p8_2 = {
  123316. 2, 289,
  123317. _vq_lengthlist__44c0_sm_p8_2,
  123318. 1, -529530880, 1611661312, 5, 0,
  123319. _vq_quantlist__44c0_sm_p8_2,
  123320. NULL,
  123321. &_vq_auxt__44c0_sm_p8_2,
  123322. NULL,
  123323. 0
  123324. };
  123325. static long _huff_lengthlist__44c0_sm_short[] = {
  123326. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123327. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123328. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123329. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123330. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123331. 12,
  123332. };
  123333. static static_codebook _huff_book__44c0_sm_short = {
  123334. 2, 81,
  123335. _huff_lengthlist__44c0_sm_short,
  123336. 0, 0, 0, 0, 0,
  123337. NULL,
  123338. NULL,
  123339. NULL,
  123340. NULL,
  123341. 0
  123342. };
  123343. static long _huff_lengthlist__44c1_s_long[] = {
  123344. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123345. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123346. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123347. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123348. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123349. 11,
  123350. };
  123351. static static_codebook _huff_book__44c1_s_long = {
  123352. 2, 81,
  123353. _huff_lengthlist__44c1_s_long,
  123354. 0, 0, 0, 0, 0,
  123355. NULL,
  123356. NULL,
  123357. NULL,
  123358. NULL,
  123359. 0
  123360. };
  123361. static long _vq_quantlist__44c1_s_p1_0[] = {
  123362. 1,
  123363. 0,
  123364. 2,
  123365. };
  123366. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123367. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123368. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123373. 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123378. 0, 0, 0, 0, 7, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0,
  123382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  123387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  123392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 4, 7, 7, 0, 0, 0, 0,
  123413. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 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, 7, 8, 8, 0, 0, 0,
  123418. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 6, 8, 8, 0, 0,
  123423. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123428. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123433. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123459. 0, 0, 0, 0, 7, 8, 9, 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, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123464. 0, 0, 0, 0, 0, 8, 8, 9, 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, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123469. 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123777. 0,
  123778. };
  123779. static float _vq_quantthresh__44c1_s_p1_0[] = {
  123780. -0.5, 0.5,
  123781. };
  123782. static long _vq_quantmap__44c1_s_p1_0[] = {
  123783. 1, 0, 2,
  123784. };
  123785. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  123786. _vq_quantthresh__44c1_s_p1_0,
  123787. _vq_quantmap__44c1_s_p1_0,
  123788. 3,
  123789. 3
  123790. };
  123791. static static_codebook _44c1_s_p1_0 = {
  123792. 8, 6561,
  123793. _vq_lengthlist__44c1_s_p1_0,
  123794. 1, -535822336, 1611661312, 2, 0,
  123795. _vq_quantlist__44c1_s_p1_0,
  123796. NULL,
  123797. &_vq_auxt__44c1_s_p1_0,
  123798. NULL,
  123799. 0
  123800. };
  123801. static long _vq_quantlist__44c1_s_p2_0[] = {
  123802. 2,
  123803. 1,
  123804. 3,
  123805. 0,
  123806. 4,
  123807. };
  123808. static long _vq_lengthlist__44c1_s_p2_0[] = {
  123809. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  123811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123812. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  123814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123815. 0, 0, 0, 0, 6, 6, 6, 8, 8, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123848. 0,
  123849. };
  123850. static float _vq_quantthresh__44c1_s_p2_0[] = {
  123851. -1.5, -0.5, 0.5, 1.5,
  123852. };
  123853. static long _vq_quantmap__44c1_s_p2_0[] = {
  123854. 3, 1, 0, 2, 4,
  123855. };
  123856. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  123857. _vq_quantthresh__44c1_s_p2_0,
  123858. _vq_quantmap__44c1_s_p2_0,
  123859. 5,
  123860. 5
  123861. };
  123862. static static_codebook _44c1_s_p2_0 = {
  123863. 4, 625,
  123864. _vq_lengthlist__44c1_s_p2_0,
  123865. 1, -533725184, 1611661312, 3, 0,
  123866. _vq_quantlist__44c1_s_p2_0,
  123867. NULL,
  123868. &_vq_auxt__44c1_s_p2_0,
  123869. NULL,
  123870. 0
  123871. };
  123872. static long _vq_quantlist__44c1_s_p3_0[] = {
  123873. 4,
  123874. 3,
  123875. 5,
  123876. 2,
  123877. 6,
  123878. 1,
  123879. 7,
  123880. 0,
  123881. 8,
  123882. };
  123883. static long _vq_lengthlist__44c1_s_p3_0[] = {
  123884. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  123885. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  123886. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  123887. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  123888. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123889. 0,
  123890. };
  123891. static float _vq_quantthresh__44c1_s_p3_0[] = {
  123892. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123893. };
  123894. static long _vq_quantmap__44c1_s_p3_0[] = {
  123895. 7, 5, 3, 1, 0, 2, 4, 6,
  123896. 8,
  123897. };
  123898. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  123899. _vq_quantthresh__44c1_s_p3_0,
  123900. _vq_quantmap__44c1_s_p3_0,
  123901. 9,
  123902. 9
  123903. };
  123904. static static_codebook _44c1_s_p3_0 = {
  123905. 2, 81,
  123906. _vq_lengthlist__44c1_s_p3_0,
  123907. 1, -531628032, 1611661312, 4, 0,
  123908. _vq_quantlist__44c1_s_p3_0,
  123909. NULL,
  123910. &_vq_auxt__44c1_s_p3_0,
  123911. NULL,
  123912. 0
  123913. };
  123914. static long _vq_quantlist__44c1_s_p4_0[] = {
  123915. 4,
  123916. 3,
  123917. 5,
  123918. 2,
  123919. 6,
  123920. 1,
  123921. 7,
  123922. 0,
  123923. 8,
  123924. };
  123925. static long _vq_lengthlist__44c1_s_p4_0[] = {
  123926. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  123927. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  123928. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  123929. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  123930. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123931. 11,
  123932. };
  123933. static float _vq_quantthresh__44c1_s_p4_0[] = {
  123934. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123935. };
  123936. static long _vq_quantmap__44c1_s_p4_0[] = {
  123937. 7, 5, 3, 1, 0, 2, 4, 6,
  123938. 8,
  123939. };
  123940. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  123941. _vq_quantthresh__44c1_s_p4_0,
  123942. _vq_quantmap__44c1_s_p4_0,
  123943. 9,
  123944. 9
  123945. };
  123946. static static_codebook _44c1_s_p4_0 = {
  123947. 2, 81,
  123948. _vq_lengthlist__44c1_s_p4_0,
  123949. 1, -531628032, 1611661312, 4, 0,
  123950. _vq_quantlist__44c1_s_p4_0,
  123951. NULL,
  123952. &_vq_auxt__44c1_s_p4_0,
  123953. NULL,
  123954. 0
  123955. };
  123956. static long _vq_quantlist__44c1_s_p5_0[] = {
  123957. 8,
  123958. 7,
  123959. 9,
  123960. 6,
  123961. 10,
  123962. 5,
  123963. 11,
  123964. 4,
  123965. 12,
  123966. 3,
  123967. 13,
  123968. 2,
  123969. 14,
  123970. 1,
  123971. 15,
  123972. 0,
  123973. 16,
  123974. };
  123975. static long _vq_lengthlist__44c1_s_p5_0[] = {
  123976. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  123977. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  123978. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123979. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  123980. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  123981. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  123982. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  123983. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123984. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  123985. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  123986. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123987. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123988. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  123989. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  123990. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  123991. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  123992. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  123993. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123994. 14,
  123995. };
  123996. static float _vq_quantthresh__44c1_s_p5_0[] = {
  123997. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123998. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123999. };
  124000. static long _vq_quantmap__44c1_s_p5_0[] = {
  124001. 15, 13, 11, 9, 7, 5, 3, 1,
  124002. 0, 2, 4, 6, 8, 10, 12, 14,
  124003. 16,
  124004. };
  124005. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124006. _vq_quantthresh__44c1_s_p5_0,
  124007. _vq_quantmap__44c1_s_p5_0,
  124008. 17,
  124009. 17
  124010. };
  124011. static static_codebook _44c1_s_p5_0 = {
  124012. 2, 289,
  124013. _vq_lengthlist__44c1_s_p5_0,
  124014. 1, -529530880, 1611661312, 5, 0,
  124015. _vq_quantlist__44c1_s_p5_0,
  124016. NULL,
  124017. &_vq_auxt__44c1_s_p5_0,
  124018. NULL,
  124019. 0
  124020. };
  124021. static long _vq_quantlist__44c1_s_p6_0[] = {
  124022. 1,
  124023. 0,
  124024. 2,
  124025. };
  124026. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124027. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124028. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124029. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124030. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124031. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124032. 11,
  124033. };
  124034. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124035. -5.5, 5.5,
  124036. };
  124037. static long _vq_quantmap__44c1_s_p6_0[] = {
  124038. 1, 0, 2,
  124039. };
  124040. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124041. _vq_quantthresh__44c1_s_p6_0,
  124042. _vq_quantmap__44c1_s_p6_0,
  124043. 3,
  124044. 3
  124045. };
  124046. static static_codebook _44c1_s_p6_0 = {
  124047. 4, 81,
  124048. _vq_lengthlist__44c1_s_p6_0,
  124049. 1, -529137664, 1618345984, 2, 0,
  124050. _vq_quantlist__44c1_s_p6_0,
  124051. NULL,
  124052. &_vq_auxt__44c1_s_p6_0,
  124053. NULL,
  124054. 0
  124055. };
  124056. static long _vq_quantlist__44c1_s_p6_1[] = {
  124057. 5,
  124058. 4,
  124059. 6,
  124060. 3,
  124061. 7,
  124062. 2,
  124063. 8,
  124064. 1,
  124065. 9,
  124066. 0,
  124067. 10,
  124068. };
  124069. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124070. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124071. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124072. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124073. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124074. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124075. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124076. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124077. 10,10,10, 8, 8, 8, 8, 8, 8,
  124078. };
  124079. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124080. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124081. 3.5, 4.5,
  124082. };
  124083. static long _vq_quantmap__44c1_s_p6_1[] = {
  124084. 9, 7, 5, 3, 1, 0, 2, 4,
  124085. 6, 8, 10,
  124086. };
  124087. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124088. _vq_quantthresh__44c1_s_p6_1,
  124089. _vq_quantmap__44c1_s_p6_1,
  124090. 11,
  124091. 11
  124092. };
  124093. static static_codebook _44c1_s_p6_1 = {
  124094. 2, 121,
  124095. _vq_lengthlist__44c1_s_p6_1,
  124096. 1, -531365888, 1611661312, 4, 0,
  124097. _vq_quantlist__44c1_s_p6_1,
  124098. NULL,
  124099. &_vq_auxt__44c1_s_p6_1,
  124100. NULL,
  124101. 0
  124102. };
  124103. static long _vq_quantlist__44c1_s_p7_0[] = {
  124104. 6,
  124105. 5,
  124106. 7,
  124107. 4,
  124108. 8,
  124109. 3,
  124110. 9,
  124111. 2,
  124112. 10,
  124113. 1,
  124114. 11,
  124115. 0,
  124116. 12,
  124117. };
  124118. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124119. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124120. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124121. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124122. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124123. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124124. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124125. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124126. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124127. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124128. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124129. 0,12,11,11,11,13,10,14,13,
  124130. };
  124131. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124132. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124133. 12.5, 17.5, 22.5, 27.5,
  124134. };
  124135. static long _vq_quantmap__44c1_s_p7_0[] = {
  124136. 11, 9, 7, 5, 3, 1, 0, 2,
  124137. 4, 6, 8, 10, 12,
  124138. };
  124139. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124140. _vq_quantthresh__44c1_s_p7_0,
  124141. _vq_quantmap__44c1_s_p7_0,
  124142. 13,
  124143. 13
  124144. };
  124145. static static_codebook _44c1_s_p7_0 = {
  124146. 2, 169,
  124147. _vq_lengthlist__44c1_s_p7_0,
  124148. 1, -526516224, 1616117760, 4, 0,
  124149. _vq_quantlist__44c1_s_p7_0,
  124150. NULL,
  124151. &_vq_auxt__44c1_s_p7_0,
  124152. NULL,
  124153. 0
  124154. };
  124155. static long _vq_quantlist__44c1_s_p7_1[] = {
  124156. 2,
  124157. 1,
  124158. 3,
  124159. 0,
  124160. 4,
  124161. };
  124162. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124163. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124164. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124165. };
  124166. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124167. -1.5, -0.5, 0.5, 1.5,
  124168. };
  124169. static long _vq_quantmap__44c1_s_p7_1[] = {
  124170. 3, 1, 0, 2, 4,
  124171. };
  124172. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124173. _vq_quantthresh__44c1_s_p7_1,
  124174. _vq_quantmap__44c1_s_p7_1,
  124175. 5,
  124176. 5
  124177. };
  124178. static static_codebook _44c1_s_p7_1 = {
  124179. 2, 25,
  124180. _vq_lengthlist__44c1_s_p7_1,
  124181. 1, -533725184, 1611661312, 3, 0,
  124182. _vq_quantlist__44c1_s_p7_1,
  124183. NULL,
  124184. &_vq_auxt__44c1_s_p7_1,
  124185. NULL,
  124186. 0
  124187. };
  124188. static long _vq_quantlist__44c1_s_p8_0[] = {
  124189. 6,
  124190. 5,
  124191. 7,
  124192. 4,
  124193. 8,
  124194. 3,
  124195. 9,
  124196. 2,
  124197. 10,
  124198. 1,
  124199. 11,
  124200. 0,
  124201. 12,
  124202. };
  124203. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124204. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124205. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124206. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124207. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124208. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124209. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124210. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124211. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124212. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124213. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124214. 10,10,10,10,10,10,10,10,10,
  124215. };
  124216. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124217. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124218. 552.5, 773.5, 994.5, 1215.5,
  124219. };
  124220. static long _vq_quantmap__44c1_s_p8_0[] = {
  124221. 11, 9, 7, 5, 3, 1, 0, 2,
  124222. 4, 6, 8, 10, 12,
  124223. };
  124224. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124225. _vq_quantthresh__44c1_s_p8_0,
  124226. _vq_quantmap__44c1_s_p8_0,
  124227. 13,
  124228. 13
  124229. };
  124230. static static_codebook _44c1_s_p8_0 = {
  124231. 2, 169,
  124232. _vq_lengthlist__44c1_s_p8_0,
  124233. 1, -514541568, 1627103232, 4, 0,
  124234. _vq_quantlist__44c1_s_p8_0,
  124235. NULL,
  124236. &_vq_auxt__44c1_s_p8_0,
  124237. NULL,
  124238. 0
  124239. };
  124240. static long _vq_quantlist__44c1_s_p8_1[] = {
  124241. 6,
  124242. 5,
  124243. 7,
  124244. 4,
  124245. 8,
  124246. 3,
  124247. 9,
  124248. 2,
  124249. 10,
  124250. 1,
  124251. 11,
  124252. 0,
  124253. 12,
  124254. };
  124255. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124256. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124257. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124258. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124259. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124260. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124261. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124262. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124263. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124264. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124265. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124266. 16,13,12,12,11,14,12,15,13,
  124267. };
  124268. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124269. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124270. 42.5, 59.5, 76.5, 93.5,
  124271. };
  124272. static long _vq_quantmap__44c1_s_p8_1[] = {
  124273. 11, 9, 7, 5, 3, 1, 0, 2,
  124274. 4, 6, 8, 10, 12,
  124275. };
  124276. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124277. _vq_quantthresh__44c1_s_p8_1,
  124278. _vq_quantmap__44c1_s_p8_1,
  124279. 13,
  124280. 13
  124281. };
  124282. static static_codebook _44c1_s_p8_1 = {
  124283. 2, 169,
  124284. _vq_lengthlist__44c1_s_p8_1,
  124285. 1, -522616832, 1620115456, 4, 0,
  124286. _vq_quantlist__44c1_s_p8_1,
  124287. NULL,
  124288. &_vq_auxt__44c1_s_p8_1,
  124289. NULL,
  124290. 0
  124291. };
  124292. static long _vq_quantlist__44c1_s_p8_2[] = {
  124293. 8,
  124294. 7,
  124295. 9,
  124296. 6,
  124297. 10,
  124298. 5,
  124299. 11,
  124300. 4,
  124301. 12,
  124302. 3,
  124303. 13,
  124304. 2,
  124305. 14,
  124306. 1,
  124307. 15,
  124308. 0,
  124309. 16,
  124310. };
  124311. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124312. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124313. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124314. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124315. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124316. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124317. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124318. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124319. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124320. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124321. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124322. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124323. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124324. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124325. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124326. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124327. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124328. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124329. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124330. 9,
  124331. };
  124332. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124333. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124334. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124335. };
  124336. static long _vq_quantmap__44c1_s_p8_2[] = {
  124337. 15, 13, 11, 9, 7, 5, 3, 1,
  124338. 0, 2, 4, 6, 8, 10, 12, 14,
  124339. 16,
  124340. };
  124341. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124342. _vq_quantthresh__44c1_s_p8_2,
  124343. _vq_quantmap__44c1_s_p8_2,
  124344. 17,
  124345. 17
  124346. };
  124347. static static_codebook _44c1_s_p8_2 = {
  124348. 2, 289,
  124349. _vq_lengthlist__44c1_s_p8_2,
  124350. 1, -529530880, 1611661312, 5, 0,
  124351. _vq_quantlist__44c1_s_p8_2,
  124352. NULL,
  124353. &_vq_auxt__44c1_s_p8_2,
  124354. NULL,
  124355. 0
  124356. };
  124357. static long _huff_lengthlist__44c1_s_short[] = {
  124358. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124359. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124360. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124361. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124362. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124363. 11,
  124364. };
  124365. static static_codebook _huff_book__44c1_s_short = {
  124366. 2, 81,
  124367. _huff_lengthlist__44c1_s_short,
  124368. 0, 0, 0, 0, 0,
  124369. NULL,
  124370. NULL,
  124371. NULL,
  124372. NULL,
  124373. 0
  124374. };
  124375. static long _huff_lengthlist__44c1_sm_long[] = {
  124376. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124377. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124378. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124379. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124380. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124381. 11,
  124382. };
  124383. static static_codebook _huff_book__44c1_sm_long = {
  124384. 2, 81,
  124385. _huff_lengthlist__44c1_sm_long,
  124386. 0, 0, 0, 0, 0,
  124387. NULL,
  124388. NULL,
  124389. NULL,
  124390. NULL,
  124391. 0
  124392. };
  124393. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124394. 1,
  124395. 0,
  124396. 2,
  124397. };
  124398. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124399. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124400. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124405. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124410. 0, 0, 0, 0, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  124414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  124419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  124424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 7, 0, 0, 0, 0,
  124445. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0,
  124450. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  124455. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124460. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124465. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124491. 0, 0, 0, 0, 8, 9, 9, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124496. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124501. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124809. 0,
  124810. };
  124811. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  124812. -0.5, 0.5,
  124813. };
  124814. static long _vq_quantmap__44c1_sm_p1_0[] = {
  124815. 1, 0, 2,
  124816. };
  124817. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  124818. _vq_quantthresh__44c1_sm_p1_0,
  124819. _vq_quantmap__44c1_sm_p1_0,
  124820. 3,
  124821. 3
  124822. };
  124823. static static_codebook _44c1_sm_p1_0 = {
  124824. 8, 6561,
  124825. _vq_lengthlist__44c1_sm_p1_0,
  124826. 1, -535822336, 1611661312, 2, 0,
  124827. _vq_quantlist__44c1_sm_p1_0,
  124828. NULL,
  124829. &_vq_auxt__44c1_sm_p1_0,
  124830. NULL,
  124831. 0
  124832. };
  124833. static long _vq_quantlist__44c1_sm_p2_0[] = {
  124834. 2,
  124835. 1,
  124836. 3,
  124837. 0,
  124838. 4,
  124839. };
  124840. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  124841. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124844. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  124846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124847. 0, 0, 0, 0, 6, 6, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124880. 0,
  124881. };
  124882. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  124883. -1.5, -0.5, 0.5, 1.5,
  124884. };
  124885. static long _vq_quantmap__44c1_sm_p2_0[] = {
  124886. 3, 1, 0, 2, 4,
  124887. };
  124888. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  124889. _vq_quantthresh__44c1_sm_p2_0,
  124890. _vq_quantmap__44c1_sm_p2_0,
  124891. 5,
  124892. 5
  124893. };
  124894. static static_codebook _44c1_sm_p2_0 = {
  124895. 4, 625,
  124896. _vq_lengthlist__44c1_sm_p2_0,
  124897. 1, -533725184, 1611661312, 3, 0,
  124898. _vq_quantlist__44c1_sm_p2_0,
  124899. NULL,
  124900. &_vq_auxt__44c1_sm_p2_0,
  124901. NULL,
  124902. 0
  124903. };
  124904. static long _vq_quantlist__44c1_sm_p3_0[] = {
  124905. 4,
  124906. 3,
  124907. 5,
  124908. 2,
  124909. 6,
  124910. 1,
  124911. 7,
  124912. 0,
  124913. 8,
  124914. };
  124915. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  124916. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  124917. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  124918. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124919. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124920. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124921. 0,
  124922. };
  124923. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  124924. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124925. };
  124926. static long _vq_quantmap__44c1_sm_p3_0[] = {
  124927. 7, 5, 3, 1, 0, 2, 4, 6,
  124928. 8,
  124929. };
  124930. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  124931. _vq_quantthresh__44c1_sm_p3_0,
  124932. _vq_quantmap__44c1_sm_p3_0,
  124933. 9,
  124934. 9
  124935. };
  124936. static static_codebook _44c1_sm_p3_0 = {
  124937. 2, 81,
  124938. _vq_lengthlist__44c1_sm_p3_0,
  124939. 1, -531628032, 1611661312, 4, 0,
  124940. _vq_quantlist__44c1_sm_p3_0,
  124941. NULL,
  124942. &_vq_auxt__44c1_sm_p3_0,
  124943. NULL,
  124944. 0
  124945. };
  124946. static long _vq_quantlist__44c1_sm_p4_0[] = {
  124947. 4,
  124948. 3,
  124949. 5,
  124950. 2,
  124951. 6,
  124952. 1,
  124953. 7,
  124954. 0,
  124955. 8,
  124956. };
  124957. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  124958. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  124959. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  124960. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  124961. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  124962. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124963. 11,
  124964. };
  124965. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  124966. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124967. };
  124968. static long _vq_quantmap__44c1_sm_p4_0[] = {
  124969. 7, 5, 3, 1, 0, 2, 4, 6,
  124970. 8,
  124971. };
  124972. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  124973. _vq_quantthresh__44c1_sm_p4_0,
  124974. _vq_quantmap__44c1_sm_p4_0,
  124975. 9,
  124976. 9
  124977. };
  124978. static static_codebook _44c1_sm_p4_0 = {
  124979. 2, 81,
  124980. _vq_lengthlist__44c1_sm_p4_0,
  124981. 1, -531628032, 1611661312, 4, 0,
  124982. _vq_quantlist__44c1_sm_p4_0,
  124983. NULL,
  124984. &_vq_auxt__44c1_sm_p4_0,
  124985. NULL,
  124986. 0
  124987. };
  124988. static long _vq_quantlist__44c1_sm_p5_0[] = {
  124989. 8,
  124990. 7,
  124991. 9,
  124992. 6,
  124993. 10,
  124994. 5,
  124995. 11,
  124996. 4,
  124997. 12,
  124998. 3,
  124999. 13,
  125000. 2,
  125001. 14,
  125002. 1,
  125003. 15,
  125004. 0,
  125005. 16,
  125006. };
  125007. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125008. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125009. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125010. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125011. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125012. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125013. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125014. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125015. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125016. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125017. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125018. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125019. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125020. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125021. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125022. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125023. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125024. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125025. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125026. 14,
  125027. };
  125028. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125029. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125030. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125031. };
  125032. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125033. 15, 13, 11, 9, 7, 5, 3, 1,
  125034. 0, 2, 4, 6, 8, 10, 12, 14,
  125035. 16,
  125036. };
  125037. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125038. _vq_quantthresh__44c1_sm_p5_0,
  125039. _vq_quantmap__44c1_sm_p5_0,
  125040. 17,
  125041. 17
  125042. };
  125043. static static_codebook _44c1_sm_p5_0 = {
  125044. 2, 289,
  125045. _vq_lengthlist__44c1_sm_p5_0,
  125046. 1, -529530880, 1611661312, 5, 0,
  125047. _vq_quantlist__44c1_sm_p5_0,
  125048. NULL,
  125049. &_vq_auxt__44c1_sm_p5_0,
  125050. NULL,
  125051. 0
  125052. };
  125053. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125054. 1,
  125055. 0,
  125056. 2,
  125057. };
  125058. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125059. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125060. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125061. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125062. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125063. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125064. 11,
  125065. };
  125066. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125067. -5.5, 5.5,
  125068. };
  125069. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125070. 1, 0, 2,
  125071. };
  125072. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125073. _vq_quantthresh__44c1_sm_p6_0,
  125074. _vq_quantmap__44c1_sm_p6_0,
  125075. 3,
  125076. 3
  125077. };
  125078. static static_codebook _44c1_sm_p6_0 = {
  125079. 4, 81,
  125080. _vq_lengthlist__44c1_sm_p6_0,
  125081. 1, -529137664, 1618345984, 2, 0,
  125082. _vq_quantlist__44c1_sm_p6_0,
  125083. NULL,
  125084. &_vq_auxt__44c1_sm_p6_0,
  125085. NULL,
  125086. 0
  125087. };
  125088. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125089. 5,
  125090. 4,
  125091. 6,
  125092. 3,
  125093. 7,
  125094. 2,
  125095. 8,
  125096. 1,
  125097. 9,
  125098. 0,
  125099. 10,
  125100. };
  125101. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125102. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125103. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125104. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125105. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125106. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125107. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125108. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125109. 10,10,10, 8, 8, 8, 8, 8, 8,
  125110. };
  125111. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125112. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125113. 3.5, 4.5,
  125114. };
  125115. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125116. 9, 7, 5, 3, 1, 0, 2, 4,
  125117. 6, 8, 10,
  125118. };
  125119. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125120. _vq_quantthresh__44c1_sm_p6_1,
  125121. _vq_quantmap__44c1_sm_p6_1,
  125122. 11,
  125123. 11
  125124. };
  125125. static static_codebook _44c1_sm_p6_1 = {
  125126. 2, 121,
  125127. _vq_lengthlist__44c1_sm_p6_1,
  125128. 1, -531365888, 1611661312, 4, 0,
  125129. _vq_quantlist__44c1_sm_p6_1,
  125130. NULL,
  125131. &_vq_auxt__44c1_sm_p6_1,
  125132. NULL,
  125133. 0
  125134. };
  125135. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125136. 6,
  125137. 5,
  125138. 7,
  125139. 4,
  125140. 8,
  125141. 3,
  125142. 9,
  125143. 2,
  125144. 10,
  125145. 1,
  125146. 11,
  125147. 0,
  125148. 12,
  125149. };
  125150. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125151. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125152. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125153. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125154. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125155. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125156. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125157. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125158. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125159. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125160. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125161. 0,12,12,11,11,13,12,14,13,
  125162. };
  125163. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125164. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125165. 12.5, 17.5, 22.5, 27.5,
  125166. };
  125167. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125168. 11, 9, 7, 5, 3, 1, 0, 2,
  125169. 4, 6, 8, 10, 12,
  125170. };
  125171. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125172. _vq_quantthresh__44c1_sm_p7_0,
  125173. _vq_quantmap__44c1_sm_p7_0,
  125174. 13,
  125175. 13
  125176. };
  125177. static static_codebook _44c1_sm_p7_0 = {
  125178. 2, 169,
  125179. _vq_lengthlist__44c1_sm_p7_0,
  125180. 1, -526516224, 1616117760, 4, 0,
  125181. _vq_quantlist__44c1_sm_p7_0,
  125182. NULL,
  125183. &_vq_auxt__44c1_sm_p7_0,
  125184. NULL,
  125185. 0
  125186. };
  125187. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125188. 2,
  125189. 1,
  125190. 3,
  125191. 0,
  125192. 4,
  125193. };
  125194. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125195. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125196. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125197. };
  125198. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125199. -1.5, -0.5, 0.5, 1.5,
  125200. };
  125201. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125202. 3, 1, 0, 2, 4,
  125203. };
  125204. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125205. _vq_quantthresh__44c1_sm_p7_1,
  125206. _vq_quantmap__44c1_sm_p7_1,
  125207. 5,
  125208. 5
  125209. };
  125210. static static_codebook _44c1_sm_p7_1 = {
  125211. 2, 25,
  125212. _vq_lengthlist__44c1_sm_p7_1,
  125213. 1, -533725184, 1611661312, 3, 0,
  125214. _vq_quantlist__44c1_sm_p7_1,
  125215. NULL,
  125216. &_vq_auxt__44c1_sm_p7_1,
  125217. NULL,
  125218. 0
  125219. };
  125220. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125221. 6,
  125222. 5,
  125223. 7,
  125224. 4,
  125225. 8,
  125226. 3,
  125227. 9,
  125228. 2,
  125229. 10,
  125230. 1,
  125231. 11,
  125232. 0,
  125233. 12,
  125234. };
  125235. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125236. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125237. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125238. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125239. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125240. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125241. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125242. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125243. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125244. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125245. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125246. 13,13,13,13,13,13,13,13,13,
  125247. };
  125248. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125249. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125250. 552.5, 773.5, 994.5, 1215.5,
  125251. };
  125252. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125253. 11, 9, 7, 5, 3, 1, 0, 2,
  125254. 4, 6, 8, 10, 12,
  125255. };
  125256. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125257. _vq_quantthresh__44c1_sm_p8_0,
  125258. _vq_quantmap__44c1_sm_p8_0,
  125259. 13,
  125260. 13
  125261. };
  125262. static static_codebook _44c1_sm_p8_0 = {
  125263. 2, 169,
  125264. _vq_lengthlist__44c1_sm_p8_0,
  125265. 1, -514541568, 1627103232, 4, 0,
  125266. _vq_quantlist__44c1_sm_p8_0,
  125267. NULL,
  125268. &_vq_auxt__44c1_sm_p8_0,
  125269. NULL,
  125270. 0
  125271. };
  125272. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125273. 6,
  125274. 5,
  125275. 7,
  125276. 4,
  125277. 8,
  125278. 3,
  125279. 9,
  125280. 2,
  125281. 10,
  125282. 1,
  125283. 11,
  125284. 0,
  125285. 12,
  125286. };
  125287. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125288. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125289. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125290. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125291. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125292. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125293. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125294. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125295. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125296. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125297. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125298. 20,13,12,12,12,14,12,14,13,
  125299. };
  125300. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125301. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125302. 42.5, 59.5, 76.5, 93.5,
  125303. };
  125304. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125305. 11, 9, 7, 5, 3, 1, 0, 2,
  125306. 4, 6, 8, 10, 12,
  125307. };
  125308. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125309. _vq_quantthresh__44c1_sm_p8_1,
  125310. _vq_quantmap__44c1_sm_p8_1,
  125311. 13,
  125312. 13
  125313. };
  125314. static static_codebook _44c1_sm_p8_1 = {
  125315. 2, 169,
  125316. _vq_lengthlist__44c1_sm_p8_1,
  125317. 1, -522616832, 1620115456, 4, 0,
  125318. _vq_quantlist__44c1_sm_p8_1,
  125319. NULL,
  125320. &_vq_auxt__44c1_sm_p8_1,
  125321. NULL,
  125322. 0
  125323. };
  125324. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125325. 8,
  125326. 7,
  125327. 9,
  125328. 6,
  125329. 10,
  125330. 5,
  125331. 11,
  125332. 4,
  125333. 12,
  125334. 3,
  125335. 13,
  125336. 2,
  125337. 14,
  125338. 1,
  125339. 15,
  125340. 0,
  125341. 16,
  125342. };
  125343. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125344. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125345. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125346. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125347. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125348. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125349. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125350. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125351. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125352. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125353. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125354. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125355. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125356. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125357. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125358. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125359. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125360. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125361. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125362. 9,
  125363. };
  125364. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125365. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125366. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125367. };
  125368. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125369. 15, 13, 11, 9, 7, 5, 3, 1,
  125370. 0, 2, 4, 6, 8, 10, 12, 14,
  125371. 16,
  125372. };
  125373. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125374. _vq_quantthresh__44c1_sm_p8_2,
  125375. _vq_quantmap__44c1_sm_p8_2,
  125376. 17,
  125377. 17
  125378. };
  125379. static static_codebook _44c1_sm_p8_2 = {
  125380. 2, 289,
  125381. _vq_lengthlist__44c1_sm_p8_2,
  125382. 1, -529530880, 1611661312, 5, 0,
  125383. _vq_quantlist__44c1_sm_p8_2,
  125384. NULL,
  125385. &_vq_auxt__44c1_sm_p8_2,
  125386. NULL,
  125387. 0
  125388. };
  125389. static long _huff_lengthlist__44c1_sm_short[] = {
  125390. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125391. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125392. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125393. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125394. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125395. 11,
  125396. };
  125397. static static_codebook _huff_book__44c1_sm_short = {
  125398. 2, 81,
  125399. _huff_lengthlist__44c1_sm_short,
  125400. 0, 0, 0, 0, 0,
  125401. NULL,
  125402. NULL,
  125403. NULL,
  125404. NULL,
  125405. 0
  125406. };
  125407. static long _huff_lengthlist__44cn1_s_long[] = {
  125408. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125409. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125410. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125411. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125412. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125413. 20,
  125414. };
  125415. static static_codebook _huff_book__44cn1_s_long = {
  125416. 2, 81,
  125417. _huff_lengthlist__44cn1_s_long,
  125418. 0, 0, 0, 0, 0,
  125419. NULL,
  125420. NULL,
  125421. NULL,
  125422. NULL,
  125423. 0
  125424. };
  125425. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125426. 1,
  125427. 0,
  125428. 2,
  125429. };
  125430. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125431. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125432. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125437. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125442. 0, 0, 0, 0, 8,10, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  125446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  125451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  125456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 8, 0, 0, 0, 0,
  125477. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 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, 7,10,10, 0, 0, 0,
  125482. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 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, 7,10,10, 0, 0,
  125487. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125492. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125497. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  125523. 0, 0, 0, 0, 8,10,10, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125528. 0, 0, 0, 0, 0, 9, 9,11, 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, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  125533. 0, 0, 0, 0, 0, 0, 9,11, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125841. 0,
  125842. };
  125843. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  125844. -0.5, 0.5,
  125845. };
  125846. static long _vq_quantmap__44cn1_s_p1_0[] = {
  125847. 1, 0, 2,
  125848. };
  125849. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  125850. _vq_quantthresh__44cn1_s_p1_0,
  125851. _vq_quantmap__44cn1_s_p1_0,
  125852. 3,
  125853. 3
  125854. };
  125855. static static_codebook _44cn1_s_p1_0 = {
  125856. 8, 6561,
  125857. _vq_lengthlist__44cn1_s_p1_0,
  125858. 1, -535822336, 1611661312, 2, 0,
  125859. _vq_quantlist__44cn1_s_p1_0,
  125860. NULL,
  125861. &_vq_auxt__44cn1_s_p1_0,
  125862. NULL,
  125863. 0
  125864. };
  125865. static long _vq_quantlist__44cn1_s_p2_0[] = {
  125866. 2,
  125867. 1,
  125868. 3,
  125869. 0,
  125870. 4,
  125871. };
  125872. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  125873. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  125875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125876. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  125878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125879. 0, 0, 0, 0, 6, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125912. 0,
  125913. };
  125914. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  125915. -1.5, -0.5, 0.5, 1.5,
  125916. };
  125917. static long _vq_quantmap__44cn1_s_p2_0[] = {
  125918. 3, 1, 0, 2, 4,
  125919. };
  125920. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  125921. _vq_quantthresh__44cn1_s_p2_0,
  125922. _vq_quantmap__44cn1_s_p2_0,
  125923. 5,
  125924. 5
  125925. };
  125926. static static_codebook _44cn1_s_p2_0 = {
  125927. 4, 625,
  125928. _vq_lengthlist__44cn1_s_p2_0,
  125929. 1, -533725184, 1611661312, 3, 0,
  125930. _vq_quantlist__44cn1_s_p2_0,
  125931. NULL,
  125932. &_vq_auxt__44cn1_s_p2_0,
  125933. NULL,
  125934. 0
  125935. };
  125936. static long _vq_quantlist__44cn1_s_p3_0[] = {
  125937. 4,
  125938. 3,
  125939. 5,
  125940. 2,
  125941. 6,
  125942. 1,
  125943. 7,
  125944. 0,
  125945. 8,
  125946. };
  125947. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  125948. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  125949. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  125950. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125951. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125952. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125953. 0,
  125954. };
  125955. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  125956. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125957. };
  125958. static long _vq_quantmap__44cn1_s_p3_0[] = {
  125959. 7, 5, 3, 1, 0, 2, 4, 6,
  125960. 8,
  125961. };
  125962. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  125963. _vq_quantthresh__44cn1_s_p3_0,
  125964. _vq_quantmap__44cn1_s_p3_0,
  125965. 9,
  125966. 9
  125967. };
  125968. static static_codebook _44cn1_s_p3_0 = {
  125969. 2, 81,
  125970. _vq_lengthlist__44cn1_s_p3_0,
  125971. 1, -531628032, 1611661312, 4, 0,
  125972. _vq_quantlist__44cn1_s_p3_0,
  125973. NULL,
  125974. &_vq_auxt__44cn1_s_p3_0,
  125975. NULL,
  125976. 0
  125977. };
  125978. static long _vq_quantlist__44cn1_s_p4_0[] = {
  125979. 4,
  125980. 3,
  125981. 5,
  125982. 2,
  125983. 6,
  125984. 1,
  125985. 7,
  125986. 0,
  125987. 8,
  125988. };
  125989. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  125990. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  125991. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  125992. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  125993. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  125994. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  125995. 11,
  125996. };
  125997. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  125998. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125999. };
  126000. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126001. 7, 5, 3, 1, 0, 2, 4, 6,
  126002. 8,
  126003. };
  126004. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126005. _vq_quantthresh__44cn1_s_p4_0,
  126006. _vq_quantmap__44cn1_s_p4_0,
  126007. 9,
  126008. 9
  126009. };
  126010. static static_codebook _44cn1_s_p4_0 = {
  126011. 2, 81,
  126012. _vq_lengthlist__44cn1_s_p4_0,
  126013. 1, -531628032, 1611661312, 4, 0,
  126014. _vq_quantlist__44cn1_s_p4_0,
  126015. NULL,
  126016. &_vq_auxt__44cn1_s_p4_0,
  126017. NULL,
  126018. 0
  126019. };
  126020. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126021. 8,
  126022. 7,
  126023. 9,
  126024. 6,
  126025. 10,
  126026. 5,
  126027. 11,
  126028. 4,
  126029. 12,
  126030. 3,
  126031. 13,
  126032. 2,
  126033. 14,
  126034. 1,
  126035. 15,
  126036. 0,
  126037. 16,
  126038. };
  126039. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126040. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126041. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126042. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126043. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126044. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126045. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126046. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126047. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126048. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126049. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126050. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126051. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126052. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126053. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126054. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126055. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126056. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126057. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126058. 14,
  126059. };
  126060. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126061. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126062. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126063. };
  126064. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126065. 15, 13, 11, 9, 7, 5, 3, 1,
  126066. 0, 2, 4, 6, 8, 10, 12, 14,
  126067. 16,
  126068. };
  126069. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126070. _vq_quantthresh__44cn1_s_p5_0,
  126071. _vq_quantmap__44cn1_s_p5_0,
  126072. 17,
  126073. 17
  126074. };
  126075. static static_codebook _44cn1_s_p5_0 = {
  126076. 2, 289,
  126077. _vq_lengthlist__44cn1_s_p5_0,
  126078. 1, -529530880, 1611661312, 5, 0,
  126079. _vq_quantlist__44cn1_s_p5_0,
  126080. NULL,
  126081. &_vq_auxt__44cn1_s_p5_0,
  126082. NULL,
  126083. 0
  126084. };
  126085. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126086. 1,
  126087. 0,
  126088. 2,
  126089. };
  126090. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126091. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126092. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126093. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126094. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126095. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126096. 10,
  126097. };
  126098. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126099. -5.5, 5.5,
  126100. };
  126101. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126102. 1, 0, 2,
  126103. };
  126104. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126105. _vq_quantthresh__44cn1_s_p6_0,
  126106. _vq_quantmap__44cn1_s_p6_0,
  126107. 3,
  126108. 3
  126109. };
  126110. static static_codebook _44cn1_s_p6_0 = {
  126111. 4, 81,
  126112. _vq_lengthlist__44cn1_s_p6_0,
  126113. 1, -529137664, 1618345984, 2, 0,
  126114. _vq_quantlist__44cn1_s_p6_0,
  126115. NULL,
  126116. &_vq_auxt__44cn1_s_p6_0,
  126117. NULL,
  126118. 0
  126119. };
  126120. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126121. 5,
  126122. 4,
  126123. 6,
  126124. 3,
  126125. 7,
  126126. 2,
  126127. 8,
  126128. 1,
  126129. 9,
  126130. 0,
  126131. 10,
  126132. };
  126133. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126134. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126135. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126136. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126137. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126138. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126139. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126140. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126141. 10,10,10, 9, 9, 9, 9, 9, 9,
  126142. };
  126143. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126144. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126145. 3.5, 4.5,
  126146. };
  126147. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126148. 9, 7, 5, 3, 1, 0, 2, 4,
  126149. 6, 8, 10,
  126150. };
  126151. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126152. _vq_quantthresh__44cn1_s_p6_1,
  126153. _vq_quantmap__44cn1_s_p6_1,
  126154. 11,
  126155. 11
  126156. };
  126157. static static_codebook _44cn1_s_p6_1 = {
  126158. 2, 121,
  126159. _vq_lengthlist__44cn1_s_p6_1,
  126160. 1, -531365888, 1611661312, 4, 0,
  126161. _vq_quantlist__44cn1_s_p6_1,
  126162. NULL,
  126163. &_vq_auxt__44cn1_s_p6_1,
  126164. NULL,
  126165. 0
  126166. };
  126167. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126168. 6,
  126169. 5,
  126170. 7,
  126171. 4,
  126172. 8,
  126173. 3,
  126174. 9,
  126175. 2,
  126176. 10,
  126177. 1,
  126178. 11,
  126179. 0,
  126180. 12,
  126181. };
  126182. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126183. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126184. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126185. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126186. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126187. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126188. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126189. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126190. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126191. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126192. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126193. 0,13,13,12,12,13,13,13,14,
  126194. };
  126195. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126196. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126197. 12.5, 17.5, 22.5, 27.5,
  126198. };
  126199. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126200. 11, 9, 7, 5, 3, 1, 0, 2,
  126201. 4, 6, 8, 10, 12,
  126202. };
  126203. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126204. _vq_quantthresh__44cn1_s_p7_0,
  126205. _vq_quantmap__44cn1_s_p7_0,
  126206. 13,
  126207. 13
  126208. };
  126209. static static_codebook _44cn1_s_p7_0 = {
  126210. 2, 169,
  126211. _vq_lengthlist__44cn1_s_p7_0,
  126212. 1, -526516224, 1616117760, 4, 0,
  126213. _vq_quantlist__44cn1_s_p7_0,
  126214. NULL,
  126215. &_vq_auxt__44cn1_s_p7_0,
  126216. NULL,
  126217. 0
  126218. };
  126219. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126220. 2,
  126221. 1,
  126222. 3,
  126223. 0,
  126224. 4,
  126225. };
  126226. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126227. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126228. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126229. };
  126230. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126231. -1.5, -0.5, 0.5, 1.5,
  126232. };
  126233. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126234. 3, 1, 0, 2, 4,
  126235. };
  126236. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126237. _vq_quantthresh__44cn1_s_p7_1,
  126238. _vq_quantmap__44cn1_s_p7_1,
  126239. 5,
  126240. 5
  126241. };
  126242. static static_codebook _44cn1_s_p7_1 = {
  126243. 2, 25,
  126244. _vq_lengthlist__44cn1_s_p7_1,
  126245. 1, -533725184, 1611661312, 3, 0,
  126246. _vq_quantlist__44cn1_s_p7_1,
  126247. NULL,
  126248. &_vq_auxt__44cn1_s_p7_1,
  126249. NULL,
  126250. 0
  126251. };
  126252. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126253. 2,
  126254. 1,
  126255. 3,
  126256. 0,
  126257. 4,
  126258. };
  126259. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126260. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126261. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126262. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126263. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126264. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126265. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126266. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126267. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126268. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126269. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126270. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126271. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126272. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126273. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126274. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126275. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126276. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126277. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126278. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126279. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126280. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126281. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126282. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126283. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126284. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126285. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126286. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126287. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126288. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126289. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126290. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126291. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126292. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126293. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126294. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126295. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126296. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126297. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126298. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126299. 12,
  126300. };
  126301. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126302. -331.5, -110.5, 110.5, 331.5,
  126303. };
  126304. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126305. 3, 1, 0, 2, 4,
  126306. };
  126307. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126308. _vq_quantthresh__44cn1_s_p8_0,
  126309. _vq_quantmap__44cn1_s_p8_0,
  126310. 5,
  126311. 5
  126312. };
  126313. static static_codebook _44cn1_s_p8_0 = {
  126314. 4, 625,
  126315. _vq_lengthlist__44cn1_s_p8_0,
  126316. 1, -518283264, 1627103232, 3, 0,
  126317. _vq_quantlist__44cn1_s_p8_0,
  126318. NULL,
  126319. &_vq_auxt__44cn1_s_p8_0,
  126320. NULL,
  126321. 0
  126322. };
  126323. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126324. 6,
  126325. 5,
  126326. 7,
  126327. 4,
  126328. 8,
  126329. 3,
  126330. 9,
  126331. 2,
  126332. 10,
  126333. 1,
  126334. 11,
  126335. 0,
  126336. 12,
  126337. };
  126338. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126339. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126340. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126341. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126342. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126343. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126344. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126345. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126346. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126347. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126348. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126349. 15,12,12,11,11,14,12,13,14,
  126350. };
  126351. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126352. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126353. 42.5, 59.5, 76.5, 93.5,
  126354. };
  126355. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126356. 11, 9, 7, 5, 3, 1, 0, 2,
  126357. 4, 6, 8, 10, 12,
  126358. };
  126359. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126360. _vq_quantthresh__44cn1_s_p8_1,
  126361. _vq_quantmap__44cn1_s_p8_1,
  126362. 13,
  126363. 13
  126364. };
  126365. static static_codebook _44cn1_s_p8_1 = {
  126366. 2, 169,
  126367. _vq_lengthlist__44cn1_s_p8_1,
  126368. 1, -522616832, 1620115456, 4, 0,
  126369. _vq_quantlist__44cn1_s_p8_1,
  126370. NULL,
  126371. &_vq_auxt__44cn1_s_p8_1,
  126372. NULL,
  126373. 0
  126374. };
  126375. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126376. 8,
  126377. 7,
  126378. 9,
  126379. 6,
  126380. 10,
  126381. 5,
  126382. 11,
  126383. 4,
  126384. 12,
  126385. 3,
  126386. 13,
  126387. 2,
  126388. 14,
  126389. 1,
  126390. 15,
  126391. 0,
  126392. 16,
  126393. };
  126394. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126395. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126396. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126397. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126398. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126399. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126400. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126401. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126402. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126403. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126404. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126405. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126406. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126407. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126408. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126409. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126410. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126411. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126412. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126413. 9,
  126414. };
  126415. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126416. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126417. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126418. };
  126419. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126420. 15, 13, 11, 9, 7, 5, 3, 1,
  126421. 0, 2, 4, 6, 8, 10, 12, 14,
  126422. 16,
  126423. };
  126424. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126425. _vq_quantthresh__44cn1_s_p8_2,
  126426. _vq_quantmap__44cn1_s_p8_2,
  126427. 17,
  126428. 17
  126429. };
  126430. static static_codebook _44cn1_s_p8_2 = {
  126431. 2, 289,
  126432. _vq_lengthlist__44cn1_s_p8_2,
  126433. 1, -529530880, 1611661312, 5, 0,
  126434. _vq_quantlist__44cn1_s_p8_2,
  126435. NULL,
  126436. &_vq_auxt__44cn1_s_p8_2,
  126437. NULL,
  126438. 0
  126439. };
  126440. static long _huff_lengthlist__44cn1_s_short[] = {
  126441. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126442. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126443. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126444. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126445. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126446. 10,
  126447. };
  126448. static static_codebook _huff_book__44cn1_s_short = {
  126449. 2, 81,
  126450. _huff_lengthlist__44cn1_s_short,
  126451. 0, 0, 0, 0, 0,
  126452. NULL,
  126453. NULL,
  126454. NULL,
  126455. NULL,
  126456. 0
  126457. };
  126458. static long _huff_lengthlist__44cn1_sm_long[] = {
  126459. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126460. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126461. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126462. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126463. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126464. 17,
  126465. };
  126466. static static_codebook _huff_book__44cn1_sm_long = {
  126467. 2, 81,
  126468. _huff_lengthlist__44cn1_sm_long,
  126469. 0, 0, 0, 0, 0,
  126470. NULL,
  126471. NULL,
  126472. NULL,
  126473. NULL,
  126474. 0
  126475. };
  126476. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126477. 1,
  126478. 0,
  126479. 2,
  126480. };
  126481. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126482. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126483. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126488. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126493. 0, 0, 0, 0, 8, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0,
  126497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
  126502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0,
  126507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  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, 5, 8, 8, 0, 0, 0, 0,
  126528. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 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, 7,10, 9, 0, 0, 0,
  126533. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 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, 7, 9, 9, 0, 0,
  126538. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126543. 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126548. 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  126574. 0, 0, 0, 0, 8, 9,10, 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, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  126579. 0, 0, 0, 0, 0, 8, 9,10, 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, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  126584. 0, 0, 0, 0, 0, 0, 9,10, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126892. 0,
  126893. };
  126894. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  126895. -0.5, 0.5,
  126896. };
  126897. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  126898. 1, 0, 2,
  126899. };
  126900. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  126901. _vq_quantthresh__44cn1_sm_p1_0,
  126902. _vq_quantmap__44cn1_sm_p1_0,
  126903. 3,
  126904. 3
  126905. };
  126906. static static_codebook _44cn1_sm_p1_0 = {
  126907. 8, 6561,
  126908. _vq_lengthlist__44cn1_sm_p1_0,
  126909. 1, -535822336, 1611661312, 2, 0,
  126910. _vq_quantlist__44cn1_sm_p1_0,
  126911. NULL,
  126912. &_vq_auxt__44cn1_sm_p1_0,
  126913. NULL,
  126914. 0
  126915. };
  126916. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  126917. 2,
  126918. 1,
  126919. 3,
  126920. 0,
  126921. 4,
  126922. };
  126923. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  126924. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126927. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126930. 0, 0, 0, 0, 7, 7, 7, 9, 9, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126963. 0,
  126964. };
  126965. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  126966. -1.5, -0.5, 0.5, 1.5,
  126967. };
  126968. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  126969. 3, 1, 0, 2, 4,
  126970. };
  126971. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  126972. _vq_quantthresh__44cn1_sm_p2_0,
  126973. _vq_quantmap__44cn1_sm_p2_0,
  126974. 5,
  126975. 5
  126976. };
  126977. static static_codebook _44cn1_sm_p2_0 = {
  126978. 4, 625,
  126979. _vq_lengthlist__44cn1_sm_p2_0,
  126980. 1, -533725184, 1611661312, 3, 0,
  126981. _vq_quantlist__44cn1_sm_p2_0,
  126982. NULL,
  126983. &_vq_auxt__44cn1_sm_p2_0,
  126984. NULL,
  126985. 0
  126986. };
  126987. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  126988. 4,
  126989. 3,
  126990. 5,
  126991. 2,
  126992. 6,
  126993. 1,
  126994. 7,
  126995. 0,
  126996. 8,
  126997. };
  126998. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  126999. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127000. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127001. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127002. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127003. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127004. 0,
  127005. };
  127006. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127007. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127008. };
  127009. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127010. 7, 5, 3, 1, 0, 2, 4, 6,
  127011. 8,
  127012. };
  127013. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127014. _vq_quantthresh__44cn1_sm_p3_0,
  127015. _vq_quantmap__44cn1_sm_p3_0,
  127016. 9,
  127017. 9
  127018. };
  127019. static static_codebook _44cn1_sm_p3_0 = {
  127020. 2, 81,
  127021. _vq_lengthlist__44cn1_sm_p3_0,
  127022. 1, -531628032, 1611661312, 4, 0,
  127023. _vq_quantlist__44cn1_sm_p3_0,
  127024. NULL,
  127025. &_vq_auxt__44cn1_sm_p3_0,
  127026. NULL,
  127027. 0
  127028. };
  127029. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127030. 4,
  127031. 3,
  127032. 5,
  127033. 2,
  127034. 6,
  127035. 1,
  127036. 7,
  127037. 0,
  127038. 8,
  127039. };
  127040. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127041. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127042. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127043. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127044. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127045. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127046. 11,
  127047. };
  127048. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127049. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127050. };
  127051. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127052. 7, 5, 3, 1, 0, 2, 4, 6,
  127053. 8,
  127054. };
  127055. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127056. _vq_quantthresh__44cn1_sm_p4_0,
  127057. _vq_quantmap__44cn1_sm_p4_0,
  127058. 9,
  127059. 9
  127060. };
  127061. static static_codebook _44cn1_sm_p4_0 = {
  127062. 2, 81,
  127063. _vq_lengthlist__44cn1_sm_p4_0,
  127064. 1, -531628032, 1611661312, 4, 0,
  127065. _vq_quantlist__44cn1_sm_p4_0,
  127066. NULL,
  127067. &_vq_auxt__44cn1_sm_p4_0,
  127068. NULL,
  127069. 0
  127070. };
  127071. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127072. 8,
  127073. 7,
  127074. 9,
  127075. 6,
  127076. 10,
  127077. 5,
  127078. 11,
  127079. 4,
  127080. 12,
  127081. 3,
  127082. 13,
  127083. 2,
  127084. 14,
  127085. 1,
  127086. 15,
  127087. 0,
  127088. 16,
  127089. };
  127090. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127091. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127092. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127093. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127094. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127095. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127096. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127097. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127098. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127099. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127100. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127101. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127102. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127103. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127104. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127105. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127106. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127107. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127108. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127109. 14,
  127110. };
  127111. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127112. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127113. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127114. };
  127115. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127116. 15, 13, 11, 9, 7, 5, 3, 1,
  127117. 0, 2, 4, 6, 8, 10, 12, 14,
  127118. 16,
  127119. };
  127120. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127121. _vq_quantthresh__44cn1_sm_p5_0,
  127122. _vq_quantmap__44cn1_sm_p5_0,
  127123. 17,
  127124. 17
  127125. };
  127126. static static_codebook _44cn1_sm_p5_0 = {
  127127. 2, 289,
  127128. _vq_lengthlist__44cn1_sm_p5_0,
  127129. 1, -529530880, 1611661312, 5, 0,
  127130. _vq_quantlist__44cn1_sm_p5_0,
  127131. NULL,
  127132. &_vq_auxt__44cn1_sm_p5_0,
  127133. NULL,
  127134. 0
  127135. };
  127136. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127137. 1,
  127138. 0,
  127139. 2,
  127140. };
  127141. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127142. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127143. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127144. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127145. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127146. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127147. 10,
  127148. };
  127149. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127150. -5.5, 5.5,
  127151. };
  127152. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127153. 1, 0, 2,
  127154. };
  127155. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127156. _vq_quantthresh__44cn1_sm_p6_0,
  127157. _vq_quantmap__44cn1_sm_p6_0,
  127158. 3,
  127159. 3
  127160. };
  127161. static static_codebook _44cn1_sm_p6_0 = {
  127162. 4, 81,
  127163. _vq_lengthlist__44cn1_sm_p6_0,
  127164. 1, -529137664, 1618345984, 2, 0,
  127165. _vq_quantlist__44cn1_sm_p6_0,
  127166. NULL,
  127167. &_vq_auxt__44cn1_sm_p6_0,
  127168. NULL,
  127169. 0
  127170. };
  127171. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127172. 5,
  127173. 4,
  127174. 6,
  127175. 3,
  127176. 7,
  127177. 2,
  127178. 8,
  127179. 1,
  127180. 9,
  127181. 0,
  127182. 10,
  127183. };
  127184. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127185. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127186. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127187. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127188. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127189. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127190. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127191. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127192. 10,10,10, 8, 9, 8, 8, 9, 8,
  127193. };
  127194. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127195. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127196. 3.5, 4.5,
  127197. };
  127198. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127199. 9, 7, 5, 3, 1, 0, 2, 4,
  127200. 6, 8, 10,
  127201. };
  127202. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127203. _vq_quantthresh__44cn1_sm_p6_1,
  127204. _vq_quantmap__44cn1_sm_p6_1,
  127205. 11,
  127206. 11
  127207. };
  127208. static static_codebook _44cn1_sm_p6_1 = {
  127209. 2, 121,
  127210. _vq_lengthlist__44cn1_sm_p6_1,
  127211. 1, -531365888, 1611661312, 4, 0,
  127212. _vq_quantlist__44cn1_sm_p6_1,
  127213. NULL,
  127214. &_vq_auxt__44cn1_sm_p6_1,
  127215. NULL,
  127216. 0
  127217. };
  127218. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127219. 6,
  127220. 5,
  127221. 7,
  127222. 4,
  127223. 8,
  127224. 3,
  127225. 9,
  127226. 2,
  127227. 10,
  127228. 1,
  127229. 11,
  127230. 0,
  127231. 12,
  127232. };
  127233. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127234. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127235. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127236. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127237. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127238. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127239. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127240. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127241. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127242. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127243. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127244. 0,13,12,12,12,13,13,13,14,
  127245. };
  127246. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127247. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127248. 12.5, 17.5, 22.5, 27.5,
  127249. };
  127250. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127251. 11, 9, 7, 5, 3, 1, 0, 2,
  127252. 4, 6, 8, 10, 12,
  127253. };
  127254. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127255. _vq_quantthresh__44cn1_sm_p7_0,
  127256. _vq_quantmap__44cn1_sm_p7_0,
  127257. 13,
  127258. 13
  127259. };
  127260. static static_codebook _44cn1_sm_p7_0 = {
  127261. 2, 169,
  127262. _vq_lengthlist__44cn1_sm_p7_0,
  127263. 1, -526516224, 1616117760, 4, 0,
  127264. _vq_quantlist__44cn1_sm_p7_0,
  127265. NULL,
  127266. &_vq_auxt__44cn1_sm_p7_0,
  127267. NULL,
  127268. 0
  127269. };
  127270. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127271. 2,
  127272. 1,
  127273. 3,
  127274. 0,
  127275. 4,
  127276. };
  127277. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127278. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127279. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127280. };
  127281. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127282. -1.5, -0.5, 0.5, 1.5,
  127283. };
  127284. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127285. 3, 1, 0, 2, 4,
  127286. };
  127287. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127288. _vq_quantthresh__44cn1_sm_p7_1,
  127289. _vq_quantmap__44cn1_sm_p7_1,
  127290. 5,
  127291. 5
  127292. };
  127293. static static_codebook _44cn1_sm_p7_1 = {
  127294. 2, 25,
  127295. _vq_lengthlist__44cn1_sm_p7_1,
  127296. 1, -533725184, 1611661312, 3, 0,
  127297. _vq_quantlist__44cn1_sm_p7_1,
  127298. NULL,
  127299. &_vq_auxt__44cn1_sm_p7_1,
  127300. NULL,
  127301. 0
  127302. };
  127303. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127304. 4,
  127305. 3,
  127306. 5,
  127307. 2,
  127308. 6,
  127309. 1,
  127310. 7,
  127311. 0,
  127312. 8,
  127313. };
  127314. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127315. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127316. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127317. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127318. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127319. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127320. 14,
  127321. };
  127322. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127323. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127324. };
  127325. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127326. 7, 5, 3, 1, 0, 2, 4, 6,
  127327. 8,
  127328. };
  127329. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127330. _vq_quantthresh__44cn1_sm_p8_0,
  127331. _vq_quantmap__44cn1_sm_p8_0,
  127332. 9,
  127333. 9
  127334. };
  127335. static static_codebook _44cn1_sm_p8_0 = {
  127336. 2, 81,
  127337. _vq_lengthlist__44cn1_sm_p8_0,
  127338. 1, -516186112, 1627103232, 4, 0,
  127339. _vq_quantlist__44cn1_sm_p8_0,
  127340. NULL,
  127341. &_vq_auxt__44cn1_sm_p8_0,
  127342. NULL,
  127343. 0
  127344. };
  127345. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127346. 6,
  127347. 5,
  127348. 7,
  127349. 4,
  127350. 8,
  127351. 3,
  127352. 9,
  127353. 2,
  127354. 10,
  127355. 1,
  127356. 11,
  127357. 0,
  127358. 12,
  127359. };
  127360. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127361. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127362. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127363. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127364. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127365. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127366. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127367. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127368. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127369. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127370. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127371. 17,12,12,11,10,13,11,13,13,
  127372. };
  127373. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127374. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127375. 42.5, 59.5, 76.5, 93.5,
  127376. };
  127377. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127378. 11, 9, 7, 5, 3, 1, 0, 2,
  127379. 4, 6, 8, 10, 12,
  127380. };
  127381. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127382. _vq_quantthresh__44cn1_sm_p8_1,
  127383. _vq_quantmap__44cn1_sm_p8_1,
  127384. 13,
  127385. 13
  127386. };
  127387. static static_codebook _44cn1_sm_p8_1 = {
  127388. 2, 169,
  127389. _vq_lengthlist__44cn1_sm_p8_1,
  127390. 1, -522616832, 1620115456, 4, 0,
  127391. _vq_quantlist__44cn1_sm_p8_1,
  127392. NULL,
  127393. &_vq_auxt__44cn1_sm_p8_1,
  127394. NULL,
  127395. 0
  127396. };
  127397. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127398. 8,
  127399. 7,
  127400. 9,
  127401. 6,
  127402. 10,
  127403. 5,
  127404. 11,
  127405. 4,
  127406. 12,
  127407. 3,
  127408. 13,
  127409. 2,
  127410. 14,
  127411. 1,
  127412. 15,
  127413. 0,
  127414. 16,
  127415. };
  127416. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127417. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127418. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127419. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127420. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127421. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127422. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127423. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127424. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127425. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127426. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127427. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127428. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127429. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127430. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127431. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127432. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127433. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127434. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127435. 9,
  127436. };
  127437. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127438. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127439. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127440. };
  127441. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127442. 15, 13, 11, 9, 7, 5, 3, 1,
  127443. 0, 2, 4, 6, 8, 10, 12, 14,
  127444. 16,
  127445. };
  127446. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127447. _vq_quantthresh__44cn1_sm_p8_2,
  127448. _vq_quantmap__44cn1_sm_p8_2,
  127449. 17,
  127450. 17
  127451. };
  127452. static static_codebook _44cn1_sm_p8_2 = {
  127453. 2, 289,
  127454. _vq_lengthlist__44cn1_sm_p8_2,
  127455. 1, -529530880, 1611661312, 5, 0,
  127456. _vq_quantlist__44cn1_sm_p8_2,
  127457. NULL,
  127458. &_vq_auxt__44cn1_sm_p8_2,
  127459. NULL,
  127460. 0
  127461. };
  127462. static long _huff_lengthlist__44cn1_sm_short[] = {
  127463. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127464. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127465. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127466. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127467. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127468. 9,
  127469. };
  127470. static static_codebook _huff_book__44cn1_sm_short = {
  127471. 2, 81,
  127472. _huff_lengthlist__44cn1_sm_short,
  127473. 0, 0, 0, 0, 0,
  127474. NULL,
  127475. NULL,
  127476. NULL,
  127477. NULL,
  127478. 0
  127479. };
  127480. /*** End of inlined file: res_books_stereo.h ***/
  127481. static vorbis_info_residue0 _residue_44_low={
  127482. 0,-1, -1, 9,-1,
  127483. {0},
  127484. {-1},
  127485. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127486. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127487. };
  127488. static vorbis_info_residue0 _residue_44_mid={
  127489. 0,-1, -1, 10,-1,
  127490. {0},
  127491. {-1},
  127492. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127493. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127494. };
  127495. static vorbis_info_residue0 _residue_44_high={
  127496. 0,-1, -1, 10,-1,
  127497. {0},
  127498. {-1},
  127499. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127500. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127501. };
  127502. static static_bookblock _resbook_44s_n1={
  127503. {
  127504. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127505. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127506. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127507. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127508. }
  127509. };
  127510. static static_bookblock _resbook_44sm_n1={
  127511. {
  127512. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  127513. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  127514. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  127515. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  127516. }
  127517. };
  127518. static static_bookblock _resbook_44s_0={
  127519. {
  127520. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  127521. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  127522. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  127523. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  127524. }
  127525. };
  127526. static static_bookblock _resbook_44sm_0={
  127527. {
  127528. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  127529. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  127530. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  127531. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  127532. }
  127533. };
  127534. static static_bookblock _resbook_44s_1={
  127535. {
  127536. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  127537. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  127538. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  127539. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  127540. }
  127541. };
  127542. static static_bookblock _resbook_44sm_1={
  127543. {
  127544. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  127545. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  127546. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  127547. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  127548. }
  127549. };
  127550. static static_bookblock _resbook_44s_2={
  127551. {
  127552. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  127553. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  127554. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  127555. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  127556. }
  127557. };
  127558. static static_bookblock _resbook_44s_3={
  127559. {
  127560. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  127561. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  127562. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  127563. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  127564. }
  127565. };
  127566. static static_bookblock _resbook_44s_4={
  127567. {
  127568. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  127569. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  127570. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  127571. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  127572. }
  127573. };
  127574. static static_bookblock _resbook_44s_5={
  127575. {
  127576. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  127577. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  127578. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  127579. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  127580. }
  127581. };
  127582. static static_bookblock _resbook_44s_6={
  127583. {
  127584. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  127585. {0,0,&_44c6_s_p4_0},
  127586. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  127587. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  127588. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  127589. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  127590. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  127591. }
  127592. };
  127593. static static_bookblock _resbook_44s_7={
  127594. {
  127595. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  127596. {0,0,&_44c7_s_p4_0},
  127597. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  127598. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  127599. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  127600. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  127601. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  127602. }
  127603. };
  127604. static static_bookblock _resbook_44s_8={
  127605. {
  127606. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  127607. {0,0,&_44c8_s_p4_0},
  127608. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  127609. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  127610. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  127611. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  127612. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  127613. }
  127614. };
  127615. static static_bookblock _resbook_44s_9={
  127616. {
  127617. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  127618. {0,0,&_44c9_s_p4_0},
  127619. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  127620. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  127621. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  127622. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  127623. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  127624. }
  127625. };
  127626. static vorbis_residue_template _res_44s_n1[]={
  127627. {2,0, &_residue_44_low,
  127628. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  127629. &_resbook_44s_n1,&_resbook_44sm_n1},
  127630. {2,0, &_residue_44_low,
  127631. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  127632. &_resbook_44s_n1,&_resbook_44sm_n1}
  127633. };
  127634. static vorbis_residue_template _res_44s_0[]={
  127635. {2,0, &_residue_44_low,
  127636. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  127637. &_resbook_44s_0,&_resbook_44sm_0},
  127638. {2,0, &_residue_44_low,
  127639. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  127640. &_resbook_44s_0,&_resbook_44sm_0}
  127641. };
  127642. static vorbis_residue_template _res_44s_1[]={
  127643. {2,0, &_residue_44_low,
  127644. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  127645. &_resbook_44s_1,&_resbook_44sm_1},
  127646. {2,0, &_residue_44_low,
  127647. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  127648. &_resbook_44s_1,&_resbook_44sm_1}
  127649. };
  127650. static vorbis_residue_template _res_44s_2[]={
  127651. {2,0, &_residue_44_mid,
  127652. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  127653. &_resbook_44s_2,&_resbook_44s_2},
  127654. {2,0, &_residue_44_mid,
  127655. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  127656. &_resbook_44s_2,&_resbook_44s_2}
  127657. };
  127658. static vorbis_residue_template _res_44s_3[]={
  127659. {2,0, &_residue_44_mid,
  127660. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  127661. &_resbook_44s_3,&_resbook_44s_3},
  127662. {2,0, &_residue_44_mid,
  127663. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  127664. &_resbook_44s_3,&_resbook_44s_3}
  127665. };
  127666. static vorbis_residue_template _res_44s_4[]={
  127667. {2,0, &_residue_44_mid,
  127668. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  127669. &_resbook_44s_4,&_resbook_44s_4},
  127670. {2,0, &_residue_44_mid,
  127671. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  127672. &_resbook_44s_4,&_resbook_44s_4}
  127673. };
  127674. static vorbis_residue_template _res_44s_5[]={
  127675. {2,0, &_residue_44_mid,
  127676. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  127677. &_resbook_44s_5,&_resbook_44s_5},
  127678. {2,0, &_residue_44_mid,
  127679. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  127680. &_resbook_44s_5,&_resbook_44s_5}
  127681. };
  127682. static vorbis_residue_template _res_44s_6[]={
  127683. {2,0, &_residue_44_high,
  127684. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  127685. &_resbook_44s_6,&_resbook_44s_6},
  127686. {2,0, &_residue_44_high,
  127687. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  127688. &_resbook_44s_6,&_resbook_44s_6}
  127689. };
  127690. static vorbis_residue_template _res_44s_7[]={
  127691. {2,0, &_residue_44_high,
  127692. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  127693. &_resbook_44s_7,&_resbook_44s_7},
  127694. {2,0, &_residue_44_high,
  127695. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  127696. &_resbook_44s_7,&_resbook_44s_7}
  127697. };
  127698. static vorbis_residue_template _res_44s_8[]={
  127699. {2,0, &_residue_44_high,
  127700. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  127701. &_resbook_44s_8,&_resbook_44s_8},
  127702. {2,0, &_residue_44_high,
  127703. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  127704. &_resbook_44s_8,&_resbook_44s_8}
  127705. };
  127706. static vorbis_residue_template _res_44s_9[]={
  127707. {2,0, &_residue_44_high,
  127708. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  127709. &_resbook_44s_9,&_resbook_44s_9},
  127710. {2,0, &_residue_44_high,
  127711. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  127712. &_resbook_44s_9,&_resbook_44s_9}
  127713. };
  127714. static vorbis_mapping_template _mapres_template_44_stereo[]={
  127715. { _map_nominal, _res_44s_n1 }, /* -1 */
  127716. { _map_nominal, _res_44s_0 }, /* 0 */
  127717. { _map_nominal, _res_44s_1 }, /* 1 */
  127718. { _map_nominal, _res_44s_2 }, /* 2 */
  127719. { _map_nominal, _res_44s_3 }, /* 3 */
  127720. { _map_nominal, _res_44s_4 }, /* 4 */
  127721. { _map_nominal, _res_44s_5 }, /* 5 */
  127722. { _map_nominal, _res_44s_6 }, /* 6 */
  127723. { _map_nominal, _res_44s_7 }, /* 7 */
  127724. { _map_nominal, _res_44s_8 }, /* 8 */
  127725. { _map_nominal, _res_44s_9 }, /* 9 */
  127726. };
  127727. /*** End of inlined file: residue_44.h ***/
  127728. /*** Start of inlined file: psych_44.h ***/
  127729. static vorbis_info_psy_global _psy_global_44[5]={
  127730. {8, /* lines per eighth octave */
  127731. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  127732. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  127733. -6.f,
  127734. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127735. },
  127736. {8, /* lines per eighth octave */
  127737. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127738. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  127739. -6.f,
  127740. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127741. },
  127742. {8, /* lines per eighth octave */
  127743. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  127744. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  127745. -6.f,
  127746. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127747. },
  127748. {8, /* lines per eighth octave */
  127749. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  127750. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  127751. -6.f,
  127752. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127753. },
  127754. {8, /* lines per eighth octave */
  127755. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  127756. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  127757. -6.f,
  127758. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  127759. },
  127760. };
  127761. static compandblock _psy_compand_44[6]={
  127762. {{
  127763. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127764. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127765. 16,17,18,19,20,21,22, 23, /* 23dB */
  127766. 24,25,26,27,28,29,30, 31, /* 31dB */
  127767. 32,33,34,35,36,37,38, 39, /* 39dB */
  127768. }},
  127769. {{
  127770. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  127771. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  127772. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  127773. 15,16,17,17,17,18,18, 19, /* 31dB */
  127774. 19,19,20,21,22,23,24, 25, /* 39dB */
  127775. }},
  127776. {{
  127777. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  127778. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  127779. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127780. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127781. 11,12,13,14,15,16,17, 18, /* 39dB */
  127782. }},
  127783. {{
  127784. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127785. 8, 9,10,11,12,13,14, 15, /* 15dB */
  127786. 16,17,18,19,20,21,22, 23, /* 23dB */
  127787. 24,25,26,27,28,29,30, 31, /* 31dB */
  127788. 32,33,34,35,36,37,38, 39, /* 39dB */
  127789. }},
  127790. {{
  127791. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127792. 8, 9,10,11,12,12,13, 13, /* 15dB */
  127793. 13,14,14,14,15,15,15, 15, /* 23dB */
  127794. 16,16,17,17,17,18,18, 19, /* 31dB */
  127795. 19,19,20,21,22,23,24, 25, /* 39dB */
  127796. }},
  127797. {{
  127798. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  127799. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  127800. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  127801. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  127802. 11,12,13,14,15,16,17, 18, /* 39dB */
  127803. }}
  127804. };
  127805. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  127806. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  127807. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  127808. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  127809. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  127810. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  127811. /* 4 */
  127812. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127813. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127814. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127815. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127816. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127817. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127818. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127819. };
  127820. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  127821. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  127822. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  127823. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  127824. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  127825. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  127826. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  127827. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  127828. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  127829. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  127830. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  127831. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  127832. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  127833. };
  127834. static noise3 _psy_noisebias_trans[12]={
  127835. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127836. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127837. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127838. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127839. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  127840. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127841. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127842. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127843. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127844. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127845. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127846. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  127847. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127848. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127849. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127850. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127851. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127852. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127853. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127854. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127855. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  127856. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127857. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127858. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127859. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  127860. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  127861. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127862. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  127863. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  127864. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127865. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127866. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  127867. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  127868. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  127869. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  127870. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127871. };
  127872. static noise3 _psy_noisebias_long[12]={
  127873. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  127874. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  127875. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127876. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  127877. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  127878. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  127879. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  127880. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  127881. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  127882. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  127883. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  127884. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  127885. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  127886. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  127887. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  127888. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127889. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  127890. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  127891. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127892. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  127893. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  127894. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127895. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  127896. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  127897. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  127898. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  127899. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  127900. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  127901. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  127902. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  127903. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127904. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  127905. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127906. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  127907. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  127908. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127909. };
  127910. static noise3 _psy_noisebias_impulse[12]={
  127911. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127912. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127913. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127914. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  127915. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  127916. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127917. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  127918. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  127919. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  127920. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  127921. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127922. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127923. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  127924. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127925. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127926. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  127927. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  127928. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  127929. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  127930. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  127931. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  127932. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  127933. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  127934. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  127935. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  127936. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  127937. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  127938. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  127939. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  127940. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  127941. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  127942. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  127943. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  127944. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  127945. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  127946. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127947. };
  127948. static noise3 _psy_noisebias_padding[12]={
  127949. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127950. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  127951. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  127952. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  127953. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  127954. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  127955. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  127956. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  127957. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  127958. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  127959. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  127960. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127961. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  127962. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  127963. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127964. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  127965. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  127966. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  127967. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127968. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  127969. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  127970. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127971. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  127972. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  127973. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  127974. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  127975. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  127976. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  127977. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  127978. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  127979. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  127980. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  127981. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  127982. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  127983. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  127984. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  127985. };
  127986. static noiseguard _psy_noiseguards_44[4]={
  127987. {3,3,15},
  127988. {3,3,15},
  127989. {10,10,100},
  127990. {10,10,100},
  127991. };
  127992. static int _psy_tone_suppress[12]={
  127993. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  127994. };
  127995. static int _psy_tone_0dB[12]={
  127996. 90,90,95,95,95,95,105,105,105,105,105,105,
  127997. };
  127998. static int _psy_noise_suppress[12]={
  127999. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128000. };
  128001. static vorbis_info_psy _psy_info_template={
  128002. -1,
  128003. -140.,-140.,
  128004. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128005. 1, -0.f, .5f, .5f, 0,0,0,
  128006. {{-1},{-1},{-1}},{-1},105.f,
  128007. 0,0,-1,-1,0.,
  128008. };
  128009. static int _psy_ath_floater[12]={
  128010. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128011. };
  128012. static int _psy_ath_abs[12]={
  128013. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128014. };
  128015. static adj_stereo _psy_stereo_modes_44[12]={
  128016. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128017. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128018. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128019. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128020. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128021. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128022. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128023. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128024. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128025. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128026. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128027. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128028. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128029. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128030. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128031. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128032. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128033. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128034. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128035. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128036. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128037. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128038. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128039. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128040. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128041. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128042. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128043. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128044. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128045. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128046. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128047. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128048. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128049. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128050. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128051. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128052. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128053. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128054. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128055. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128056. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128057. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128058. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128059. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128060. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128061. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128062. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128063. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128064. };
  128065. static att3 _psy_tone_masteratt_44[12]={
  128066. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128067. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128068. /* 1 */
  128069. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128070. /* 2 */
  128071. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128072. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128073. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128074. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128075. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128076. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128077. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128078. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128079. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128080. };
  128081. static double _psy_lowpass_44[12]={
  128082. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128083. };
  128084. static int _noise_start_short_44[11]={
  128085. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128086. };
  128087. static int _noise_start_long_44[11]={
  128088. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128089. };
  128090. static int _noise_part_short_44[11]={
  128091. 8,8,8,8,8,8,8,8,8,8,8
  128092. };
  128093. static int _noise_part_long_44[11]={
  128094. 32,32,32,32,32,32,32,32,32,32,32
  128095. };
  128096. static double _noise_thresh_44[11]={
  128097. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128098. };
  128099. static double _noise_thresh_5only[2]={
  128100. .5,.5,
  128101. };
  128102. /*** End of inlined file: psych_44.h ***/
  128103. static double rate_mapping_44_stereo[12]={
  128104. 22500.,32000.,40000.,48000.,56000.,64000.,
  128105. 80000.,96000.,112000.,128000.,160000.,250001.
  128106. };
  128107. static double quality_mapping_44[12]={
  128108. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128109. };
  128110. static int blocksize_short_44[11]={
  128111. 512,256,256,256,256,256,256,256,256,256,256
  128112. };
  128113. static int blocksize_long_44[11]={
  128114. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128115. };
  128116. static double _psy_compand_short_mapping[12]={
  128117. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128118. };
  128119. static double _psy_compand_long_mapping[12]={
  128120. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128121. };
  128122. static double _global_mapping_44[12]={
  128123. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128124. };
  128125. static int _floor_short_mapping_44[11]={
  128126. 1,0,0,2,2,4,5,5,5,5,5
  128127. };
  128128. static int _floor_long_mapping_44[11]={
  128129. 8,7,7,7,7,7,7,7,7,7,7
  128130. };
  128131. ve_setup_data_template ve_setup_44_stereo={
  128132. 11,
  128133. rate_mapping_44_stereo,
  128134. quality_mapping_44,
  128135. 2,
  128136. 40000,
  128137. 50000,
  128138. blocksize_short_44,
  128139. blocksize_long_44,
  128140. _psy_tone_masteratt_44,
  128141. _psy_tone_0dB,
  128142. _psy_tone_suppress,
  128143. _vp_tonemask_adj_otherblock,
  128144. _vp_tonemask_adj_longblock,
  128145. _vp_tonemask_adj_otherblock,
  128146. _psy_noiseguards_44,
  128147. _psy_noisebias_impulse,
  128148. _psy_noisebias_padding,
  128149. _psy_noisebias_trans,
  128150. _psy_noisebias_long,
  128151. _psy_noise_suppress,
  128152. _psy_compand_44,
  128153. _psy_compand_short_mapping,
  128154. _psy_compand_long_mapping,
  128155. {_noise_start_short_44,_noise_start_long_44},
  128156. {_noise_part_short_44,_noise_part_long_44},
  128157. _noise_thresh_44,
  128158. _psy_ath_floater,
  128159. _psy_ath_abs,
  128160. _psy_lowpass_44,
  128161. _psy_global_44,
  128162. _global_mapping_44,
  128163. _psy_stereo_modes_44,
  128164. _floor_books,
  128165. _floor,
  128166. _floor_short_mapping_44,
  128167. _floor_long_mapping_44,
  128168. _mapres_template_44_stereo
  128169. };
  128170. /*** End of inlined file: setup_44.h ***/
  128171. /*** Start of inlined file: setup_44u.h ***/
  128172. /*** Start of inlined file: residue_44u.h ***/
  128173. /*** Start of inlined file: res_books_uncoupled.h ***/
  128174. static long _vq_quantlist__16u0__p1_0[] = {
  128175. 1,
  128176. 0,
  128177. 2,
  128178. };
  128179. static long _vq_lengthlist__16u0__p1_0[] = {
  128180. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128181. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128182. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128183. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128184. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128185. 12,
  128186. };
  128187. static float _vq_quantthresh__16u0__p1_0[] = {
  128188. -0.5, 0.5,
  128189. };
  128190. static long _vq_quantmap__16u0__p1_0[] = {
  128191. 1, 0, 2,
  128192. };
  128193. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128194. _vq_quantthresh__16u0__p1_0,
  128195. _vq_quantmap__16u0__p1_0,
  128196. 3,
  128197. 3
  128198. };
  128199. static static_codebook _16u0__p1_0 = {
  128200. 4, 81,
  128201. _vq_lengthlist__16u0__p1_0,
  128202. 1, -535822336, 1611661312, 2, 0,
  128203. _vq_quantlist__16u0__p1_0,
  128204. NULL,
  128205. &_vq_auxt__16u0__p1_0,
  128206. NULL,
  128207. 0
  128208. };
  128209. static long _vq_quantlist__16u0__p2_0[] = {
  128210. 1,
  128211. 0,
  128212. 2,
  128213. };
  128214. static long _vq_lengthlist__16u0__p2_0[] = {
  128215. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128216. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128217. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128218. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128219. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128220. 8,
  128221. };
  128222. static float _vq_quantthresh__16u0__p2_0[] = {
  128223. -0.5, 0.5,
  128224. };
  128225. static long _vq_quantmap__16u0__p2_0[] = {
  128226. 1, 0, 2,
  128227. };
  128228. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128229. _vq_quantthresh__16u0__p2_0,
  128230. _vq_quantmap__16u0__p2_0,
  128231. 3,
  128232. 3
  128233. };
  128234. static static_codebook _16u0__p2_0 = {
  128235. 4, 81,
  128236. _vq_lengthlist__16u0__p2_0,
  128237. 1, -535822336, 1611661312, 2, 0,
  128238. _vq_quantlist__16u0__p2_0,
  128239. NULL,
  128240. &_vq_auxt__16u0__p2_0,
  128241. NULL,
  128242. 0
  128243. };
  128244. static long _vq_quantlist__16u0__p3_0[] = {
  128245. 2,
  128246. 1,
  128247. 3,
  128248. 0,
  128249. 4,
  128250. };
  128251. static long _vq_lengthlist__16u0__p3_0[] = {
  128252. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128253. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128254. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128255. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128256. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128257. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128258. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128259. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128260. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128261. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128262. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128263. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128264. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128265. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128266. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128267. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128268. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128269. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128270. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128271. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128272. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128273. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128274. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128275. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128276. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128277. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128278. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128279. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128280. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128281. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128282. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128283. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128284. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128285. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128286. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128287. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128288. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128289. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128290. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128291. 18,
  128292. };
  128293. static float _vq_quantthresh__16u0__p3_0[] = {
  128294. -1.5, -0.5, 0.5, 1.5,
  128295. };
  128296. static long _vq_quantmap__16u0__p3_0[] = {
  128297. 3, 1, 0, 2, 4,
  128298. };
  128299. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128300. _vq_quantthresh__16u0__p3_0,
  128301. _vq_quantmap__16u0__p3_0,
  128302. 5,
  128303. 5
  128304. };
  128305. static static_codebook _16u0__p3_0 = {
  128306. 4, 625,
  128307. _vq_lengthlist__16u0__p3_0,
  128308. 1, -533725184, 1611661312, 3, 0,
  128309. _vq_quantlist__16u0__p3_0,
  128310. NULL,
  128311. &_vq_auxt__16u0__p3_0,
  128312. NULL,
  128313. 0
  128314. };
  128315. static long _vq_quantlist__16u0__p4_0[] = {
  128316. 2,
  128317. 1,
  128318. 3,
  128319. 0,
  128320. 4,
  128321. };
  128322. static long _vq_lengthlist__16u0__p4_0[] = {
  128323. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128324. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128325. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128326. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128327. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128328. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128329. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128330. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128331. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128332. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128333. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128334. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128335. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128336. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128337. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128338. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128339. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128340. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128341. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128342. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128343. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128344. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128345. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128346. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128347. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128348. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128349. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128350. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128351. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128352. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128353. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128354. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128355. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128356. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128357. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128358. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128359. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128360. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128361. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128362. 11,
  128363. };
  128364. static float _vq_quantthresh__16u0__p4_0[] = {
  128365. -1.5, -0.5, 0.5, 1.5,
  128366. };
  128367. static long _vq_quantmap__16u0__p4_0[] = {
  128368. 3, 1, 0, 2, 4,
  128369. };
  128370. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128371. _vq_quantthresh__16u0__p4_0,
  128372. _vq_quantmap__16u0__p4_0,
  128373. 5,
  128374. 5
  128375. };
  128376. static static_codebook _16u0__p4_0 = {
  128377. 4, 625,
  128378. _vq_lengthlist__16u0__p4_0,
  128379. 1, -533725184, 1611661312, 3, 0,
  128380. _vq_quantlist__16u0__p4_0,
  128381. NULL,
  128382. &_vq_auxt__16u0__p4_0,
  128383. NULL,
  128384. 0
  128385. };
  128386. static long _vq_quantlist__16u0__p5_0[] = {
  128387. 4,
  128388. 3,
  128389. 5,
  128390. 2,
  128391. 6,
  128392. 1,
  128393. 7,
  128394. 0,
  128395. 8,
  128396. };
  128397. static long _vq_lengthlist__16u0__p5_0[] = {
  128398. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128399. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128400. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128401. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128402. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128403. 12,
  128404. };
  128405. static float _vq_quantthresh__16u0__p5_0[] = {
  128406. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128407. };
  128408. static long _vq_quantmap__16u0__p5_0[] = {
  128409. 7, 5, 3, 1, 0, 2, 4, 6,
  128410. 8,
  128411. };
  128412. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128413. _vq_quantthresh__16u0__p5_0,
  128414. _vq_quantmap__16u0__p5_0,
  128415. 9,
  128416. 9
  128417. };
  128418. static static_codebook _16u0__p5_0 = {
  128419. 2, 81,
  128420. _vq_lengthlist__16u0__p5_0,
  128421. 1, -531628032, 1611661312, 4, 0,
  128422. _vq_quantlist__16u0__p5_0,
  128423. NULL,
  128424. &_vq_auxt__16u0__p5_0,
  128425. NULL,
  128426. 0
  128427. };
  128428. static long _vq_quantlist__16u0__p6_0[] = {
  128429. 6,
  128430. 5,
  128431. 7,
  128432. 4,
  128433. 8,
  128434. 3,
  128435. 9,
  128436. 2,
  128437. 10,
  128438. 1,
  128439. 11,
  128440. 0,
  128441. 12,
  128442. };
  128443. static long _vq_lengthlist__16u0__p6_0[] = {
  128444. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128445. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128446. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128447. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128448. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128449. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128450. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128451. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128452. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128453. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128454. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128455. };
  128456. static float _vq_quantthresh__16u0__p6_0[] = {
  128457. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128458. 12.5, 17.5, 22.5, 27.5,
  128459. };
  128460. static long _vq_quantmap__16u0__p6_0[] = {
  128461. 11, 9, 7, 5, 3, 1, 0, 2,
  128462. 4, 6, 8, 10, 12,
  128463. };
  128464. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128465. _vq_quantthresh__16u0__p6_0,
  128466. _vq_quantmap__16u0__p6_0,
  128467. 13,
  128468. 13
  128469. };
  128470. static static_codebook _16u0__p6_0 = {
  128471. 2, 169,
  128472. _vq_lengthlist__16u0__p6_0,
  128473. 1, -526516224, 1616117760, 4, 0,
  128474. _vq_quantlist__16u0__p6_0,
  128475. NULL,
  128476. &_vq_auxt__16u0__p6_0,
  128477. NULL,
  128478. 0
  128479. };
  128480. static long _vq_quantlist__16u0__p6_1[] = {
  128481. 2,
  128482. 1,
  128483. 3,
  128484. 0,
  128485. 4,
  128486. };
  128487. static long _vq_lengthlist__16u0__p6_1[] = {
  128488. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128489. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128490. };
  128491. static float _vq_quantthresh__16u0__p6_1[] = {
  128492. -1.5, -0.5, 0.5, 1.5,
  128493. };
  128494. static long _vq_quantmap__16u0__p6_1[] = {
  128495. 3, 1, 0, 2, 4,
  128496. };
  128497. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128498. _vq_quantthresh__16u0__p6_1,
  128499. _vq_quantmap__16u0__p6_1,
  128500. 5,
  128501. 5
  128502. };
  128503. static static_codebook _16u0__p6_1 = {
  128504. 2, 25,
  128505. _vq_lengthlist__16u0__p6_1,
  128506. 1, -533725184, 1611661312, 3, 0,
  128507. _vq_quantlist__16u0__p6_1,
  128508. NULL,
  128509. &_vq_auxt__16u0__p6_1,
  128510. NULL,
  128511. 0
  128512. };
  128513. static long _vq_quantlist__16u0__p7_0[] = {
  128514. 1,
  128515. 0,
  128516. 2,
  128517. };
  128518. static long _vq_lengthlist__16u0__p7_0[] = {
  128519. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128520. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  128521. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128522. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128523. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  128524. 7,
  128525. };
  128526. static float _vq_quantthresh__16u0__p7_0[] = {
  128527. -157.5, 157.5,
  128528. };
  128529. static long _vq_quantmap__16u0__p7_0[] = {
  128530. 1, 0, 2,
  128531. };
  128532. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  128533. _vq_quantthresh__16u0__p7_0,
  128534. _vq_quantmap__16u0__p7_0,
  128535. 3,
  128536. 3
  128537. };
  128538. static static_codebook _16u0__p7_0 = {
  128539. 4, 81,
  128540. _vq_lengthlist__16u0__p7_0,
  128541. 1, -518803456, 1628680192, 2, 0,
  128542. _vq_quantlist__16u0__p7_0,
  128543. NULL,
  128544. &_vq_auxt__16u0__p7_0,
  128545. NULL,
  128546. 0
  128547. };
  128548. static long _vq_quantlist__16u0__p7_1[] = {
  128549. 7,
  128550. 6,
  128551. 8,
  128552. 5,
  128553. 9,
  128554. 4,
  128555. 10,
  128556. 3,
  128557. 11,
  128558. 2,
  128559. 12,
  128560. 1,
  128561. 13,
  128562. 0,
  128563. 14,
  128564. };
  128565. static long _vq_lengthlist__16u0__p7_1[] = {
  128566. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  128567. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  128568. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  128569. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  128570. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  128571. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  128572. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128573. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128574. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128575. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128576. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128577. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128578. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128579. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  128580. 10,
  128581. };
  128582. static float _vq_quantthresh__16u0__p7_1[] = {
  128583. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  128584. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  128585. };
  128586. static long _vq_quantmap__16u0__p7_1[] = {
  128587. 13, 11, 9, 7, 5, 3, 1, 0,
  128588. 2, 4, 6, 8, 10, 12, 14,
  128589. };
  128590. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  128591. _vq_quantthresh__16u0__p7_1,
  128592. _vq_quantmap__16u0__p7_1,
  128593. 15,
  128594. 15
  128595. };
  128596. static static_codebook _16u0__p7_1 = {
  128597. 2, 225,
  128598. _vq_lengthlist__16u0__p7_1,
  128599. 1, -520986624, 1620377600, 4, 0,
  128600. _vq_quantlist__16u0__p7_1,
  128601. NULL,
  128602. &_vq_auxt__16u0__p7_1,
  128603. NULL,
  128604. 0
  128605. };
  128606. static long _vq_quantlist__16u0__p7_2[] = {
  128607. 10,
  128608. 9,
  128609. 11,
  128610. 8,
  128611. 12,
  128612. 7,
  128613. 13,
  128614. 6,
  128615. 14,
  128616. 5,
  128617. 15,
  128618. 4,
  128619. 16,
  128620. 3,
  128621. 17,
  128622. 2,
  128623. 18,
  128624. 1,
  128625. 19,
  128626. 0,
  128627. 20,
  128628. };
  128629. static long _vq_lengthlist__16u0__p7_2[] = {
  128630. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  128631. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  128632. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  128633. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  128634. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  128635. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  128636. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  128637. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  128638. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  128639. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  128640. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  128641. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  128642. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  128643. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  128644. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  128645. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  128646. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  128647. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  128648. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  128649. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  128650. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  128651. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  128652. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  128653. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  128654. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  128655. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  128656. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  128657. 10,10,12,11,10,11,11,11,10,
  128658. };
  128659. static float _vq_quantthresh__16u0__p7_2[] = {
  128660. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  128661. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  128662. 6.5, 7.5, 8.5, 9.5,
  128663. };
  128664. static long _vq_quantmap__16u0__p7_2[] = {
  128665. 19, 17, 15, 13, 11, 9, 7, 5,
  128666. 3, 1, 0, 2, 4, 6, 8, 10,
  128667. 12, 14, 16, 18, 20,
  128668. };
  128669. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  128670. _vq_quantthresh__16u0__p7_2,
  128671. _vq_quantmap__16u0__p7_2,
  128672. 21,
  128673. 21
  128674. };
  128675. static static_codebook _16u0__p7_2 = {
  128676. 2, 441,
  128677. _vq_lengthlist__16u0__p7_2,
  128678. 1, -529268736, 1611661312, 5, 0,
  128679. _vq_quantlist__16u0__p7_2,
  128680. NULL,
  128681. &_vq_auxt__16u0__p7_2,
  128682. NULL,
  128683. 0
  128684. };
  128685. static long _huff_lengthlist__16u0__single[] = {
  128686. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  128687. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  128688. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  128689. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  128690. };
  128691. static static_codebook _huff_book__16u0__single = {
  128692. 2, 64,
  128693. _huff_lengthlist__16u0__single,
  128694. 0, 0, 0, 0, 0,
  128695. NULL,
  128696. NULL,
  128697. NULL,
  128698. NULL,
  128699. 0
  128700. };
  128701. static long _huff_lengthlist__16u1__long[] = {
  128702. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  128703. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  128704. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  128705. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  128706. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  128707. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  128708. 16,13,16,18,
  128709. };
  128710. static static_codebook _huff_book__16u1__long = {
  128711. 2, 100,
  128712. _huff_lengthlist__16u1__long,
  128713. 0, 0, 0, 0, 0,
  128714. NULL,
  128715. NULL,
  128716. NULL,
  128717. NULL,
  128718. 0
  128719. };
  128720. static long _vq_quantlist__16u1__p1_0[] = {
  128721. 1,
  128722. 0,
  128723. 2,
  128724. };
  128725. static long _vq_lengthlist__16u1__p1_0[] = {
  128726. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  128727. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  128728. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  128729. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  128730. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  128731. 11,
  128732. };
  128733. static float _vq_quantthresh__16u1__p1_0[] = {
  128734. -0.5, 0.5,
  128735. };
  128736. static long _vq_quantmap__16u1__p1_0[] = {
  128737. 1, 0, 2,
  128738. };
  128739. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  128740. _vq_quantthresh__16u1__p1_0,
  128741. _vq_quantmap__16u1__p1_0,
  128742. 3,
  128743. 3
  128744. };
  128745. static static_codebook _16u1__p1_0 = {
  128746. 4, 81,
  128747. _vq_lengthlist__16u1__p1_0,
  128748. 1, -535822336, 1611661312, 2, 0,
  128749. _vq_quantlist__16u1__p1_0,
  128750. NULL,
  128751. &_vq_auxt__16u1__p1_0,
  128752. NULL,
  128753. 0
  128754. };
  128755. static long _vq_quantlist__16u1__p2_0[] = {
  128756. 1,
  128757. 0,
  128758. 2,
  128759. };
  128760. static long _vq_lengthlist__16u1__p2_0[] = {
  128761. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  128762. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  128763. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  128764. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  128765. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  128766. 8,
  128767. };
  128768. static float _vq_quantthresh__16u1__p2_0[] = {
  128769. -0.5, 0.5,
  128770. };
  128771. static long _vq_quantmap__16u1__p2_0[] = {
  128772. 1, 0, 2,
  128773. };
  128774. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  128775. _vq_quantthresh__16u1__p2_0,
  128776. _vq_quantmap__16u1__p2_0,
  128777. 3,
  128778. 3
  128779. };
  128780. static static_codebook _16u1__p2_0 = {
  128781. 4, 81,
  128782. _vq_lengthlist__16u1__p2_0,
  128783. 1, -535822336, 1611661312, 2, 0,
  128784. _vq_quantlist__16u1__p2_0,
  128785. NULL,
  128786. &_vq_auxt__16u1__p2_0,
  128787. NULL,
  128788. 0
  128789. };
  128790. static long _vq_quantlist__16u1__p3_0[] = {
  128791. 2,
  128792. 1,
  128793. 3,
  128794. 0,
  128795. 4,
  128796. };
  128797. static long _vq_lengthlist__16u1__p3_0[] = {
  128798. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  128799. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  128800. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  128801. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  128802. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  128803. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  128804. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  128805. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  128806. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  128807. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  128808. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  128809. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  128810. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  128811. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  128812. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  128813. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  128814. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  128815. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  128816. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  128817. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  128818. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  128819. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  128820. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  128821. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  128822. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  128823. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  128824. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  128825. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  128826. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  128827. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  128828. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  128829. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  128830. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  128831. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  128832. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  128833. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  128834. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  128835. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  128836. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  128837. 16,
  128838. };
  128839. static float _vq_quantthresh__16u1__p3_0[] = {
  128840. -1.5, -0.5, 0.5, 1.5,
  128841. };
  128842. static long _vq_quantmap__16u1__p3_0[] = {
  128843. 3, 1, 0, 2, 4,
  128844. };
  128845. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  128846. _vq_quantthresh__16u1__p3_0,
  128847. _vq_quantmap__16u1__p3_0,
  128848. 5,
  128849. 5
  128850. };
  128851. static static_codebook _16u1__p3_0 = {
  128852. 4, 625,
  128853. _vq_lengthlist__16u1__p3_0,
  128854. 1, -533725184, 1611661312, 3, 0,
  128855. _vq_quantlist__16u1__p3_0,
  128856. NULL,
  128857. &_vq_auxt__16u1__p3_0,
  128858. NULL,
  128859. 0
  128860. };
  128861. static long _vq_quantlist__16u1__p4_0[] = {
  128862. 2,
  128863. 1,
  128864. 3,
  128865. 0,
  128866. 4,
  128867. };
  128868. static long _vq_lengthlist__16u1__p4_0[] = {
  128869. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  128870. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  128871. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  128872. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  128873. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  128874. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  128875. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  128876. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  128877. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  128878. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  128879. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  128880. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  128881. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  128882. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  128883. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  128884. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  128885. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  128886. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  128887. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  128888. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  128889. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  128890. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  128891. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  128892. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  128893. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  128894. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  128895. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  128896. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  128897. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  128898. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  128899. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  128900. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  128901. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  128902. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  128903. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  128904. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  128905. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  128906. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  128907. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  128908. 11,
  128909. };
  128910. static float _vq_quantthresh__16u1__p4_0[] = {
  128911. -1.5, -0.5, 0.5, 1.5,
  128912. };
  128913. static long _vq_quantmap__16u1__p4_0[] = {
  128914. 3, 1, 0, 2, 4,
  128915. };
  128916. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  128917. _vq_quantthresh__16u1__p4_0,
  128918. _vq_quantmap__16u1__p4_0,
  128919. 5,
  128920. 5
  128921. };
  128922. static static_codebook _16u1__p4_0 = {
  128923. 4, 625,
  128924. _vq_lengthlist__16u1__p4_0,
  128925. 1, -533725184, 1611661312, 3, 0,
  128926. _vq_quantlist__16u1__p4_0,
  128927. NULL,
  128928. &_vq_auxt__16u1__p4_0,
  128929. NULL,
  128930. 0
  128931. };
  128932. static long _vq_quantlist__16u1__p5_0[] = {
  128933. 4,
  128934. 3,
  128935. 5,
  128936. 2,
  128937. 6,
  128938. 1,
  128939. 7,
  128940. 0,
  128941. 8,
  128942. };
  128943. static long _vq_lengthlist__16u1__p5_0[] = {
  128944. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128945. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  128946. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  128947. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  128948. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  128949. 13,
  128950. };
  128951. static float _vq_quantthresh__16u1__p5_0[] = {
  128952. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128953. };
  128954. static long _vq_quantmap__16u1__p5_0[] = {
  128955. 7, 5, 3, 1, 0, 2, 4, 6,
  128956. 8,
  128957. };
  128958. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  128959. _vq_quantthresh__16u1__p5_0,
  128960. _vq_quantmap__16u1__p5_0,
  128961. 9,
  128962. 9
  128963. };
  128964. static static_codebook _16u1__p5_0 = {
  128965. 2, 81,
  128966. _vq_lengthlist__16u1__p5_0,
  128967. 1, -531628032, 1611661312, 4, 0,
  128968. _vq_quantlist__16u1__p5_0,
  128969. NULL,
  128970. &_vq_auxt__16u1__p5_0,
  128971. NULL,
  128972. 0
  128973. };
  128974. static long _vq_quantlist__16u1__p6_0[] = {
  128975. 4,
  128976. 3,
  128977. 5,
  128978. 2,
  128979. 6,
  128980. 1,
  128981. 7,
  128982. 0,
  128983. 8,
  128984. };
  128985. static long _vq_lengthlist__16u1__p6_0[] = {
  128986. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  128987. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  128988. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  128989. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  128990. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  128991. 11,
  128992. };
  128993. static float _vq_quantthresh__16u1__p6_0[] = {
  128994. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128995. };
  128996. static long _vq_quantmap__16u1__p6_0[] = {
  128997. 7, 5, 3, 1, 0, 2, 4, 6,
  128998. 8,
  128999. };
  129000. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129001. _vq_quantthresh__16u1__p6_0,
  129002. _vq_quantmap__16u1__p6_0,
  129003. 9,
  129004. 9
  129005. };
  129006. static static_codebook _16u1__p6_0 = {
  129007. 2, 81,
  129008. _vq_lengthlist__16u1__p6_0,
  129009. 1, -531628032, 1611661312, 4, 0,
  129010. _vq_quantlist__16u1__p6_0,
  129011. NULL,
  129012. &_vq_auxt__16u1__p6_0,
  129013. NULL,
  129014. 0
  129015. };
  129016. static long _vq_quantlist__16u1__p7_0[] = {
  129017. 1,
  129018. 0,
  129019. 2,
  129020. };
  129021. static long _vq_lengthlist__16u1__p7_0[] = {
  129022. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129023. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129024. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129025. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129026. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129027. 13,
  129028. };
  129029. static float _vq_quantthresh__16u1__p7_0[] = {
  129030. -5.5, 5.5,
  129031. };
  129032. static long _vq_quantmap__16u1__p7_0[] = {
  129033. 1, 0, 2,
  129034. };
  129035. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129036. _vq_quantthresh__16u1__p7_0,
  129037. _vq_quantmap__16u1__p7_0,
  129038. 3,
  129039. 3
  129040. };
  129041. static static_codebook _16u1__p7_0 = {
  129042. 4, 81,
  129043. _vq_lengthlist__16u1__p7_0,
  129044. 1, -529137664, 1618345984, 2, 0,
  129045. _vq_quantlist__16u1__p7_0,
  129046. NULL,
  129047. &_vq_auxt__16u1__p7_0,
  129048. NULL,
  129049. 0
  129050. };
  129051. static long _vq_quantlist__16u1__p7_1[] = {
  129052. 5,
  129053. 4,
  129054. 6,
  129055. 3,
  129056. 7,
  129057. 2,
  129058. 8,
  129059. 1,
  129060. 9,
  129061. 0,
  129062. 10,
  129063. };
  129064. static long _vq_lengthlist__16u1__p7_1[] = {
  129065. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129066. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129067. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129068. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129069. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129070. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129071. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129072. 8, 9, 9,10,10,10,10,10,10,
  129073. };
  129074. static float _vq_quantthresh__16u1__p7_1[] = {
  129075. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129076. 3.5, 4.5,
  129077. };
  129078. static long _vq_quantmap__16u1__p7_1[] = {
  129079. 9, 7, 5, 3, 1, 0, 2, 4,
  129080. 6, 8, 10,
  129081. };
  129082. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129083. _vq_quantthresh__16u1__p7_1,
  129084. _vq_quantmap__16u1__p7_1,
  129085. 11,
  129086. 11
  129087. };
  129088. static static_codebook _16u1__p7_1 = {
  129089. 2, 121,
  129090. _vq_lengthlist__16u1__p7_1,
  129091. 1, -531365888, 1611661312, 4, 0,
  129092. _vq_quantlist__16u1__p7_1,
  129093. NULL,
  129094. &_vq_auxt__16u1__p7_1,
  129095. NULL,
  129096. 0
  129097. };
  129098. static long _vq_quantlist__16u1__p8_0[] = {
  129099. 5,
  129100. 4,
  129101. 6,
  129102. 3,
  129103. 7,
  129104. 2,
  129105. 8,
  129106. 1,
  129107. 9,
  129108. 0,
  129109. 10,
  129110. };
  129111. static long _vq_lengthlist__16u1__p8_0[] = {
  129112. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129113. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129114. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129115. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129116. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129117. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129118. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129119. 13,14,14,15,15,16,16,15,16,
  129120. };
  129121. static float _vq_quantthresh__16u1__p8_0[] = {
  129122. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129123. 38.5, 49.5,
  129124. };
  129125. static long _vq_quantmap__16u1__p8_0[] = {
  129126. 9, 7, 5, 3, 1, 0, 2, 4,
  129127. 6, 8, 10,
  129128. };
  129129. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129130. _vq_quantthresh__16u1__p8_0,
  129131. _vq_quantmap__16u1__p8_0,
  129132. 11,
  129133. 11
  129134. };
  129135. static static_codebook _16u1__p8_0 = {
  129136. 2, 121,
  129137. _vq_lengthlist__16u1__p8_0,
  129138. 1, -524582912, 1618345984, 4, 0,
  129139. _vq_quantlist__16u1__p8_0,
  129140. NULL,
  129141. &_vq_auxt__16u1__p8_0,
  129142. NULL,
  129143. 0
  129144. };
  129145. static long _vq_quantlist__16u1__p8_1[] = {
  129146. 5,
  129147. 4,
  129148. 6,
  129149. 3,
  129150. 7,
  129151. 2,
  129152. 8,
  129153. 1,
  129154. 9,
  129155. 0,
  129156. 10,
  129157. };
  129158. static long _vq_lengthlist__16u1__p8_1[] = {
  129159. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129160. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129161. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129162. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129163. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129164. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129165. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129166. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129167. };
  129168. static float _vq_quantthresh__16u1__p8_1[] = {
  129169. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129170. 3.5, 4.5,
  129171. };
  129172. static long _vq_quantmap__16u1__p8_1[] = {
  129173. 9, 7, 5, 3, 1, 0, 2, 4,
  129174. 6, 8, 10,
  129175. };
  129176. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129177. _vq_quantthresh__16u1__p8_1,
  129178. _vq_quantmap__16u1__p8_1,
  129179. 11,
  129180. 11
  129181. };
  129182. static static_codebook _16u1__p8_1 = {
  129183. 2, 121,
  129184. _vq_lengthlist__16u1__p8_1,
  129185. 1, -531365888, 1611661312, 4, 0,
  129186. _vq_quantlist__16u1__p8_1,
  129187. NULL,
  129188. &_vq_auxt__16u1__p8_1,
  129189. NULL,
  129190. 0
  129191. };
  129192. static long _vq_quantlist__16u1__p9_0[] = {
  129193. 7,
  129194. 6,
  129195. 8,
  129196. 5,
  129197. 9,
  129198. 4,
  129199. 10,
  129200. 3,
  129201. 11,
  129202. 2,
  129203. 12,
  129204. 1,
  129205. 13,
  129206. 0,
  129207. 14,
  129208. };
  129209. static long _vq_lengthlist__16u1__p9_0[] = {
  129210. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129211. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129212. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129213. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129214. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129215. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129216. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129217. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129218. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129219. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129220. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129221. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129222. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129223. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129224. 8,
  129225. };
  129226. static float _vq_quantthresh__16u1__p9_0[] = {
  129227. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129228. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129229. };
  129230. static long _vq_quantmap__16u1__p9_0[] = {
  129231. 13, 11, 9, 7, 5, 3, 1, 0,
  129232. 2, 4, 6, 8, 10, 12, 14,
  129233. };
  129234. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129235. _vq_quantthresh__16u1__p9_0,
  129236. _vq_quantmap__16u1__p9_0,
  129237. 15,
  129238. 15
  129239. };
  129240. static static_codebook _16u1__p9_0 = {
  129241. 2, 225,
  129242. _vq_lengthlist__16u1__p9_0,
  129243. 1, -514071552, 1627381760, 4, 0,
  129244. _vq_quantlist__16u1__p9_0,
  129245. NULL,
  129246. &_vq_auxt__16u1__p9_0,
  129247. NULL,
  129248. 0
  129249. };
  129250. static long _vq_quantlist__16u1__p9_1[] = {
  129251. 7,
  129252. 6,
  129253. 8,
  129254. 5,
  129255. 9,
  129256. 4,
  129257. 10,
  129258. 3,
  129259. 11,
  129260. 2,
  129261. 12,
  129262. 1,
  129263. 13,
  129264. 0,
  129265. 14,
  129266. };
  129267. static long _vq_lengthlist__16u1__p9_1[] = {
  129268. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129269. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129270. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129271. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129272. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129273. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129274. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129275. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129276. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129277. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129278. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129279. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129280. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129281. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129282. 9,
  129283. };
  129284. static float _vq_quantthresh__16u1__p9_1[] = {
  129285. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129286. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129287. };
  129288. static long _vq_quantmap__16u1__p9_1[] = {
  129289. 13, 11, 9, 7, 5, 3, 1, 0,
  129290. 2, 4, 6, 8, 10, 12, 14,
  129291. };
  129292. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129293. _vq_quantthresh__16u1__p9_1,
  129294. _vq_quantmap__16u1__p9_1,
  129295. 15,
  129296. 15
  129297. };
  129298. static static_codebook _16u1__p9_1 = {
  129299. 2, 225,
  129300. _vq_lengthlist__16u1__p9_1,
  129301. 1, -522338304, 1620115456, 4, 0,
  129302. _vq_quantlist__16u1__p9_1,
  129303. NULL,
  129304. &_vq_auxt__16u1__p9_1,
  129305. NULL,
  129306. 0
  129307. };
  129308. static long _vq_quantlist__16u1__p9_2[] = {
  129309. 8,
  129310. 7,
  129311. 9,
  129312. 6,
  129313. 10,
  129314. 5,
  129315. 11,
  129316. 4,
  129317. 12,
  129318. 3,
  129319. 13,
  129320. 2,
  129321. 14,
  129322. 1,
  129323. 15,
  129324. 0,
  129325. 16,
  129326. };
  129327. static long _vq_lengthlist__16u1__p9_2[] = {
  129328. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129329. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129330. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129331. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129332. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129333. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129334. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129335. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129336. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129337. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129338. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129339. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129340. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129341. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129342. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129343. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129344. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129345. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129346. 10,
  129347. };
  129348. static float _vq_quantthresh__16u1__p9_2[] = {
  129349. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129350. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129351. };
  129352. static long _vq_quantmap__16u1__p9_2[] = {
  129353. 15, 13, 11, 9, 7, 5, 3, 1,
  129354. 0, 2, 4, 6, 8, 10, 12, 14,
  129355. 16,
  129356. };
  129357. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129358. _vq_quantthresh__16u1__p9_2,
  129359. _vq_quantmap__16u1__p9_2,
  129360. 17,
  129361. 17
  129362. };
  129363. static static_codebook _16u1__p9_2 = {
  129364. 2, 289,
  129365. _vq_lengthlist__16u1__p9_2,
  129366. 1, -529530880, 1611661312, 5, 0,
  129367. _vq_quantlist__16u1__p9_2,
  129368. NULL,
  129369. &_vq_auxt__16u1__p9_2,
  129370. NULL,
  129371. 0
  129372. };
  129373. static long _huff_lengthlist__16u1__short[] = {
  129374. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129375. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129376. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129377. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129378. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129379. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129380. 16,16,16,16,
  129381. };
  129382. static static_codebook _huff_book__16u1__short = {
  129383. 2, 100,
  129384. _huff_lengthlist__16u1__short,
  129385. 0, 0, 0, 0, 0,
  129386. NULL,
  129387. NULL,
  129388. NULL,
  129389. NULL,
  129390. 0
  129391. };
  129392. static long _huff_lengthlist__16u2__long[] = {
  129393. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129394. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129395. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129396. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129397. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129398. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129399. 13,14,18,18,
  129400. };
  129401. static static_codebook _huff_book__16u2__long = {
  129402. 2, 100,
  129403. _huff_lengthlist__16u2__long,
  129404. 0, 0, 0, 0, 0,
  129405. NULL,
  129406. NULL,
  129407. NULL,
  129408. NULL,
  129409. 0
  129410. };
  129411. static long _huff_lengthlist__16u2__short[] = {
  129412. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129413. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129414. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129415. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129416. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129417. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129418. 16,16,16,16,
  129419. };
  129420. static static_codebook _huff_book__16u2__short = {
  129421. 2, 100,
  129422. _huff_lengthlist__16u2__short,
  129423. 0, 0, 0, 0, 0,
  129424. NULL,
  129425. NULL,
  129426. NULL,
  129427. NULL,
  129428. 0
  129429. };
  129430. static long _vq_quantlist__16u2_p1_0[] = {
  129431. 1,
  129432. 0,
  129433. 2,
  129434. };
  129435. static long _vq_lengthlist__16u2_p1_0[] = {
  129436. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129437. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129438. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129439. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129440. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129441. 10,
  129442. };
  129443. static float _vq_quantthresh__16u2_p1_0[] = {
  129444. -0.5, 0.5,
  129445. };
  129446. static long _vq_quantmap__16u2_p1_0[] = {
  129447. 1, 0, 2,
  129448. };
  129449. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129450. _vq_quantthresh__16u2_p1_0,
  129451. _vq_quantmap__16u2_p1_0,
  129452. 3,
  129453. 3
  129454. };
  129455. static static_codebook _16u2_p1_0 = {
  129456. 4, 81,
  129457. _vq_lengthlist__16u2_p1_0,
  129458. 1, -535822336, 1611661312, 2, 0,
  129459. _vq_quantlist__16u2_p1_0,
  129460. NULL,
  129461. &_vq_auxt__16u2_p1_0,
  129462. NULL,
  129463. 0
  129464. };
  129465. static long _vq_quantlist__16u2_p2_0[] = {
  129466. 2,
  129467. 1,
  129468. 3,
  129469. 0,
  129470. 4,
  129471. };
  129472. static long _vq_lengthlist__16u2_p2_0[] = {
  129473. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129474. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129475. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129476. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129477. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129478. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129479. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129480. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129481. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129482. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129483. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129484. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129485. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129486. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129487. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129488. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129489. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129490. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129491. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129492. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129493. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129494. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129495. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129496. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129497. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129498. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129499. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129500. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129501. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129502. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129503. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129504. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129505. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129506. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129507. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129508. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  129509. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  129510. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  129511. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  129512. 13,
  129513. };
  129514. static float _vq_quantthresh__16u2_p2_0[] = {
  129515. -1.5, -0.5, 0.5, 1.5,
  129516. };
  129517. static long _vq_quantmap__16u2_p2_0[] = {
  129518. 3, 1, 0, 2, 4,
  129519. };
  129520. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  129521. _vq_quantthresh__16u2_p2_0,
  129522. _vq_quantmap__16u2_p2_0,
  129523. 5,
  129524. 5
  129525. };
  129526. static static_codebook _16u2_p2_0 = {
  129527. 4, 625,
  129528. _vq_lengthlist__16u2_p2_0,
  129529. 1, -533725184, 1611661312, 3, 0,
  129530. _vq_quantlist__16u2_p2_0,
  129531. NULL,
  129532. &_vq_auxt__16u2_p2_0,
  129533. NULL,
  129534. 0
  129535. };
  129536. static long _vq_quantlist__16u2_p3_0[] = {
  129537. 4,
  129538. 3,
  129539. 5,
  129540. 2,
  129541. 6,
  129542. 1,
  129543. 7,
  129544. 0,
  129545. 8,
  129546. };
  129547. static long _vq_lengthlist__16u2_p3_0[] = {
  129548. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  129549. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  129550. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129551. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129552. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129553. 11,
  129554. };
  129555. static float _vq_quantthresh__16u2_p3_0[] = {
  129556. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129557. };
  129558. static long _vq_quantmap__16u2_p3_0[] = {
  129559. 7, 5, 3, 1, 0, 2, 4, 6,
  129560. 8,
  129561. };
  129562. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  129563. _vq_quantthresh__16u2_p3_0,
  129564. _vq_quantmap__16u2_p3_0,
  129565. 9,
  129566. 9
  129567. };
  129568. static static_codebook _16u2_p3_0 = {
  129569. 2, 81,
  129570. _vq_lengthlist__16u2_p3_0,
  129571. 1, -531628032, 1611661312, 4, 0,
  129572. _vq_quantlist__16u2_p3_0,
  129573. NULL,
  129574. &_vq_auxt__16u2_p3_0,
  129575. NULL,
  129576. 0
  129577. };
  129578. static long _vq_quantlist__16u2_p4_0[] = {
  129579. 8,
  129580. 7,
  129581. 9,
  129582. 6,
  129583. 10,
  129584. 5,
  129585. 11,
  129586. 4,
  129587. 12,
  129588. 3,
  129589. 13,
  129590. 2,
  129591. 14,
  129592. 1,
  129593. 15,
  129594. 0,
  129595. 16,
  129596. };
  129597. static long _vq_lengthlist__16u2_p4_0[] = {
  129598. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  129599. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  129600. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  129601. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  129602. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  129603. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  129604. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  129605. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  129606. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  129607. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  129608. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  129609. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  129610. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  129611. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  129612. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  129613. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  129614. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  129615. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  129616. 14,
  129617. };
  129618. static float _vq_quantthresh__16u2_p4_0[] = {
  129619. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129620. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129621. };
  129622. static long _vq_quantmap__16u2_p4_0[] = {
  129623. 15, 13, 11, 9, 7, 5, 3, 1,
  129624. 0, 2, 4, 6, 8, 10, 12, 14,
  129625. 16,
  129626. };
  129627. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  129628. _vq_quantthresh__16u2_p4_0,
  129629. _vq_quantmap__16u2_p4_0,
  129630. 17,
  129631. 17
  129632. };
  129633. static static_codebook _16u2_p4_0 = {
  129634. 2, 289,
  129635. _vq_lengthlist__16u2_p4_0,
  129636. 1, -529530880, 1611661312, 5, 0,
  129637. _vq_quantlist__16u2_p4_0,
  129638. NULL,
  129639. &_vq_auxt__16u2_p4_0,
  129640. NULL,
  129641. 0
  129642. };
  129643. static long _vq_quantlist__16u2_p5_0[] = {
  129644. 1,
  129645. 0,
  129646. 2,
  129647. };
  129648. static long _vq_lengthlist__16u2_p5_0[] = {
  129649. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  129650. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  129651. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  129652. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  129653. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  129654. 10,
  129655. };
  129656. static float _vq_quantthresh__16u2_p5_0[] = {
  129657. -5.5, 5.5,
  129658. };
  129659. static long _vq_quantmap__16u2_p5_0[] = {
  129660. 1, 0, 2,
  129661. };
  129662. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  129663. _vq_quantthresh__16u2_p5_0,
  129664. _vq_quantmap__16u2_p5_0,
  129665. 3,
  129666. 3
  129667. };
  129668. static static_codebook _16u2_p5_0 = {
  129669. 4, 81,
  129670. _vq_lengthlist__16u2_p5_0,
  129671. 1, -529137664, 1618345984, 2, 0,
  129672. _vq_quantlist__16u2_p5_0,
  129673. NULL,
  129674. &_vq_auxt__16u2_p5_0,
  129675. NULL,
  129676. 0
  129677. };
  129678. static long _vq_quantlist__16u2_p5_1[] = {
  129679. 5,
  129680. 4,
  129681. 6,
  129682. 3,
  129683. 7,
  129684. 2,
  129685. 8,
  129686. 1,
  129687. 9,
  129688. 0,
  129689. 10,
  129690. };
  129691. static long _vq_lengthlist__16u2_p5_1[] = {
  129692. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  129693. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  129694. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  129695. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129696. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129697. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129698. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129699. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  129700. };
  129701. static float _vq_quantthresh__16u2_p5_1[] = {
  129702. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129703. 3.5, 4.5,
  129704. };
  129705. static long _vq_quantmap__16u2_p5_1[] = {
  129706. 9, 7, 5, 3, 1, 0, 2, 4,
  129707. 6, 8, 10,
  129708. };
  129709. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  129710. _vq_quantthresh__16u2_p5_1,
  129711. _vq_quantmap__16u2_p5_1,
  129712. 11,
  129713. 11
  129714. };
  129715. static static_codebook _16u2_p5_1 = {
  129716. 2, 121,
  129717. _vq_lengthlist__16u2_p5_1,
  129718. 1, -531365888, 1611661312, 4, 0,
  129719. _vq_quantlist__16u2_p5_1,
  129720. NULL,
  129721. &_vq_auxt__16u2_p5_1,
  129722. NULL,
  129723. 0
  129724. };
  129725. static long _vq_quantlist__16u2_p6_0[] = {
  129726. 6,
  129727. 5,
  129728. 7,
  129729. 4,
  129730. 8,
  129731. 3,
  129732. 9,
  129733. 2,
  129734. 10,
  129735. 1,
  129736. 11,
  129737. 0,
  129738. 12,
  129739. };
  129740. static long _vq_lengthlist__16u2_p6_0[] = {
  129741. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  129742. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  129743. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  129744. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  129745. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  129746. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  129747. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  129748. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  129749. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  129750. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  129751. 12,13,13,14,14,14,14,15,15,
  129752. };
  129753. static float _vq_quantthresh__16u2_p6_0[] = {
  129754. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  129755. 12.5, 17.5, 22.5, 27.5,
  129756. };
  129757. static long _vq_quantmap__16u2_p6_0[] = {
  129758. 11, 9, 7, 5, 3, 1, 0, 2,
  129759. 4, 6, 8, 10, 12,
  129760. };
  129761. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  129762. _vq_quantthresh__16u2_p6_0,
  129763. _vq_quantmap__16u2_p6_0,
  129764. 13,
  129765. 13
  129766. };
  129767. static static_codebook _16u2_p6_0 = {
  129768. 2, 169,
  129769. _vq_lengthlist__16u2_p6_0,
  129770. 1, -526516224, 1616117760, 4, 0,
  129771. _vq_quantlist__16u2_p6_0,
  129772. NULL,
  129773. &_vq_auxt__16u2_p6_0,
  129774. NULL,
  129775. 0
  129776. };
  129777. static long _vq_quantlist__16u2_p6_1[] = {
  129778. 2,
  129779. 1,
  129780. 3,
  129781. 0,
  129782. 4,
  129783. };
  129784. static long _vq_lengthlist__16u2_p6_1[] = {
  129785. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  129786. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  129787. };
  129788. static float _vq_quantthresh__16u2_p6_1[] = {
  129789. -1.5, -0.5, 0.5, 1.5,
  129790. };
  129791. static long _vq_quantmap__16u2_p6_1[] = {
  129792. 3, 1, 0, 2, 4,
  129793. };
  129794. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  129795. _vq_quantthresh__16u2_p6_1,
  129796. _vq_quantmap__16u2_p6_1,
  129797. 5,
  129798. 5
  129799. };
  129800. static static_codebook _16u2_p6_1 = {
  129801. 2, 25,
  129802. _vq_lengthlist__16u2_p6_1,
  129803. 1, -533725184, 1611661312, 3, 0,
  129804. _vq_quantlist__16u2_p6_1,
  129805. NULL,
  129806. &_vq_auxt__16u2_p6_1,
  129807. NULL,
  129808. 0
  129809. };
  129810. static long _vq_quantlist__16u2_p7_0[] = {
  129811. 6,
  129812. 5,
  129813. 7,
  129814. 4,
  129815. 8,
  129816. 3,
  129817. 9,
  129818. 2,
  129819. 10,
  129820. 1,
  129821. 11,
  129822. 0,
  129823. 12,
  129824. };
  129825. static long _vq_lengthlist__16u2_p7_0[] = {
  129826. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  129827. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  129828. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  129829. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  129830. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  129831. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  129832. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  129833. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  129834. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  129835. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  129836. 12,13,13,13,14,14,14,15,14,
  129837. };
  129838. static float _vq_quantthresh__16u2_p7_0[] = {
  129839. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  129840. 27.5, 38.5, 49.5, 60.5,
  129841. };
  129842. static long _vq_quantmap__16u2_p7_0[] = {
  129843. 11, 9, 7, 5, 3, 1, 0, 2,
  129844. 4, 6, 8, 10, 12,
  129845. };
  129846. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  129847. _vq_quantthresh__16u2_p7_0,
  129848. _vq_quantmap__16u2_p7_0,
  129849. 13,
  129850. 13
  129851. };
  129852. static static_codebook _16u2_p7_0 = {
  129853. 2, 169,
  129854. _vq_lengthlist__16u2_p7_0,
  129855. 1, -523206656, 1618345984, 4, 0,
  129856. _vq_quantlist__16u2_p7_0,
  129857. NULL,
  129858. &_vq_auxt__16u2_p7_0,
  129859. NULL,
  129860. 0
  129861. };
  129862. static long _vq_quantlist__16u2_p7_1[] = {
  129863. 5,
  129864. 4,
  129865. 6,
  129866. 3,
  129867. 7,
  129868. 2,
  129869. 8,
  129870. 1,
  129871. 9,
  129872. 0,
  129873. 10,
  129874. };
  129875. static long _vq_lengthlist__16u2_p7_1[] = {
  129876. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  129877. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  129878. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  129879. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  129880. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  129881. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  129882. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  129883. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129884. };
  129885. static float _vq_quantthresh__16u2_p7_1[] = {
  129886. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129887. 3.5, 4.5,
  129888. };
  129889. static long _vq_quantmap__16u2_p7_1[] = {
  129890. 9, 7, 5, 3, 1, 0, 2, 4,
  129891. 6, 8, 10,
  129892. };
  129893. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  129894. _vq_quantthresh__16u2_p7_1,
  129895. _vq_quantmap__16u2_p7_1,
  129896. 11,
  129897. 11
  129898. };
  129899. static static_codebook _16u2_p7_1 = {
  129900. 2, 121,
  129901. _vq_lengthlist__16u2_p7_1,
  129902. 1, -531365888, 1611661312, 4, 0,
  129903. _vq_quantlist__16u2_p7_1,
  129904. NULL,
  129905. &_vq_auxt__16u2_p7_1,
  129906. NULL,
  129907. 0
  129908. };
  129909. static long _vq_quantlist__16u2_p8_0[] = {
  129910. 7,
  129911. 6,
  129912. 8,
  129913. 5,
  129914. 9,
  129915. 4,
  129916. 10,
  129917. 3,
  129918. 11,
  129919. 2,
  129920. 12,
  129921. 1,
  129922. 13,
  129923. 0,
  129924. 14,
  129925. };
  129926. static long _vq_lengthlist__16u2_p8_0[] = {
  129927. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  129928. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  129929. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  129930. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  129931. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  129932. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  129933. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  129934. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  129935. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  129936. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  129937. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  129938. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  129939. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  129940. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  129941. 14,
  129942. };
  129943. static float _vq_quantthresh__16u2_p8_0[] = {
  129944. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129945. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129946. };
  129947. static long _vq_quantmap__16u2_p8_0[] = {
  129948. 13, 11, 9, 7, 5, 3, 1, 0,
  129949. 2, 4, 6, 8, 10, 12, 14,
  129950. };
  129951. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  129952. _vq_quantthresh__16u2_p8_0,
  129953. _vq_quantmap__16u2_p8_0,
  129954. 15,
  129955. 15
  129956. };
  129957. static static_codebook _16u2_p8_0 = {
  129958. 2, 225,
  129959. _vq_lengthlist__16u2_p8_0,
  129960. 1, -520986624, 1620377600, 4, 0,
  129961. _vq_quantlist__16u2_p8_0,
  129962. NULL,
  129963. &_vq_auxt__16u2_p8_0,
  129964. NULL,
  129965. 0
  129966. };
  129967. static long _vq_quantlist__16u2_p8_1[] = {
  129968. 10,
  129969. 9,
  129970. 11,
  129971. 8,
  129972. 12,
  129973. 7,
  129974. 13,
  129975. 6,
  129976. 14,
  129977. 5,
  129978. 15,
  129979. 4,
  129980. 16,
  129981. 3,
  129982. 17,
  129983. 2,
  129984. 18,
  129985. 1,
  129986. 19,
  129987. 0,
  129988. 20,
  129989. };
  129990. static long _vq_lengthlist__16u2_p8_1[] = {
  129991. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  129992. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  129993. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  129994. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  129995. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  129996. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  129997. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  129998. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  129999. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130000. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130001. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130002. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130003. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130004. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130005. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130006. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130007. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130008. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130009. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130010. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130011. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130012. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130013. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130014. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130015. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130016. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130017. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130018. 11,11,10,11,11,11,10,11,11,
  130019. };
  130020. static float _vq_quantthresh__16u2_p8_1[] = {
  130021. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130022. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130023. 6.5, 7.5, 8.5, 9.5,
  130024. };
  130025. static long _vq_quantmap__16u2_p8_1[] = {
  130026. 19, 17, 15, 13, 11, 9, 7, 5,
  130027. 3, 1, 0, 2, 4, 6, 8, 10,
  130028. 12, 14, 16, 18, 20,
  130029. };
  130030. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130031. _vq_quantthresh__16u2_p8_1,
  130032. _vq_quantmap__16u2_p8_1,
  130033. 21,
  130034. 21
  130035. };
  130036. static static_codebook _16u2_p8_1 = {
  130037. 2, 441,
  130038. _vq_lengthlist__16u2_p8_1,
  130039. 1, -529268736, 1611661312, 5, 0,
  130040. _vq_quantlist__16u2_p8_1,
  130041. NULL,
  130042. &_vq_auxt__16u2_p8_1,
  130043. NULL,
  130044. 0
  130045. };
  130046. static long _vq_quantlist__16u2_p9_0[] = {
  130047. 5586,
  130048. 4655,
  130049. 6517,
  130050. 3724,
  130051. 7448,
  130052. 2793,
  130053. 8379,
  130054. 1862,
  130055. 9310,
  130056. 931,
  130057. 10241,
  130058. 0,
  130059. 11172,
  130060. 5521,
  130061. 5651,
  130062. };
  130063. static long _vq_lengthlist__16u2_p9_0[] = {
  130064. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130065. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130066. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130067. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130068. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130069. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130070. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130071. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130072. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130073. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130074. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130075. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130076. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130077. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130078. 5,
  130079. };
  130080. static float _vq_quantthresh__16u2_p9_0[] = {
  130081. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130082. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130083. };
  130084. static long _vq_quantmap__16u2_p9_0[] = {
  130085. 11, 9, 7, 5, 3, 1, 13, 0,
  130086. 14, 2, 4, 6, 8, 10, 12,
  130087. };
  130088. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130089. _vq_quantthresh__16u2_p9_0,
  130090. _vq_quantmap__16u2_p9_0,
  130091. 15,
  130092. 15
  130093. };
  130094. static static_codebook _16u2_p9_0 = {
  130095. 2, 225,
  130096. _vq_lengthlist__16u2_p9_0,
  130097. 1, -510275072, 1611661312, 14, 0,
  130098. _vq_quantlist__16u2_p9_0,
  130099. NULL,
  130100. &_vq_auxt__16u2_p9_0,
  130101. NULL,
  130102. 0
  130103. };
  130104. static long _vq_quantlist__16u2_p9_1[] = {
  130105. 392,
  130106. 343,
  130107. 441,
  130108. 294,
  130109. 490,
  130110. 245,
  130111. 539,
  130112. 196,
  130113. 588,
  130114. 147,
  130115. 637,
  130116. 98,
  130117. 686,
  130118. 49,
  130119. 735,
  130120. 0,
  130121. 784,
  130122. 388,
  130123. 396,
  130124. };
  130125. static long _vq_lengthlist__16u2_p9_1[] = {
  130126. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130127. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130128. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130129. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130130. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130131. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130132. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130133. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130134. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130135. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130136. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130137. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130138. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130139. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130140. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130141. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130142. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130143. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130144. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130145. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130146. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130147. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130148. 11,11,11,11,11,11,11, 5, 4,
  130149. };
  130150. static float _vq_quantthresh__16u2_p9_1[] = {
  130151. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130152. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130153. 318.5, 367.5,
  130154. };
  130155. static long _vq_quantmap__16u2_p9_1[] = {
  130156. 15, 13, 11, 9, 7, 5, 3, 1,
  130157. 17, 0, 18, 2, 4, 6, 8, 10,
  130158. 12, 14, 16,
  130159. };
  130160. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130161. _vq_quantthresh__16u2_p9_1,
  130162. _vq_quantmap__16u2_p9_1,
  130163. 19,
  130164. 19
  130165. };
  130166. static static_codebook _16u2_p9_1 = {
  130167. 2, 361,
  130168. _vq_lengthlist__16u2_p9_1,
  130169. 1, -518488064, 1611661312, 10, 0,
  130170. _vq_quantlist__16u2_p9_1,
  130171. NULL,
  130172. &_vq_auxt__16u2_p9_1,
  130173. NULL,
  130174. 0
  130175. };
  130176. static long _vq_quantlist__16u2_p9_2[] = {
  130177. 24,
  130178. 23,
  130179. 25,
  130180. 22,
  130181. 26,
  130182. 21,
  130183. 27,
  130184. 20,
  130185. 28,
  130186. 19,
  130187. 29,
  130188. 18,
  130189. 30,
  130190. 17,
  130191. 31,
  130192. 16,
  130193. 32,
  130194. 15,
  130195. 33,
  130196. 14,
  130197. 34,
  130198. 13,
  130199. 35,
  130200. 12,
  130201. 36,
  130202. 11,
  130203. 37,
  130204. 10,
  130205. 38,
  130206. 9,
  130207. 39,
  130208. 8,
  130209. 40,
  130210. 7,
  130211. 41,
  130212. 6,
  130213. 42,
  130214. 5,
  130215. 43,
  130216. 4,
  130217. 44,
  130218. 3,
  130219. 45,
  130220. 2,
  130221. 46,
  130222. 1,
  130223. 47,
  130224. 0,
  130225. 48,
  130226. };
  130227. static long _vq_lengthlist__16u2_p9_2[] = {
  130228. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130229. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130230. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130231. 11,
  130232. };
  130233. static float _vq_quantthresh__16u2_p9_2[] = {
  130234. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130235. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130236. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130237. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130238. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130239. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130240. };
  130241. static long _vq_quantmap__16u2_p9_2[] = {
  130242. 47, 45, 43, 41, 39, 37, 35, 33,
  130243. 31, 29, 27, 25, 23, 21, 19, 17,
  130244. 15, 13, 11, 9, 7, 5, 3, 1,
  130245. 0, 2, 4, 6, 8, 10, 12, 14,
  130246. 16, 18, 20, 22, 24, 26, 28, 30,
  130247. 32, 34, 36, 38, 40, 42, 44, 46,
  130248. 48,
  130249. };
  130250. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130251. _vq_quantthresh__16u2_p9_2,
  130252. _vq_quantmap__16u2_p9_2,
  130253. 49,
  130254. 49
  130255. };
  130256. static static_codebook _16u2_p9_2 = {
  130257. 1, 49,
  130258. _vq_lengthlist__16u2_p9_2,
  130259. 1, -526909440, 1611661312, 6, 0,
  130260. _vq_quantlist__16u2_p9_2,
  130261. NULL,
  130262. &_vq_auxt__16u2_p9_2,
  130263. NULL,
  130264. 0
  130265. };
  130266. static long _vq_quantlist__8u0__p1_0[] = {
  130267. 1,
  130268. 0,
  130269. 2,
  130270. };
  130271. static long _vq_lengthlist__8u0__p1_0[] = {
  130272. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130273. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130274. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130275. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130276. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130277. 11,
  130278. };
  130279. static float _vq_quantthresh__8u0__p1_0[] = {
  130280. -0.5, 0.5,
  130281. };
  130282. static long _vq_quantmap__8u0__p1_0[] = {
  130283. 1, 0, 2,
  130284. };
  130285. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130286. _vq_quantthresh__8u0__p1_0,
  130287. _vq_quantmap__8u0__p1_0,
  130288. 3,
  130289. 3
  130290. };
  130291. static static_codebook _8u0__p1_0 = {
  130292. 4, 81,
  130293. _vq_lengthlist__8u0__p1_0,
  130294. 1, -535822336, 1611661312, 2, 0,
  130295. _vq_quantlist__8u0__p1_0,
  130296. NULL,
  130297. &_vq_auxt__8u0__p1_0,
  130298. NULL,
  130299. 0
  130300. };
  130301. static long _vq_quantlist__8u0__p2_0[] = {
  130302. 1,
  130303. 0,
  130304. 2,
  130305. };
  130306. static long _vq_lengthlist__8u0__p2_0[] = {
  130307. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130308. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130309. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130310. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130311. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130312. 8,
  130313. };
  130314. static float _vq_quantthresh__8u0__p2_0[] = {
  130315. -0.5, 0.5,
  130316. };
  130317. static long _vq_quantmap__8u0__p2_0[] = {
  130318. 1, 0, 2,
  130319. };
  130320. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130321. _vq_quantthresh__8u0__p2_0,
  130322. _vq_quantmap__8u0__p2_0,
  130323. 3,
  130324. 3
  130325. };
  130326. static static_codebook _8u0__p2_0 = {
  130327. 4, 81,
  130328. _vq_lengthlist__8u0__p2_0,
  130329. 1, -535822336, 1611661312, 2, 0,
  130330. _vq_quantlist__8u0__p2_0,
  130331. NULL,
  130332. &_vq_auxt__8u0__p2_0,
  130333. NULL,
  130334. 0
  130335. };
  130336. static long _vq_quantlist__8u0__p3_0[] = {
  130337. 2,
  130338. 1,
  130339. 3,
  130340. 0,
  130341. 4,
  130342. };
  130343. static long _vq_lengthlist__8u0__p3_0[] = {
  130344. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130345. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130346. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130347. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130348. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130349. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130350. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130351. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130352. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130353. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130354. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130355. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130356. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130357. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130358. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130359. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130360. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130361. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130362. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130363. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130364. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130365. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130366. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130367. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130368. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130369. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130370. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130371. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130372. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130373. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130374. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130375. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130376. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130377. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130378. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130379. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130380. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130381. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130382. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130383. 16,
  130384. };
  130385. static float _vq_quantthresh__8u0__p3_0[] = {
  130386. -1.5, -0.5, 0.5, 1.5,
  130387. };
  130388. static long _vq_quantmap__8u0__p3_0[] = {
  130389. 3, 1, 0, 2, 4,
  130390. };
  130391. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130392. _vq_quantthresh__8u0__p3_0,
  130393. _vq_quantmap__8u0__p3_0,
  130394. 5,
  130395. 5
  130396. };
  130397. static static_codebook _8u0__p3_0 = {
  130398. 4, 625,
  130399. _vq_lengthlist__8u0__p3_0,
  130400. 1, -533725184, 1611661312, 3, 0,
  130401. _vq_quantlist__8u0__p3_0,
  130402. NULL,
  130403. &_vq_auxt__8u0__p3_0,
  130404. NULL,
  130405. 0
  130406. };
  130407. static long _vq_quantlist__8u0__p4_0[] = {
  130408. 2,
  130409. 1,
  130410. 3,
  130411. 0,
  130412. 4,
  130413. };
  130414. static long _vq_lengthlist__8u0__p4_0[] = {
  130415. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130416. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130417. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130418. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130419. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130420. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130421. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130422. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130423. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130424. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130425. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130426. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130427. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130428. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130429. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130430. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130431. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130432. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130433. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130434. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130435. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130436. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130437. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130438. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130439. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130440. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130441. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130442. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130443. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130444. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130445. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130446. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130447. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130448. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130449. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130450. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130451. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130452. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130453. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130454. 12,
  130455. };
  130456. static float _vq_quantthresh__8u0__p4_0[] = {
  130457. -1.5, -0.5, 0.5, 1.5,
  130458. };
  130459. static long _vq_quantmap__8u0__p4_0[] = {
  130460. 3, 1, 0, 2, 4,
  130461. };
  130462. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130463. _vq_quantthresh__8u0__p4_0,
  130464. _vq_quantmap__8u0__p4_0,
  130465. 5,
  130466. 5
  130467. };
  130468. static static_codebook _8u0__p4_0 = {
  130469. 4, 625,
  130470. _vq_lengthlist__8u0__p4_0,
  130471. 1, -533725184, 1611661312, 3, 0,
  130472. _vq_quantlist__8u0__p4_0,
  130473. NULL,
  130474. &_vq_auxt__8u0__p4_0,
  130475. NULL,
  130476. 0
  130477. };
  130478. static long _vq_quantlist__8u0__p5_0[] = {
  130479. 4,
  130480. 3,
  130481. 5,
  130482. 2,
  130483. 6,
  130484. 1,
  130485. 7,
  130486. 0,
  130487. 8,
  130488. };
  130489. static long _vq_lengthlist__8u0__p5_0[] = {
  130490. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130491. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130492. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130493. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130494. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130495. 12,
  130496. };
  130497. static float _vq_quantthresh__8u0__p5_0[] = {
  130498. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130499. };
  130500. static long _vq_quantmap__8u0__p5_0[] = {
  130501. 7, 5, 3, 1, 0, 2, 4, 6,
  130502. 8,
  130503. };
  130504. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130505. _vq_quantthresh__8u0__p5_0,
  130506. _vq_quantmap__8u0__p5_0,
  130507. 9,
  130508. 9
  130509. };
  130510. static static_codebook _8u0__p5_0 = {
  130511. 2, 81,
  130512. _vq_lengthlist__8u0__p5_0,
  130513. 1, -531628032, 1611661312, 4, 0,
  130514. _vq_quantlist__8u0__p5_0,
  130515. NULL,
  130516. &_vq_auxt__8u0__p5_0,
  130517. NULL,
  130518. 0
  130519. };
  130520. static long _vq_quantlist__8u0__p6_0[] = {
  130521. 6,
  130522. 5,
  130523. 7,
  130524. 4,
  130525. 8,
  130526. 3,
  130527. 9,
  130528. 2,
  130529. 10,
  130530. 1,
  130531. 11,
  130532. 0,
  130533. 12,
  130534. };
  130535. static long _vq_lengthlist__8u0__p6_0[] = {
  130536. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  130537. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  130538. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  130539. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  130540. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  130541. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  130542. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  130543. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  130544. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  130545. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  130546. 16, 0,15, 0,17, 0, 0, 0, 0,
  130547. };
  130548. static float _vq_quantthresh__8u0__p6_0[] = {
  130549. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130550. 12.5, 17.5, 22.5, 27.5,
  130551. };
  130552. static long _vq_quantmap__8u0__p6_0[] = {
  130553. 11, 9, 7, 5, 3, 1, 0, 2,
  130554. 4, 6, 8, 10, 12,
  130555. };
  130556. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  130557. _vq_quantthresh__8u0__p6_0,
  130558. _vq_quantmap__8u0__p6_0,
  130559. 13,
  130560. 13
  130561. };
  130562. static static_codebook _8u0__p6_0 = {
  130563. 2, 169,
  130564. _vq_lengthlist__8u0__p6_0,
  130565. 1, -526516224, 1616117760, 4, 0,
  130566. _vq_quantlist__8u0__p6_0,
  130567. NULL,
  130568. &_vq_auxt__8u0__p6_0,
  130569. NULL,
  130570. 0
  130571. };
  130572. static long _vq_quantlist__8u0__p6_1[] = {
  130573. 2,
  130574. 1,
  130575. 3,
  130576. 0,
  130577. 4,
  130578. };
  130579. static long _vq_lengthlist__8u0__p6_1[] = {
  130580. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  130581. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  130582. };
  130583. static float _vq_quantthresh__8u0__p6_1[] = {
  130584. -1.5, -0.5, 0.5, 1.5,
  130585. };
  130586. static long _vq_quantmap__8u0__p6_1[] = {
  130587. 3, 1, 0, 2, 4,
  130588. };
  130589. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  130590. _vq_quantthresh__8u0__p6_1,
  130591. _vq_quantmap__8u0__p6_1,
  130592. 5,
  130593. 5
  130594. };
  130595. static static_codebook _8u0__p6_1 = {
  130596. 2, 25,
  130597. _vq_lengthlist__8u0__p6_1,
  130598. 1, -533725184, 1611661312, 3, 0,
  130599. _vq_quantlist__8u0__p6_1,
  130600. NULL,
  130601. &_vq_auxt__8u0__p6_1,
  130602. NULL,
  130603. 0
  130604. };
  130605. static long _vq_quantlist__8u0__p7_0[] = {
  130606. 1,
  130607. 0,
  130608. 2,
  130609. };
  130610. static long _vq_lengthlist__8u0__p7_0[] = {
  130611. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130612. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130613. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130614. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130615. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  130616. 7,
  130617. };
  130618. static float _vq_quantthresh__8u0__p7_0[] = {
  130619. -157.5, 157.5,
  130620. };
  130621. static long _vq_quantmap__8u0__p7_0[] = {
  130622. 1, 0, 2,
  130623. };
  130624. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  130625. _vq_quantthresh__8u0__p7_0,
  130626. _vq_quantmap__8u0__p7_0,
  130627. 3,
  130628. 3
  130629. };
  130630. static static_codebook _8u0__p7_0 = {
  130631. 4, 81,
  130632. _vq_lengthlist__8u0__p7_0,
  130633. 1, -518803456, 1628680192, 2, 0,
  130634. _vq_quantlist__8u0__p7_0,
  130635. NULL,
  130636. &_vq_auxt__8u0__p7_0,
  130637. NULL,
  130638. 0
  130639. };
  130640. static long _vq_quantlist__8u0__p7_1[] = {
  130641. 7,
  130642. 6,
  130643. 8,
  130644. 5,
  130645. 9,
  130646. 4,
  130647. 10,
  130648. 3,
  130649. 11,
  130650. 2,
  130651. 12,
  130652. 1,
  130653. 13,
  130654. 0,
  130655. 14,
  130656. };
  130657. static long _vq_lengthlist__8u0__p7_1[] = {
  130658. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  130659. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  130660. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  130661. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  130662. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  130663. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  130664. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130665. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130666. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130667. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130668. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130669. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130670. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  130671. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130672. 10,
  130673. };
  130674. static float _vq_quantthresh__8u0__p7_1[] = {
  130675. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130676. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130677. };
  130678. static long _vq_quantmap__8u0__p7_1[] = {
  130679. 13, 11, 9, 7, 5, 3, 1, 0,
  130680. 2, 4, 6, 8, 10, 12, 14,
  130681. };
  130682. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  130683. _vq_quantthresh__8u0__p7_1,
  130684. _vq_quantmap__8u0__p7_1,
  130685. 15,
  130686. 15
  130687. };
  130688. static static_codebook _8u0__p7_1 = {
  130689. 2, 225,
  130690. _vq_lengthlist__8u0__p7_1,
  130691. 1, -520986624, 1620377600, 4, 0,
  130692. _vq_quantlist__8u0__p7_1,
  130693. NULL,
  130694. &_vq_auxt__8u0__p7_1,
  130695. NULL,
  130696. 0
  130697. };
  130698. static long _vq_quantlist__8u0__p7_2[] = {
  130699. 10,
  130700. 9,
  130701. 11,
  130702. 8,
  130703. 12,
  130704. 7,
  130705. 13,
  130706. 6,
  130707. 14,
  130708. 5,
  130709. 15,
  130710. 4,
  130711. 16,
  130712. 3,
  130713. 17,
  130714. 2,
  130715. 18,
  130716. 1,
  130717. 19,
  130718. 0,
  130719. 20,
  130720. };
  130721. static long _vq_lengthlist__8u0__p7_2[] = {
  130722. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  130723. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  130724. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  130725. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  130726. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  130727. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  130728. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  130729. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  130730. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  130731. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  130732. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  130733. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  130734. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  130735. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  130736. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  130737. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  130738. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  130739. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  130740. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  130741. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  130742. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  130743. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  130744. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  130745. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  130746. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  130747. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  130748. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  130749. 11,12,11,11,11,10,10,11,11,
  130750. };
  130751. static float _vq_quantthresh__8u0__p7_2[] = {
  130752. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130753. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130754. 6.5, 7.5, 8.5, 9.5,
  130755. };
  130756. static long _vq_quantmap__8u0__p7_2[] = {
  130757. 19, 17, 15, 13, 11, 9, 7, 5,
  130758. 3, 1, 0, 2, 4, 6, 8, 10,
  130759. 12, 14, 16, 18, 20,
  130760. };
  130761. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  130762. _vq_quantthresh__8u0__p7_2,
  130763. _vq_quantmap__8u0__p7_2,
  130764. 21,
  130765. 21
  130766. };
  130767. static static_codebook _8u0__p7_2 = {
  130768. 2, 441,
  130769. _vq_lengthlist__8u0__p7_2,
  130770. 1, -529268736, 1611661312, 5, 0,
  130771. _vq_quantlist__8u0__p7_2,
  130772. NULL,
  130773. &_vq_auxt__8u0__p7_2,
  130774. NULL,
  130775. 0
  130776. };
  130777. static long _huff_lengthlist__8u0__single[] = {
  130778. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  130779. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  130780. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  130781. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  130782. };
  130783. static static_codebook _huff_book__8u0__single = {
  130784. 2, 64,
  130785. _huff_lengthlist__8u0__single,
  130786. 0, 0, 0, 0, 0,
  130787. NULL,
  130788. NULL,
  130789. NULL,
  130790. NULL,
  130791. 0
  130792. };
  130793. static long _vq_quantlist__8u1__p1_0[] = {
  130794. 1,
  130795. 0,
  130796. 2,
  130797. };
  130798. static long _vq_lengthlist__8u1__p1_0[] = {
  130799. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  130800. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  130801. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  130802. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  130803. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  130804. 10,
  130805. };
  130806. static float _vq_quantthresh__8u1__p1_0[] = {
  130807. -0.5, 0.5,
  130808. };
  130809. static long _vq_quantmap__8u1__p1_0[] = {
  130810. 1, 0, 2,
  130811. };
  130812. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  130813. _vq_quantthresh__8u1__p1_0,
  130814. _vq_quantmap__8u1__p1_0,
  130815. 3,
  130816. 3
  130817. };
  130818. static static_codebook _8u1__p1_0 = {
  130819. 4, 81,
  130820. _vq_lengthlist__8u1__p1_0,
  130821. 1, -535822336, 1611661312, 2, 0,
  130822. _vq_quantlist__8u1__p1_0,
  130823. NULL,
  130824. &_vq_auxt__8u1__p1_0,
  130825. NULL,
  130826. 0
  130827. };
  130828. static long _vq_quantlist__8u1__p2_0[] = {
  130829. 1,
  130830. 0,
  130831. 2,
  130832. };
  130833. static long _vq_lengthlist__8u1__p2_0[] = {
  130834. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  130835. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  130836. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  130837. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  130838. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  130839. 7,
  130840. };
  130841. static float _vq_quantthresh__8u1__p2_0[] = {
  130842. -0.5, 0.5,
  130843. };
  130844. static long _vq_quantmap__8u1__p2_0[] = {
  130845. 1, 0, 2,
  130846. };
  130847. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  130848. _vq_quantthresh__8u1__p2_0,
  130849. _vq_quantmap__8u1__p2_0,
  130850. 3,
  130851. 3
  130852. };
  130853. static static_codebook _8u1__p2_0 = {
  130854. 4, 81,
  130855. _vq_lengthlist__8u1__p2_0,
  130856. 1, -535822336, 1611661312, 2, 0,
  130857. _vq_quantlist__8u1__p2_0,
  130858. NULL,
  130859. &_vq_auxt__8u1__p2_0,
  130860. NULL,
  130861. 0
  130862. };
  130863. static long _vq_quantlist__8u1__p3_0[] = {
  130864. 2,
  130865. 1,
  130866. 3,
  130867. 0,
  130868. 4,
  130869. };
  130870. static long _vq_lengthlist__8u1__p3_0[] = {
  130871. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130872. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130873. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  130874. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  130875. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  130876. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  130877. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  130878. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  130879. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  130880. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  130881. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  130882. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  130883. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  130884. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  130885. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  130886. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  130887. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  130888. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  130889. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  130890. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  130891. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  130892. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  130893. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  130894. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  130895. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  130896. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  130897. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  130898. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  130899. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  130900. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  130901. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  130902. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  130903. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  130904. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  130905. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  130906. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  130907. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  130908. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  130909. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  130910. 16,
  130911. };
  130912. static float _vq_quantthresh__8u1__p3_0[] = {
  130913. -1.5, -0.5, 0.5, 1.5,
  130914. };
  130915. static long _vq_quantmap__8u1__p3_0[] = {
  130916. 3, 1, 0, 2, 4,
  130917. };
  130918. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  130919. _vq_quantthresh__8u1__p3_0,
  130920. _vq_quantmap__8u1__p3_0,
  130921. 5,
  130922. 5
  130923. };
  130924. static static_codebook _8u1__p3_0 = {
  130925. 4, 625,
  130926. _vq_lengthlist__8u1__p3_0,
  130927. 1, -533725184, 1611661312, 3, 0,
  130928. _vq_quantlist__8u1__p3_0,
  130929. NULL,
  130930. &_vq_auxt__8u1__p3_0,
  130931. NULL,
  130932. 0
  130933. };
  130934. static long _vq_quantlist__8u1__p4_0[] = {
  130935. 2,
  130936. 1,
  130937. 3,
  130938. 0,
  130939. 4,
  130940. };
  130941. static long _vq_lengthlist__8u1__p4_0[] = {
  130942. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  130943. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  130944. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  130945. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  130946. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  130947. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  130948. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  130949. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  130950. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  130951. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  130952. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  130953. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  130954. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  130955. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  130956. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  130957. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  130958. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  130959. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  130960. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  130961. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  130962. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  130963. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  130964. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  130965. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  130966. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  130967. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  130968. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  130969. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  130970. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  130971. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  130972. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  130973. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  130974. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  130975. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  130976. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  130977. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  130978. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  130979. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  130980. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  130981. 10,
  130982. };
  130983. static float _vq_quantthresh__8u1__p4_0[] = {
  130984. -1.5, -0.5, 0.5, 1.5,
  130985. };
  130986. static long _vq_quantmap__8u1__p4_0[] = {
  130987. 3, 1, 0, 2, 4,
  130988. };
  130989. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  130990. _vq_quantthresh__8u1__p4_0,
  130991. _vq_quantmap__8u1__p4_0,
  130992. 5,
  130993. 5
  130994. };
  130995. static static_codebook _8u1__p4_0 = {
  130996. 4, 625,
  130997. _vq_lengthlist__8u1__p4_0,
  130998. 1, -533725184, 1611661312, 3, 0,
  130999. _vq_quantlist__8u1__p4_0,
  131000. NULL,
  131001. &_vq_auxt__8u1__p4_0,
  131002. NULL,
  131003. 0
  131004. };
  131005. static long _vq_quantlist__8u1__p5_0[] = {
  131006. 4,
  131007. 3,
  131008. 5,
  131009. 2,
  131010. 6,
  131011. 1,
  131012. 7,
  131013. 0,
  131014. 8,
  131015. };
  131016. static long _vq_lengthlist__8u1__p5_0[] = {
  131017. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131018. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131019. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131020. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131021. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131022. 13,
  131023. };
  131024. static float _vq_quantthresh__8u1__p5_0[] = {
  131025. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131026. };
  131027. static long _vq_quantmap__8u1__p5_0[] = {
  131028. 7, 5, 3, 1, 0, 2, 4, 6,
  131029. 8,
  131030. };
  131031. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131032. _vq_quantthresh__8u1__p5_0,
  131033. _vq_quantmap__8u1__p5_0,
  131034. 9,
  131035. 9
  131036. };
  131037. static static_codebook _8u1__p5_0 = {
  131038. 2, 81,
  131039. _vq_lengthlist__8u1__p5_0,
  131040. 1, -531628032, 1611661312, 4, 0,
  131041. _vq_quantlist__8u1__p5_0,
  131042. NULL,
  131043. &_vq_auxt__8u1__p5_0,
  131044. NULL,
  131045. 0
  131046. };
  131047. static long _vq_quantlist__8u1__p6_0[] = {
  131048. 4,
  131049. 3,
  131050. 5,
  131051. 2,
  131052. 6,
  131053. 1,
  131054. 7,
  131055. 0,
  131056. 8,
  131057. };
  131058. static long _vq_lengthlist__8u1__p6_0[] = {
  131059. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131060. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131061. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131062. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131063. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131064. 10,
  131065. };
  131066. static float _vq_quantthresh__8u1__p6_0[] = {
  131067. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131068. };
  131069. static long _vq_quantmap__8u1__p6_0[] = {
  131070. 7, 5, 3, 1, 0, 2, 4, 6,
  131071. 8,
  131072. };
  131073. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131074. _vq_quantthresh__8u1__p6_0,
  131075. _vq_quantmap__8u1__p6_0,
  131076. 9,
  131077. 9
  131078. };
  131079. static static_codebook _8u1__p6_0 = {
  131080. 2, 81,
  131081. _vq_lengthlist__8u1__p6_0,
  131082. 1, -531628032, 1611661312, 4, 0,
  131083. _vq_quantlist__8u1__p6_0,
  131084. NULL,
  131085. &_vq_auxt__8u1__p6_0,
  131086. NULL,
  131087. 0
  131088. };
  131089. static long _vq_quantlist__8u1__p7_0[] = {
  131090. 1,
  131091. 0,
  131092. 2,
  131093. };
  131094. static long _vq_lengthlist__8u1__p7_0[] = {
  131095. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131096. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131097. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131098. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131099. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131100. 11,
  131101. };
  131102. static float _vq_quantthresh__8u1__p7_0[] = {
  131103. -5.5, 5.5,
  131104. };
  131105. static long _vq_quantmap__8u1__p7_0[] = {
  131106. 1, 0, 2,
  131107. };
  131108. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131109. _vq_quantthresh__8u1__p7_0,
  131110. _vq_quantmap__8u1__p7_0,
  131111. 3,
  131112. 3
  131113. };
  131114. static static_codebook _8u1__p7_0 = {
  131115. 4, 81,
  131116. _vq_lengthlist__8u1__p7_0,
  131117. 1, -529137664, 1618345984, 2, 0,
  131118. _vq_quantlist__8u1__p7_0,
  131119. NULL,
  131120. &_vq_auxt__8u1__p7_0,
  131121. NULL,
  131122. 0
  131123. };
  131124. static long _vq_quantlist__8u1__p7_1[] = {
  131125. 5,
  131126. 4,
  131127. 6,
  131128. 3,
  131129. 7,
  131130. 2,
  131131. 8,
  131132. 1,
  131133. 9,
  131134. 0,
  131135. 10,
  131136. };
  131137. static long _vq_lengthlist__8u1__p7_1[] = {
  131138. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131139. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131140. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131141. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131142. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131143. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131144. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131145. 9, 9, 9, 9, 9,10,10,10,10,
  131146. };
  131147. static float _vq_quantthresh__8u1__p7_1[] = {
  131148. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131149. 3.5, 4.5,
  131150. };
  131151. static long _vq_quantmap__8u1__p7_1[] = {
  131152. 9, 7, 5, 3, 1, 0, 2, 4,
  131153. 6, 8, 10,
  131154. };
  131155. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131156. _vq_quantthresh__8u1__p7_1,
  131157. _vq_quantmap__8u1__p7_1,
  131158. 11,
  131159. 11
  131160. };
  131161. static static_codebook _8u1__p7_1 = {
  131162. 2, 121,
  131163. _vq_lengthlist__8u1__p7_1,
  131164. 1, -531365888, 1611661312, 4, 0,
  131165. _vq_quantlist__8u1__p7_1,
  131166. NULL,
  131167. &_vq_auxt__8u1__p7_1,
  131168. NULL,
  131169. 0
  131170. };
  131171. static long _vq_quantlist__8u1__p8_0[] = {
  131172. 5,
  131173. 4,
  131174. 6,
  131175. 3,
  131176. 7,
  131177. 2,
  131178. 8,
  131179. 1,
  131180. 9,
  131181. 0,
  131182. 10,
  131183. };
  131184. static long _vq_lengthlist__8u1__p8_0[] = {
  131185. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131186. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131187. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131188. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131189. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131190. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131191. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131192. 12,13,13,14,14,15,15,15,15,
  131193. };
  131194. static float _vq_quantthresh__8u1__p8_0[] = {
  131195. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131196. 38.5, 49.5,
  131197. };
  131198. static long _vq_quantmap__8u1__p8_0[] = {
  131199. 9, 7, 5, 3, 1, 0, 2, 4,
  131200. 6, 8, 10,
  131201. };
  131202. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131203. _vq_quantthresh__8u1__p8_0,
  131204. _vq_quantmap__8u1__p8_0,
  131205. 11,
  131206. 11
  131207. };
  131208. static static_codebook _8u1__p8_0 = {
  131209. 2, 121,
  131210. _vq_lengthlist__8u1__p8_0,
  131211. 1, -524582912, 1618345984, 4, 0,
  131212. _vq_quantlist__8u1__p8_0,
  131213. NULL,
  131214. &_vq_auxt__8u1__p8_0,
  131215. NULL,
  131216. 0
  131217. };
  131218. static long _vq_quantlist__8u1__p8_1[] = {
  131219. 5,
  131220. 4,
  131221. 6,
  131222. 3,
  131223. 7,
  131224. 2,
  131225. 8,
  131226. 1,
  131227. 9,
  131228. 0,
  131229. 10,
  131230. };
  131231. static long _vq_lengthlist__8u1__p8_1[] = {
  131232. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131233. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131234. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131235. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131236. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131237. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131238. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131239. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131240. };
  131241. static float _vq_quantthresh__8u1__p8_1[] = {
  131242. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131243. 3.5, 4.5,
  131244. };
  131245. static long _vq_quantmap__8u1__p8_1[] = {
  131246. 9, 7, 5, 3, 1, 0, 2, 4,
  131247. 6, 8, 10,
  131248. };
  131249. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131250. _vq_quantthresh__8u1__p8_1,
  131251. _vq_quantmap__8u1__p8_1,
  131252. 11,
  131253. 11
  131254. };
  131255. static static_codebook _8u1__p8_1 = {
  131256. 2, 121,
  131257. _vq_lengthlist__8u1__p8_1,
  131258. 1, -531365888, 1611661312, 4, 0,
  131259. _vq_quantlist__8u1__p8_1,
  131260. NULL,
  131261. &_vq_auxt__8u1__p8_1,
  131262. NULL,
  131263. 0
  131264. };
  131265. static long _vq_quantlist__8u1__p9_0[] = {
  131266. 7,
  131267. 6,
  131268. 8,
  131269. 5,
  131270. 9,
  131271. 4,
  131272. 10,
  131273. 3,
  131274. 11,
  131275. 2,
  131276. 12,
  131277. 1,
  131278. 13,
  131279. 0,
  131280. 14,
  131281. };
  131282. static long _vq_lengthlist__8u1__p9_0[] = {
  131283. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131284. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131285. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131286. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131287. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131288. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131289. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131290. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131291. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131292. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131293. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131294. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131295. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131296. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131297. 10,
  131298. };
  131299. static float _vq_quantthresh__8u1__p9_0[] = {
  131300. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131301. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131302. };
  131303. static long _vq_quantmap__8u1__p9_0[] = {
  131304. 13, 11, 9, 7, 5, 3, 1, 0,
  131305. 2, 4, 6, 8, 10, 12, 14,
  131306. };
  131307. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131308. _vq_quantthresh__8u1__p9_0,
  131309. _vq_quantmap__8u1__p9_0,
  131310. 15,
  131311. 15
  131312. };
  131313. static static_codebook _8u1__p9_0 = {
  131314. 2, 225,
  131315. _vq_lengthlist__8u1__p9_0,
  131316. 1, -514071552, 1627381760, 4, 0,
  131317. _vq_quantlist__8u1__p9_0,
  131318. NULL,
  131319. &_vq_auxt__8u1__p9_0,
  131320. NULL,
  131321. 0
  131322. };
  131323. static long _vq_quantlist__8u1__p9_1[] = {
  131324. 7,
  131325. 6,
  131326. 8,
  131327. 5,
  131328. 9,
  131329. 4,
  131330. 10,
  131331. 3,
  131332. 11,
  131333. 2,
  131334. 12,
  131335. 1,
  131336. 13,
  131337. 0,
  131338. 14,
  131339. };
  131340. static long _vq_lengthlist__8u1__p9_1[] = {
  131341. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131342. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131343. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131344. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131345. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131346. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131347. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131348. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131349. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131350. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131351. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131352. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131353. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131354. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131355. 13,
  131356. };
  131357. static float _vq_quantthresh__8u1__p9_1[] = {
  131358. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131359. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131360. };
  131361. static long _vq_quantmap__8u1__p9_1[] = {
  131362. 13, 11, 9, 7, 5, 3, 1, 0,
  131363. 2, 4, 6, 8, 10, 12, 14,
  131364. };
  131365. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131366. _vq_quantthresh__8u1__p9_1,
  131367. _vq_quantmap__8u1__p9_1,
  131368. 15,
  131369. 15
  131370. };
  131371. static static_codebook _8u1__p9_1 = {
  131372. 2, 225,
  131373. _vq_lengthlist__8u1__p9_1,
  131374. 1, -522338304, 1620115456, 4, 0,
  131375. _vq_quantlist__8u1__p9_1,
  131376. NULL,
  131377. &_vq_auxt__8u1__p9_1,
  131378. NULL,
  131379. 0
  131380. };
  131381. static long _vq_quantlist__8u1__p9_2[] = {
  131382. 8,
  131383. 7,
  131384. 9,
  131385. 6,
  131386. 10,
  131387. 5,
  131388. 11,
  131389. 4,
  131390. 12,
  131391. 3,
  131392. 13,
  131393. 2,
  131394. 14,
  131395. 1,
  131396. 15,
  131397. 0,
  131398. 16,
  131399. };
  131400. static long _vq_lengthlist__8u1__p9_2[] = {
  131401. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131402. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131403. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131404. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131405. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131406. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131407. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131408. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131409. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131410. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131411. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131412. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131413. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131414. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131415. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131416. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131417. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131418. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131419. 10,
  131420. };
  131421. static float _vq_quantthresh__8u1__p9_2[] = {
  131422. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131423. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131424. };
  131425. static long _vq_quantmap__8u1__p9_2[] = {
  131426. 15, 13, 11, 9, 7, 5, 3, 1,
  131427. 0, 2, 4, 6, 8, 10, 12, 14,
  131428. 16,
  131429. };
  131430. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131431. _vq_quantthresh__8u1__p9_2,
  131432. _vq_quantmap__8u1__p9_2,
  131433. 17,
  131434. 17
  131435. };
  131436. static static_codebook _8u1__p9_2 = {
  131437. 2, 289,
  131438. _vq_lengthlist__8u1__p9_2,
  131439. 1, -529530880, 1611661312, 5, 0,
  131440. _vq_quantlist__8u1__p9_2,
  131441. NULL,
  131442. &_vq_auxt__8u1__p9_2,
  131443. NULL,
  131444. 0
  131445. };
  131446. static long _huff_lengthlist__8u1__single[] = {
  131447. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131448. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131449. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131450. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131451. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131452. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131453. 13, 8, 8,15,
  131454. };
  131455. static static_codebook _huff_book__8u1__single = {
  131456. 2, 100,
  131457. _huff_lengthlist__8u1__single,
  131458. 0, 0, 0, 0, 0,
  131459. NULL,
  131460. NULL,
  131461. NULL,
  131462. NULL,
  131463. 0
  131464. };
  131465. static long _huff_lengthlist__44u0__long[] = {
  131466. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131467. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131468. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131469. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131470. };
  131471. static static_codebook _huff_book__44u0__long = {
  131472. 2, 64,
  131473. _huff_lengthlist__44u0__long,
  131474. 0, 0, 0, 0, 0,
  131475. NULL,
  131476. NULL,
  131477. NULL,
  131478. NULL,
  131479. 0
  131480. };
  131481. static long _vq_quantlist__44u0__p1_0[] = {
  131482. 1,
  131483. 0,
  131484. 2,
  131485. };
  131486. static long _vq_lengthlist__44u0__p1_0[] = {
  131487. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131488. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131489. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131490. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131491. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131492. 13,
  131493. };
  131494. static float _vq_quantthresh__44u0__p1_0[] = {
  131495. -0.5, 0.5,
  131496. };
  131497. static long _vq_quantmap__44u0__p1_0[] = {
  131498. 1, 0, 2,
  131499. };
  131500. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131501. _vq_quantthresh__44u0__p1_0,
  131502. _vq_quantmap__44u0__p1_0,
  131503. 3,
  131504. 3
  131505. };
  131506. static static_codebook _44u0__p1_0 = {
  131507. 4, 81,
  131508. _vq_lengthlist__44u0__p1_0,
  131509. 1, -535822336, 1611661312, 2, 0,
  131510. _vq_quantlist__44u0__p1_0,
  131511. NULL,
  131512. &_vq_auxt__44u0__p1_0,
  131513. NULL,
  131514. 0
  131515. };
  131516. static long _vq_quantlist__44u0__p2_0[] = {
  131517. 1,
  131518. 0,
  131519. 2,
  131520. };
  131521. static long _vq_lengthlist__44u0__p2_0[] = {
  131522. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  131523. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  131524. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  131525. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  131526. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  131527. 9,
  131528. };
  131529. static float _vq_quantthresh__44u0__p2_0[] = {
  131530. -0.5, 0.5,
  131531. };
  131532. static long _vq_quantmap__44u0__p2_0[] = {
  131533. 1, 0, 2,
  131534. };
  131535. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  131536. _vq_quantthresh__44u0__p2_0,
  131537. _vq_quantmap__44u0__p2_0,
  131538. 3,
  131539. 3
  131540. };
  131541. static static_codebook _44u0__p2_0 = {
  131542. 4, 81,
  131543. _vq_lengthlist__44u0__p2_0,
  131544. 1, -535822336, 1611661312, 2, 0,
  131545. _vq_quantlist__44u0__p2_0,
  131546. NULL,
  131547. &_vq_auxt__44u0__p2_0,
  131548. NULL,
  131549. 0
  131550. };
  131551. static long _vq_quantlist__44u0__p3_0[] = {
  131552. 2,
  131553. 1,
  131554. 3,
  131555. 0,
  131556. 4,
  131557. };
  131558. static long _vq_lengthlist__44u0__p3_0[] = {
  131559. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  131560. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  131561. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  131562. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  131563. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  131564. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  131565. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  131566. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  131567. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  131568. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  131569. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  131570. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  131571. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  131572. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  131573. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  131574. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  131575. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  131576. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  131577. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  131578. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  131579. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  131580. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  131581. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  131582. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  131583. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  131584. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  131585. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  131586. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  131587. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  131588. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  131589. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  131590. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  131591. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  131592. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  131593. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  131594. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  131595. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  131596. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  131597. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  131598. 19,
  131599. };
  131600. static float _vq_quantthresh__44u0__p3_0[] = {
  131601. -1.5, -0.5, 0.5, 1.5,
  131602. };
  131603. static long _vq_quantmap__44u0__p3_0[] = {
  131604. 3, 1, 0, 2, 4,
  131605. };
  131606. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  131607. _vq_quantthresh__44u0__p3_0,
  131608. _vq_quantmap__44u0__p3_0,
  131609. 5,
  131610. 5
  131611. };
  131612. static static_codebook _44u0__p3_0 = {
  131613. 4, 625,
  131614. _vq_lengthlist__44u0__p3_0,
  131615. 1, -533725184, 1611661312, 3, 0,
  131616. _vq_quantlist__44u0__p3_0,
  131617. NULL,
  131618. &_vq_auxt__44u0__p3_0,
  131619. NULL,
  131620. 0
  131621. };
  131622. static long _vq_quantlist__44u0__p4_0[] = {
  131623. 2,
  131624. 1,
  131625. 3,
  131626. 0,
  131627. 4,
  131628. };
  131629. static long _vq_lengthlist__44u0__p4_0[] = {
  131630. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  131631. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  131632. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  131633. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  131634. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  131635. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  131636. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  131637. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  131638. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  131639. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  131640. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  131641. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  131642. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  131643. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  131644. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  131645. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  131646. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  131647. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  131648. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  131649. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  131650. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  131651. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  131652. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  131653. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  131654. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  131655. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  131656. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  131657. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  131658. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  131659. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  131660. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  131661. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  131662. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  131663. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  131664. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  131665. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  131666. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  131667. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  131668. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  131669. 12,
  131670. };
  131671. static float _vq_quantthresh__44u0__p4_0[] = {
  131672. -1.5, -0.5, 0.5, 1.5,
  131673. };
  131674. static long _vq_quantmap__44u0__p4_0[] = {
  131675. 3, 1, 0, 2, 4,
  131676. };
  131677. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  131678. _vq_quantthresh__44u0__p4_0,
  131679. _vq_quantmap__44u0__p4_0,
  131680. 5,
  131681. 5
  131682. };
  131683. static static_codebook _44u0__p4_0 = {
  131684. 4, 625,
  131685. _vq_lengthlist__44u0__p4_0,
  131686. 1, -533725184, 1611661312, 3, 0,
  131687. _vq_quantlist__44u0__p4_0,
  131688. NULL,
  131689. &_vq_auxt__44u0__p4_0,
  131690. NULL,
  131691. 0
  131692. };
  131693. static long _vq_quantlist__44u0__p5_0[] = {
  131694. 4,
  131695. 3,
  131696. 5,
  131697. 2,
  131698. 6,
  131699. 1,
  131700. 7,
  131701. 0,
  131702. 8,
  131703. };
  131704. static long _vq_lengthlist__44u0__p5_0[] = {
  131705. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  131706. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  131707. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  131708. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  131709. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  131710. 12,
  131711. };
  131712. static float _vq_quantthresh__44u0__p5_0[] = {
  131713. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131714. };
  131715. static long _vq_quantmap__44u0__p5_0[] = {
  131716. 7, 5, 3, 1, 0, 2, 4, 6,
  131717. 8,
  131718. };
  131719. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  131720. _vq_quantthresh__44u0__p5_0,
  131721. _vq_quantmap__44u0__p5_0,
  131722. 9,
  131723. 9
  131724. };
  131725. static static_codebook _44u0__p5_0 = {
  131726. 2, 81,
  131727. _vq_lengthlist__44u0__p5_0,
  131728. 1, -531628032, 1611661312, 4, 0,
  131729. _vq_quantlist__44u0__p5_0,
  131730. NULL,
  131731. &_vq_auxt__44u0__p5_0,
  131732. NULL,
  131733. 0
  131734. };
  131735. static long _vq_quantlist__44u0__p6_0[] = {
  131736. 6,
  131737. 5,
  131738. 7,
  131739. 4,
  131740. 8,
  131741. 3,
  131742. 9,
  131743. 2,
  131744. 10,
  131745. 1,
  131746. 11,
  131747. 0,
  131748. 12,
  131749. };
  131750. static long _vq_lengthlist__44u0__p6_0[] = {
  131751. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  131752. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  131753. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  131754. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  131755. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  131756. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  131757. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  131758. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  131759. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  131760. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  131761. 15,17,16,17,18,17,17,18, 0,
  131762. };
  131763. static float _vq_quantthresh__44u0__p6_0[] = {
  131764. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131765. 12.5, 17.5, 22.5, 27.5,
  131766. };
  131767. static long _vq_quantmap__44u0__p6_0[] = {
  131768. 11, 9, 7, 5, 3, 1, 0, 2,
  131769. 4, 6, 8, 10, 12,
  131770. };
  131771. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  131772. _vq_quantthresh__44u0__p6_0,
  131773. _vq_quantmap__44u0__p6_0,
  131774. 13,
  131775. 13
  131776. };
  131777. static static_codebook _44u0__p6_0 = {
  131778. 2, 169,
  131779. _vq_lengthlist__44u0__p6_0,
  131780. 1, -526516224, 1616117760, 4, 0,
  131781. _vq_quantlist__44u0__p6_0,
  131782. NULL,
  131783. &_vq_auxt__44u0__p6_0,
  131784. NULL,
  131785. 0
  131786. };
  131787. static long _vq_quantlist__44u0__p6_1[] = {
  131788. 2,
  131789. 1,
  131790. 3,
  131791. 0,
  131792. 4,
  131793. };
  131794. static long _vq_lengthlist__44u0__p6_1[] = {
  131795. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  131796. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  131797. };
  131798. static float _vq_quantthresh__44u0__p6_1[] = {
  131799. -1.5, -0.5, 0.5, 1.5,
  131800. };
  131801. static long _vq_quantmap__44u0__p6_1[] = {
  131802. 3, 1, 0, 2, 4,
  131803. };
  131804. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  131805. _vq_quantthresh__44u0__p6_1,
  131806. _vq_quantmap__44u0__p6_1,
  131807. 5,
  131808. 5
  131809. };
  131810. static static_codebook _44u0__p6_1 = {
  131811. 2, 25,
  131812. _vq_lengthlist__44u0__p6_1,
  131813. 1, -533725184, 1611661312, 3, 0,
  131814. _vq_quantlist__44u0__p6_1,
  131815. NULL,
  131816. &_vq_auxt__44u0__p6_1,
  131817. NULL,
  131818. 0
  131819. };
  131820. static long _vq_quantlist__44u0__p7_0[] = {
  131821. 2,
  131822. 1,
  131823. 3,
  131824. 0,
  131825. 4,
  131826. };
  131827. static long _vq_lengthlist__44u0__p7_0[] = {
  131828. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  131829. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131830. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131831. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131832. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131833. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131834. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131835. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  131836. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131837. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131838. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131839. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131840. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131841. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131842. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131843. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131844. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131845. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131846. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131847. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131848. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131849. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131850. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131851. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131852. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131853. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131854. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131855. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131856. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131857. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131858. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  131859. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131860. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131861. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131862. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131863. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131864. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131865. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131866. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131867. 10,
  131868. };
  131869. static float _vq_quantthresh__44u0__p7_0[] = {
  131870. -253.5, -84.5, 84.5, 253.5,
  131871. };
  131872. static long _vq_quantmap__44u0__p7_0[] = {
  131873. 3, 1, 0, 2, 4,
  131874. };
  131875. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  131876. _vq_quantthresh__44u0__p7_0,
  131877. _vq_quantmap__44u0__p7_0,
  131878. 5,
  131879. 5
  131880. };
  131881. static static_codebook _44u0__p7_0 = {
  131882. 4, 625,
  131883. _vq_lengthlist__44u0__p7_0,
  131884. 1, -518709248, 1626677248, 3, 0,
  131885. _vq_quantlist__44u0__p7_0,
  131886. NULL,
  131887. &_vq_auxt__44u0__p7_0,
  131888. NULL,
  131889. 0
  131890. };
  131891. static long _vq_quantlist__44u0__p7_1[] = {
  131892. 6,
  131893. 5,
  131894. 7,
  131895. 4,
  131896. 8,
  131897. 3,
  131898. 9,
  131899. 2,
  131900. 10,
  131901. 1,
  131902. 11,
  131903. 0,
  131904. 12,
  131905. };
  131906. static long _vq_lengthlist__44u0__p7_1[] = {
  131907. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  131908. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  131909. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  131910. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  131911. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  131912. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  131913. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  131914. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  131915. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  131916. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  131917. 15,15,15,15,15,15,15,15,15,
  131918. };
  131919. static float _vq_quantthresh__44u0__p7_1[] = {
  131920. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  131921. 32.5, 45.5, 58.5, 71.5,
  131922. };
  131923. static long _vq_quantmap__44u0__p7_1[] = {
  131924. 11, 9, 7, 5, 3, 1, 0, 2,
  131925. 4, 6, 8, 10, 12,
  131926. };
  131927. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  131928. _vq_quantthresh__44u0__p7_1,
  131929. _vq_quantmap__44u0__p7_1,
  131930. 13,
  131931. 13
  131932. };
  131933. static static_codebook _44u0__p7_1 = {
  131934. 2, 169,
  131935. _vq_lengthlist__44u0__p7_1,
  131936. 1, -523010048, 1618608128, 4, 0,
  131937. _vq_quantlist__44u0__p7_1,
  131938. NULL,
  131939. &_vq_auxt__44u0__p7_1,
  131940. NULL,
  131941. 0
  131942. };
  131943. static long _vq_quantlist__44u0__p7_2[] = {
  131944. 6,
  131945. 5,
  131946. 7,
  131947. 4,
  131948. 8,
  131949. 3,
  131950. 9,
  131951. 2,
  131952. 10,
  131953. 1,
  131954. 11,
  131955. 0,
  131956. 12,
  131957. };
  131958. static long _vq_lengthlist__44u0__p7_2[] = {
  131959. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  131960. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  131961. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  131962. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  131963. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  131964. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  131965. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  131966. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  131967. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  131968. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  131969. 9, 9, 9,10, 9, 9,10,10, 9,
  131970. };
  131971. static float _vq_quantthresh__44u0__p7_2[] = {
  131972. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  131973. 2.5, 3.5, 4.5, 5.5,
  131974. };
  131975. static long _vq_quantmap__44u0__p7_2[] = {
  131976. 11, 9, 7, 5, 3, 1, 0, 2,
  131977. 4, 6, 8, 10, 12,
  131978. };
  131979. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  131980. _vq_quantthresh__44u0__p7_2,
  131981. _vq_quantmap__44u0__p7_2,
  131982. 13,
  131983. 13
  131984. };
  131985. static static_codebook _44u0__p7_2 = {
  131986. 2, 169,
  131987. _vq_lengthlist__44u0__p7_2,
  131988. 1, -531103744, 1611661312, 4, 0,
  131989. _vq_quantlist__44u0__p7_2,
  131990. NULL,
  131991. &_vq_auxt__44u0__p7_2,
  131992. NULL,
  131993. 0
  131994. };
  131995. static long _huff_lengthlist__44u0__short[] = {
  131996. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  131997. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  131998. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  131999. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132000. };
  132001. static static_codebook _huff_book__44u0__short = {
  132002. 2, 64,
  132003. _huff_lengthlist__44u0__short,
  132004. 0, 0, 0, 0, 0,
  132005. NULL,
  132006. NULL,
  132007. NULL,
  132008. NULL,
  132009. 0
  132010. };
  132011. static long _huff_lengthlist__44u1__long[] = {
  132012. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132013. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132014. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132015. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132016. };
  132017. static static_codebook _huff_book__44u1__long = {
  132018. 2, 64,
  132019. _huff_lengthlist__44u1__long,
  132020. 0, 0, 0, 0, 0,
  132021. NULL,
  132022. NULL,
  132023. NULL,
  132024. NULL,
  132025. 0
  132026. };
  132027. static long _vq_quantlist__44u1__p1_0[] = {
  132028. 1,
  132029. 0,
  132030. 2,
  132031. };
  132032. static long _vq_lengthlist__44u1__p1_0[] = {
  132033. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132034. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132035. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132036. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132037. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132038. 13,
  132039. };
  132040. static float _vq_quantthresh__44u1__p1_0[] = {
  132041. -0.5, 0.5,
  132042. };
  132043. static long _vq_quantmap__44u1__p1_0[] = {
  132044. 1, 0, 2,
  132045. };
  132046. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132047. _vq_quantthresh__44u1__p1_0,
  132048. _vq_quantmap__44u1__p1_0,
  132049. 3,
  132050. 3
  132051. };
  132052. static static_codebook _44u1__p1_0 = {
  132053. 4, 81,
  132054. _vq_lengthlist__44u1__p1_0,
  132055. 1, -535822336, 1611661312, 2, 0,
  132056. _vq_quantlist__44u1__p1_0,
  132057. NULL,
  132058. &_vq_auxt__44u1__p1_0,
  132059. NULL,
  132060. 0
  132061. };
  132062. static long _vq_quantlist__44u1__p2_0[] = {
  132063. 1,
  132064. 0,
  132065. 2,
  132066. };
  132067. static long _vq_lengthlist__44u1__p2_0[] = {
  132068. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132069. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132070. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132071. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132072. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132073. 9,
  132074. };
  132075. static float _vq_quantthresh__44u1__p2_0[] = {
  132076. -0.5, 0.5,
  132077. };
  132078. static long _vq_quantmap__44u1__p2_0[] = {
  132079. 1, 0, 2,
  132080. };
  132081. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132082. _vq_quantthresh__44u1__p2_0,
  132083. _vq_quantmap__44u1__p2_0,
  132084. 3,
  132085. 3
  132086. };
  132087. static static_codebook _44u1__p2_0 = {
  132088. 4, 81,
  132089. _vq_lengthlist__44u1__p2_0,
  132090. 1, -535822336, 1611661312, 2, 0,
  132091. _vq_quantlist__44u1__p2_0,
  132092. NULL,
  132093. &_vq_auxt__44u1__p2_0,
  132094. NULL,
  132095. 0
  132096. };
  132097. static long _vq_quantlist__44u1__p3_0[] = {
  132098. 2,
  132099. 1,
  132100. 3,
  132101. 0,
  132102. 4,
  132103. };
  132104. static long _vq_lengthlist__44u1__p3_0[] = {
  132105. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132106. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132107. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132108. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132109. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132110. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132111. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132112. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132113. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132114. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132115. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132116. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132117. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132118. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132119. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132120. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132121. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132122. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132123. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132124. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132125. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132126. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132127. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132128. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132129. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132130. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132131. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132132. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132133. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132134. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132135. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132136. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132137. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132138. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132139. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132140. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132141. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132142. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132143. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132144. 19,
  132145. };
  132146. static float _vq_quantthresh__44u1__p3_0[] = {
  132147. -1.5, -0.5, 0.5, 1.5,
  132148. };
  132149. static long _vq_quantmap__44u1__p3_0[] = {
  132150. 3, 1, 0, 2, 4,
  132151. };
  132152. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132153. _vq_quantthresh__44u1__p3_0,
  132154. _vq_quantmap__44u1__p3_0,
  132155. 5,
  132156. 5
  132157. };
  132158. static static_codebook _44u1__p3_0 = {
  132159. 4, 625,
  132160. _vq_lengthlist__44u1__p3_0,
  132161. 1, -533725184, 1611661312, 3, 0,
  132162. _vq_quantlist__44u1__p3_0,
  132163. NULL,
  132164. &_vq_auxt__44u1__p3_0,
  132165. NULL,
  132166. 0
  132167. };
  132168. static long _vq_quantlist__44u1__p4_0[] = {
  132169. 2,
  132170. 1,
  132171. 3,
  132172. 0,
  132173. 4,
  132174. };
  132175. static long _vq_lengthlist__44u1__p4_0[] = {
  132176. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132177. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132178. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132179. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132180. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132181. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132182. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132183. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132184. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132185. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132186. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132187. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132188. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132189. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132190. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132191. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132192. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132193. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132194. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132195. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132196. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132197. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132198. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132199. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132200. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132201. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132202. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132203. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132204. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132205. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132206. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132207. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132208. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132209. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132210. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132211. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132212. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132213. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132214. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132215. 12,
  132216. };
  132217. static float _vq_quantthresh__44u1__p4_0[] = {
  132218. -1.5, -0.5, 0.5, 1.5,
  132219. };
  132220. static long _vq_quantmap__44u1__p4_0[] = {
  132221. 3, 1, 0, 2, 4,
  132222. };
  132223. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132224. _vq_quantthresh__44u1__p4_0,
  132225. _vq_quantmap__44u1__p4_0,
  132226. 5,
  132227. 5
  132228. };
  132229. static static_codebook _44u1__p4_0 = {
  132230. 4, 625,
  132231. _vq_lengthlist__44u1__p4_0,
  132232. 1, -533725184, 1611661312, 3, 0,
  132233. _vq_quantlist__44u1__p4_0,
  132234. NULL,
  132235. &_vq_auxt__44u1__p4_0,
  132236. NULL,
  132237. 0
  132238. };
  132239. static long _vq_quantlist__44u1__p5_0[] = {
  132240. 4,
  132241. 3,
  132242. 5,
  132243. 2,
  132244. 6,
  132245. 1,
  132246. 7,
  132247. 0,
  132248. 8,
  132249. };
  132250. static long _vq_lengthlist__44u1__p5_0[] = {
  132251. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132252. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132253. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132254. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132255. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132256. 12,
  132257. };
  132258. static float _vq_quantthresh__44u1__p5_0[] = {
  132259. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132260. };
  132261. static long _vq_quantmap__44u1__p5_0[] = {
  132262. 7, 5, 3, 1, 0, 2, 4, 6,
  132263. 8,
  132264. };
  132265. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132266. _vq_quantthresh__44u1__p5_0,
  132267. _vq_quantmap__44u1__p5_0,
  132268. 9,
  132269. 9
  132270. };
  132271. static static_codebook _44u1__p5_0 = {
  132272. 2, 81,
  132273. _vq_lengthlist__44u1__p5_0,
  132274. 1, -531628032, 1611661312, 4, 0,
  132275. _vq_quantlist__44u1__p5_0,
  132276. NULL,
  132277. &_vq_auxt__44u1__p5_0,
  132278. NULL,
  132279. 0
  132280. };
  132281. static long _vq_quantlist__44u1__p6_0[] = {
  132282. 6,
  132283. 5,
  132284. 7,
  132285. 4,
  132286. 8,
  132287. 3,
  132288. 9,
  132289. 2,
  132290. 10,
  132291. 1,
  132292. 11,
  132293. 0,
  132294. 12,
  132295. };
  132296. static long _vq_lengthlist__44u1__p6_0[] = {
  132297. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132298. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132299. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132300. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132301. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132302. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132303. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132304. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132305. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132306. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132307. 15,17,16,17,18,17,17,18, 0,
  132308. };
  132309. static float _vq_quantthresh__44u1__p6_0[] = {
  132310. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132311. 12.5, 17.5, 22.5, 27.5,
  132312. };
  132313. static long _vq_quantmap__44u1__p6_0[] = {
  132314. 11, 9, 7, 5, 3, 1, 0, 2,
  132315. 4, 6, 8, 10, 12,
  132316. };
  132317. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132318. _vq_quantthresh__44u1__p6_0,
  132319. _vq_quantmap__44u1__p6_0,
  132320. 13,
  132321. 13
  132322. };
  132323. static static_codebook _44u1__p6_0 = {
  132324. 2, 169,
  132325. _vq_lengthlist__44u1__p6_0,
  132326. 1, -526516224, 1616117760, 4, 0,
  132327. _vq_quantlist__44u1__p6_0,
  132328. NULL,
  132329. &_vq_auxt__44u1__p6_0,
  132330. NULL,
  132331. 0
  132332. };
  132333. static long _vq_quantlist__44u1__p6_1[] = {
  132334. 2,
  132335. 1,
  132336. 3,
  132337. 0,
  132338. 4,
  132339. };
  132340. static long _vq_lengthlist__44u1__p6_1[] = {
  132341. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132342. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132343. };
  132344. static float _vq_quantthresh__44u1__p6_1[] = {
  132345. -1.5, -0.5, 0.5, 1.5,
  132346. };
  132347. static long _vq_quantmap__44u1__p6_1[] = {
  132348. 3, 1, 0, 2, 4,
  132349. };
  132350. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132351. _vq_quantthresh__44u1__p6_1,
  132352. _vq_quantmap__44u1__p6_1,
  132353. 5,
  132354. 5
  132355. };
  132356. static static_codebook _44u1__p6_1 = {
  132357. 2, 25,
  132358. _vq_lengthlist__44u1__p6_1,
  132359. 1, -533725184, 1611661312, 3, 0,
  132360. _vq_quantlist__44u1__p6_1,
  132361. NULL,
  132362. &_vq_auxt__44u1__p6_1,
  132363. NULL,
  132364. 0
  132365. };
  132366. static long _vq_quantlist__44u1__p7_0[] = {
  132367. 3,
  132368. 2,
  132369. 4,
  132370. 1,
  132371. 5,
  132372. 0,
  132373. 6,
  132374. };
  132375. static long _vq_lengthlist__44u1__p7_0[] = {
  132376. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132377. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132378. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132379. 8,
  132380. };
  132381. static float _vq_quantthresh__44u1__p7_0[] = {
  132382. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132383. };
  132384. static long _vq_quantmap__44u1__p7_0[] = {
  132385. 5, 3, 1, 0, 2, 4, 6,
  132386. };
  132387. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132388. _vq_quantthresh__44u1__p7_0,
  132389. _vq_quantmap__44u1__p7_0,
  132390. 7,
  132391. 7
  132392. };
  132393. static static_codebook _44u1__p7_0 = {
  132394. 2, 49,
  132395. _vq_lengthlist__44u1__p7_0,
  132396. 1, -518017024, 1626677248, 3, 0,
  132397. _vq_quantlist__44u1__p7_0,
  132398. NULL,
  132399. &_vq_auxt__44u1__p7_0,
  132400. NULL,
  132401. 0
  132402. };
  132403. static long _vq_quantlist__44u1__p7_1[] = {
  132404. 6,
  132405. 5,
  132406. 7,
  132407. 4,
  132408. 8,
  132409. 3,
  132410. 9,
  132411. 2,
  132412. 10,
  132413. 1,
  132414. 11,
  132415. 0,
  132416. 12,
  132417. };
  132418. static long _vq_lengthlist__44u1__p7_1[] = {
  132419. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132420. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132421. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132422. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132423. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132424. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132425. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132426. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132427. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132428. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132429. 15,15,15,15,15,15,15,15,15,
  132430. };
  132431. static float _vq_quantthresh__44u1__p7_1[] = {
  132432. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132433. 32.5, 45.5, 58.5, 71.5,
  132434. };
  132435. static long _vq_quantmap__44u1__p7_1[] = {
  132436. 11, 9, 7, 5, 3, 1, 0, 2,
  132437. 4, 6, 8, 10, 12,
  132438. };
  132439. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132440. _vq_quantthresh__44u1__p7_1,
  132441. _vq_quantmap__44u1__p7_1,
  132442. 13,
  132443. 13
  132444. };
  132445. static static_codebook _44u1__p7_1 = {
  132446. 2, 169,
  132447. _vq_lengthlist__44u1__p7_1,
  132448. 1, -523010048, 1618608128, 4, 0,
  132449. _vq_quantlist__44u1__p7_1,
  132450. NULL,
  132451. &_vq_auxt__44u1__p7_1,
  132452. NULL,
  132453. 0
  132454. };
  132455. static long _vq_quantlist__44u1__p7_2[] = {
  132456. 6,
  132457. 5,
  132458. 7,
  132459. 4,
  132460. 8,
  132461. 3,
  132462. 9,
  132463. 2,
  132464. 10,
  132465. 1,
  132466. 11,
  132467. 0,
  132468. 12,
  132469. };
  132470. static long _vq_lengthlist__44u1__p7_2[] = {
  132471. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132472. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132473. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132474. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132475. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132476. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132477. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132478. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132479. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132480. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132481. 9, 9, 9,10, 9, 9,10,10, 9,
  132482. };
  132483. static float _vq_quantthresh__44u1__p7_2[] = {
  132484. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132485. 2.5, 3.5, 4.5, 5.5,
  132486. };
  132487. static long _vq_quantmap__44u1__p7_2[] = {
  132488. 11, 9, 7, 5, 3, 1, 0, 2,
  132489. 4, 6, 8, 10, 12,
  132490. };
  132491. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132492. _vq_quantthresh__44u1__p7_2,
  132493. _vq_quantmap__44u1__p7_2,
  132494. 13,
  132495. 13
  132496. };
  132497. static static_codebook _44u1__p7_2 = {
  132498. 2, 169,
  132499. _vq_lengthlist__44u1__p7_2,
  132500. 1, -531103744, 1611661312, 4, 0,
  132501. _vq_quantlist__44u1__p7_2,
  132502. NULL,
  132503. &_vq_auxt__44u1__p7_2,
  132504. NULL,
  132505. 0
  132506. };
  132507. static long _huff_lengthlist__44u1__short[] = {
  132508. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132509. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132510. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132511. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132512. };
  132513. static static_codebook _huff_book__44u1__short = {
  132514. 2, 64,
  132515. _huff_lengthlist__44u1__short,
  132516. 0, 0, 0, 0, 0,
  132517. NULL,
  132518. NULL,
  132519. NULL,
  132520. NULL,
  132521. 0
  132522. };
  132523. static long _huff_lengthlist__44u2__long[] = {
  132524. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  132525. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  132526. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  132527. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  132528. };
  132529. static static_codebook _huff_book__44u2__long = {
  132530. 2, 64,
  132531. _huff_lengthlist__44u2__long,
  132532. 0, 0, 0, 0, 0,
  132533. NULL,
  132534. NULL,
  132535. NULL,
  132536. NULL,
  132537. 0
  132538. };
  132539. static long _vq_quantlist__44u2__p1_0[] = {
  132540. 1,
  132541. 0,
  132542. 2,
  132543. };
  132544. static long _vq_lengthlist__44u2__p1_0[] = {
  132545. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132546. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132547. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  132548. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  132549. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  132550. 13,
  132551. };
  132552. static float _vq_quantthresh__44u2__p1_0[] = {
  132553. -0.5, 0.5,
  132554. };
  132555. static long _vq_quantmap__44u2__p1_0[] = {
  132556. 1, 0, 2,
  132557. };
  132558. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  132559. _vq_quantthresh__44u2__p1_0,
  132560. _vq_quantmap__44u2__p1_0,
  132561. 3,
  132562. 3
  132563. };
  132564. static static_codebook _44u2__p1_0 = {
  132565. 4, 81,
  132566. _vq_lengthlist__44u2__p1_0,
  132567. 1, -535822336, 1611661312, 2, 0,
  132568. _vq_quantlist__44u2__p1_0,
  132569. NULL,
  132570. &_vq_auxt__44u2__p1_0,
  132571. NULL,
  132572. 0
  132573. };
  132574. static long _vq_quantlist__44u2__p2_0[] = {
  132575. 1,
  132576. 0,
  132577. 2,
  132578. };
  132579. static long _vq_lengthlist__44u2__p2_0[] = {
  132580. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  132581. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  132582. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132583. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  132584. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132585. 9,
  132586. };
  132587. static float _vq_quantthresh__44u2__p2_0[] = {
  132588. -0.5, 0.5,
  132589. };
  132590. static long _vq_quantmap__44u2__p2_0[] = {
  132591. 1, 0, 2,
  132592. };
  132593. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  132594. _vq_quantthresh__44u2__p2_0,
  132595. _vq_quantmap__44u2__p2_0,
  132596. 3,
  132597. 3
  132598. };
  132599. static static_codebook _44u2__p2_0 = {
  132600. 4, 81,
  132601. _vq_lengthlist__44u2__p2_0,
  132602. 1, -535822336, 1611661312, 2, 0,
  132603. _vq_quantlist__44u2__p2_0,
  132604. NULL,
  132605. &_vq_auxt__44u2__p2_0,
  132606. NULL,
  132607. 0
  132608. };
  132609. static long _vq_quantlist__44u2__p3_0[] = {
  132610. 2,
  132611. 1,
  132612. 3,
  132613. 0,
  132614. 4,
  132615. };
  132616. static long _vq_lengthlist__44u2__p3_0[] = {
  132617. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  132618. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  132619. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  132620. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  132621. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  132622. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  132623. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  132624. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  132625. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  132626. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  132627. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  132628. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  132629. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  132630. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  132631. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  132632. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  132633. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  132634. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  132635. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  132636. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  132637. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  132638. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  132639. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  132640. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  132641. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  132642. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  132643. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  132644. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  132645. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  132646. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  132647. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  132648. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  132649. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  132650. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  132651. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  132652. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  132653. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  132654. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  132655. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  132656. 0,
  132657. };
  132658. static float _vq_quantthresh__44u2__p3_0[] = {
  132659. -1.5, -0.5, 0.5, 1.5,
  132660. };
  132661. static long _vq_quantmap__44u2__p3_0[] = {
  132662. 3, 1, 0, 2, 4,
  132663. };
  132664. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  132665. _vq_quantthresh__44u2__p3_0,
  132666. _vq_quantmap__44u2__p3_0,
  132667. 5,
  132668. 5
  132669. };
  132670. static static_codebook _44u2__p3_0 = {
  132671. 4, 625,
  132672. _vq_lengthlist__44u2__p3_0,
  132673. 1, -533725184, 1611661312, 3, 0,
  132674. _vq_quantlist__44u2__p3_0,
  132675. NULL,
  132676. &_vq_auxt__44u2__p3_0,
  132677. NULL,
  132678. 0
  132679. };
  132680. static long _vq_quantlist__44u2__p4_0[] = {
  132681. 2,
  132682. 1,
  132683. 3,
  132684. 0,
  132685. 4,
  132686. };
  132687. static long _vq_lengthlist__44u2__p4_0[] = {
  132688. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  132689. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  132690. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  132691. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  132692. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  132693. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  132694. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  132695. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  132696. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  132697. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  132698. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  132699. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132700. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  132701. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  132702. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  132703. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  132704. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  132705. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  132706. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  132707. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  132708. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  132709. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  132710. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  132711. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  132712. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  132713. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  132714. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  132715. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  132716. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  132717. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  132718. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  132719. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  132720. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  132721. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  132722. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  132723. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  132724. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  132725. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  132726. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  132727. 13,
  132728. };
  132729. static float _vq_quantthresh__44u2__p4_0[] = {
  132730. -1.5, -0.5, 0.5, 1.5,
  132731. };
  132732. static long _vq_quantmap__44u2__p4_0[] = {
  132733. 3, 1, 0, 2, 4,
  132734. };
  132735. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  132736. _vq_quantthresh__44u2__p4_0,
  132737. _vq_quantmap__44u2__p4_0,
  132738. 5,
  132739. 5
  132740. };
  132741. static static_codebook _44u2__p4_0 = {
  132742. 4, 625,
  132743. _vq_lengthlist__44u2__p4_0,
  132744. 1, -533725184, 1611661312, 3, 0,
  132745. _vq_quantlist__44u2__p4_0,
  132746. NULL,
  132747. &_vq_auxt__44u2__p4_0,
  132748. NULL,
  132749. 0
  132750. };
  132751. static long _vq_quantlist__44u2__p5_0[] = {
  132752. 4,
  132753. 3,
  132754. 5,
  132755. 2,
  132756. 6,
  132757. 1,
  132758. 7,
  132759. 0,
  132760. 8,
  132761. };
  132762. static long _vq_lengthlist__44u2__p5_0[] = {
  132763. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  132764. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  132765. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  132766. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  132767. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  132768. 13,
  132769. };
  132770. static float _vq_quantthresh__44u2__p5_0[] = {
  132771. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132772. };
  132773. static long _vq_quantmap__44u2__p5_0[] = {
  132774. 7, 5, 3, 1, 0, 2, 4, 6,
  132775. 8,
  132776. };
  132777. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  132778. _vq_quantthresh__44u2__p5_0,
  132779. _vq_quantmap__44u2__p5_0,
  132780. 9,
  132781. 9
  132782. };
  132783. static static_codebook _44u2__p5_0 = {
  132784. 2, 81,
  132785. _vq_lengthlist__44u2__p5_0,
  132786. 1, -531628032, 1611661312, 4, 0,
  132787. _vq_quantlist__44u2__p5_0,
  132788. NULL,
  132789. &_vq_auxt__44u2__p5_0,
  132790. NULL,
  132791. 0
  132792. };
  132793. static long _vq_quantlist__44u2__p6_0[] = {
  132794. 6,
  132795. 5,
  132796. 7,
  132797. 4,
  132798. 8,
  132799. 3,
  132800. 9,
  132801. 2,
  132802. 10,
  132803. 1,
  132804. 11,
  132805. 0,
  132806. 12,
  132807. };
  132808. static long _vq_lengthlist__44u2__p6_0[] = {
  132809. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  132810. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  132811. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  132812. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  132813. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  132814. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  132815. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  132816. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  132817. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  132818. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  132819. 15,17,17,16,18,17,18, 0, 0,
  132820. };
  132821. static float _vq_quantthresh__44u2__p6_0[] = {
  132822. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132823. 12.5, 17.5, 22.5, 27.5,
  132824. };
  132825. static long _vq_quantmap__44u2__p6_0[] = {
  132826. 11, 9, 7, 5, 3, 1, 0, 2,
  132827. 4, 6, 8, 10, 12,
  132828. };
  132829. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  132830. _vq_quantthresh__44u2__p6_0,
  132831. _vq_quantmap__44u2__p6_0,
  132832. 13,
  132833. 13
  132834. };
  132835. static static_codebook _44u2__p6_0 = {
  132836. 2, 169,
  132837. _vq_lengthlist__44u2__p6_0,
  132838. 1, -526516224, 1616117760, 4, 0,
  132839. _vq_quantlist__44u2__p6_0,
  132840. NULL,
  132841. &_vq_auxt__44u2__p6_0,
  132842. NULL,
  132843. 0
  132844. };
  132845. static long _vq_quantlist__44u2__p6_1[] = {
  132846. 2,
  132847. 1,
  132848. 3,
  132849. 0,
  132850. 4,
  132851. };
  132852. static long _vq_lengthlist__44u2__p6_1[] = {
  132853. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  132854. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  132855. };
  132856. static float _vq_quantthresh__44u2__p6_1[] = {
  132857. -1.5, -0.5, 0.5, 1.5,
  132858. };
  132859. static long _vq_quantmap__44u2__p6_1[] = {
  132860. 3, 1, 0, 2, 4,
  132861. };
  132862. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  132863. _vq_quantthresh__44u2__p6_1,
  132864. _vq_quantmap__44u2__p6_1,
  132865. 5,
  132866. 5
  132867. };
  132868. static static_codebook _44u2__p6_1 = {
  132869. 2, 25,
  132870. _vq_lengthlist__44u2__p6_1,
  132871. 1, -533725184, 1611661312, 3, 0,
  132872. _vq_quantlist__44u2__p6_1,
  132873. NULL,
  132874. &_vq_auxt__44u2__p6_1,
  132875. NULL,
  132876. 0
  132877. };
  132878. static long _vq_quantlist__44u2__p7_0[] = {
  132879. 4,
  132880. 3,
  132881. 5,
  132882. 2,
  132883. 6,
  132884. 1,
  132885. 7,
  132886. 0,
  132887. 8,
  132888. };
  132889. static long _vq_lengthlist__44u2__p7_0[] = {
  132890. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  132891. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  132892. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132893. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132894. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132895. 11,
  132896. };
  132897. static float _vq_quantthresh__44u2__p7_0[] = {
  132898. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  132899. };
  132900. static long _vq_quantmap__44u2__p7_0[] = {
  132901. 7, 5, 3, 1, 0, 2, 4, 6,
  132902. 8,
  132903. };
  132904. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  132905. _vq_quantthresh__44u2__p7_0,
  132906. _vq_quantmap__44u2__p7_0,
  132907. 9,
  132908. 9
  132909. };
  132910. static static_codebook _44u2__p7_0 = {
  132911. 2, 81,
  132912. _vq_lengthlist__44u2__p7_0,
  132913. 1, -516612096, 1626677248, 4, 0,
  132914. _vq_quantlist__44u2__p7_0,
  132915. NULL,
  132916. &_vq_auxt__44u2__p7_0,
  132917. NULL,
  132918. 0
  132919. };
  132920. static long _vq_quantlist__44u2__p7_1[] = {
  132921. 6,
  132922. 5,
  132923. 7,
  132924. 4,
  132925. 8,
  132926. 3,
  132927. 9,
  132928. 2,
  132929. 10,
  132930. 1,
  132931. 11,
  132932. 0,
  132933. 12,
  132934. };
  132935. static long _vq_lengthlist__44u2__p7_1[] = {
  132936. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  132937. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  132938. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  132939. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  132940. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  132941. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  132942. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  132943. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  132944. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  132945. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  132946. 14,14,14,17,15,17,17,17,17,
  132947. };
  132948. static float _vq_quantthresh__44u2__p7_1[] = {
  132949. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132950. 32.5, 45.5, 58.5, 71.5,
  132951. };
  132952. static long _vq_quantmap__44u2__p7_1[] = {
  132953. 11, 9, 7, 5, 3, 1, 0, 2,
  132954. 4, 6, 8, 10, 12,
  132955. };
  132956. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  132957. _vq_quantthresh__44u2__p7_1,
  132958. _vq_quantmap__44u2__p7_1,
  132959. 13,
  132960. 13
  132961. };
  132962. static static_codebook _44u2__p7_1 = {
  132963. 2, 169,
  132964. _vq_lengthlist__44u2__p7_1,
  132965. 1, -523010048, 1618608128, 4, 0,
  132966. _vq_quantlist__44u2__p7_1,
  132967. NULL,
  132968. &_vq_auxt__44u2__p7_1,
  132969. NULL,
  132970. 0
  132971. };
  132972. static long _vq_quantlist__44u2__p7_2[] = {
  132973. 6,
  132974. 5,
  132975. 7,
  132976. 4,
  132977. 8,
  132978. 3,
  132979. 9,
  132980. 2,
  132981. 10,
  132982. 1,
  132983. 11,
  132984. 0,
  132985. 12,
  132986. };
  132987. static long _vq_lengthlist__44u2__p7_2[] = {
  132988. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  132989. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  132990. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  132991. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132992. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  132993. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  132994. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  132995. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132996. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  132997. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  132998. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132999. };
  133000. static float _vq_quantthresh__44u2__p7_2[] = {
  133001. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133002. 2.5, 3.5, 4.5, 5.5,
  133003. };
  133004. static long _vq_quantmap__44u2__p7_2[] = {
  133005. 11, 9, 7, 5, 3, 1, 0, 2,
  133006. 4, 6, 8, 10, 12,
  133007. };
  133008. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133009. _vq_quantthresh__44u2__p7_2,
  133010. _vq_quantmap__44u2__p7_2,
  133011. 13,
  133012. 13
  133013. };
  133014. static static_codebook _44u2__p7_2 = {
  133015. 2, 169,
  133016. _vq_lengthlist__44u2__p7_2,
  133017. 1, -531103744, 1611661312, 4, 0,
  133018. _vq_quantlist__44u2__p7_2,
  133019. NULL,
  133020. &_vq_auxt__44u2__p7_2,
  133021. NULL,
  133022. 0
  133023. };
  133024. static long _huff_lengthlist__44u2__short[] = {
  133025. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133026. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133027. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133028. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133029. };
  133030. static static_codebook _huff_book__44u2__short = {
  133031. 2, 64,
  133032. _huff_lengthlist__44u2__short,
  133033. 0, 0, 0, 0, 0,
  133034. NULL,
  133035. NULL,
  133036. NULL,
  133037. NULL,
  133038. 0
  133039. };
  133040. static long _huff_lengthlist__44u3__long[] = {
  133041. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133042. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133043. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133044. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133045. };
  133046. static static_codebook _huff_book__44u3__long = {
  133047. 2, 64,
  133048. _huff_lengthlist__44u3__long,
  133049. 0, 0, 0, 0, 0,
  133050. NULL,
  133051. NULL,
  133052. NULL,
  133053. NULL,
  133054. 0
  133055. };
  133056. static long _vq_quantlist__44u3__p1_0[] = {
  133057. 1,
  133058. 0,
  133059. 2,
  133060. };
  133061. static long _vq_lengthlist__44u3__p1_0[] = {
  133062. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133063. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133064. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133065. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133066. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133067. 13,
  133068. };
  133069. static float _vq_quantthresh__44u3__p1_0[] = {
  133070. -0.5, 0.5,
  133071. };
  133072. static long _vq_quantmap__44u3__p1_0[] = {
  133073. 1, 0, 2,
  133074. };
  133075. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133076. _vq_quantthresh__44u3__p1_0,
  133077. _vq_quantmap__44u3__p1_0,
  133078. 3,
  133079. 3
  133080. };
  133081. static static_codebook _44u3__p1_0 = {
  133082. 4, 81,
  133083. _vq_lengthlist__44u3__p1_0,
  133084. 1, -535822336, 1611661312, 2, 0,
  133085. _vq_quantlist__44u3__p1_0,
  133086. NULL,
  133087. &_vq_auxt__44u3__p1_0,
  133088. NULL,
  133089. 0
  133090. };
  133091. static long _vq_quantlist__44u3__p2_0[] = {
  133092. 1,
  133093. 0,
  133094. 2,
  133095. };
  133096. static long _vq_lengthlist__44u3__p2_0[] = {
  133097. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133098. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133099. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133100. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133101. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133102. 9,
  133103. };
  133104. static float _vq_quantthresh__44u3__p2_0[] = {
  133105. -0.5, 0.5,
  133106. };
  133107. static long _vq_quantmap__44u3__p2_0[] = {
  133108. 1, 0, 2,
  133109. };
  133110. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133111. _vq_quantthresh__44u3__p2_0,
  133112. _vq_quantmap__44u3__p2_0,
  133113. 3,
  133114. 3
  133115. };
  133116. static static_codebook _44u3__p2_0 = {
  133117. 4, 81,
  133118. _vq_lengthlist__44u3__p2_0,
  133119. 1, -535822336, 1611661312, 2, 0,
  133120. _vq_quantlist__44u3__p2_0,
  133121. NULL,
  133122. &_vq_auxt__44u3__p2_0,
  133123. NULL,
  133124. 0
  133125. };
  133126. static long _vq_quantlist__44u3__p3_0[] = {
  133127. 2,
  133128. 1,
  133129. 3,
  133130. 0,
  133131. 4,
  133132. };
  133133. static long _vq_lengthlist__44u3__p3_0[] = {
  133134. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133135. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133136. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133137. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133138. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133139. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133140. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133141. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133142. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133143. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133144. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133145. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133146. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133147. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133148. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133149. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133150. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133151. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133152. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133153. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133154. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133155. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133156. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133157. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133158. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133159. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133160. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133161. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133162. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133163. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133164. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133165. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133166. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133167. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133168. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133169. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133170. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133171. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133172. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133173. 0,
  133174. };
  133175. static float _vq_quantthresh__44u3__p3_0[] = {
  133176. -1.5, -0.5, 0.5, 1.5,
  133177. };
  133178. static long _vq_quantmap__44u3__p3_0[] = {
  133179. 3, 1, 0, 2, 4,
  133180. };
  133181. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133182. _vq_quantthresh__44u3__p3_0,
  133183. _vq_quantmap__44u3__p3_0,
  133184. 5,
  133185. 5
  133186. };
  133187. static static_codebook _44u3__p3_0 = {
  133188. 4, 625,
  133189. _vq_lengthlist__44u3__p3_0,
  133190. 1, -533725184, 1611661312, 3, 0,
  133191. _vq_quantlist__44u3__p3_0,
  133192. NULL,
  133193. &_vq_auxt__44u3__p3_0,
  133194. NULL,
  133195. 0
  133196. };
  133197. static long _vq_quantlist__44u3__p4_0[] = {
  133198. 2,
  133199. 1,
  133200. 3,
  133201. 0,
  133202. 4,
  133203. };
  133204. static long _vq_lengthlist__44u3__p4_0[] = {
  133205. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133206. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133207. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133208. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133209. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133210. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133211. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133212. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133213. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133214. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133215. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133216. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133217. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133218. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133219. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133220. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133221. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133222. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133223. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133224. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133225. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133226. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133227. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133228. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133229. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133230. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133231. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133232. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133233. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133234. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133235. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133236. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133237. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133238. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133239. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133240. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133241. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133242. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133243. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133244. 13,
  133245. };
  133246. static float _vq_quantthresh__44u3__p4_0[] = {
  133247. -1.5, -0.5, 0.5, 1.5,
  133248. };
  133249. static long _vq_quantmap__44u3__p4_0[] = {
  133250. 3, 1, 0, 2, 4,
  133251. };
  133252. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133253. _vq_quantthresh__44u3__p4_0,
  133254. _vq_quantmap__44u3__p4_0,
  133255. 5,
  133256. 5
  133257. };
  133258. static static_codebook _44u3__p4_0 = {
  133259. 4, 625,
  133260. _vq_lengthlist__44u3__p4_0,
  133261. 1, -533725184, 1611661312, 3, 0,
  133262. _vq_quantlist__44u3__p4_0,
  133263. NULL,
  133264. &_vq_auxt__44u3__p4_0,
  133265. NULL,
  133266. 0
  133267. };
  133268. static long _vq_quantlist__44u3__p5_0[] = {
  133269. 4,
  133270. 3,
  133271. 5,
  133272. 2,
  133273. 6,
  133274. 1,
  133275. 7,
  133276. 0,
  133277. 8,
  133278. };
  133279. static long _vq_lengthlist__44u3__p5_0[] = {
  133280. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133281. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133282. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133283. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133284. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133285. 12,
  133286. };
  133287. static float _vq_quantthresh__44u3__p5_0[] = {
  133288. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133289. };
  133290. static long _vq_quantmap__44u3__p5_0[] = {
  133291. 7, 5, 3, 1, 0, 2, 4, 6,
  133292. 8,
  133293. };
  133294. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133295. _vq_quantthresh__44u3__p5_0,
  133296. _vq_quantmap__44u3__p5_0,
  133297. 9,
  133298. 9
  133299. };
  133300. static static_codebook _44u3__p5_0 = {
  133301. 2, 81,
  133302. _vq_lengthlist__44u3__p5_0,
  133303. 1, -531628032, 1611661312, 4, 0,
  133304. _vq_quantlist__44u3__p5_0,
  133305. NULL,
  133306. &_vq_auxt__44u3__p5_0,
  133307. NULL,
  133308. 0
  133309. };
  133310. static long _vq_quantlist__44u3__p6_0[] = {
  133311. 6,
  133312. 5,
  133313. 7,
  133314. 4,
  133315. 8,
  133316. 3,
  133317. 9,
  133318. 2,
  133319. 10,
  133320. 1,
  133321. 11,
  133322. 0,
  133323. 12,
  133324. };
  133325. static long _vq_lengthlist__44u3__p6_0[] = {
  133326. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133327. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133328. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133329. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133330. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133331. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133332. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133333. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133334. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133335. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133336. 15,16,16,16,17,18,16,20,18,
  133337. };
  133338. static float _vq_quantthresh__44u3__p6_0[] = {
  133339. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133340. 12.5, 17.5, 22.5, 27.5,
  133341. };
  133342. static long _vq_quantmap__44u3__p6_0[] = {
  133343. 11, 9, 7, 5, 3, 1, 0, 2,
  133344. 4, 6, 8, 10, 12,
  133345. };
  133346. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133347. _vq_quantthresh__44u3__p6_0,
  133348. _vq_quantmap__44u3__p6_0,
  133349. 13,
  133350. 13
  133351. };
  133352. static static_codebook _44u3__p6_0 = {
  133353. 2, 169,
  133354. _vq_lengthlist__44u3__p6_0,
  133355. 1, -526516224, 1616117760, 4, 0,
  133356. _vq_quantlist__44u3__p6_0,
  133357. NULL,
  133358. &_vq_auxt__44u3__p6_0,
  133359. NULL,
  133360. 0
  133361. };
  133362. static long _vq_quantlist__44u3__p6_1[] = {
  133363. 2,
  133364. 1,
  133365. 3,
  133366. 0,
  133367. 4,
  133368. };
  133369. static long _vq_lengthlist__44u3__p6_1[] = {
  133370. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133371. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133372. };
  133373. static float _vq_quantthresh__44u3__p6_1[] = {
  133374. -1.5, -0.5, 0.5, 1.5,
  133375. };
  133376. static long _vq_quantmap__44u3__p6_1[] = {
  133377. 3, 1, 0, 2, 4,
  133378. };
  133379. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133380. _vq_quantthresh__44u3__p6_1,
  133381. _vq_quantmap__44u3__p6_1,
  133382. 5,
  133383. 5
  133384. };
  133385. static static_codebook _44u3__p6_1 = {
  133386. 2, 25,
  133387. _vq_lengthlist__44u3__p6_1,
  133388. 1, -533725184, 1611661312, 3, 0,
  133389. _vq_quantlist__44u3__p6_1,
  133390. NULL,
  133391. &_vq_auxt__44u3__p6_1,
  133392. NULL,
  133393. 0
  133394. };
  133395. static long _vq_quantlist__44u3__p7_0[] = {
  133396. 4,
  133397. 3,
  133398. 5,
  133399. 2,
  133400. 6,
  133401. 1,
  133402. 7,
  133403. 0,
  133404. 8,
  133405. };
  133406. static long _vq_lengthlist__44u3__p7_0[] = {
  133407. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133408. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133409. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133410. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133411. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133412. 9,
  133413. };
  133414. static float _vq_quantthresh__44u3__p7_0[] = {
  133415. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133416. };
  133417. static long _vq_quantmap__44u3__p7_0[] = {
  133418. 7, 5, 3, 1, 0, 2, 4, 6,
  133419. 8,
  133420. };
  133421. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133422. _vq_quantthresh__44u3__p7_0,
  133423. _vq_quantmap__44u3__p7_0,
  133424. 9,
  133425. 9
  133426. };
  133427. static static_codebook _44u3__p7_0 = {
  133428. 2, 81,
  133429. _vq_lengthlist__44u3__p7_0,
  133430. 1, -515907584, 1627381760, 4, 0,
  133431. _vq_quantlist__44u3__p7_0,
  133432. NULL,
  133433. &_vq_auxt__44u3__p7_0,
  133434. NULL,
  133435. 0
  133436. };
  133437. static long _vq_quantlist__44u3__p7_1[] = {
  133438. 7,
  133439. 6,
  133440. 8,
  133441. 5,
  133442. 9,
  133443. 4,
  133444. 10,
  133445. 3,
  133446. 11,
  133447. 2,
  133448. 12,
  133449. 1,
  133450. 13,
  133451. 0,
  133452. 14,
  133453. };
  133454. static long _vq_lengthlist__44u3__p7_1[] = {
  133455. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133456. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133457. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133458. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133459. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133460. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133461. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133462. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133463. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133464. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133465. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133466. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133467. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133468. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133469. 17,
  133470. };
  133471. static float _vq_quantthresh__44u3__p7_1[] = {
  133472. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133473. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133474. };
  133475. static long _vq_quantmap__44u3__p7_1[] = {
  133476. 13, 11, 9, 7, 5, 3, 1, 0,
  133477. 2, 4, 6, 8, 10, 12, 14,
  133478. };
  133479. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133480. _vq_quantthresh__44u3__p7_1,
  133481. _vq_quantmap__44u3__p7_1,
  133482. 15,
  133483. 15
  133484. };
  133485. static static_codebook _44u3__p7_1 = {
  133486. 2, 225,
  133487. _vq_lengthlist__44u3__p7_1,
  133488. 1, -522338304, 1620115456, 4, 0,
  133489. _vq_quantlist__44u3__p7_1,
  133490. NULL,
  133491. &_vq_auxt__44u3__p7_1,
  133492. NULL,
  133493. 0
  133494. };
  133495. static long _vq_quantlist__44u3__p7_2[] = {
  133496. 8,
  133497. 7,
  133498. 9,
  133499. 6,
  133500. 10,
  133501. 5,
  133502. 11,
  133503. 4,
  133504. 12,
  133505. 3,
  133506. 13,
  133507. 2,
  133508. 14,
  133509. 1,
  133510. 15,
  133511. 0,
  133512. 16,
  133513. };
  133514. static long _vq_lengthlist__44u3__p7_2[] = {
  133515. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  133516. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133517. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  133518. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133519. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  133520. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133521. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  133522. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  133523. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  133524. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  133525. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  133526. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  133527. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  133528. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133529. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  133530. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  133531. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  133532. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  133533. 11,
  133534. };
  133535. static float _vq_quantthresh__44u3__p7_2[] = {
  133536. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  133537. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  133538. };
  133539. static long _vq_quantmap__44u3__p7_2[] = {
  133540. 15, 13, 11, 9, 7, 5, 3, 1,
  133541. 0, 2, 4, 6, 8, 10, 12, 14,
  133542. 16,
  133543. };
  133544. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  133545. _vq_quantthresh__44u3__p7_2,
  133546. _vq_quantmap__44u3__p7_2,
  133547. 17,
  133548. 17
  133549. };
  133550. static static_codebook _44u3__p7_2 = {
  133551. 2, 289,
  133552. _vq_lengthlist__44u3__p7_2,
  133553. 1, -529530880, 1611661312, 5, 0,
  133554. _vq_quantlist__44u3__p7_2,
  133555. NULL,
  133556. &_vq_auxt__44u3__p7_2,
  133557. NULL,
  133558. 0
  133559. };
  133560. static long _huff_lengthlist__44u3__short[] = {
  133561. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  133562. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  133563. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  133564. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  133565. };
  133566. static static_codebook _huff_book__44u3__short = {
  133567. 2, 64,
  133568. _huff_lengthlist__44u3__short,
  133569. 0, 0, 0, 0, 0,
  133570. NULL,
  133571. NULL,
  133572. NULL,
  133573. NULL,
  133574. 0
  133575. };
  133576. static long _huff_lengthlist__44u4__long[] = {
  133577. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  133578. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  133579. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  133580. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  133581. };
  133582. static static_codebook _huff_book__44u4__long = {
  133583. 2, 64,
  133584. _huff_lengthlist__44u4__long,
  133585. 0, 0, 0, 0, 0,
  133586. NULL,
  133587. NULL,
  133588. NULL,
  133589. NULL,
  133590. 0
  133591. };
  133592. static long _vq_quantlist__44u4__p1_0[] = {
  133593. 1,
  133594. 0,
  133595. 2,
  133596. };
  133597. static long _vq_lengthlist__44u4__p1_0[] = {
  133598. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133599. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133600. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  133601. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133602. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  133603. 13,
  133604. };
  133605. static float _vq_quantthresh__44u4__p1_0[] = {
  133606. -0.5, 0.5,
  133607. };
  133608. static long _vq_quantmap__44u4__p1_0[] = {
  133609. 1, 0, 2,
  133610. };
  133611. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  133612. _vq_quantthresh__44u4__p1_0,
  133613. _vq_quantmap__44u4__p1_0,
  133614. 3,
  133615. 3
  133616. };
  133617. static static_codebook _44u4__p1_0 = {
  133618. 4, 81,
  133619. _vq_lengthlist__44u4__p1_0,
  133620. 1, -535822336, 1611661312, 2, 0,
  133621. _vq_quantlist__44u4__p1_0,
  133622. NULL,
  133623. &_vq_auxt__44u4__p1_0,
  133624. NULL,
  133625. 0
  133626. };
  133627. static long _vq_quantlist__44u4__p2_0[] = {
  133628. 1,
  133629. 0,
  133630. 2,
  133631. };
  133632. static long _vq_lengthlist__44u4__p2_0[] = {
  133633. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133634. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  133635. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133636. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  133637. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133638. 9,
  133639. };
  133640. static float _vq_quantthresh__44u4__p2_0[] = {
  133641. -0.5, 0.5,
  133642. };
  133643. static long _vq_quantmap__44u4__p2_0[] = {
  133644. 1, 0, 2,
  133645. };
  133646. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  133647. _vq_quantthresh__44u4__p2_0,
  133648. _vq_quantmap__44u4__p2_0,
  133649. 3,
  133650. 3
  133651. };
  133652. static static_codebook _44u4__p2_0 = {
  133653. 4, 81,
  133654. _vq_lengthlist__44u4__p2_0,
  133655. 1, -535822336, 1611661312, 2, 0,
  133656. _vq_quantlist__44u4__p2_0,
  133657. NULL,
  133658. &_vq_auxt__44u4__p2_0,
  133659. NULL,
  133660. 0
  133661. };
  133662. static long _vq_quantlist__44u4__p3_0[] = {
  133663. 2,
  133664. 1,
  133665. 3,
  133666. 0,
  133667. 4,
  133668. };
  133669. static long _vq_lengthlist__44u4__p3_0[] = {
  133670. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133671. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  133672. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  133673. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  133674. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  133675. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  133676. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  133677. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  133678. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  133679. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  133680. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  133681. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  133682. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  133683. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  133684. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  133685. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  133686. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  133687. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  133688. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  133689. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  133690. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  133691. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  133692. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  133693. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  133694. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  133695. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  133696. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  133697. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  133698. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  133699. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  133700. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  133701. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  133702. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  133703. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  133704. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  133705. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  133706. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  133707. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  133708. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  133709. 0,
  133710. };
  133711. static float _vq_quantthresh__44u4__p3_0[] = {
  133712. -1.5, -0.5, 0.5, 1.5,
  133713. };
  133714. static long _vq_quantmap__44u4__p3_0[] = {
  133715. 3, 1, 0, 2, 4,
  133716. };
  133717. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  133718. _vq_quantthresh__44u4__p3_0,
  133719. _vq_quantmap__44u4__p3_0,
  133720. 5,
  133721. 5
  133722. };
  133723. static static_codebook _44u4__p3_0 = {
  133724. 4, 625,
  133725. _vq_lengthlist__44u4__p3_0,
  133726. 1, -533725184, 1611661312, 3, 0,
  133727. _vq_quantlist__44u4__p3_0,
  133728. NULL,
  133729. &_vq_auxt__44u4__p3_0,
  133730. NULL,
  133731. 0
  133732. };
  133733. static long _vq_quantlist__44u4__p4_0[] = {
  133734. 2,
  133735. 1,
  133736. 3,
  133737. 0,
  133738. 4,
  133739. };
  133740. static long _vq_lengthlist__44u4__p4_0[] = {
  133741. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133742. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133743. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133744. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133745. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133746. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  133747. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  133748. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  133749. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133750. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133751. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133752. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133753. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133754. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  133755. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133756. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133757. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133758. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133759. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133760. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133761. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133762. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133763. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133764. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133765. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133766. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  133767. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  133768. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  133769. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  133770. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  133771. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  133772. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133773. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133774. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  133775. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133776. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  133777. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133778. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  133779. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  133780. 13,
  133781. };
  133782. static float _vq_quantthresh__44u4__p4_0[] = {
  133783. -1.5, -0.5, 0.5, 1.5,
  133784. };
  133785. static long _vq_quantmap__44u4__p4_0[] = {
  133786. 3, 1, 0, 2, 4,
  133787. };
  133788. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  133789. _vq_quantthresh__44u4__p4_0,
  133790. _vq_quantmap__44u4__p4_0,
  133791. 5,
  133792. 5
  133793. };
  133794. static static_codebook _44u4__p4_0 = {
  133795. 4, 625,
  133796. _vq_lengthlist__44u4__p4_0,
  133797. 1, -533725184, 1611661312, 3, 0,
  133798. _vq_quantlist__44u4__p4_0,
  133799. NULL,
  133800. &_vq_auxt__44u4__p4_0,
  133801. NULL,
  133802. 0
  133803. };
  133804. static long _vq_quantlist__44u4__p5_0[] = {
  133805. 4,
  133806. 3,
  133807. 5,
  133808. 2,
  133809. 6,
  133810. 1,
  133811. 7,
  133812. 0,
  133813. 8,
  133814. };
  133815. static long _vq_lengthlist__44u4__p5_0[] = {
  133816. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133817. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133818. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  133819. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133820. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  133821. 12,
  133822. };
  133823. static float _vq_quantthresh__44u4__p5_0[] = {
  133824. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133825. };
  133826. static long _vq_quantmap__44u4__p5_0[] = {
  133827. 7, 5, 3, 1, 0, 2, 4, 6,
  133828. 8,
  133829. };
  133830. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  133831. _vq_quantthresh__44u4__p5_0,
  133832. _vq_quantmap__44u4__p5_0,
  133833. 9,
  133834. 9
  133835. };
  133836. static static_codebook _44u4__p5_0 = {
  133837. 2, 81,
  133838. _vq_lengthlist__44u4__p5_0,
  133839. 1, -531628032, 1611661312, 4, 0,
  133840. _vq_quantlist__44u4__p5_0,
  133841. NULL,
  133842. &_vq_auxt__44u4__p5_0,
  133843. NULL,
  133844. 0
  133845. };
  133846. static long _vq_quantlist__44u4__p6_0[] = {
  133847. 6,
  133848. 5,
  133849. 7,
  133850. 4,
  133851. 8,
  133852. 3,
  133853. 9,
  133854. 2,
  133855. 10,
  133856. 1,
  133857. 11,
  133858. 0,
  133859. 12,
  133860. };
  133861. static long _vq_lengthlist__44u4__p6_0[] = {
  133862. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  133863. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133864. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133865. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133866. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  133867. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  133868. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  133869. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  133870. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  133871. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  133872. 16,16,16,17,17,18,17,20,21,
  133873. };
  133874. static float _vq_quantthresh__44u4__p6_0[] = {
  133875. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133876. 12.5, 17.5, 22.5, 27.5,
  133877. };
  133878. static long _vq_quantmap__44u4__p6_0[] = {
  133879. 11, 9, 7, 5, 3, 1, 0, 2,
  133880. 4, 6, 8, 10, 12,
  133881. };
  133882. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  133883. _vq_quantthresh__44u4__p6_0,
  133884. _vq_quantmap__44u4__p6_0,
  133885. 13,
  133886. 13
  133887. };
  133888. static static_codebook _44u4__p6_0 = {
  133889. 2, 169,
  133890. _vq_lengthlist__44u4__p6_0,
  133891. 1, -526516224, 1616117760, 4, 0,
  133892. _vq_quantlist__44u4__p6_0,
  133893. NULL,
  133894. &_vq_auxt__44u4__p6_0,
  133895. NULL,
  133896. 0
  133897. };
  133898. static long _vq_quantlist__44u4__p6_1[] = {
  133899. 2,
  133900. 1,
  133901. 3,
  133902. 0,
  133903. 4,
  133904. };
  133905. static long _vq_lengthlist__44u4__p6_1[] = {
  133906. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133907. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133908. };
  133909. static float _vq_quantthresh__44u4__p6_1[] = {
  133910. -1.5, -0.5, 0.5, 1.5,
  133911. };
  133912. static long _vq_quantmap__44u4__p6_1[] = {
  133913. 3, 1, 0, 2, 4,
  133914. };
  133915. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  133916. _vq_quantthresh__44u4__p6_1,
  133917. _vq_quantmap__44u4__p6_1,
  133918. 5,
  133919. 5
  133920. };
  133921. static static_codebook _44u4__p6_1 = {
  133922. 2, 25,
  133923. _vq_lengthlist__44u4__p6_1,
  133924. 1, -533725184, 1611661312, 3, 0,
  133925. _vq_quantlist__44u4__p6_1,
  133926. NULL,
  133927. &_vq_auxt__44u4__p6_1,
  133928. NULL,
  133929. 0
  133930. };
  133931. static long _vq_quantlist__44u4__p7_0[] = {
  133932. 6,
  133933. 5,
  133934. 7,
  133935. 4,
  133936. 8,
  133937. 3,
  133938. 9,
  133939. 2,
  133940. 10,
  133941. 1,
  133942. 11,
  133943. 0,
  133944. 12,
  133945. };
  133946. static long _vq_lengthlist__44u4__p7_0[] = {
  133947. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  133948. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  133949. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133950. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133951. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  133952. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133953. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133954. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133955. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133956. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133957. 11,11,11,11,11,11,11,11,11,
  133958. };
  133959. static float _vq_quantthresh__44u4__p7_0[] = {
  133960. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  133961. 637.5, 892.5, 1147.5, 1402.5,
  133962. };
  133963. static long _vq_quantmap__44u4__p7_0[] = {
  133964. 11, 9, 7, 5, 3, 1, 0, 2,
  133965. 4, 6, 8, 10, 12,
  133966. };
  133967. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  133968. _vq_quantthresh__44u4__p7_0,
  133969. _vq_quantmap__44u4__p7_0,
  133970. 13,
  133971. 13
  133972. };
  133973. static static_codebook _44u4__p7_0 = {
  133974. 2, 169,
  133975. _vq_lengthlist__44u4__p7_0,
  133976. 1, -514332672, 1627381760, 4, 0,
  133977. _vq_quantlist__44u4__p7_0,
  133978. NULL,
  133979. &_vq_auxt__44u4__p7_0,
  133980. NULL,
  133981. 0
  133982. };
  133983. static long _vq_quantlist__44u4__p7_1[] = {
  133984. 7,
  133985. 6,
  133986. 8,
  133987. 5,
  133988. 9,
  133989. 4,
  133990. 10,
  133991. 3,
  133992. 11,
  133993. 2,
  133994. 12,
  133995. 1,
  133996. 13,
  133997. 0,
  133998. 14,
  133999. };
  134000. static long _vq_lengthlist__44u4__p7_1[] = {
  134001. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134002. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134003. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134004. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134005. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134006. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134007. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134008. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134009. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134010. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134011. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134012. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134013. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134014. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134015. 16,
  134016. };
  134017. static float _vq_quantthresh__44u4__p7_1[] = {
  134018. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134019. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134020. };
  134021. static long _vq_quantmap__44u4__p7_1[] = {
  134022. 13, 11, 9, 7, 5, 3, 1, 0,
  134023. 2, 4, 6, 8, 10, 12, 14,
  134024. };
  134025. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134026. _vq_quantthresh__44u4__p7_1,
  134027. _vq_quantmap__44u4__p7_1,
  134028. 15,
  134029. 15
  134030. };
  134031. static static_codebook _44u4__p7_1 = {
  134032. 2, 225,
  134033. _vq_lengthlist__44u4__p7_1,
  134034. 1, -522338304, 1620115456, 4, 0,
  134035. _vq_quantlist__44u4__p7_1,
  134036. NULL,
  134037. &_vq_auxt__44u4__p7_1,
  134038. NULL,
  134039. 0
  134040. };
  134041. static long _vq_quantlist__44u4__p7_2[] = {
  134042. 8,
  134043. 7,
  134044. 9,
  134045. 6,
  134046. 10,
  134047. 5,
  134048. 11,
  134049. 4,
  134050. 12,
  134051. 3,
  134052. 13,
  134053. 2,
  134054. 14,
  134055. 1,
  134056. 15,
  134057. 0,
  134058. 16,
  134059. };
  134060. static long _vq_lengthlist__44u4__p7_2[] = {
  134061. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134062. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134063. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134064. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134065. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134066. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134067. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134068. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134069. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134070. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134071. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134072. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134073. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134074. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134075. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134076. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134077. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134078. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134079. 10,
  134080. };
  134081. static float _vq_quantthresh__44u4__p7_2[] = {
  134082. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134083. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134084. };
  134085. static long _vq_quantmap__44u4__p7_2[] = {
  134086. 15, 13, 11, 9, 7, 5, 3, 1,
  134087. 0, 2, 4, 6, 8, 10, 12, 14,
  134088. 16,
  134089. };
  134090. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134091. _vq_quantthresh__44u4__p7_2,
  134092. _vq_quantmap__44u4__p7_2,
  134093. 17,
  134094. 17
  134095. };
  134096. static static_codebook _44u4__p7_2 = {
  134097. 2, 289,
  134098. _vq_lengthlist__44u4__p7_2,
  134099. 1, -529530880, 1611661312, 5, 0,
  134100. _vq_quantlist__44u4__p7_2,
  134101. NULL,
  134102. &_vq_auxt__44u4__p7_2,
  134103. NULL,
  134104. 0
  134105. };
  134106. static long _huff_lengthlist__44u4__short[] = {
  134107. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134108. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134109. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134110. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134111. };
  134112. static static_codebook _huff_book__44u4__short = {
  134113. 2, 64,
  134114. _huff_lengthlist__44u4__short,
  134115. 0, 0, 0, 0, 0,
  134116. NULL,
  134117. NULL,
  134118. NULL,
  134119. NULL,
  134120. 0
  134121. };
  134122. static long _huff_lengthlist__44u5__long[] = {
  134123. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134124. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134125. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134126. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134127. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134128. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134129. 14, 8, 7, 8,
  134130. };
  134131. static static_codebook _huff_book__44u5__long = {
  134132. 2, 100,
  134133. _huff_lengthlist__44u5__long,
  134134. 0, 0, 0, 0, 0,
  134135. NULL,
  134136. NULL,
  134137. NULL,
  134138. NULL,
  134139. 0
  134140. };
  134141. static long _vq_quantlist__44u5__p1_0[] = {
  134142. 1,
  134143. 0,
  134144. 2,
  134145. };
  134146. static long _vq_lengthlist__44u5__p1_0[] = {
  134147. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134148. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134149. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134150. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134151. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134152. 12,
  134153. };
  134154. static float _vq_quantthresh__44u5__p1_0[] = {
  134155. -0.5, 0.5,
  134156. };
  134157. static long _vq_quantmap__44u5__p1_0[] = {
  134158. 1, 0, 2,
  134159. };
  134160. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134161. _vq_quantthresh__44u5__p1_0,
  134162. _vq_quantmap__44u5__p1_0,
  134163. 3,
  134164. 3
  134165. };
  134166. static static_codebook _44u5__p1_0 = {
  134167. 4, 81,
  134168. _vq_lengthlist__44u5__p1_0,
  134169. 1, -535822336, 1611661312, 2, 0,
  134170. _vq_quantlist__44u5__p1_0,
  134171. NULL,
  134172. &_vq_auxt__44u5__p1_0,
  134173. NULL,
  134174. 0
  134175. };
  134176. static long _vq_quantlist__44u5__p2_0[] = {
  134177. 1,
  134178. 0,
  134179. 2,
  134180. };
  134181. static long _vq_lengthlist__44u5__p2_0[] = {
  134182. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134183. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134184. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134185. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134186. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134187. 9,
  134188. };
  134189. static float _vq_quantthresh__44u5__p2_0[] = {
  134190. -0.5, 0.5,
  134191. };
  134192. static long _vq_quantmap__44u5__p2_0[] = {
  134193. 1, 0, 2,
  134194. };
  134195. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134196. _vq_quantthresh__44u5__p2_0,
  134197. _vq_quantmap__44u5__p2_0,
  134198. 3,
  134199. 3
  134200. };
  134201. static static_codebook _44u5__p2_0 = {
  134202. 4, 81,
  134203. _vq_lengthlist__44u5__p2_0,
  134204. 1, -535822336, 1611661312, 2, 0,
  134205. _vq_quantlist__44u5__p2_0,
  134206. NULL,
  134207. &_vq_auxt__44u5__p2_0,
  134208. NULL,
  134209. 0
  134210. };
  134211. static long _vq_quantlist__44u5__p3_0[] = {
  134212. 2,
  134213. 1,
  134214. 3,
  134215. 0,
  134216. 4,
  134217. };
  134218. static long _vq_lengthlist__44u5__p3_0[] = {
  134219. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134220. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134221. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134222. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134223. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134224. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134225. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134226. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134227. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134228. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134229. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134230. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134231. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134232. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134233. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134234. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134235. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134236. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134237. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134238. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134239. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134240. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134241. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134242. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134243. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134244. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134245. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134246. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134247. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134248. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134249. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134250. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134251. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134252. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134253. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134254. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134255. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134256. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134257. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134258. 0,
  134259. };
  134260. static float _vq_quantthresh__44u5__p3_0[] = {
  134261. -1.5, -0.5, 0.5, 1.5,
  134262. };
  134263. static long _vq_quantmap__44u5__p3_0[] = {
  134264. 3, 1, 0, 2, 4,
  134265. };
  134266. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134267. _vq_quantthresh__44u5__p3_0,
  134268. _vq_quantmap__44u5__p3_0,
  134269. 5,
  134270. 5
  134271. };
  134272. static static_codebook _44u5__p3_0 = {
  134273. 4, 625,
  134274. _vq_lengthlist__44u5__p3_0,
  134275. 1, -533725184, 1611661312, 3, 0,
  134276. _vq_quantlist__44u5__p3_0,
  134277. NULL,
  134278. &_vq_auxt__44u5__p3_0,
  134279. NULL,
  134280. 0
  134281. };
  134282. static long _vq_quantlist__44u5__p4_0[] = {
  134283. 2,
  134284. 1,
  134285. 3,
  134286. 0,
  134287. 4,
  134288. };
  134289. static long _vq_lengthlist__44u5__p4_0[] = {
  134290. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134291. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134292. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134293. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134294. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134295. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134296. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134297. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134298. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134299. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134300. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134301. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134302. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134303. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134304. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134305. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134306. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134307. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134308. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134309. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134310. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134311. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134312. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134313. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134314. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134315. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134316. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134317. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134318. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134319. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134320. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134321. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134322. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134323. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134324. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134325. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134326. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134327. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134328. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134329. 12,
  134330. };
  134331. static float _vq_quantthresh__44u5__p4_0[] = {
  134332. -1.5, -0.5, 0.5, 1.5,
  134333. };
  134334. static long _vq_quantmap__44u5__p4_0[] = {
  134335. 3, 1, 0, 2, 4,
  134336. };
  134337. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134338. _vq_quantthresh__44u5__p4_0,
  134339. _vq_quantmap__44u5__p4_0,
  134340. 5,
  134341. 5
  134342. };
  134343. static static_codebook _44u5__p4_0 = {
  134344. 4, 625,
  134345. _vq_lengthlist__44u5__p4_0,
  134346. 1, -533725184, 1611661312, 3, 0,
  134347. _vq_quantlist__44u5__p4_0,
  134348. NULL,
  134349. &_vq_auxt__44u5__p4_0,
  134350. NULL,
  134351. 0
  134352. };
  134353. static long _vq_quantlist__44u5__p5_0[] = {
  134354. 4,
  134355. 3,
  134356. 5,
  134357. 2,
  134358. 6,
  134359. 1,
  134360. 7,
  134361. 0,
  134362. 8,
  134363. };
  134364. static long _vq_lengthlist__44u5__p5_0[] = {
  134365. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134366. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134367. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134368. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134369. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134370. 14,
  134371. };
  134372. static float _vq_quantthresh__44u5__p5_0[] = {
  134373. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134374. };
  134375. static long _vq_quantmap__44u5__p5_0[] = {
  134376. 7, 5, 3, 1, 0, 2, 4, 6,
  134377. 8,
  134378. };
  134379. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134380. _vq_quantthresh__44u5__p5_0,
  134381. _vq_quantmap__44u5__p5_0,
  134382. 9,
  134383. 9
  134384. };
  134385. static static_codebook _44u5__p5_0 = {
  134386. 2, 81,
  134387. _vq_lengthlist__44u5__p5_0,
  134388. 1, -531628032, 1611661312, 4, 0,
  134389. _vq_quantlist__44u5__p5_0,
  134390. NULL,
  134391. &_vq_auxt__44u5__p5_0,
  134392. NULL,
  134393. 0
  134394. };
  134395. static long _vq_quantlist__44u5__p6_0[] = {
  134396. 4,
  134397. 3,
  134398. 5,
  134399. 2,
  134400. 6,
  134401. 1,
  134402. 7,
  134403. 0,
  134404. 8,
  134405. };
  134406. static long _vq_lengthlist__44u5__p6_0[] = {
  134407. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134408. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134409. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134410. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134411. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134412. 11,
  134413. };
  134414. static float _vq_quantthresh__44u5__p6_0[] = {
  134415. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134416. };
  134417. static long _vq_quantmap__44u5__p6_0[] = {
  134418. 7, 5, 3, 1, 0, 2, 4, 6,
  134419. 8,
  134420. };
  134421. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134422. _vq_quantthresh__44u5__p6_0,
  134423. _vq_quantmap__44u5__p6_0,
  134424. 9,
  134425. 9
  134426. };
  134427. static static_codebook _44u5__p6_0 = {
  134428. 2, 81,
  134429. _vq_lengthlist__44u5__p6_0,
  134430. 1, -531628032, 1611661312, 4, 0,
  134431. _vq_quantlist__44u5__p6_0,
  134432. NULL,
  134433. &_vq_auxt__44u5__p6_0,
  134434. NULL,
  134435. 0
  134436. };
  134437. static long _vq_quantlist__44u5__p7_0[] = {
  134438. 1,
  134439. 0,
  134440. 2,
  134441. };
  134442. static long _vq_lengthlist__44u5__p7_0[] = {
  134443. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134444. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134445. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134446. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134447. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134448. 12,
  134449. };
  134450. static float _vq_quantthresh__44u5__p7_0[] = {
  134451. -5.5, 5.5,
  134452. };
  134453. static long _vq_quantmap__44u5__p7_0[] = {
  134454. 1, 0, 2,
  134455. };
  134456. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134457. _vq_quantthresh__44u5__p7_0,
  134458. _vq_quantmap__44u5__p7_0,
  134459. 3,
  134460. 3
  134461. };
  134462. static static_codebook _44u5__p7_0 = {
  134463. 4, 81,
  134464. _vq_lengthlist__44u5__p7_0,
  134465. 1, -529137664, 1618345984, 2, 0,
  134466. _vq_quantlist__44u5__p7_0,
  134467. NULL,
  134468. &_vq_auxt__44u5__p7_0,
  134469. NULL,
  134470. 0
  134471. };
  134472. static long _vq_quantlist__44u5__p7_1[] = {
  134473. 5,
  134474. 4,
  134475. 6,
  134476. 3,
  134477. 7,
  134478. 2,
  134479. 8,
  134480. 1,
  134481. 9,
  134482. 0,
  134483. 10,
  134484. };
  134485. static long _vq_lengthlist__44u5__p7_1[] = {
  134486. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134487. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134488. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134489. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134490. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134491. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134492. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134493. 9, 9, 9, 9, 9,10,10,10,10,
  134494. };
  134495. static float _vq_quantthresh__44u5__p7_1[] = {
  134496. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134497. 3.5, 4.5,
  134498. };
  134499. static long _vq_quantmap__44u5__p7_1[] = {
  134500. 9, 7, 5, 3, 1, 0, 2, 4,
  134501. 6, 8, 10,
  134502. };
  134503. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134504. _vq_quantthresh__44u5__p7_1,
  134505. _vq_quantmap__44u5__p7_1,
  134506. 11,
  134507. 11
  134508. };
  134509. static static_codebook _44u5__p7_1 = {
  134510. 2, 121,
  134511. _vq_lengthlist__44u5__p7_1,
  134512. 1, -531365888, 1611661312, 4, 0,
  134513. _vq_quantlist__44u5__p7_1,
  134514. NULL,
  134515. &_vq_auxt__44u5__p7_1,
  134516. NULL,
  134517. 0
  134518. };
  134519. static long _vq_quantlist__44u5__p8_0[] = {
  134520. 5,
  134521. 4,
  134522. 6,
  134523. 3,
  134524. 7,
  134525. 2,
  134526. 8,
  134527. 1,
  134528. 9,
  134529. 0,
  134530. 10,
  134531. };
  134532. static long _vq_lengthlist__44u5__p8_0[] = {
  134533. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  134534. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  134535. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  134536. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  134537. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  134538. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  134539. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  134540. 12,13,13,14,14,14,14,15,15,
  134541. };
  134542. static float _vq_quantthresh__44u5__p8_0[] = {
  134543. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  134544. 38.5, 49.5,
  134545. };
  134546. static long _vq_quantmap__44u5__p8_0[] = {
  134547. 9, 7, 5, 3, 1, 0, 2, 4,
  134548. 6, 8, 10,
  134549. };
  134550. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  134551. _vq_quantthresh__44u5__p8_0,
  134552. _vq_quantmap__44u5__p8_0,
  134553. 11,
  134554. 11
  134555. };
  134556. static static_codebook _44u5__p8_0 = {
  134557. 2, 121,
  134558. _vq_lengthlist__44u5__p8_0,
  134559. 1, -524582912, 1618345984, 4, 0,
  134560. _vq_quantlist__44u5__p8_0,
  134561. NULL,
  134562. &_vq_auxt__44u5__p8_0,
  134563. NULL,
  134564. 0
  134565. };
  134566. static long _vq_quantlist__44u5__p8_1[] = {
  134567. 5,
  134568. 4,
  134569. 6,
  134570. 3,
  134571. 7,
  134572. 2,
  134573. 8,
  134574. 1,
  134575. 9,
  134576. 0,
  134577. 10,
  134578. };
  134579. static long _vq_lengthlist__44u5__p8_1[] = {
  134580. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  134581. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  134582. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  134583. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  134584. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  134585. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  134586. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134587. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  134588. };
  134589. static float _vq_quantthresh__44u5__p8_1[] = {
  134590. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134591. 3.5, 4.5,
  134592. };
  134593. static long _vq_quantmap__44u5__p8_1[] = {
  134594. 9, 7, 5, 3, 1, 0, 2, 4,
  134595. 6, 8, 10,
  134596. };
  134597. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  134598. _vq_quantthresh__44u5__p8_1,
  134599. _vq_quantmap__44u5__p8_1,
  134600. 11,
  134601. 11
  134602. };
  134603. static static_codebook _44u5__p8_1 = {
  134604. 2, 121,
  134605. _vq_lengthlist__44u5__p8_1,
  134606. 1, -531365888, 1611661312, 4, 0,
  134607. _vq_quantlist__44u5__p8_1,
  134608. NULL,
  134609. &_vq_auxt__44u5__p8_1,
  134610. NULL,
  134611. 0
  134612. };
  134613. static long _vq_quantlist__44u5__p9_0[] = {
  134614. 6,
  134615. 5,
  134616. 7,
  134617. 4,
  134618. 8,
  134619. 3,
  134620. 9,
  134621. 2,
  134622. 10,
  134623. 1,
  134624. 11,
  134625. 0,
  134626. 12,
  134627. };
  134628. static long _vq_lengthlist__44u5__p9_0[] = {
  134629. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  134630. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  134631. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  134632. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  134633. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134634. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134635. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134636. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  134637. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  134638. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134639. 12,12,12,12,12,12,12,12,12,
  134640. };
  134641. static float _vq_quantthresh__44u5__p9_0[] = {
  134642. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134643. 637.5, 892.5, 1147.5, 1402.5,
  134644. };
  134645. static long _vq_quantmap__44u5__p9_0[] = {
  134646. 11, 9, 7, 5, 3, 1, 0, 2,
  134647. 4, 6, 8, 10, 12,
  134648. };
  134649. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  134650. _vq_quantthresh__44u5__p9_0,
  134651. _vq_quantmap__44u5__p9_0,
  134652. 13,
  134653. 13
  134654. };
  134655. static static_codebook _44u5__p9_0 = {
  134656. 2, 169,
  134657. _vq_lengthlist__44u5__p9_0,
  134658. 1, -514332672, 1627381760, 4, 0,
  134659. _vq_quantlist__44u5__p9_0,
  134660. NULL,
  134661. &_vq_auxt__44u5__p9_0,
  134662. NULL,
  134663. 0
  134664. };
  134665. static long _vq_quantlist__44u5__p9_1[] = {
  134666. 7,
  134667. 6,
  134668. 8,
  134669. 5,
  134670. 9,
  134671. 4,
  134672. 10,
  134673. 3,
  134674. 11,
  134675. 2,
  134676. 12,
  134677. 1,
  134678. 13,
  134679. 0,
  134680. 14,
  134681. };
  134682. static long _vq_lengthlist__44u5__p9_1[] = {
  134683. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  134684. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  134685. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  134686. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  134687. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  134688. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  134689. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  134690. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  134691. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  134692. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  134693. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  134694. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  134695. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  134696. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  134697. 14,
  134698. };
  134699. static float _vq_quantthresh__44u5__p9_1[] = {
  134700. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134701. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134702. };
  134703. static long _vq_quantmap__44u5__p9_1[] = {
  134704. 13, 11, 9, 7, 5, 3, 1, 0,
  134705. 2, 4, 6, 8, 10, 12, 14,
  134706. };
  134707. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  134708. _vq_quantthresh__44u5__p9_1,
  134709. _vq_quantmap__44u5__p9_1,
  134710. 15,
  134711. 15
  134712. };
  134713. static static_codebook _44u5__p9_1 = {
  134714. 2, 225,
  134715. _vq_lengthlist__44u5__p9_1,
  134716. 1, -522338304, 1620115456, 4, 0,
  134717. _vq_quantlist__44u5__p9_1,
  134718. NULL,
  134719. &_vq_auxt__44u5__p9_1,
  134720. NULL,
  134721. 0
  134722. };
  134723. static long _vq_quantlist__44u5__p9_2[] = {
  134724. 8,
  134725. 7,
  134726. 9,
  134727. 6,
  134728. 10,
  134729. 5,
  134730. 11,
  134731. 4,
  134732. 12,
  134733. 3,
  134734. 13,
  134735. 2,
  134736. 14,
  134737. 1,
  134738. 15,
  134739. 0,
  134740. 16,
  134741. };
  134742. static long _vq_lengthlist__44u5__p9_2[] = {
  134743. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134744. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134745. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134746. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134747. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134748. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  134749. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  134750. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  134751. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134752. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  134753. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  134754. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  134755. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134756. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134757. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134758. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134759. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  134760. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  134761. 10,
  134762. };
  134763. static float _vq_quantthresh__44u5__p9_2[] = {
  134764. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134765. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134766. };
  134767. static long _vq_quantmap__44u5__p9_2[] = {
  134768. 15, 13, 11, 9, 7, 5, 3, 1,
  134769. 0, 2, 4, 6, 8, 10, 12, 14,
  134770. 16,
  134771. };
  134772. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  134773. _vq_quantthresh__44u5__p9_2,
  134774. _vq_quantmap__44u5__p9_2,
  134775. 17,
  134776. 17
  134777. };
  134778. static static_codebook _44u5__p9_2 = {
  134779. 2, 289,
  134780. _vq_lengthlist__44u5__p9_2,
  134781. 1, -529530880, 1611661312, 5, 0,
  134782. _vq_quantlist__44u5__p9_2,
  134783. NULL,
  134784. &_vq_auxt__44u5__p9_2,
  134785. NULL,
  134786. 0
  134787. };
  134788. static long _huff_lengthlist__44u5__short[] = {
  134789. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  134790. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  134791. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  134792. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  134793. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  134794. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  134795. 6, 8,15,17,
  134796. };
  134797. static static_codebook _huff_book__44u5__short = {
  134798. 2, 100,
  134799. _huff_lengthlist__44u5__short,
  134800. 0, 0, 0, 0, 0,
  134801. NULL,
  134802. NULL,
  134803. NULL,
  134804. NULL,
  134805. 0
  134806. };
  134807. static long _huff_lengthlist__44u6__long[] = {
  134808. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  134809. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  134810. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  134811. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  134812. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  134813. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  134814. 13, 8, 7, 7,
  134815. };
  134816. static static_codebook _huff_book__44u6__long = {
  134817. 2, 100,
  134818. _huff_lengthlist__44u6__long,
  134819. 0, 0, 0, 0, 0,
  134820. NULL,
  134821. NULL,
  134822. NULL,
  134823. NULL,
  134824. 0
  134825. };
  134826. static long _vq_quantlist__44u6__p1_0[] = {
  134827. 1,
  134828. 0,
  134829. 2,
  134830. };
  134831. static long _vq_lengthlist__44u6__p1_0[] = {
  134832. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134833. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134834. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134835. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  134836. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134837. 12,
  134838. };
  134839. static float _vq_quantthresh__44u6__p1_0[] = {
  134840. -0.5, 0.5,
  134841. };
  134842. static long _vq_quantmap__44u6__p1_0[] = {
  134843. 1, 0, 2,
  134844. };
  134845. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  134846. _vq_quantthresh__44u6__p1_0,
  134847. _vq_quantmap__44u6__p1_0,
  134848. 3,
  134849. 3
  134850. };
  134851. static static_codebook _44u6__p1_0 = {
  134852. 4, 81,
  134853. _vq_lengthlist__44u6__p1_0,
  134854. 1, -535822336, 1611661312, 2, 0,
  134855. _vq_quantlist__44u6__p1_0,
  134856. NULL,
  134857. &_vq_auxt__44u6__p1_0,
  134858. NULL,
  134859. 0
  134860. };
  134861. static long _vq_quantlist__44u6__p2_0[] = {
  134862. 1,
  134863. 0,
  134864. 2,
  134865. };
  134866. static long _vq_lengthlist__44u6__p2_0[] = {
  134867. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134868. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134869. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  134870. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134871. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134872. 9,
  134873. };
  134874. static float _vq_quantthresh__44u6__p2_0[] = {
  134875. -0.5, 0.5,
  134876. };
  134877. static long _vq_quantmap__44u6__p2_0[] = {
  134878. 1, 0, 2,
  134879. };
  134880. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  134881. _vq_quantthresh__44u6__p2_0,
  134882. _vq_quantmap__44u6__p2_0,
  134883. 3,
  134884. 3
  134885. };
  134886. static static_codebook _44u6__p2_0 = {
  134887. 4, 81,
  134888. _vq_lengthlist__44u6__p2_0,
  134889. 1, -535822336, 1611661312, 2, 0,
  134890. _vq_quantlist__44u6__p2_0,
  134891. NULL,
  134892. &_vq_auxt__44u6__p2_0,
  134893. NULL,
  134894. 0
  134895. };
  134896. static long _vq_quantlist__44u6__p3_0[] = {
  134897. 2,
  134898. 1,
  134899. 3,
  134900. 0,
  134901. 4,
  134902. };
  134903. static long _vq_lengthlist__44u6__p3_0[] = {
  134904. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134905. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  134906. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134907. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  134908. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  134909. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  134910. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  134911. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  134912. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  134913. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134914. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  134915. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134916. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  134917. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  134918. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  134919. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  134920. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134921. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  134922. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  134923. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  134924. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  134925. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  134926. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  134927. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  134928. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  134929. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  134930. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  134931. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  134932. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  134933. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  134934. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  134935. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  134936. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  134937. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  134938. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  134939. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  134940. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  134941. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  134942. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  134943. 19,
  134944. };
  134945. static float _vq_quantthresh__44u6__p3_0[] = {
  134946. -1.5, -0.5, 0.5, 1.5,
  134947. };
  134948. static long _vq_quantmap__44u6__p3_0[] = {
  134949. 3, 1, 0, 2, 4,
  134950. };
  134951. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  134952. _vq_quantthresh__44u6__p3_0,
  134953. _vq_quantmap__44u6__p3_0,
  134954. 5,
  134955. 5
  134956. };
  134957. static static_codebook _44u6__p3_0 = {
  134958. 4, 625,
  134959. _vq_lengthlist__44u6__p3_0,
  134960. 1, -533725184, 1611661312, 3, 0,
  134961. _vq_quantlist__44u6__p3_0,
  134962. NULL,
  134963. &_vq_auxt__44u6__p3_0,
  134964. NULL,
  134965. 0
  134966. };
  134967. static long _vq_quantlist__44u6__p4_0[] = {
  134968. 2,
  134969. 1,
  134970. 3,
  134971. 0,
  134972. 4,
  134973. };
  134974. static long _vq_lengthlist__44u6__p4_0[] = {
  134975. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134976. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134977. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  134978. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  134979. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  134980. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  134981. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  134982. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  134983. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  134984. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  134985. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  134986. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  134987. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134988. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  134989. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  134990. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  134991. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  134992. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  134993. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134994. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  134995. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  134996. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  134997. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  134998. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  134999. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135000. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135001. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135002. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135003. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135004. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135005. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135006. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135007. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135008. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135009. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135010. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135011. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135012. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135013. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135014. 13,
  135015. };
  135016. static float _vq_quantthresh__44u6__p4_0[] = {
  135017. -1.5, -0.5, 0.5, 1.5,
  135018. };
  135019. static long _vq_quantmap__44u6__p4_0[] = {
  135020. 3, 1, 0, 2, 4,
  135021. };
  135022. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135023. _vq_quantthresh__44u6__p4_0,
  135024. _vq_quantmap__44u6__p4_0,
  135025. 5,
  135026. 5
  135027. };
  135028. static static_codebook _44u6__p4_0 = {
  135029. 4, 625,
  135030. _vq_lengthlist__44u6__p4_0,
  135031. 1, -533725184, 1611661312, 3, 0,
  135032. _vq_quantlist__44u6__p4_0,
  135033. NULL,
  135034. &_vq_auxt__44u6__p4_0,
  135035. NULL,
  135036. 0
  135037. };
  135038. static long _vq_quantlist__44u6__p5_0[] = {
  135039. 4,
  135040. 3,
  135041. 5,
  135042. 2,
  135043. 6,
  135044. 1,
  135045. 7,
  135046. 0,
  135047. 8,
  135048. };
  135049. static long _vq_lengthlist__44u6__p5_0[] = {
  135050. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135051. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135052. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135053. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135054. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135055. 14,
  135056. };
  135057. static float _vq_quantthresh__44u6__p5_0[] = {
  135058. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135059. };
  135060. static long _vq_quantmap__44u6__p5_0[] = {
  135061. 7, 5, 3, 1, 0, 2, 4, 6,
  135062. 8,
  135063. };
  135064. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135065. _vq_quantthresh__44u6__p5_0,
  135066. _vq_quantmap__44u6__p5_0,
  135067. 9,
  135068. 9
  135069. };
  135070. static static_codebook _44u6__p5_0 = {
  135071. 2, 81,
  135072. _vq_lengthlist__44u6__p5_0,
  135073. 1, -531628032, 1611661312, 4, 0,
  135074. _vq_quantlist__44u6__p5_0,
  135075. NULL,
  135076. &_vq_auxt__44u6__p5_0,
  135077. NULL,
  135078. 0
  135079. };
  135080. static long _vq_quantlist__44u6__p6_0[] = {
  135081. 4,
  135082. 3,
  135083. 5,
  135084. 2,
  135085. 6,
  135086. 1,
  135087. 7,
  135088. 0,
  135089. 8,
  135090. };
  135091. static long _vq_lengthlist__44u6__p6_0[] = {
  135092. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135093. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135094. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135095. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135096. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135097. 12,
  135098. };
  135099. static float _vq_quantthresh__44u6__p6_0[] = {
  135100. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135101. };
  135102. static long _vq_quantmap__44u6__p6_0[] = {
  135103. 7, 5, 3, 1, 0, 2, 4, 6,
  135104. 8,
  135105. };
  135106. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135107. _vq_quantthresh__44u6__p6_0,
  135108. _vq_quantmap__44u6__p6_0,
  135109. 9,
  135110. 9
  135111. };
  135112. static static_codebook _44u6__p6_0 = {
  135113. 2, 81,
  135114. _vq_lengthlist__44u6__p6_0,
  135115. 1, -531628032, 1611661312, 4, 0,
  135116. _vq_quantlist__44u6__p6_0,
  135117. NULL,
  135118. &_vq_auxt__44u6__p6_0,
  135119. NULL,
  135120. 0
  135121. };
  135122. static long _vq_quantlist__44u6__p7_0[] = {
  135123. 1,
  135124. 0,
  135125. 2,
  135126. };
  135127. static long _vq_lengthlist__44u6__p7_0[] = {
  135128. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135129. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135130. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135131. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135132. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135133. 10,
  135134. };
  135135. static float _vq_quantthresh__44u6__p7_0[] = {
  135136. -5.5, 5.5,
  135137. };
  135138. static long _vq_quantmap__44u6__p7_0[] = {
  135139. 1, 0, 2,
  135140. };
  135141. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135142. _vq_quantthresh__44u6__p7_0,
  135143. _vq_quantmap__44u6__p7_0,
  135144. 3,
  135145. 3
  135146. };
  135147. static static_codebook _44u6__p7_0 = {
  135148. 4, 81,
  135149. _vq_lengthlist__44u6__p7_0,
  135150. 1, -529137664, 1618345984, 2, 0,
  135151. _vq_quantlist__44u6__p7_0,
  135152. NULL,
  135153. &_vq_auxt__44u6__p7_0,
  135154. NULL,
  135155. 0
  135156. };
  135157. static long _vq_quantlist__44u6__p7_1[] = {
  135158. 5,
  135159. 4,
  135160. 6,
  135161. 3,
  135162. 7,
  135163. 2,
  135164. 8,
  135165. 1,
  135166. 9,
  135167. 0,
  135168. 10,
  135169. };
  135170. static long _vq_lengthlist__44u6__p7_1[] = {
  135171. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135172. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135173. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135174. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135175. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135176. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135177. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135178. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135179. };
  135180. static float _vq_quantthresh__44u6__p7_1[] = {
  135181. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135182. 3.5, 4.5,
  135183. };
  135184. static long _vq_quantmap__44u6__p7_1[] = {
  135185. 9, 7, 5, 3, 1, 0, 2, 4,
  135186. 6, 8, 10,
  135187. };
  135188. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135189. _vq_quantthresh__44u6__p7_1,
  135190. _vq_quantmap__44u6__p7_1,
  135191. 11,
  135192. 11
  135193. };
  135194. static static_codebook _44u6__p7_1 = {
  135195. 2, 121,
  135196. _vq_lengthlist__44u6__p7_1,
  135197. 1, -531365888, 1611661312, 4, 0,
  135198. _vq_quantlist__44u6__p7_1,
  135199. NULL,
  135200. &_vq_auxt__44u6__p7_1,
  135201. NULL,
  135202. 0
  135203. };
  135204. static long _vq_quantlist__44u6__p8_0[] = {
  135205. 5,
  135206. 4,
  135207. 6,
  135208. 3,
  135209. 7,
  135210. 2,
  135211. 8,
  135212. 1,
  135213. 9,
  135214. 0,
  135215. 10,
  135216. };
  135217. static long _vq_lengthlist__44u6__p8_0[] = {
  135218. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135219. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135220. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135221. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135222. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135223. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135224. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135225. 12,13,13,14,14,14,15,15,15,
  135226. };
  135227. static float _vq_quantthresh__44u6__p8_0[] = {
  135228. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135229. 38.5, 49.5,
  135230. };
  135231. static long _vq_quantmap__44u6__p8_0[] = {
  135232. 9, 7, 5, 3, 1, 0, 2, 4,
  135233. 6, 8, 10,
  135234. };
  135235. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135236. _vq_quantthresh__44u6__p8_0,
  135237. _vq_quantmap__44u6__p8_0,
  135238. 11,
  135239. 11
  135240. };
  135241. static static_codebook _44u6__p8_0 = {
  135242. 2, 121,
  135243. _vq_lengthlist__44u6__p8_0,
  135244. 1, -524582912, 1618345984, 4, 0,
  135245. _vq_quantlist__44u6__p8_0,
  135246. NULL,
  135247. &_vq_auxt__44u6__p8_0,
  135248. NULL,
  135249. 0
  135250. };
  135251. static long _vq_quantlist__44u6__p8_1[] = {
  135252. 5,
  135253. 4,
  135254. 6,
  135255. 3,
  135256. 7,
  135257. 2,
  135258. 8,
  135259. 1,
  135260. 9,
  135261. 0,
  135262. 10,
  135263. };
  135264. static long _vq_lengthlist__44u6__p8_1[] = {
  135265. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135266. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135267. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135268. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135269. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135270. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135271. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135272. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135273. };
  135274. static float _vq_quantthresh__44u6__p8_1[] = {
  135275. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135276. 3.5, 4.5,
  135277. };
  135278. static long _vq_quantmap__44u6__p8_1[] = {
  135279. 9, 7, 5, 3, 1, 0, 2, 4,
  135280. 6, 8, 10,
  135281. };
  135282. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135283. _vq_quantthresh__44u6__p8_1,
  135284. _vq_quantmap__44u6__p8_1,
  135285. 11,
  135286. 11
  135287. };
  135288. static static_codebook _44u6__p8_1 = {
  135289. 2, 121,
  135290. _vq_lengthlist__44u6__p8_1,
  135291. 1, -531365888, 1611661312, 4, 0,
  135292. _vq_quantlist__44u6__p8_1,
  135293. NULL,
  135294. &_vq_auxt__44u6__p8_1,
  135295. NULL,
  135296. 0
  135297. };
  135298. static long _vq_quantlist__44u6__p9_0[] = {
  135299. 7,
  135300. 6,
  135301. 8,
  135302. 5,
  135303. 9,
  135304. 4,
  135305. 10,
  135306. 3,
  135307. 11,
  135308. 2,
  135309. 12,
  135310. 1,
  135311. 13,
  135312. 0,
  135313. 14,
  135314. };
  135315. static long _vq_lengthlist__44u6__p9_0[] = {
  135316. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135317. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135318. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135319. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135320. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135321. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135322. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135323. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135324. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135325. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135326. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135327. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135328. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135329. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135330. 14,
  135331. };
  135332. static float _vq_quantthresh__44u6__p9_0[] = {
  135333. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135334. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135335. };
  135336. static long _vq_quantmap__44u6__p9_0[] = {
  135337. 13, 11, 9, 7, 5, 3, 1, 0,
  135338. 2, 4, 6, 8, 10, 12, 14,
  135339. };
  135340. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135341. _vq_quantthresh__44u6__p9_0,
  135342. _vq_quantmap__44u6__p9_0,
  135343. 15,
  135344. 15
  135345. };
  135346. static static_codebook _44u6__p9_0 = {
  135347. 2, 225,
  135348. _vq_lengthlist__44u6__p9_0,
  135349. 1, -514071552, 1627381760, 4, 0,
  135350. _vq_quantlist__44u6__p9_0,
  135351. NULL,
  135352. &_vq_auxt__44u6__p9_0,
  135353. NULL,
  135354. 0
  135355. };
  135356. static long _vq_quantlist__44u6__p9_1[] = {
  135357. 7,
  135358. 6,
  135359. 8,
  135360. 5,
  135361. 9,
  135362. 4,
  135363. 10,
  135364. 3,
  135365. 11,
  135366. 2,
  135367. 12,
  135368. 1,
  135369. 13,
  135370. 0,
  135371. 14,
  135372. };
  135373. static long _vq_lengthlist__44u6__p9_1[] = {
  135374. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135375. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135376. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135377. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135378. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135379. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135380. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135381. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135382. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135383. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135384. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135385. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135386. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135387. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135388. 13,
  135389. };
  135390. static float _vq_quantthresh__44u6__p9_1[] = {
  135391. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135392. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135393. };
  135394. static long _vq_quantmap__44u6__p9_1[] = {
  135395. 13, 11, 9, 7, 5, 3, 1, 0,
  135396. 2, 4, 6, 8, 10, 12, 14,
  135397. };
  135398. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135399. _vq_quantthresh__44u6__p9_1,
  135400. _vq_quantmap__44u6__p9_1,
  135401. 15,
  135402. 15
  135403. };
  135404. static static_codebook _44u6__p9_1 = {
  135405. 2, 225,
  135406. _vq_lengthlist__44u6__p9_1,
  135407. 1, -522338304, 1620115456, 4, 0,
  135408. _vq_quantlist__44u6__p9_1,
  135409. NULL,
  135410. &_vq_auxt__44u6__p9_1,
  135411. NULL,
  135412. 0
  135413. };
  135414. static long _vq_quantlist__44u6__p9_2[] = {
  135415. 8,
  135416. 7,
  135417. 9,
  135418. 6,
  135419. 10,
  135420. 5,
  135421. 11,
  135422. 4,
  135423. 12,
  135424. 3,
  135425. 13,
  135426. 2,
  135427. 14,
  135428. 1,
  135429. 15,
  135430. 0,
  135431. 16,
  135432. };
  135433. static long _vq_lengthlist__44u6__p9_2[] = {
  135434. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135435. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135436. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135437. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135438. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135439. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135440. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135441. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135442. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135443. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135444. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135445. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135446. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135447. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135448. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135449. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135450. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135451. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135452. 10,
  135453. };
  135454. static float _vq_quantthresh__44u6__p9_2[] = {
  135455. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135456. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135457. };
  135458. static long _vq_quantmap__44u6__p9_2[] = {
  135459. 15, 13, 11, 9, 7, 5, 3, 1,
  135460. 0, 2, 4, 6, 8, 10, 12, 14,
  135461. 16,
  135462. };
  135463. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135464. _vq_quantthresh__44u6__p9_2,
  135465. _vq_quantmap__44u6__p9_2,
  135466. 17,
  135467. 17
  135468. };
  135469. static static_codebook _44u6__p9_2 = {
  135470. 2, 289,
  135471. _vq_lengthlist__44u6__p9_2,
  135472. 1, -529530880, 1611661312, 5, 0,
  135473. _vq_quantlist__44u6__p9_2,
  135474. NULL,
  135475. &_vq_auxt__44u6__p9_2,
  135476. NULL,
  135477. 0
  135478. };
  135479. static long _huff_lengthlist__44u6__short[] = {
  135480. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135481. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135482. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135483. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135484. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135485. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135486. 7, 6, 9,16,
  135487. };
  135488. static static_codebook _huff_book__44u6__short = {
  135489. 2, 100,
  135490. _huff_lengthlist__44u6__short,
  135491. 0, 0, 0, 0, 0,
  135492. NULL,
  135493. NULL,
  135494. NULL,
  135495. NULL,
  135496. 0
  135497. };
  135498. static long _huff_lengthlist__44u7__long[] = {
  135499. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135500. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135501. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135502. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135503. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135504. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135505. 12, 8, 6, 7,
  135506. };
  135507. static static_codebook _huff_book__44u7__long = {
  135508. 2, 100,
  135509. _huff_lengthlist__44u7__long,
  135510. 0, 0, 0, 0, 0,
  135511. NULL,
  135512. NULL,
  135513. NULL,
  135514. NULL,
  135515. 0
  135516. };
  135517. static long _vq_quantlist__44u7__p1_0[] = {
  135518. 1,
  135519. 0,
  135520. 2,
  135521. };
  135522. static long _vq_lengthlist__44u7__p1_0[] = {
  135523. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135524. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  135525. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135526. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  135527. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  135528. 12,
  135529. };
  135530. static float _vq_quantthresh__44u7__p1_0[] = {
  135531. -0.5, 0.5,
  135532. };
  135533. static long _vq_quantmap__44u7__p1_0[] = {
  135534. 1, 0, 2,
  135535. };
  135536. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  135537. _vq_quantthresh__44u7__p1_0,
  135538. _vq_quantmap__44u7__p1_0,
  135539. 3,
  135540. 3
  135541. };
  135542. static static_codebook _44u7__p1_0 = {
  135543. 4, 81,
  135544. _vq_lengthlist__44u7__p1_0,
  135545. 1, -535822336, 1611661312, 2, 0,
  135546. _vq_quantlist__44u7__p1_0,
  135547. NULL,
  135548. &_vq_auxt__44u7__p1_0,
  135549. NULL,
  135550. 0
  135551. };
  135552. static long _vq_quantlist__44u7__p2_0[] = {
  135553. 1,
  135554. 0,
  135555. 2,
  135556. };
  135557. static long _vq_lengthlist__44u7__p2_0[] = {
  135558. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135559. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135560. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  135561. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135562. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135563. 9,
  135564. };
  135565. static float _vq_quantthresh__44u7__p2_0[] = {
  135566. -0.5, 0.5,
  135567. };
  135568. static long _vq_quantmap__44u7__p2_0[] = {
  135569. 1, 0, 2,
  135570. };
  135571. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  135572. _vq_quantthresh__44u7__p2_0,
  135573. _vq_quantmap__44u7__p2_0,
  135574. 3,
  135575. 3
  135576. };
  135577. static static_codebook _44u7__p2_0 = {
  135578. 4, 81,
  135579. _vq_lengthlist__44u7__p2_0,
  135580. 1, -535822336, 1611661312, 2, 0,
  135581. _vq_quantlist__44u7__p2_0,
  135582. NULL,
  135583. &_vq_auxt__44u7__p2_0,
  135584. NULL,
  135585. 0
  135586. };
  135587. static long _vq_quantlist__44u7__p3_0[] = {
  135588. 2,
  135589. 1,
  135590. 3,
  135591. 0,
  135592. 4,
  135593. };
  135594. static long _vq_lengthlist__44u7__p3_0[] = {
  135595. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135596. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135597. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135598. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  135599. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  135600. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  135601. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  135602. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  135603. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  135604. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  135605. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  135606. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  135607. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  135608. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  135609. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  135610. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  135611. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  135612. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135613. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  135614. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  135615. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  135616. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  135617. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  135618. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  135619. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  135620. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  135621. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  135622. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  135623. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  135624. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  135625. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  135626. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  135627. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  135628. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  135629. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  135630. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  135631. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  135632. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  135633. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  135634. 0,
  135635. };
  135636. static float _vq_quantthresh__44u7__p3_0[] = {
  135637. -1.5, -0.5, 0.5, 1.5,
  135638. };
  135639. static long _vq_quantmap__44u7__p3_0[] = {
  135640. 3, 1, 0, 2, 4,
  135641. };
  135642. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  135643. _vq_quantthresh__44u7__p3_0,
  135644. _vq_quantmap__44u7__p3_0,
  135645. 5,
  135646. 5
  135647. };
  135648. static static_codebook _44u7__p3_0 = {
  135649. 4, 625,
  135650. _vq_lengthlist__44u7__p3_0,
  135651. 1, -533725184, 1611661312, 3, 0,
  135652. _vq_quantlist__44u7__p3_0,
  135653. NULL,
  135654. &_vq_auxt__44u7__p3_0,
  135655. NULL,
  135656. 0
  135657. };
  135658. static long _vq_quantlist__44u7__p4_0[] = {
  135659. 2,
  135660. 1,
  135661. 3,
  135662. 0,
  135663. 4,
  135664. };
  135665. static long _vq_lengthlist__44u7__p4_0[] = {
  135666. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135667. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  135668. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  135669. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  135670. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135671. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  135672. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  135673. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  135674. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135675. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135676. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  135677. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135678. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135679. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  135680. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  135681. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135682. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  135683. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135684. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  135685. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  135686. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135687. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135688. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  135689. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135690. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  135691. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  135692. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135693. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  135694. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  135695. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  135696. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  135697. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135698. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  135699. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135700. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  135701. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135702. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  135703. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  135704. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  135705. 14,
  135706. };
  135707. static float _vq_quantthresh__44u7__p4_0[] = {
  135708. -1.5, -0.5, 0.5, 1.5,
  135709. };
  135710. static long _vq_quantmap__44u7__p4_0[] = {
  135711. 3, 1, 0, 2, 4,
  135712. };
  135713. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  135714. _vq_quantthresh__44u7__p4_0,
  135715. _vq_quantmap__44u7__p4_0,
  135716. 5,
  135717. 5
  135718. };
  135719. static static_codebook _44u7__p4_0 = {
  135720. 4, 625,
  135721. _vq_lengthlist__44u7__p4_0,
  135722. 1, -533725184, 1611661312, 3, 0,
  135723. _vq_quantlist__44u7__p4_0,
  135724. NULL,
  135725. &_vq_auxt__44u7__p4_0,
  135726. NULL,
  135727. 0
  135728. };
  135729. static long _vq_quantlist__44u7__p5_0[] = {
  135730. 4,
  135731. 3,
  135732. 5,
  135733. 2,
  135734. 6,
  135735. 1,
  135736. 7,
  135737. 0,
  135738. 8,
  135739. };
  135740. static long _vq_lengthlist__44u7__p5_0[] = {
  135741. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135742. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  135743. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  135744. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  135745. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  135746. 14,
  135747. };
  135748. static float _vq_quantthresh__44u7__p5_0[] = {
  135749. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135750. };
  135751. static long _vq_quantmap__44u7__p5_0[] = {
  135752. 7, 5, 3, 1, 0, 2, 4, 6,
  135753. 8,
  135754. };
  135755. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  135756. _vq_quantthresh__44u7__p5_0,
  135757. _vq_quantmap__44u7__p5_0,
  135758. 9,
  135759. 9
  135760. };
  135761. static static_codebook _44u7__p5_0 = {
  135762. 2, 81,
  135763. _vq_lengthlist__44u7__p5_0,
  135764. 1, -531628032, 1611661312, 4, 0,
  135765. _vq_quantlist__44u7__p5_0,
  135766. NULL,
  135767. &_vq_auxt__44u7__p5_0,
  135768. NULL,
  135769. 0
  135770. };
  135771. static long _vq_quantlist__44u7__p6_0[] = {
  135772. 4,
  135773. 3,
  135774. 5,
  135775. 2,
  135776. 6,
  135777. 1,
  135778. 7,
  135779. 0,
  135780. 8,
  135781. };
  135782. static long _vq_lengthlist__44u7__p6_0[] = {
  135783. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  135784. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  135785. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135786. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  135787. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  135788. 12,
  135789. };
  135790. static float _vq_quantthresh__44u7__p6_0[] = {
  135791. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135792. };
  135793. static long _vq_quantmap__44u7__p6_0[] = {
  135794. 7, 5, 3, 1, 0, 2, 4, 6,
  135795. 8,
  135796. };
  135797. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  135798. _vq_quantthresh__44u7__p6_0,
  135799. _vq_quantmap__44u7__p6_0,
  135800. 9,
  135801. 9
  135802. };
  135803. static static_codebook _44u7__p6_0 = {
  135804. 2, 81,
  135805. _vq_lengthlist__44u7__p6_0,
  135806. 1, -531628032, 1611661312, 4, 0,
  135807. _vq_quantlist__44u7__p6_0,
  135808. NULL,
  135809. &_vq_auxt__44u7__p6_0,
  135810. NULL,
  135811. 0
  135812. };
  135813. static long _vq_quantlist__44u7__p7_0[] = {
  135814. 1,
  135815. 0,
  135816. 2,
  135817. };
  135818. static long _vq_lengthlist__44u7__p7_0[] = {
  135819. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  135820. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  135821. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  135822. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  135823. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  135824. 10,
  135825. };
  135826. static float _vq_quantthresh__44u7__p7_0[] = {
  135827. -5.5, 5.5,
  135828. };
  135829. static long _vq_quantmap__44u7__p7_0[] = {
  135830. 1, 0, 2,
  135831. };
  135832. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  135833. _vq_quantthresh__44u7__p7_0,
  135834. _vq_quantmap__44u7__p7_0,
  135835. 3,
  135836. 3
  135837. };
  135838. static static_codebook _44u7__p7_0 = {
  135839. 4, 81,
  135840. _vq_lengthlist__44u7__p7_0,
  135841. 1, -529137664, 1618345984, 2, 0,
  135842. _vq_quantlist__44u7__p7_0,
  135843. NULL,
  135844. &_vq_auxt__44u7__p7_0,
  135845. NULL,
  135846. 0
  135847. };
  135848. static long _vq_quantlist__44u7__p7_1[] = {
  135849. 5,
  135850. 4,
  135851. 6,
  135852. 3,
  135853. 7,
  135854. 2,
  135855. 8,
  135856. 1,
  135857. 9,
  135858. 0,
  135859. 10,
  135860. };
  135861. static long _vq_lengthlist__44u7__p7_1[] = {
  135862. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  135863. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  135864. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  135865. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  135866. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  135867. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135868. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  135869. 8, 9, 9, 9, 9, 9,10,10,10,
  135870. };
  135871. static float _vq_quantthresh__44u7__p7_1[] = {
  135872. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135873. 3.5, 4.5,
  135874. };
  135875. static long _vq_quantmap__44u7__p7_1[] = {
  135876. 9, 7, 5, 3, 1, 0, 2, 4,
  135877. 6, 8, 10,
  135878. };
  135879. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  135880. _vq_quantthresh__44u7__p7_1,
  135881. _vq_quantmap__44u7__p7_1,
  135882. 11,
  135883. 11
  135884. };
  135885. static static_codebook _44u7__p7_1 = {
  135886. 2, 121,
  135887. _vq_lengthlist__44u7__p7_1,
  135888. 1, -531365888, 1611661312, 4, 0,
  135889. _vq_quantlist__44u7__p7_1,
  135890. NULL,
  135891. &_vq_auxt__44u7__p7_1,
  135892. NULL,
  135893. 0
  135894. };
  135895. static long _vq_quantlist__44u7__p8_0[] = {
  135896. 5,
  135897. 4,
  135898. 6,
  135899. 3,
  135900. 7,
  135901. 2,
  135902. 8,
  135903. 1,
  135904. 9,
  135905. 0,
  135906. 10,
  135907. };
  135908. static long _vq_lengthlist__44u7__p8_0[] = {
  135909. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  135910. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  135911. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  135912. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  135913. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  135914. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  135915. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  135916. 12,13,13,14,14,15,15,15,16,
  135917. };
  135918. static float _vq_quantthresh__44u7__p8_0[] = {
  135919. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135920. 38.5, 49.5,
  135921. };
  135922. static long _vq_quantmap__44u7__p8_0[] = {
  135923. 9, 7, 5, 3, 1, 0, 2, 4,
  135924. 6, 8, 10,
  135925. };
  135926. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  135927. _vq_quantthresh__44u7__p8_0,
  135928. _vq_quantmap__44u7__p8_0,
  135929. 11,
  135930. 11
  135931. };
  135932. static static_codebook _44u7__p8_0 = {
  135933. 2, 121,
  135934. _vq_lengthlist__44u7__p8_0,
  135935. 1, -524582912, 1618345984, 4, 0,
  135936. _vq_quantlist__44u7__p8_0,
  135937. NULL,
  135938. &_vq_auxt__44u7__p8_0,
  135939. NULL,
  135940. 0
  135941. };
  135942. static long _vq_quantlist__44u7__p8_1[] = {
  135943. 5,
  135944. 4,
  135945. 6,
  135946. 3,
  135947. 7,
  135948. 2,
  135949. 8,
  135950. 1,
  135951. 9,
  135952. 0,
  135953. 10,
  135954. };
  135955. static long _vq_lengthlist__44u7__p8_1[] = {
  135956. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  135957. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  135958. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  135959. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  135960. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  135961. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  135962. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  135963. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  135964. };
  135965. static float _vq_quantthresh__44u7__p8_1[] = {
  135966. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135967. 3.5, 4.5,
  135968. };
  135969. static long _vq_quantmap__44u7__p8_1[] = {
  135970. 9, 7, 5, 3, 1, 0, 2, 4,
  135971. 6, 8, 10,
  135972. };
  135973. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  135974. _vq_quantthresh__44u7__p8_1,
  135975. _vq_quantmap__44u7__p8_1,
  135976. 11,
  135977. 11
  135978. };
  135979. static static_codebook _44u7__p8_1 = {
  135980. 2, 121,
  135981. _vq_lengthlist__44u7__p8_1,
  135982. 1, -531365888, 1611661312, 4, 0,
  135983. _vq_quantlist__44u7__p8_1,
  135984. NULL,
  135985. &_vq_auxt__44u7__p8_1,
  135986. NULL,
  135987. 0
  135988. };
  135989. static long _vq_quantlist__44u7__p9_0[] = {
  135990. 5,
  135991. 4,
  135992. 6,
  135993. 3,
  135994. 7,
  135995. 2,
  135996. 8,
  135997. 1,
  135998. 9,
  135999. 0,
  136000. 10,
  136001. };
  136002. static long _vq_lengthlist__44u7__p9_0[] = {
  136003. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136004. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136005. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136006. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136007. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136008. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136009. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136010. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136011. };
  136012. static float _vq_quantthresh__44u7__p9_0[] = {
  136013. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136014. 2229.5, 2866.5,
  136015. };
  136016. static long _vq_quantmap__44u7__p9_0[] = {
  136017. 9, 7, 5, 3, 1, 0, 2, 4,
  136018. 6, 8, 10,
  136019. };
  136020. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136021. _vq_quantthresh__44u7__p9_0,
  136022. _vq_quantmap__44u7__p9_0,
  136023. 11,
  136024. 11
  136025. };
  136026. static static_codebook _44u7__p9_0 = {
  136027. 2, 121,
  136028. _vq_lengthlist__44u7__p9_0,
  136029. 1, -512171520, 1630791680, 4, 0,
  136030. _vq_quantlist__44u7__p9_0,
  136031. NULL,
  136032. &_vq_auxt__44u7__p9_0,
  136033. NULL,
  136034. 0
  136035. };
  136036. static long _vq_quantlist__44u7__p9_1[] = {
  136037. 6,
  136038. 5,
  136039. 7,
  136040. 4,
  136041. 8,
  136042. 3,
  136043. 9,
  136044. 2,
  136045. 10,
  136046. 1,
  136047. 11,
  136048. 0,
  136049. 12,
  136050. };
  136051. static long _vq_lengthlist__44u7__p9_1[] = {
  136052. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136053. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136054. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136055. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136056. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136057. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136058. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136059. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136060. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136061. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136062. 15,15,15,15,17,17,16,17,16,
  136063. };
  136064. static float _vq_quantthresh__44u7__p9_1[] = {
  136065. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136066. 122.5, 171.5, 220.5, 269.5,
  136067. };
  136068. static long _vq_quantmap__44u7__p9_1[] = {
  136069. 11, 9, 7, 5, 3, 1, 0, 2,
  136070. 4, 6, 8, 10, 12,
  136071. };
  136072. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136073. _vq_quantthresh__44u7__p9_1,
  136074. _vq_quantmap__44u7__p9_1,
  136075. 13,
  136076. 13
  136077. };
  136078. static static_codebook _44u7__p9_1 = {
  136079. 2, 169,
  136080. _vq_lengthlist__44u7__p9_1,
  136081. 1, -518889472, 1622704128, 4, 0,
  136082. _vq_quantlist__44u7__p9_1,
  136083. NULL,
  136084. &_vq_auxt__44u7__p9_1,
  136085. NULL,
  136086. 0
  136087. };
  136088. static long _vq_quantlist__44u7__p9_2[] = {
  136089. 24,
  136090. 23,
  136091. 25,
  136092. 22,
  136093. 26,
  136094. 21,
  136095. 27,
  136096. 20,
  136097. 28,
  136098. 19,
  136099. 29,
  136100. 18,
  136101. 30,
  136102. 17,
  136103. 31,
  136104. 16,
  136105. 32,
  136106. 15,
  136107. 33,
  136108. 14,
  136109. 34,
  136110. 13,
  136111. 35,
  136112. 12,
  136113. 36,
  136114. 11,
  136115. 37,
  136116. 10,
  136117. 38,
  136118. 9,
  136119. 39,
  136120. 8,
  136121. 40,
  136122. 7,
  136123. 41,
  136124. 6,
  136125. 42,
  136126. 5,
  136127. 43,
  136128. 4,
  136129. 44,
  136130. 3,
  136131. 45,
  136132. 2,
  136133. 46,
  136134. 1,
  136135. 47,
  136136. 0,
  136137. 48,
  136138. };
  136139. static long _vq_lengthlist__44u7__p9_2[] = {
  136140. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136141. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136142. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136143. 8,
  136144. };
  136145. static float _vq_quantthresh__44u7__p9_2[] = {
  136146. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136147. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136148. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136149. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136150. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136151. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136152. };
  136153. static long _vq_quantmap__44u7__p9_2[] = {
  136154. 47, 45, 43, 41, 39, 37, 35, 33,
  136155. 31, 29, 27, 25, 23, 21, 19, 17,
  136156. 15, 13, 11, 9, 7, 5, 3, 1,
  136157. 0, 2, 4, 6, 8, 10, 12, 14,
  136158. 16, 18, 20, 22, 24, 26, 28, 30,
  136159. 32, 34, 36, 38, 40, 42, 44, 46,
  136160. 48,
  136161. };
  136162. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136163. _vq_quantthresh__44u7__p9_2,
  136164. _vq_quantmap__44u7__p9_2,
  136165. 49,
  136166. 49
  136167. };
  136168. static static_codebook _44u7__p9_2 = {
  136169. 1, 49,
  136170. _vq_lengthlist__44u7__p9_2,
  136171. 1, -526909440, 1611661312, 6, 0,
  136172. _vq_quantlist__44u7__p9_2,
  136173. NULL,
  136174. &_vq_auxt__44u7__p9_2,
  136175. NULL,
  136176. 0
  136177. };
  136178. static long _huff_lengthlist__44u7__short[] = {
  136179. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136180. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136181. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136182. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136183. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136184. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136185. 6, 8, 5, 9,
  136186. };
  136187. static static_codebook _huff_book__44u7__short = {
  136188. 2, 100,
  136189. _huff_lengthlist__44u7__short,
  136190. 0, 0, 0, 0, 0,
  136191. NULL,
  136192. NULL,
  136193. NULL,
  136194. NULL,
  136195. 0
  136196. };
  136197. static long _huff_lengthlist__44u8__long[] = {
  136198. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136199. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136200. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136201. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136202. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136203. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136204. 10, 8, 8, 9,
  136205. };
  136206. static static_codebook _huff_book__44u8__long = {
  136207. 2, 100,
  136208. _huff_lengthlist__44u8__long,
  136209. 0, 0, 0, 0, 0,
  136210. NULL,
  136211. NULL,
  136212. NULL,
  136213. NULL,
  136214. 0
  136215. };
  136216. static long _huff_lengthlist__44u8__short[] = {
  136217. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136218. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136219. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136220. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136221. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136222. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136223. 10,10,15,17,
  136224. };
  136225. static static_codebook _huff_book__44u8__short = {
  136226. 2, 100,
  136227. _huff_lengthlist__44u8__short,
  136228. 0, 0, 0, 0, 0,
  136229. NULL,
  136230. NULL,
  136231. NULL,
  136232. NULL,
  136233. 0
  136234. };
  136235. static long _vq_quantlist__44u8_p1_0[] = {
  136236. 1,
  136237. 0,
  136238. 2,
  136239. };
  136240. static long _vq_lengthlist__44u8_p1_0[] = {
  136241. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136242. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136243. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136244. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136245. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136246. 10,
  136247. };
  136248. static float _vq_quantthresh__44u8_p1_0[] = {
  136249. -0.5, 0.5,
  136250. };
  136251. static long _vq_quantmap__44u8_p1_0[] = {
  136252. 1, 0, 2,
  136253. };
  136254. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136255. _vq_quantthresh__44u8_p1_0,
  136256. _vq_quantmap__44u8_p1_0,
  136257. 3,
  136258. 3
  136259. };
  136260. static static_codebook _44u8_p1_0 = {
  136261. 4, 81,
  136262. _vq_lengthlist__44u8_p1_0,
  136263. 1, -535822336, 1611661312, 2, 0,
  136264. _vq_quantlist__44u8_p1_0,
  136265. NULL,
  136266. &_vq_auxt__44u8_p1_0,
  136267. NULL,
  136268. 0
  136269. };
  136270. static long _vq_quantlist__44u8_p2_0[] = {
  136271. 2,
  136272. 1,
  136273. 3,
  136274. 0,
  136275. 4,
  136276. };
  136277. static long _vq_lengthlist__44u8_p2_0[] = {
  136278. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136279. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136280. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136281. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136282. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136283. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136284. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136285. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136286. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136287. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136288. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136289. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136290. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136291. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136292. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136293. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136294. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136295. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136296. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136297. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136298. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136299. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136300. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136301. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136302. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136303. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136304. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136305. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136306. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136307. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136308. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136309. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136310. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136311. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136312. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136313. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136314. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136315. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136316. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136317. 14,
  136318. };
  136319. static float _vq_quantthresh__44u8_p2_0[] = {
  136320. -1.5, -0.5, 0.5, 1.5,
  136321. };
  136322. static long _vq_quantmap__44u8_p2_0[] = {
  136323. 3, 1, 0, 2, 4,
  136324. };
  136325. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136326. _vq_quantthresh__44u8_p2_0,
  136327. _vq_quantmap__44u8_p2_0,
  136328. 5,
  136329. 5
  136330. };
  136331. static static_codebook _44u8_p2_0 = {
  136332. 4, 625,
  136333. _vq_lengthlist__44u8_p2_0,
  136334. 1, -533725184, 1611661312, 3, 0,
  136335. _vq_quantlist__44u8_p2_0,
  136336. NULL,
  136337. &_vq_auxt__44u8_p2_0,
  136338. NULL,
  136339. 0
  136340. };
  136341. static long _vq_quantlist__44u8_p3_0[] = {
  136342. 4,
  136343. 3,
  136344. 5,
  136345. 2,
  136346. 6,
  136347. 1,
  136348. 7,
  136349. 0,
  136350. 8,
  136351. };
  136352. static long _vq_lengthlist__44u8_p3_0[] = {
  136353. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136354. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136355. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136356. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136357. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136358. 12,
  136359. };
  136360. static float _vq_quantthresh__44u8_p3_0[] = {
  136361. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136362. };
  136363. static long _vq_quantmap__44u8_p3_0[] = {
  136364. 7, 5, 3, 1, 0, 2, 4, 6,
  136365. 8,
  136366. };
  136367. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136368. _vq_quantthresh__44u8_p3_0,
  136369. _vq_quantmap__44u8_p3_0,
  136370. 9,
  136371. 9
  136372. };
  136373. static static_codebook _44u8_p3_0 = {
  136374. 2, 81,
  136375. _vq_lengthlist__44u8_p3_0,
  136376. 1, -531628032, 1611661312, 4, 0,
  136377. _vq_quantlist__44u8_p3_0,
  136378. NULL,
  136379. &_vq_auxt__44u8_p3_0,
  136380. NULL,
  136381. 0
  136382. };
  136383. static long _vq_quantlist__44u8_p4_0[] = {
  136384. 8,
  136385. 7,
  136386. 9,
  136387. 6,
  136388. 10,
  136389. 5,
  136390. 11,
  136391. 4,
  136392. 12,
  136393. 3,
  136394. 13,
  136395. 2,
  136396. 14,
  136397. 1,
  136398. 15,
  136399. 0,
  136400. 16,
  136401. };
  136402. static long _vq_lengthlist__44u8_p4_0[] = {
  136403. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136404. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136405. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136406. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136407. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136408. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136409. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136410. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136411. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136412. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136413. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136414. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136415. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136416. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136417. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136418. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136419. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136420. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136421. 14,
  136422. };
  136423. static float _vq_quantthresh__44u8_p4_0[] = {
  136424. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136425. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136426. };
  136427. static long _vq_quantmap__44u8_p4_0[] = {
  136428. 15, 13, 11, 9, 7, 5, 3, 1,
  136429. 0, 2, 4, 6, 8, 10, 12, 14,
  136430. 16,
  136431. };
  136432. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136433. _vq_quantthresh__44u8_p4_0,
  136434. _vq_quantmap__44u8_p4_0,
  136435. 17,
  136436. 17
  136437. };
  136438. static static_codebook _44u8_p4_0 = {
  136439. 2, 289,
  136440. _vq_lengthlist__44u8_p4_0,
  136441. 1, -529530880, 1611661312, 5, 0,
  136442. _vq_quantlist__44u8_p4_0,
  136443. NULL,
  136444. &_vq_auxt__44u8_p4_0,
  136445. NULL,
  136446. 0
  136447. };
  136448. static long _vq_quantlist__44u8_p5_0[] = {
  136449. 1,
  136450. 0,
  136451. 2,
  136452. };
  136453. static long _vq_lengthlist__44u8_p5_0[] = {
  136454. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136455. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136456. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136457. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136458. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136459. 10,
  136460. };
  136461. static float _vq_quantthresh__44u8_p5_0[] = {
  136462. -5.5, 5.5,
  136463. };
  136464. static long _vq_quantmap__44u8_p5_0[] = {
  136465. 1, 0, 2,
  136466. };
  136467. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136468. _vq_quantthresh__44u8_p5_0,
  136469. _vq_quantmap__44u8_p5_0,
  136470. 3,
  136471. 3
  136472. };
  136473. static static_codebook _44u8_p5_0 = {
  136474. 4, 81,
  136475. _vq_lengthlist__44u8_p5_0,
  136476. 1, -529137664, 1618345984, 2, 0,
  136477. _vq_quantlist__44u8_p5_0,
  136478. NULL,
  136479. &_vq_auxt__44u8_p5_0,
  136480. NULL,
  136481. 0
  136482. };
  136483. static long _vq_quantlist__44u8_p5_1[] = {
  136484. 5,
  136485. 4,
  136486. 6,
  136487. 3,
  136488. 7,
  136489. 2,
  136490. 8,
  136491. 1,
  136492. 9,
  136493. 0,
  136494. 10,
  136495. };
  136496. static long _vq_lengthlist__44u8_p5_1[] = {
  136497. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136498. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136499. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136500. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136501. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136502. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136503. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136504. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136505. };
  136506. static float _vq_quantthresh__44u8_p5_1[] = {
  136507. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136508. 3.5, 4.5,
  136509. };
  136510. static long _vq_quantmap__44u8_p5_1[] = {
  136511. 9, 7, 5, 3, 1, 0, 2, 4,
  136512. 6, 8, 10,
  136513. };
  136514. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  136515. _vq_quantthresh__44u8_p5_1,
  136516. _vq_quantmap__44u8_p5_1,
  136517. 11,
  136518. 11
  136519. };
  136520. static static_codebook _44u8_p5_1 = {
  136521. 2, 121,
  136522. _vq_lengthlist__44u8_p5_1,
  136523. 1, -531365888, 1611661312, 4, 0,
  136524. _vq_quantlist__44u8_p5_1,
  136525. NULL,
  136526. &_vq_auxt__44u8_p5_1,
  136527. NULL,
  136528. 0
  136529. };
  136530. static long _vq_quantlist__44u8_p6_0[] = {
  136531. 6,
  136532. 5,
  136533. 7,
  136534. 4,
  136535. 8,
  136536. 3,
  136537. 9,
  136538. 2,
  136539. 10,
  136540. 1,
  136541. 11,
  136542. 0,
  136543. 12,
  136544. };
  136545. static long _vq_lengthlist__44u8_p6_0[] = {
  136546. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  136547. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  136548. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  136549. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  136550. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  136551. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  136552. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  136553. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  136554. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  136555. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  136556. 11,11,11,11,11,12,11,12,12,
  136557. };
  136558. static float _vq_quantthresh__44u8_p6_0[] = {
  136559. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  136560. 12.5, 17.5, 22.5, 27.5,
  136561. };
  136562. static long _vq_quantmap__44u8_p6_0[] = {
  136563. 11, 9, 7, 5, 3, 1, 0, 2,
  136564. 4, 6, 8, 10, 12,
  136565. };
  136566. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  136567. _vq_quantthresh__44u8_p6_0,
  136568. _vq_quantmap__44u8_p6_0,
  136569. 13,
  136570. 13
  136571. };
  136572. static static_codebook _44u8_p6_0 = {
  136573. 2, 169,
  136574. _vq_lengthlist__44u8_p6_0,
  136575. 1, -526516224, 1616117760, 4, 0,
  136576. _vq_quantlist__44u8_p6_0,
  136577. NULL,
  136578. &_vq_auxt__44u8_p6_0,
  136579. NULL,
  136580. 0
  136581. };
  136582. static long _vq_quantlist__44u8_p6_1[] = {
  136583. 2,
  136584. 1,
  136585. 3,
  136586. 0,
  136587. 4,
  136588. };
  136589. static long _vq_lengthlist__44u8_p6_1[] = {
  136590. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  136591. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  136592. };
  136593. static float _vq_quantthresh__44u8_p6_1[] = {
  136594. -1.5, -0.5, 0.5, 1.5,
  136595. };
  136596. static long _vq_quantmap__44u8_p6_1[] = {
  136597. 3, 1, 0, 2, 4,
  136598. };
  136599. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  136600. _vq_quantthresh__44u8_p6_1,
  136601. _vq_quantmap__44u8_p6_1,
  136602. 5,
  136603. 5
  136604. };
  136605. static static_codebook _44u8_p6_1 = {
  136606. 2, 25,
  136607. _vq_lengthlist__44u8_p6_1,
  136608. 1, -533725184, 1611661312, 3, 0,
  136609. _vq_quantlist__44u8_p6_1,
  136610. NULL,
  136611. &_vq_auxt__44u8_p6_1,
  136612. NULL,
  136613. 0
  136614. };
  136615. static long _vq_quantlist__44u8_p7_0[] = {
  136616. 6,
  136617. 5,
  136618. 7,
  136619. 4,
  136620. 8,
  136621. 3,
  136622. 9,
  136623. 2,
  136624. 10,
  136625. 1,
  136626. 11,
  136627. 0,
  136628. 12,
  136629. };
  136630. static long _vq_lengthlist__44u8_p7_0[] = {
  136631. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  136632. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  136633. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  136634. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  136635. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  136636. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  136637. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  136638. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  136639. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  136640. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  136641. 13,13,14,14,14,15,15,15,16,
  136642. };
  136643. static float _vq_quantthresh__44u8_p7_0[] = {
  136644. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  136645. 27.5, 38.5, 49.5, 60.5,
  136646. };
  136647. static long _vq_quantmap__44u8_p7_0[] = {
  136648. 11, 9, 7, 5, 3, 1, 0, 2,
  136649. 4, 6, 8, 10, 12,
  136650. };
  136651. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  136652. _vq_quantthresh__44u8_p7_0,
  136653. _vq_quantmap__44u8_p7_0,
  136654. 13,
  136655. 13
  136656. };
  136657. static static_codebook _44u8_p7_0 = {
  136658. 2, 169,
  136659. _vq_lengthlist__44u8_p7_0,
  136660. 1, -523206656, 1618345984, 4, 0,
  136661. _vq_quantlist__44u8_p7_0,
  136662. NULL,
  136663. &_vq_auxt__44u8_p7_0,
  136664. NULL,
  136665. 0
  136666. };
  136667. static long _vq_quantlist__44u8_p7_1[] = {
  136668. 5,
  136669. 4,
  136670. 6,
  136671. 3,
  136672. 7,
  136673. 2,
  136674. 8,
  136675. 1,
  136676. 9,
  136677. 0,
  136678. 10,
  136679. };
  136680. static long _vq_lengthlist__44u8_p7_1[] = {
  136681. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136682. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  136683. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136684. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  136685. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  136686. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136687. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136688. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136689. };
  136690. static float _vq_quantthresh__44u8_p7_1[] = {
  136691. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136692. 3.5, 4.5,
  136693. };
  136694. static long _vq_quantmap__44u8_p7_1[] = {
  136695. 9, 7, 5, 3, 1, 0, 2, 4,
  136696. 6, 8, 10,
  136697. };
  136698. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  136699. _vq_quantthresh__44u8_p7_1,
  136700. _vq_quantmap__44u8_p7_1,
  136701. 11,
  136702. 11
  136703. };
  136704. static static_codebook _44u8_p7_1 = {
  136705. 2, 121,
  136706. _vq_lengthlist__44u8_p7_1,
  136707. 1, -531365888, 1611661312, 4, 0,
  136708. _vq_quantlist__44u8_p7_1,
  136709. NULL,
  136710. &_vq_auxt__44u8_p7_1,
  136711. NULL,
  136712. 0
  136713. };
  136714. static long _vq_quantlist__44u8_p8_0[] = {
  136715. 7,
  136716. 6,
  136717. 8,
  136718. 5,
  136719. 9,
  136720. 4,
  136721. 10,
  136722. 3,
  136723. 11,
  136724. 2,
  136725. 12,
  136726. 1,
  136727. 13,
  136728. 0,
  136729. 14,
  136730. };
  136731. static long _vq_lengthlist__44u8_p8_0[] = {
  136732. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  136733. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  136734. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  136735. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  136736. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  136737. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  136738. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  136739. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  136740. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  136741. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  136742. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  136743. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  136744. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  136745. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  136746. 17,
  136747. };
  136748. static float _vq_quantthresh__44u8_p8_0[] = {
  136749. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  136750. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  136751. };
  136752. static long _vq_quantmap__44u8_p8_0[] = {
  136753. 13, 11, 9, 7, 5, 3, 1, 0,
  136754. 2, 4, 6, 8, 10, 12, 14,
  136755. };
  136756. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  136757. _vq_quantthresh__44u8_p8_0,
  136758. _vq_quantmap__44u8_p8_0,
  136759. 15,
  136760. 15
  136761. };
  136762. static static_codebook _44u8_p8_0 = {
  136763. 2, 225,
  136764. _vq_lengthlist__44u8_p8_0,
  136765. 1, -520986624, 1620377600, 4, 0,
  136766. _vq_quantlist__44u8_p8_0,
  136767. NULL,
  136768. &_vq_auxt__44u8_p8_0,
  136769. NULL,
  136770. 0
  136771. };
  136772. static long _vq_quantlist__44u8_p8_1[] = {
  136773. 10,
  136774. 9,
  136775. 11,
  136776. 8,
  136777. 12,
  136778. 7,
  136779. 13,
  136780. 6,
  136781. 14,
  136782. 5,
  136783. 15,
  136784. 4,
  136785. 16,
  136786. 3,
  136787. 17,
  136788. 2,
  136789. 18,
  136790. 1,
  136791. 19,
  136792. 0,
  136793. 20,
  136794. };
  136795. static long _vq_lengthlist__44u8_p8_1[] = {
  136796. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  136797. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  136798. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  136799. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  136800. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136801. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  136802. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  136803. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  136804. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136805. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136806. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  136807. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  136808. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136809. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  136810. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  136811. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  136812. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  136813. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  136814. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  136815. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  136816. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136817. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136818. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  136819. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  136820. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  136821. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  136822. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  136823. 10,10,10,10,10,10,10,10,10,
  136824. };
  136825. static float _vq_quantthresh__44u8_p8_1[] = {
  136826. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  136827. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  136828. 6.5, 7.5, 8.5, 9.5,
  136829. };
  136830. static long _vq_quantmap__44u8_p8_1[] = {
  136831. 19, 17, 15, 13, 11, 9, 7, 5,
  136832. 3, 1, 0, 2, 4, 6, 8, 10,
  136833. 12, 14, 16, 18, 20,
  136834. };
  136835. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  136836. _vq_quantthresh__44u8_p8_1,
  136837. _vq_quantmap__44u8_p8_1,
  136838. 21,
  136839. 21
  136840. };
  136841. static static_codebook _44u8_p8_1 = {
  136842. 2, 441,
  136843. _vq_lengthlist__44u8_p8_1,
  136844. 1, -529268736, 1611661312, 5, 0,
  136845. _vq_quantlist__44u8_p8_1,
  136846. NULL,
  136847. &_vq_auxt__44u8_p8_1,
  136848. NULL,
  136849. 0
  136850. };
  136851. static long _vq_quantlist__44u8_p9_0[] = {
  136852. 4,
  136853. 3,
  136854. 5,
  136855. 2,
  136856. 6,
  136857. 1,
  136858. 7,
  136859. 0,
  136860. 8,
  136861. };
  136862. static long _vq_lengthlist__44u8_p9_0[] = {
  136863. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  136864. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136865. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136866. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136867. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136868. 8,
  136869. };
  136870. static float _vq_quantthresh__44u8_p9_0[] = {
  136871. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  136872. };
  136873. static long _vq_quantmap__44u8_p9_0[] = {
  136874. 7, 5, 3, 1, 0, 2, 4, 6,
  136875. 8,
  136876. };
  136877. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  136878. _vq_quantthresh__44u8_p9_0,
  136879. _vq_quantmap__44u8_p9_0,
  136880. 9,
  136881. 9
  136882. };
  136883. static static_codebook _44u8_p9_0 = {
  136884. 2, 81,
  136885. _vq_lengthlist__44u8_p9_0,
  136886. 1, -511895552, 1631393792, 4, 0,
  136887. _vq_quantlist__44u8_p9_0,
  136888. NULL,
  136889. &_vq_auxt__44u8_p9_0,
  136890. NULL,
  136891. 0
  136892. };
  136893. static long _vq_quantlist__44u8_p9_1[] = {
  136894. 9,
  136895. 8,
  136896. 10,
  136897. 7,
  136898. 11,
  136899. 6,
  136900. 12,
  136901. 5,
  136902. 13,
  136903. 4,
  136904. 14,
  136905. 3,
  136906. 15,
  136907. 2,
  136908. 16,
  136909. 1,
  136910. 17,
  136911. 0,
  136912. 18,
  136913. };
  136914. static long _vq_lengthlist__44u8_p9_1[] = {
  136915. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  136916. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  136917. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  136918. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  136919. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  136920. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  136921. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  136922. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  136923. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  136924. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  136925. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  136926. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  136927. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  136928. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  136929. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  136930. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  136931. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  136932. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  136933. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  136934. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  136935. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  136936. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  136937. 16,15,16,16,16,16,16,16,16,
  136938. };
  136939. static float _vq_quantthresh__44u8_p9_1[] = {
  136940. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  136941. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  136942. 367.5, 416.5,
  136943. };
  136944. static long _vq_quantmap__44u8_p9_1[] = {
  136945. 17, 15, 13, 11, 9, 7, 5, 3,
  136946. 1, 0, 2, 4, 6, 8, 10, 12,
  136947. 14, 16, 18,
  136948. };
  136949. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  136950. _vq_quantthresh__44u8_p9_1,
  136951. _vq_quantmap__44u8_p9_1,
  136952. 19,
  136953. 19
  136954. };
  136955. static static_codebook _44u8_p9_1 = {
  136956. 2, 361,
  136957. _vq_lengthlist__44u8_p9_1,
  136958. 1, -518287360, 1622704128, 5, 0,
  136959. _vq_quantlist__44u8_p9_1,
  136960. NULL,
  136961. &_vq_auxt__44u8_p9_1,
  136962. NULL,
  136963. 0
  136964. };
  136965. static long _vq_quantlist__44u8_p9_2[] = {
  136966. 24,
  136967. 23,
  136968. 25,
  136969. 22,
  136970. 26,
  136971. 21,
  136972. 27,
  136973. 20,
  136974. 28,
  136975. 19,
  136976. 29,
  136977. 18,
  136978. 30,
  136979. 17,
  136980. 31,
  136981. 16,
  136982. 32,
  136983. 15,
  136984. 33,
  136985. 14,
  136986. 34,
  136987. 13,
  136988. 35,
  136989. 12,
  136990. 36,
  136991. 11,
  136992. 37,
  136993. 10,
  136994. 38,
  136995. 9,
  136996. 39,
  136997. 8,
  136998. 40,
  136999. 7,
  137000. 41,
  137001. 6,
  137002. 42,
  137003. 5,
  137004. 43,
  137005. 4,
  137006. 44,
  137007. 3,
  137008. 45,
  137009. 2,
  137010. 46,
  137011. 1,
  137012. 47,
  137013. 0,
  137014. 48,
  137015. };
  137016. static long _vq_lengthlist__44u8_p9_2[] = {
  137017. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137018. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137019. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137020. 7,
  137021. };
  137022. static float _vq_quantthresh__44u8_p9_2[] = {
  137023. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137024. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137025. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137026. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137027. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137028. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137029. };
  137030. static long _vq_quantmap__44u8_p9_2[] = {
  137031. 47, 45, 43, 41, 39, 37, 35, 33,
  137032. 31, 29, 27, 25, 23, 21, 19, 17,
  137033. 15, 13, 11, 9, 7, 5, 3, 1,
  137034. 0, 2, 4, 6, 8, 10, 12, 14,
  137035. 16, 18, 20, 22, 24, 26, 28, 30,
  137036. 32, 34, 36, 38, 40, 42, 44, 46,
  137037. 48,
  137038. };
  137039. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137040. _vq_quantthresh__44u8_p9_2,
  137041. _vq_quantmap__44u8_p9_2,
  137042. 49,
  137043. 49
  137044. };
  137045. static static_codebook _44u8_p9_2 = {
  137046. 1, 49,
  137047. _vq_lengthlist__44u8_p9_2,
  137048. 1, -526909440, 1611661312, 6, 0,
  137049. _vq_quantlist__44u8_p9_2,
  137050. NULL,
  137051. &_vq_auxt__44u8_p9_2,
  137052. NULL,
  137053. 0
  137054. };
  137055. static long _huff_lengthlist__44u9__long[] = {
  137056. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137057. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137058. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137059. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137060. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137061. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137062. 10, 8, 8, 9,
  137063. };
  137064. static static_codebook _huff_book__44u9__long = {
  137065. 2, 100,
  137066. _huff_lengthlist__44u9__long,
  137067. 0, 0, 0, 0, 0,
  137068. NULL,
  137069. NULL,
  137070. NULL,
  137071. NULL,
  137072. 0
  137073. };
  137074. static long _huff_lengthlist__44u9__short[] = {
  137075. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137076. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137077. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137078. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137079. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137080. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137081. 9, 9,12,15,
  137082. };
  137083. static static_codebook _huff_book__44u9__short = {
  137084. 2, 100,
  137085. _huff_lengthlist__44u9__short,
  137086. 0, 0, 0, 0, 0,
  137087. NULL,
  137088. NULL,
  137089. NULL,
  137090. NULL,
  137091. 0
  137092. };
  137093. static long _vq_quantlist__44u9_p1_0[] = {
  137094. 1,
  137095. 0,
  137096. 2,
  137097. };
  137098. static long _vq_lengthlist__44u9_p1_0[] = {
  137099. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137100. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137101. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137102. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137103. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137104. 10,
  137105. };
  137106. static float _vq_quantthresh__44u9_p1_0[] = {
  137107. -0.5, 0.5,
  137108. };
  137109. static long _vq_quantmap__44u9_p1_0[] = {
  137110. 1, 0, 2,
  137111. };
  137112. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137113. _vq_quantthresh__44u9_p1_0,
  137114. _vq_quantmap__44u9_p1_0,
  137115. 3,
  137116. 3
  137117. };
  137118. static static_codebook _44u9_p1_0 = {
  137119. 4, 81,
  137120. _vq_lengthlist__44u9_p1_0,
  137121. 1, -535822336, 1611661312, 2, 0,
  137122. _vq_quantlist__44u9_p1_0,
  137123. NULL,
  137124. &_vq_auxt__44u9_p1_0,
  137125. NULL,
  137126. 0
  137127. };
  137128. static long _vq_quantlist__44u9_p2_0[] = {
  137129. 2,
  137130. 1,
  137131. 3,
  137132. 0,
  137133. 4,
  137134. };
  137135. static long _vq_lengthlist__44u9_p2_0[] = {
  137136. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137137. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137138. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137139. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137140. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137141. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137142. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137143. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137144. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137145. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137146. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137147. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137148. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137149. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137150. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137151. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137152. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137153. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137154. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137155. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137156. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137157. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137158. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137159. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137160. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137161. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137162. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137163. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137164. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137165. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137166. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137167. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137168. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137169. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137170. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137171. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137172. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137173. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137174. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137175. 14,
  137176. };
  137177. static float _vq_quantthresh__44u9_p2_0[] = {
  137178. -1.5, -0.5, 0.5, 1.5,
  137179. };
  137180. static long _vq_quantmap__44u9_p2_0[] = {
  137181. 3, 1, 0, 2, 4,
  137182. };
  137183. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137184. _vq_quantthresh__44u9_p2_0,
  137185. _vq_quantmap__44u9_p2_0,
  137186. 5,
  137187. 5
  137188. };
  137189. static static_codebook _44u9_p2_0 = {
  137190. 4, 625,
  137191. _vq_lengthlist__44u9_p2_0,
  137192. 1, -533725184, 1611661312, 3, 0,
  137193. _vq_quantlist__44u9_p2_0,
  137194. NULL,
  137195. &_vq_auxt__44u9_p2_0,
  137196. NULL,
  137197. 0
  137198. };
  137199. static long _vq_quantlist__44u9_p3_0[] = {
  137200. 4,
  137201. 3,
  137202. 5,
  137203. 2,
  137204. 6,
  137205. 1,
  137206. 7,
  137207. 0,
  137208. 8,
  137209. };
  137210. static long _vq_lengthlist__44u9_p3_0[] = {
  137211. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137212. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137213. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137214. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137215. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137216. 11,
  137217. };
  137218. static float _vq_quantthresh__44u9_p3_0[] = {
  137219. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137220. };
  137221. static long _vq_quantmap__44u9_p3_0[] = {
  137222. 7, 5, 3, 1, 0, 2, 4, 6,
  137223. 8,
  137224. };
  137225. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137226. _vq_quantthresh__44u9_p3_0,
  137227. _vq_quantmap__44u9_p3_0,
  137228. 9,
  137229. 9
  137230. };
  137231. static static_codebook _44u9_p3_0 = {
  137232. 2, 81,
  137233. _vq_lengthlist__44u9_p3_0,
  137234. 1, -531628032, 1611661312, 4, 0,
  137235. _vq_quantlist__44u9_p3_0,
  137236. NULL,
  137237. &_vq_auxt__44u9_p3_0,
  137238. NULL,
  137239. 0
  137240. };
  137241. static long _vq_quantlist__44u9_p4_0[] = {
  137242. 8,
  137243. 7,
  137244. 9,
  137245. 6,
  137246. 10,
  137247. 5,
  137248. 11,
  137249. 4,
  137250. 12,
  137251. 3,
  137252. 13,
  137253. 2,
  137254. 14,
  137255. 1,
  137256. 15,
  137257. 0,
  137258. 16,
  137259. };
  137260. static long _vq_lengthlist__44u9_p4_0[] = {
  137261. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137262. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137263. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137264. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137265. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137266. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137267. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137268. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137269. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137270. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137271. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137272. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137273. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137274. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137275. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137276. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137277. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137278. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137279. 14,
  137280. };
  137281. static float _vq_quantthresh__44u9_p4_0[] = {
  137282. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137283. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137284. };
  137285. static long _vq_quantmap__44u9_p4_0[] = {
  137286. 15, 13, 11, 9, 7, 5, 3, 1,
  137287. 0, 2, 4, 6, 8, 10, 12, 14,
  137288. 16,
  137289. };
  137290. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137291. _vq_quantthresh__44u9_p4_0,
  137292. _vq_quantmap__44u9_p4_0,
  137293. 17,
  137294. 17
  137295. };
  137296. static static_codebook _44u9_p4_0 = {
  137297. 2, 289,
  137298. _vq_lengthlist__44u9_p4_0,
  137299. 1, -529530880, 1611661312, 5, 0,
  137300. _vq_quantlist__44u9_p4_0,
  137301. NULL,
  137302. &_vq_auxt__44u9_p4_0,
  137303. NULL,
  137304. 0
  137305. };
  137306. static long _vq_quantlist__44u9_p5_0[] = {
  137307. 1,
  137308. 0,
  137309. 2,
  137310. };
  137311. static long _vq_lengthlist__44u9_p5_0[] = {
  137312. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137313. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137314. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137315. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137316. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137317. 10,
  137318. };
  137319. static float _vq_quantthresh__44u9_p5_0[] = {
  137320. -5.5, 5.5,
  137321. };
  137322. static long _vq_quantmap__44u9_p5_0[] = {
  137323. 1, 0, 2,
  137324. };
  137325. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137326. _vq_quantthresh__44u9_p5_0,
  137327. _vq_quantmap__44u9_p5_0,
  137328. 3,
  137329. 3
  137330. };
  137331. static static_codebook _44u9_p5_0 = {
  137332. 4, 81,
  137333. _vq_lengthlist__44u9_p5_0,
  137334. 1, -529137664, 1618345984, 2, 0,
  137335. _vq_quantlist__44u9_p5_0,
  137336. NULL,
  137337. &_vq_auxt__44u9_p5_0,
  137338. NULL,
  137339. 0
  137340. };
  137341. static long _vq_quantlist__44u9_p5_1[] = {
  137342. 5,
  137343. 4,
  137344. 6,
  137345. 3,
  137346. 7,
  137347. 2,
  137348. 8,
  137349. 1,
  137350. 9,
  137351. 0,
  137352. 10,
  137353. };
  137354. static long _vq_lengthlist__44u9_p5_1[] = {
  137355. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137356. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137357. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137358. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137359. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137360. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137361. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137362. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137363. };
  137364. static float _vq_quantthresh__44u9_p5_1[] = {
  137365. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137366. 3.5, 4.5,
  137367. };
  137368. static long _vq_quantmap__44u9_p5_1[] = {
  137369. 9, 7, 5, 3, 1, 0, 2, 4,
  137370. 6, 8, 10,
  137371. };
  137372. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137373. _vq_quantthresh__44u9_p5_1,
  137374. _vq_quantmap__44u9_p5_1,
  137375. 11,
  137376. 11
  137377. };
  137378. static static_codebook _44u9_p5_1 = {
  137379. 2, 121,
  137380. _vq_lengthlist__44u9_p5_1,
  137381. 1, -531365888, 1611661312, 4, 0,
  137382. _vq_quantlist__44u9_p5_1,
  137383. NULL,
  137384. &_vq_auxt__44u9_p5_1,
  137385. NULL,
  137386. 0
  137387. };
  137388. static long _vq_quantlist__44u9_p6_0[] = {
  137389. 6,
  137390. 5,
  137391. 7,
  137392. 4,
  137393. 8,
  137394. 3,
  137395. 9,
  137396. 2,
  137397. 10,
  137398. 1,
  137399. 11,
  137400. 0,
  137401. 12,
  137402. };
  137403. static long _vq_lengthlist__44u9_p6_0[] = {
  137404. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137405. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137406. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137407. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137408. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137409. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137410. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137411. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137412. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137413. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137414. 10,11,11,11,11,12,11,12,12,
  137415. };
  137416. static float _vq_quantthresh__44u9_p6_0[] = {
  137417. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137418. 12.5, 17.5, 22.5, 27.5,
  137419. };
  137420. static long _vq_quantmap__44u9_p6_0[] = {
  137421. 11, 9, 7, 5, 3, 1, 0, 2,
  137422. 4, 6, 8, 10, 12,
  137423. };
  137424. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137425. _vq_quantthresh__44u9_p6_0,
  137426. _vq_quantmap__44u9_p6_0,
  137427. 13,
  137428. 13
  137429. };
  137430. static static_codebook _44u9_p6_0 = {
  137431. 2, 169,
  137432. _vq_lengthlist__44u9_p6_0,
  137433. 1, -526516224, 1616117760, 4, 0,
  137434. _vq_quantlist__44u9_p6_0,
  137435. NULL,
  137436. &_vq_auxt__44u9_p6_0,
  137437. NULL,
  137438. 0
  137439. };
  137440. static long _vq_quantlist__44u9_p6_1[] = {
  137441. 2,
  137442. 1,
  137443. 3,
  137444. 0,
  137445. 4,
  137446. };
  137447. static long _vq_lengthlist__44u9_p6_1[] = {
  137448. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137449. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137450. };
  137451. static float _vq_quantthresh__44u9_p6_1[] = {
  137452. -1.5, -0.5, 0.5, 1.5,
  137453. };
  137454. static long _vq_quantmap__44u9_p6_1[] = {
  137455. 3, 1, 0, 2, 4,
  137456. };
  137457. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137458. _vq_quantthresh__44u9_p6_1,
  137459. _vq_quantmap__44u9_p6_1,
  137460. 5,
  137461. 5
  137462. };
  137463. static static_codebook _44u9_p6_1 = {
  137464. 2, 25,
  137465. _vq_lengthlist__44u9_p6_1,
  137466. 1, -533725184, 1611661312, 3, 0,
  137467. _vq_quantlist__44u9_p6_1,
  137468. NULL,
  137469. &_vq_auxt__44u9_p6_1,
  137470. NULL,
  137471. 0
  137472. };
  137473. static long _vq_quantlist__44u9_p7_0[] = {
  137474. 6,
  137475. 5,
  137476. 7,
  137477. 4,
  137478. 8,
  137479. 3,
  137480. 9,
  137481. 2,
  137482. 10,
  137483. 1,
  137484. 11,
  137485. 0,
  137486. 12,
  137487. };
  137488. static long _vq_lengthlist__44u9_p7_0[] = {
  137489. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137490. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137491. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137492. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137493. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137494. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137495. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137496. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137497. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137498. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137499. 12,13,13,14,14,14,15,15,15,
  137500. };
  137501. static float _vq_quantthresh__44u9_p7_0[] = {
  137502. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137503. 27.5, 38.5, 49.5, 60.5,
  137504. };
  137505. static long _vq_quantmap__44u9_p7_0[] = {
  137506. 11, 9, 7, 5, 3, 1, 0, 2,
  137507. 4, 6, 8, 10, 12,
  137508. };
  137509. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  137510. _vq_quantthresh__44u9_p7_0,
  137511. _vq_quantmap__44u9_p7_0,
  137512. 13,
  137513. 13
  137514. };
  137515. static static_codebook _44u9_p7_0 = {
  137516. 2, 169,
  137517. _vq_lengthlist__44u9_p7_0,
  137518. 1, -523206656, 1618345984, 4, 0,
  137519. _vq_quantlist__44u9_p7_0,
  137520. NULL,
  137521. &_vq_auxt__44u9_p7_0,
  137522. NULL,
  137523. 0
  137524. };
  137525. static long _vq_quantlist__44u9_p7_1[] = {
  137526. 5,
  137527. 4,
  137528. 6,
  137529. 3,
  137530. 7,
  137531. 2,
  137532. 8,
  137533. 1,
  137534. 9,
  137535. 0,
  137536. 10,
  137537. };
  137538. static long _vq_lengthlist__44u9_p7_1[] = {
  137539. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  137540. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137541. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  137542. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137543. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137544. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137545. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  137546. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  137547. };
  137548. static float _vq_quantthresh__44u9_p7_1[] = {
  137549. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137550. 3.5, 4.5,
  137551. };
  137552. static long _vq_quantmap__44u9_p7_1[] = {
  137553. 9, 7, 5, 3, 1, 0, 2, 4,
  137554. 6, 8, 10,
  137555. };
  137556. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  137557. _vq_quantthresh__44u9_p7_1,
  137558. _vq_quantmap__44u9_p7_1,
  137559. 11,
  137560. 11
  137561. };
  137562. static static_codebook _44u9_p7_1 = {
  137563. 2, 121,
  137564. _vq_lengthlist__44u9_p7_1,
  137565. 1, -531365888, 1611661312, 4, 0,
  137566. _vq_quantlist__44u9_p7_1,
  137567. NULL,
  137568. &_vq_auxt__44u9_p7_1,
  137569. NULL,
  137570. 0
  137571. };
  137572. static long _vq_quantlist__44u9_p8_0[] = {
  137573. 7,
  137574. 6,
  137575. 8,
  137576. 5,
  137577. 9,
  137578. 4,
  137579. 10,
  137580. 3,
  137581. 11,
  137582. 2,
  137583. 12,
  137584. 1,
  137585. 13,
  137586. 0,
  137587. 14,
  137588. };
  137589. static long _vq_lengthlist__44u9_p8_0[] = {
  137590. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  137591. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137592. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  137593. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  137594. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  137595. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  137596. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  137597. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  137598. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  137599. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  137600. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  137601. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  137602. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  137603. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  137604. 15,
  137605. };
  137606. static float _vq_quantthresh__44u9_p8_0[] = {
  137607. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137608. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137609. };
  137610. static long _vq_quantmap__44u9_p8_0[] = {
  137611. 13, 11, 9, 7, 5, 3, 1, 0,
  137612. 2, 4, 6, 8, 10, 12, 14,
  137613. };
  137614. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  137615. _vq_quantthresh__44u9_p8_0,
  137616. _vq_quantmap__44u9_p8_0,
  137617. 15,
  137618. 15
  137619. };
  137620. static static_codebook _44u9_p8_0 = {
  137621. 2, 225,
  137622. _vq_lengthlist__44u9_p8_0,
  137623. 1, -520986624, 1620377600, 4, 0,
  137624. _vq_quantlist__44u9_p8_0,
  137625. NULL,
  137626. &_vq_auxt__44u9_p8_0,
  137627. NULL,
  137628. 0
  137629. };
  137630. static long _vq_quantlist__44u9_p8_1[] = {
  137631. 10,
  137632. 9,
  137633. 11,
  137634. 8,
  137635. 12,
  137636. 7,
  137637. 13,
  137638. 6,
  137639. 14,
  137640. 5,
  137641. 15,
  137642. 4,
  137643. 16,
  137644. 3,
  137645. 17,
  137646. 2,
  137647. 18,
  137648. 1,
  137649. 19,
  137650. 0,
  137651. 20,
  137652. };
  137653. static long _vq_lengthlist__44u9_p8_1[] = {
  137654. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137655. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137656. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  137657. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137658. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  137659. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137660. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137661. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  137662. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137663. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137664. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  137665. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  137666. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137667. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137668. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137669. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137670. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137671. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137672. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  137673. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137674. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137675. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  137676. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  137677. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  137678. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137679. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  137680. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137681. 10,10,10,10,10,10,10,10,10,
  137682. };
  137683. static float _vq_quantthresh__44u9_p8_1[] = {
  137684. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137685. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137686. 6.5, 7.5, 8.5, 9.5,
  137687. };
  137688. static long _vq_quantmap__44u9_p8_1[] = {
  137689. 19, 17, 15, 13, 11, 9, 7, 5,
  137690. 3, 1, 0, 2, 4, 6, 8, 10,
  137691. 12, 14, 16, 18, 20,
  137692. };
  137693. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  137694. _vq_quantthresh__44u9_p8_1,
  137695. _vq_quantmap__44u9_p8_1,
  137696. 21,
  137697. 21
  137698. };
  137699. static static_codebook _44u9_p8_1 = {
  137700. 2, 441,
  137701. _vq_lengthlist__44u9_p8_1,
  137702. 1, -529268736, 1611661312, 5, 0,
  137703. _vq_quantlist__44u9_p8_1,
  137704. NULL,
  137705. &_vq_auxt__44u9_p8_1,
  137706. NULL,
  137707. 0
  137708. };
  137709. static long _vq_quantlist__44u9_p9_0[] = {
  137710. 7,
  137711. 6,
  137712. 8,
  137713. 5,
  137714. 9,
  137715. 4,
  137716. 10,
  137717. 3,
  137718. 11,
  137719. 2,
  137720. 12,
  137721. 1,
  137722. 13,
  137723. 0,
  137724. 14,
  137725. };
  137726. static long _vq_lengthlist__44u9_p9_0[] = {
  137727. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  137728. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  137729. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137730. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137731. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137732. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137733. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137734. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137735. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137736. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137737. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137738. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  137739. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137740. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137741. 10,
  137742. };
  137743. static float _vq_quantthresh__44u9_p9_0[] = {
  137744. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  137745. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  137746. };
  137747. static long _vq_quantmap__44u9_p9_0[] = {
  137748. 13, 11, 9, 7, 5, 3, 1, 0,
  137749. 2, 4, 6, 8, 10, 12, 14,
  137750. };
  137751. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  137752. _vq_quantthresh__44u9_p9_0,
  137753. _vq_quantmap__44u9_p9_0,
  137754. 15,
  137755. 15
  137756. };
  137757. static static_codebook _44u9_p9_0 = {
  137758. 2, 225,
  137759. _vq_lengthlist__44u9_p9_0,
  137760. 1, -510036736, 1631393792, 4, 0,
  137761. _vq_quantlist__44u9_p9_0,
  137762. NULL,
  137763. &_vq_auxt__44u9_p9_0,
  137764. NULL,
  137765. 0
  137766. };
  137767. static long _vq_quantlist__44u9_p9_1[] = {
  137768. 9,
  137769. 8,
  137770. 10,
  137771. 7,
  137772. 11,
  137773. 6,
  137774. 12,
  137775. 5,
  137776. 13,
  137777. 4,
  137778. 14,
  137779. 3,
  137780. 15,
  137781. 2,
  137782. 16,
  137783. 1,
  137784. 17,
  137785. 0,
  137786. 18,
  137787. };
  137788. static long _vq_lengthlist__44u9_p9_1[] = {
  137789. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  137790. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  137791. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  137792. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  137793. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  137794. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  137795. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  137796. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  137797. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  137798. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  137799. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  137800. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  137801. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  137802. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  137803. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  137804. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  137805. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  137806. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  137807. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  137808. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  137809. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  137810. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  137811. 17,17,15,17,15,17,16,16,17,
  137812. };
  137813. static float _vq_quantthresh__44u9_p9_1[] = {
  137814. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137815. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137816. 367.5, 416.5,
  137817. };
  137818. static long _vq_quantmap__44u9_p9_1[] = {
  137819. 17, 15, 13, 11, 9, 7, 5, 3,
  137820. 1, 0, 2, 4, 6, 8, 10, 12,
  137821. 14, 16, 18,
  137822. };
  137823. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  137824. _vq_quantthresh__44u9_p9_1,
  137825. _vq_quantmap__44u9_p9_1,
  137826. 19,
  137827. 19
  137828. };
  137829. static static_codebook _44u9_p9_1 = {
  137830. 2, 361,
  137831. _vq_lengthlist__44u9_p9_1,
  137832. 1, -518287360, 1622704128, 5, 0,
  137833. _vq_quantlist__44u9_p9_1,
  137834. NULL,
  137835. &_vq_auxt__44u9_p9_1,
  137836. NULL,
  137837. 0
  137838. };
  137839. static long _vq_quantlist__44u9_p9_2[] = {
  137840. 24,
  137841. 23,
  137842. 25,
  137843. 22,
  137844. 26,
  137845. 21,
  137846. 27,
  137847. 20,
  137848. 28,
  137849. 19,
  137850. 29,
  137851. 18,
  137852. 30,
  137853. 17,
  137854. 31,
  137855. 16,
  137856. 32,
  137857. 15,
  137858. 33,
  137859. 14,
  137860. 34,
  137861. 13,
  137862. 35,
  137863. 12,
  137864. 36,
  137865. 11,
  137866. 37,
  137867. 10,
  137868. 38,
  137869. 9,
  137870. 39,
  137871. 8,
  137872. 40,
  137873. 7,
  137874. 41,
  137875. 6,
  137876. 42,
  137877. 5,
  137878. 43,
  137879. 4,
  137880. 44,
  137881. 3,
  137882. 45,
  137883. 2,
  137884. 46,
  137885. 1,
  137886. 47,
  137887. 0,
  137888. 48,
  137889. };
  137890. static long _vq_lengthlist__44u9_p9_2[] = {
  137891. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  137892. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137893. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137894. 7,
  137895. };
  137896. static float _vq_quantthresh__44u9_p9_2[] = {
  137897. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137898. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137899. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137900. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137901. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137902. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137903. };
  137904. static long _vq_quantmap__44u9_p9_2[] = {
  137905. 47, 45, 43, 41, 39, 37, 35, 33,
  137906. 31, 29, 27, 25, 23, 21, 19, 17,
  137907. 15, 13, 11, 9, 7, 5, 3, 1,
  137908. 0, 2, 4, 6, 8, 10, 12, 14,
  137909. 16, 18, 20, 22, 24, 26, 28, 30,
  137910. 32, 34, 36, 38, 40, 42, 44, 46,
  137911. 48,
  137912. };
  137913. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  137914. _vq_quantthresh__44u9_p9_2,
  137915. _vq_quantmap__44u9_p9_2,
  137916. 49,
  137917. 49
  137918. };
  137919. static static_codebook _44u9_p9_2 = {
  137920. 1, 49,
  137921. _vq_lengthlist__44u9_p9_2,
  137922. 1, -526909440, 1611661312, 6, 0,
  137923. _vq_quantlist__44u9_p9_2,
  137924. NULL,
  137925. &_vq_auxt__44u9_p9_2,
  137926. NULL,
  137927. 0
  137928. };
  137929. static long _huff_lengthlist__44un1__long[] = {
  137930. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  137931. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  137932. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  137933. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  137934. };
  137935. static static_codebook _huff_book__44un1__long = {
  137936. 2, 64,
  137937. _huff_lengthlist__44un1__long,
  137938. 0, 0, 0, 0, 0,
  137939. NULL,
  137940. NULL,
  137941. NULL,
  137942. NULL,
  137943. 0
  137944. };
  137945. static long _vq_quantlist__44un1__p1_0[] = {
  137946. 1,
  137947. 0,
  137948. 2,
  137949. };
  137950. static long _vq_lengthlist__44un1__p1_0[] = {
  137951. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  137952. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  137953. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  137954. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  137955. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  137956. 12,
  137957. };
  137958. static float _vq_quantthresh__44un1__p1_0[] = {
  137959. -0.5, 0.5,
  137960. };
  137961. static long _vq_quantmap__44un1__p1_0[] = {
  137962. 1, 0, 2,
  137963. };
  137964. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  137965. _vq_quantthresh__44un1__p1_0,
  137966. _vq_quantmap__44un1__p1_0,
  137967. 3,
  137968. 3
  137969. };
  137970. static static_codebook _44un1__p1_0 = {
  137971. 4, 81,
  137972. _vq_lengthlist__44un1__p1_0,
  137973. 1, -535822336, 1611661312, 2, 0,
  137974. _vq_quantlist__44un1__p1_0,
  137975. NULL,
  137976. &_vq_auxt__44un1__p1_0,
  137977. NULL,
  137978. 0
  137979. };
  137980. static long _vq_quantlist__44un1__p2_0[] = {
  137981. 1,
  137982. 0,
  137983. 2,
  137984. };
  137985. static long _vq_lengthlist__44un1__p2_0[] = {
  137986. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  137987. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  137988. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  137989. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  137990. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  137991. 8,
  137992. };
  137993. static float _vq_quantthresh__44un1__p2_0[] = {
  137994. -0.5, 0.5,
  137995. };
  137996. static long _vq_quantmap__44un1__p2_0[] = {
  137997. 1, 0, 2,
  137998. };
  137999. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138000. _vq_quantthresh__44un1__p2_0,
  138001. _vq_quantmap__44un1__p2_0,
  138002. 3,
  138003. 3
  138004. };
  138005. static static_codebook _44un1__p2_0 = {
  138006. 4, 81,
  138007. _vq_lengthlist__44un1__p2_0,
  138008. 1, -535822336, 1611661312, 2, 0,
  138009. _vq_quantlist__44un1__p2_0,
  138010. NULL,
  138011. &_vq_auxt__44un1__p2_0,
  138012. NULL,
  138013. 0
  138014. };
  138015. static long _vq_quantlist__44un1__p3_0[] = {
  138016. 2,
  138017. 1,
  138018. 3,
  138019. 0,
  138020. 4,
  138021. };
  138022. static long _vq_lengthlist__44un1__p3_0[] = {
  138023. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138024. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138025. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138026. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138027. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138028. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138029. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138030. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138031. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138032. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138033. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138034. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138035. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138036. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138037. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138038. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138039. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138040. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138041. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138042. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138043. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138044. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138045. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138046. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138047. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138048. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138049. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138050. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138051. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138052. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138053. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138054. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138055. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138056. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138057. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138058. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138059. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138060. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138061. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138062. 17,
  138063. };
  138064. static float _vq_quantthresh__44un1__p3_0[] = {
  138065. -1.5, -0.5, 0.5, 1.5,
  138066. };
  138067. static long _vq_quantmap__44un1__p3_0[] = {
  138068. 3, 1, 0, 2, 4,
  138069. };
  138070. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138071. _vq_quantthresh__44un1__p3_0,
  138072. _vq_quantmap__44un1__p3_0,
  138073. 5,
  138074. 5
  138075. };
  138076. static static_codebook _44un1__p3_0 = {
  138077. 4, 625,
  138078. _vq_lengthlist__44un1__p3_0,
  138079. 1, -533725184, 1611661312, 3, 0,
  138080. _vq_quantlist__44un1__p3_0,
  138081. NULL,
  138082. &_vq_auxt__44un1__p3_0,
  138083. NULL,
  138084. 0
  138085. };
  138086. static long _vq_quantlist__44un1__p4_0[] = {
  138087. 2,
  138088. 1,
  138089. 3,
  138090. 0,
  138091. 4,
  138092. };
  138093. static long _vq_lengthlist__44un1__p4_0[] = {
  138094. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138095. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138096. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138097. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138098. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138099. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138100. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138101. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138102. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138103. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138104. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138105. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138106. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138107. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138108. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138109. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138110. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138111. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138112. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138113. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138114. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138115. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138116. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138117. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138118. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138119. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138120. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138121. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138122. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138123. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138124. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138125. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138126. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138127. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138128. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138129. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138130. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138131. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138132. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138133. 12,
  138134. };
  138135. static float _vq_quantthresh__44un1__p4_0[] = {
  138136. -1.5, -0.5, 0.5, 1.5,
  138137. };
  138138. static long _vq_quantmap__44un1__p4_0[] = {
  138139. 3, 1, 0, 2, 4,
  138140. };
  138141. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138142. _vq_quantthresh__44un1__p4_0,
  138143. _vq_quantmap__44un1__p4_0,
  138144. 5,
  138145. 5
  138146. };
  138147. static static_codebook _44un1__p4_0 = {
  138148. 4, 625,
  138149. _vq_lengthlist__44un1__p4_0,
  138150. 1, -533725184, 1611661312, 3, 0,
  138151. _vq_quantlist__44un1__p4_0,
  138152. NULL,
  138153. &_vq_auxt__44un1__p4_0,
  138154. NULL,
  138155. 0
  138156. };
  138157. static long _vq_quantlist__44un1__p5_0[] = {
  138158. 4,
  138159. 3,
  138160. 5,
  138161. 2,
  138162. 6,
  138163. 1,
  138164. 7,
  138165. 0,
  138166. 8,
  138167. };
  138168. static long _vq_lengthlist__44un1__p5_0[] = {
  138169. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138170. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138171. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138172. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138173. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138174. 12,
  138175. };
  138176. static float _vq_quantthresh__44un1__p5_0[] = {
  138177. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138178. };
  138179. static long _vq_quantmap__44un1__p5_0[] = {
  138180. 7, 5, 3, 1, 0, 2, 4, 6,
  138181. 8,
  138182. };
  138183. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138184. _vq_quantthresh__44un1__p5_0,
  138185. _vq_quantmap__44un1__p5_0,
  138186. 9,
  138187. 9
  138188. };
  138189. static static_codebook _44un1__p5_0 = {
  138190. 2, 81,
  138191. _vq_lengthlist__44un1__p5_0,
  138192. 1, -531628032, 1611661312, 4, 0,
  138193. _vq_quantlist__44un1__p5_0,
  138194. NULL,
  138195. &_vq_auxt__44un1__p5_0,
  138196. NULL,
  138197. 0
  138198. };
  138199. static long _vq_quantlist__44un1__p6_0[] = {
  138200. 6,
  138201. 5,
  138202. 7,
  138203. 4,
  138204. 8,
  138205. 3,
  138206. 9,
  138207. 2,
  138208. 10,
  138209. 1,
  138210. 11,
  138211. 0,
  138212. 12,
  138213. };
  138214. static long _vq_lengthlist__44un1__p6_0[] = {
  138215. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138216. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138217. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138218. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138219. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138220. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138221. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138222. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138223. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138224. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138225. 16, 0,15,18,18, 0,16, 0, 0,
  138226. };
  138227. static float _vq_quantthresh__44un1__p6_0[] = {
  138228. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138229. 12.5, 17.5, 22.5, 27.5,
  138230. };
  138231. static long _vq_quantmap__44un1__p6_0[] = {
  138232. 11, 9, 7, 5, 3, 1, 0, 2,
  138233. 4, 6, 8, 10, 12,
  138234. };
  138235. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138236. _vq_quantthresh__44un1__p6_0,
  138237. _vq_quantmap__44un1__p6_0,
  138238. 13,
  138239. 13
  138240. };
  138241. static static_codebook _44un1__p6_0 = {
  138242. 2, 169,
  138243. _vq_lengthlist__44un1__p6_0,
  138244. 1, -526516224, 1616117760, 4, 0,
  138245. _vq_quantlist__44un1__p6_0,
  138246. NULL,
  138247. &_vq_auxt__44un1__p6_0,
  138248. NULL,
  138249. 0
  138250. };
  138251. static long _vq_quantlist__44un1__p6_1[] = {
  138252. 2,
  138253. 1,
  138254. 3,
  138255. 0,
  138256. 4,
  138257. };
  138258. static long _vq_lengthlist__44un1__p6_1[] = {
  138259. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138260. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138261. };
  138262. static float _vq_quantthresh__44un1__p6_1[] = {
  138263. -1.5, -0.5, 0.5, 1.5,
  138264. };
  138265. static long _vq_quantmap__44un1__p6_1[] = {
  138266. 3, 1, 0, 2, 4,
  138267. };
  138268. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138269. _vq_quantthresh__44un1__p6_1,
  138270. _vq_quantmap__44un1__p6_1,
  138271. 5,
  138272. 5
  138273. };
  138274. static static_codebook _44un1__p6_1 = {
  138275. 2, 25,
  138276. _vq_lengthlist__44un1__p6_1,
  138277. 1, -533725184, 1611661312, 3, 0,
  138278. _vq_quantlist__44un1__p6_1,
  138279. NULL,
  138280. &_vq_auxt__44un1__p6_1,
  138281. NULL,
  138282. 0
  138283. };
  138284. static long _vq_quantlist__44un1__p7_0[] = {
  138285. 2,
  138286. 1,
  138287. 3,
  138288. 0,
  138289. 4,
  138290. };
  138291. static long _vq_lengthlist__44un1__p7_0[] = {
  138292. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138293. 11,11,11,11,11,11,11,11,11,10,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,10,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. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138298. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138299. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138300. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138301. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138302. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138303. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138304. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138305. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138306. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138307. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138308. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138309. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138310. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138311. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138312. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138313. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138314. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138315. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138316. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138317. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138318. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138319. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138320. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138321. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138322. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138323. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138324. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138325. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138326. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138327. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138328. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138329. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138330. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138331. 10,
  138332. };
  138333. static float _vq_quantthresh__44un1__p7_0[] = {
  138334. -253.5, -84.5, 84.5, 253.5,
  138335. };
  138336. static long _vq_quantmap__44un1__p7_0[] = {
  138337. 3, 1, 0, 2, 4,
  138338. };
  138339. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138340. _vq_quantthresh__44un1__p7_0,
  138341. _vq_quantmap__44un1__p7_0,
  138342. 5,
  138343. 5
  138344. };
  138345. static static_codebook _44un1__p7_0 = {
  138346. 4, 625,
  138347. _vq_lengthlist__44un1__p7_0,
  138348. 1, -518709248, 1626677248, 3, 0,
  138349. _vq_quantlist__44un1__p7_0,
  138350. NULL,
  138351. &_vq_auxt__44un1__p7_0,
  138352. NULL,
  138353. 0
  138354. };
  138355. static long _vq_quantlist__44un1__p7_1[] = {
  138356. 6,
  138357. 5,
  138358. 7,
  138359. 4,
  138360. 8,
  138361. 3,
  138362. 9,
  138363. 2,
  138364. 10,
  138365. 1,
  138366. 11,
  138367. 0,
  138368. 12,
  138369. };
  138370. static long _vq_lengthlist__44un1__p7_1[] = {
  138371. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138372. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138373. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138374. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138375. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138376. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138377. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138378. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138379. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138380. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138381. 12,13,13,12,13,13,14,14,14,
  138382. };
  138383. static float _vq_quantthresh__44un1__p7_1[] = {
  138384. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138385. 32.5, 45.5, 58.5, 71.5,
  138386. };
  138387. static long _vq_quantmap__44un1__p7_1[] = {
  138388. 11, 9, 7, 5, 3, 1, 0, 2,
  138389. 4, 6, 8, 10, 12,
  138390. };
  138391. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138392. _vq_quantthresh__44un1__p7_1,
  138393. _vq_quantmap__44un1__p7_1,
  138394. 13,
  138395. 13
  138396. };
  138397. static static_codebook _44un1__p7_1 = {
  138398. 2, 169,
  138399. _vq_lengthlist__44un1__p7_1,
  138400. 1, -523010048, 1618608128, 4, 0,
  138401. _vq_quantlist__44un1__p7_1,
  138402. NULL,
  138403. &_vq_auxt__44un1__p7_1,
  138404. NULL,
  138405. 0
  138406. };
  138407. static long _vq_quantlist__44un1__p7_2[] = {
  138408. 6,
  138409. 5,
  138410. 7,
  138411. 4,
  138412. 8,
  138413. 3,
  138414. 9,
  138415. 2,
  138416. 10,
  138417. 1,
  138418. 11,
  138419. 0,
  138420. 12,
  138421. };
  138422. static long _vq_lengthlist__44un1__p7_2[] = {
  138423. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138424. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138425. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138426. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138427. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138428. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138429. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138430. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138431. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138432. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138433. 9, 9, 9,10,10,10,10,10,10,
  138434. };
  138435. static float _vq_quantthresh__44un1__p7_2[] = {
  138436. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138437. 2.5, 3.5, 4.5, 5.5,
  138438. };
  138439. static long _vq_quantmap__44un1__p7_2[] = {
  138440. 11, 9, 7, 5, 3, 1, 0, 2,
  138441. 4, 6, 8, 10, 12,
  138442. };
  138443. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138444. _vq_quantthresh__44un1__p7_2,
  138445. _vq_quantmap__44un1__p7_2,
  138446. 13,
  138447. 13
  138448. };
  138449. static static_codebook _44un1__p7_2 = {
  138450. 2, 169,
  138451. _vq_lengthlist__44un1__p7_2,
  138452. 1, -531103744, 1611661312, 4, 0,
  138453. _vq_quantlist__44un1__p7_2,
  138454. NULL,
  138455. &_vq_auxt__44un1__p7_2,
  138456. NULL,
  138457. 0
  138458. };
  138459. static long _huff_lengthlist__44un1__short[] = {
  138460. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138461. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138462. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138463. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138464. };
  138465. static static_codebook _huff_book__44un1__short = {
  138466. 2, 64,
  138467. _huff_lengthlist__44un1__short,
  138468. 0, 0, 0, 0, 0,
  138469. NULL,
  138470. NULL,
  138471. NULL,
  138472. NULL,
  138473. 0
  138474. };
  138475. /*** End of inlined file: res_books_uncoupled.h ***/
  138476. static vorbis_info_residue0 _residue_44_low_un={
  138477. 0,-1, -1, 8,-1,
  138478. {0},
  138479. {-1},
  138480. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138481. { -1, 25, -1, 45, -1, -1, -1}
  138482. };
  138483. static vorbis_info_residue0 _residue_44_mid_un={
  138484. 0,-1, -1, 10,-1,
  138485. {0},
  138486. {-1},
  138487. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138488. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138489. };
  138490. static vorbis_info_residue0 _residue_44_hi_un={
  138491. 0,-1, -1, 10,-1,
  138492. {0},
  138493. {-1},
  138494. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138495. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138496. };
  138497. static vorbis_info_mapping0 _map_nominal_u[2]={
  138498. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138499. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138500. };
  138501. static static_bookblock _resbook_44u_n1={
  138502. {
  138503. {0},
  138504. {0,0,&_44un1__p1_0},
  138505. {0,0,&_44un1__p2_0},
  138506. {0,0,&_44un1__p3_0},
  138507. {0,0,&_44un1__p4_0},
  138508. {0,0,&_44un1__p5_0},
  138509. {&_44un1__p6_0,&_44un1__p6_1},
  138510. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  138511. }
  138512. };
  138513. static static_bookblock _resbook_44u_0={
  138514. {
  138515. {0},
  138516. {0,0,&_44u0__p1_0},
  138517. {0,0,&_44u0__p2_0},
  138518. {0,0,&_44u0__p3_0},
  138519. {0,0,&_44u0__p4_0},
  138520. {0,0,&_44u0__p5_0},
  138521. {&_44u0__p6_0,&_44u0__p6_1},
  138522. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  138523. }
  138524. };
  138525. static static_bookblock _resbook_44u_1={
  138526. {
  138527. {0},
  138528. {0,0,&_44u1__p1_0},
  138529. {0,0,&_44u1__p2_0},
  138530. {0,0,&_44u1__p3_0},
  138531. {0,0,&_44u1__p4_0},
  138532. {0,0,&_44u1__p5_0},
  138533. {&_44u1__p6_0,&_44u1__p6_1},
  138534. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  138535. }
  138536. };
  138537. static static_bookblock _resbook_44u_2={
  138538. {
  138539. {0},
  138540. {0,0,&_44u2__p1_0},
  138541. {0,0,&_44u2__p2_0},
  138542. {0,0,&_44u2__p3_0},
  138543. {0,0,&_44u2__p4_0},
  138544. {0,0,&_44u2__p5_0},
  138545. {&_44u2__p6_0,&_44u2__p6_1},
  138546. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  138547. }
  138548. };
  138549. static static_bookblock _resbook_44u_3={
  138550. {
  138551. {0},
  138552. {0,0,&_44u3__p1_0},
  138553. {0,0,&_44u3__p2_0},
  138554. {0,0,&_44u3__p3_0},
  138555. {0,0,&_44u3__p4_0},
  138556. {0,0,&_44u3__p5_0},
  138557. {&_44u3__p6_0,&_44u3__p6_1},
  138558. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  138559. }
  138560. };
  138561. static static_bookblock _resbook_44u_4={
  138562. {
  138563. {0},
  138564. {0,0,&_44u4__p1_0},
  138565. {0,0,&_44u4__p2_0},
  138566. {0,0,&_44u4__p3_0},
  138567. {0,0,&_44u4__p4_0},
  138568. {0,0,&_44u4__p5_0},
  138569. {&_44u4__p6_0,&_44u4__p6_1},
  138570. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  138571. }
  138572. };
  138573. static static_bookblock _resbook_44u_5={
  138574. {
  138575. {0},
  138576. {0,0,&_44u5__p1_0},
  138577. {0,0,&_44u5__p2_0},
  138578. {0,0,&_44u5__p3_0},
  138579. {0,0,&_44u5__p4_0},
  138580. {0,0,&_44u5__p5_0},
  138581. {0,0,&_44u5__p6_0},
  138582. {&_44u5__p7_0,&_44u5__p7_1},
  138583. {&_44u5__p8_0,&_44u5__p8_1},
  138584. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  138585. }
  138586. };
  138587. static static_bookblock _resbook_44u_6={
  138588. {
  138589. {0},
  138590. {0,0,&_44u6__p1_0},
  138591. {0,0,&_44u6__p2_0},
  138592. {0,0,&_44u6__p3_0},
  138593. {0,0,&_44u6__p4_0},
  138594. {0,0,&_44u6__p5_0},
  138595. {0,0,&_44u6__p6_0},
  138596. {&_44u6__p7_0,&_44u6__p7_1},
  138597. {&_44u6__p8_0,&_44u6__p8_1},
  138598. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  138599. }
  138600. };
  138601. static static_bookblock _resbook_44u_7={
  138602. {
  138603. {0},
  138604. {0,0,&_44u7__p1_0},
  138605. {0,0,&_44u7__p2_0},
  138606. {0,0,&_44u7__p3_0},
  138607. {0,0,&_44u7__p4_0},
  138608. {0,0,&_44u7__p5_0},
  138609. {0,0,&_44u7__p6_0},
  138610. {&_44u7__p7_0,&_44u7__p7_1},
  138611. {&_44u7__p8_0,&_44u7__p8_1},
  138612. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  138613. }
  138614. };
  138615. static static_bookblock _resbook_44u_8={
  138616. {
  138617. {0},
  138618. {0,0,&_44u8_p1_0},
  138619. {0,0,&_44u8_p2_0},
  138620. {0,0,&_44u8_p3_0},
  138621. {0,0,&_44u8_p4_0},
  138622. {&_44u8_p5_0,&_44u8_p5_1},
  138623. {&_44u8_p6_0,&_44u8_p6_1},
  138624. {&_44u8_p7_0,&_44u8_p7_1},
  138625. {&_44u8_p8_0,&_44u8_p8_1},
  138626. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  138627. }
  138628. };
  138629. static static_bookblock _resbook_44u_9={
  138630. {
  138631. {0},
  138632. {0,0,&_44u9_p1_0},
  138633. {0,0,&_44u9_p2_0},
  138634. {0,0,&_44u9_p3_0},
  138635. {0,0,&_44u9_p4_0},
  138636. {&_44u9_p5_0,&_44u9_p5_1},
  138637. {&_44u9_p6_0,&_44u9_p6_1},
  138638. {&_44u9_p7_0,&_44u9_p7_1},
  138639. {&_44u9_p8_0,&_44u9_p8_1},
  138640. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  138641. }
  138642. };
  138643. static vorbis_residue_template _res_44u_n1[]={
  138644. {1,0, &_residue_44_low_un,
  138645. &_huff_book__44un1__short,&_huff_book__44un1__short,
  138646. &_resbook_44u_n1,&_resbook_44u_n1},
  138647. {1,0, &_residue_44_low_un,
  138648. &_huff_book__44un1__long,&_huff_book__44un1__long,
  138649. &_resbook_44u_n1,&_resbook_44u_n1}
  138650. };
  138651. static vorbis_residue_template _res_44u_0[]={
  138652. {1,0, &_residue_44_low_un,
  138653. &_huff_book__44u0__short,&_huff_book__44u0__short,
  138654. &_resbook_44u_0,&_resbook_44u_0},
  138655. {1,0, &_residue_44_low_un,
  138656. &_huff_book__44u0__long,&_huff_book__44u0__long,
  138657. &_resbook_44u_0,&_resbook_44u_0}
  138658. };
  138659. static vorbis_residue_template _res_44u_1[]={
  138660. {1,0, &_residue_44_low_un,
  138661. &_huff_book__44u1__short,&_huff_book__44u1__short,
  138662. &_resbook_44u_1,&_resbook_44u_1},
  138663. {1,0, &_residue_44_low_un,
  138664. &_huff_book__44u1__long,&_huff_book__44u1__long,
  138665. &_resbook_44u_1,&_resbook_44u_1}
  138666. };
  138667. static vorbis_residue_template _res_44u_2[]={
  138668. {1,0, &_residue_44_low_un,
  138669. &_huff_book__44u2__short,&_huff_book__44u2__short,
  138670. &_resbook_44u_2,&_resbook_44u_2},
  138671. {1,0, &_residue_44_low_un,
  138672. &_huff_book__44u2__long,&_huff_book__44u2__long,
  138673. &_resbook_44u_2,&_resbook_44u_2}
  138674. };
  138675. static vorbis_residue_template _res_44u_3[]={
  138676. {1,0, &_residue_44_low_un,
  138677. &_huff_book__44u3__short,&_huff_book__44u3__short,
  138678. &_resbook_44u_3,&_resbook_44u_3},
  138679. {1,0, &_residue_44_low_un,
  138680. &_huff_book__44u3__long,&_huff_book__44u3__long,
  138681. &_resbook_44u_3,&_resbook_44u_3}
  138682. };
  138683. static vorbis_residue_template _res_44u_4[]={
  138684. {1,0, &_residue_44_low_un,
  138685. &_huff_book__44u4__short,&_huff_book__44u4__short,
  138686. &_resbook_44u_4,&_resbook_44u_4},
  138687. {1,0, &_residue_44_low_un,
  138688. &_huff_book__44u4__long,&_huff_book__44u4__long,
  138689. &_resbook_44u_4,&_resbook_44u_4}
  138690. };
  138691. static vorbis_residue_template _res_44u_5[]={
  138692. {1,0, &_residue_44_mid_un,
  138693. &_huff_book__44u5__short,&_huff_book__44u5__short,
  138694. &_resbook_44u_5,&_resbook_44u_5},
  138695. {1,0, &_residue_44_mid_un,
  138696. &_huff_book__44u5__long,&_huff_book__44u5__long,
  138697. &_resbook_44u_5,&_resbook_44u_5}
  138698. };
  138699. static vorbis_residue_template _res_44u_6[]={
  138700. {1,0, &_residue_44_mid_un,
  138701. &_huff_book__44u6__short,&_huff_book__44u6__short,
  138702. &_resbook_44u_6,&_resbook_44u_6},
  138703. {1,0, &_residue_44_mid_un,
  138704. &_huff_book__44u6__long,&_huff_book__44u6__long,
  138705. &_resbook_44u_6,&_resbook_44u_6}
  138706. };
  138707. static vorbis_residue_template _res_44u_7[]={
  138708. {1,0, &_residue_44_mid_un,
  138709. &_huff_book__44u7__short,&_huff_book__44u7__short,
  138710. &_resbook_44u_7,&_resbook_44u_7},
  138711. {1,0, &_residue_44_mid_un,
  138712. &_huff_book__44u7__long,&_huff_book__44u7__long,
  138713. &_resbook_44u_7,&_resbook_44u_7}
  138714. };
  138715. static vorbis_residue_template _res_44u_8[]={
  138716. {1,0, &_residue_44_hi_un,
  138717. &_huff_book__44u8__short,&_huff_book__44u8__short,
  138718. &_resbook_44u_8,&_resbook_44u_8},
  138719. {1,0, &_residue_44_hi_un,
  138720. &_huff_book__44u8__long,&_huff_book__44u8__long,
  138721. &_resbook_44u_8,&_resbook_44u_8}
  138722. };
  138723. static vorbis_residue_template _res_44u_9[]={
  138724. {1,0, &_residue_44_hi_un,
  138725. &_huff_book__44u9__short,&_huff_book__44u9__short,
  138726. &_resbook_44u_9,&_resbook_44u_9},
  138727. {1,0, &_residue_44_hi_un,
  138728. &_huff_book__44u9__long,&_huff_book__44u9__long,
  138729. &_resbook_44u_9,&_resbook_44u_9}
  138730. };
  138731. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  138732. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  138733. { _map_nominal_u, _res_44u_0 }, /* 0 */
  138734. { _map_nominal_u, _res_44u_1 }, /* 1 */
  138735. { _map_nominal_u, _res_44u_2 }, /* 2 */
  138736. { _map_nominal_u, _res_44u_3 }, /* 3 */
  138737. { _map_nominal_u, _res_44u_4 }, /* 4 */
  138738. { _map_nominal_u, _res_44u_5 }, /* 5 */
  138739. { _map_nominal_u, _res_44u_6 }, /* 6 */
  138740. { _map_nominal_u, _res_44u_7 }, /* 7 */
  138741. { _map_nominal_u, _res_44u_8 }, /* 8 */
  138742. { _map_nominal_u, _res_44u_9 }, /* 9 */
  138743. };
  138744. /*** End of inlined file: residue_44u.h ***/
  138745. static double rate_mapping_44_un[12]={
  138746. 32000.,48000.,60000.,70000.,80000.,86000.,
  138747. 96000.,110000.,120000.,140000.,160000.,240001.
  138748. };
  138749. ve_setup_data_template ve_setup_44_uncoupled={
  138750. 11,
  138751. rate_mapping_44_un,
  138752. quality_mapping_44,
  138753. -1,
  138754. 40000,
  138755. 50000,
  138756. blocksize_short_44,
  138757. blocksize_long_44,
  138758. _psy_tone_masteratt_44,
  138759. _psy_tone_0dB,
  138760. _psy_tone_suppress,
  138761. _vp_tonemask_adj_otherblock,
  138762. _vp_tonemask_adj_longblock,
  138763. _vp_tonemask_adj_otherblock,
  138764. _psy_noiseguards_44,
  138765. _psy_noisebias_impulse,
  138766. _psy_noisebias_padding,
  138767. _psy_noisebias_trans,
  138768. _psy_noisebias_long,
  138769. _psy_noise_suppress,
  138770. _psy_compand_44,
  138771. _psy_compand_short_mapping,
  138772. _psy_compand_long_mapping,
  138773. {_noise_start_short_44,_noise_start_long_44},
  138774. {_noise_part_short_44,_noise_part_long_44},
  138775. _noise_thresh_44,
  138776. _psy_ath_floater,
  138777. _psy_ath_abs,
  138778. _psy_lowpass_44,
  138779. _psy_global_44,
  138780. _global_mapping_44,
  138781. NULL,
  138782. _floor_books,
  138783. _floor,
  138784. _floor_short_mapping_44,
  138785. _floor_long_mapping_44,
  138786. _mapres_template_44_uncoupled
  138787. };
  138788. /*** End of inlined file: setup_44u.h ***/
  138789. /*** Start of inlined file: setup_32.h ***/
  138790. static double rate_mapping_32[12]={
  138791. 18000.,28000.,35000.,45000.,56000.,60000.,
  138792. 75000.,90000.,100000.,115000.,150000.,190000.,
  138793. };
  138794. static double rate_mapping_32_un[12]={
  138795. 30000.,42000.,52000.,64000.,72000.,78000.,
  138796. 86000.,92000.,110000.,120000.,140000.,190000.,
  138797. };
  138798. static double _psy_lowpass_32[12]={
  138799. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  138800. };
  138801. ve_setup_data_template ve_setup_32_stereo={
  138802. 11,
  138803. rate_mapping_32,
  138804. quality_mapping_44,
  138805. 2,
  138806. 26000,
  138807. 40000,
  138808. blocksize_short_44,
  138809. blocksize_long_44,
  138810. _psy_tone_masteratt_44,
  138811. _psy_tone_0dB,
  138812. _psy_tone_suppress,
  138813. _vp_tonemask_adj_otherblock,
  138814. _vp_tonemask_adj_longblock,
  138815. _vp_tonemask_adj_otherblock,
  138816. _psy_noiseguards_44,
  138817. _psy_noisebias_impulse,
  138818. _psy_noisebias_padding,
  138819. _psy_noisebias_trans,
  138820. _psy_noisebias_long,
  138821. _psy_noise_suppress,
  138822. _psy_compand_44,
  138823. _psy_compand_short_mapping,
  138824. _psy_compand_long_mapping,
  138825. {_noise_start_short_44,_noise_start_long_44},
  138826. {_noise_part_short_44,_noise_part_long_44},
  138827. _noise_thresh_44,
  138828. _psy_ath_floater,
  138829. _psy_ath_abs,
  138830. _psy_lowpass_32,
  138831. _psy_global_44,
  138832. _global_mapping_44,
  138833. _psy_stereo_modes_44,
  138834. _floor_books,
  138835. _floor,
  138836. _floor_short_mapping_44,
  138837. _floor_long_mapping_44,
  138838. _mapres_template_44_stereo
  138839. };
  138840. ve_setup_data_template ve_setup_32_uncoupled={
  138841. 11,
  138842. rate_mapping_32_un,
  138843. quality_mapping_44,
  138844. -1,
  138845. 26000,
  138846. 40000,
  138847. blocksize_short_44,
  138848. blocksize_long_44,
  138849. _psy_tone_masteratt_44,
  138850. _psy_tone_0dB,
  138851. _psy_tone_suppress,
  138852. _vp_tonemask_adj_otherblock,
  138853. _vp_tonemask_adj_longblock,
  138854. _vp_tonemask_adj_otherblock,
  138855. _psy_noiseguards_44,
  138856. _psy_noisebias_impulse,
  138857. _psy_noisebias_padding,
  138858. _psy_noisebias_trans,
  138859. _psy_noisebias_long,
  138860. _psy_noise_suppress,
  138861. _psy_compand_44,
  138862. _psy_compand_short_mapping,
  138863. _psy_compand_long_mapping,
  138864. {_noise_start_short_44,_noise_start_long_44},
  138865. {_noise_part_short_44,_noise_part_long_44},
  138866. _noise_thresh_44,
  138867. _psy_ath_floater,
  138868. _psy_ath_abs,
  138869. _psy_lowpass_32,
  138870. _psy_global_44,
  138871. _global_mapping_44,
  138872. NULL,
  138873. _floor_books,
  138874. _floor,
  138875. _floor_short_mapping_44,
  138876. _floor_long_mapping_44,
  138877. _mapres_template_44_uncoupled
  138878. };
  138879. /*** End of inlined file: setup_32.h ***/
  138880. /*** Start of inlined file: setup_8.h ***/
  138881. /*** Start of inlined file: psych_8.h ***/
  138882. static att3 _psy_tone_masteratt_8[3]={
  138883. {{ 32, 25, 12}, 0, 0}, /* 0 */
  138884. {{ 30, 25, 12}, 0, 0}, /* 0 */
  138885. {{ 20, 0, -14}, 0, 0}, /* 0 */
  138886. };
  138887. static vp_adjblock _vp_tonemask_adj_8[3]={
  138888. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138889. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  138890. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  138891. };
  138892. static noise3 _psy_noisebias_8[3]={
  138893. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138894. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  138895. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138896. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  138897. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  138898. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  138899. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  138900. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  138901. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  138902. };
  138903. static adj_stereo _psy_stereo_modes_8[3]={
  138904. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138905. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138906. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138907. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138908. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138909. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138910. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138911. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138912. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  138913. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  138914. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  138915. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  138916. };
  138917. static noiseguard _psy_noiseguards_8[2]={
  138918. {10,10,-1},
  138919. {10,10,-1},
  138920. };
  138921. static compandblock _psy_compand_8[2]={
  138922. {{
  138923. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  138924. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  138925. 12,12,13,13,14,14,15, 15, /* 23dB */
  138926. 16,16,17,17,17,18,18, 19, /* 31dB */
  138927. 19,19,20,21,22,23,24, 25, /* 39dB */
  138928. }},
  138929. {{
  138930. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  138931. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  138932. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  138933. 9,10,11,12,13,14,15, 16, /* 31dB */
  138934. 17,18,19,20,21,22,23, 24, /* 39dB */
  138935. }},
  138936. };
  138937. static double _psy_lowpass_8[3]={3.,4.,4.};
  138938. static int _noise_start_8[2]={
  138939. 64,64,
  138940. };
  138941. static int _noise_part_8[2]={
  138942. 8,8,
  138943. };
  138944. static int _psy_ath_floater_8[3]={
  138945. -100,-100,-105,
  138946. };
  138947. static int _psy_ath_abs_8[3]={
  138948. -130,-130,-140,
  138949. };
  138950. /*** End of inlined file: psych_8.h ***/
  138951. /*** Start of inlined file: residue_8.h ***/
  138952. static static_bookblock _resbook_8s_0={
  138953. {
  138954. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  138955. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  138956. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  138957. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  138958. }
  138959. };
  138960. static static_bookblock _resbook_8s_1={
  138961. {
  138962. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  138963. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  138964. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  138965. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  138966. }
  138967. };
  138968. static vorbis_residue_template _res_8s_0[]={
  138969. {2,0, &_residue_44_mid,
  138970. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  138971. &_resbook_8s_0,&_resbook_8s_0},
  138972. };
  138973. static vorbis_residue_template _res_8s_1[]={
  138974. {2,0, &_residue_44_mid,
  138975. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  138976. &_resbook_8s_1,&_resbook_8s_1},
  138977. };
  138978. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  138979. { _map_nominal, _res_8s_0 }, /* 0 */
  138980. { _map_nominal, _res_8s_1 }, /* 1 */
  138981. };
  138982. static static_bookblock _resbook_8u_0={
  138983. {
  138984. {0},
  138985. {0,0,&_8u0__p1_0},
  138986. {0,0,&_8u0__p2_0},
  138987. {0,0,&_8u0__p3_0},
  138988. {0,0,&_8u0__p4_0},
  138989. {0,0,&_8u0__p5_0},
  138990. {&_8u0__p6_0,&_8u0__p6_1},
  138991. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  138992. }
  138993. };
  138994. static static_bookblock _resbook_8u_1={
  138995. {
  138996. {0},
  138997. {0,0,&_8u1__p1_0},
  138998. {0,0,&_8u1__p2_0},
  138999. {0,0,&_8u1__p3_0},
  139000. {0,0,&_8u1__p4_0},
  139001. {0,0,&_8u1__p5_0},
  139002. {0,0,&_8u1__p6_0},
  139003. {&_8u1__p7_0,&_8u1__p7_1},
  139004. {&_8u1__p8_0,&_8u1__p8_1},
  139005. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139006. }
  139007. };
  139008. static vorbis_residue_template _res_8u_0[]={
  139009. {1,0, &_residue_44_low_un,
  139010. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139011. &_resbook_8u_0,&_resbook_8u_0},
  139012. };
  139013. static vorbis_residue_template _res_8u_1[]={
  139014. {1,0, &_residue_44_mid_un,
  139015. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139016. &_resbook_8u_1,&_resbook_8u_1},
  139017. };
  139018. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139019. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139020. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139021. };
  139022. /*** End of inlined file: residue_8.h ***/
  139023. static int blocksize_8[2]={
  139024. 512,512
  139025. };
  139026. static int _floor_mapping_8[2]={
  139027. 6,6,
  139028. };
  139029. static double rate_mapping_8[3]={
  139030. 6000.,9000.,32000.,
  139031. };
  139032. static double rate_mapping_8_uncoupled[3]={
  139033. 8000.,14000.,42000.,
  139034. };
  139035. static double quality_mapping_8[3]={
  139036. -.1,.0,1.
  139037. };
  139038. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139039. static double _global_mapping_8[3]={ 1., 2., 3. };
  139040. ve_setup_data_template ve_setup_8_stereo={
  139041. 2,
  139042. rate_mapping_8,
  139043. quality_mapping_8,
  139044. 2,
  139045. 8000,
  139046. 9000,
  139047. blocksize_8,
  139048. blocksize_8,
  139049. _psy_tone_masteratt_8,
  139050. _psy_tone_0dB,
  139051. _psy_tone_suppress,
  139052. _vp_tonemask_adj_8,
  139053. NULL,
  139054. _vp_tonemask_adj_8,
  139055. _psy_noiseguards_8,
  139056. _psy_noisebias_8,
  139057. _psy_noisebias_8,
  139058. NULL,
  139059. NULL,
  139060. _psy_noise_suppress,
  139061. _psy_compand_8,
  139062. _psy_compand_8_mapping,
  139063. NULL,
  139064. {_noise_start_8,_noise_start_8},
  139065. {_noise_part_8,_noise_part_8},
  139066. _noise_thresh_5only,
  139067. _psy_ath_floater_8,
  139068. _psy_ath_abs_8,
  139069. _psy_lowpass_8,
  139070. _psy_global_44,
  139071. _global_mapping_8,
  139072. _psy_stereo_modes_8,
  139073. _floor_books,
  139074. _floor,
  139075. _floor_mapping_8,
  139076. NULL,
  139077. _mapres_template_8_stereo
  139078. };
  139079. ve_setup_data_template ve_setup_8_uncoupled={
  139080. 2,
  139081. rate_mapping_8_uncoupled,
  139082. quality_mapping_8,
  139083. -1,
  139084. 8000,
  139085. 9000,
  139086. blocksize_8,
  139087. blocksize_8,
  139088. _psy_tone_masteratt_8,
  139089. _psy_tone_0dB,
  139090. _psy_tone_suppress,
  139091. _vp_tonemask_adj_8,
  139092. NULL,
  139093. _vp_tonemask_adj_8,
  139094. _psy_noiseguards_8,
  139095. _psy_noisebias_8,
  139096. _psy_noisebias_8,
  139097. NULL,
  139098. NULL,
  139099. _psy_noise_suppress,
  139100. _psy_compand_8,
  139101. _psy_compand_8_mapping,
  139102. NULL,
  139103. {_noise_start_8,_noise_start_8},
  139104. {_noise_part_8,_noise_part_8},
  139105. _noise_thresh_5only,
  139106. _psy_ath_floater_8,
  139107. _psy_ath_abs_8,
  139108. _psy_lowpass_8,
  139109. _psy_global_44,
  139110. _global_mapping_8,
  139111. _psy_stereo_modes_8,
  139112. _floor_books,
  139113. _floor,
  139114. _floor_mapping_8,
  139115. NULL,
  139116. _mapres_template_8_uncoupled
  139117. };
  139118. /*** End of inlined file: setup_8.h ***/
  139119. /*** Start of inlined file: setup_11.h ***/
  139120. /*** Start of inlined file: psych_11.h ***/
  139121. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139122. static att3 _psy_tone_masteratt_11[3]={
  139123. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139124. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139125. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139126. };
  139127. static vp_adjblock _vp_tonemask_adj_11[3]={
  139128. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139129. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139130. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139131. };
  139132. static noise3 _psy_noisebias_11[3]={
  139133. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139134. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139135. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139136. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139137. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139138. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139139. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139140. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139141. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139142. };
  139143. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139144. /*** End of inlined file: psych_11.h ***/
  139145. static int blocksize_11[2]={
  139146. 512,512
  139147. };
  139148. static int _floor_mapping_11[2]={
  139149. 6,6,
  139150. };
  139151. static double rate_mapping_11[3]={
  139152. 8000.,13000.,44000.,
  139153. };
  139154. static double rate_mapping_11_uncoupled[3]={
  139155. 12000.,20000.,50000.,
  139156. };
  139157. static double quality_mapping_11[3]={
  139158. -.1,.0,1.
  139159. };
  139160. ve_setup_data_template ve_setup_11_stereo={
  139161. 2,
  139162. rate_mapping_11,
  139163. quality_mapping_11,
  139164. 2,
  139165. 9000,
  139166. 15000,
  139167. blocksize_11,
  139168. blocksize_11,
  139169. _psy_tone_masteratt_11,
  139170. _psy_tone_0dB,
  139171. _psy_tone_suppress,
  139172. _vp_tonemask_adj_11,
  139173. NULL,
  139174. _vp_tonemask_adj_11,
  139175. _psy_noiseguards_8,
  139176. _psy_noisebias_11,
  139177. _psy_noisebias_11,
  139178. NULL,
  139179. NULL,
  139180. _psy_noise_suppress,
  139181. _psy_compand_8,
  139182. _psy_compand_8_mapping,
  139183. NULL,
  139184. {_noise_start_8,_noise_start_8},
  139185. {_noise_part_8,_noise_part_8},
  139186. _noise_thresh_11,
  139187. _psy_ath_floater_8,
  139188. _psy_ath_abs_8,
  139189. _psy_lowpass_11,
  139190. _psy_global_44,
  139191. _global_mapping_8,
  139192. _psy_stereo_modes_8,
  139193. _floor_books,
  139194. _floor,
  139195. _floor_mapping_11,
  139196. NULL,
  139197. _mapres_template_8_stereo
  139198. };
  139199. ve_setup_data_template ve_setup_11_uncoupled={
  139200. 2,
  139201. rate_mapping_11_uncoupled,
  139202. quality_mapping_11,
  139203. -1,
  139204. 9000,
  139205. 15000,
  139206. blocksize_11,
  139207. blocksize_11,
  139208. _psy_tone_masteratt_11,
  139209. _psy_tone_0dB,
  139210. _psy_tone_suppress,
  139211. _vp_tonemask_adj_11,
  139212. NULL,
  139213. _vp_tonemask_adj_11,
  139214. _psy_noiseguards_8,
  139215. _psy_noisebias_11,
  139216. _psy_noisebias_11,
  139217. NULL,
  139218. NULL,
  139219. _psy_noise_suppress,
  139220. _psy_compand_8,
  139221. _psy_compand_8_mapping,
  139222. NULL,
  139223. {_noise_start_8,_noise_start_8},
  139224. {_noise_part_8,_noise_part_8},
  139225. _noise_thresh_11,
  139226. _psy_ath_floater_8,
  139227. _psy_ath_abs_8,
  139228. _psy_lowpass_11,
  139229. _psy_global_44,
  139230. _global_mapping_8,
  139231. _psy_stereo_modes_8,
  139232. _floor_books,
  139233. _floor,
  139234. _floor_mapping_11,
  139235. NULL,
  139236. _mapres_template_8_uncoupled
  139237. };
  139238. /*** End of inlined file: setup_11.h ***/
  139239. /*** Start of inlined file: setup_16.h ***/
  139240. /*** Start of inlined file: psych_16.h ***/
  139241. static adj_stereo _psy_stereo_modes_16[4]={
  139242. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139243. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139244. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139245. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139246. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139247. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139248. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139249. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139250. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139251. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139252. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139253. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139254. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139255. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139256. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139257. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139258. };
  139259. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139260. static att3 _psy_tone_masteratt_16[4]={
  139261. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139262. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139263. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139264. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139265. };
  139266. static vp_adjblock _vp_tonemask_adj_16[4]={
  139267. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139268. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139269. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139270. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139271. };
  139272. static noise3 _psy_noisebias_16_short[4]={
  139273. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139274. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 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,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139277. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139278. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139279. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139280. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139281. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139282. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139283. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139284. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139285. };
  139286. static noise3 _psy_noisebias_16_impulse[4]={
  139287. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139288. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139289. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139290. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139291. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139292. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139293. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139294. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139295. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139296. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139297. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139298. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139299. };
  139300. static noise3 _psy_noisebias_16[4]={
  139301. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139302. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139303. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139304. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139305. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139306. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139307. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139308. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139309. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139310. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139311. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139312. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139313. };
  139314. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139315. static int _noise_start_16[3]={ 256,256,9999 };
  139316. static int _noise_part_16[4]={ 8,8,8,8 };
  139317. static int _psy_ath_floater_16[4]={
  139318. -100,-100,-100,-105,
  139319. };
  139320. static int _psy_ath_abs_16[4]={
  139321. -130,-130,-130,-140,
  139322. };
  139323. /*** End of inlined file: psych_16.h ***/
  139324. /*** Start of inlined file: residue_16.h ***/
  139325. static static_bookblock _resbook_16s_0={
  139326. {
  139327. {0},
  139328. {0,0,&_16c0_s_p1_0},
  139329. {0,0,&_16c0_s_p2_0},
  139330. {0,0,&_16c0_s_p3_0},
  139331. {0,0,&_16c0_s_p4_0},
  139332. {0,0,&_16c0_s_p5_0},
  139333. {0,0,&_16c0_s_p6_0},
  139334. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139335. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139336. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139337. }
  139338. };
  139339. static static_bookblock _resbook_16s_1={
  139340. {
  139341. {0},
  139342. {0,0,&_16c1_s_p1_0},
  139343. {0,0,&_16c1_s_p2_0},
  139344. {0,0,&_16c1_s_p3_0},
  139345. {0,0,&_16c1_s_p4_0},
  139346. {0,0,&_16c1_s_p5_0},
  139347. {0,0,&_16c1_s_p6_0},
  139348. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139349. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139350. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139351. }
  139352. };
  139353. static static_bookblock _resbook_16s_2={
  139354. {
  139355. {0},
  139356. {0,0,&_16c2_s_p1_0},
  139357. {0,0,&_16c2_s_p2_0},
  139358. {0,0,&_16c2_s_p3_0},
  139359. {0,0,&_16c2_s_p4_0},
  139360. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139361. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139362. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139363. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139364. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139365. }
  139366. };
  139367. static vorbis_residue_template _res_16s_0[]={
  139368. {2,0, &_residue_44_mid,
  139369. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139370. &_resbook_16s_0,&_resbook_16s_0},
  139371. };
  139372. static vorbis_residue_template _res_16s_1[]={
  139373. {2,0, &_residue_44_mid,
  139374. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139375. &_resbook_16s_1,&_resbook_16s_1},
  139376. {2,0, &_residue_44_mid,
  139377. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139378. &_resbook_16s_1,&_resbook_16s_1}
  139379. };
  139380. static vorbis_residue_template _res_16s_2[]={
  139381. {2,0, &_residue_44_high,
  139382. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139383. &_resbook_16s_2,&_resbook_16s_2},
  139384. {2,0, &_residue_44_high,
  139385. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139386. &_resbook_16s_2,&_resbook_16s_2}
  139387. };
  139388. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139389. { _map_nominal, _res_16s_0 }, /* 0 */
  139390. { _map_nominal, _res_16s_1 }, /* 1 */
  139391. { _map_nominal, _res_16s_2 }, /* 2 */
  139392. };
  139393. static static_bookblock _resbook_16u_0={
  139394. {
  139395. {0},
  139396. {0,0,&_16u0__p1_0},
  139397. {0,0,&_16u0__p2_0},
  139398. {0,0,&_16u0__p3_0},
  139399. {0,0,&_16u0__p4_0},
  139400. {0,0,&_16u0__p5_0},
  139401. {&_16u0__p6_0,&_16u0__p6_1},
  139402. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139403. }
  139404. };
  139405. static static_bookblock _resbook_16u_1={
  139406. {
  139407. {0},
  139408. {0,0,&_16u1__p1_0},
  139409. {0,0,&_16u1__p2_0},
  139410. {0,0,&_16u1__p3_0},
  139411. {0,0,&_16u1__p4_0},
  139412. {0,0,&_16u1__p5_0},
  139413. {0,0,&_16u1__p6_0},
  139414. {&_16u1__p7_0,&_16u1__p7_1},
  139415. {&_16u1__p8_0,&_16u1__p8_1},
  139416. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139417. }
  139418. };
  139419. static static_bookblock _resbook_16u_2={
  139420. {
  139421. {0},
  139422. {0,0,&_16u2_p1_0},
  139423. {0,0,&_16u2_p2_0},
  139424. {0,0,&_16u2_p3_0},
  139425. {0,0,&_16u2_p4_0},
  139426. {&_16u2_p5_0,&_16u2_p5_1},
  139427. {&_16u2_p6_0,&_16u2_p6_1},
  139428. {&_16u2_p7_0,&_16u2_p7_1},
  139429. {&_16u2_p8_0,&_16u2_p8_1},
  139430. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139431. }
  139432. };
  139433. static vorbis_residue_template _res_16u_0[]={
  139434. {1,0, &_residue_44_low_un,
  139435. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139436. &_resbook_16u_0,&_resbook_16u_0},
  139437. };
  139438. static vorbis_residue_template _res_16u_1[]={
  139439. {1,0, &_residue_44_mid_un,
  139440. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139441. &_resbook_16u_1,&_resbook_16u_1},
  139442. {1,0, &_residue_44_mid_un,
  139443. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139444. &_resbook_16u_1,&_resbook_16u_1}
  139445. };
  139446. static vorbis_residue_template _res_16u_2[]={
  139447. {1,0, &_residue_44_hi_un,
  139448. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139449. &_resbook_16u_2,&_resbook_16u_2},
  139450. {1,0, &_residue_44_hi_un,
  139451. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139452. &_resbook_16u_2,&_resbook_16u_2}
  139453. };
  139454. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139455. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139456. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139457. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139458. };
  139459. /*** End of inlined file: residue_16.h ***/
  139460. static int blocksize_16_short[3]={
  139461. 1024,512,512
  139462. };
  139463. static int blocksize_16_long[3]={
  139464. 1024,1024,1024
  139465. };
  139466. static int _floor_mapping_16_short[3]={
  139467. 9,3,3
  139468. };
  139469. static int _floor_mapping_16[3]={
  139470. 9,9,9
  139471. };
  139472. static double rate_mapping_16[4]={
  139473. 12000.,20000.,44000.,86000.
  139474. };
  139475. static double rate_mapping_16_uncoupled[4]={
  139476. 16000.,28000.,64000.,100000.
  139477. };
  139478. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139479. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139480. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139481. ve_setup_data_template ve_setup_16_stereo={
  139482. 3,
  139483. rate_mapping_16,
  139484. quality_mapping_16,
  139485. 2,
  139486. 15000,
  139487. 19000,
  139488. blocksize_16_short,
  139489. blocksize_16_long,
  139490. _psy_tone_masteratt_16,
  139491. _psy_tone_0dB,
  139492. _psy_tone_suppress,
  139493. _vp_tonemask_adj_16,
  139494. _vp_tonemask_adj_16,
  139495. _vp_tonemask_adj_16,
  139496. _psy_noiseguards_8,
  139497. _psy_noisebias_16_impulse,
  139498. _psy_noisebias_16_short,
  139499. _psy_noisebias_16_short,
  139500. _psy_noisebias_16,
  139501. _psy_noise_suppress,
  139502. _psy_compand_8,
  139503. _psy_compand_16_mapping,
  139504. _psy_compand_16_mapping,
  139505. {_noise_start_16,_noise_start_16},
  139506. { _noise_part_16, _noise_part_16},
  139507. _noise_thresh_16,
  139508. _psy_ath_floater_16,
  139509. _psy_ath_abs_16,
  139510. _psy_lowpass_16,
  139511. _psy_global_44,
  139512. _global_mapping_16,
  139513. _psy_stereo_modes_16,
  139514. _floor_books,
  139515. _floor,
  139516. _floor_mapping_16_short,
  139517. _floor_mapping_16,
  139518. _mapres_template_16_stereo
  139519. };
  139520. ve_setup_data_template ve_setup_16_uncoupled={
  139521. 3,
  139522. rate_mapping_16_uncoupled,
  139523. quality_mapping_16,
  139524. -1,
  139525. 15000,
  139526. 19000,
  139527. blocksize_16_short,
  139528. blocksize_16_long,
  139529. _psy_tone_masteratt_16,
  139530. _psy_tone_0dB,
  139531. _psy_tone_suppress,
  139532. _vp_tonemask_adj_16,
  139533. _vp_tonemask_adj_16,
  139534. _vp_tonemask_adj_16,
  139535. _psy_noiseguards_8,
  139536. _psy_noisebias_16_impulse,
  139537. _psy_noisebias_16_short,
  139538. _psy_noisebias_16_short,
  139539. _psy_noisebias_16,
  139540. _psy_noise_suppress,
  139541. _psy_compand_8,
  139542. _psy_compand_16_mapping,
  139543. _psy_compand_16_mapping,
  139544. {_noise_start_16,_noise_start_16},
  139545. { _noise_part_16, _noise_part_16},
  139546. _noise_thresh_16,
  139547. _psy_ath_floater_16,
  139548. _psy_ath_abs_16,
  139549. _psy_lowpass_16,
  139550. _psy_global_44,
  139551. _global_mapping_16,
  139552. _psy_stereo_modes_16,
  139553. _floor_books,
  139554. _floor,
  139555. _floor_mapping_16_short,
  139556. _floor_mapping_16,
  139557. _mapres_template_16_uncoupled
  139558. };
  139559. /*** End of inlined file: setup_16.h ***/
  139560. /*** Start of inlined file: setup_22.h ***/
  139561. static double rate_mapping_22[4]={
  139562. 15000.,20000.,44000.,86000.
  139563. };
  139564. static double rate_mapping_22_uncoupled[4]={
  139565. 16000.,28000.,50000.,90000.
  139566. };
  139567. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  139568. ve_setup_data_template ve_setup_22_stereo={
  139569. 3,
  139570. rate_mapping_22,
  139571. quality_mapping_16,
  139572. 2,
  139573. 19000,
  139574. 26000,
  139575. blocksize_16_short,
  139576. blocksize_16_long,
  139577. _psy_tone_masteratt_16,
  139578. _psy_tone_0dB,
  139579. _psy_tone_suppress,
  139580. _vp_tonemask_adj_16,
  139581. _vp_tonemask_adj_16,
  139582. _vp_tonemask_adj_16,
  139583. _psy_noiseguards_8,
  139584. _psy_noisebias_16_impulse,
  139585. _psy_noisebias_16_short,
  139586. _psy_noisebias_16_short,
  139587. _psy_noisebias_16,
  139588. _psy_noise_suppress,
  139589. _psy_compand_8,
  139590. _psy_compand_8_mapping,
  139591. _psy_compand_8_mapping,
  139592. {_noise_start_16,_noise_start_16},
  139593. { _noise_part_16, _noise_part_16},
  139594. _noise_thresh_16,
  139595. _psy_ath_floater_16,
  139596. _psy_ath_abs_16,
  139597. _psy_lowpass_22,
  139598. _psy_global_44,
  139599. _global_mapping_16,
  139600. _psy_stereo_modes_16,
  139601. _floor_books,
  139602. _floor,
  139603. _floor_mapping_16_short,
  139604. _floor_mapping_16,
  139605. _mapres_template_16_stereo
  139606. };
  139607. ve_setup_data_template ve_setup_22_uncoupled={
  139608. 3,
  139609. rate_mapping_22_uncoupled,
  139610. quality_mapping_16,
  139611. -1,
  139612. 19000,
  139613. 26000,
  139614. blocksize_16_short,
  139615. blocksize_16_long,
  139616. _psy_tone_masteratt_16,
  139617. _psy_tone_0dB,
  139618. _psy_tone_suppress,
  139619. _vp_tonemask_adj_16,
  139620. _vp_tonemask_adj_16,
  139621. _vp_tonemask_adj_16,
  139622. _psy_noiseguards_8,
  139623. _psy_noisebias_16_impulse,
  139624. _psy_noisebias_16_short,
  139625. _psy_noisebias_16_short,
  139626. _psy_noisebias_16,
  139627. _psy_noise_suppress,
  139628. _psy_compand_8,
  139629. _psy_compand_8_mapping,
  139630. _psy_compand_8_mapping,
  139631. {_noise_start_16,_noise_start_16},
  139632. { _noise_part_16, _noise_part_16},
  139633. _noise_thresh_16,
  139634. _psy_ath_floater_16,
  139635. _psy_ath_abs_16,
  139636. _psy_lowpass_22,
  139637. _psy_global_44,
  139638. _global_mapping_16,
  139639. _psy_stereo_modes_16,
  139640. _floor_books,
  139641. _floor,
  139642. _floor_mapping_16_short,
  139643. _floor_mapping_16,
  139644. _mapres_template_16_uncoupled
  139645. };
  139646. /*** End of inlined file: setup_22.h ***/
  139647. /*** Start of inlined file: setup_X.h ***/
  139648. static double rate_mapping_X[12]={
  139649. -1.,-1.,-1.,-1.,-1.,-1.,
  139650. -1.,-1.,-1.,-1.,-1.,-1.
  139651. };
  139652. ve_setup_data_template ve_setup_X_stereo={
  139653. 11,
  139654. rate_mapping_X,
  139655. quality_mapping_44,
  139656. 2,
  139657. 50000,
  139658. 200000,
  139659. blocksize_short_44,
  139660. blocksize_long_44,
  139661. _psy_tone_masteratt_44,
  139662. _psy_tone_0dB,
  139663. _psy_tone_suppress,
  139664. _vp_tonemask_adj_otherblock,
  139665. _vp_tonemask_adj_longblock,
  139666. _vp_tonemask_adj_otherblock,
  139667. _psy_noiseguards_44,
  139668. _psy_noisebias_impulse,
  139669. _psy_noisebias_padding,
  139670. _psy_noisebias_trans,
  139671. _psy_noisebias_long,
  139672. _psy_noise_suppress,
  139673. _psy_compand_44,
  139674. _psy_compand_short_mapping,
  139675. _psy_compand_long_mapping,
  139676. {_noise_start_short_44,_noise_start_long_44},
  139677. {_noise_part_short_44,_noise_part_long_44},
  139678. _noise_thresh_44,
  139679. _psy_ath_floater,
  139680. _psy_ath_abs,
  139681. _psy_lowpass_44,
  139682. _psy_global_44,
  139683. _global_mapping_44,
  139684. _psy_stereo_modes_44,
  139685. _floor_books,
  139686. _floor,
  139687. _floor_short_mapping_44,
  139688. _floor_long_mapping_44,
  139689. _mapres_template_44_stereo
  139690. };
  139691. ve_setup_data_template ve_setup_X_uncoupled={
  139692. 11,
  139693. rate_mapping_X,
  139694. quality_mapping_44,
  139695. -1,
  139696. 50000,
  139697. 200000,
  139698. blocksize_short_44,
  139699. blocksize_long_44,
  139700. _psy_tone_masteratt_44,
  139701. _psy_tone_0dB,
  139702. _psy_tone_suppress,
  139703. _vp_tonemask_adj_otherblock,
  139704. _vp_tonemask_adj_longblock,
  139705. _vp_tonemask_adj_otherblock,
  139706. _psy_noiseguards_44,
  139707. _psy_noisebias_impulse,
  139708. _psy_noisebias_padding,
  139709. _psy_noisebias_trans,
  139710. _psy_noisebias_long,
  139711. _psy_noise_suppress,
  139712. _psy_compand_44,
  139713. _psy_compand_short_mapping,
  139714. _psy_compand_long_mapping,
  139715. {_noise_start_short_44,_noise_start_long_44},
  139716. {_noise_part_short_44,_noise_part_long_44},
  139717. _noise_thresh_44,
  139718. _psy_ath_floater,
  139719. _psy_ath_abs,
  139720. _psy_lowpass_44,
  139721. _psy_global_44,
  139722. _global_mapping_44,
  139723. NULL,
  139724. _floor_books,
  139725. _floor,
  139726. _floor_short_mapping_44,
  139727. _floor_long_mapping_44,
  139728. _mapres_template_44_uncoupled
  139729. };
  139730. ve_setup_data_template ve_setup_XX_stereo={
  139731. 2,
  139732. rate_mapping_X,
  139733. quality_mapping_8,
  139734. 2,
  139735. 0,
  139736. 8000,
  139737. blocksize_8,
  139738. blocksize_8,
  139739. _psy_tone_masteratt_8,
  139740. _psy_tone_0dB,
  139741. _psy_tone_suppress,
  139742. _vp_tonemask_adj_8,
  139743. NULL,
  139744. _vp_tonemask_adj_8,
  139745. _psy_noiseguards_8,
  139746. _psy_noisebias_8,
  139747. _psy_noisebias_8,
  139748. NULL,
  139749. NULL,
  139750. _psy_noise_suppress,
  139751. _psy_compand_8,
  139752. _psy_compand_8_mapping,
  139753. NULL,
  139754. {_noise_start_8,_noise_start_8},
  139755. {_noise_part_8,_noise_part_8},
  139756. _noise_thresh_5only,
  139757. _psy_ath_floater_8,
  139758. _psy_ath_abs_8,
  139759. _psy_lowpass_8,
  139760. _psy_global_44,
  139761. _global_mapping_8,
  139762. _psy_stereo_modes_8,
  139763. _floor_books,
  139764. _floor,
  139765. _floor_mapping_8,
  139766. NULL,
  139767. _mapres_template_8_stereo
  139768. };
  139769. ve_setup_data_template ve_setup_XX_uncoupled={
  139770. 2,
  139771. rate_mapping_X,
  139772. quality_mapping_8,
  139773. -1,
  139774. 0,
  139775. 8000,
  139776. blocksize_8,
  139777. blocksize_8,
  139778. _psy_tone_masteratt_8,
  139779. _psy_tone_0dB,
  139780. _psy_tone_suppress,
  139781. _vp_tonemask_adj_8,
  139782. NULL,
  139783. _vp_tonemask_adj_8,
  139784. _psy_noiseguards_8,
  139785. _psy_noisebias_8,
  139786. _psy_noisebias_8,
  139787. NULL,
  139788. NULL,
  139789. _psy_noise_suppress,
  139790. _psy_compand_8,
  139791. _psy_compand_8_mapping,
  139792. NULL,
  139793. {_noise_start_8,_noise_start_8},
  139794. {_noise_part_8,_noise_part_8},
  139795. _noise_thresh_5only,
  139796. _psy_ath_floater_8,
  139797. _psy_ath_abs_8,
  139798. _psy_lowpass_8,
  139799. _psy_global_44,
  139800. _global_mapping_8,
  139801. _psy_stereo_modes_8,
  139802. _floor_books,
  139803. _floor,
  139804. _floor_mapping_8,
  139805. NULL,
  139806. _mapres_template_8_uncoupled
  139807. };
  139808. /*** End of inlined file: setup_X.h ***/
  139809. static ve_setup_data_template *setup_list[]={
  139810. &ve_setup_44_stereo,
  139811. &ve_setup_44_uncoupled,
  139812. &ve_setup_32_stereo,
  139813. &ve_setup_32_uncoupled,
  139814. &ve_setup_22_stereo,
  139815. &ve_setup_22_uncoupled,
  139816. &ve_setup_16_stereo,
  139817. &ve_setup_16_uncoupled,
  139818. &ve_setup_11_stereo,
  139819. &ve_setup_11_uncoupled,
  139820. &ve_setup_8_stereo,
  139821. &ve_setup_8_uncoupled,
  139822. &ve_setup_X_stereo,
  139823. &ve_setup_X_uncoupled,
  139824. &ve_setup_XX_stereo,
  139825. &ve_setup_XX_uncoupled,
  139826. 0
  139827. };
  139828. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  139829. if(vi && vi->codec_setup){
  139830. vi->version=0;
  139831. vi->channels=ch;
  139832. vi->rate=rate;
  139833. return(0);
  139834. }
  139835. return(OV_EINVAL);
  139836. }
  139837. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  139838. static_codebook ***books,
  139839. vorbis_info_floor1 *in,
  139840. int *x){
  139841. int i,k,is=s;
  139842. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  139843. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139844. memcpy(f,in+x[is],sizeof(*f));
  139845. f->n=ci->blocksizes[block]>>1;
  139846. {
  139847. int partitions=f->partitions;
  139848. int maxclass=-1;
  139849. int maxbook=-1;
  139850. for(i=0;i<partitions;i++)
  139851. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  139852. for(i=0;i<=maxclass;i++){
  139853. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  139854. f->class_book[i]+=ci->books;
  139855. for(k=0;k<(1<<f->class_subs[i]);k++){
  139856. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  139857. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  139858. }
  139859. }
  139860. for(i=0;i<=maxbook;i++)
  139861. ci->book_param[ci->books++]=books[x[is]][i];
  139862. }
  139863. ci->floor_type[ci->floors]=1;
  139864. ci->floor_param[ci->floors]=f;
  139865. ci->floors++;
  139866. return;
  139867. }
  139868. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  139869. vorbis_info_psy_global *in,
  139870. double *x){
  139871. int i,is=s;
  139872. double ds=s-is;
  139873. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139874. vorbis_info_psy_global *g=&ci->psy_g_param;
  139875. memcpy(g,in+(int)x[is],sizeof(*g));
  139876. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139877. is=(int)ds;
  139878. ds-=is;
  139879. if(ds==0 && is>0){
  139880. is--;
  139881. ds=1.;
  139882. }
  139883. for(i=0;i<4;i++){
  139884. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  139885. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  139886. }
  139887. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  139888. return;
  139889. }
  139890. static void vorbis_encode_global_stereo(vorbis_info *vi,
  139891. highlevel_encode_setup *hi,
  139892. adj_stereo *p){
  139893. float s=hi->stereo_point_setting;
  139894. int i,is=s;
  139895. double ds=s-is;
  139896. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139897. vorbis_info_psy_global *g=&ci->psy_g_param;
  139898. if(p){
  139899. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  139900. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  139901. if(hi->managed){
  139902. for(i=0;i<PACKETBLOBS;i++){
  139903. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  139904. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139905. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139906. g->coupling_pkHz[i]=kHz;
  139907. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  139908. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139909. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139910. }
  139911. }else{
  139912. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  139913. for(i=0;i<PACKETBLOBS;i++){
  139914. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139915. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139916. g->coupling_pkHz[i]=kHz;
  139917. }
  139918. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  139919. for(i=0;i<PACKETBLOBS;i++){
  139920. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  139921. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  139922. }
  139923. }
  139924. }else{
  139925. for(i=0;i<PACKETBLOBS;i++){
  139926. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  139927. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  139928. }
  139929. }
  139930. return;
  139931. }
  139932. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  139933. int *nn_start,
  139934. int *nn_partition,
  139935. double *nn_thresh,
  139936. int block){
  139937. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  139938. vorbis_info_psy *p=ci->psy_param[block];
  139939. highlevel_encode_setup *hi=&ci->hi;
  139940. int is=s;
  139941. if(block>=ci->psys)
  139942. ci->psys=block+1;
  139943. if(!p){
  139944. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  139945. ci->psy_param[block]=p;
  139946. }
  139947. memcpy(p,&_psy_info_template,sizeof(*p));
  139948. p->blockflag=block>>1;
  139949. if(hi->noise_normalize_p){
  139950. p->normal_channel_p=1;
  139951. p->normal_point_p=1;
  139952. p->normal_start=nn_start[is];
  139953. p->normal_partition=nn_partition[is];
  139954. p->normal_thresh=nn_thresh[is];
  139955. }
  139956. return;
  139957. }
  139958. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  139959. att3 *att,
  139960. int *max,
  139961. vp_adjblock *in){
  139962. int i,is=s;
  139963. double ds=s-is;
  139964. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  139965. vorbis_info_psy *p=ci->psy_param[block];
  139966. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  139967. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  139968. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  139969. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  139970. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  139971. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  139972. for(i=0;i<P_BANDS;i++)
  139973. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  139974. return;
  139975. }
  139976. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  139977. compandblock *in, double *x){
  139978. int i,is=s;
  139979. double ds=s-is;
  139980. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139981. vorbis_info_psy *p=ci->psy_param[block];
  139982. ds=x[is]*(1.-ds)+x[is+1]*ds;
  139983. is=(int)ds;
  139984. ds-=is;
  139985. if(ds==0 && is>0){
  139986. is--;
  139987. ds=1.;
  139988. }
  139989. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  139990. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  139991. return;
  139992. }
  139993. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  139994. int *suppress){
  139995. int is=s;
  139996. double ds=s-is;
  139997. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  139998. vorbis_info_psy *p=ci->psy_param[block];
  139999. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140000. return;
  140001. }
  140002. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140003. int *suppress,
  140004. noise3 *in,
  140005. noiseguard *guard,
  140006. double userbias){
  140007. int i,is=s,j;
  140008. double ds=s-is;
  140009. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140010. vorbis_info_psy *p=ci->psy_param[block];
  140011. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140012. p->noisewindowlomin=guard[block].lo;
  140013. p->noisewindowhimin=guard[block].hi;
  140014. p->noisewindowfixed=guard[block].fixed;
  140015. for(j=0;j<P_NOISECURVES;j++)
  140016. for(i=0;i<P_BANDS;i++)
  140017. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140018. for(j=0;j<P_NOISECURVES;j++){
  140019. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140020. for(i=0;i<P_BANDS;i++){
  140021. p->noiseoff[j][i]+=userbias;
  140022. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140023. }
  140024. }
  140025. return;
  140026. }
  140027. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140028. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140029. vorbis_info_psy *p=ci->psy_param[block];
  140030. p->ath_adjatt=ci->hi.ath_floating_dB;
  140031. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140032. return;
  140033. }
  140034. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140035. int i;
  140036. for(i=0;i<ci->books;i++)
  140037. if(ci->book_param[i]==book)return(i);
  140038. return(ci->books++);
  140039. }
  140040. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140041. int *shortb,int *longb){
  140042. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140043. int is=s;
  140044. int blockshort=shortb[is];
  140045. int blocklong=longb[is];
  140046. ci->blocksizes[0]=blockshort;
  140047. ci->blocksizes[1]=blocklong;
  140048. }
  140049. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140050. int number, int block,
  140051. vorbis_residue_template *res){
  140052. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140053. int i,n;
  140054. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140055. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140056. memcpy(r,res->res,sizeof(*r));
  140057. if(ci->residues<=number)ci->residues=number+1;
  140058. switch(ci->blocksizes[block]){
  140059. case 64:case 128:case 256:
  140060. r->grouping=16;
  140061. break;
  140062. default:
  140063. r->grouping=32;
  140064. break;
  140065. }
  140066. ci->residue_type[number]=res->res_type;
  140067. n=r->end=ci->blocksizes[block]>>1;
  140068. if(res->res_type==2)
  140069. n=r->end*=vi->channels;
  140070. {
  140071. int booklist=0,k;
  140072. if(ci->hi.managed){
  140073. for(i=0;i<r->partitions;i++)
  140074. for(k=0;k<3;k++)
  140075. if(res->books_base_managed->books[i][k])
  140076. r->secondstages[i]|=(1<<k);
  140077. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140078. ci->book_param[r->groupbook]=res->book_aux_managed;
  140079. for(i=0;i<r->partitions;i++){
  140080. for(k=0;k<3;k++){
  140081. if(res->books_base_managed->books[i][k]){
  140082. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140083. r->booklist[booklist++]=bookid;
  140084. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140085. }
  140086. }
  140087. }
  140088. }else{
  140089. for(i=0;i<r->partitions;i++)
  140090. for(k=0;k<3;k++)
  140091. if(res->books_base->books[i][k])
  140092. r->secondstages[i]|=(1<<k);
  140093. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140094. ci->book_param[r->groupbook]=res->book_aux;
  140095. for(i=0;i<r->partitions;i++){
  140096. for(k=0;k<3;k++){
  140097. if(res->books_base->books[i][k]){
  140098. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140099. r->booklist[booklist++]=bookid;
  140100. ci->book_param[bookid]=res->books_base->books[i][k];
  140101. }
  140102. }
  140103. }
  140104. }
  140105. }
  140106. {
  140107. double freq=ci->hi.lowpass_kHz*1000.;
  140108. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140109. double nyq=vi->rate/2.;
  140110. long blocksize=ci->blocksizes[block]>>1;
  140111. if(freq>nyq)freq=nyq;
  140112. f->n=freq/nyq*blocksize;
  140113. if(res->limit_type){
  140114. if(ci->hi.managed)
  140115. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140116. else
  140117. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140118. if(freq>nyq)freq=nyq;
  140119. }
  140120. if(ci->residue_type[block]==2)
  140121. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140122. r->grouping;
  140123. else
  140124. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140125. r->grouping;
  140126. }
  140127. }
  140128. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140129. vorbis_mapping_template *maps){
  140130. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140131. int i,j,is=s,modes=2;
  140132. vorbis_info_mapping0 *map=maps[is].map;
  140133. vorbis_info_mode *mode=_mode_template;
  140134. vorbis_residue_template *res=maps[is].res;
  140135. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140136. for(i=0;i<modes;i++){
  140137. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140138. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140139. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140140. if(i>=ci->modes)ci->modes=i+1;
  140141. ci->map_type[i]=0;
  140142. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140143. if(i>=ci->maps)ci->maps=i+1;
  140144. for(j=0;j<map[i].submaps;j++)
  140145. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140146. ,res+map[i].residuesubmap[j]);
  140147. }
  140148. }
  140149. static double setting_to_approx_bitrate(vorbis_info *vi){
  140150. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140151. highlevel_encode_setup *hi=&ci->hi;
  140152. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140153. int is=hi->base_setting;
  140154. double ds=hi->base_setting-is;
  140155. int ch=vi->channels;
  140156. double *r=setup->rate_mapping;
  140157. if(r==NULL)
  140158. return(-1);
  140159. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140160. }
  140161. static void get_setup_template(vorbis_info *vi,
  140162. long ch,long srate,
  140163. double req,int q_or_bitrate){
  140164. int i=0,j;
  140165. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140166. highlevel_encode_setup *hi=&ci->hi;
  140167. if(q_or_bitrate)req/=ch;
  140168. while(setup_list[i]){
  140169. if(setup_list[i]->coupling_restriction==-1 ||
  140170. setup_list[i]->coupling_restriction==ch){
  140171. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140172. srate<=setup_list[i]->samplerate_max_restriction){
  140173. int mappings=setup_list[i]->mappings;
  140174. double *map=(q_or_bitrate?
  140175. setup_list[i]->rate_mapping:
  140176. setup_list[i]->quality_mapping);
  140177. if(req<map[0]){++i;continue;}
  140178. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140179. for(j=0;j<mappings;j++)
  140180. if(req>=map[j] && req<map[j+1])break;
  140181. hi->setup=setup_list[i];
  140182. if(j==mappings)
  140183. hi->base_setting=j-.001;
  140184. else{
  140185. float low=map[j];
  140186. float high=map[j+1];
  140187. float del=(req-low)/(high-low);
  140188. hi->base_setting=j+del;
  140189. }
  140190. return;
  140191. }
  140192. }
  140193. i++;
  140194. }
  140195. hi->setup=NULL;
  140196. }
  140197. int vorbis_encode_setup_init(vorbis_info *vi){
  140198. int i0=0,singleblock=0;
  140199. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140200. ve_setup_data_template *setup=NULL;
  140201. highlevel_encode_setup *hi=&ci->hi;
  140202. if(ci==NULL)return(OV_EINVAL);
  140203. if(!hi->impulse_block_p)i0=1;
  140204. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140205. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140206. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140207. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140208. setup=(ve_setup_data_template *)hi->setup;
  140209. if(setup==NULL)return(OV_EINVAL);
  140210. hi->set_in_stone=1;
  140211. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140212. setup->blocksize_short,
  140213. setup->blocksize_long);
  140214. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140215. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140216. setup->floor_books,
  140217. setup->floor_params,
  140218. setup->floor_short_mapping);
  140219. if(!singleblock)
  140220. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140221. setup->floor_books,
  140222. setup->floor_params,
  140223. setup->floor_long_mapping);
  140224. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140225. setup->global_params,
  140226. setup->global_mapping);
  140227. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140228. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140229. setup->psy_noise_normal_start[0],
  140230. setup->psy_noise_normal_partition[0],
  140231. setup->psy_noise_normal_thresh,
  140232. 0);
  140233. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140234. setup->psy_noise_normal_start[0],
  140235. setup->psy_noise_normal_partition[0],
  140236. setup->psy_noise_normal_thresh,
  140237. 1);
  140238. if(!singleblock){
  140239. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140240. setup->psy_noise_normal_start[1],
  140241. setup->psy_noise_normal_partition[1],
  140242. setup->psy_noise_normal_thresh,
  140243. 2);
  140244. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140245. setup->psy_noise_normal_start[1],
  140246. setup->psy_noise_normal_partition[1],
  140247. setup->psy_noise_normal_thresh,
  140248. 3);
  140249. }
  140250. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140251. setup->psy_tone_masteratt,
  140252. setup->psy_tone_0dB,
  140253. setup->psy_tone_adj_impulse);
  140254. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140255. setup->psy_tone_masteratt,
  140256. setup->psy_tone_0dB,
  140257. setup->psy_tone_adj_other);
  140258. if(!singleblock){
  140259. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140260. setup->psy_tone_masteratt,
  140261. setup->psy_tone_0dB,
  140262. setup->psy_tone_adj_other);
  140263. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140264. setup->psy_tone_masteratt,
  140265. setup->psy_tone_0dB,
  140266. setup->psy_tone_adj_long);
  140267. }
  140268. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140269. setup->psy_noise_compand,
  140270. setup->psy_noise_compand_short_mapping);
  140271. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140272. setup->psy_noise_compand,
  140273. setup->psy_noise_compand_short_mapping);
  140274. if(!singleblock){
  140275. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140276. setup->psy_noise_compand,
  140277. setup->psy_noise_compand_long_mapping);
  140278. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140279. setup->psy_noise_compand,
  140280. setup->psy_noise_compand_long_mapping);
  140281. }
  140282. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140283. setup->psy_tone_dBsuppress);
  140284. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140285. setup->psy_tone_dBsuppress);
  140286. if(!singleblock){
  140287. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140288. setup->psy_tone_dBsuppress);
  140289. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140290. setup->psy_tone_dBsuppress);
  140291. }
  140292. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140293. setup->psy_noise_dBsuppress,
  140294. setup->psy_noise_bias_impulse,
  140295. setup->psy_noiseguards,
  140296. (i0==0?hi->impulse_noisetune:0.));
  140297. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140298. setup->psy_noise_dBsuppress,
  140299. setup->psy_noise_bias_padding,
  140300. setup->psy_noiseguards,0.);
  140301. if(!singleblock){
  140302. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140303. setup->psy_noise_dBsuppress,
  140304. setup->psy_noise_bias_trans,
  140305. setup->psy_noiseguards,0.);
  140306. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140307. setup->psy_noise_dBsuppress,
  140308. setup->psy_noise_bias_long,
  140309. setup->psy_noiseguards,0.);
  140310. }
  140311. vorbis_encode_ath_setup(vi,0);
  140312. vorbis_encode_ath_setup(vi,1);
  140313. if(!singleblock){
  140314. vorbis_encode_ath_setup(vi,2);
  140315. vorbis_encode_ath_setup(vi,3);
  140316. }
  140317. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140318. if(hi->bitrate_av>0)
  140319. vi->bitrate_nominal=hi->bitrate_av;
  140320. else{
  140321. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140322. }
  140323. vi->bitrate_lower=hi->bitrate_min;
  140324. vi->bitrate_upper=hi->bitrate_max;
  140325. if(hi->bitrate_av)
  140326. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140327. else
  140328. vi->bitrate_window=0.;
  140329. if(hi->managed){
  140330. ci->bi.avg_rate=hi->bitrate_av;
  140331. ci->bi.min_rate=hi->bitrate_min;
  140332. ci->bi.max_rate=hi->bitrate_max;
  140333. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140334. ci->bi.reservoir_bias=
  140335. hi->bitrate_reservoir_bias;
  140336. ci->bi.slew_damp=hi->bitrate_av_damp;
  140337. }
  140338. return(0);
  140339. }
  140340. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140341. long channels,
  140342. long rate){
  140343. int ret=0,i,is;
  140344. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140345. highlevel_encode_setup *hi=&ci->hi;
  140346. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140347. double ds;
  140348. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140349. if(ret)return(ret);
  140350. is=hi->base_setting;
  140351. ds=hi->base_setting-is;
  140352. hi->short_setting=hi->base_setting;
  140353. hi->long_setting=hi->base_setting;
  140354. hi->managed=0;
  140355. hi->impulse_block_p=1;
  140356. hi->noise_normalize_p=1;
  140357. hi->stereo_point_setting=hi->base_setting;
  140358. hi->lowpass_kHz=
  140359. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140360. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140361. setup->psy_ath_float[is+1]*ds;
  140362. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140363. setup->psy_ath_abs[is+1]*ds;
  140364. hi->amplitude_track_dBpersec=-6.;
  140365. hi->trigger_setting=hi->base_setting;
  140366. for(i=0;i<4;i++){
  140367. hi->block[i].tone_mask_setting=hi->base_setting;
  140368. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140369. hi->block[i].noise_bias_setting=hi->base_setting;
  140370. hi->block[i].noise_compand_setting=hi->base_setting;
  140371. }
  140372. return(ret);
  140373. }
  140374. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140375. long channels,
  140376. long rate,
  140377. float quality){
  140378. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140379. highlevel_encode_setup *hi=&ci->hi;
  140380. quality+=.0000001;
  140381. if(quality>=1.)quality=.9999;
  140382. get_setup_template(vi,channels,rate,quality,0);
  140383. if(!hi->setup)return OV_EIMPL;
  140384. return vorbis_encode_setup_setting(vi,channels,rate);
  140385. }
  140386. int vorbis_encode_init_vbr(vorbis_info *vi,
  140387. long channels,
  140388. long rate,
  140389. float base_quality /* 0. to 1. */
  140390. ){
  140391. int ret=0;
  140392. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140393. if(ret){
  140394. vorbis_info_clear(vi);
  140395. return ret;
  140396. }
  140397. ret=vorbis_encode_setup_init(vi);
  140398. if(ret)
  140399. vorbis_info_clear(vi);
  140400. return(ret);
  140401. }
  140402. int vorbis_encode_setup_managed(vorbis_info *vi,
  140403. long channels,
  140404. long rate,
  140405. long max_bitrate,
  140406. long nominal_bitrate,
  140407. long min_bitrate){
  140408. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140409. highlevel_encode_setup *hi=&ci->hi;
  140410. double tnominal=nominal_bitrate;
  140411. int ret=0;
  140412. if(nominal_bitrate<=0.){
  140413. if(max_bitrate>0.){
  140414. if(min_bitrate>0.)
  140415. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140416. else
  140417. nominal_bitrate=max_bitrate*.875;
  140418. }else{
  140419. if(min_bitrate>0.){
  140420. nominal_bitrate=min_bitrate;
  140421. }else{
  140422. return(OV_EINVAL);
  140423. }
  140424. }
  140425. }
  140426. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140427. if(!hi->setup)return OV_EIMPL;
  140428. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140429. if(ret){
  140430. vorbis_info_clear(vi);
  140431. return ret;
  140432. }
  140433. hi->managed=1;
  140434. hi->bitrate_min=min_bitrate;
  140435. hi->bitrate_max=max_bitrate;
  140436. hi->bitrate_av=tnominal;
  140437. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140438. hi->bitrate_reservoir=nominal_bitrate*2;
  140439. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140440. return(ret);
  140441. }
  140442. int vorbis_encode_init(vorbis_info *vi,
  140443. long channels,
  140444. long rate,
  140445. long max_bitrate,
  140446. long nominal_bitrate,
  140447. long min_bitrate){
  140448. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140449. max_bitrate,
  140450. nominal_bitrate,
  140451. min_bitrate);
  140452. if(ret){
  140453. vorbis_info_clear(vi);
  140454. return(ret);
  140455. }
  140456. ret=vorbis_encode_setup_init(vi);
  140457. if(ret)
  140458. vorbis_info_clear(vi);
  140459. return(ret);
  140460. }
  140461. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140462. if(vi){
  140463. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140464. highlevel_encode_setup *hi=&ci->hi;
  140465. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140466. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140467. switch(number){
  140468. case OV_ECTL_RATEMANAGE_GET:
  140469. {
  140470. struct ovectl_ratemanage_arg *ai=
  140471. (struct ovectl_ratemanage_arg *)arg;
  140472. ai->management_active=hi->managed;
  140473. ai->bitrate_hard_window=ai->bitrate_av_window=
  140474. (double)hi->bitrate_reservoir/vi->rate;
  140475. ai->bitrate_av_window_center=1.;
  140476. ai->bitrate_hard_min=hi->bitrate_min;
  140477. ai->bitrate_hard_max=hi->bitrate_max;
  140478. ai->bitrate_av_lo=hi->bitrate_av;
  140479. ai->bitrate_av_hi=hi->bitrate_av;
  140480. }
  140481. return(0);
  140482. case OV_ECTL_RATEMANAGE_SET:
  140483. {
  140484. struct ovectl_ratemanage_arg *ai=
  140485. (struct ovectl_ratemanage_arg *)arg;
  140486. if(ai==NULL){
  140487. hi->managed=0;
  140488. }else{
  140489. hi->managed=ai->management_active;
  140490. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140491. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140492. }
  140493. }
  140494. return 0;
  140495. case OV_ECTL_RATEMANAGE_AVG:
  140496. {
  140497. struct ovectl_ratemanage_arg *ai=
  140498. (struct ovectl_ratemanage_arg *)arg;
  140499. if(ai==NULL){
  140500. hi->bitrate_av=0;
  140501. }else{
  140502. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140503. }
  140504. }
  140505. return(0);
  140506. case OV_ECTL_RATEMANAGE_HARD:
  140507. {
  140508. struct ovectl_ratemanage_arg *ai=
  140509. (struct ovectl_ratemanage_arg *)arg;
  140510. if(ai==NULL){
  140511. hi->bitrate_min=0;
  140512. hi->bitrate_max=0;
  140513. }else{
  140514. hi->bitrate_min=ai->bitrate_hard_min;
  140515. hi->bitrate_max=ai->bitrate_hard_max;
  140516. hi->bitrate_reservoir=ai->bitrate_hard_window*
  140517. (hi->bitrate_max+hi->bitrate_min)*.5;
  140518. }
  140519. if(hi->bitrate_reservoir<128.)
  140520. hi->bitrate_reservoir=128.;
  140521. }
  140522. return(0);
  140523. case OV_ECTL_RATEMANAGE2_GET:
  140524. {
  140525. struct ovectl_ratemanage2_arg *ai=
  140526. (struct ovectl_ratemanage2_arg *)arg;
  140527. if(ai==NULL)return OV_EINVAL;
  140528. ai->management_active=hi->managed;
  140529. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  140530. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  140531. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  140532. ai->bitrate_average_damping=hi->bitrate_av_damp;
  140533. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  140534. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  140535. }
  140536. return (0);
  140537. case OV_ECTL_RATEMANAGE2_SET:
  140538. {
  140539. struct ovectl_ratemanage2_arg *ai=
  140540. (struct ovectl_ratemanage2_arg *)arg;
  140541. if(ai==NULL){
  140542. hi->managed=0;
  140543. }else{
  140544. if(ai->bitrate_limit_min_kbps>0 &&
  140545. ai->bitrate_average_kbps>0 &&
  140546. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  140547. return OV_EINVAL;
  140548. if(ai->bitrate_limit_max_kbps>0 &&
  140549. ai->bitrate_average_kbps>0 &&
  140550. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  140551. return OV_EINVAL;
  140552. if(ai->bitrate_limit_min_kbps>0 &&
  140553. ai->bitrate_limit_max_kbps>0 &&
  140554. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  140555. return OV_EINVAL;
  140556. if(ai->bitrate_average_damping <= 0.)
  140557. return OV_EINVAL;
  140558. if(ai->bitrate_limit_reservoir_bits < 0)
  140559. return OV_EINVAL;
  140560. if(ai->bitrate_limit_reservoir_bias < 0.)
  140561. return OV_EINVAL;
  140562. if(ai->bitrate_limit_reservoir_bias > 1.)
  140563. return OV_EINVAL;
  140564. hi->managed=ai->management_active;
  140565. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  140566. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  140567. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  140568. hi->bitrate_av_damp=ai->bitrate_average_damping;
  140569. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  140570. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  140571. }
  140572. }
  140573. return 0;
  140574. case OV_ECTL_LOWPASS_GET:
  140575. {
  140576. double *farg=(double *)arg;
  140577. *farg=hi->lowpass_kHz;
  140578. }
  140579. return(0);
  140580. case OV_ECTL_LOWPASS_SET:
  140581. {
  140582. double *farg=(double *)arg;
  140583. hi->lowpass_kHz=*farg;
  140584. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  140585. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  140586. }
  140587. return(0);
  140588. case OV_ECTL_IBLOCK_GET:
  140589. {
  140590. double *farg=(double *)arg;
  140591. *farg=hi->impulse_noisetune;
  140592. }
  140593. return(0);
  140594. case OV_ECTL_IBLOCK_SET:
  140595. {
  140596. double *farg=(double *)arg;
  140597. hi->impulse_noisetune=*farg;
  140598. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  140599. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  140600. }
  140601. return(0);
  140602. }
  140603. return(OV_EIMPL);
  140604. }
  140605. return(OV_EINVAL);
  140606. }
  140607. #endif
  140608. /*** End of inlined file: vorbisenc.c ***/
  140609. /*** Start of inlined file: vorbisfile.c ***/
  140610. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  140611. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  140612. // tasks..
  140613. #if JUCE_MSVC
  140614. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  140615. #endif
  140616. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  140617. #if JUCE_USE_OGGVORBIS
  140618. #include <stdlib.h>
  140619. #include <stdio.h>
  140620. #include <errno.h>
  140621. #include <string.h>
  140622. #include <math.h>
  140623. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  140624. over 8k gets what they deserve */
  140625. static long _get_data(OggVorbis_File *vf){
  140626. errno=0;
  140627. if(vf->datasource){
  140628. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  140629. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  140630. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  140631. if(bytes==0 && errno)return(-1);
  140632. return(bytes);
  140633. }else
  140634. return(0);
  140635. }
  140636. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  140637. if(vf->datasource){
  140638. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  140639. vf->offset=offset;
  140640. ogg_sync_reset(&vf->oy);
  140641. }else{
  140642. return;
  140643. }
  140644. }
  140645. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  140646. ogg_int64_t boundary){
  140647. if(boundary>0)boundary+=vf->offset;
  140648. while(1){
  140649. long more;
  140650. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  140651. more=ogg_sync_pageseek(&vf->oy,og);
  140652. if(more<0){
  140653. vf->offset-=more;
  140654. }else{
  140655. if(more==0){
  140656. if(!boundary)return(OV_FALSE);
  140657. {
  140658. long ret=_get_data(vf);
  140659. if(ret==0)return(OV_EOF);
  140660. if(ret<0)return(OV_EREAD);
  140661. }
  140662. }else{
  140663. ogg_int64_t ret=vf->offset;
  140664. vf->offset+=more;
  140665. return(ret);
  140666. }
  140667. }
  140668. }
  140669. }
  140670. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  140671. ogg_int64_t begin=vf->offset;
  140672. ogg_int64_t end=begin;
  140673. ogg_int64_t ret;
  140674. ogg_int64_t offset=-1;
  140675. while(offset==-1){
  140676. begin-=CHUNKSIZE;
  140677. if(begin<0)
  140678. begin=0;
  140679. _seek_helper(vf,begin);
  140680. while(vf->offset<end){
  140681. ret=_get_next_page(vf,og,end-vf->offset);
  140682. if(ret==OV_EREAD)return(OV_EREAD);
  140683. if(ret<0){
  140684. break;
  140685. }else{
  140686. offset=ret;
  140687. }
  140688. }
  140689. }
  140690. _seek_helper(vf,offset);
  140691. ret=_get_next_page(vf,og,CHUNKSIZE);
  140692. if(ret<0)
  140693. return(OV_EFAULT);
  140694. return(offset);
  140695. }
  140696. static int _bisect_forward_serialno(OggVorbis_File *vf,
  140697. ogg_int64_t begin,
  140698. ogg_int64_t searched,
  140699. ogg_int64_t end,
  140700. long currentno,
  140701. long m){
  140702. ogg_int64_t endsearched=end;
  140703. ogg_int64_t next=end;
  140704. ogg_page og;
  140705. ogg_int64_t ret;
  140706. while(searched<endsearched){
  140707. ogg_int64_t bisect;
  140708. if(endsearched-searched<CHUNKSIZE){
  140709. bisect=searched;
  140710. }else{
  140711. bisect=(searched+endsearched)/2;
  140712. }
  140713. _seek_helper(vf,bisect);
  140714. ret=_get_next_page(vf,&og,-1);
  140715. if(ret==OV_EREAD)return(OV_EREAD);
  140716. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  140717. endsearched=bisect;
  140718. if(ret>=0)next=ret;
  140719. }else{
  140720. searched=ret+og.header_len+og.body_len;
  140721. }
  140722. }
  140723. _seek_helper(vf,next);
  140724. ret=_get_next_page(vf,&og,-1);
  140725. if(ret==OV_EREAD)return(OV_EREAD);
  140726. if(searched>=end || ret<0){
  140727. vf->links=m+1;
  140728. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  140729. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  140730. vf->offsets[m+1]=searched;
  140731. }else{
  140732. ret=_bisect_forward_serialno(vf,next,vf->offset,
  140733. end,ogg_page_serialno(&og),m+1);
  140734. if(ret==OV_EREAD)return(OV_EREAD);
  140735. }
  140736. vf->offsets[m]=begin;
  140737. vf->serialnos[m]=currentno;
  140738. return(0);
  140739. }
  140740. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  140741. long *serialno,ogg_page *og_ptr){
  140742. ogg_page og;
  140743. ogg_packet op;
  140744. int i,ret;
  140745. if(!og_ptr){
  140746. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  140747. if(llret==OV_EREAD)return(OV_EREAD);
  140748. if(llret<0)return OV_ENOTVORBIS;
  140749. og_ptr=&og;
  140750. }
  140751. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  140752. if(serialno)*serialno=vf->os.serialno;
  140753. vf->ready_state=STREAMSET;
  140754. vorbis_info_init(vi);
  140755. vorbis_comment_init(vc);
  140756. i=0;
  140757. while(i<3){
  140758. ogg_stream_pagein(&vf->os,og_ptr);
  140759. while(i<3){
  140760. int result=ogg_stream_packetout(&vf->os,&op);
  140761. if(result==0)break;
  140762. if(result==-1){
  140763. ret=OV_EBADHEADER;
  140764. goto bail_header;
  140765. }
  140766. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  140767. goto bail_header;
  140768. }
  140769. i++;
  140770. }
  140771. if(i<3)
  140772. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  140773. ret=OV_EBADHEADER;
  140774. goto bail_header;
  140775. }
  140776. }
  140777. return 0;
  140778. bail_header:
  140779. vorbis_info_clear(vi);
  140780. vorbis_comment_clear(vc);
  140781. vf->ready_state=OPENED;
  140782. return ret;
  140783. }
  140784. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  140785. ogg_page og;
  140786. int i;
  140787. ogg_int64_t ret;
  140788. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  140789. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  140790. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  140791. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  140792. for(i=0;i<vf->links;i++){
  140793. if(i==0){
  140794. vf->dataoffsets[i]=dataoffset;
  140795. _seek_helper(vf,dataoffset);
  140796. }else{
  140797. _seek_helper(vf,vf->offsets[i]);
  140798. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  140799. vf->dataoffsets[i]=-1;
  140800. }else{
  140801. vf->dataoffsets[i]=vf->offset;
  140802. }
  140803. }
  140804. if(vf->dataoffsets[i]!=-1){
  140805. ogg_int64_t accumulated=0;
  140806. long lastblock=-1;
  140807. int result;
  140808. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  140809. while(1){
  140810. ogg_packet op;
  140811. ret=_get_next_page(vf,&og,-1);
  140812. if(ret<0)
  140813. break;
  140814. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  140815. break;
  140816. ogg_stream_pagein(&vf->os,&og);
  140817. while((result=ogg_stream_packetout(&vf->os,&op))){
  140818. if(result>0){ /* ignore holes */
  140819. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  140820. if(lastblock!=-1)
  140821. accumulated+=(lastblock+thisblock)>>2;
  140822. lastblock=thisblock;
  140823. }
  140824. }
  140825. if(ogg_page_granulepos(&og)!=-1){
  140826. accumulated= ogg_page_granulepos(&og)-accumulated;
  140827. break;
  140828. }
  140829. }
  140830. if(accumulated<0)accumulated=0;
  140831. vf->pcmlengths[i*2]=accumulated;
  140832. }
  140833. {
  140834. ogg_int64_t end=vf->offsets[i+1];
  140835. _seek_helper(vf,end);
  140836. while(1){
  140837. ret=_get_prev_page(vf,&og);
  140838. if(ret<0){
  140839. vorbis_info_clear(vf->vi+i);
  140840. vorbis_comment_clear(vf->vc+i);
  140841. break;
  140842. }
  140843. if(ogg_page_granulepos(&og)!=-1){
  140844. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  140845. break;
  140846. }
  140847. vf->offset=ret;
  140848. }
  140849. }
  140850. }
  140851. }
  140852. static int _make_decode_ready(OggVorbis_File *vf){
  140853. if(vf->ready_state>STREAMSET)return 0;
  140854. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  140855. if(vf->seekable){
  140856. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  140857. return OV_EBADLINK;
  140858. }else{
  140859. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  140860. return OV_EBADLINK;
  140861. }
  140862. vorbis_block_init(&vf->vd,&vf->vb);
  140863. vf->ready_state=INITSET;
  140864. vf->bittrack=0.f;
  140865. vf->samptrack=0.f;
  140866. return 0;
  140867. }
  140868. static int _open_seekable2(OggVorbis_File *vf){
  140869. long serialno=vf->current_serialno;
  140870. ogg_int64_t dataoffset=vf->offset, end;
  140871. ogg_page og;
  140872. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  140873. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  140874. end=_get_prev_page(vf,&og);
  140875. if(end<0)return(end);
  140876. if(ogg_page_serialno(&og)!=serialno){
  140877. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  140878. }else{
  140879. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  140880. }
  140881. _prefetch_all_headers(vf,dataoffset);
  140882. return(ov_raw_seek(vf,0));
  140883. }
  140884. static void _decode_clear(OggVorbis_File *vf){
  140885. vorbis_dsp_clear(&vf->vd);
  140886. vorbis_block_clear(&vf->vb);
  140887. vf->ready_state=OPENED;
  140888. }
  140889. static int _fetch_and_process_packet(OggVorbis_File *vf,
  140890. ogg_packet *op_in,
  140891. int readp,
  140892. int spanp){
  140893. ogg_page og;
  140894. while(1){
  140895. if(vf->ready_state==INITSET){
  140896. while(1) {
  140897. ogg_packet op;
  140898. ogg_packet *op_ptr=(op_in?op_in:&op);
  140899. int result=ogg_stream_packetout(&vf->os,op_ptr);
  140900. ogg_int64_t granulepos;
  140901. op_in=NULL;
  140902. if(result==-1)return(OV_HOLE); /* hole in the data. */
  140903. if(result>0){
  140904. granulepos=op_ptr->granulepos;
  140905. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  140906. header handling. The
  140907. header packets aren't
  140908. audio, so if/when we
  140909. submit them,
  140910. vorbis_synthesis will
  140911. reject them */
  140912. {
  140913. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  140914. if(oldsamples)return(OV_EFAULT);
  140915. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  140916. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  140917. vf->bittrack+=op_ptr->bytes*8;
  140918. }
  140919. if(granulepos!=-1 && !op_ptr->e_o_s){
  140920. int link=(vf->seekable?vf->current_link:0);
  140921. int i,samples;
  140922. if(vf->seekable && link>0)
  140923. granulepos-=vf->pcmlengths[link*2];
  140924. if(granulepos<0)granulepos=0; /* actually, this
  140925. shouldn't be possible
  140926. here unless the stream
  140927. is very broken */
  140928. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  140929. granulepos-=samples;
  140930. for(i=0;i<link;i++)
  140931. granulepos+=vf->pcmlengths[i*2+1];
  140932. vf->pcm_offset=granulepos;
  140933. }
  140934. return(1);
  140935. }
  140936. }
  140937. else
  140938. break;
  140939. }
  140940. }
  140941. if(vf->ready_state>=OPENED){
  140942. ogg_int64_t ret;
  140943. if(!readp)return(0);
  140944. if((ret=_get_next_page(vf,&og,-1))<0){
  140945. return(OV_EOF); /* eof.
  140946. leave unitialized */
  140947. }
  140948. vf->bittrack+=og.header_len*8;
  140949. if(vf->ready_state==INITSET){
  140950. if(vf->current_serialno!=ogg_page_serialno(&og)){
  140951. if(!spanp)
  140952. return(OV_EOF);
  140953. _decode_clear(vf);
  140954. if(!vf->seekable){
  140955. vorbis_info_clear(vf->vi);
  140956. vorbis_comment_clear(vf->vc);
  140957. }
  140958. }
  140959. }
  140960. }
  140961. if(vf->ready_state!=INITSET){
  140962. int link;
  140963. if(vf->ready_state<STREAMSET){
  140964. if(vf->seekable){
  140965. vf->current_serialno=ogg_page_serialno(&og);
  140966. for(link=0;link<vf->links;link++)
  140967. if(vf->serialnos[link]==vf->current_serialno)break;
  140968. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  140969. stream. error out,
  140970. leave machine
  140971. uninitialized */
  140972. vf->current_link=link;
  140973. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  140974. vf->ready_state=STREAMSET;
  140975. }else{
  140976. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  140977. if(ret)return(ret);
  140978. vf->current_link++;
  140979. link=0;
  140980. }
  140981. }
  140982. {
  140983. int ret=_make_decode_ready(vf);
  140984. if(ret<0)return ret;
  140985. }
  140986. }
  140987. ogg_stream_pagein(&vf->os,&og);
  140988. }
  140989. }
  140990. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  140991. if(f==NULL)return(-1);
  140992. return fseek(f,off,whence);
  140993. }
  140994. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  140995. long ibytes, ov_callbacks callbacks){
  140996. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  140997. int ret;
  140998. memset(vf,0,sizeof(*vf));
  140999. vf->datasource=f;
  141000. vf->callbacks = callbacks;
  141001. ogg_sync_init(&vf->oy);
  141002. if(initial){
  141003. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141004. memcpy(buffer,initial,ibytes);
  141005. ogg_sync_wrote(&vf->oy,ibytes);
  141006. }
  141007. if(offsettest!=-1)vf->seekable=1;
  141008. vf->links=1;
  141009. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141010. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141011. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141012. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141013. vf->datasource=NULL;
  141014. ov_clear(vf);
  141015. }else
  141016. vf->ready_state=PARTOPEN;
  141017. return(ret);
  141018. }
  141019. static int _ov_open2(OggVorbis_File *vf){
  141020. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141021. vf->ready_state=OPENED;
  141022. if(vf->seekable){
  141023. int ret=_open_seekable2(vf);
  141024. if(ret){
  141025. vf->datasource=NULL;
  141026. ov_clear(vf);
  141027. }
  141028. return(ret);
  141029. }else
  141030. vf->ready_state=STREAMSET;
  141031. return 0;
  141032. }
  141033. int ov_clear(OggVorbis_File *vf){
  141034. if(vf){
  141035. vorbis_block_clear(&vf->vb);
  141036. vorbis_dsp_clear(&vf->vd);
  141037. ogg_stream_clear(&vf->os);
  141038. if(vf->vi && vf->links){
  141039. int i;
  141040. for(i=0;i<vf->links;i++){
  141041. vorbis_info_clear(vf->vi+i);
  141042. vorbis_comment_clear(vf->vc+i);
  141043. }
  141044. _ogg_free(vf->vi);
  141045. _ogg_free(vf->vc);
  141046. }
  141047. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141048. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141049. if(vf->serialnos)_ogg_free(vf->serialnos);
  141050. if(vf->offsets)_ogg_free(vf->offsets);
  141051. ogg_sync_clear(&vf->oy);
  141052. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141053. memset(vf,0,sizeof(*vf));
  141054. }
  141055. #ifdef DEBUG_LEAKS
  141056. _VDBG_dump();
  141057. #endif
  141058. return(0);
  141059. }
  141060. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141061. ov_callbacks callbacks){
  141062. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141063. if(ret)return ret;
  141064. return _ov_open2(vf);
  141065. }
  141066. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141067. ov_callbacks callbacks = {
  141068. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141069. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141070. (int (*)(void *)) fclose,
  141071. (long (*)(void *)) ftell
  141072. };
  141073. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141074. }
  141075. int ov_halfrate(OggVorbis_File *vf,int flag){
  141076. int i;
  141077. if(vf->vi==NULL)return OV_EINVAL;
  141078. if(!vf->seekable)return OV_EINVAL;
  141079. if(vf->ready_state>=STREAMSET)
  141080. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141081. will be able to swap this on the fly, but
  141082. for now dumping the decode machine is needed
  141083. to reinit the MDCT lookups. 1.1 libvorbis
  141084. is planned to be able to switch on the fly */
  141085. for(i=0;i<vf->links;i++){
  141086. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141087. ov_halfrate(vf,0);
  141088. return OV_EINVAL;
  141089. }
  141090. }
  141091. return 0;
  141092. }
  141093. int ov_halfrate_p(OggVorbis_File *vf){
  141094. if(vf->vi==NULL)return OV_EINVAL;
  141095. return vorbis_synthesis_halfrate_p(vf->vi);
  141096. }
  141097. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141098. ov_callbacks callbacks)
  141099. {
  141100. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141101. }
  141102. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141103. ov_callbacks callbacks = {
  141104. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141105. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141106. (int (*)(void *)) fclose,
  141107. (long (*)(void *)) ftell
  141108. };
  141109. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141110. }
  141111. int ov_test_open(OggVorbis_File *vf){
  141112. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141113. return _ov_open2(vf);
  141114. }
  141115. long ov_streams(OggVorbis_File *vf){
  141116. return vf->links;
  141117. }
  141118. long ov_seekable(OggVorbis_File *vf){
  141119. return vf->seekable;
  141120. }
  141121. long ov_bitrate(OggVorbis_File *vf,int i){
  141122. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141123. if(i>=vf->links)return(OV_EINVAL);
  141124. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141125. if(i<0){
  141126. ogg_int64_t bits=0;
  141127. int i;
  141128. float br;
  141129. for(i=0;i<vf->links;i++)
  141130. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141131. br = bits/ov_time_total(vf,-1);
  141132. return(rint(br));
  141133. }else{
  141134. if(vf->seekable){
  141135. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141136. }else{
  141137. if(vf->vi[i].bitrate_nominal>0){
  141138. return vf->vi[i].bitrate_nominal;
  141139. }else{
  141140. if(vf->vi[i].bitrate_upper>0){
  141141. if(vf->vi[i].bitrate_lower>0){
  141142. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141143. }else{
  141144. return vf->vi[i].bitrate_upper;
  141145. }
  141146. }
  141147. return(OV_FALSE);
  141148. }
  141149. }
  141150. }
  141151. }
  141152. long ov_bitrate_instant(OggVorbis_File *vf){
  141153. int link=(vf->seekable?vf->current_link:0);
  141154. long ret;
  141155. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141156. if(vf->samptrack==0)return(OV_FALSE);
  141157. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141158. vf->bittrack=0.f;
  141159. vf->samptrack=0.f;
  141160. return(ret);
  141161. }
  141162. long ov_serialnumber(OggVorbis_File *vf,int i){
  141163. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141164. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141165. if(i<0){
  141166. return(vf->current_serialno);
  141167. }else{
  141168. return(vf->serialnos[i]);
  141169. }
  141170. }
  141171. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141172. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141173. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141174. if(i<0){
  141175. ogg_int64_t acc=0;
  141176. int i;
  141177. for(i=0;i<vf->links;i++)
  141178. acc+=ov_raw_total(vf,i);
  141179. return(acc);
  141180. }else{
  141181. return(vf->offsets[i+1]-vf->offsets[i]);
  141182. }
  141183. }
  141184. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141185. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141186. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141187. if(i<0){
  141188. ogg_int64_t acc=0;
  141189. int i;
  141190. for(i=0;i<vf->links;i++)
  141191. acc+=ov_pcm_total(vf,i);
  141192. return(acc);
  141193. }else{
  141194. return(vf->pcmlengths[i*2+1]);
  141195. }
  141196. }
  141197. double ov_time_total(OggVorbis_File *vf,int i){
  141198. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141199. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141200. if(i<0){
  141201. double acc=0;
  141202. int i;
  141203. for(i=0;i<vf->links;i++)
  141204. acc+=ov_time_total(vf,i);
  141205. return(acc);
  141206. }else{
  141207. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141208. }
  141209. }
  141210. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141211. ogg_stream_state work_os;
  141212. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141213. if(!vf->seekable)
  141214. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141215. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141216. vf->pcm_offset=-1;
  141217. ogg_stream_reset_serialno(&vf->os,
  141218. vf->current_serialno); /* must set serialno */
  141219. vorbis_synthesis_restart(&vf->vd);
  141220. _seek_helper(vf,pos);
  141221. {
  141222. ogg_page og;
  141223. ogg_packet op;
  141224. int lastblock=0;
  141225. int accblock=0;
  141226. int thisblock;
  141227. int eosflag;
  141228. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141229. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141230. return from not necessarily
  141231. starting from the beginning */
  141232. while(1){
  141233. if(vf->ready_state>=STREAMSET){
  141234. int result=ogg_stream_packetout(&work_os,&op);
  141235. if(result>0){
  141236. if(vf->vi[vf->current_link].codec_setup){
  141237. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141238. if(thisblock<0){
  141239. ogg_stream_packetout(&vf->os,NULL);
  141240. thisblock=0;
  141241. }else{
  141242. if(eosflag)
  141243. ogg_stream_packetout(&vf->os,NULL);
  141244. else
  141245. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141246. }
  141247. if(op.granulepos!=-1){
  141248. int i,link=vf->current_link;
  141249. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141250. if(granulepos<0)granulepos=0;
  141251. for(i=0;i<link;i++)
  141252. granulepos+=vf->pcmlengths[i*2+1];
  141253. vf->pcm_offset=granulepos-accblock;
  141254. break;
  141255. }
  141256. lastblock=thisblock;
  141257. continue;
  141258. }else
  141259. ogg_stream_packetout(&vf->os,NULL);
  141260. }
  141261. }
  141262. if(!lastblock){
  141263. if(_get_next_page(vf,&og,-1)<0){
  141264. vf->pcm_offset=ov_pcm_total(vf,-1);
  141265. break;
  141266. }
  141267. }else{
  141268. vf->pcm_offset=-1;
  141269. break;
  141270. }
  141271. if(vf->ready_state>=STREAMSET)
  141272. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141273. _decode_clear(vf); /* clear out stream state */
  141274. ogg_stream_clear(&work_os);
  141275. }
  141276. if(vf->ready_state<STREAMSET){
  141277. int link;
  141278. vf->current_serialno=ogg_page_serialno(&og);
  141279. for(link=0;link<vf->links;link++)
  141280. if(vf->serialnos[link]==vf->current_serialno)break;
  141281. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141282. error out, leave
  141283. machine uninitialized */
  141284. vf->current_link=link;
  141285. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141286. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141287. vf->ready_state=STREAMSET;
  141288. }
  141289. ogg_stream_pagein(&vf->os,&og);
  141290. ogg_stream_pagein(&work_os,&og);
  141291. eosflag=ogg_page_eos(&og);
  141292. }
  141293. }
  141294. ogg_stream_clear(&work_os);
  141295. vf->bittrack=0.f;
  141296. vf->samptrack=0.f;
  141297. return(0);
  141298. seek_error:
  141299. vf->pcm_offset=-1;
  141300. ogg_stream_clear(&work_os);
  141301. _decode_clear(vf);
  141302. return OV_EBADLINK;
  141303. }
  141304. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141305. int link=-1;
  141306. ogg_int64_t result=0;
  141307. ogg_int64_t total=ov_pcm_total(vf,-1);
  141308. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141309. if(!vf->seekable)return(OV_ENOSEEK);
  141310. if(pos<0 || pos>total)return(OV_EINVAL);
  141311. for(link=vf->links-1;link>=0;link--){
  141312. total-=vf->pcmlengths[link*2+1];
  141313. if(pos>=total)break;
  141314. }
  141315. {
  141316. ogg_int64_t end=vf->offsets[link+1];
  141317. ogg_int64_t begin=vf->offsets[link];
  141318. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141319. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141320. ogg_int64_t target=pos-total+begintime;
  141321. ogg_int64_t best=begin;
  141322. ogg_page og;
  141323. while(begin<end){
  141324. ogg_int64_t bisect;
  141325. if(end-begin<CHUNKSIZE){
  141326. bisect=begin;
  141327. }else{
  141328. bisect=begin +
  141329. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141330. if(bisect<=begin)
  141331. bisect=begin+1;
  141332. }
  141333. _seek_helper(vf,bisect);
  141334. while(begin<end){
  141335. result=_get_next_page(vf,&og,end-vf->offset);
  141336. if(result==OV_EREAD) goto seek_error;
  141337. if(result<0){
  141338. if(bisect<=begin+1)
  141339. end=begin; /* found it */
  141340. else{
  141341. if(bisect==0) goto seek_error;
  141342. bisect-=CHUNKSIZE;
  141343. if(bisect<=begin)bisect=begin+1;
  141344. _seek_helper(vf,bisect);
  141345. }
  141346. }else{
  141347. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141348. if(granulepos==-1)continue;
  141349. if(granulepos<target){
  141350. best=result; /* raw offset of packet with granulepos */
  141351. begin=vf->offset; /* raw offset of next page */
  141352. begintime=granulepos;
  141353. if(target-begintime>44100)break;
  141354. bisect=begin; /* *not* begin + 1 */
  141355. }else{
  141356. if(bisect<=begin+1)
  141357. end=begin; /* found it */
  141358. else{
  141359. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141360. end=result;
  141361. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141362. if(bisect<=begin)bisect=begin+1;
  141363. _seek_helper(vf,bisect);
  141364. }else{
  141365. end=result;
  141366. endtime=granulepos;
  141367. break;
  141368. }
  141369. }
  141370. }
  141371. }
  141372. }
  141373. }
  141374. {
  141375. ogg_page og;
  141376. ogg_packet op;
  141377. _seek_helper(vf,best);
  141378. vf->pcm_offset=-1;
  141379. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141380. if(link!=vf->current_link){
  141381. _decode_clear(vf);
  141382. vf->current_link=link;
  141383. vf->current_serialno=ogg_page_serialno(&og);
  141384. vf->ready_state=STREAMSET;
  141385. }else{
  141386. vorbis_synthesis_restart(&vf->vd);
  141387. }
  141388. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141389. ogg_stream_pagein(&vf->os,&og);
  141390. while(1){
  141391. result=ogg_stream_packetpeek(&vf->os,&op);
  141392. if(result==0){
  141393. _seek_helper(vf,best);
  141394. while(1){
  141395. result=_get_prev_page(vf,&og);
  141396. if(result<0) goto seek_error;
  141397. if(ogg_page_granulepos(&og)>-1 ||
  141398. !ogg_page_continued(&og)){
  141399. return ov_raw_seek(vf,result);
  141400. }
  141401. vf->offset=result;
  141402. }
  141403. }
  141404. if(result<0){
  141405. result = OV_EBADPACKET;
  141406. goto seek_error;
  141407. }
  141408. if(op.granulepos!=-1){
  141409. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141410. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141411. vf->pcm_offset+=total;
  141412. break;
  141413. }else
  141414. result=ogg_stream_packetout(&vf->os,NULL);
  141415. }
  141416. }
  141417. }
  141418. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141419. result=OV_EFAULT;
  141420. goto seek_error;
  141421. }
  141422. vf->bittrack=0.f;
  141423. vf->samptrack=0.f;
  141424. return(0);
  141425. seek_error:
  141426. vf->pcm_offset=-1;
  141427. _decode_clear(vf);
  141428. return (int)result;
  141429. }
  141430. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141431. int thisblock,lastblock=0;
  141432. int ret=ov_pcm_seek_page(vf,pos);
  141433. if(ret<0)return(ret);
  141434. if((ret=_make_decode_ready(vf)))return ret;
  141435. while(1){
  141436. ogg_packet op;
  141437. ogg_page og;
  141438. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141439. if(ret>0){
  141440. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141441. if(thisblock<0){
  141442. ogg_stream_packetout(&vf->os,NULL);
  141443. continue; /* non audio packet */
  141444. }
  141445. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141446. if(vf->pcm_offset+((thisblock+
  141447. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141448. ogg_stream_packetout(&vf->os,NULL);
  141449. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141450. only tracking, no
  141451. pcm_decode */
  141452. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141453. if(op.granulepos>-1){
  141454. int i;
  141455. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141456. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141457. for(i=0;i<vf->current_link;i++)
  141458. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141459. }
  141460. lastblock=thisblock;
  141461. }else{
  141462. if(ret<0 && ret!=OV_HOLE)break;
  141463. if(_get_next_page(vf,&og,-1)<0)break;
  141464. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141465. if(vf->ready_state<STREAMSET){
  141466. int link;
  141467. vf->current_serialno=ogg_page_serialno(&og);
  141468. for(link=0;link<vf->links;link++)
  141469. if(vf->serialnos[link]==vf->current_serialno)break;
  141470. if(link==vf->links)return(OV_EBADLINK);
  141471. vf->current_link=link;
  141472. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141473. vf->ready_state=STREAMSET;
  141474. ret=_make_decode_ready(vf);
  141475. if(ret)return ret;
  141476. lastblock=0;
  141477. }
  141478. ogg_stream_pagein(&vf->os,&og);
  141479. }
  141480. }
  141481. vf->bittrack=0.f;
  141482. vf->samptrack=0.f;
  141483. while(vf->pcm_offset<pos){
  141484. ogg_int64_t target=pos-vf->pcm_offset;
  141485. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141486. if(samples>target)samples=target;
  141487. vorbis_synthesis_read(&vf->vd,samples);
  141488. vf->pcm_offset+=samples;
  141489. if(samples<target)
  141490. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141491. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141492. }
  141493. return 0;
  141494. }
  141495. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141496. int link=-1;
  141497. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141498. double time_total=ov_time_total(vf,-1);
  141499. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141500. if(!vf->seekable)return(OV_ENOSEEK);
  141501. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141502. for(link=vf->links-1;link>=0;link--){
  141503. pcm_total-=vf->pcmlengths[link*2+1];
  141504. time_total-=ov_time_total(vf,link);
  141505. if(seconds>=time_total)break;
  141506. }
  141507. {
  141508. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141509. return(ov_pcm_seek(vf,target));
  141510. }
  141511. }
  141512. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  141513. int link=-1;
  141514. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141515. double time_total=ov_time_total(vf,-1);
  141516. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141517. if(!vf->seekable)return(OV_ENOSEEK);
  141518. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141519. for(link=vf->links-1;link>=0;link--){
  141520. pcm_total-=vf->pcmlengths[link*2+1];
  141521. time_total-=ov_time_total(vf,link);
  141522. if(seconds>=time_total)break;
  141523. }
  141524. {
  141525. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  141526. return(ov_pcm_seek_page(vf,target));
  141527. }
  141528. }
  141529. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  141530. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141531. return(vf->offset);
  141532. }
  141533. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  141534. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141535. return(vf->pcm_offset);
  141536. }
  141537. double ov_time_tell(OggVorbis_File *vf){
  141538. int link=0;
  141539. ogg_int64_t pcm_total=0;
  141540. double time_total=0.f;
  141541. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141542. if(vf->seekable){
  141543. pcm_total=ov_pcm_total(vf,-1);
  141544. time_total=ov_time_total(vf,-1);
  141545. for(link=vf->links-1;link>=0;link--){
  141546. pcm_total-=vf->pcmlengths[link*2+1];
  141547. time_total-=ov_time_total(vf,link);
  141548. if(vf->pcm_offset>=pcm_total)break;
  141549. }
  141550. }
  141551. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  141552. }
  141553. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  141554. if(vf->seekable){
  141555. if(link<0)
  141556. if(vf->ready_state>=STREAMSET)
  141557. return vf->vi+vf->current_link;
  141558. else
  141559. return vf->vi;
  141560. else
  141561. if(link>=vf->links)
  141562. return NULL;
  141563. else
  141564. return vf->vi+link;
  141565. }else{
  141566. return vf->vi;
  141567. }
  141568. }
  141569. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  141570. if(vf->seekable){
  141571. if(link<0)
  141572. if(vf->ready_state>=STREAMSET)
  141573. return vf->vc+vf->current_link;
  141574. else
  141575. return vf->vc;
  141576. else
  141577. if(link>=vf->links)
  141578. return NULL;
  141579. else
  141580. return vf->vc+link;
  141581. }else{
  141582. return vf->vc;
  141583. }
  141584. }
  141585. static int host_is_big_endian() {
  141586. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  141587. unsigned char *bytewise = (unsigned char *)&pattern;
  141588. if (bytewise[0] == 0xfe) return 1;
  141589. return 0;
  141590. }
  141591. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  141592. int bigendianp,int word,int sgned,int *bitstream){
  141593. int i,j;
  141594. int host_endian = host_is_big_endian();
  141595. float **pcm;
  141596. long samples;
  141597. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141598. while(1){
  141599. if(vf->ready_state==INITSET){
  141600. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141601. if(samples)break;
  141602. }
  141603. {
  141604. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141605. if(ret==OV_EOF)
  141606. return(0);
  141607. if(ret<=0)
  141608. return(ret);
  141609. }
  141610. }
  141611. if(samples>0){
  141612. long channels=ov_info(vf,-1)->channels;
  141613. long bytespersample=word * channels;
  141614. vorbis_fpu_control fpu;
  141615. (void) fpu; // (to avoid a warning about it being unused)
  141616. if(samples>length/bytespersample)samples=length/bytespersample;
  141617. if(samples <= 0)
  141618. return OV_EINVAL;
  141619. {
  141620. int val;
  141621. if(word==1){
  141622. int off=(sgned?0:128);
  141623. vorbis_fpu_setround(&fpu);
  141624. for(j=0;j<samples;j++)
  141625. for(i=0;i<channels;i++){
  141626. val=vorbis_ftoi(pcm[i][j]*128.f);
  141627. if(val>127)val=127;
  141628. else if(val<-128)val=-128;
  141629. *buffer++=val+off;
  141630. }
  141631. vorbis_fpu_restore(fpu);
  141632. }else{
  141633. int off=(sgned?0:32768);
  141634. if(host_endian==bigendianp){
  141635. if(sgned){
  141636. vorbis_fpu_setround(&fpu);
  141637. for(i=0;i<channels;i++) { /* It's faster in this order */
  141638. float *src=pcm[i];
  141639. short *dest=((short *)buffer)+i;
  141640. for(j=0;j<samples;j++) {
  141641. val=vorbis_ftoi(src[j]*32768.f);
  141642. if(val>32767)val=32767;
  141643. else if(val<-32768)val=-32768;
  141644. *dest=val;
  141645. dest+=channels;
  141646. }
  141647. }
  141648. vorbis_fpu_restore(fpu);
  141649. }else{
  141650. vorbis_fpu_setround(&fpu);
  141651. for(i=0;i<channels;i++) {
  141652. float *src=pcm[i];
  141653. short *dest=((short *)buffer)+i;
  141654. for(j=0;j<samples;j++) {
  141655. val=vorbis_ftoi(src[j]*32768.f);
  141656. if(val>32767)val=32767;
  141657. else if(val<-32768)val=-32768;
  141658. *dest=val+off;
  141659. dest+=channels;
  141660. }
  141661. }
  141662. vorbis_fpu_restore(fpu);
  141663. }
  141664. }else if(bigendianp){
  141665. vorbis_fpu_setround(&fpu);
  141666. for(j=0;j<samples;j++)
  141667. for(i=0;i<channels;i++){
  141668. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141669. if(val>32767)val=32767;
  141670. else if(val<-32768)val=-32768;
  141671. val+=off;
  141672. *buffer++=(val>>8);
  141673. *buffer++=(val&0xff);
  141674. }
  141675. vorbis_fpu_restore(fpu);
  141676. }else{
  141677. int val;
  141678. vorbis_fpu_setround(&fpu);
  141679. for(j=0;j<samples;j++)
  141680. for(i=0;i<channels;i++){
  141681. val=vorbis_ftoi(pcm[i][j]*32768.f);
  141682. if(val>32767)val=32767;
  141683. else if(val<-32768)val=-32768;
  141684. val+=off;
  141685. *buffer++=(val&0xff);
  141686. *buffer++=(val>>8);
  141687. }
  141688. vorbis_fpu_restore(fpu);
  141689. }
  141690. }
  141691. }
  141692. vorbis_synthesis_read(&vf->vd,samples);
  141693. vf->pcm_offset+=samples;
  141694. if(bitstream)*bitstream=vf->current_link;
  141695. return(samples*bytespersample);
  141696. }else{
  141697. return(samples);
  141698. }
  141699. }
  141700. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  141701. int *bitstream){
  141702. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141703. while(1){
  141704. if(vf->ready_state==INITSET){
  141705. float **pcm;
  141706. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  141707. if(samples){
  141708. if(pcm_channels)*pcm_channels=pcm;
  141709. if(samples>length)samples=length;
  141710. vorbis_synthesis_read(&vf->vd,samples);
  141711. vf->pcm_offset+=samples;
  141712. if(bitstream)*bitstream=vf->current_link;
  141713. return samples;
  141714. }
  141715. }
  141716. {
  141717. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  141718. if(ret==OV_EOF)return(0);
  141719. if(ret<=0)return(ret);
  141720. }
  141721. }
  141722. }
  141723. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  141724. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  141725. ogg_int64_t off);
  141726. static void _ov_splice(float **pcm,float **lappcm,
  141727. int n1, int n2,
  141728. int ch1, int ch2,
  141729. float *w1, float *w2){
  141730. int i,j;
  141731. float *w=w1;
  141732. int n=n1;
  141733. if(n1>n2){
  141734. n=n2;
  141735. w=w2;
  141736. }
  141737. for(j=0;j<ch1 && j<ch2;j++){
  141738. float *s=lappcm[j];
  141739. float *d=pcm[j];
  141740. for(i=0;i<n;i++){
  141741. float wd=w[i]*w[i];
  141742. float ws=1.-wd;
  141743. d[i]=d[i]*wd + s[i]*ws;
  141744. }
  141745. }
  141746. for(;j<ch2;j++){
  141747. float *d=pcm[j];
  141748. for(i=0;i<n;i++){
  141749. float wd=w[i]*w[i];
  141750. d[i]=d[i]*wd;
  141751. }
  141752. }
  141753. }
  141754. static int _ov_initset(OggVorbis_File *vf){
  141755. while(1){
  141756. if(vf->ready_state==INITSET)break;
  141757. {
  141758. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141759. if(ret<0 && ret!=OV_HOLE)return(ret);
  141760. }
  141761. }
  141762. return 0;
  141763. }
  141764. static int _ov_initprime(OggVorbis_File *vf){
  141765. vorbis_dsp_state *vd=&vf->vd;
  141766. while(1){
  141767. if(vf->ready_state==INITSET)
  141768. if(vorbis_synthesis_pcmout(vd,NULL))break;
  141769. {
  141770. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  141771. if(ret<0 && ret!=OV_HOLE)return(ret);
  141772. }
  141773. }
  141774. return 0;
  141775. }
  141776. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  141777. float **lappcm,int lapsize){
  141778. int lapcount=0,i;
  141779. float **pcm;
  141780. while(lapcount<lapsize){
  141781. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  141782. if(samples){
  141783. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141784. for(i=0;i<vi->channels;i++)
  141785. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141786. lapcount+=samples;
  141787. vorbis_synthesis_read(vd,samples);
  141788. }else{
  141789. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  141790. if(ret==OV_EOF)break;
  141791. }
  141792. }
  141793. if(lapcount<lapsize){
  141794. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  141795. if(samples==0){
  141796. for(i=0;i<vi->channels;i++)
  141797. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  141798. lapcount=lapsize;
  141799. }else{
  141800. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  141801. for(i=0;i<vi->channels;i++)
  141802. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  141803. lapcount+=samples;
  141804. }
  141805. }
  141806. }
  141807. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  141808. vorbis_info *vi1,*vi2;
  141809. float **lappcm;
  141810. float **pcm;
  141811. float *w1,*w2;
  141812. int n1,n2,i,ret,hs1,hs2;
  141813. if(vf1==vf2)return(0); /* degenerate case */
  141814. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  141815. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  141816. ret=_ov_initset(vf1);
  141817. if(ret)return(ret);
  141818. ret=_ov_initprime(vf2);
  141819. if(ret)return(ret);
  141820. vi1=ov_info(vf1,-1);
  141821. vi2=ov_info(vf2,-1);
  141822. hs1=ov_halfrate_p(vf1);
  141823. hs2=ov_halfrate_p(vf2);
  141824. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  141825. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  141826. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  141827. w1=vorbis_window(&vf1->vd,0);
  141828. w2=vorbis_window(&vf2->vd,0);
  141829. for(i=0;i<vi1->channels;i++)
  141830. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141831. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  141832. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  141833. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  141834. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  141835. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  141836. return(0);
  141837. }
  141838. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  141839. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  141840. vorbis_info *vi;
  141841. float **lappcm;
  141842. float **pcm;
  141843. float *w1,*w2;
  141844. int n1,n2,ch1,ch2,hs;
  141845. int i,ret;
  141846. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141847. ret=_ov_initset(vf);
  141848. if(ret)return(ret);
  141849. vi=ov_info(vf,-1);
  141850. hs=ov_halfrate_p(vf);
  141851. ch1=vi->channels;
  141852. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141853. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141854. persistent; even if the decode state
  141855. from this link gets dumped, this
  141856. window array continues to exist */
  141857. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141858. for(i=0;i<ch1;i++)
  141859. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141860. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141861. ret=localseek(vf,pos);
  141862. if(ret)return ret;
  141863. ret=_ov_initprime(vf);
  141864. if(ret)return(ret);
  141865. vi=ov_info(vf,-1);
  141866. ch2=vi->channels;
  141867. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141868. w2=vorbis_window(&vf->vd,0);
  141869. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141870. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141871. return(0);
  141872. }
  141873. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141874. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  141875. }
  141876. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141877. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  141878. }
  141879. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  141880. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  141881. }
  141882. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  141883. int (*localseek)(OggVorbis_File *,double)){
  141884. vorbis_info *vi;
  141885. float **lappcm;
  141886. float **pcm;
  141887. float *w1,*w2;
  141888. int n1,n2,ch1,ch2,hs;
  141889. int i,ret;
  141890. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141891. ret=_ov_initset(vf);
  141892. if(ret)return(ret);
  141893. vi=ov_info(vf,-1);
  141894. hs=ov_halfrate_p(vf);
  141895. ch1=vi->channels;
  141896. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  141897. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  141898. persistent; even if the decode state
  141899. from this link gets dumped, this
  141900. window array continues to exist */
  141901. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  141902. for(i=0;i<ch1;i++)
  141903. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  141904. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  141905. ret=localseek(vf,pos);
  141906. if(ret)return ret;
  141907. ret=_ov_initprime(vf);
  141908. if(ret)return(ret);
  141909. vi=ov_info(vf,-1);
  141910. ch2=vi->channels;
  141911. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  141912. w2=vorbis_window(&vf->vd,0);
  141913. vorbis_synthesis_lapout(&vf->vd,&pcm);
  141914. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  141915. return(0);
  141916. }
  141917. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  141918. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  141919. }
  141920. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  141921. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  141922. }
  141923. #endif
  141924. /*** End of inlined file: vorbisfile.c ***/
  141925. /*** Start of inlined file: window.c ***/
  141926. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141927. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141928. // tasks..
  141929. #if JUCE_MSVC
  141930. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141931. #endif
  141932. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141933. #if JUCE_USE_OGGVORBIS
  141934. #include <stdlib.h>
  141935. #include <math.h>
  141936. static float vwin64[32] = {
  141937. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  141938. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  141939. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  141940. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  141941. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  141942. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  141943. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  141944. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  141945. };
  141946. static float vwin128[64] = {
  141947. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  141948. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  141949. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  141950. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  141951. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  141952. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  141953. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  141954. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  141955. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  141956. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  141957. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  141958. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  141959. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  141960. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  141961. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  141962. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  141963. };
  141964. static float vwin256[128] = {
  141965. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  141966. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  141967. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  141968. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  141969. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  141970. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  141971. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  141972. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  141973. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  141974. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  141975. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  141976. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  141977. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  141978. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  141979. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  141980. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  141981. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  141982. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  141983. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  141984. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  141985. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  141986. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  141987. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  141988. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  141989. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  141990. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  141991. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  141992. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  141993. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  141994. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  141995. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  141996. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  141997. };
  141998. static float vwin512[256] = {
  141999. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142000. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142001. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142002. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142003. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142004. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142005. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142006. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142007. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142008. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142009. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142010. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142011. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142012. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142013. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142014. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142015. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142016. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142017. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142018. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142019. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142020. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142021. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142022. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142023. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142024. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142025. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142026. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142027. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142028. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142029. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142030. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142031. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142032. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142033. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142034. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142035. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142036. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142037. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142038. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142039. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142040. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142041. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142042. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142043. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142044. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142045. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142046. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142047. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142048. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142049. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142050. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142051. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142052. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142053. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142054. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142055. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142056. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142057. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142058. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142059. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142060. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142061. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142062. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142063. };
  142064. static float vwin1024[512] = {
  142065. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142066. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142067. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142068. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142069. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142070. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142071. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142072. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142073. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142074. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142075. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142076. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142077. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142078. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142079. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142080. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142081. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142082. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142083. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142084. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142085. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142086. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142087. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142088. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142089. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142090. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142091. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142092. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142093. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142094. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142095. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142096. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142097. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142098. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142099. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142100. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142101. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142102. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142103. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142104. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142105. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142106. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142107. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142108. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142109. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142110. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142111. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142112. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142113. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142114. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142115. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142116. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142117. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142118. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142119. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142120. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142121. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142122. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142123. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142124. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142125. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142126. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142127. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142128. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142129. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142130. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142131. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142132. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142133. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142134. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142135. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142136. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142137. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142138. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142139. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142140. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142141. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142142. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142143. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142144. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142145. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142146. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142147. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142148. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142149. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142150. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142151. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142152. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142153. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142154. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142155. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142156. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142157. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142158. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142159. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142160. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142161. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142162. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142163. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142164. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142165. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142166. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142167. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142168. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142169. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142170. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142171. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142172. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142173. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142174. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142175. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142176. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142177. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142178. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142179. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142180. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142181. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142182. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142183. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142184. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142185. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142186. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142187. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142188. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142189. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142190. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142191. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142192. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142193. };
  142194. static float vwin2048[1024] = {
  142195. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142196. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142197. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142198. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142199. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142200. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142201. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142202. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142203. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142204. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142205. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142206. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142207. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142208. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142209. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142210. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142211. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142212. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142213. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142214. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142215. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142216. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142217. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142218. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142219. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142220. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142221. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142222. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142223. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142224. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142225. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142226. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142227. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142228. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142229. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142230. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142231. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142232. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142233. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142234. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142235. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142236. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142237. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142238. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142239. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142240. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142241. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142242. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142243. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142244. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142245. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142246. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142247. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142248. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142249. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142250. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142251. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142252. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142253. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142254. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142255. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142256. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142257. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142258. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142259. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142260. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142261. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142262. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142263. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142264. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142265. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142266. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142267. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142268. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142269. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142270. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142271. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142272. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142273. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142274. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142275. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142276. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142277. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142278. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142279. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142280. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142281. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142282. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142283. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142284. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142285. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142286. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142287. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142288. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142289. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142290. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142291. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142292. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142293. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142294. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142295. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142296. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142297. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142298. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142299. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142300. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142301. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142302. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142303. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142304. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142305. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142306. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142307. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142308. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142309. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142310. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142311. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142312. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142313. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142314. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142315. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142316. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142317. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142318. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142319. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142320. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142321. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142322. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142323. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142324. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142325. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142326. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142327. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142328. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142329. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142330. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142331. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142332. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142333. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142334. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142335. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142336. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142337. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142338. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142339. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142340. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142341. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142342. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142343. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142344. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142345. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142346. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142347. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142348. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142349. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142350. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142351. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142352. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142353. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142354. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142355. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142356. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142357. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142358. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142359. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142360. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142361. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142362. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142363. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142364. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142365. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142366. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142367. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142368. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142369. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142370. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142371. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142372. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142373. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142374. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142375. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142376. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142377. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142378. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142379. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142380. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142381. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142382. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142383. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142384. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142385. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142386. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142387. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142388. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142389. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142390. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142391. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142392. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142393. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142394. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142395. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142396. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142397. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142398. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142399. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142400. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142401. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142402. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142403. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142404. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142405. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142406. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142407. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142408. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142409. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142410. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142411. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142412. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142413. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142414. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142415. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142416. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142417. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142418. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142419. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142420. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142421. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142422. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142423. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142424. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142425. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142426. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142427. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142428. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142429. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142430. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142431. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142432. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142433. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142434. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142435. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142436. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142437. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142438. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142439. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142440. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142441. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142442. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142443. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142444. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142445. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142446. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142447. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142448. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142449. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142450. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142451. };
  142452. static float vwin4096[2048] = {
  142453. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142454. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142455. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142456. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142457. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142458. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142459. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142460. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142461. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142462. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142463. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142464. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142465. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142466. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142467. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142468. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142469. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142470. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142471. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142472. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142473. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142474. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142475. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142476. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142477. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142478. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142479. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142480. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142481. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142482. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142483. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142484. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142485. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142486. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142487. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142488. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142489. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142490. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142491. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142492. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142493. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142494. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142495. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142496. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142497. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142498. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142499. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142500. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142501. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142502. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142503. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142504. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142505. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142506. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142507. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142508. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  142509. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  142510. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  142511. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  142512. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  142513. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  142514. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  142515. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  142516. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  142517. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  142518. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  142519. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  142520. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  142521. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  142522. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  142523. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  142524. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  142525. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  142526. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  142527. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  142528. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  142529. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  142530. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  142531. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  142532. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  142533. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  142534. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  142535. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  142536. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  142537. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  142538. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  142539. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  142540. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  142541. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  142542. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  142543. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  142544. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  142545. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  142546. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  142547. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  142548. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  142549. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  142550. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  142551. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  142552. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  142553. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  142554. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  142555. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  142556. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  142557. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  142558. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  142559. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  142560. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  142561. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  142562. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  142563. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  142564. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  142565. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  142566. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  142567. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  142568. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  142569. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  142570. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  142571. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  142572. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  142573. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  142574. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  142575. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  142576. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  142577. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  142578. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  142579. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  142580. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  142581. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  142582. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  142583. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  142584. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  142585. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  142586. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  142587. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  142588. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  142589. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  142590. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  142591. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  142592. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  142593. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  142594. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  142595. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  142596. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  142597. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  142598. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  142599. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  142600. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  142601. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  142602. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  142603. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  142604. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  142605. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  142606. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  142607. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  142608. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  142609. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  142610. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  142611. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  142612. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  142613. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  142614. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  142615. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  142616. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  142617. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  142618. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  142619. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  142620. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  142621. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  142622. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  142623. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  142624. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  142625. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  142626. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  142627. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  142628. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  142629. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  142630. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  142631. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  142632. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  142633. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  142634. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  142635. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  142636. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  142637. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  142638. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  142639. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  142640. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  142641. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  142642. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  142643. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  142644. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  142645. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  142646. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  142647. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  142648. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  142649. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  142650. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  142651. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  142652. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  142653. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  142654. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  142655. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  142656. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  142657. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  142658. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  142659. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  142660. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  142661. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  142662. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  142663. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  142664. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  142665. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  142666. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  142667. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  142668. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  142669. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  142670. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  142671. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  142672. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  142673. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  142674. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  142675. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  142676. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  142677. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  142678. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  142679. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  142680. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  142681. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  142682. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  142683. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  142684. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  142685. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  142686. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  142687. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  142688. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  142689. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  142690. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  142691. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  142692. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  142693. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  142694. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  142695. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  142696. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  142697. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  142698. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  142699. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  142700. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  142701. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  142702. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  142703. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  142704. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  142705. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  142706. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  142707. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  142708. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  142709. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  142710. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  142711. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  142712. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  142713. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  142714. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  142715. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  142716. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  142717. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  142718. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  142719. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  142720. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  142721. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  142722. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  142723. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  142724. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  142725. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  142726. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  142727. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  142728. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  142729. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  142730. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  142731. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  142732. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  142733. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  142734. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  142735. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  142736. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  142737. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  142738. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  142739. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  142740. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  142741. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  142742. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  142743. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  142744. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  142745. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  142746. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  142747. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  142748. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  142749. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  142750. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  142751. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  142752. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  142753. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  142754. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  142755. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  142756. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  142757. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  142758. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  142759. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  142760. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  142761. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  142762. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  142763. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  142764. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  142765. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  142766. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  142767. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  142768. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  142769. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  142770. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  142771. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  142772. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  142773. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  142774. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  142775. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  142776. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  142777. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  142778. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  142779. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  142780. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  142781. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  142782. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  142783. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  142784. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  142785. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  142786. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  142787. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  142788. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  142789. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  142790. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  142791. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  142792. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  142793. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  142794. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  142795. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  142796. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  142797. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  142798. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  142799. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  142800. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  142801. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  142802. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  142803. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  142804. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  142805. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  142806. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  142807. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  142808. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  142809. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  142810. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  142811. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  142812. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  142813. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  142814. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  142815. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  142816. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  142817. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  142818. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  142819. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  142820. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  142821. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  142822. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  142823. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  142824. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  142825. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  142826. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  142827. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  142828. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  142829. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  142830. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  142831. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  142832. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  142833. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  142834. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  142835. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  142836. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  142837. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  142838. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  142839. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  142840. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  142841. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  142842. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  142843. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  142844. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  142845. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  142846. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  142847. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  142848. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  142849. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  142850. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  142851. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  142852. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  142853. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  142854. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  142855. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  142856. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  142857. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  142858. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  142859. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  142860. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  142861. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  142862. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  142863. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  142864. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  142865. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  142866. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  142867. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  142868. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  142869. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  142870. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  142871. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  142872. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  142873. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  142874. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  142875. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  142876. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  142877. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  142878. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  142879. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  142880. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  142881. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  142882. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  142883. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  142884. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  142885. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  142886. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  142887. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  142888. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  142889. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  142890. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  142891. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  142892. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  142893. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  142894. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  142895. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  142896. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  142897. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  142898. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  142899. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  142900. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  142901. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  142902. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  142903. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  142904. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  142905. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  142906. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  142907. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  142908. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  142909. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  142910. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  142911. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  142912. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  142913. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  142914. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  142915. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  142916. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  142917. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  142918. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  142919. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  142920. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  142921. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  142922. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  142923. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  142924. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  142925. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  142926. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  142927. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  142928. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  142929. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  142930. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  142931. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  142932. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  142933. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  142934. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  142935. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  142936. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  142937. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  142938. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  142939. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  142940. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  142941. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  142942. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  142943. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  142944. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  142945. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  142946. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  142947. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  142948. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  142949. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  142950. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  142951. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  142952. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  142953. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  142954. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  142955. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  142956. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  142957. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  142958. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  142959. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  142960. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  142961. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  142962. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  142963. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  142964. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  142965. };
  142966. static float vwin8192[4096] = {
  142967. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  142968. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  142969. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  142970. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  142971. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  142972. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  142973. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  142974. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  142975. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  142976. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  142977. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  142978. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  142979. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  142980. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  142981. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  142982. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  142983. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  142984. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  142985. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  142986. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  142987. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  142988. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  142989. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  142990. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  142991. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  142992. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  142993. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  142994. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  142995. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  142996. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  142997. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  142998. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  142999. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143000. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143001. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143002. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143003. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143004. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143005. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143006. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143007. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143008. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143009. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143010. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143011. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143012. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143013. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143014. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143015. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143016. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143017. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143018. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143019. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143020. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143021. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143022. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143023. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143024. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143025. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143026. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143027. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143028. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143029. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143030. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143031. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143032. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143033. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143034. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143035. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143036. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143037. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143038. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143039. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143040. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143041. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143042. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143043. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143044. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143045. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143046. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143047. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143048. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143049. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143050. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143051. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143052. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143053. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143054. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143055. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143056. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143057. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143058. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143059. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143060. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143061. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143062. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143063. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143064. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143065. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143066. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143067. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143068. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143069. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143070. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143071. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143072. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143073. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143074. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143075. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143076. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143077. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143078. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143079. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143080. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143081. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143082. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143083. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143084. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143085. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143086. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143087. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143088. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143089. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143090. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143091. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143092. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143093. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143094. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143095. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143096. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143097. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143098. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143099. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143100. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143101. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143102. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143103. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143104. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143105. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143106. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143107. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143108. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143109. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143110. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143111. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143112. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143113. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143114. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143115. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143116. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143117. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143118. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143119. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143120. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143121. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143122. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143123. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143124. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143125. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143126. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143127. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143128. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143129. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143130. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143131. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143132. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143133. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143134. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143135. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143136. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143137. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143138. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143139. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143140. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143141. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143142. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143143. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143144. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143145. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143146. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143147. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143148. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143149. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143150. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143151. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143152. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143153. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143154. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143155. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143156. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143157. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143158. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143159. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143160. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143161. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143162. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143163. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143164. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143165. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143166. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143167. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143168. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143169. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143170. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143171. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143172. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143173. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143174. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143175. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143176. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143177. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143178. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143179. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143180. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143181. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143182. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143183. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143184. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143185. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143186. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143187. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143188. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143189. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143190. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143191. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143192. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143193. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143194. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143195. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143196. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143197. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143198. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143199. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143200. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143201. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143202. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143203. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143204. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143205. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143206. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143207. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143208. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143209. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143210. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143211. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143212. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143213. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143214. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143215. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143216. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143217. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143218. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143219. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143220. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143221. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143222. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143223. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143224. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143225. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143226. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143227. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143228. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143229. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143230. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143231. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143232. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143233. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143234. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143235. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143236. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143237. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143238. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143239. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143240. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143241. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143242. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143243. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143244. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143245. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143246. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143247. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143248. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143249. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143250. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143251. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143252. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143253. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143254. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143255. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143256. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143257. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143258. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143259. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143260. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143261. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143262. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143263. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143264. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143265. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143266. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143267. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143268. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143269. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143270. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143271. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143272. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143273. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143274. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143275. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143276. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143277. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143278. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143279. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143280. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143281. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143282. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143283. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143284. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143285. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143286. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143287. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143288. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143289. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143290. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143291. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143292. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143293. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143294. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143295. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143296. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143297. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143298. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143299. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143300. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143301. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143302. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143303. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143304. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143305. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143306. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143307. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143308. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143309. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143310. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143311. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143312. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143313. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143314. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143315. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143316. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143317. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143318. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143319. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143320. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143321. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143322. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143323. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143324. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143325. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143326. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143327. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143328. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143329. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143330. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143331. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143332. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143333. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143334. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143335. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143336. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143337. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143338. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143339. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143340. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143341. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143342. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143343. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143344. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143345. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143346. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143347. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143348. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143349. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143350. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143351. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143352. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143353. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143354. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143355. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143356. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143357. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143358. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143359. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143360. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143361. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143362. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143363. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143364. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143365. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143366. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143367. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143368. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143369. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143370. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143371. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143372. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143373. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143374. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143375. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143376. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143377. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143378. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143379. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143380. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143381. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143382. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143383. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143384. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143385. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143386. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143387. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143388. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143389. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143390. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143391. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143392. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143393. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143394. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143395. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143396. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143397. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143398. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143399. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143400. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143401. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143402. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143403. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143404. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143405. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143406. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143407. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143408. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143409. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143410. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143411. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143412. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143413. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143414. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143415. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143416. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143417. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143418. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143419. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143420. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143421. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143422. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143423. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143424. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143425. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143426. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143427. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143428. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143429. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143430. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143431. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143432. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143433. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143434. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143435. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143436. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143437. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143438. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143439. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143440. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143441. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143442. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143443. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143444. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143445. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143446. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143447. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143448. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143449. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143450. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143451. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143452. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143453. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143454. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143455. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143456. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143457. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143458. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143459. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143460. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143461. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143462. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143463. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143464. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143465. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143466. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143467. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143468. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143469. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143470. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143471. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143472. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143473. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143474. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143475. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143476. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143477. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143478. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143479. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143480. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143481. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143482. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143483. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143484. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143485. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143486. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143487. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143488. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143489. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143490. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143491. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143492. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143493. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143494. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143495. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143496. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143497. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143498. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143499. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143500. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143501. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143502. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143503. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143504. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143505. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143506. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143507. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143508. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  143509. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  143510. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  143511. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  143512. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  143513. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  143514. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  143515. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  143516. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  143517. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  143518. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  143519. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  143520. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  143521. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  143522. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  143523. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  143524. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  143525. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  143526. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  143527. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  143528. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  143529. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  143530. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  143531. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  143532. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  143533. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  143534. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  143535. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  143536. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  143537. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  143538. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  143539. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  143540. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  143541. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  143542. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  143543. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  143544. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  143545. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  143546. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  143547. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  143548. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  143549. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  143550. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  143551. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  143552. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  143553. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  143554. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  143555. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  143556. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  143557. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  143558. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  143559. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  143560. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  143561. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  143562. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  143563. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  143564. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  143565. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  143566. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  143567. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  143568. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  143569. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  143570. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  143571. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  143572. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  143573. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  143574. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  143575. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  143576. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  143577. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  143578. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  143579. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  143580. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  143581. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  143582. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  143583. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  143584. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  143585. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  143586. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  143587. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  143588. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  143589. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  143590. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  143591. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  143592. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  143593. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  143594. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  143595. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  143596. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  143597. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  143598. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  143599. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  143600. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  143601. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  143602. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  143603. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  143604. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  143605. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  143606. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  143607. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  143608. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  143609. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  143610. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  143611. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  143612. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  143613. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  143614. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  143615. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  143616. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  143617. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  143618. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  143619. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  143620. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  143621. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  143622. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  143623. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  143624. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  143625. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  143626. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  143627. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  143628. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  143629. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  143630. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  143631. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  143632. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  143633. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  143634. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  143635. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  143636. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  143637. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  143638. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  143639. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  143640. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  143641. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  143642. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  143643. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  143644. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  143645. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  143646. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  143647. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  143648. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  143649. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  143650. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  143651. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  143652. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  143653. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  143654. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  143655. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  143656. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  143657. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  143658. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  143659. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  143660. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  143661. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  143662. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  143663. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  143664. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  143665. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  143666. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  143667. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  143668. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  143669. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  143670. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  143671. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  143672. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  143673. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  143674. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  143675. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  143676. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  143677. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  143678. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  143679. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  143680. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  143681. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  143682. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  143683. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  143684. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  143685. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  143686. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  143687. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  143688. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  143689. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  143690. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  143691. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  143692. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  143693. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  143694. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  143695. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  143696. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  143697. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  143698. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  143699. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  143700. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  143701. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  143702. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  143703. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  143704. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  143705. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  143706. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  143707. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  143708. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  143709. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  143710. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  143711. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  143712. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  143713. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  143714. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  143715. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  143716. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  143717. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  143718. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  143719. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  143720. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  143721. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  143722. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  143723. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  143724. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  143725. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  143726. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  143727. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  143728. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  143729. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  143730. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  143731. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  143732. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  143733. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  143734. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  143735. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  143736. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  143737. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  143738. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  143739. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  143740. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  143741. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  143742. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  143743. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  143744. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  143745. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  143746. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  143747. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  143748. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  143749. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  143750. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  143751. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  143752. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  143753. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  143754. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  143755. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  143756. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  143757. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  143758. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  143759. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  143760. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  143761. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  143762. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  143763. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  143764. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  143765. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  143766. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  143767. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  143768. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  143769. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  143770. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  143771. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  143772. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  143773. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  143774. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  143775. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  143776. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  143777. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  143778. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  143779. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  143780. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  143781. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  143782. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  143783. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  143784. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  143785. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  143786. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  143787. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  143788. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  143789. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  143790. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  143791. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  143792. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  143793. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  143794. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  143795. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  143796. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  143797. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  143798. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  143799. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  143800. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  143801. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  143802. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  143803. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  143804. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  143805. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  143806. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  143807. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  143808. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  143809. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  143810. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  143811. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  143812. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  143813. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  143814. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  143815. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  143816. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  143817. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  143818. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  143819. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  143820. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  143821. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  143822. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  143823. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  143824. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  143825. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  143826. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  143827. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  143828. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  143829. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  143830. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  143831. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  143832. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  143833. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  143834. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  143835. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  143836. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  143837. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  143838. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  143839. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  143840. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  143841. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  143842. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  143843. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  143844. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  143845. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  143846. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  143847. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  143848. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  143849. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  143850. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  143851. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  143852. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  143853. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  143854. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  143855. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  143856. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  143857. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  143858. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  143859. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  143860. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  143861. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  143862. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  143863. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  143864. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  143865. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  143866. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  143867. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  143868. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  143869. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  143870. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  143871. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  143872. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  143873. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  143874. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  143875. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  143876. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  143877. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  143878. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  143879. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  143880. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  143881. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  143882. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  143883. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  143884. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  143885. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  143886. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  143887. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  143888. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  143889. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  143890. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  143891. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  143892. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  143893. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  143894. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  143895. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  143896. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  143897. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  143898. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  143899. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  143900. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  143901. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  143902. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  143903. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  143904. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  143905. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  143906. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  143907. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  143908. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  143909. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  143910. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  143911. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  143912. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  143913. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  143914. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  143915. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  143916. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  143917. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  143918. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  143919. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  143920. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  143921. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  143922. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  143923. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  143924. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  143925. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  143926. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  143927. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  143928. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  143929. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  143930. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  143931. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  143932. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  143933. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  143934. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  143935. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  143936. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  143937. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  143938. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  143939. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  143940. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  143941. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  143942. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  143943. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  143944. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  143945. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  143946. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  143947. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  143948. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  143949. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  143950. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  143951. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  143952. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  143953. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  143954. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  143955. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  143956. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  143957. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  143958. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  143959. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  143960. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  143961. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  143962. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  143963. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  143964. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  143965. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  143966. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  143967. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  143968. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  143969. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  143970. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  143971. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  143972. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  143973. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  143974. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  143975. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  143976. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  143977. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  143978. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  143979. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  143980. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  143981. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  143982. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  143983. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  143984. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  143985. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  143986. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  143987. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  143988. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  143989. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143990. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143991. };
  143992. static float *vwin[8] = {
  143993. vwin64,
  143994. vwin128,
  143995. vwin256,
  143996. vwin512,
  143997. vwin1024,
  143998. vwin2048,
  143999. vwin4096,
  144000. vwin8192,
  144001. };
  144002. float *_vorbis_window_get(int n){
  144003. return vwin[n];
  144004. }
  144005. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144006. int lW,int W,int nW){
  144007. lW=(W?lW:0);
  144008. nW=(W?nW:0);
  144009. {
  144010. float *windowLW=vwin[winno[lW]];
  144011. float *windowNW=vwin[winno[nW]];
  144012. long n=blocksizes[W];
  144013. long ln=blocksizes[lW];
  144014. long rn=blocksizes[nW];
  144015. long leftbegin=n/4-ln/4;
  144016. long leftend=leftbegin+ln/2;
  144017. long rightbegin=n/2+n/4-rn/4;
  144018. long rightend=rightbegin+rn/2;
  144019. int i,p;
  144020. for(i=0;i<leftbegin;i++)
  144021. d[i]=0.f;
  144022. for(p=0;i<leftend;i++,p++)
  144023. d[i]*=windowLW[p];
  144024. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144025. d[i]*=windowNW[p];
  144026. for(;i<n;i++)
  144027. d[i]=0.f;
  144028. }
  144029. }
  144030. #endif
  144031. /*** End of inlined file: window.c ***/
  144032. #else
  144033. #include <vorbis/vorbisenc.h>
  144034. #include <vorbis/codec.h>
  144035. #include <vorbis/vorbisfile.h>
  144036. #endif
  144037. }
  144038. #undef max
  144039. #undef min
  144040. BEGIN_JUCE_NAMESPACE
  144041. static const char* const oggFormatName = "Ogg-Vorbis file";
  144042. static const juce_wchar* const oggExtensions[] = { T(".ogg"), 0 };
  144043. class OggReader : public AudioFormatReader
  144044. {
  144045. OggVorbisNamespace::OggVorbis_File ovFile;
  144046. OggVorbisNamespace::ov_callbacks callbacks;
  144047. AudioSampleBuffer reservoir;
  144048. int reservoirStart, samplesInReservoir;
  144049. public:
  144050. OggReader (InputStream* const inp)
  144051. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144052. reservoir (2, 4096),
  144053. reservoirStart (0),
  144054. samplesInReservoir (0)
  144055. {
  144056. using namespace OggVorbisNamespace;
  144057. sampleRate = 0;
  144058. usesFloatingPointData = true;
  144059. callbacks.read_func = &oggReadCallback;
  144060. callbacks.seek_func = &oggSeekCallback;
  144061. callbacks.close_func = &oggCloseCallback;
  144062. callbacks.tell_func = &oggTellCallback;
  144063. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144064. if (err == 0)
  144065. {
  144066. vorbis_info* info = ov_info (&ovFile, -1);
  144067. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144068. numChannels = info->channels;
  144069. bitsPerSample = 16;
  144070. sampleRate = info->rate;
  144071. reservoir.setSize (numChannels,
  144072. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144073. }
  144074. }
  144075. ~OggReader()
  144076. {
  144077. OggVorbisNamespace::ov_clear (&ovFile);
  144078. }
  144079. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144080. int64 startSampleInFile, int numSamples)
  144081. {
  144082. while (numSamples > 0)
  144083. {
  144084. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144085. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144086. {
  144087. // got a few samples overlapping, so use them before seeking..
  144088. const int numToUse = jmin (numSamples, numAvailable);
  144089. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144090. if (destSamples[i] != 0)
  144091. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144092. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144093. sizeof (float) * numToUse);
  144094. startSampleInFile += numToUse;
  144095. numSamples -= numToUse;
  144096. startOffsetInDestBuffer += numToUse;
  144097. if (numSamples == 0)
  144098. break;
  144099. }
  144100. if (startSampleInFile < reservoirStart
  144101. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144102. {
  144103. // buffer miss, so refill the reservoir
  144104. int bitStream = 0;
  144105. reservoirStart = jmax (0, (int) startSampleInFile);
  144106. samplesInReservoir = reservoir.getNumSamples();
  144107. if (reservoirStart != (int) OggVorbisNamespace::ov_pcm_tell (&ovFile))
  144108. OggVorbisNamespace::ov_pcm_seek (&ovFile, reservoirStart);
  144109. int offset = 0;
  144110. int numToRead = samplesInReservoir;
  144111. while (numToRead > 0)
  144112. {
  144113. float** dataIn = 0;
  144114. const int samps = OggVorbisNamespace::ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144115. if (samps <= 0)
  144116. break;
  144117. jassert (samps <= numToRead);
  144118. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144119. {
  144120. memcpy (reservoir.getSampleData (i, offset),
  144121. dataIn[i],
  144122. sizeof (float) * samps);
  144123. }
  144124. numToRead -= samps;
  144125. offset += samps;
  144126. }
  144127. if (numToRead > 0)
  144128. reservoir.clear (offset, numToRead);
  144129. }
  144130. }
  144131. if (numSamples > 0)
  144132. {
  144133. for (int i = numDestChannels; --i >= 0;)
  144134. if (destSamples[i] != 0)
  144135. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144136. sizeof (int) * numSamples);
  144137. }
  144138. return true;
  144139. }
  144140. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144141. {
  144142. return (size_t) (static_cast <InputStream*> (datasource)->read (ptr, (int) (size * nmemb)) / size);
  144143. }
  144144. static int oggSeekCallback (void* datasource, OggVorbisNamespace::ogg_int64_t offset, int whence)
  144145. {
  144146. InputStream* const in = static_cast <InputStream*> (datasource);
  144147. if (whence == SEEK_CUR)
  144148. offset += in->getPosition();
  144149. else if (whence == SEEK_END)
  144150. offset += in->getTotalLength();
  144151. in->setPosition (offset);
  144152. return 0;
  144153. }
  144154. static int oggCloseCallback (void*)
  144155. {
  144156. return 0;
  144157. }
  144158. static long oggTellCallback (void* datasource)
  144159. {
  144160. return (long) static_cast <InputStream*> (datasource)->getPosition();
  144161. }
  144162. juce_UseDebuggingNewOperator
  144163. };
  144164. class OggWriter : public AudioFormatWriter
  144165. {
  144166. OggVorbisNamespace::ogg_stream_state os;
  144167. OggVorbisNamespace::ogg_page og;
  144168. OggVorbisNamespace::ogg_packet op;
  144169. OggVorbisNamespace::vorbis_info vi;
  144170. OggVorbisNamespace::vorbis_comment vc;
  144171. OggVorbisNamespace::vorbis_dsp_state vd;
  144172. OggVorbisNamespace::vorbis_block vb;
  144173. public:
  144174. bool ok;
  144175. OggWriter (OutputStream* const out,
  144176. const double sampleRate,
  144177. const int numChannels,
  144178. const int bitsPerSample,
  144179. const int qualityIndex)
  144180. : AudioFormatWriter (out, TRANS (oggFormatName),
  144181. sampleRate,
  144182. numChannels,
  144183. bitsPerSample)
  144184. {
  144185. using namespace OggVorbisNamespace;
  144186. ok = false;
  144187. vorbis_info_init (&vi);
  144188. if (vorbis_encode_init_vbr (&vi,
  144189. numChannels,
  144190. (int) sampleRate,
  144191. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144192. {
  144193. vorbis_comment_init (&vc);
  144194. if (JUCEApplication::getInstance() != 0)
  144195. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144196. vorbis_analysis_init (&vd, &vi);
  144197. vorbis_block_init (&vd, &vb);
  144198. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144199. ogg_packet header;
  144200. ogg_packet header_comm;
  144201. ogg_packet header_code;
  144202. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144203. ogg_stream_packetin (&os, &header);
  144204. ogg_stream_packetin (&os, &header_comm);
  144205. ogg_stream_packetin (&os, &header_code);
  144206. for (;;)
  144207. {
  144208. if (ogg_stream_flush (&os, &og) == 0)
  144209. break;
  144210. output->write (og.header, og.header_len);
  144211. output->write (og.body, og.body_len);
  144212. }
  144213. ok = true;
  144214. }
  144215. }
  144216. ~OggWriter()
  144217. {
  144218. using namespace OggVorbisNamespace;
  144219. if (ok)
  144220. {
  144221. // write a zero-length packet to show ogg that we're finished..
  144222. write (0, 0);
  144223. ogg_stream_clear (&os);
  144224. vorbis_block_clear (&vb);
  144225. vorbis_dsp_clear (&vd);
  144226. vorbis_comment_clear (&vc);
  144227. vorbis_info_clear (&vi);
  144228. output->flush();
  144229. }
  144230. else
  144231. {
  144232. vorbis_info_clear (&vi);
  144233. output = 0; // to stop the base class deleting this, as it needs to be returned
  144234. // to the caller of createWriter()
  144235. }
  144236. }
  144237. bool write (const int** samplesToWrite, int numSamples)
  144238. {
  144239. using namespace OggVorbisNamespace;
  144240. if (! ok)
  144241. return false;
  144242. if (numSamples > 0)
  144243. {
  144244. const double gain = 1.0 / 0x80000000u;
  144245. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144246. for (int i = numChannels; --i >= 0;)
  144247. {
  144248. float* const dst = vorbisBuffer[i];
  144249. const int* const src = samplesToWrite [i];
  144250. if (src != 0 && dst != 0)
  144251. {
  144252. for (int j = 0; j < numSamples; ++j)
  144253. dst[j] = (float) (src[j] * gain);
  144254. }
  144255. }
  144256. }
  144257. vorbis_analysis_wrote (&vd, numSamples);
  144258. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144259. {
  144260. vorbis_analysis (&vb, 0);
  144261. vorbis_bitrate_addblock (&vb);
  144262. while (vorbis_bitrate_flushpacket (&vd, &op))
  144263. {
  144264. ogg_stream_packetin (&os, &op);
  144265. for (;;)
  144266. {
  144267. if (ogg_stream_pageout (&os, &og) == 0)
  144268. break;
  144269. output->write (og.header, og.header_len);
  144270. output->write (og.body, og.body_len);
  144271. if (ogg_page_eos (&og))
  144272. break;
  144273. }
  144274. }
  144275. }
  144276. return true;
  144277. }
  144278. juce_UseDebuggingNewOperator
  144279. };
  144280. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144281. : AudioFormat (TRANS (oggFormatName), (const juce_wchar**) oggExtensions)
  144282. {
  144283. }
  144284. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144285. {
  144286. }
  144287. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144288. {
  144289. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144290. return Array <int> (rates);
  144291. }
  144292. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144293. {
  144294. Array <int> depths;
  144295. depths.add (32);
  144296. return depths;
  144297. }
  144298. bool OggVorbisAudioFormat::canDoStereo()
  144299. {
  144300. return true;
  144301. }
  144302. bool OggVorbisAudioFormat::canDoMono()
  144303. {
  144304. return true;
  144305. }
  144306. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144307. const bool deleteStreamIfOpeningFails)
  144308. {
  144309. ScopedPointer <OggReader> r (new OggReader (in));
  144310. if (r->sampleRate != 0)
  144311. return r.release();
  144312. if (! deleteStreamIfOpeningFails)
  144313. r->input = 0;
  144314. return 0;
  144315. }
  144316. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144317. double sampleRate,
  144318. unsigned int numChannels,
  144319. int bitsPerSample,
  144320. const StringPairArray& /*metadataValues*/,
  144321. int qualityOptionIndex)
  144322. {
  144323. ScopedPointer <OggWriter> w (new OggWriter (out,
  144324. sampleRate,
  144325. numChannels,
  144326. bitsPerSample,
  144327. qualityOptionIndex));
  144328. return w->ok ? w.release() : 0;
  144329. }
  144330. bool OggVorbisAudioFormat::isCompressed()
  144331. {
  144332. return true;
  144333. }
  144334. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144335. {
  144336. StringArray s;
  144337. s.add ("Low Quality");
  144338. s.add ("Medium Quality");
  144339. s.add ("High Quality");
  144340. return s;
  144341. }
  144342. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144343. {
  144344. FileInputStream* const in = source.createInputStream();
  144345. if (in != 0)
  144346. {
  144347. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144348. if (r != 0)
  144349. {
  144350. const int64 numSamps = r->lengthInSamples;
  144351. r = 0;
  144352. const int64 fileNumSamps = source.getSize() / 4;
  144353. const double ratio = numSamps / (double) fileNumSamps;
  144354. if (ratio > 12.0)
  144355. return 0;
  144356. else if (ratio > 6.0)
  144357. return 1;
  144358. else
  144359. return 2;
  144360. }
  144361. }
  144362. return 1;
  144363. }
  144364. END_JUCE_NAMESPACE
  144365. #endif
  144366. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144367. #endif
  144368. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144369. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144370. #if JUCE_MSVC
  144371. #pragma warning (push)
  144372. #endif
  144373. namespace jpeglibNamespace
  144374. {
  144375. #if JUCE_INCLUDE_JPEGLIB_CODE
  144376. #if JUCE_MINGW
  144377. typedef unsigned char boolean;
  144378. #endif
  144379. extern "C"
  144380. {
  144381. #define JPEG_INTERNALS
  144382. #undef FAR
  144383. /*** Start of inlined file: jpeglib.h ***/
  144384. #ifndef JPEGLIB_H
  144385. #define JPEGLIB_H
  144386. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144387. /*** Start of inlined file: jconfig.h ***/
  144388. // disable all the warnings under MSVC
  144389. #ifdef _MSC_VER
  144390. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144391. #endif
  144392. #ifdef __BORLANDC__
  144393. #pragma warn -8057
  144394. #pragma warn -8019
  144395. #pragma warn -8004
  144396. #pragma warn -8008
  144397. #endif
  144398. #define HAVE_PROTOTYPES
  144399. #define HAVE_UNSIGNED_CHAR
  144400. #define HAVE_UNSIGNED_SHORT
  144401. #undef CHAR_IS_UNSIGNED
  144402. #define HAVE_STDDEF_H
  144403. #define HAVE_STDLIB_H
  144404. #undef NEED_BSD_STRINGS
  144405. #undef NEED_SYS_TYPES_H
  144406. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144407. #undef NEED_SHORT_EXTERNAL_NAMES
  144408. #undef INCOMPLETE_TYPES_BROKEN
  144409. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144410. typedef unsigned char boolean;
  144411. #endif
  144412. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144413. #ifdef JPEG_INTERNALS
  144414. #undef RIGHT_SHIFT_IS_UNSIGNED
  144415. #endif /* JPEG_INTERNALS */
  144416. #ifdef JPEG_CJPEG_DJPEG
  144417. #define BMP_SUPPORTED /* BMP image file format */
  144418. #define GIF_SUPPORTED /* GIF image file format */
  144419. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144420. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144421. #define TARGA_SUPPORTED /* Targa image file format */
  144422. #define TWO_FILE_COMMANDLINE /* optional */
  144423. #define USE_SETMODE /* Microsoft has setmode() */
  144424. #undef NEED_SIGNAL_CATCHER
  144425. #undef DONT_USE_B_MODE
  144426. #undef PROGRESS_REPORT /* optional */
  144427. #endif /* JPEG_CJPEG_DJPEG */
  144428. /*** End of inlined file: jconfig.h ***/
  144429. /* widely used configuration options */
  144430. #endif
  144431. /*** Start of inlined file: jmorecfg.h ***/
  144432. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144433. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144434. #if BITS_IN_JSAMPLE == 8
  144435. #ifdef HAVE_UNSIGNED_CHAR
  144436. typedef unsigned char JSAMPLE;
  144437. #define GETJSAMPLE(value) ((int) (value))
  144438. #else /* not HAVE_UNSIGNED_CHAR */
  144439. typedef char JSAMPLE;
  144440. #ifdef CHAR_IS_UNSIGNED
  144441. #define GETJSAMPLE(value) ((int) (value))
  144442. #else
  144443. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144444. #endif /* CHAR_IS_UNSIGNED */
  144445. #endif /* HAVE_UNSIGNED_CHAR */
  144446. #define MAXJSAMPLE 255
  144447. #define CENTERJSAMPLE 128
  144448. #endif /* BITS_IN_JSAMPLE == 8 */
  144449. #if BITS_IN_JSAMPLE == 12
  144450. typedef short JSAMPLE;
  144451. #define GETJSAMPLE(value) ((int) (value))
  144452. #define MAXJSAMPLE 4095
  144453. #define CENTERJSAMPLE 2048
  144454. #endif /* BITS_IN_JSAMPLE == 12 */
  144455. typedef short JCOEF;
  144456. #ifdef HAVE_UNSIGNED_CHAR
  144457. typedef unsigned char JOCTET;
  144458. #define GETJOCTET(value) (value)
  144459. #else /* not HAVE_UNSIGNED_CHAR */
  144460. typedef char JOCTET;
  144461. #ifdef CHAR_IS_UNSIGNED
  144462. #define GETJOCTET(value) (value)
  144463. #else
  144464. #define GETJOCTET(value) ((value) & 0xFF)
  144465. #endif /* CHAR_IS_UNSIGNED */
  144466. #endif /* HAVE_UNSIGNED_CHAR */
  144467. #ifdef HAVE_UNSIGNED_CHAR
  144468. typedef unsigned char UINT8;
  144469. #else /* not HAVE_UNSIGNED_CHAR */
  144470. #ifdef CHAR_IS_UNSIGNED
  144471. typedef char UINT8;
  144472. #else /* not CHAR_IS_UNSIGNED */
  144473. typedef short UINT8;
  144474. #endif /* CHAR_IS_UNSIGNED */
  144475. #endif /* HAVE_UNSIGNED_CHAR */
  144476. #ifdef HAVE_UNSIGNED_SHORT
  144477. typedef unsigned short UINT16;
  144478. #else /* not HAVE_UNSIGNED_SHORT */
  144479. typedef unsigned int UINT16;
  144480. #endif /* HAVE_UNSIGNED_SHORT */
  144481. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144482. typedef short INT16;
  144483. #endif
  144484. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144485. typedef long INT32;
  144486. #endif
  144487. typedef unsigned int JDIMENSION;
  144488. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144489. #define METHODDEF(type) static type
  144490. #define LOCAL(type) static type
  144491. #define GLOBAL(type) type
  144492. #define EXTERN(type) extern type
  144493. #ifdef HAVE_PROTOTYPES
  144494. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144495. #else
  144496. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144497. #endif
  144498. #ifdef NEED_FAR_POINTERS
  144499. #define FAR far
  144500. #else
  144501. #define FAR
  144502. #endif
  144503. #ifndef HAVE_BOOLEAN
  144504. typedef int boolean;
  144505. #endif
  144506. #ifndef FALSE /* in case these macros already exist */
  144507. #define FALSE 0 /* values of boolean */
  144508. #endif
  144509. #ifndef TRUE
  144510. #define TRUE 1
  144511. #endif
  144512. #ifdef JPEG_INTERNALS
  144513. #define JPEG_INTERNAL_OPTIONS
  144514. #endif
  144515. #ifdef JPEG_INTERNAL_OPTIONS
  144516. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  144517. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  144518. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  144519. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144520. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144521. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144522. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  144523. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  144524. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  144525. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  144526. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  144527. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  144528. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  144529. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  144530. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  144531. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  144532. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  144533. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  144534. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  144535. #define RGB_GREEN 1 /* Offset of Green */
  144536. #define RGB_BLUE 2 /* Offset of Blue */
  144537. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  144538. #ifndef INLINE
  144539. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  144540. #define INLINE __inline__
  144541. #endif
  144542. #ifndef INLINE
  144543. #define INLINE /* default is to define it as empty */
  144544. #endif
  144545. #endif
  144546. #ifndef MULTIPLIER
  144547. #define MULTIPLIER int /* type for fastest integer multiply */
  144548. #endif
  144549. #ifndef FAST_FLOAT
  144550. #ifdef HAVE_PROTOTYPES
  144551. #define FAST_FLOAT float
  144552. #else
  144553. #define FAST_FLOAT double
  144554. #endif
  144555. #endif
  144556. #endif /* JPEG_INTERNAL_OPTIONS */
  144557. /*** End of inlined file: jmorecfg.h ***/
  144558. /* seldom changed options */
  144559. #define JPEG_LIB_VERSION 62 /* Version 6b */
  144560. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  144561. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  144562. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  144563. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  144564. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  144565. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  144566. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  144567. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  144568. #ifndef D_MAX_BLOCKS_IN_MCU
  144569. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  144570. #endif
  144571. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  144572. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  144573. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  144574. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  144575. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  144576. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  144577. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  144578. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  144579. typedef struct {
  144580. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  144581. boolean sent_table; /* TRUE when table has been output */
  144582. } JQUANT_TBL;
  144583. typedef struct {
  144584. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  144585. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  144586. boolean sent_table; /* TRUE when table has been output */
  144587. } JHUFF_TBL;
  144588. typedef struct {
  144589. int component_id; /* identifier for this component (0..255) */
  144590. int component_index; /* its index in SOF or cinfo->comp_info[] */
  144591. int h_samp_factor; /* horizontal sampling factor (1..4) */
  144592. int v_samp_factor; /* vertical sampling factor (1..4) */
  144593. int quant_tbl_no; /* quantization table selector (0..3) */
  144594. int dc_tbl_no; /* DC entropy table selector (0..3) */
  144595. int ac_tbl_no; /* AC entropy table selector (0..3) */
  144596. JDIMENSION width_in_blocks;
  144597. JDIMENSION height_in_blocks;
  144598. int DCT_scaled_size;
  144599. JDIMENSION downsampled_width; /* actual width in samples */
  144600. JDIMENSION downsampled_height; /* actual height in samples */
  144601. boolean component_needed; /* do we need the value of this component? */
  144602. int MCU_width; /* number of blocks per MCU, horizontally */
  144603. int MCU_height; /* number of blocks per MCU, vertically */
  144604. int MCU_blocks; /* MCU_width * MCU_height */
  144605. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  144606. int last_col_width; /* # of non-dummy blocks across in last MCU */
  144607. int last_row_height; /* # of non-dummy blocks down in last MCU */
  144608. JQUANT_TBL * quant_table;
  144609. void * dct_table;
  144610. } jpeg_component_info;
  144611. typedef struct {
  144612. int comps_in_scan; /* number of components encoded in this scan */
  144613. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  144614. int Ss, Se; /* progressive JPEG spectral selection parms */
  144615. int Ah, Al; /* progressive JPEG successive approx. parms */
  144616. } jpeg_scan_info;
  144617. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  144618. struct jpeg_marker_struct {
  144619. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  144620. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  144621. unsigned int original_length; /* # bytes of data in the file */
  144622. unsigned int data_length; /* # bytes of data saved at data[] */
  144623. JOCTET FAR * data; /* the data contained in the marker */
  144624. };
  144625. typedef enum {
  144626. JCS_UNKNOWN, /* error/unspecified */
  144627. JCS_GRAYSCALE, /* monochrome */
  144628. JCS_RGB, /* red/green/blue */
  144629. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  144630. JCS_CMYK, /* C/M/Y/K */
  144631. JCS_YCCK /* Y/Cb/Cr/K */
  144632. } J_COLOR_SPACE;
  144633. typedef enum {
  144634. JDCT_ISLOW, /* slow but accurate integer algorithm */
  144635. JDCT_IFAST, /* faster, less accurate integer method */
  144636. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  144637. } J_DCT_METHOD;
  144638. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  144639. #define JDCT_DEFAULT JDCT_ISLOW
  144640. #endif
  144641. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  144642. #define JDCT_FASTEST JDCT_IFAST
  144643. #endif
  144644. typedef enum {
  144645. JDITHER_NONE, /* no dithering */
  144646. JDITHER_ORDERED, /* simple ordered dither */
  144647. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  144648. } J_DITHER_MODE;
  144649. #define jpeg_common_fields \
  144650. struct jpeg_error_mgr * err; /* Error handler module */\
  144651. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  144652. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  144653. void * client_data; /* Available for use by application */\
  144654. boolean is_decompressor; /* So common code can tell which is which */\
  144655. int global_state /* For checking call sequence validity */
  144656. struct jpeg_common_struct {
  144657. jpeg_common_fields; /* Fields common to both master struct types */
  144658. };
  144659. typedef struct jpeg_common_struct * j_common_ptr;
  144660. typedef struct jpeg_compress_struct * j_compress_ptr;
  144661. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  144662. struct jpeg_compress_struct {
  144663. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  144664. struct jpeg_destination_mgr * dest;
  144665. JDIMENSION image_width; /* input image width */
  144666. JDIMENSION image_height; /* input image height */
  144667. int input_components; /* # of color components in input image */
  144668. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  144669. double input_gamma; /* image gamma of input image */
  144670. int data_precision; /* bits of precision in image data */
  144671. int num_components; /* # of color components in JPEG image */
  144672. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144673. jpeg_component_info * comp_info;
  144674. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144675. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144676. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144677. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144678. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144679. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144680. int num_scans; /* # of entries in scan_info array */
  144681. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  144682. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  144683. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144684. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  144685. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144686. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  144687. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  144688. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  144689. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  144690. boolean write_JFIF_header; /* should a JFIF marker be written? */
  144691. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  144692. UINT8 JFIF_minor_version;
  144693. UINT8 density_unit; /* JFIF code for pixel size units */
  144694. UINT16 X_density; /* Horizontal pixel density */
  144695. UINT16 Y_density; /* Vertical pixel density */
  144696. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  144697. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  144698. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  144699. int max_h_samp_factor; /* largest h_samp_factor */
  144700. int max_v_samp_factor; /* largest v_samp_factor */
  144701. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  144702. int comps_in_scan; /* # of JPEG components in this scan */
  144703. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144704. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144705. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144706. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144707. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  144708. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144709. struct jpeg_comp_master * master;
  144710. struct jpeg_c_main_controller * main;
  144711. struct jpeg_c_prep_controller * prep;
  144712. struct jpeg_c_coef_controller * coef;
  144713. struct jpeg_marker_writer * marker;
  144714. struct jpeg_color_converter * cconvert;
  144715. struct jpeg_downsampler * downsample;
  144716. struct jpeg_forward_dct * fdct;
  144717. struct jpeg_entropy_encoder * entropy;
  144718. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  144719. int script_space_size;
  144720. };
  144721. struct jpeg_decompress_struct {
  144722. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  144723. struct jpeg_source_mgr * src;
  144724. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  144725. JDIMENSION image_height; /* nominal image height */
  144726. int num_components; /* # of color components in JPEG image */
  144727. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  144728. J_COLOR_SPACE out_color_space; /* colorspace for output */
  144729. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  144730. double output_gamma; /* image gamma wanted in output */
  144731. boolean buffered_image; /* TRUE=multiple output passes */
  144732. boolean raw_data_out; /* TRUE=downsampled data wanted */
  144733. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  144734. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  144735. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  144736. boolean quantize_colors; /* TRUE=colormapped output wanted */
  144737. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  144738. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  144739. int desired_number_of_colors; /* max # colors to use in created colormap */
  144740. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  144741. boolean enable_external_quant;/* enable future use of external colormap */
  144742. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  144743. JDIMENSION output_width; /* scaled image width */
  144744. JDIMENSION output_height; /* scaled image height */
  144745. int out_color_components; /* # of color components in out_color_space */
  144746. int output_components; /* # of color components returned */
  144747. int rec_outbuf_height; /* min recommended height of scanline buffer */
  144748. int actual_number_of_colors; /* number of entries in use */
  144749. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  144750. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  144751. int input_scan_number; /* Number of SOS markers seen so far */
  144752. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  144753. int output_scan_number; /* Nominal scan number being displayed */
  144754. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  144755. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  144756. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  144757. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144758. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  144759. int data_precision; /* bits of precision in image data */
  144760. jpeg_component_info * comp_info;
  144761. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  144762. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  144763. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  144764. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  144765. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  144766. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  144767. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  144768. UINT8 JFIF_major_version; /* JFIF version number */
  144769. UINT8 JFIF_minor_version;
  144770. UINT8 density_unit; /* JFIF code for pixel size units */
  144771. UINT16 X_density; /* Horizontal pixel density */
  144772. UINT16 Y_density; /* Vertical pixel density */
  144773. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  144774. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  144775. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  144776. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  144777. int max_h_samp_factor; /* largest h_samp_factor */
  144778. int max_v_samp_factor; /* largest v_samp_factor */
  144779. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  144780. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  144781. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  144782. int comps_in_scan; /* # of JPEG components in this scan */
  144783. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  144784. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  144785. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  144786. int blocks_in_MCU; /* # of DCT blocks per MCU */
  144787. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  144788. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  144789. int unread_marker;
  144790. struct jpeg_decomp_master * master;
  144791. struct jpeg_d_main_controller * main;
  144792. struct jpeg_d_coef_controller * coef;
  144793. struct jpeg_d_post_controller * post;
  144794. struct jpeg_input_controller * inputctl;
  144795. struct jpeg_marker_reader * marker;
  144796. struct jpeg_entropy_decoder * entropy;
  144797. struct jpeg_inverse_dct * idct;
  144798. struct jpeg_upsampler * upsample;
  144799. struct jpeg_color_deconverter * cconvert;
  144800. struct jpeg_color_quantizer * cquantize;
  144801. };
  144802. struct jpeg_error_mgr {
  144803. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  144804. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  144805. JMETHOD(void, output_message, (j_common_ptr cinfo));
  144806. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  144807. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  144808. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  144809. int msg_code;
  144810. #define JMSG_STR_PARM_MAX 80
  144811. union {
  144812. int i[8];
  144813. char s[JMSG_STR_PARM_MAX];
  144814. } msg_parm;
  144815. int trace_level; /* max msg_level that will be displayed */
  144816. long num_warnings; /* number of corrupt-data warnings */
  144817. const char * const * jpeg_message_table; /* Library errors */
  144818. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  144819. const char * const * addon_message_table; /* Non-library errors */
  144820. int first_addon_message; /* code for first string in addon table */
  144821. int last_addon_message; /* code for last string in addon table */
  144822. };
  144823. struct jpeg_progress_mgr {
  144824. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  144825. long pass_counter; /* work units completed in this pass */
  144826. long pass_limit; /* total number of work units in this pass */
  144827. int completed_passes; /* passes completed so far */
  144828. int total_passes; /* total number of passes expected */
  144829. };
  144830. struct jpeg_destination_mgr {
  144831. JOCTET * next_output_byte; /* => next byte to write in buffer */
  144832. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  144833. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  144834. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  144835. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  144836. };
  144837. struct jpeg_source_mgr {
  144838. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  144839. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  144840. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  144841. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  144842. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  144843. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  144844. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  144845. };
  144846. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  144847. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  144848. #define JPOOL_NUMPOOLS 2
  144849. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  144850. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  144851. struct jpeg_memory_mgr {
  144852. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  144853. size_t sizeofobject));
  144854. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  144855. size_t sizeofobject));
  144856. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  144857. JDIMENSION samplesperrow,
  144858. JDIMENSION numrows));
  144859. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  144860. JDIMENSION blocksperrow,
  144861. JDIMENSION numrows));
  144862. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  144863. int pool_id,
  144864. boolean pre_zero,
  144865. JDIMENSION samplesperrow,
  144866. JDIMENSION numrows,
  144867. JDIMENSION maxaccess));
  144868. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  144869. int pool_id,
  144870. boolean pre_zero,
  144871. JDIMENSION blocksperrow,
  144872. JDIMENSION numrows,
  144873. JDIMENSION maxaccess));
  144874. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  144875. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  144876. jvirt_sarray_ptr ptr,
  144877. JDIMENSION start_row,
  144878. JDIMENSION num_rows,
  144879. boolean writable));
  144880. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  144881. jvirt_barray_ptr ptr,
  144882. JDIMENSION start_row,
  144883. JDIMENSION num_rows,
  144884. boolean writable));
  144885. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  144886. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  144887. long max_memory_to_use;
  144888. long max_alloc_chunk;
  144889. };
  144890. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  144891. #ifdef HAVE_PROTOTYPES
  144892. #define JPP(arglist) arglist
  144893. #else
  144894. #define JPP(arglist) ()
  144895. #endif
  144896. #ifdef NEED_SHORT_EXTERNAL_NAMES
  144897. #define jpeg_std_error jStdError
  144898. #define jpeg_CreateCompress jCreaCompress
  144899. #define jpeg_CreateDecompress jCreaDecompress
  144900. #define jpeg_destroy_compress jDestCompress
  144901. #define jpeg_destroy_decompress jDestDecompress
  144902. #define jpeg_stdio_dest jStdDest
  144903. #define jpeg_stdio_src jStdSrc
  144904. #define jpeg_set_defaults jSetDefaults
  144905. #define jpeg_set_colorspace jSetColorspace
  144906. #define jpeg_default_colorspace jDefColorspace
  144907. #define jpeg_set_quality jSetQuality
  144908. #define jpeg_set_linear_quality jSetLQuality
  144909. #define jpeg_add_quant_table jAddQuantTable
  144910. #define jpeg_quality_scaling jQualityScaling
  144911. #define jpeg_simple_progression jSimProgress
  144912. #define jpeg_suppress_tables jSuppressTables
  144913. #define jpeg_alloc_quant_table jAlcQTable
  144914. #define jpeg_alloc_huff_table jAlcHTable
  144915. #define jpeg_start_compress jStrtCompress
  144916. #define jpeg_write_scanlines jWrtScanlines
  144917. #define jpeg_finish_compress jFinCompress
  144918. #define jpeg_write_raw_data jWrtRawData
  144919. #define jpeg_write_marker jWrtMarker
  144920. #define jpeg_write_m_header jWrtMHeader
  144921. #define jpeg_write_m_byte jWrtMByte
  144922. #define jpeg_write_tables jWrtTables
  144923. #define jpeg_read_header jReadHeader
  144924. #define jpeg_start_decompress jStrtDecompress
  144925. #define jpeg_read_scanlines jReadScanlines
  144926. #define jpeg_finish_decompress jFinDecompress
  144927. #define jpeg_read_raw_data jReadRawData
  144928. #define jpeg_has_multiple_scans jHasMultScn
  144929. #define jpeg_start_output jStrtOutput
  144930. #define jpeg_finish_output jFinOutput
  144931. #define jpeg_input_complete jInComplete
  144932. #define jpeg_new_colormap jNewCMap
  144933. #define jpeg_consume_input jConsumeInput
  144934. #define jpeg_calc_output_dimensions jCalcDimensions
  144935. #define jpeg_save_markers jSaveMarkers
  144936. #define jpeg_set_marker_processor jSetMarker
  144937. #define jpeg_read_coefficients jReadCoefs
  144938. #define jpeg_write_coefficients jWrtCoefs
  144939. #define jpeg_copy_critical_parameters jCopyCrit
  144940. #define jpeg_abort_compress jAbrtCompress
  144941. #define jpeg_abort_decompress jAbrtDecompress
  144942. #define jpeg_abort jAbort
  144943. #define jpeg_destroy jDestroy
  144944. #define jpeg_resync_to_restart jResyncRestart
  144945. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  144946. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  144947. JPP((struct jpeg_error_mgr * err));
  144948. #define jpeg_create_compress(cinfo) \
  144949. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  144950. (size_t) sizeof(struct jpeg_compress_struct))
  144951. #define jpeg_create_decompress(cinfo) \
  144952. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  144953. (size_t) sizeof(struct jpeg_decompress_struct))
  144954. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  144955. int version, size_t structsize));
  144956. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  144957. int version, size_t structsize));
  144958. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  144959. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  144960. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  144961. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  144962. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  144963. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  144964. J_COLOR_SPACE colorspace));
  144965. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  144966. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  144967. boolean force_baseline));
  144968. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  144969. int scale_factor,
  144970. boolean force_baseline));
  144971. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  144972. const unsigned int *basic_table,
  144973. int scale_factor,
  144974. boolean force_baseline));
  144975. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  144976. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  144977. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  144978. boolean suppress));
  144979. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  144980. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  144981. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  144982. boolean write_all_tables));
  144983. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  144984. JSAMPARRAY scanlines,
  144985. JDIMENSION num_lines));
  144986. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  144987. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  144988. JSAMPIMAGE data,
  144989. JDIMENSION num_lines));
  144990. EXTERN(void) jpeg_write_marker
  144991. JPP((j_compress_ptr cinfo, int marker,
  144992. const JOCTET * dataptr, unsigned int datalen));
  144993. EXTERN(void) jpeg_write_m_header
  144994. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  144995. EXTERN(void) jpeg_write_m_byte
  144996. JPP((j_compress_ptr cinfo, int val));
  144997. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  144998. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  144999. boolean require_image));
  145000. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145001. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145002. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145003. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145004. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145005. JSAMPARRAY scanlines,
  145006. JDIMENSION max_lines));
  145007. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145008. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145009. JSAMPIMAGE data,
  145010. JDIMENSION max_lines));
  145011. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145012. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145013. int scan_number));
  145014. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145015. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145016. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145017. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145018. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145019. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145020. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145021. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145022. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145023. EXTERN(void) jpeg_save_markers
  145024. JPP((j_decompress_ptr cinfo, int marker_code,
  145025. unsigned int length_limit));
  145026. EXTERN(void) jpeg_set_marker_processor
  145027. JPP((j_decompress_ptr cinfo, int marker_code,
  145028. jpeg_marker_parser_method routine));
  145029. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145030. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145031. jvirt_barray_ptr * coef_arrays));
  145032. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145033. j_compress_ptr dstinfo));
  145034. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145035. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145036. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145037. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145038. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145039. int desired));
  145040. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145041. #define JPEG_EOI 0xD9 /* EOI marker code */
  145042. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145043. #define JPEG_COM 0xFE /* COM marker code */
  145044. #ifdef INCOMPLETE_TYPES_BROKEN
  145045. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145046. struct jvirt_sarray_control { long dummy; };
  145047. struct jvirt_barray_control { long dummy; };
  145048. struct jpeg_comp_master { long dummy; };
  145049. struct jpeg_c_main_controller { long dummy; };
  145050. struct jpeg_c_prep_controller { long dummy; };
  145051. struct jpeg_c_coef_controller { long dummy; };
  145052. struct jpeg_marker_writer { long dummy; };
  145053. struct jpeg_color_converter { long dummy; };
  145054. struct jpeg_downsampler { long dummy; };
  145055. struct jpeg_forward_dct { long dummy; };
  145056. struct jpeg_entropy_encoder { long dummy; };
  145057. struct jpeg_decomp_master { long dummy; };
  145058. struct jpeg_d_main_controller { long dummy; };
  145059. struct jpeg_d_coef_controller { long dummy; };
  145060. struct jpeg_d_post_controller { long dummy; };
  145061. struct jpeg_input_controller { long dummy; };
  145062. struct jpeg_marker_reader { long dummy; };
  145063. struct jpeg_entropy_decoder { long dummy; };
  145064. struct jpeg_inverse_dct { long dummy; };
  145065. struct jpeg_upsampler { long dummy; };
  145066. struct jpeg_color_deconverter { long dummy; };
  145067. struct jpeg_color_quantizer { long dummy; };
  145068. #endif /* JPEG_INTERNALS */
  145069. #endif /* INCOMPLETE_TYPES_BROKEN */
  145070. #ifdef JPEG_INTERNALS
  145071. /*** Start of inlined file: jpegint.h ***/
  145072. typedef enum { /* Operating modes for buffer controllers */
  145073. JBUF_PASS_THRU, /* Plain stripwise operation */
  145074. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145075. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145076. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145077. } J_BUF_MODE;
  145078. #define CSTATE_START 100 /* after create_compress */
  145079. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145080. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145081. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145082. #define DSTATE_START 200 /* after create_decompress */
  145083. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145084. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145085. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145086. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145087. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145088. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145089. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145090. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145091. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145092. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145093. struct jpeg_comp_master {
  145094. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145095. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145096. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145097. boolean call_pass_startup; /* True if pass_startup must be called */
  145098. boolean is_last_pass; /* True during last pass */
  145099. };
  145100. struct jpeg_c_main_controller {
  145101. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145102. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145103. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145104. JDIMENSION in_rows_avail));
  145105. };
  145106. struct jpeg_c_prep_controller {
  145107. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145108. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145109. JSAMPARRAY input_buf,
  145110. JDIMENSION *in_row_ctr,
  145111. JDIMENSION in_rows_avail,
  145112. JSAMPIMAGE output_buf,
  145113. JDIMENSION *out_row_group_ctr,
  145114. JDIMENSION out_row_groups_avail));
  145115. };
  145116. struct jpeg_c_coef_controller {
  145117. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145118. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145119. JSAMPIMAGE input_buf));
  145120. };
  145121. struct jpeg_color_converter {
  145122. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145123. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145124. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145125. JDIMENSION output_row, int num_rows));
  145126. };
  145127. struct jpeg_downsampler {
  145128. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145129. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145130. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145131. JSAMPIMAGE output_buf,
  145132. JDIMENSION out_row_group_index));
  145133. boolean need_context_rows; /* TRUE if need rows above & below */
  145134. };
  145135. struct jpeg_forward_dct {
  145136. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145137. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145138. jpeg_component_info * compptr,
  145139. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145140. JDIMENSION start_row, JDIMENSION start_col,
  145141. JDIMENSION num_blocks));
  145142. };
  145143. struct jpeg_entropy_encoder {
  145144. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145145. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145146. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145147. };
  145148. struct jpeg_marker_writer {
  145149. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145150. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145151. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145152. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145153. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145154. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145155. unsigned int datalen));
  145156. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145157. };
  145158. struct jpeg_decomp_master {
  145159. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145160. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145161. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145162. };
  145163. struct jpeg_input_controller {
  145164. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145165. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145166. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145167. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145168. boolean has_multiple_scans; /* True if file has multiple scans */
  145169. boolean eoi_reached; /* True when EOI has been consumed */
  145170. };
  145171. struct jpeg_d_main_controller {
  145172. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145173. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145174. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145175. JDIMENSION out_rows_avail));
  145176. };
  145177. struct jpeg_d_coef_controller {
  145178. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145179. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145180. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145181. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145182. JSAMPIMAGE output_buf));
  145183. jvirt_barray_ptr *coef_arrays;
  145184. };
  145185. struct jpeg_d_post_controller {
  145186. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145187. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145188. JSAMPIMAGE input_buf,
  145189. JDIMENSION *in_row_group_ctr,
  145190. JDIMENSION in_row_groups_avail,
  145191. JSAMPARRAY output_buf,
  145192. JDIMENSION *out_row_ctr,
  145193. JDIMENSION out_rows_avail));
  145194. };
  145195. struct jpeg_marker_reader {
  145196. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145197. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145198. jpeg_marker_parser_method read_restart_marker;
  145199. boolean saw_SOI; /* found SOI? */
  145200. boolean saw_SOF; /* found SOF? */
  145201. int next_restart_num; /* next restart number expected (0-7) */
  145202. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145203. };
  145204. struct jpeg_entropy_decoder {
  145205. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145206. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145207. JBLOCKROW *MCU_data));
  145208. boolean insufficient_data; /* set TRUE after emitting warning */
  145209. };
  145210. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145211. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145212. JCOEFPTR coef_block,
  145213. JSAMPARRAY output_buf, JDIMENSION output_col));
  145214. struct jpeg_inverse_dct {
  145215. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145216. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145217. };
  145218. struct jpeg_upsampler {
  145219. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145220. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145221. JSAMPIMAGE input_buf,
  145222. JDIMENSION *in_row_group_ctr,
  145223. JDIMENSION in_row_groups_avail,
  145224. JSAMPARRAY output_buf,
  145225. JDIMENSION *out_row_ctr,
  145226. JDIMENSION out_rows_avail));
  145227. boolean need_context_rows; /* TRUE if need rows above & below */
  145228. };
  145229. struct jpeg_color_deconverter {
  145230. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145231. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145232. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145233. JSAMPARRAY output_buf, int num_rows));
  145234. };
  145235. struct jpeg_color_quantizer {
  145236. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145237. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145238. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145239. int num_rows));
  145240. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145241. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145242. };
  145243. #undef MAX
  145244. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145245. #undef MIN
  145246. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145247. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145248. #define SHIFT_TEMPS INT32 shift_temp;
  145249. #define RIGHT_SHIFT(x,shft) \
  145250. ((shift_temp = (x)) < 0 ? \
  145251. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145252. (shift_temp >> (shft)))
  145253. #else
  145254. #define SHIFT_TEMPS
  145255. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145256. #endif
  145257. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145258. #define jinit_compress_master jICompress
  145259. #define jinit_c_master_control jICMaster
  145260. #define jinit_c_main_controller jICMainC
  145261. #define jinit_c_prep_controller jICPrepC
  145262. #define jinit_c_coef_controller jICCoefC
  145263. #define jinit_color_converter jICColor
  145264. #define jinit_downsampler jIDownsampler
  145265. #define jinit_forward_dct jIFDCT
  145266. #define jinit_huff_encoder jIHEncoder
  145267. #define jinit_phuff_encoder jIPHEncoder
  145268. #define jinit_marker_writer jIMWriter
  145269. #define jinit_master_decompress jIDMaster
  145270. #define jinit_d_main_controller jIDMainC
  145271. #define jinit_d_coef_controller jIDCoefC
  145272. #define jinit_d_post_controller jIDPostC
  145273. #define jinit_input_controller jIInCtlr
  145274. #define jinit_marker_reader jIMReader
  145275. #define jinit_huff_decoder jIHDecoder
  145276. #define jinit_phuff_decoder jIPHDecoder
  145277. #define jinit_inverse_dct jIIDCT
  145278. #define jinit_upsampler jIUpsampler
  145279. #define jinit_color_deconverter jIDColor
  145280. #define jinit_1pass_quantizer jI1Quant
  145281. #define jinit_2pass_quantizer jI2Quant
  145282. #define jinit_merged_upsampler jIMUpsampler
  145283. #define jinit_memory_mgr jIMemMgr
  145284. #define jdiv_round_up jDivRound
  145285. #define jround_up jRound
  145286. #define jcopy_sample_rows jCopySamples
  145287. #define jcopy_block_row jCopyBlocks
  145288. #define jzero_far jZeroFar
  145289. #define jpeg_zigzag_order jZIGTable
  145290. #define jpeg_natural_order jZAGTable
  145291. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145292. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145293. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145294. boolean transcode_only));
  145295. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145296. boolean need_full_buffer));
  145297. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145298. boolean need_full_buffer));
  145299. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145300. boolean need_full_buffer));
  145301. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145302. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145303. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145304. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145305. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145306. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145307. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145308. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145309. boolean need_full_buffer));
  145310. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145311. boolean need_full_buffer));
  145312. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145313. boolean need_full_buffer));
  145314. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145315. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145316. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145317. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145318. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145319. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145320. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145321. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145322. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145323. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145324. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145325. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145326. EXTERN(long) jround_up JPP((long a, long b));
  145327. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145328. JSAMPARRAY output_array, int dest_row,
  145329. int num_rows, JDIMENSION num_cols));
  145330. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145331. JDIMENSION num_blocks));
  145332. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145333. #if 0 /* This table is not actually needed in v6a */
  145334. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145335. #endif
  145336. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145337. #ifdef INCOMPLETE_TYPES_BROKEN
  145338. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145339. struct jvirt_sarray_control { long dummy; };
  145340. struct jvirt_barray_control { long dummy; };
  145341. #endif
  145342. #endif /* INCOMPLETE_TYPES_BROKEN */
  145343. /*** End of inlined file: jpegint.h ***/
  145344. /* fetch private declarations */
  145345. /*** Start of inlined file: jerror.h ***/
  145346. #ifndef JMESSAGE
  145347. #ifndef JERROR_H
  145348. #define JMAKE_ENUM_LIST
  145349. #else
  145350. #define JMESSAGE(code,string)
  145351. #endif /* JERROR_H */
  145352. #endif /* JMESSAGE */
  145353. #ifdef JMAKE_ENUM_LIST
  145354. typedef enum {
  145355. #define JMESSAGE(code,string) code ,
  145356. #endif /* JMAKE_ENUM_LIST */
  145357. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145358. JMESSAGE(JERR_ARITH_NOTIMPL,
  145359. "Sorry, there are legal restrictions on arithmetic coding")
  145360. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145361. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145362. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145363. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145364. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145365. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145366. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145367. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145368. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145369. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145370. JMESSAGE(JERR_BAD_LIB_VERSION,
  145371. "Wrong JPEG library version: library is %d, caller expects %d")
  145372. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145373. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145374. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145375. JMESSAGE(JERR_BAD_PROGRESSION,
  145376. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145377. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145378. "Invalid progressive parameters at scan script entry %d")
  145379. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145380. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145381. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145382. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145383. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145384. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145385. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145386. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145387. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145388. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145389. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145390. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145391. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145392. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145393. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145394. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145395. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145396. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145397. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145398. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145399. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145400. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145401. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145402. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145403. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145404. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145405. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145406. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145407. "Cannot transcode due to multiple use of quantization table %d")
  145408. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145409. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145410. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145411. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145412. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145413. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145414. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145415. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145416. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145417. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145418. JMESSAGE(JERR_QUANT_COMPONENTS,
  145419. "Cannot quantize more than %d color components")
  145420. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145421. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145422. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145423. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145424. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145425. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145426. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145427. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145428. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145429. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145430. JMESSAGE(JERR_TFILE_WRITE,
  145431. "Write failed on temporary file --- out of disk space?")
  145432. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145433. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145434. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145435. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145436. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145437. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145438. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145439. JMESSAGE(JMSG_VERSION, JVERSION)
  145440. JMESSAGE(JTRC_16BIT_TABLES,
  145441. "Caution: quantization tables are too coarse for baseline JPEG")
  145442. JMESSAGE(JTRC_ADOBE,
  145443. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145444. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145445. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145446. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145447. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145448. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145449. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145450. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145451. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145452. JMESSAGE(JTRC_EOI, "End Of Image")
  145453. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145454. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145455. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145456. "Warning: thumbnail image size does not match data length %u")
  145457. JMESSAGE(JTRC_JFIF_EXTENSION,
  145458. "JFIF extension marker: type 0x%02x, length %u")
  145459. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145460. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145461. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145462. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145463. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145464. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145465. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145466. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145467. JMESSAGE(JTRC_RST, "RST%d")
  145468. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145469. "Smoothing not supported with nonstandard sampling ratios")
  145470. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145471. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145472. JMESSAGE(JTRC_SOI, "Start of Image")
  145473. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145474. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145475. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145476. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145477. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145478. JMESSAGE(JTRC_THUMB_JPEG,
  145479. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145480. JMESSAGE(JTRC_THUMB_PALETTE,
  145481. "JFIF extension marker: palette thumbnail image, length %u")
  145482. JMESSAGE(JTRC_THUMB_RGB,
  145483. "JFIF extension marker: RGB thumbnail image, length %u")
  145484. JMESSAGE(JTRC_UNKNOWN_IDS,
  145485. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145486. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145487. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145488. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145489. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145490. "Inconsistent progression sequence for component %d coefficient %d")
  145491. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145492. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145493. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145494. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145495. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145496. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145497. JMESSAGE(JWRN_MUST_RESYNC,
  145498. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145499. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145500. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145501. #ifdef JMAKE_ENUM_LIST
  145502. JMSG_LASTMSGCODE
  145503. } J_MESSAGE_CODE;
  145504. #undef JMAKE_ENUM_LIST
  145505. #endif /* JMAKE_ENUM_LIST */
  145506. #undef JMESSAGE
  145507. #ifndef JERROR_H
  145508. #define JERROR_H
  145509. #define ERREXIT(cinfo,code) \
  145510. ((cinfo)->err->msg_code = (code), \
  145511. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145512. #define ERREXIT1(cinfo,code,p1) \
  145513. ((cinfo)->err->msg_code = (code), \
  145514. (cinfo)->err->msg_parm.i[0] = (p1), \
  145515. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145516. #define ERREXIT2(cinfo,code,p1,p2) \
  145517. ((cinfo)->err->msg_code = (code), \
  145518. (cinfo)->err->msg_parm.i[0] = (p1), \
  145519. (cinfo)->err->msg_parm.i[1] = (p2), \
  145520. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145521. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  145522. ((cinfo)->err->msg_code = (code), \
  145523. (cinfo)->err->msg_parm.i[0] = (p1), \
  145524. (cinfo)->err->msg_parm.i[1] = (p2), \
  145525. (cinfo)->err->msg_parm.i[2] = (p3), \
  145526. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145527. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  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->msg_parm.i[2] = (p3), \
  145532. (cinfo)->err->msg_parm.i[3] = (p4), \
  145533. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145534. #define ERREXITS(cinfo,code,str) \
  145535. ((cinfo)->err->msg_code = (code), \
  145536. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145537. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145538. #define MAKESTMT(stuff) do { stuff } while (0)
  145539. #define WARNMS(cinfo,code) \
  145540. ((cinfo)->err->msg_code = (code), \
  145541. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145542. #define WARNMS1(cinfo,code,p1) \
  145543. ((cinfo)->err->msg_code = (code), \
  145544. (cinfo)->err->msg_parm.i[0] = (p1), \
  145545. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145546. #define WARNMS2(cinfo,code,p1,p2) \
  145547. ((cinfo)->err->msg_code = (code), \
  145548. (cinfo)->err->msg_parm.i[0] = (p1), \
  145549. (cinfo)->err->msg_parm.i[1] = (p2), \
  145550. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  145551. #define TRACEMS(cinfo,lvl,code) \
  145552. ((cinfo)->err->msg_code = (code), \
  145553. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145554. #define TRACEMS1(cinfo,lvl,code,p1) \
  145555. ((cinfo)->err->msg_code = (code), \
  145556. (cinfo)->err->msg_parm.i[0] = (p1), \
  145557. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145558. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  145559. ((cinfo)->err->msg_code = (code), \
  145560. (cinfo)->err->msg_parm.i[0] = (p1), \
  145561. (cinfo)->err->msg_parm.i[1] = (p2), \
  145562. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145563. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  145564. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145565. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  145566. (cinfo)->err->msg_code = (code); \
  145567. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145568. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  145569. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145570. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145571. (cinfo)->err->msg_code = (code); \
  145572. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145573. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  145574. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145575. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145576. _mp[4] = (p5); \
  145577. (cinfo)->err->msg_code = (code); \
  145578. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145579. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  145580. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  145581. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  145582. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  145583. (cinfo)->err->msg_code = (code); \
  145584. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  145585. #define TRACEMSS(cinfo,lvl,code,str) \
  145586. ((cinfo)->err->msg_code = (code), \
  145587. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  145588. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  145589. #endif /* JERROR_H */
  145590. /*** End of inlined file: jerror.h ***/
  145591. /* fetch error codes too */
  145592. #endif
  145593. #endif /* JPEGLIB_H */
  145594. /*** End of inlined file: jpeglib.h ***/
  145595. /*** Start of inlined file: jcapimin.c ***/
  145596. #define JPEG_INTERNALS
  145597. /*** Start of inlined file: jinclude.h ***/
  145598. #ifndef __jinclude_h__
  145599. #define __jinclude_h__
  145600. /*** Start of inlined file: jconfig.h ***/
  145601. // disable all the warnings under MSVC
  145602. #ifdef _MSC_VER
  145603. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  145604. #endif
  145605. #ifdef __BORLANDC__
  145606. #pragma warn -8057
  145607. #pragma warn -8019
  145608. #pragma warn -8004
  145609. #pragma warn -8008
  145610. #endif
  145611. #define HAVE_PROTOTYPES
  145612. #define HAVE_UNSIGNED_CHAR
  145613. #define HAVE_UNSIGNED_SHORT
  145614. #undef CHAR_IS_UNSIGNED
  145615. #define HAVE_STDDEF_H
  145616. #define HAVE_STDLIB_H
  145617. #undef NEED_BSD_STRINGS
  145618. #undef NEED_SYS_TYPES_H
  145619. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  145620. #undef NEED_SHORT_EXTERNAL_NAMES
  145621. #undef INCOMPLETE_TYPES_BROKEN
  145622. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  145623. typedef unsigned char boolean;
  145624. #endif
  145625. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  145626. #ifdef JPEG_INTERNALS
  145627. #undef RIGHT_SHIFT_IS_UNSIGNED
  145628. #endif /* JPEG_INTERNALS */
  145629. #ifdef JPEG_CJPEG_DJPEG
  145630. #define BMP_SUPPORTED /* BMP image file format */
  145631. #define GIF_SUPPORTED /* GIF image file format */
  145632. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  145633. #undef RLE_SUPPORTED /* Utah RLE image file format */
  145634. #define TARGA_SUPPORTED /* Targa image file format */
  145635. #define TWO_FILE_COMMANDLINE /* optional */
  145636. #define USE_SETMODE /* Microsoft has setmode() */
  145637. #undef NEED_SIGNAL_CATCHER
  145638. #undef DONT_USE_B_MODE
  145639. #undef PROGRESS_REPORT /* optional */
  145640. #endif /* JPEG_CJPEG_DJPEG */
  145641. /*** End of inlined file: jconfig.h ***/
  145642. /* auto configuration options */
  145643. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  145644. #ifdef HAVE_STDDEF_H
  145645. #include <stddef.h>
  145646. #endif
  145647. #ifdef HAVE_STDLIB_H
  145648. #include <stdlib.h>
  145649. #endif
  145650. #ifdef NEED_SYS_TYPES_H
  145651. #include <sys/types.h>
  145652. #endif
  145653. #include <stdio.h>
  145654. #ifdef NEED_BSD_STRINGS
  145655. #include <strings.h>
  145656. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  145657. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  145658. #else /* not BSD, assume ANSI/SysV string lib */
  145659. #include <string.h>
  145660. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  145661. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  145662. #endif
  145663. #define SIZEOF(object) ((size_t) sizeof(object))
  145664. #define JFREAD(file,buf,sizeofbuf) \
  145665. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145666. #define JFWRITE(file,buf,sizeofbuf) \
  145667. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  145668. typedef enum { /* JPEG marker codes */
  145669. M_SOF0 = 0xc0,
  145670. M_SOF1 = 0xc1,
  145671. M_SOF2 = 0xc2,
  145672. M_SOF3 = 0xc3,
  145673. M_SOF5 = 0xc5,
  145674. M_SOF6 = 0xc6,
  145675. M_SOF7 = 0xc7,
  145676. M_JPG = 0xc8,
  145677. M_SOF9 = 0xc9,
  145678. M_SOF10 = 0xca,
  145679. M_SOF11 = 0xcb,
  145680. M_SOF13 = 0xcd,
  145681. M_SOF14 = 0xce,
  145682. M_SOF15 = 0xcf,
  145683. M_DHT = 0xc4,
  145684. M_DAC = 0xcc,
  145685. M_RST0 = 0xd0,
  145686. M_RST1 = 0xd1,
  145687. M_RST2 = 0xd2,
  145688. M_RST3 = 0xd3,
  145689. M_RST4 = 0xd4,
  145690. M_RST5 = 0xd5,
  145691. M_RST6 = 0xd6,
  145692. M_RST7 = 0xd7,
  145693. M_SOI = 0xd8,
  145694. M_EOI = 0xd9,
  145695. M_SOS = 0xda,
  145696. M_DQT = 0xdb,
  145697. M_DNL = 0xdc,
  145698. M_DRI = 0xdd,
  145699. M_DHP = 0xde,
  145700. M_EXP = 0xdf,
  145701. M_APP0 = 0xe0,
  145702. M_APP1 = 0xe1,
  145703. M_APP2 = 0xe2,
  145704. M_APP3 = 0xe3,
  145705. M_APP4 = 0xe4,
  145706. M_APP5 = 0xe5,
  145707. M_APP6 = 0xe6,
  145708. M_APP7 = 0xe7,
  145709. M_APP8 = 0xe8,
  145710. M_APP9 = 0xe9,
  145711. M_APP10 = 0xea,
  145712. M_APP11 = 0xeb,
  145713. M_APP12 = 0xec,
  145714. M_APP13 = 0xed,
  145715. M_APP14 = 0xee,
  145716. M_APP15 = 0xef,
  145717. M_JPG0 = 0xf0,
  145718. M_JPG13 = 0xfd,
  145719. M_COM = 0xfe,
  145720. M_TEM = 0x01,
  145721. M_ERROR = 0x100
  145722. } JPEG_MARKER;
  145723. #ifdef AVOID_TABLES
  145724. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  145725. #else
  145726. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  145727. static const int extend_test[16] = /* entry n is 2**(n-1) */
  145728. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  145729. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  145730. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  145731. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  145732. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  145733. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  145734. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  145735. #endif /* AVOID_TABLES */
  145736. #endif
  145737. /*** End of inlined file: jinclude.h ***/
  145738. GLOBAL(void)
  145739. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  145740. {
  145741. int i;
  145742. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  145743. if (version != JPEG_LIB_VERSION)
  145744. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  145745. if (structsize != SIZEOF(struct jpeg_compress_struct))
  145746. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  145747. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  145748. {
  145749. struct jpeg_error_mgr * err = cinfo->err;
  145750. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  145751. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  145752. cinfo->err = err;
  145753. cinfo->client_data = client_data;
  145754. }
  145755. cinfo->is_decompressor = FALSE;
  145756. jinit_memory_mgr((j_common_ptr) cinfo);
  145757. cinfo->progress = NULL;
  145758. cinfo->dest = NULL;
  145759. cinfo->comp_info = NULL;
  145760. for (i = 0; i < NUM_QUANT_TBLS; i++)
  145761. cinfo->quant_tbl_ptrs[i] = NULL;
  145762. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145763. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  145764. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  145765. }
  145766. cinfo->script_space = NULL;
  145767. cinfo->input_gamma = 1.0; /* in case application forgets */
  145768. cinfo->global_state = CSTATE_START;
  145769. }
  145770. GLOBAL(void)
  145771. jpeg_destroy_compress (j_compress_ptr cinfo)
  145772. {
  145773. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  145774. }
  145775. GLOBAL(void)
  145776. jpeg_abort_compress (j_compress_ptr cinfo)
  145777. {
  145778. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  145779. }
  145780. GLOBAL(void)
  145781. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  145782. {
  145783. int i;
  145784. JQUANT_TBL * qtbl;
  145785. JHUFF_TBL * htbl;
  145786. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  145787. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  145788. qtbl->sent_table = suppress;
  145789. }
  145790. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  145791. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  145792. htbl->sent_table = suppress;
  145793. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  145794. htbl->sent_table = suppress;
  145795. }
  145796. }
  145797. GLOBAL(void)
  145798. jpeg_finish_compress (j_compress_ptr cinfo)
  145799. {
  145800. JDIMENSION iMCU_row;
  145801. if (cinfo->global_state == CSTATE_SCANNING ||
  145802. cinfo->global_state == CSTATE_RAW_OK) {
  145803. if (cinfo->next_scanline < cinfo->image_height)
  145804. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  145805. (*cinfo->master->finish_pass) (cinfo);
  145806. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  145807. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145808. while (! cinfo->master->is_last_pass) {
  145809. (*cinfo->master->prepare_for_pass) (cinfo);
  145810. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  145811. if (cinfo->progress != NULL) {
  145812. cinfo->progress->pass_counter = (long) iMCU_row;
  145813. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  145814. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145815. }
  145816. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  145817. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  145818. }
  145819. (*cinfo->master->finish_pass) (cinfo);
  145820. }
  145821. (*cinfo->marker->write_file_trailer) (cinfo);
  145822. (*cinfo->dest->term_destination) (cinfo);
  145823. jpeg_abort((j_common_ptr) cinfo);
  145824. }
  145825. GLOBAL(void)
  145826. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  145827. const JOCTET *dataptr, unsigned int datalen)
  145828. {
  145829. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  145830. if (cinfo->next_scanline != 0 ||
  145831. (cinfo->global_state != CSTATE_SCANNING &&
  145832. cinfo->global_state != CSTATE_RAW_OK &&
  145833. cinfo->global_state != CSTATE_WRCOEFS))
  145834. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145835. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145836. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  145837. while (datalen--) {
  145838. (*write_marker_byte) (cinfo, *dataptr);
  145839. dataptr++;
  145840. }
  145841. }
  145842. GLOBAL(void)
  145843. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  145844. {
  145845. if (cinfo->next_scanline != 0 ||
  145846. (cinfo->global_state != CSTATE_SCANNING &&
  145847. cinfo->global_state != CSTATE_RAW_OK &&
  145848. cinfo->global_state != CSTATE_WRCOEFS))
  145849. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145850. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  145851. }
  145852. GLOBAL(void)
  145853. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  145854. {
  145855. (*cinfo->marker->write_marker_byte) (cinfo, val);
  145856. }
  145857. GLOBAL(void)
  145858. jpeg_write_tables (j_compress_ptr cinfo)
  145859. {
  145860. if (cinfo->global_state != CSTATE_START)
  145861. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145862. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145863. (*cinfo->dest->init_destination) (cinfo);
  145864. jinit_marker_writer(cinfo);
  145865. (*cinfo->marker->write_tables_only) (cinfo);
  145866. (*cinfo->dest->term_destination) (cinfo);
  145867. }
  145868. /*** End of inlined file: jcapimin.c ***/
  145869. /*** Start of inlined file: jcapistd.c ***/
  145870. #define JPEG_INTERNALS
  145871. GLOBAL(void)
  145872. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  145873. {
  145874. if (cinfo->global_state != CSTATE_START)
  145875. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145876. if (write_all_tables)
  145877. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  145878. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  145879. (*cinfo->dest->init_destination) (cinfo);
  145880. jinit_compress_master(cinfo);
  145881. (*cinfo->master->prepare_for_pass) (cinfo);
  145882. cinfo->next_scanline = 0;
  145883. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  145884. }
  145885. GLOBAL(JDIMENSION)
  145886. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  145887. JDIMENSION num_lines)
  145888. {
  145889. JDIMENSION row_ctr, rows_left;
  145890. if (cinfo->global_state != CSTATE_SCANNING)
  145891. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145892. if (cinfo->next_scanline >= cinfo->image_height)
  145893. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145894. if (cinfo->progress != NULL) {
  145895. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145896. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145897. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145898. }
  145899. if (cinfo->master->call_pass_startup)
  145900. (*cinfo->master->pass_startup) (cinfo);
  145901. rows_left = cinfo->image_height - cinfo->next_scanline;
  145902. if (num_lines > rows_left)
  145903. num_lines = rows_left;
  145904. row_ctr = 0;
  145905. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  145906. cinfo->next_scanline += row_ctr;
  145907. return row_ctr;
  145908. }
  145909. GLOBAL(JDIMENSION)
  145910. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  145911. JDIMENSION num_lines)
  145912. {
  145913. JDIMENSION lines_per_iMCU_row;
  145914. if (cinfo->global_state != CSTATE_RAW_OK)
  145915. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  145916. if (cinfo->next_scanline >= cinfo->image_height) {
  145917. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  145918. return 0;
  145919. }
  145920. if (cinfo->progress != NULL) {
  145921. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  145922. cinfo->progress->pass_limit = (long) cinfo->image_height;
  145923. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  145924. }
  145925. if (cinfo->master->call_pass_startup)
  145926. (*cinfo->master->pass_startup) (cinfo);
  145927. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  145928. if (num_lines < lines_per_iMCU_row)
  145929. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  145930. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  145931. return 0;
  145932. }
  145933. cinfo->next_scanline += lines_per_iMCU_row;
  145934. return lines_per_iMCU_row;
  145935. }
  145936. /*** End of inlined file: jcapistd.c ***/
  145937. /*** Start of inlined file: jccoefct.c ***/
  145938. #define JPEG_INTERNALS
  145939. #ifdef ENTROPY_OPT_SUPPORTED
  145940. #define FULL_COEF_BUFFER_SUPPORTED
  145941. #else
  145942. #ifdef C_MULTISCAN_FILES_SUPPORTED
  145943. #define FULL_COEF_BUFFER_SUPPORTED
  145944. #endif
  145945. #endif
  145946. typedef struct {
  145947. struct jpeg_c_coef_controller pub; /* public fields */
  145948. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  145949. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  145950. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  145951. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  145952. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  145953. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  145954. } my_coef_controller;
  145955. typedef my_coef_controller * my_coef_ptr;
  145956. METHODDEF(boolean) compress_data
  145957. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145958. #ifdef FULL_COEF_BUFFER_SUPPORTED
  145959. METHODDEF(boolean) compress_first_pass
  145960. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145961. METHODDEF(boolean) compress_output
  145962. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  145963. #endif
  145964. LOCAL(void)
  145965. start_iMCU_row (j_compress_ptr cinfo)
  145966. {
  145967. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145968. if (cinfo->comps_in_scan > 1) {
  145969. coef->MCU_rows_per_iMCU_row = 1;
  145970. } else {
  145971. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  145972. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  145973. else
  145974. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  145975. }
  145976. coef->mcu_ctr = 0;
  145977. coef->MCU_vert_offset = 0;
  145978. }
  145979. METHODDEF(void)
  145980. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  145981. {
  145982. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  145983. coef->iMCU_row_num = 0;
  145984. start_iMCU_row(cinfo);
  145985. switch (pass_mode) {
  145986. case JBUF_PASS_THRU:
  145987. if (coef->whole_image[0] != NULL)
  145988. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145989. coef->pub.compress_data = compress_data;
  145990. break;
  145991. #ifdef FULL_COEF_BUFFER_SUPPORTED
  145992. case JBUF_SAVE_AND_PASS:
  145993. if (coef->whole_image[0] == NULL)
  145994. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  145995. coef->pub.compress_data = compress_first_pass;
  145996. break;
  145997. case JBUF_CRANK_DEST:
  145998. if (coef->whole_image[0] == NULL)
  145999. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146000. coef->pub.compress_data = compress_output;
  146001. break;
  146002. #endif
  146003. default:
  146004. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146005. break;
  146006. }
  146007. }
  146008. METHODDEF(boolean)
  146009. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146010. {
  146011. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146012. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146013. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146014. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146015. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146016. JDIMENSION ypos, xpos;
  146017. jpeg_component_info *compptr;
  146018. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146019. yoffset++) {
  146020. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146021. MCU_col_num++) {
  146022. blkn = 0;
  146023. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146024. compptr = cinfo->cur_comp_info[ci];
  146025. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146026. : compptr->last_col_width;
  146027. xpos = MCU_col_num * compptr->MCU_sample_width;
  146028. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146029. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146030. if (coef->iMCU_row_num < last_iMCU_row ||
  146031. yoffset+yindex < compptr->last_row_height) {
  146032. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146033. input_buf[compptr->component_index],
  146034. coef->MCU_buffer[blkn],
  146035. ypos, xpos, (JDIMENSION) blockcnt);
  146036. if (blockcnt < compptr->MCU_width) {
  146037. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146038. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146039. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146040. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146041. }
  146042. }
  146043. } else {
  146044. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146045. compptr->MCU_width * SIZEOF(JBLOCK));
  146046. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146047. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146048. }
  146049. }
  146050. blkn += compptr->MCU_width;
  146051. ypos += DCTSIZE;
  146052. }
  146053. }
  146054. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146055. coef->MCU_vert_offset = yoffset;
  146056. coef->mcu_ctr = MCU_col_num;
  146057. return FALSE;
  146058. }
  146059. }
  146060. coef->mcu_ctr = 0;
  146061. }
  146062. coef->iMCU_row_num++;
  146063. start_iMCU_row(cinfo);
  146064. return TRUE;
  146065. }
  146066. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146067. METHODDEF(boolean)
  146068. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146069. {
  146070. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146071. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146072. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146073. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146074. JCOEF lastDC;
  146075. jpeg_component_info *compptr;
  146076. JBLOCKARRAY buffer;
  146077. JBLOCKROW thisblockrow, lastblockrow;
  146078. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146079. ci++, compptr++) {
  146080. buffer = (*cinfo->mem->access_virt_barray)
  146081. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146082. coef->iMCU_row_num * compptr->v_samp_factor,
  146083. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146084. if (coef->iMCU_row_num < last_iMCU_row)
  146085. block_rows = compptr->v_samp_factor;
  146086. else {
  146087. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146088. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146089. }
  146090. blocks_across = compptr->width_in_blocks;
  146091. h_samp_factor = compptr->h_samp_factor;
  146092. ndummy = (int) (blocks_across % h_samp_factor);
  146093. if (ndummy > 0)
  146094. ndummy = h_samp_factor - ndummy;
  146095. for (block_row = 0; block_row < block_rows; block_row++) {
  146096. thisblockrow = buffer[block_row];
  146097. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146098. input_buf[ci], thisblockrow,
  146099. (JDIMENSION) (block_row * DCTSIZE),
  146100. (JDIMENSION) 0, blocks_across);
  146101. if (ndummy > 0) {
  146102. thisblockrow += blocks_across; /* => first dummy block */
  146103. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146104. lastDC = thisblockrow[-1][0];
  146105. for (bi = 0; bi < ndummy; bi++) {
  146106. thisblockrow[bi][0] = lastDC;
  146107. }
  146108. }
  146109. }
  146110. if (coef->iMCU_row_num == last_iMCU_row) {
  146111. blocks_across += ndummy; /* include lower right corner */
  146112. MCUs_across = blocks_across / h_samp_factor;
  146113. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146114. block_row++) {
  146115. thisblockrow = buffer[block_row];
  146116. lastblockrow = buffer[block_row-1];
  146117. jzero_far((void FAR *) thisblockrow,
  146118. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146119. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146120. lastDC = lastblockrow[h_samp_factor-1][0];
  146121. for (bi = 0; bi < h_samp_factor; bi++) {
  146122. thisblockrow[bi][0] = lastDC;
  146123. }
  146124. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146125. lastblockrow += h_samp_factor;
  146126. }
  146127. }
  146128. }
  146129. }
  146130. return compress_output(cinfo, input_buf);
  146131. }
  146132. METHODDEF(boolean)
  146133. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146134. {
  146135. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146136. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146137. int blkn, ci, xindex, yindex, yoffset;
  146138. JDIMENSION start_col;
  146139. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146140. JBLOCKROW buffer_ptr;
  146141. jpeg_component_info *compptr;
  146142. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146143. compptr = cinfo->cur_comp_info[ci];
  146144. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146145. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146146. coef->iMCU_row_num * compptr->v_samp_factor,
  146147. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146148. }
  146149. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146150. yoffset++) {
  146151. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146152. MCU_col_num++) {
  146153. blkn = 0; /* index of current DCT block within MCU */
  146154. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146155. compptr = cinfo->cur_comp_info[ci];
  146156. start_col = MCU_col_num * compptr->MCU_width;
  146157. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146158. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146159. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146160. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146161. }
  146162. }
  146163. }
  146164. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146165. coef->MCU_vert_offset = yoffset;
  146166. coef->mcu_ctr = MCU_col_num;
  146167. return FALSE;
  146168. }
  146169. }
  146170. coef->mcu_ctr = 0;
  146171. }
  146172. coef->iMCU_row_num++;
  146173. start_iMCU_row(cinfo);
  146174. return TRUE;
  146175. }
  146176. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146177. GLOBAL(void)
  146178. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146179. {
  146180. my_coef_ptr coef;
  146181. coef = (my_coef_ptr)
  146182. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146183. SIZEOF(my_coef_controller));
  146184. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146185. coef->pub.start_pass = start_pass_coef;
  146186. if (need_full_buffer) {
  146187. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146188. int ci;
  146189. jpeg_component_info *compptr;
  146190. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146191. ci++, compptr++) {
  146192. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146193. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146194. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146195. (long) compptr->h_samp_factor),
  146196. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146197. (long) compptr->v_samp_factor),
  146198. (JDIMENSION) compptr->v_samp_factor);
  146199. }
  146200. #else
  146201. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146202. #endif
  146203. } else {
  146204. JBLOCKROW buffer;
  146205. int i;
  146206. buffer = (JBLOCKROW)
  146207. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146208. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146209. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146210. coef->MCU_buffer[i] = buffer + i;
  146211. }
  146212. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146213. }
  146214. }
  146215. /*** End of inlined file: jccoefct.c ***/
  146216. /*** Start of inlined file: jccolor.c ***/
  146217. #define JPEG_INTERNALS
  146218. typedef struct {
  146219. struct jpeg_color_converter pub; /* public fields */
  146220. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146221. } my_color_converter;
  146222. typedef my_color_converter * my_cconvert_ptr;
  146223. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146224. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146225. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146226. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146227. #define R_Y_OFF 0 /* offset to R => Y section */
  146228. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146229. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146230. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146231. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146232. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146233. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146234. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146235. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146236. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146237. METHODDEF(void)
  146238. rgb_ycc_start (j_compress_ptr cinfo)
  146239. {
  146240. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146241. INT32 * rgb_ycc_tab;
  146242. INT32 i;
  146243. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146244. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146245. (TABLE_SIZE * SIZEOF(INT32)));
  146246. for (i = 0; i <= MAXJSAMPLE; i++) {
  146247. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146248. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146249. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146250. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146251. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146252. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146253. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146254. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146255. }
  146256. }
  146257. METHODDEF(void)
  146258. rgb_ycc_convert (j_compress_ptr cinfo,
  146259. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146260. JDIMENSION output_row, int num_rows)
  146261. {
  146262. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146263. register int r, g, b;
  146264. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146265. register JSAMPROW inptr;
  146266. register JSAMPROW outptr0, outptr1, outptr2;
  146267. register JDIMENSION col;
  146268. JDIMENSION num_cols = cinfo->image_width;
  146269. while (--num_rows >= 0) {
  146270. inptr = *input_buf++;
  146271. outptr0 = output_buf[0][output_row];
  146272. outptr1 = output_buf[1][output_row];
  146273. outptr2 = output_buf[2][output_row];
  146274. output_row++;
  146275. for (col = 0; col < num_cols; col++) {
  146276. r = GETJSAMPLE(inptr[RGB_RED]);
  146277. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146278. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146279. inptr += RGB_PIXELSIZE;
  146280. outptr0[col] = (JSAMPLE)
  146281. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146282. >> SCALEBITS);
  146283. outptr1[col] = (JSAMPLE)
  146284. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146285. >> SCALEBITS);
  146286. outptr2[col] = (JSAMPLE)
  146287. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146288. >> SCALEBITS);
  146289. }
  146290. }
  146291. }
  146292. METHODDEF(void)
  146293. rgb_gray_convert (j_compress_ptr cinfo,
  146294. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146295. JDIMENSION output_row, int num_rows)
  146296. {
  146297. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146298. register int r, g, b;
  146299. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146300. register JSAMPROW inptr;
  146301. register JSAMPROW outptr;
  146302. register JDIMENSION col;
  146303. JDIMENSION num_cols = cinfo->image_width;
  146304. while (--num_rows >= 0) {
  146305. inptr = *input_buf++;
  146306. outptr = output_buf[0][output_row];
  146307. output_row++;
  146308. for (col = 0; col < num_cols; col++) {
  146309. r = GETJSAMPLE(inptr[RGB_RED]);
  146310. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146311. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146312. inptr += RGB_PIXELSIZE;
  146313. outptr[col] = (JSAMPLE)
  146314. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146315. >> SCALEBITS);
  146316. }
  146317. }
  146318. }
  146319. METHODDEF(void)
  146320. cmyk_ycck_convert (j_compress_ptr cinfo,
  146321. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146322. JDIMENSION output_row, int num_rows)
  146323. {
  146324. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146325. register int r, g, b;
  146326. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146327. register JSAMPROW inptr;
  146328. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146329. register JDIMENSION col;
  146330. JDIMENSION num_cols = cinfo->image_width;
  146331. while (--num_rows >= 0) {
  146332. inptr = *input_buf++;
  146333. outptr0 = output_buf[0][output_row];
  146334. outptr1 = output_buf[1][output_row];
  146335. outptr2 = output_buf[2][output_row];
  146336. outptr3 = output_buf[3][output_row];
  146337. output_row++;
  146338. for (col = 0; col < num_cols; col++) {
  146339. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146340. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146341. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146342. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146343. inptr += 4;
  146344. outptr0[col] = (JSAMPLE)
  146345. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146346. >> SCALEBITS);
  146347. outptr1[col] = (JSAMPLE)
  146348. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146349. >> SCALEBITS);
  146350. outptr2[col] = (JSAMPLE)
  146351. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146352. >> SCALEBITS);
  146353. }
  146354. }
  146355. }
  146356. METHODDEF(void)
  146357. grayscale_convert (j_compress_ptr cinfo,
  146358. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146359. JDIMENSION output_row, int num_rows)
  146360. {
  146361. register JSAMPROW inptr;
  146362. register JSAMPROW outptr;
  146363. register JDIMENSION col;
  146364. JDIMENSION num_cols = cinfo->image_width;
  146365. int instride = cinfo->input_components;
  146366. while (--num_rows >= 0) {
  146367. inptr = *input_buf++;
  146368. outptr = output_buf[0][output_row];
  146369. output_row++;
  146370. for (col = 0; col < num_cols; col++) {
  146371. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146372. inptr += instride;
  146373. }
  146374. }
  146375. }
  146376. METHODDEF(void)
  146377. null_convert (j_compress_ptr cinfo,
  146378. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146379. JDIMENSION output_row, int num_rows)
  146380. {
  146381. register JSAMPROW inptr;
  146382. register JSAMPROW outptr;
  146383. register JDIMENSION col;
  146384. register int ci;
  146385. int nc = cinfo->num_components;
  146386. JDIMENSION num_cols = cinfo->image_width;
  146387. while (--num_rows >= 0) {
  146388. for (ci = 0; ci < nc; ci++) {
  146389. inptr = *input_buf;
  146390. outptr = output_buf[ci][output_row];
  146391. for (col = 0; col < num_cols; col++) {
  146392. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146393. inptr += nc;
  146394. }
  146395. }
  146396. input_buf++;
  146397. output_row++;
  146398. }
  146399. }
  146400. METHODDEF(void)
  146401. null_method (j_compress_ptr cinfo)
  146402. {
  146403. }
  146404. GLOBAL(void)
  146405. jinit_color_converter (j_compress_ptr cinfo)
  146406. {
  146407. my_cconvert_ptr cconvert;
  146408. cconvert = (my_cconvert_ptr)
  146409. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146410. SIZEOF(my_color_converter));
  146411. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146412. cconvert->pub.start_pass = null_method;
  146413. switch (cinfo->in_color_space) {
  146414. case JCS_GRAYSCALE:
  146415. if (cinfo->input_components != 1)
  146416. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146417. break;
  146418. case JCS_RGB:
  146419. #if RGB_PIXELSIZE != 3
  146420. if (cinfo->input_components != RGB_PIXELSIZE)
  146421. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146422. break;
  146423. #endif /* else share code with YCbCr */
  146424. case JCS_YCbCr:
  146425. if (cinfo->input_components != 3)
  146426. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146427. break;
  146428. case JCS_CMYK:
  146429. case JCS_YCCK:
  146430. if (cinfo->input_components != 4)
  146431. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146432. break;
  146433. default: /* JCS_UNKNOWN can be anything */
  146434. if (cinfo->input_components < 1)
  146435. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146436. break;
  146437. }
  146438. switch (cinfo->jpeg_color_space) {
  146439. case JCS_GRAYSCALE:
  146440. if (cinfo->num_components != 1)
  146441. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146442. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146443. cconvert->pub.color_convert = grayscale_convert;
  146444. else if (cinfo->in_color_space == JCS_RGB) {
  146445. cconvert->pub.start_pass = rgb_ycc_start;
  146446. cconvert->pub.color_convert = rgb_gray_convert;
  146447. } else if (cinfo->in_color_space == JCS_YCbCr)
  146448. cconvert->pub.color_convert = grayscale_convert;
  146449. else
  146450. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146451. break;
  146452. case JCS_RGB:
  146453. if (cinfo->num_components != 3)
  146454. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146455. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146456. cconvert->pub.color_convert = null_convert;
  146457. else
  146458. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146459. break;
  146460. case JCS_YCbCr:
  146461. if (cinfo->num_components != 3)
  146462. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146463. if (cinfo->in_color_space == JCS_RGB) {
  146464. cconvert->pub.start_pass = rgb_ycc_start;
  146465. cconvert->pub.color_convert = rgb_ycc_convert;
  146466. } else if (cinfo->in_color_space == JCS_YCbCr)
  146467. cconvert->pub.color_convert = null_convert;
  146468. else
  146469. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146470. break;
  146471. case JCS_CMYK:
  146472. if (cinfo->num_components != 4)
  146473. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146474. if (cinfo->in_color_space == JCS_CMYK)
  146475. cconvert->pub.color_convert = null_convert;
  146476. else
  146477. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146478. break;
  146479. case JCS_YCCK:
  146480. if (cinfo->num_components != 4)
  146481. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146482. if (cinfo->in_color_space == JCS_CMYK) {
  146483. cconvert->pub.start_pass = rgb_ycc_start;
  146484. cconvert->pub.color_convert = cmyk_ycck_convert;
  146485. } else if (cinfo->in_color_space == JCS_YCCK)
  146486. cconvert->pub.color_convert = null_convert;
  146487. else
  146488. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146489. break;
  146490. default: /* allow null conversion of JCS_UNKNOWN */
  146491. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146492. cinfo->num_components != cinfo->input_components)
  146493. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146494. cconvert->pub.color_convert = null_convert;
  146495. break;
  146496. }
  146497. }
  146498. /*** End of inlined file: jccolor.c ***/
  146499. #undef FIX
  146500. /*** Start of inlined file: jcdctmgr.c ***/
  146501. #define JPEG_INTERNALS
  146502. /*** Start of inlined file: jdct.h ***/
  146503. #ifndef __jdct_h__
  146504. #define __jdct_h__
  146505. #if BITS_IN_JSAMPLE == 8
  146506. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146507. #else
  146508. typedef INT32 DCTELEM; /* must have 32 bits */
  146509. #endif
  146510. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146511. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146512. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146513. #if BITS_IN_JSAMPLE == 8
  146514. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  146515. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  146516. #else
  146517. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  146518. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  146519. #endif
  146520. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  146521. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  146522. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  146523. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146524. #define jpeg_fdct_islow jFDislow
  146525. #define jpeg_fdct_ifast jFDifast
  146526. #define jpeg_fdct_float jFDfloat
  146527. #define jpeg_idct_islow jRDislow
  146528. #define jpeg_idct_ifast jRDifast
  146529. #define jpeg_idct_float jRDfloat
  146530. #define jpeg_idct_4x4 jRD4x4
  146531. #define jpeg_idct_2x2 jRD2x2
  146532. #define jpeg_idct_1x1 jRD1x1
  146533. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146534. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  146535. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  146536. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  146537. EXTERN(void) jpeg_idct_islow
  146538. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146539. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146540. EXTERN(void) jpeg_idct_ifast
  146541. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146542. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146543. EXTERN(void) jpeg_idct_float
  146544. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146545. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146546. EXTERN(void) jpeg_idct_4x4
  146547. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146548. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146549. EXTERN(void) jpeg_idct_2x2
  146550. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146551. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146552. EXTERN(void) jpeg_idct_1x1
  146553. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  146554. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  146555. #define ONE ((INT32) 1)
  146556. #define CONST_SCALE (ONE << CONST_BITS)
  146557. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  146558. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  146559. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146560. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  146561. #endif
  146562. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  146563. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  146564. #endif
  146565. #ifndef MULTIPLY16C16 /* default definition */
  146566. #define MULTIPLY16C16(var,const) ((var) * (const))
  146567. #endif
  146568. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  146569. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  146570. #endif
  146571. #ifndef MULTIPLY16V16 /* default definition */
  146572. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  146573. #endif
  146574. #endif
  146575. /*** End of inlined file: jdct.h ***/
  146576. /* Private declarations for DCT subsystem */
  146577. typedef struct {
  146578. struct jpeg_forward_dct pub; /* public fields */
  146579. forward_DCT_method_ptr do_dct;
  146580. DCTELEM * divisors[NUM_QUANT_TBLS];
  146581. #ifdef DCT_FLOAT_SUPPORTED
  146582. float_DCT_method_ptr do_float_dct;
  146583. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  146584. #endif
  146585. } my_fdct_controller;
  146586. typedef my_fdct_controller * my_fdct_ptr;
  146587. METHODDEF(void)
  146588. start_pass_fdctmgr (j_compress_ptr cinfo)
  146589. {
  146590. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146591. int ci, qtblno, i;
  146592. jpeg_component_info *compptr;
  146593. JQUANT_TBL * qtbl;
  146594. DCTELEM * dtbl;
  146595. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146596. ci++, compptr++) {
  146597. qtblno = compptr->quant_tbl_no;
  146598. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  146599. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  146600. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  146601. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  146602. switch (cinfo->dct_method) {
  146603. #ifdef DCT_ISLOW_SUPPORTED
  146604. case JDCT_ISLOW:
  146605. if (fdct->divisors[qtblno] == NULL) {
  146606. fdct->divisors[qtblno] = (DCTELEM *)
  146607. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146608. DCTSIZE2 * SIZEOF(DCTELEM));
  146609. }
  146610. dtbl = fdct->divisors[qtblno];
  146611. for (i = 0; i < DCTSIZE2; i++) {
  146612. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  146613. }
  146614. break;
  146615. #endif
  146616. #ifdef DCT_IFAST_SUPPORTED
  146617. case JDCT_IFAST:
  146618. {
  146619. #define CONST_BITS 14
  146620. static const INT16 aanscales[DCTSIZE2] = {
  146621. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146622. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  146623. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  146624. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  146625. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  146626. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  146627. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  146628. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  146629. };
  146630. SHIFT_TEMPS
  146631. if (fdct->divisors[qtblno] == NULL) {
  146632. fdct->divisors[qtblno] = (DCTELEM *)
  146633. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146634. DCTSIZE2 * SIZEOF(DCTELEM));
  146635. }
  146636. dtbl = fdct->divisors[qtblno];
  146637. for (i = 0; i < DCTSIZE2; i++) {
  146638. dtbl[i] = (DCTELEM)
  146639. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  146640. (INT32) aanscales[i]),
  146641. CONST_BITS-3);
  146642. }
  146643. }
  146644. break;
  146645. #endif
  146646. #ifdef DCT_FLOAT_SUPPORTED
  146647. case JDCT_FLOAT:
  146648. {
  146649. FAST_FLOAT * fdtbl;
  146650. int row, col;
  146651. static const double aanscalefactor[DCTSIZE] = {
  146652. 1.0, 1.387039845, 1.306562965, 1.175875602,
  146653. 1.0, 0.785694958, 0.541196100, 0.275899379
  146654. };
  146655. if (fdct->float_divisors[qtblno] == NULL) {
  146656. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  146657. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146658. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  146659. }
  146660. fdtbl = fdct->float_divisors[qtblno];
  146661. i = 0;
  146662. for (row = 0; row < DCTSIZE; row++) {
  146663. for (col = 0; col < DCTSIZE; col++) {
  146664. fdtbl[i] = (FAST_FLOAT)
  146665. (1.0 / (((double) qtbl->quantval[i] *
  146666. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  146667. i++;
  146668. }
  146669. }
  146670. }
  146671. break;
  146672. #endif
  146673. default:
  146674. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146675. break;
  146676. }
  146677. }
  146678. }
  146679. METHODDEF(void)
  146680. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146681. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146682. JDIMENSION start_row, JDIMENSION start_col,
  146683. JDIMENSION num_blocks)
  146684. {
  146685. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146686. forward_DCT_method_ptr do_dct = fdct->do_dct;
  146687. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  146688. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146689. JDIMENSION bi;
  146690. sample_data += start_row; /* fold in the vertical offset once */
  146691. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146692. { register DCTELEM *workspaceptr;
  146693. register JSAMPROW elemptr;
  146694. register int elemr;
  146695. workspaceptr = workspace;
  146696. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146697. elemptr = sample_data[elemr] + start_col;
  146698. #if DCTSIZE == 8 /* unroll the inner loop */
  146699. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146700. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146701. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146702. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146703. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146704. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146705. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146706. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146707. #else
  146708. { register int elemc;
  146709. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146710. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  146711. }
  146712. }
  146713. #endif
  146714. }
  146715. }
  146716. (*do_dct) (workspace);
  146717. { register DCTELEM temp, qval;
  146718. register int i;
  146719. register JCOEFPTR output_ptr = coef_blocks[bi];
  146720. for (i = 0; i < DCTSIZE2; i++) {
  146721. qval = divisors[i];
  146722. temp = workspace[i];
  146723. #ifdef FAST_DIVIDE
  146724. #define DIVIDE_BY(a,b) a /= b
  146725. #else
  146726. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  146727. #endif
  146728. if (temp < 0) {
  146729. temp = -temp;
  146730. temp += qval>>1; /* for rounding */
  146731. DIVIDE_BY(temp, qval);
  146732. temp = -temp;
  146733. } else {
  146734. temp += qval>>1; /* for rounding */
  146735. DIVIDE_BY(temp, qval);
  146736. }
  146737. output_ptr[i] = (JCOEF) temp;
  146738. }
  146739. }
  146740. }
  146741. }
  146742. #ifdef DCT_FLOAT_SUPPORTED
  146743. METHODDEF(void)
  146744. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  146745. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  146746. JDIMENSION start_row, JDIMENSION start_col,
  146747. JDIMENSION num_blocks)
  146748. {
  146749. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  146750. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  146751. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  146752. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  146753. JDIMENSION bi;
  146754. sample_data += start_row; /* fold in the vertical offset once */
  146755. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  146756. { register FAST_FLOAT *workspaceptr;
  146757. register JSAMPROW elemptr;
  146758. register int elemr;
  146759. workspaceptr = workspace;
  146760. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  146761. elemptr = sample_data[elemr] + start_col;
  146762. #if DCTSIZE == 8 /* unroll the inner loop */
  146763. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146764. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146765. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146766. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146767. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146768. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146769. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146770. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146771. #else
  146772. { register int elemc;
  146773. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  146774. *workspaceptr++ = (FAST_FLOAT)
  146775. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  146776. }
  146777. }
  146778. #endif
  146779. }
  146780. }
  146781. (*do_dct) (workspace);
  146782. { register FAST_FLOAT temp;
  146783. register int i;
  146784. register JCOEFPTR output_ptr = coef_blocks[bi];
  146785. for (i = 0; i < DCTSIZE2; i++) {
  146786. temp = workspace[i] * divisors[i];
  146787. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  146788. }
  146789. }
  146790. }
  146791. }
  146792. #endif /* DCT_FLOAT_SUPPORTED */
  146793. GLOBAL(void)
  146794. jinit_forward_dct (j_compress_ptr cinfo)
  146795. {
  146796. my_fdct_ptr fdct;
  146797. int i;
  146798. fdct = (my_fdct_ptr)
  146799. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146800. SIZEOF(my_fdct_controller));
  146801. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  146802. fdct->pub.start_pass = start_pass_fdctmgr;
  146803. switch (cinfo->dct_method) {
  146804. #ifdef DCT_ISLOW_SUPPORTED
  146805. case JDCT_ISLOW:
  146806. fdct->pub.forward_DCT = forward_DCT;
  146807. fdct->do_dct = jpeg_fdct_islow;
  146808. break;
  146809. #endif
  146810. #ifdef DCT_IFAST_SUPPORTED
  146811. case JDCT_IFAST:
  146812. fdct->pub.forward_DCT = forward_DCT;
  146813. fdct->do_dct = jpeg_fdct_ifast;
  146814. break;
  146815. #endif
  146816. #ifdef DCT_FLOAT_SUPPORTED
  146817. case JDCT_FLOAT:
  146818. fdct->pub.forward_DCT = forward_DCT_float;
  146819. fdct->do_float_dct = jpeg_fdct_float;
  146820. break;
  146821. #endif
  146822. default:
  146823. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146824. break;
  146825. }
  146826. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146827. fdct->divisors[i] = NULL;
  146828. #ifdef DCT_FLOAT_SUPPORTED
  146829. fdct->float_divisors[i] = NULL;
  146830. #endif
  146831. }
  146832. }
  146833. /*** End of inlined file: jcdctmgr.c ***/
  146834. #undef CONST_BITS
  146835. /*** Start of inlined file: jchuff.c ***/
  146836. #define JPEG_INTERNALS
  146837. /*** Start of inlined file: jchuff.h ***/
  146838. #ifndef _jchuff_h_
  146839. #define _jchuff_h_
  146840. #if BITS_IN_JSAMPLE == 8
  146841. #define MAX_COEF_BITS 10
  146842. #else
  146843. #define MAX_COEF_BITS 14
  146844. #endif
  146845. typedef struct {
  146846. unsigned int ehufco[256]; /* code for each symbol */
  146847. char ehufsi[256]; /* length of code for each symbol */
  146848. } c_derived_tbl;
  146849. #ifdef NEED_SHORT_EXTERNAL_NAMES
  146850. #define jpeg_make_c_derived_tbl jMkCDerived
  146851. #define jpeg_gen_optimal_table jGenOptTbl
  146852. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  146853. EXTERN(void) jpeg_make_c_derived_tbl
  146854. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  146855. c_derived_tbl ** pdtbl));
  146856. EXTERN(void) jpeg_gen_optimal_table
  146857. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  146858. #endif
  146859. /*** End of inlined file: jchuff.h ***/
  146860. /* Declarations shared with jcphuff.c */
  146861. typedef struct {
  146862. INT32 put_buffer; /* current bit-accumulation buffer */
  146863. int put_bits; /* # of bits now in it */
  146864. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  146865. } savable_state;
  146866. #ifndef NO_STRUCT_ASSIGN
  146867. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  146868. #else
  146869. #if MAX_COMPS_IN_SCAN == 4
  146870. #define ASSIGN_STATE(dest,src) \
  146871. ((dest).put_buffer = (src).put_buffer, \
  146872. (dest).put_bits = (src).put_bits, \
  146873. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  146874. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  146875. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  146876. (dest).last_dc_val[3] = (src).last_dc_val[3])
  146877. #endif
  146878. #endif
  146879. typedef struct {
  146880. struct jpeg_entropy_encoder pub; /* public fields */
  146881. savable_state saved; /* Bit buffer & DC state at start of MCU */
  146882. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  146883. int next_restart_num; /* next restart number to write (0-7) */
  146884. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  146885. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  146886. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  146887. long * dc_count_ptrs[NUM_HUFF_TBLS];
  146888. long * ac_count_ptrs[NUM_HUFF_TBLS];
  146889. #endif
  146890. } huff_entropy_encoder;
  146891. typedef huff_entropy_encoder * huff_entropy_ptr;
  146892. typedef struct {
  146893. JOCTET * next_output_byte; /* => next byte to write in buffer */
  146894. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  146895. savable_state cur; /* Current bit buffer & DC state */
  146896. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  146897. } working_state;
  146898. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  146899. JBLOCKROW *MCU_data));
  146900. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  146901. #ifdef ENTROPY_OPT_SUPPORTED
  146902. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  146903. JBLOCKROW *MCU_data));
  146904. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  146905. #endif
  146906. METHODDEF(void)
  146907. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  146908. {
  146909. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  146910. int ci, dctbl, actbl;
  146911. jpeg_component_info * compptr;
  146912. if (gather_statistics) {
  146913. #ifdef ENTROPY_OPT_SUPPORTED
  146914. entropy->pub.encode_mcu = encode_mcu_gather;
  146915. entropy->pub.finish_pass = finish_pass_gather;
  146916. #else
  146917. ERREXIT(cinfo, JERR_NOT_COMPILED);
  146918. #endif
  146919. } else {
  146920. entropy->pub.encode_mcu = encode_mcu_huff;
  146921. entropy->pub.finish_pass = finish_pass_huff;
  146922. }
  146923. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146924. compptr = cinfo->cur_comp_info[ci];
  146925. dctbl = compptr->dc_tbl_no;
  146926. actbl = compptr->ac_tbl_no;
  146927. if (gather_statistics) {
  146928. #ifdef ENTROPY_OPT_SUPPORTED
  146929. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  146930. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  146931. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  146932. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  146933. if (entropy->dc_count_ptrs[dctbl] == NULL)
  146934. entropy->dc_count_ptrs[dctbl] = (long *)
  146935. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146936. 257 * SIZEOF(long));
  146937. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  146938. if (entropy->ac_count_ptrs[actbl] == NULL)
  146939. entropy->ac_count_ptrs[actbl] = (long *)
  146940. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146941. 257 * SIZEOF(long));
  146942. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  146943. #endif
  146944. } else {
  146945. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  146946. & entropy->dc_derived_tbls[dctbl]);
  146947. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  146948. & entropy->ac_derived_tbls[actbl]);
  146949. }
  146950. entropy->saved.last_dc_val[ci] = 0;
  146951. }
  146952. entropy->saved.put_buffer = 0;
  146953. entropy->saved.put_bits = 0;
  146954. entropy->restarts_to_go = cinfo->restart_interval;
  146955. entropy->next_restart_num = 0;
  146956. }
  146957. GLOBAL(void)
  146958. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  146959. c_derived_tbl ** pdtbl)
  146960. {
  146961. JHUFF_TBL *htbl;
  146962. c_derived_tbl *dtbl;
  146963. int p, i, l, lastp, si, maxsymbol;
  146964. char huffsize[257];
  146965. unsigned int huffcode[257];
  146966. unsigned int code;
  146967. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  146968. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  146969. htbl =
  146970. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  146971. if (htbl == NULL)
  146972. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  146973. if (*pdtbl == NULL)
  146974. *pdtbl = (c_derived_tbl *)
  146975. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146976. SIZEOF(c_derived_tbl));
  146977. dtbl = *pdtbl;
  146978. p = 0;
  146979. for (l = 1; l <= 16; l++) {
  146980. i = (int) htbl->bits[l];
  146981. if (i < 0 || p + i > 256) /* protect against table overrun */
  146982. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  146983. while (i--)
  146984. huffsize[p++] = (char) l;
  146985. }
  146986. huffsize[p] = 0;
  146987. lastp = p;
  146988. code = 0;
  146989. si = huffsize[0];
  146990. p = 0;
  146991. while (huffsize[p]) {
  146992. while (((int) huffsize[p]) == si) {
  146993. huffcode[p++] = code;
  146994. code++;
  146995. }
  146996. if (((INT32) code) >= (((INT32) 1) << si))
  146997. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  146998. code <<= 1;
  146999. si++;
  147000. }
  147001. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147002. maxsymbol = isDC ? 15 : 255;
  147003. for (p = 0; p < lastp; p++) {
  147004. i = htbl->huffval[p];
  147005. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147006. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147007. dtbl->ehufco[i] = huffcode[p];
  147008. dtbl->ehufsi[i] = huffsize[p];
  147009. }
  147010. }
  147011. #define emit_byte(state,val,action) \
  147012. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147013. if (--(state)->free_in_buffer == 0) \
  147014. if (! dump_buffer(state)) \
  147015. { action; } }
  147016. LOCAL(boolean)
  147017. dump_buffer (working_state * state)
  147018. {
  147019. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147020. if (! (*dest->empty_output_buffer) (state->cinfo))
  147021. return FALSE;
  147022. state->next_output_byte = dest->next_output_byte;
  147023. state->free_in_buffer = dest->free_in_buffer;
  147024. return TRUE;
  147025. }
  147026. INLINE
  147027. LOCAL(boolean)
  147028. emit_bits (working_state * state, unsigned int code, int size)
  147029. {
  147030. register INT32 put_buffer = (INT32) code;
  147031. register int put_bits = state->cur.put_bits;
  147032. if (size == 0)
  147033. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147034. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147035. put_bits += size; /* new number of bits in buffer */
  147036. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147037. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147038. while (put_bits >= 8) {
  147039. int c = (int) ((put_buffer >> 16) & 0xFF);
  147040. emit_byte(state, c, return FALSE);
  147041. if (c == 0xFF) { /* need to stuff a zero byte? */
  147042. emit_byte(state, 0, return FALSE);
  147043. }
  147044. put_buffer <<= 8;
  147045. put_bits -= 8;
  147046. }
  147047. state->cur.put_buffer = put_buffer; /* update state variables */
  147048. state->cur.put_bits = put_bits;
  147049. return TRUE;
  147050. }
  147051. LOCAL(boolean)
  147052. flush_bits (working_state * state)
  147053. {
  147054. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147055. return FALSE;
  147056. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147057. state->cur.put_bits = 0;
  147058. return TRUE;
  147059. }
  147060. LOCAL(boolean)
  147061. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147062. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147063. {
  147064. register int temp, temp2;
  147065. register int nbits;
  147066. register int k, r, i;
  147067. temp = temp2 = block[0] - last_dc_val;
  147068. if (temp < 0) {
  147069. temp = -temp; /* temp is abs value of input */
  147070. temp2--;
  147071. }
  147072. nbits = 0;
  147073. while (temp) {
  147074. nbits++;
  147075. temp >>= 1;
  147076. }
  147077. if (nbits > MAX_COEF_BITS+1)
  147078. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147079. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147080. return FALSE;
  147081. if (nbits) /* emit_bits rejects calls with size 0 */
  147082. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147083. return FALSE;
  147084. r = 0; /* r = run length of zeros */
  147085. for (k = 1; k < DCTSIZE2; k++) {
  147086. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147087. r++;
  147088. } else {
  147089. while (r > 15) {
  147090. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147091. return FALSE;
  147092. r -= 16;
  147093. }
  147094. temp2 = temp;
  147095. if (temp < 0) {
  147096. temp = -temp; /* temp is abs value of input */
  147097. temp2--;
  147098. }
  147099. nbits = 1; /* there must be at least one 1 bit */
  147100. while ((temp >>= 1))
  147101. nbits++;
  147102. if (nbits > MAX_COEF_BITS)
  147103. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147104. i = (r << 4) + nbits;
  147105. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147106. return FALSE;
  147107. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147108. return FALSE;
  147109. r = 0;
  147110. }
  147111. }
  147112. if (r > 0)
  147113. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147114. return FALSE;
  147115. return TRUE;
  147116. }
  147117. LOCAL(boolean)
  147118. emit_restart (working_state * state, int restart_num)
  147119. {
  147120. int ci;
  147121. if (! flush_bits(state))
  147122. return FALSE;
  147123. emit_byte(state, 0xFF, return FALSE);
  147124. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147125. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147126. state->cur.last_dc_val[ci] = 0;
  147127. return TRUE;
  147128. }
  147129. METHODDEF(boolean)
  147130. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147131. {
  147132. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147133. working_state state;
  147134. int blkn, ci;
  147135. jpeg_component_info * compptr;
  147136. state.next_output_byte = cinfo->dest->next_output_byte;
  147137. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147138. ASSIGN_STATE(state.cur, entropy->saved);
  147139. state.cinfo = cinfo;
  147140. if (cinfo->restart_interval) {
  147141. if (entropy->restarts_to_go == 0)
  147142. if (! emit_restart(&state, entropy->next_restart_num))
  147143. return FALSE;
  147144. }
  147145. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147146. ci = cinfo->MCU_membership[blkn];
  147147. compptr = cinfo->cur_comp_info[ci];
  147148. if (! encode_one_block(&state,
  147149. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147150. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147151. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147152. return FALSE;
  147153. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147154. }
  147155. cinfo->dest->next_output_byte = state.next_output_byte;
  147156. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147157. ASSIGN_STATE(entropy->saved, state.cur);
  147158. if (cinfo->restart_interval) {
  147159. if (entropy->restarts_to_go == 0) {
  147160. entropy->restarts_to_go = cinfo->restart_interval;
  147161. entropy->next_restart_num++;
  147162. entropy->next_restart_num &= 7;
  147163. }
  147164. entropy->restarts_to_go--;
  147165. }
  147166. return TRUE;
  147167. }
  147168. METHODDEF(void)
  147169. finish_pass_huff (j_compress_ptr cinfo)
  147170. {
  147171. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147172. working_state state;
  147173. state.next_output_byte = cinfo->dest->next_output_byte;
  147174. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147175. ASSIGN_STATE(state.cur, entropy->saved);
  147176. state.cinfo = cinfo;
  147177. if (! flush_bits(&state))
  147178. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147179. cinfo->dest->next_output_byte = state.next_output_byte;
  147180. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147181. ASSIGN_STATE(entropy->saved, state.cur);
  147182. }
  147183. #ifdef ENTROPY_OPT_SUPPORTED
  147184. LOCAL(void)
  147185. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147186. long dc_counts[], long ac_counts[])
  147187. {
  147188. register int temp;
  147189. register int nbits;
  147190. register int k, r;
  147191. temp = block[0] - last_dc_val;
  147192. if (temp < 0)
  147193. temp = -temp;
  147194. nbits = 0;
  147195. while (temp) {
  147196. nbits++;
  147197. temp >>= 1;
  147198. }
  147199. if (nbits > MAX_COEF_BITS+1)
  147200. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147201. dc_counts[nbits]++;
  147202. r = 0; /* r = run length of zeros */
  147203. for (k = 1; k < DCTSIZE2; k++) {
  147204. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147205. r++;
  147206. } else {
  147207. while (r > 15) {
  147208. ac_counts[0xF0]++;
  147209. r -= 16;
  147210. }
  147211. if (temp < 0)
  147212. temp = -temp;
  147213. nbits = 1; /* there must be at least one 1 bit */
  147214. while ((temp >>= 1))
  147215. nbits++;
  147216. if (nbits > MAX_COEF_BITS)
  147217. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147218. ac_counts[(r << 4) + nbits]++;
  147219. r = 0;
  147220. }
  147221. }
  147222. if (r > 0)
  147223. ac_counts[0]++;
  147224. }
  147225. METHODDEF(boolean)
  147226. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147227. {
  147228. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147229. int blkn, ci;
  147230. jpeg_component_info * compptr;
  147231. if (cinfo->restart_interval) {
  147232. if (entropy->restarts_to_go == 0) {
  147233. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147234. entropy->saved.last_dc_val[ci] = 0;
  147235. entropy->restarts_to_go = cinfo->restart_interval;
  147236. }
  147237. entropy->restarts_to_go--;
  147238. }
  147239. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147240. ci = cinfo->MCU_membership[blkn];
  147241. compptr = cinfo->cur_comp_info[ci];
  147242. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147243. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147244. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147245. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147246. }
  147247. return TRUE;
  147248. }
  147249. GLOBAL(void)
  147250. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147251. {
  147252. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147253. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147254. int codesize[257]; /* codesize[k] = code length of symbol k */
  147255. int others[257]; /* next symbol in current branch of tree */
  147256. int c1, c2;
  147257. int p, i, j;
  147258. long v;
  147259. MEMZERO(bits, SIZEOF(bits));
  147260. MEMZERO(codesize, SIZEOF(codesize));
  147261. for (i = 0; i < 257; i++)
  147262. others[i] = -1; /* init links to empty */
  147263. freq[256] = 1; /* make sure 256 has a nonzero count */
  147264. for (;;) {
  147265. c1 = -1;
  147266. v = 1000000000L;
  147267. for (i = 0; i <= 256; i++) {
  147268. if (freq[i] && freq[i] <= v) {
  147269. v = freq[i];
  147270. c1 = i;
  147271. }
  147272. }
  147273. c2 = -1;
  147274. v = 1000000000L;
  147275. for (i = 0; i <= 256; i++) {
  147276. if (freq[i] && freq[i] <= v && i != c1) {
  147277. v = freq[i];
  147278. c2 = i;
  147279. }
  147280. }
  147281. if (c2 < 0)
  147282. break;
  147283. freq[c1] += freq[c2];
  147284. freq[c2] = 0;
  147285. codesize[c1]++;
  147286. while (others[c1] >= 0) {
  147287. c1 = others[c1];
  147288. codesize[c1]++;
  147289. }
  147290. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147291. codesize[c2]++;
  147292. while (others[c2] >= 0) {
  147293. c2 = others[c2];
  147294. codesize[c2]++;
  147295. }
  147296. }
  147297. for (i = 0; i <= 256; i++) {
  147298. if (codesize[i]) {
  147299. if (codesize[i] > MAX_CLEN)
  147300. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147301. bits[codesize[i]]++;
  147302. }
  147303. }
  147304. for (i = MAX_CLEN; i > 16; i--) {
  147305. while (bits[i] > 0) {
  147306. j = i - 2; /* find length of new prefix to be used */
  147307. while (bits[j] == 0)
  147308. j--;
  147309. bits[i] -= 2; /* remove two symbols */
  147310. bits[i-1]++; /* one goes in this length */
  147311. bits[j+1] += 2; /* two new symbols in this length */
  147312. bits[j]--; /* symbol of this length is now a prefix */
  147313. }
  147314. }
  147315. while (bits[i] == 0) /* find largest codelength still in use */
  147316. i--;
  147317. bits[i]--;
  147318. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147319. p = 0;
  147320. for (i = 1; i <= MAX_CLEN; i++) {
  147321. for (j = 0; j <= 255; j++) {
  147322. if (codesize[j] == i) {
  147323. htbl->huffval[p] = (UINT8) j;
  147324. p++;
  147325. }
  147326. }
  147327. }
  147328. htbl->sent_table = FALSE;
  147329. }
  147330. METHODDEF(void)
  147331. finish_pass_gather (j_compress_ptr cinfo)
  147332. {
  147333. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147334. int ci, dctbl, actbl;
  147335. jpeg_component_info * compptr;
  147336. JHUFF_TBL **htblptr;
  147337. boolean did_dc[NUM_HUFF_TBLS];
  147338. boolean did_ac[NUM_HUFF_TBLS];
  147339. MEMZERO(did_dc, SIZEOF(did_dc));
  147340. MEMZERO(did_ac, SIZEOF(did_ac));
  147341. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147342. compptr = cinfo->cur_comp_info[ci];
  147343. dctbl = compptr->dc_tbl_no;
  147344. actbl = compptr->ac_tbl_no;
  147345. if (! did_dc[dctbl]) {
  147346. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147347. if (*htblptr == NULL)
  147348. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147349. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147350. did_dc[dctbl] = TRUE;
  147351. }
  147352. if (! did_ac[actbl]) {
  147353. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147354. if (*htblptr == NULL)
  147355. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147356. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147357. did_ac[actbl] = TRUE;
  147358. }
  147359. }
  147360. }
  147361. #endif /* ENTROPY_OPT_SUPPORTED */
  147362. GLOBAL(void)
  147363. jinit_huff_encoder (j_compress_ptr cinfo)
  147364. {
  147365. huff_entropy_ptr entropy;
  147366. int i;
  147367. entropy = (huff_entropy_ptr)
  147368. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147369. SIZEOF(huff_entropy_encoder));
  147370. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147371. entropy->pub.start_pass = start_pass_huff;
  147372. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147373. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147374. #ifdef ENTROPY_OPT_SUPPORTED
  147375. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147376. #endif
  147377. }
  147378. }
  147379. /*** End of inlined file: jchuff.c ***/
  147380. #undef emit_byte
  147381. /*** Start of inlined file: jcinit.c ***/
  147382. #define JPEG_INTERNALS
  147383. GLOBAL(void)
  147384. jinit_compress_master (j_compress_ptr cinfo)
  147385. {
  147386. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147387. if (! cinfo->raw_data_in) {
  147388. jinit_color_converter(cinfo);
  147389. jinit_downsampler(cinfo);
  147390. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147391. }
  147392. jinit_forward_dct(cinfo);
  147393. if (cinfo->arith_code) {
  147394. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147395. } else {
  147396. if (cinfo->progressive_mode) {
  147397. #ifdef C_PROGRESSIVE_SUPPORTED
  147398. jinit_phuff_encoder(cinfo);
  147399. #else
  147400. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147401. #endif
  147402. } else
  147403. jinit_huff_encoder(cinfo);
  147404. }
  147405. jinit_c_coef_controller(cinfo,
  147406. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147407. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147408. jinit_marker_writer(cinfo);
  147409. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147410. (*cinfo->marker->write_file_header) (cinfo);
  147411. }
  147412. /*** End of inlined file: jcinit.c ***/
  147413. /*** Start of inlined file: jcmainct.c ***/
  147414. #define JPEG_INTERNALS
  147415. #undef FULL_MAIN_BUFFER_SUPPORTED
  147416. typedef struct {
  147417. struct jpeg_c_main_controller pub; /* public fields */
  147418. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147419. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147420. boolean suspended; /* remember if we suspended output */
  147421. J_BUF_MODE pass_mode; /* current operating mode */
  147422. JSAMPARRAY buffer[MAX_COMPONENTS];
  147423. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147424. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147425. #endif
  147426. } my_main_controller;
  147427. typedef my_main_controller * my_main_ptr;
  147428. METHODDEF(void) process_data_simple_main
  147429. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147430. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147431. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147432. METHODDEF(void) process_data_buffer_main
  147433. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147434. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147435. #endif
  147436. METHODDEF(void)
  147437. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147438. {
  147439. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147440. if (cinfo->raw_data_in)
  147441. return;
  147442. main_->cur_iMCU_row = 0; /* initialize counters */
  147443. main_->rowgroup_ctr = 0;
  147444. main_->suspended = FALSE;
  147445. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147446. switch (pass_mode) {
  147447. case JBUF_PASS_THRU:
  147448. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147449. if (main_->whole_image[0] != NULL)
  147450. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147451. #endif
  147452. main_->pub.process_data = process_data_simple_main;
  147453. break;
  147454. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147455. case JBUF_SAVE_SOURCE:
  147456. case JBUF_CRANK_DEST:
  147457. case JBUF_SAVE_AND_PASS:
  147458. if (main_->whole_image[0] == NULL)
  147459. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147460. main_->pub.process_data = process_data_buffer_main;
  147461. break;
  147462. #endif
  147463. default:
  147464. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147465. break;
  147466. }
  147467. }
  147468. METHODDEF(void)
  147469. process_data_simple_main (j_compress_ptr cinfo,
  147470. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147471. JDIMENSION in_rows_avail)
  147472. {
  147473. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147474. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147475. if (main_->rowgroup_ctr < DCTSIZE)
  147476. (*cinfo->prep->pre_process_data) (cinfo,
  147477. input_buf, in_row_ctr, in_rows_avail,
  147478. main_->buffer, &main_->rowgroup_ctr,
  147479. (JDIMENSION) DCTSIZE);
  147480. if (main_->rowgroup_ctr != DCTSIZE)
  147481. return;
  147482. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147483. if (! main_->suspended) {
  147484. (*in_row_ctr)--;
  147485. main_->suspended = TRUE;
  147486. }
  147487. return;
  147488. }
  147489. if (main_->suspended) {
  147490. (*in_row_ctr)++;
  147491. main_->suspended = FALSE;
  147492. }
  147493. main_->rowgroup_ctr = 0;
  147494. main_->cur_iMCU_row++;
  147495. }
  147496. }
  147497. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147498. METHODDEF(void)
  147499. process_data_buffer_main (j_compress_ptr cinfo,
  147500. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147501. JDIMENSION in_rows_avail)
  147502. {
  147503. my_main_ptr main = (my_main_ptr) cinfo->main;
  147504. int ci;
  147505. jpeg_component_info *compptr;
  147506. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147507. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147508. if (main->rowgroup_ctr == 0) {
  147509. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147510. ci++, compptr++) {
  147511. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147512. ((j_common_ptr) cinfo, main->whole_image[ci],
  147513. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  147514. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  147515. }
  147516. if (! writing) {
  147517. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  147518. main->rowgroup_ctr = DCTSIZE;
  147519. }
  147520. }
  147521. if (writing) {
  147522. (*cinfo->prep->pre_process_data) (cinfo,
  147523. input_buf, in_row_ctr, in_rows_avail,
  147524. main->buffer, &main->rowgroup_ctr,
  147525. (JDIMENSION) DCTSIZE);
  147526. if (main->rowgroup_ctr < DCTSIZE)
  147527. return;
  147528. }
  147529. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  147530. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  147531. if (! main->suspended) {
  147532. (*in_row_ctr)--;
  147533. main->suspended = TRUE;
  147534. }
  147535. return;
  147536. }
  147537. if (main->suspended) {
  147538. (*in_row_ctr)++;
  147539. main->suspended = FALSE;
  147540. }
  147541. }
  147542. main->rowgroup_ctr = 0;
  147543. main->cur_iMCU_row++;
  147544. }
  147545. }
  147546. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  147547. GLOBAL(void)
  147548. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  147549. {
  147550. my_main_ptr main_;
  147551. int ci;
  147552. jpeg_component_info *compptr;
  147553. main_ = (my_main_ptr)
  147554. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147555. SIZEOF(my_main_controller));
  147556. cinfo->main = (struct jpeg_c_main_controller *) main_;
  147557. main_->pub.start_pass = start_pass_main;
  147558. if (cinfo->raw_data_in)
  147559. return;
  147560. if (need_full_buffer) {
  147561. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147562. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147563. ci++, compptr++) {
  147564. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  147565. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  147566. compptr->width_in_blocks * DCTSIZE,
  147567. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  147568. (long) compptr->v_samp_factor) * DCTSIZE,
  147569. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147570. }
  147571. #else
  147572. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147573. #endif
  147574. } else {
  147575. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147576. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  147577. #endif
  147578. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147579. ci++, compptr++) {
  147580. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  147581. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147582. compptr->width_in_blocks * DCTSIZE,
  147583. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  147584. }
  147585. }
  147586. }
  147587. /*** End of inlined file: jcmainct.c ***/
  147588. /*** Start of inlined file: jcmarker.c ***/
  147589. #define JPEG_INTERNALS
  147590. typedef struct {
  147591. struct jpeg_marker_writer pub; /* public fields */
  147592. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  147593. } my_marker_writer;
  147594. typedef my_marker_writer * my_marker_ptr;
  147595. LOCAL(void)
  147596. emit_byte (j_compress_ptr cinfo, int val)
  147597. {
  147598. struct jpeg_destination_mgr * dest = cinfo->dest;
  147599. *(dest->next_output_byte)++ = (JOCTET) val;
  147600. if (--dest->free_in_buffer == 0) {
  147601. if (! (*dest->empty_output_buffer) (cinfo))
  147602. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147603. }
  147604. }
  147605. LOCAL(void)
  147606. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  147607. {
  147608. emit_byte(cinfo, 0xFF);
  147609. emit_byte(cinfo, (int) mark);
  147610. }
  147611. LOCAL(void)
  147612. emit_2bytes (j_compress_ptr cinfo, int value)
  147613. {
  147614. emit_byte(cinfo, (value >> 8) & 0xFF);
  147615. emit_byte(cinfo, value & 0xFF);
  147616. }
  147617. LOCAL(int)
  147618. emit_dqt (j_compress_ptr cinfo, int index)
  147619. {
  147620. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  147621. int prec;
  147622. int i;
  147623. if (qtbl == NULL)
  147624. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  147625. prec = 0;
  147626. for (i = 0; i < DCTSIZE2; i++) {
  147627. if (qtbl->quantval[i] > 255)
  147628. prec = 1;
  147629. }
  147630. if (! qtbl->sent_table) {
  147631. emit_marker(cinfo, M_DQT);
  147632. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  147633. emit_byte(cinfo, index + (prec<<4));
  147634. for (i = 0; i < DCTSIZE2; i++) {
  147635. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  147636. if (prec)
  147637. emit_byte(cinfo, (int) (qval >> 8));
  147638. emit_byte(cinfo, (int) (qval & 0xFF));
  147639. }
  147640. qtbl->sent_table = TRUE;
  147641. }
  147642. return prec;
  147643. }
  147644. LOCAL(void)
  147645. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  147646. {
  147647. JHUFF_TBL * htbl;
  147648. int length, i;
  147649. if (is_ac) {
  147650. htbl = cinfo->ac_huff_tbl_ptrs[index];
  147651. index += 0x10; /* output index has AC bit set */
  147652. } else {
  147653. htbl = cinfo->dc_huff_tbl_ptrs[index];
  147654. }
  147655. if (htbl == NULL)
  147656. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  147657. if (! htbl->sent_table) {
  147658. emit_marker(cinfo, M_DHT);
  147659. length = 0;
  147660. for (i = 1; i <= 16; i++)
  147661. length += htbl->bits[i];
  147662. emit_2bytes(cinfo, length + 2 + 1 + 16);
  147663. emit_byte(cinfo, index);
  147664. for (i = 1; i <= 16; i++)
  147665. emit_byte(cinfo, htbl->bits[i]);
  147666. for (i = 0; i < length; i++)
  147667. emit_byte(cinfo, htbl->huffval[i]);
  147668. htbl->sent_table = TRUE;
  147669. }
  147670. }
  147671. LOCAL(void)
  147672. emit_dac (j_compress_ptr cinfo)
  147673. {
  147674. #ifdef C_ARITH_CODING_SUPPORTED
  147675. char dc_in_use[NUM_ARITH_TBLS];
  147676. char ac_in_use[NUM_ARITH_TBLS];
  147677. int length, i;
  147678. jpeg_component_info *compptr;
  147679. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147680. dc_in_use[i] = ac_in_use[i] = 0;
  147681. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147682. compptr = cinfo->cur_comp_info[i];
  147683. dc_in_use[compptr->dc_tbl_no] = 1;
  147684. ac_in_use[compptr->ac_tbl_no] = 1;
  147685. }
  147686. length = 0;
  147687. for (i = 0; i < NUM_ARITH_TBLS; i++)
  147688. length += dc_in_use[i] + ac_in_use[i];
  147689. emit_marker(cinfo, M_DAC);
  147690. emit_2bytes(cinfo, length*2 + 2);
  147691. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  147692. if (dc_in_use[i]) {
  147693. emit_byte(cinfo, i);
  147694. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  147695. }
  147696. if (ac_in_use[i]) {
  147697. emit_byte(cinfo, i + 0x10);
  147698. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  147699. }
  147700. }
  147701. #endif /* C_ARITH_CODING_SUPPORTED */
  147702. }
  147703. LOCAL(void)
  147704. emit_dri (j_compress_ptr cinfo)
  147705. {
  147706. emit_marker(cinfo, M_DRI);
  147707. emit_2bytes(cinfo, 4); /* fixed length */
  147708. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  147709. }
  147710. LOCAL(void)
  147711. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  147712. {
  147713. int ci;
  147714. jpeg_component_info *compptr;
  147715. emit_marker(cinfo, code);
  147716. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  147717. if ((long) cinfo->image_height > 65535L ||
  147718. (long) cinfo->image_width > 65535L)
  147719. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  147720. emit_byte(cinfo, cinfo->data_precision);
  147721. emit_2bytes(cinfo, (int) cinfo->image_height);
  147722. emit_2bytes(cinfo, (int) cinfo->image_width);
  147723. emit_byte(cinfo, cinfo->num_components);
  147724. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147725. ci++, compptr++) {
  147726. emit_byte(cinfo, compptr->component_id);
  147727. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  147728. emit_byte(cinfo, compptr->quant_tbl_no);
  147729. }
  147730. }
  147731. LOCAL(void)
  147732. emit_sos (j_compress_ptr cinfo)
  147733. {
  147734. int i, td, ta;
  147735. jpeg_component_info *compptr;
  147736. emit_marker(cinfo, M_SOS);
  147737. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  147738. emit_byte(cinfo, cinfo->comps_in_scan);
  147739. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147740. compptr = cinfo->cur_comp_info[i];
  147741. emit_byte(cinfo, compptr->component_id);
  147742. td = compptr->dc_tbl_no;
  147743. ta = compptr->ac_tbl_no;
  147744. if (cinfo->progressive_mode) {
  147745. if (cinfo->Ss == 0) {
  147746. ta = 0; /* DC scan */
  147747. if (cinfo->Ah != 0 && !cinfo->arith_code)
  147748. td = 0; /* no DC table either */
  147749. } else {
  147750. td = 0; /* AC scan */
  147751. }
  147752. }
  147753. emit_byte(cinfo, (td << 4) + ta);
  147754. }
  147755. emit_byte(cinfo, cinfo->Ss);
  147756. emit_byte(cinfo, cinfo->Se);
  147757. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  147758. }
  147759. LOCAL(void)
  147760. emit_jfif_app0 (j_compress_ptr cinfo)
  147761. {
  147762. emit_marker(cinfo, M_APP0);
  147763. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  147764. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  147765. emit_byte(cinfo, 0x46);
  147766. emit_byte(cinfo, 0x49);
  147767. emit_byte(cinfo, 0x46);
  147768. emit_byte(cinfo, 0);
  147769. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  147770. emit_byte(cinfo, cinfo->JFIF_minor_version);
  147771. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  147772. emit_2bytes(cinfo, (int) cinfo->X_density);
  147773. emit_2bytes(cinfo, (int) cinfo->Y_density);
  147774. emit_byte(cinfo, 0); /* No thumbnail image */
  147775. emit_byte(cinfo, 0);
  147776. }
  147777. LOCAL(void)
  147778. emit_adobe_app14 (j_compress_ptr cinfo)
  147779. {
  147780. emit_marker(cinfo, M_APP14);
  147781. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  147782. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  147783. emit_byte(cinfo, 0x64);
  147784. emit_byte(cinfo, 0x6F);
  147785. emit_byte(cinfo, 0x62);
  147786. emit_byte(cinfo, 0x65);
  147787. emit_2bytes(cinfo, 100); /* Version */
  147788. emit_2bytes(cinfo, 0); /* Flags0 */
  147789. emit_2bytes(cinfo, 0); /* Flags1 */
  147790. switch (cinfo->jpeg_color_space) {
  147791. case JCS_YCbCr:
  147792. emit_byte(cinfo, 1); /* Color transform = 1 */
  147793. break;
  147794. case JCS_YCCK:
  147795. emit_byte(cinfo, 2); /* Color transform = 2 */
  147796. break;
  147797. default:
  147798. emit_byte(cinfo, 0); /* Color transform = 0 */
  147799. break;
  147800. }
  147801. }
  147802. METHODDEF(void)
  147803. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  147804. {
  147805. if (datalen > (unsigned int) 65533) /* safety check */
  147806. ERREXIT(cinfo, JERR_BAD_LENGTH);
  147807. emit_marker(cinfo, (JPEG_MARKER) marker);
  147808. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  147809. }
  147810. METHODDEF(void)
  147811. write_marker_byte (j_compress_ptr cinfo, int val)
  147812. {
  147813. emit_byte(cinfo, val);
  147814. }
  147815. METHODDEF(void)
  147816. write_file_header (j_compress_ptr cinfo)
  147817. {
  147818. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147819. emit_marker(cinfo, M_SOI); /* first the SOI */
  147820. marker->last_restart_interval = 0;
  147821. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  147822. emit_jfif_app0(cinfo);
  147823. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  147824. emit_adobe_app14(cinfo);
  147825. }
  147826. METHODDEF(void)
  147827. write_frame_header (j_compress_ptr cinfo)
  147828. {
  147829. int ci, prec;
  147830. boolean is_baseline;
  147831. jpeg_component_info *compptr;
  147832. prec = 0;
  147833. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147834. ci++, compptr++) {
  147835. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  147836. }
  147837. if (cinfo->arith_code || cinfo->progressive_mode ||
  147838. cinfo->data_precision != 8) {
  147839. is_baseline = FALSE;
  147840. } else {
  147841. is_baseline = TRUE;
  147842. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147843. ci++, compptr++) {
  147844. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  147845. is_baseline = FALSE;
  147846. }
  147847. if (prec && is_baseline) {
  147848. is_baseline = FALSE;
  147849. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  147850. }
  147851. }
  147852. if (cinfo->arith_code) {
  147853. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  147854. } else {
  147855. if (cinfo->progressive_mode)
  147856. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  147857. else if (is_baseline)
  147858. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  147859. else
  147860. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  147861. }
  147862. }
  147863. METHODDEF(void)
  147864. write_scan_header (j_compress_ptr cinfo)
  147865. {
  147866. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  147867. int i;
  147868. jpeg_component_info *compptr;
  147869. if (cinfo->arith_code) {
  147870. emit_dac(cinfo);
  147871. } else {
  147872. for (i = 0; i < cinfo->comps_in_scan; i++) {
  147873. compptr = cinfo->cur_comp_info[i];
  147874. if (cinfo->progressive_mode) {
  147875. if (cinfo->Ss == 0) {
  147876. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  147877. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147878. } else {
  147879. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147880. }
  147881. } else {
  147882. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  147883. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  147884. }
  147885. }
  147886. }
  147887. if (cinfo->restart_interval != marker->last_restart_interval) {
  147888. emit_dri(cinfo);
  147889. marker->last_restart_interval = cinfo->restart_interval;
  147890. }
  147891. emit_sos(cinfo);
  147892. }
  147893. METHODDEF(void)
  147894. write_file_trailer (j_compress_ptr cinfo)
  147895. {
  147896. emit_marker(cinfo, M_EOI);
  147897. }
  147898. METHODDEF(void)
  147899. write_tables_only (j_compress_ptr cinfo)
  147900. {
  147901. int i;
  147902. emit_marker(cinfo, M_SOI);
  147903. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147904. if (cinfo->quant_tbl_ptrs[i] != NULL)
  147905. (void) emit_dqt(cinfo, i);
  147906. }
  147907. if (! cinfo->arith_code) {
  147908. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147909. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  147910. emit_dht(cinfo, i, FALSE);
  147911. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  147912. emit_dht(cinfo, i, TRUE);
  147913. }
  147914. }
  147915. emit_marker(cinfo, M_EOI);
  147916. }
  147917. GLOBAL(void)
  147918. jinit_marker_writer (j_compress_ptr cinfo)
  147919. {
  147920. my_marker_ptr marker;
  147921. marker = (my_marker_ptr)
  147922. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147923. SIZEOF(my_marker_writer));
  147924. cinfo->marker = (struct jpeg_marker_writer *) marker;
  147925. marker->pub.write_file_header = write_file_header;
  147926. marker->pub.write_frame_header = write_frame_header;
  147927. marker->pub.write_scan_header = write_scan_header;
  147928. marker->pub.write_file_trailer = write_file_trailer;
  147929. marker->pub.write_tables_only = write_tables_only;
  147930. marker->pub.write_marker_header = write_marker_header;
  147931. marker->pub.write_marker_byte = write_marker_byte;
  147932. marker->last_restart_interval = 0;
  147933. }
  147934. /*** End of inlined file: jcmarker.c ***/
  147935. /*** Start of inlined file: jcmaster.c ***/
  147936. #define JPEG_INTERNALS
  147937. typedef enum {
  147938. main_pass, /* input data, also do first output step */
  147939. huff_opt_pass, /* Huffman code optimization pass */
  147940. output_pass /* data output pass */
  147941. } c_pass_type;
  147942. typedef struct {
  147943. struct jpeg_comp_master pub; /* public fields */
  147944. c_pass_type pass_type; /* the type of the current pass */
  147945. int pass_number; /* # of passes completed */
  147946. int total_passes; /* total # of passes needed */
  147947. int scan_number; /* current index in scan_info[] */
  147948. } my_comp_master;
  147949. typedef my_comp_master * my_master_ptr;
  147950. LOCAL(void)
  147951. initial_setup (j_compress_ptr cinfo)
  147952. {
  147953. int ci;
  147954. jpeg_component_info *compptr;
  147955. long samplesperrow;
  147956. JDIMENSION jd_samplesperrow;
  147957. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  147958. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  147959. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  147960. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  147961. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  147962. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  147963. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  147964. jd_samplesperrow = (JDIMENSION) samplesperrow;
  147965. if ((long) jd_samplesperrow != samplesperrow)
  147966. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  147967. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  147968. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  147969. if (cinfo->num_components > MAX_COMPONENTS)
  147970. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  147971. MAX_COMPONENTS);
  147972. cinfo->max_h_samp_factor = 1;
  147973. cinfo->max_v_samp_factor = 1;
  147974. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147975. ci++, compptr++) {
  147976. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  147977. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  147978. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  147979. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  147980. compptr->h_samp_factor);
  147981. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  147982. compptr->v_samp_factor);
  147983. }
  147984. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147985. ci++, compptr++) {
  147986. compptr->component_index = ci;
  147987. compptr->DCT_scaled_size = DCTSIZE;
  147988. compptr->width_in_blocks = (JDIMENSION)
  147989. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  147990. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  147991. compptr->height_in_blocks = (JDIMENSION)
  147992. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  147993. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  147994. compptr->downsampled_width = (JDIMENSION)
  147995. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  147996. (long) cinfo->max_h_samp_factor);
  147997. compptr->downsampled_height = (JDIMENSION)
  147998. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  147999. (long) cinfo->max_v_samp_factor);
  148000. compptr->component_needed = TRUE;
  148001. }
  148002. cinfo->total_iMCU_rows = (JDIMENSION)
  148003. jdiv_round_up((long) cinfo->image_height,
  148004. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148005. }
  148006. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148007. LOCAL(void)
  148008. validate_script (j_compress_ptr cinfo)
  148009. {
  148010. const jpeg_scan_info * scanptr;
  148011. int scanno, ncomps, ci, coefi, thisi;
  148012. int Ss, Se, Ah, Al;
  148013. boolean component_sent[MAX_COMPONENTS];
  148014. #ifdef C_PROGRESSIVE_SUPPORTED
  148015. int * last_bitpos_ptr;
  148016. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148017. #endif
  148018. if (cinfo->num_scans <= 0)
  148019. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148020. scanptr = cinfo->scan_info;
  148021. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148022. #ifdef C_PROGRESSIVE_SUPPORTED
  148023. cinfo->progressive_mode = TRUE;
  148024. last_bitpos_ptr = & last_bitpos[0][0];
  148025. for (ci = 0; ci < cinfo->num_components; ci++)
  148026. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148027. *last_bitpos_ptr++ = -1;
  148028. #else
  148029. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148030. #endif
  148031. } else {
  148032. cinfo->progressive_mode = FALSE;
  148033. for (ci = 0; ci < cinfo->num_components; ci++)
  148034. component_sent[ci] = FALSE;
  148035. }
  148036. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148037. ncomps = scanptr->comps_in_scan;
  148038. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148039. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148040. for (ci = 0; ci < ncomps; ci++) {
  148041. thisi = scanptr->component_index[ci];
  148042. if (thisi < 0 || thisi >= cinfo->num_components)
  148043. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148044. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148045. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148046. }
  148047. Ss = scanptr->Ss;
  148048. Se = scanptr->Se;
  148049. Ah = scanptr->Ah;
  148050. Al = scanptr->Al;
  148051. if (cinfo->progressive_mode) {
  148052. #ifdef C_PROGRESSIVE_SUPPORTED
  148053. #if BITS_IN_JSAMPLE == 8
  148054. #define MAX_AH_AL 10
  148055. #else
  148056. #define MAX_AH_AL 13
  148057. #endif
  148058. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148059. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148060. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148061. if (Ss == 0) {
  148062. if (Se != 0) /* DC and AC together not OK */
  148063. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148064. } else {
  148065. if (ncomps != 1) /* AC scans must be for only one component */
  148066. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148067. }
  148068. for (ci = 0; ci < ncomps; ci++) {
  148069. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148070. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148071. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148072. for (coefi = Ss; coefi <= Se; coefi++) {
  148073. if (last_bitpos_ptr[coefi] < 0) {
  148074. if (Ah != 0)
  148075. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148076. } else {
  148077. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148078. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148079. }
  148080. last_bitpos_ptr[coefi] = Al;
  148081. }
  148082. }
  148083. #endif
  148084. } else {
  148085. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148086. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148087. for (ci = 0; ci < ncomps; ci++) {
  148088. thisi = scanptr->component_index[ci];
  148089. if (component_sent[thisi])
  148090. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148091. component_sent[thisi] = TRUE;
  148092. }
  148093. }
  148094. }
  148095. if (cinfo->progressive_mode) {
  148096. #ifdef C_PROGRESSIVE_SUPPORTED
  148097. for (ci = 0; ci < cinfo->num_components; ci++) {
  148098. if (last_bitpos[ci][0] < 0)
  148099. ERREXIT(cinfo, JERR_MISSING_DATA);
  148100. }
  148101. #endif
  148102. } else {
  148103. for (ci = 0; ci < cinfo->num_components; ci++) {
  148104. if (! component_sent[ci])
  148105. ERREXIT(cinfo, JERR_MISSING_DATA);
  148106. }
  148107. }
  148108. }
  148109. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148110. LOCAL(void)
  148111. select_scan_parameters (j_compress_ptr cinfo)
  148112. {
  148113. int ci;
  148114. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148115. if (cinfo->scan_info != NULL) {
  148116. my_master_ptr master = (my_master_ptr) cinfo->master;
  148117. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148118. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148119. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148120. cinfo->cur_comp_info[ci] =
  148121. &cinfo->comp_info[scanptr->component_index[ci]];
  148122. }
  148123. cinfo->Ss = scanptr->Ss;
  148124. cinfo->Se = scanptr->Se;
  148125. cinfo->Ah = scanptr->Ah;
  148126. cinfo->Al = scanptr->Al;
  148127. }
  148128. else
  148129. #endif
  148130. {
  148131. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148132. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148133. MAX_COMPS_IN_SCAN);
  148134. cinfo->comps_in_scan = cinfo->num_components;
  148135. for (ci = 0; ci < cinfo->num_components; ci++) {
  148136. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148137. }
  148138. cinfo->Ss = 0;
  148139. cinfo->Se = DCTSIZE2-1;
  148140. cinfo->Ah = 0;
  148141. cinfo->Al = 0;
  148142. }
  148143. }
  148144. LOCAL(void)
  148145. per_scan_setup (j_compress_ptr cinfo)
  148146. {
  148147. int ci, mcublks, tmp;
  148148. jpeg_component_info *compptr;
  148149. if (cinfo->comps_in_scan == 1) {
  148150. compptr = cinfo->cur_comp_info[0];
  148151. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148152. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148153. compptr->MCU_width = 1;
  148154. compptr->MCU_height = 1;
  148155. compptr->MCU_blocks = 1;
  148156. compptr->MCU_sample_width = DCTSIZE;
  148157. compptr->last_col_width = 1;
  148158. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148159. if (tmp == 0) tmp = compptr->v_samp_factor;
  148160. compptr->last_row_height = tmp;
  148161. cinfo->blocks_in_MCU = 1;
  148162. cinfo->MCU_membership[0] = 0;
  148163. } else {
  148164. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148165. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148166. MAX_COMPS_IN_SCAN);
  148167. cinfo->MCUs_per_row = (JDIMENSION)
  148168. jdiv_round_up((long) cinfo->image_width,
  148169. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148170. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148171. jdiv_round_up((long) cinfo->image_height,
  148172. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148173. cinfo->blocks_in_MCU = 0;
  148174. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148175. compptr = cinfo->cur_comp_info[ci];
  148176. compptr->MCU_width = compptr->h_samp_factor;
  148177. compptr->MCU_height = compptr->v_samp_factor;
  148178. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148179. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148180. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148181. if (tmp == 0) tmp = compptr->MCU_width;
  148182. compptr->last_col_width = tmp;
  148183. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148184. if (tmp == 0) tmp = compptr->MCU_height;
  148185. compptr->last_row_height = tmp;
  148186. mcublks = compptr->MCU_blocks;
  148187. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148188. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148189. while (mcublks-- > 0) {
  148190. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148191. }
  148192. }
  148193. }
  148194. if (cinfo->restart_in_rows > 0) {
  148195. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148196. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148197. }
  148198. }
  148199. METHODDEF(void)
  148200. prepare_for_pass (j_compress_ptr cinfo)
  148201. {
  148202. my_master_ptr master = (my_master_ptr) cinfo->master;
  148203. switch (master->pass_type) {
  148204. case main_pass:
  148205. select_scan_parameters(cinfo);
  148206. per_scan_setup(cinfo);
  148207. if (! cinfo->raw_data_in) {
  148208. (*cinfo->cconvert->start_pass) (cinfo);
  148209. (*cinfo->downsample->start_pass) (cinfo);
  148210. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148211. }
  148212. (*cinfo->fdct->start_pass) (cinfo);
  148213. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148214. (*cinfo->coef->start_pass) (cinfo,
  148215. (master->total_passes > 1 ?
  148216. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148217. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148218. if (cinfo->optimize_coding) {
  148219. master->pub.call_pass_startup = FALSE;
  148220. } else {
  148221. master->pub.call_pass_startup = TRUE;
  148222. }
  148223. break;
  148224. #ifdef ENTROPY_OPT_SUPPORTED
  148225. case huff_opt_pass:
  148226. select_scan_parameters(cinfo);
  148227. per_scan_setup(cinfo);
  148228. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148229. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148230. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148231. master->pub.call_pass_startup = FALSE;
  148232. break;
  148233. }
  148234. master->pass_type = output_pass;
  148235. master->pass_number++;
  148236. #endif
  148237. case output_pass:
  148238. if (! cinfo->optimize_coding) {
  148239. select_scan_parameters(cinfo);
  148240. per_scan_setup(cinfo);
  148241. }
  148242. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148243. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148244. if (master->scan_number == 0)
  148245. (*cinfo->marker->write_frame_header) (cinfo);
  148246. (*cinfo->marker->write_scan_header) (cinfo);
  148247. master->pub.call_pass_startup = FALSE;
  148248. break;
  148249. default:
  148250. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148251. }
  148252. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148253. if (cinfo->progress != NULL) {
  148254. cinfo->progress->completed_passes = master->pass_number;
  148255. cinfo->progress->total_passes = master->total_passes;
  148256. }
  148257. }
  148258. METHODDEF(void)
  148259. pass_startup (j_compress_ptr cinfo)
  148260. {
  148261. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148262. (*cinfo->marker->write_frame_header) (cinfo);
  148263. (*cinfo->marker->write_scan_header) (cinfo);
  148264. }
  148265. METHODDEF(void)
  148266. finish_pass_master (j_compress_ptr cinfo)
  148267. {
  148268. my_master_ptr master = (my_master_ptr) cinfo->master;
  148269. (*cinfo->entropy->finish_pass) (cinfo);
  148270. switch (master->pass_type) {
  148271. case main_pass:
  148272. master->pass_type = output_pass;
  148273. if (! cinfo->optimize_coding)
  148274. master->scan_number++;
  148275. break;
  148276. case huff_opt_pass:
  148277. master->pass_type = output_pass;
  148278. break;
  148279. case output_pass:
  148280. if (cinfo->optimize_coding)
  148281. master->pass_type = huff_opt_pass;
  148282. master->scan_number++;
  148283. break;
  148284. }
  148285. master->pass_number++;
  148286. }
  148287. GLOBAL(void)
  148288. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148289. {
  148290. my_master_ptr master;
  148291. master = (my_master_ptr)
  148292. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148293. SIZEOF(my_comp_master));
  148294. cinfo->master = (struct jpeg_comp_master *) master;
  148295. master->pub.prepare_for_pass = prepare_for_pass;
  148296. master->pub.pass_startup = pass_startup;
  148297. master->pub.finish_pass = finish_pass_master;
  148298. master->pub.is_last_pass = FALSE;
  148299. initial_setup(cinfo);
  148300. if (cinfo->scan_info != NULL) {
  148301. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148302. validate_script(cinfo);
  148303. #else
  148304. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148305. #endif
  148306. } else {
  148307. cinfo->progressive_mode = FALSE;
  148308. cinfo->num_scans = 1;
  148309. }
  148310. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148311. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148312. if (transcode_only) {
  148313. if (cinfo->optimize_coding)
  148314. master->pass_type = huff_opt_pass;
  148315. else
  148316. master->pass_type = output_pass;
  148317. } else {
  148318. master->pass_type = main_pass;
  148319. }
  148320. master->scan_number = 0;
  148321. master->pass_number = 0;
  148322. if (cinfo->optimize_coding)
  148323. master->total_passes = cinfo->num_scans * 2;
  148324. else
  148325. master->total_passes = cinfo->num_scans;
  148326. }
  148327. /*** End of inlined file: jcmaster.c ***/
  148328. /*** Start of inlined file: jcomapi.c ***/
  148329. #define JPEG_INTERNALS
  148330. GLOBAL(void)
  148331. jpeg_abort (j_common_ptr cinfo)
  148332. {
  148333. int pool;
  148334. if (cinfo->mem == NULL)
  148335. return;
  148336. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148337. (*cinfo->mem->free_pool) (cinfo, pool);
  148338. }
  148339. if (cinfo->is_decompressor) {
  148340. cinfo->global_state = DSTATE_START;
  148341. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148342. } else {
  148343. cinfo->global_state = CSTATE_START;
  148344. }
  148345. }
  148346. GLOBAL(void)
  148347. jpeg_destroy (j_common_ptr cinfo)
  148348. {
  148349. if (cinfo->mem != NULL)
  148350. (*cinfo->mem->self_destruct) (cinfo);
  148351. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148352. cinfo->global_state = 0; /* mark it destroyed */
  148353. }
  148354. GLOBAL(JQUANT_TBL *)
  148355. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148356. {
  148357. JQUANT_TBL *tbl;
  148358. tbl = (JQUANT_TBL *)
  148359. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148360. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148361. return tbl;
  148362. }
  148363. GLOBAL(JHUFF_TBL *)
  148364. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148365. {
  148366. JHUFF_TBL *tbl;
  148367. tbl = (JHUFF_TBL *)
  148368. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148369. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148370. return tbl;
  148371. }
  148372. /*** End of inlined file: jcomapi.c ***/
  148373. /*** Start of inlined file: jcparam.c ***/
  148374. #define JPEG_INTERNALS
  148375. GLOBAL(void)
  148376. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148377. const unsigned int *basic_table,
  148378. int scale_factor, boolean force_baseline)
  148379. {
  148380. JQUANT_TBL ** qtblptr;
  148381. int i;
  148382. long temp;
  148383. if (cinfo->global_state != CSTATE_START)
  148384. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148385. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148386. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148387. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148388. if (*qtblptr == NULL)
  148389. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148390. for (i = 0; i < DCTSIZE2; i++) {
  148391. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148392. if (temp <= 0L) temp = 1L;
  148393. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148394. if (force_baseline && temp > 255L)
  148395. temp = 255L; /* limit to baseline range if requested */
  148396. (*qtblptr)->quantval[i] = (UINT16) temp;
  148397. }
  148398. (*qtblptr)->sent_table = FALSE;
  148399. }
  148400. GLOBAL(void)
  148401. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148402. boolean force_baseline)
  148403. {
  148404. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148405. 16, 11, 10, 16, 24, 40, 51, 61,
  148406. 12, 12, 14, 19, 26, 58, 60, 55,
  148407. 14, 13, 16, 24, 40, 57, 69, 56,
  148408. 14, 17, 22, 29, 51, 87, 80, 62,
  148409. 18, 22, 37, 56, 68, 109, 103, 77,
  148410. 24, 35, 55, 64, 81, 104, 113, 92,
  148411. 49, 64, 78, 87, 103, 121, 120, 101,
  148412. 72, 92, 95, 98, 112, 100, 103, 99
  148413. };
  148414. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148415. 17, 18, 24, 47, 99, 99, 99, 99,
  148416. 18, 21, 26, 66, 99, 99, 99, 99,
  148417. 24, 26, 56, 99, 99, 99, 99, 99,
  148418. 47, 66, 99, 99, 99, 99, 99, 99,
  148419. 99, 99, 99, 99, 99, 99, 99, 99,
  148420. 99, 99, 99, 99, 99, 99, 99, 99,
  148421. 99, 99, 99, 99, 99, 99, 99, 99,
  148422. 99, 99, 99, 99, 99, 99, 99, 99
  148423. };
  148424. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148425. scale_factor, force_baseline);
  148426. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148427. scale_factor, force_baseline);
  148428. }
  148429. GLOBAL(int)
  148430. jpeg_quality_scaling (int quality)
  148431. {
  148432. if (quality <= 0) quality = 1;
  148433. if (quality > 100) quality = 100;
  148434. if (quality < 50)
  148435. quality = 5000 / quality;
  148436. else
  148437. quality = 200 - quality*2;
  148438. return quality;
  148439. }
  148440. GLOBAL(void)
  148441. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148442. {
  148443. quality = jpeg_quality_scaling(quality);
  148444. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148445. }
  148446. LOCAL(void)
  148447. add_huff_table (j_compress_ptr cinfo,
  148448. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148449. {
  148450. int nsymbols, len;
  148451. if (*htblptr == NULL)
  148452. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148453. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148454. nsymbols = 0;
  148455. for (len = 1; len <= 16; len++)
  148456. nsymbols += bits[len];
  148457. if (nsymbols < 1 || nsymbols > 256)
  148458. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148459. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148460. (*htblptr)->sent_table = FALSE;
  148461. }
  148462. LOCAL(void)
  148463. std_huff_tables (j_compress_ptr cinfo)
  148464. {
  148465. static const UINT8 bits_dc_luminance[17] =
  148466. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148467. static const UINT8 val_dc_luminance[] =
  148468. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148469. static const UINT8 bits_dc_chrominance[17] =
  148470. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148471. static const UINT8 val_dc_chrominance[] =
  148472. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148473. static const UINT8 bits_ac_luminance[17] =
  148474. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148475. static const UINT8 val_ac_luminance[] =
  148476. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148477. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148478. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148479. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148480. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148481. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148482. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148483. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148484. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148485. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148486. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148487. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148488. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148489. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148490. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148491. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148492. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148493. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148494. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148495. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148496. 0xf9, 0xfa };
  148497. static const UINT8 bits_ac_chrominance[17] =
  148498. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148499. static const UINT8 val_ac_chrominance[] =
  148500. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148501. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148502. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148503. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148504. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148505. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148506. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148507. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148508. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148509. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148510. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148511. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148512. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148513. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  148514. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  148515. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  148516. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  148517. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  148518. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  148519. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148520. 0xf9, 0xfa };
  148521. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  148522. bits_dc_luminance, val_dc_luminance);
  148523. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  148524. bits_ac_luminance, val_ac_luminance);
  148525. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  148526. bits_dc_chrominance, val_dc_chrominance);
  148527. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  148528. bits_ac_chrominance, val_ac_chrominance);
  148529. }
  148530. GLOBAL(void)
  148531. jpeg_set_defaults (j_compress_ptr cinfo)
  148532. {
  148533. int i;
  148534. if (cinfo->global_state != CSTATE_START)
  148535. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148536. if (cinfo->comp_info == NULL)
  148537. cinfo->comp_info = (jpeg_component_info *)
  148538. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148539. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  148540. cinfo->data_precision = BITS_IN_JSAMPLE;
  148541. jpeg_set_quality(cinfo, 75, TRUE);
  148542. std_huff_tables(cinfo);
  148543. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148544. cinfo->arith_dc_L[i] = 0;
  148545. cinfo->arith_dc_U[i] = 1;
  148546. cinfo->arith_ac_K[i] = 5;
  148547. }
  148548. cinfo->scan_info = NULL;
  148549. cinfo->num_scans = 0;
  148550. cinfo->raw_data_in = FALSE;
  148551. cinfo->arith_code = FALSE;
  148552. cinfo->optimize_coding = FALSE;
  148553. if (cinfo->data_precision > 8)
  148554. cinfo->optimize_coding = TRUE;
  148555. cinfo->CCIR601_sampling = FALSE;
  148556. cinfo->smoothing_factor = 0;
  148557. cinfo->dct_method = JDCT_DEFAULT;
  148558. cinfo->restart_interval = 0;
  148559. cinfo->restart_in_rows = 0;
  148560. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  148561. cinfo->JFIF_minor_version = 1;
  148562. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  148563. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  148564. cinfo->Y_density = 1;
  148565. jpeg_default_colorspace(cinfo);
  148566. }
  148567. GLOBAL(void)
  148568. jpeg_default_colorspace (j_compress_ptr cinfo)
  148569. {
  148570. switch (cinfo->in_color_space) {
  148571. case JCS_GRAYSCALE:
  148572. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  148573. break;
  148574. case JCS_RGB:
  148575. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148576. break;
  148577. case JCS_YCbCr:
  148578. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  148579. break;
  148580. case JCS_CMYK:
  148581. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  148582. break;
  148583. case JCS_YCCK:
  148584. jpeg_set_colorspace(cinfo, JCS_YCCK);
  148585. break;
  148586. case JCS_UNKNOWN:
  148587. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  148588. break;
  148589. default:
  148590. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  148591. }
  148592. }
  148593. GLOBAL(void)
  148594. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  148595. {
  148596. jpeg_component_info * compptr;
  148597. int ci;
  148598. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  148599. (compptr = &cinfo->comp_info[index], \
  148600. compptr->component_id = (id), \
  148601. compptr->h_samp_factor = (hsamp), \
  148602. compptr->v_samp_factor = (vsamp), \
  148603. compptr->quant_tbl_no = (quant), \
  148604. compptr->dc_tbl_no = (dctbl), \
  148605. compptr->ac_tbl_no = (actbl) )
  148606. if (cinfo->global_state != CSTATE_START)
  148607. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148608. cinfo->jpeg_color_space = colorspace;
  148609. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  148610. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  148611. switch (colorspace) {
  148612. case JCS_GRAYSCALE:
  148613. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148614. cinfo->num_components = 1;
  148615. SET_COMP(0, 1, 1,1, 0, 0,0);
  148616. break;
  148617. case JCS_RGB:
  148618. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  148619. cinfo->num_components = 3;
  148620. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  148621. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  148622. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  148623. break;
  148624. case JCS_YCbCr:
  148625. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  148626. cinfo->num_components = 3;
  148627. SET_COMP(0, 1, 2,2, 0, 0,0);
  148628. SET_COMP(1, 2, 1,1, 1, 1,1);
  148629. SET_COMP(2, 3, 1,1, 1, 1,1);
  148630. break;
  148631. case JCS_CMYK:
  148632. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  148633. cinfo->num_components = 4;
  148634. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  148635. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  148636. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  148637. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  148638. break;
  148639. case JCS_YCCK:
  148640. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  148641. cinfo->num_components = 4;
  148642. SET_COMP(0, 1, 2,2, 0, 0,0);
  148643. SET_COMP(1, 2, 1,1, 1, 1,1);
  148644. SET_COMP(2, 3, 1,1, 1, 1,1);
  148645. SET_COMP(3, 4, 2,2, 0, 0,0);
  148646. break;
  148647. case JCS_UNKNOWN:
  148648. cinfo->num_components = cinfo->input_components;
  148649. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  148650. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148651. MAX_COMPONENTS);
  148652. for (ci = 0; ci < cinfo->num_components; ci++) {
  148653. SET_COMP(ci, ci, 1,1, 0, 0,0);
  148654. }
  148655. break;
  148656. default:
  148657. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  148658. }
  148659. }
  148660. #ifdef C_PROGRESSIVE_SUPPORTED
  148661. LOCAL(jpeg_scan_info *)
  148662. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  148663. int Ss, int Se, int Ah, int Al)
  148664. {
  148665. scanptr->comps_in_scan = 1;
  148666. scanptr->component_index[0] = ci;
  148667. scanptr->Ss = Ss;
  148668. scanptr->Se = Se;
  148669. scanptr->Ah = Ah;
  148670. scanptr->Al = Al;
  148671. scanptr++;
  148672. return scanptr;
  148673. }
  148674. LOCAL(jpeg_scan_info *)
  148675. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  148676. int Ss, int Se, int Ah, int Al)
  148677. {
  148678. int ci;
  148679. for (ci = 0; ci < ncomps; ci++) {
  148680. scanptr->comps_in_scan = 1;
  148681. scanptr->component_index[0] = ci;
  148682. scanptr->Ss = Ss;
  148683. scanptr->Se = Se;
  148684. scanptr->Ah = Ah;
  148685. scanptr->Al = Al;
  148686. scanptr++;
  148687. }
  148688. return scanptr;
  148689. }
  148690. LOCAL(jpeg_scan_info *)
  148691. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  148692. {
  148693. int ci;
  148694. if (ncomps <= MAX_COMPS_IN_SCAN) {
  148695. scanptr->comps_in_scan = ncomps;
  148696. for (ci = 0; ci < ncomps; ci++)
  148697. scanptr->component_index[ci] = ci;
  148698. scanptr->Ss = scanptr->Se = 0;
  148699. scanptr->Ah = Ah;
  148700. scanptr->Al = Al;
  148701. scanptr++;
  148702. } else {
  148703. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  148704. }
  148705. return scanptr;
  148706. }
  148707. GLOBAL(void)
  148708. jpeg_simple_progression (j_compress_ptr cinfo)
  148709. {
  148710. int ncomps = cinfo->num_components;
  148711. int nscans;
  148712. jpeg_scan_info * scanptr;
  148713. if (cinfo->global_state != CSTATE_START)
  148714. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148715. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148716. nscans = 10;
  148717. } else {
  148718. if (ncomps > MAX_COMPS_IN_SCAN)
  148719. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  148720. else
  148721. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  148722. }
  148723. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  148724. cinfo->script_space_size = MAX(nscans, 10);
  148725. cinfo->script_space = (jpeg_scan_info *)
  148726. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  148727. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  148728. }
  148729. scanptr = cinfo->script_space;
  148730. cinfo->scan_info = scanptr;
  148731. cinfo->num_scans = nscans;
  148732. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  148733. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148734. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  148735. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  148736. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  148737. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  148738. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  148739. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148740. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  148741. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  148742. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  148743. } else {
  148744. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  148745. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  148746. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  148747. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  148748. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  148749. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  148750. }
  148751. }
  148752. #endif /* C_PROGRESSIVE_SUPPORTED */
  148753. /*** End of inlined file: jcparam.c ***/
  148754. /*** Start of inlined file: jcphuff.c ***/
  148755. #define JPEG_INTERNALS
  148756. #ifdef C_PROGRESSIVE_SUPPORTED
  148757. typedef struct {
  148758. struct jpeg_entropy_encoder pub; /* public fields */
  148759. boolean gather_statistics;
  148760. JOCTET * next_output_byte; /* => next byte to write in buffer */
  148761. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  148762. INT32 put_buffer; /* current bit-accumulation buffer */
  148763. int put_bits; /* # of bits now in it */
  148764. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  148765. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  148766. int ac_tbl_no; /* the table number of the single component */
  148767. unsigned int EOBRUN; /* run length of EOBs */
  148768. unsigned int BE; /* # of buffered correction bits before MCU */
  148769. char * bit_buffer; /* buffer for correction bits (1 per char) */
  148770. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  148771. int next_restart_num; /* next restart number to write (0-7) */
  148772. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  148773. long * count_ptrs[NUM_HUFF_TBLS];
  148774. } phuff_entropy_encoder;
  148775. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  148776. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  148777. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  148778. #define ISHIFT_TEMPS int ishift_temp;
  148779. #define IRIGHT_SHIFT(x,shft) \
  148780. ((ishift_temp = (x)) < 0 ? \
  148781. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  148782. (ishift_temp >> (shft)))
  148783. #else
  148784. #define ISHIFT_TEMPS
  148785. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  148786. #endif
  148787. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  148788. JBLOCKROW *MCU_data));
  148789. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  148790. JBLOCKROW *MCU_data));
  148791. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  148792. JBLOCKROW *MCU_data));
  148793. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  148794. JBLOCKROW *MCU_data));
  148795. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  148796. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  148797. METHODDEF(void)
  148798. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  148799. {
  148800. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148801. boolean is_DC_band;
  148802. int ci, tbl;
  148803. jpeg_component_info * compptr;
  148804. entropy->cinfo = cinfo;
  148805. entropy->gather_statistics = gather_statistics;
  148806. is_DC_band = (cinfo->Ss == 0);
  148807. if (cinfo->Ah == 0) {
  148808. if (is_DC_band)
  148809. entropy->pub.encode_mcu = encode_mcu_DC_first;
  148810. else
  148811. entropy->pub.encode_mcu = encode_mcu_AC_first;
  148812. } else {
  148813. if (is_DC_band)
  148814. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  148815. else {
  148816. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  148817. if (entropy->bit_buffer == NULL)
  148818. entropy->bit_buffer = (char *)
  148819. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148820. MAX_CORR_BITS * SIZEOF(char));
  148821. }
  148822. }
  148823. if (gather_statistics)
  148824. entropy->pub.finish_pass = finish_pass_gather_phuff;
  148825. else
  148826. entropy->pub.finish_pass = finish_pass_phuff;
  148827. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148828. compptr = cinfo->cur_comp_info[ci];
  148829. entropy->last_dc_val[ci] = 0;
  148830. if (is_DC_band) {
  148831. if (cinfo->Ah != 0) /* DC refinement needs no table */
  148832. continue;
  148833. tbl = compptr->dc_tbl_no;
  148834. } else {
  148835. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  148836. }
  148837. if (gather_statistics) {
  148838. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  148839. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  148840. if (entropy->count_ptrs[tbl] == NULL)
  148841. entropy->count_ptrs[tbl] = (long *)
  148842. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148843. 257 * SIZEOF(long));
  148844. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  148845. } else {
  148846. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  148847. & entropy->derived_tbls[tbl]);
  148848. }
  148849. }
  148850. entropy->EOBRUN = 0;
  148851. entropy->BE = 0;
  148852. entropy->put_buffer = 0;
  148853. entropy->put_bits = 0;
  148854. entropy->restarts_to_go = cinfo->restart_interval;
  148855. entropy->next_restart_num = 0;
  148856. }
  148857. #define emit_byte(entropy,val) \
  148858. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  148859. if (--(entropy)->free_in_buffer == 0) \
  148860. dump_buffer_p(entropy); }
  148861. LOCAL(void)
  148862. dump_buffer_p (phuff_entropy_ptr entropy)
  148863. {
  148864. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  148865. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  148866. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  148867. entropy->next_output_byte = dest->next_output_byte;
  148868. entropy->free_in_buffer = dest->free_in_buffer;
  148869. }
  148870. INLINE
  148871. LOCAL(void)
  148872. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  148873. {
  148874. register INT32 put_buffer = (INT32) code;
  148875. register int put_bits = entropy->put_bits;
  148876. if (size == 0)
  148877. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148878. if (entropy->gather_statistics)
  148879. return; /* do nothing if we're only getting stats */
  148880. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  148881. put_bits += size; /* new number of bits in buffer */
  148882. put_buffer <<= 24 - put_bits; /* align incoming bits */
  148883. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  148884. while (put_bits >= 8) {
  148885. int c = (int) ((put_buffer >> 16) & 0xFF);
  148886. emit_byte(entropy, c);
  148887. if (c == 0xFF) { /* need to stuff a zero byte? */
  148888. emit_byte(entropy, 0);
  148889. }
  148890. put_buffer <<= 8;
  148891. put_bits -= 8;
  148892. }
  148893. entropy->put_buffer = put_buffer; /* update variables */
  148894. entropy->put_bits = put_bits;
  148895. }
  148896. LOCAL(void)
  148897. flush_bits_p (phuff_entropy_ptr entropy)
  148898. {
  148899. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  148900. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  148901. entropy->put_bits = 0;
  148902. }
  148903. INLINE
  148904. LOCAL(void)
  148905. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  148906. {
  148907. if (entropy->gather_statistics)
  148908. entropy->count_ptrs[tbl_no][symbol]++;
  148909. else {
  148910. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  148911. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  148912. }
  148913. }
  148914. LOCAL(void)
  148915. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  148916. unsigned int nbits)
  148917. {
  148918. if (entropy->gather_statistics)
  148919. return; /* no real work */
  148920. while (nbits > 0) {
  148921. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  148922. bufstart++;
  148923. nbits--;
  148924. }
  148925. }
  148926. LOCAL(void)
  148927. emit_eobrun (phuff_entropy_ptr entropy)
  148928. {
  148929. register int temp, nbits;
  148930. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  148931. temp = entropy->EOBRUN;
  148932. nbits = 0;
  148933. while ((temp >>= 1))
  148934. nbits++;
  148935. if (nbits > 14)
  148936. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  148937. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  148938. if (nbits)
  148939. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  148940. entropy->EOBRUN = 0;
  148941. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  148942. entropy->BE = 0;
  148943. }
  148944. }
  148945. LOCAL(void)
  148946. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  148947. {
  148948. int ci;
  148949. emit_eobrun(entropy);
  148950. if (! entropy->gather_statistics) {
  148951. flush_bits_p(entropy);
  148952. emit_byte(entropy, 0xFF);
  148953. emit_byte(entropy, JPEG_RST0 + restart_num);
  148954. }
  148955. if (entropy->cinfo->Ss == 0) {
  148956. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  148957. entropy->last_dc_val[ci] = 0;
  148958. } else {
  148959. entropy->EOBRUN = 0;
  148960. entropy->BE = 0;
  148961. }
  148962. }
  148963. METHODDEF(boolean)
  148964. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  148965. {
  148966. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  148967. register int temp, temp2;
  148968. register int nbits;
  148969. int blkn, ci;
  148970. int Al = cinfo->Al;
  148971. JBLOCKROW block;
  148972. jpeg_component_info * compptr;
  148973. ISHIFT_TEMPS
  148974. entropy->next_output_byte = cinfo->dest->next_output_byte;
  148975. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  148976. if (cinfo->restart_interval)
  148977. if (entropy->restarts_to_go == 0)
  148978. emit_restart_p(entropy, entropy->next_restart_num);
  148979. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  148980. block = MCU_data[blkn];
  148981. ci = cinfo->MCU_membership[blkn];
  148982. compptr = cinfo->cur_comp_info[ci];
  148983. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  148984. temp = temp2 - entropy->last_dc_val[ci];
  148985. entropy->last_dc_val[ci] = temp2;
  148986. temp2 = temp;
  148987. if (temp < 0) {
  148988. temp = -temp; /* temp is abs value of input */
  148989. temp2--;
  148990. }
  148991. nbits = 0;
  148992. while (temp) {
  148993. nbits++;
  148994. temp >>= 1;
  148995. }
  148996. if (nbits > MAX_COEF_BITS+1)
  148997. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  148998. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  148999. if (nbits) /* emit_bits rejects calls with size 0 */
  149000. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149001. }
  149002. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149003. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149004. if (cinfo->restart_interval) {
  149005. if (entropy->restarts_to_go == 0) {
  149006. entropy->restarts_to_go = cinfo->restart_interval;
  149007. entropy->next_restart_num++;
  149008. entropy->next_restart_num &= 7;
  149009. }
  149010. entropy->restarts_to_go--;
  149011. }
  149012. return TRUE;
  149013. }
  149014. METHODDEF(boolean)
  149015. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149016. {
  149017. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149018. register int temp, temp2;
  149019. register int nbits;
  149020. register int r, k;
  149021. int Se = cinfo->Se;
  149022. int Al = cinfo->Al;
  149023. JBLOCKROW block;
  149024. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149025. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149026. if (cinfo->restart_interval)
  149027. if (entropy->restarts_to_go == 0)
  149028. emit_restart_p(entropy, entropy->next_restart_num);
  149029. block = MCU_data[0];
  149030. r = 0; /* r = run length of zeros */
  149031. for (k = cinfo->Ss; k <= Se; k++) {
  149032. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149033. r++;
  149034. continue;
  149035. }
  149036. if (temp < 0) {
  149037. temp = -temp; /* temp is abs value of input */
  149038. temp >>= Al; /* apply the point transform */
  149039. temp2 = ~temp;
  149040. } else {
  149041. temp >>= Al; /* apply the point transform */
  149042. temp2 = temp;
  149043. }
  149044. if (temp == 0) {
  149045. r++;
  149046. continue;
  149047. }
  149048. if (entropy->EOBRUN > 0)
  149049. emit_eobrun(entropy);
  149050. while (r > 15) {
  149051. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149052. r -= 16;
  149053. }
  149054. nbits = 1; /* there must be at least one 1 bit */
  149055. while ((temp >>= 1))
  149056. nbits++;
  149057. if (nbits > MAX_COEF_BITS)
  149058. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149059. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149060. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149061. r = 0; /* reset zero run length */
  149062. }
  149063. if (r > 0) { /* If there are trailing zeroes, */
  149064. entropy->EOBRUN++; /* count an EOB */
  149065. if (entropy->EOBRUN == 0x7FFF)
  149066. emit_eobrun(entropy); /* force it out to avoid overflow */
  149067. }
  149068. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149069. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149070. if (cinfo->restart_interval) {
  149071. if (entropy->restarts_to_go == 0) {
  149072. entropy->restarts_to_go = cinfo->restart_interval;
  149073. entropy->next_restart_num++;
  149074. entropy->next_restart_num &= 7;
  149075. }
  149076. entropy->restarts_to_go--;
  149077. }
  149078. return TRUE;
  149079. }
  149080. METHODDEF(boolean)
  149081. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149082. {
  149083. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149084. register int temp;
  149085. int blkn;
  149086. int Al = cinfo->Al;
  149087. JBLOCKROW block;
  149088. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149089. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149090. if (cinfo->restart_interval)
  149091. if (entropy->restarts_to_go == 0)
  149092. emit_restart_p(entropy, entropy->next_restart_num);
  149093. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149094. block = MCU_data[blkn];
  149095. temp = (*block)[0];
  149096. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149097. }
  149098. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149099. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149100. if (cinfo->restart_interval) {
  149101. if (entropy->restarts_to_go == 0) {
  149102. entropy->restarts_to_go = cinfo->restart_interval;
  149103. entropy->next_restart_num++;
  149104. entropy->next_restart_num &= 7;
  149105. }
  149106. entropy->restarts_to_go--;
  149107. }
  149108. return TRUE;
  149109. }
  149110. METHODDEF(boolean)
  149111. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149112. {
  149113. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149114. register int temp;
  149115. register int r, k;
  149116. int EOB;
  149117. char *BR_buffer;
  149118. unsigned int BR;
  149119. int Se = cinfo->Se;
  149120. int Al = cinfo->Al;
  149121. JBLOCKROW block;
  149122. int absvalues[DCTSIZE2];
  149123. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149124. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149125. if (cinfo->restart_interval)
  149126. if (entropy->restarts_to_go == 0)
  149127. emit_restart_p(entropy, entropy->next_restart_num);
  149128. block = MCU_data[0];
  149129. EOB = 0;
  149130. for (k = cinfo->Ss; k <= Se; k++) {
  149131. temp = (*block)[jpeg_natural_order[k]];
  149132. if (temp < 0)
  149133. temp = -temp; /* temp is abs value of input */
  149134. temp >>= Al; /* apply the point transform */
  149135. absvalues[k] = temp; /* save abs value for main pass */
  149136. if (temp == 1)
  149137. EOB = k; /* EOB = index of last newly-nonzero coef */
  149138. }
  149139. r = 0; /* r = run length of zeros */
  149140. BR = 0; /* BR = count of buffered bits added now */
  149141. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149142. for (k = cinfo->Ss; k <= Se; k++) {
  149143. if ((temp = absvalues[k]) == 0) {
  149144. r++;
  149145. continue;
  149146. }
  149147. while (r > 15 && k <= EOB) {
  149148. emit_eobrun(entropy);
  149149. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149150. r -= 16;
  149151. emit_buffered_bits(entropy, BR_buffer, BR);
  149152. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149153. BR = 0;
  149154. }
  149155. if (temp > 1) {
  149156. BR_buffer[BR++] = (char) (temp & 1);
  149157. continue;
  149158. }
  149159. emit_eobrun(entropy);
  149160. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149161. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149162. emit_bits_p(entropy, (unsigned int) temp, 1);
  149163. emit_buffered_bits(entropy, BR_buffer, BR);
  149164. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149165. BR = 0;
  149166. r = 0; /* reset zero run length */
  149167. }
  149168. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149169. entropy->EOBRUN++; /* count an EOB */
  149170. entropy->BE += BR; /* concat my correction bits to older ones */
  149171. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149172. emit_eobrun(entropy);
  149173. }
  149174. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149175. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149176. if (cinfo->restart_interval) {
  149177. if (entropy->restarts_to_go == 0) {
  149178. entropy->restarts_to_go = cinfo->restart_interval;
  149179. entropy->next_restart_num++;
  149180. entropy->next_restart_num &= 7;
  149181. }
  149182. entropy->restarts_to_go--;
  149183. }
  149184. return TRUE;
  149185. }
  149186. METHODDEF(void)
  149187. finish_pass_phuff (j_compress_ptr cinfo)
  149188. {
  149189. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149190. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149191. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149192. emit_eobrun(entropy);
  149193. flush_bits_p(entropy);
  149194. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149195. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149196. }
  149197. METHODDEF(void)
  149198. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149199. {
  149200. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149201. boolean is_DC_band;
  149202. int ci, tbl;
  149203. jpeg_component_info * compptr;
  149204. JHUFF_TBL **htblptr;
  149205. boolean did[NUM_HUFF_TBLS];
  149206. emit_eobrun(entropy);
  149207. is_DC_band = (cinfo->Ss == 0);
  149208. MEMZERO(did, SIZEOF(did));
  149209. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149210. compptr = cinfo->cur_comp_info[ci];
  149211. if (is_DC_band) {
  149212. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149213. continue;
  149214. tbl = compptr->dc_tbl_no;
  149215. } else {
  149216. tbl = compptr->ac_tbl_no;
  149217. }
  149218. if (! did[tbl]) {
  149219. if (is_DC_band)
  149220. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149221. else
  149222. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149223. if (*htblptr == NULL)
  149224. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149225. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149226. did[tbl] = TRUE;
  149227. }
  149228. }
  149229. }
  149230. GLOBAL(void)
  149231. jinit_phuff_encoder (j_compress_ptr cinfo)
  149232. {
  149233. phuff_entropy_ptr entropy;
  149234. int i;
  149235. entropy = (phuff_entropy_ptr)
  149236. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149237. SIZEOF(phuff_entropy_encoder));
  149238. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149239. entropy->pub.start_pass = start_pass_phuff;
  149240. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149241. entropy->derived_tbls[i] = NULL;
  149242. entropy->count_ptrs[i] = NULL;
  149243. }
  149244. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149245. }
  149246. #endif /* C_PROGRESSIVE_SUPPORTED */
  149247. /*** End of inlined file: jcphuff.c ***/
  149248. /*** Start of inlined file: jcprepct.c ***/
  149249. #define JPEG_INTERNALS
  149250. #ifdef INPUT_SMOOTHING_SUPPORTED
  149251. #define CONTEXT_ROWS_SUPPORTED
  149252. #endif
  149253. typedef struct {
  149254. struct jpeg_c_prep_controller pub; /* public fields */
  149255. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149256. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149257. int next_buf_row; /* index of next row to store in color_buf */
  149258. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149259. int this_row_group; /* starting row index of group to process */
  149260. int next_buf_stop; /* downsample when we reach this index */
  149261. #endif
  149262. } my_prep_controller;
  149263. typedef my_prep_controller * my_prep_ptr;
  149264. METHODDEF(void)
  149265. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149266. {
  149267. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149268. if (pass_mode != JBUF_PASS_THRU)
  149269. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149270. prep->rows_to_go = cinfo->image_height;
  149271. prep->next_buf_row = 0;
  149272. #ifdef CONTEXT_ROWS_SUPPORTED
  149273. prep->this_row_group = 0;
  149274. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149275. #endif
  149276. }
  149277. LOCAL(void)
  149278. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149279. int input_rows, int output_rows)
  149280. {
  149281. register int row;
  149282. for (row = input_rows; row < output_rows; row++) {
  149283. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149284. 1, num_cols);
  149285. }
  149286. }
  149287. METHODDEF(void)
  149288. pre_process_data (j_compress_ptr cinfo,
  149289. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149290. JDIMENSION in_rows_avail,
  149291. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149292. JDIMENSION out_row_groups_avail)
  149293. {
  149294. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149295. int numrows, ci;
  149296. JDIMENSION inrows;
  149297. jpeg_component_info * compptr;
  149298. while (*in_row_ctr < in_rows_avail &&
  149299. *out_row_group_ctr < out_row_groups_avail) {
  149300. inrows = in_rows_avail - *in_row_ctr;
  149301. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149302. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149303. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149304. prep->color_buf,
  149305. (JDIMENSION) prep->next_buf_row,
  149306. numrows);
  149307. *in_row_ctr += numrows;
  149308. prep->next_buf_row += numrows;
  149309. prep->rows_to_go -= numrows;
  149310. if (prep->rows_to_go == 0 &&
  149311. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149312. for (ci = 0; ci < cinfo->num_components; ci++) {
  149313. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149314. prep->next_buf_row, cinfo->max_v_samp_factor);
  149315. }
  149316. prep->next_buf_row = cinfo->max_v_samp_factor;
  149317. }
  149318. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149319. (*cinfo->downsample->downsample) (cinfo,
  149320. prep->color_buf, (JDIMENSION) 0,
  149321. output_buf, *out_row_group_ctr);
  149322. prep->next_buf_row = 0;
  149323. (*out_row_group_ctr)++;
  149324. }
  149325. if (prep->rows_to_go == 0 &&
  149326. *out_row_group_ctr < out_row_groups_avail) {
  149327. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149328. ci++, compptr++) {
  149329. expand_bottom_edge(output_buf[ci],
  149330. compptr->width_in_blocks * DCTSIZE,
  149331. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149332. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149333. }
  149334. *out_row_group_ctr = out_row_groups_avail;
  149335. break; /* can exit outer loop without test */
  149336. }
  149337. }
  149338. }
  149339. #ifdef CONTEXT_ROWS_SUPPORTED
  149340. METHODDEF(void)
  149341. pre_process_context (j_compress_ptr cinfo,
  149342. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149343. JDIMENSION in_rows_avail,
  149344. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149345. JDIMENSION out_row_groups_avail)
  149346. {
  149347. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149348. int numrows, ci;
  149349. int buf_height = cinfo->max_v_samp_factor * 3;
  149350. JDIMENSION inrows;
  149351. while (*out_row_group_ctr < out_row_groups_avail) {
  149352. if (*in_row_ctr < in_rows_avail) {
  149353. inrows = in_rows_avail - *in_row_ctr;
  149354. numrows = prep->next_buf_stop - prep->next_buf_row;
  149355. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149356. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149357. prep->color_buf,
  149358. (JDIMENSION) prep->next_buf_row,
  149359. numrows);
  149360. if (prep->rows_to_go == cinfo->image_height) {
  149361. for (ci = 0; ci < cinfo->num_components; ci++) {
  149362. int row;
  149363. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149364. jcopy_sample_rows(prep->color_buf[ci], 0,
  149365. prep->color_buf[ci], -row,
  149366. 1, cinfo->image_width);
  149367. }
  149368. }
  149369. }
  149370. *in_row_ctr += numrows;
  149371. prep->next_buf_row += numrows;
  149372. prep->rows_to_go -= numrows;
  149373. } else {
  149374. if (prep->rows_to_go != 0)
  149375. break;
  149376. if (prep->next_buf_row < prep->next_buf_stop) {
  149377. for (ci = 0; ci < cinfo->num_components; ci++) {
  149378. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149379. prep->next_buf_row, prep->next_buf_stop);
  149380. }
  149381. prep->next_buf_row = prep->next_buf_stop;
  149382. }
  149383. }
  149384. if (prep->next_buf_row == prep->next_buf_stop) {
  149385. (*cinfo->downsample->downsample) (cinfo,
  149386. prep->color_buf,
  149387. (JDIMENSION) prep->this_row_group,
  149388. output_buf, *out_row_group_ctr);
  149389. (*out_row_group_ctr)++;
  149390. prep->this_row_group += cinfo->max_v_samp_factor;
  149391. if (prep->this_row_group >= buf_height)
  149392. prep->this_row_group = 0;
  149393. if (prep->next_buf_row >= buf_height)
  149394. prep->next_buf_row = 0;
  149395. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149396. }
  149397. }
  149398. }
  149399. LOCAL(void)
  149400. create_context_buffer (j_compress_ptr cinfo)
  149401. {
  149402. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149403. int rgroup_height = cinfo->max_v_samp_factor;
  149404. int ci, i;
  149405. jpeg_component_info * compptr;
  149406. JSAMPARRAY true_buffer, fake_buffer;
  149407. fake_buffer = (JSAMPARRAY)
  149408. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149409. (cinfo->num_components * 5 * rgroup_height) *
  149410. SIZEOF(JSAMPROW));
  149411. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149412. ci++, compptr++) {
  149413. true_buffer = (*cinfo->mem->alloc_sarray)
  149414. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149415. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149416. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149417. (JDIMENSION) (3 * rgroup_height));
  149418. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149419. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149420. for (i = 0; i < rgroup_height; i++) {
  149421. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149422. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149423. }
  149424. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149425. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149426. }
  149427. }
  149428. #endif /* CONTEXT_ROWS_SUPPORTED */
  149429. GLOBAL(void)
  149430. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149431. {
  149432. my_prep_ptr prep;
  149433. int ci;
  149434. jpeg_component_info * compptr;
  149435. if (need_full_buffer) /* safety check */
  149436. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149437. prep = (my_prep_ptr)
  149438. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149439. SIZEOF(my_prep_controller));
  149440. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149441. prep->pub.start_pass = start_pass_prep;
  149442. if (cinfo->downsample->need_context_rows) {
  149443. #ifdef CONTEXT_ROWS_SUPPORTED
  149444. prep->pub.pre_process_data = pre_process_context;
  149445. create_context_buffer(cinfo);
  149446. #else
  149447. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149448. #endif
  149449. } else {
  149450. prep->pub.pre_process_data = pre_process_data;
  149451. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149452. ci++, compptr++) {
  149453. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149454. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149455. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149456. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149457. (JDIMENSION) cinfo->max_v_samp_factor);
  149458. }
  149459. }
  149460. }
  149461. /*** End of inlined file: jcprepct.c ***/
  149462. /*** Start of inlined file: jcsample.c ***/
  149463. #define JPEG_INTERNALS
  149464. typedef JMETHOD(void, downsample1_ptr,
  149465. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149466. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149467. typedef struct {
  149468. struct jpeg_downsampler pub; /* public fields */
  149469. downsample1_ptr methods[MAX_COMPONENTS];
  149470. } my_downsampler;
  149471. typedef my_downsampler * my_downsample_ptr;
  149472. METHODDEF(void)
  149473. start_pass_downsample (j_compress_ptr cinfo)
  149474. {
  149475. }
  149476. LOCAL(void)
  149477. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149478. JDIMENSION input_cols, JDIMENSION output_cols)
  149479. {
  149480. register JSAMPROW ptr;
  149481. register JSAMPLE pixval;
  149482. register int count;
  149483. int row;
  149484. int numcols = (int) (output_cols - input_cols);
  149485. if (numcols > 0) {
  149486. for (row = 0; row < num_rows; row++) {
  149487. ptr = image_data[row] + input_cols;
  149488. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149489. for (count = numcols; count > 0; count--)
  149490. *ptr++ = pixval;
  149491. }
  149492. }
  149493. }
  149494. METHODDEF(void)
  149495. sep_downsample (j_compress_ptr cinfo,
  149496. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149497. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149498. {
  149499. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149500. int ci;
  149501. jpeg_component_info * compptr;
  149502. JSAMPARRAY in_ptr, out_ptr;
  149503. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149504. ci++, compptr++) {
  149505. in_ptr = input_buf[ci] + in_row_index;
  149506. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149507. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149508. }
  149509. }
  149510. METHODDEF(void)
  149511. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149512. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149513. {
  149514. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  149515. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  149516. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149517. JSAMPROW inptr, outptr;
  149518. INT32 outvalue;
  149519. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  149520. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  149521. numpix = h_expand * v_expand;
  149522. numpix2 = numpix/2;
  149523. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149524. cinfo->image_width, output_cols * h_expand);
  149525. inrow = 0;
  149526. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149527. outptr = output_data[outrow];
  149528. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  149529. outcol++, outcol_h += h_expand) {
  149530. outvalue = 0;
  149531. for (v = 0; v < v_expand; v++) {
  149532. inptr = input_data[inrow+v] + outcol_h;
  149533. for (h = 0; h < h_expand; h++) {
  149534. outvalue += (INT32) GETJSAMPLE(*inptr++);
  149535. }
  149536. }
  149537. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  149538. }
  149539. inrow += v_expand;
  149540. }
  149541. }
  149542. METHODDEF(void)
  149543. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149544. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149545. {
  149546. jcopy_sample_rows(input_data, 0, output_data, 0,
  149547. cinfo->max_v_samp_factor, cinfo->image_width);
  149548. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  149549. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  149550. }
  149551. METHODDEF(void)
  149552. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149553. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149554. {
  149555. int outrow;
  149556. JDIMENSION outcol;
  149557. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149558. register JSAMPROW inptr, outptr;
  149559. register int bias;
  149560. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149561. cinfo->image_width, output_cols * 2);
  149562. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149563. outptr = output_data[outrow];
  149564. inptr = input_data[outrow];
  149565. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  149566. for (outcol = 0; outcol < output_cols; outcol++) {
  149567. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  149568. + bias) >> 1);
  149569. bias ^= 1; /* 0=>1, 1=>0 */
  149570. inptr += 2;
  149571. }
  149572. }
  149573. }
  149574. METHODDEF(void)
  149575. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149576. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149577. {
  149578. int inrow, outrow;
  149579. JDIMENSION outcol;
  149580. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149581. register JSAMPROW inptr0, inptr1, outptr;
  149582. register int bias;
  149583. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  149584. cinfo->image_width, output_cols * 2);
  149585. inrow = 0;
  149586. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149587. outptr = output_data[outrow];
  149588. inptr0 = input_data[inrow];
  149589. inptr1 = input_data[inrow+1];
  149590. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  149591. for (outcol = 0; outcol < output_cols; outcol++) {
  149592. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149593. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  149594. + bias) >> 2);
  149595. bias ^= 3; /* 1=>2, 2=>1 */
  149596. inptr0 += 2; inptr1 += 2;
  149597. }
  149598. inrow += 2;
  149599. }
  149600. }
  149601. #ifdef INPUT_SMOOTHING_SUPPORTED
  149602. METHODDEF(void)
  149603. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149604. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149605. {
  149606. int inrow, outrow;
  149607. JDIMENSION colctr;
  149608. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149609. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  149610. INT32 membersum, neighsum, memberscale, neighscale;
  149611. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149612. cinfo->image_width, output_cols * 2);
  149613. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  149614. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  149615. inrow = 0;
  149616. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149617. outptr = output_data[outrow];
  149618. inptr0 = input_data[inrow];
  149619. inptr1 = input_data[inrow+1];
  149620. above_ptr = input_data[inrow-1];
  149621. below_ptr = input_data[inrow+2];
  149622. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149623. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149624. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149625. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149626. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  149627. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  149628. neighsum += neighsum;
  149629. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  149630. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  149631. membersum = membersum * memberscale + neighsum * neighscale;
  149632. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149633. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149634. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149635. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149636. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149637. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149638. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149639. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  149640. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  149641. neighsum += neighsum;
  149642. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  149643. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  149644. membersum = membersum * memberscale + neighsum * neighscale;
  149645. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149646. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  149647. }
  149648. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  149649. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  149650. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  149651. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  149652. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  149653. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  149654. neighsum += neighsum;
  149655. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  149656. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  149657. membersum = membersum * memberscale + neighsum * neighscale;
  149658. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149659. inrow += 2;
  149660. }
  149661. }
  149662. METHODDEF(void)
  149663. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  149664. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149665. {
  149666. int outrow;
  149667. JDIMENSION colctr;
  149668. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  149669. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  149670. INT32 membersum, neighsum, memberscale, neighscale;
  149671. int colsum, lastcolsum, nextcolsum;
  149672. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  149673. cinfo->image_width, output_cols);
  149674. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  149675. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  149676. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  149677. outptr = output_data[outrow];
  149678. inptr = input_data[outrow];
  149679. above_ptr = input_data[outrow-1];
  149680. below_ptr = input_data[outrow+1];
  149681. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  149682. GETJSAMPLE(*inptr);
  149683. membersum = GETJSAMPLE(*inptr++);
  149684. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149685. GETJSAMPLE(*inptr);
  149686. neighsum = colsum + (colsum - membersum) + nextcolsum;
  149687. membersum = membersum * memberscale + neighsum * neighscale;
  149688. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149689. lastcolsum = colsum; colsum = nextcolsum;
  149690. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  149691. membersum = GETJSAMPLE(*inptr++);
  149692. above_ptr++; below_ptr++;
  149693. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  149694. GETJSAMPLE(*inptr);
  149695. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  149696. membersum = membersum * memberscale + neighsum * neighscale;
  149697. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  149698. lastcolsum = colsum; colsum = nextcolsum;
  149699. }
  149700. membersum = GETJSAMPLE(*inptr);
  149701. neighsum = lastcolsum + (colsum - membersum) + colsum;
  149702. membersum = membersum * memberscale + neighsum * neighscale;
  149703. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  149704. }
  149705. }
  149706. #endif /* INPUT_SMOOTHING_SUPPORTED */
  149707. GLOBAL(void)
  149708. jinit_downsampler (j_compress_ptr cinfo)
  149709. {
  149710. my_downsample_ptr downsample;
  149711. int ci;
  149712. jpeg_component_info * compptr;
  149713. boolean smoothok = TRUE;
  149714. downsample = (my_downsample_ptr)
  149715. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149716. SIZEOF(my_downsampler));
  149717. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  149718. downsample->pub.start_pass = start_pass_downsample;
  149719. downsample->pub.downsample = sep_downsample;
  149720. downsample->pub.need_context_rows = FALSE;
  149721. if (cinfo->CCIR601_sampling)
  149722. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  149723. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149724. ci++, compptr++) {
  149725. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  149726. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149727. #ifdef INPUT_SMOOTHING_SUPPORTED
  149728. if (cinfo->smoothing_factor) {
  149729. downsample->methods[ci] = fullsize_smooth_downsample;
  149730. downsample->pub.need_context_rows = TRUE;
  149731. } else
  149732. #endif
  149733. downsample->methods[ci] = fullsize_downsample;
  149734. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149735. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  149736. smoothok = FALSE;
  149737. downsample->methods[ci] = h2v1_downsample;
  149738. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  149739. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  149740. #ifdef INPUT_SMOOTHING_SUPPORTED
  149741. if (cinfo->smoothing_factor) {
  149742. downsample->methods[ci] = h2v2_smooth_downsample;
  149743. downsample->pub.need_context_rows = TRUE;
  149744. } else
  149745. #endif
  149746. downsample->methods[ci] = h2v2_downsample;
  149747. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  149748. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  149749. smoothok = FALSE;
  149750. downsample->methods[ci] = int_downsample;
  149751. } else
  149752. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  149753. }
  149754. #ifdef INPUT_SMOOTHING_SUPPORTED
  149755. if (cinfo->smoothing_factor && !smoothok)
  149756. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  149757. #endif
  149758. }
  149759. /*** End of inlined file: jcsample.c ***/
  149760. /*** Start of inlined file: jctrans.c ***/
  149761. #define JPEG_INTERNALS
  149762. LOCAL(void) transencode_master_selection
  149763. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149764. LOCAL(void) transencode_coef_controller
  149765. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  149766. GLOBAL(void)
  149767. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  149768. {
  149769. if (cinfo->global_state != CSTATE_START)
  149770. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149771. jpeg_suppress_tables(cinfo, FALSE);
  149772. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  149773. (*cinfo->dest->init_destination) (cinfo);
  149774. transencode_master_selection(cinfo, coef_arrays);
  149775. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  149776. cinfo->global_state = CSTATE_WRCOEFS;
  149777. }
  149778. GLOBAL(void)
  149779. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  149780. j_compress_ptr dstinfo)
  149781. {
  149782. JQUANT_TBL ** qtblptr;
  149783. jpeg_component_info *incomp, *outcomp;
  149784. JQUANT_TBL *c_quant, *slot_quant;
  149785. int tblno, ci, coefi;
  149786. if (dstinfo->global_state != CSTATE_START)
  149787. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  149788. dstinfo->image_width = srcinfo->image_width;
  149789. dstinfo->image_height = srcinfo->image_height;
  149790. dstinfo->input_components = srcinfo->num_components;
  149791. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  149792. jpeg_set_defaults(dstinfo);
  149793. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  149794. dstinfo->data_precision = srcinfo->data_precision;
  149795. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  149796. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  149797. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  149798. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  149799. if (*qtblptr == NULL)
  149800. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  149801. MEMCOPY((*qtblptr)->quantval,
  149802. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  149803. SIZEOF((*qtblptr)->quantval));
  149804. (*qtblptr)->sent_table = FALSE;
  149805. }
  149806. }
  149807. dstinfo->num_components = srcinfo->num_components;
  149808. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  149809. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  149810. MAX_COMPONENTS);
  149811. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  149812. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  149813. outcomp->component_id = incomp->component_id;
  149814. outcomp->h_samp_factor = incomp->h_samp_factor;
  149815. outcomp->v_samp_factor = incomp->v_samp_factor;
  149816. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  149817. tblno = outcomp->quant_tbl_no;
  149818. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  149819. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  149820. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  149821. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  149822. c_quant = incomp->quant_table;
  149823. if (c_quant != NULL) {
  149824. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  149825. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  149826. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  149827. }
  149828. }
  149829. }
  149830. if (srcinfo->saw_JFIF_marker) {
  149831. if (srcinfo->JFIF_major_version == 1) {
  149832. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  149833. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  149834. }
  149835. dstinfo->density_unit = srcinfo->density_unit;
  149836. dstinfo->X_density = srcinfo->X_density;
  149837. dstinfo->Y_density = srcinfo->Y_density;
  149838. }
  149839. }
  149840. LOCAL(void)
  149841. transencode_master_selection (j_compress_ptr cinfo,
  149842. jvirt_barray_ptr * coef_arrays)
  149843. {
  149844. cinfo->input_components = 1;
  149845. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  149846. if (cinfo->arith_code) {
  149847. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  149848. } else {
  149849. if (cinfo->progressive_mode) {
  149850. #ifdef C_PROGRESSIVE_SUPPORTED
  149851. jinit_phuff_encoder(cinfo);
  149852. #else
  149853. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149854. #endif
  149855. } else
  149856. jinit_huff_encoder(cinfo);
  149857. }
  149858. transencode_coef_controller(cinfo, coef_arrays);
  149859. jinit_marker_writer(cinfo);
  149860. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  149861. (*cinfo->marker->write_file_header) (cinfo);
  149862. }
  149863. typedef struct {
  149864. struct jpeg_c_coef_controller pub; /* public fields */
  149865. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  149866. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  149867. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  149868. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  149869. jvirt_barray_ptr * whole_image;
  149870. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  149871. } my_coef_controller2;
  149872. typedef my_coef_controller2 * my_coef_ptr2;
  149873. LOCAL(void)
  149874. start_iMCU_row2 (j_compress_ptr cinfo)
  149875. {
  149876. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149877. if (cinfo->comps_in_scan > 1) {
  149878. coef->MCU_rows_per_iMCU_row = 1;
  149879. } else {
  149880. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  149881. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  149882. else
  149883. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  149884. }
  149885. coef->mcu_ctr = 0;
  149886. coef->MCU_vert_offset = 0;
  149887. }
  149888. METHODDEF(void)
  149889. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149890. {
  149891. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149892. if (pass_mode != JBUF_CRANK_DEST)
  149893. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149894. coef->iMCU_row_num = 0;
  149895. start_iMCU_row2(cinfo);
  149896. }
  149897. METHODDEF(boolean)
  149898. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  149899. {
  149900. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  149901. JDIMENSION MCU_col_num; /* index of current MCU within row */
  149902. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  149903. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  149904. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  149905. JDIMENSION start_col;
  149906. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  149907. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  149908. JBLOCKROW buffer_ptr;
  149909. jpeg_component_info *compptr;
  149910. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149911. compptr = cinfo->cur_comp_info[ci];
  149912. buffer[ci] = (*cinfo->mem->access_virt_barray)
  149913. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  149914. coef->iMCU_row_num * compptr->v_samp_factor,
  149915. (JDIMENSION) compptr->v_samp_factor, FALSE);
  149916. }
  149917. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  149918. yoffset++) {
  149919. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  149920. MCU_col_num++) {
  149921. blkn = 0; /* index of current DCT block within MCU */
  149922. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149923. compptr = cinfo->cur_comp_info[ci];
  149924. start_col = MCU_col_num * compptr->MCU_width;
  149925. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  149926. : compptr->last_col_width;
  149927. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  149928. if (coef->iMCU_row_num < last_iMCU_row ||
  149929. yindex+yoffset < compptr->last_row_height) {
  149930. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  149931. for (xindex = 0; xindex < blockcnt; xindex++)
  149932. MCU_buffer[blkn++] = buffer_ptr++;
  149933. } else {
  149934. xindex = 0;
  149935. }
  149936. for (; xindex < compptr->MCU_width; xindex++) {
  149937. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  149938. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  149939. blkn++;
  149940. }
  149941. }
  149942. }
  149943. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  149944. coef->MCU_vert_offset = yoffset;
  149945. coef->mcu_ctr = MCU_col_num;
  149946. return FALSE;
  149947. }
  149948. }
  149949. coef->mcu_ctr = 0;
  149950. }
  149951. coef->iMCU_row_num++;
  149952. start_iMCU_row2(cinfo);
  149953. return TRUE;
  149954. }
  149955. LOCAL(void)
  149956. transencode_coef_controller (j_compress_ptr cinfo,
  149957. jvirt_barray_ptr * coef_arrays)
  149958. {
  149959. my_coef_ptr2 coef;
  149960. JBLOCKROW buffer;
  149961. int i;
  149962. coef = (my_coef_ptr2)
  149963. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149964. SIZEOF(my_coef_controller2));
  149965. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  149966. coef->pub.start_pass = start_pass_coef2;
  149967. coef->pub.compress_data = compress_output2;
  149968. coef->whole_image = coef_arrays;
  149969. buffer = (JBLOCKROW)
  149970. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149971. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  149972. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  149973. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  149974. coef->dummy_buffer[i] = buffer + i;
  149975. }
  149976. }
  149977. /*** End of inlined file: jctrans.c ***/
  149978. /*** Start of inlined file: jdapistd.c ***/
  149979. #define JPEG_INTERNALS
  149980. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  149981. GLOBAL(boolean)
  149982. jpeg_start_decompress (j_decompress_ptr cinfo)
  149983. {
  149984. if (cinfo->global_state == DSTATE_READY) {
  149985. jinit_master_decompress(cinfo);
  149986. if (cinfo->buffered_image) {
  149987. cinfo->global_state = DSTATE_BUFIMAGE;
  149988. return TRUE;
  149989. }
  149990. cinfo->global_state = DSTATE_PRELOAD;
  149991. }
  149992. if (cinfo->global_state == DSTATE_PRELOAD) {
  149993. if (cinfo->inputctl->has_multiple_scans) {
  149994. #ifdef D_MULTISCAN_FILES_SUPPORTED
  149995. for (;;) {
  149996. int retcode;
  149997. if (cinfo->progress != NULL)
  149998. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  149999. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150000. if (retcode == JPEG_SUSPENDED)
  150001. return FALSE;
  150002. if (retcode == JPEG_REACHED_EOI)
  150003. break;
  150004. if (cinfo->progress != NULL &&
  150005. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150006. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150007. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150008. }
  150009. }
  150010. }
  150011. #else
  150012. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150013. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150014. }
  150015. cinfo->output_scan_number = cinfo->input_scan_number;
  150016. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150017. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150018. return output_pass_setup(cinfo);
  150019. }
  150020. LOCAL(boolean)
  150021. output_pass_setup (j_decompress_ptr cinfo)
  150022. {
  150023. if (cinfo->global_state != DSTATE_PRESCAN) {
  150024. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150025. cinfo->output_scanline = 0;
  150026. cinfo->global_state = DSTATE_PRESCAN;
  150027. }
  150028. while (cinfo->master->is_dummy_pass) {
  150029. #ifdef QUANT_2PASS_SUPPORTED
  150030. while (cinfo->output_scanline < cinfo->output_height) {
  150031. JDIMENSION last_scanline;
  150032. if (cinfo->progress != NULL) {
  150033. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150034. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150035. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150036. }
  150037. last_scanline = cinfo->output_scanline;
  150038. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150039. &cinfo->output_scanline, (JDIMENSION) 0);
  150040. if (cinfo->output_scanline == last_scanline)
  150041. return FALSE; /* No progress made, must suspend */
  150042. }
  150043. (*cinfo->master->finish_output_pass) (cinfo);
  150044. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150045. cinfo->output_scanline = 0;
  150046. #else
  150047. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150048. #endif /* QUANT_2PASS_SUPPORTED */
  150049. }
  150050. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150051. return TRUE;
  150052. }
  150053. GLOBAL(JDIMENSION)
  150054. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150055. JDIMENSION max_lines)
  150056. {
  150057. JDIMENSION row_ctr;
  150058. if (cinfo->global_state != DSTATE_SCANNING)
  150059. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150060. if (cinfo->output_scanline >= cinfo->output_height) {
  150061. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150062. return 0;
  150063. }
  150064. if (cinfo->progress != NULL) {
  150065. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150066. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150067. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150068. }
  150069. row_ctr = 0;
  150070. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150071. cinfo->output_scanline += row_ctr;
  150072. return row_ctr;
  150073. }
  150074. GLOBAL(JDIMENSION)
  150075. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150076. JDIMENSION max_lines)
  150077. {
  150078. JDIMENSION lines_per_iMCU_row;
  150079. if (cinfo->global_state != DSTATE_RAW_OK)
  150080. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150081. if (cinfo->output_scanline >= cinfo->output_height) {
  150082. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150083. return 0;
  150084. }
  150085. if (cinfo->progress != NULL) {
  150086. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150087. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150088. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150089. }
  150090. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150091. if (max_lines < lines_per_iMCU_row)
  150092. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150093. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150094. return 0; /* suspension forced, can do nothing more */
  150095. cinfo->output_scanline += lines_per_iMCU_row;
  150096. return lines_per_iMCU_row;
  150097. }
  150098. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150099. GLOBAL(boolean)
  150100. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150101. {
  150102. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150103. cinfo->global_state != DSTATE_PRESCAN)
  150104. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150105. if (scan_number <= 0)
  150106. scan_number = 1;
  150107. if (cinfo->inputctl->eoi_reached &&
  150108. scan_number > cinfo->input_scan_number)
  150109. scan_number = cinfo->input_scan_number;
  150110. cinfo->output_scan_number = scan_number;
  150111. return output_pass_setup(cinfo);
  150112. }
  150113. GLOBAL(boolean)
  150114. jpeg_finish_output (j_decompress_ptr cinfo)
  150115. {
  150116. if ((cinfo->global_state == DSTATE_SCANNING ||
  150117. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150118. (*cinfo->master->finish_output_pass) (cinfo);
  150119. cinfo->global_state = DSTATE_BUFPOST;
  150120. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150121. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150122. }
  150123. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150124. ! cinfo->inputctl->eoi_reached) {
  150125. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150126. return FALSE; /* Suspend, come back later */
  150127. }
  150128. cinfo->global_state = DSTATE_BUFIMAGE;
  150129. return TRUE;
  150130. }
  150131. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150132. /*** End of inlined file: jdapistd.c ***/
  150133. /*** Start of inlined file: jdapimin.c ***/
  150134. #define JPEG_INTERNALS
  150135. GLOBAL(void)
  150136. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150137. {
  150138. int i;
  150139. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150140. if (version != JPEG_LIB_VERSION)
  150141. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150142. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150143. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150144. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150145. {
  150146. struct jpeg_error_mgr * err = cinfo->err;
  150147. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150148. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150149. cinfo->err = err;
  150150. cinfo->client_data = client_data;
  150151. }
  150152. cinfo->is_decompressor = TRUE;
  150153. jinit_memory_mgr((j_common_ptr) cinfo);
  150154. cinfo->progress = NULL;
  150155. cinfo->src = NULL;
  150156. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150157. cinfo->quant_tbl_ptrs[i] = NULL;
  150158. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150159. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150160. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150161. }
  150162. cinfo->marker_list = NULL;
  150163. jinit_marker_reader(cinfo);
  150164. jinit_input_controller(cinfo);
  150165. cinfo->global_state = DSTATE_START;
  150166. }
  150167. GLOBAL(void)
  150168. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150169. {
  150170. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150171. }
  150172. GLOBAL(void)
  150173. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150174. {
  150175. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150176. }
  150177. LOCAL(void)
  150178. default_decompress_parms (j_decompress_ptr cinfo)
  150179. {
  150180. switch (cinfo->num_components) {
  150181. case 1:
  150182. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150183. cinfo->out_color_space = JCS_GRAYSCALE;
  150184. break;
  150185. case 3:
  150186. if (cinfo->saw_JFIF_marker) {
  150187. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150188. } else if (cinfo->saw_Adobe_marker) {
  150189. switch (cinfo->Adobe_transform) {
  150190. case 0:
  150191. cinfo->jpeg_color_space = JCS_RGB;
  150192. break;
  150193. case 1:
  150194. cinfo->jpeg_color_space = JCS_YCbCr;
  150195. break;
  150196. default:
  150197. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150198. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150199. break;
  150200. }
  150201. } else {
  150202. int cid0 = cinfo->comp_info[0].component_id;
  150203. int cid1 = cinfo->comp_info[1].component_id;
  150204. int cid2 = cinfo->comp_info[2].component_id;
  150205. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150206. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150207. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150208. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150209. else {
  150210. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150211. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150212. }
  150213. }
  150214. cinfo->out_color_space = JCS_RGB;
  150215. break;
  150216. case 4:
  150217. if (cinfo->saw_Adobe_marker) {
  150218. switch (cinfo->Adobe_transform) {
  150219. case 0:
  150220. cinfo->jpeg_color_space = JCS_CMYK;
  150221. break;
  150222. case 2:
  150223. cinfo->jpeg_color_space = JCS_YCCK;
  150224. break;
  150225. default:
  150226. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150227. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150228. break;
  150229. }
  150230. } else {
  150231. cinfo->jpeg_color_space = JCS_CMYK;
  150232. }
  150233. cinfo->out_color_space = JCS_CMYK;
  150234. break;
  150235. default:
  150236. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150237. cinfo->out_color_space = JCS_UNKNOWN;
  150238. break;
  150239. }
  150240. cinfo->scale_num = 1; /* 1:1 scaling */
  150241. cinfo->scale_denom = 1;
  150242. cinfo->output_gamma = 1.0;
  150243. cinfo->buffered_image = FALSE;
  150244. cinfo->raw_data_out = FALSE;
  150245. cinfo->dct_method = JDCT_DEFAULT;
  150246. cinfo->do_fancy_upsampling = TRUE;
  150247. cinfo->do_block_smoothing = TRUE;
  150248. cinfo->quantize_colors = FALSE;
  150249. cinfo->dither_mode = JDITHER_FS;
  150250. #ifdef QUANT_2PASS_SUPPORTED
  150251. cinfo->two_pass_quantize = TRUE;
  150252. #else
  150253. cinfo->two_pass_quantize = FALSE;
  150254. #endif
  150255. cinfo->desired_number_of_colors = 256;
  150256. cinfo->colormap = NULL;
  150257. cinfo->enable_1pass_quant = FALSE;
  150258. cinfo->enable_external_quant = FALSE;
  150259. cinfo->enable_2pass_quant = FALSE;
  150260. }
  150261. GLOBAL(int)
  150262. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150263. {
  150264. int retcode;
  150265. if (cinfo->global_state != DSTATE_START &&
  150266. cinfo->global_state != DSTATE_INHEADER)
  150267. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150268. retcode = jpeg_consume_input(cinfo);
  150269. switch (retcode) {
  150270. case JPEG_REACHED_SOS:
  150271. retcode = JPEG_HEADER_OK;
  150272. break;
  150273. case JPEG_REACHED_EOI:
  150274. if (require_image) /* Complain if application wanted an image */
  150275. ERREXIT(cinfo, JERR_NO_IMAGE);
  150276. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150277. retcode = JPEG_HEADER_TABLES_ONLY;
  150278. break;
  150279. case JPEG_SUSPENDED:
  150280. break;
  150281. }
  150282. return retcode;
  150283. }
  150284. GLOBAL(int)
  150285. jpeg_consume_input (j_decompress_ptr cinfo)
  150286. {
  150287. int retcode = JPEG_SUSPENDED;
  150288. switch (cinfo->global_state) {
  150289. case DSTATE_START:
  150290. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150291. (*cinfo->src->init_source) (cinfo);
  150292. cinfo->global_state = DSTATE_INHEADER;
  150293. case DSTATE_INHEADER:
  150294. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150295. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150296. default_decompress_parms(cinfo);
  150297. cinfo->global_state = DSTATE_READY;
  150298. }
  150299. break;
  150300. case DSTATE_READY:
  150301. retcode = JPEG_REACHED_SOS;
  150302. break;
  150303. case DSTATE_PRELOAD:
  150304. case DSTATE_PRESCAN:
  150305. case DSTATE_SCANNING:
  150306. case DSTATE_RAW_OK:
  150307. case DSTATE_BUFIMAGE:
  150308. case DSTATE_BUFPOST:
  150309. case DSTATE_STOPPING:
  150310. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150311. break;
  150312. default:
  150313. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150314. }
  150315. return retcode;
  150316. }
  150317. GLOBAL(boolean)
  150318. jpeg_input_complete (j_decompress_ptr cinfo)
  150319. {
  150320. if (cinfo->global_state < DSTATE_START ||
  150321. cinfo->global_state > DSTATE_STOPPING)
  150322. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150323. return cinfo->inputctl->eoi_reached;
  150324. }
  150325. GLOBAL(boolean)
  150326. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150327. {
  150328. if (cinfo->global_state < DSTATE_READY ||
  150329. cinfo->global_state > DSTATE_STOPPING)
  150330. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150331. return cinfo->inputctl->has_multiple_scans;
  150332. }
  150333. GLOBAL(boolean)
  150334. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150335. {
  150336. if ((cinfo->global_state == DSTATE_SCANNING ||
  150337. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150338. if (cinfo->output_scanline < cinfo->output_height)
  150339. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150340. (*cinfo->master->finish_output_pass) (cinfo);
  150341. cinfo->global_state = DSTATE_STOPPING;
  150342. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150343. cinfo->global_state = DSTATE_STOPPING;
  150344. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150345. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150346. }
  150347. while (! cinfo->inputctl->eoi_reached) {
  150348. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150349. return FALSE; /* Suspend, come back later */
  150350. }
  150351. (*cinfo->src->term_source) (cinfo);
  150352. jpeg_abort((j_common_ptr) cinfo);
  150353. return TRUE;
  150354. }
  150355. /*** End of inlined file: jdapimin.c ***/
  150356. /*** Start of inlined file: jdatasrc.c ***/
  150357. /*** Start of inlined file: jerror.h ***/
  150358. #ifndef JMESSAGE
  150359. #ifndef JERROR_H
  150360. #define JMAKE_ENUM_LIST
  150361. #else
  150362. #define JMESSAGE(code,string)
  150363. #endif /* JERROR_H */
  150364. #endif /* JMESSAGE */
  150365. #ifdef JMAKE_ENUM_LIST
  150366. typedef enum {
  150367. #define JMESSAGE(code,string) code ,
  150368. #endif /* JMAKE_ENUM_LIST */
  150369. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150370. JMESSAGE(JERR_ARITH_NOTIMPL,
  150371. "Sorry, there are legal restrictions on arithmetic coding")
  150372. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150373. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150374. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150375. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150376. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150377. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150378. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150379. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150380. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150381. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150382. JMESSAGE(JERR_BAD_LIB_VERSION,
  150383. "Wrong JPEG library version: library is %d, caller expects %d")
  150384. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150385. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150386. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150387. JMESSAGE(JERR_BAD_PROGRESSION,
  150388. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150389. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150390. "Invalid progressive parameters at scan script entry %d")
  150391. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150392. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150393. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150394. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150395. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150396. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150397. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150398. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150399. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150400. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150401. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150402. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150403. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150404. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150405. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150406. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150407. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150408. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150409. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150410. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150411. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150412. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150413. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150414. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150415. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150416. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150417. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150418. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150419. "Cannot transcode due to multiple use of quantization table %d")
  150420. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150421. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150422. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150423. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150424. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150425. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150426. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150427. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150428. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150429. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150430. JMESSAGE(JERR_QUANT_COMPONENTS,
  150431. "Cannot quantize more than %d color components")
  150432. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150433. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150434. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150435. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150436. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150437. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150438. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150439. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150440. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150441. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150442. JMESSAGE(JERR_TFILE_WRITE,
  150443. "Write failed on temporary file --- out of disk space?")
  150444. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150445. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150446. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150447. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150448. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150449. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150450. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150451. JMESSAGE(JMSG_VERSION, JVERSION)
  150452. JMESSAGE(JTRC_16BIT_TABLES,
  150453. "Caution: quantization tables are too coarse for baseline JPEG")
  150454. JMESSAGE(JTRC_ADOBE,
  150455. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150456. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150457. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150458. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150459. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150460. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150461. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150462. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150463. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150464. JMESSAGE(JTRC_EOI, "End Of Image")
  150465. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150466. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150467. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150468. "Warning: thumbnail image size does not match data length %u")
  150469. JMESSAGE(JTRC_JFIF_EXTENSION,
  150470. "JFIF extension marker: type 0x%02x, length %u")
  150471. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150472. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150473. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150474. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150475. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150476. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150477. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150478. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150479. JMESSAGE(JTRC_RST, "RST%d")
  150480. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150481. "Smoothing not supported with nonstandard sampling ratios")
  150482. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150483. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150484. JMESSAGE(JTRC_SOI, "Start of Image")
  150485. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150486. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150487. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150488. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150489. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150490. JMESSAGE(JTRC_THUMB_JPEG,
  150491. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150492. JMESSAGE(JTRC_THUMB_PALETTE,
  150493. "JFIF extension marker: palette thumbnail image, length %u")
  150494. JMESSAGE(JTRC_THUMB_RGB,
  150495. "JFIF extension marker: RGB thumbnail image, length %u")
  150496. JMESSAGE(JTRC_UNKNOWN_IDS,
  150497. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150498. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150499. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150500. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150501. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150502. "Inconsistent progression sequence for component %d coefficient %d")
  150503. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150504. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150505. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150506. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150507. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150508. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150509. JMESSAGE(JWRN_MUST_RESYNC,
  150510. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150511. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150512. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150513. #ifdef JMAKE_ENUM_LIST
  150514. JMSG_LASTMSGCODE
  150515. } J_MESSAGE_CODE;
  150516. #undef JMAKE_ENUM_LIST
  150517. #endif /* JMAKE_ENUM_LIST */
  150518. #undef JMESSAGE
  150519. #ifndef JERROR_H
  150520. #define JERROR_H
  150521. #define ERREXIT(cinfo,code) \
  150522. ((cinfo)->err->msg_code = (code), \
  150523. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150524. #define ERREXIT1(cinfo,code,p1) \
  150525. ((cinfo)->err->msg_code = (code), \
  150526. (cinfo)->err->msg_parm.i[0] = (p1), \
  150527. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150528. #define ERREXIT2(cinfo,code,p1,p2) \
  150529. ((cinfo)->err->msg_code = (code), \
  150530. (cinfo)->err->msg_parm.i[0] = (p1), \
  150531. (cinfo)->err->msg_parm.i[1] = (p2), \
  150532. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150533. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  150534. ((cinfo)->err->msg_code = (code), \
  150535. (cinfo)->err->msg_parm.i[0] = (p1), \
  150536. (cinfo)->err->msg_parm.i[1] = (p2), \
  150537. (cinfo)->err->msg_parm.i[2] = (p3), \
  150538. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150539. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  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->msg_parm.i[2] = (p3), \
  150544. (cinfo)->err->msg_parm.i[3] = (p4), \
  150545. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150546. #define ERREXITS(cinfo,code,str) \
  150547. ((cinfo)->err->msg_code = (code), \
  150548. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150549. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  150550. #define MAKESTMT(stuff) do { stuff } while (0)
  150551. #define WARNMS(cinfo,code) \
  150552. ((cinfo)->err->msg_code = (code), \
  150553. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150554. #define WARNMS1(cinfo,code,p1) \
  150555. ((cinfo)->err->msg_code = (code), \
  150556. (cinfo)->err->msg_parm.i[0] = (p1), \
  150557. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150558. #define WARNMS2(cinfo,code,p1,p2) \
  150559. ((cinfo)->err->msg_code = (code), \
  150560. (cinfo)->err->msg_parm.i[0] = (p1), \
  150561. (cinfo)->err->msg_parm.i[1] = (p2), \
  150562. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  150563. #define TRACEMS(cinfo,lvl,code) \
  150564. ((cinfo)->err->msg_code = (code), \
  150565. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150566. #define TRACEMS1(cinfo,lvl,code,p1) \
  150567. ((cinfo)->err->msg_code = (code), \
  150568. (cinfo)->err->msg_parm.i[0] = (p1), \
  150569. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150570. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  150571. ((cinfo)->err->msg_code = (code), \
  150572. (cinfo)->err->msg_parm.i[0] = (p1), \
  150573. (cinfo)->err->msg_parm.i[1] = (p2), \
  150574. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150575. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  150576. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150577. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  150578. (cinfo)->err->msg_code = (code); \
  150579. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150580. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  150581. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150582. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150583. (cinfo)->err->msg_code = (code); \
  150584. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150585. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  150586. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150587. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150588. _mp[4] = (p5); \
  150589. (cinfo)->err->msg_code = (code); \
  150590. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150591. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  150592. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  150593. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  150594. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  150595. (cinfo)->err->msg_code = (code); \
  150596. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  150597. #define TRACEMSS(cinfo,lvl,code,str) \
  150598. ((cinfo)->err->msg_code = (code), \
  150599. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  150600. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  150601. #endif /* JERROR_H */
  150602. /*** End of inlined file: jerror.h ***/
  150603. typedef struct {
  150604. struct jpeg_source_mgr pub; /* public fields */
  150605. FILE * infile; /* source stream */
  150606. JOCTET * buffer; /* start of buffer */
  150607. boolean start_of_file; /* have we gotten any data yet? */
  150608. } my_source_mgr;
  150609. typedef my_source_mgr * my_src_ptr;
  150610. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  150611. METHODDEF(void)
  150612. init_source (j_decompress_ptr cinfo)
  150613. {
  150614. my_src_ptr src = (my_src_ptr) cinfo->src;
  150615. src->start_of_file = TRUE;
  150616. }
  150617. METHODDEF(boolean)
  150618. fill_input_buffer (j_decompress_ptr cinfo)
  150619. {
  150620. my_src_ptr src = (my_src_ptr) cinfo->src;
  150621. size_t nbytes;
  150622. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  150623. if (nbytes <= 0) {
  150624. if (src->start_of_file) /* Treat empty input file as fatal error */
  150625. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  150626. WARNMS(cinfo, JWRN_JPEG_EOF);
  150627. src->buffer[0] = (JOCTET) 0xFF;
  150628. src->buffer[1] = (JOCTET) JPEG_EOI;
  150629. nbytes = 2;
  150630. }
  150631. src->pub.next_input_byte = src->buffer;
  150632. src->pub.bytes_in_buffer = nbytes;
  150633. src->start_of_file = FALSE;
  150634. return TRUE;
  150635. }
  150636. METHODDEF(void)
  150637. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  150638. {
  150639. my_src_ptr src = (my_src_ptr) cinfo->src;
  150640. if (num_bytes > 0) {
  150641. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  150642. num_bytes -= (long) src->pub.bytes_in_buffer;
  150643. (void) fill_input_buffer(cinfo);
  150644. }
  150645. src->pub.next_input_byte += (size_t) num_bytes;
  150646. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  150647. }
  150648. }
  150649. METHODDEF(void)
  150650. term_source (j_decompress_ptr cinfo)
  150651. {
  150652. }
  150653. GLOBAL(void)
  150654. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  150655. {
  150656. my_src_ptr src;
  150657. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  150658. cinfo->src = (struct jpeg_source_mgr *)
  150659. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150660. SIZEOF(my_source_mgr));
  150661. src = (my_src_ptr) cinfo->src;
  150662. src->buffer = (JOCTET *)
  150663. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  150664. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  150665. }
  150666. src = (my_src_ptr) cinfo->src;
  150667. src->pub.init_source = init_source;
  150668. src->pub.fill_input_buffer = fill_input_buffer;
  150669. src->pub.skip_input_data = skip_input_data;
  150670. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  150671. src->pub.term_source = term_source;
  150672. src->infile = infile;
  150673. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  150674. src->pub.next_input_byte = NULL; /* until buffer loaded */
  150675. }
  150676. /*** End of inlined file: jdatasrc.c ***/
  150677. /*** Start of inlined file: jdcoefct.c ***/
  150678. #define JPEG_INTERNALS
  150679. #ifndef D_PROGRESSIVE_SUPPORTED
  150680. #undef BLOCK_SMOOTHING_SUPPORTED
  150681. #endif
  150682. typedef struct {
  150683. struct jpeg_d_coef_controller pub; /* public fields */
  150684. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  150685. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150686. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150687. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  150688. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150689. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  150690. #endif
  150691. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150692. int * coef_bits_latch;
  150693. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  150694. #endif
  150695. } my_coef_controller3;
  150696. typedef my_coef_controller3 * my_coef_ptr3;
  150697. METHODDEF(int) decompress_onepass
  150698. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150699. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150700. METHODDEF(int) decompress_data
  150701. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150702. #endif
  150703. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150704. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  150705. METHODDEF(int) decompress_smooth_data
  150706. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  150707. #endif
  150708. LOCAL(void)
  150709. start_iMCU_row3 (j_decompress_ptr cinfo)
  150710. {
  150711. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150712. if (cinfo->comps_in_scan > 1) {
  150713. coef->MCU_rows_per_iMCU_row = 1;
  150714. } else {
  150715. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  150716. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150717. else
  150718. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150719. }
  150720. coef->MCU_ctr = 0;
  150721. coef->MCU_vert_offset = 0;
  150722. }
  150723. METHODDEF(void)
  150724. start_input_pass (j_decompress_ptr cinfo)
  150725. {
  150726. cinfo->input_iMCU_row = 0;
  150727. start_iMCU_row3(cinfo);
  150728. }
  150729. METHODDEF(void)
  150730. start_output_pass (j_decompress_ptr cinfo)
  150731. {
  150732. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150733. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150734. if (coef->pub.coef_arrays != NULL) {
  150735. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  150736. coef->pub.decompress_data = decompress_smooth_data;
  150737. else
  150738. coef->pub.decompress_data = decompress_data;
  150739. }
  150740. #endif
  150741. cinfo->output_iMCU_row = 0;
  150742. }
  150743. METHODDEF(int)
  150744. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150745. {
  150746. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150747. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150748. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150749. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150750. int blkn, ci, xindex, yindex, yoffset, useful_width;
  150751. JSAMPARRAY output_ptr;
  150752. JDIMENSION start_col, output_col;
  150753. jpeg_component_info *compptr;
  150754. inverse_DCT_method_ptr inverse_DCT;
  150755. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150756. yoffset++) {
  150757. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  150758. MCU_col_num++) {
  150759. jzero_far((void FAR *) coef->MCU_buffer[0],
  150760. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  150761. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150762. coef->MCU_vert_offset = yoffset;
  150763. coef->MCU_ctr = MCU_col_num;
  150764. return JPEG_SUSPENDED;
  150765. }
  150766. blkn = 0; /* index of current DCT block within MCU */
  150767. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150768. compptr = cinfo->cur_comp_info[ci];
  150769. if (! compptr->component_needed) {
  150770. blkn += compptr->MCU_blocks;
  150771. continue;
  150772. }
  150773. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  150774. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150775. : compptr->last_col_width;
  150776. output_ptr = output_buf[compptr->component_index] +
  150777. yoffset * compptr->DCT_scaled_size;
  150778. start_col = MCU_col_num * compptr->MCU_sample_width;
  150779. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150780. if (cinfo->input_iMCU_row < last_iMCU_row ||
  150781. yoffset+yindex < compptr->last_row_height) {
  150782. output_col = start_col;
  150783. for (xindex = 0; xindex < useful_width; xindex++) {
  150784. (*inverse_DCT) (cinfo, compptr,
  150785. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  150786. output_ptr, output_col);
  150787. output_col += compptr->DCT_scaled_size;
  150788. }
  150789. }
  150790. blkn += compptr->MCU_width;
  150791. output_ptr += compptr->DCT_scaled_size;
  150792. }
  150793. }
  150794. }
  150795. coef->MCU_ctr = 0;
  150796. }
  150797. cinfo->output_iMCU_row++;
  150798. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150799. start_iMCU_row3(cinfo);
  150800. return JPEG_ROW_COMPLETED;
  150801. }
  150802. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150803. return JPEG_SCAN_COMPLETED;
  150804. }
  150805. METHODDEF(int)
  150806. dummy_consume_data (j_decompress_ptr cinfo)
  150807. {
  150808. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  150809. }
  150810. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150811. METHODDEF(int)
  150812. consume_data (j_decompress_ptr cinfo)
  150813. {
  150814. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150815. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150816. int blkn, ci, xindex, yindex, yoffset;
  150817. JDIMENSION start_col;
  150818. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150819. JBLOCKROW buffer_ptr;
  150820. jpeg_component_info *compptr;
  150821. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150822. compptr = cinfo->cur_comp_info[ci];
  150823. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150824. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150825. cinfo->input_iMCU_row * compptr->v_samp_factor,
  150826. (JDIMENSION) compptr->v_samp_factor, TRUE);
  150827. }
  150828. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150829. yoffset++) {
  150830. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150831. MCU_col_num++) {
  150832. blkn = 0; /* index of current DCT block within MCU */
  150833. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150834. compptr = cinfo->cur_comp_info[ci];
  150835. start_col = MCU_col_num * compptr->MCU_width;
  150836. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150837. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150838. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  150839. coef->MCU_buffer[blkn++] = buffer_ptr++;
  150840. }
  150841. }
  150842. }
  150843. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  150844. coef->MCU_vert_offset = yoffset;
  150845. coef->MCU_ctr = MCU_col_num;
  150846. return JPEG_SUSPENDED;
  150847. }
  150848. }
  150849. coef->MCU_ctr = 0;
  150850. }
  150851. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  150852. start_iMCU_row3(cinfo);
  150853. return JPEG_ROW_COMPLETED;
  150854. }
  150855. (*cinfo->inputctl->finish_input_pass) (cinfo);
  150856. return JPEG_SCAN_COMPLETED;
  150857. }
  150858. METHODDEF(int)
  150859. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150860. {
  150861. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150862. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150863. JDIMENSION block_num;
  150864. int ci, block_row, block_rows;
  150865. JBLOCKARRAY buffer;
  150866. JBLOCKROW buffer_ptr;
  150867. JSAMPARRAY output_ptr;
  150868. JDIMENSION output_col;
  150869. jpeg_component_info *compptr;
  150870. inverse_DCT_method_ptr inverse_DCT;
  150871. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  150872. (cinfo->input_scan_number == cinfo->output_scan_number &&
  150873. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  150874. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150875. return JPEG_SUSPENDED;
  150876. }
  150877. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150878. ci++, compptr++) {
  150879. if (! compptr->component_needed)
  150880. continue;
  150881. buffer = (*cinfo->mem->access_virt_barray)
  150882. ((j_common_ptr) cinfo, coef->whole_image[ci],
  150883. cinfo->output_iMCU_row * compptr->v_samp_factor,
  150884. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150885. if (cinfo->output_iMCU_row < last_iMCU_row)
  150886. block_rows = compptr->v_samp_factor;
  150887. else {
  150888. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  150889. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  150890. }
  150891. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  150892. output_ptr = output_buf[ci];
  150893. for (block_row = 0; block_row < block_rows; block_row++) {
  150894. buffer_ptr = buffer[block_row];
  150895. output_col = 0;
  150896. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  150897. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  150898. output_ptr, output_col);
  150899. buffer_ptr++;
  150900. output_col += compptr->DCT_scaled_size;
  150901. }
  150902. output_ptr += compptr->DCT_scaled_size;
  150903. }
  150904. }
  150905. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  150906. return JPEG_ROW_COMPLETED;
  150907. return JPEG_SCAN_COMPLETED;
  150908. }
  150909. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150910. #ifdef BLOCK_SMOOTHING_SUPPORTED
  150911. #define Q01_POS 1
  150912. #define Q10_POS 8
  150913. #define Q20_POS 16
  150914. #define Q11_POS 9
  150915. #define Q02_POS 2
  150916. LOCAL(boolean)
  150917. smoothing_ok (j_decompress_ptr cinfo)
  150918. {
  150919. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150920. boolean smoothing_useful = FALSE;
  150921. int ci, coefi;
  150922. jpeg_component_info *compptr;
  150923. JQUANT_TBL * qtable;
  150924. int * coef_bits;
  150925. int * coef_bits_latch;
  150926. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  150927. return FALSE;
  150928. if (coef->coef_bits_latch == NULL)
  150929. coef->coef_bits_latch = (int *)
  150930. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150931. cinfo->num_components *
  150932. (SAVED_COEFS * SIZEOF(int)));
  150933. coef_bits_latch = coef->coef_bits_latch;
  150934. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150935. ci++, compptr++) {
  150936. if ((qtable = compptr->quant_table) == NULL)
  150937. return FALSE;
  150938. if (qtable->quantval[0] == 0 ||
  150939. qtable->quantval[Q01_POS] == 0 ||
  150940. qtable->quantval[Q10_POS] == 0 ||
  150941. qtable->quantval[Q20_POS] == 0 ||
  150942. qtable->quantval[Q11_POS] == 0 ||
  150943. qtable->quantval[Q02_POS] == 0)
  150944. return FALSE;
  150945. coef_bits = cinfo->coef_bits[ci];
  150946. if (coef_bits[0] < 0)
  150947. return FALSE;
  150948. for (coefi = 1; coefi <= 5; coefi++) {
  150949. coef_bits_latch[coefi] = coef_bits[coefi];
  150950. if (coef_bits[coefi] != 0)
  150951. smoothing_useful = TRUE;
  150952. }
  150953. coef_bits_latch += SAVED_COEFS;
  150954. }
  150955. return smoothing_useful;
  150956. }
  150957. METHODDEF(int)
  150958. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  150959. {
  150960. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  150961. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150962. JDIMENSION block_num, last_block_column;
  150963. int ci, block_row, block_rows, access_rows;
  150964. JBLOCKARRAY buffer;
  150965. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  150966. JSAMPARRAY output_ptr;
  150967. JDIMENSION output_col;
  150968. jpeg_component_info *compptr;
  150969. inverse_DCT_method_ptr inverse_DCT;
  150970. boolean first_row, last_row;
  150971. JBLOCK workspace;
  150972. int *coef_bits;
  150973. JQUANT_TBL *quanttbl;
  150974. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  150975. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  150976. int Al, pred;
  150977. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150978. ! cinfo->inputctl->eoi_reached) {
  150979. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  150980. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  150981. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  150982. break;
  150983. }
  150984. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  150985. return JPEG_SUSPENDED;
  150986. }
  150987. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150988. ci++, compptr++) {
  150989. if (! compptr->component_needed)
  150990. continue;
  150991. if (cinfo->output_iMCU_row < last_iMCU_row) {
  150992. block_rows = compptr->v_samp_factor;
  150993. access_rows = block_rows * 2; /* this and next iMCU row */
  150994. last_row = FALSE;
  150995. } else {
  150996. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  150997. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  150998. access_rows = block_rows; /* this iMCU row only */
  150999. last_row = TRUE;
  151000. }
  151001. if (cinfo->output_iMCU_row > 0) {
  151002. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151003. buffer = (*cinfo->mem->access_virt_barray)
  151004. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151005. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151006. (JDIMENSION) access_rows, FALSE);
  151007. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151008. first_row = FALSE;
  151009. } else {
  151010. buffer = (*cinfo->mem->access_virt_barray)
  151011. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151012. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151013. first_row = TRUE;
  151014. }
  151015. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151016. quanttbl = compptr->quant_table;
  151017. Q00 = quanttbl->quantval[0];
  151018. Q01 = quanttbl->quantval[Q01_POS];
  151019. Q10 = quanttbl->quantval[Q10_POS];
  151020. Q20 = quanttbl->quantval[Q20_POS];
  151021. Q11 = quanttbl->quantval[Q11_POS];
  151022. Q02 = quanttbl->quantval[Q02_POS];
  151023. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151024. output_ptr = output_buf[ci];
  151025. for (block_row = 0; block_row < block_rows; block_row++) {
  151026. buffer_ptr = buffer[block_row];
  151027. if (first_row && block_row == 0)
  151028. prev_block_row = buffer_ptr;
  151029. else
  151030. prev_block_row = buffer[block_row-1];
  151031. if (last_row && block_row == block_rows-1)
  151032. next_block_row = buffer_ptr;
  151033. else
  151034. next_block_row = buffer[block_row+1];
  151035. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151036. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151037. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151038. output_col = 0;
  151039. last_block_column = compptr->width_in_blocks - 1;
  151040. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151041. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151042. if (block_num < last_block_column) {
  151043. DC3 = (int) prev_block_row[1][0];
  151044. DC6 = (int) buffer_ptr[1][0];
  151045. DC9 = (int) next_block_row[1][0];
  151046. }
  151047. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151048. num = 36 * Q00 * (DC4 - DC6);
  151049. if (num >= 0) {
  151050. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151051. if (Al > 0 && pred >= (1<<Al))
  151052. pred = (1<<Al)-1;
  151053. } else {
  151054. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151055. if (Al > 0 && pred >= (1<<Al))
  151056. pred = (1<<Al)-1;
  151057. pred = -pred;
  151058. }
  151059. workspace[1] = (JCOEF) pred;
  151060. }
  151061. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151062. num = 36 * Q00 * (DC2 - DC8);
  151063. if (num >= 0) {
  151064. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151065. if (Al > 0 && pred >= (1<<Al))
  151066. pred = (1<<Al)-1;
  151067. } else {
  151068. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151069. if (Al > 0 && pred >= (1<<Al))
  151070. pred = (1<<Al)-1;
  151071. pred = -pred;
  151072. }
  151073. workspace[8] = (JCOEF) pred;
  151074. }
  151075. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151076. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151077. if (num >= 0) {
  151078. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151079. if (Al > 0 && pred >= (1<<Al))
  151080. pred = (1<<Al)-1;
  151081. } else {
  151082. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151083. if (Al > 0 && pred >= (1<<Al))
  151084. pred = (1<<Al)-1;
  151085. pred = -pred;
  151086. }
  151087. workspace[16] = (JCOEF) pred;
  151088. }
  151089. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151090. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151091. if (num >= 0) {
  151092. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151093. if (Al > 0 && pred >= (1<<Al))
  151094. pred = (1<<Al)-1;
  151095. } else {
  151096. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151097. if (Al > 0 && pred >= (1<<Al))
  151098. pred = (1<<Al)-1;
  151099. pred = -pred;
  151100. }
  151101. workspace[9] = (JCOEF) pred;
  151102. }
  151103. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151104. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151105. if (num >= 0) {
  151106. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151107. if (Al > 0 && pred >= (1<<Al))
  151108. pred = (1<<Al)-1;
  151109. } else {
  151110. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151111. if (Al > 0 && pred >= (1<<Al))
  151112. pred = (1<<Al)-1;
  151113. pred = -pred;
  151114. }
  151115. workspace[2] = (JCOEF) pred;
  151116. }
  151117. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151118. output_ptr, output_col);
  151119. DC1 = DC2; DC2 = DC3;
  151120. DC4 = DC5; DC5 = DC6;
  151121. DC7 = DC8; DC8 = DC9;
  151122. buffer_ptr++, prev_block_row++, next_block_row++;
  151123. output_col += compptr->DCT_scaled_size;
  151124. }
  151125. output_ptr += compptr->DCT_scaled_size;
  151126. }
  151127. }
  151128. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151129. return JPEG_ROW_COMPLETED;
  151130. return JPEG_SCAN_COMPLETED;
  151131. }
  151132. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151133. GLOBAL(void)
  151134. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151135. {
  151136. my_coef_ptr3 coef;
  151137. coef = (my_coef_ptr3)
  151138. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151139. SIZEOF(my_coef_controller3));
  151140. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151141. coef->pub.start_input_pass = start_input_pass;
  151142. coef->pub.start_output_pass = start_output_pass;
  151143. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151144. coef->coef_bits_latch = NULL;
  151145. #endif
  151146. if (need_full_buffer) {
  151147. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151148. int ci, access_rows;
  151149. jpeg_component_info *compptr;
  151150. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151151. ci++, compptr++) {
  151152. access_rows = compptr->v_samp_factor;
  151153. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151154. if (cinfo->progressive_mode)
  151155. access_rows *= 3;
  151156. #endif
  151157. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151158. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151159. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151160. (long) compptr->h_samp_factor),
  151161. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151162. (long) compptr->v_samp_factor),
  151163. (JDIMENSION) access_rows);
  151164. }
  151165. coef->pub.consume_data = consume_data;
  151166. coef->pub.decompress_data = decompress_data;
  151167. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151168. #else
  151169. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151170. #endif
  151171. } else {
  151172. JBLOCKROW buffer;
  151173. int i;
  151174. buffer = (JBLOCKROW)
  151175. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151176. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151177. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151178. coef->MCU_buffer[i] = buffer + i;
  151179. }
  151180. coef->pub.consume_data = dummy_consume_data;
  151181. coef->pub.decompress_data = decompress_onepass;
  151182. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151183. }
  151184. }
  151185. /*** End of inlined file: jdcoefct.c ***/
  151186. #undef FIX
  151187. /*** Start of inlined file: jdcolor.c ***/
  151188. #define JPEG_INTERNALS
  151189. typedef struct {
  151190. struct jpeg_color_deconverter pub; /* public fields */
  151191. int * Cr_r_tab; /* => table for Cr to R conversion */
  151192. int * Cb_b_tab; /* => table for Cb to B conversion */
  151193. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151194. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151195. } my_color_deconverter2;
  151196. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151197. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151198. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151199. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151200. LOCAL(void)
  151201. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151202. {
  151203. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151204. int i;
  151205. INT32 x;
  151206. SHIFT_TEMPS
  151207. cconvert->Cr_r_tab = (int *)
  151208. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151209. (MAXJSAMPLE+1) * SIZEOF(int));
  151210. cconvert->Cb_b_tab = (int *)
  151211. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151212. (MAXJSAMPLE+1) * SIZEOF(int));
  151213. cconvert->Cr_g_tab = (INT32 *)
  151214. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151215. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151216. cconvert->Cb_g_tab = (INT32 *)
  151217. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151218. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151219. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151220. cconvert->Cr_r_tab[i] = (int)
  151221. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151222. cconvert->Cb_b_tab[i] = (int)
  151223. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151224. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151225. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151226. }
  151227. }
  151228. METHODDEF(void)
  151229. ycc_rgb_convert (j_decompress_ptr cinfo,
  151230. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151231. JSAMPARRAY output_buf, int num_rows)
  151232. {
  151233. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151234. register int y, cb, cr;
  151235. register JSAMPROW outptr;
  151236. register JSAMPROW inptr0, inptr1, inptr2;
  151237. register JDIMENSION col;
  151238. JDIMENSION num_cols = cinfo->output_width;
  151239. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151240. register int * Crrtab = cconvert->Cr_r_tab;
  151241. register int * Cbbtab = cconvert->Cb_b_tab;
  151242. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151243. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151244. SHIFT_TEMPS
  151245. while (--num_rows >= 0) {
  151246. inptr0 = input_buf[0][input_row];
  151247. inptr1 = input_buf[1][input_row];
  151248. inptr2 = input_buf[2][input_row];
  151249. input_row++;
  151250. outptr = *output_buf++;
  151251. for (col = 0; col < num_cols; col++) {
  151252. y = GETJSAMPLE(inptr0[col]);
  151253. cb = GETJSAMPLE(inptr1[col]);
  151254. cr = GETJSAMPLE(inptr2[col]);
  151255. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151256. outptr[RGB_GREEN] = range_limit[y +
  151257. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151258. SCALEBITS))];
  151259. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151260. outptr += RGB_PIXELSIZE;
  151261. }
  151262. }
  151263. }
  151264. METHODDEF(void)
  151265. null_convert2 (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 count;
  151271. register int num_components = cinfo->num_components;
  151272. JDIMENSION num_cols = cinfo->output_width;
  151273. int ci;
  151274. while (--num_rows >= 0) {
  151275. for (ci = 0; ci < num_components; ci++) {
  151276. inptr = input_buf[ci][input_row];
  151277. outptr = output_buf[0] + ci;
  151278. for (count = num_cols; count > 0; count--) {
  151279. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151280. outptr += num_components;
  151281. }
  151282. }
  151283. input_row++;
  151284. output_buf++;
  151285. }
  151286. }
  151287. METHODDEF(void)
  151288. grayscale_convert2 (j_decompress_ptr cinfo,
  151289. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151290. JSAMPARRAY output_buf, int num_rows)
  151291. {
  151292. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151293. num_rows, cinfo->output_width);
  151294. }
  151295. METHODDEF(void)
  151296. gray_rgb_convert (j_decompress_ptr cinfo,
  151297. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151298. JSAMPARRAY output_buf, int num_rows)
  151299. {
  151300. register JSAMPROW inptr, outptr;
  151301. register JDIMENSION col;
  151302. JDIMENSION num_cols = cinfo->output_width;
  151303. while (--num_rows >= 0) {
  151304. inptr = input_buf[0][input_row++];
  151305. outptr = *output_buf++;
  151306. for (col = 0; col < num_cols; col++) {
  151307. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151308. outptr += RGB_PIXELSIZE;
  151309. }
  151310. }
  151311. }
  151312. METHODDEF(void)
  151313. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151314. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151315. JSAMPARRAY output_buf, int num_rows)
  151316. {
  151317. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151318. register int y, cb, cr;
  151319. register JSAMPROW outptr;
  151320. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151321. register JDIMENSION col;
  151322. JDIMENSION num_cols = cinfo->output_width;
  151323. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151324. register int * Crrtab = cconvert->Cr_r_tab;
  151325. register int * Cbbtab = cconvert->Cb_b_tab;
  151326. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151327. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151328. SHIFT_TEMPS
  151329. while (--num_rows >= 0) {
  151330. inptr0 = input_buf[0][input_row];
  151331. inptr1 = input_buf[1][input_row];
  151332. inptr2 = input_buf[2][input_row];
  151333. inptr3 = input_buf[3][input_row];
  151334. input_row++;
  151335. outptr = *output_buf++;
  151336. for (col = 0; col < num_cols; col++) {
  151337. y = GETJSAMPLE(inptr0[col]);
  151338. cb = GETJSAMPLE(inptr1[col]);
  151339. cr = GETJSAMPLE(inptr2[col]);
  151340. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151341. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151342. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151343. SCALEBITS)))];
  151344. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151345. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151346. outptr += 4;
  151347. }
  151348. }
  151349. }
  151350. METHODDEF(void)
  151351. start_pass_dcolor (j_decompress_ptr cinfo)
  151352. {
  151353. }
  151354. GLOBAL(void)
  151355. jinit_color_deconverter (j_decompress_ptr cinfo)
  151356. {
  151357. my_cconvert_ptr2 cconvert;
  151358. int ci;
  151359. cconvert = (my_cconvert_ptr2)
  151360. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151361. SIZEOF(my_color_deconverter2));
  151362. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151363. cconvert->pub.start_pass = start_pass_dcolor;
  151364. switch (cinfo->jpeg_color_space) {
  151365. case JCS_GRAYSCALE:
  151366. if (cinfo->num_components != 1)
  151367. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151368. break;
  151369. case JCS_RGB:
  151370. case JCS_YCbCr:
  151371. if (cinfo->num_components != 3)
  151372. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151373. break;
  151374. case JCS_CMYK:
  151375. case JCS_YCCK:
  151376. if (cinfo->num_components != 4)
  151377. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151378. break;
  151379. default: /* JCS_UNKNOWN can be anything */
  151380. if (cinfo->num_components < 1)
  151381. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151382. break;
  151383. }
  151384. switch (cinfo->out_color_space) {
  151385. case JCS_GRAYSCALE:
  151386. cinfo->out_color_components = 1;
  151387. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151388. cinfo->jpeg_color_space == JCS_YCbCr) {
  151389. cconvert->pub.color_convert = grayscale_convert2;
  151390. for (ci = 1; ci < cinfo->num_components; ci++)
  151391. cinfo->comp_info[ci].component_needed = FALSE;
  151392. } else
  151393. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151394. break;
  151395. case JCS_RGB:
  151396. cinfo->out_color_components = RGB_PIXELSIZE;
  151397. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151398. cconvert->pub.color_convert = ycc_rgb_convert;
  151399. build_ycc_rgb_table(cinfo);
  151400. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151401. cconvert->pub.color_convert = gray_rgb_convert;
  151402. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151403. cconvert->pub.color_convert = null_convert2;
  151404. } else
  151405. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151406. break;
  151407. case JCS_CMYK:
  151408. cinfo->out_color_components = 4;
  151409. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151410. cconvert->pub.color_convert = ycck_cmyk_convert;
  151411. build_ycc_rgb_table(cinfo);
  151412. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151413. cconvert->pub.color_convert = null_convert2;
  151414. } else
  151415. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151416. break;
  151417. default:
  151418. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151419. cinfo->out_color_components = cinfo->num_components;
  151420. cconvert->pub.color_convert = null_convert2;
  151421. } else /* unsupported non-null conversion */
  151422. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151423. break;
  151424. }
  151425. if (cinfo->quantize_colors)
  151426. cinfo->output_components = 1; /* single colormapped output component */
  151427. else
  151428. cinfo->output_components = cinfo->out_color_components;
  151429. }
  151430. /*** End of inlined file: jdcolor.c ***/
  151431. #undef FIX
  151432. /*** Start of inlined file: jddctmgr.c ***/
  151433. #define JPEG_INTERNALS
  151434. typedef struct {
  151435. struct jpeg_inverse_dct pub; /* public fields */
  151436. int cur_method[MAX_COMPONENTS];
  151437. } my_idct_controller;
  151438. typedef my_idct_controller * my_idct_ptr;
  151439. typedef union {
  151440. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151441. #ifdef DCT_IFAST_SUPPORTED
  151442. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151443. #endif
  151444. #ifdef DCT_FLOAT_SUPPORTED
  151445. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151446. #endif
  151447. } multiplier_table;
  151448. #ifdef DCT_ISLOW_SUPPORTED
  151449. #define PROVIDE_ISLOW_TABLES
  151450. #else
  151451. #ifdef IDCT_SCALING_SUPPORTED
  151452. #define PROVIDE_ISLOW_TABLES
  151453. #endif
  151454. #endif
  151455. METHODDEF(void)
  151456. start_pass (j_decompress_ptr cinfo)
  151457. {
  151458. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151459. int ci, i;
  151460. jpeg_component_info *compptr;
  151461. int method = 0;
  151462. inverse_DCT_method_ptr method_ptr = NULL;
  151463. JQUANT_TBL * qtbl;
  151464. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151465. ci++, compptr++) {
  151466. switch (compptr->DCT_scaled_size) {
  151467. #ifdef IDCT_SCALING_SUPPORTED
  151468. case 1:
  151469. method_ptr = jpeg_idct_1x1;
  151470. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151471. break;
  151472. case 2:
  151473. method_ptr = jpeg_idct_2x2;
  151474. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151475. break;
  151476. case 4:
  151477. method_ptr = jpeg_idct_4x4;
  151478. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151479. break;
  151480. #endif
  151481. case DCTSIZE:
  151482. switch (cinfo->dct_method) {
  151483. #ifdef DCT_ISLOW_SUPPORTED
  151484. case JDCT_ISLOW:
  151485. method_ptr = jpeg_idct_islow;
  151486. method = JDCT_ISLOW;
  151487. break;
  151488. #endif
  151489. #ifdef DCT_IFAST_SUPPORTED
  151490. case JDCT_IFAST:
  151491. method_ptr = jpeg_idct_ifast;
  151492. method = JDCT_IFAST;
  151493. break;
  151494. #endif
  151495. #ifdef DCT_FLOAT_SUPPORTED
  151496. case JDCT_FLOAT:
  151497. method_ptr = jpeg_idct_float;
  151498. method = JDCT_FLOAT;
  151499. break;
  151500. #endif
  151501. default:
  151502. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151503. break;
  151504. }
  151505. break;
  151506. default:
  151507. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151508. break;
  151509. }
  151510. idct->pub.inverse_DCT[ci] = method_ptr;
  151511. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151512. continue;
  151513. qtbl = compptr->quant_table;
  151514. if (qtbl == NULL) /* happens if no data yet for component */
  151515. continue;
  151516. idct->cur_method[ci] = method;
  151517. switch (method) {
  151518. #ifdef PROVIDE_ISLOW_TABLES
  151519. case JDCT_ISLOW:
  151520. {
  151521. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  151522. for (i = 0; i < DCTSIZE2; i++) {
  151523. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  151524. }
  151525. }
  151526. break;
  151527. #endif
  151528. #ifdef DCT_IFAST_SUPPORTED
  151529. case JDCT_IFAST:
  151530. {
  151531. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  151532. #define CONST_BITS 14
  151533. static const INT16 aanscales[DCTSIZE2] = {
  151534. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151535. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  151536. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  151537. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  151538. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  151539. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  151540. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  151541. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  151542. };
  151543. SHIFT_TEMPS
  151544. for (i = 0; i < DCTSIZE2; i++) {
  151545. ifmtbl[i] = (IFAST_MULT_TYPE)
  151546. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  151547. (INT32) aanscales[i]),
  151548. CONST_BITS-IFAST_SCALE_BITS);
  151549. }
  151550. }
  151551. break;
  151552. #endif
  151553. #ifdef DCT_FLOAT_SUPPORTED
  151554. case JDCT_FLOAT:
  151555. {
  151556. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  151557. int row, col;
  151558. static const double aanscalefactor[DCTSIZE] = {
  151559. 1.0, 1.387039845, 1.306562965, 1.175875602,
  151560. 1.0, 0.785694958, 0.541196100, 0.275899379
  151561. };
  151562. i = 0;
  151563. for (row = 0; row < DCTSIZE; row++) {
  151564. for (col = 0; col < DCTSIZE; col++) {
  151565. fmtbl[i] = (FLOAT_MULT_TYPE)
  151566. ((double) qtbl->quantval[i] *
  151567. aanscalefactor[row] * aanscalefactor[col]);
  151568. i++;
  151569. }
  151570. }
  151571. }
  151572. break;
  151573. #endif
  151574. default:
  151575. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151576. break;
  151577. }
  151578. }
  151579. }
  151580. GLOBAL(void)
  151581. jinit_inverse_dct (j_decompress_ptr cinfo)
  151582. {
  151583. my_idct_ptr idct;
  151584. int ci;
  151585. jpeg_component_info *compptr;
  151586. idct = (my_idct_ptr)
  151587. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151588. SIZEOF(my_idct_controller));
  151589. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  151590. idct->pub.start_pass = start_pass;
  151591. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151592. ci++, compptr++) {
  151593. compptr->dct_table =
  151594. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151595. SIZEOF(multiplier_table));
  151596. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  151597. idct->cur_method[ci] = -1;
  151598. }
  151599. }
  151600. /*** End of inlined file: jddctmgr.c ***/
  151601. #undef CONST_BITS
  151602. #undef ASSIGN_STATE
  151603. /*** Start of inlined file: jdhuff.c ***/
  151604. #define JPEG_INTERNALS
  151605. /*** Start of inlined file: jdhuff.h ***/
  151606. #ifndef __jdhuff_h__
  151607. #define __jdhuff_h__
  151608. #ifdef NEED_SHORT_EXTERNAL_NAMES
  151609. #define jpeg_make_d_derived_tbl jMkDDerived
  151610. #define jpeg_fill_bit_buffer jFilBitBuf
  151611. #define jpeg_huff_decode jHufDecode
  151612. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  151613. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  151614. typedef struct {
  151615. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  151616. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  151617. JHUFF_TBL *pub;
  151618. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  151619. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  151620. } d_derived_tbl;
  151621. EXTERN(void) jpeg_make_d_derived_tbl
  151622. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  151623. d_derived_tbl ** pdtbl));
  151624. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  151625. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  151626. typedef struct { /* Bitreading state saved across MCUs */
  151627. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151628. int bits_left; /* # of unused bits in it */
  151629. } bitread_perm_state;
  151630. typedef struct { /* Bitreading working state within an MCU */
  151631. const JOCTET * next_input_byte; /* => next byte to read from source */
  151632. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  151633. bit_buf_type get_buffer; /* current bit-extraction buffer */
  151634. int bits_left; /* # of unused bits in it */
  151635. j_decompress_ptr cinfo; /* back link to decompress master record */
  151636. } bitread_working_state;
  151637. #define BITREAD_STATE_VARS \
  151638. register bit_buf_type get_buffer; \
  151639. register int bits_left; \
  151640. bitread_working_state br_state
  151641. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  151642. br_state.cinfo = cinfop; \
  151643. br_state.next_input_byte = cinfop->src->next_input_byte; \
  151644. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  151645. get_buffer = permstate.get_buffer; \
  151646. bits_left = permstate.bits_left;
  151647. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  151648. cinfop->src->next_input_byte = br_state.next_input_byte; \
  151649. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  151650. permstate.get_buffer = get_buffer; \
  151651. permstate.bits_left = bits_left
  151652. #define CHECK_BIT_BUFFER(state,nbits,action) \
  151653. { if (bits_left < (nbits)) { \
  151654. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  151655. { action; } \
  151656. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  151657. #define GET_BITS(nbits) \
  151658. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  151659. #define PEEK_BITS(nbits) \
  151660. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  151661. #define DROP_BITS(nbits) \
  151662. (bits_left -= (nbits))
  151663. EXTERN(boolean) jpeg_fill_bit_buffer
  151664. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151665. register int bits_left, int nbits));
  151666. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  151667. { register int nb, look; \
  151668. if (bits_left < HUFF_LOOKAHEAD) { \
  151669. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  151670. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151671. if (bits_left < HUFF_LOOKAHEAD) { \
  151672. nb = 1; goto slowlabel; \
  151673. } \
  151674. } \
  151675. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  151676. if ((nb = htbl->look_nbits[look]) != 0) { \
  151677. DROP_BITS(nb); \
  151678. result = htbl->look_sym[look]; \
  151679. } else { \
  151680. nb = HUFF_LOOKAHEAD+1; \
  151681. slowlabel: \
  151682. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  151683. { failaction; } \
  151684. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  151685. } \
  151686. }
  151687. EXTERN(int) jpeg_huff_decode
  151688. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  151689. register int bits_left, d_derived_tbl * htbl, int min_bits));
  151690. #endif
  151691. /*** End of inlined file: jdhuff.h ***/
  151692. /* Declarations shared with jdphuff.c */
  151693. typedef struct {
  151694. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  151695. } savable_state2;
  151696. #ifndef NO_STRUCT_ASSIGN
  151697. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  151698. #else
  151699. #if MAX_COMPS_IN_SCAN == 4
  151700. #define ASSIGN_STATE(dest,src) \
  151701. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  151702. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  151703. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  151704. (dest).last_dc_val[3] = (src).last_dc_val[3])
  151705. #endif
  151706. #endif
  151707. typedef struct {
  151708. struct jpeg_entropy_decoder pub; /* public fields */
  151709. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  151710. savable_state2 saved; /* Other state at start of MCU */
  151711. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  151712. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  151713. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  151714. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151715. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  151716. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  151717. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  151718. } huff_entropy_decoder2;
  151719. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  151720. METHODDEF(void)
  151721. start_pass_huff_decoder (j_decompress_ptr cinfo)
  151722. {
  151723. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151724. int ci, blkn, dctbl, actbl;
  151725. jpeg_component_info * compptr;
  151726. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  151727. cinfo->Ah != 0 || cinfo->Al != 0)
  151728. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  151729. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151730. compptr = cinfo->cur_comp_info[ci];
  151731. dctbl = compptr->dc_tbl_no;
  151732. actbl = compptr->ac_tbl_no;
  151733. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  151734. & entropy->dc_derived_tbls[dctbl]);
  151735. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  151736. & entropy->ac_derived_tbls[actbl]);
  151737. entropy->saved.last_dc_val[ci] = 0;
  151738. }
  151739. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151740. ci = cinfo->MCU_membership[blkn];
  151741. compptr = cinfo->cur_comp_info[ci];
  151742. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  151743. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  151744. if (compptr->component_needed) {
  151745. entropy->dc_needed[blkn] = TRUE;
  151746. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  151747. } else {
  151748. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  151749. }
  151750. }
  151751. entropy->bitstate.bits_left = 0;
  151752. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  151753. entropy->pub.insufficient_data = FALSE;
  151754. entropy->restarts_to_go = cinfo->restart_interval;
  151755. }
  151756. GLOBAL(void)
  151757. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  151758. d_derived_tbl ** pdtbl)
  151759. {
  151760. JHUFF_TBL *htbl;
  151761. d_derived_tbl *dtbl;
  151762. int p, i, l, si, numsymbols;
  151763. int lookbits, ctr;
  151764. char huffsize[257];
  151765. unsigned int huffcode[257];
  151766. unsigned int code;
  151767. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  151768. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151769. htbl =
  151770. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  151771. if (htbl == NULL)
  151772. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  151773. if (*pdtbl == NULL)
  151774. *pdtbl = (d_derived_tbl *)
  151775. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151776. SIZEOF(d_derived_tbl));
  151777. dtbl = *pdtbl;
  151778. dtbl->pub = htbl; /* fill in back link */
  151779. p = 0;
  151780. for (l = 1; l <= 16; l++) {
  151781. i = (int) htbl->bits[l];
  151782. if (i < 0 || p + i > 256) /* protect against table overrun */
  151783. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151784. while (i--)
  151785. huffsize[p++] = (char) l;
  151786. }
  151787. huffsize[p] = 0;
  151788. numsymbols = p;
  151789. code = 0;
  151790. si = huffsize[0];
  151791. p = 0;
  151792. while (huffsize[p]) {
  151793. while (((int) huffsize[p]) == si) {
  151794. huffcode[p++] = code;
  151795. code++;
  151796. }
  151797. if (((INT32) code) >= (((INT32) 1) << si))
  151798. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151799. code <<= 1;
  151800. si++;
  151801. }
  151802. p = 0;
  151803. for (l = 1; l <= 16; l++) {
  151804. if (htbl->bits[l]) {
  151805. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  151806. p += htbl->bits[l];
  151807. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  151808. } else {
  151809. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  151810. }
  151811. }
  151812. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  151813. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  151814. p = 0;
  151815. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  151816. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  151817. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  151818. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  151819. dtbl->look_nbits[lookbits] = l;
  151820. dtbl->look_sym[lookbits] = htbl->huffval[p];
  151821. lookbits++;
  151822. }
  151823. }
  151824. }
  151825. if (isDC) {
  151826. for (i = 0; i < numsymbols; i++) {
  151827. int sym = htbl->huffval[i];
  151828. if (sym < 0 || sym > 15)
  151829. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  151830. }
  151831. }
  151832. }
  151833. #ifdef SLOW_SHIFT_32
  151834. #define MIN_GET_BITS 15 /* minimum allowable value */
  151835. #else
  151836. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  151837. #endif
  151838. GLOBAL(boolean)
  151839. jpeg_fill_bit_buffer (bitread_working_state * state,
  151840. register bit_buf_type get_buffer, register int bits_left,
  151841. int nbits)
  151842. {
  151843. register const JOCTET * next_input_byte = state->next_input_byte;
  151844. register size_t bytes_in_buffer = state->bytes_in_buffer;
  151845. j_decompress_ptr cinfo = state->cinfo;
  151846. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  151847. while (bits_left < MIN_GET_BITS) {
  151848. register int c;
  151849. if (bytes_in_buffer == 0) {
  151850. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151851. return FALSE;
  151852. next_input_byte = cinfo->src->next_input_byte;
  151853. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151854. }
  151855. bytes_in_buffer--;
  151856. c = GETJOCTET(*next_input_byte++);
  151857. if (c == 0xFF) {
  151858. do {
  151859. if (bytes_in_buffer == 0) {
  151860. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  151861. return FALSE;
  151862. next_input_byte = cinfo->src->next_input_byte;
  151863. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  151864. }
  151865. bytes_in_buffer--;
  151866. c = GETJOCTET(*next_input_byte++);
  151867. } while (c == 0xFF);
  151868. if (c == 0) {
  151869. c = 0xFF;
  151870. } else {
  151871. cinfo->unread_marker = c;
  151872. goto no_more_bytes;
  151873. }
  151874. }
  151875. get_buffer = (get_buffer << 8) | c;
  151876. bits_left += 8;
  151877. } /* end while */
  151878. } else {
  151879. no_more_bytes:
  151880. if (nbits > bits_left) {
  151881. if (! cinfo->entropy->insufficient_data) {
  151882. WARNMS(cinfo, JWRN_HIT_MARKER);
  151883. cinfo->entropy->insufficient_data = TRUE;
  151884. }
  151885. get_buffer <<= MIN_GET_BITS - bits_left;
  151886. bits_left = MIN_GET_BITS;
  151887. }
  151888. }
  151889. state->next_input_byte = next_input_byte;
  151890. state->bytes_in_buffer = bytes_in_buffer;
  151891. state->get_buffer = get_buffer;
  151892. state->bits_left = bits_left;
  151893. return TRUE;
  151894. }
  151895. GLOBAL(int)
  151896. jpeg_huff_decode (bitread_working_state * state,
  151897. register bit_buf_type get_buffer, register int bits_left,
  151898. d_derived_tbl * htbl, int min_bits)
  151899. {
  151900. register int l = min_bits;
  151901. register INT32 code;
  151902. CHECK_BIT_BUFFER(*state, l, return -1);
  151903. code = GET_BITS(l);
  151904. while (code > htbl->maxcode[l]) {
  151905. code <<= 1;
  151906. CHECK_BIT_BUFFER(*state, 1, return -1);
  151907. code |= GET_BITS(1);
  151908. l++;
  151909. }
  151910. state->get_buffer = get_buffer;
  151911. state->bits_left = bits_left;
  151912. if (l > 16) {
  151913. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  151914. return 0; /* fake a zero as the safest result */
  151915. }
  151916. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  151917. }
  151918. LOCAL(boolean)
  151919. process_restart (j_decompress_ptr cinfo)
  151920. {
  151921. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151922. int ci;
  151923. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  151924. entropy->bitstate.bits_left = 0;
  151925. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  151926. return FALSE;
  151927. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  151928. entropy->saved.last_dc_val[ci] = 0;
  151929. entropy->restarts_to_go = cinfo->restart_interval;
  151930. if (cinfo->unread_marker == 0)
  151931. entropy->pub.insufficient_data = FALSE;
  151932. return TRUE;
  151933. }
  151934. METHODDEF(boolean)
  151935. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  151936. {
  151937. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  151938. int blkn;
  151939. BITREAD_STATE_VARS;
  151940. savable_state2 state;
  151941. if (cinfo->restart_interval) {
  151942. if (entropy->restarts_to_go == 0)
  151943. if (! process_restart(cinfo))
  151944. return FALSE;
  151945. }
  151946. if (! entropy->pub.insufficient_data) {
  151947. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  151948. ASSIGN_STATE(state, entropy->saved);
  151949. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  151950. JBLOCKROW block = MCU_data[blkn];
  151951. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  151952. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  151953. register int s, k, r;
  151954. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  151955. if (s) {
  151956. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151957. r = GET_BITS(s);
  151958. s = HUFF_EXTEND(r, s);
  151959. }
  151960. if (entropy->dc_needed[blkn]) {
  151961. int ci = cinfo->MCU_membership[blkn];
  151962. s += state.last_dc_val[ci];
  151963. state.last_dc_val[ci] = s;
  151964. (*block)[0] = (JCOEF) s;
  151965. }
  151966. if (entropy->ac_needed[blkn]) {
  151967. for (k = 1; k < DCTSIZE2; k++) {
  151968. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  151969. r = s >> 4;
  151970. s &= 15;
  151971. if (s) {
  151972. k += r;
  151973. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151974. r = GET_BITS(s);
  151975. s = HUFF_EXTEND(r, s);
  151976. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  151977. } else {
  151978. if (r != 15)
  151979. break;
  151980. k += 15;
  151981. }
  151982. }
  151983. } else {
  151984. for (k = 1; k < DCTSIZE2; k++) {
  151985. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  151986. r = s >> 4;
  151987. s &= 15;
  151988. if (s) {
  151989. k += r;
  151990. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  151991. DROP_BITS(s);
  151992. } else {
  151993. if (r != 15)
  151994. break;
  151995. k += 15;
  151996. }
  151997. }
  151998. }
  151999. }
  152000. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152001. ASSIGN_STATE(entropy->saved, state);
  152002. }
  152003. entropy->restarts_to_go--;
  152004. return TRUE;
  152005. }
  152006. GLOBAL(void)
  152007. jinit_huff_decoder (j_decompress_ptr cinfo)
  152008. {
  152009. huff_entropy_ptr2 entropy;
  152010. int i;
  152011. entropy = (huff_entropy_ptr2)
  152012. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152013. SIZEOF(huff_entropy_decoder2));
  152014. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152015. entropy->pub.start_pass = start_pass_huff_decoder;
  152016. entropy->pub.decode_mcu = decode_mcu;
  152017. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152018. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152019. }
  152020. }
  152021. /*** End of inlined file: jdhuff.c ***/
  152022. /*** Start of inlined file: jdinput.c ***/
  152023. #define JPEG_INTERNALS
  152024. typedef struct {
  152025. struct jpeg_input_controller pub; /* public fields */
  152026. boolean inheaders; /* TRUE until first SOS is reached */
  152027. } my_input_controller;
  152028. typedef my_input_controller * my_inputctl_ptr;
  152029. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152030. LOCAL(void)
  152031. initial_setup2 (j_decompress_ptr cinfo)
  152032. {
  152033. int ci;
  152034. jpeg_component_info *compptr;
  152035. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152036. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152037. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152038. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152039. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152040. if (cinfo->num_components > MAX_COMPONENTS)
  152041. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152042. MAX_COMPONENTS);
  152043. cinfo->max_h_samp_factor = 1;
  152044. cinfo->max_v_samp_factor = 1;
  152045. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152046. ci++, compptr++) {
  152047. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152048. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152049. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152050. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152051. compptr->h_samp_factor);
  152052. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152053. compptr->v_samp_factor);
  152054. }
  152055. cinfo->min_DCT_scaled_size = DCTSIZE;
  152056. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152057. ci++, compptr++) {
  152058. compptr->DCT_scaled_size = DCTSIZE;
  152059. compptr->width_in_blocks = (JDIMENSION)
  152060. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152061. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152062. compptr->height_in_blocks = (JDIMENSION)
  152063. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152064. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152065. compptr->downsampled_width = (JDIMENSION)
  152066. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152067. (long) cinfo->max_h_samp_factor);
  152068. compptr->downsampled_height = (JDIMENSION)
  152069. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152070. (long) cinfo->max_v_samp_factor);
  152071. compptr->component_needed = TRUE;
  152072. compptr->quant_table = NULL;
  152073. }
  152074. cinfo->total_iMCU_rows = (JDIMENSION)
  152075. jdiv_round_up((long) cinfo->image_height,
  152076. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152077. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152078. cinfo->inputctl->has_multiple_scans = TRUE;
  152079. else
  152080. cinfo->inputctl->has_multiple_scans = FALSE;
  152081. }
  152082. LOCAL(void)
  152083. per_scan_setup2 (j_decompress_ptr cinfo)
  152084. {
  152085. int ci, mcublks, tmp;
  152086. jpeg_component_info *compptr;
  152087. if (cinfo->comps_in_scan == 1) {
  152088. compptr = cinfo->cur_comp_info[0];
  152089. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152090. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152091. compptr->MCU_width = 1;
  152092. compptr->MCU_height = 1;
  152093. compptr->MCU_blocks = 1;
  152094. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152095. compptr->last_col_width = 1;
  152096. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152097. if (tmp == 0) tmp = compptr->v_samp_factor;
  152098. compptr->last_row_height = tmp;
  152099. cinfo->blocks_in_MCU = 1;
  152100. cinfo->MCU_membership[0] = 0;
  152101. } else {
  152102. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152103. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152104. MAX_COMPS_IN_SCAN);
  152105. cinfo->MCUs_per_row = (JDIMENSION)
  152106. jdiv_round_up((long) cinfo->image_width,
  152107. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152108. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152109. jdiv_round_up((long) cinfo->image_height,
  152110. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152111. cinfo->blocks_in_MCU = 0;
  152112. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152113. compptr = cinfo->cur_comp_info[ci];
  152114. compptr->MCU_width = compptr->h_samp_factor;
  152115. compptr->MCU_height = compptr->v_samp_factor;
  152116. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152117. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152118. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152119. if (tmp == 0) tmp = compptr->MCU_width;
  152120. compptr->last_col_width = tmp;
  152121. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152122. if (tmp == 0) tmp = compptr->MCU_height;
  152123. compptr->last_row_height = tmp;
  152124. mcublks = compptr->MCU_blocks;
  152125. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152126. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152127. while (mcublks-- > 0) {
  152128. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152129. }
  152130. }
  152131. }
  152132. }
  152133. LOCAL(void)
  152134. latch_quant_tables (j_decompress_ptr cinfo)
  152135. {
  152136. int ci, qtblno;
  152137. jpeg_component_info *compptr;
  152138. JQUANT_TBL * qtbl;
  152139. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152140. compptr = cinfo->cur_comp_info[ci];
  152141. if (compptr->quant_table != NULL)
  152142. continue;
  152143. qtblno = compptr->quant_tbl_no;
  152144. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152145. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152146. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152147. qtbl = (JQUANT_TBL *)
  152148. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152149. SIZEOF(JQUANT_TBL));
  152150. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152151. compptr->quant_table = qtbl;
  152152. }
  152153. }
  152154. METHODDEF(void)
  152155. start_input_pass2 (j_decompress_ptr cinfo)
  152156. {
  152157. per_scan_setup2(cinfo);
  152158. latch_quant_tables(cinfo);
  152159. (*cinfo->entropy->start_pass) (cinfo);
  152160. (*cinfo->coef->start_input_pass) (cinfo);
  152161. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152162. }
  152163. METHODDEF(void)
  152164. finish_input_pass (j_decompress_ptr cinfo)
  152165. {
  152166. cinfo->inputctl->consume_input = consume_markers;
  152167. }
  152168. METHODDEF(int)
  152169. consume_markers (j_decompress_ptr cinfo)
  152170. {
  152171. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152172. int val;
  152173. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152174. return JPEG_REACHED_EOI;
  152175. val = (*cinfo->marker->read_markers) (cinfo);
  152176. switch (val) {
  152177. case JPEG_REACHED_SOS: /* Found SOS */
  152178. if (inputctl->inheaders) { /* 1st SOS */
  152179. initial_setup2(cinfo);
  152180. inputctl->inheaders = FALSE;
  152181. } else { /* 2nd or later SOS marker */
  152182. if (! inputctl->pub.has_multiple_scans)
  152183. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152184. start_input_pass2(cinfo);
  152185. }
  152186. break;
  152187. case JPEG_REACHED_EOI: /* Found EOI */
  152188. inputctl->pub.eoi_reached = TRUE;
  152189. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152190. if (cinfo->marker->saw_SOF)
  152191. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152192. } else {
  152193. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152194. cinfo->output_scan_number = cinfo->input_scan_number;
  152195. }
  152196. break;
  152197. case JPEG_SUSPENDED:
  152198. break;
  152199. }
  152200. return val;
  152201. }
  152202. METHODDEF(void)
  152203. reset_input_controller (j_decompress_ptr cinfo)
  152204. {
  152205. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152206. inputctl->pub.consume_input = consume_markers;
  152207. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152208. inputctl->pub.eoi_reached = FALSE;
  152209. inputctl->inheaders = TRUE;
  152210. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152211. (*cinfo->marker->reset_marker_reader) (cinfo);
  152212. cinfo->coef_bits = NULL;
  152213. }
  152214. GLOBAL(void)
  152215. jinit_input_controller (j_decompress_ptr cinfo)
  152216. {
  152217. my_inputctl_ptr inputctl;
  152218. inputctl = (my_inputctl_ptr)
  152219. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152220. SIZEOF(my_input_controller));
  152221. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152222. inputctl->pub.consume_input = consume_markers;
  152223. inputctl->pub.reset_input_controller = reset_input_controller;
  152224. inputctl->pub.start_input_pass = start_input_pass2;
  152225. inputctl->pub.finish_input_pass = finish_input_pass;
  152226. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152227. inputctl->pub.eoi_reached = FALSE;
  152228. inputctl->inheaders = TRUE;
  152229. }
  152230. /*** End of inlined file: jdinput.c ***/
  152231. /*** Start of inlined file: jdmainct.c ***/
  152232. #define JPEG_INTERNALS
  152233. typedef struct {
  152234. struct jpeg_d_main_controller pub; /* public fields */
  152235. JSAMPARRAY buffer[MAX_COMPONENTS];
  152236. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152237. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152238. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152239. int whichptr; /* indicates which pointer set is now in use */
  152240. int context_state; /* process_data state machine status */
  152241. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152242. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152243. } my_main_controller4;
  152244. typedef my_main_controller4 * my_main_ptr4;
  152245. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152246. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152247. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152248. METHODDEF(void) process_data_simple_main2
  152249. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152250. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152251. METHODDEF(void) process_data_context_main
  152252. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152253. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152254. #ifdef QUANT_2PASS_SUPPORTED
  152255. METHODDEF(void) process_data_crank_post
  152256. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152257. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152258. #endif
  152259. LOCAL(void)
  152260. alloc_funny_pointers (j_decompress_ptr cinfo)
  152261. {
  152262. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152263. int ci, rgroup;
  152264. int M = cinfo->min_DCT_scaled_size;
  152265. jpeg_component_info *compptr;
  152266. JSAMPARRAY xbuf;
  152267. main_->xbuffer[0] = (JSAMPIMAGE)
  152268. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152269. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152270. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152271. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152272. ci++, compptr++) {
  152273. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152274. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152275. xbuf = (JSAMPARRAY)
  152276. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152277. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152278. xbuf += rgroup; /* want one row group at negative offsets */
  152279. main_->xbuffer[0][ci] = xbuf;
  152280. xbuf += rgroup * (M + 4);
  152281. main_->xbuffer[1][ci] = xbuf;
  152282. }
  152283. }
  152284. LOCAL(void)
  152285. make_funny_pointers (j_decompress_ptr cinfo)
  152286. {
  152287. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152288. int ci, i, rgroup;
  152289. int M = cinfo->min_DCT_scaled_size;
  152290. jpeg_component_info *compptr;
  152291. JSAMPARRAY buf, xbuf0, xbuf1;
  152292. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152293. ci++, compptr++) {
  152294. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152295. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152296. xbuf0 = main_->xbuffer[0][ci];
  152297. xbuf1 = main_->xbuffer[1][ci];
  152298. buf = main_->buffer[ci];
  152299. for (i = 0; i < rgroup * (M + 2); i++) {
  152300. xbuf0[i] = xbuf1[i] = buf[i];
  152301. }
  152302. for (i = 0; i < rgroup * 2; i++) {
  152303. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152304. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152305. }
  152306. for (i = 0; i < rgroup; i++) {
  152307. xbuf0[i - rgroup] = xbuf0[0];
  152308. }
  152309. }
  152310. }
  152311. LOCAL(void)
  152312. set_wraparound_pointers (j_decompress_ptr cinfo)
  152313. {
  152314. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152315. int ci, i, rgroup;
  152316. int M = cinfo->min_DCT_scaled_size;
  152317. jpeg_component_info *compptr;
  152318. JSAMPARRAY xbuf0, xbuf1;
  152319. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152320. ci++, compptr++) {
  152321. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152322. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152323. xbuf0 = main_->xbuffer[0][ci];
  152324. xbuf1 = main_->xbuffer[1][ci];
  152325. for (i = 0; i < rgroup; i++) {
  152326. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152327. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152328. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152329. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152330. }
  152331. }
  152332. }
  152333. LOCAL(void)
  152334. set_bottom_pointers (j_decompress_ptr cinfo)
  152335. {
  152336. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152337. int ci, i, rgroup, iMCUheight, rows_left;
  152338. jpeg_component_info *compptr;
  152339. JSAMPARRAY xbuf;
  152340. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152341. ci++, compptr++) {
  152342. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152343. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152344. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152345. if (rows_left == 0) rows_left = iMCUheight;
  152346. if (ci == 0) {
  152347. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152348. }
  152349. xbuf = main_->xbuffer[main_->whichptr][ci];
  152350. for (i = 0; i < rgroup * 2; i++) {
  152351. xbuf[rows_left + i] = xbuf[rows_left-1];
  152352. }
  152353. }
  152354. }
  152355. METHODDEF(void)
  152356. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152357. {
  152358. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152359. switch (pass_mode) {
  152360. case JBUF_PASS_THRU:
  152361. if (cinfo->upsample->need_context_rows) {
  152362. main_->pub.process_data = process_data_context_main;
  152363. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152364. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152365. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152366. main_->iMCU_row_ctr = 0;
  152367. } else {
  152368. main_->pub.process_data = process_data_simple_main2;
  152369. }
  152370. main_->buffer_full = FALSE; /* Mark buffer empty */
  152371. main_->rowgroup_ctr = 0;
  152372. break;
  152373. #ifdef QUANT_2PASS_SUPPORTED
  152374. case JBUF_CRANK_DEST:
  152375. main_->pub.process_data = process_data_crank_post;
  152376. break;
  152377. #endif
  152378. default:
  152379. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152380. break;
  152381. }
  152382. }
  152383. METHODDEF(void)
  152384. process_data_simple_main2 (j_decompress_ptr cinfo,
  152385. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152386. JDIMENSION out_rows_avail)
  152387. {
  152388. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152389. JDIMENSION rowgroups_avail;
  152390. if (! main_->buffer_full) {
  152391. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152392. return; /* suspension forced, can do nothing more */
  152393. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152394. }
  152395. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152396. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152397. &main_->rowgroup_ctr, rowgroups_avail,
  152398. output_buf, out_row_ctr, out_rows_avail);
  152399. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152400. main_->buffer_full = FALSE;
  152401. main_->rowgroup_ctr = 0;
  152402. }
  152403. }
  152404. METHODDEF(void)
  152405. process_data_context_main (j_decompress_ptr cinfo,
  152406. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152407. JDIMENSION out_rows_avail)
  152408. {
  152409. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152410. if (! main_->buffer_full) {
  152411. if (! (*cinfo->coef->decompress_data) (cinfo,
  152412. main_->xbuffer[main_->whichptr]))
  152413. return; /* suspension forced, can do nothing more */
  152414. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152415. main_->iMCU_row_ctr++; /* count rows received */
  152416. }
  152417. switch (main_->context_state) {
  152418. case CTX_POSTPONED_ROW:
  152419. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152420. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152421. output_buf, out_row_ctr, out_rows_avail);
  152422. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152423. return; /* Need to suspend */
  152424. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152425. if (*out_row_ctr >= out_rows_avail)
  152426. return; /* Postprocessor exactly filled output buf */
  152427. case CTX_PREPARE_FOR_IMCU:
  152428. main_->rowgroup_ctr = 0;
  152429. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152430. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152431. set_bottom_pointers(cinfo);
  152432. main_->context_state = CTX_PROCESS_IMCU;
  152433. case CTX_PROCESS_IMCU:
  152434. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152435. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152436. output_buf, out_row_ctr, out_rows_avail);
  152437. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152438. return; /* Need to suspend */
  152439. if (main_->iMCU_row_ctr == 1)
  152440. set_wraparound_pointers(cinfo);
  152441. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152442. main_->buffer_full = FALSE;
  152443. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152444. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152445. main_->context_state = CTX_POSTPONED_ROW;
  152446. }
  152447. }
  152448. #ifdef QUANT_2PASS_SUPPORTED
  152449. METHODDEF(void)
  152450. process_data_crank_post (j_decompress_ptr cinfo,
  152451. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152452. JDIMENSION out_rows_avail)
  152453. {
  152454. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152455. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152456. output_buf, out_row_ctr, out_rows_avail);
  152457. }
  152458. #endif /* QUANT_2PASS_SUPPORTED */
  152459. GLOBAL(void)
  152460. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152461. {
  152462. my_main_ptr4 main_;
  152463. int ci, rgroup, ngroups;
  152464. jpeg_component_info *compptr;
  152465. main_ = (my_main_ptr4)
  152466. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152467. SIZEOF(my_main_controller4));
  152468. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152469. main_->pub.start_pass = start_pass_main2;
  152470. if (need_full_buffer) /* shouldn't happen */
  152471. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152472. if (cinfo->upsample->need_context_rows) {
  152473. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152474. ERREXIT(cinfo, JERR_NOTIMPL);
  152475. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152476. ngroups = cinfo->min_DCT_scaled_size + 2;
  152477. } else {
  152478. ngroups = cinfo->min_DCT_scaled_size;
  152479. }
  152480. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152481. ci++, compptr++) {
  152482. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152483. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152484. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152485. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152486. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152487. (JDIMENSION) (rgroup * ngroups));
  152488. }
  152489. }
  152490. /*** End of inlined file: jdmainct.c ***/
  152491. /*** Start of inlined file: jdmarker.c ***/
  152492. #define JPEG_INTERNALS
  152493. typedef struct {
  152494. struct jpeg_marker_reader pub; /* public fields */
  152495. jpeg_marker_parser_method process_COM;
  152496. jpeg_marker_parser_method process_APPn[16];
  152497. unsigned int length_limit_COM;
  152498. unsigned int length_limit_APPn[16];
  152499. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152500. unsigned int bytes_read; /* data bytes read so far in marker */
  152501. } my_marker_reader;
  152502. typedef my_marker_reader * my_marker_ptr2;
  152503. #define INPUT_VARS(cinfo) \
  152504. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152505. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152506. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152507. #define INPUT_SYNC(cinfo) \
  152508. ( datasrc->next_input_byte = next_input_byte, \
  152509. datasrc->bytes_in_buffer = bytes_in_buffer )
  152510. #define INPUT_RELOAD(cinfo) \
  152511. ( next_input_byte = datasrc->next_input_byte, \
  152512. bytes_in_buffer = datasrc->bytes_in_buffer )
  152513. #define MAKE_BYTE_AVAIL(cinfo,action) \
  152514. if (bytes_in_buffer == 0) { \
  152515. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  152516. { action; } \
  152517. INPUT_RELOAD(cinfo); \
  152518. }
  152519. #define INPUT_BYTE(cinfo,V,action) \
  152520. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152521. bytes_in_buffer--; \
  152522. V = GETJOCTET(*next_input_byte++); )
  152523. #define INPUT_2BYTES(cinfo,V,action) \
  152524. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  152525. bytes_in_buffer--; \
  152526. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  152527. MAKE_BYTE_AVAIL(cinfo,action); \
  152528. bytes_in_buffer--; \
  152529. V += GETJOCTET(*next_input_byte++); )
  152530. LOCAL(boolean)
  152531. get_soi (j_decompress_ptr cinfo)
  152532. {
  152533. int i;
  152534. TRACEMS(cinfo, 1, JTRC_SOI);
  152535. if (cinfo->marker->saw_SOI)
  152536. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  152537. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  152538. cinfo->arith_dc_L[i] = 0;
  152539. cinfo->arith_dc_U[i] = 1;
  152540. cinfo->arith_ac_K[i] = 5;
  152541. }
  152542. cinfo->restart_interval = 0;
  152543. cinfo->jpeg_color_space = JCS_UNKNOWN;
  152544. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  152545. cinfo->saw_JFIF_marker = FALSE;
  152546. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  152547. cinfo->JFIF_minor_version = 1;
  152548. cinfo->density_unit = 0;
  152549. cinfo->X_density = 1;
  152550. cinfo->Y_density = 1;
  152551. cinfo->saw_Adobe_marker = FALSE;
  152552. cinfo->Adobe_transform = 0;
  152553. cinfo->marker->saw_SOI = TRUE;
  152554. return TRUE;
  152555. }
  152556. LOCAL(boolean)
  152557. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  152558. {
  152559. INT32 length;
  152560. int c, ci;
  152561. jpeg_component_info * compptr;
  152562. INPUT_VARS(cinfo);
  152563. cinfo->progressive_mode = is_prog;
  152564. cinfo->arith_code = is_arith;
  152565. INPUT_2BYTES(cinfo, length, return FALSE);
  152566. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  152567. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  152568. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  152569. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  152570. length -= 8;
  152571. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  152572. (int) cinfo->image_width, (int) cinfo->image_height,
  152573. cinfo->num_components);
  152574. if (cinfo->marker->saw_SOF)
  152575. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  152576. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  152577. || cinfo->num_components <= 0)
  152578. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  152579. if (length != (cinfo->num_components * 3))
  152580. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152581. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  152582. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  152583. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152584. cinfo->num_components * SIZEOF(jpeg_component_info));
  152585. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152586. ci++, compptr++) {
  152587. compptr->component_index = ci;
  152588. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  152589. INPUT_BYTE(cinfo, c, return FALSE);
  152590. compptr->h_samp_factor = (c >> 4) & 15;
  152591. compptr->v_samp_factor = (c ) & 15;
  152592. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  152593. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  152594. compptr->component_id, compptr->h_samp_factor,
  152595. compptr->v_samp_factor, compptr->quant_tbl_no);
  152596. }
  152597. cinfo->marker->saw_SOF = TRUE;
  152598. INPUT_SYNC(cinfo);
  152599. return TRUE;
  152600. }
  152601. LOCAL(boolean)
  152602. get_sos (j_decompress_ptr cinfo)
  152603. {
  152604. INT32 length;
  152605. int i, ci, n, c, cc;
  152606. jpeg_component_info * compptr;
  152607. INPUT_VARS(cinfo);
  152608. if (! cinfo->marker->saw_SOF)
  152609. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  152610. INPUT_2BYTES(cinfo, length, return FALSE);
  152611. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  152612. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  152613. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  152614. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152615. cinfo->comps_in_scan = n;
  152616. for (i = 0; i < n; i++) {
  152617. INPUT_BYTE(cinfo, cc, return FALSE);
  152618. INPUT_BYTE(cinfo, c, return FALSE);
  152619. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152620. ci++, compptr++) {
  152621. if (cc == compptr->component_id)
  152622. goto id_found;
  152623. }
  152624. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  152625. id_found:
  152626. cinfo->cur_comp_info[i] = compptr;
  152627. compptr->dc_tbl_no = (c >> 4) & 15;
  152628. compptr->ac_tbl_no = (c ) & 15;
  152629. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  152630. compptr->dc_tbl_no, compptr->ac_tbl_no);
  152631. }
  152632. INPUT_BYTE(cinfo, c, return FALSE);
  152633. cinfo->Ss = c;
  152634. INPUT_BYTE(cinfo, c, return FALSE);
  152635. cinfo->Se = c;
  152636. INPUT_BYTE(cinfo, c, return FALSE);
  152637. cinfo->Ah = (c >> 4) & 15;
  152638. cinfo->Al = (c ) & 15;
  152639. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  152640. cinfo->Ah, cinfo->Al);
  152641. cinfo->marker->next_restart_num = 0;
  152642. cinfo->input_scan_number++;
  152643. INPUT_SYNC(cinfo);
  152644. return TRUE;
  152645. }
  152646. #ifdef D_ARITH_CODING_SUPPORTED
  152647. LOCAL(boolean)
  152648. get_dac (j_decompress_ptr cinfo)
  152649. {
  152650. INT32 length;
  152651. int index, val;
  152652. INPUT_VARS(cinfo);
  152653. INPUT_2BYTES(cinfo, length, return FALSE);
  152654. length -= 2;
  152655. while (length > 0) {
  152656. INPUT_BYTE(cinfo, index, return FALSE);
  152657. INPUT_BYTE(cinfo, val, return FALSE);
  152658. length -= 2;
  152659. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  152660. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  152661. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  152662. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  152663. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  152664. } else { /* define DC table */
  152665. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  152666. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  152667. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  152668. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  152669. }
  152670. }
  152671. if (length != 0)
  152672. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152673. INPUT_SYNC(cinfo);
  152674. return TRUE;
  152675. }
  152676. #else /* ! D_ARITH_CODING_SUPPORTED */
  152677. #define get_dac(cinfo) skip_variable(cinfo)
  152678. #endif /* D_ARITH_CODING_SUPPORTED */
  152679. LOCAL(boolean)
  152680. get_dht (j_decompress_ptr cinfo)
  152681. {
  152682. INT32 length;
  152683. UINT8 bits[17];
  152684. UINT8 huffval[256];
  152685. int i, index, count;
  152686. JHUFF_TBL **htblptr;
  152687. INPUT_VARS(cinfo);
  152688. INPUT_2BYTES(cinfo, length, return FALSE);
  152689. length -= 2;
  152690. while (length > 16) {
  152691. INPUT_BYTE(cinfo, index, return FALSE);
  152692. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  152693. bits[0] = 0;
  152694. count = 0;
  152695. for (i = 1; i <= 16; i++) {
  152696. INPUT_BYTE(cinfo, bits[i], return FALSE);
  152697. count += bits[i];
  152698. }
  152699. length -= 1 + 16;
  152700. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152701. bits[1], bits[2], bits[3], bits[4],
  152702. bits[5], bits[6], bits[7], bits[8]);
  152703. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  152704. bits[9], bits[10], bits[11], bits[12],
  152705. bits[13], bits[14], bits[15], bits[16]);
  152706. if (count > 256 || ((INT32) count) > length)
  152707. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152708. for (i = 0; i < count; i++)
  152709. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  152710. length -= count;
  152711. if (index & 0x10) { /* AC table definition */
  152712. index -= 0x10;
  152713. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  152714. } else { /* DC table definition */
  152715. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  152716. }
  152717. if (index < 0 || index >= NUM_HUFF_TBLS)
  152718. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  152719. if (*htblptr == NULL)
  152720. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  152721. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  152722. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  152723. }
  152724. if (length != 0)
  152725. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152726. INPUT_SYNC(cinfo);
  152727. return TRUE;
  152728. }
  152729. LOCAL(boolean)
  152730. get_dqt (j_decompress_ptr cinfo)
  152731. {
  152732. INT32 length;
  152733. int n, i, prec;
  152734. unsigned int tmp;
  152735. JQUANT_TBL *quant_ptr;
  152736. INPUT_VARS(cinfo);
  152737. INPUT_2BYTES(cinfo, length, return FALSE);
  152738. length -= 2;
  152739. while (length > 0) {
  152740. INPUT_BYTE(cinfo, n, return FALSE);
  152741. prec = n >> 4;
  152742. n &= 0x0F;
  152743. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  152744. if (n >= NUM_QUANT_TBLS)
  152745. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  152746. if (cinfo->quant_tbl_ptrs[n] == NULL)
  152747. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  152748. quant_ptr = cinfo->quant_tbl_ptrs[n];
  152749. for (i = 0; i < DCTSIZE2; i++) {
  152750. if (prec)
  152751. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152752. else
  152753. INPUT_BYTE(cinfo, tmp, return FALSE);
  152754. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  152755. }
  152756. if (cinfo->err->trace_level >= 2) {
  152757. for (i = 0; i < DCTSIZE2; i += 8) {
  152758. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  152759. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  152760. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  152761. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  152762. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  152763. }
  152764. }
  152765. length -= DCTSIZE2+1;
  152766. if (prec) length -= DCTSIZE2;
  152767. }
  152768. if (length != 0)
  152769. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152770. INPUT_SYNC(cinfo);
  152771. return TRUE;
  152772. }
  152773. LOCAL(boolean)
  152774. get_dri (j_decompress_ptr cinfo)
  152775. {
  152776. INT32 length;
  152777. unsigned int tmp;
  152778. INPUT_VARS(cinfo);
  152779. INPUT_2BYTES(cinfo, length, return FALSE);
  152780. if (length != 4)
  152781. ERREXIT(cinfo, JERR_BAD_LENGTH);
  152782. INPUT_2BYTES(cinfo, tmp, return FALSE);
  152783. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  152784. cinfo->restart_interval = tmp;
  152785. INPUT_SYNC(cinfo);
  152786. return TRUE;
  152787. }
  152788. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  152789. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  152790. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  152791. LOCAL(void)
  152792. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152793. unsigned int datalen, INT32 remaining)
  152794. {
  152795. INT32 totallen = (INT32) datalen + remaining;
  152796. if (datalen >= APP0_DATA_LEN &&
  152797. GETJOCTET(data[0]) == 0x4A &&
  152798. GETJOCTET(data[1]) == 0x46 &&
  152799. GETJOCTET(data[2]) == 0x49 &&
  152800. GETJOCTET(data[3]) == 0x46 &&
  152801. GETJOCTET(data[4]) == 0) {
  152802. cinfo->saw_JFIF_marker = TRUE;
  152803. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  152804. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  152805. cinfo->density_unit = GETJOCTET(data[7]);
  152806. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  152807. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  152808. if (cinfo->JFIF_major_version != 1)
  152809. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  152810. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  152811. TRACEMS5(cinfo, 1, JTRC_JFIF,
  152812. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  152813. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  152814. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  152815. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  152816. GETJOCTET(data[12]), GETJOCTET(data[13]));
  152817. totallen -= APP0_DATA_LEN;
  152818. if (totallen !=
  152819. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  152820. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  152821. } else if (datalen >= 6 &&
  152822. GETJOCTET(data[0]) == 0x4A &&
  152823. GETJOCTET(data[1]) == 0x46 &&
  152824. GETJOCTET(data[2]) == 0x58 &&
  152825. GETJOCTET(data[3]) == 0x58 &&
  152826. GETJOCTET(data[4]) == 0) {
  152827. switch (GETJOCTET(data[5])) {
  152828. case 0x10:
  152829. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  152830. break;
  152831. case 0x11:
  152832. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  152833. break;
  152834. case 0x13:
  152835. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  152836. break;
  152837. default:
  152838. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  152839. GETJOCTET(data[5]), (int) totallen);
  152840. break;
  152841. }
  152842. } else {
  152843. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  152844. }
  152845. }
  152846. LOCAL(void)
  152847. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  152848. unsigned int datalen, INT32 remaining)
  152849. {
  152850. unsigned int version, flags0, flags1, transform;
  152851. if (datalen >= APP14_DATA_LEN &&
  152852. GETJOCTET(data[0]) == 0x41 &&
  152853. GETJOCTET(data[1]) == 0x64 &&
  152854. GETJOCTET(data[2]) == 0x6F &&
  152855. GETJOCTET(data[3]) == 0x62 &&
  152856. GETJOCTET(data[4]) == 0x65) {
  152857. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  152858. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  152859. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  152860. transform = GETJOCTET(data[11]);
  152861. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  152862. cinfo->saw_Adobe_marker = TRUE;
  152863. cinfo->Adobe_transform = (UINT8) transform;
  152864. } else {
  152865. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  152866. }
  152867. }
  152868. METHODDEF(boolean)
  152869. get_interesting_appn (j_decompress_ptr cinfo)
  152870. {
  152871. INT32 length;
  152872. JOCTET b[APPN_DATA_LEN];
  152873. unsigned int i, numtoread;
  152874. INPUT_VARS(cinfo);
  152875. INPUT_2BYTES(cinfo, length, return FALSE);
  152876. length -= 2;
  152877. if (length >= APPN_DATA_LEN)
  152878. numtoread = APPN_DATA_LEN;
  152879. else if (length > 0)
  152880. numtoread = (unsigned int) length;
  152881. else
  152882. numtoread = 0;
  152883. for (i = 0; i < numtoread; i++)
  152884. INPUT_BYTE(cinfo, b[i], return FALSE);
  152885. length -= numtoread;
  152886. switch (cinfo->unread_marker) {
  152887. case M_APP0:
  152888. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  152889. break;
  152890. case M_APP14:
  152891. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  152892. break;
  152893. default:
  152894. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  152895. break;
  152896. }
  152897. INPUT_SYNC(cinfo);
  152898. if (length > 0)
  152899. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152900. return TRUE;
  152901. }
  152902. #ifdef SAVE_MARKERS_SUPPORTED
  152903. METHODDEF(boolean)
  152904. save_marker (j_decompress_ptr cinfo)
  152905. {
  152906. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  152907. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  152908. unsigned int bytes_read, data_length;
  152909. JOCTET FAR * data;
  152910. INT32 length = 0;
  152911. INPUT_VARS(cinfo);
  152912. if (cur_marker == NULL) {
  152913. INPUT_2BYTES(cinfo, length, return FALSE);
  152914. length -= 2;
  152915. if (length >= 0) { /* watch out for bogus length word */
  152916. unsigned int limit;
  152917. if (cinfo->unread_marker == (int) M_COM)
  152918. limit = marker->length_limit_COM;
  152919. else
  152920. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  152921. if ((unsigned int) length < limit)
  152922. limit = (unsigned int) length;
  152923. cur_marker = (jpeg_saved_marker_ptr)
  152924. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152925. SIZEOF(struct jpeg_marker_struct) + limit);
  152926. cur_marker->next = NULL;
  152927. cur_marker->marker = (UINT8) cinfo->unread_marker;
  152928. cur_marker->original_length = (unsigned int) length;
  152929. cur_marker->data_length = limit;
  152930. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  152931. marker->cur_marker = cur_marker;
  152932. marker->bytes_read = 0;
  152933. bytes_read = 0;
  152934. data_length = limit;
  152935. } else {
  152936. bytes_read = data_length = 0;
  152937. data = NULL;
  152938. }
  152939. } else {
  152940. bytes_read = marker->bytes_read;
  152941. data_length = cur_marker->data_length;
  152942. data = cur_marker->data + bytes_read;
  152943. }
  152944. while (bytes_read < data_length) {
  152945. INPUT_SYNC(cinfo); /* move the restart point to here */
  152946. marker->bytes_read = bytes_read;
  152947. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  152948. while (bytes_read < data_length && bytes_in_buffer > 0) {
  152949. *data++ = *next_input_byte++;
  152950. bytes_in_buffer--;
  152951. bytes_read++;
  152952. }
  152953. }
  152954. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  152955. if (cinfo->marker_list == NULL) {
  152956. cinfo->marker_list = cur_marker;
  152957. } else {
  152958. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  152959. while (prev->next != NULL)
  152960. prev = prev->next;
  152961. prev->next = cur_marker;
  152962. }
  152963. data = cur_marker->data;
  152964. length = cur_marker->original_length - data_length;
  152965. }
  152966. marker->cur_marker = NULL;
  152967. switch (cinfo->unread_marker) {
  152968. case M_APP0:
  152969. examine_app0(cinfo, data, data_length, length);
  152970. break;
  152971. case M_APP14:
  152972. examine_app14(cinfo, data, data_length, length);
  152973. break;
  152974. default:
  152975. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  152976. (int) (data_length + length));
  152977. break;
  152978. }
  152979. INPUT_SYNC(cinfo); /* do before skip_input_data */
  152980. if (length > 0)
  152981. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152982. return TRUE;
  152983. }
  152984. #endif /* SAVE_MARKERS_SUPPORTED */
  152985. METHODDEF(boolean)
  152986. skip_variable (j_decompress_ptr cinfo)
  152987. {
  152988. INT32 length;
  152989. INPUT_VARS(cinfo);
  152990. INPUT_2BYTES(cinfo, length, return FALSE);
  152991. length -= 2;
  152992. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  152993. INPUT_SYNC(cinfo); /* do before skip_input_data */
  152994. if (length > 0)
  152995. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  152996. return TRUE;
  152997. }
  152998. LOCAL(boolean)
  152999. next_marker (j_decompress_ptr cinfo)
  153000. {
  153001. int c;
  153002. INPUT_VARS(cinfo);
  153003. for (;;) {
  153004. INPUT_BYTE(cinfo, c, return FALSE);
  153005. while (c != 0xFF) {
  153006. cinfo->marker->discarded_bytes++;
  153007. INPUT_SYNC(cinfo);
  153008. INPUT_BYTE(cinfo, c, return FALSE);
  153009. }
  153010. do {
  153011. INPUT_BYTE(cinfo, c, return FALSE);
  153012. } while (c == 0xFF);
  153013. if (c != 0)
  153014. break; /* found a valid marker, exit loop */
  153015. cinfo->marker->discarded_bytes += 2;
  153016. INPUT_SYNC(cinfo);
  153017. }
  153018. if (cinfo->marker->discarded_bytes != 0) {
  153019. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153020. cinfo->marker->discarded_bytes = 0;
  153021. }
  153022. cinfo->unread_marker = c;
  153023. INPUT_SYNC(cinfo);
  153024. return TRUE;
  153025. }
  153026. LOCAL(boolean)
  153027. first_marker (j_decompress_ptr cinfo)
  153028. {
  153029. int c, c2;
  153030. INPUT_VARS(cinfo);
  153031. INPUT_BYTE(cinfo, c, return FALSE);
  153032. INPUT_BYTE(cinfo, c2, return FALSE);
  153033. if (c != 0xFF || c2 != (int) M_SOI)
  153034. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153035. cinfo->unread_marker = c2;
  153036. INPUT_SYNC(cinfo);
  153037. return TRUE;
  153038. }
  153039. METHODDEF(int)
  153040. read_markers (j_decompress_ptr cinfo)
  153041. {
  153042. for (;;) {
  153043. if (cinfo->unread_marker == 0) {
  153044. if (! cinfo->marker->saw_SOI) {
  153045. if (! first_marker(cinfo))
  153046. return JPEG_SUSPENDED;
  153047. } else {
  153048. if (! next_marker(cinfo))
  153049. return JPEG_SUSPENDED;
  153050. }
  153051. }
  153052. switch (cinfo->unread_marker) {
  153053. case M_SOI:
  153054. if (! get_soi(cinfo))
  153055. return JPEG_SUSPENDED;
  153056. break;
  153057. case M_SOF0: /* Baseline */
  153058. case M_SOF1: /* Extended sequential, Huffman */
  153059. if (! get_sof(cinfo, FALSE, FALSE))
  153060. return JPEG_SUSPENDED;
  153061. break;
  153062. case M_SOF2: /* Progressive, Huffman */
  153063. if (! get_sof(cinfo, TRUE, FALSE))
  153064. return JPEG_SUSPENDED;
  153065. break;
  153066. case M_SOF9: /* Extended sequential, arithmetic */
  153067. if (! get_sof(cinfo, FALSE, TRUE))
  153068. return JPEG_SUSPENDED;
  153069. break;
  153070. case M_SOF10: /* Progressive, arithmetic */
  153071. if (! get_sof(cinfo, TRUE, TRUE))
  153072. return JPEG_SUSPENDED;
  153073. break;
  153074. case M_SOF3: /* Lossless, Huffman */
  153075. case M_SOF5: /* Differential sequential, Huffman */
  153076. case M_SOF6: /* Differential progressive, Huffman */
  153077. case M_SOF7: /* Differential lossless, Huffman */
  153078. case M_JPG: /* Reserved for JPEG extensions */
  153079. case M_SOF11: /* Lossless, arithmetic */
  153080. case M_SOF13: /* Differential sequential, arithmetic */
  153081. case M_SOF14: /* Differential progressive, arithmetic */
  153082. case M_SOF15: /* Differential lossless, arithmetic */
  153083. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153084. break;
  153085. case M_SOS:
  153086. if (! get_sos(cinfo))
  153087. return JPEG_SUSPENDED;
  153088. cinfo->unread_marker = 0; /* processed the marker */
  153089. return JPEG_REACHED_SOS;
  153090. case M_EOI:
  153091. TRACEMS(cinfo, 1, JTRC_EOI);
  153092. cinfo->unread_marker = 0; /* processed the marker */
  153093. return JPEG_REACHED_EOI;
  153094. case M_DAC:
  153095. if (! get_dac(cinfo))
  153096. return JPEG_SUSPENDED;
  153097. break;
  153098. case M_DHT:
  153099. if (! get_dht(cinfo))
  153100. return JPEG_SUSPENDED;
  153101. break;
  153102. case M_DQT:
  153103. if (! get_dqt(cinfo))
  153104. return JPEG_SUSPENDED;
  153105. break;
  153106. case M_DRI:
  153107. if (! get_dri(cinfo))
  153108. return JPEG_SUSPENDED;
  153109. break;
  153110. case M_APP0:
  153111. case M_APP1:
  153112. case M_APP2:
  153113. case M_APP3:
  153114. case M_APP4:
  153115. case M_APP5:
  153116. case M_APP6:
  153117. case M_APP7:
  153118. case M_APP8:
  153119. case M_APP9:
  153120. case M_APP10:
  153121. case M_APP11:
  153122. case M_APP12:
  153123. case M_APP13:
  153124. case M_APP14:
  153125. case M_APP15:
  153126. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153127. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153128. return JPEG_SUSPENDED;
  153129. break;
  153130. case M_COM:
  153131. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153132. return JPEG_SUSPENDED;
  153133. break;
  153134. case M_RST0: /* these are all parameterless */
  153135. case M_RST1:
  153136. case M_RST2:
  153137. case M_RST3:
  153138. case M_RST4:
  153139. case M_RST5:
  153140. case M_RST6:
  153141. case M_RST7:
  153142. case M_TEM:
  153143. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153144. break;
  153145. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153146. if (! skip_variable(cinfo))
  153147. return JPEG_SUSPENDED;
  153148. break;
  153149. default: /* must be DHP, EXP, JPGn, or RESn */
  153150. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153151. break;
  153152. }
  153153. cinfo->unread_marker = 0;
  153154. } /* end loop */
  153155. }
  153156. METHODDEF(boolean)
  153157. read_restart_marker (j_decompress_ptr cinfo)
  153158. {
  153159. if (cinfo->unread_marker == 0) {
  153160. if (! next_marker(cinfo))
  153161. return FALSE;
  153162. }
  153163. if (cinfo->unread_marker ==
  153164. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153165. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153166. cinfo->unread_marker = 0;
  153167. } else {
  153168. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153169. cinfo->marker->next_restart_num))
  153170. return FALSE;
  153171. }
  153172. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153173. return TRUE;
  153174. }
  153175. GLOBAL(boolean)
  153176. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153177. {
  153178. int marker = cinfo->unread_marker;
  153179. int action = 1;
  153180. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153181. for (;;) {
  153182. if (marker < (int) M_SOF0)
  153183. action = 2; /* invalid marker */
  153184. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153185. action = 3; /* valid non-restart marker */
  153186. else {
  153187. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153188. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153189. action = 3; /* one of the next two expected restarts */
  153190. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153191. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153192. action = 2; /* a prior restart, so advance */
  153193. else
  153194. action = 1; /* desired restart or too far away */
  153195. }
  153196. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153197. switch (action) {
  153198. case 1:
  153199. cinfo->unread_marker = 0;
  153200. return TRUE;
  153201. case 2:
  153202. if (! next_marker(cinfo))
  153203. return FALSE;
  153204. marker = cinfo->unread_marker;
  153205. break;
  153206. case 3:
  153207. return TRUE;
  153208. }
  153209. } /* end loop */
  153210. }
  153211. METHODDEF(void)
  153212. reset_marker_reader (j_decompress_ptr cinfo)
  153213. {
  153214. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153215. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153216. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153217. cinfo->unread_marker = 0; /* no pending marker */
  153218. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153219. marker->pub.saw_SOF = FALSE;
  153220. marker->pub.discarded_bytes = 0;
  153221. marker->cur_marker = NULL;
  153222. }
  153223. GLOBAL(void)
  153224. jinit_marker_reader (j_decompress_ptr cinfo)
  153225. {
  153226. my_marker_ptr2 marker;
  153227. int i;
  153228. marker = (my_marker_ptr2)
  153229. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153230. SIZEOF(my_marker_reader));
  153231. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153232. marker->pub.reset_marker_reader = reset_marker_reader;
  153233. marker->pub.read_markers = read_markers;
  153234. marker->pub.read_restart_marker = read_restart_marker;
  153235. marker->process_COM = skip_variable;
  153236. marker->length_limit_COM = 0;
  153237. for (i = 0; i < 16; i++) {
  153238. marker->process_APPn[i] = skip_variable;
  153239. marker->length_limit_APPn[i] = 0;
  153240. }
  153241. marker->process_APPn[0] = get_interesting_appn;
  153242. marker->process_APPn[14] = get_interesting_appn;
  153243. reset_marker_reader(cinfo);
  153244. }
  153245. #ifdef SAVE_MARKERS_SUPPORTED
  153246. GLOBAL(void)
  153247. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153248. unsigned int length_limit)
  153249. {
  153250. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153251. long maxlength;
  153252. jpeg_marker_parser_method processor;
  153253. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153254. if (((long) length_limit) > maxlength)
  153255. length_limit = (unsigned int) maxlength;
  153256. if (length_limit) {
  153257. processor = save_marker;
  153258. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153259. length_limit = APP0_DATA_LEN;
  153260. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153261. length_limit = APP14_DATA_LEN;
  153262. } else {
  153263. processor = skip_variable;
  153264. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153265. processor = get_interesting_appn;
  153266. }
  153267. if (marker_code == (int) M_COM) {
  153268. marker->process_COM = processor;
  153269. marker->length_limit_COM = length_limit;
  153270. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153271. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153272. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153273. } else
  153274. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153275. }
  153276. #endif /* SAVE_MARKERS_SUPPORTED */
  153277. GLOBAL(void)
  153278. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153279. jpeg_marker_parser_method routine)
  153280. {
  153281. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153282. if (marker_code == (int) M_COM)
  153283. marker->process_COM = routine;
  153284. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153285. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153286. else
  153287. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153288. }
  153289. /*** End of inlined file: jdmarker.c ***/
  153290. /*** Start of inlined file: jdmaster.c ***/
  153291. #define JPEG_INTERNALS
  153292. typedef struct {
  153293. struct jpeg_decomp_master pub; /* public fields */
  153294. int pass_number; /* # of passes completed */
  153295. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153296. struct jpeg_color_quantizer * quantizer_1pass;
  153297. struct jpeg_color_quantizer * quantizer_2pass;
  153298. } my_decomp_master;
  153299. typedef my_decomp_master * my_master_ptr6;
  153300. LOCAL(boolean)
  153301. use_merged_upsample (j_decompress_ptr cinfo)
  153302. {
  153303. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153304. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153305. return FALSE;
  153306. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153307. cinfo->out_color_space != JCS_RGB ||
  153308. cinfo->out_color_components != RGB_PIXELSIZE)
  153309. return FALSE;
  153310. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153311. cinfo->comp_info[1].h_samp_factor != 1 ||
  153312. cinfo->comp_info[2].h_samp_factor != 1 ||
  153313. cinfo->comp_info[0].v_samp_factor > 2 ||
  153314. cinfo->comp_info[1].v_samp_factor != 1 ||
  153315. cinfo->comp_info[2].v_samp_factor != 1)
  153316. return FALSE;
  153317. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153318. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153319. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153320. return FALSE;
  153321. return TRUE; /* by golly, it'll work... */
  153322. #else
  153323. return FALSE;
  153324. #endif
  153325. }
  153326. GLOBAL(void)
  153327. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153328. {
  153329. #ifdef IDCT_SCALING_SUPPORTED
  153330. int ci;
  153331. jpeg_component_info *compptr;
  153332. #endif
  153333. if (cinfo->global_state != DSTATE_READY)
  153334. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153335. #ifdef IDCT_SCALING_SUPPORTED
  153336. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153337. cinfo->output_width = (JDIMENSION)
  153338. jdiv_round_up((long) cinfo->image_width, 8L);
  153339. cinfo->output_height = (JDIMENSION)
  153340. jdiv_round_up((long) cinfo->image_height, 8L);
  153341. cinfo->min_DCT_scaled_size = 1;
  153342. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153343. cinfo->output_width = (JDIMENSION)
  153344. jdiv_round_up((long) cinfo->image_width, 4L);
  153345. cinfo->output_height = (JDIMENSION)
  153346. jdiv_round_up((long) cinfo->image_height, 4L);
  153347. cinfo->min_DCT_scaled_size = 2;
  153348. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153349. cinfo->output_width = (JDIMENSION)
  153350. jdiv_round_up((long) cinfo->image_width, 2L);
  153351. cinfo->output_height = (JDIMENSION)
  153352. jdiv_round_up((long) cinfo->image_height, 2L);
  153353. cinfo->min_DCT_scaled_size = 4;
  153354. } else {
  153355. cinfo->output_width = cinfo->image_width;
  153356. cinfo->output_height = cinfo->image_height;
  153357. cinfo->min_DCT_scaled_size = DCTSIZE;
  153358. }
  153359. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153360. ci++, compptr++) {
  153361. int ssize = cinfo->min_DCT_scaled_size;
  153362. while (ssize < DCTSIZE &&
  153363. (compptr->h_samp_factor * ssize * 2 <=
  153364. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153365. (compptr->v_samp_factor * ssize * 2 <=
  153366. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153367. ssize = ssize * 2;
  153368. }
  153369. compptr->DCT_scaled_size = ssize;
  153370. }
  153371. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153372. ci++, compptr++) {
  153373. compptr->downsampled_width = (JDIMENSION)
  153374. jdiv_round_up((long) cinfo->image_width *
  153375. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153376. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153377. compptr->downsampled_height = (JDIMENSION)
  153378. jdiv_round_up((long) cinfo->image_height *
  153379. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153380. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153381. }
  153382. #else /* !IDCT_SCALING_SUPPORTED */
  153383. cinfo->output_width = cinfo->image_width;
  153384. cinfo->output_height = cinfo->image_height;
  153385. #endif /* IDCT_SCALING_SUPPORTED */
  153386. switch (cinfo->out_color_space) {
  153387. case JCS_GRAYSCALE:
  153388. cinfo->out_color_components = 1;
  153389. break;
  153390. case JCS_RGB:
  153391. #if RGB_PIXELSIZE != 3
  153392. cinfo->out_color_components = RGB_PIXELSIZE;
  153393. break;
  153394. #endif /* else share code with YCbCr */
  153395. case JCS_YCbCr:
  153396. cinfo->out_color_components = 3;
  153397. break;
  153398. case JCS_CMYK:
  153399. case JCS_YCCK:
  153400. cinfo->out_color_components = 4;
  153401. break;
  153402. default: /* else must be same colorspace as in file */
  153403. cinfo->out_color_components = cinfo->num_components;
  153404. break;
  153405. }
  153406. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153407. cinfo->out_color_components);
  153408. if (use_merged_upsample(cinfo))
  153409. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153410. else
  153411. cinfo->rec_outbuf_height = 1;
  153412. }
  153413. LOCAL(void)
  153414. prepare_range_limit_table (j_decompress_ptr cinfo)
  153415. {
  153416. JSAMPLE * table;
  153417. int i;
  153418. table = (JSAMPLE *)
  153419. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153420. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153421. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153422. cinfo->sample_range_limit = table;
  153423. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153424. for (i = 0; i <= MAXJSAMPLE; i++)
  153425. table[i] = (JSAMPLE) i;
  153426. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153427. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153428. table[i] = MAXJSAMPLE;
  153429. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153430. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153431. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153432. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153433. }
  153434. LOCAL(void)
  153435. master_selection (j_decompress_ptr cinfo)
  153436. {
  153437. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153438. boolean use_c_buffer;
  153439. long samplesperrow;
  153440. JDIMENSION jd_samplesperrow;
  153441. jpeg_calc_output_dimensions(cinfo);
  153442. prepare_range_limit_table(cinfo);
  153443. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153444. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153445. if ((long) jd_samplesperrow != samplesperrow)
  153446. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153447. master->pass_number = 0;
  153448. master->using_merged_upsample = use_merged_upsample(cinfo);
  153449. master->quantizer_1pass = NULL;
  153450. master->quantizer_2pass = NULL;
  153451. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153452. cinfo->enable_1pass_quant = FALSE;
  153453. cinfo->enable_external_quant = FALSE;
  153454. cinfo->enable_2pass_quant = FALSE;
  153455. }
  153456. if (cinfo->quantize_colors) {
  153457. if (cinfo->raw_data_out)
  153458. ERREXIT(cinfo, JERR_NOTIMPL);
  153459. if (cinfo->out_color_components != 3) {
  153460. cinfo->enable_1pass_quant = TRUE;
  153461. cinfo->enable_external_quant = FALSE;
  153462. cinfo->enable_2pass_quant = FALSE;
  153463. cinfo->colormap = NULL;
  153464. } else if (cinfo->colormap != NULL) {
  153465. cinfo->enable_external_quant = TRUE;
  153466. } else if (cinfo->two_pass_quantize) {
  153467. cinfo->enable_2pass_quant = TRUE;
  153468. } else {
  153469. cinfo->enable_1pass_quant = TRUE;
  153470. }
  153471. if (cinfo->enable_1pass_quant) {
  153472. #ifdef QUANT_1PASS_SUPPORTED
  153473. jinit_1pass_quantizer(cinfo);
  153474. master->quantizer_1pass = cinfo->cquantize;
  153475. #else
  153476. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153477. #endif
  153478. }
  153479. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153480. #ifdef QUANT_2PASS_SUPPORTED
  153481. jinit_2pass_quantizer(cinfo);
  153482. master->quantizer_2pass = cinfo->cquantize;
  153483. #else
  153484. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153485. #endif
  153486. }
  153487. }
  153488. if (! cinfo->raw_data_out) {
  153489. if (master->using_merged_upsample) {
  153490. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153491. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153492. #else
  153493. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153494. #endif
  153495. } else {
  153496. jinit_color_deconverter(cinfo);
  153497. jinit_upsampler(cinfo);
  153498. }
  153499. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153500. }
  153501. jinit_inverse_dct(cinfo);
  153502. if (cinfo->arith_code) {
  153503. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153504. } else {
  153505. if (cinfo->progressive_mode) {
  153506. #ifdef D_PROGRESSIVE_SUPPORTED
  153507. jinit_phuff_decoder(cinfo);
  153508. #else
  153509. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153510. #endif
  153511. } else
  153512. jinit_huff_decoder(cinfo);
  153513. }
  153514. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  153515. jinit_d_coef_controller(cinfo, use_c_buffer);
  153516. if (! cinfo->raw_data_out)
  153517. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  153518. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  153519. (*cinfo->inputctl->start_input_pass) (cinfo);
  153520. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153521. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  153522. cinfo->inputctl->has_multiple_scans) {
  153523. int nscans;
  153524. if (cinfo->progressive_mode) {
  153525. nscans = 2 + 3 * cinfo->num_components;
  153526. } else {
  153527. nscans = cinfo->num_components;
  153528. }
  153529. cinfo->progress->pass_counter = 0L;
  153530. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  153531. cinfo->progress->completed_passes = 0;
  153532. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  153533. master->pass_number++;
  153534. }
  153535. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153536. }
  153537. METHODDEF(void)
  153538. prepare_for_output_pass (j_decompress_ptr cinfo)
  153539. {
  153540. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153541. if (master->pub.is_dummy_pass) {
  153542. #ifdef QUANT_2PASS_SUPPORTED
  153543. master->pub.is_dummy_pass = FALSE;
  153544. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  153545. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  153546. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  153547. #else
  153548. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153549. #endif /* QUANT_2PASS_SUPPORTED */
  153550. } else {
  153551. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  153552. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  153553. cinfo->cquantize = master->quantizer_2pass;
  153554. master->pub.is_dummy_pass = TRUE;
  153555. } else if (cinfo->enable_1pass_quant) {
  153556. cinfo->cquantize = master->quantizer_1pass;
  153557. } else {
  153558. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153559. }
  153560. }
  153561. (*cinfo->idct->start_pass) (cinfo);
  153562. (*cinfo->coef->start_output_pass) (cinfo);
  153563. if (! cinfo->raw_data_out) {
  153564. if (! master->using_merged_upsample)
  153565. (*cinfo->cconvert->start_pass) (cinfo);
  153566. (*cinfo->upsample->start_pass) (cinfo);
  153567. if (cinfo->quantize_colors)
  153568. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  153569. (*cinfo->post->start_pass) (cinfo,
  153570. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  153571. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  153572. }
  153573. }
  153574. if (cinfo->progress != NULL) {
  153575. cinfo->progress->completed_passes = master->pass_number;
  153576. cinfo->progress->total_passes = master->pass_number +
  153577. (master->pub.is_dummy_pass ? 2 : 1);
  153578. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  153579. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  153580. }
  153581. }
  153582. }
  153583. METHODDEF(void)
  153584. finish_output_pass (j_decompress_ptr cinfo)
  153585. {
  153586. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153587. if (cinfo->quantize_colors)
  153588. (*cinfo->cquantize->finish_pass) (cinfo);
  153589. master->pass_number++;
  153590. }
  153591. #ifdef D_MULTISCAN_FILES_SUPPORTED
  153592. GLOBAL(void)
  153593. jpeg_new_colormap (j_decompress_ptr cinfo)
  153594. {
  153595. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153596. if (cinfo->global_state != DSTATE_BUFIMAGE)
  153597. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153598. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  153599. cinfo->colormap != NULL) {
  153600. cinfo->cquantize = master->quantizer_2pass;
  153601. (*cinfo->cquantize->new_color_map) (cinfo);
  153602. master->pub.is_dummy_pass = FALSE; /* just in case */
  153603. } else
  153604. ERREXIT(cinfo, JERR_MODE_CHANGE);
  153605. }
  153606. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  153607. GLOBAL(void)
  153608. jinit_master_decompress (j_decompress_ptr cinfo)
  153609. {
  153610. my_master_ptr6 master;
  153611. master = (my_master_ptr6)
  153612. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153613. SIZEOF(my_decomp_master));
  153614. cinfo->master = (struct jpeg_decomp_master *) master;
  153615. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  153616. master->pub.finish_output_pass = finish_output_pass;
  153617. master->pub.is_dummy_pass = FALSE;
  153618. master_selection(cinfo);
  153619. }
  153620. /*** End of inlined file: jdmaster.c ***/
  153621. #undef FIX
  153622. /*** Start of inlined file: jdmerge.c ***/
  153623. #define JPEG_INTERNALS
  153624. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153625. typedef struct {
  153626. struct jpeg_upsampler pub; /* public fields */
  153627. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  153628. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153629. JSAMPARRAY output_buf));
  153630. int * Cr_r_tab; /* => table for Cr to R conversion */
  153631. int * Cb_b_tab; /* => table for Cb to B conversion */
  153632. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  153633. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  153634. JSAMPROW spare_row;
  153635. boolean spare_full; /* T if spare buffer is occupied */
  153636. JDIMENSION out_row_width; /* samples per output row */
  153637. JDIMENSION rows_to_go; /* counts rows remaining in image */
  153638. } my_upsampler;
  153639. typedef my_upsampler * my_upsample_ptr;
  153640. #define SCALEBITS 16 /* speediest right-shift on some machines */
  153641. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  153642. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  153643. LOCAL(void)
  153644. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  153645. {
  153646. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153647. int i;
  153648. INT32 x;
  153649. SHIFT_TEMPS
  153650. upsample->Cr_r_tab = (int *)
  153651. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153652. (MAXJSAMPLE+1) * SIZEOF(int));
  153653. upsample->Cb_b_tab = (int *)
  153654. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153655. (MAXJSAMPLE+1) * SIZEOF(int));
  153656. upsample->Cr_g_tab = (INT32 *)
  153657. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153658. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153659. upsample->Cb_g_tab = (INT32 *)
  153660. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153661. (MAXJSAMPLE+1) * SIZEOF(INT32));
  153662. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  153663. upsample->Cr_r_tab[i] = (int)
  153664. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  153665. upsample->Cb_b_tab[i] = (int)
  153666. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  153667. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  153668. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  153669. }
  153670. }
  153671. METHODDEF(void)
  153672. start_pass_merged_upsample (j_decompress_ptr cinfo)
  153673. {
  153674. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153675. upsample->spare_full = FALSE;
  153676. upsample->rows_to_go = cinfo->output_height;
  153677. }
  153678. METHODDEF(void)
  153679. merged_2v_upsample (j_decompress_ptr cinfo,
  153680. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153681. JDIMENSION in_row_groups_avail,
  153682. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153683. JDIMENSION out_rows_avail)
  153684. {
  153685. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153686. JSAMPROW work_ptrs[2];
  153687. JDIMENSION num_rows; /* number of rows returned to caller */
  153688. if (upsample->spare_full) {
  153689. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  153690. 1, upsample->out_row_width);
  153691. num_rows = 1;
  153692. upsample->spare_full = FALSE;
  153693. } else {
  153694. num_rows = 2;
  153695. if (num_rows > upsample->rows_to_go)
  153696. num_rows = upsample->rows_to_go;
  153697. out_rows_avail -= *out_row_ctr;
  153698. if (num_rows > out_rows_avail)
  153699. num_rows = out_rows_avail;
  153700. work_ptrs[0] = output_buf[*out_row_ctr];
  153701. if (num_rows > 1) {
  153702. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  153703. } else {
  153704. work_ptrs[1] = upsample->spare_row;
  153705. upsample->spare_full = TRUE;
  153706. }
  153707. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  153708. }
  153709. *out_row_ctr += num_rows;
  153710. upsample->rows_to_go -= num_rows;
  153711. if (! upsample->spare_full)
  153712. (*in_row_group_ctr)++;
  153713. }
  153714. METHODDEF(void)
  153715. merged_1v_upsample (j_decompress_ptr cinfo,
  153716. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  153717. JDIMENSION in_row_groups_avail,
  153718. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  153719. JDIMENSION out_rows_avail)
  153720. {
  153721. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153722. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  153723. output_buf + *out_row_ctr);
  153724. (*out_row_ctr)++;
  153725. (*in_row_group_ctr)++;
  153726. }
  153727. METHODDEF(void)
  153728. h2v1_merged_upsample (j_decompress_ptr cinfo,
  153729. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153730. JSAMPARRAY output_buf)
  153731. {
  153732. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153733. register int y, cred, cgreen, cblue;
  153734. int cb, cr;
  153735. register JSAMPROW outptr;
  153736. JSAMPROW inptr0, inptr1, inptr2;
  153737. JDIMENSION col;
  153738. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153739. int * Crrtab = upsample->Cr_r_tab;
  153740. int * Cbbtab = upsample->Cb_b_tab;
  153741. INT32 * Crgtab = upsample->Cr_g_tab;
  153742. INT32 * Cbgtab = upsample->Cb_g_tab;
  153743. SHIFT_TEMPS
  153744. inptr0 = input_buf[0][in_row_group_ctr];
  153745. inptr1 = input_buf[1][in_row_group_ctr];
  153746. inptr2 = input_buf[2][in_row_group_ctr];
  153747. outptr = output_buf[0];
  153748. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153749. cb = GETJSAMPLE(*inptr1++);
  153750. cr = GETJSAMPLE(*inptr2++);
  153751. cred = Crrtab[cr];
  153752. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153753. cblue = Cbbtab[cb];
  153754. y = GETJSAMPLE(*inptr0++);
  153755. outptr[RGB_RED] = range_limit[y + cred];
  153756. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153757. outptr[RGB_BLUE] = range_limit[y + cblue];
  153758. outptr += RGB_PIXELSIZE;
  153759. y = GETJSAMPLE(*inptr0++);
  153760. outptr[RGB_RED] = range_limit[y + cred];
  153761. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153762. outptr[RGB_BLUE] = range_limit[y + cblue];
  153763. outptr += RGB_PIXELSIZE;
  153764. }
  153765. if (cinfo->output_width & 1) {
  153766. cb = GETJSAMPLE(*inptr1);
  153767. cr = GETJSAMPLE(*inptr2);
  153768. cred = Crrtab[cr];
  153769. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153770. cblue = Cbbtab[cb];
  153771. y = GETJSAMPLE(*inptr0);
  153772. outptr[RGB_RED] = range_limit[y + cred];
  153773. outptr[RGB_GREEN] = range_limit[y + cgreen];
  153774. outptr[RGB_BLUE] = range_limit[y + cblue];
  153775. }
  153776. }
  153777. METHODDEF(void)
  153778. h2v2_merged_upsample (j_decompress_ptr cinfo,
  153779. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  153780. JSAMPARRAY output_buf)
  153781. {
  153782. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  153783. register int y, cred, cgreen, cblue;
  153784. int cb, cr;
  153785. register JSAMPROW outptr0, outptr1;
  153786. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  153787. JDIMENSION col;
  153788. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  153789. int * Crrtab = upsample->Cr_r_tab;
  153790. int * Cbbtab = upsample->Cb_b_tab;
  153791. INT32 * Crgtab = upsample->Cr_g_tab;
  153792. INT32 * Cbgtab = upsample->Cb_g_tab;
  153793. SHIFT_TEMPS
  153794. inptr00 = input_buf[0][in_row_group_ctr*2];
  153795. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  153796. inptr1 = input_buf[1][in_row_group_ctr];
  153797. inptr2 = input_buf[2][in_row_group_ctr];
  153798. outptr0 = output_buf[0];
  153799. outptr1 = output_buf[1];
  153800. for (col = cinfo->output_width >> 1; col > 0; col--) {
  153801. cb = GETJSAMPLE(*inptr1++);
  153802. cr = GETJSAMPLE(*inptr2++);
  153803. cred = Crrtab[cr];
  153804. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153805. cblue = Cbbtab[cb];
  153806. y = GETJSAMPLE(*inptr00++);
  153807. outptr0[RGB_RED] = range_limit[y + cred];
  153808. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153809. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153810. outptr0 += RGB_PIXELSIZE;
  153811. y = GETJSAMPLE(*inptr00++);
  153812. outptr0[RGB_RED] = range_limit[y + cred];
  153813. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153814. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153815. outptr0 += RGB_PIXELSIZE;
  153816. y = GETJSAMPLE(*inptr01++);
  153817. outptr1[RGB_RED] = range_limit[y + cred];
  153818. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153819. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153820. outptr1 += RGB_PIXELSIZE;
  153821. y = GETJSAMPLE(*inptr01++);
  153822. outptr1[RGB_RED] = range_limit[y + cred];
  153823. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153824. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153825. outptr1 += RGB_PIXELSIZE;
  153826. }
  153827. if (cinfo->output_width & 1) {
  153828. cb = GETJSAMPLE(*inptr1);
  153829. cr = GETJSAMPLE(*inptr2);
  153830. cred = Crrtab[cr];
  153831. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  153832. cblue = Cbbtab[cb];
  153833. y = GETJSAMPLE(*inptr00);
  153834. outptr0[RGB_RED] = range_limit[y + cred];
  153835. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  153836. outptr0[RGB_BLUE] = range_limit[y + cblue];
  153837. y = GETJSAMPLE(*inptr01);
  153838. outptr1[RGB_RED] = range_limit[y + cred];
  153839. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  153840. outptr1[RGB_BLUE] = range_limit[y + cblue];
  153841. }
  153842. }
  153843. GLOBAL(void)
  153844. jinit_merged_upsampler (j_decompress_ptr cinfo)
  153845. {
  153846. my_upsample_ptr upsample;
  153847. upsample = (my_upsample_ptr)
  153848. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153849. SIZEOF(my_upsampler));
  153850. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  153851. upsample->pub.start_pass = start_pass_merged_upsample;
  153852. upsample->pub.need_context_rows = FALSE;
  153853. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  153854. if (cinfo->max_v_samp_factor == 2) {
  153855. upsample->pub.upsample = merged_2v_upsample;
  153856. upsample->upmethod = h2v2_merged_upsample;
  153857. upsample->spare_row = (JSAMPROW)
  153858. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153859. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  153860. } else {
  153861. upsample->pub.upsample = merged_1v_upsample;
  153862. upsample->upmethod = h2v1_merged_upsample;
  153863. upsample->spare_row = NULL;
  153864. }
  153865. build_ycc_rgb_table2(cinfo);
  153866. }
  153867. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  153868. /*** End of inlined file: jdmerge.c ***/
  153869. #undef ASSIGN_STATE
  153870. /*** Start of inlined file: jdphuff.c ***/
  153871. #define JPEG_INTERNALS
  153872. #ifdef D_PROGRESSIVE_SUPPORTED
  153873. typedef struct {
  153874. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  153875. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  153876. } savable_state3;
  153877. #ifndef NO_STRUCT_ASSIGN
  153878. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  153879. #else
  153880. #if MAX_COMPS_IN_SCAN == 4
  153881. #define ASSIGN_STATE(dest,src) \
  153882. ((dest).EOBRUN = (src).EOBRUN, \
  153883. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  153884. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  153885. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  153886. (dest).last_dc_val[3] = (src).last_dc_val[3])
  153887. #endif
  153888. #endif
  153889. typedef struct {
  153890. struct jpeg_entropy_decoder pub; /* public fields */
  153891. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  153892. savable_state3 saved; /* Other state at start of MCU */
  153893. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  153894. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  153895. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  153896. } phuff_entropy_decoder;
  153897. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  153898. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  153899. JBLOCKROW *MCU_data));
  153900. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  153901. JBLOCKROW *MCU_data));
  153902. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  153903. JBLOCKROW *MCU_data));
  153904. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  153905. JBLOCKROW *MCU_data));
  153906. METHODDEF(void)
  153907. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  153908. {
  153909. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153910. boolean is_DC_band, bad;
  153911. int ci, coefi, tbl;
  153912. int *coef_bit_ptr;
  153913. jpeg_component_info * compptr;
  153914. is_DC_band = (cinfo->Ss == 0);
  153915. bad = FALSE;
  153916. if (is_DC_band) {
  153917. if (cinfo->Se != 0)
  153918. bad = TRUE;
  153919. } else {
  153920. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  153921. bad = TRUE;
  153922. if (cinfo->comps_in_scan != 1)
  153923. bad = TRUE;
  153924. }
  153925. if (cinfo->Ah != 0) {
  153926. if (cinfo->Al != cinfo->Ah-1)
  153927. bad = TRUE;
  153928. }
  153929. if (cinfo->Al > 13) /* need not check for < 0 */
  153930. bad = TRUE;
  153931. if (bad)
  153932. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  153933. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  153934. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153935. int cindex = cinfo->cur_comp_info[ci]->component_index;
  153936. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  153937. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  153938. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  153939. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  153940. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  153941. if (cinfo->Ah != expected)
  153942. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  153943. coef_bit_ptr[coefi] = cinfo->Al;
  153944. }
  153945. }
  153946. if (cinfo->Ah == 0) {
  153947. if (is_DC_band)
  153948. entropy->pub.decode_mcu = decode_mcu_DC_first;
  153949. else
  153950. entropy->pub.decode_mcu = decode_mcu_AC_first;
  153951. } else {
  153952. if (is_DC_band)
  153953. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  153954. else
  153955. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  153956. }
  153957. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  153958. compptr = cinfo->cur_comp_info[ci];
  153959. if (is_DC_band) {
  153960. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  153961. tbl = compptr->dc_tbl_no;
  153962. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  153963. & entropy->derived_tbls[tbl]);
  153964. }
  153965. } else {
  153966. tbl = compptr->ac_tbl_no;
  153967. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  153968. & entropy->derived_tbls[tbl]);
  153969. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  153970. }
  153971. entropy->saved.last_dc_val[ci] = 0;
  153972. }
  153973. entropy->bitstate.bits_left = 0;
  153974. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  153975. entropy->pub.insufficient_data = FALSE;
  153976. entropy->saved.EOBRUN = 0;
  153977. entropy->restarts_to_go = cinfo->restart_interval;
  153978. }
  153979. LOCAL(boolean)
  153980. process_restartp (j_decompress_ptr cinfo)
  153981. {
  153982. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  153983. int ci;
  153984. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  153985. entropy->bitstate.bits_left = 0;
  153986. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  153987. return FALSE;
  153988. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  153989. entropy->saved.last_dc_val[ci] = 0;
  153990. entropy->saved.EOBRUN = 0;
  153991. entropy->restarts_to_go = cinfo->restart_interval;
  153992. if (cinfo->unread_marker == 0)
  153993. entropy->pub.insufficient_data = FALSE;
  153994. return TRUE;
  153995. }
  153996. METHODDEF(boolean)
  153997. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  153998. {
  153999. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154000. int Al = cinfo->Al;
  154001. register int s, r;
  154002. int blkn, ci;
  154003. JBLOCKROW block;
  154004. BITREAD_STATE_VARS;
  154005. savable_state3 state;
  154006. d_derived_tbl * tbl;
  154007. jpeg_component_info * compptr;
  154008. if (cinfo->restart_interval) {
  154009. if (entropy->restarts_to_go == 0)
  154010. if (! process_restartp(cinfo))
  154011. return FALSE;
  154012. }
  154013. if (! entropy->pub.insufficient_data) {
  154014. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154015. ASSIGN_STATE(state, entropy->saved);
  154016. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154017. block = MCU_data[blkn];
  154018. ci = cinfo->MCU_membership[blkn];
  154019. compptr = cinfo->cur_comp_info[ci];
  154020. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154021. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154022. if (s) {
  154023. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154024. r = GET_BITS(s);
  154025. s = HUFF_EXTEND(r, s);
  154026. }
  154027. s += state.last_dc_val[ci];
  154028. state.last_dc_val[ci] = s;
  154029. (*block)[0] = (JCOEF) (s << Al);
  154030. }
  154031. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154032. ASSIGN_STATE(entropy->saved, state);
  154033. }
  154034. entropy->restarts_to_go--;
  154035. return TRUE;
  154036. }
  154037. METHODDEF(boolean)
  154038. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154039. {
  154040. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154041. int Se = cinfo->Se;
  154042. int Al = cinfo->Al;
  154043. register int s, k, r;
  154044. unsigned int EOBRUN;
  154045. JBLOCKROW block;
  154046. BITREAD_STATE_VARS;
  154047. d_derived_tbl * tbl;
  154048. if (cinfo->restart_interval) {
  154049. if (entropy->restarts_to_go == 0)
  154050. if (! process_restartp(cinfo))
  154051. return FALSE;
  154052. }
  154053. if (! entropy->pub.insufficient_data) {
  154054. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154055. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154056. EOBRUN--; /* ...process it now (we do nothing) */
  154057. else {
  154058. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154059. block = MCU_data[0];
  154060. tbl = entropy->ac_derived_tbl;
  154061. for (k = cinfo->Ss; k <= Se; k++) {
  154062. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154063. r = s >> 4;
  154064. s &= 15;
  154065. if (s) {
  154066. k += r;
  154067. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154068. r = GET_BITS(s);
  154069. s = HUFF_EXTEND(r, s);
  154070. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154071. } else {
  154072. if (r == 15) { /* ZRL */
  154073. k += 15; /* skip 15 zeroes in band */
  154074. } else { /* EOBr, run length is 2^r + appended bits */
  154075. EOBRUN = 1 << r;
  154076. if (r) { /* EOBr, r > 0 */
  154077. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154078. r = GET_BITS(r);
  154079. EOBRUN += r;
  154080. }
  154081. EOBRUN--; /* this band is processed at this moment */
  154082. break; /* force end-of-band */
  154083. }
  154084. }
  154085. }
  154086. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154087. }
  154088. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154089. }
  154090. entropy->restarts_to_go--;
  154091. return TRUE;
  154092. }
  154093. METHODDEF(boolean)
  154094. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154095. {
  154096. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154097. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154098. int blkn;
  154099. JBLOCKROW block;
  154100. BITREAD_STATE_VARS;
  154101. if (cinfo->restart_interval) {
  154102. if (entropy->restarts_to_go == 0)
  154103. if (! process_restartp(cinfo))
  154104. return FALSE;
  154105. }
  154106. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154107. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154108. block = MCU_data[blkn];
  154109. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154110. if (GET_BITS(1))
  154111. (*block)[0] |= p1;
  154112. }
  154113. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154114. entropy->restarts_to_go--;
  154115. return TRUE;
  154116. }
  154117. METHODDEF(boolean)
  154118. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154119. {
  154120. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154121. int Se = cinfo->Se;
  154122. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154123. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154124. register int s, k, r;
  154125. unsigned int EOBRUN;
  154126. JBLOCKROW block;
  154127. JCOEFPTR thiscoef;
  154128. BITREAD_STATE_VARS;
  154129. d_derived_tbl * tbl;
  154130. int num_newnz;
  154131. int newnz_pos[DCTSIZE2];
  154132. if (cinfo->restart_interval) {
  154133. if (entropy->restarts_to_go == 0)
  154134. if (! process_restartp(cinfo))
  154135. return FALSE;
  154136. }
  154137. if (! entropy->pub.insufficient_data) {
  154138. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154139. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154140. block = MCU_data[0];
  154141. tbl = entropy->ac_derived_tbl;
  154142. num_newnz = 0;
  154143. k = cinfo->Ss;
  154144. if (EOBRUN == 0) {
  154145. for (; k <= Se; k++) {
  154146. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154147. r = s >> 4;
  154148. s &= 15;
  154149. if (s) {
  154150. if (s != 1) /* size of new coef should always be 1 */
  154151. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154152. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154153. if (GET_BITS(1))
  154154. s = p1; /* newly nonzero coef is positive */
  154155. else
  154156. s = m1; /* newly nonzero coef is negative */
  154157. } else {
  154158. if (r != 15) {
  154159. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154160. if (r) {
  154161. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154162. r = GET_BITS(r);
  154163. EOBRUN += r;
  154164. }
  154165. break; /* rest of block is handled by EOB logic */
  154166. }
  154167. }
  154168. do {
  154169. thiscoef = *block + jpeg_natural_order[k];
  154170. if (*thiscoef != 0) {
  154171. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154172. if (GET_BITS(1)) {
  154173. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154174. if (*thiscoef >= 0)
  154175. *thiscoef += p1;
  154176. else
  154177. *thiscoef += m1;
  154178. }
  154179. }
  154180. } else {
  154181. if (--r < 0)
  154182. break; /* reached target zero coefficient */
  154183. }
  154184. k++;
  154185. } while (k <= Se);
  154186. if (s) {
  154187. int pos = jpeg_natural_order[k];
  154188. (*block)[pos] = (JCOEF) s;
  154189. newnz_pos[num_newnz++] = pos;
  154190. }
  154191. }
  154192. }
  154193. if (EOBRUN > 0) {
  154194. for (; k <= Se; k++) {
  154195. thiscoef = *block + jpeg_natural_order[k];
  154196. if (*thiscoef != 0) {
  154197. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154198. if (GET_BITS(1)) {
  154199. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154200. if (*thiscoef >= 0)
  154201. *thiscoef += p1;
  154202. else
  154203. *thiscoef += m1;
  154204. }
  154205. }
  154206. }
  154207. }
  154208. EOBRUN--;
  154209. }
  154210. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154211. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154212. }
  154213. entropy->restarts_to_go--;
  154214. return TRUE;
  154215. undoit:
  154216. while (num_newnz > 0)
  154217. (*block)[newnz_pos[--num_newnz]] = 0;
  154218. return FALSE;
  154219. }
  154220. GLOBAL(void)
  154221. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154222. {
  154223. phuff_entropy_ptr2 entropy;
  154224. int *coef_bit_ptr;
  154225. int ci, i;
  154226. entropy = (phuff_entropy_ptr2)
  154227. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154228. SIZEOF(phuff_entropy_decoder));
  154229. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154230. entropy->pub.start_pass = start_pass_phuff_decoder;
  154231. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154232. entropy->derived_tbls[i] = NULL;
  154233. }
  154234. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154235. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154236. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154237. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154238. for (ci = 0; ci < cinfo->num_components; ci++)
  154239. for (i = 0; i < DCTSIZE2; i++)
  154240. *coef_bit_ptr++ = -1;
  154241. }
  154242. #endif /* D_PROGRESSIVE_SUPPORTED */
  154243. /*** End of inlined file: jdphuff.c ***/
  154244. /*** Start of inlined file: jdpostct.c ***/
  154245. #define JPEG_INTERNALS
  154246. typedef struct {
  154247. struct jpeg_d_post_controller pub; /* public fields */
  154248. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154249. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154250. JDIMENSION strip_height; /* buffer size in rows */
  154251. JDIMENSION starting_row; /* row # of first row in current strip */
  154252. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154253. } my_post_controller;
  154254. typedef my_post_controller * my_post_ptr;
  154255. METHODDEF(void) post_process_1pass
  154256. JPP((j_decompress_ptr cinfo,
  154257. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154258. JDIMENSION in_row_groups_avail,
  154259. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154260. JDIMENSION out_rows_avail));
  154261. #ifdef QUANT_2PASS_SUPPORTED
  154262. METHODDEF(void) post_process_prepass
  154263. JPP((j_decompress_ptr cinfo,
  154264. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154265. JDIMENSION in_row_groups_avail,
  154266. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154267. JDIMENSION out_rows_avail));
  154268. METHODDEF(void) post_process_2pass
  154269. JPP((j_decompress_ptr cinfo,
  154270. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154271. JDIMENSION in_row_groups_avail,
  154272. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154273. JDIMENSION out_rows_avail));
  154274. #endif
  154275. METHODDEF(void)
  154276. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154277. {
  154278. my_post_ptr post = (my_post_ptr) cinfo->post;
  154279. switch (pass_mode) {
  154280. case JBUF_PASS_THRU:
  154281. if (cinfo->quantize_colors) {
  154282. post->pub.post_process_data = post_process_1pass;
  154283. if (post->buffer == NULL) {
  154284. post->buffer = (*cinfo->mem->access_virt_sarray)
  154285. ((j_common_ptr) cinfo, post->whole_image,
  154286. (JDIMENSION) 0, post->strip_height, TRUE);
  154287. }
  154288. } else {
  154289. post->pub.post_process_data = cinfo->upsample->upsample;
  154290. }
  154291. break;
  154292. #ifdef QUANT_2PASS_SUPPORTED
  154293. case JBUF_SAVE_AND_PASS:
  154294. if (post->whole_image == NULL)
  154295. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154296. post->pub.post_process_data = post_process_prepass;
  154297. break;
  154298. case JBUF_CRANK_DEST:
  154299. if (post->whole_image == NULL)
  154300. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154301. post->pub.post_process_data = post_process_2pass;
  154302. break;
  154303. #endif /* QUANT_2PASS_SUPPORTED */
  154304. default:
  154305. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154306. break;
  154307. }
  154308. post->starting_row = post->next_row = 0;
  154309. }
  154310. METHODDEF(void)
  154311. post_process_1pass (j_decompress_ptr cinfo,
  154312. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154313. JDIMENSION in_row_groups_avail,
  154314. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154315. JDIMENSION out_rows_avail)
  154316. {
  154317. my_post_ptr post = (my_post_ptr) cinfo->post;
  154318. JDIMENSION num_rows, max_rows;
  154319. max_rows = out_rows_avail - *out_row_ctr;
  154320. if (max_rows > post->strip_height)
  154321. max_rows = post->strip_height;
  154322. num_rows = 0;
  154323. (*cinfo->upsample->upsample) (cinfo,
  154324. input_buf, in_row_group_ctr, in_row_groups_avail,
  154325. post->buffer, &num_rows, max_rows);
  154326. (*cinfo->cquantize->color_quantize) (cinfo,
  154327. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154328. *out_row_ctr += num_rows;
  154329. }
  154330. #ifdef QUANT_2PASS_SUPPORTED
  154331. METHODDEF(void)
  154332. post_process_prepass (j_decompress_ptr cinfo,
  154333. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154334. JDIMENSION in_row_groups_avail,
  154335. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154336. JDIMENSION out_rows_avail)
  154337. {
  154338. my_post_ptr post = (my_post_ptr) cinfo->post;
  154339. JDIMENSION old_next_row, num_rows;
  154340. if (post->next_row == 0) {
  154341. post->buffer = (*cinfo->mem->access_virt_sarray)
  154342. ((j_common_ptr) cinfo, post->whole_image,
  154343. post->starting_row, post->strip_height, TRUE);
  154344. }
  154345. old_next_row = post->next_row;
  154346. (*cinfo->upsample->upsample) (cinfo,
  154347. input_buf, in_row_group_ctr, in_row_groups_avail,
  154348. post->buffer, &post->next_row, post->strip_height);
  154349. if (post->next_row > old_next_row) {
  154350. num_rows = post->next_row - old_next_row;
  154351. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154352. (JSAMPARRAY) NULL, (int) num_rows);
  154353. *out_row_ctr += num_rows;
  154354. }
  154355. if (post->next_row >= post->strip_height) {
  154356. post->starting_row += post->strip_height;
  154357. post->next_row = 0;
  154358. }
  154359. }
  154360. METHODDEF(void)
  154361. post_process_2pass (j_decompress_ptr cinfo,
  154362. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154363. JDIMENSION in_row_groups_avail,
  154364. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154365. JDIMENSION out_rows_avail)
  154366. {
  154367. my_post_ptr post = (my_post_ptr) cinfo->post;
  154368. JDIMENSION num_rows, max_rows;
  154369. if (post->next_row == 0) {
  154370. post->buffer = (*cinfo->mem->access_virt_sarray)
  154371. ((j_common_ptr) cinfo, post->whole_image,
  154372. post->starting_row, post->strip_height, FALSE);
  154373. }
  154374. num_rows = post->strip_height - post->next_row; /* available in strip */
  154375. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154376. if (num_rows > max_rows)
  154377. num_rows = max_rows;
  154378. max_rows = cinfo->output_height - post->starting_row;
  154379. if (num_rows > max_rows)
  154380. num_rows = max_rows;
  154381. (*cinfo->cquantize->color_quantize) (cinfo,
  154382. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154383. (int) num_rows);
  154384. *out_row_ctr += num_rows;
  154385. post->next_row += num_rows;
  154386. if (post->next_row >= post->strip_height) {
  154387. post->starting_row += post->strip_height;
  154388. post->next_row = 0;
  154389. }
  154390. }
  154391. #endif /* QUANT_2PASS_SUPPORTED */
  154392. GLOBAL(void)
  154393. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154394. {
  154395. my_post_ptr post;
  154396. post = (my_post_ptr)
  154397. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154398. SIZEOF(my_post_controller));
  154399. cinfo->post = (struct jpeg_d_post_controller *) post;
  154400. post->pub.start_pass = start_pass_dpost;
  154401. post->whole_image = NULL; /* flag for no virtual arrays */
  154402. post->buffer = NULL; /* flag for no strip buffer */
  154403. if (cinfo->quantize_colors) {
  154404. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154405. if (need_full_buffer) {
  154406. #ifdef QUANT_2PASS_SUPPORTED
  154407. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154408. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154409. cinfo->output_width * cinfo->out_color_components,
  154410. (JDIMENSION) jround_up((long) cinfo->output_height,
  154411. (long) post->strip_height),
  154412. post->strip_height);
  154413. #else
  154414. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154415. #endif /* QUANT_2PASS_SUPPORTED */
  154416. } else {
  154417. post->buffer = (*cinfo->mem->alloc_sarray)
  154418. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154419. cinfo->output_width * cinfo->out_color_components,
  154420. post->strip_height);
  154421. }
  154422. }
  154423. }
  154424. /*** End of inlined file: jdpostct.c ***/
  154425. #undef FIX
  154426. /*** Start of inlined file: jdsample.c ***/
  154427. #define JPEG_INTERNALS
  154428. typedef JMETHOD(void, upsample1_ptr,
  154429. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154430. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154431. typedef struct {
  154432. struct jpeg_upsampler pub; /* public fields */
  154433. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154434. upsample1_ptr methods[MAX_COMPONENTS];
  154435. int next_row_out; /* counts rows emitted from color_buf */
  154436. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154437. int rowgroup_height[MAX_COMPONENTS];
  154438. UINT8 h_expand[MAX_COMPONENTS];
  154439. UINT8 v_expand[MAX_COMPONENTS];
  154440. } my_upsampler2;
  154441. typedef my_upsampler2 * my_upsample_ptr2;
  154442. METHODDEF(void)
  154443. start_pass_upsample (j_decompress_ptr cinfo)
  154444. {
  154445. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154446. upsample->next_row_out = cinfo->max_v_samp_factor;
  154447. upsample->rows_to_go = cinfo->output_height;
  154448. }
  154449. METHODDEF(void)
  154450. sep_upsample (j_decompress_ptr cinfo,
  154451. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154452. JDIMENSION in_row_groups_avail,
  154453. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154454. JDIMENSION out_rows_avail)
  154455. {
  154456. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154457. int ci;
  154458. jpeg_component_info * compptr;
  154459. JDIMENSION num_rows;
  154460. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154461. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154462. ci++, compptr++) {
  154463. (*upsample->methods[ci]) (cinfo, compptr,
  154464. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154465. upsample->color_buf + ci);
  154466. }
  154467. upsample->next_row_out = 0;
  154468. }
  154469. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154470. if (num_rows > upsample->rows_to_go)
  154471. num_rows = upsample->rows_to_go;
  154472. out_rows_avail -= *out_row_ctr;
  154473. if (num_rows > out_rows_avail)
  154474. num_rows = out_rows_avail;
  154475. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154476. (JDIMENSION) upsample->next_row_out,
  154477. output_buf + *out_row_ctr,
  154478. (int) num_rows);
  154479. *out_row_ctr += num_rows;
  154480. upsample->rows_to_go -= num_rows;
  154481. upsample->next_row_out += num_rows;
  154482. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154483. (*in_row_group_ctr)++;
  154484. }
  154485. METHODDEF(void)
  154486. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154487. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154488. {
  154489. *output_data_ptr = input_data;
  154490. }
  154491. METHODDEF(void)
  154492. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154493. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154494. {
  154495. *output_data_ptr = NULL; /* safety check */
  154496. }
  154497. METHODDEF(void)
  154498. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154499. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154500. {
  154501. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154502. JSAMPARRAY output_data = *output_data_ptr;
  154503. register JSAMPROW inptr, outptr;
  154504. register JSAMPLE invalue;
  154505. register int h;
  154506. JSAMPROW outend;
  154507. int h_expand, v_expand;
  154508. int inrow, outrow;
  154509. h_expand = upsample->h_expand[compptr->component_index];
  154510. v_expand = upsample->v_expand[compptr->component_index];
  154511. inrow = outrow = 0;
  154512. while (outrow < cinfo->max_v_samp_factor) {
  154513. inptr = input_data[inrow];
  154514. outptr = output_data[outrow];
  154515. outend = outptr + cinfo->output_width;
  154516. while (outptr < outend) {
  154517. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154518. for (h = h_expand; h > 0; h--) {
  154519. *outptr++ = invalue;
  154520. }
  154521. }
  154522. if (v_expand > 1) {
  154523. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154524. v_expand-1, cinfo->output_width);
  154525. }
  154526. inrow++;
  154527. outrow += v_expand;
  154528. }
  154529. }
  154530. METHODDEF(void)
  154531. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154532. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154533. {
  154534. JSAMPARRAY output_data = *output_data_ptr;
  154535. register JSAMPROW inptr, outptr;
  154536. register JSAMPLE invalue;
  154537. JSAMPROW outend;
  154538. int inrow;
  154539. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154540. inptr = input_data[inrow];
  154541. outptr = output_data[inrow];
  154542. outend = outptr + cinfo->output_width;
  154543. while (outptr < outend) {
  154544. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154545. *outptr++ = invalue;
  154546. *outptr++ = invalue;
  154547. }
  154548. }
  154549. }
  154550. METHODDEF(void)
  154551. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154552. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154553. {
  154554. JSAMPARRAY output_data = *output_data_ptr;
  154555. register JSAMPROW inptr, outptr;
  154556. register JSAMPLE invalue;
  154557. JSAMPROW outend;
  154558. int inrow, outrow;
  154559. inrow = outrow = 0;
  154560. while (outrow < cinfo->max_v_samp_factor) {
  154561. inptr = input_data[inrow];
  154562. outptr = output_data[outrow];
  154563. outend = outptr + cinfo->output_width;
  154564. while (outptr < outend) {
  154565. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  154566. *outptr++ = invalue;
  154567. *outptr++ = invalue;
  154568. }
  154569. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  154570. 1, cinfo->output_width);
  154571. inrow++;
  154572. outrow += 2;
  154573. }
  154574. }
  154575. METHODDEF(void)
  154576. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154577. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154578. {
  154579. JSAMPARRAY output_data = *output_data_ptr;
  154580. register JSAMPROW inptr, outptr;
  154581. register int invalue;
  154582. register JDIMENSION colctr;
  154583. int inrow;
  154584. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  154585. inptr = input_data[inrow];
  154586. outptr = output_data[inrow];
  154587. invalue = GETJSAMPLE(*inptr++);
  154588. *outptr++ = (JSAMPLE) invalue;
  154589. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  154590. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154591. invalue = GETJSAMPLE(*inptr++) * 3;
  154592. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  154593. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  154594. }
  154595. invalue = GETJSAMPLE(*inptr);
  154596. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  154597. *outptr++ = (JSAMPLE) invalue;
  154598. }
  154599. }
  154600. METHODDEF(void)
  154601. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154602. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154603. {
  154604. JSAMPARRAY output_data = *output_data_ptr;
  154605. register JSAMPROW inptr0, inptr1, outptr;
  154606. #if BITS_IN_JSAMPLE == 8
  154607. register int thiscolsum, lastcolsum, nextcolsum;
  154608. #else
  154609. register INT32 thiscolsum, lastcolsum, nextcolsum;
  154610. #endif
  154611. register JDIMENSION colctr;
  154612. int inrow, outrow, v;
  154613. inrow = outrow = 0;
  154614. while (outrow < cinfo->max_v_samp_factor) {
  154615. for (v = 0; v < 2; v++) {
  154616. inptr0 = input_data[inrow];
  154617. if (v == 0) /* next nearest is row above */
  154618. inptr1 = input_data[inrow-1];
  154619. else /* next nearest is row below */
  154620. inptr1 = input_data[inrow+1];
  154621. outptr = output_data[outrow++];
  154622. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154623. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154624. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  154625. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154626. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154627. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  154628. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  154629. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154630. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  154631. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  154632. }
  154633. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  154634. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  154635. }
  154636. inrow++;
  154637. }
  154638. }
  154639. GLOBAL(void)
  154640. jinit_upsampler (j_decompress_ptr cinfo)
  154641. {
  154642. my_upsample_ptr2 upsample;
  154643. int ci;
  154644. jpeg_component_info * compptr;
  154645. boolean need_buffer, do_fancy;
  154646. int h_in_group, v_in_group, h_out_group, v_out_group;
  154647. upsample = (my_upsample_ptr2)
  154648. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154649. SIZEOF(my_upsampler2));
  154650. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154651. upsample->pub.start_pass = start_pass_upsample;
  154652. upsample->pub.upsample = sep_upsample;
  154653. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  154654. if (cinfo->CCIR601_sampling) /* this isn't supported */
  154655. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  154656. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  154657. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154658. ci++, compptr++) {
  154659. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  154660. cinfo->min_DCT_scaled_size;
  154661. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  154662. cinfo->min_DCT_scaled_size;
  154663. h_out_group = cinfo->max_h_samp_factor;
  154664. v_out_group = cinfo->max_v_samp_factor;
  154665. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  154666. need_buffer = TRUE;
  154667. if (! compptr->component_needed) {
  154668. upsample->methods[ci] = noop_upsample;
  154669. need_buffer = FALSE;
  154670. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  154671. upsample->methods[ci] = fullsize_upsample;
  154672. need_buffer = FALSE;
  154673. } else if (h_in_group * 2 == h_out_group &&
  154674. v_in_group == v_out_group) {
  154675. if (do_fancy && compptr->downsampled_width > 2)
  154676. upsample->methods[ci] = h2v1_fancy_upsample;
  154677. else
  154678. upsample->methods[ci] = h2v1_upsample;
  154679. } else if (h_in_group * 2 == h_out_group &&
  154680. v_in_group * 2 == v_out_group) {
  154681. if (do_fancy && compptr->downsampled_width > 2) {
  154682. upsample->methods[ci] = h2v2_fancy_upsample;
  154683. upsample->pub.need_context_rows = TRUE;
  154684. } else
  154685. upsample->methods[ci] = h2v2_upsample;
  154686. } else if ((h_out_group % h_in_group) == 0 &&
  154687. (v_out_group % v_in_group) == 0) {
  154688. upsample->methods[ci] = int_upsample;
  154689. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  154690. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  154691. } else
  154692. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  154693. if (need_buffer) {
  154694. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  154695. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154696. (JDIMENSION) jround_up((long) cinfo->output_width,
  154697. (long) cinfo->max_h_samp_factor),
  154698. (JDIMENSION) cinfo->max_v_samp_factor);
  154699. }
  154700. }
  154701. }
  154702. /*** End of inlined file: jdsample.c ***/
  154703. /*** Start of inlined file: jdtrans.c ***/
  154704. #define JPEG_INTERNALS
  154705. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  154706. GLOBAL(jvirt_barray_ptr *)
  154707. jpeg_read_coefficients (j_decompress_ptr cinfo)
  154708. {
  154709. if (cinfo->global_state == DSTATE_READY) {
  154710. transdecode_master_selection(cinfo);
  154711. cinfo->global_state = DSTATE_RDCOEFS;
  154712. }
  154713. if (cinfo->global_state == DSTATE_RDCOEFS) {
  154714. for (;;) {
  154715. int retcode;
  154716. if (cinfo->progress != NULL)
  154717. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  154718. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  154719. if (retcode == JPEG_SUSPENDED)
  154720. return NULL;
  154721. if (retcode == JPEG_REACHED_EOI)
  154722. break;
  154723. if (cinfo->progress != NULL &&
  154724. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  154725. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  154726. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  154727. }
  154728. }
  154729. }
  154730. cinfo->global_state = DSTATE_STOPPING;
  154731. }
  154732. if ((cinfo->global_state == DSTATE_STOPPING ||
  154733. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  154734. return cinfo->coef->coef_arrays;
  154735. }
  154736. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154737. return NULL; /* keep compiler happy */
  154738. }
  154739. LOCAL(void)
  154740. transdecode_master_selection (j_decompress_ptr cinfo)
  154741. {
  154742. cinfo->buffered_image = TRUE;
  154743. if (cinfo->arith_code) {
  154744. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  154745. } else {
  154746. if (cinfo->progressive_mode) {
  154747. #ifdef D_PROGRESSIVE_SUPPORTED
  154748. jinit_phuff_decoder(cinfo);
  154749. #else
  154750. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154751. #endif
  154752. } else
  154753. jinit_huff_decoder(cinfo);
  154754. }
  154755. jinit_d_coef_controller(cinfo, TRUE);
  154756. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154757. (*cinfo->inputctl->start_input_pass) (cinfo);
  154758. if (cinfo->progress != NULL) {
  154759. int nscans;
  154760. if (cinfo->progressive_mode) {
  154761. nscans = 2 + 3 * cinfo->num_components;
  154762. } else if (cinfo->inputctl->has_multiple_scans) {
  154763. nscans = cinfo->num_components;
  154764. } else {
  154765. nscans = 1;
  154766. }
  154767. cinfo->progress->pass_counter = 0L;
  154768. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154769. cinfo->progress->completed_passes = 0;
  154770. cinfo->progress->total_passes = 1;
  154771. }
  154772. }
  154773. /*** End of inlined file: jdtrans.c ***/
  154774. /*** Start of inlined file: jfdctflt.c ***/
  154775. #define JPEG_INTERNALS
  154776. #ifdef DCT_FLOAT_SUPPORTED
  154777. #if DCTSIZE != 8
  154778. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154779. #endif
  154780. GLOBAL(void)
  154781. jpeg_fdct_float (FAST_FLOAT * data)
  154782. {
  154783. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154784. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  154785. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  154786. FAST_FLOAT *dataptr;
  154787. int ctr;
  154788. dataptr = data;
  154789. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154790. tmp0 = dataptr[0] + dataptr[7];
  154791. tmp7 = dataptr[0] - dataptr[7];
  154792. tmp1 = dataptr[1] + dataptr[6];
  154793. tmp6 = dataptr[1] - dataptr[6];
  154794. tmp2 = dataptr[2] + dataptr[5];
  154795. tmp5 = dataptr[2] - dataptr[5];
  154796. tmp3 = dataptr[3] + dataptr[4];
  154797. tmp4 = dataptr[3] - dataptr[4];
  154798. tmp10 = tmp0 + tmp3; /* phase 2 */
  154799. tmp13 = tmp0 - tmp3;
  154800. tmp11 = tmp1 + tmp2;
  154801. tmp12 = tmp1 - tmp2;
  154802. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  154803. dataptr[4] = tmp10 - tmp11;
  154804. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154805. dataptr[2] = tmp13 + z1; /* phase 5 */
  154806. dataptr[6] = tmp13 - z1;
  154807. tmp10 = tmp4 + tmp5; /* phase 2 */
  154808. tmp11 = tmp5 + tmp6;
  154809. tmp12 = tmp6 + tmp7;
  154810. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154811. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154812. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154813. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154814. z11 = tmp7 + z3; /* phase 5 */
  154815. z13 = tmp7 - z3;
  154816. dataptr[5] = z13 + z2; /* phase 6 */
  154817. dataptr[3] = z13 - z2;
  154818. dataptr[1] = z11 + z4;
  154819. dataptr[7] = z11 - z4;
  154820. dataptr += DCTSIZE; /* advance pointer to next row */
  154821. }
  154822. dataptr = data;
  154823. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154824. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154825. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154826. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154827. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154828. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154829. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154830. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154831. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154832. tmp10 = tmp0 + tmp3; /* phase 2 */
  154833. tmp13 = tmp0 - tmp3;
  154834. tmp11 = tmp1 + tmp2;
  154835. tmp12 = tmp1 - tmp2;
  154836. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  154837. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  154838. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  154839. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  154840. dataptr[DCTSIZE*6] = tmp13 - z1;
  154841. tmp10 = tmp4 + tmp5; /* phase 2 */
  154842. tmp11 = tmp5 + tmp6;
  154843. tmp12 = tmp6 + tmp7;
  154844. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  154845. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  154846. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  154847. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  154848. z11 = tmp7 + z3; /* phase 5 */
  154849. z13 = tmp7 - z3;
  154850. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  154851. dataptr[DCTSIZE*3] = z13 - z2;
  154852. dataptr[DCTSIZE*1] = z11 + z4;
  154853. dataptr[DCTSIZE*7] = z11 - z4;
  154854. dataptr++; /* advance pointer to next column */
  154855. }
  154856. }
  154857. #endif /* DCT_FLOAT_SUPPORTED */
  154858. /*** End of inlined file: jfdctflt.c ***/
  154859. /*** Start of inlined file: jfdctint.c ***/
  154860. #define JPEG_INTERNALS
  154861. #ifdef DCT_ISLOW_SUPPORTED
  154862. #if DCTSIZE != 8
  154863. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  154864. #endif
  154865. #if BITS_IN_JSAMPLE == 8
  154866. #define CONST_BITS 13
  154867. #define PASS1_BITS 2
  154868. #else
  154869. #define CONST_BITS 13
  154870. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  154871. #endif
  154872. #if CONST_BITS == 13
  154873. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  154874. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  154875. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  154876. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  154877. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  154878. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  154879. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  154880. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  154881. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  154882. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  154883. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  154884. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  154885. #else
  154886. #define FIX_0_298631336 FIX(0.298631336)
  154887. #define FIX_0_390180644 FIX(0.390180644)
  154888. #define FIX_0_541196100 FIX(0.541196100)
  154889. #define FIX_0_765366865 FIX(0.765366865)
  154890. #define FIX_0_899976223 FIX(0.899976223)
  154891. #define FIX_1_175875602 FIX(1.175875602)
  154892. #define FIX_1_501321110 FIX(1.501321110)
  154893. #define FIX_1_847759065 FIX(1.847759065)
  154894. #define FIX_1_961570560 FIX(1.961570560)
  154895. #define FIX_2_053119869 FIX(2.053119869)
  154896. #define FIX_2_562915447 FIX(2.562915447)
  154897. #define FIX_3_072711026 FIX(3.072711026)
  154898. #endif
  154899. #if BITS_IN_JSAMPLE == 8
  154900. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  154901. #else
  154902. #define MULTIPLY(var,const) ((var) * (const))
  154903. #endif
  154904. GLOBAL(void)
  154905. jpeg_fdct_islow (DCTELEM * data)
  154906. {
  154907. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  154908. INT32 tmp10, tmp11, tmp12, tmp13;
  154909. INT32 z1, z2, z3, z4, z5;
  154910. DCTELEM *dataptr;
  154911. int ctr;
  154912. SHIFT_TEMPS
  154913. dataptr = data;
  154914. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154915. tmp0 = dataptr[0] + dataptr[7];
  154916. tmp7 = dataptr[0] - dataptr[7];
  154917. tmp1 = dataptr[1] + dataptr[6];
  154918. tmp6 = dataptr[1] - dataptr[6];
  154919. tmp2 = dataptr[2] + dataptr[5];
  154920. tmp5 = dataptr[2] - dataptr[5];
  154921. tmp3 = dataptr[3] + dataptr[4];
  154922. tmp4 = dataptr[3] - dataptr[4];
  154923. tmp10 = tmp0 + tmp3;
  154924. tmp13 = tmp0 - tmp3;
  154925. tmp11 = tmp1 + tmp2;
  154926. tmp12 = tmp1 - tmp2;
  154927. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  154928. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  154929. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  154930. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  154931. CONST_BITS-PASS1_BITS);
  154932. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  154933. CONST_BITS-PASS1_BITS);
  154934. z1 = tmp4 + tmp7;
  154935. z2 = tmp5 + tmp6;
  154936. z3 = tmp4 + tmp6;
  154937. z4 = tmp5 + tmp7;
  154938. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  154939. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  154940. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  154941. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  154942. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  154943. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  154944. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  154945. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  154946. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  154947. z3 += z5;
  154948. z4 += z5;
  154949. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  154950. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  154951. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  154952. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  154953. dataptr += DCTSIZE; /* advance pointer to next row */
  154954. }
  154955. dataptr = data;
  154956. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  154957. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  154958. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  154959. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  154960. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  154961. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  154962. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  154963. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  154964. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  154965. tmp10 = tmp0 + tmp3;
  154966. tmp13 = tmp0 - tmp3;
  154967. tmp11 = tmp1 + tmp2;
  154968. tmp12 = tmp1 - tmp2;
  154969. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  154970. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  154971. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  154972. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  154973. CONST_BITS+PASS1_BITS);
  154974. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  154975. CONST_BITS+PASS1_BITS);
  154976. z1 = tmp4 + tmp7;
  154977. z2 = tmp5 + tmp6;
  154978. z3 = tmp4 + tmp6;
  154979. z4 = tmp5 + tmp7;
  154980. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  154981. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  154982. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  154983. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  154984. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  154985. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  154986. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  154987. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  154988. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  154989. z3 += z5;
  154990. z4 += z5;
  154991. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  154992. CONST_BITS+PASS1_BITS);
  154993. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  154994. CONST_BITS+PASS1_BITS);
  154995. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  154996. CONST_BITS+PASS1_BITS);
  154997. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  154998. CONST_BITS+PASS1_BITS);
  154999. dataptr++; /* advance pointer to next column */
  155000. }
  155001. }
  155002. #endif /* DCT_ISLOW_SUPPORTED */
  155003. /*** End of inlined file: jfdctint.c ***/
  155004. #undef CONST_BITS
  155005. #undef MULTIPLY
  155006. #undef FIX_0_541196100
  155007. /*** Start of inlined file: jfdctfst.c ***/
  155008. #define JPEG_INTERNALS
  155009. #ifdef DCT_IFAST_SUPPORTED
  155010. #if DCTSIZE != 8
  155011. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155012. #endif
  155013. #define CONST_BITS 8
  155014. #if CONST_BITS == 8
  155015. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155016. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155017. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155018. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155019. #else
  155020. #define FIX_0_382683433 FIX(0.382683433)
  155021. #define FIX_0_541196100 FIX(0.541196100)
  155022. #define FIX_0_707106781 FIX(0.707106781)
  155023. #define FIX_1_306562965 FIX(1.306562965)
  155024. #endif
  155025. #ifndef USE_ACCURATE_ROUNDING
  155026. #undef DESCALE
  155027. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155028. #endif
  155029. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155030. GLOBAL(void)
  155031. jpeg_fdct_ifast (DCTELEM * data)
  155032. {
  155033. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155034. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155035. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155036. DCTELEM *dataptr;
  155037. int ctr;
  155038. SHIFT_TEMPS
  155039. dataptr = data;
  155040. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155041. tmp0 = dataptr[0] + dataptr[7];
  155042. tmp7 = dataptr[0] - dataptr[7];
  155043. tmp1 = dataptr[1] + dataptr[6];
  155044. tmp6 = dataptr[1] - dataptr[6];
  155045. tmp2 = dataptr[2] + dataptr[5];
  155046. tmp5 = dataptr[2] - dataptr[5];
  155047. tmp3 = dataptr[3] + dataptr[4];
  155048. tmp4 = dataptr[3] - dataptr[4];
  155049. tmp10 = tmp0 + tmp3; /* phase 2 */
  155050. tmp13 = tmp0 - tmp3;
  155051. tmp11 = tmp1 + tmp2;
  155052. tmp12 = tmp1 - tmp2;
  155053. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155054. dataptr[4] = tmp10 - tmp11;
  155055. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155056. dataptr[2] = tmp13 + z1; /* phase 5 */
  155057. dataptr[6] = tmp13 - z1;
  155058. tmp10 = tmp4 + tmp5; /* phase 2 */
  155059. tmp11 = tmp5 + tmp6;
  155060. tmp12 = tmp6 + tmp7;
  155061. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155062. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155063. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155064. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155065. z11 = tmp7 + z3; /* phase 5 */
  155066. z13 = tmp7 - z3;
  155067. dataptr[5] = z13 + z2; /* phase 6 */
  155068. dataptr[3] = z13 - z2;
  155069. dataptr[1] = z11 + z4;
  155070. dataptr[7] = z11 - z4;
  155071. dataptr += DCTSIZE; /* advance pointer to next row */
  155072. }
  155073. dataptr = data;
  155074. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155075. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155076. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155077. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155078. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155079. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155080. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155081. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155082. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155083. tmp10 = tmp0 + tmp3; /* phase 2 */
  155084. tmp13 = tmp0 - tmp3;
  155085. tmp11 = tmp1 + tmp2;
  155086. tmp12 = tmp1 - tmp2;
  155087. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155088. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155089. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155090. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155091. dataptr[DCTSIZE*6] = tmp13 - z1;
  155092. tmp10 = tmp4 + tmp5; /* phase 2 */
  155093. tmp11 = tmp5 + tmp6;
  155094. tmp12 = tmp6 + tmp7;
  155095. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155096. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155097. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155098. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155099. z11 = tmp7 + z3; /* phase 5 */
  155100. z13 = tmp7 - z3;
  155101. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155102. dataptr[DCTSIZE*3] = z13 - z2;
  155103. dataptr[DCTSIZE*1] = z11 + z4;
  155104. dataptr[DCTSIZE*7] = z11 - z4;
  155105. dataptr++; /* advance pointer to next column */
  155106. }
  155107. }
  155108. #endif /* DCT_IFAST_SUPPORTED */
  155109. /*** End of inlined file: jfdctfst.c ***/
  155110. #undef FIX_0_541196100
  155111. /*** Start of inlined file: jidctflt.c ***/
  155112. #define JPEG_INTERNALS
  155113. #ifdef DCT_FLOAT_SUPPORTED
  155114. #if DCTSIZE != 8
  155115. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155116. #endif
  155117. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155118. GLOBAL(void)
  155119. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155120. JCOEFPTR coef_block,
  155121. JSAMPARRAY output_buf, JDIMENSION output_col)
  155122. {
  155123. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155124. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155125. FAST_FLOAT z5, z10, z11, z12, z13;
  155126. JCOEFPTR inptr;
  155127. FLOAT_MULT_TYPE * quantptr;
  155128. FAST_FLOAT * wsptr;
  155129. JSAMPROW outptr;
  155130. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155131. int ctr;
  155132. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155133. SHIFT_TEMPS
  155134. inptr = coef_block;
  155135. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155136. wsptr = workspace;
  155137. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155138. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155139. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155140. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155141. inptr[DCTSIZE*7] == 0) {
  155142. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155143. wsptr[DCTSIZE*0] = dcval;
  155144. wsptr[DCTSIZE*1] = dcval;
  155145. wsptr[DCTSIZE*2] = dcval;
  155146. wsptr[DCTSIZE*3] = dcval;
  155147. wsptr[DCTSIZE*4] = dcval;
  155148. wsptr[DCTSIZE*5] = dcval;
  155149. wsptr[DCTSIZE*6] = dcval;
  155150. wsptr[DCTSIZE*7] = dcval;
  155151. inptr++; /* advance pointers to next column */
  155152. quantptr++;
  155153. wsptr++;
  155154. continue;
  155155. }
  155156. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155157. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155158. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155159. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155160. tmp10 = tmp0 + tmp2; /* phase 3 */
  155161. tmp11 = tmp0 - tmp2;
  155162. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155163. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155164. tmp0 = tmp10 + tmp13; /* phase 2 */
  155165. tmp3 = tmp10 - tmp13;
  155166. tmp1 = tmp11 + tmp12;
  155167. tmp2 = tmp11 - tmp12;
  155168. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155169. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155170. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155171. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155172. z13 = tmp6 + tmp5; /* phase 6 */
  155173. z10 = tmp6 - tmp5;
  155174. z11 = tmp4 + tmp7;
  155175. z12 = tmp4 - tmp7;
  155176. tmp7 = z11 + z13; /* phase 5 */
  155177. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155178. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155179. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155180. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155181. tmp6 = tmp12 - tmp7; /* phase 2 */
  155182. tmp5 = tmp11 - tmp6;
  155183. tmp4 = tmp10 + tmp5;
  155184. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155185. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155186. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155187. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155188. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155189. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155190. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155191. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155192. inptr++; /* advance pointers to next column */
  155193. quantptr++;
  155194. wsptr++;
  155195. }
  155196. wsptr = workspace;
  155197. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155198. outptr = output_buf[ctr] + output_col;
  155199. tmp10 = wsptr[0] + wsptr[4];
  155200. tmp11 = wsptr[0] - wsptr[4];
  155201. tmp13 = wsptr[2] + wsptr[6];
  155202. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155203. tmp0 = tmp10 + tmp13;
  155204. tmp3 = tmp10 - tmp13;
  155205. tmp1 = tmp11 + tmp12;
  155206. tmp2 = tmp11 - tmp12;
  155207. z13 = wsptr[5] + wsptr[3];
  155208. z10 = wsptr[5] - wsptr[3];
  155209. z11 = wsptr[1] + wsptr[7];
  155210. z12 = wsptr[1] - wsptr[7];
  155211. tmp7 = z11 + z13;
  155212. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155213. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155214. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155215. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155216. tmp6 = tmp12 - tmp7;
  155217. tmp5 = tmp11 - tmp6;
  155218. tmp4 = tmp10 + tmp5;
  155219. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155220. & RANGE_MASK];
  155221. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155222. & RANGE_MASK];
  155223. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155224. & RANGE_MASK];
  155225. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155226. & RANGE_MASK];
  155227. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155228. & RANGE_MASK];
  155229. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155230. & RANGE_MASK];
  155231. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155232. & RANGE_MASK];
  155233. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155234. & RANGE_MASK];
  155235. wsptr += DCTSIZE; /* advance pointer to next row */
  155236. }
  155237. }
  155238. #endif /* DCT_FLOAT_SUPPORTED */
  155239. /*** End of inlined file: jidctflt.c ***/
  155240. #undef CONST_BITS
  155241. #undef FIX_1_847759065
  155242. #undef MULTIPLY
  155243. #undef DEQUANTIZE
  155244. #undef DESCALE
  155245. /*** Start of inlined file: jidctfst.c ***/
  155246. #define JPEG_INTERNALS
  155247. #ifdef DCT_IFAST_SUPPORTED
  155248. #if DCTSIZE != 8
  155249. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155250. #endif
  155251. #if BITS_IN_JSAMPLE == 8
  155252. #define CONST_BITS 8
  155253. #define PASS1_BITS 2
  155254. #else
  155255. #define CONST_BITS 8
  155256. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155257. #endif
  155258. #if CONST_BITS == 8
  155259. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155260. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155261. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155262. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155263. #else
  155264. #define FIX_1_082392200 FIX(1.082392200)
  155265. #define FIX_1_414213562 FIX(1.414213562)
  155266. #define FIX_1_847759065 FIX(1.847759065)
  155267. #define FIX_2_613125930 FIX(2.613125930)
  155268. #endif
  155269. #ifndef USE_ACCURATE_ROUNDING
  155270. #undef DESCALE
  155271. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155272. #endif
  155273. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155274. #if BITS_IN_JSAMPLE == 8
  155275. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155276. #else
  155277. #define DEQUANTIZE(coef,quantval) \
  155278. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155279. #endif
  155280. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155281. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155282. #if BITS_IN_JSAMPLE == 8
  155283. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155284. #else
  155285. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155286. #endif
  155287. #define IRIGHT_SHIFT(x,shft) \
  155288. ((ishift_temp = (x)) < 0 ? \
  155289. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155290. (ishift_temp >> (shft)))
  155291. #else
  155292. #define ISHIFT_TEMPS
  155293. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155294. #endif
  155295. #ifdef USE_ACCURATE_ROUNDING
  155296. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155297. #else
  155298. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155299. #endif
  155300. GLOBAL(void)
  155301. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155302. JCOEFPTR coef_block,
  155303. JSAMPARRAY output_buf, JDIMENSION output_col)
  155304. {
  155305. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155306. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155307. DCTELEM z5, z10, z11, z12, z13;
  155308. JCOEFPTR inptr;
  155309. IFAST_MULT_TYPE * quantptr;
  155310. int * wsptr;
  155311. JSAMPROW outptr;
  155312. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155313. int ctr;
  155314. int workspace[DCTSIZE2]; /* buffers data between passes */
  155315. SHIFT_TEMPS /* for DESCALE */
  155316. ISHIFT_TEMPS /* for IDESCALE */
  155317. inptr = coef_block;
  155318. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155319. wsptr = workspace;
  155320. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155321. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155322. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155323. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155324. inptr[DCTSIZE*7] == 0) {
  155325. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155326. wsptr[DCTSIZE*0] = dcval;
  155327. wsptr[DCTSIZE*1] = dcval;
  155328. wsptr[DCTSIZE*2] = dcval;
  155329. wsptr[DCTSIZE*3] = dcval;
  155330. wsptr[DCTSIZE*4] = dcval;
  155331. wsptr[DCTSIZE*5] = dcval;
  155332. wsptr[DCTSIZE*6] = dcval;
  155333. wsptr[DCTSIZE*7] = dcval;
  155334. inptr++; /* advance pointers to next column */
  155335. quantptr++;
  155336. wsptr++;
  155337. continue;
  155338. }
  155339. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155340. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155341. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155342. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155343. tmp10 = tmp0 + tmp2; /* phase 3 */
  155344. tmp11 = tmp0 - tmp2;
  155345. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155346. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155347. tmp0 = tmp10 + tmp13; /* phase 2 */
  155348. tmp3 = tmp10 - tmp13;
  155349. tmp1 = tmp11 + tmp12;
  155350. tmp2 = tmp11 - tmp12;
  155351. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155352. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155353. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155354. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155355. z13 = tmp6 + tmp5; /* phase 6 */
  155356. z10 = tmp6 - tmp5;
  155357. z11 = tmp4 + tmp7;
  155358. z12 = tmp4 - tmp7;
  155359. tmp7 = z11 + z13; /* phase 5 */
  155360. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155361. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155362. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155363. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155364. tmp6 = tmp12 - tmp7; /* phase 2 */
  155365. tmp5 = tmp11 - tmp6;
  155366. tmp4 = tmp10 + tmp5;
  155367. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155368. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155369. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155370. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155371. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155372. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155373. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155374. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155375. inptr++; /* advance pointers to next column */
  155376. quantptr++;
  155377. wsptr++;
  155378. }
  155379. wsptr = workspace;
  155380. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155381. outptr = output_buf[ctr] + output_col;
  155382. #ifndef NO_ZERO_ROW_TEST
  155383. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155384. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155385. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155386. & RANGE_MASK];
  155387. outptr[0] = dcval;
  155388. outptr[1] = dcval;
  155389. outptr[2] = dcval;
  155390. outptr[3] = dcval;
  155391. outptr[4] = dcval;
  155392. outptr[5] = dcval;
  155393. outptr[6] = dcval;
  155394. outptr[7] = dcval;
  155395. wsptr += DCTSIZE; /* advance pointer to next row */
  155396. continue;
  155397. }
  155398. #endif
  155399. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155400. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155401. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155402. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155403. - tmp13;
  155404. tmp0 = tmp10 + tmp13;
  155405. tmp3 = tmp10 - tmp13;
  155406. tmp1 = tmp11 + tmp12;
  155407. tmp2 = tmp11 - tmp12;
  155408. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155409. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155410. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155411. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155412. tmp7 = z11 + z13; /* phase 5 */
  155413. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155414. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155415. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155416. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155417. tmp6 = tmp12 - tmp7; /* phase 2 */
  155418. tmp5 = tmp11 - tmp6;
  155419. tmp4 = tmp10 + tmp5;
  155420. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155421. & RANGE_MASK];
  155422. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155423. & RANGE_MASK];
  155424. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155425. & RANGE_MASK];
  155426. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155427. & RANGE_MASK];
  155428. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155429. & RANGE_MASK];
  155430. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155431. & RANGE_MASK];
  155432. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155433. & RANGE_MASK];
  155434. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155435. & RANGE_MASK];
  155436. wsptr += DCTSIZE; /* advance pointer to next row */
  155437. }
  155438. }
  155439. #endif /* DCT_IFAST_SUPPORTED */
  155440. /*** End of inlined file: jidctfst.c ***/
  155441. #undef CONST_BITS
  155442. #undef FIX_1_847759065
  155443. #undef MULTIPLY
  155444. #undef DEQUANTIZE
  155445. /*** Start of inlined file: jidctint.c ***/
  155446. #define JPEG_INTERNALS
  155447. #ifdef DCT_ISLOW_SUPPORTED
  155448. #if DCTSIZE != 8
  155449. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155450. #endif
  155451. #if BITS_IN_JSAMPLE == 8
  155452. #define CONST_BITS 13
  155453. #define PASS1_BITS 2
  155454. #else
  155455. #define CONST_BITS 13
  155456. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155457. #endif
  155458. #if CONST_BITS == 13
  155459. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155460. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155461. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155462. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155463. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155464. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155465. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155466. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155467. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155468. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155469. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155470. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155471. #else
  155472. #define FIX_0_298631336 FIX(0.298631336)
  155473. #define FIX_0_390180644 FIX(0.390180644)
  155474. #define FIX_0_541196100 FIX(0.541196100)
  155475. #define FIX_0_765366865 FIX(0.765366865)
  155476. #define FIX_0_899976223 FIX(0.899976223)
  155477. #define FIX_1_175875602 FIX(1.175875602)
  155478. #define FIX_1_501321110 FIX(1.501321110)
  155479. #define FIX_1_847759065 FIX(1.847759065)
  155480. #define FIX_1_961570560 FIX(1.961570560)
  155481. #define FIX_2_053119869 FIX(2.053119869)
  155482. #define FIX_2_562915447 FIX(2.562915447)
  155483. #define FIX_3_072711026 FIX(3.072711026)
  155484. #endif
  155485. #if BITS_IN_JSAMPLE == 8
  155486. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155487. #else
  155488. #define MULTIPLY(var,const) ((var) * (const))
  155489. #endif
  155490. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155491. GLOBAL(void)
  155492. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155493. JCOEFPTR coef_block,
  155494. JSAMPARRAY output_buf, JDIMENSION output_col)
  155495. {
  155496. INT32 tmp0, tmp1, tmp2, tmp3;
  155497. INT32 tmp10, tmp11, tmp12, tmp13;
  155498. INT32 z1, z2, z3, z4, z5;
  155499. JCOEFPTR inptr;
  155500. ISLOW_MULT_TYPE * quantptr;
  155501. int * wsptr;
  155502. JSAMPROW outptr;
  155503. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155504. int ctr;
  155505. int workspace[DCTSIZE2]; /* buffers data between passes */
  155506. SHIFT_TEMPS
  155507. inptr = coef_block;
  155508. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155509. wsptr = workspace;
  155510. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155511. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155512. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155513. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155514. inptr[DCTSIZE*7] == 0) {
  155515. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155516. wsptr[DCTSIZE*0] = dcval;
  155517. wsptr[DCTSIZE*1] = dcval;
  155518. wsptr[DCTSIZE*2] = dcval;
  155519. wsptr[DCTSIZE*3] = dcval;
  155520. wsptr[DCTSIZE*4] = dcval;
  155521. wsptr[DCTSIZE*5] = dcval;
  155522. wsptr[DCTSIZE*6] = dcval;
  155523. wsptr[DCTSIZE*7] = dcval;
  155524. inptr++; /* advance pointers to next column */
  155525. quantptr++;
  155526. wsptr++;
  155527. continue;
  155528. }
  155529. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155530. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155531. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155532. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155533. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155534. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155535. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155536. tmp0 = (z2 + z3) << CONST_BITS;
  155537. tmp1 = (z2 - z3) << CONST_BITS;
  155538. tmp10 = tmp0 + tmp3;
  155539. tmp13 = tmp0 - tmp3;
  155540. tmp11 = tmp1 + tmp2;
  155541. tmp12 = tmp1 - tmp2;
  155542. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155543. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155544. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155545. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155546. z1 = tmp0 + tmp3;
  155547. z2 = tmp1 + tmp2;
  155548. z3 = tmp0 + tmp2;
  155549. z4 = tmp1 + tmp3;
  155550. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155551. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155552. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155553. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155554. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155555. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155556. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155557. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155558. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155559. z3 += z5;
  155560. z4 += z5;
  155561. tmp0 += z1 + z3;
  155562. tmp1 += z2 + z4;
  155563. tmp2 += z2 + z3;
  155564. tmp3 += z1 + z4;
  155565. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  155566. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  155567. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  155568. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  155569. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  155570. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  155571. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  155572. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  155573. inptr++; /* advance pointers to next column */
  155574. quantptr++;
  155575. wsptr++;
  155576. }
  155577. wsptr = workspace;
  155578. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155579. outptr = output_buf[ctr] + output_col;
  155580. #ifndef NO_ZERO_ROW_TEST
  155581. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155582. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155583. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155584. & RANGE_MASK];
  155585. outptr[0] = dcval;
  155586. outptr[1] = dcval;
  155587. outptr[2] = dcval;
  155588. outptr[3] = dcval;
  155589. outptr[4] = dcval;
  155590. outptr[5] = dcval;
  155591. outptr[6] = dcval;
  155592. outptr[7] = dcval;
  155593. wsptr += DCTSIZE; /* advance pointer to next row */
  155594. continue;
  155595. }
  155596. #endif
  155597. z2 = (INT32) wsptr[2];
  155598. z3 = (INT32) wsptr[6];
  155599. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  155600. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  155601. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  155602. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  155603. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  155604. tmp10 = tmp0 + tmp3;
  155605. tmp13 = tmp0 - tmp3;
  155606. tmp11 = tmp1 + tmp2;
  155607. tmp12 = tmp1 - tmp2;
  155608. tmp0 = (INT32) wsptr[7];
  155609. tmp1 = (INT32) wsptr[5];
  155610. tmp2 = (INT32) wsptr[3];
  155611. tmp3 = (INT32) wsptr[1];
  155612. z1 = tmp0 + tmp3;
  155613. z2 = tmp1 + tmp2;
  155614. z3 = tmp0 + tmp2;
  155615. z4 = tmp1 + tmp3;
  155616. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155617. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155618. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155619. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155620. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155621. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155622. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155623. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155624. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155625. z3 += z5;
  155626. z4 += z5;
  155627. tmp0 += z1 + z3;
  155628. tmp1 += z2 + z4;
  155629. tmp2 += z2 + z3;
  155630. tmp3 += z1 + z4;
  155631. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  155632. CONST_BITS+PASS1_BITS+3)
  155633. & RANGE_MASK];
  155634. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  155635. CONST_BITS+PASS1_BITS+3)
  155636. & RANGE_MASK];
  155637. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  155638. CONST_BITS+PASS1_BITS+3)
  155639. & RANGE_MASK];
  155640. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  155641. CONST_BITS+PASS1_BITS+3)
  155642. & RANGE_MASK];
  155643. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  155644. CONST_BITS+PASS1_BITS+3)
  155645. & RANGE_MASK];
  155646. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  155647. CONST_BITS+PASS1_BITS+3)
  155648. & RANGE_MASK];
  155649. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  155650. CONST_BITS+PASS1_BITS+3)
  155651. & RANGE_MASK];
  155652. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  155653. CONST_BITS+PASS1_BITS+3)
  155654. & RANGE_MASK];
  155655. wsptr += DCTSIZE; /* advance pointer to next row */
  155656. }
  155657. }
  155658. #endif /* DCT_ISLOW_SUPPORTED */
  155659. /*** End of inlined file: jidctint.c ***/
  155660. /*** Start of inlined file: jidctred.c ***/
  155661. #define JPEG_INTERNALS
  155662. #ifdef IDCT_SCALING_SUPPORTED
  155663. #if DCTSIZE != 8
  155664. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155665. #endif
  155666. #if BITS_IN_JSAMPLE == 8
  155667. #define CONST_BITS 13
  155668. #define PASS1_BITS 2
  155669. #else
  155670. #define CONST_BITS 13
  155671. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155672. #endif
  155673. #if CONST_BITS == 13
  155674. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  155675. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  155676. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  155677. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  155678. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155679. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  155680. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155681. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  155682. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  155683. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  155684. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155685. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  155686. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155687. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  155688. #else
  155689. #define FIX_0_211164243 FIX(0.211164243)
  155690. #define FIX_0_509795579 FIX(0.509795579)
  155691. #define FIX_0_601344887 FIX(0.601344887)
  155692. #define FIX_0_720959822 FIX(0.720959822)
  155693. #define FIX_0_765366865 FIX(0.765366865)
  155694. #define FIX_0_850430095 FIX(0.850430095)
  155695. #define FIX_0_899976223 FIX(0.899976223)
  155696. #define FIX_1_061594337 FIX(1.061594337)
  155697. #define FIX_1_272758580 FIX(1.272758580)
  155698. #define FIX_1_451774981 FIX(1.451774981)
  155699. #define FIX_1_847759065 FIX(1.847759065)
  155700. #define FIX_2_172734803 FIX(2.172734803)
  155701. #define FIX_2_562915447 FIX(2.562915447)
  155702. #define FIX_3_624509785 FIX(3.624509785)
  155703. #endif
  155704. #if BITS_IN_JSAMPLE == 8
  155705. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155706. #else
  155707. #define MULTIPLY(var,const) ((var) * (const))
  155708. #endif
  155709. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155710. GLOBAL(void)
  155711. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155712. JCOEFPTR coef_block,
  155713. JSAMPARRAY output_buf, JDIMENSION output_col)
  155714. {
  155715. INT32 tmp0, tmp2, tmp10, tmp12;
  155716. INT32 z1, z2, z3, z4;
  155717. JCOEFPTR inptr;
  155718. ISLOW_MULT_TYPE * quantptr;
  155719. int * wsptr;
  155720. JSAMPROW outptr;
  155721. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155722. int ctr;
  155723. int workspace[DCTSIZE*4]; /* buffers data between passes */
  155724. SHIFT_TEMPS
  155725. inptr = coef_block;
  155726. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155727. wsptr = workspace;
  155728. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155729. if (ctr == DCTSIZE-4)
  155730. continue;
  155731. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155732. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  155733. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  155734. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155735. wsptr[DCTSIZE*0] = dcval;
  155736. wsptr[DCTSIZE*1] = dcval;
  155737. wsptr[DCTSIZE*2] = dcval;
  155738. wsptr[DCTSIZE*3] = dcval;
  155739. continue;
  155740. }
  155741. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155742. tmp0 <<= (CONST_BITS+1);
  155743. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155744. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155745. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  155746. tmp10 = tmp0 + tmp2;
  155747. tmp12 = tmp0 - tmp2;
  155748. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155749. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155750. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155751. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155752. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155753. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155754. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155755. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155756. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155757. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155758. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155759. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155760. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  155761. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  155762. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  155763. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  155764. }
  155765. wsptr = workspace;
  155766. for (ctr = 0; ctr < 4; ctr++) {
  155767. outptr = output_buf[ctr] + output_col;
  155768. #ifndef NO_ZERO_ROW_TEST
  155769. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  155770. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155771. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155772. & RANGE_MASK];
  155773. outptr[0] = dcval;
  155774. outptr[1] = dcval;
  155775. outptr[2] = dcval;
  155776. outptr[3] = dcval;
  155777. wsptr += DCTSIZE; /* advance pointer to next row */
  155778. continue;
  155779. }
  155780. #endif
  155781. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  155782. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  155783. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  155784. tmp10 = tmp0 + tmp2;
  155785. tmp12 = tmp0 - tmp2;
  155786. z1 = (INT32) wsptr[7];
  155787. z2 = (INT32) wsptr[5];
  155788. z3 = (INT32) wsptr[3];
  155789. z4 = (INT32) wsptr[1];
  155790. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  155791. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  155792. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  155793. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  155794. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  155795. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  155796. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  155797. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  155798. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  155799. CONST_BITS+PASS1_BITS+3+1)
  155800. & RANGE_MASK];
  155801. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  155802. CONST_BITS+PASS1_BITS+3+1)
  155803. & RANGE_MASK];
  155804. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  155805. CONST_BITS+PASS1_BITS+3+1)
  155806. & RANGE_MASK];
  155807. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  155808. CONST_BITS+PASS1_BITS+3+1)
  155809. & RANGE_MASK];
  155810. wsptr += DCTSIZE; /* advance pointer to next row */
  155811. }
  155812. }
  155813. GLOBAL(void)
  155814. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155815. JCOEFPTR coef_block,
  155816. JSAMPARRAY output_buf, JDIMENSION output_col)
  155817. {
  155818. INT32 tmp0, tmp10, z1;
  155819. JCOEFPTR inptr;
  155820. ISLOW_MULT_TYPE * quantptr;
  155821. int * wsptr;
  155822. JSAMPROW outptr;
  155823. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155824. int ctr;
  155825. int workspace[DCTSIZE*2]; /* buffers data between passes */
  155826. SHIFT_TEMPS
  155827. inptr = coef_block;
  155828. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155829. wsptr = workspace;
  155830. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  155831. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  155832. continue;
  155833. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  155834. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  155835. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  155836. wsptr[DCTSIZE*0] = dcval;
  155837. wsptr[DCTSIZE*1] = dcval;
  155838. continue;
  155839. }
  155840. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155841. tmp10 = z1 << (CONST_BITS+2);
  155842. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155843. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  155844. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155845. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  155846. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155847. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  155848. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155849. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155850. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  155851. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  155852. }
  155853. wsptr = workspace;
  155854. for (ctr = 0; ctr < 2; ctr++) {
  155855. outptr = output_buf[ctr] + output_col;
  155856. #ifndef NO_ZERO_ROW_TEST
  155857. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  155858. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  155859. & RANGE_MASK];
  155860. outptr[0] = dcval;
  155861. outptr[1] = dcval;
  155862. wsptr += DCTSIZE; /* advance pointer to next row */
  155863. continue;
  155864. }
  155865. #endif
  155866. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  155867. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  155868. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  155869. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  155870. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  155871. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  155872. CONST_BITS+PASS1_BITS+3+2)
  155873. & RANGE_MASK];
  155874. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  155875. CONST_BITS+PASS1_BITS+3+2)
  155876. & RANGE_MASK];
  155877. wsptr += DCTSIZE; /* advance pointer to next row */
  155878. }
  155879. }
  155880. GLOBAL(void)
  155881. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155882. JCOEFPTR coef_block,
  155883. JSAMPARRAY output_buf, JDIMENSION output_col)
  155884. {
  155885. int dcval;
  155886. ISLOW_MULT_TYPE * quantptr;
  155887. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155888. SHIFT_TEMPS
  155889. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155890. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  155891. dcval = (int) DESCALE((INT32) dcval, 3);
  155892. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  155893. }
  155894. #endif /* IDCT_SCALING_SUPPORTED */
  155895. /*** End of inlined file: jidctred.c ***/
  155896. /*** Start of inlined file: jmemmgr.c ***/
  155897. #define JPEG_INTERNALS
  155898. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  155899. /*** Start of inlined file: jmemsys.h ***/
  155900. #ifndef __jmemsys_h__
  155901. #define __jmemsys_h__
  155902. #ifdef NEED_SHORT_EXTERNAL_NAMES
  155903. #define jpeg_get_small jGetSmall
  155904. #define jpeg_free_small jFreeSmall
  155905. #define jpeg_get_large jGetLarge
  155906. #define jpeg_free_large jFreeLarge
  155907. #define jpeg_mem_available jMemAvail
  155908. #define jpeg_open_backing_store jOpenBackStore
  155909. #define jpeg_mem_init jMemInit
  155910. #define jpeg_mem_term jMemTerm
  155911. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  155912. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  155913. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  155914. size_t sizeofobject));
  155915. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  155916. size_t sizeofobject));
  155917. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  155918. size_t sizeofobject));
  155919. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  155920. #define MAX_ALLOC_CHUNK 1000000000L
  155921. #endif
  155922. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  155923. long min_bytes_needed,
  155924. long max_bytes_needed,
  155925. long already_allocated));
  155926. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  155927. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  155928. typedef unsigned short XMSH; /* type of extended-memory handles */
  155929. typedef unsigned short EMSH; /* type of expanded-memory handles */
  155930. typedef union {
  155931. short file_handle; /* DOS file handle if it's a temp file */
  155932. XMSH xms_handle; /* handle if it's a chunk of XMS */
  155933. EMSH ems_handle; /* handle if it's a chunk of EMS */
  155934. } handle_union;
  155935. #endif /* USE_MSDOS_MEMMGR */
  155936. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  155937. #include <Files.h>
  155938. #endif /* USE_MAC_MEMMGR */
  155939. //typedef struct backing_store_struct * backing_store_ptr;
  155940. typedef struct backing_store_struct {
  155941. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  155942. struct backing_store_struct *info,
  155943. void FAR * buffer_address,
  155944. long file_offset, long byte_count));
  155945. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  155946. struct backing_store_struct *info,
  155947. void FAR * buffer_address,
  155948. long file_offset, long byte_count));
  155949. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  155950. struct backing_store_struct *info));
  155951. #ifdef USE_MSDOS_MEMMGR
  155952. handle_union handle; /* reference to backing-store storage object */
  155953. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  155954. #else
  155955. #ifdef USE_MAC_MEMMGR
  155956. short temp_file; /* file reference number to temp file */
  155957. FSSpec tempSpec; /* the FSSpec for the temp file */
  155958. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  155959. #else
  155960. FILE * temp_file; /* stdio reference to temp file */
  155961. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  155962. #endif
  155963. #endif
  155964. } backing_store_info;
  155965. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  155966. struct backing_store_struct *info,
  155967. long total_bytes_needed));
  155968. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  155969. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  155970. #endif
  155971. /*** End of inlined file: jmemsys.h ***/
  155972. /* import the system-dependent declarations */
  155973. #ifndef NO_GETENV
  155974. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  155975. extern char * getenv JPP((const char * name));
  155976. #endif
  155977. #endif
  155978. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  155979. #define ALIGN_TYPE double
  155980. #endif
  155981. typedef union small_pool_struct * small_pool_ptr;
  155982. typedef union small_pool_struct {
  155983. struct {
  155984. small_pool_ptr next; /* next in list of pools */
  155985. size_t bytes_used; /* how many bytes already used within pool */
  155986. size_t bytes_left; /* bytes still available in this pool */
  155987. } hdr;
  155988. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  155989. } small_pool_hdr;
  155990. typedef union large_pool_struct FAR * large_pool_ptr;
  155991. typedef union large_pool_struct {
  155992. struct {
  155993. large_pool_ptr next; /* next in list of pools */
  155994. size_t bytes_used; /* how many bytes already used within pool */
  155995. size_t bytes_left; /* bytes still available in this pool */
  155996. } hdr;
  155997. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  155998. } large_pool_hdr;
  155999. typedef struct {
  156000. struct jpeg_memory_mgr pub; /* public fields */
  156001. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156002. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156003. jvirt_sarray_ptr virt_sarray_list;
  156004. jvirt_barray_ptr virt_barray_list;
  156005. long total_space_allocated;
  156006. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156007. } my_memory_mgr;
  156008. typedef my_memory_mgr * my_mem_ptr;
  156009. struct jvirt_sarray_control {
  156010. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156011. JDIMENSION rows_in_array; /* total virtual array height */
  156012. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156013. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156014. JDIMENSION rows_in_mem; /* height of memory buffer */
  156015. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156016. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156017. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156018. boolean pre_zero; /* pre-zero mode requested? */
  156019. boolean dirty; /* do current buffer contents need written? */
  156020. boolean b_s_open; /* is backing-store data valid? */
  156021. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156022. backing_store_info b_s_info; /* System-dependent control info */
  156023. };
  156024. struct jvirt_barray_control {
  156025. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156026. JDIMENSION rows_in_array; /* total virtual array height */
  156027. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156028. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156029. JDIMENSION rows_in_mem; /* height of memory buffer */
  156030. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156031. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156032. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156033. boolean pre_zero; /* pre-zero mode requested? */
  156034. boolean dirty; /* do current buffer contents need written? */
  156035. boolean b_s_open; /* is backing-store data valid? */
  156036. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156037. backing_store_info b_s_info; /* System-dependent control info */
  156038. };
  156039. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156040. LOCAL(void)
  156041. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156042. {
  156043. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156044. small_pool_ptr shdr_ptr;
  156045. large_pool_ptr lhdr_ptr;
  156046. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156047. pool_id, mem->total_space_allocated);
  156048. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156049. lhdr_ptr = lhdr_ptr->hdr.next) {
  156050. fprintf(stderr, " Large chunk used %ld\n",
  156051. (long) lhdr_ptr->hdr.bytes_used);
  156052. }
  156053. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156054. shdr_ptr = shdr_ptr->hdr.next) {
  156055. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156056. (long) shdr_ptr->hdr.bytes_used,
  156057. (long) shdr_ptr->hdr.bytes_left);
  156058. }
  156059. }
  156060. #endif /* MEM_STATS */
  156061. LOCAL(void)
  156062. out_of_memory (j_common_ptr cinfo, int which)
  156063. {
  156064. #ifdef MEM_STATS
  156065. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156066. #endif
  156067. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156068. }
  156069. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156070. {
  156071. 1600, /* first PERMANENT pool */
  156072. 16000 /* first IMAGE pool */
  156073. };
  156074. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156075. {
  156076. 0, /* additional PERMANENT pools */
  156077. 5000 /* additional IMAGE pools */
  156078. };
  156079. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156080. METHODDEF(void *)
  156081. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156082. {
  156083. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156084. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156085. char * data_ptr;
  156086. size_t odd_bytes, min_request, slop;
  156087. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156088. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156089. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156090. if (odd_bytes > 0)
  156091. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156092. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156093. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156094. prev_hdr_ptr = NULL;
  156095. hdr_ptr = mem->small_list[pool_id];
  156096. while (hdr_ptr != NULL) {
  156097. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156098. break; /* found pool with enough space */
  156099. prev_hdr_ptr = hdr_ptr;
  156100. hdr_ptr = hdr_ptr->hdr.next;
  156101. }
  156102. if (hdr_ptr == NULL) {
  156103. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156104. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156105. slop = first_pool_slop[pool_id];
  156106. else
  156107. slop = extra_pool_slop[pool_id];
  156108. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156109. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156110. for (;;) {
  156111. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156112. if (hdr_ptr != NULL)
  156113. break;
  156114. slop /= 2;
  156115. if (slop < MIN_SLOP) /* give up when it gets real small */
  156116. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156117. }
  156118. mem->total_space_allocated += min_request + slop;
  156119. hdr_ptr->hdr.next = NULL;
  156120. hdr_ptr->hdr.bytes_used = 0;
  156121. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156122. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156123. mem->small_list[pool_id] = hdr_ptr;
  156124. else
  156125. prev_hdr_ptr->hdr.next = hdr_ptr;
  156126. }
  156127. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156128. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156129. hdr_ptr->hdr.bytes_used += sizeofobject;
  156130. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156131. return (void *) data_ptr;
  156132. }
  156133. METHODDEF(void FAR *)
  156134. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156135. {
  156136. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156137. large_pool_ptr hdr_ptr;
  156138. size_t odd_bytes;
  156139. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156140. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156141. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156142. if (odd_bytes > 0)
  156143. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156144. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156145. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156146. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156147. SIZEOF(large_pool_hdr));
  156148. if (hdr_ptr == NULL)
  156149. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156150. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156151. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156152. hdr_ptr->hdr.bytes_used = sizeofobject;
  156153. hdr_ptr->hdr.bytes_left = 0;
  156154. mem->large_list[pool_id] = hdr_ptr;
  156155. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156156. }
  156157. METHODDEF(JSAMPARRAY)
  156158. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156159. JDIMENSION samplesperrow, JDIMENSION numrows)
  156160. {
  156161. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156162. JSAMPARRAY result;
  156163. JSAMPROW workspace;
  156164. JDIMENSION rowsperchunk, currow, i;
  156165. long ltemp;
  156166. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156167. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156168. if (ltemp <= 0)
  156169. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156170. if (ltemp < (long) numrows)
  156171. rowsperchunk = (JDIMENSION) ltemp;
  156172. else
  156173. rowsperchunk = numrows;
  156174. mem->last_rowsperchunk = rowsperchunk;
  156175. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156176. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156177. currow = 0;
  156178. while (currow < numrows) {
  156179. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156180. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156181. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156182. * SIZEOF(JSAMPLE)));
  156183. for (i = rowsperchunk; i > 0; i--) {
  156184. result[currow++] = workspace;
  156185. workspace += samplesperrow;
  156186. }
  156187. }
  156188. return result;
  156189. }
  156190. METHODDEF(JBLOCKARRAY)
  156191. alloc_barray (j_common_ptr cinfo, int pool_id,
  156192. JDIMENSION blocksperrow, JDIMENSION numrows)
  156193. {
  156194. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156195. JBLOCKARRAY result;
  156196. JBLOCKROW workspace;
  156197. JDIMENSION rowsperchunk, currow, i;
  156198. long ltemp;
  156199. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156200. ((long) blocksperrow * SIZEOF(JBLOCK));
  156201. if (ltemp <= 0)
  156202. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156203. if (ltemp < (long) numrows)
  156204. rowsperchunk = (JDIMENSION) ltemp;
  156205. else
  156206. rowsperchunk = numrows;
  156207. mem->last_rowsperchunk = rowsperchunk;
  156208. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156209. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156210. currow = 0;
  156211. while (currow < numrows) {
  156212. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156213. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156214. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156215. * SIZEOF(JBLOCK)));
  156216. for (i = rowsperchunk; i > 0; i--) {
  156217. result[currow++] = workspace;
  156218. workspace += blocksperrow;
  156219. }
  156220. }
  156221. return result;
  156222. }
  156223. METHODDEF(jvirt_sarray_ptr)
  156224. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156225. JDIMENSION samplesperrow, JDIMENSION numrows,
  156226. JDIMENSION maxaccess)
  156227. {
  156228. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156229. jvirt_sarray_ptr result;
  156230. if (pool_id != JPOOL_IMAGE)
  156231. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156232. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156233. SIZEOF(struct jvirt_sarray_control));
  156234. result->mem_buffer = NULL; /* marks array not yet realized */
  156235. result->rows_in_array = numrows;
  156236. result->samplesperrow = samplesperrow;
  156237. result->maxaccess = maxaccess;
  156238. result->pre_zero = pre_zero;
  156239. result->b_s_open = FALSE; /* no associated backing-store object */
  156240. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156241. mem->virt_sarray_list = result;
  156242. return result;
  156243. }
  156244. METHODDEF(jvirt_barray_ptr)
  156245. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156246. JDIMENSION blocksperrow, JDIMENSION numrows,
  156247. JDIMENSION maxaccess)
  156248. {
  156249. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156250. jvirt_barray_ptr result;
  156251. if (pool_id != JPOOL_IMAGE)
  156252. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156253. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156254. SIZEOF(struct jvirt_barray_control));
  156255. result->mem_buffer = NULL; /* marks array not yet realized */
  156256. result->rows_in_array = numrows;
  156257. result->blocksperrow = blocksperrow;
  156258. result->maxaccess = maxaccess;
  156259. result->pre_zero = pre_zero;
  156260. result->b_s_open = FALSE; /* no associated backing-store object */
  156261. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156262. mem->virt_barray_list = result;
  156263. return result;
  156264. }
  156265. METHODDEF(void)
  156266. realize_virt_arrays (j_common_ptr cinfo)
  156267. {
  156268. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156269. long space_per_minheight, maximum_space, avail_mem;
  156270. long minheights, max_minheights;
  156271. jvirt_sarray_ptr sptr;
  156272. jvirt_barray_ptr bptr;
  156273. space_per_minheight = 0;
  156274. maximum_space = 0;
  156275. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156276. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156277. space_per_minheight += (long) sptr->maxaccess *
  156278. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156279. maximum_space += (long) sptr->rows_in_array *
  156280. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156281. }
  156282. }
  156283. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156284. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156285. space_per_minheight += (long) bptr->maxaccess *
  156286. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156287. maximum_space += (long) bptr->rows_in_array *
  156288. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156289. }
  156290. }
  156291. if (space_per_minheight <= 0)
  156292. return; /* no unrealized arrays, no work */
  156293. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156294. mem->total_space_allocated);
  156295. if (avail_mem >= maximum_space)
  156296. max_minheights = 1000000000L;
  156297. else {
  156298. max_minheights = avail_mem / space_per_minheight;
  156299. if (max_minheights <= 0)
  156300. max_minheights = 1;
  156301. }
  156302. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156303. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156304. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156305. if (minheights <= max_minheights) {
  156306. sptr->rows_in_mem = sptr->rows_in_array;
  156307. } else {
  156308. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156309. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156310. (long) sptr->rows_in_array *
  156311. (long) sptr->samplesperrow *
  156312. (long) SIZEOF(JSAMPLE));
  156313. sptr->b_s_open = TRUE;
  156314. }
  156315. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156316. sptr->samplesperrow, sptr->rows_in_mem);
  156317. sptr->rowsperchunk = mem->last_rowsperchunk;
  156318. sptr->cur_start_row = 0;
  156319. sptr->first_undef_row = 0;
  156320. sptr->dirty = FALSE;
  156321. }
  156322. }
  156323. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156324. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156325. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156326. if (minheights <= max_minheights) {
  156327. bptr->rows_in_mem = bptr->rows_in_array;
  156328. } else {
  156329. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156330. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156331. (long) bptr->rows_in_array *
  156332. (long) bptr->blocksperrow *
  156333. (long) SIZEOF(JBLOCK));
  156334. bptr->b_s_open = TRUE;
  156335. }
  156336. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156337. bptr->blocksperrow, bptr->rows_in_mem);
  156338. bptr->rowsperchunk = mem->last_rowsperchunk;
  156339. bptr->cur_start_row = 0;
  156340. bptr->first_undef_row = 0;
  156341. bptr->dirty = FALSE;
  156342. }
  156343. }
  156344. }
  156345. LOCAL(void)
  156346. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156347. {
  156348. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156349. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156350. file_offset = ptr->cur_start_row * bytesperrow;
  156351. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156352. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156353. thisrow = (long) ptr->cur_start_row + i;
  156354. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156355. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156356. if (rows <= 0) /* this chunk might be past end of file! */
  156357. break;
  156358. byte_count = rows * bytesperrow;
  156359. if (writing)
  156360. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156361. (void FAR *) ptr->mem_buffer[i],
  156362. file_offset, byte_count);
  156363. else
  156364. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156365. (void FAR *) ptr->mem_buffer[i],
  156366. file_offset, byte_count);
  156367. file_offset += byte_count;
  156368. }
  156369. }
  156370. LOCAL(void)
  156371. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156372. {
  156373. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156374. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156375. file_offset = ptr->cur_start_row * bytesperrow;
  156376. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156377. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156378. thisrow = (long) ptr->cur_start_row + i;
  156379. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156380. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156381. if (rows <= 0) /* this chunk might be past end of file! */
  156382. break;
  156383. byte_count = rows * bytesperrow;
  156384. if (writing)
  156385. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156386. (void FAR *) ptr->mem_buffer[i],
  156387. file_offset, byte_count);
  156388. else
  156389. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156390. (void FAR *) ptr->mem_buffer[i],
  156391. file_offset, byte_count);
  156392. file_offset += byte_count;
  156393. }
  156394. }
  156395. METHODDEF(JSAMPARRAY)
  156396. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156397. JDIMENSION start_row, JDIMENSION num_rows,
  156398. boolean writable)
  156399. {
  156400. JDIMENSION end_row = start_row + num_rows;
  156401. JDIMENSION undef_row;
  156402. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156403. ptr->mem_buffer == NULL)
  156404. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156405. if (start_row < ptr->cur_start_row ||
  156406. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156407. if (! ptr->b_s_open)
  156408. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156409. if (ptr->dirty) {
  156410. do_sarray_io(cinfo, ptr, TRUE);
  156411. ptr->dirty = FALSE;
  156412. }
  156413. if (start_row > ptr->cur_start_row) {
  156414. ptr->cur_start_row = start_row;
  156415. } else {
  156416. long ltemp;
  156417. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156418. if (ltemp < 0)
  156419. ltemp = 0; /* don't fall off front end of file */
  156420. ptr->cur_start_row = (JDIMENSION) ltemp;
  156421. }
  156422. do_sarray_io(cinfo, ptr, FALSE);
  156423. }
  156424. if (ptr->first_undef_row < end_row) {
  156425. if (ptr->first_undef_row < start_row) {
  156426. if (writable) /* writer skipped over a section of array */
  156427. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156428. undef_row = start_row; /* but reader is allowed to read ahead */
  156429. } else {
  156430. undef_row = ptr->first_undef_row;
  156431. }
  156432. if (writable)
  156433. ptr->first_undef_row = end_row;
  156434. if (ptr->pre_zero) {
  156435. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156436. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156437. end_row -= ptr->cur_start_row;
  156438. while (undef_row < end_row) {
  156439. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156440. undef_row++;
  156441. }
  156442. } else {
  156443. if (! writable) /* reader looking at undefined data */
  156444. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156445. }
  156446. }
  156447. if (writable)
  156448. ptr->dirty = TRUE;
  156449. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156450. }
  156451. METHODDEF(JBLOCKARRAY)
  156452. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156453. JDIMENSION start_row, JDIMENSION num_rows,
  156454. boolean writable)
  156455. {
  156456. JDIMENSION end_row = start_row + num_rows;
  156457. JDIMENSION undef_row;
  156458. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156459. ptr->mem_buffer == NULL)
  156460. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156461. if (start_row < ptr->cur_start_row ||
  156462. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156463. if (! ptr->b_s_open)
  156464. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156465. if (ptr->dirty) {
  156466. do_barray_io(cinfo, ptr, TRUE);
  156467. ptr->dirty = FALSE;
  156468. }
  156469. if (start_row > ptr->cur_start_row) {
  156470. ptr->cur_start_row = start_row;
  156471. } else {
  156472. long ltemp;
  156473. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156474. if (ltemp < 0)
  156475. ltemp = 0; /* don't fall off front end of file */
  156476. ptr->cur_start_row = (JDIMENSION) ltemp;
  156477. }
  156478. do_barray_io(cinfo, ptr, FALSE);
  156479. }
  156480. if (ptr->first_undef_row < end_row) {
  156481. if (ptr->first_undef_row < start_row) {
  156482. if (writable) /* writer skipped over a section of array */
  156483. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156484. undef_row = start_row; /* but reader is allowed to read ahead */
  156485. } else {
  156486. undef_row = ptr->first_undef_row;
  156487. }
  156488. if (writable)
  156489. ptr->first_undef_row = end_row;
  156490. if (ptr->pre_zero) {
  156491. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156492. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156493. end_row -= ptr->cur_start_row;
  156494. while (undef_row < end_row) {
  156495. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156496. undef_row++;
  156497. }
  156498. } else {
  156499. if (! writable) /* reader looking at undefined data */
  156500. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156501. }
  156502. }
  156503. if (writable)
  156504. ptr->dirty = TRUE;
  156505. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156506. }
  156507. METHODDEF(void)
  156508. free_pool (j_common_ptr cinfo, int pool_id)
  156509. {
  156510. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156511. small_pool_ptr shdr_ptr;
  156512. large_pool_ptr lhdr_ptr;
  156513. size_t space_freed;
  156514. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156515. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156516. #ifdef MEM_STATS
  156517. if (cinfo->err->trace_level > 1)
  156518. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  156519. #endif
  156520. if (pool_id == JPOOL_IMAGE) {
  156521. jvirt_sarray_ptr sptr;
  156522. jvirt_barray_ptr bptr;
  156523. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156524. if (sptr->b_s_open) { /* there may be no backing store */
  156525. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  156526. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  156527. }
  156528. }
  156529. mem->virt_sarray_list = NULL;
  156530. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156531. if (bptr->b_s_open) { /* there may be no backing store */
  156532. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  156533. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  156534. }
  156535. }
  156536. mem->virt_barray_list = NULL;
  156537. }
  156538. lhdr_ptr = mem->large_list[pool_id];
  156539. mem->large_list[pool_id] = NULL;
  156540. while (lhdr_ptr != NULL) {
  156541. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  156542. space_freed = lhdr_ptr->hdr.bytes_used +
  156543. lhdr_ptr->hdr.bytes_left +
  156544. SIZEOF(large_pool_hdr);
  156545. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  156546. mem->total_space_allocated -= space_freed;
  156547. lhdr_ptr = next_lhdr_ptr;
  156548. }
  156549. shdr_ptr = mem->small_list[pool_id];
  156550. mem->small_list[pool_id] = NULL;
  156551. while (shdr_ptr != NULL) {
  156552. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  156553. space_freed = shdr_ptr->hdr.bytes_used +
  156554. shdr_ptr->hdr.bytes_left +
  156555. SIZEOF(small_pool_hdr);
  156556. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  156557. mem->total_space_allocated -= space_freed;
  156558. shdr_ptr = next_shdr_ptr;
  156559. }
  156560. }
  156561. METHODDEF(void)
  156562. self_destruct (j_common_ptr cinfo)
  156563. {
  156564. int pool;
  156565. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156566. free_pool(cinfo, pool);
  156567. }
  156568. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  156569. cinfo->mem = NULL; /* ensures I will be called only once */
  156570. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156571. }
  156572. GLOBAL(void)
  156573. jinit_memory_mgr (j_common_ptr cinfo)
  156574. {
  156575. my_mem_ptr mem;
  156576. long max_to_use;
  156577. int pool;
  156578. size_t test_mac;
  156579. cinfo->mem = NULL; /* for safety if init fails */
  156580. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  156581. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  156582. test_mac = (size_t) MAX_ALLOC_CHUNK;
  156583. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  156584. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  156585. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  156586. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  156587. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  156588. if (mem == NULL) {
  156589. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  156590. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  156591. }
  156592. mem->pub.alloc_small = alloc_small;
  156593. mem->pub.alloc_large = alloc_large;
  156594. mem->pub.alloc_sarray = alloc_sarray;
  156595. mem->pub.alloc_barray = alloc_barray;
  156596. mem->pub.request_virt_sarray = request_virt_sarray;
  156597. mem->pub.request_virt_barray = request_virt_barray;
  156598. mem->pub.realize_virt_arrays = realize_virt_arrays;
  156599. mem->pub.access_virt_sarray = access_virt_sarray;
  156600. mem->pub.access_virt_barray = access_virt_barray;
  156601. mem->pub.free_pool = free_pool;
  156602. mem->pub.self_destruct = self_destruct;
  156603. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  156604. mem->pub.max_memory_to_use = max_to_use;
  156605. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  156606. mem->small_list[pool] = NULL;
  156607. mem->large_list[pool] = NULL;
  156608. }
  156609. mem->virt_sarray_list = NULL;
  156610. mem->virt_barray_list = NULL;
  156611. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  156612. cinfo->mem = & mem->pub;
  156613. #ifndef NO_GETENV
  156614. { char * memenv;
  156615. if ((memenv = getenv("JPEGMEM")) != NULL) {
  156616. char ch = 'x';
  156617. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  156618. if (ch == 'm' || ch == 'M')
  156619. max_to_use *= 1000L;
  156620. mem->pub.max_memory_to_use = max_to_use * 1000L;
  156621. }
  156622. }
  156623. }
  156624. #endif
  156625. }
  156626. /*** End of inlined file: jmemmgr.c ***/
  156627. /*** Start of inlined file: jmemnobs.c ***/
  156628. #define JPEG_INTERNALS
  156629. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  156630. extern void * malloc JPP((size_t size));
  156631. extern void free JPP((void *ptr));
  156632. #endif
  156633. GLOBAL(void *)
  156634. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  156635. {
  156636. return (void *) malloc(sizeofobject);
  156637. }
  156638. GLOBAL(void)
  156639. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  156640. {
  156641. free(object);
  156642. }
  156643. GLOBAL(void FAR *)
  156644. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  156645. {
  156646. return (void FAR *) malloc(sizeofobject);
  156647. }
  156648. GLOBAL(void)
  156649. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  156650. {
  156651. free(object);
  156652. }
  156653. GLOBAL(long)
  156654. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  156655. long max_bytes_needed, long already_allocated)
  156656. {
  156657. return max_bytes_needed;
  156658. }
  156659. GLOBAL(void)
  156660. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  156661. long total_bytes_needed)
  156662. {
  156663. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  156664. }
  156665. GLOBAL(long)
  156666. jpeg_mem_init (j_common_ptr cinfo)
  156667. {
  156668. return 0; /* just set max_memory_to_use to 0 */
  156669. }
  156670. GLOBAL(void)
  156671. jpeg_mem_term (j_common_ptr cinfo)
  156672. {
  156673. }
  156674. /*** End of inlined file: jmemnobs.c ***/
  156675. /*** Start of inlined file: jquant1.c ***/
  156676. #define JPEG_INTERNALS
  156677. #ifdef QUANT_1PASS_SUPPORTED
  156678. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  156679. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  156680. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  156681. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  156682. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  156683. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  156684. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  156685. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  156686. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  156687. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  156688. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  156689. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  156690. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  156691. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  156692. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  156693. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  156694. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  156695. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  156696. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  156697. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  156698. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  156699. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  156700. };
  156701. #if BITS_IN_JSAMPLE == 8
  156702. typedef INT16 FSERROR; /* 16 bits should be enough */
  156703. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  156704. #else
  156705. typedef INT32 FSERROR; /* may need more than 16 bits */
  156706. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  156707. #endif
  156708. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  156709. #define MAX_Q_COMPS 4 /* max components I can handle */
  156710. typedef struct {
  156711. struct jpeg_color_quantizer pub; /* public fields */
  156712. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  156713. int sv_actual; /* number of entries in use */
  156714. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  156715. boolean is_padded; /* is the colorindex padded for odither? */
  156716. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  156717. int row_index; /* cur row's vertical index in dither matrix */
  156718. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  156719. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  156720. boolean on_odd_row; /* flag to remember which row we are on */
  156721. } my_cquantizer;
  156722. typedef my_cquantizer * my_cquantize_ptr;
  156723. LOCAL(int)
  156724. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  156725. {
  156726. int nc = cinfo->out_color_components; /* number of color components */
  156727. int max_colors = cinfo->desired_number_of_colors;
  156728. int total_colors, iroot, i, j;
  156729. boolean changed;
  156730. long temp;
  156731. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  156732. iroot = 1;
  156733. do {
  156734. iroot++;
  156735. temp = iroot; /* set temp = iroot ** nc */
  156736. for (i = 1; i < nc; i++)
  156737. temp *= iroot;
  156738. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  156739. iroot--; /* now iroot = floor(root) */
  156740. if (iroot < 2)
  156741. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  156742. total_colors = 1;
  156743. for (i = 0; i < nc; i++) {
  156744. Ncolors[i] = iroot;
  156745. total_colors *= iroot;
  156746. }
  156747. do {
  156748. changed = FALSE;
  156749. for (i = 0; i < nc; i++) {
  156750. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  156751. temp = total_colors / Ncolors[j];
  156752. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  156753. if (temp > (long) max_colors)
  156754. break; /* won't fit, done with this pass */
  156755. Ncolors[j]++; /* OK, apply the increment */
  156756. total_colors = (int) temp;
  156757. changed = TRUE;
  156758. }
  156759. } while (changed);
  156760. return total_colors;
  156761. }
  156762. LOCAL(int)
  156763. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156764. {
  156765. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  156766. }
  156767. LOCAL(int)
  156768. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  156769. {
  156770. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  156771. }
  156772. LOCAL(void)
  156773. create_colormap (j_decompress_ptr cinfo)
  156774. {
  156775. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156776. JSAMPARRAY colormap; /* Created colormap */
  156777. int total_colors; /* Number of distinct output colors */
  156778. int i,j,k, nci, blksize, blkdist, ptr, val;
  156779. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  156780. if (cinfo->out_color_components == 3)
  156781. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  156782. total_colors, cquantize->Ncolors[0],
  156783. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  156784. else
  156785. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  156786. colormap = (*cinfo->mem->alloc_sarray)
  156787. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156788. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  156789. blkdist = total_colors;
  156790. for (i = 0; i < cinfo->out_color_components; i++) {
  156791. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156792. blksize = blkdist / nci;
  156793. for (j = 0; j < nci; j++) {
  156794. val = output_value(cinfo, i, j, nci-1);
  156795. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  156796. for (k = 0; k < blksize; k++)
  156797. colormap[i][ptr+k] = (JSAMPLE) val;
  156798. }
  156799. }
  156800. blkdist = blksize; /* blksize of this color is blkdist of next */
  156801. }
  156802. cquantize->sv_colormap = colormap;
  156803. cquantize->sv_actual = total_colors;
  156804. }
  156805. LOCAL(void)
  156806. create_colorindex (j_decompress_ptr cinfo)
  156807. {
  156808. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156809. JSAMPROW indexptr;
  156810. int i,j,k, nci, blksize, val, pad;
  156811. if (cinfo->dither_mode == JDITHER_ORDERED) {
  156812. pad = MAXJSAMPLE*2;
  156813. cquantize->is_padded = TRUE;
  156814. } else {
  156815. pad = 0;
  156816. cquantize->is_padded = FALSE;
  156817. }
  156818. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  156819. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156820. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  156821. (JDIMENSION) cinfo->out_color_components);
  156822. blksize = cquantize->sv_actual;
  156823. for (i = 0; i < cinfo->out_color_components; i++) {
  156824. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156825. blksize = blksize / nci;
  156826. if (pad)
  156827. cquantize->colorindex[i] += MAXJSAMPLE;
  156828. indexptr = cquantize->colorindex[i];
  156829. val = 0;
  156830. k = largest_input_value(cinfo, i, 0, nci-1);
  156831. for (j = 0; j <= MAXJSAMPLE; j++) {
  156832. while (j > k) /* advance val if past boundary */
  156833. k = largest_input_value(cinfo, i, ++val, nci-1);
  156834. indexptr[j] = (JSAMPLE) (val * blksize);
  156835. }
  156836. if (pad)
  156837. for (j = 1; j <= MAXJSAMPLE; j++) {
  156838. indexptr[-j] = indexptr[0];
  156839. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  156840. }
  156841. }
  156842. }
  156843. LOCAL(ODITHER_MATRIX_PTR)
  156844. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  156845. {
  156846. ODITHER_MATRIX_PTR odither;
  156847. int j,k;
  156848. INT32 num,den;
  156849. odither = (ODITHER_MATRIX_PTR)
  156850. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  156851. SIZEOF(ODITHER_MATRIX));
  156852. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  156853. for (j = 0; j < ODITHER_SIZE; j++) {
  156854. for (k = 0; k < ODITHER_SIZE; k++) {
  156855. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  156856. * MAXJSAMPLE;
  156857. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  156858. }
  156859. }
  156860. return odither;
  156861. }
  156862. LOCAL(void)
  156863. create_odither_tables (j_decompress_ptr cinfo)
  156864. {
  156865. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156866. ODITHER_MATRIX_PTR odither;
  156867. int i, j, nci;
  156868. for (i = 0; i < cinfo->out_color_components; i++) {
  156869. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  156870. odither = NULL; /* search for matching prior component */
  156871. for (j = 0; j < i; j++) {
  156872. if (nci == cquantize->Ncolors[j]) {
  156873. odither = cquantize->odither[j];
  156874. break;
  156875. }
  156876. }
  156877. if (odither == NULL) /* need a new table? */
  156878. odither = make_odither_array(cinfo, nci);
  156879. cquantize->odither[i] = odither;
  156880. }
  156881. }
  156882. METHODDEF(void)
  156883. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156884. JSAMPARRAY output_buf, int num_rows)
  156885. {
  156886. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156887. JSAMPARRAY colorindex = cquantize->colorindex;
  156888. register int pixcode, ci;
  156889. register JSAMPROW ptrin, ptrout;
  156890. int row;
  156891. JDIMENSION col;
  156892. JDIMENSION width = cinfo->output_width;
  156893. register int nc = cinfo->out_color_components;
  156894. for (row = 0; row < num_rows; row++) {
  156895. ptrin = input_buf[row];
  156896. ptrout = output_buf[row];
  156897. for (col = width; col > 0; col--) {
  156898. pixcode = 0;
  156899. for (ci = 0; ci < nc; ci++) {
  156900. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  156901. }
  156902. *ptrout++ = (JSAMPLE) pixcode;
  156903. }
  156904. }
  156905. }
  156906. METHODDEF(void)
  156907. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156908. JSAMPARRAY output_buf, int num_rows)
  156909. {
  156910. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156911. register int pixcode;
  156912. register JSAMPROW ptrin, ptrout;
  156913. JSAMPROW colorindex0 = cquantize->colorindex[0];
  156914. JSAMPROW colorindex1 = cquantize->colorindex[1];
  156915. JSAMPROW colorindex2 = cquantize->colorindex[2];
  156916. int row;
  156917. JDIMENSION col;
  156918. JDIMENSION width = cinfo->output_width;
  156919. for (row = 0; row < num_rows; row++) {
  156920. ptrin = input_buf[row];
  156921. ptrout = output_buf[row];
  156922. for (col = width; col > 0; col--) {
  156923. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  156924. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  156925. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  156926. *ptrout++ = (JSAMPLE) pixcode;
  156927. }
  156928. }
  156929. }
  156930. METHODDEF(void)
  156931. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156932. JSAMPARRAY output_buf, int num_rows)
  156933. {
  156934. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156935. register JSAMPROW input_ptr;
  156936. register JSAMPROW output_ptr;
  156937. JSAMPROW colorindex_ci;
  156938. int * dither; /* points to active row of dither matrix */
  156939. int row_index, col_index; /* current indexes into dither matrix */
  156940. int nc = cinfo->out_color_components;
  156941. int ci;
  156942. int row;
  156943. JDIMENSION col;
  156944. JDIMENSION width = cinfo->output_width;
  156945. for (row = 0; row < num_rows; row++) {
  156946. jzero_far((void FAR *) output_buf[row],
  156947. (size_t) (width * SIZEOF(JSAMPLE)));
  156948. row_index = cquantize->row_index;
  156949. for (ci = 0; ci < nc; ci++) {
  156950. input_ptr = input_buf[row] + ci;
  156951. output_ptr = output_buf[row];
  156952. colorindex_ci = cquantize->colorindex[ci];
  156953. dither = cquantize->odither[ci][row_index];
  156954. col_index = 0;
  156955. for (col = width; col > 0; col--) {
  156956. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  156957. input_ptr += nc;
  156958. output_ptr++;
  156959. col_index = (col_index + 1) & ODITHER_MASK;
  156960. }
  156961. }
  156962. row_index = (row_index + 1) & ODITHER_MASK;
  156963. cquantize->row_index = row_index;
  156964. }
  156965. }
  156966. METHODDEF(void)
  156967. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  156968. JSAMPARRAY output_buf, int num_rows)
  156969. {
  156970. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  156971. register int pixcode;
  156972. register JSAMPROW input_ptr;
  156973. register JSAMPROW output_ptr;
  156974. JSAMPROW colorindex0 = cquantize->colorindex[0];
  156975. JSAMPROW colorindex1 = cquantize->colorindex[1];
  156976. JSAMPROW colorindex2 = cquantize->colorindex[2];
  156977. int * dither0; /* points to active row of dither matrix */
  156978. int * dither1;
  156979. int * dither2;
  156980. int row_index, col_index; /* current indexes into dither matrix */
  156981. int row;
  156982. JDIMENSION col;
  156983. JDIMENSION width = cinfo->output_width;
  156984. for (row = 0; row < num_rows; row++) {
  156985. row_index = cquantize->row_index;
  156986. input_ptr = input_buf[row];
  156987. output_ptr = output_buf[row];
  156988. dither0 = cquantize->odither[0][row_index];
  156989. dither1 = cquantize->odither[1][row_index];
  156990. dither2 = cquantize->odither[2][row_index];
  156991. col_index = 0;
  156992. for (col = width; col > 0; col--) {
  156993. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  156994. dither0[col_index]]);
  156995. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  156996. dither1[col_index]]);
  156997. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  156998. dither2[col_index]]);
  156999. *output_ptr++ = (JSAMPLE) pixcode;
  157000. col_index = (col_index + 1) & ODITHER_MASK;
  157001. }
  157002. row_index = (row_index + 1) & ODITHER_MASK;
  157003. cquantize->row_index = row_index;
  157004. }
  157005. }
  157006. METHODDEF(void)
  157007. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157008. JSAMPARRAY output_buf, int num_rows)
  157009. {
  157010. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157011. register LOCFSERROR cur; /* current error or pixel value */
  157012. LOCFSERROR belowerr; /* error for pixel below cur */
  157013. LOCFSERROR bpreverr; /* error for below/prev col */
  157014. LOCFSERROR bnexterr; /* error for below/next col */
  157015. LOCFSERROR delta;
  157016. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157017. register JSAMPROW input_ptr;
  157018. register JSAMPROW output_ptr;
  157019. JSAMPROW colorindex_ci;
  157020. JSAMPROW colormap_ci;
  157021. int pixcode;
  157022. int nc = cinfo->out_color_components;
  157023. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157024. int dirnc; /* dir * nc */
  157025. int ci;
  157026. int row;
  157027. JDIMENSION col;
  157028. JDIMENSION width = cinfo->output_width;
  157029. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157030. SHIFT_TEMPS
  157031. for (row = 0; row < num_rows; row++) {
  157032. jzero_far((void FAR *) output_buf[row],
  157033. (size_t) (width * SIZEOF(JSAMPLE)));
  157034. for (ci = 0; ci < nc; ci++) {
  157035. input_ptr = input_buf[row] + ci;
  157036. output_ptr = output_buf[row];
  157037. if (cquantize->on_odd_row) {
  157038. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157039. output_ptr += width-1;
  157040. dir = -1;
  157041. dirnc = -nc;
  157042. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157043. } else {
  157044. dir = 1;
  157045. dirnc = nc;
  157046. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157047. }
  157048. colorindex_ci = cquantize->colorindex[ci];
  157049. colormap_ci = cquantize->sv_colormap[ci];
  157050. cur = 0;
  157051. belowerr = bpreverr = 0;
  157052. for (col = width; col > 0; col--) {
  157053. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157054. cur += GETJSAMPLE(*input_ptr);
  157055. cur = GETJSAMPLE(range_limit[cur]);
  157056. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157057. *output_ptr += (JSAMPLE) pixcode;
  157058. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157059. bnexterr = cur;
  157060. delta = cur * 2;
  157061. cur += delta; /* form error * 3 */
  157062. errorptr[0] = (FSERROR) (bpreverr + cur);
  157063. cur += delta; /* form error * 5 */
  157064. bpreverr = belowerr + cur;
  157065. belowerr = bnexterr;
  157066. cur += delta; /* form error * 7 */
  157067. input_ptr += dirnc; /* advance input ptr to next column */
  157068. output_ptr += dir; /* advance output ptr to next column */
  157069. errorptr += dir; /* advance errorptr to current column */
  157070. }
  157071. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157072. }
  157073. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157074. }
  157075. }
  157076. LOCAL(void)
  157077. alloc_fs_workspace (j_decompress_ptr cinfo)
  157078. {
  157079. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157080. size_t arraysize;
  157081. int i;
  157082. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157083. for (i = 0; i < cinfo->out_color_components; i++) {
  157084. cquantize->fserrors[i] = (FSERRPTR)
  157085. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157086. }
  157087. }
  157088. METHODDEF(void)
  157089. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157090. {
  157091. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157092. size_t arraysize;
  157093. int i;
  157094. cinfo->colormap = cquantize->sv_colormap;
  157095. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157096. switch (cinfo->dither_mode) {
  157097. case JDITHER_NONE:
  157098. if (cinfo->out_color_components == 3)
  157099. cquantize->pub.color_quantize = color_quantize3;
  157100. else
  157101. cquantize->pub.color_quantize = color_quantize;
  157102. break;
  157103. case JDITHER_ORDERED:
  157104. if (cinfo->out_color_components == 3)
  157105. cquantize->pub.color_quantize = quantize3_ord_dither;
  157106. else
  157107. cquantize->pub.color_quantize = quantize_ord_dither;
  157108. cquantize->row_index = 0; /* initialize state for ordered dither */
  157109. if (! cquantize->is_padded)
  157110. create_colorindex(cinfo);
  157111. if (cquantize->odither[0] == NULL)
  157112. create_odither_tables(cinfo);
  157113. break;
  157114. case JDITHER_FS:
  157115. cquantize->pub.color_quantize = quantize_fs_dither;
  157116. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157117. if (cquantize->fserrors[0] == NULL)
  157118. alloc_fs_workspace(cinfo);
  157119. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157120. for (i = 0; i < cinfo->out_color_components; i++)
  157121. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157122. break;
  157123. default:
  157124. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157125. break;
  157126. }
  157127. }
  157128. METHODDEF(void)
  157129. finish_pass_1_quant (j_decompress_ptr cinfo)
  157130. {
  157131. }
  157132. METHODDEF(void)
  157133. new_color_map_1_quant (j_decompress_ptr cinfo)
  157134. {
  157135. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157136. }
  157137. GLOBAL(void)
  157138. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157139. {
  157140. my_cquantize_ptr cquantize;
  157141. cquantize = (my_cquantize_ptr)
  157142. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157143. SIZEOF(my_cquantizer));
  157144. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157145. cquantize->pub.start_pass = start_pass_1_quant;
  157146. cquantize->pub.finish_pass = finish_pass_1_quant;
  157147. cquantize->pub.new_color_map = new_color_map_1_quant;
  157148. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157149. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157150. if (cinfo->out_color_components > MAX_Q_COMPS)
  157151. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157152. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157153. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157154. create_colormap(cinfo);
  157155. create_colorindex(cinfo);
  157156. if (cinfo->dither_mode == JDITHER_FS)
  157157. alloc_fs_workspace(cinfo);
  157158. }
  157159. #endif /* QUANT_1PASS_SUPPORTED */
  157160. /*** End of inlined file: jquant1.c ***/
  157161. /*** Start of inlined file: jquant2.c ***/
  157162. #define JPEG_INTERNALS
  157163. #ifdef QUANT_2PASS_SUPPORTED
  157164. #define R_SCALE 2 /* scale R distances by this much */
  157165. #define G_SCALE 3 /* scale G distances by this much */
  157166. #define B_SCALE 1 /* and B by this much */
  157167. #if RGB_RED == 0
  157168. #define C0_SCALE R_SCALE
  157169. #endif
  157170. #if RGB_BLUE == 0
  157171. #define C0_SCALE B_SCALE
  157172. #endif
  157173. #if RGB_GREEN == 1
  157174. #define C1_SCALE G_SCALE
  157175. #endif
  157176. #if RGB_RED == 2
  157177. #define C2_SCALE R_SCALE
  157178. #endif
  157179. #if RGB_BLUE == 2
  157180. #define C2_SCALE B_SCALE
  157181. #endif
  157182. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157183. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157184. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157185. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157186. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157187. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157188. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157189. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157190. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157191. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157192. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157193. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157194. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157195. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157196. typedef hist2d * hist3d; /* type for top-level pointer */
  157197. #if BITS_IN_JSAMPLE == 8
  157198. typedef INT16 FSERROR; /* 16 bits should be enough */
  157199. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157200. #else
  157201. typedef INT32 FSERROR; /* may need more than 16 bits */
  157202. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157203. #endif
  157204. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157205. typedef struct {
  157206. struct jpeg_color_quantizer pub; /* public fields */
  157207. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157208. int desired; /* desired # of colors = size of colormap */
  157209. hist3d histogram; /* pointer to the histogram */
  157210. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157211. FSERRPTR fserrors; /* accumulated errors */
  157212. boolean on_odd_row; /* flag to remember which row we are on */
  157213. int * error_limiter; /* table for clamping the applied error */
  157214. } my_cquantizer2;
  157215. typedef my_cquantizer2 * my_cquantize_ptr2;
  157216. METHODDEF(void)
  157217. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157218. JSAMPARRAY output_buf, int num_rows)
  157219. {
  157220. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157221. register JSAMPROW ptr;
  157222. register histptr histp;
  157223. register hist3d histogram = cquantize->histogram;
  157224. int row;
  157225. JDIMENSION col;
  157226. JDIMENSION width = cinfo->output_width;
  157227. for (row = 0; row < num_rows; row++) {
  157228. ptr = input_buf[row];
  157229. for (col = width; col > 0; col--) {
  157230. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157231. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157232. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157233. if (++(*histp) <= 0)
  157234. (*histp)--;
  157235. ptr += 3;
  157236. }
  157237. }
  157238. }
  157239. typedef struct {
  157240. int c0min, c0max;
  157241. int c1min, c1max;
  157242. int c2min, c2max;
  157243. INT32 volume;
  157244. long colorcount;
  157245. } box;
  157246. typedef box * boxptr;
  157247. LOCAL(boxptr)
  157248. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157249. {
  157250. register boxptr boxp;
  157251. register int i;
  157252. register long maxc = 0;
  157253. boxptr which = NULL;
  157254. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157255. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157256. which = boxp;
  157257. maxc = boxp->colorcount;
  157258. }
  157259. }
  157260. return which;
  157261. }
  157262. LOCAL(boxptr)
  157263. find_biggest_volume (boxptr boxlist, int numboxes)
  157264. {
  157265. register boxptr boxp;
  157266. register int i;
  157267. register INT32 maxv = 0;
  157268. boxptr which = NULL;
  157269. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157270. if (boxp->volume > maxv) {
  157271. which = boxp;
  157272. maxv = boxp->volume;
  157273. }
  157274. }
  157275. return which;
  157276. }
  157277. LOCAL(void)
  157278. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157279. {
  157280. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157281. hist3d histogram = cquantize->histogram;
  157282. histptr histp;
  157283. int c0,c1,c2;
  157284. int c0min,c0max,c1min,c1max,c2min,c2max;
  157285. INT32 dist0,dist1,dist2;
  157286. long ccount;
  157287. c0min = boxp->c0min; c0max = boxp->c0max;
  157288. c1min = boxp->c1min; c1max = boxp->c1max;
  157289. c2min = boxp->c2min; c2max = boxp->c2max;
  157290. if (c0max > c0min)
  157291. for (c0 = c0min; c0 <= c0max; c0++)
  157292. for (c1 = c1min; c1 <= c1max; c1++) {
  157293. histp = & histogram[c0][c1][c2min];
  157294. for (c2 = c2min; c2 <= c2max; c2++)
  157295. if (*histp++ != 0) {
  157296. boxp->c0min = c0min = c0;
  157297. goto have_c0min;
  157298. }
  157299. }
  157300. have_c0min:
  157301. if (c0max > c0min)
  157302. for (c0 = c0max; c0 >= c0min; c0--)
  157303. for (c1 = c1min; c1 <= c1max; c1++) {
  157304. histp = & histogram[c0][c1][c2min];
  157305. for (c2 = c2min; c2 <= c2max; c2++)
  157306. if (*histp++ != 0) {
  157307. boxp->c0max = c0max = c0;
  157308. goto have_c0max;
  157309. }
  157310. }
  157311. have_c0max:
  157312. if (c1max > c1min)
  157313. for (c1 = c1min; c1 <= c1max; c1++)
  157314. for (c0 = c0min; c0 <= c0max; c0++) {
  157315. histp = & histogram[c0][c1][c2min];
  157316. for (c2 = c2min; c2 <= c2max; c2++)
  157317. if (*histp++ != 0) {
  157318. boxp->c1min = c1min = c1;
  157319. goto have_c1min;
  157320. }
  157321. }
  157322. have_c1min:
  157323. if (c1max > c1min)
  157324. for (c1 = c1max; c1 >= c1min; c1--)
  157325. for (c0 = c0min; c0 <= c0max; c0++) {
  157326. histp = & histogram[c0][c1][c2min];
  157327. for (c2 = c2min; c2 <= c2max; c2++)
  157328. if (*histp++ != 0) {
  157329. boxp->c1max = c1max = c1;
  157330. goto have_c1max;
  157331. }
  157332. }
  157333. have_c1max:
  157334. if (c2max > c2min)
  157335. for (c2 = c2min; c2 <= c2max; c2++)
  157336. for (c0 = c0min; c0 <= c0max; c0++) {
  157337. histp = & histogram[c0][c1min][c2];
  157338. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157339. if (*histp != 0) {
  157340. boxp->c2min = c2min = c2;
  157341. goto have_c2min;
  157342. }
  157343. }
  157344. have_c2min:
  157345. if (c2max > c2min)
  157346. for (c2 = c2max; c2 >= c2min; c2--)
  157347. for (c0 = c0min; c0 <= c0max; c0++) {
  157348. histp = & histogram[c0][c1min][c2];
  157349. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157350. if (*histp != 0) {
  157351. boxp->c2max = c2max = c2;
  157352. goto have_c2max;
  157353. }
  157354. }
  157355. have_c2max:
  157356. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157357. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157358. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157359. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157360. ccount = 0;
  157361. for (c0 = c0min; c0 <= c0max; c0++)
  157362. for (c1 = c1min; c1 <= c1max; c1++) {
  157363. histp = & histogram[c0][c1][c2min];
  157364. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157365. if (*histp != 0) {
  157366. ccount++;
  157367. }
  157368. }
  157369. boxp->colorcount = ccount;
  157370. }
  157371. LOCAL(int)
  157372. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157373. int desired_colors)
  157374. {
  157375. int n,lb;
  157376. int c0,c1,c2,cmax;
  157377. register boxptr b1,b2;
  157378. while (numboxes < desired_colors) {
  157379. if (numboxes*2 <= desired_colors) {
  157380. b1 = find_biggest_color_pop(boxlist, numboxes);
  157381. } else {
  157382. b1 = find_biggest_volume(boxlist, numboxes);
  157383. }
  157384. if (b1 == NULL) /* no splittable boxes left! */
  157385. break;
  157386. b2 = &boxlist[numboxes]; /* where new box will go */
  157387. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157388. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157389. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157390. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157391. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157392. #if RGB_RED == 0
  157393. cmax = c1; n = 1;
  157394. if (c0 > cmax) { cmax = c0; n = 0; }
  157395. if (c2 > cmax) { n = 2; }
  157396. #else
  157397. cmax = c1; n = 1;
  157398. if (c2 > cmax) { cmax = c2; n = 2; }
  157399. if (c0 > cmax) { n = 0; }
  157400. #endif
  157401. switch (n) {
  157402. case 0:
  157403. lb = (b1->c0max + b1->c0min) / 2;
  157404. b1->c0max = lb;
  157405. b2->c0min = lb+1;
  157406. break;
  157407. case 1:
  157408. lb = (b1->c1max + b1->c1min) / 2;
  157409. b1->c1max = lb;
  157410. b2->c1min = lb+1;
  157411. break;
  157412. case 2:
  157413. lb = (b1->c2max + b1->c2min) / 2;
  157414. b1->c2max = lb;
  157415. b2->c2min = lb+1;
  157416. break;
  157417. }
  157418. update_box(cinfo, b1);
  157419. update_box(cinfo, b2);
  157420. numboxes++;
  157421. }
  157422. return numboxes;
  157423. }
  157424. LOCAL(void)
  157425. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157426. {
  157427. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157428. hist3d histogram = cquantize->histogram;
  157429. histptr histp;
  157430. int c0,c1,c2;
  157431. int c0min,c0max,c1min,c1max,c2min,c2max;
  157432. long count;
  157433. long total = 0;
  157434. long c0total = 0;
  157435. long c1total = 0;
  157436. long c2total = 0;
  157437. c0min = boxp->c0min; c0max = boxp->c0max;
  157438. c1min = boxp->c1min; c1max = boxp->c1max;
  157439. c2min = boxp->c2min; c2max = boxp->c2max;
  157440. for (c0 = c0min; c0 <= c0max; c0++)
  157441. for (c1 = c1min; c1 <= c1max; c1++) {
  157442. histp = & histogram[c0][c1][c2min];
  157443. for (c2 = c2min; c2 <= c2max; c2++) {
  157444. if ((count = *histp++) != 0) {
  157445. total += count;
  157446. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157447. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157448. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157449. }
  157450. }
  157451. }
  157452. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157453. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157454. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157455. }
  157456. LOCAL(void)
  157457. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157458. {
  157459. boxptr boxlist;
  157460. int numboxes;
  157461. int i;
  157462. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157463. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157464. numboxes = 1;
  157465. boxlist[0].c0min = 0;
  157466. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157467. boxlist[0].c1min = 0;
  157468. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157469. boxlist[0].c2min = 0;
  157470. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157471. update_box(cinfo, & boxlist[0]);
  157472. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157473. for (i = 0; i < numboxes; i++)
  157474. compute_color(cinfo, & boxlist[i], i);
  157475. cinfo->actual_number_of_colors = numboxes;
  157476. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157477. }
  157478. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157479. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157480. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157481. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157482. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157483. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157484. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157485. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157486. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157487. LOCAL(int)
  157488. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157489. JSAMPLE colorlist[])
  157490. {
  157491. int numcolors = cinfo->actual_number_of_colors;
  157492. int maxc0, maxc1, maxc2;
  157493. int centerc0, centerc1, centerc2;
  157494. int i, x, ncolors;
  157495. INT32 minmaxdist, min_dist, max_dist, tdist;
  157496. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157497. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157498. centerc0 = (minc0 + maxc0) >> 1;
  157499. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157500. centerc1 = (minc1 + maxc1) >> 1;
  157501. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157502. centerc2 = (minc2 + maxc2) >> 1;
  157503. minmaxdist = 0x7FFFFFFFL;
  157504. for (i = 0; i < numcolors; i++) {
  157505. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157506. if (x < minc0) {
  157507. tdist = (x - minc0) * C0_SCALE;
  157508. min_dist = tdist*tdist;
  157509. tdist = (x - maxc0) * C0_SCALE;
  157510. max_dist = tdist*tdist;
  157511. } else if (x > maxc0) {
  157512. tdist = (x - maxc0) * C0_SCALE;
  157513. min_dist = tdist*tdist;
  157514. tdist = (x - minc0) * C0_SCALE;
  157515. max_dist = tdist*tdist;
  157516. } else {
  157517. min_dist = 0;
  157518. if (x <= centerc0) {
  157519. tdist = (x - maxc0) * C0_SCALE;
  157520. max_dist = tdist*tdist;
  157521. } else {
  157522. tdist = (x - minc0) * C0_SCALE;
  157523. max_dist = tdist*tdist;
  157524. }
  157525. }
  157526. x = GETJSAMPLE(cinfo->colormap[1][i]);
  157527. if (x < minc1) {
  157528. tdist = (x - minc1) * C1_SCALE;
  157529. min_dist += tdist*tdist;
  157530. tdist = (x - maxc1) * C1_SCALE;
  157531. max_dist += tdist*tdist;
  157532. } else if (x > maxc1) {
  157533. tdist = (x - maxc1) * C1_SCALE;
  157534. min_dist += tdist*tdist;
  157535. tdist = (x - minc1) * C1_SCALE;
  157536. max_dist += tdist*tdist;
  157537. } else {
  157538. if (x <= centerc1) {
  157539. tdist = (x - maxc1) * C1_SCALE;
  157540. max_dist += tdist*tdist;
  157541. } else {
  157542. tdist = (x - minc1) * C1_SCALE;
  157543. max_dist += tdist*tdist;
  157544. }
  157545. }
  157546. x = GETJSAMPLE(cinfo->colormap[2][i]);
  157547. if (x < minc2) {
  157548. tdist = (x - minc2) * C2_SCALE;
  157549. min_dist += tdist*tdist;
  157550. tdist = (x - maxc2) * C2_SCALE;
  157551. max_dist += tdist*tdist;
  157552. } else if (x > maxc2) {
  157553. tdist = (x - maxc2) * C2_SCALE;
  157554. min_dist += tdist*tdist;
  157555. tdist = (x - minc2) * C2_SCALE;
  157556. max_dist += tdist*tdist;
  157557. } else {
  157558. if (x <= centerc2) {
  157559. tdist = (x - maxc2) * C2_SCALE;
  157560. max_dist += tdist*tdist;
  157561. } else {
  157562. tdist = (x - minc2) * C2_SCALE;
  157563. max_dist += tdist*tdist;
  157564. }
  157565. }
  157566. mindist[i] = min_dist; /* save away the results */
  157567. if (max_dist < minmaxdist)
  157568. minmaxdist = max_dist;
  157569. }
  157570. ncolors = 0;
  157571. for (i = 0; i < numcolors; i++) {
  157572. if (mindist[i] <= minmaxdist)
  157573. colorlist[ncolors++] = (JSAMPLE) i;
  157574. }
  157575. return ncolors;
  157576. }
  157577. LOCAL(void)
  157578. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157579. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  157580. {
  157581. int ic0, ic1, ic2;
  157582. int i, icolor;
  157583. register INT32 * bptr; /* pointer into bestdist[] array */
  157584. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157585. INT32 dist0, dist1; /* initial distance values */
  157586. register INT32 dist2; /* current distance in inner loop */
  157587. INT32 xx0, xx1; /* distance increments */
  157588. register INT32 xx2;
  157589. INT32 inc0, inc1, inc2; /* initial values for increments */
  157590. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157591. bptr = bestdist;
  157592. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  157593. *bptr++ = 0x7FFFFFFFL;
  157594. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  157595. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  157596. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  157597. for (i = 0; i < numcolors; i++) {
  157598. icolor = GETJSAMPLE(colorlist[i]);
  157599. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  157600. dist0 = inc0*inc0;
  157601. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  157602. dist0 += inc1*inc1;
  157603. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  157604. dist0 += inc2*inc2;
  157605. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  157606. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  157607. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  157608. bptr = bestdist;
  157609. cptr = bestcolor;
  157610. xx0 = inc0;
  157611. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  157612. dist1 = dist0;
  157613. xx1 = inc1;
  157614. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  157615. dist2 = dist1;
  157616. xx2 = inc2;
  157617. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  157618. if (dist2 < *bptr) {
  157619. *bptr = dist2;
  157620. *cptr = (JSAMPLE) icolor;
  157621. }
  157622. dist2 += xx2;
  157623. xx2 += 2 * STEP_C2 * STEP_C2;
  157624. bptr++;
  157625. cptr++;
  157626. }
  157627. dist1 += xx1;
  157628. xx1 += 2 * STEP_C1 * STEP_C1;
  157629. }
  157630. dist0 += xx0;
  157631. xx0 += 2 * STEP_C0 * STEP_C0;
  157632. }
  157633. }
  157634. }
  157635. LOCAL(void)
  157636. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  157637. {
  157638. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157639. hist3d histogram = cquantize->histogram;
  157640. int minc0, minc1, minc2; /* lower left corner of update box */
  157641. int ic0, ic1, ic2;
  157642. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  157643. register histptr cachep; /* pointer into main cache array */
  157644. JSAMPLE colorlist[MAXNUMCOLORS];
  157645. int numcolors; /* number of candidate colors */
  157646. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  157647. c0 >>= BOX_C0_LOG;
  157648. c1 >>= BOX_C1_LOG;
  157649. c2 >>= BOX_C2_LOG;
  157650. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  157651. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  157652. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  157653. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  157654. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  157655. bestcolor);
  157656. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  157657. c1 <<= BOX_C1_LOG;
  157658. c2 <<= BOX_C2_LOG;
  157659. cptr = bestcolor;
  157660. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  157661. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  157662. cachep = & histogram[c0+ic0][c1+ic1][c2];
  157663. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  157664. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  157665. }
  157666. }
  157667. }
  157668. }
  157669. METHODDEF(void)
  157670. pass2_no_dither (j_decompress_ptr cinfo,
  157671. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157672. {
  157673. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157674. hist3d histogram = cquantize->histogram;
  157675. register JSAMPROW inptr, outptr;
  157676. register histptr cachep;
  157677. register int c0, c1, c2;
  157678. int row;
  157679. JDIMENSION col;
  157680. JDIMENSION width = cinfo->output_width;
  157681. for (row = 0; row < num_rows; row++) {
  157682. inptr = input_buf[row];
  157683. outptr = output_buf[row];
  157684. for (col = width; col > 0; col--) {
  157685. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  157686. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  157687. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  157688. cachep = & histogram[c0][c1][c2];
  157689. if (*cachep == 0)
  157690. fill_inverse_cmap(cinfo, c0,c1,c2);
  157691. *outptr++ = (JSAMPLE) (*cachep - 1);
  157692. }
  157693. }
  157694. }
  157695. METHODDEF(void)
  157696. pass2_fs_dither (j_decompress_ptr cinfo,
  157697. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  157698. {
  157699. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157700. hist3d histogram = cquantize->histogram;
  157701. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  157702. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  157703. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  157704. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157705. JSAMPROW inptr; /* => current input pixel */
  157706. JSAMPROW outptr; /* => current output pixel */
  157707. histptr cachep;
  157708. int dir; /* +1 or -1 depending on direction */
  157709. int dir3; /* 3*dir, for advancing inptr & errorptr */
  157710. int row;
  157711. JDIMENSION col;
  157712. JDIMENSION width = cinfo->output_width;
  157713. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157714. int *error_limit = cquantize->error_limiter;
  157715. JSAMPROW colormap0 = cinfo->colormap[0];
  157716. JSAMPROW colormap1 = cinfo->colormap[1];
  157717. JSAMPROW colormap2 = cinfo->colormap[2];
  157718. SHIFT_TEMPS
  157719. for (row = 0; row < num_rows; row++) {
  157720. inptr = input_buf[row];
  157721. outptr = output_buf[row];
  157722. if (cquantize->on_odd_row) {
  157723. inptr += (width-1) * 3; /* so point to rightmost pixel */
  157724. outptr += width-1;
  157725. dir = -1;
  157726. dir3 = -3;
  157727. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  157728. cquantize->on_odd_row = FALSE; /* flip for next time */
  157729. } else {
  157730. dir = 1;
  157731. dir3 = 3;
  157732. errorptr = cquantize->fserrors; /* => entry before first real column */
  157733. cquantize->on_odd_row = TRUE; /* flip for next time */
  157734. }
  157735. cur0 = cur1 = cur2 = 0;
  157736. belowerr0 = belowerr1 = belowerr2 = 0;
  157737. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  157738. for (col = width; col > 0; col--) {
  157739. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  157740. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  157741. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  157742. cur0 = error_limit[cur0];
  157743. cur1 = error_limit[cur1];
  157744. cur2 = error_limit[cur2];
  157745. cur0 += GETJSAMPLE(inptr[0]);
  157746. cur1 += GETJSAMPLE(inptr[1]);
  157747. cur2 += GETJSAMPLE(inptr[2]);
  157748. cur0 = GETJSAMPLE(range_limit[cur0]);
  157749. cur1 = GETJSAMPLE(range_limit[cur1]);
  157750. cur2 = GETJSAMPLE(range_limit[cur2]);
  157751. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  157752. if (*cachep == 0)
  157753. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  157754. { register int pixcode = *cachep - 1;
  157755. *outptr = (JSAMPLE) pixcode;
  157756. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  157757. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  157758. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  157759. }
  157760. { register LOCFSERROR bnexterr, delta;
  157761. bnexterr = cur0; /* Process component 0 */
  157762. delta = cur0 * 2;
  157763. cur0 += delta; /* form error * 3 */
  157764. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  157765. cur0 += delta; /* form error * 5 */
  157766. bpreverr0 = belowerr0 + cur0;
  157767. belowerr0 = bnexterr;
  157768. cur0 += delta; /* form error * 7 */
  157769. bnexterr = cur1; /* Process component 1 */
  157770. delta = cur1 * 2;
  157771. cur1 += delta; /* form error * 3 */
  157772. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  157773. cur1 += delta; /* form error * 5 */
  157774. bpreverr1 = belowerr1 + cur1;
  157775. belowerr1 = bnexterr;
  157776. cur1 += delta; /* form error * 7 */
  157777. bnexterr = cur2; /* Process component 2 */
  157778. delta = cur2 * 2;
  157779. cur2 += delta; /* form error * 3 */
  157780. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  157781. cur2 += delta; /* form error * 5 */
  157782. bpreverr2 = belowerr2 + cur2;
  157783. belowerr2 = bnexterr;
  157784. cur2 += delta; /* form error * 7 */
  157785. }
  157786. inptr += dir3; /* Advance pixel pointers to next column */
  157787. outptr += dir;
  157788. errorptr += dir3; /* advance errorptr to current column */
  157789. }
  157790. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  157791. errorptr[1] = (FSERROR) bpreverr1;
  157792. errorptr[2] = (FSERROR) bpreverr2;
  157793. }
  157794. }
  157795. LOCAL(void)
  157796. init_error_limit (j_decompress_ptr cinfo)
  157797. {
  157798. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157799. int * table;
  157800. int in, out;
  157801. table = (int *) (*cinfo->mem->alloc_small)
  157802. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  157803. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  157804. cquantize->error_limiter = table;
  157805. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  157806. out = 0;
  157807. for (in = 0; in < STEPSIZE; in++, out++) {
  157808. table[in] = out; table[-in] = -out;
  157809. }
  157810. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  157811. table[in] = out; table[-in] = -out;
  157812. }
  157813. for (; in <= MAXJSAMPLE; in++) {
  157814. table[in] = out; table[-in] = -out;
  157815. }
  157816. #undef STEPSIZE
  157817. }
  157818. METHODDEF(void)
  157819. finish_pass1 (j_decompress_ptr cinfo)
  157820. {
  157821. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157822. cinfo->colormap = cquantize->sv_colormap;
  157823. select_colors(cinfo, cquantize->desired);
  157824. cquantize->needs_zeroed = TRUE;
  157825. }
  157826. METHODDEF(void)
  157827. finish_pass2 (j_decompress_ptr cinfo)
  157828. {
  157829. }
  157830. METHODDEF(void)
  157831. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157832. {
  157833. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157834. hist3d histogram = cquantize->histogram;
  157835. int i;
  157836. if (cinfo->dither_mode != JDITHER_NONE)
  157837. cinfo->dither_mode = JDITHER_FS;
  157838. if (is_pre_scan) {
  157839. cquantize->pub.color_quantize = prescan_quantize;
  157840. cquantize->pub.finish_pass = finish_pass1;
  157841. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  157842. } else {
  157843. if (cinfo->dither_mode == JDITHER_FS)
  157844. cquantize->pub.color_quantize = pass2_fs_dither;
  157845. else
  157846. cquantize->pub.color_quantize = pass2_no_dither;
  157847. cquantize->pub.finish_pass = finish_pass2;
  157848. i = cinfo->actual_number_of_colors;
  157849. if (i < 1)
  157850. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  157851. if (i > MAXNUMCOLORS)
  157852. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157853. if (cinfo->dither_mode == JDITHER_FS) {
  157854. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  157855. (3 * SIZEOF(FSERROR)));
  157856. if (cquantize->fserrors == NULL)
  157857. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157858. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157859. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  157860. if (cquantize->error_limiter == NULL)
  157861. init_error_limit(cinfo);
  157862. cquantize->on_odd_row = FALSE;
  157863. }
  157864. }
  157865. if (cquantize->needs_zeroed) {
  157866. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157867. jzero_far((void FAR *) histogram[i],
  157868. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157869. }
  157870. cquantize->needs_zeroed = FALSE;
  157871. }
  157872. }
  157873. METHODDEF(void)
  157874. new_color_map_2_quant (j_decompress_ptr cinfo)
  157875. {
  157876. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157877. cquantize->needs_zeroed = TRUE;
  157878. }
  157879. GLOBAL(void)
  157880. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  157881. {
  157882. my_cquantize_ptr2 cquantize;
  157883. int i;
  157884. cquantize = (my_cquantize_ptr2)
  157885. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157886. SIZEOF(my_cquantizer2));
  157887. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157888. cquantize->pub.start_pass = start_pass_2_quant;
  157889. cquantize->pub.new_color_map = new_color_map_2_quant;
  157890. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  157891. cquantize->error_limiter = NULL;
  157892. if (cinfo->out_color_components != 3)
  157893. ERREXIT(cinfo, JERR_NOTIMPL);
  157894. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  157895. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  157896. for (i = 0; i < HIST_C0_ELEMS; i++) {
  157897. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  157898. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157899. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  157900. }
  157901. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  157902. if (cinfo->enable_2pass_quant) {
  157903. int desired = cinfo->desired_number_of_colors;
  157904. if (desired < 8)
  157905. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  157906. if (desired > MAXNUMCOLORS)
  157907. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  157908. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  157909. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  157910. cquantize->desired = desired;
  157911. } else
  157912. cquantize->sv_colormap = NULL;
  157913. if (cinfo->dither_mode != JDITHER_NONE)
  157914. cinfo->dither_mode = JDITHER_FS;
  157915. if (cinfo->dither_mode == JDITHER_FS) {
  157916. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  157917. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157918. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  157919. init_error_limit(cinfo);
  157920. }
  157921. }
  157922. #endif /* QUANT_2PASS_SUPPORTED */
  157923. /*** End of inlined file: jquant2.c ***/
  157924. /*** Start of inlined file: jutils.c ***/
  157925. #define JPEG_INTERNALS
  157926. #if 0 /* This table is not actually needed in v6a */
  157927. const int jpeg_zigzag_order[DCTSIZE2] = {
  157928. 0, 1, 5, 6, 14, 15, 27, 28,
  157929. 2, 4, 7, 13, 16, 26, 29, 42,
  157930. 3, 8, 12, 17, 25, 30, 41, 43,
  157931. 9, 11, 18, 24, 31, 40, 44, 53,
  157932. 10, 19, 23, 32, 39, 45, 52, 54,
  157933. 20, 22, 33, 38, 46, 51, 55, 60,
  157934. 21, 34, 37, 47, 50, 56, 59, 61,
  157935. 35, 36, 48, 49, 57, 58, 62, 63
  157936. };
  157937. #endif
  157938. const int jpeg_natural_order[DCTSIZE2+16] = {
  157939. 0, 1, 8, 16, 9, 2, 3, 10,
  157940. 17, 24, 32, 25, 18, 11, 4, 5,
  157941. 12, 19, 26, 33, 40, 48, 41, 34,
  157942. 27, 20, 13, 6, 7, 14, 21, 28,
  157943. 35, 42, 49, 56, 57, 50, 43, 36,
  157944. 29, 22, 15, 23, 30, 37, 44, 51,
  157945. 58, 59, 52, 45, 38, 31, 39, 46,
  157946. 53, 60, 61, 54, 47, 55, 62, 63,
  157947. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  157948. 63, 63, 63, 63, 63, 63, 63, 63
  157949. };
  157950. GLOBAL(long)
  157951. jdiv_round_up (long a, long b)
  157952. {
  157953. return (a + b - 1L) / b;
  157954. }
  157955. GLOBAL(long)
  157956. jround_up (long a, long b)
  157957. {
  157958. a += b - 1L;
  157959. return a - (a % b);
  157960. }
  157961. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  157962. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  157963. #define FMEMZERO(target,size) MEMZERO(target,size)
  157964. #else /* 80x86 case, define if we can */
  157965. #ifdef USE_FMEM
  157966. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  157967. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  157968. #endif
  157969. #endif
  157970. GLOBAL(void)
  157971. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  157972. JSAMPARRAY output_array, int dest_row,
  157973. int num_rows, JDIMENSION num_cols)
  157974. {
  157975. register JSAMPROW inptr, outptr;
  157976. #ifdef FMEMCOPY
  157977. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  157978. #else
  157979. register JDIMENSION count;
  157980. #endif
  157981. register int row;
  157982. input_array += source_row;
  157983. output_array += dest_row;
  157984. for (row = num_rows; row > 0; row--) {
  157985. inptr = *input_array++;
  157986. outptr = *output_array++;
  157987. #ifdef FMEMCOPY
  157988. FMEMCOPY(outptr, inptr, count);
  157989. #else
  157990. for (count = num_cols; count > 0; count--)
  157991. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  157992. #endif
  157993. }
  157994. }
  157995. GLOBAL(void)
  157996. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  157997. JDIMENSION num_blocks)
  157998. {
  157999. #ifdef FMEMCOPY
  158000. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158001. #else
  158002. register JCOEFPTR inptr, outptr;
  158003. register long count;
  158004. inptr = (JCOEFPTR) input_row;
  158005. outptr = (JCOEFPTR) output_row;
  158006. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158007. *outptr++ = *inptr++;
  158008. }
  158009. #endif
  158010. }
  158011. GLOBAL(void)
  158012. jzero_far (void FAR * target, size_t bytestozero)
  158013. {
  158014. #ifdef FMEMZERO
  158015. FMEMZERO(target, bytestozero);
  158016. #else
  158017. register char FAR * ptr = (char FAR *) target;
  158018. register size_t count;
  158019. for (count = bytestozero; count > 0; count--) {
  158020. *ptr++ = 0;
  158021. }
  158022. #endif
  158023. }
  158024. /*** End of inlined file: jutils.c ***/
  158025. /*** Start of inlined file: transupp.c ***/
  158026. #define JPEG_INTERNALS
  158027. /*** Start of inlined file: transupp.h ***/
  158028. #ifndef TRANSFORMS_SUPPORTED
  158029. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158030. #endif
  158031. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158032. #define jtransform_request_workspace jTrRequest
  158033. #define jtransform_adjust_parameters jTrAdjust
  158034. #define jtransform_execute_transformation jTrExec
  158035. #define jcopy_markers_setup jCMrkSetup
  158036. #define jcopy_markers_execute jCMrkExec
  158037. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158038. typedef enum {
  158039. JXFORM_NONE, /* no transformation */
  158040. JXFORM_FLIP_H, /* horizontal flip */
  158041. JXFORM_FLIP_V, /* vertical flip */
  158042. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158043. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158044. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158045. JXFORM_ROT_180, /* 180-degree rotation */
  158046. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158047. } JXFORM_CODE;
  158048. typedef struct {
  158049. JXFORM_CODE transform; /* image transform operator */
  158050. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158051. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158052. int num_components; /* # of components in workspace */
  158053. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158054. } jpeg_transform_info;
  158055. #if TRANSFORMS_SUPPORTED
  158056. EXTERN(void) jtransform_request_workspace
  158057. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158058. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158059. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158060. jvirt_barray_ptr *src_coef_arrays,
  158061. jpeg_transform_info *info));
  158062. EXTERN(void) jtransform_execute_transformation
  158063. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158064. jvirt_barray_ptr *src_coef_arrays,
  158065. jpeg_transform_info *info));
  158066. #endif /* TRANSFORMS_SUPPORTED */
  158067. typedef enum {
  158068. JCOPYOPT_NONE, /* copy no optional markers */
  158069. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158070. JCOPYOPT_ALL /* copy all optional markers */
  158071. } JCOPY_OPTION;
  158072. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158073. EXTERN(void) jcopy_markers_setup
  158074. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158075. EXTERN(void) jcopy_markers_execute
  158076. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158077. JCOPY_OPTION option));
  158078. /*** End of inlined file: transupp.h ***/
  158079. /* My own external interface */
  158080. #if TRANSFORMS_SUPPORTED
  158081. LOCAL(void)
  158082. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158083. jvirt_barray_ptr *src_coef_arrays)
  158084. {
  158085. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158086. int ci, k, offset_y;
  158087. JBLOCKARRAY buffer;
  158088. JCOEFPTR ptr1, ptr2;
  158089. JCOEF temp1, temp2;
  158090. jpeg_component_info *compptr;
  158091. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158092. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158093. compptr = dstinfo->comp_info + ci;
  158094. comp_width = MCU_cols * compptr->h_samp_factor;
  158095. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158096. blk_y += compptr->v_samp_factor) {
  158097. buffer = (*srcinfo->mem->access_virt_barray)
  158098. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158099. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158100. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158101. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158102. ptr1 = buffer[offset_y][blk_x];
  158103. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158104. for (k = 0; k < DCTSIZE2; k += 2) {
  158105. temp1 = *ptr1; /* swap even column */
  158106. temp2 = *ptr2;
  158107. *ptr1++ = temp2;
  158108. *ptr2++ = temp1;
  158109. temp1 = *ptr1; /* swap odd column with sign change */
  158110. temp2 = *ptr2;
  158111. *ptr1++ = -temp2;
  158112. *ptr2++ = -temp1;
  158113. }
  158114. }
  158115. }
  158116. }
  158117. }
  158118. }
  158119. LOCAL(void)
  158120. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158121. jvirt_barray_ptr *src_coef_arrays,
  158122. jvirt_barray_ptr *dst_coef_arrays)
  158123. {
  158124. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158125. int ci, i, j, offset_y;
  158126. JBLOCKARRAY src_buffer, dst_buffer;
  158127. JBLOCKROW src_row_ptr, dst_row_ptr;
  158128. JCOEFPTR src_ptr, dst_ptr;
  158129. jpeg_component_info *compptr;
  158130. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158131. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158132. compptr = dstinfo->comp_info + ci;
  158133. comp_height = MCU_rows * compptr->v_samp_factor;
  158134. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158135. dst_blk_y += compptr->v_samp_factor) {
  158136. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158137. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158138. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158139. if (dst_blk_y < comp_height) {
  158140. src_buffer = (*srcinfo->mem->access_virt_barray)
  158141. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158142. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158143. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158144. } else {
  158145. src_buffer = (*srcinfo->mem->access_virt_barray)
  158146. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158147. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158148. }
  158149. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158150. if (dst_blk_y < comp_height) {
  158151. dst_row_ptr = dst_buffer[offset_y];
  158152. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158153. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158154. dst_blk_x++) {
  158155. dst_ptr = dst_row_ptr[dst_blk_x];
  158156. src_ptr = src_row_ptr[dst_blk_x];
  158157. for (i = 0; i < DCTSIZE; i += 2) {
  158158. for (j = 0; j < DCTSIZE; j++)
  158159. *dst_ptr++ = *src_ptr++;
  158160. for (j = 0; j < DCTSIZE; j++)
  158161. *dst_ptr++ = - *src_ptr++;
  158162. }
  158163. }
  158164. } else {
  158165. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158166. compptr->width_in_blocks);
  158167. }
  158168. }
  158169. }
  158170. }
  158171. }
  158172. LOCAL(void)
  158173. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158174. jvirt_barray_ptr *src_coef_arrays,
  158175. jvirt_barray_ptr *dst_coef_arrays)
  158176. {
  158177. JDIMENSION dst_blk_x, dst_blk_y;
  158178. int ci, i, j, offset_x, offset_y;
  158179. JBLOCKARRAY src_buffer, dst_buffer;
  158180. JCOEFPTR src_ptr, dst_ptr;
  158181. jpeg_component_info *compptr;
  158182. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158183. compptr = dstinfo->comp_info + ci;
  158184. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158185. dst_blk_y += compptr->v_samp_factor) {
  158186. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158187. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158188. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158189. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158190. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158191. dst_blk_x += compptr->h_samp_factor) {
  158192. src_buffer = (*srcinfo->mem->access_virt_barray)
  158193. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158194. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158195. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158196. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158197. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158198. for (i = 0; i < DCTSIZE; i++)
  158199. for (j = 0; j < DCTSIZE; j++)
  158200. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158201. }
  158202. }
  158203. }
  158204. }
  158205. }
  158206. }
  158207. LOCAL(void)
  158208. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158209. jvirt_barray_ptr *src_coef_arrays,
  158210. jvirt_barray_ptr *dst_coef_arrays)
  158211. {
  158212. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158213. int ci, i, j, offset_x, offset_y;
  158214. JBLOCKARRAY src_buffer, dst_buffer;
  158215. JCOEFPTR src_ptr, dst_ptr;
  158216. jpeg_component_info *compptr;
  158217. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158218. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158219. compptr = dstinfo->comp_info + ci;
  158220. comp_width = MCU_cols * compptr->h_samp_factor;
  158221. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158222. dst_blk_y += compptr->v_samp_factor) {
  158223. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158224. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158225. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158226. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158227. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158228. dst_blk_x += compptr->h_samp_factor) {
  158229. src_buffer = (*srcinfo->mem->access_virt_barray)
  158230. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158231. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158232. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158233. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158234. if (dst_blk_x < comp_width) {
  158235. dst_ptr = dst_buffer[offset_y]
  158236. [comp_width - dst_blk_x - offset_x - 1];
  158237. for (i = 0; i < DCTSIZE; i++) {
  158238. for (j = 0; j < DCTSIZE; j++)
  158239. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158240. i++;
  158241. for (j = 0; j < DCTSIZE; j++)
  158242. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158243. }
  158244. } else {
  158245. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158246. for (i = 0; i < DCTSIZE; i++)
  158247. for (j = 0; j < DCTSIZE; j++)
  158248. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158249. }
  158250. }
  158251. }
  158252. }
  158253. }
  158254. }
  158255. }
  158256. LOCAL(void)
  158257. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158258. jvirt_barray_ptr *src_coef_arrays,
  158259. jvirt_barray_ptr *dst_coef_arrays)
  158260. {
  158261. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158262. int ci, i, j, offset_x, offset_y;
  158263. JBLOCKARRAY src_buffer, dst_buffer;
  158264. JCOEFPTR src_ptr, dst_ptr;
  158265. jpeg_component_info *compptr;
  158266. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158267. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158268. compptr = dstinfo->comp_info + ci;
  158269. comp_height = MCU_rows * compptr->v_samp_factor;
  158270. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158271. dst_blk_y += compptr->v_samp_factor) {
  158272. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158273. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158274. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158275. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158276. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158277. dst_blk_x += compptr->h_samp_factor) {
  158278. src_buffer = (*srcinfo->mem->access_virt_barray)
  158279. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158280. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158281. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158282. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158283. if (dst_blk_y < comp_height) {
  158284. src_ptr = src_buffer[offset_x]
  158285. [comp_height - dst_blk_y - offset_y - 1];
  158286. for (i = 0; i < DCTSIZE; i++) {
  158287. for (j = 0; j < DCTSIZE; j++) {
  158288. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158289. j++;
  158290. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158291. }
  158292. }
  158293. } else {
  158294. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158295. for (i = 0; i < DCTSIZE; i++)
  158296. for (j = 0; j < DCTSIZE; j++)
  158297. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158298. }
  158299. }
  158300. }
  158301. }
  158302. }
  158303. }
  158304. }
  158305. LOCAL(void)
  158306. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158307. jvirt_barray_ptr *src_coef_arrays,
  158308. jvirt_barray_ptr *dst_coef_arrays)
  158309. {
  158310. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158311. int ci, i, j, offset_y;
  158312. JBLOCKARRAY src_buffer, dst_buffer;
  158313. JBLOCKROW src_row_ptr, dst_row_ptr;
  158314. JCOEFPTR src_ptr, dst_ptr;
  158315. jpeg_component_info *compptr;
  158316. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158317. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158318. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158319. compptr = dstinfo->comp_info + ci;
  158320. comp_width = MCU_cols * compptr->h_samp_factor;
  158321. comp_height = MCU_rows * compptr->v_samp_factor;
  158322. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158323. dst_blk_y += compptr->v_samp_factor) {
  158324. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158325. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158326. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158327. if (dst_blk_y < comp_height) {
  158328. src_buffer = (*srcinfo->mem->access_virt_barray)
  158329. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158330. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158331. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158332. } else {
  158333. src_buffer = (*srcinfo->mem->access_virt_barray)
  158334. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158335. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158336. }
  158337. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158338. if (dst_blk_y < comp_height) {
  158339. dst_row_ptr = dst_buffer[offset_y];
  158340. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158341. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158342. dst_ptr = dst_row_ptr[dst_blk_x];
  158343. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158344. for (i = 0; i < DCTSIZE; i += 2) {
  158345. for (j = 0; j < DCTSIZE; j += 2) {
  158346. *dst_ptr++ = *src_ptr++;
  158347. *dst_ptr++ = - *src_ptr++;
  158348. }
  158349. for (j = 0; j < DCTSIZE; j += 2) {
  158350. *dst_ptr++ = - *src_ptr++;
  158351. *dst_ptr++ = *src_ptr++;
  158352. }
  158353. }
  158354. }
  158355. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158356. dst_ptr = dst_row_ptr[dst_blk_x];
  158357. src_ptr = src_row_ptr[dst_blk_x];
  158358. for (i = 0; i < DCTSIZE; i += 2) {
  158359. for (j = 0; j < DCTSIZE; j++)
  158360. *dst_ptr++ = *src_ptr++;
  158361. for (j = 0; j < DCTSIZE; j++)
  158362. *dst_ptr++ = - *src_ptr++;
  158363. }
  158364. }
  158365. } else {
  158366. dst_row_ptr = dst_buffer[offset_y];
  158367. src_row_ptr = src_buffer[offset_y];
  158368. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158369. dst_ptr = dst_row_ptr[dst_blk_x];
  158370. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158371. for (i = 0; i < DCTSIZE2; i += 2) {
  158372. *dst_ptr++ = *src_ptr++;
  158373. *dst_ptr++ = - *src_ptr++;
  158374. }
  158375. }
  158376. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158377. dst_ptr = dst_row_ptr[dst_blk_x];
  158378. src_ptr = src_row_ptr[dst_blk_x];
  158379. for (i = 0; i < DCTSIZE2; i++)
  158380. *dst_ptr++ = *src_ptr++;
  158381. }
  158382. }
  158383. }
  158384. }
  158385. }
  158386. }
  158387. LOCAL(void)
  158388. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158389. jvirt_barray_ptr *src_coef_arrays,
  158390. jvirt_barray_ptr *dst_coef_arrays)
  158391. {
  158392. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158393. int ci, i, j, offset_x, offset_y;
  158394. JBLOCKARRAY src_buffer, dst_buffer;
  158395. JCOEFPTR src_ptr, dst_ptr;
  158396. jpeg_component_info *compptr;
  158397. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158398. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158399. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158400. compptr = dstinfo->comp_info + ci;
  158401. comp_width = MCU_cols * compptr->h_samp_factor;
  158402. comp_height = MCU_rows * compptr->v_samp_factor;
  158403. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158404. dst_blk_y += compptr->v_samp_factor) {
  158405. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158406. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158407. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158408. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158409. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158410. dst_blk_x += compptr->h_samp_factor) {
  158411. src_buffer = (*srcinfo->mem->access_virt_barray)
  158412. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158413. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158414. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158415. if (dst_blk_y < comp_height) {
  158416. src_ptr = src_buffer[offset_x]
  158417. [comp_height - dst_blk_y - offset_y - 1];
  158418. if (dst_blk_x < comp_width) {
  158419. dst_ptr = dst_buffer[offset_y]
  158420. [comp_width - dst_blk_x - offset_x - 1];
  158421. for (i = 0; i < DCTSIZE; i++) {
  158422. for (j = 0; j < DCTSIZE; j++) {
  158423. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158424. j++;
  158425. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158426. }
  158427. i++;
  158428. for (j = 0; j < DCTSIZE; j++) {
  158429. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158430. j++;
  158431. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158432. }
  158433. }
  158434. } else {
  158435. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158436. for (i = 0; i < DCTSIZE; i++) {
  158437. for (j = 0; j < DCTSIZE; j++) {
  158438. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158439. j++;
  158440. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158441. }
  158442. }
  158443. }
  158444. } else {
  158445. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158446. if (dst_blk_x < comp_width) {
  158447. dst_ptr = dst_buffer[offset_y]
  158448. [comp_width - dst_blk_x - offset_x - 1];
  158449. for (i = 0; i < DCTSIZE; i++) {
  158450. for (j = 0; j < DCTSIZE; j++)
  158451. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158452. i++;
  158453. for (j = 0; j < DCTSIZE; j++)
  158454. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158455. }
  158456. } else {
  158457. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158458. for (i = 0; i < DCTSIZE; i++)
  158459. for (j = 0; j < DCTSIZE; j++)
  158460. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158461. }
  158462. }
  158463. }
  158464. }
  158465. }
  158466. }
  158467. }
  158468. }
  158469. GLOBAL(void)
  158470. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158471. jpeg_transform_info *info)
  158472. {
  158473. jvirt_barray_ptr *coef_arrays = NULL;
  158474. jpeg_component_info *compptr;
  158475. int ci;
  158476. if (info->force_grayscale &&
  158477. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158478. srcinfo->num_components == 3) {
  158479. info->num_components = 1;
  158480. } else {
  158481. info->num_components = srcinfo->num_components;
  158482. }
  158483. switch (info->transform) {
  158484. case JXFORM_NONE:
  158485. case JXFORM_FLIP_H:
  158486. break;
  158487. case JXFORM_FLIP_V:
  158488. case JXFORM_ROT_180:
  158489. coef_arrays = (jvirt_barray_ptr *)
  158490. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158491. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158492. for (ci = 0; ci < info->num_components; ci++) {
  158493. compptr = srcinfo->comp_info + ci;
  158494. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158495. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158496. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158497. (long) compptr->h_samp_factor),
  158498. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158499. (long) compptr->v_samp_factor),
  158500. (JDIMENSION) compptr->v_samp_factor);
  158501. }
  158502. break;
  158503. case JXFORM_TRANSPOSE:
  158504. case JXFORM_TRANSVERSE:
  158505. case JXFORM_ROT_90:
  158506. case JXFORM_ROT_270:
  158507. coef_arrays = (jvirt_barray_ptr *)
  158508. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158509. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158510. for (ci = 0; ci < info->num_components; ci++) {
  158511. compptr = srcinfo->comp_info + ci;
  158512. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158513. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158514. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158515. (long) compptr->v_samp_factor),
  158516. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158517. (long) compptr->h_samp_factor),
  158518. (JDIMENSION) compptr->h_samp_factor);
  158519. }
  158520. break;
  158521. }
  158522. info->workspace_coef_arrays = coef_arrays;
  158523. }
  158524. LOCAL(void)
  158525. transpose_critical_parameters (j_compress_ptr dstinfo)
  158526. {
  158527. int tblno, i, j, ci, itemp;
  158528. jpeg_component_info *compptr;
  158529. JQUANT_TBL *qtblptr;
  158530. JDIMENSION dtemp;
  158531. UINT16 qtemp;
  158532. dtemp = dstinfo->image_width;
  158533. dstinfo->image_width = dstinfo->image_height;
  158534. dstinfo->image_height = dtemp;
  158535. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158536. compptr = dstinfo->comp_info + ci;
  158537. itemp = compptr->h_samp_factor;
  158538. compptr->h_samp_factor = compptr->v_samp_factor;
  158539. compptr->v_samp_factor = itemp;
  158540. }
  158541. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  158542. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  158543. if (qtblptr != NULL) {
  158544. for (i = 0; i < DCTSIZE; i++) {
  158545. for (j = 0; j < i; j++) {
  158546. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  158547. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  158548. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  158549. }
  158550. }
  158551. }
  158552. }
  158553. }
  158554. LOCAL(void)
  158555. trim_right_edge (j_compress_ptr dstinfo)
  158556. {
  158557. int ci, max_h_samp_factor;
  158558. JDIMENSION MCU_cols;
  158559. max_h_samp_factor = 1;
  158560. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158561. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  158562. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  158563. }
  158564. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  158565. if (MCU_cols > 0) /* can't trim to 0 pixels */
  158566. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  158567. }
  158568. LOCAL(void)
  158569. trim_bottom_edge (j_compress_ptr dstinfo)
  158570. {
  158571. int ci, max_v_samp_factor;
  158572. JDIMENSION MCU_rows;
  158573. max_v_samp_factor = 1;
  158574. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158575. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  158576. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  158577. }
  158578. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  158579. if (MCU_rows > 0) /* can't trim to 0 pixels */
  158580. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  158581. }
  158582. GLOBAL(jvirt_barray_ptr *)
  158583. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  158584. j_compress_ptr dstinfo,
  158585. jvirt_barray_ptr *src_coef_arrays,
  158586. jpeg_transform_info *info)
  158587. {
  158588. if (info->force_grayscale) {
  158589. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  158590. dstinfo->num_components == 3) ||
  158591. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  158592. dstinfo->num_components == 1)) {
  158593. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  158594. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  158595. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  158596. } else {
  158597. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  158598. }
  158599. }
  158600. switch (info->transform) {
  158601. case JXFORM_NONE:
  158602. break;
  158603. case JXFORM_FLIP_H:
  158604. if (info->trim)
  158605. trim_right_edge(dstinfo);
  158606. break;
  158607. case JXFORM_FLIP_V:
  158608. if (info->trim)
  158609. trim_bottom_edge(dstinfo);
  158610. break;
  158611. case JXFORM_TRANSPOSE:
  158612. transpose_critical_parameters(dstinfo);
  158613. break;
  158614. case JXFORM_TRANSVERSE:
  158615. transpose_critical_parameters(dstinfo);
  158616. if (info->trim) {
  158617. trim_right_edge(dstinfo);
  158618. trim_bottom_edge(dstinfo);
  158619. }
  158620. break;
  158621. case JXFORM_ROT_90:
  158622. transpose_critical_parameters(dstinfo);
  158623. if (info->trim)
  158624. trim_right_edge(dstinfo);
  158625. break;
  158626. case JXFORM_ROT_180:
  158627. if (info->trim) {
  158628. trim_right_edge(dstinfo);
  158629. trim_bottom_edge(dstinfo);
  158630. }
  158631. break;
  158632. case JXFORM_ROT_270:
  158633. transpose_critical_parameters(dstinfo);
  158634. if (info->trim)
  158635. trim_bottom_edge(dstinfo);
  158636. break;
  158637. }
  158638. if (info->workspace_coef_arrays != NULL)
  158639. return info->workspace_coef_arrays;
  158640. return src_coef_arrays;
  158641. }
  158642. GLOBAL(void)
  158643. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  158644. j_compress_ptr dstinfo,
  158645. jvirt_barray_ptr *src_coef_arrays,
  158646. jpeg_transform_info *info)
  158647. {
  158648. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  158649. switch (info->transform) {
  158650. case JXFORM_NONE:
  158651. break;
  158652. case JXFORM_FLIP_H:
  158653. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  158654. break;
  158655. case JXFORM_FLIP_V:
  158656. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158657. break;
  158658. case JXFORM_TRANSPOSE:
  158659. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158660. break;
  158661. case JXFORM_TRANSVERSE:
  158662. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158663. break;
  158664. case JXFORM_ROT_90:
  158665. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158666. break;
  158667. case JXFORM_ROT_180:
  158668. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158669. break;
  158670. case JXFORM_ROT_270:
  158671. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  158672. break;
  158673. }
  158674. }
  158675. #endif /* TRANSFORMS_SUPPORTED */
  158676. GLOBAL(void)
  158677. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  158678. {
  158679. #ifdef SAVE_MARKERS_SUPPORTED
  158680. int m;
  158681. if (option != JCOPYOPT_NONE) {
  158682. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  158683. }
  158684. if (option == JCOPYOPT_ALL) {
  158685. for (m = 0; m < 16; m++)
  158686. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  158687. }
  158688. #endif /* SAVE_MARKERS_SUPPORTED */
  158689. }
  158690. GLOBAL(void)
  158691. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158692. JCOPY_OPTION option)
  158693. {
  158694. jpeg_saved_marker_ptr marker;
  158695. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  158696. if (dstinfo->write_JFIF_header &&
  158697. marker->marker == JPEG_APP0 &&
  158698. marker->data_length >= 5 &&
  158699. GETJOCTET(marker->data[0]) == 0x4A &&
  158700. GETJOCTET(marker->data[1]) == 0x46 &&
  158701. GETJOCTET(marker->data[2]) == 0x49 &&
  158702. GETJOCTET(marker->data[3]) == 0x46 &&
  158703. GETJOCTET(marker->data[4]) == 0)
  158704. continue; /* reject duplicate JFIF */
  158705. if (dstinfo->write_Adobe_marker &&
  158706. marker->marker == JPEG_APP0+14 &&
  158707. marker->data_length >= 5 &&
  158708. GETJOCTET(marker->data[0]) == 0x41 &&
  158709. GETJOCTET(marker->data[1]) == 0x64 &&
  158710. GETJOCTET(marker->data[2]) == 0x6F &&
  158711. GETJOCTET(marker->data[3]) == 0x62 &&
  158712. GETJOCTET(marker->data[4]) == 0x65)
  158713. continue; /* reject duplicate Adobe */
  158714. #ifdef NEED_FAR_POINTERS
  158715. {
  158716. unsigned int i;
  158717. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  158718. for (i = 0; i < marker->data_length; i++)
  158719. jpeg_write_m_byte(dstinfo, marker->data[i]);
  158720. }
  158721. #else
  158722. jpeg_write_marker(dstinfo, marker->marker,
  158723. marker->data, marker->data_length);
  158724. #endif
  158725. }
  158726. }
  158727. /*** End of inlined file: transupp.c ***/
  158728. }
  158729. #else
  158730. #define JPEG_INTERNALS
  158731. #undef FAR
  158732. #include <jpeglib.h>
  158733. #endif
  158734. }
  158735. #undef max
  158736. #undef min
  158737. #if JUCE_MSVC
  158738. #pragma warning (pop)
  158739. #endif
  158740. BEGIN_JUCE_NAMESPACE
  158741. namespace JPEGHelpers
  158742. {
  158743. using namespace jpeglibNamespace;
  158744. #if ! JUCE_MSVC
  158745. using jpeglibNamespace::boolean;
  158746. #endif
  158747. struct JPEGDecodingFailure {};
  158748. static void fatalErrorHandler (j_common_ptr)
  158749. {
  158750. throw JPEGDecodingFailure();
  158751. }
  158752. static void silentErrorCallback1 (j_common_ptr) {}
  158753. static void silentErrorCallback2 (j_common_ptr, int) {}
  158754. static void silentErrorCallback3 (j_common_ptr, char*) {}
  158755. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  158756. {
  158757. zerostruct (err);
  158758. err.error_exit = fatalErrorHandler;
  158759. err.emit_message = silentErrorCallback2;
  158760. err.output_message = silentErrorCallback1;
  158761. err.format_message = silentErrorCallback3;
  158762. err.reset_error_mgr = silentErrorCallback1;
  158763. }
  158764. static void dummyCallback1 (j_decompress_ptr)
  158765. {
  158766. }
  158767. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  158768. {
  158769. decompStruct->src->next_input_byte += num;
  158770. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  158771. decompStruct->src->bytes_in_buffer -= num;
  158772. }
  158773. static boolean jpegFill (j_decompress_ptr)
  158774. {
  158775. return 0;
  158776. }
  158777. static const int jpegBufferSize = 512;
  158778. struct JuceJpegDest : public jpeg_destination_mgr
  158779. {
  158780. OutputStream* output;
  158781. char* buffer;
  158782. };
  158783. static void jpegWriteInit (j_compress_ptr)
  158784. {
  158785. }
  158786. static void jpegWriteTerminate (j_compress_ptr cinfo)
  158787. {
  158788. JuceJpegDest* const dest = static_cast <JuceJpegDest*> (cinfo->dest);
  158789. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  158790. dest->output->write (dest->buffer, (int) numToWrite);
  158791. }
  158792. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  158793. {
  158794. JuceJpegDest* const dest = static_cast <JuceJpegDest*> (cinfo->dest);
  158795. const int numToWrite = jpegBufferSize;
  158796. dest->next_output_byte = reinterpret_cast <JOCTET*> (dest->buffer);
  158797. dest->free_in_buffer = jpegBufferSize;
  158798. return dest->output->write (dest->buffer, numToWrite);
  158799. }
  158800. }
  158801. Image* juce_loadJPEGImageFromStream (InputStream& in)
  158802. {
  158803. using namespace jpeglibNamespace;
  158804. using namespace JPEGHelpers;
  158805. MemoryBlock mb;
  158806. in.readIntoMemoryBlock (mb);
  158807. Image* image = 0;
  158808. if (mb.getSize() > 16)
  158809. {
  158810. struct jpeg_decompress_struct jpegDecompStruct;
  158811. struct jpeg_error_mgr jerr;
  158812. setupSilentErrorHandler (jerr);
  158813. jpegDecompStruct.err = &jerr;
  158814. jpeg_create_decompress (&jpegDecompStruct);
  158815. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  158816. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  158817. jpegDecompStruct.src->init_source = dummyCallback1;
  158818. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  158819. jpegDecompStruct.src->skip_input_data = jpegSkip;
  158820. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  158821. jpegDecompStruct.src->term_source = dummyCallback1;
  158822. jpegDecompStruct.src->next_input_byte = static_cast <const unsigned char*> (mb.getData());
  158823. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  158824. try
  158825. {
  158826. jpeg_read_header (&jpegDecompStruct, TRUE);
  158827. jpeg_calc_output_dimensions (&jpegDecompStruct);
  158828. const int width = jpegDecompStruct.output_width;
  158829. const int height = jpegDecompStruct.output_height;
  158830. jpegDecompStruct.out_color_space = JCS_RGB;
  158831. JSAMPARRAY buffer
  158832. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  158833. JPOOL_IMAGE,
  158834. width * 3, 1);
  158835. if (jpeg_start_decompress (&jpegDecompStruct))
  158836. {
  158837. image = Image::createNativeImage (Image::RGB, width, height, false);
  158838. const bool hasAlphaChan = image->hasAlphaChannel();
  158839. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  158840. for (int y = 0; y < height; ++y)
  158841. {
  158842. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  158843. const uint8* src = *buffer;
  158844. uint8* dest = destData.getLinePointer (y);
  158845. if (hasAlphaChan)
  158846. {
  158847. for (int i = width; --i >= 0;)
  158848. {
  158849. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158850. ((PixelARGB*) dest)->premultiply();
  158851. dest += destData.pixelStride;
  158852. src += 3;
  158853. }
  158854. }
  158855. else
  158856. {
  158857. for (int i = width; --i >= 0;)
  158858. {
  158859. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  158860. dest += destData.pixelStride;
  158861. src += 3;
  158862. }
  158863. }
  158864. }
  158865. jpeg_finish_decompress (&jpegDecompStruct);
  158866. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  158867. }
  158868. jpeg_destroy_decompress (&jpegDecompStruct);
  158869. }
  158870. catch (...)
  158871. {}
  158872. }
  158873. return image;
  158874. }
  158875. bool juce_writeJPEGImageToStream (const Image& image,
  158876. OutputStream& out,
  158877. float quality)
  158878. {
  158879. using namespace jpeglibNamespace;
  158880. using namespace JPEGHelpers;
  158881. if (image.hasAlphaChannel())
  158882. {
  158883. // this method could fill the background in white and still save the image..
  158884. jassertfalse
  158885. return true;
  158886. }
  158887. struct jpeg_compress_struct jpegCompStruct;
  158888. struct jpeg_error_mgr jerr;
  158889. setupSilentErrorHandler (jerr);
  158890. jpegCompStruct.err = &jerr;
  158891. jpeg_create_compress (&jpegCompStruct);
  158892. JuceJpegDest dest;
  158893. jpegCompStruct.dest = &dest;
  158894. dest.output = &out;
  158895. HeapBlock <char> tempBuffer (jpegBufferSize);
  158896. dest.buffer = tempBuffer;
  158897. dest.next_output_byte = (JOCTET*) dest.buffer;
  158898. dest.free_in_buffer = jpegBufferSize;
  158899. dest.init_destination = jpegWriteInit;
  158900. dest.empty_output_buffer = jpegWriteFlush;
  158901. dest.term_destination = jpegWriteTerminate;
  158902. jpegCompStruct.image_width = image.getWidth();
  158903. jpegCompStruct.image_height = image.getHeight();
  158904. jpegCompStruct.input_components = 3;
  158905. jpegCompStruct.in_color_space = JCS_RGB;
  158906. jpegCompStruct.write_JFIF_header = 1;
  158907. jpegCompStruct.X_density = 72;
  158908. jpegCompStruct.Y_density = 72;
  158909. jpeg_set_defaults (&jpegCompStruct);
  158910. jpegCompStruct.dct_method = JDCT_FLOAT;
  158911. jpegCompStruct.optimize_coding = 1;
  158912. //jpegCompStruct.smoothing_factor = 10;
  158913. if (quality < 0.0f)
  158914. quality = 0.85f;
  158915. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  158916. jpeg_start_compress (&jpegCompStruct, TRUE);
  158917. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  158918. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  158919. JPOOL_IMAGE, strideBytes, 1);
  158920. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  158921. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  158922. {
  158923. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  158924. uint8* dst = *buffer;
  158925. for (int i = jpegCompStruct.image_width; --i >= 0;)
  158926. {
  158927. *dst++ = ((const PixelRGB*) src)->getRed();
  158928. *dst++ = ((const PixelRGB*) src)->getGreen();
  158929. *dst++ = ((const PixelRGB*) src)->getBlue();
  158930. src += srcData.pixelStride;
  158931. }
  158932. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  158933. }
  158934. jpeg_finish_compress (&jpegCompStruct);
  158935. jpeg_destroy_compress (&jpegCompStruct);
  158936. out.flush();
  158937. return true;
  158938. }
  158939. END_JUCE_NAMESPACE
  158940. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  158941. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  158942. #ifdef _MSC_VER
  158943. #pragma warning (push)
  158944. #pragma warning (disable: 4390 4611)
  158945. #endif
  158946. namespace zlibNamespace
  158947. {
  158948. #if JUCE_INCLUDE_ZLIB_CODE
  158949. #undef OS_CODE
  158950. #undef fdopen
  158951. #undef OS_CODE
  158952. #else
  158953. #include <zlib.h>
  158954. #endif
  158955. }
  158956. namespace pnglibNamespace
  158957. {
  158958. using namespace zlibNamespace;
  158959. #if JUCE_INCLUDE_PNGLIB_CODE
  158960. #if _MSC_VER != 1310
  158961. using ::calloc; // (causes conflict in VS.NET 2003)
  158962. using ::malloc;
  158963. using ::free;
  158964. #endif
  158965. extern "C"
  158966. {
  158967. using ::abs;
  158968. #define PNG_INTERNAL
  158969. #define NO_DUMMY_DECL
  158970. #define PNG_SETJMP_NOT_SUPPORTED
  158971. /*** Start of inlined file: png.h ***/
  158972. #ifndef PNG_H
  158973. #define PNG_H
  158974. #define PNG_LIBPNG_VER_STRING "1.2.21"
  158975. #define PNG_HEADER_VERSION_STRING \
  158976. " libpng version 1.2.21 - October 4, 2007\n"
  158977. #define PNG_LIBPNG_VER_SONUM 0
  158978. #define PNG_LIBPNG_VER_DLLNUM 13
  158979. #define PNG_LIBPNG_VER_MAJOR 1
  158980. #define PNG_LIBPNG_VER_MINOR 2
  158981. #define PNG_LIBPNG_VER_RELEASE 21
  158982. #define PNG_LIBPNG_VER_BUILD 0
  158983. #define PNG_LIBPNG_BUILD_ALPHA 1
  158984. #define PNG_LIBPNG_BUILD_BETA 2
  158985. #define PNG_LIBPNG_BUILD_RC 3
  158986. #define PNG_LIBPNG_BUILD_STABLE 4
  158987. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  158988. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  158989. PNG_LIBPNG_BUILD_STABLE only */
  158990. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  158991. PNG_LIBPNG_BUILD_SPECIAL */
  158992. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  158993. PNG_LIBPNG_BUILD_PRIVATE */
  158994. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  158995. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  158996. #ifndef PNG_VERSION_INFO_ONLY
  158997. #endif
  158998. /*** Start of inlined file: pngconf.h ***/
  158999. #ifndef PNGCONF_H
  159000. #define PNGCONF_H
  159001. #define PNG_1_2_X
  159002. // These are some Juce config settings that should remove any unnecessary code bloat..
  159003. #define PNG_NO_STDIO 1
  159004. #define PNG_DEBUG 0
  159005. #define PNG_NO_WARNINGS 1
  159006. #define PNG_NO_ERROR_TEXT 1
  159007. #define PNG_NO_ERROR_NUMBERS 1
  159008. #define PNG_NO_USER_MEM 1
  159009. #define PNG_NO_READ_iCCP 1
  159010. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159011. #define PNG_NO_READ_USER_CHUNKS 1
  159012. #define PNG_NO_READ_iTXt 1
  159013. #define PNG_NO_READ_sCAL 1
  159014. #define PNG_NO_READ_sPLT 1
  159015. #define png_error(a, b) png_err(a)
  159016. #define png_warning(a, b)
  159017. #define png_chunk_error(a, b) png_err(a)
  159018. #define png_chunk_warning(a, b)
  159019. #ifdef PNG_USER_CONFIG
  159020. # ifndef PNG_USER_PRIVATEBUILD
  159021. # define PNG_USER_PRIVATEBUILD
  159022. # endif
  159023. #include "pngusr.h"
  159024. #endif
  159025. #ifdef PNG_CONFIGURE_LIBPNG
  159026. #ifdef HAVE_CONFIG_H
  159027. #include "config.h"
  159028. #endif
  159029. #endif
  159030. #ifdef __STDC__
  159031. #ifdef SPECIALBUILD
  159032. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159033. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159034. #endif
  159035. #ifdef PRIVATEBUILD
  159036. # pragma message("PRIVATEBUILD is deprecated.\
  159037. Use PNG_USER_PRIVATEBUILD instead.")
  159038. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159039. #endif
  159040. #endif /* __STDC__ */
  159041. #ifndef PNG_VERSION_INFO_ONLY
  159042. # define PNG_WARN_UNINITIALIZED_ROW 1
  159043. #ifndef PNG_ZBUF_SIZE
  159044. # define PNG_ZBUF_SIZE 8192
  159045. #endif
  159046. #ifndef PNG_NO_READ_SUPPORTED
  159047. # define PNG_READ_SUPPORTED
  159048. #endif
  159049. #ifndef PNG_NO_WRITE_SUPPORTED
  159050. # define PNG_WRITE_SUPPORTED
  159051. #endif
  159052. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159053. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159054. # define PNG_MNG_FEATURES_SUPPORTED
  159055. # endif
  159056. #endif
  159057. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159058. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159059. # define PNG_FLOATING_POINT_SUPPORTED
  159060. # endif
  159061. #endif
  159062. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159063. # define PNG_MAX_MALLOC_64K
  159064. #endif
  159065. #if defined(__CYGWIN__)
  159066. # if defined(ALL_STATIC)
  159067. # if defined(PNG_BUILD_DLL)
  159068. # undef PNG_BUILD_DLL
  159069. # endif
  159070. # if defined(PNG_USE_DLL)
  159071. # undef PNG_USE_DLL
  159072. # endif
  159073. # if defined(PNG_DLL)
  159074. # undef PNG_DLL
  159075. # endif
  159076. # if !defined(PNG_STATIC)
  159077. # define PNG_STATIC
  159078. # endif
  159079. # else
  159080. # if defined (PNG_BUILD_DLL)
  159081. # if defined(PNG_STATIC)
  159082. # undef PNG_STATIC
  159083. # endif
  159084. # if defined(PNG_USE_DLL)
  159085. # undef PNG_USE_DLL
  159086. # endif
  159087. # if !defined(PNG_DLL)
  159088. # define PNG_DLL
  159089. # endif
  159090. # else
  159091. # if defined(PNG_STATIC)
  159092. # if defined(PNG_USE_DLL)
  159093. # undef PNG_USE_DLL
  159094. # endif
  159095. # if defined(PNG_DLL)
  159096. # undef PNG_DLL
  159097. # endif
  159098. # else
  159099. # if !defined(PNG_USE_DLL)
  159100. # define PNG_USE_DLL
  159101. # endif
  159102. # if !defined(PNG_DLL)
  159103. # define PNG_DLL
  159104. # endif
  159105. # endif
  159106. # endif
  159107. # endif
  159108. #endif
  159109. #if defined(_WIN32_WCE)
  159110. # include <windows.h>
  159111. # define PNG_NO_CONSOLE_IO
  159112. # ifdef PNG_DEBUG
  159113. # undef PNG_DEBUG
  159114. # endif
  159115. #endif
  159116. #ifdef PNG_BUILD_DLL
  159117. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159118. # ifndef PNG_NO_CONSOLE_IO
  159119. # define PNG_NO_CONSOLE_IO
  159120. # endif
  159121. # endif
  159122. #endif
  159123. # ifdef PNG_NO_STDIO
  159124. # ifndef PNG_NO_CONSOLE_IO
  159125. # define PNG_NO_CONSOLE_IO
  159126. # endif
  159127. # ifdef PNG_DEBUG
  159128. # if (PNG_DEBUG > 0)
  159129. # include <stdio.h>
  159130. # endif
  159131. # endif
  159132. # else
  159133. # if !defined(_WIN32_WCE)
  159134. # include <stdio.h>
  159135. # endif
  159136. # endif
  159137. #ifndef PNGARG
  159138. #ifdef OF /* zlib prototype munger */
  159139. # define PNGARG(arglist) OF(arglist)
  159140. #else
  159141. #ifdef _NO_PROTO
  159142. # define PNGARG(arglist) ()
  159143. # ifndef PNG_TYPECAST_NULL
  159144. # define PNG_TYPECAST_NULL
  159145. # endif
  159146. #else
  159147. # define PNGARG(arglist) arglist
  159148. #endif /* _NO_PROTO */
  159149. #endif /* OF */
  159150. #endif /* PNGARG */
  159151. #ifndef MACOS
  159152. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159153. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159154. # define MACOS
  159155. # endif
  159156. #endif
  159157. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159158. # include <sys/types.h>
  159159. #endif
  159160. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159161. # define PNG_SETJMP_SUPPORTED
  159162. #endif
  159163. #ifdef PNG_SETJMP_SUPPORTED
  159164. # ifdef __linux__
  159165. # ifdef _BSD_SOURCE
  159166. # define PNG_SAVE_BSD_SOURCE
  159167. # undef _BSD_SOURCE
  159168. # endif
  159169. # ifdef _SETJMP_H
  159170. __png.h__ already includes setjmp.h;
  159171. __dont__ include it again.;
  159172. # endif
  159173. # endif /* __linux__ */
  159174. # include <setjmp.h>
  159175. # ifdef __linux__
  159176. # ifdef PNG_SAVE_BSD_SOURCE
  159177. # define _BSD_SOURCE
  159178. # undef PNG_SAVE_BSD_SOURCE
  159179. # endif
  159180. # endif /* __linux__ */
  159181. #endif /* PNG_SETJMP_SUPPORTED */
  159182. #ifdef BSD
  159183. #if ! JUCE_MAC
  159184. # include <strings.h>
  159185. #endif
  159186. #else
  159187. # include <string.h>
  159188. #endif
  159189. #ifdef PNG_INTERNAL
  159190. #include <stdlib.h>
  159191. #define PNG_EXTERN
  159192. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159193. # if defined(MACOS)
  159194. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159195. # include <fp.h>
  159196. # endif
  159197. # else
  159198. # include <math.h>
  159199. # endif
  159200. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159201. # include <m68881.h>
  159202. # endif
  159203. #endif
  159204. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159205. # define PNG_ALWAYS_EXTERN
  159206. #endif
  159207. #if defined(__TURBOC__) && defined(__MSDOS__)
  159208. # include <mem.h>
  159209. # include <alloc.h>
  159210. #endif
  159211. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159212. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159213. # include <malloc.h>
  159214. #endif
  159215. #ifndef PNG_DITHER_RED_BITS
  159216. # define PNG_DITHER_RED_BITS 5
  159217. #endif
  159218. #ifndef PNG_DITHER_GREEN_BITS
  159219. # define PNG_DITHER_GREEN_BITS 5
  159220. #endif
  159221. #ifndef PNG_DITHER_BLUE_BITS
  159222. # define PNG_DITHER_BLUE_BITS 5
  159223. #endif
  159224. #ifndef PNG_MAX_GAMMA_8
  159225. # define PNG_MAX_GAMMA_8 11
  159226. #endif
  159227. #ifndef PNG_GAMMA_THRESHOLD
  159228. # define PNG_GAMMA_THRESHOLD 0.05
  159229. #endif
  159230. #endif /* PNG_INTERNAL */
  159231. #ifndef PNG_NO_CONST
  159232. # define PNG_CONST const
  159233. #else
  159234. # define PNG_CONST
  159235. #endif
  159236. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159237. # ifndef PNG_NO_iTXt_SUPPORTED
  159238. # define PNG_NO_iTXt_SUPPORTED
  159239. # endif
  159240. # ifndef PNG_NO_READ_iTXt
  159241. # define PNG_NO_READ_iTXt
  159242. # endif
  159243. # ifndef PNG_NO_WRITE_iTXt
  159244. # define PNG_NO_WRITE_iTXt
  159245. # endif
  159246. #endif
  159247. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159248. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159249. # define PNG_READ_iTXt
  159250. # endif
  159251. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159252. # define PNG_WRITE_iTXt
  159253. # endif
  159254. #endif
  159255. #ifdef PNG_LEGACY_SUPPORTED
  159256. # define PNG_NO_FREE_ME
  159257. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159258. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159259. # define PNG_NO_READ_USER_CHUNKS
  159260. # define PNG_NO_READ_iCCP
  159261. # define PNG_NO_WRITE_iCCP
  159262. # define PNG_NO_READ_iTXt
  159263. # define PNG_NO_WRITE_iTXt
  159264. # define PNG_NO_READ_sCAL
  159265. # define PNG_NO_WRITE_sCAL
  159266. # define PNG_NO_READ_sPLT
  159267. # define PNG_NO_WRITE_sPLT
  159268. # define PNG_NO_INFO_IMAGE
  159269. # define PNG_NO_READ_RGB_TO_GRAY
  159270. # define PNG_NO_READ_USER_TRANSFORM
  159271. # define PNG_NO_WRITE_USER_TRANSFORM
  159272. # define PNG_NO_USER_MEM
  159273. # define PNG_NO_READ_EMPTY_PLTE
  159274. # define PNG_NO_MNG_FEATURES
  159275. # define PNG_NO_FIXED_POINT_SUPPORTED
  159276. #endif
  159277. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159278. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159279. # define PNG_FIXED_POINT_SUPPORTED
  159280. #endif
  159281. #ifndef PNG_NO_FREE_ME
  159282. # define PNG_FREE_ME_SUPPORTED
  159283. #endif
  159284. #if defined(PNG_READ_SUPPORTED)
  159285. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159286. !defined(PNG_NO_READ_TRANSFORMS)
  159287. # define PNG_READ_TRANSFORMS_SUPPORTED
  159288. #endif
  159289. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159290. # ifndef PNG_NO_READ_EXPAND
  159291. # define PNG_READ_EXPAND_SUPPORTED
  159292. # endif
  159293. # ifndef PNG_NO_READ_SHIFT
  159294. # define PNG_READ_SHIFT_SUPPORTED
  159295. # endif
  159296. # ifndef PNG_NO_READ_PACK
  159297. # define PNG_READ_PACK_SUPPORTED
  159298. # endif
  159299. # ifndef PNG_NO_READ_BGR
  159300. # define PNG_READ_BGR_SUPPORTED
  159301. # endif
  159302. # ifndef PNG_NO_READ_SWAP
  159303. # define PNG_READ_SWAP_SUPPORTED
  159304. # endif
  159305. # ifndef PNG_NO_READ_PACKSWAP
  159306. # define PNG_READ_PACKSWAP_SUPPORTED
  159307. # endif
  159308. # ifndef PNG_NO_READ_INVERT
  159309. # define PNG_READ_INVERT_SUPPORTED
  159310. # endif
  159311. # ifndef PNG_NO_READ_DITHER
  159312. # define PNG_READ_DITHER_SUPPORTED
  159313. # endif
  159314. # ifndef PNG_NO_READ_BACKGROUND
  159315. # define PNG_READ_BACKGROUND_SUPPORTED
  159316. # endif
  159317. # ifndef PNG_NO_READ_16_TO_8
  159318. # define PNG_READ_16_TO_8_SUPPORTED
  159319. # endif
  159320. # ifndef PNG_NO_READ_FILLER
  159321. # define PNG_READ_FILLER_SUPPORTED
  159322. # endif
  159323. # ifndef PNG_NO_READ_GAMMA
  159324. # define PNG_READ_GAMMA_SUPPORTED
  159325. # endif
  159326. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159327. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159328. # endif
  159329. # ifndef PNG_NO_READ_SWAP_ALPHA
  159330. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159331. # endif
  159332. # ifndef PNG_NO_READ_INVERT_ALPHA
  159333. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159334. # endif
  159335. # ifndef PNG_NO_READ_STRIP_ALPHA
  159336. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159337. # endif
  159338. # ifndef PNG_NO_READ_USER_TRANSFORM
  159339. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159340. # endif
  159341. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159342. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159343. # endif
  159344. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159345. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159346. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159347. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159348. #endif /* about interlacing capability! You'll */
  159349. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159350. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159351. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159352. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159353. # endif
  159354. #endif
  159355. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159356. #ifndef PNG_NO_READ_EMPTY_PLTE
  159357. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159358. #endif
  159359. #endif
  159360. #endif /* PNG_READ_SUPPORTED */
  159361. #if defined(PNG_WRITE_SUPPORTED)
  159362. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159363. !defined(PNG_NO_WRITE_TRANSFORMS)
  159364. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159365. #endif
  159366. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159367. # ifndef PNG_NO_WRITE_SHIFT
  159368. # define PNG_WRITE_SHIFT_SUPPORTED
  159369. # endif
  159370. # ifndef PNG_NO_WRITE_PACK
  159371. # define PNG_WRITE_PACK_SUPPORTED
  159372. # endif
  159373. # ifndef PNG_NO_WRITE_BGR
  159374. # define PNG_WRITE_BGR_SUPPORTED
  159375. # endif
  159376. # ifndef PNG_NO_WRITE_SWAP
  159377. # define PNG_WRITE_SWAP_SUPPORTED
  159378. # endif
  159379. # ifndef PNG_NO_WRITE_PACKSWAP
  159380. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159381. # endif
  159382. # ifndef PNG_NO_WRITE_INVERT
  159383. # define PNG_WRITE_INVERT_SUPPORTED
  159384. # endif
  159385. # ifndef PNG_NO_WRITE_FILLER
  159386. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159387. # endif
  159388. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159389. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159390. # endif
  159391. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159392. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159393. # endif
  159394. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159395. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159396. # endif
  159397. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159398. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159399. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159400. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159401. encoders, but can cause trouble
  159402. if left undefined */
  159403. #endif
  159404. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159405. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159406. defined(PNG_FLOATING_POINT_SUPPORTED)
  159407. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159408. #endif
  159409. #ifndef PNG_NO_WRITE_FLUSH
  159410. # define PNG_WRITE_FLUSH_SUPPORTED
  159411. #endif
  159412. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159413. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159414. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159415. #endif
  159416. #endif
  159417. #endif /* PNG_WRITE_SUPPORTED */
  159418. #ifndef PNG_1_0_X
  159419. # ifndef PNG_NO_ERROR_NUMBERS
  159420. # define PNG_ERROR_NUMBERS_SUPPORTED
  159421. # endif
  159422. #endif /* PNG_1_0_X */
  159423. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159424. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159425. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159426. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159427. # endif
  159428. #endif
  159429. #ifndef PNG_NO_STDIO
  159430. # define PNG_TIME_RFC1123_SUPPORTED
  159431. #endif
  159432. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159433. # define PNG_EASY_ACCESS_SUPPORTED
  159434. #endif
  159435. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159436. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159437. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159438. # endif
  159439. #endif
  159440. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159441. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159442. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159443. # endif
  159444. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159445. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159446. # define PNG_NO_MMX_CODE
  159447. # endif
  159448. # endif
  159449. # if defined(__APPLE__)
  159450. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159451. # define PNG_NO_MMX_CODE
  159452. # endif
  159453. # endif
  159454. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159455. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159456. # define PNG_NO_MMX_CODE
  159457. # endif
  159458. # endif
  159459. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159460. # define PNG_MMX_CODE_SUPPORTED
  159461. # endif
  159462. #endif
  159463. #if !defined(PNG_1_0_X)
  159464. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159465. # define PNG_USER_MEM_SUPPORTED
  159466. #endif
  159467. #endif /* PNG_1_0_X */
  159468. #if !defined(PNG_1_0_X)
  159469. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159470. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159471. # define PNG_SET_USER_LIMITS_SUPPORTED
  159472. #endif
  159473. #endif
  159474. #endif /* PNG_1_0_X */
  159475. #ifndef PNG_USER_WIDTH_MAX
  159476. # define PNG_USER_WIDTH_MAX 1000000L
  159477. #endif
  159478. #ifndef PNG_USER_HEIGHT_MAX
  159479. # define PNG_USER_HEIGHT_MAX 1000000L
  159480. #endif
  159481. #if defined(PNG_READ_SUPPORTED) && \
  159482. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159483. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159484. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159485. #endif
  159486. #if defined(PNG_WRITE_SUPPORTED) && \
  159487. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159488. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159489. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159490. #endif
  159491. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159492. #ifdef PNG_NO_READ_TEXT
  159493. # define PNG_NO_READ_iTXt
  159494. # define PNG_NO_READ_tEXt
  159495. # define PNG_NO_READ_zTXt
  159496. #endif
  159497. #ifndef PNG_NO_READ_bKGD
  159498. # define PNG_READ_bKGD_SUPPORTED
  159499. # define PNG_bKGD_SUPPORTED
  159500. #endif
  159501. #ifndef PNG_NO_READ_cHRM
  159502. # define PNG_READ_cHRM_SUPPORTED
  159503. # define PNG_cHRM_SUPPORTED
  159504. #endif
  159505. #ifndef PNG_NO_READ_gAMA
  159506. # define PNG_READ_gAMA_SUPPORTED
  159507. # define PNG_gAMA_SUPPORTED
  159508. #endif
  159509. #ifndef PNG_NO_READ_hIST
  159510. # define PNG_READ_hIST_SUPPORTED
  159511. # define PNG_hIST_SUPPORTED
  159512. #endif
  159513. #ifndef PNG_NO_READ_iCCP
  159514. # define PNG_READ_iCCP_SUPPORTED
  159515. # define PNG_iCCP_SUPPORTED
  159516. #endif
  159517. #ifndef PNG_NO_READ_iTXt
  159518. # ifndef PNG_READ_iTXt_SUPPORTED
  159519. # define PNG_READ_iTXt_SUPPORTED
  159520. # endif
  159521. # ifndef PNG_iTXt_SUPPORTED
  159522. # define PNG_iTXt_SUPPORTED
  159523. # endif
  159524. #endif
  159525. #ifndef PNG_NO_READ_oFFs
  159526. # define PNG_READ_oFFs_SUPPORTED
  159527. # define PNG_oFFs_SUPPORTED
  159528. #endif
  159529. #ifndef PNG_NO_READ_pCAL
  159530. # define PNG_READ_pCAL_SUPPORTED
  159531. # define PNG_pCAL_SUPPORTED
  159532. #endif
  159533. #ifndef PNG_NO_READ_sCAL
  159534. # define PNG_READ_sCAL_SUPPORTED
  159535. # define PNG_sCAL_SUPPORTED
  159536. #endif
  159537. #ifndef PNG_NO_READ_pHYs
  159538. # define PNG_READ_pHYs_SUPPORTED
  159539. # define PNG_pHYs_SUPPORTED
  159540. #endif
  159541. #ifndef PNG_NO_READ_sBIT
  159542. # define PNG_READ_sBIT_SUPPORTED
  159543. # define PNG_sBIT_SUPPORTED
  159544. #endif
  159545. #ifndef PNG_NO_READ_sPLT
  159546. # define PNG_READ_sPLT_SUPPORTED
  159547. # define PNG_sPLT_SUPPORTED
  159548. #endif
  159549. #ifndef PNG_NO_READ_sRGB
  159550. # define PNG_READ_sRGB_SUPPORTED
  159551. # define PNG_sRGB_SUPPORTED
  159552. #endif
  159553. #ifndef PNG_NO_READ_tEXt
  159554. # define PNG_READ_tEXt_SUPPORTED
  159555. # define PNG_tEXt_SUPPORTED
  159556. #endif
  159557. #ifndef PNG_NO_READ_tIME
  159558. # define PNG_READ_tIME_SUPPORTED
  159559. # define PNG_tIME_SUPPORTED
  159560. #endif
  159561. #ifndef PNG_NO_READ_tRNS
  159562. # define PNG_READ_tRNS_SUPPORTED
  159563. # define PNG_tRNS_SUPPORTED
  159564. #endif
  159565. #ifndef PNG_NO_READ_zTXt
  159566. # define PNG_READ_zTXt_SUPPORTED
  159567. # define PNG_zTXt_SUPPORTED
  159568. #endif
  159569. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  159570. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  159571. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159572. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159573. # endif
  159574. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159575. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159576. # endif
  159577. #endif
  159578. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  159579. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  159580. # define PNG_READ_USER_CHUNKS_SUPPORTED
  159581. # define PNG_USER_CHUNKS_SUPPORTED
  159582. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  159583. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  159584. # endif
  159585. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  159586. # undef PNG_NO_HANDLE_AS_UNKNOWN
  159587. # endif
  159588. #endif
  159589. #ifndef PNG_NO_READ_OPT_PLTE
  159590. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  159591. #endif /* optional PLTE chunk in RGB and RGBA images */
  159592. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  159593. defined(PNG_READ_zTXt_SUPPORTED)
  159594. # define PNG_READ_TEXT_SUPPORTED
  159595. # define PNG_TEXT_SUPPORTED
  159596. #endif
  159597. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  159598. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159599. #ifdef PNG_NO_WRITE_TEXT
  159600. # define PNG_NO_WRITE_iTXt
  159601. # define PNG_NO_WRITE_tEXt
  159602. # define PNG_NO_WRITE_zTXt
  159603. #endif
  159604. #ifndef PNG_NO_WRITE_bKGD
  159605. # define PNG_WRITE_bKGD_SUPPORTED
  159606. # ifndef PNG_bKGD_SUPPORTED
  159607. # define PNG_bKGD_SUPPORTED
  159608. # endif
  159609. #endif
  159610. #ifndef PNG_NO_WRITE_cHRM
  159611. # define PNG_WRITE_cHRM_SUPPORTED
  159612. # ifndef PNG_cHRM_SUPPORTED
  159613. # define PNG_cHRM_SUPPORTED
  159614. # endif
  159615. #endif
  159616. #ifndef PNG_NO_WRITE_gAMA
  159617. # define PNG_WRITE_gAMA_SUPPORTED
  159618. # ifndef PNG_gAMA_SUPPORTED
  159619. # define PNG_gAMA_SUPPORTED
  159620. # endif
  159621. #endif
  159622. #ifndef PNG_NO_WRITE_hIST
  159623. # define PNG_WRITE_hIST_SUPPORTED
  159624. # ifndef PNG_hIST_SUPPORTED
  159625. # define PNG_hIST_SUPPORTED
  159626. # endif
  159627. #endif
  159628. #ifndef PNG_NO_WRITE_iCCP
  159629. # define PNG_WRITE_iCCP_SUPPORTED
  159630. # ifndef PNG_iCCP_SUPPORTED
  159631. # define PNG_iCCP_SUPPORTED
  159632. # endif
  159633. #endif
  159634. #ifndef PNG_NO_WRITE_iTXt
  159635. # ifndef PNG_WRITE_iTXt_SUPPORTED
  159636. # define PNG_WRITE_iTXt_SUPPORTED
  159637. # endif
  159638. # ifndef PNG_iTXt_SUPPORTED
  159639. # define PNG_iTXt_SUPPORTED
  159640. # endif
  159641. #endif
  159642. #ifndef PNG_NO_WRITE_oFFs
  159643. # define PNG_WRITE_oFFs_SUPPORTED
  159644. # ifndef PNG_oFFs_SUPPORTED
  159645. # define PNG_oFFs_SUPPORTED
  159646. # endif
  159647. #endif
  159648. #ifndef PNG_NO_WRITE_pCAL
  159649. # define PNG_WRITE_pCAL_SUPPORTED
  159650. # ifndef PNG_pCAL_SUPPORTED
  159651. # define PNG_pCAL_SUPPORTED
  159652. # endif
  159653. #endif
  159654. #ifndef PNG_NO_WRITE_sCAL
  159655. # define PNG_WRITE_sCAL_SUPPORTED
  159656. # ifndef PNG_sCAL_SUPPORTED
  159657. # define PNG_sCAL_SUPPORTED
  159658. # endif
  159659. #endif
  159660. #ifndef PNG_NO_WRITE_pHYs
  159661. # define PNG_WRITE_pHYs_SUPPORTED
  159662. # ifndef PNG_pHYs_SUPPORTED
  159663. # define PNG_pHYs_SUPPORTED
  159664. # endif
  159665. #endif
  159666. #ifndef PNG_NO_WRITE_sBIT
  159667. # define PNG_WRITE_sBIT_SUPPORTED
  159668. # ifndef PNG_sBIT_SUPPORTED
  159669. # define PNG_sBIT_SUPPORTED
  159670. # endif
  159671. #endif
  159672. #ifndef PNG_NO_WRITE_sPLT
  159673. # define PNG_WRITE_sPLT_SUPPORTED
  159674. # ifndef PNG_sPLT_SUPPORTED
  159675. # define PNG_sPLT_SUPPORTED
  159676. # endif
  159677. #endif
  159678. #ifndef PNG_NO_WRITE_sRGB
  159679. # define PNG_WRITE_sRGB_SUPPORTED
  159680. # ifndef PNG_sRGB_SUPPORTED
  159681. # define PNG_sRGB_SUPPORTED
  159682. # endif
  159683. #endif
  159684. #ifndef PNG_NO_WRITE_tEXt
  159685. # define PNG_WRITE_tEXt_SUPPORTED
  159686. # ifndef PNG_tEXt_SUPPORTED
  159687. # define PNG_tEXt_SUPPORTED
  159688. # endif
  159689. #endif
  159690. #ifndef PNG_NO_WRITE_tIME
  159691. # define PNG_WRITE_tIME_SUPPORTED
  159692. # ifndef PNG_tIME_SUPPORTED
  159693. # define PNG_tIME_SUPPORTED
  159694. # endif
  159695. #endif
  159696. #ifndef PNG_NO_WRITE_tRNS
  159697. # define PNG_WRITE_tRNS_SUPPORTED
  159698. # ifndef PNG_tRNS_SUPPORTED
  159699. # define PNG_tRNS_SUPPORTED
  159700. # endif
  159701. #endif
  159702. #ifndef PNG_NO_WRITE_zTXt
  159703. # define PNG_WRITE_zTXt_SUPPORTED
  159704. # ifndef PNG_zTXt_SUPPORTED
  159705. # define PNG_zTXt_SUPPORTED
  159706. # endif
  159707. #endif
  159708. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  159709. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  159710. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  159711. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  159712. # endif
  159713. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  159714. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159715. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  159716. # endif
  159717. # endif
  159718. #endif
  159719. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  159720. defined(PNG_WRITE_zTXt_SUPPORTED)
  159721. # define PNG_WRITE_TEXT_SUPPORTED
  159722. # ifndef PNG_TEXT_SUPPORTED
  159723. # define PNG_TEXT_SUPPORTED
  159724. # endif
  159725. #endif
  159726. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  159727. #ifndef PNG_NO_INFO_IMAGE
  159728. # define PNG_INFO_IMAGE_SUPPORTED
  159729. #endif
  159730. #if defined(PNG_tIME_SUPPORTED)
  159731. # if !defined(_WIN32_WCE)
  159732. # include <time.h>
  159733. # endif
  159734. #endif
  159735. typedef unsigned long png_uint_32;
  159736. typedef long png_int_32;
  159737. typedef unsigned short png_uint_16;
  159738. typedef short png_int_16;
  159739. typedef unsigned char png_byte;
  159740. #ifdef PNG_SIZE_T
  159741. typedef PNG_SIZE_T png_size_t;
  159742. # define png_sizeof(x) png_convert_size(sizeof (x))
  159743. #else
  159744. typedef size_t png_size_t;
  159745. # define png_sizeof(x) sizeof (x)
  159746. #endif
  159747. #ifdef __BORLANDC__
  159748. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  159749. # define LDATA 1
  159750. # else
  159751. # define LDATA 0
  159752. # endif
  159753. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  159754. # define PNG_MAX_MALLOC_64K
  159755. # if (LDATA != 1)
  159756. # ifndef FAR
  159757. # define FAR __far
  159758. # endif
  159759. # define USE_FAR_KEYWORD
  159760. # endif /* LDATA != 1 */
  159761. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  159762. #endif /* __BORLANDC__ */
  159763. #if defined(FAR)
  159764. # if defined(M_I86MM)
  159765. # define USE_FAR_KEYWORD
  159766. # define FARDATA FAR
  159767. # include <dos.h>
  159768. # endif
  159769. #endif
  159770. #ifndef FAR
  159771. # define FAR
  159772. #endif
  159773. #ifndef FARDATA
  159774. # define FARDATA
  159775. #endif
  159776. typedef png_int_32 png_fixed_point;
  159777. typedef void FAR * png_voidp;
  159778. typedef png_byte FAR * png_bytep;
  159779. typedef png_uint_32 FAR * png_uint_32p;
  159780. typedef png_int_32 FAR * png_int_32p;
  159781. typedef png_uint_16 FAR * png_uint_16p;
  159782. typedef png_int_16 FAR * png_int_16p;
  159783. typedef PNG_CONST char FAR * png_const_charp;
  159784. typedef char FAR * png_charp;
  159785. typedef png_fixed_point FAR * png_fixed_point_p;
  159786. #ifndef PNG_NO_STDIO
  159787. #if defined(_WIN32_WCE)
  159788. typedef HANDLE png_FILE_p;
  159789. #else
  159790. typedef FILE * png_FILE_p;
  159791. #endif
  159792. #endif
  159793. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159794. typedef double FAR * png_doublep;
  159795. #endif
  159796. typedef png_byte FAR * FAR * png_bytepp;
  159797. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  159798. typedef png_int_32 FAR * FAR * png_int_32pp;
  159799. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  159800. typedef png_int_16 FAR * FAR * png_int_16pp;
  159801. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  159802. typedef char FAR * FAR * png_charpp;
  159803. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  159804. #ifdef PNG_FLOATING_POINT_SUPPORTED
  159805. typedef double FAR * FAR * png_doublepp;
  159806. #endif
  159807. typedef char FAR * FAR * FAR * png_charppp;
  159808. #if 0
  159809. typedef charf * png_zcharp;
  159810. typedef charf * FAR * png_zcharpp;
  159811. typedef z_stream FAR * png_zstreamp;
  159812. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  159813. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  159814. # define PNG_DLL
  159815. #endif
  159816. #if defined(__CYGWIN__)
  159817. # if !defined(PNG_STATIC)
  159818. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159819. # undef PNG_USE_GLOBAL_ARRAYS
  159820. # endif
  159821. # if !defined(PNG_USE_LOCAL_ARRAYS)
  159822. # define PNG_USE_LOCAL_ARRAYS
  159823. # endif
  159824. # else
  159825. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  159826. # if defined(PNG_USE_GLOBAL_ARRAYS)
  159827. # undef PNG_USE_GLOBAL_ARRAYS
  159828. # endif
  159829. # endif
  159830. # endif
  159831. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159832. # define PNG_USE_LOCAL_ARRAYS
  159833. # endif
  159834. #endif
  159835. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  159836. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  159837. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  159838. # define PNG_USE_LOCAL_ARRAYS
  159839. # else
  159840. # define PNG_USE_GLOBAL_ARRAYS
  159841. # endif
  159842. #endif
  159843. #if defined(__CYGWIN__)
  159844. # undef PNGAPI
  159845. # define PNGAPI __cdecl
  159846. # undef PNG_IMPEXP
  159847. # define PNG_IMPEXP
  159848. #endif
  159849. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  159850. # ifndef PNG_NO_MODULEDEF
  159851. # define PNG_NO_MODULEDEF
  159852. # endif
  159853. #endif
  159854. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  159855. # define PNG_IMPEXP
  159856. #endif
  159857. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  159858. (( defined(_Windows) || defined(_WINDOWS) || \
  159859. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  159860. # ifndef PNGAPI
  159861. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  159862. # define PNGAPI __cdecl
  159863. # else
  159864. # define PNGAPI _cdecl
  159865. # endif
  159866. # endif
  159867. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  159868. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  159869. # define PNG_IMPEXP
  159870. # endif
  159871. # if !defined(PNG_IMPEXP)
  159872. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159873. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  159874. # if defined(_MSC_VER) || defined(__BORLANDC__)
  159875. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  159876. # define PNG_EXPORT PNG_EXPORT_TYPE1
  159877. # else
  159878. # define PNG_EXPORT PNG_EXPORT_TYPE2
  159879. # if defined(PNG_BUILD_DLL)
  159880. # define PNG_IMPEXP __export
  159881. # else
  159882. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  159883. VC++ */
  159884. # endif /* Exists in Borland C++ for
  159885. C++ classes (== huge) */
  159886. # endif
  159887. # endif
  159888. # if !defined(PNG_IMPEXP)
  159889. # if defined(PNG_BUILD_DLL)
  159890. # define PNG_IMPEXP __declspec(dllexport)
  159891. # else
  159892. # define PNG_IMPEXP __declspec(dllimport)
  159893. # endif
  159894. # endif
  159895. # endif /* PNG_IMPEXP */
  159896. #else /* !(DLL || non-cygwin WINDOWS) */
  159897. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  159898. # ifndef PNGAPI
  159899. # define PNGAPI _System
  159900. # endif
  159901. # else
  159902. # if 0 /* ... other platforms, with other meanings */
  159903. # endif
  159904. # endif
  159905. #endif
  159906. #ifndef PNGAPI
  159907. # define PNGAPI
  159908. #endif
  159909. #ifndef PNG_IMPEXP
  159910. # define PNG_IMPEXP
  159911. #endif
  159912. #ifdef PNG_BUILDSYMS
  159913. # ifndef PNG_EXPORT
  159914. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  159915. # endif
  159916. # ifdef PNG_USE_GLOBAL_ARRAYS
  159917. # ifndef PNG_EXPORT_VAR
  159918. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  159919. # endif
  159920. # endif
  159921. #endif
  159922. #ifndef PNG_EXPORT
  159923. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  159924. #endif
  159925. #ifdef PNG_USE_GLOBAL_ARRAYS
  159926. # ifndef PNG_EXPORT_VAR
  159927. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  159928. # endif
  159929. #endif
  159930. #ifndef PNG_ABORT
  159931. # define PNG_ABORT() abort()
  159932. #endif
  159933. #ifdef PNG_SETJMP_SUPPORTED
  159934. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  159935. #else
  159936. # define png_jmpbuf(png_ptr) \
  159937. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  159938. #endif
  159939. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  159940. # define CHECK 1
  159941. # define NOCHECK 0
  159942. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  159943. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  159944. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  159945. # define png_strcpy _fstrcpy
  159946. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  159947. # define png_strlen _fstrlen
  159948. # define png_memcmp _fmemcmp /* SJT: added */
  159949. # define png_memcpy _fmemcpy
  159950. # define png_memset _fmemset
  159951. #else /* use the usual functions */
  159952. # define CVT_PTR(ptr) (ptr)
  159953. # define CVT_PTR_NOCHECK(ptr) (ptr)
  159954. # ifndef PNG_NO_SNPRINTF
  159955. # ifdef _MSC_VER
  159956. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  159957. # define png_snprintf2 _snprintf
  159958. # define png_snprintf6 _snprintf
  159959. # else
  159960. # define png_snprintf snprintf /* Added to v 1.2.19 */
  159961. # define png_snprintf2 snprintf
  159962. # define png_snprintf6 snprintf
  159963. # endif
  159964. # else
  159965. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  159966. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  159967. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  159968. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  159969. # endif
  159970. # define png_strcpy strcpy
  159971. # define png_strncpy strncpy /* Added to v 1.2.6 */
  159972. # define png_strlen strlen
  159973. # define png_memcmp memcmp /* SJT: added */
  159974. # define png_memcpy memcpy
  159975. # define png_memset memset
  159976. #endif
  159977. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  159978. # undef PNG_ZBUF_SIZE
  159979. # define PNG_ZBUF_SIZE 65536L
  159980. #endif
  159981. #endif /* PNG_VERSION_INFO_ONLY */
  159982. #endif /* PNGCONF_H */
  159983. /*** End of inlined file: pngconf.h ***/
  159984. #ifdef _MSC_VER
  159985. #pragma warning (disable: 4996 4100)
  159986. #endif
  159987. #if defined(PNG_USER_PRIVATEBUILD)
  159988. # define PNG_LIBPNG_BUILD_TYPE \
  159989. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  159990. #else
  159991. # if defined(PNG_LIBPNG_SPECIALBUILD)
  159992. # define PNG_LIBPNG_BUILD_TYPE \
  159993. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  159994. # else
  159995. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  159996. # endif
  159997. #endif
  159998. #ifndef PNG_VERSION_INFO_ONLY
  159999. #ifdef __cplusplus
  160000. extern "C" {
  160001. #endif /* __cplusplus */
  160002. #ifndef PNG_NO_TYPECAST_NULL
  160003. #define int_p_NULL (int *)NULL
  160004. #define png_bytep_NULL (png_bytep)NULL
  160005. #define png_bytepp_NULL (png_bytepp)NULL
  160006. #define png_doublep_NULL (png_doublep)NULL
  160007. #define png_error_ptr_NULL (png_error_ptr)NULL
  160008. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160009. #define png_free_ptr_NULL (png_free_ptr)NULL
  160010. #define png_infopp_NULL (png_infopp)NULL
  160011. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160012. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160013. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160014. #define png_structp_NULL (png_structp)NULL
  160015. #define png_uint_16p_NULL (png_uint_16p)NULL
  160016. #define png_voidp_NULL (png_voidp)NULL
  160017. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160018. #else
  160019. #define int_p_NULL NULL
  160020. #define png_bytep_NULL NULL
  160021. #define png_bytepp_NULL NULL
  160022. #define png_doublep_NULL NULL
  160023. #define png_error_ptr_NULL NULL
  160024. #define png_flush_ptr_NULL NULL
  160025. #define png_free_ptr_NULL NULL
  160026. #define png_infopp_NULL NULL
  160027. #define png_malloc_ptr_NULL NULL
  160028. #define png_read_status_ptr_NULL NULL
  160029. #define png_rw_ptr_NULL NULL
  160030. #define png_structp_NULL NULL
  160031. #define png_uint_16p_NULL NULL
  160032. #define png_voidp_NULL NULL
  160033. #define png_write_status_ptr_NULL NULL
  160034. #endif
  160035. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160036. #ifdef PNG_USE_GLOBAL_ARRAYS
  160037. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160038. #else
  160039. #define png_libpng_ver png_get_header_ver(NULL)
  160040. #endif
  160041. #ifdef PNG_USE_GLOBAL_ARRAYS
  160042. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160043. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160044. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160045. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160046. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160047. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160048. #endif
  160049. #endif /* PNG_NO_EXTERN */
  160050. typedef struct png_color_struct
  160051. {
  160052. png_byte red;
  160053. png_byte green;
  160054. png_byte blue;
  160055. } png_color;
  160056. typedef png_color FAR * png_colorp;
  160057. typedef png_color FAR * FAR * png_colorpp;
  160058. typedef struct png_color_16_struct
  160059. {
  160060. png_byte index; /* used for palette files */
  160061. png_uint_16 red; /* for use in red green blue files */
  160062. png_uint_16 green;
  160063. png_uint_16 blue;
  160064. png_uint_16 gray; /* for use in grayscale files */
  160065. } png_color_16;
  160066. typedef png_color_16 FAR * png_color_16p;
  160067. typedef png_color_16 FAR * FAR * png_color_16pp;
  160068. typedef struct png_color_8_struct
  160069. {
  160070. png_byte red; /* for use in red green blue files */
  160071. png_byte green;
  160072. png_byte blue;
  160073. png_byte gray; /* for use in grayscale files */
  160074. png_byte alpha; /* for alpha channel files */
  160075. } png_color_8;
  160076. typedef png_color_8 FAR * png_color_8p;
  160077. typedef png_color_8 FAR * FAR * png_color_8pp;
  160078. typedef struct png_sPLT_entry_struct
  160079. {
  160080. png_uint_16 red;
  160081. png_uint_16 green;
  160082. png_uint_16 blue;
  160083. png_uint_16 alpha;
  160084. png_uint_16 frequency;
  160085. } png_sPLT_entry;
  160086. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160087. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160088. typedef struct png_sPLT_struct
  160089. {
  160090. png_charp name; /* palette name */
  160091. png_byte depth; /* depth of palette samples */
  160092. png_sPLT_entryp entries; /* palette entries */
  160093. png_int_32 nentries; /* number of palette entries */
  160094. } png_sPLT_t;
  160095. typedef png_sPLT_t FAR * png_sPLT_tp;
  160096. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160097. #ifdef PNG_TEXT_SUPPORTED
  160098. typedef struct png_text_struct
  160099. {
  160100. int compression; /* compression value:
  160101. -1: tEXt, none
  160102. 0: zTXt, deflate
  160103. 1: iTXt, none
  160104. 2: iTXt, deflate */
  160105. png_charp key; /* keyword, 1-79 character description of "text" */
  160106. png_charp text; /* comment, may be an empty string (ie "")
  160107. or a NULL pointer */
  160108. png_size_t text_length; /* length of the text string */
  160109. #ifdef PNG_iTXt_SUPPORTED
  160110. png_size_t itxt_length; /* length of the itxt string */
  160111. png_charp lang; /* language code, 0-79 characters
  160112. or a NULL pointer */
  160113. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160114. chars or a NULL pointer */
  160115. #endif
  160116. } png_text;
  160117. typedef png_text FAR * png_textp;
  160118. typedef png_text FAR * FAR * png_textpp;
  160119. #endif
  160120. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160121. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160122. #define PNG_TEXT_COMPRESSION_NONE -1
  160123. #define PNG_TEXT_COMPRESSION_zTXt 0
  160124. #define PNG_ITXT_COMPRESSION_NONE 1
  160125. #define PNG_ITXT_COMPRESSION_zTXt 2
  160126. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160127. typedef struct png_time_struct
  160128. {
  160129. png_uint_16 year; /* full year, as in, 1995 */
  160130. png_byte month; /* month of year, 1 - 12 */
  160131. png_byte day; /* day of month, 1 - 31 */
  160132. png_byte hour; /* hour of day, 0 - 23 */
  160133. png_byte minute; /* minute of hour, 0 - 59 */
  160134. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160135. } png_time;
  160136. typedef png_time FAR * png_timep;
  160137. typedef png_time FAR * FAR * png_timepp;
  160138. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160139. typedef struct png_unknown_chunk_t
  160140. {
  160141. png_byte name[5];
  160142. png_byte *data;
  160143. png_size_t size;
  160144. png_byte location; /* mode of operation at read time */
  160145. }
  160146. png_unknown_chunk;
  160147. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160148. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160149. #endif
  160150. typedef struct png_info_struct
  160151. {
  160152. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160153. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160154. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160155. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160156. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160157. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160158. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160159. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160160. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160161. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160162. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160163. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160164. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160165. png_byte pixel_depth; /* number of bits per pixel */
  160166. png_byte spare_byte; /* to align the data, and for future use */
  160167. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160168. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160169. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160170. #endif
  160171. #if defined(PNG_sRGB_SUPPORTED)
  160172. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160173. #endif
  160174. #if defined(PNG_TEXT_SUPPORTED)
  160175. int num_text; /* number of comments read/to write */
  160176. int max_text; /* current size of text array */
  160177. png_textp text; /* array of comments read/to write */
  160178. #endif /* PNG_TEXT_SUPPORTED */
  160179. #if defined(PNG_tIME_SUPPORTED)
  160180. png_time mod_time;
  160181. #endif
  160182. #if defined(PNG_sBIT_SUPPORTED)
  160183. png_color_8 sig_bit; /* significant bits in color channels */
  160184. #endif
  160185. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160186. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160187. png_bytep trans; /* transparent values for paletted image */
  160188. png_color_16 trans_values; /* transparent color for non-palette image */
  160189. #endif
  160190. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160191. png_color_16 background;
  160192. #endif
  160193. #if defined(PNG_oFFs_SUPPORTED)
  160194. png_int_32 x_offset; /* x offset on page */
  160195. png_int_32 y_offset; /* y offset on page */
  160196. png_byte offset_unit_type; /* offset units type */
  160197. #endif
  160198. #if defined(PNG_pHYs_SUPPORTED)
  160199. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160200. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160201. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160202. #endif
  160203. #if defined(PNG_hIST_SUPPORTED)
  160204. png_uint_16p hist;
  160205. #endif
  160206. #ifdef PNG_cHRM_SUPPORTED
  160207. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160208. float x_white;
  160209. float y_white;
  160210. float x_red;
  160211. float y_red;
  160212. float x_green;
  160213. float y_green;
  160214. float x_blue;
  160215. float y_blue;
  160216. #endif
  160217. #endif
  160218. #if defined(PNG_pCAL_SUPPORTED)
  160219. png_charp pcal_purpose; /* pCAL chunk description string */
  160220. png_int_32 pcal_X0; /* minimum value */
  160221. png_int_32 pcal_X1; /* maximum value */
  160222. png_charp pcal_units; /* Latin-1 string giving physical units */
  160223. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160224. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160225. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160226. #endif
  160227. #ifdef PNG_FREE_ME_SUPPORTED
  160228. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160229. #endif
  160230. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160231. png_unknown_chunkp unknown_chunks;
  160232. png_size_t unknown_chunks_num;
  160233. #endif
  160234. #if defined(PNG_iCCP_SUPPORTED)
  160235. png_charp iccp_name; /* profile name */
  160236. png_charp iccp_profile; /* International Color Consortium profile data */
  160237. png_uint_32 iccp_proflen; /* ICC profile data length */
  160238. png_byte iccp_compression; /* Always zero */
  160239. #endif
  160240. #if defined(PNG_sPLT_SUPPORTED)
  160241. png_sPLT_tp splt_palettes;
  160242. png_uint_32 splt_palettes_num;
  160243. #endif
  160244. #if defined(PNG_sCAL_SUPPORTED)
  160245. png_byte scal_unit; /* unit of physical scale */
  160246. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160247. double scal_pixel_width; /* width of one pixel */
  160248. double scal_pixel_height; /* height of one pixel */
  160249. #endif
  160250. #ifdef PNG_FIXED_POINT_SUPPORTED
  160251. png_charp scal_s_width; /* string containing height */
  160252. png_charp scal_s_height; /* string containing width */
  160253. #endif
  160254. #endif
  160255. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160256. png_bytepp row_pointers; /* the image bits */
  160257. #endif
  160258. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160259. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160260. #endif
  160261. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160262. png_fixed_point int_x_white;
  160263. png_fixed_point int_y_white;
  160264. png_fixed_point int_x_red;
  160265. png_fixed_point int_y_red;
  160266. png_fixed_point int_x_green;
  160267. png_fixed_point int_y_green;
  160268. png_fixed_point int_x_blue;
  160269. png_fixed_point int_y_blue;
  160270. #endif
  160271. } png_info;
  160272. typedef png_info FAR * png_infop;
  160273. typedef png_info FAR * FAR * png_infopp;
  160274. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160275. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160276. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160277. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160278. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160279. #endif
  160280. #define PNG_COLOR_MASK_PALETTE 1
  160281. #define PNG_COLOR_MASK_COLOR 2
  160282. #define PNG_COLOR_MASK_ALPHA 4
  160283. #define PNG_COLOR_TYPE_GRAY 0
  160284. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160285. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160286. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160287. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160288. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160289. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160290. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160291. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160292. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160293. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160294. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160295. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160296. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160297. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160298. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160299. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160300. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160301. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160302. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160303. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160304. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160305. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160306. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160307. #define PNG_SCALE_METER 1 /* meters per pixel */
  160308. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160309. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160310. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160311. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160312. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160313. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160314. #define PNG_sRGB_INTENT_RELATIVE 1
  160315. #define PNG_sRGB_INTENT_SATURATION 2
  160316. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160317. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160318. #define PNG_KEYWORD_MAX_LENGTH 79
  160319. #define PNG_MAX_PALETTE_LENGTH 256
  160320. #define PNG_INFO_gAMA 0x0001
  160321. #define PNG_INFO_sBIT 0x0002
  160322. #define PNG_INFO_cHRM 0x0004
  160323. #define PNG_INFO_PLTE 0x0008
  160324. #define PNG_INFO_tRNS 0x0010
  160325. #define PNG_INFO_bKGD 0x0020
  160326. #define PNG_INFO_hIST 0x0040
  160327. #define PNG_INFO_pHYs 0x0080
  160328. #define PNG_INFO_oFFs 0x0100
  160329. #define PNG_INFO_tIME 0x0200
  160330. #define PNG_INFO_pCAL 0x0400
  160331. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160332. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160333. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160334. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160335. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160336. typedef struct png_row_info_struct
  160337. {
  160338. png_uint_32 width; /* width of row */
  160339. png_uint_32 rowbytes; /* number of bytes in row */
  160340. png_byte color_type; /* color type of row */
  160341. png_byte bit_depth; /* bit depth of row */
  160342. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160343. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160344. } png_row_info;
  160345. typedef png_row_info FAR * png_row_infop;
  160346. typedef png_row_info FAR * FAR * png_row_infopp;
  160347. typedef struct png_struct_def png_struct;
  160348. typedef png_struct FAR * png_structp;
  160349. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160350. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160351. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160352. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160353. int));
  160354. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160355. int));
  160356. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160357. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160358. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160359. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160360. png_uint_32, int));
  160361. #endif
  160362. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160363. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160364. defined(PNG_LEGACY_SUPPORTED)
  160365. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160366. png_row_infop, png_bytep));
  160367. #endif
  160368. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160369. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160370. #endif
  160371. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160372. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160373. #endif
  160374. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160375. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160376. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160377. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160378. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160379. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160380. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160381. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160382. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160383. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160384. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160385. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160386. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160387. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160388. #define PNG_FLAG_MNG_FILTER_64 0x04
  160389. #define PNG_ALL_MNG_FEATURES 0x05
  160390. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160391. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160392. struct png_struct_def
  160393. {
  160394. #ifdef PNG_SETJMP_SUPPORTED
  160395. jmp_buf jmpbuf; /* used in png_error */
  160396. #endif
  160397. png_error_ptr error_fn; /* function for printing errors and aborting */
  160398. png_error_ptr warning_fn; /* function for printing warnings */
  160399. png_voidp error_ptr; /* user supplied struct for error functions */
  160400. png_rw_ptr write_data_fn; /* function for writing output data */
  160401. png_rw_ptr read_data_fn; /* function for reading input data */
  160402. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160403. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160404. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160405. #endif
  160406. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160407. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160408. #endif
  160409. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160410. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160411. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160412. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160413. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160414. png_byte user_transform_channels; /* channels in user transformed pixels */
  160415. #endif
  160416. #endif
  160417. png_uint_32 mode; /* tells us where we are in the PNG file */
  160418. png_uint_32 flags; /* flags indicating various things to libpng */
  160419. png_uint_32 transformations; /* which transformations to perform */
  160420. z_stream zstream; /* pointer to decompression structure (below) */
  160421. png_bytep zbuf; /* buffer for zlib */
  160422. png_size_t zbuf_size; /* size of zbuf */
  160423. int zlib_level; /* holds zlib compression level */
  160424. int zlib_method; /* holds zlib compression method */
  160425. int zlib_window_bits; /* holds zlib compression window bits */
  160426. int zlib_mem_level; /* holds zlib compression memory level */
  160427. int zlib_strategy; /* holds zlib compression strategy */
  160428. png_uint_32 width; /* width of image in pixels */
  160429. png_uint_32 height; /* height of image in pixels */
  160430. png_uint_32 num_rows; /* number of rows in current pass */
  160431. png_uint_32 usr_width; /* width of row at start of write */
  160432. png_uint_32 rowbytes; /* size of row in bytes */
  160433. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160434. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160435. png_uint_32 row_number; /* current row in interlace pass */
  160436. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160437. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160438. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160439. png_bytep up_row; /* buffer to save "up" row when filtering */
  160440. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160441. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160442. png_row_info row_info; /* used for transformation routines */
  160443. png_uint_32 idat_size; /* current IDAT size for read */
  160444. png_uint_32 crc; /* current chunk CRC value */
  160445. png_colorp palette; /* palette from the input file */
  160446. png_uint_16 num_palette; /* number of color entries in palette */
  160447. png_uint_16 num_trans; /* number of transparency values */
  160448. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160449. png_byte compression; /* file compression type (always 0) */
  160450. png_byte filter; /* file filter type (always 0) */
  160451. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160452. png_byte pass; /* current interlace pass (0 - 6) */
  160453. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160454. png_byte color_type; /* color type of file */
  160455. png_byte bit_depth; /* bit depth of file */
  160456. png_byte usr_bit_depth; /* bit depth of users row */
  160457. png_byte pixel_depth; /* number of bits per pixel */
  160458. png_byte channels; /* number of channels in file */
  160459. png_byte usr_channels; /* channels at start of write */
  160460. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160461. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160462. #ifdef PNG_LEGACY_SUPPORTED
  160463. png_byte filler; /* filler byte for pixel expansion */
  160464. #else
  160465. png_uint_16 filler; /* filler bytes for pixel expansion */
  160466. #endif
  160467. #endif
  160468. #if defined(PNG_bKGD_SUPPORTED)
  160469. png_byte background_gamma_type;
  160470. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160471. float background_gamma;
  160472. # endif
  160473. png_color_16 background; /* background color in screen gamma space */
  160474. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160475. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160476. #endif
  160477. #endif /* PNG_bKGD_SUPPORTED */
  160478. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160479. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160480. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160481. png_uint_32 flush_rows; /* number of rows written since last flush */
  160482. #endif
  160483. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160484. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160485. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160486. float gamma; /* file gamma value */
  160487. float screen_gamma; /* screen gamma value (display_exponent) */
  160488. #endif
  160489. #endif
  160490. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160491. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160492. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160493. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160494. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160495. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160496. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160497. #endif
  160498. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160499. png_color_8 sig_bit; /* significant bits in each available channel */
  160500. #endif
  160501. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160502. png_color_8 shift; /* shift for significant bit tranformation */
  160503. #endif
  160504. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160505. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160506. png_bytep trans; /* transparency values for paletted files */
  160507. png_color_16 trans_values; /* transparency values for non-paletted files */
  160508. #endif
  160509. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160510. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160511. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160512. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160513. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160514. png_progressive_end_ptr end_fn; /* called after image is complete */
  160515. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160516. png_bytep save_buffer; /* buffer for previously read data */
  160517. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160518. png_bytep current_buffer; /* buffer for recently used data */
  160519. png_uint_32 push_length; /* size of current input chunk */
  160520. png_uint_32 skip_length; /* bytes to skip in input data */
  160521. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  160522. png_size_t save_buffer_max; /* total size of save_buffer */
  160523. png_size_t buffer_size; /* total amount of available input data */
  160524. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  160525. int process_mode; /* what push library is currently doing */
  160526. int cur_palette; /* current push library palette index */
  160527. # if defined(PNG_TEXT_SUPPORTED)
  160528. png_size_t current_text_size; /* current size of text input data */
  160529. png_size_t current_text_left; /* how much text left to read in input */
  160530. png_charp current_text; /* current text chunk buffer */
  160531. png_charp current_text_ptr; /* current location in current_text */
  160532. # endif /* PNG_TEXT_SUPPORTED */
  160533. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160534. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  160535. png_bytepp offset_table_ptr;
  160536. png_bytep offset_table;
  160537. png_uint_16 offset_table_number;
  160538. png_uint_16 offset_table_count;
  160539. png_uint_16 offset_table_count_free;
  160540. #endif
  160541. #if defined(PNG_READ_DITHER_SUPPORTED)
  160542. png_bytep palette_lookup; /* lookup table for dithering */
  160543. png_bytep dither_index; /* index translation for palette files */
  160544. #endif
  160545. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  160546. png_uint_16p hist; /* histogram */
  160547. #endif
  160548. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  160549. png_byte heuristic_method; /* heuristic for row filter selection */
  160550. png_byte num_prev_filters; /* number of weights for previous rows */
  160551. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  160552. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  160553. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  160554. png_uint_16p filter_costs; /* relative filter calculation cost */
  160555. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  160556. #endif
  160557. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160558. png_charp time_buffer; /* String to hold RFC 1123 time text */
  160559. #endif
  160560. #ifdef PNG_FREE_ME_SUPPORTED
  160561. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160562. #endif
  160563. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160564. png_voidp user_chunk_ptr;
  160565. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  160566. #endif
  160567. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160568. int num_chunk_list;
  160569. png_bytep chunk_list;
  160570. #endif
  160571. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160572. png_byte rgb_to_gray_status;
  160573. png_uint_16 rgb_to_gray_red_coeff;
  160574. png_uint_16 rgb_to_gray_green_coeff;
  160575. png_uint_16 rgb_to_gray_blue_coeff;
  160576. #endif
  160577. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  160578. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160579. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160580. #ifdef PNG_1_0_X
  160581. png_byte mng_features_permitted;
  160582. #else
  160583. png_uint_32 mng_features_permitted;
  160584. #endif /* PNG_1_0_X */
  160585. #endif
  160586. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160587. png_fixed_point int_gamma;
  160588. #endif
  160589. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  160590. png_byte filter_type;
  160591. #endif
  160592. #if defined(PNG_1_0_X)
  160593. png_uint_32 row_buf_size;
  160594. #endif
  160595. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  160596. # if !defined(PNG_1_0_X)
  160597. # if defined(PNG_MMX_CODE_SUPPORTED)
  160598. png_byte mmx_bitdepth_threshold;
  160599. png_uint_32 mmx_rowbytes_threshold;
  160600. # endif
  160601. png_uint_32 asm_flags;
  160602. # endif
  160603. #endif
  160604. #ifdef PNG_USER_MEM_SUPPORTED
  160605. png_voidp mem_ptr; /* user supplied struct for mem functions */
  160606. png_malloc_ptr malloc_fn; /* function for allocating memory */
  160607. png_free_ptr free_fn; /* function for freeing memory */
  160608. #endif
  160609. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  160610. #if defined(PNG_READ_DITHER_SUPPORTED)
  160611. png_bytep dither_sort; /* working sort array */
  160612. png_bytep index_to_palette; /* where the original index currently is */
  160613. png_bytep palette_to_index; /* which original index points to this */
  160614. #endif
  160615. png_byte compression_type;
  160616. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  160617. png_uint_32 user_width_max;
  160618. png_uint_32 user_height_max;
  160619. #endif
  160620. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160621. png_unknown_chunk unknown_chunk;
  160622. #endif
  160623. };
  160624. typedef png_structp version_1_2_21;
  160625. typedef png_struct FAR * FAR * png_structpp;
  160626. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  160627. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  160628. int num_bytes));
  160629. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  160630. png_size_t num_to_check));
  160631. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  160632. extern PNG_EXPORT(png_structp,png_create_read_struct)
  160633. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160634. png_error_ptr error_fn, png_error_ptr warn_fn));
  160635. extern PNG_EXPORT(png_structp,png_create_write_struct)
  160636. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160637. png_error_ptr error_fn, png_error_ptr warn_fn));
  160638. #ifdef PNG_WRITE_SUPPORTED
  160639. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  160640. PNGARG((png_structp png_ptr));
  160641. #endif
  160642. #ifdef PNG_WRITE_SUPPORTED
  160643. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  160644. PNGARG((png_structp png_ptr, png_uint_32 size));
  160645. #endif
  160646. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  160647. #ifdef PNG_USER_MEM_SUPPORTED
  160648. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  160649. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160650. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160651. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160652. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  160653. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  160654. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  160655. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160656. #endif
  160657. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  160658. png_bytep chunk_name, png_bytep data, png_size_t length));
  160659. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  160660. png_bytep chunk_name, png_uint_32 length));
  160661. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  160662. png_bytep data, png_size_t length));
  160663. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  160664. extern PNG_EXPORT(png_infop,png_create_info_struct)
  160665. PNGARG((png_structp png_ptr));
  160666. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160667. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  160668. #undef png_info_init
  160669. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  160670. png_sizeof(png_info));
  160671. #endif
  160672. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  160673. png_size_t png_info_struct_size));
  160674. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  160675. png_infop info_ptr));
  160676. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  160677. png_infop info_ptr));
  160678. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160679. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  160680. png_infop info_ptr));
  160681. #endif
  160682. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  160683. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  160684. PNGARG((png_structp png_ptr, png_timep ptime));
  160685. #endif
  160686. #if !defined(_WIN32_WCE)
  160687. #if defined(PNG_WRITE_tIME_SUPPORTED)
  160688. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  160689. struct tm FAR * ttime));
  160690. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  160691. time_t ttime));
  160692. #endif /* PNG_WRITE_tIME_SUPPORTED */
  160693. #endif /* _WIN32_WCE */
  160694. #if defined(PNG_READ_EXPAND_SUPPORTED)
  160695. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  160696. #if !defined(PNG_1_0_X)
  160697. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  160698. png_ptr));
  160699. #endif
  160700. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  160701. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  160702. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160703. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  160704. #endif
  160705. #endif
  160706. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  160707. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  160708. #endif
  160709. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  160710. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  160711. #endif
  160712. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  160713. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160714. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  160715. int error_action, double red, double green ));
  160716. #endif
  160717. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  160718. int error_action, png_fixed_point red, png_fixed_point green ));
  160719. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  160720. png_ptr));
  160721. #endif
  160722. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  160723. png_colorp palette));
  160724. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  160725. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  160726. #endif
  160727. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  160728. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  160729. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  160730. #endif
  160731. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  160732. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  160733. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  160734. #endif
  160735. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160736. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  160737. png_uint_32 filler, int flags));
  160738. #define PNG_FILLER_BEFORE 0
  160739. #define PNG_FILLER_AFTER 1
  160740. #if !defined(PNG_1_0_X)
  160741. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  160742. png_uint_32 filler, int flags));
  160743. #endif
  160744. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  160745. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  160746. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  160747. #endif
  160748. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  160749. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  160750. #endif
  160751. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  160752. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  160753. #endif
  160754. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160755. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  160756. png_color_8p true_bits));
  160757. #endif
  160758. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  160759. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  160760. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  160761. #endif
  160762. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  160763. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  160764. #endif
  160765. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  160766. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160767. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  160768. png_color_16p background_color, int background_gamma_code,
  160769. int need_expand, double background_gamma));
  160770. #endif
  160771. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  160772. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  160773. #define PNG_BACKGROUND_GAMMA_FILE 2
  160774. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  160775. #endif
  160776. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  160777. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  160778. #endif
  160779. #if defined(PNG_READ_DITHER_SUPPORTED)
  160780. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  160781. png_colorp palette, int num_palette, int maximum_colors,
  160782. png_uint_16p histogram, int full_dither));
  160783. #endif
  160784. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160785. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160786. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  160787. double screen_gamma, double default_file_gamma));
  160788. #endif
  160789. #endif
  160790. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160791. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  160792. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  160793. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  160794. int empty_plte_permitted));
  160795. #endif
  160796. #endif
  160797. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160798. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  160799. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  160800. #endif
  160801. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  160802. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  160803. png_infop info_ptr));
  160804. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160805. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  160806. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  160807. #endif
  160808. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160809. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  160810. png_bytep row,
  160811. png_bytep display_row));
  160812. #endif
  160813. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160814. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  160815. png_bytepp image));
  160816. #endif
  160817. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  160818. png_bytep row));
  160819. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  160820. png_bytepp row, png_uint_32 num_rows));
  160821. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  160822. png_bytepp image));
  160823. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  160824. png_infop info_ptr));
  160825. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  160826. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  160827. png_infop info_ptr));
  160828. #endif
  160829. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  160830. png_infopp info_ptr_ptr));
  160831. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  160832. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  160833. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  160834. png_infop end_info_ptr));
  160835. extern PNG_EXPORT(void,png_destroy_write_struct)
  160836. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  160837. extern void png_write_destroy PNGARG((png_structp png_ptr));
  160838. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  160839. int crit_action, int ancil_action));
  160840. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  160841. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  160842. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  160843. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  160844. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  160845. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  160846. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  160847. int filters));
  160848. #define PNG_NO_FILTERS 0x00
  160849. #define PNG_FILTER_NONE 0x08
  160850. #define PNG_FILTER_SUB 0x10
  160851. #define PNG_FILTER_UP 0x20
  160852. #define PNG_FILTER_AVG 0x40
  160853. #define PNG_FILTER_PAETH 0x80
  160854. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  160855. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  160856. #define PNG_FILTER_VALUE_NONE 0
  160857. #define PNG_FILTER_VALUE_SUB 1
  160858. #define PNG_FILTER_VALUE_UP 2
  160859. #define PNG_FILTER_VALUE_AVG 3
  160860. #define PNG_FILTER_VALUE_PAETH 4
  160861. #define PNG_FILTER_VALUE_LAST 5
  160862. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  160863. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160864. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  160865. int heuristic_method, int num_weights, png_doublep filter_weights,
  160866. png_doublep filter_costs));
  160867. #endif
  160868. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  160869. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  160870. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  160871. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  160872. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  160873. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  160874. int level));
  160875. extern PNG_EXPORT(void,png_set_compression_mem_level)
  160876. PNGARG((png_structp png_ptr, int mem_level));
  160877. extern PNG_EXPORT(void,png_set_compression_strategy)
  160878. PNGARG((png_structp png_ptr, int strategy));
  160879. extern PNG_EXPORT(void,png_set_compression_window_bits)
  160880. PNGARG((png_structp png_ptr, int window_bits));
  160881. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  160882. int method));
  160883. #if !defined(PNG_NO_STDIO)
  160884. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  160885. #endif
  160886. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  160887. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  160888. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  160889. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  160890. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  160891. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  160892. png_voidp io_ptr, png_rw_ptr read_data_fn));
  160893. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  160894. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  160895. png_read_status_ptr read_row_fn));
  160896. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  160897. png_write_status_ptr write_row_fn));
  160898. #ifdef PNG_USER_MEM_SUPPORTED
  160899. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  160900. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  160901. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  160902. #endif
  160903. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160904. defined(PNG_LEGACY_SUPPORTED)
  160905. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  160906. png_ptr, png_user_transform_ptr read_user_transform_fn));
  160907. #endif
  160908. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160909. defined(PNG_LEGACY_SUPPORTED)
  160910. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  160911. png_ptr, png_user_transform_ptr write_user_transform_fn));
  160912. #endif
  160913. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160914. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160915. defined(PNG_LEGACY_SUPPORTED)
  160916. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  160917. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  160918. int user_transform_channels));
  160919. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  160920. PNGARG((png_structp png_ptr));
  160921. #endif
  160922. #ifdef PNG_USER_CHUNKS_SUPPORTED
  160923. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  160924. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  160925. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  160926. png_ptr));
  160927. #endif
  160928. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160929. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  160930. png_voidp progressive_ptr,
  160931. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  160932. png_progressive_end_ptr end_fn));
  160933. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  160934. PNGARG((png_structp png_ptr));
  160935. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  160936. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  160937. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  160938. png_bytep old_row, png_bytep new_row));
  160939. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  160940. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  160941. png_uint_32 size));
  160942. #if defined(PNG_1_0_X)
  160943. # define png_malloc_warn png_malloc
  160944. #else
  160945. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  160946. png_uint_32 size));
  160947. #endif
  160948. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  160949. #if defined(PNG_1_0_X)
  160950. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  160951. uInt size));
  160952. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  160953. #endif
  160954. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  160955. png_infop info_ptr, png_uint_32 free_me, int num));
  160956. #ifdef PNG_FREE_ME_SUPPORTED
  160957. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  160958. png_infop info_ptr, int freer, png_uint_32 mask));
  160959. #endif
  160960. #define PNG_DESTROY_WILL_FREE_DATA 1
  160961. #define PNG_SET_WILL_FREE_DATA 1
  160962. #define PNG_USER_WILL_FREE_DATA 2
  160963. #define PNG_FREE_HIST 0x0008
  160964. #define PNG_FREE_ICCP 0x0010
  160965. #define PNG_FREE_SPLT 0x0020
  160966. #define PNG_FREE_ROWS 0x0040
  160967. #define PNG_FREE_PCAL 0x0080
  160968. #define PNG_FREE_SCAL 0x0100
  160969. #define PNG_FREE_UNKN 0x0200
  160970. #define PNG_FREE_LIST 0x0400
  160971. #define PNG_FREE_PLTE 0x1000
  160972. #define PNG_FREE_TRNS 0x2000
  160973. #define PNG_FREE_TEXT 0x4000
  160974. #define PNG_FREE_ALL 0x7fff
  160975. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  160976. #ifdef PNG_USER_MEM_SUPPORTED
  160977. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  160978. png_uint_32 size));
  160979. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  160980. png_voidp ptr));
  160981. #endif
  160982. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  160983. png_voidp s1, png_voidp s2, png_uint_32 size));
  160984. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  160985. png_voidp s1, int value, png_uint_32 size));
  160986. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  160987. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  160988. int check));
  160989. #endif /* USE_FAR_KEYWORD */
  160990. #ifndef PNG_NO_ERROR_TEXT
  160991. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  160992. png_const_charp error_message));
  160993. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  160994. png_const_charp error_message));
  160995. #else
  160996. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  160997. #endif
  160998. #ifndef PNG_NO_WARNINGS
  160999. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161000. png_const_charp warning_message));
  161001. #ifdef PNG_READ_SUPPORTED
  161002. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161003. png_const_charp warning_message));
  161004. #endif /* PNG_READ_SUPPORTED */
  161005. #endif /* PNG_NO_WARNINGS */
  161006. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161007. png_infop info_ptr, png_uint_32 flag));
  161008. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161009. png_infop info_ptr));
  161010. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161011. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161012. png_infop info_ptr));
  161013. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161014. png_infop info_ptr, png_bytepp row_pointers));
  161015. #endif
  161016. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161017. png_infop info_ptr));
  161018. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161019. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161020. png_ptr, png_infop info_ptr));
  161021. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161022. png_ptr, png_infop info_ptr));
  161023. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161024. png_ptr, png_infop info_ptr));
  161025. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161026. png_ptr, png_infop info_ptr));
  161027. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161028. png_ptr, png_infop info_ptr));
  161029. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161030. png_ptr, png_infop info_ptr));
  161031. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161032. png_ptr, png_infop info_ptr));
  161033. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161034. png_ptr, png_infop info_ptr));
  161035. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161036. png_ptr, png_infop info_ptr));
  161037. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161038. png_ptr, png_infop info_ptr));
  161039. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161040. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161041. png_ptr, png_infop info_ptr));
  161042. #endif
  161043. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161044. png_ptr, png_infop info_ptr));
  161045. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161046. png_ptr, png_infop info_ptr));
  161047. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161048. png_ptr, png_infop info_ptr));
  161049. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161050. png_ptr, png_infop info_ptr));
  161051. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161052. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161053. png_infop info_ptr));
  161054. #if defined(PNG_bKGD_SUPPORTED)
  161055. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161056. png_infop info_ptr, png_color_16p *background));
  161057. #endif
  161058. #if defined(PNG_bKGD_SUPPORTED)
  161059. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161060. png_infop info_ptr, png_color_16p background));
  161061. #endif
  161062. #if defined(PNG_cHRM_SUPPORTED)
  161063. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161064. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161065. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161066. double *red_y, double *green_x, double *green_y, double *blue_x,
  161067. double *blue_y));
  161068. #endif
  161069. #ifdef PNG_FIXED_POINT_SUPPORTED
  161070. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161071. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161072. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161073. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161074. *int_blue_x, png_fixed_point *int_blue_y));
  161075. #endif
  161076. #endif
  161077. #if defined(PNG_cHRM_SUPPORTED)
  161078. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161079. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161080. png_infop info_ptr, double white_x, double white_y, double red_x,
  161081. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161082. #endif
  161083. #ifdef PNG_FIXED_POINT_SUPPORTED
  161084. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161085. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161086. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161087. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161088. png_fixed_point int_blue_y));
  161089. #endif
  161090. #endif
  161091. #if defined(PNG_gAMA_SUPPORTED)
  161092. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161093. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161094. png_infop info_ptr, double *file_gamma));
  161095. #endif
  161096. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161097. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161098. #endif
  161099. #if defined(PNG_gAMA_SUPPORTED)
  161100. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161101. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161102. png_infop info_ptr, double file_gamma));
  161103. #endif
  161104. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161105. png_infop info_ptr, png_fixed_point int_file_gamma));
  161106. #endif
  161107. #if defined(PNG_hIST_SUPPORTED)
  161108. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161109. png_infop info_ptr, png_uint_16p *hist));
  161110. #endif
  161111. #if defined(PNG_hIST_SUPPORTED)
  161112. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161113. png_infop info_ptr, png_uint_16p hist));
  161114. #endif
  161115. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161116. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161117. int *bit_depth, int *color_type, int *interlace_method,
  161118. int *compression_method, int *filter_method));
  161119. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161120. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161121. int color_type, int interlace_method, int compression_method,
  161122. int filter_method));
  161123. #if defined(PNG_oFFs_SUPPORTED)
  161124. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161125. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161126. int *unit_type));
  161127. #endif
  161128. #if defined(PNG_oFFs_SUPPORTED)
  161129. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161130. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161131. int unit_type));
  161132. #endif
  161133. #if defined(PNG_pCAL_SUPPORTED)
  161134. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161135. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161136. int *type, int *nparams, png_charp *units, png_charpp *params));
  161137. #endif
  161138. #if defined(PNG_pCAL_SUPPORTED)
  161139. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161140. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161141. int type, int nparams, png_charp units, png_charpp params));
  161142. #endif
  161143. #if defined(PNG_pHYs_SUPPORTED)
  161144. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161145. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161146. #endif
  161147. #if defined(PNG_pHYs_SUPPORTED)
  161148. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161149. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161150. #endif
  161151. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161152. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161153. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161154. png_infop info_ptr, png_colorp palette, int num_palette));
  161155. #if defined(PNG_sBIT_SUPPORTED)
  161156. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161157. png_infop info_ptr, png_color_8p *sig_bit));
  161158. #endif
  161159. #if defined(PNG_sBIT_SUPPORTED)
  161160. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161161. png_infop info_ptr, png_color_8p sig_bit));
  161162. #endif
  161163. #if defined(PNG_sRGB_SUPPORTED)
  161164. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161165. png_infop info_ptr, int *intent));
  161166. #endif
  161167. #if defined(PNG_sRGB_SUPPORTED)
  161168. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161169. png_infop info_ptr, int intent));
  161170. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161171. png_infop info_ptr, int intent));
  161172. #endif
  161173. #if defined(PNG_iCCP_SUPPORTED)
  161174. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161175. png_infop info_ptr, png_charpp name, int *compression_type,
  161176. png_charpp profile, png_uint_32 *proflen));
  161177. #endif
  161178. #if defined(PNG_iCCP_SUPPORTED)
  161179. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161180. png_infop info_ptr, png_charp name, int compression_type,
  161181. png_charp profile, png_uint_32 proflen));
  161182. #endif
  161183. #if defined(PNG_sPLT_SUPPORTED)
  161184. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161185. png_infop info_ptr, png_sPLT_tpp entries));
  161186. #endif
  161187. #if defined(PNG_sPLT_SUPPORTED)
  161188. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161189. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161190. #endif
  161191. #if defined(PNG_TEXT_SUPPORTED)
  161192. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161193. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161194. #endif
  161195. #if defined(PNG_TEXT_SUPPORTED)
  161196. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161197. png_infop info_ptr, png_textp text_ptr, int num_text));
  161198. #endif
  161199. #if defined(PNG_tIME_SUPPORTED)
  161200. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161201. png_infop info_ptr, png_timep *mod_time));
  161202. #endif
  161203. #if defined(PNG_tIME_SUPPORTED)
  161204. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161205. png_infop info_ptr, png_timep mod_time));
  161206. #endif
  161207. #if defined(PNG_tRNS_SUPPORTED)
  161208. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161209. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161210. png_color_16p *trans_values));
  161211. #endif
  161212. #if defined(PNG_tRNS_SUPPORTED)
  161213. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161214. png_infop info_ptr, png_bytep trans, int num_trans,
  161215. png_color_16p trans_values));
  161216. #endif
  161217. #if defined(PNG_tRNS_SUPPORTED)
  161218. #endif
  161219. #if defined(PNG_sCAL_SUPPORTED)
  161220. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161221. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161222. png_infop info_ptr, int *unit, double *width, double *height));
  161223. #else
  161224. #ifdef PNG_FIXED_POINT_SUPPORTED
  161225. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161226. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161227. #endif
  161228. #endif
  161229. #endif /* PNG_sCAL_SUPPORTED */
  161230. #if defined(PNG_sCAL_SUPPORTED)
  161231. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161232. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161233. png_infop info_ptr, int unit, double width, double height));
  161234. #else
  161235. #ifdef PNG_FIXED_POINT_SUPPORTED
  161236. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161237. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161238. #endif
  161239. #endif
  161240. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161241. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161242. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161243. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161244. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161245. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161246. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161247. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161248. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161249. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161250. #endif
  161251. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161252. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161253. chunk_name));
  161254. #endif
  161255. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161256. png_infop info_ptr, int mask));
  161257. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161258. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161259. png_infop info_ptr,
  161260. int transforms,
  161261. png_voidp params));
  161262. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161263. png_infop info_ptr,
  161264. int transforms,
  161265. png_voidp params));
  161266. #endif
  161267. #ifdef PNG_DEBUG
  161268. #if (PNG_DEBUG > 0)
  161269. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161270. #include <crtdbg.h>
  161271. #if (PNG_DEBUG > 1)
  161272. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161273. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161274. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161275. #endif
  161276. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161277. #ifndef PNG_DEBUG_FILE
  161278. #define PNG_DEBUG_FILE stderr
  161279. #endif /* PNG_DEBUG_FILE */
  161280. #if (PNG_DEBUG > 1)
  161281. #define png_debug(l,m) \
  161282. { \
  161283. int num_tabs=l; \
  161284. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161285. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161286. }
  161287. #define png_debug1(l,m,p1) \
  161288. { \
  161289. int num_tabs=l; \
  161290. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161291. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161292. }
  161293. #define png_debug2(l,m,p1,p2) \
  161294. { \
  161295. int num_tabs=l; \
  161296. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161297. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161298. }
  161299. #endif /* (PNG_DEBUG > 1) */
  161300. #endif /* _MSC_VER */
  161301. #endif /* (PNG_DEBUG > 0) */
  161302. #endif /* PNG_DEBUG */
  161303. #ifndef png_debug
  161304. #define png_debug(l, m)
  161305. #endif
  161306. #ifndef png_debug1
  161307. #define png_debug1(l, m, p1)
  161308. #endif
  161309. #ifndef png_debug2
  161310. #define png_debug2(l, m, p1, p2)
  161311. #endif
  161312. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161313. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161314. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161315. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161316. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161317. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161318. png_ptr, png_uint_32 mng_features_permitted));
  161319. #endif
  161320. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161321. #define PNG_HANDLE_CHUNK_NEVER 1
  161322. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161323. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161324. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161325. #if defined(PNG_MMX_CODE_SUPPORTED)
  161326. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161327. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161328. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161329. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161330. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161331. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161332. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161333. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161334. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161335. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161336. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161337. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161338. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161339. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161340. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161341. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161342. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161343. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161344. | PNG_MMX_READ_FLAGS \
  161345. | PNG_MMX_WRITE_FLAGS )
  161346. #define PNG_SELECT_READ 1
  161347. #define PNG_SELECT_WRITE 2
  161348. #endif /* PNG_MMX_CODE_SUPPORTED */
  161349. #if !defined(PNG_1_0_X)
  161350. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161351. PNGARG((int flag_select, int *compilerID));
  161352. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161353. PNGARG((int flag_select));
  161354. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161355. PNGARG((png_structp png_ptr));
  161356. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161357. PNGARG((png_structp png_ptr));
  161358. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161359. PNGARG((png_structp png_ptr));
  161360. extern PNG_EXPORT(void,png_set_asm_flags)
  161361. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161362. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161363. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161364. png_uint_32 mmx_rowbytes_threshold));
  161365. #endif /* PNG_1_0_X */
  161366. #if !defined(PNG_1_0_X)
  161367. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161368. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161369. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161370. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161371. png_ptr, png_uint_32 strip_mode));
  161372. #endif
  161373. #endif /* PNG_1_0_X */
  161374. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161375. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161376. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161377. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161378. png_ptr));
  161379. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161380. png_ptr));
  161381. #endif
  161382. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161383. # define png_composite(composite, fg, alpha, bg) \
  161384. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161385. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161386. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161387. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161388. # define png_composite_16(composite, fg, alpha, bg) \
  161389. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161390. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161391. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161392. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161393. #else /* standard method using integer division */
  161394. # define png_composite(composite, fg, alpha, bg) \
  161395. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161396. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161397. (png_uint_16)127) / 255)
  161398. # define png_composite_16(composite, fg, alpha, bg) \
  161399. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161400. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161401. (png_uint_32)32767) / (png_uint_32)65535L)
  161402. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161403. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161404. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161405. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161406. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161407. #else
  161408. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161409. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161410. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161411. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161412. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161413. PNGARG((png_structp png_ptr, png_bytep buf));
  161414. extern PNG_EXPORT(void,png_save_uint_32)
  161415. PNGARG((png_bytep buf, png_uint_32 i));
  161416. extern PNG_EXPORT(void,png_save_int_32)
  161417. PNGARG((png_bytep buf, png_int_32 i));
  161418. extern PNG_EXPORT(void,png_save_uint_16)
  161419. PNGARG((png_bytep buf, unsigned int i));
  161420. #define PNG_HAVE_IHDR 0x01
  161421. #define PNG_HAVE_PLTE 0x02
  161422. #define PNG_HAVE_IDAT 0x04
  161423. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161424. #define PNG_HAVE_IEND 0x10
  161425. #if defined(PNG_INTERNAL)
  161426. #define PNG_HAVE_gAMA 0x20
  161427. #define PNG_HAVE_cHRM 0x40
  161428. #define PNG_HAVE_sRGB 0x80
  161429. #define PNG_HAVE_CHUNK_HEADER 0x100
  161430. #define PNG_WROTE_tIME 0x200
  161431. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161432. #define PNG_BACKGROUND_IS_GRAY 0x800
  161433. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161434. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161435. #define PNG_BGR 0x0001
  161436. #define PNG_INTERLACE 0x0002
  161437. #define PNG_PACK 0x0004
  161438. #define PNG_SHIFT 0x0008
  161439. #define PNG_SWAP_BYTES 0x0010
  161440. #define PNG_INVERT_MONO 0x0020
  161441. #define PNG_DITHER 0x0040
  161442. #define PNG_BACKGROUND 0x0080
  161443. #define PNG_BACKGROUND_EXPAND 0x0100
  161444. #define PNG_16_TO_8 0x0400
  161445. #define PNG_RGBA 0x0800
  161446. #define PNG_EXPAND 0x1000
  161447. #define PNG_GAMMA 0x2000
  161448. #define PNG_GRAY_TO_RGB 0x4000
  161449. #define PNG_FILLER 0x8000L
  161450. #define PNG_PACKSWAP 0x10000L
  161451. #define PNG_SWAP_ALPHA 0x20000L
  161452. #define PNG_STRIP_ALPHA 0x40000L
  161453. #define PNG_INVERT_ALPHA 0x80000L
  161454. #define PNG_USER_TRANSFORM 0x100000L
  161455. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161456. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161457. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161458. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161459. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161460. #define PNG_STRUCT_PNG 0x0001
  161461. #define PNG_STRUCT_INFO 0x0002
  161462. #define PNG_WEIGHT_SHIFT 8
  161463. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161464. #define PNG_COST_SHIFT 3
  161465. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161466. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161467. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161468. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161469. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161470. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161471. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161472. #define PNG_FLAG_ROW_INIT 0x0040
  161473. #define PNG_FLAG_FILLER_AFTER 0x0080
  161474. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161475. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161476. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161477. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161478. #define PNG_FLAG_FREE_PLTE 0x1000
  161479. #define PNG_FLAG_FREE_TRNS 0x2000
  161480. #define PNG_FLAG_FREE_HIST 0x4000
  161481. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161482. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161483. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161484. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161485. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161486. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161487. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161488. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161489. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161490. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161491. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161492. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161493. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161494. PNG_FLAG_CRC_CRITICAL_MASK)
  161495. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161496. abs((int)((c1).green) - (int)((c2).green)) + \
  161497. abs((int)((c1).blue) - (int)((c2).blue)))
  161498. #define PNG_ROWBYTES(pixel_bits, width) \
  161499. ((pixel_bits) >= 8 ? \
  161500. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161501. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161502. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161503. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161504. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161505. #ifdef PNG_USE_GLOBAL_ARRAYS
  161506. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161507. #else
  161508. #endif
  161509. #endif /* PNG_NO_EXTERN */
  161510. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161511. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161512. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161513. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161514. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161515. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161516. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161517. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161518. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161519. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161520. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161521. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  161522. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  161523. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  161524. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  161525. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  161526. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  161527. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  161528. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  161529. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  161530. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  161531. #ifdef PNG_USE_GLOBAL_ARRAYS
  161532. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  161533. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  161534. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  161535. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  161536. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  161537. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  161538. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  161539. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  161540. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  161541. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  161542. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  161543. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  161544. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  161545. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  161546. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  161547. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  161548. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  161549. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  161550. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  161551. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  161552. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  161553. #endif /* PNG_USE_GLOBAL_ARRAYS */
  161554. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161555. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  161556. #undef png_read_init
  161557. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  161558. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161559. #endif
  161560. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  161561. png_const_charp user_png_ver, png_size_t png_struct_size));
  161562. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161563. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  161564. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161565. png_info_size));
  161566. #endif
  161567. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161568. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  161569. #undef png_write_init
  161570. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  161571. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  161572. #endif
  161573. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  161574. png_const_charp user_png_ver, png_size_t png_struct_size));
  161575. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  161576. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  161577. png_info_size));
  161578. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  161579. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  161580. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  161581. malloc_fn, png_voidp mem_ptr));
  161582. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  161583. png_free_ptr free_fn, png_voidp mem_ptr));
  161584. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  161585. png_infop info_ptr));
  161586. #ifndef PNG_1_0_X
  161587. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  161588. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  161589. #ifdef PNG_SIZE_T
  161590. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  161591. #endif
  161592. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  161593. png_bytep data, png_size_t length));
  161594. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161595. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  161596. png_bytep buffer, png_size_t length));
  161597. #endif
  161598. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  161599. png_bytep data, png_size_t length));
  161600. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161601. #if !defined(PNG_NO_STDIO)
  161602. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  161603. #endif
  161604. #endif
  161605. #else /* PNG_1_0_X */
  161606. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161607. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  161608. png_bytep buffer, png_size_t length));
  161609. #endif
  161610. #endif /* PNG_1_0_X */
  161611. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  161612. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  161613. png_size_t length));
  161614. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  161615. png_size_t length));
  161616. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  161617. png_size_t length));
  161618. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  161619. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  161620. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  161621. int comp_type, png_charp chunkdata, png_size_t chunklength,
  161622. png_size_t prefix_length, png_size_t *data_length));
  161623. #endif
  161624. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  161625. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  161626. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  161627. png_size_t length));
  161628. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161629. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  161630. #endif
  161631. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  161632. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  161633. png_uint_32 height,
  161634. int bit_depth, int color_type, int compression_method, int filter_method,
  161635. int interlace_method));
  161636. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  161637. png_uint_32 num_pal));
  161638. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  161639. png_size_t length));
  161640. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  161641. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  161642. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161643. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  161644. #endif
  161645. #ifdef PNG_FIXED_POINT_SUPPORTED
  161646. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  161647. file_gamma));
  161648. #endif
  161649. #endif
  161650. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  161651. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  161652. int color_type));
  161653. #endif
  161654. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  161655. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161656. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  161657. double white_x, double white_y,
  161658. double red_x, double red_y, double green_x, double green_y,
  161659. double blue_x, double blue_y));
  161660. #endif
  161661. #ifdef PNG_FIXED_POINT_SUPPORTED
  161662. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  161663. png_fixed_point int_white_x, png_fixed_point int_white_y,
  161664. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161665. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161666. png_fixed_point int_blue_y));
  161667. #endif
  161668. #endif
  161669. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  161670. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  161671. int intent));
  161672. #endif
  161673. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  161674. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  161675. png_charp name, int compression_type,
  161676. png_charp profile, int proflen));
  161677. #endif
  161678. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  161679. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  161680. png_sPLT_tp palette));
  161681. #endif
  161682. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  161683. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  161684. png_color_16p values, int number, int color_type));
  161685. #endif
  161686. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  161687. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  161688. png_color_16p values, int color_type));
  161689. #endif
  161690. #if defined(PNG_WRITE_hIST_SUPPORTED)
  161691. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  161692. int num_hist));
  161693. #endif
  161694. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  161695. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  161696. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  161697. png_charp key, png_charpp new_key));
  161698. #endif
  161699. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  161700. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  161701. png_charp text, png_size_t text_len));
  161702. #endif
  161703. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  161704. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  161705. png_charp text, png_size_t text_len, int compression));
  161706. #endif
  161707. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  161708. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  161709. int compression, png_charp key, png_charp lang, png_charp lang_key,
  161710. png_charp text));
  161711. #endif
  161712. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  161713. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  161714. png_infop info_ptr, png_textp text_ptr, int num_text));
  161715. #endif
  161716. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  161717. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  161718. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  161719. #endif
  161720. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  161721. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  161722. png_int_32 X0, png_int_32 X1, int type, int nparams,
  161723. png_charp units, png_charpp params));
  161724. #endif
  161725. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  161726. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  161727. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  161728. int unit_type));
  161729. #endif
  161730. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161731. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  161732. png_timep mod_time));
  161733. #endif
  161734. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  161735. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  161736. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  161737. int unit, double width, double height));
  161738. #else
  161739. #ifdef PNG_FIXED_POINT_SUPPORTED
  161740. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  161741. int unit, png_charp width, png_charp height));
  161742. #endif
  161743. #endif
  161744. #endif
  161745. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  161746. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  161747. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161748. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  161749. #endif
  161750. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  161751. int mask));
  161752. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  161753. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  161754. #endif
  161755. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161756. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  161757. png_bytep row, int pass));
  161758. #endif
  161759. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  161760. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  161761. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  161762. png_row_infop row_info));
  161763. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  161764. png_bytep filtered_row));
  161765. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  161766. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  161767. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  161768. png_infop info_ptr));
  161769. #if defined(PNG_READ_FILLER_SUPPORTED)
  161770. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  161771. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  161772. #endif
  161773. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  161774. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  161775. png_bytep row));
  161776. #endif
  161777. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161778. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  161779. png_bytep row));
  161780. #endif
  161781. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  161782. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  161783. png_bytep row));
  161784. #endif
  161785. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161786. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  161787. png_bytep row));
  161788. #endif
  161789. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  161790. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161791. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  161792. png_bytep row, png_uint_32 flags));
  161793. #endif
  161794. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161795. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  161796. #endif
  161797. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161798. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  161799. #endif
  161800. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161801. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  161802. row_info, png_bytep row));
  161803. #endif
  161804. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161805. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  161806. png_bytep row));
  161807. #endif
  161808. #if defined(PNG_READ_PACK_SUPPORTED)
  161809. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  161810. #endif
  161811. #if defined(PNG_READ_SHIFT_SUPPORTED)
  161812. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  161813. png_color_8p sig_bits));
  161814. #endif
  161815. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161816. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  161817. #endif
  161818. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161819. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  161820. #endif
  161821. #if defined(PNG_READ_DITHER_SUPPORTED)
  161822. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  161823. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  161824. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  161825. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  161826. png_colorp palette, int num_palette));
  161827. # endif
  161828. #endif
  161829. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161830. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  161831. #endif
  161832. #if defined(PNG_WRITE_PACK_SUPPORTED)
  161833. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  161834. png_bytep row, png_uint_32 bit_depth));
  161835. #endif
  161836. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  161837. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  161838. png_color_8p bit_depth));
  161839. #endif
  161840. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161841. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161842. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161843. png_color_16p trans_values, png_color_16p background,
  161844. png_color_16p background_1,
  161845. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  161846. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  161847. png_uint_16pp gamma_16_to_1, int gamma_shift));
  161848. #else
  161849. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  161850. png_color_16p trans_values, png_color_16p background));
  161851. #endif
  161852. #endif
  161853. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161854. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  161855. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  161856. int gamma_shift));
  161857. #endif
  161858. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161859. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  161860. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  161861. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  161862. png_bytep row, png_color_16p trans_value));
  161863. #endif
  161864. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  161865. png_uint_32 length));
  161866. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  161867. png_uint_32 length));
  161868. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  161869. png_uint_32 length));
  161870. #if defined(PNG_READ_bKGD_SUPPORTED)
  161871. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  161872. png_uint_32 length));
  161873. #endif
  161874. #if defined(PNG_READ_cHRM_SUPPORTED)
  161875. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  161876. png_uint_32 length));
  161877. #endif
  161878. #if defined(PNG_READ_gAMA_SUPPORTED)
  161879. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  161880. png_uint_32 length));
  161881. #endif
  161882. #if defined(PNG_READ_hIST_SUPPORTED)
  161883. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  161884. png_uint_32 length));
  161885. #endif
  161886. #if defined(PNG_READ_iCCP_SUPPORTED)
  161887. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  161888. png_uint_32 length));
  161889. #endif /* PNG_READ_iCCP_SUPPORTED */
  161890. #if defined(PNG_READ_iTXt_SUPPORTED)
  161891. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161892. png_uint_32 length));
  161893. #endif
  161894. #if defined(PNG_READ_oFFs_SUPPORTED)
  161895. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161896. png_uint_32 length));
  161897. #endif
  161898. #if defined(PNG_READ_pCAL_SUPPORTED)
  161899. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161900. png_uint_32 length));
  161901. #endif
  161902. #if defined(PNG_READ_pHYs_SUPPORTED)
  161903. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  161904. png_uint_32 length));
  161905. #endif
  161906. #if defined(PNG_READ_sBIT_SUPPORTED)
  161907. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  161908. png_uint_32 length));
  161909. #endif
  161910. #if defined(PNG_READ_sCAL_SUPPORTED)
  161911. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  161912. png_uint_32 length));
  161913. #endif
  161914. #if defined(PNG_READ_sPLT_SUPPORTED)
  161915. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  161916. png_uint_32 length));
  161917. #endif /* PNG_READ_sPLT_SUPPORTED */
  161918. #if defined(PNG_READ_sRGB_SUPPORTED)
  161919. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  161920. png_uint_32 length));
  161921. #endif
  161922. #if defined(PNG_READ_tEXt_SUPPORTED)
  161923. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161924. png_uint_32 length));
  161925. #endif
  161926. #if defined(PNG_READ_tIME_SUPPORTED)
  161927. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  161928. png_uint_32 length));
  161929. #endif
  161930. #if defined(PNG_READ_tRNS_SUPPORTED)
  161931. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  161932. png_uint_32 length));
  161933. #endif
  161934. #if defined(PNG_READ_zTXt_SUPPORTED)
  161935. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  161936. png_uint_32 length));
  161937. #endif
  161938. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  161939. png_infop info_ptr, png_uint_32 length));
  161940. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  161941. png_bytep chunk_name));
  161942. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  161943. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  161944. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  161945. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161946. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  161947. png_infop info_ptr));
  161948. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  161949. png_infop info_ptr));
  161950. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  161951. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  161952. png_uint_32 length));
  161953. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  161954. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  161955. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  161956. png_bytep buffer, png_size_t buffer_length));
  161957. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  161958. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  161959. png_bytep buffer, png_size_t buffer_length));
  161960. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  161961. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  161962. png_infop info_ptr, png_uint_32 length));
  161963. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  161964. png_infop info_ptr));
  161965. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  161966. png_infop info_ptr));
  161967. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  161968. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  161969. png_infop info_ptr));
  161970. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  161971. png_infop info_ptr));
  161972. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  161973. #if defined(PNG_READ_tEXt_SUPPORTED)
  161974. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  161975. png_infop info_ptr, png_uint_32 length));
  161976. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  161977. png_infop info_ptr));
  161978. #endif
  161979. #if defined(PNG_READ_zTXt_SUPPORTED)
  161980. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  161981. png_infop info_ptr, png_uint_32 length));
  161982. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  161983. png_infop info_ptr));
  161984. #endif
  161985. #if defined(PNG_READ_iTXt_SUPPORTED)
  161986. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  161987. png_infop info_ptr, png_uint_32 length));
  161988. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  161989. png_infop info_ptr));
  161990. #endif
  161991. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161992. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161993. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  161994. png_bytep row));
  161995. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  161996. png_bytep row));
  161997. #endif
  161998. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161999. #if defined(PNG_MMX_CODE_SUPPORTED)
  162000. /* PRIVATE */
  162001. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162002. #endif
  162003. #endif
  162004. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162005. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162006. png_infop info_ptr));
  162007. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162008. png_infop info_ptr));
  162009. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162010. png_infop info_ptr));
  162011. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162012. png_infop info_ptr));
  162013. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162014. png_infop info_ptr));
  162015. #if defined(PNG_pHYs_SUPPORTED)
  162016. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162017. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162018. #endif /* PNG_pHYs_SUPPORTED */
  162019. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162020. #endif /* PNG_INTERNAL */
  162021. #ifdef __cplusplus
  162022. }
  162023. #endif
  162024. #endif /* PNG_VERSION_INFO_ONLY */
  162025. #endif /* PNG_H */
  162026. /*** End of inlined file: png.h ***/
  162027. #define PNG_NO_EXTERN
  162028. /*** Start of inlined file: png.c ***/
  162029. #define PNG_INTERNAL
  162030. #define PNG_NO_EXTERN
  162031. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162032. #ifdef PNG_USE_GLOBAL_ARRAYS
  162033. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162034. #ifdef PNG_READ_SUPPORTED
  162035. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162036. #endif /* PNG_READ_SUPPORTED */
  162037. PNG_IHDR;
  162038. PNG_IDAT;
  162039. PNG_IEND;
  162040. PNG_PLTE;
  162041. PNG_bKGD;
  162042. PNG_cHRM;
  162043. PNG_gAMA;
  162044. PNG_hIST;
  162045. PNG_iCCP;
  162046. PNG_iTXt;
  162047. PNG_oFFs;
  162048. PNG_pCAL;
  162049. PNG_sCAL;
  162050. PNG_pHYs;
  162051. PNG_sBIT;
  162052. PNG_sPLT;
  162053. PNG_sRGB;
  162054. PNG_tEXt;
  162055. PNG_tIME;
  162056. PNG_tRNS;
  162057. PNG_zTXt;
  162058. #ifdef PNG_READ_SUPPORTED
  162059. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162060. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162061. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162062. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162063. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162064. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162065. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162066. #endif /* PNG_READ_SUPPORTED */
  162067. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162068. #ifdef PNG_READ_SUPPORTED
  162069. void PNGAPI
  162070. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162071. {
  162072. if(png_ptr == NULL) return;
  162073. png_debug(1, "in png_set_sig_bytes\n");
  162074. if (num_bytes > 8)
  162075. png_error(png_ptr, "Too many bytes for PNG signature.");
  162076. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162077. }
  162078. int PNGAPI
  162079. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162080. {
  162081. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162082. if (num_to_check > 8)
  162083. num_to_check = 8;
  162084. else if (num_to_check < 1)
  162085. return (-1);
  162086. if (start > 7)
  162087. return (-1);
  162088. if (start + num_to_check > 8)
  162089. num_to_check = 8 - start;
  162090. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162091. }
  162092. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162093. int PNGAPI
  162094. png_check_sig(png_bytep sig, int num)
  162095. {
  162096. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162097. }
  162098. #endif
  162099. #endif /* PNG_READ_SUPPORTED */
  162100. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162101. #ifdef PNG_1_0_X
  162102. voidpf PNGAPI
  162103. #else
  162104. voidpf /* private */
  162105. #endif
  162106. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162107. {
  162108. png_voidp ptr;
  162109. png_structp p=(png_structp)png_ptr;
  162110. png_uint_32 save_flags=p->flags;
  162111. png_uint_32 num_bytes;
  162112. if(png_ptr == NULL) return (NULL);
  162113. if (items > PNG_UINT_32_MAX/size)
  162114. {
  162115. png_warning (p, "Potential overflow in png_zalloc()");
  162116. return (NULL);
  162117. }
  162118. num_bytes = (png_uint_32)items * size;
  162119. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162120. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162121. p->flags=save_flags;
  162122. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162123. if (ptr == NULL)
  162124. return ((voidpf)ptr);
  162125. if (num_bytes > (png_uint_32)0x8000L)
  162126. {
  162127. png_memset(ptr, 0, (png_size_t)0x8000L);
  162128. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162129. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162130. }
  162131. else
  162132. {
  162133. png_memset(ptr, 0, (png_size_t)num_bytes);
  162134. }
  162135. #endif
  162136. return ((voidpf)ptr);
  162137. }
  162138. #ifdef PNG_1_0_X
  162139. void PNGAPI
  162140. #else
  162141. void /* private */
  162142. #endif
  162143. png_zfree(voidpf png_ptr, voidpf ptr)
  162144. {
  162145. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162146. }
  162147. void /* PRIVATE */
  162148. png_reset_crc(png_structp png_ptr)
  162149. {
  162150. png_ptr->crc = crc32(0, Z_NULL, 0);
  162151. }
  162152. void /* PRIVATE */
  162153. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162154. {
  162155. int need_crc = 1;
  162156. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162157. {
  162158. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162159. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162160. need_crc = 0;
  162161. }
  162162. else /* critical */
  162163. {
  162164. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162165. need_crc = 0;
  162166. }
  162167. if (need_crc)
  162168. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162169. }
  162170. png_infop PNGAPI
  162171. png_create_info_struct(png_structp png_ptr)
  162172. {
  162173. png_infop info_ptr;
  162174. png_debug(1, "in png_create_info_struct\n");
  162175. if(png_ptr == NULL) return (NULL);
  162176. #ifdef PNG_USER_MEM_SUPPORTED
  162177. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162178. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162179. #else
  162180. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162181. #endif
  162182. if (info_ptr != NULL)
  162183. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162184. return (info_ptr);
  162185. }
  162186. void PNGAPI
  162187. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162188. {
  162189. png_infop info_ptr = NULL;
  162190. if(png_ptr == NULL) return;
  162191. png_debug(1, "in png_destroy_info_struct\n");
  162192. if (info_ptr_ptr != NULL)
  162193. info_ptr = *info_ptr_ptr;
  162194. if (info_ptr != NULL)
  162195. {
  162196. png_info_destroy(png_ptr, info_ptr);
  162197. #ifdef PNG_USER_MEM_SUPPORTED
  162198. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162199. png_ptr->mem_ptr);
  162200. #else
  162201. png_destroy_struct((png_voidp)info_ptr);
  162202. #endif
  162203. *info_ptr_ptr = NULL;
  162204. }
  162205. }
  162206. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162207. #undef png_info_init
  162208. void PNGAPI
  162209. png_info_init(png_infop info_ptr)
  162210. {
  162211. png_info_init_3(&info_ptr, 0);
  162212. }
  162213. #endif
  162214. void PNGAPI
  162215. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162216. {
  162217. png_infop info_ptr = *ptr_ptr;
  162218. if(info_ptr == NULL) return;
  162219. png_debug(1, "in png_info_init_3\n");
  162220. if(png_sizeof(png_info) > png_info_struct_size)
  162221. {
  162222. png_destroy_struct(info_ptr);
  162223. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162224. *ptr_ptr = info_ptr;
  162225. }
  162226. png_memset(info_ptr, 0, png_sizeof (png_info));
  162227. }
  162228. #ifdef PNG_FREE_ME_SUPPORTED
  162229. void PNGAPI
  162230. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162231. int freer, png_uint_32 mask)
  162232. {
  162233. png_debug(1, "in png_data_freer\n");
  162234. if (png_ptr == NULL || info_ptr == NULL)
  162235. return;
  162236. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162237. info_ptr->free_me |= mask;
  162238. else if(freer == PNG_USER_WILL_FREE_DATA)
  162239. info_ptr->free_me &= ~mask;
  162240. else
  162241. png_warning(png_ptr,
  162242. "Unknown freer parameter in png_data_freer.");
  162243. }
  162244. #endif
  162245. void PNGAPI
  162246. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162247. int num)
  162248. {
  162249. png_debug(1, "in png_free_data\n");
  162250. if (png_ptr == NULL || info_ptr == NULL)
  162251. return;
  162252. #if defined(PNG_TEXT_SUPPORTED)
  162253. #ifdef PNG_FREE_ME_SUPPORTED
  162254. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162255. #else
  162256. if (mask & PNG_FREE_TEXT)
  162257. #endif
  162258. {
  162259. if (num != -1)
  162260. {
  162261. if (info_ptr->text && info_ptr->text[num].key)
  162262. {
  162263. png_free(png_ptr, info_ptr->text[num].key);
  162264. info_ptr->text[num].key = NULL;
  162265. }
  162266. }
  162267. else
  162268. {
  162269. int i;
  162270. for (i = 0; i < info_ptr->num_text; i++)
  162271. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162272. png_free(png_ptr, info_ptr->text);
  162273. info_ptr->text = NULL;
  162274. info_ptr->num_text=0;
  162275. }
  162276. }
  162277. #endif
  162278. #if defined(PNG_tRNS_SUPPORTED)
  162279. #ifdef PNG_FREE_ME_SUPPORTED
  162280. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162281. #else
  162282. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162283. #endif
  162284. {
  162285. png_free(png_ptr, info_ptr->trans);
  162286. info_ptr->valid &= ~PNG_INFO_tRNS;
  162287. #ifndef PNG_FREE_ME_SUPPORTED
  162288. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162289. #endif
  162290. info_ptr->trans = NULL;
  162291. }
  162292. #endif
  162293. #if defined(PNG_sCAL_SUPPORTED)
  162294. #ifdef PNG_FREE_ME_SUPPORTED
  162295. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162296. #else
  162297. if (mask & PNG_FREE_SCAL)
  162298. #endif
  162299. {
  162300. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162301. png_free(png_ptr, info_ptr->scal_s_width);
  162302. png_free(png_ptr, info_ptr->scal_s_height);
  162303. info_ptr->scal_s_width = NULL;
  162304. info_ptr->scal_s_height = NULL;
  162305. #endif
  162306. info_ptr->valid &= ~PNG_INFO_sCAL;
  162307. }
  162308. #endif
  162309. #if defined(PNG_pCAL_SUPPORTED)
  162310. #ifdef PNG_FREE_ME_SUPPORTED
  162311. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162312. #else
  162313. if (mask & PNG_FREE_PCAL)
  162314. #endif
  162315. {
  162316. png_free(png_ptr, info_ptr->pcal_purpose);
  162317. png_free(png_ptr, info_ptr->pcal_units);
  162318. info_ptr->pcal_purpose = NULL;
  162319. info_ptr->pcal_units = NULL;
  162320. if (info_ptr->pcal_params != NULL)
  162321. {
  162322. int i;
  162323. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162324. {
  162325. png_free(png_ptr, info_ptr->pcal_params[i]);
  162326. info_ptr->pcal_params[i]=NULL;
  162327. }
  162328. png_free(png_ptr, info_ptr->pcal_params);
  162329. info_ptr->pcal_params = NULL;
  162330. }
  162331. info_ptr->valid &= ~PNG_INFO_pCAL;
  162332. }
  162333. #endif
  162334. #if defined(PNG_iCCP_SUPPORTED)
  162335. #ifdef PNG_FREE_ME_SUPPORTED
  162336. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162337. #else
  162338. if (mask & PNG_FREE_ICCP)
  162339. #endif
  162340. {
  162341. png_free(png_ptr, info_ptr->iccp_name);
  162342. png_free(png_ptr, info_ptr->iccp_profile);
  162343. info_ptr->iccp_name = NULL;
  162344. info_ptr->iccp_profile = NULL;
  162345. info_ptr->valid &= ~PNG_INFO_iCCP;
  162346. }
  162347. #endif
  162348. #if defined(PNG_sPLT_SUPPORTED)
  162349. #ifdef PNG_FREE_ME_SUPPORTED
  162350. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162351. #else
  162352. if (mask & PNG_FREE_SPLT)
  162353. #endif
  162354. {
  162355. if (num != -1)
  162356. {
  162357. if(info_ptr->splt_palettes)
  162358. {
  162359. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162360. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162361. info_ptr->splt_palettes[num].name = NULL;
  162362. info_ptr->splt_palettes[num].entries = NULL;
  162363. }
  162364. }
  162365. else
  162366. {
  162367. if(info_ptr->splt_palettes_num)
  162368. {
  162369. int i;
  162370. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162371. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162372. png_free(png_ptr, info_ptr->splt_palettes);
  162373. info_ptr->splt_palettes = NULL;
  162374. info_ptr->splt_palettes_num = 0;
  162375. }
  162376. info_ptr->valid &= ~PNG_INFO_sPLT;
  162377. }
  162378. }
  162379. #endif
  162380. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162381. if(png_ptr->unknown_chunk.data)
  162382. {
  162383. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162384. png_ptr->unknown_chunk.data = NULL;
  162385. }
  162386. #ifdef PNG_FREE_ME_SUPPORTED
  162387. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162388. #else
  162389. if (mask & PNG_FREE_UNKN)
  162390. #endif
  162391. {
  162392. if (num != -1)
  162393. {
  162394. if(info_ptr->unknown_chunks)
  162395. {
  162396. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162397. info_ptr->unknown_chunks[num].data = NULL;
  162398. }
  162399. }
  162400. else
  162401. {
  162402. int i;
  162403. if(info_ptr->unknown_chunks_num)
  162404. {
  162405. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162406. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162407. png_free(png_ptr, info_ptr->unknown_chunks);
  162408. info_ptr->unknown_chunks = NULL;
  162409. info_ptr->unknown_chunks_num = 0;
  162410. }
  162411. }
  162412. }
  162413. #endif
  162414. #if defined(PNG_hIST_SUPPORTED)
  162415. #ifdef PNG_FREE_ME_SUPPORTED
  162416. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162417. #else
  162418. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162419. #endif
  162420. {
  162421. png_free(png_ptr, info_ptr->hist);
  162422. info_ptr->hist = NULL;
  162423. info_ptr->valid &= ~PNG_INFO_hIST;
  162424. #ifndef PNG_FREE_ME_SUPPORTED
  162425. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162426. #endif
  162427. }
  162428. #endif
  162429. #ifdef PNG_FREE_ME_SUPPORTED
  162430. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162431. #else
  162432. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162433. #endif
  162434. {
  162435. png_zfree(png_ptr, info_ptr->palette);
  162436. info_ptr->palette = NULL;
  162437. info_ptr->valid &= ~PNG_INFO_PLTE;
  162438. #ifndef PNG_FREE_ME_SUPPORTED
  162439. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162440. #endif
  162441. info_ptr->num_palette = 0;
  162442. }
  162443. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162444. #ifdef PNG_FREE_ME_SUPPORTED
  162445. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162446. #else
  162447. if (mask & PNG_FREE_ROWS)
  162448. #endif
  162449. {
  162450. if(info_ptr->row_pointers)
  162451. {
  162452. int row;
  162453. for (row = 0; row < (int)info_ptr->height; row++)
  162454. {
  162455. png_free(png_ptr, info_ptr->row_pointers[row]);
  162456. info_ptr->row_pointers[row]=NULL;
  162457. }
  162458. png_free(png_ptr, info_ptr->row_pointers);
  162459. info_ptr->row_pointers=NULL;
  162460. }
  162461. info_ptr->valid &= ~PNG_INFO_IDAT;
  162462. }
  162463. #endif
  162464. #ifdef PNG_FREE_ME_SUPPORTED
  162465. if(num == -1)
  162466. info_ptr->free_me &= ~mask;
  162467. else
  162468. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162469. #endif
  162470. }
  162471. void /* PRIVATE */
  162472. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162473. {
  162474. png_debug(1, "in png_info_destroy\n");
  162475. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162476. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162477. if (png_ptr->num_chunk_list)
  162478. {
  162479. png_free(png_ptr, png_ptr->chunk_list);
  162480. png_ptr->chunk_list=NULL;
  162481. png_ptr->num_chunk_list=0;
  162482. }
  162483. #endif
  162484. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162485. }
  162486. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162487. png_voidp PNGAPI
  162488. png_get_io_ptr(png_structp png_ptr)
  162489. {
  162490. if(png_ptr == NULL) return (NULL);
  162491. return (png_ptr->io_ptr);
  162492. }
  162493. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162494. #if !defined(PNG_NO_STDIO)
  162495. void PNGAPI
  162496. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162497. {
  162498. png_debug(1, "in png_init_io\n");
  162499. if(png_ptr == NULL) return;
  162500. png_ptr->io_ptr = (png_voidp)fp;
  162501. }
  162502. #endif
  162503. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162504. png_charp PNGAPI
  162505. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162506. {
  162507. static PNG_CONST char short_months[12][4] =
  162508. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162509. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162510. if(png_ptr == NULL) return (NULL);
  162511. if (png_ptr->time_buffer == NULL)
  162512. {
  162513. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162514. png_sizeof(char)));
  162515. }
  162516. #if defined(_WIN32_WCE)
  162517. {
  162518. wchar_t time_buf[29];
  162519. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162520. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162521. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162522. ptime->second % 61);
  162523. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  162524. NULL, NULL);
  162525. }
  162526. #else
  162527. #ifdef USE_FAR_KEYWORD
  162528. {
  162529. char near_time_buf[29];
  162530. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  162531. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162532. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162533. ptime->second % 61);
  162534. png_memcpy(png_ptr->time_buffer, near_time_buf,
  162535. 29*png_sizeof(char));
  162536. }
  162537. #else
  162538. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  162539. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162540. ptime->year, ptime->hour % 24, ptime->minute % 60,
  162541. ptime->second % 61);
  162542. #endif
  162543. #endif /* _WIN32_WCE */
  162544. return ((png_charp)png_ptr->time_buffer);
  162545. }
  162546. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  162547. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162548. png_charp PNGAPI
  162549. png_get_copyright(png_structp png_ptr)
  162550. {
  162551. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162552. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  162553. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  162554. Copyright (c) 1996-1997 Andreas Dilger\n\
  162555. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  162556. }
  162557. png_charp PNGAPI
  162558. png_get_libpng_ver(png_structp png_ptr)
  162559. {
  162560. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162561. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162562. }
  162563. png_charp PNGAPI
  162564. png_get_header_ver(png_structp png_ptr)
  162565. {
  162566. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162567. return ((png_charp) PNG_LIBPNG_VER_STRING);
  162568. }
  162569. png_charp PNGAPI
  162570. png_get_header_version(png_structp png_ptr)
  162571. {
  162572. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  162573. return ((png_charp) PNG_HEADER_VERSION_STRING
  162574. #ifndef PNG_READ_SUPPORTED
  162575. " (NO READ SUPPORT)"
  162576. #endif
  162577. "\n");
  162578. }
  162579. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162580. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  162581. int PNGAPI
  162582. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  162583. {
  162584. int i;
  162585. png_bytep p;
  162586. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  162587. return 0;
  162588. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  162589. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  162590. if (!png_memcmp(chunk_name, p, 4))
  162591. return ((int)*(p+4));
  162592. return 0;
  162593. }
  162594. #endif
  162595. int PNGAPI
  162596. png_reset_zstream(png_structp png_ptr)
  162597. {
  162598. if (png_ptr == NULL) return Z_STREAM_ERROR;
  162599. return (inflateReset(&png_ptr->zstream));
  162600. }
  162601. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162602. png_uint_32 PNGAPI
  162603. png_access_version_number(void)
  162604. {
  162605. return((png_uint_32) PNG_LIBPNG_VER);
  162606. }
  162607. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162608. #if !defined(PNG_1_0_X)
  162609. int PNGAPI
  162610. png_mmx_support(void)
  162611. {
  162612. return -1;
  162613. }
  162614. #endif /* PNG_1_0_X */
  162615. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  162616. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162617. #ifdef PNG_SIZE_T
  162618. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162619. png_size_t PNGAPI
  162620. png_convert_size(size_t size)
  162621. {
  162622. if (size > (png_size_t)-1)
  162623. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  162624. return ((png_size_t)size);
  162625. }
  162626. #endif /* PNG_SIZE_T */
  162627. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162628. /*** End of inlined file: png.c ***/
  162629. /*** Start of inlined file: pngerror.c ***/
  162630. #define PNG_INTERNAL
  162631. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162632. static void /* PRIVATE */
  162633. png_default_error PNGARG((png_structp png_ptr,
  162634. png_const_charp error_message));
  162635. #ifndef PNG_NO_WARNINGS
  162636. static void /* PRIVATE */
  162637. png_default_warning PNGARG((png_structp png_ptr,
  162638. png_const_charp warning_message));
  162639. #endif /* PNG_NO_WARNINGS */
  162640. #ifndef PNG_NO_ERROR_TEXT
  162641. void PNGAPI
  162642. png_error(png_structp png_ptr, png_const_charp error_message)
  162643. {
  162644. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162645. char msg[16];
  162646. if (png_ptr != NULL)
  162647. {
  162648. if (png_ptr->flags&
  162649. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162650. {
  162651. if (*error_message == '#')
  162652. {
  162653. int offset;
  162654. for (offset=1; offset<15; offset++)
  162655. if (*(error_message+offset) == ' ')
  162656. break;
  162657. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162658. {
  162659. int i;
  162660. for (i=0; i<offset-1; i++)
  162661. msg[i]=error_message[i+1];
  162662. msg[i]='\0';
  162663. error_message=msg;
  162664. }
  162665. else
  162666. error_message+=offset;
  162667. }
  162668. else
  162669. {
  162670. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  162671. {
  162672. msg[0]='0';
  162673. msg[1]='\0';
  162674. error_message=msg;
  162675. }
  162676. }
  162677. }
  162678. }
  162679. #endif
  162680. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162681. (*(png_ptr->error_fn))(png_ptr, error_message);
  162682. png_default_error(png_ptr, error_message);
  162683. }
  162684. #else
  162685. void PNGAPI
  162686. png_err(png_structp png_ptr)
  162687. {
  162688. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  162689. (*(png_ptr->error_fn))(png_ptr, '\0');
  162690. png_default_error(png_ptr, '\0');
  162691. }
  162692. #endif /* PNG_NO_ERROR_TEXT */
  162693. #ifndef PNG_NO_WARNINGS
  162694. void PNGAPI
  162695. png_warning(png_structp png_ptr, png_const_charp warning_message)
  162696. {
  162697. int offset = 0;
  162698. if (png_ptr != NULL)
  162699. {
  162700. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162701. if (png_ptr->flags&
  162702. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  162703. #endif
  162704. {
  162705. if (*warning_message == '#')
  162706. {
  162707. for (offset=1; offset<15; offset++)
  162708. if (*(warning_message+offset) == ' ')
  162709. break;
  162710. }
  162711. }
  162712. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  162713. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  162714. }
  162715. else
  162716. png_default_warning(png_ptr, warning_message+offset);
  162717. }
  162718. #endif /* PNG_NO_WARNINGS */
  162719. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  162720. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  162721. static void /* PRIVATE */
  162722. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  162723. error_message)
  162724. {
  162725. int iout = 0, iin = 0;
  162726. while (iin < 4)
  162727. {
  162728. int c = png_ptr->chunk_name[iin++];
  162729. if (isnonalpha(c))
  162730. {
  162731. buffer[iout++] = '[';
  162732. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  162733. buffer[iout++] = png_digit[c & 0x0f];
  162734. buffer[iout++] = ']';
  162735. }
  162736. else
  162737. {
  162738. buffer[iout++] = (png_byte)c;
  162739. }
  162740. }
  162741. if (error_message == NULL)
  162742. buffer[iout] = 0;
  162743. else
  162744. {
  162745. buffer[iout++] = ':';
  162746. buffer[iout++] = ' ';
  162747. png_strncpy(buffer+iout, error_message, 63);
  162748. buffer[iout+63] = 0;
  162749. }
  162750. }
  162751. #ifdef PNG_READ_SUPPORTED
  162752. void PNGAPI
  162753. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  162754. {
  162755. char msg[18+64];
  162756. if (png_ptr == NULL)
  162757. png_error(png_ptr, error_message);
  162758. else
  162759. {
  162760. png_format_buffer(png_ptr, msg, error_message);
  162761. png_error(png_ptr, msg);
  162762. }
  162763. }
  162764. #endif /* PNG_READ_SUPPORTED */
  162765. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  162766. #ifndef PNG_NO_WARNINGS
  162767. void PNGAPI
  162768. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  162769. {
  162770. char msg[18+64];
  162771. if (png_ptr == NULL)
  162772. png_warning(png_ptr, warning_message);
  162773. else
  162774. {
  162775. png_format_buffer(png_ptr, msg, warning_message);
  162776. png_warning(png_ptr, msg);
  162777. }
  162778. }
  162779. #endif /* PNG_NO_WARNINGS */
  162780. static void /* PRIVATE */
  162781. png_default_error(png_structp png_ptr, png_const_charp error_message)
  162782. {
  162783. #ifndef PNG_NO_CONSOLE_IO
  162784. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162785. if (*error_message == '#')
  162786. {
  162787. int offset;
  162788. char error_number[16];
  162789. for (offset=0; offset<15; offset++)
  162790. {
  162791. error_number[offset] = *(error_message+offset+1);
  162792. if (*(error_message+offset) == ' ')
  162793. break;
  162794. }
  162795. if((offset > 1) && (offset < 15))
  162796. {
  162797. error_number[offset-1]='\0';
  162798. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  162799. error_message+offset);
  162800. }
  162801. else
  162802. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  162803. }
  162804. else
  162805. #endif
  162806. fprintf(stderr, "libpng error: %s\n", error_message);
  162807. #endif
  162808. #ifdef PNG_SETJMP_SUPPORTED
  162809. if (png_ptr)
  162810. {
  162811. # ifdef USE_FAR_KEYWORD
  162812. {
  162813. jmp_buf jmpbuf;
  162814. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  162815. longjmp(jmpbuf, 1);
  162816. }
  162817. # else
  162818. longjmp(png_ptr->jmpbuf, 1);
  162819. # endif
  162820. }
  162821. #else
  162822. PNG_ABORT();
  162823. #endif
  162824. #ifdef PNG_NO_CONSOLE_IO
  162825. error_message = error_message; /* make compiler happy */
  162826. #endif
  162827. }
  162828. #ifndef PNG_NO_WARNINGS
  162829. static void /* PRIVATE */
  162830. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  162831. {
  162832. #ifndef PNG_NO_CONSOLE_IO
  162833. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162834. if (*warning_message == '#')
  162835. {
  162836. int offset;
  162837. char warning_number[16];
  162838. for (offset=0; offset<15; offset++)
  162839. {
  162840. warning_number[offset]=*(warning_message+offset+1);
  162841. if (*(warning_message+offset) == ' ')
  162842. break;
  162843. }
  162844. if((offset > 1) && (offset < 15))
  162845. {
  162846. warning_number[offset-1]='\0';
  162847. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  162848. warning_message+offset);
  162849. }
  162850. else
  162851. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162852. }
  162853. else
  162854. # endif
  162855. fprintf(stderr, "libpng warning: %s\n", warning_message);
  162856. #else
  162857. warning_message = warning_message; /* make compiler happy */
  162858. #endif
  162859. png_ptr = png_ptr; /* make compiler happy */
  162860. }
  162861. #endif /* PNG_NO_WARNINGS */
  162862. void PNGAPI
  162863. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  162864. png_error_ptr error_fn, png_error_ptr warning_fn)
  162865. {
  162866. if (png_ptr == NULL)
  162867. return;
  162868. png_ptr->error_ptr = error_ptr;
  162869. png_ptr->error_fn = error_fn;
  162870. png_ptr->warning_fn = warning_fn;
  162871. }
  162872. png_voidp PNGAPI
  162873. png_get_error_ptr(png_structp png_ptr)
  162874. {
  162875. if (png_ptr == NULL)
  162876. return NULL;
  162877. return ((png_voidp)png_ptr->error_ptr);
  162878. }
  162879. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  162880. void PNGAPI
  162881. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  162882. {
  162883. if(png_ptr != NULL)
  162884. {
  162885. png_ptr->flags &=
  162886. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  162887. }
  162888. }
  162889. #endif
  162890. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  162891. /*** End of inlined file: pngerror.c ***/
  162892. /*** Start of inlined file: pngget.c ***/
  162893. #define PNG_INTERNAL
  162894. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162895. png_uint_32 PNGAPI
  162896. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  162897. {
  162898. if (png_ptr != NULL && info_ptr != NULL)
  162899. return(info_ptr->valid & flag);
  162900. else
  162901. return(0);
  162902. }
  162903. png_uint_32 PNGAPI
  162904. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  162905. {
  162906. if (png_ptr != NULL && info_ptr != NULL)
  162907. return(info_ptr->rowbytes);
  162908. else
  162909. return(0);
  162910. }
  162911. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162912. png_bytepp PNGAPI
  162913. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  162914. {
  162915. if (png_ptr != NULL && info_ptr != NULL)
  162916. return(info_ptr->row_pointers);
  162917. else
  162918. return(0);
  162919. }
  162920. #endif
  162921. #ifdef PNG_EASY_ACCESS_SUPPORTED
  162922. png_uint_32 PNGAPI
  162923. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  162924. {
  162925. if (png_ptr != NULL && info_ptr != NULL)
  162926. {
  162927. return info_ptr->width;
  162928. }
  162929. return (0);
  162930. }
  162931. png_uint_32 PNGAPI
  162932. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  162933. {
  162934. if (png_ptr != NULL && info_ptr != NULL)
  162935. {
  162936. return info_ptr->height;
  162937. }
  162938. return (0);
  162939. }
  162940. png_byte PNGAPI
  162941. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  162942. {
  162943. if (png_ptr != NULL && info_ptr != NULL)
  162944. {
  162945. return info_ptr->bit_depth;
  162946. }
  162947. return (0);
  162948. }
  162949. png_byte PNGAPI
  162950. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  162951. {
  162952. if (png_ptr != NULL && info_ptr != NULL)
  162953. {
  162954. return info_ptr->color_type;
  162955. }
  162956. return (0);
  162957. }
  162958. png_byte PNGAPI
  162959. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  162960. {
  162961. if (png_ptr != NULL && info_ptr != NULL)
  162962. {
  162963. return info_ptr->filter_type;
  162964. }
  162965. return (0);
  162966. }
  162967. png_byte PNGAPI
  162968. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  162969. {
  162970. if (png_ptr != NULL && info_ptr != NULL)
  162971. {
  162972. return info_ptr->interlace_type;
  162973. }
  162974. return (0);
  162975. }
  162976. png_byte PNGAPI
  162977. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  162978. {
  162979. if (png_ptr != NULL && info_ptr != NULL)
  162980. {
  162981. return info_ptr->compression_type;
  162982. }
  162983. return (0);
  162984. }
  162985. png_uint_32 PNGAPI
  162986. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  162987. {
  162988. if (png_ptr != NULL && info_ptr != NULL)
  162989. #if defined(PNG_pHYs_SUPPORTED)
  162990. if (info_ptr->valid & PNG_INFO_pHYs)
  162991. {
  162992. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  162993. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  162994. return (0);
  162995. else return (info_ptr->x_pixels_per_unit);
  162996. }
  162997. #else
  162998. return (0);
  162999. #endif
  163000. return (0);
  163001. }
  163002. png_uint_32 PNGAPI
  163003. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163004. {
  163005. if (png_ptr != NULL && info_ptr != NULL)
  163006. #if defined(PNG_pHYs_SUPPORTED)
  163007. if (info_ptr->valid & PNG_INFO_pHYs)
  163008. {
  163009. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163010. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163011. return (0);
  163012. else return (info_ptr->y_pixels_per_unit);
  163013. }
  163014. #else
  163015. return (0);
  163016. #endif
  163017. return (0);
  163018. }
  163019. png_uint_32 PNGAPI
  163020. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163021. {
  163022. if (png_ptr != NULL && info_ptr != NULL)
  163023. #if defined(PNG_pHYs_SUPPORTED)
  163024. if (info_ptr->valid & PNG_INFO_pHYs)
  163025. {
  163026. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163027. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163028. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163029. return (0);
  163030. else return (info_ptr->x_pixels_per_unit);
  163031. }
  163032. #else
  163033. return (0);
  163034. #endif
  163035. return (0);
  163036. }
  163037. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163038. float PNGAPI
  163039. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163040. {
  163041. if (png_ptr != NULL && info_ptr != NULL)
  163042. #if defined(PNG_pHYs_SUPPORTED)
  163043. if (info_ptr->valid & PNG_INFO_pHYs)
  163044. {
  163045. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163046. if (info_ptr->x_pixels_per_unit == 0)
  163047. return ((float)0.0);
  163048. else
  163049. return ((float)((float)info_ptr->y_pixels_per_unit
  163050. /(float)info_ptr->x_pixels_per_unit));
  163051. }
  163052. #else
  163053. return (0.0);
  163054. #endif
  163055. return ((float)0.0);
  163056. }
  163057. #endif
  163058. png_int_32 PNGAPI
  163059. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163060. {
  163061. if (png_ptr != NULL && info_ptr != NULL)
  163062. #if defined(PNG_oFFs_SUPPORTED)
  163063. if (info_ptr->valid & PNG_INFO_oFFs)
  163064. {
  163065. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163066. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163067. return (0);
  163068. else return (info_ptr->x_offset);
  163069. }
  163070. #else
  163071. return (0);
  163072. #endif
  163073. return (0);
  163074. }
  163075. png_int_32 PNGAPI
  163076. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163077. {
  163078. if (png_ptr != NULL && info_ptr != NULL)
  163079. #if defined(PNG_oFFs_SUPPORTED)
  163080. if (info_ptr->valid & PNG_INFO_oFFs)
  163081. {
  163082. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163083. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163084. return (0);
  163085. else return (info_ptr->y_offset);
  163086. }
  163087. #else
  163088. return (0);
  163089. #endif
  163090. return (0);
  163091. }
  163092. png_int_32 PNGAPI
  163093. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163094. {
  163095. if (png_ptr != NULL && info_ptr != NULL)
  163096. #if defined(PNG_oFFs_SUPPORTED)
  163097. if (info_ptr->valid & PNG_INFO_oFFs)
  163098. {
  163099. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163100. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163101. return (0);
  163102. else return (info_ptr->x_offset);
  163103. }
  163104. #else
  163105. return (0);
  163106. #endif
  163107. return (0);
  163108. }
  163109. png_int_32 PNGAPI
  163110. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163111. {
  163112. if (png_ptr != NULL && info_ptr != NULL)
  163113. #if defined(PNG_oFFs_SUPPORTED)
  163114. if (info_ptr->valid & PNG_INFO_oFFs)
  163115. {
  163116. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163117. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163118. return (0);
  163119. else return (info_ptr->y_offset);
  163120. }
  163121. #else
  163122. return (0);
  163123. #endif
  163124. return (0);
  163125. }
  163126. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163127. png_uint_32 PNGAPI
  163128. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163129. {
  163130. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163131. *.0254 +.5));
  163132. }
  163133. png_uint_32 PNGAPI
  163134. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163135. {
  163136. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163137. *.0254 +.5));
  163138. }
  163139. png_uint_32 PNGAPI
  163140. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163141. {
  163142. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163143. *.0254 +.5));
  163144. }
  163145. float PNGAPI
  163146. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163147. {
  163148. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163149. *.00003937);
  163150. }
  163151. float PNGAPI
  163152. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163153. {
  163154. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163155. *.00003937);
  163156. }
  163157. #if defined(PNG_pHYs_SUPPORTED)
  163158. png_uint_32 PNGAPI
  163159. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163160. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163161. {
  163162. png_uint_32 retval = 0;
  163163. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163164. {
  163165. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163166. if (res_x != NULL)
  163167. {
  163168. *res_x = info_ptr->x_pixels_per_unit;
  163169. retval |= PNG_INFO_pHYs;
  163170. }
  163171. if (res_y != NULL)
  163172. {
  163173. *res_y = info_ptr->y_pixels_per_unit;
  163174. retval |= PNG_INFO_pHYs;
  163175. }
  163176. if (unit_type != NULL)
  163177. {
  163178. *unit_type = (int)info_ptr->phys_unit_type;
  163179. retval |= PNG_INFO_pHYs;
  163180. if(*unit_type == 1)
  163181. {
  163182. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163183. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163184. }
  163185. }
  163186. }
  163187. return (retval);
  163188. }
  163189. #endif /* PNG_pHYs_SUPPORTED */
  163190. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163191. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163192. png_byte PNGAPI
  163193. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163194. {
  163195. if (png_ptr != NULL && info_ptr != NULL)
  163196. return(info_ptr->channels);
  163197. else
  163198. return (0);
  163199. }
  163200. png_bytep PNGAPI
  163201. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163202. {
  163203. if (png_ptr != NULL && info_ptr != NULL)
  163204. return(info_ptr->signature);
  163205. else
  163206. return (NULL);
  163207. }
  163208. #if defined(PNG_bKGD_SUPPORTED)
  163209. png_uint_32 PNGAPI
  163210. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163211. png_color_16p *background)
  163212. {
  163213. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163214. && background != NULL)
  163215. {
  163216. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163217. *background = &(info_ptr->background);
  163218. return (PNG_INFO_bKGD);
  163219. }
  163220. return (0);
  163221. }
  163222. #endif
  163223. #if defined(PNG_cHRM_SUPPORTED)
  163224. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163225. png_uint_32 PNGAPI
  163226. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163227. double *white_x, double *white_y, double *red_x, double *red_y,
  163228. double *green_x, double *green_y, double *blue_x, double *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 = (double)info_ptr->x_white;
  163235. if (white_y != NULL)
  163236. *white_y = (double)info_ptr->y_white;
  163237. if (red_x != NULL)
  163238. *red_x = (double)info_ptr->x_red;
  163239. if (red_y != NULL)
  163240. *red_y = (double)info_ptr->y_red;
  163241. if (green_x != NULL)
  163242. *green_x = (double)info_ptr->x_green;
  163243. if (green_y != NULL)
  163244. *green_y = (double)info_ptr->y_green;
  163245. if (blue_x != NULL)
  163246. *blue_x = (double)info_ptr->x_blue;
  163247. if (blue_y != NULL)
  163248. *blue_y = (double)info_ptr->y_blue;
  163249. return (PNG_INFO_cHRM);
  163250. }
  163251. return (0);
  163252. }
  163253. #endif
  163254. #ifdef PNG_FIXED_POINT_SUPPORTED
  163255. png_uint_32 PNGAPI
  163256. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163257. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163258. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163259. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163260. {
  163261. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163262. {
  163263. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163264. if (white_x != NULL)
  163265. *white_x = info_ptr->int_x_white;
  163266. if (white_y != NULL)
  163267. *white_y = info_ptr->int_y_white;
  163268. if (red_x != NULL)
  163269. *red_x = info_ptr->int_x_red;
  163270. if (red_y != NULL)
  163271. *red_y = info_ptr->int_y_red;
  163272. if (green_x != NULL)
  163273. *green_x = info_ptr->int_x_green;
  163274. if (green_y != NULL)
  163275. *green_y = info_ptr->int_y_green;
  163276. if (blue_x != NULL)
  163277. *blue_x = info_ptr->int_x_blue;
  163278. if (blue_y != NULL)
  163279. *blue_y = info_ptr->int_y_blue;
  163280. return (PNG_INFO_cHRM);
  163281. }
  163282. return (0);
  163283. }
  163284. #endif
  163285. #endif
  163286. #if defined(PNG_gAMA_SUPPORTED)
  163287. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163288. png_uint_32 PNGAPI
  163289. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163290. {
  163291. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163292. && file_gamma != NULL)
  163293. {
  163294. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163295. *file_gamma = (double)info_ptr->gamma;
  163296. return (PNG_INFO_gAMA);
  163297. }
  163298. return (0);
  163299. }
  163300. #endif
  163301. #ifdef PNG_FIXED_POINT_SUPPORTED
  163302. png_uint_32 PNGAPI
  163303. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163304. png_fixed_point *int_file_gamma)
  163305. {
  163306. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163307. && int_file_gamma != NULL)
  163308. {
  163309. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163310. *int_file_gamma = info_ptr->int_gamma;
  163311. return (PNG_INFO_gAMA);
  163312. }
  163313. return (0);
  163314. }
  163315. #endif
  163316. #endif
  163317. #if defined(PNG_sRGB_SUPPORTED)
  163318. png_uint_32 PNGAPI
  163319. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163320. {
  163321. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163322. && file_srgb_intent != NULL)
  163323. {
  163324. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163325. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163326. return (PNG_INFO_sRGB);
  163327. }
  163328. return (0);
  163329. }
  163330. #endif
  163331. #if defined(PNG_iCCP_SUPPORTED)
  163332. png_uint_32 PNGAPI
  163333. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163334. png_charpp name, int *compression_type,
  163335. png_charpp profile, png_uint_32 *proflen)
  163336. {
  163337. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163338. && name != NULL && profile != NULL && proflen != NULL)
  163339. {
  163340. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163341. *name = info_ptr->iccp_name;
  163342. *profile = info_ptr->iccp_profile;
  163343. *proflen = (int)info_ptr->iccp_proflen;
  163344. *compression_type = (int)info_ptr->iccp_compression;
  163345. return (PNG_INFO_iCCP);
  163346. }
  163347. return (0);
  163348. }
  163349. #endif
  163350. #if defined(PNG_sPLT_SUPPORTED)
  163351. png_uint_32 PNGAPI
  163352. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163353. png_sPLT_tpp spalettes)
  163354. {
  163355. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163356. {
  163357. *spalettes = info_ptr->splt_palettes;
  163358. return ((png_uint_32)info_ptr->splt_palettes_num);
  163359. }
  163360. return (0);
  163361. }
  163362. #endif
  163363. #if defined(PNG_hIST_SUPPORTED)
  163364. png_uint_32 PNGAPI
  163365. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163366. {
  163367. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163368. && hist != NULL)
  163369. {
  163370. png_debug1(1, "in %s retrieval function\n", "hIST");
  163371. *hist = info_ptr->hist;
  163372. return (PNG_INFO_hIST);
  163373. }
  163374. return (0);
  163375. }
  163376. #endif
  163377. png_uint_32 PNGAPI
  163378. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163379. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163380. int *color_type, int *interlace_type, int *compression_type,
  163381. int *filter_type)
  163382. {
  163383. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163384. bit_depth != NULL && color_type != NULL)
  163385. {
  163386. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163387. *width = info_ptr->width;
  163388. *height = info_ptr->height;
  163389. *bit_depth = info_ptr->bit_depth;
  163390. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163391. png_error(png_ptr, "Invalid bit depth");
  163392. *color_type = info_ptr->color_type;
  163393. if (info_ptr->color_type > 6)
  163394. png_error(png_ptr, "Invalid color type");
  163395. if (compression_type != NULL)
  163396. *compression_type = info_ptr->compression_type;
  163397. if (filter_type != NULL)
  163398. *filter_type = info_ptr->filter_type;
  163399. if (interlace_type != NULL)
  163400. *interlace_type = info_ptr->interlace_type;
  163401. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163402. png_error(png_ptr, "Invalid image width");
  163403. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163404. png_error(png_ptr, "Invalid image height");
  163405. if (info_ptr->width > (PNG_UINT_32_MAX
  163406. >> 3) /* 8-byte RGBA pixels */
  163407. - 64 /* bigrowbuf hack */
  163408. - 1 /* filter byte */
  163409. - 7*8 /* rounding of width to multiple of 8 pixels */
  163410. - 8) /* extra max_pixel_depth pad */
  163411. {
  163412. png_warning(png_ptr,
  163413. "Width too large for libpng to process image data.");
  163414. }
  163415. return (1);
  163416. }
  163417. return (0);
  163418. }
  163419. #if defined(PNG_oFFs_SUPPORTED)
  163420. png_uint_32 PNGAPI
  163421. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163422. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163423. {
  163424. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163425. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163426. {
  163427. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163428. *offset_x = info_ptr->x_offset;
  163429. *offset_y = info_ptr->y_offset;
  163430. *unit_type = (int)info_ptr->offset_unit_type;
  163431. return (PNG_INFO_oFFs);
  163432. }
  163433. return (0);
  163434. }
  163435. #endif
  163436. #if defined(PNG_pCAL_SUPPORTED)
  163437. png_uint_32 PNGAPI
  163438. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163439. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163440. png_charp *units, png_charpp *params)
  163441. {
  163442. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163443. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163444. nparams != NULL && units != NULL && params != NULL)
  163445. {
  163446. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163447. *purpose = info_ptr->pcal_purpose;
  163448. *X0 = info_ptr->pcal_X0;
  163449. *X1 = info_ptr->pcal_X1;
  163450. *type = (int)info_ptr->pcal_type;
  163451. *nparams = (int)info_ptr->pcal_nparams;
  163452. *units = info_ptr->pcal_units;
  163453. *params = info_ptr->pcal_params;
  163454. return (PNG_INFO_pCAL);
  163455. }
  163456. return (0);
  163457. }
  163458. #endif
  163459. #if defined(PNG_sCAL_SUPPORTED)
  163460. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163461. png_uint_32 PNGAPI
  163462. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163463. int *unit, double *width, double *height)
  163464. {
  163465. if (png_ptr != NULL && info_ptr != NULL &&
  163466. (info_ptr->valid & PNG_INFO_sCAL))
  163467. {
  163468. *unit = info_ptr->scal_unit;
  163469. *width = info_ptr->scal_pixel_width;
  163470. *height = info_ptr->scal_pixel_height;
  163471. return (PNG_INFO_sCAL);
  163472. }
  163473. return(0);
  163474. }
  163475. #else
  163476. #ifdef PNG_FIXED_POINT_SUPPORTED
  163477. png_uint_32 PNGAPI
  163478. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163479. int *unit, png_charpp width, png_charpp height)
  163480. {
  163481. if (png_ptr != NULL && info_ptr != NULL &&
  163482. (info_ptr->valid & PNG_INFO_sCAL))
  163483. {
  163484. *unit = info_ptr->scal_unit;
  163485. *width = info_ptr->scal_s_width;
  163486. *height = info_ptr->scal_s_height;
  163487. return (PNG_INFO_sCAL);
  163488. }
  163489. return(0);
  163490. }
  163491. #endif
  163492. #endif
  163493. #endif
  163494. #if defined(PNG_pHYs_SUPPORTED)
  163495. png_uint_32 PNGAPI
  163496. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163497. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163498. {
  163499. png_uint_32 retval = 0;
  163500. if (png_ptr != NULL && info_ptr != NULL &&
  163501. (info_ptr->valid & PNG_INFO_pHYs))
  163502. {
  163503. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163504. if (res_x != NULL)
  163505. {
  163506. *res_x = info_ptr->x_pixels_per_unit;
  163507. retval |= PNG_INFO_pHYs;
  163508. }
  163509. if (res_y != NULL)
  163510. {
  163511. *res_y = info_ptr->y_pixels_per_unit;
  163512. retval |= PNG_INFO_pHYs;
  163513. }
  163514. if (unit_type != NULL)
  163515. {
  163516. *unit_type = (int)info_ptr->phys_unit_type;
  163517. retval |= PNG_INFO_pHYs;
  163518. }
  163519. }
  163520. return (retval);
  163521. }
  163522. #endif
  163523. png_uint_32 PNGAPI
  163524. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  163525. int *num_palette)
  163526. {
  163527. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  163528. && palette != NULL)
  163529. {
  163530. png_debug1(1, "in %s retrieval function\n", "PLTE");
  163531. *palette = info_ptr->palette;
  163532. *num_palette = info_ptr->num_palette;
  163533. png_debug1(3, "num_palette = %d\n", *num_palette);
  163534. return (PNG_INFO_PLTE);
  163535. }
  163536. return (0);
  163537. }
  163538. #if defined(PNG_sBIT_SUPPORTED)
  163539. png_uint_32 PNGAPI
  163540. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  163541. {
  163542. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  163543. && sig_bit != NULL)
  163544. {
  163545. png_debug1(1, "in %s retrieval function\n", "sBIT");
  163546. *sig_bit = &(info_ptr->sig_bit);
  163547. return (PNG_INFO_sBIT);
  163548. }
  163549. return (0);
  163550. }
  163551. #endif
  163552. #if defined(PNG_TEXT_SUPPORTED)
  163553. png_uint_32 PNGAPI
  163554. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  163555. int *num_text)
  163556. {
  163557. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  163558. {
  163559. png_debug1(1, "in %s retrieval function\n",
  163560. (png_ptr->chunk_name[0] == '\0' ? "text"
  163561. : (png_const_charp)png_ptr->chunk_name));
  163562. if (text_ptr != NULL)
  163563. *text_ptr = info_ptr->text;
  163564. if (num_text != NULL)
  163565. *num_text = info_ptr->num_text;
  163566. return ((png_uint_32)info_ptr->num_text);
  163567. }
  163568. if (num_text != NULL)
  163569. *num_text = 0;
  163570. return(0);
  163571. }
  163572. #endif
  163573. #if defined(PNG_tIME_SUPPORTED)
  163574. png_uint_32 PNGAPI
  163575. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  163576. {
  163577. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  163578. && mod_time != NULL)
  163579. {
  163580. png_debug1(1, "in %s retrieval function\n", "tIME");
  163581. *mod_time = &(info_ptr->mod_time);
  163582. return (PNG_INFO_tIME);
  163583. }
  163584. return (0);
  163585. }
  163586. #endif
  163587. #if defined(PNG_tRNS_SUPPORTED)
  163588. png_uint_32 PNGAPI
  163589. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  163590. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  163591. {
  163592. png_uint_32 retval = 0;
  163593. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  163594. {
  163595. png_debug1(1, "in %s retrieval function\n", "tRNS");
  163596. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  163597. {
  163598. if (trans != NULL)
  163599. {
  163600. *trans = info_ptr->trans;
  163601. retval |= PNG_INFO_tRNS;
  163602. }
  163603. if (trans_values != NULL)
  163604. *trans_values = &(info_ptr->trans_values);
  163605. }
  163606. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  163607. {
  163608. if (trans_values != NULL)
  163609. {
  163610. *trans_values = &(info_ptr->trans_values);
  163611. retval |= PNG_INFO_tRNS;
  163612. }
  163613. if(trans != NULL)
  163614. *trans = NULL;
  163615. }
  163616. if(num_trans != NULL)
  163617. {
  163618. *num_trans = info_ptr->num_trans;
  163619. retval |= PNG_INFO_tRNS;
  163620. }
  163621. }
  163622. return (retval);
  163623. }
  163624. #endif
  163625. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  163626. png_uint_32 PNGAPI
  163627. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  163628. png_unknown_chunkpp unknowns)
  163629. {
  163630. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  163631. {
  163632. *unknowns = info_ptr->unknown_chunks;
  163633. return ((png_uint_32)info_ptr->unknown_chunks_num);
  163634. }
  163635. return (0);
  163636. }
  163637. #endif
  163638. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  163639. png_byte PNGAPI
  163640. png_get_rgb_to_gray_status (png_structp png_ptr)
  163641. {
  163642. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  163643. }
  163644. #endif
  163645. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  163646. png_voidp PNGAPI
  163647. png_get_user_chunk_ptr(png_structp png_ptr)
  163648. {
  163649. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  163650. }
  163651. #endif
  163652. #ifdef PNG_WRITE_SUPPORTED
  163653. png_uint_32 PNGAPI
  163654. png_get_compression_buffer_size(png_structp png_ptr)
  163655. {
  163656. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  163657. }
  163658. #endif
  163659. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  163660. #ifndef PNG_1_0_X
  163661. png_uint_32 PNGAPI
  163662. png_get_asm_flags (png_structp png_ptr)
  163663. {
  163664. return (png_ptr? 0L: 0L);
  163665. }
  163666. png_uint_32 PNGAPI
  163667. png_get_asm_flagmask (int flag_select)
  163668. {
  163669. flag_select=flag_select;
  163670. return 0L;
  163671. }
  163672. png_uint_32 PNGAPI
  163673. png_get_mmx_flagmask (int flag_select, int *compilerID)
  163674. {
  163675. flag_select=flag_select;
  163676. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  163677. return 0L;
  163678. }
  163679. png_byte PNGAPI
  163680. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  163681. {
  163682. return (png_ptr? 0: 0);
  163683. }
  163684. png_uint_32 PNGAPI
  163685. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  163686. {
  163687. return (png_ptr? 0L: 0L);
  163688. }
  163689. #endif /* ?PNG_1_0_X */
  163690. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  163691. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  163692. png_uint_32 PNGAPI
  163693. png_get_user_width_max (png_structp png_ptr)
  163694. {
  163695. return (png_ptr? png_ptr->user_width_max : 0);
  163696. }
  163697. png_uint_32 PNGAPI
  163698. png_get_user_height_max (png_structp png_ptr)
  163699. {
  163700. return (png_ptr? png_ptr->user_height_max : 0);
  163701. }
  163702. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  163703. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163704. /*** End of inlined file: pngget.c ***/
  163705. /*** Start of inlined file: pngmem.c ***/
  163706. #define PNG_INTERNAL
  163707. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163708. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  163709. png_voidp /* PRIVATE */
  163710. png_create_struct(int type)
  163711. {
  163712. #ifdef PNG_USER_MEM_SUPPORTED
  163713. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163714. }
  163715. png_voidp /* PRIVATE */
  163716. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163717. {
  163718. #endif /* PNG_USER_MEM_SUPPORTED */
  163719. png_size_t size;
  163720. png_voidp struct_ptr;
  163721. if (type == PNG_STRUCT_INFO)
  163722. size = png_sizeof(png_info);
  163723. else if (type == PNG_STRUCT_PNG)
  163724. size = png_sizeof(png_struct);
  163725. else
  163726. return (png_get_copyright(NULL));
  163727. #ifdef PNG_USER_MEM_SUPPORTED
  163728. if(malloc_fn != NULL)
  163729. {
  163730. png_struct dummy_struct;
  163731. png_structp png_ptr = &dummy_struct;
  163732. png_ptr->mem_ptr=mem_ptr;
  163733. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  163734. }
  163735. else
  163736. #endif /* PNG_USER_MEM_SUPPORTED */
  163737. struct_ptr = (png_voidp)farmalloc(size);
  163738. if (struct_ptr != NULL)
  163739. png_memset(struct_ptr, 0, size);
  163740. return (struct_ptr);
  163741. }
  163742. void /* PRIVATE */
  163743. png_destroy_struct(png_voidp struct_ptr)
  163744. {
  163745. #ifdef PNG_USER_MEM_SUPPORTED
  163746. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163747. }
  163748. void /* PRIVATE */
  163749. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163750. png_voidp mem_ptr)
  163751. {
  163752. #endif
  163753. if (struct_ptr != NULL)
  163754. {
  163755. #ifdef PNG_USER_MEM_SUPPORTED
  163756. if(free_fn != NULL)
  163757. {
  163758. png_struct dummy_struct;
  163759. png_structp png_ptr = &dummy_struct;
  163760. png_ptr->mem_ptr=mem_ptr;
  163761. (*(free_fn))(png_ptr, struct_ptr);
  163762. return;
  163763. }
  163764. #endif /* PNG_USER_MEM_SUPPORTED */
  163765. farfree (struct_ptr);
  163766. }
  163767. }
  163768. png_voidp PNGAPI
  163769. png_malloc(png_structp png_ptr, png_uint_32 size)
  163770. {
  163771. png_voidp ret;
  163772. if (png_ptr == NULL || size == 0)
  163773. return (NULL);
  163774. #ifdef PNG_USER_MEM_SUPPORTED
  163775. if(png_ptr->malloc_fn != NULL)
  163776. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  163777. else
  163778. ret = (png_malloc_default(png_ptr, size));
  163779. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163780. png_error(png_ptr, "Out of memory!");
  163781. return (ret);
  163782. }
  163783. png_voidp PNGAPI
  163784. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  163785. {
  163786. png_voidp ret;
  163787. #endif /* PNG_USER_MEM_SUPPORTED */
  163788. if (png_ptr == NULL || size == 0)
  163789. return (NULL);
  163790. #ifdef PNG_MAX_MALLOC_64K
  163791. if (size > (png_uint_32)65536L)
  163792. {
  163793. png_warning(png_ptr, "Cannot Allocate > 64K");
  163794. ret = NULL;
  163795. }
  163796. else
  163797. #endif
  163798. if (size != (size_t)size)
  163799. ret = NULL;
  163800. else if (size == (png_uint_32)65536L)
  163801. {
  163802. if (png_ptr->offset_table == NULL)
  163803. {
  163804. ret = farmalloc(size);
  163805. if (ret == NULL || ((png_size_t)ret & 0xffff))
  163806. {
  163807. int num_blocks;
  163808. png_uint_32 total_size;
  163809. png_bytep table;
  163810. int i;
  163811. png_byte huge * hptr;
  163812. if (ret != NULL)
  163813. {
  163814. farfree(ret);
  163815. ret = NULL;
  163816. }
  163817. if(png_ptr->zlib_window_bits > 14)
  163818. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  163819. else
  163820. num_blocks = 1;
  163821. if (png_ptr->zlib_mem_level >= 7)
  163822. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  163823. else
  163824. num_blocks++;
  163825. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  163826. table = farmalloc(total_size);
  163827. if (table == NULL)
  163828. {
  163829. #ifndef PNG_USER_MEM_SUPPORTED
  163830. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163831. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  163832. else
  163833. png_warning(png_ptr, "Out Of Memory.");
  163834. #endif
  163835. return (NULL);
  163836. }
  163837. if ((png_size_t)table & 0xfff0)
  163838. {
  163839. #ifndef PNG_USER_MEM_SUPPORTED
  163840. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163841. png_error(png_ptr,
  163842. "Farmalloc didn't return normalized pointer");
  163843. else
  163844. png_warning(png_ptr,
  163845. "Farmalloc didn't return normalized pointer");
  163846. #endif
  163847. return (NULL);
  163848. }
  163849. png_ptr->offset_table = table;
  163850. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  163851. png_sizeof (png_bytep));
  163852. if (png_ptr->offset_table_ptr == NULL)
  163853. {
  163854. #ifndef PNG_USER_MEM_SUPPORTED
  163855. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163856. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  163857. else
  163858. png_warning(png_ptr, "Out Of memory.");
  163859. #endif
  163860. return (NULL);
  163861. }
  163862. hptr = (png_byte huge *)table;
  163863. if ((png_size_t)hptr & 0xf)
  163864. {
  163865. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  163866. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  163867. }
  163868. for (i = 0; i < num_blocks; i++)
  163869. {
  163870. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  163871. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  163872. }
  163873. png_ptr->offset_table_number = num_blocks;
  163874. png_ptr->offset_table_count = 0;
  163875. png_ptr->offset_table_count_free = 0;
  163876. }
  163877. }
  163878. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  163879. {
  163880. #ifndef PNG_USER_MEM_SUPPORTED
  163881. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163882. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  163883. else
  163884. png_warning(png_ptr, "Out of Memory.");
  163885. #endif
  163886. return (NULL);
  163887. }
  163888. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  163889. }
  163890. else
  163891. ret = farmalloc(size);
  163892. #ifndef PNG_USER_MEM_SUPPORTED
  163893. if (ret == NULL)
  163894. {
  163895. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  163896. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163897. else
  163898. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  163899. }
  163900. #endif
  163901. return (ret);
  163902. }
  163903. void PNGAPI
  163904. png_free(png_structp png_ptr, png_voidp ptr)
  163905. {
  163906. if (png_ptr == NULL || ptr == NULL)
  163907. return;
  163908. #ifdef PNG_USER_MEM_SUPPORTED
  163909. if (png_ptr->free_fn != NULL)
  163910. {
  163911. (*(png_ptr->free_fn))(png_ptr, ptr);
  163912. return;
  163913. }
  163914. else png_free_default(png_ptr, ptr);
  163915. }
  163916. void PNGAPI
  163917. png_free_default(png_structp png_ptr, png_voidp ptr)
  163918. {
  163919. #endif /* PNG_USER_MEM_SUPPORTED */
  163920. if(png_ptr == NULL) return;
  163921. if (png_ptr->offset_table != NULL)
  163922. {
  163923. int i;
  163924. for (i = 0; i < png_ptr->offset_table_count; i++)
  163925. {
  163926. if (ptr == png_ptr->offset_table_ptr[i])
  163927. {
  163928. ptr = NULL;
  163929. png_ptr->offset_table_count_free++;
  163930. break;
  163931. }
  163932. }
  163933. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  163934. {
  163935. farfree(png_ptr->offset_table);
  163936. farfree(png_ptr->offset_table_ptr);
  163937. png_ptr->offset_table = NULL;
  163938. png_ptr->offset_table_ptr = NULL;
  163939. }
  163940. }
  163941. if (ptr != NULL)
  163942. {
  163943. farfree(ptr);
  163944. }
  163945. }
  163946. #else /* Not the Borland DOS special memory handler */
  163947. png_voidp /* PRIVATE */
  163948. png_create_struct(int type)
  163949. {
  163950. #ifdef PNG_USER_MEM_SUPPORTED
  163951. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  163952. }
  163953. png_voidp /* PRIVATE */
  163954. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  163955. {
  163956. #endif /* PNG_USER_MEM_SUPPORTED */
  163957. png_size_t size;
  163958. png_voidp struct_ptr;
  163959. if (type == PNG_STRUCT_INFO)
  163960. size = png_sizeof(png_info);
  163961. else if (type == PNG_STRUCT_PNG)
  163962. size = png_sizeof(png_struct);
  163963. else
  163964. return (NULL);
  163965. #ifdef PNG_USER_MEM_SUPPORTED
  163966. if(malloc_fn != NULL)
  163967. {
  163968. png_struct dummy_struct;
  163969. png_structp png_ptr = &dummy_struct;
  163970. png_ptr->mem_ptr=mem_ptr;
  163971. struct_ptr = (*(malloc_fn))(png_ptr, size);
  163972. if (struct_ptr != NULL)
  163973. png_memset(struct_ptr, 0, size);
  163974. return (struct_ptr);
  163975. }
  163976. #endif /* PNG_USER_MEM_SUPPORTED */
  163977. #if defined(__TURBOC__) && !defined(__FLAT__)
  163978. struct_ptr = (png_voidp)farmalloc(size);
  163979. #else
  163980. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  163981. struct_ptr = (png_voidp)halloc(size,1);
  163982. # else
  163983. struct_ptr = (png_voidp)malloc(size);
  163984. # endif
  163985. #endif
  163986. if (struct_ptr != NULL)
  163987. png_memset(struct_ptr, 0, size);
  163988. return (struct_ptr);
  163989. }
  163990. void /* PRIVATE */
  163991. png_destroy_struct(png_voidp struct_ptr)
  163992. {
  163993. #ifdef PNG_USER_MEM_SUPPORTED
  163994. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  163995. }
  163996. void /* PRIVATE */
  163997. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  163998. png_voidp mem_ptr)
  163999. {
  164000. #endif /* PNG_USER_MEM_SUPPORTED */
  164001. if (struct_ptr != NULL)
  164002. {
  164003. #ifdef PNG_USER_MEM_SUPPORTED
  164004. if(free_fn != NULL)
  164005. {
  164006. png_struct dummy_struct;
  164007. png_structp png_ptr = &dummy_struct;
  164008. png_ptr->mem_ptr=mem_ptr;
  164009. (*(free_fn))(png_ptr, struct_ptr);
  164010. return;
  164011. }
  164012. #endif /* PNG_USER_MEM_SUPPORTED */
  164013. #if defined(__TURBOC__) && !defined(__FLAT__)
  164014. farfree(struct_ptr);
  164015. #else
  164016. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164017. hfree(struct_ptr);
  164018. # else
  164019. free(struct_ptr);
  164020. # endif
  164021. #endif
  164022. }
  164023. }
  164024. png_voidp PNGAPI
  164025. png_malloc(png_structp png_ptr, png_uint_32 size)
  164026. {
  164027. png_voidp ret;
  164028. #ifdef PNG_USER_MEM_SUPPORTED
  164029. if (png_ptr == NULL || size == 0)
  164030. return (NULL);
  164031. if(png_ptr->malloc_fn != NULL)
  164032. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164033. else
  164034. ret = (png_malloc_default(png_ptr, size));
  164035. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164036. png_error(png_ptr, "Out of Memory!");
  164037. return (ret);
  164038. }
  164039. png_voidp PNGAPI
  164040. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164041. {
  164042. png_voidp ret;
  164043. #endif /* PNG_USER_MEM_SUPPORTED */
  164044. if (png_ptr == NULL || size == 0)
  164045. return (NULL);
  164046. #ifdef PNG_MAX_MALLOC_64K
  164047. if (size > (png_uint_32)65536L)
  164048. {
  164049. #ifndef PNG_USER_MEM_SUPPORTED
  164050. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164051. png_error(png_ptr, "Cannot Allocate > 64K");
  164052. else
  164053. #endif
  164054. return NULL;
  164055. }
  164056. #endif
  164057. #if defined(__TURBOC__) && !defined(__FLAT__)
  164058. if (size != (unsigned long)size)
  164059. ret = NULL;
  164060. else
  164061. ret = farmalloc(size);
  164062. #else
  164063. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164064. if (size != (unsigned long)size)
  164065. ret = NULL;
  164066. else
  164067. ret = halloc(size, 1);
  164068. # else
  164069. if (size != (size_t)size)
  164070. ret = NULL;
  164071. else
  164072. ret = malloc((size_t)size);
  164073. # endif
  164074. #endif
  164075. #ifndef PNG_USER_MEM_SUPPORTED
  164076. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164077. png_error(png_ptr, "Out of Memory");
  164078. #endif
  164079. return (ret);
  164080. }
  164081. void PNGAPI
  164082. png_free(png_structp png_ptr, png_voidp ptr)
  164083. {
  164084. if (png_ptr == NULL || ptr == NULL)
  164085. return;
  164086. #ifdef PNG_USER_MEM_SUPPORTED
  164087. if (png_ptr->free_fn != NULL)
  164088. {
  164089. (*(png_ptr->free_fn))(png_ptr, ptr);
  164090. return;
  164091. }
  164092. else png_free_default(png_ptr, ptr);
  164093. }
  164094. void PNGAPI
  164095. png_free_default(png_structp png_ptr, png_voidp ptr)
  164096. {
  164097. if (png_ptr == NULL || ptr == NULL)
  164098. return;
  164099. #endif /* PNG_USER_MEM_SUPPORTED */
  164100. #if defined(__TURBOC__) && !defined(__FLAT__)
  164101. farfree(ptr);
  164102. #else
  164103. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164104. hfree(ptr);
  164105. # else
  164106. free(ptr);
  164107. # endif
  164108. #endif
  164109. }
  164110. #endif /* Not Borland DOS special memory handler */
  164111. #if defined(PNG_1_0_X)
  164112. # define png_malloc_warn png_malloc
  164113. #else
  164114. png_voidp PNGAPI
  164115. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164116. {
  164117. png_voidp ptr;
  164118. png_uint_32 save_flags;
  164119. if(png_ptr == NULL) return (NULL);
  164120. save_flags=png_ptr->flags;
  164121. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164122. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164123. png_ptr->flags=save_flags;
  164124. return(ptr);
  164125. }
  164126. #endif
  164127. png_voidp PNGAPI
  164128. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164129. png_uint_32 length)
  164130. {
  164131. png_size_t size;
  164132. size = (png_size_t)length;
  164133. if ((png_uint_32)size != length)
  164134. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164135. return(png_memcpy (s1, s2, size));
  164136. }
  164137. png_voidp PNGAPI
  164138. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164139. png_uint_32 length)
  164140. {
  164141. png_size_t size;
  164142. size = (png_size_t)length;
  164143. if ((png_uint_32)size != length)
  164144. png_error(png_ptr,"Overflow in png_memset_check.");
  164145. return (png_memset (s1, value, size));
  164146. }
  164147. #ifdef PNG_USER_MEM_SUPPORTED
  164148. void PNGAPI
  164149. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164150. malloc_fn, png_free_ptr free_fn)
  164151. {
  164152. if(png_ptr != NULL) {
  164153. png_ptr->mem_ptr = mem_ptr;
  164154. png_ptr->malloc_fn = malloc_fn;
  164155. png_ptr->free_fn = free_fn;
  164156. }
  164157. }
  164158. png_voidp PNGAPI
  164159. png_get_mem_ptr(png_structp png_ptr)
  164160. {
  164161. if(png_ptr == NULL) return (NULL);
  164162. return ((png_voidp)png_ptr->mem_ptr);
  164163. }
  164164. #endif /* PNG_USER_MEM_SUPPORTED */
  164165. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164166. /*** End of inlined file: pngmem.c ***/
  164167. /*** Start of inlined file: pngread.c ***/
  164168. #define PNG_INTERNAL
  164169. #if defined(PNG_READ_SUPPORTED)
  164170. png_structp PNGAPI
  164171. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164172. png_error_ptr error_fn, png_error_ptr warn_fn)
  164173. {
  164174. #ifdef PNG_USER_MEM_SUPPORTED
  164175. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164176. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164177. }
  164178. png_structp PNGAPI
  164179. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164180. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164181. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164182. {
  164183. #endif /* PNG_USER_MEM_SUPPORTED */
  164184. png_structp png_ptr;
  164185. #ifdef PNG_SETJMP_SUPPORTED
  164186. #ifdef USE_FAR_KEYWORD
  164187. jmp_buf jmpbuf;
  164188. #endif
  164189. #endif
  164190. int i;
  164191. png_debug(1, "in png_create_read_struct\n");
  164192. #ifdef PNG_USER_MEM_SUPPORTED
  164193. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164194. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164195. #else
  164196. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164197. #endif
  164198. if (png_ptr == NULL)
  164199. return (NULL);
  164200. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164201. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164202. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164203. #endif
  164204. #ifdef PNG_SETJMP_SUPPORTED
  164205. #ifdef USE_FAR_KEYWORD
  164206. if (setjmp(jmpbuf))
  164207. #else
  164208. if (setjmp(png_ptr->jmpbuf))
  164209. #endif
  164210. {
  164211. png_free(png_ptr, png_ptr->zbuf);
  164212. png_ptr->zbuf=NULL;
  164213. #ifdef PNG_USER_MEM_SUPPORTED
  164214. png_destroy_struct_2((png_voidp)png_ptr,
  164215. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164216. #else
  164217. png_destroy_struct((png_voidp)png_ptr);
  164218. #endif
  164219. return (NULL);
  164220. }
  164221. #ifdef USE_FAR_KEYWORD
  164222. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164223. #endif
  164224. #endif
  164225. #ifdef PNG_USER_MEM_SUPPORTED
  164226. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164227. #endif
  164228. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164229. i=0;
  164230. do
  164231. {
  164232. if(user_png_ver[i] != png_libpng_ver[i])
  164233. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164234. } while (png_libpng_ver[i++]);
  164235. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164236. {
  164237. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164238. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164239. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164240. {
  164241. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164242. char msg[80];
  164243. if (user_png_ver)
  164244. {
  164245. png_snprintf(msg, 80,
  164246. "Application was compiled with png.h from libpng-%.20s",
  164247. user_png_ver);
  164248. png_warning(png_ptr, msg);
  164249. }
  164250. png_snprintf(msg, 80,
  164251. "Application is running with png.c from libpng-%.20s",
  164252. png_libpng_ver);
  164253. png_warning(png_ptr, msg);
  164254. #endif
  164255. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164256. png_ptr->flags=0;
  164257. #endif
  164258. png_error(png_ptr,
  164259. "Incompatible libpng version in application and library");
  164260. }
  164261. }
  164262. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164263. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164264. (png_uint_32)png_ptr->zbuf_size);
  164265. png_ptr->zstream.zalloc = png_zalloc;
  164266. png_ptr->zstream.zfree = png_zfree;
  164267. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164268. switch (inflateInit(&png_ptr->zstream))
  164269. {
  164270. case Z_OK: /* Do nothing */ break;
  164271. case Z_MEM_ERROR:
  164272. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164273. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164274. default: png_error(png_ptr, "Unknown zlib error");
  164275. }
  164276. png_ptr->zstream.next_out = png_ptr->zbuf;
  164277. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164278. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164279. #ifdef PNG_SETJMP_SUPPORTED
  164280. #ifdef USE_FAR_KEYWORD
  164281. if (setjmp(jmpbuf))
  164282. PNG_ABORT();
  164283. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164284. #else
  164285. if (setjmp(png_ptr->jmpbuf))
  164286. PNG_ABORT();
  164287. #endif
  164288. #endif
  164289. return (png_ptr);
  164290. }
  164291. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164292. #undef png_read_init
  164293. void PNGAPI
  164294. png_read_init(png_structp png_ptr)
  164295. {
  164296. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164297. }
  164298. void PNGAPI
  164299. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164300. png_size_t png_struct_size, png_size_t png_info_size)
  164301. {
  164302. if(png_ptr == NULL) return;
  164303. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164304. if(png_sizeof(png_struct) > png_struct_size ||
  164305. png_sizeof(png_info) > png_info_size)
  164306. {
  164307. char msg[80];
  164308. png_ptr->warning_fn=NULL;
  164309. if (user_png_ver)
  164310. {
  164311. png_snprintf(msg, 80,
  164312. "Application was compiled with png.h from libpng-%.20s",
  164313. user_png_ver);
  164314. png_warning(png_ptr, msg);
  164315. }
  164316. png_snprintf(msg, 80,
  164317. "Application is running with png.c from libpng-%.20s",
  164318. png_libpng_ver);
  164319. png_warning(png_ptr, msg);
  164320. }
  164321. #endif
  164322. if(png_sizeof(png_struct) > png_struct_size)
  164323. {
  164324. png_ptr->error_fn=NULL;
  164325. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164326. png_ptr->flags=0;
  164327. #endif
  164328. png_error(png_ptr,
  164329. "The png struct allocated by the application for reading is too small.");
  164330. }
  164331. if(png_sizeof(png_info) > png_info_size)
  164332. {
  164333. png_ptr->error_fn=NULL;
  164334. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164335. png_ptr->flags=0;
  164336. #endif
  164337. png_error(png_ptr,
  164338. "The info struct allocated by application for reading is too small.");
  164339. }
  164340. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164341. }
  164342. #endif /* PNG_1_0_X || PNG_1_2_X */
  164343. void PNGAPI
  164344. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164345. png_size_t png_struct_size)
  164346. {
  164347. #ifdef PNG_SETJMP_SUPPORTED
  164348. jmp_buf tmp_jmp; /* to save current jump buffer */
  164349. #endif
  164350. int i=0;
  164351. png_structp png_ptr=*ptr_ptr;
  164352. if(png_ptr == NULL) return;
  164353. do
  164354. {
  164355. if(user_png_ver[i] != png_libpng_ver[i])
  164356. {
  164357. #ifdef PNG_LEGACY_SUPPORTED
  164358. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164359. #else
  164360. png_ptr->warning_fn=NULL;
  164361. png_warning(png_ptr,
  164362. "Application uses deprecated png_read_init() and should be recompiled.");
  164363. break;
  164364. #endif
  164365. }
  164366. } while (png_libpng_ver[i++]);
  164367. png_debug(1, "in png_read_init_3\n");
  164368. #ifdef PNG_SETJMP_SUPPORTED
  164369. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164370. #endif
  164371. if(png_sizeof(png_struct) > png_struct_size)
  164372. {
  164373. png_destroy_struct(png_ptr);
  164374. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164375. png_ptr = *ptr_ptr;
  164376. }
  164377. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164378. #ifdef PNG_SETJMP_SUPPORTED
  164379. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164380. #endif
  164381. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164382. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164383. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164384. #endif
  164385. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164386. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164387. (png_uint_32)png_ptr->zbuf_size);
  164388. png_ptr->zstream.zalloc = png_zalloc;
  164389. png_ptr->zstream.zfree = png_zfree;
  164390. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164391. switch (inflateInit(&png_ptr->zstream))
  164392. {
  164393. case Z_OK: /* Do nothing */ break;
  164394. case Z_MEM_ERROR:
  164395. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164396. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164397. default: png_error(png_ptr, "Unknown zlib error");
  164398. }
  164399. png_ptr->zstream.next_out = png_ptr->zbuf;
  164400. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164401. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164402. }
  164403. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164404. void PNGAPI
  164405. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164406. {
  164407. if(png_ptr == NULL) return;
  164408. png_debug(1, "in png_read_info\n");
  164409. if (png_ptr->sig_bytes < 8)
  164410. {
  164411. png_size_t num_checked = png_ptr->sig_bytes,
  164412. num_to_check = 8 - num_checked;
  164413. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164414. png_ptr->sig_bytes = 8;
  164415. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164416. {
  164417. if (num_checked < 4 &&
  164418. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164419. png_error(png_ptr, "Not a PNG file");
  164420. else
  164421. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164422. }
  164423. if (num_checked < 3)
  164424. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164425. }
  164426. for(;;)
  164427. {
  164428. #ifdef PNG_USE_LOCAL_ARRAYS
  164429. PNG_CONST PNG_IHDR;
  164430. PNG_CONST PNG_IDAT;
  164431. PNG_CONST PNG_IEND;
  164432. PNG_CONST PNG_PLTE;
  164433. #if defined(PNG_READ_bKGD_SUPPORTED)
  164434. PNG_CONST PNG_bKGD;
  164435. #endif
  164436. #if defined(PNG_READ_cHRM_SUPPORTED)
  164437. PNG_CONST PNG_cHRM;
  164438. #endif
  164439. #if defined(PNG_READ_gAMA_SUPPORTED)
  164440. PNG_CONST PNG_gAMA;
  164441. #endif
  164442. #if defined(PNG_READ_hIST_SUPPORTED)
  164443. PNG_CONST PNG_hIST;
  164444. #endif
  164445. #if defined(PNG_READ_iCCP_SUPPORTED)
  164446. PNG_CONST PNG_iCCP;
  164447. #endif
  164448. #if defined(PNG_READ_iTXt_SUPPORTED)
  164449. PNG_CONST PNG_iTXt;
  164450. #endif
  164451. #if defined(PNG_READ_oFFs_SUPPORTED)
  164452. PNG_CONST PNG_oFFs;
  164453. #endif
  164454. #if defined(PNG_READ_pCAL_SUPPORTED)
  164455. PNG_CONST PNG_pCAL;
  164456. #endif
  164457. #if defined(PNG_READ_pHYs_SUPPORTED)
  164458. PNG_CONST PNG_pHYs;
  164459. #endif
  164460. #if defined(PNG_READ_sBIT_SUPPORTED)
  164461. PNG_CONST PNG_sBIT;
  164462. #endif
  164463. #if defined(PNG_READ_sCAL_SUPPORTED)
  164464. PNG_CONST PNG_sCAL;
  164465. #endif
  164466. #if defined(PNG_READ_sPLT_SUPPORTED)
  164467. PNG_CONST PNG_sPLT;
  164468. #endif
  164469. #if defined(PNG_READ_sRGB_SUPPORTED)
  164470. PNG_CONST PNG_sRGB;
  164471. #endif
  164472. #if defined(PNG_READ_tEXt_SUPPORTED)
  164473. PNG_CONST PNG_tEXt;
  164474. #endif
  164475. #if defined(PNG_READ_tIME_SUPPORTED)
  164476. PNG_CONST PNG_tIME;
  164477. #endif
  164478. #if defined(PNG_READ_tRNS_SUPPORTED)
  164479. PNG_CONST PNG_tRNS;
  164480. #endif
  164481. #if defined(PNG_READ_zTXt_SUPPORTED)
  164482. PNG_CONST PNG_zTXt;
  164483. #endif
  164484. #endif /* PNG_USE_LOCAL_ARRAYS */
  164485. png_byte chunk_length[4];
  164486. png_uint_32 length;
  164487. png_read_data(png_ptr, chunk_length, 4);
  164488. length = png_get_uint_31(png_ptr,chunk_length);
  164489. png_reset_crc(png_ptr);
  164490. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164491. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164492. length);
  164493. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164494. if(png_ptr->mode & PNG_AFTER_IDAT)
  164495. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164496. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164497. png_handle_IHDR(png_ptr, info_ptr, length);
  164498. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164499. png_handle_IEND(png_ptr, info_ptr, length);
  164500. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164501. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164502. {
  164503. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164504. png_ptr->mode |= PNG_HAVE_IDAT;
  164505. png_handle_unknown(png_ptr, info_ptr, length);
  164506. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164507. png_ptr->mode |= PNG_HAVE_PLTE;
  164508. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164509. {
  164510. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164511. png_error(png_ptr, "Missing IHDR before IDAT");
  164512. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164513. !(png_ptr->mode & PNG_HAVE_PLTE))
  164514. png_error(png_ptr, "Missing PLTE before IDAT");
  164515. break;
  164516. }
  164517. }
  164518. #endif
  164519. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164520. png_handle_PLTE(png_ptr, info_ptr, length);
  164521. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164522. {
  164523. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164524. png_error(png_ptr, "Missing IHDR before IDAT");
  164525. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164526. !(png_ptr->mode & PNG_HAVE_PLTE))
  164527. png_error(png_ptr, "Missing PLTE before IDAT");
  164528. png_ptr->idat_size = length;
  164529. png_ptr->mode |= PNG_HAVE_IDAT;
  164530. break;
  164531. }
  164532. #if defined(PNG_READ_bKGD_SUPPORTED)
  164533. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  164534. png_handle_bKGD(png_ptr, info_ptr, length);
  164535. #endif
  164536. #if defined(PNG_READ_cHRM_SUPPORTED)
  164537. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  164538. png_handle_cHRM(png_ptr, info_ptr, length);
  164539. #endif
  164540. #if defined(PNG_READ_gAMA_SUPPORTED)
  164541. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  164542. png_handle_gAMA(png_ptr, info_ptr, length);
  164543. #endif
  164544. #if defined(PNG_READ_hIST_SUPPORTED)
  164545. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  164546. png_handle_hIST(png_ptr, info_ptr, length);
  164547. #endif
  164548. #if defined(PNG_READ_oFFs_SUPPORTED)
  164549. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  164550. png_handle_oFFs(png_ptr, info_ptr, length);
  164551. #endif
  164552. #if defined(PNG_READ_pCAL_SUPPORTED)
  164553. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  164554. png_handle_pCAL(png_ptr, info_ptr, length);
  164555. #endif
  164556. #if defined(PNG_READ_sCAL_SUPPORTED)
  164557. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  164558. png_handle_sCAL(png_ptr, info_ptr, length);
  164559. #endif
  164560. #if defined(PNG_READ_pHYs_SUPPORTED)
  164561. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  164562. png_handle_pHYs(png_ptr, info_ptr, length);
  164563. #endif
  164564. #if defined(PNG_READ_sBIT_SUPPORTED)
  164565. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  164566. png_handle_sBIT(png_ptr, info_ptr, length);
  164567. #endif
  164568. #if defined(PNG_READ_sRGB_SUPPORTED)
  164569. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  164570. png_handle_sRGB(png_ptr, info_ptr, length);
  164571. #endif
  164572. #if defined(PNG_READ_iCCP_SUPPORTED)
  164573. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  164574. png_handle_iCCP(png_ptr, info_ptr, length);
  164575. #endif
  164576. #if defined(PNG_READ_sPLT_SUPPORTED)
  164577. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  164578. png_handle_sPLT(png_ptr, info_ptr, length);
  164579. #endif
  164580. #if defined(PNG_READ_tEXt_SUPPORTED)
  164581. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  164582. png_handle_tEXt(png_ptr, info_ptr, length);
  164583. #endif
  164584. #if defined(PNG_READ_tIME_SUPPORTED)
  164585. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  164586. png_handle_tIME(png_ptr, info_ptr, length);
  164587. #endif
  164588. #if defined(PNG_READ_tRNS_SUPPORTED)
  164589. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  164590. png_handle_tRNS(png_ptr, info_ptr, length);
  164591. #endif
  164592. #if defined(PNG_READ_zTXt_SUPPORTED)
  164593. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  164594. png_handle_zTXt(png_ptr, info_ptr, length);
  164595. #endif
  164596. #if defined(PNG_READ_iTXt_SUPPORTED)
  164597. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  164598. png_handle_iTXt(png_ptr, info_ptr, length);
  164599. #endif
  164600. else
  164601. png_handle_unknown(png_ptr, info_ptr, length);
  164602. }
  164603. }
  164604. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164605. void PNGAPI
  164606. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  164607. {
  164608. png_debug(1, "in png_read_update_info\n");
  164609. if(png_ptr == NULL) return;
  164610. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164611. png_read_start_row(png_ptr);
  164612. else
  164613. png_warning(png_ptr,
  164614. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  164615. png_read_transform_info(png_ptr, info_ptr);
  164616. }
  164617. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164618. void PNGAPI
  164619. png_start_read_image(png_structp png_ptr)
  164620. {
  164621. png_debug(1, "in png_start_read_image\n");
  164622. if(png_ptr == NULL) return;
  164623. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164624. png_read_start_row(png_ptr);
  164625. }
  164626. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164627. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164628. void PNGAPI
  164629. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  164630. {
  164631. #ifdef PNG_USE_LOCAL_ARRAYS
  164632. PNG_CONST PNG_IDAT;
  164633. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  164634. 0xff};
  164635. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  164636. #endif
  164637. int ret;
  164638. if(png_ptr == NULL) return;
  164639. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  164640. png_ptr->row_number, png_ptr->pass);
  164641. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  164642. png_read_start_row(png_ptr);
  164643. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  164644. {
  164645. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  164646. if (png_ptr->transformations & PNG_INVERT_MONO)
  164647. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  164648. #endif
  164649. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  164650. if (png_ptr->transformations & PNG_FILLER)
  164651. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  164652. #endif
  164653. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  164654. if (png_ptr->transformations & PNG_PACKSWAP)
  164655. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  164656. #endif
  164657. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  164658. if (png_ptr->transformations & PNG_PACK)
  164659. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  164660. #endif
  164661. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  164662. if (png_ptr->transformations & PNG_SHIFT)
  164663. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  164664. #endif
  164665. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  164666. if (png_ptr->transformations & PNG_BGR)
  164667. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  164668. #endif
  164669. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  164670. if (png_ptr->transformations & PNG_SWAP_BYTES)
  164671. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  164672. #endif
  164673. }
  164674. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164675. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  164676. {
  164677. switch (png_ptr->pass)
  164678. {
  164679. case 0:
  164680. if (png_ptr->row_number & 0x07)
  164681. {
  164682. if (dsp_row != NULL)
  164683. png_combine_row(png_ptr, dsp_row,
  164684. png_pass_dsp_mask[png_ptr->pass]);
  164685. png_read_finish_row(png_ptr);
  164686. return;
  164687. }
  164688. break;
  164689. case 1:
  164690. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  164691. {
  164692. if (dsp_row != NULL)
  164693. png_combine_row(png_ptr, dsp_row,
  164694. png_pass_dsp_mask[png_ptr->pass]);
  164695. png_read_finish_row(png_ptr);
  164696. return;
  164697. }
  164698. break;
  164699. case 2:
  164700. if ((png_ptr->row_number & 0x07) != 4)
  164701. {
  164702. if (dsp_row != NULL && (png_ptr->row_number & 4))
  164703. png_combine_row(png_ptr, dsp_row,
  164704. png_pass_dsp_mask[png_ptr->pass]);
  164705. png_read_finish_row(png_ptr);
  164706. return;
  164707. }
  164708. break;
  164709. case 3:
  164710. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  164711. {
  164712. if (dsp_row != NULL)
  164713. png_combine_row(png_ptr, dsp_row,
  164714. png_pass_dsp_mask[png_ptr->pass]);
  164715. png_read_finish_row(png_ptr);
  164716. return;
  164717. }
  164718. break;
  164719. case 4:
  164720. if ((png_ptr->row_number & 3) != 2)
  164721. {
  164722. if (dsp_row != NULL && (png_ptr->row_number & 2))
  164723. png_combine_row(png_ptr, dsp_row,
  164724. png_pass_dsp_mask[png_ptr->pass]);
  164725. png_read_finish_row(png_ptr);
  164726. return;
  164727. }
  164728. break;
  164729. case 5:
  164730. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  164731. {
  164732. if (dsp_row != NULL)
  164733. png_combine_row(png_ptr, dsp_row,
  164734. png_pass_dsp_mask[png_ptr->pass]);
  164735. png_read_finish_row(png_ptr);
  164736. return;
  164737. }
  164738. break;
  164739. case 6:
  164740. if (!(png_ptr->row_number & 1))
  164741. {
  164742. png_read_finish_row(png_ptr);
  164743. return;
  164744. }
  164745. break;
  164746. }
  164747. }
  164748. #endif
  164749. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  164750. png_error(png_ptr, "Invalid attempt to read row data");
  164751. png_ptr->zstream.next_out = png_ptr->row_buf;
  164752. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  164753. do
  164754. {
  164755. if (!(png_ptr->zstream.avail_in))
  164756. {
  164757. while (!png_ptr->idat_size)
  164758. {
  164759. png_byte chunk_length[4];
  164760. png_crc_finish(png_ptr, 0);
  164761. png_read_data(png_ptr, chunk_length, 4);
  164762. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  164763. png_reset_crc(png_ptr);
  164764. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164765. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164766. png_error(png_ptr, "Not enough image data");
  164767. }
  164768. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  164769. png_ptr->zstream.next_in = png_ptr->zbuf;
  164770. if (png_ptr->zbuf_size > png_ptr->idat_size)
  164771. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  164772. png_crc_read(png_ptr, png_ptr->zbuf,
  164773. (png_size_t)png_ptr->zstream.avail_in);
  164774. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  164775. }
  164776. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  164777. if (ret == Z_STREAM_END)
  164778. {
  164779. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  164780. png_ptr->idat_size)
  164781. png_error(png_ptr, "Extra compressed data");
  164782. png_ptr->mode |= PNG_AFTER_IDAT;
  164783. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  164784. break;
  164785. }
  164786. if (ret != Z_OK)
  164787. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  164788. "Decompression error");
  164789. } while (png_ptr->zstream.avail_out);
  164790. png_ptr->row_info.color_type = png_ptr->color_type;
  164791. png_ptr->row_info.width = png_ptr->iwidth;
  164792. png_ptr->row_info.channels = png_ptr->channels;
  164793. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  164794. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  164795. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  164796. png_ptr->row_info.width);
  164797. if(png_ptr->row_buf[0])
  164798. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  164799. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  164800. (int)(png_ptr->row_buf[0]));
  164801. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  164802. png_ptr->rowbytes + 1);
  164803. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  164804. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  164805. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  164806. {
  164807. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  164808. }
  164809. #endif
  164810. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  164811. png_do_read_transformations(png_ptr);
  164812. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  164813. if (png_ptr->interlaced &&
  164814. (png_ptr->transformations & PNG_INTERLACE))
  164815. {
  164816. if (png_ptr->pass < 6)
  164817. png_do_read_interlace(png_ptr);
  164818. if (dsp_row != NULL)
  164819. png_combine_row(png_ptr, dsp_row,
  164820. png_pass_dsp_mask[png_ptr->pass]);
  164821. if (row != NULL)
  164822. png_combine_row(png_ptr, row,
  164823. png_pass_mask[png_ptr->pass]);
  164824. }
  164825. else
  164826. #endif
  164827. {
  164828. if (row != NULL)
  164829. png_combine_row(png_ptr, row, 0xff);
  164830. if (dsp_row != NULL)
  164831. png_combine_row(png_ptr, dsp_row, 0xff);
  164832. }
  164833. png_read_finish_row(png_ptr);
  164834. if (png_ptr->read_row_fn != NULL)
  164835. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  164836. }
  164837. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164838. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164839. void PNGAPI
  164840. png_read_rows(png_structp png_ptr, png_bytepp row,
  164841. png_bytepp display_row, png_uint_32 num_rows)
  164842. {
  164843. png_uint_32 i;
  164844. png_bytepp rp;
  164845. png_bytepp dp;
  164846. png_debug(1, "in png_read_rows\n");
  164847. if(png_ptr == NULL) return;
  164848. rp = row;
  164849. dp = display_row;
  164850. if (rp != NULL && dp != NULL)
  164851. for (i = 0; i < num_rows; i++)
  164852. {
  164853. png_bytep rptr = *rp++;
  164854. png_bytep dptr = *dp++;
  164855. png_read_row(png_ptr, rptr, dptr);
  164856. }
  164857. else if(rp != NULL)
  164858. for (i = 0; i < num_rows; i++)
  164859. {
  164860. png_bytep rptr = *rp;
  164861. png_read_row(png_ptr, rptr, png_bytep_NULL);
  164862. rp++;
  164863. }
  164864. else if(dp != NULL)
  164865. for (i = 0; i < num_rows; i++)
  164866. {
  164867. png_bytep dptr = *dp;
  164868. png_read_row(png_ptr, png_bytep_NULL, dptr);
  164869. dp++;
  164870. }
  164871. }
  164872. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164873. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164874. void PNGAPI
  164875. png_read_image(png_structp png_ptr, png_bytepp image)
  164876. {
  164877. png_uint_32 i,image_height;
  164878. int pass, j;
  164879. png_bytepp rp;
  164880. png_debug(1, "in png_read_image\n");
  164881. if(png_ptr == NULL) return;
  164882. #ifdef PNG_READ_INTERLACING_SUPPORTED
  164883. pass = png_set_interlace_handling(png_ptr);
  164884. #else
  164885. if (png_ptr->interlaced)
  164886. png_error(png_ptr,
  164887. "Cannot read interlaced image -- interlace handler disabled.");
  164888. pass = 1;
  164889. #endif
  164890. image_height=png_ptr->height;
  164891. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  164892. for (j = 0; j < pass; j++)
  164893. {
  164894. rp = image;
  164895. for (i = 0; i < image_height; i++)
  164896. {
  164897. png_read_row(png_ptr, *rp, png_bytep_NULL);
  164898. rp++;
  164899. }
  164900. }
  164901. }
  164902. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  164903. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164904. void PNGAPI
  164905. png_read_end(png_structp png_ptr, png_infop info_ptr)
  164906. {
  164907. png_byte chunk_length[4];
  164908. png_uint_32 length;
  164909. png_debug(1, "in png_read_end\n");
  164910. if(png_ptr == NULL) return;
  164911. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  164912. do
  164913. {
  164914. #ifdef PNG_USE_LOCAL_ARRAYS
  164915. PNG_CONST PNG_IHDR;
  164916. PNG_CONST PNG_IDAT;
  164917. PNG_CONST PNG_IEND;
  164918. PNG_CONST PNG_PLTE;
  164919. #if defined(PNG_READ_bKGD_SUPPORTED)
  164920. PNG_CONST PNG_bKGD;
  164921. #endif
  164922. #if defined(PNG_READ_cHRM_SUPPORTED)
  164923. PNG_CONST PNG_cHRM;
  164924. #endif
  164925. #if defined(PNG_READ_gAMA_SUPPORTED)
  164926. PNG_CONST PNG_gAMA;
  164927. #endif
  164928. #if defined(PNG_READ_hIST_SUPPORTED)
  164929. PNG_CONST PNG_hIST;
  164930. #endif
  164931. #if defined(PNG_READ_iCCP_SUPPORTED)
  164932. PNG_CONST PNG_iCCP;
  164933. #endif
  164934. #if defined(PNG_READ_iTXt_SUPPORTED)
  164935. PNG_CONST PNG_iTXt;
  164936. #endif
  164937. #if defined(PNG_READ_oFFs_SUPPORTED)
  164938. PNG_CONST PNG_oFFs;
  164939. #endif
  164940. #if defined(PNG_READ_pCAL_SUPPORTED)
  164941. PNG_CONST PNG_pCAL;
  164942. #endif
  164943. #if defined(PNG_READ_pHYs_SUPPORTED)
  164944. PNG_CONST PNG_pHYs;
  164945. #endif
  164946. #if defined(PNG_READ_sBIT_SUPPORTED)
  164947. PNG_CONST PNG_sBIT;
  164948. #endif
  164949. #if defined(PNG_READ_sCAL_SUPPORTED)
  164950. PNG_CONST PNG_sCAL;
  164951. #endif
  164952. #if defined(PNG_READ_sPLT_SUPPORTED)
  164953. PNG_CONST PNG_sPLT;
  164954. #endif
  164955. #if defined(PNG_READ_sRGB_SUPPORTED)
  164956. PNG_CONST PNG_sRGB;
  164957. #endif
  164958. #if defined(PNG_READ_tEXt_SUPPORTED)
  164959. PNG_CONST PNG_tEXt;
  164960. #endif
  164961. #if defined(PNG_READ_tIME_SUPPORTED)
  164962. PNG_CONST PNG_tIME;
  164963. #endif
  164964. #if defined(PNG_READ_tRNS_SUPPORTED)
  164965. PNG_CONST PNG_tRNS;
  164966. #endif
  164967. #if defined(PNG_READ_zTXt_SUPPORTED)
  164968. PNG_CONST PNG_zTXt;
  164969. #endif
  164970. #endif /* PNG_USE_LOCAL_ARRAYS */
  164971. png_read_data(png_ptr, chunk_length, 4);
  164972. length = png_get_uint_31(png_ptr,chunk_length);
  164973. png_reset_crc(png_ptr);
  164974. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164975. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  164976. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164977. png_handle_IHDR(png_ptr, info_ptr, length);
  164978. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164979. png_handle_IEND(png_ptr, info_ptr, length);
  164980. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164981. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164982. {
  164983. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164984. {
  164985. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  164986. png_error(png_ptr, "Too many IDAT's found");
  164987. }
  164988. png_handle_unknown(png_ptr, info_ptr, length);
  164989. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164990. png_ptr->mode |= PNG_HAVE_PLTE;
  164991. }
  164992. #endif
  164993. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164994. {
  164995. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  164996. png_error(png_ptr, "Too many IDAT's found");
  164997. png_crc_finish(png_ptr, length);
  164998. }
  164999. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165000. png_handle_PLTE(png_ptr, info_ptr, length);
  165001. #if defined(PNG_READ_bKGD_SUPPORTED)
  165002. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165003. png_handle_bKGD(png_ptr, info_ptr, length);
  165004. #endif
  165005. #if defined(PNG_READ_cHRM_SUPPORTED)
  165006. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165007. png_handle_cHRM(png_ptr, info_ptr, length);
  165008. #endif
  165009. #if defined(PNG_READ_gAMA_SUPPORTED)
  165010. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165011. png_handle_gAMA(png_ptr, info_ptr, length);
  165012. #endif
  165013. #if defined(PNG_READ_hIST_SUPPORTED)
  165014. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165015. png_handle_hIST(png_ptr, info_ptr, length);
  165016. #endif
  165017. #if defined(PNG_READ_oFFs_SUPPORTED)
  165018. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165019. png_handle_oFFs(png_ptr, info_ptr, length);
  165020. #endif
  165021. #if defined(PNG_READ_pCAL_SUPPORTED)
  165022. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165023. png_handle_pCAL(png_ptr, info_ptr, length);
  165024. #endif
  165025. #if defined(PNG_READ_sCAL_SUPPORTED)
  165026. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165027. png_handle_sCAL(png_ptr, info_ptr, length);
  165028. #endif
  165029. #if defined(PNG_READ_pHYs_SUPPORTED)
  165030. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165031. png_handle_pHYs(png_ptr, info_ptr, length);
  165032. #endif
  165033. #if defined(PNG_READ_sBIT_SUPPORTED)
  165034. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165035. png_handle_sBIT(png_ptr, info_ptr, length);
  165036. #endif
  165037. #if defined(PNG_READ_sRGB_SUPPORTED)
  165038. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165039. png_handle_sRGB(png_ptr, info_ptr, length);
  165040. #endif
  165041. #if defined(PNG_READ_iCCP_SUPPORTED)
  165042. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165043. png_handle_iCCP(png_ptr, info_ptr, length);
  165044. #endif
  165045. #if defined(PNG_READ_sPLT_SUPPORTED)
  165046. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165047. png_handle_sPLT(png_ptr, info_ptr, length);
  165048. #endif
  165049. #if defined(PNG_READ_tEXt_SUPPORTED)
  165050. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165051. png_handle_tEXt(png_ptr, info_ptr, length);
  165052. #endif
  165053. #if defined(PNG_READ_tIME_SUPPORTED)
  165054. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165055. png_handle_tIME(png_ptr, info_ptr, length);
  165056. #endif
  165057. #if defined(PNG_READ_tRNS_SUPPORTED)
  165058. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165059. png_handle_tRNS(png_ptr, info_ptr, length);
  165060. #endif
  165061. #if defined(PNG_READ_zTXt_SUPPORTED)
  165062. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165063. png_handle_zTXt(png_ptr, info_ptr, length);
  165064. #endif
  165065. #if defined(PNG_READ_iTXt_SUPPORTED)
  165066. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165067. png_handle_iTXt(png_ptr, info_ptr, length);
  165068. #endif
  165069. else
  165070. png_handle_unknown(png_ptr, info_ptr, length);
  165071. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165072. }
  165073. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165074. void PNGAPI
  165075. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165076. png_infopp end_info_ptr_ptr)
  165077. {
  165078. png_structp png_ptr = NULL;
  165079. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165080. #ifdef PNG_USER_MEM_SUPPORTED
  165081. png_free_ptr free_fn;
  165082. png_voidp mem_ptr;
  165083. #endif
  165084. png_debug(1, "in png_destroy_read_struct\n");
  165085. if (png_ptr_ptr != NULL)
  165086. png_ptr = *png_ptr_ptr;
  165087. if (info_ptr_ptr != NULL)
  165088. info_ptr = *info_ptr_ptr;
  165089. if (end_info_ptr_ptr != NULL)
  165090. end_info_ptr = *end_info_ptr_ptr;
  165091. #ifdef PNG_USER_MEM_SUPPORTED
  165092. free_fn = png_ptr->free_fn;
  165093. mem_ptr = png_ptr->mem_ptr;
  165094. #endif
  165095. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165096. if (info_ptr != NULL)
  165097. {
  165098. #if defined(PNG_TEXT_SUPPORTED)
  165099. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165100. #endif
  165101. #ifdef PNG_USER_MEM_SUPPORTED
  165102. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165103. (png_voidp)mem_ptr);
  165104. #else
  165105. png_destroy_struct((png_voidp)info_ptr);
  165106. #endif
  165107. *info_ptr_ptr = NULL;
  165108. }
  165109. if (end_info_ptr != NULL)
  165110. {
  165111. #if defined(PNG_READ_TEXT_SUPPORTED)
  165112. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165113. #endif
  165114. #ifdef PNG_USER_MEM_SUPPORTED
  165115. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165116. (png_voidp)mem_ptr);
  165117. #else
  165118. png_destroy_struct((png_voidp)end_info_ptr);
  165119. #endif
  165120. *end_info_ptr_ptr = NULL;
  165121. }
  165122. if (png_ptr != NULL)
  165123. {
  165124. #ifdef PNG_USER_MEM_SUPPORTED
  165125. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165126. (png_voidp)mem_ptr);
  165127. #else
  165128. png_destroy_struct((png_voidp)png_ptr);
  165129. #endif
  165130. *png_ptr_ptr = NULL;
  165131. }
  165132. }
  165133. void /* PRIVATE */
  165134. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165135. {
  165136. #ifdef PNG_SETJMP_SUPPORTED
  165137. jmp_buf tmp_jmp;
  165138. #endif
  165139. png_error_ptr error_fn;
  165140. png_error_ptr warning_fn;
  165141. png_voidp error_ptr;
  165142. #ifdef PNG_USER_MEM_SUPPORTED
  165143. png_free_ptr free_fn;
  165144. #endif
  165145. png_debug(1, "in png_read_destroy\n");
  165146. if (info_ptr != NULL)
  165147. png_info_destroy(png_ptr, info_ptr);
  165148. if (end_info_ptr != NULL)
  165149. png_info_destroy(png_ptr, end_info_ptr);
  165150. png_free(png_ptr, png_ptr->zbuf);
  165151. png_free(png_ptr, png_ptr->big_row_buf);
  165152. png_free(png_ptr, png_ptr->prev_row);
  165153. #if defined(PNG_READ_DITHER_SUPPORTED)
  165154. png_free(png_ptr, png_ptr->palette_lookup);
  165155. png_free(png_ptr, png_ptr->dither_index);
  165156. #endif
  165157. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165158. png_free(png_ptr, png_ptr->gamma_table);
  165159. #endif
  165160. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165161. png_free(png_ptr, png_ptr->gamma_from_1);
  165162. png_free(png_ptr, png_ptr->gamma_to_1);
  165163. #endif
  165164. #ifdef PNG_FREE_ME_SUPPORTED
  165165. if (png_ptr->free_me & PNG_FREE_PLTE)
  165166. png_zfree(png_ptr, png_ptr->palette);
  165167. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165168. #else
  165169. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165170. png_zfree(png_ptr, png_ptr->palette);
  165171. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165172. #endif
  165173. #if defined(PNG_tRNS_SUPPORTED) || \
  165174. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165175. #ifdef PNG_FREE_ME_SUPPORTED
  165176. if (png_ptr->free_me & PNG_FREE_TRNS)
  165177. png_free(png_ptr, png_ptr->trans);
  165178. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165179. #else
  165180. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165181. png_free(png_ptr, png_ptr->trans);
  165182. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165183. #endif
  165184. #endif
  165185. #if defined(PNG_READ_hIST_SUPPORTED)
  165186. #ifdef PNG_FREE_ME_SUPPORTED
  165187. if (png_ptr->free_me & PNG_FREE_HIST)
  165188. png_free(png_ptr, png_ptr->hist);
  165189. png_ptr->free_me &= ~PNG_FREE_HIST;
  165190. #else
  165191. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165192. png_free(png_ptr, png_ptr->hist);
  165193. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165194. #endif
  165195. #endif
  165196. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165197. if (png_ptr->gamma_16_table != NULL)
  165198. {
  165199. int i;
  165200. int istop = (1 << (8 - png_ptr->gamma_shift));
  165201. for (i = 0; i < istop; i++)
  165202. {
  165203. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165204. }
  165205. png_free(png_ptr, png_ptr->gamma_16_table);
  165206. }
  165207. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165208. if (png_ptr->gamma_16_from_1 != NULL)
  165209. {
  165210. int i;
  165211. int istop = (1 << (8 - png_ptr->gamma_shift));
  165212. for (i = 0; i < istop; i++)
  165213. {
  165214. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165215. }
  165216. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165217. }
  165218. if (png_ptr->gamma_16_to_1 != NULL)
  165219. {
  165220. int i;
  165221. int istop = (1 << (8 - png_ptr->gamma_shift));
  165222. for (i = 0; i < istop; i++)
  165223. {
  165224. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165225. }
  165226. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165227. }
  165228. #endif
  165229. #endif
  165230. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165231. png_free(png_ptr, png_ptr->time_buffer);
  165232. #endif
  165233. inflateEnd(&png_ptr->zstream);
  165234. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165235. png_free(png_ptr, png_ptr->save_buffer);
  165236. #endif
  165237. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165238. #ifdef PNG_TEXT_SUPPORTED
  165239. png_free(png_ptr, png_ptr->current_text);
  165240. #endif /* PNG_TEXT_SUPPORTED */
  165241. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165242. #ifdef PNG_SETJMP_SUPPORTED
  165243. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165244. #endif
  165245. error_fn = png_ptr->error_fn;
  165246. warning_fn = png_ptr->warning_fn;
  165247. error_ptr = png_ptr->error_ptr;
  165248. #ifdef PNG_USER_MEM_SUPPORTED
  165249. free_fn = png_ptr->free_fn;
  165250. #endif
  165251. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165252. png_ptr->error_fn = error_fn;
  165253. png_ptr->warning_fn = warning_fn;
  165254. png_ptr->error_ptr = error_ptr;
  165255. #ifdef PNG_USER_MEM_SUPPORTED
  165256. png_ptr->free_fn = free_fn;
  165257. #endif
  165258. #ifdef PNG_SETJMP_SUPPORTED
  165259. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165260. #endif
  165261. }
  165262. void PNGAPI
  165263. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165264. {
  165265. if(png_ptr == NULL) return;
  165266. png_ptr->read_row_fn = read_row_fn;
  165267. }
  165268. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165269. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165270. void PNGAPI
  165271. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165272. int transforms,
  165273. voidp params)
  165274. {
  165275. int row;
  165276. if(png_ptr == NULL) return;
  165277. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165278. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165279. png_set_invert_alpha(png_ptr);
  165280. #endif
  165281. png_read_info(png_ptr, info_ptr);
  165282. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165283. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165284. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165285. if (transforms & PNG_TRANSFORM_STRIP_16)
  165286. png_set_strip_16(png_ptr);
  165287. #endif
  165288. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165289. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165290. png_set_strip_alpha(png_ptr);
  165291. #endif
  165292. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165293. if (transforms & PNG_TRANSFORM_PACKING)
  165294. png_set_packing(png_ptr);
  165295. #endif
  165296. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165297. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165298. png_set_packswap(png_ptr);
  165299. #endif
  165300. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165301. if (transforms & PNG_TRANSFORM_EXPAND)
  165302. if ((png_ptr->bit_depth < 8) ||
  165303. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165304. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165305. png_set_expand(png_ptr);
  165306. #endif
  165307. #if defined(PNG_READ_INVERT_SUPPORTED)
  165308. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165309. png_set_invert_mono(png_ptr);
  165310. #endif
  165311. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165312. if ((transforms & PNG_TRANSFORM_SHIFT)
  165313. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165314. {
  165315. png_color_8p sig_bit;
  165316. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165317. png_set_shift(png_ptr, sig_bit);
  165318. }
  165319. #endif
  165320. #if defined(PNG_READ_BGR_SUPPORTED)
  165321. if (transforms & PNG_TRANSFORM_BGR)
  165322. png_set_bgr(png_ptr);
  165323. #endif
  165324. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165325. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165326. png_set_swap_alpha(png_ptr);
  165327. #endif
  165328. #if defined(PNG_READ_SWAP_SUPPORTED)
  165329. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165330. png_set_swap(png_ptr);
  165331. #endif
  165332. png_read_update_info(png_ptr, info_ptr);
  165333. #ifdef PNG_FREE_ME_SUPPORTED
  165334. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165335. #endif
  165336. if(info_ptr->row_pointers == NULL)
  165337. {
  165338. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165339. info_ptr->height * png_sizeof(png_bytep));
  165340. #ifdef PNG_FREE_ME_SUPPORTED
  165341. info_ptr->free_me |= PNG_FREE_ROWS;
  165342. #endif
  165343. for (row = 0; row < (int)info_ptr->height; row++)
  165344. {
  165345. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165346. png_get_rowbytes(png_ptr, info_ptr));
  165347. }
  165348. }
  165349. png_read_image(png_ptr, info_ptr->row_pointers);
  165350. info_ptr->valid |= PNG_INFO_IDAT;
  165351. png_read_end(png_ptr, info_ptr);
  165352. transforms = transforms; /* quiet compiler warnings */
  165353. params = params;
  165354. }
  165355. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165356. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165357. #endif /* PNG_READ_SUPPORTED */
  165358. /*** End of inlined file: pngread.c ***/
  165359. /*** Start of inlined file: pngpread.c ***/
  165360. #define PNG_INTERNAL
  165361. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165362. #define PNG_READ_SIG_MODE 0
  165363. #define PNG_READ_CHUNK_MODE 1
  165364. #define PNG_READ_IDAT_MODE 2
  165365. #define PNG_SKIP_MODE 3
  165366. #define PNG_READ_tEXt_MODE 4
  165367. #define PNG_READ_zTXt_MODE 5
  165368. #define PNG_READ_DONE_MODE 6
  165369. #define PNG_READ_iTXt_MODE 7
  165370. #define PNG_ERROR_MODE 8
  165371. void PNGAPI
  165372. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165373. png_bytep buffer, png_size_t buffer_size)
  165374. {
  165375. if(png_ptr == NULL) return;
  165376. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165377. while (png_ptr->buffer_size)
  165378. {
  165379. png_process_some_data(png_ptr, info_ptr);
  165380. }
  165381. }
  165382. void /* PRIVATE */
  165383. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165384. {
  165385. if(png_ptr == NULL) return;
  165386. switch (png_ptr->process_mode)
  165387. {
  165388. case PNG_READ_SIG_MODE:
  165389. {
  165390. png_push_read_sig(png_ptr, info_ptr);
  165391. break;
  165392. }
  165393. case PNG_READ_CHUNK_MODE:
  165394. {
  165395. png_push_read_chunk(png_ptr, info_ptr);
  165396. break;
  165397. }
  165398. case PNG_READ_IDAT_MODE:
  165399. {
  165400. png_push_read_IDAT(png_ptr);
  165401. break;
  165402. }
  165403. #if defined(PNG_READ_tEXt_SUPPORTED)
  165404. case PNG_READ_tEXt_MODE:
  165405. {
  165406. png_push_read_tEXt(png_ptr, info_ptr);
  165407. break;
  165408. }
  165409. #endif
  165410. #if defined(PNG_READ_zTXt_SUPPORTED)
  165411. case PNG_READ_zTXt_MODE:
  165412. {
  165413. png_push_read_zTXt(png_ptr, info_ptr);
  165414. break;
  165415. }
  165416. #endif
  165417. #if defined(PNG_READ_iTXt_SUPPORTED)
  165418. case PNG_READ_iTXt_MODE:
  165419. {
  165420. png_push_read_iTXt(png_ptr, info_ptr);
  165421. break;
  165422. }
  165423. #endif
  165424. case PNG_SKIP_MODE:
  165425. {
  165426. png_push_crc_finish(png_ptr);
  165427. break;
  165428. }
  165429. default:
  165430. {
  165431. png_ptr->buffer_size = 0;
  165432. break;
  165433. }
  165434. }
  165435. }
  165436. void /* PRIVATE */
  165437. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165438. {
  165439. png_size_t num_checked = png_ptr->sig_bytes,
  165440. num_to_check = 8 - num_checked;
  165441. if (png_ptr->buffer_size < num_to_check)
  165442. {
  165443. num_to_check = png_ptr->buffer_size;
  165444. }
  165445. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165446. num_to_check);
  165447. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165448. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165449. {
  165450. if (num_checked < 4 &&
  165451. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165452. png_error(png_ptr, "Not a PNG file");
  165453. else
  165454. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165455. }
  165456. else
  165457. {
  165458. if (png_ptr->sig_bytes >= 8)
  165459. {
  165460. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165461. }
  165462. }
  165463. }
  165464. void /* PRIVATE */
  165465. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165466. {
  165467. #ifdef PNG_USE_LOCAL_ARRAYS
  165468. PNG_CONST PNG_IHDR;
  165469. PNG_CONST PNG_IDAT;
  165470. PNG_CONST PNG_IEND;
  165471. PNG_CONST PNG_PLTE;
  165472. #if defined(PNG_READ_bKGD_SUPPORTED)
  165473. PNG_CONST PNG_bKGD;
  165474. #endif
  165475. #if defined(PNG_READ_cHRM_SUPPORTED)
  165476. PNG_CONST PNG_cHRM;
  165477. #endif
  165478. #if defined(PNG_READ_gAMA_SUPPORTED)
  165479. PNG_CONST PNG_gAMA;
  165480. #endif
  165481. #if defined(PNG_READ_hIST_SUPPORTED)
  165482. PNG_CONST PNG_hIST;
  165483. #endif
  165484. #if defined(PNG_READ_iCCP_SUPPORTED)
  165485. PNG_CONST PNG_iCCP;
  165486. #endif
  165487. #if defined(PNG_READ_iTXt_SUPPORTED)
  165488. PNG_CONST PNG_iTXt;
  165489. #endif
  165490. #if defined(PNG_READ_oFFs_SUPPORTED)
  165491. PNG_CONST PNG_oFFs;
  165492. #endif
  165493. #if defined(PNG_READ_pCAL_SUPPORTED)
  165494. PNG_CONST PNG_pCAL;
  165495. #endif
  165496. #if defined(PNG_READ_pHYs_SUPPORTED)
  165497. PNG_CONST PNG_pHYs;
  165498. #endif
  165499. #if defined(PNG_READ_sBIT_SUPPORTED)
  165500. PNG_CONST PNG_sBIT;
  165501. #endif
  165502. #if defined(PNG_READ_sCAL_SUPPORTED)
  165503. PNG_CONST PNG_sCAL;
  165504. #endif
  165505. #if defined(PNG_READ_sRGB_SUPPORTED)
  165506. PNG_CONST PNG_sRGB;
  165507. #endif
  165508. #if defined(PNG_READ_sPLT_SUPPORTED)
  165509. PNG_CONST PNG_sPLT;
  165510. #endif
  165511. #if defined(PNG_READ_tEXt_SUPPORTED)
  165512. PNG_CONST PNG_tEXt;
  165513. #endif
  165514. #if defined(PNG_READ_tIME_SUPPORTED)
  165515. PNG_CONST PNG_tIME;
  165516. #endif
  165517. #if defined(PNG_READ_tRNS_SUPPORTED)
  165518. PNG_CONST PNG_tRNS;
  165519. #endif
  165520. #if defined(PNG_READ_zTXt_SUPPORTED)
  165521. PNG_CONST PNG_zTXt;
  165522. #endif
  165523. #endif /* PNG_USE_LOCAL_ARRAYS */
  165524. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165525. {
  165526. png_byte chunk_length[4];
  165527. if (png_ptr->buffer_size < 8)
  165528. {
  165529. png_push_save_buffer(png_ptr);
  165530. return;
  165531. }
  165532. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165533. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165534. png_reset_crc(png_ptr);
  165535. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165536. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165537. }
  165538. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165539. if(png_ptr->mode & PNG_AFTER_IDAT)
  165540. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  165541. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165542. {
  165543. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165544. {
  165545. png_push_save_buffer(png_ptr);
  165546. return;
  165547. }
  165548. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  165549. }
  165550. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165551. {
  165552. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165553. {
  165554. png_push_save_buffer(png_ptr);
  165555. return;
  165556. }
  165557. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  165558. png_ptr->process_mode = PNG_READ_DONE_MODE;
  165559. png_push_have_end(png_ptr, info_ptr);
  165560. }
  165561. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165562. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165563. {
  165564. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165565. {
  165566. png_push_save_buffer(png_ptr);
  165567. return;
  165568. }
  165569. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165570. png_ptr->mode |= PNG_HAVE_IDAT;
  165571. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165572. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165573. png_ptr->mode |= PNG_HAVE_PLTE;
  165574. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165575. {
  165576. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165577. png_error(png_ptr, "Missing IHDR before IDAT");
  165578. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165579. !(png_ptr->mode & PNG_HAVE_PLTE))
  165580. png_error(png_ptr, "Missing PLTE before IDAT");
  165581. }
  165582. }
  165583. #endif
  165584. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165585. {
  165586. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165587. {
  165588. png_push_save_buffer(png_ptr);
  165589. return;
  165590. }
  165591. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  165592. }
  165593. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165594. {
  165595. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165596. png_error(png_ptr, "Missing IHDR before IDAT");
  165597. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165598. !(png_ptr->mode & PNG_HAVE_PLTE))
  165599. png_error(png_ptr, "Missing PLTE before IDAT");
  165600. if (png_ptr->mode & PNG_HAVE_IDAT)
  165601. {
  165602. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165603. if (png_ptr->push_length == 0)
  165604. return;
  165605. if (png_ptr->mode & PNG_AFTER_IDAT)
  165606. png_error(png_ptr, "Too many IDAT's found");
  165607. }
  165608. png_ptr->idat_size = png_ptr->push_length;
  165609. png_ptr->mode |= PNG_HAVE_IDAT;
  165610. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  165611. png_push_have_info(png_ptr, info_ptr);
  165612. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165613. png_ptr->zstream.next_out = png_ptr->row_buf;
  165614. return;
  165615. }
  165616. #if defined(PNG_READ_gAMA_SUPPORTED)
  165617. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165618. {
  165619. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165620. {
  165621. png_push_save_buffer(png_ptr);
  165622. return;
  165623. }
  165624. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  165625. }
  165626. #endif
  165627. #if defined(PNG_READ_sBIT_SUPPORTED)
  165628. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165629. {
  165630. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165631. {
  165632. png_push_save_buffer(png_ptr);
  165633. return;
  165634. }
  165635. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  165636. }
  165637. #endif
  165638. #if defined(PNG_READ_cHRM_SUPPORTED)
  165639. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165640. {
  165641. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165642. {
  165643. png_push_save_buffer(png_ptr);
  165644. return;
  165645. }
  165646. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  165647. }
  165648. #endif
  165649. #if defined(PNG_READ_sRGB_SUPPORTED)
  165650. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165651. {
  165652. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165653. {
  165654. png_push_save_buffer(png_ptr);
  165655. return;
  165656. }
  165657. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  165658. }
  165659. #endif
  165660. #if defined(PNG_READ_iCCP_SUPPORTED)
  165661. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165662. {
  165663. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165664. {
  165665. png_push_save_buffer(png_ptr);
  165666. return;
  165667. }
  165668. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  165669. }
  165670. #endif
  165671. #if defined(PNG_READ_sPLT_SUPPORTED)
  165672. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165673. {
  165674. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165675. {
  165676. png_push_save_buffer(png_ptr);
  165677. return;
  165678. }
  165679. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  165680. }
  165681. #endif
  165682. #if defined(PNG_READ_tRNS_SUPPORTED)
  165683. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165684. {
  165685. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165686. {
  165687. png_push_save_buffer(png_ptr);
  165688. return;
  165689. }
  165690. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  165691. }
  165692. #endif
  165693. #if defined(PNG_READ_bKGD_SUPPORTED)
  165694. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165695. {
  165696. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165697. {
  165698. png_push_save_buffer(png_ptr);
  165699. return;
  165700. }
  165701. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  165702. }
  165703. #endif
  165704. #if defined(PNG_READ_hIST_SUPPORTED)
  165705. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165706. {
  165707. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165708. {
  165709. png_push_save_buffer(png_ptr);
  165710. return;
  165711. }
  165712. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  165713. }
  165714. #endif
  165715. #if defined(PNG_READ_pHYs_SUPPORTED)
  165716. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165717. {
  165718. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165719. {
  165720. png_push_save_buffer(png_ptr);
  165721. return;
  165722. }
  165723. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  165724. }
  165725. #endif
  165726. #if defined(PNG_READ_oFFs_SUPPORTED)
  165727. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165728. {
  165729. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165730. {
  165731. png_push_save_buffer(png_ptr);
  165732. return;
  165733. }
  165734. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  165735. }
  165736. #endif
  165737. #if defined(PNG_READ_pCAL_SUPPORTED)
  165738. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165739. {
  165740. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165741. {
  165742. png_push_save_buffer(png_ptr);
  165743. return;
  165744. }
  165745. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  165746. }
  165747. #endif
  165748. #if defined(PNG_READ_sCAL_SUPPORTED)
  165749. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165750. {
  165751. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165752. {
  165753. png_push_save_buffer(png_ptr);
  165754. return;
  165755. }
  165756. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  165757. }
  165758. #endif
  165759. #if defined(PNG_READ_tIME_SUPPORTED)
  165760. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165761. {
  165762. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165763. {
  165764. png_push_save_buffer(png_ptr);
  165765. return;
  165766. }
  165767. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  165768. }
  165769. #endif
  165770. #if defined(PNG_READ_tEXt_SUPPORTED)
  165771. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165772. {
  165773. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165774. {
  165775. png_push_save_buffer(png_ptr);
  165776. return;
  165777. }
  165778. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  165779. }
  165780. #endif
  165781. #if defined(PNG_READ_zTXt_SUPPORTED)
  165782. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165783. {
  165784. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165785. {
  165786. png_push_save_buffer(png_ptr);
  165787. return;
  165788. }
  165789. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  165790. }
  165791. #endif
  165792. #if defined(PNG_READ_iTXt_SUPPORTED)
  165793. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165794. {
  165795. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165796. {
  165797. png_push_save_buffer(png_ptr);
  165798. return;
  165799. }
  165800. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  165801. }
  165802. #endif
  165803. else
  165804. {
  165805. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  165806. {
  165807. png_push_save_buffer(png_ptr);
  165808. return;
  165809. }
  165810. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  165811. }
  165812. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  165813. }
  165814. void /* PRIVATE */
  165815. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  165816. {
  165817. png_ptr->process_mode = PNG_SKIP_MODE;
  165818. png_ptr->skip_length = skip;
  165819. }
  165820. void /* PRIVATE */
  165821. png_push_crc_finish(png_structp png_ptr)
  165822. {
  165823. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  165824. {
  165825. png_size_t save_size;
  165826. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  165827. save_size = (png_size_t)png_ptr->skip_length;
  165828. else
  165829. save_size = png_ptr->save_buffer_size;
  165830. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165831. png_ptr->skip_length -= save_size;
  165832. png_ptr->buffer_size -= save_size;
  165833. png_ptr->save_buffer_size -= save_size;
  165834. png_ptr->save_buffer_ptr += save_size;
  165835. }
  165836. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  165837. {
  165838. png_size_t save_size;
  165839. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  165840. save_size = (png_size_t)png_ptr->skip_length;
  165841. else
  165842. save_size = png_ptr->current_buffer_size;
  165843. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  165844. png_ptr->skip_length -= save_size;
  165845. png_ptr->buffer_size -= save_size;
  165846. png_ptr->current_buffer_size -= save_size;
  165847. png_ptr->current_buffer_ptr += save_size;
  165848. }
  165849. if (!png_ptr->skip_length)
  165850. {
  165851. if (png_ptr->buffer_size < 4)
  165852. {
  165853. png_push_save_buffer(png_ptr);
  165854. return;
  165855. }
  165856. png_crc_finish(png_ptr, 0);
  165857. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165858. }
  165859. }
  165860. void PNGAPI
  165861. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  165862. {
  165863. png_bytep ptr;
  165864. if(png_ptr == NULL) return;
  165865. ptr = buffer;
  165866. if (png_ptr->save_buffer_size)
  165867. {
  165868. png_size_t save_size;
  165869. if (length < png_ptr->save_buffer_size)
  165870. save_size = length;
  165871. else
  165872. save_size = png_ptr->save_buffer_size;
  165873. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  165874. length -= save_size;
  165875. ptr += save_size;
  165876. png_ptr->buffer_size -= save_size;
  165877. png_ptr->save_buffer_size -= save_size;
  165878. png_ptr->save_buffer_ptr += save_size;
  165879. }
  165880. if (length && png_ptr->current_buffer_size)
  165881. {
  165882. png_size_t save_size;
  165883. if (length < png_ptr->current_buffer_size)
  165884. save_size = length;
  165885. else
  165886. save_size = png_ptr->current_buffer_size;
  165887. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  165888. png_ptr->buffer_size -= save_size;
  165889. png_ptr->current_buffer_size -= save_size;
  165890. png_ptr->current_buffer_ptr += save_size;
  165891. }
  165892. }
  165893. void /* PRIVATE */
  165894. png_push_save_buffer(png_structp png_ptr)
  165895. {
  165896. if (png_ptr->save_buffer_size)
  165897. {
  165898. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  165899. {
  165900. png_size_t i,istop;
  165901. png_bytep sp;
  165902. png_bytep dp;
  165903. istop = png_ptr->save_buffer_size;
  165904. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  165905. i < istop; i++, sp++, dp++)
  165906. {
  165907. *dp = *sp;
  165908. }
  165909. }
  165910. }
  165911. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  165912. png_ptr->save_buffer_max)
  165913. {
  165914. png_size_t new_max;
  165915. png_bytep old_buffer;
  165916. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  165917. (png_ptr->current_buffer_size + 256))
  165918. {
  165919. png_error(png_ptr, "Potential overflow of save_buffer");
  165920. }
  165921. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  165922. old_buffer = png_ptr->save_buffer;
  165923. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  165924. (png_uint_32)new_max);
  165925. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  165926. png_free(png_ptr, old_buffer);
  165927. png_ptr->save_buffer_max = new_max;
  165928. }
  165929. if (png_ptr->current_buffer_size)
  165930. {
  165931. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  165932. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  165933. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  165934. png_ptr->current_buffer_size = 0;
  165935. }
  165936. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  165937. png_ptr->buffer_size = 0;
  165938. }
  165939. void /* PRIVATE */
  165940. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  165941. png_size_t buffer_length)
  165942. {
  165943. png_ptr->current_buffer = buffer;
  165944. png_ptr->current_buffer_size = buffer_length;
  165945. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  165946. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  165947. }
  165948. void /* PRIVATE */
  165949. png_push_read_IDAT(png_structp png_ptr)
  165950. {
  165951. #ifdef PNG_USE_LOCAL_ARRAYS
  165952. PNG_CONST PNG_IDAT;
  165953. #endif
  165954. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  165955. {
  165956. png_byte chunk_length[4];
  165957. if (png_ptr->buffer_size < 8)
  165958. {
  165959. png_push_save_buffer(png_ptr);
  165960. return;
  165961. }
  165962. png_push_fill_buffer(png_ptr, chunk_length, 4);
  165963. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  165964. png_reset_crc(png_ptr);
  165965. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165966. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  165967. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165968. {
  165969. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165970. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  165971. png_error(png_ptr, "Not enough compressed data");
  165972. return;
  165973. }
  165974. png_ptr->idat_size = png_ptr->push_length;
  165975. }
  165976. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  165977. {
  165978. png_size_t save_size;
  165979. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  165980. {
  165981. save_size = (png_size_t)png_ptr->idat_size;
  165982. if((png_uint_32)save_size != png_ptr->idat_size)
  165983. png_error(png_ptr, "save_size overflowed in pngpread");
  165984. }
  165985. else
  165986. save_size = png_ptr->save_buffer_size;
  165987. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165988. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  165989. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  165990. png_ptr->idat_size -= save_size;
  165991. png_ptr->buffer_size -= save_size;
  165992. png_ptr->save_buffer_size -= save_size;
  165993. png_ptr->save_buffer_ptr += save_size;
  165994. }
  165995. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  165996. {
  165997. png_size_t save_size;
  165998. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  165999. {
  166000. save_size = (png_size_t)png_ptr->idat_size;
  166001. if((png_uint_32)save_size != png_ptr->idat_size)
  166002. png_error(png_ptr, "save_size overflowed in pngpread");
  166003. }
  166004. else
  166005. save_size = png_ptr->current_buffer_size;
  166006. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166007. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166008. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166009. png_ptr->idat_size -= save_size;
  166010. png_ptr->buffer_size -= save_size;
  166011. png_ptr->current_buffer_size -= save_size;
  166012. png_ptr->current_buffer_ptr += save_size;
  166013. }
  166014. if (!png_ptr->idat_size)
  166015. {
  166016. if (png_ptr->buffer_size < 4)
  166017. {
  166018. png_push_save_buffer(png_ptr);
  166019. return;
  166020. }
  166021. png_crc_finish(png_ptr, 0);
  166022. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166023. png_ptr->mode |= PNG_AFTER_IDAT;
  166024. }
  166025. }
  166026. void /* PRIVATE */
  166027. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166028. png_size_t buffer_length)
  166029. {
  166030. int ret;
  166031. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166032. png_error(png_ptr, "Extra compression data");
  166033. png_ptr->zstream.next_in = buffer;
  166034. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166035. for(;;)
  166036. {
  166037. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166038. if (ret != Z_OK)
  166039. {
  166040. if (ret == Z_STREAM_END)
  166041. {
  166042. if (png_ptr->zstream.avail_in)
  166043. png_error(png_ptr, "Extra compressed data");
  166044. if (!(png_ptr->zstream.avail_out))
  166045. {
  166046. png_push_process_row(png_ptr);
  166047. }
  166048. png_ptr->mode |= PNG_AFTER_IDAT;
  166049. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166050. break;
  166051. }
  166052. else if (ret == Z_BUF_ERROR)
  166053. break;
  166054. else
  166055. png_error(png_ptr, "Decompression Error");
  166056. }
  166057. if (!(png_ptr->zstream.avail_out))
  166058. {
  166059. if ((
  166060. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166061. png_ptr->interlaced && png_ptr->pass > 6) ||
  166062. (!png_ptr->interlaced &&
  166063. #endif
  166064. png_ptr->row_number == png_ptr->num_rows))
  166065. {
  166066. if (png_ptr->zstream.avail_in)
  166067. {
  166068. png_warning(png_ptr, "Too much data in IDAT chunks");
  166069. }
  166070. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166071. break;
  166072. }
  166073. png_push_process_row(png_ptr);
  166074. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166075. png_ptr->zstream.next_out = png_ptr->row_buf;
  166076. }
  166077. else
  166078. break;
  166079. }
  166080. }
  166081. void /* PRIVATE */
  166082. png_push_process_row(png_structp png_ptr)
  166083. {
  166084. png_ptr->row_info.color_type = png_ptr->color_type;
  166085. png_ptr->row_info.width = png_ptr->iwidth;
  166086. png_ptr->row_info.channels = png_ptr->channels;
  166087. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166088. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166089. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166090. png_ptr->row_info.width);
  166091. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166092. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166093. (int)(png_ptr->row_buf[0]));
  166094. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166095. png_ptr->rowbytes + 1);
  166096. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166097. png_do_read_transformations(png_ptr);
  166098. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166099. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166100. {
  166101. if (png_ptr->pass < 6)
  166102. png_do_read_interlace(png_ptr);
  166103. switch (png_ptr->pass)
  166104. {
  166105. case 0:
  166106. {
  166107. int i;
  166108. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166109. {
  166110. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166111. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166112. }
  166113. if (png_ptr->pass == 2) /* pass 1 might be empty */
  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. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166122. {
  166123. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166124. {
  166125. png_push_have_row(png_ptr, png_bytep_NULL);
  166126. png_read_push_finish_row(png_ptr);
  166127. }
  166128. }
  166129. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166130. {
  166131. png_push_have_row(png_ptr, png_bytep_NULL);
  166132. png_read_push_finish_row(png_ptr);
  166133. }
  166134. break;
  166135. }
  166136. case 1:
  166137. {
  166138. int i;
  166139. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166140. {
  166141. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166142. png_read_push_finish_row(png_ptr);
  166143. }
  166144. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166145. {
  166146. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166147. {
  166148. png_push_have_row(png_ptr, png_bytep_NULL);
  166149. png_read_push_finish_row(png_ptr);
  166150. }
  166151. }
  166152. break;
  166153. }
  166154. case 2:
  166155. {
  166156. int i;
  166157. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166158. {
  166159. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166160. png_read_push_finish_row(png_ptr);
  166161. }
  166162. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166163. {
  166164. png_push_have_row(png_ptr, png_bytep_NULL);
  166165. png_read_push_finish_row(png_ptr);
  166166. }
  166167. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166168. {
  166169. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166170. {
  166171. png_push_have_row(png_ptr, png_bytep_NULL);
  166172. png_read_push_finish_row(png_ptr);
  166173. }
  166174. }
  166175. break;
  166176. }
  166177. case 3:
  166178. {
  166179. int i;
  166180. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166181. {
  166182. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166183. png_read_push_finish_row(png_ptr);
  166184. }
  166185. if (png_ptr->pass == 4) /* skip top two generated rows */
  166186. {
  166187. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166188. {
  166189. png_push_have_row(png_ptr, png_bytep_NULL);
  166190. png_read_push_finish_row(png_ptr);
  166191. }
  166192. }
  166193. break;
  166194. }
  166195. case 4:
  166196. {
  166197. int i;
  166198. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166199. {
  166200. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166201. png_read_push_finish_row(png_ptr);
  166202. }
  166203. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166204. {
  166205. png_push_have_row(png_ptr, png_bytep_NULL);
  166206. png_read_push_finish_row(png_ptr);
  166207. }
  166208. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166209. {
  166210. png_push_have_row(png_ptr, png_bytep_NULL);
  166211. png_read_push_finish_row(png_ptr);
  166212. }
  166213. break;
  166214. }
  166215. case 5:
  166216. {
  166217. int i;
  166218. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166219. {
  166220. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166221. png_read_push_finish_row(png_ptr);
  166222. }
  166223. if (png_ptr->pass == 6) /* skip top generated row */
  166224. {
  166225. png_push_have_row(png_ptr, png_bytep_NULL);
  166226. png_read_push_finish_row(png_ptr);
  166227. }
  166228. break;
  166229. }
  166230. case 6:
  166231. {
  166232. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166233. png_read_push_finish_row(png_ptr);
  166234. if (png_ptr->pass != 6)
  166235. break;
  166236. png_push_have_row(png_ptr, png_bytep_NULL);
  166237. png_read_push_finish_row(png_ptr);
  166238. }
  166239. }
  166240. }
  166241. else
  166242. #endif
  166243. {
  166244. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166245. png_read_push_finish_row(png_ptr);
  166246. }
  166247. }
  166248. void /* PRIVATE */
  166249. png_read_push_finish_row(png_structp png_ptr)
  166250. {
  166251. #ifdef PNG_USE_LOCAL_ARRAYS
  166252. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166253. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166254. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166255. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166256. #endif
  166257. png_ptr->row_number++;
  166258. if (png_ptr->row_number < png_ptr->num_rows)
  166259. return;
  166260. if (png_ptr->interlaced)
  166261. {
  166262. png_ptr->row_number = 0;
  166263. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166264. png_ptr->rowbytes + 1);
  166265. do
  166266. {
  166267. png_ptr->pass++;
  166268. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166269. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166270. (png_ptr->pass == 5 && png_ptr->width < 2))
  166271. png_ptr->pass++;
  166272. if (png_ptr->pass > 7)
  166273. png_ptr->pass--;
  166274. if (png_ptr->pass >= 7)
  166275. break;
  166276. png_ptr->iwidth = (png_ptr->width +
  166277. png_pass_inc[png_ptr->pass] - 1 -
  166278. png_pass_start[png_ptr->pass]) /
  166279. png_pass_inc[png_ptr->pass];
  166280. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166281. png_ptr->iwidth) + 1;
  166282. if (png_ptr->transformations & PNG_INTERLACE)
  166283. break;
  166284. png_ptr->num_rows = (png_ptr->height +
  166285. png_pass_yinc[png_ptr->pass] - 1 -
  166286. png_pass_ystart[png_ptr->pass]) /
  166287. png_pass_yinc[png_ptr->pass];
  166288. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166289. }
  166290. }
  166291. #if defined(PNG_READ_tEXt_SUPPORTED)
  166292. void /* PRIVATE */
  166293. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166294. length)
  166295. {
  166296. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166297. {
  166298. png_error(png_ptr, "Out of place tEXt");
  166299. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166300. }
  166301. #ifdef PNG_MAX_MALLOC_64K
  166302. png_ptr->skip_length = 0; /* This may not be necessary */
  166303. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166304. {
  166305. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166306. png_ptr->skip_length = length - (png_uint_32)65535L;
  166307. length = (png_uint_32)65535L;
  166308. }
  166309. #endif
  166310. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166311. (png_uint_32)(length+1));
  166312. png_ptr->current_text[length] = '\0';
  166313. png_ptr->current_text_ptr = png_ptr->current_text;
  166314. png_ptr->current_text_size = (png_size_t)length;
  166315. png_ptr->current_text_left = (png_size_t)length;
  166316. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166317. }
  166318. void /* PRIVATE */
  166319. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166320. {
  166321. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166322. {
  166323. png_size_t text_size;
  166324. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166325. text_size = png_ptr->buffer_size;
  166326. else
  166327. text_size = png_ptr->current_text_left;
  166328. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166329. png_ptr->current_text_left -= text_size;
  166330. png_ptr->current_text_ptr += text_size;
  166331. }
  166332. if (!(png_ptr->current_text_left))
  166333. {
  166334. png_textp text_ptr;
  166335. png_charp text;
  166336. png_charp key;
  166337. int ret;
  166338. if (png_ptr->buffer_size < 4)
  166339. {
  166340. png_push_save_buffer(png_ptr);
  166341. return;
  166342. }
  166343. png_push_crc_finish(png_ptr);
  166344. #if defined(PNG_MAX_MALLOC_64K)
  166345. if (png_ptr->skip_length)
  166346. return;
  166347. #endif
  166348. key = png_ptr->current_text;
  166349. for (text = key; *text; text++)
  166350. ;
  166351. if (text < key + png_ptr->current_text_size)
  166352. text++;
  166353. text_ptr = (png_textp)png_malloc(png_ptr,
  166354. (png_uint_32)png_sizeof(png_text));
  166355. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166356. text_ptr->key = key;
  166357. #ifdef PNG_iTXt_SUPPORTED
  166358. text_ptr->lang = NULL;
  166359. text_ptr->lang_key = NULL;
  166360. #endif
  166361. text_ptr->text = text;
  166362. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166363. png_free(png_ptr, key);
  166364. png_free(png_ptr, text_ptr);
  166365. png_ptr->current_text = NULL;
  166366. if (ret)
  166367. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166368. }
  166369. }
  166370. #endif
  166371. #if defined(PNG_READ_zTXt_SUPPORTED)
  166372. void /* PRIVATE */
  166373. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166374. length)
  166375. {
  166376. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166377. {
  166378. png_error(png_ptr, "Out of place zTXt");
  166379. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166380. }
  166381. #ifdef PNG_MAX_MALLOC_64K
  166382. if (length > (png_uint_32)65535L)
  166383. {
  166384. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166385. png_push_crc_skip(png_ptr, length);
  166386. return;
  166387. }
  166388. #endif
  166389. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166390. (png_uint_32)(length+1));
  166391. png_ptr->current_text[length] = '\0';
  166392. png_ptr->current_text_ptr = png_ptr->current_text;
  166393. png_ptr->current_text_size = (png_size_t)length;
  166394. png_ptr->current_text_left = (png_size_t)length;
  166395. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166396. }
  166397. void /* PRIVATE */
  166398. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166399. {
  166400. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166401. {
  166402. png_size_t text_size;
  166403. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166404. text_size = png_ptr->buffer_size;
  166405. else
  166406. text_size = png_ptr->current_text_left;
  166407. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166408. png_ptr->current_text_left -= text_size;
  166409. png_ptr->current_text_ptr += text_size;
  166410. }
  166411. if (!(png_ptr->current_text_left))
  166412. {
  166413. png_textp text_ptr;
  166414. png_charp text;
  166415. png_charp key;
  166416. int ret;
  166417. png_size_t text_size, key_size;
  166418. if (png_ptr->buffer_size < 4)
  166419. {
  166420. png_push_save_buffer(png_ptr);
  166421. return;
  166422. }
  166423. png_push_crc_finish(png_ptr);
  166424. key = png_ptr->current_text;
  166425. for (text = key; *text; text++)
  166426. ;
  166427. if (text >= key + png_ptr->current_text_size)
  166428. {
  166429. png_ptr->current_text = NULL;
  166430. png_free(png_ptr, key);
  166431. return;
  166432. }
  166433. text++;
  166434. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166435. {
  166436. png_ptr->current_text = NULL;
  166437. png_free(png_ptr, key);
  166438. return;
  166439. }
  166440. text++;
  166441. png_ptr->zstream.next_in = (png_bytep )text;
  166442. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166443. (text - key));
  166444. png_ptr->zstream.next_out = png_ptr->zbuf;
  166445. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166446. key_size = text - key;
  166447. text_size = 0;
  166448. text = NULL;
  166449. ret = Z_STREAM_END;
  166450. while (png_ptr->zstream.avail_in)
  166451. {
  166452. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166453. if (ret != Z_OK && ret != Z_STREAM_END)
  166454. {
  166455. inflateReset(&png_ptr->zstream);
  166456. png_ptr->zstream.avail_in = 0;
  166457. png_ptr->current_text = NULL;
  166458. png_free(png_ptr, key);
  166459. png_free(png_ptr, text);
  166460. return;
  166461. }
  166462. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166463. {
  166464. if (text == NULL)
  166465. {
  166466. text = (png_charp)png_malloc(png_ptr,
  166467. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166468. + key_size + 1));
  166469. png_memcpy(text + key_size, png_ptr->zbuf,
  166470. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166471. png_memcpy(text, key, key_size);
  166472. text_size = key_size + png_ptr->zbuf_size -
  166473. png_ptr->zstream.avail_out;
  166474. *(text + text_size) = '\0';
  166475. }
  166476. else
  166477. {
  166478. png_charp tmp;
  166479. tmp = text;
  166480. text = (png_charp)png_malloc(png_ptr, text_size +
  166481. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166482. + 1));
  166483. png_memcpy(text, tmp, text_size);
  166484. png_free(png_ptr, tmp);
  166485. png_memcpy(text + text_size, png_ptr->zbuf,
  166486. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166487. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166488. *(text + text_size) = '\0';
  166489. }
  166490. if (ret != Z_STREAM_END)
  166491. {
  166492. png_ptr->zstream.next_out = png_ptr->zbuf;
  166493. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166494. }
  166495. }
  166496. else
  166497. {
  166498. break;
  166499. }
  166500. if (ret == Z_STREAM_END)
  166501. break;
  166502. }
  166503. inflateReset(&png_ptr->zstream);
  166504. png_ptr->zstream.avail_in = 0;
  166505. if (ret != Z_STREAM_END)
  166506. {
  166507. png_ptr->current_text = NULL;
  166508. png_free(png_ptr, key);
  166509. png_free(png_ptr, text);
  166510. return;
  166511. }
  166512. png_ptr->current_text = NULL;
  166513. png_free(png_ptr, key);
  166514. key = text;
  166515. text += key_size;
  166516. text_ptr = (png_textp)png_malloc(png_ptr,
  166517. (png_uint_32)png_sizeof(png_text));
  166518. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166519. text_ptr->key = key;
  166520. #ifdef PNG_iTXt_SUPPORTED
  166521. text_ptr->lang = NULL;
  166522. text_ptr->lang_key = NULL;
  166523. #endif
  166524. text_ptr->text = text;
  166525. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166526. png_free(png_ptr, key);
  166527. png_free(png_ptr, text_ptr);
  166528. if (ret)
  166529. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166530. }
  166531. }
  166532. #endif
  166533. #if defined(PNG_READ_iTXt_SUPPORTED)
  166534. void /* PRIVATE */
  166535. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166536. length)
  166537. {
  166538. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166539. {
  166540. png_error(png_ptr, "Out of place iTXt");
  166541. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166542. }
  166543. #ifdef PNG_MAX_MALLOC_64K
  166544. png_ptr->skip_length = 0; /* This may not be necessary */
  166545. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166546. {
  166547. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  166548. png_ptr->skip_length = length - (png_uint_32)65535L;
  166549. length = (png_uint_32)65535L;
  166550. }
  166551. #endif
  166552. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166553. (png_uint_32)(length+1));
  166554. png_ptr->current_text[length] = '\0';
  166555. png_ptr->current_text_ptr = png_ptr->current_text;
  166556. png_ptr->current_text_size = (png_size_t)length;
  166557. png_ptr->current_text_left = (png_size_t)length;
  166558. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  166559. }
  166560. void /* PRIVATE */
  166561. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  166562. {
  166563. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166564. {
  166565. png_size_t text_size;
  166566. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166567. text_size = png_ptr->buffer_size;
  166568. else
  166569. text_size = png_ptr->current_text_left;
  166570. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166571. png_ptr->current_text_left -= text_size;
  166572. png_ptr->current_text_ptr += text_size;
  166573. }
  166574. if (!(png_ptr->current_text_left))
  166575. {
  166576. png_textp text_ptr;
  166577. png_charp key;
  166578. int comp_flag;
  166579. png_charp lang;
  166580. png_charp lang_key;
  166581. png_charp text;
  166582. int ret;
  166583. if (png_ptr->buffer_size < 4)
  166584. {
  166585. png_push_save_buffer(png_ptr);
  166586. return;
  166587. }
  166588. png_push_crc_finish(png_ptr);
  166589. #if defined(PNG_MAX_MALLOC_64K)
  166590. if (png_ptr->skip_length)
  166591. return;
  166592. #endif
  166593. key = png_ptr->current_text;
  166594. for (lang = key; *lang; lang++)
  166595. ;
  166596. if (lang < key + png_ptr->current_text_size - 3)
  166597. lang++;
  166598. comp_flag = *lang++;
  166599. lang++; /* skip comp_type, always zero */
  166600. for (lang_key = lang; *lang_key; lang_key++)
  166601. ;
  166602. lang_key++; /* skip NUL separator */
  166603. text=lang_key;
  166604. if (lang_key < key + png_ptr->current_text_size - 1)
  166605. {
  166606. for (; *text; text++)
  166607. ;
  166608. }
  166609. if (text < key + png_ptr->current_text_size)
  166610. text++;
  166611. text_ptr = (png_textp)png_malloc(png_ptr,
  166612. (png_uint_32)png_sizeof(png_text));
  166613. text_ptr->compression = comp_flag + 2;
  166614. text_ptr->key = key;
  166615. text_ptr->lang = lang;
  166616. text_ptr->lang_key = lang_key;
  166617. text_ptr->text = text;
  166618. text_ptr->text_length = 0;
  166619. text_ptr->itxt_length = png_strlen(text);
  166620. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166621. png_ptr->current_text = NULL;
  166622. png_free(png_ptr, text_ptr);
  166623. if (ret)
  166624. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  166625. }
  166626. }
  166627. #endif
  166628. void /* PRIVATE */
  166629. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166630. length)
  166631. {
  166632. png_uint_32 skip=0;
  166633. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  166634. if (!(png_ptr->chunk_name[0] & 0x20))
  166635. {
  166636. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166637. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166638. PNG_HANDLE_CHUNK_ALWAYS
  166639. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166640. && png_ptr->read_user_chunk_fn == NULL
  166641. #endif
  166642. )
  166643. #endif
  166644. png_chunk_error(png_ptr, "unknown critical chunk");
  166645. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166646. }
  166647. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  166648. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  166649. {
  166650. #ifdef PNG_MAX_MALLOC_64K
  166651. if (length > (png_uint_32)65535L)
  166652. {
  166653. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  166654. skip = length - (png_uint_32)65535L;
  166655. length = (png_uint_32)65535L;
  166656. }
  166657. #endif
  166658. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  166659. (png_charp)png_ptr->chunk_name, 5);
  166660. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  166661. png_ptr->unknown_chunk.size = (png_size_t)length;
  166662. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  166663. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  166664. if(png_ptr->read_user_chunk_fn != NULL)
  166665. {
  166666. int ret;
  166667. ret = (*(png_ptr->read_user_chunk_fn))
  166668. (png_ptr, &png_ptr->unknown_chunk);
  166669. if (ret < 0)
  166670. png_chunk_error(png_ptr, "error in user chunk");
  166671. if (ret == 0)
  166672. {
  166673. if (!(png_ptr->chunk_name[0] & 0x20))
  166674. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  166675. PNG_HANDLE_CHUNK_ALWAYS)
  166676. png_chunk_error(png_ptr, "unknown critical chunk");
  166677. png_set_unknown_chunks(png_ptr, info_ptr,
  166678. &png_ptr->unknown_chunk, 1);
  166679. }
  166680. }
  166681. #else
  166682. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  166683. #endif
  166684. png_free(png_ptr, png_ptr->unknown_chunk.data);
  166685. png_ptr->unknown_chunk.data = NULL;
  166686. }
  166687. else
  166688. #endif
  166689. skip=length;
  166690. png_push_crc_skip(png_ptr, skip);
  166691. }
  166692. void /* PRIVATE */
  166693. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  166694. {
  166695. if (png_ptr->info_fn != NULL)
  166696. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  166697. }
  166698. void /* PRIVATE */
  166699. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  166700. {
  166701. if (png_ptr->end_fn != NULL)
  166702. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  166703. }
  166704. void /* PRIVATE */
  166705. png_push_have_row(png_structp png_ptr, png_bytep row)
  166706. {
  166707. if (png_ptr->row_fn != NULL)
  166708. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  166709. (int)png_ptr->pass);
  166710. }
  166711. void PNGAPI
  166712. png_progressive_combine_row (png_structp png_ptr,
  166713. png_bytep old_row, png_bytep new_row)
  166714. {
  166715. #ifdef PNG_USE_LOCAL_ARRAYS
  166716. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  166717. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  166718. #endif
  166719. if(png_ptr == NULL) return;
  166720. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  166721. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  166722. }
  166723. void PNGAPI
  166724. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  166725. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  166726. png_progressive_end_ptr end_fn)
  166727. {
  166728. if(png_ptr == NULL) return;
  166729. png_ptr->info_fn = info_fn;
  166730. png_ptr->row_fn = row_fn;
  166731. png_ptr->end_fn = end_fn;
  166732. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  166733. }
  166734. png_voidp PNGAPI
  166735. png_get_progressive_ptr(png_structp png_ptr)
  166736. {
  166737. if(png_ptr == NULL) return (NULL);
  166738. return png_ptr->io_ptr;
  166739. }
  166740. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  166741. /*** End of inlined file: pngpread.c ***/
  166742. /*** Start of inlined file: pngrio.c ***/
  166743. #define PNG_INTERNAL
  166744. #if defined(PNG_READ_SUPPORTED)
  166745. void /* PRIVATE */
  166746. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166747. {
  166748. png_debug1(4,"reading %d bytes\n", (int)length);
  166749. if (png_ptr->read_data_fn != NULL)
  166750. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  166751. else
  166752. png_error(png_ptr, "Call to NULL read function");
  166753. }
  166754. #if !defined(PNG_NO_STDIO)
  166755. #ifndef USE_FAR_KEYWORD
  166756. void PNGAPI
  166757. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166758. {
  166759. png_size_t check;
  166760. if(png_ptr == NULL) return;
  166761. #if defined(_WIN32_WCE)
  166762. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166763. check = 0;
  166764. #else
  166765. check = (png_size_t)fread(data, (png_size_t)1, length,
  166766. (png_FILE_p)png_ptr->io_ptr);
  166767. #endif
  166768. if (check != length)
  166769. png_error(png_ptr, "Read Error");
  166770. }
  166771. #else
  166772. #define NEAR_BUF_SIZE 1024
  166773. #define MIN(a,b) (a <= b ? a : b)
  166774. static void PNGAPI
  166775. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  166776. {
  166777. int check;
  166778. png_byte *n_data;
  166779. png_FILE_p io_ptr;
  166780. if(png_ptr == NULL) return;
  166781. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  166782. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  166783. if ((png_bytep)n_data == data)
  166784. {
  166785. #if defined(_WIN32_WCE)
  166786. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  166787. check = 0;
  166788. #else
  166789. check = fread(n_data, 1, length, io_ptr);
  166790. #endif
  166791. }
  166792. else
  166793. {
  166794. png_byte buf[NEAR_BUF_SIZE];
  166795. png_size_t read, remaining, err;
  166796. check = 0;
  166797. remaining = length;
  166798. do
  166799. {
  166800. read = MIN(NEAR_BUF_SIZE, remaining);
  166801. #if defined(_WIN32_WCE)
  166802. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  166803. err = 0;
  166804. #else
  166805. err = fread(buf, (png_size_t)1, read, io_ptr);
  166806. #endif
  166807. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  166808. if(err != read)
  166809. break;
  166810. else
  166811. check += err;
  166812. data += read;
  166813. remaining -= read;
  166814. }
  166815. while (remaining != 0);
  166816. }
  166817. if ((png_uint_32)check != (png_uint_32)length)
  166818. png_error(png_ptr, "read Error");
  166819. }
  166820. #endif
  166821. #endif
  166822. void PNGAPI
  166823. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  166824. png_rw_ptr read_data_fn)
  166825. {
  166826. if(png_ptr == NULL) return;
  166827. png_ptr->io_ptr = io_ptr;
  166828. #if !defined(PNG_NO_STDIO)
  166829. if (read_data_fn != NULL)
  166830. png_ptr->read_data_fn = read_data_fn;
  166831. else
  166832. png_ptr->read_data_fn = png_default_read_data;
  166833. #else
  166834. png_ptr->read_data_fn = read_data_fn;
  166835. #endif
  166836. if (png_ptr->write_data_fn != NULL)
  166837. {
  166838. png_ptr->write_data_fn = NULL;
  166839. png_warning(png_ptr,
  166840. "It's an error to set both read_data_fn and write_data_fn in the ");
  166841. png_warning(png_ptr,
  166842. "same structure. Resetting write_data_fn to NULL.");
  166843. }
  166844. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  166845. png_ptr->output_flush_fn = NULL;
  166846. #endif
  166847. }
  166848. #endif /* PNG_READ_SUPPORTED */
  166849. /*** End of inlined file: pngrio.c ***/
  166850. /*** Start of inlined file: pngrtran.c ***/
  166851. #define PNG_INTERNAL
  166852. #if defined(PNG_READ_SUPPORTED)
  166853. void PNGAPI
  166854. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  166855. {
  166856. png_debug(1, "in png_set_crc_action\n");
  166857. if(png_ptr == NULL) return;
  166858. switch (crit_action)
  166859. {
  166860. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166861. break;
  166862. case PNG_CRC_WARN_USE: /* warn/use data */
  166863. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166864. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  166865. break;
  166866. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166867. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166868. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  166869. PNG_FLAG_CRC_CRITICAL_IGNORE;
  166870. break;
  166871. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  166872. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  166873. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166874. case PNG_CRC_DEFAULT:
  166875. default:
  166876. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  166877. break;
  166878. }
  166879. switch (ancil_action)
  166880. {
  166881. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  166882. break;
  166883. case PNG_CRC_WARN_USE: /* warn/use data */
  166884. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166885. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  166886. break;
  166887. case PNG_CRC_QUIET_USE: /* quiet/use data */
  166888. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166889. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  166890. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166891. break;
  166892. case PNG_CRC_ERROR_QUIT: /* error/quit */
  166893. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166894. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  166895. break;
  166896. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  166897. case PNG_CRC_DEFAULT:
  166898. default:
  166899. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  166900. break;
  166901. }
  166902. }
  166903. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  166904. defined(PNG_FLOATING_POINT_SUPPORTED)
  166905. void PNGAPI
  166906. png_set_background(png_structp png_ptr,
  166907. png_color_16p background_color, int background_gamma_code,
  166908. int need_expand, double background_gamma)
  166909. {
  166910. png_debug(1, "in png_set_background\n");
  166911. if(png_ptr == NULL) return;
  166912. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  166913. {
  166914. png_warning(png_ptr, "Application must supply a known background gamma");
  166915. return;
  166916. }
  166917. png_ptr->transformations |= PNG_BACKGROUND;
  166918. png_memcpy(&(png_ptr->background), background_color,
  166919. png_sizeof(png_color_16));
  166920. png_ptr->background_gamma = (float)background_gamma;
  166921. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  166922. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  166923. }
  166924. #endif
  166925. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  166926. void PNGAPI
  166927. png_set_strip_16(png_structp png_ptr)
  166928. {
  166929. png_debug(1, "in png_set_strip_16\n");
  166930. if(png_ptr == NULL) return;
  166931. png_ptr->transformations |= PNG_16_TO_8;
  166932. }
  166933. #endif
  166934. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  166935. void PNGAPI
  166936. png_set_strip_alpha(png_structp png_ptr)
  166937. {
  166938. png_debug(1, "in png_set_strip_alpha\n");
  166939. if(png_ptr == NULL) return;
  166940. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  166941. }
  166942. #endif
  166943. #if defined(PNG_READ_DITHER_SUPPORTED)
  166944. typedef struct png_dsort_struct
  166945. {
  166946. struct png_dsort_struct FAR * next;
  166947. png_byte left;
  166948. png_byte right;
  166949. } png_dsort;
  166950. typedef png_dsort FAR * png_dsortp;
  166951. typedef png_dsort FAR * FAR * png_dsortpp;
  166952. void PNGAPI
  166953. png_set_dither(png_structp png_ptr, png_colorp palette,
  166954. int num_palette, int maximum_colors, png_uint_16p histogram,
  166955. int full_dither)
  166956. {
  166957. png_debug(1, "in png_set_dither\n");
  166958. if(png_ptr == NULL) return;
  166959. png_ptr->transformations |= PNG_DITHER;
  166960. if (!full_dither)
  166961. {
  166962. int i;
  166963. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  166964. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166965. for (i = 0; i < num_palette; i++)
  166966. png_ptr->dither_index[i] = (png_byte)i;
  166967. }
  166968. if (num_palette > maximum_colors)
  166969. {
  166970. if (histogram != NULL)
  166971. {
  166972. int i;
  166973. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  166974. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  166975. for (i = 0; i < num_palette; i++)
  166976. png_ptr->dither_sort[i] = (png_byte)i;
  166977. for (i = num_palette - 1; i >= maximum_colors; i--)
  166978. {
  166979. int done; /* to stop early if the list is pre-sorted */
  166980. int j;
  166981. done = 1;
  166982. for (j = 0; j < i; j++)
  166983. {
  166984. if (histogram[png_ptr->dither_sort[j]]
  166985. < histogram[png_ptr->dither_sort[j + 1]])
  166986. {
  166987. png_byte t;
  166988. t = png_ptr->dither_sort[j];
  166989. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  166990. png_ptr->dither_sort[j + 1] = t;
  166991. done = 0;
  166992. }
  166993. }
  166994. if (done)
  166995. break;
  166996. }
  166997. if (full_dither)
  166998. {
  166999. int j = num_palette;
  167000. for (i = 0; i < maximum_colors; i++)
  167001. {
  167002. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167003. {
  167004. do
  167005. j--;
  167006. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167007. palette[i] = palette[j];
  167008. }
  167009. }
  167010. }
  167011. else
  167012. {
  167013. int j = num_palette;
  167014. for (i = 0; i < maximum_colors; i++)
  167015. {
  167016. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167017. {
  167018. png_color tmp_color;
  167019. do
  167020. j--;
  167021. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167022. tmp_color = palette[j];
  167023. palette[j] = palette[i];
  167024. palette[i] = tmp_color;
  167025. png_ptr->dither_index[j] = (png_byte)i;
  167026. png_ptr->dither_index[i] = (png_byte)j;
  167027. }
  167028. }
  167029. for (i = 0; i < num_palette; i++)
  167030. {
  167031. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167032. {
  167033. int min_d, k, min_k, d_index;
  167034. d_index = png_ptr->dither_index[i];
  167035. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167036. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167037. {
  167038. int d;
  167039. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167040. if (d < min_d)
  167041. {
  167042. min_d = d;
  167043. min_k = k;
  167044. }
  167045. }
  167046. png_ptr->dither_index[i] = (png_byte)min_k;
  167047. }
  167048. }
  167049. }
  167050. png_free(png_ptr, png_ptr->dither_sort);
  167051. png_ptr->dither_sort=NULL;
  167052. }
  167053. else
  167054. {
  167055. int i;
  167056. int max_d;
  167057. int num_new_palette;
  167058. png_dsortp t;
  167059. png_dsortpp hash;
  167060. t=NULL;
  167061. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167062. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167063. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167064. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167065. for (i = 0; i < num_palette; i++)
  167066. {
  167067. png_ptr->index_to_palette[i] = (png_byte)i;
  167068. png_ptr->palette_to_index[i] = (png_byte)i;
  167069. }
  167070. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167071. png_sizeof (png_dsortp)));
  167072. for (i = 0; i < 769; i++)
  167073. hash[i] = NULL;
  167074. num_new_palette = num_palette;
  167075. max_d = 96;
  167076. while (num_new_palette > maximum_colors)
  167077. {
  167078. for (i = 0; i < num_new_palette - 1; i++)
  167079. {
  167080. int j;
  167081. for (j = i + 1; j < num_new_palette; j++)
  167082. {
  167083. int d;
  167084. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167085. if (d <= max_d)
  167086. {
  167087. t = (png_dsortp)png_malloc_warn(png_ptr,
  167088. (png_uint_32)(png_sizeof(png_dsort)));
  167089. if (t == NULL)
  167090. break;
  167091. t->next = hash[d];
  167092. t->left = (png_byte)i;
  167093. t->right = (png_byte)j;
  167094. hash[d] = t;
  167095. }
  167096. }
  167097. if (t == NULL)
  167098. break;
  167099. }
  167100. if (t != NULL)
  167101. for (i = 0; i <= max_d; i++)
  167102. {
  167103. if (hash[i] != NULL)
  167104. {
  167105. png_dsortp p;
  167106. for (p = hash[i]; p; p = p->next)
  167107. {
  167108. if ((int)png_ptr->index_to_palette[p->left]
  167109. < num_new_palette &&
  167110. (int)png_ptr->index_to_palette[p->right]
  167111. < num_new_palette)
  167112. {
  167113. int j, next_j;
  167114. if (num_new_palette & 0x01)
  167115. {
  167116. j = p->left;
  167117. next_j = p->right;
  167118. }
  167119. else
  167120. {
  167121. j = p->right;
  167122. next_j = p->left;
  167123. }
  167124. num_new_palette--;
  167125. palette[png_ptr->index_to_palette[j]]
  167126. = palette[num_new_palette];
  167127. if (!full_dither)
  167128. {
  167129. int k;
  167130. for (k = 0; k < num_palette; k++)
  167131. {
  167132. if (png_ptr->dither_index[k] ==
  167133. png_ptr->index_to_palette[j])
  167134. png_ptr->dither_index[k] =
  167135. png_ptr->index_to_palette[next_j];
  167136. if ((int)png_ptr->dither_index[k] ==
  167137. num_new_palette)
  167138. png_ptr->dither_index[k] =
  167139. png_ptr->index_to_palette[j];
  167140. }
  167141. }
  167142. png_ptr->index_to_palette[png_ptr->palette_to_index
  167143. [num_new_palette]] = png_ptr->index_to_palette[j];
  167144. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167145. = png_ptr->palette_to_index[num_new_palette];
  167146. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167147. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167148. }
  167149. if (num_new_palette <= maximum_colors)
  167150. break;
  167151. }
  167152. if (num_new_palette <= maximum_colors)
  167153. break;
  167154. }
  167155. }
  167156. for (i = 0; i < 769; i++)
  167157. {
  167158. if (hash[i] != NULL)
  167159. {
  167160. png_dsortp p = hash[i];
  167161. while (p)
  167162. {
  167163. t = p->next;
  167164. png_free(png_ptr, p);
  167165. p = t;
  167166. }
  167167. }
  167168. hash[i] = 0;
  167169. }
  167170. max_d += 96;
  167171. }
  167172. png_free(png_ptr, hash);
  167173. png_free(png_ptr, png_ptr->palette_to_index);
  167174. png_free(png_ptr, png_ptr->index_to_palette);
  167175. png_ptr->palette_to_index=NULL;
  167176. png_ptr->index_to_palette=NULL;
  167177. }
  167178. num_palette = maximum_colors;
  167179. }
  167180. if (png_ptr->palette == NULL)
  167181. {
  167182. png_ptr->palette = palette;
  167183. }
  167184. png_ptr->num_palette = (png_uint_16)num_palette;
  167185. if (full_dither)
  167186. {
  167187. int i;
  167188. png_bytep distance;
  167189. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167190. PNG_DITHER_BLUE_BITS;
  167191. int num_red = (1 << PNG_DITHER_RED_BITS);
  167192. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167193. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167194. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167195. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167196. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167197. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167198. png_sizeof (png_byte));
  167199. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167200. png_sizeof(png_byte)));
  167201. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167202. for (i = 0; i < num_palette; i++)
  167203. {
  167204. int ir, ig, ib;
  167205. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167206. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167207. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167208. for (ir = 0; ir < num_red; ir++)
  167209. {
  167210. int dr = ((ir > r) ? ir - r : r - ir);
  167211. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167212. for (ig = 0; ig < num_green; ig++)
  167213. {
  167214. int dg = ((ig > g) ? ig - g : g - ig);
  167215. int dt = dr + dg;
  167216. int dm = ((dr > dg) ? dr : dg);
  167217. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167218. for (ib = 0; ib < num_blue; ib++)
  167219. {
  167220. int d_index = index_g | ib;
  167221. int db = ((ib > b) ? ib - b : b - ib);
  167222. int dmax = ((dm > db) ? dm : db);
  167223. int d = dmax + dt + db;
  167224. if (d < (int)distance[d_index])
  167225. {
  167226. distance[d_index] = (png_byte)d;
  167227. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167228. }
  167229. }
  167230. }
  167231. }
  167232. }
  167233. png_free(png_ptr, distance);
  167234. }
  167235. }
  167236. #endif
  167237. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167238. void PNGAPI
  167239. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167240. {
  167241. png_debug(1, "in png_set_gamma\n");
  167242. if(png_ptr == NULL) return;
  167243. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167244. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167245. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167246. png_ptr->transformations |= PNG_GAMMA;
  167247. png_ptr->gamma = (float)file_gamma;
  167248. png_ptr->screen_gamma = (float)scrn_gamma;
  167249. }
  167250. #endif
  167251. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167252. void PNGAPI
  167253. png_set_expand(png_structp png_ptr)
  167254. {
  167255. png_debug(1, "in png_set_expand\n");
  167256. if(png_ptr == NULL) return;
  167257. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167258. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167259. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167260. #endif
  167261. }
  167262. void PNGAPI
  167263. png_set_palette_to_rgb(png_structp png_ptr)
  167264. {
  167265. png_debug(1, "in png_set_palette_to_rgb\n");
  167266. if(png_ptr == NULL) return;
  167267. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167268. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167269. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167270. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167271. #endif
  167272. }
  167273. #if !defined(PNG_1_0_X)
  167274. void PNGAPI
  167275. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167276. {
  167277. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167278. if(png_ptr == NULL) return;
  167279. png_ptr->transformations |= PNG_EXPAND;
  167280. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167281. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167282. #endif
  167283. }
  167284. #endif
  167285. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167286. void PNGAPI
  167287. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167288. {
  167289. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167290. if(png_ptr == NULL) return;
  167291. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167292. }
  167293. #endif
  167294. void PNGAPI
  167295. png_set_tRNS_to_alpha(png_structp png_ptr)
  167296. {
  167297. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167298. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167299. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167300. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167301. #endif
  167302. }
  167303. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167304. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167305. void PNGAPI
  167306. png_set_gray_to_rgb(png_structp png_ptr)
  167307. {
  167308. png_debug(1, "in png_set_gray_to_rgb\n");
  167309. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167310. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167311. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167312. #endif
  167313. }
  167314. #endif
  167315. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167316. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167317. void PNGAPI
  167318. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167319. double green)
  167320. {
  167321. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167322. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167323. if(png_ptr == NULL) return;
  167324. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167325. }
  167326. #endif
  167327. void PNGAPI
  167328. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167329. png_fixed_point red, png_fixed_point green)
  167330. {
  167331. png_debug(1, "in png_set_rgb_to_gray\n");
  167332. if(png_ptr == NULL) return;
  167333. switch(error_action)
  167334. {
  167335. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167336. break;
  167337. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167338. break;
  167339. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167340. }
  167341. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167342. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167343. png_ptr->transformations |= PNG_EXPAND;
  167344. #else
  167345. {
  167346. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167347. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167348. }
  167349. #endif
  167350. {
  167351. png_uint_16 red_int, green_int;
  167352. if(red < 0 || green < 0)
  167353. {
  167354. red_int = 6968; /* .212671 * 32768 + .5 */
  167355. green_int = 23434; /* .715160 * 32768 + .5 */
  167356. }
  167357. else if(red + green < 100000L)
  167358. {
  167359. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167360. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167361. }
  167362. else
  167363. {
  167364. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167365. red_int = 6968;
  167366. green_int = 23434;
  167367. }
  167368. png_ptr->rgb_to_gray_red_coeff = red_int;
  167369. png_ptr->rgb_to_gray_green_coeff = green_int;
  167370. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167371. }
  167372. }
  167373. #endif
  167374. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167375. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167376. defined(PNG_LEGACY_SUPPORTED)
  167377. void PNGAPI
  167378. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167379. read_user_transform_fn)
  167380. {
  167381. png_debug(1, "in png_set_read_user_transform_fn\n");
  167382. if(png_ptr == NULL) return;
  167383. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167384. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167385. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167386. #endif
  167387. #ifdef PNG_LEGACY_SUPPORTED
  167388. if(read_user_transform_fn)
  167389. png_warning(png_ptr,
  167390. "This version of libpng does not support user transforms");
  167391. #endif
  167392. }
  167393. #endif
  167394. void /* PRIVATE */
  167395. png_init_read_transformations(png_structp png_ptr)
  167396. {
  167397. png_debug(1, "in png_init_read_transformations\n");
  167398. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167399. if(png_ptr != NULL)
  167400. #endif
  167401. {
  167402. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167403. || defined(PNG_READ_GAMMA_SUPPORTED)
  167404. int color_type = png_ptr->color_type;
  167405. #endif
  167406. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167407. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167408. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167409. !(color_type & PNG_COLOR_MASK_COLOR))
  167410. {
  167411. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167412. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167413. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167414. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167415. png_ptr->background.red == png_ptr->background.green &&
  167416. png_ptr->background.red == png_ptr->background.blue)
  167417. {
  167418. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167419. png_ptr->background.gray = png_ptr->background.red;
  167420. }
  167421. #endif
  167422. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167423. (png_ptr->transformations & PNG_EXPAND))
  167424. {
  167425. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167426. {
  167427. switch (png_ptr->bit_depth)
  167428. {
  167429. case 1:
  167430. png_ptr->background.gray *= (png_uint_16)0xff;
  167431. png_ptr->background.red = png_ptr->background.green
  167432. = png_ptr->background.blue = png_ptr->background.gray;
  167433. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167434. {
  167435. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167436. png_ptr->trans_values.red = png_ptr->trans_values.green
  167437. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167438. }
  167439. break;
  167440. case 2:
  167441. png_ptr->background.gray *= (png_uint_16)0x55;
  167442. png_ptr->background.red = png_ptr->background.green
  167443. = png_ptr->background.blue = png_ptr->background.gray;
  167444. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167445. {
  167446. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167447. png_ptr->trans_values.red = png_ptr->trans_values.green
  167448. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167449. }
  167450. break;
  167451. case 4:
  167452. png_ptr->background.gray *= (png_uint_16)0x11;
  167453. png_ptr->background.red = png_ptr->background.green
  167454. = png_ptr->background.blue = png_ptr->background.gray;
  167455. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167456. {
  167457. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167458. png_ptr->trans_values.red = png_ptr->trans_values.green
  167459. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167460. }
  167461. break;
  167462. case 8:
  167463. case 16:
  167464. png_ptr->background.red = png_ptr->background.green
  167465. = png_ptr->background.blue = png_ptr->background.gray;
  167466. break;
  167467. }
  167468. }
  167469. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167470. {
  167471. png_ptr->background.red =
  167472. png_ptr->palette[png_ptr->background.index].red;
  167473. png_ptr->background.green =
  167474. png_ptr->palette[png_ptr->background.index].green;
  167475. png_ptr->background.blue =
  167476. png_ptr->palette[png_ptr->background.index].blue;
  167477. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167478. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167479. {
  167480. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167481. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167482. #endif
  167483. {
  167484. int i,istop;
  167485. istop=(int)png_ptr->num_trans;
  167486. for (i=0; i<istop; i++)
  167487. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167488. }
  167489. }
  167490. #endif
  167491. }
  167492. }
  167493. #endif
  167494. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167495. png_ptr->background_1 = png_ptr->background;
  167496. #endif
  167497. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167498. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167499. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167500. < PNG_GAMMA_THRESHOLD))
  167501. {
  167502. int i,k;
  167503. k=0;
  167504. for (i=0; i<png_ptr->num_trans; i++)
  167505. {
  167506. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167507. k=1; /* partial transparency is present */
  167508. }
  167509. if (k == 0)
  167510. png_ptr->transformations &= (~PNG_GAMMA);
  167511. }
  167512. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167513. png_ptr->gamma != 0.0)
  167514. {
  167515. png_build_gamma_table(png_ptr);
  167516. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167517. if (png_ptr->transformations & PNG_BACKGROUND)
  167518. {
  167519. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167520. {
  167521. png_color back, back_1;
  167522. png_colorp palette = png_ptr->palette;
  167523. int num_palette = png_ptr->num_palette;
  167524. int i;
  167525. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  167526. {
  167527. back.red = png_ptr->gamma_table[png_ptr->background.red];
  167528. back.green = png_ptr->gamma_table[png_ptr->background.green];
  167529. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  167530. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  167531. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  167532. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  167533. }
  167534. else
  167535. {
  167536. double g, gs;
  167537. switch (png_ptr->background_gamma_type)
  167538. {
  167539. case PNG_BACKGROUND_GAMMA_SCREEN:
  167540. g = (png_ptr->screen_gamma);
  167541. gs = 1.0;
  167542. break;
  167543. case PNG_BACKGROUND_GAMMA_FILE:
  167544. g = 1.0 / (png_ptr->gamma);
  167545. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167546. break;
  167547. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167548. g = 1.0 / (png_ptr->background_gamma);
  167549. gs = 1.0 / (png_ptr->background_gamma *
  167550. png_ptr->screen_gamma);
  167551. break;
  167552. default:
  167553. g = 1.0; /* back_1 */
  167554. gs = 1.0; /* back */
  167555. }
  167556. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  167557. {
  167558. back.red = (png_byte)png_ptr->background.red;
  167559. back.green = (png_byte)png_ptr->background.green;
  167560. back.blue = (png_byte)png_ptr->background.blue;
  167561. }
  167562. else
  167563. {
  167564. back.red = (png_byte)(pow(
  167565. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  167566. back.green = (png_byte)(pow(
  167567. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  167568. back.blue = (png_byte)(pow(
  167569. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  167570. }
  167571. back_1.red = (png_byte)(pow(
  167572. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  167573. back_1.green = (png_byte)(pow(
  167574. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  167575. back_1.blue = (png_byte)(pow(
  167576. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  167577. }
  167578. for (i = 0; i < num_palette; i++)
  167579. {
  167580. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  167581. {
  167582. if (png_ptr->trans[i] == 0)
  167583. {
  167584. palette[i] = back;
  167585. }
  167586. else /* if (png_ptr->trans[i] != 0xff) */
  167587. {
  167588. png_byte v, w;
  167589. v = png_ptr->gamma_to_1[palette[i].red];
  167590. png_composite(w, v, png_ptr->trans[i], back_1.red);
  167591. palette[i].red = png_ptr->gamma_from_1[w];
  167592. v = png_ptr->gamma_to_1[palette[i].green];
  167593. png_composite(w, v, png_ptr->trans[i], back_1.green);
  167594. palette[i].green = png_ptr->gamma_from_1[w];
  167595. v = png_ptr->gamma_to_1[palette[i].blue];
  167596. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  167597. palette[i].blue = png_ptr->gamma_from_1[w];
  167598. }
  167599. }
  167600. else
  167601. {
  167602. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167603. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167604. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167605. }
  167606. }
  167607. }
  167608. else
  167609. {
  167610. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  167611. double g = 1.0;
  167612. double gs = 1.0;
  167613. switch (png_ptr->background_gamma_type)
  167614. {
  167615. case PNG_BACKGROUND_GAMMA_SCREEN:
  167616. g = (png_ptr->screen_gamma);
  167617. gs = 1.0;
  167618. break;
  167619. case PNG_BACKGROUND_GAMMA_FILE:
  167620. g = 1.0 / (png_ptr->gamma);
  167621. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  167622. break;
  167623. case PNG_BACKGROUND_GAMMA_UNIQUE:
  167624. g = 1.0 / (png_ptr->background_gamma);
  167625. gs = 1.0 / (png_ptr->background_gamma *
  167626. png_ptr->screen_gamma);
  167627. break;
  167628. }
  167629. png_ptr->background_1.gray = (png_uint_16)(pow(
  167630. (double)png_ptr->background.gray / m, g) * m + .5);
  167631. png_ptr->background.gray = (png_uint_16)(pow(
  167632. (double)png_ptr->background.gray / m, gs) * m + .5);
  167633. if ((png_ptr->background.red != png_ptr->background.green) ||
  167634. (png_ptr->background.red != png_ptr->background.blue) ||
  167635. (png_ptr->background.red != png_ptr->background.gray))
  167636. {
  167637. png_ptr->background_1.red = (png_uint_16)(pow(
  167638. (double)png_ptr->background.red / m, g) * m + .5);
  167639. png_ptr->background_1.green = (png_uint_16)(pow(
  167640. (double)png_ptr->background.green / m, g) * m + .5);
  167641. png_ptr->background_1.blue = (png_uint_16)(pow(
  167642. (double)png_ptr->background.blue / m, g) * m + .5);
  167643. png_ptr->background.red = (png_uint_16)(pow(
  167644. (double)png_ptr->background.red / m, gs) * m + .5);
  167645. png_ptr->background.green = (png_uint_16)(pow(
  167646. (double)png_ptr->background.green / m, gs) * m + .5);
  167647. png_ptr->background.blue = (png_uint_16)(pow(
  167648. (double)png_ptr->background.blue / m, gs) * m + .5);
  167649. }
  167650. else
  167651. {
  167652. png_ptr->background_1.red = png_ptr->background_1.green
  167653. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  167654. png_ptr->background.red = png_ptr->background.green
  167655. = png_ptr->background.blue = png_ptr->background.gray;
  167656. }
  167657. }
  167658. }
  167659. else
  167660. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167661. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167662. {
  167663. png_colorp palette = png_ptr->palette;
  167664. int num_palette = png_ptr->num_palette;
  167665. int i;
  167666. for (i = 0; i < num_palette; i++)
  167667. {
  167668. palette[i].red = png_ptr->gamma_table[palette[i].red];
  167669. palette[i].green = png_ptr->gamma_table[palette[i].green];
  167670. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  167671. }
  167672. }
  167673. }
  167674. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167675. else
  167676. #endif
  167677. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  167678. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167679. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167680. (color_type == PNG_COLOR_TYPE_PALETTE))
  167681. {
  167682. int i;
  167683. int istop = (int)png_ptr->num_trans;
  167684. png_color back;
  167685. png_colorp palette = png_ptr->palette;
  167686. back.red = (png_byte)png_ptr->background.red;
  167687. back.green = (png_byte)png_ptr->background.green;
  167688. back.blue = (png_byte)png_ptr->background.blue;
  167689. for (i = 0; i < istop; i++)
  167690. {
  167691. if (png_ptr->trans[i] == 0)
  167692. {
  167693. palette[i] = back;
  167694. }
  167695. else if (png_ptr->trans[i] != 0xff)
  167696. {
  167697. png_composite(palette[i].red, palette[i].red,
  167698. png_ptr->trans[i], back.red);
  167699. png_composite(palette[i].green, palette[i].green,
  167700. png_ptr->trans[i], back.green);
  167701. png_composite(palette[i].blue, palette[i].blue,
  167702. png_ptr->trans[i], back.blue);
  167703. }
  167704. }
  167705. }
  167706. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  167707. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167708. if ((png_ptr->transformations & PNG_SHIFT) &&
  167709. (color_type == PNG_COLOR_TYPE_PALETTE))
  167710. {
  167711. png_uint_16 i;
  167712. png_uint_16 istop = png_ptr->num_palette;
  167713. int sr = 8 - png_ptr->sig_bit.red;
  167714. int sg = 8 - png_ptr->sig_bit.green;
  167715. int sb = 8 - png_ptr->sig_bit.blue;
  167716. if (sr < 0 || sr > 8)
  167717. sr = 0;
  167718. if (sg < 0 || sg > 8)
  167719. sg = 0;
  167720. if (sb < 0 || sb > 8)
  167721. sb = 0;
  167722. for (i = 0; i < istop; i++)
  167723. {
  167724. png_ptr->palette[i].red >>= sr;
  167725. png_ptr->palette[i].green >>= sg;
  167726. png_ptr->palette[i].blue >>= sb;
  167727. }
  167728. }
  167729. #endif /* PNG_READ_SHIFT_SUPPORTED */
  167730. }
  167731. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  167732. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  167733. if(png_ptr)
  167734. return;
  167735. #endif
  167736. }
  167737. void /* PRIVATE */
  167738. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  167739. {
  167740. png_debug(1, "in png_read_transform_info\n");
  167741. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167742. if (png_ptr->transformations & PNG_EXPAND)
  167743. {
  167744. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167745. {
  167746. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  167747. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  167748. else
  167749. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  167750. info_ptr->bit_depth = 8;
  167751. info_ptr->num_trans = 0;
  167752. }
  167753. else
  167754. {
  167755. if (png_ptr->num_trans)
  167756. {
  167757. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  167758. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167759. else
  167760. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167761. }
  167762. if (info_ptr->bit_depth < 8)
  167763. info_ptr->bit_depth = 8;
  167764. info_ptr->num_trans = 0;
  167765. }
  167766. }
  167767. #endif
  167768. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167769. if (png_ptr->transformations & PNG_BACKGROUND)
  167770. {
  167771. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167772. info_ptr->num_trans = 0;
  167773. info_ptr->background = png_ptr->background;
  167774. }
  167775. #endif
  167776. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167777. if (png_ptr->transformations & PNG_GAMMA)
  167778. {
  167779. #ifdef PNG_FLOATING_POINT_SUPPORTED
  167780. info_ptr->gamma = png_ptr->gamma;
  167781. #endif
  167782. #ifdef PNG_FIXED_POINT_SUPPORTED
  167783. info_ptr->int_gamma = png_ptr->int_gamma;
  167784. #endif
  167785. }
  167786. #endif
  167787. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167788. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  167789. info_ptr->bit_depth = 8;
  167790. #endif
  167791. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167792. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  167793. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  167794. #endif
  167795. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167796. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167797. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  167798. #endif
  167799. #if defined(PNG_READ_DITHER_SUPPORTED)
  167800. if (png_ptr->transformations & PNG_DITHER)
  167801. {
  167802. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167803. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  167804. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  167805. {
  167806. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  167807. }
  167808. }
  167809. #endif
  167810. #if defined(PNG_READ_PACK_SUPPORTED)
  167811. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  167812. info_ptr->bit_depth = 8;
  167813. #endif
  167814. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167815. info_ptr->channels = 1;
  167816. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  167817. info_ptr->channels = 3;
  167818. else
  167819. info_ptr->channels = 1;
  167820. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167821. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167822. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  167823. #endif
  167824. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  167825. info_ptr->channels++;
  167826. #if defined(PNG_READ_FILLER_SUPPORTED)
  167827. if ((png_ptr->transformations & PNG_FILLER) &&
  167828. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  167829. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  167830. {
  167831. info_ptr->channels++;
  167832. #if !defined(PNG_1_0_X)
  167833. if (png_ptr->transformations & PNG_ADD_ALPHA)
  167834. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  167835. #endif
  167836. }
  167837. #endif
  167838. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  167839. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167840. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  167841. {
  167842. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  167843. info_ptr->bit_depth = png_ptr->user_transform_depth;
  167844. if(info_ptr->channels < png_ptr->user_transform_channels)
  167845. info_ptr->channels = png_ptr->user_transform_channels;
  167846. }
  167847. #endif
  167848. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  167849. info_ptr->bit_depth);
  167850. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  167851. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  167852. if(png_ptr)
  167853. return;
  167854. #endif
  167855. }
  167856. void /* PRIVATE */
  167857. png_do_read_transformations(png_structp png_ptr)
  167858. {
  167859. png_debug(1, "in png_do_read_transformations\n");
  167860. if (png_ptr->row_buf == NULL)
  167861. {
  167862. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  167863. char msg[50];
  167864. png_snprintf2(msg, 50,
  167865. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  167866. png_ptr->pass);
  167867. png_error(png_ptr, msg);
  167868. #else
  167869. png_error(png_ptr, "NULL row buffer");
  167870. #endif
  167871. }
  167872. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167873. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  167874. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  167875. png_error(png_ptr, "Uninitialized row");
  167876. #else
  167877. png_warning(png_ptr, "Uninitialized row");
  167878. #endif
  167879. #endif
  167880. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167881. if (png_ptr->transformations & PNG_EXPAND)
  167882. {
  167883. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  167884. {
  167885. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167886. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  167887. }
  167888. else
  167889. {
  167890. if (png_ptr->num_trans &&
  167891. (png_ptr->transformations & PNG_EXPAND_tRNS))
  167892. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167893. &(png_ptr->trans_values));
  167894. else
  167895. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167896. NULL);
  167897. }
  167898. }
  167899. #endif
  167900. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167901. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  167902. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167903. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  167904. #endif
  167905. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167906. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  167907. {
  167908. int rgb_error =
  167909. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  167910. if(rgb_error)
  167911. {
  167912. png_ptr->rgb_to_gray_status=1;
  167913. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  167914. PNG_RGB_TO_GRAY_WARN)
  167915. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  167916. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  167917. PNG_RGB_TO_GRAY_ERR)
  167918. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  167919. }
  167920. }
  167921. #endif
  167922. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167923. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167924. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  167925. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167926. #endif
  167927. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167928. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167929. ((png_ptr->num_trans != 0 ) ||
  167930. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  167931. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167932. &(png_ptr->trans_values), &(png_ptr->background)
  167933. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167934. , &(png_ptr->background_1),
  167935. png_ptr->gamma_table, png_ptr->gamma_from_1,
  167936. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  167937. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  167938. png_ptr->gamma_shift
  167939. #endif
  167940. );
  167941. #endif
  167942. #if defined(PNG_READ_GAMMA_SUPPORTED)
  167943. if ((png_ptr->transformations & PNG_GAMMA) &&
  167944. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167945. !((png_ptr->transformations & PNG_BACKGROUND) &&
  167946. ((png_ptr->num_trans != 0) ||
  167947. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  167948. #endif
  167949. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  167950. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167951. png_ptr->gamma_table, png_ptr->gamma_16_table,
  167952. png_ptr->gamma_shift);
  167953. #endif
  167954. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167955. if (png_ptr->transformations & PNG_16_TO_8)
  167956. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167957. #endif
  167958. #if defined(PNG_READ_DITHER_SUPPORTED)
  167959. if (png_ptr->transformations & PNG_DITHER)
  167960. {
  167961. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  167962. png_ptr->palette_lookup, png_ptr->dither_index);
  167963. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  167964. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  167965. }
  167966. #endif
  167967. #if defined(PNG_READ_INVERT_SUPPORTED)
  167968. if (png_ptr->transformations & PNG_INVERT_MONO)
  167969. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167970. #endif
  167971. #if defined(PNG_READ_SHIFT_SUPPORTED)
  167972. if (png_ptr->transformations & PNG_SHIFT)
  167973. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167974. &(png_ptr->shift));
  167975. #endif
  167976. #if defined(PNG_READ_PACK_SUPPORTED)
  167977. if (png_ptr->transformations & PNG_PACK)
  167978. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167979. #endif
  167980. #if defined(PNG_READ_BGR_SUPPORTED)
  167981. if (png_ptr->transformations & PNG_BGR)
  167982. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167983. #endif
  167984. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  167985. if (png_ptr->transformations & PNG_PACKSWAP)
  167986. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167987. #endif
  167988. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167989. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167990. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  167991. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  167992. #endif
  167993. #if defined(PNG_READ_FILLER_SUPPORTED)
  167994. if (png_ptr->transformations & PNG_FILLER)
  167995. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  167996. (png_uint_32)png_ptr->filler, png_ptr->flags);
  167997. #endif
  167998. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167999. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168000. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168001. #endif
  168002. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168003. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168004. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168005. #endif
  168006. #if defined(PNG_READ_SWAP_SUPPORTED)
  168007. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168008. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168009. #endif
  168010. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168011. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168012. {
  168013. if(png_ptr->read_user_transform_fn != NULL)
  168014. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168015. (png_ptr, /* png_ptr */
  168016. &(png_ptr->row_info), /* row_info: */
  168017. png_ptr->row_buf + 1); /* start of pixel data for row */
  168018. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168019. if(png_ptr->user_transform_depth)
  168020. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168021. if(png_ptr->user_transform_channels)
  168022. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168023. #endif
  168024. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168025. png_ptr->row_info.channels);
  168026. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168027. png_ptr->row_info.width);
  168028. }
  168029. #endif
  168030. }
  168031. #if defined(PNG_READ_PACK_SUPPORTED)
  168032. void /* PRIVATE */
  168033. png_do_unpack(png_row_infop row_info, png_bytep row)
  168034. {
  168035. png_debug(1, "in png_do_unpack\n");
  168036. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168037. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168038. #else
  168039. if (row_info->bit_depth < 8)
  168040. #endif
  168041. {
  168042. png_uint_32 i;
  168043. png_uint_32 row_width=row_info->width;
  168044. switch (row_info->bit_depth)
  168045. {
  168046. case 1:
  168047. {
  168048. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168049. png_bytep dp = row + (png_size_t)row_width - 1;
  168050. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168051. for (i = 0; i < row_width; i++)
  168052. {
  168053. *dp = (png_byte)((*sp >> shift) & 0x01);
  168054. if (shift == 7)
  168055. {
  168056. shift = 0;
  168057. sp--;
  168058. }
  168059. else
  168060. shift++;
  168061. dp--;
  168062. }
  168063. break;
  168064. }
  168065. case 2:
  168066. {
  168067. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168068. png_bytep dp = row + (png_size_t)row_width - 1;
  168069. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168070. for (i = 0; i < row_width; i++)
  168071. {
  168072. *dp = (png_byte)((*sp >> shift) & 0x03);
  168073. if (shift == 6)
  168074. {
  168075. shift = 0;
  168076. sp--;
  168077. }
  168078. else
  168079. shift += 2;
  168080. dp--;
  168081. }
  168082. break;
  168083. }
  168084. case 4:
  168085. {
  168086. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168087. png_bytep dp = row + (png_size_t)row_width - 1;
  168088. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168089. for (i = 0; i < row_width; i++)
  168090. {
  168091. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168092. if (shift == 4)
  168093. {
  168094. shift = 0;
  168095. sp--;
  168096. }
  168097. else
  168098. shift = 4;
  168099. dp--;
  168100. }
  168101. break;
  168102. }
  168103. }
  168104. row_info->bit_depth = 8;
  168105. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168106. row_info->rowbytes = row_width * row_info->channels;
  168107. }
  168108. }
  168109. #endif
  168110. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168111. void /* PRIVATE */
  168112. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168113. {
  168114. png_debug(1, "in png_do_unshift\n");
  168115. if (
  168116. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168117. row != NULL && row_info != NULL && sig_bits != NULL &&
  168118. #endif
  168119. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168120. {
  168121. int shift[4];
  168122. int channels = 0;
  168123. int c;
  168124. png_uint_16 value = 0;
  168125. png_uint_32 row_width = row_info->width;
  168126. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168127. {
  168128. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168129. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168130. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168131. }
  168132. else
  168133. {
  168134. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168135. }
  168136. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168137. {
  168138. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168139. }
  168140. for (c = 0; c < channels; c++)
  168141. {
  168142. if (shift[c] <= 0)
  168143. shift[c] = 0;
  168144. else
  168145. value = 1;
  168146. }
  168147. if (!value)
  168148. return;
  168149. switch (row_info->bit_depth)
  168150. {
  168151. case 2:
  168152. {
  168153. png_bytep bp;
  168154. png_uint_32 i;
  168155. png_uint_32 istop = row_info->rowbytes;
  168156. for (bp = row, i = 0; i < istop; i++)
  168157. {
  168158. *bp >>= 1;
  168159. *bp++ &= 0x55;
  168160. }
  168161. break;
  168162. }
  168163. case 4:
  168164. {
  168165. png_bytep bp = row;
  168166. png_uint_32 i;
  168167. png_uint_32 istop = row_info->rowbytes;
  168168. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168169. (png_byte)((int)0xf >> shift[0]));
  168170. for (i = 0; i < istop; i++)
  168171. {
  168172. *bp >>= shift[0];
  168173. *bp++ &= mask;
  168174. }
  168175. break;
  168176. }
  168177. case 8:
  168178. {
  168179. png_bytep bp = row;
  168180. png_uint_32 i;
  168181. png_uint_32 istop = row_width * channels;
  168182. for (i = 0; i < istop; i++)
  168183. {
  168184. *bp++ >>= shift[i%channels];
  168185. }
  168186. break;
  168187. }
  168188. case 16:
  168189. {
  168190. png_bytep bp = row;
  168191. png_uint_32 i;
  168192. png_uint_32 istop = channels * row_width;
  168193. for (i = 0; i < istop; i++)
  168194. {
  168195. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168196. value >>= shift[i%channels];
  168197. *bp++ = (png_byte)(value >> 8);
  168198. *bp++ = (png_byte)(value & 0xff);
  168199. }
  168200. break;
  168201. }
  168202. }
  168203. }
  168204. }
  168205. #endif
  168206. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168207. void /* PRIVATE */
  168208. png_do_chop(png_row_infop row_info, png_bytep row)
  168209. {
  168210. png_debug(1, "in png_do_chop\n");
  168211. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168212. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168213. #else
  168214. if (row_info->bit_depth == 16)
  168215. #endif
  168216. {
  168217. png_bytep sp = row;
  168218. png_bytep dp = row;
  168219. png_uint_32 i;
  168220. png_uint_32 istop = row_info->width * row_info->channels;
  168221. for (i = 0; i<istop; i++, sp += 2, dp++)
  168222. {
  168223. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168224. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168225. #else
  168226. *dp = *sp;
  168227. #endif
  168228. }
  168229. row_info->bit_depth = 8;
  168230. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168231. row_info->rowbytes = row_info->width * row_info->channels;
  168232. }
  168233. }
  168234. #endif
  168235. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168236. void /* PRIVATE */
  168237. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168238. {
  168239. png_debug(1, "in png_do_read_swap_alpha\n");
  168240. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168241. if (row != NULL && row_info != NULL)
  168242. #endif
  168243. {
  168244. png_uint_32 row_width = row_info->width;
  168245. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168246. {
  168247. if (row_info->bit_depth == 8)
  168248. {
  168249. png_bytep sp = row + row_info->rowbytes;
  168250. png_bytep dp = sp;
  168251. png_byte save;
  168252. png_uint_32 i;
  168253. for (i = 0; i < row_width; i++)
  168254. {
  168255. save = *(--sp);
  168256. *(--dp) = *(--sp);
  168257. *(--dp) = *(--sp);
  168258. *(--dp) = *(--sp);
  168259. *(--dp) = save;
  168260. }
  168261. }
  168262. else
  168263. {
  168264. png_bytep sp = row + row_info->rowbytes;
  168265. png_bytep dp = sp;
  168266. png_byte save[2];
  168267. png_uint_32 i;
  168268. for (i = 0; i < row_width; i++)
  168269. {
  168270. save[0] = *(--sp);
  168271. save[1] = *(--sp);
  168272. *(--dp) = *(--sp);
  168273. *(--dp) = *(--sp);
  168274. *(--dp) = *(--sp);
  168275. *(--dp) = *(--sp);
  168276. *(--dp) = *(--sp);
  168277. *(--dp) = *(--sp);
  168278. *(--dp) = save[0];
  168279. *(--dp) = save[1];
  168280. }
  168281. }
  168282. }
  168283. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168284. {
  168285. if (row_info->bit_depth == 8)
  168286. {
  168287. png_bytep sp = row + row_info->rowbytes;
  168288. png_bytep dp = sp;
  168289. png_byte save;
  168290. png_uint_32 i;
  168291. for (i = 0; i < row_width; i++)
  168292. {
  168293. save = *(--sp);
  168294. *(--dp) = *(--sp);
  168295. *(--dp) = save;
  168296. }
  168297. }
  168298. else
  168299. {
  168300. png_bytep sp = row + row_info->rowbytes;
  168301. png_bytep dp = sp;
  168302. png_byte save[2];
  168303. png_uint_32 i;
  168304. for (i = 0; i < row_width; i++)
  168305. {
  168306. save[0] = *(--sp);
  168307. save[1] = *(--sp);
  168308. *(--dp) = *(--sp);
  168309. *(--dp) = *(--sp);
  168310. *(--dp) = save[0];
  168311. *(--dp) = save[1];
  168312. }
  168313. }
  168314. }
  168315. }
  168316. }
  168317. #endif
  168318. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168319. void /* PRIVATE */
  168320. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168321. {
  168322. png_debug(1, "in png_do_read_invert_alpha\n");
  168323. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168324. if (row != NULL && row_info != NULL)
  168325. #endif
  168326. {
  168327. png_uint_32 row_width = row_info->width;
  168328. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168329. {
  168330. if (row_info->bit_depth == 8)
  168331. {
  168332. png_bytep sp = row + row_info->rowbytes;
  168333. png_bytep dp = sp;
  168334. png_uint_32 i;
  168335. for (i = 0; i < row_width; i++)
  168336. {
  168337. *(--dp) = (png_byte)(255 - *(--sp));
  168338. sp-=3;
  168339. dp=sp;
  168340. }
  168341. }
  168342. else
  168343. {
  168344. png_bytep sp = row + row_info->rowbytes;
  168345. png_bytep dp = sp;
  168346. png_uint_32 i;
  168347. for (i = 0; i < row_width; i++)
  168348. {
  168349. *(--dp) = (png_byte)(255 - *(--sp));
  168350. *(--dp) = (png_byte)(255 - *(--sp));
  168351. sp-=6;
  168352. dp=sp;
  168353. }
  168354. }
  168355. }
  168356. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168357. {
  168358. if (row_info->bit_depth == 8)
  168359. {
  168360. png_bytep sp = row + row_info->rowbytes;
  168361. png_bytep dp = sp;
  168362. png_uint_32 i;
  168363. for (i = 0; i < row_width; i++)
  168364. {
  168365. *(--dp) = (png_byte)(255 - *(--sp));
  168366. *(--dp) = *(--sp);
  168367. }
  168368. }
  168369. else
  168370. {
  168371. png_bytep sp = row + row_info->rowbytes;
  168372. png_bytep dp = sp;
  168373. png_uint_32 i;
  168374. for (i = 0; i < row_width; i++)
  168375. {
  168376. *(--dp) = (png_byte)(255 - *(--sp));
  168377. *(--dp) = (png_byte)(255 - *(--sp));
  168378. sp-=2;
  168379. dp=sp;
  168380. }
  168381. }
  168382. }
  168383. }
  168384. }
  168385. #endif
  168386. #if defined(PNG_READ_FILLER_SUPPORTED)
  168387. void /* PRIVATE */
  168388. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168389. png_uint_32 filler, png_uint_32 flags)
  168390. {
  168391. png_uint_32 i;
  168392. png_uint_32 row_width = row_info->width;
  168393. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168394. png_byte lo_filler = (png_byte)(filler & 0xff);
  168395. png_debug(1, "in png_do_read_filler\n");
  168396. if (
  168397. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168398. row != NULL && row_info != NULL &&
  168399. #endif
  168400. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168401. {
  168402. if(row_info->bit_depth == 8)
  168403. {
  168404. if (flags & PNG_FLAG_FILLER_AFTER)
  168405. {
  168406. png_bytep sp = row + (png_size_t)row_width;
  168407. png_bytep dp = sp + (png_size_t)row_width;
  168408. for (i = 1; i < row_width; i++)
  168409. {
  168410. *(--dp) = lo_filler;
  168411. *(--dp) = *(--sp);
  168412. }
  168413. *(--dp) = lo_filler;
  168414. row_info->channels = 2;
  168415. row_info->pixel_depth = 16;
  168416. row_info->rowbytes = row_width * 2;
  168417. }
  168418. else
  168419. {
  168420. png_bytep sp = row + (png_size_t)row_width;
  168421. png_bytep dp = sp + (png_size_t)row_width;
  168422. for (i = 0; i < row_width; i++)
  168423. {
  168424. *(--dp) = *(--sp);
  168425. *(--dp) = lo_filler;
  168426. }
  168427. row_info->channels = 2;
  168428. row_info->pixel_depth = 16;
  168429. row_info->rowbytes = row_width * 2;
  168430. }
  168431. }
  168432. else if(row_info->bit_depth == 16)
  168433. {
  168434. if (flags & PNG_FLAG_FILLER_AFTER)
  168435. {
  168436. png_bytep sp = row + (png_size_t)row_width * 2;
  168437. png_bytep dp = sp + (png_size_t)row_width * 2;
  168438. for (i = 1; i < row_width; i++)
  168439. {
  168440. *(--dp) = hi_filler;
  168441. *(--dp) = lo_filler;
  168442. *(--dp) = *(--sp);
  168443. *(--dp) = *(--sp);
  168444. }
  168445. *(--dp) = hi_filler;
  168446. *(--dp) = lo_filler;
  168447. row_info->channels = 2;
  168448. row_info->pixel_depth = 32;
  168449. row_info->rowbytes = row_width * 4;
  168450. }
  168451. else
  168452. {
  168453. png_bytep sp = row + (png_size_t)row_width * 2;
  168454. png_bytep dp = sp + (png_size_t)row_width * 2;
  168455. for (i = 0; i < row_width; i++)
  168456. {
  168457. *(--dp) = *(--sp);
  168458. *(--dp) = *(--sp);
  168459. *(--dp) = hi_filler;
  168460. *(--dp) = lo_filler;
  168461. }
  168462. row_info->channels = 2;
  168463. row_info->pixel_depth = 32;
  168464. row_info->rowbytes = row_width * 4;
  168465. }
  168466. }
  168467. } /* COLOR_TYPE == GRAY */
  168468. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168469. {
  168470. if(row_info->bit_depth == 8)
  168471. {
  168472. if (flags & PNG_FLAG_FILLER_AFTER)
  168473. {
  168474. png_bytep sp = row + (png_size_t)row_width * 3;
  168475. png_bytep dp = sp + (png_size_t)row_width;
  168476. for (i = 1; i < row_width; i++)
  168477. {
  168478. *(--dp) = lo_filler;
  168479. *(--dp) = *(--sp);
  168480. *(--dp) = *(--sp);
  168481. *(--dp) = *(--sp);
  168482. }
  168483. *(--dp) = lo_filler;
  168484. row_info->channels = 4;
  168485. row_info->pixel_depth = 32;
  168486. row_info->rowbytes = row_width * 4;
  168487. }
  168488. else
  168489. {
  168490. png_bytep sp = row + (png_size_t)row_width * 3;
  168491. png_bytep dp = sp + (png_size_t)row_width;
  168492. for (i = 0; i < row_width; i++)
  168493. {
  168494. *(--dp) = *(--sp);
  168495. *(--dp) = *(--sp);
  168496. *(--dp) = *(--sp);
  168497. *(--dp) = lo_filler;
  168498. }
  168499. row_info->channels = 4;
  168500. row_info->pixel_depth = 32;
  168501. row_info->rowbytes = row_width * 4;
  168502. }
  168503. }
  168504. else if(row_info->bit_depth == 16)
  168505. {
  168506. if (flags & PNG_FLAG_FILLER_AFTER)
  168507. {
  168508. png_bytep sp = row + (png_size_t)row_width * 6;
  168509. png_bytep dp = sp + (png_size_t)row_width * 2;
  168510. for (i = 1; i < row_width; i++)
  168511. {
  168512. *(--dp) = hi_filler;
  168513. *(--dp) = lo_filler;
  168514. *(--dp) = *(--sp);
  168515. *(--dp) = *(--sp);
  168516. *(--dp) = *(--sp);
  168517. *(--dp) = *(--sp);
  168518. *(--dp) = *(--sp);
  168519. *(--dp) = *(--sp);
  168520. }
  168521. *(--dp) = hi_filler;
  168522. *(--dp) = lo_filler;
  168523. row_info->channels = 4;
  168524. row_info->pixel_depth = 64;
  168525. row_info->rowbytes = row_width * 8;
  168526. }
  168527. else
  168528. {
  168529. png_bytep sp = row + (png_size_t)row_width * 6;
  168530. png_bytep dp = sp + (png_size_t)row_width * 2;
  168531. for (i = 0; i < row_width; i++)
  168532. {
  168533. *(--dp) = *(--sp);
  168534. *(--dp) = *(--sp);
  168535. *(--dp) = *(--sp);
  168536. *(--dp) = *(--sp);
  168537. *(--dp) = *(--sp);
  168538. *(--dp) = *(--sp);
  168539. *(--dp) = hi_filler;
  168540. *(--dp) = lo_filler;
  168541. }
  168542. row_info->channels = 4;
  168543. row_info->pixel_depth = 64;
  168544. row_info->rowbytes = row_width * 8;
  168545. }
  168546. }
  168547. } /* COLOR_TYPE == RGB */
  168548. }
  168549. #endif
  168550. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168551. void /* PRIVATE */
  168552. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  168553. {
  168554. png_uint_32 i;
  168555. png_uint_32 row_width = row_info->width;
  168556. png_debug(1, "in png_do_gray_to_rgb\n");
  168557. if (row_info->bit_depth >= 8 &&
  168558. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168559. row != NULL && row_info != NULL &&
  168560. #endif
  168561. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  168562. {
  168563. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168564. {
  168565. if (row_info->bit_depth == 8)
  168566. {
  168567. png_bytep sp = row + (png_size_t)row_width - 1;
  168568. png_bytep dp = sp + (png_size_t)row_width * 2;
  168569. for (i = 0; i < row_width; i++)
  168570. {
  168571. *(dp--) = *sp;
  168572. *(dp--) = *sp;
  168573. *(dp--) = *(sp--);
  168574. }
  168575. }
  168576. else
  168577. {
  168578. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168579. png_bytep dp = sp + (png_size_t)row_width * 4;
  168580. for (i = 0; i < row_width; i++)
  168581. {
  168582. *(dp--) = *sp;
  168583. *(dp--) = *(sp - 1);
  168584. *(dp--) = *sp;
  168585. *(dp--) = *(sp - 1);
  168586. *(dp--) = *(sp--);
  168587. *(dp--) = *(sp--);
  168588. }
  168589. }
  168590. }
  168591. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168592. {
  168593. if (row_info->bit_depth == 8)
  168594. {
  168595. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  168596. png_bytep dp = sp + (png_size_t)row_width * 2;
  168597. for (i = 0; i < row_width; i++)
  168598. {
  168599. *(dp--) = *(sp--);
  168600. *(dp--) = *sp;
  168601. *(dp--) = *sp;
  168602. *(dp--) = *(sp--);
  168603. }
  168604. }
  168605. else
  168606. {
  168607. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  168608. png_bytep dp = sp + (png_size_t)row_width * 4;
  168609. for (i = 0; i < row_width; i++)
  168610. {
  168611. *(dp--) = *(sp--);
  168612. *(dp--) = *(sp--);
  168613. *(dp--) = *sp;
  168614. *(dp--) = *(sp - 1);
  168615. *(dp--) = *sp;
  168616. *(dp--) = *(sp - 1);
  168617. *(dp--) = *(sp--);
  168618. *(dp--) = *(sp--);
  168619. }
  168620. }
  168621. }
  168622. row_info->channels += (png_byte)2;
  168623. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  168624. row_info->pixel_depth = (png_byte)(row_info->channels *
  168625. row_info->bit_depth);
  168626. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168627. }
  168628. }
  168629. #endif
  168630. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168631. int /* PRIVATE */
  168632. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  168633. {
  168634. png_uint_32 i;
  168635. png_uint_32 row_width = row_info->width;
  168636. int rgb_error = 0;
  168637. png_debug(1, "in png_do_rgb_to_gray\n");
  168638. if (
  168639. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168640. row != NULL && row_info != NULL &&
  168641. #endif
  168642. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  168643. {
  168644. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  168645. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  168646. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  168647. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168648. {
  168649. if (row_info->bit_depth == 8)
  168650. {
  168651. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168652. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168653. {
  168654. png_bytep sp = row;
  168655. png_bytep dp = row;
  168656. for (i = 0; i < row_width; i++)
  168657. {
  168658. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168659. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168660. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168661. if(red != green || red != blue)
  168662. {
  168663. rgb_error |= 1;
  168664. *(dp++) = png_ptr->gamma_from_1[
  168665. (rc*red+gc*green+bc*blue)>>15];
  168666. }
  168667. else
  168668. *(dp++) = *(sp-1);
  168669. }
  168670. }
  168671. else
  168672. #endif
  168673. {
  168674. png_bytep sp = row;
  168675. png_bytep dp = row;
  168676. for (i = 0; i < row_width; i++)
  168677. {
  168678. png_byte red = *(sp++);
  168679. png_byte green = *(sp++);
  168680. png_byte blue = *(sp++);
  168681. if(red != green || red != blue)
  168682. {
  168683. rgb_error |= 1;
  168684. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  168685. }
  168686. else
  168687. *(dp++) = *(sp-1);
  168688. }
  168689. }
  168690. }
  168691. else /* RGB bit_depth == 16 */
  168692. {
  168693. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168694. if (png_ptr->gamma_16_to_1 != NULL &&
  168695. png_ptr->gamma_16_from_1 != NULL)
  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, w;
  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. w = red;
  168707. else
  168708. {
  168709. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168710. png_ptr->gamma_shift][red>>8];
  168711. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168712. png_ptr->gamma_shift][green>>8];
  168713. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168714. png_ptr->gamma_shift][blue>>8];
  168715. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  168716. + bc*blue_1)>>15);
  168717. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168718. png_ptr->gamma_shift][gray16 >> 8];
  168719. rgb_error |= 1;
  168720. }
  168721. *(dp++) = (png_byte)((w>>8) & 0xff);
  168722. *(dp++) = (png_byte)(w & 0xff);
  168723. }
  168724. }
  168725. else
  168726. #endif
  168727. {
  168728. png_bytep sp = row;
  168729. png_bytep dp = row;
  168730. for (i = 0; i < row_width; i++)
  168731. {
  168732. png_uint_16 red, green, blue, gray16;
  168733. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168734. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168735. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168736. if(red != green || red != blue)
  168737. rgb_error |= 1;
  168738. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168739. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168740. *(dp++) = (png_byte)(gray16 & 0xff);
  168741. }
  168742. }
  168743. }
  168744. }
  168745. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168746. {
  168747. if (row_info->bit_depth == 8)
  168748. {
  168749. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168750. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  168751. {
  168752. png_bytep sp = row;
  168753. png_bytep dp = row;
  168754. for (i = 0; i < row_width; i++)
  168755. {
  168756. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  168757. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  168758. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  168759. if(red != green || red != blue)
  168760. rgb_error |= 1;
  168761. *(dp++) = png_ptr->gamma_from_1
  168762. [(rc*red + gc*green + bc*blue)>>15];
  168763. *(dp++) = *(sp++); /* alpha */
  168764. }
  168765. }
  168766. else
  168767. #endif
  168768. {
  168769. png_bytep sp = row;
  168770. png_bytep dp = row;
  168771. for (i = 0; i < row_width; i++)
  168772. {
  168773. png_byte red = *(sp++);
  168774. png_byte green = *(sp++);
  168775. png_byte blue = *(sp++);
  168776. if(red != green || red != blue)
  168777. rgb_error |= 1;
  168778. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  168779. *(dp++) = *(sp++); /* alpha */
  168780. }
  168781. }
  168782. }
  168783. else /* RGBA bit_depth == 16 */
  168784. {
  168785. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  168786. if (png_ptr->gamma_16_to_1 != NULL &&
  168787. png_ptr->gamma_16_from_1 != NULL)
  168788. {
  168789. png_bytep sp = row;
  168790. png_bytep dp = row;
  168791. for (i = 0; i < row_width; i++)
  168792. {
  168793. png_uint_16 red, green, blue, w;
  168794. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168795. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168796. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  168797. if(red == green && red == blue)
  168798. w = red;
  168799. else
  168800. {
  168801. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  168802. png_ptr->gamma_shift][red>>8];
  168803. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  168804. png_ptr->gamma_shift][green>>8];
  168805. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  168806. png_ptr->gamma_shift][blue>>8];
  168807. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  168808. + gc * green_1 + bc * blue_1)>>15);
  168809. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  168810. png_ptr->gamma_shift][gray16 >> 8];
  168811. rgb_error |= 1;
  168812. }
  168813. *(dp++) = (png_byte)((w>>8) & 0xff);
  168814. *(dp++) = (png_byte)(w & 0xff);
  168815. *(dp++) = *(sp++); /* alpha */
  168816. *(dp++) = *(sp++);
  168817. }
  168818. }
  168819. else
  168820. #endif
  168821. {
  168822. png_bytep sp = row;
  168823. png_bytep dp = row;
  168824. for (i = 0; i < row_width; i++)
  168825. {
  168826. png_uint_16 red, green, blue, gray16;
  168827. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168828. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168829. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  168830. if(red != green || red != blue)
  168831. rgb_error |= 1;
  168832. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  168833. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  168834. *(dp++) = (png_byte)(gray16 & 0xff);
  168835. *(dp++) = *(sp++); /* alpha */
  168836. *(dp++) = *(sp++);
  168837. }
  168838. }
  168839. }
  168840. }
  168841. row_info->channels -= (png_byte)2;
  168842. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  168843. row_info->pixel_depth = (png_byte)(row_info->channels *
  168844. row_info->bit_depth);
  168845. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  168846. }
  168847. return rgb_error;
  168848. }
  168849. #endif
  168850. void PNGAPI
  168851. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  168852. {
  168853. int num_palette;
  168854. int color_inc;
  168855. int i;
  168856. int v;
  168857. png_debug(1, "in png_do_build_grayscale_palette\n");
  168858. if (palette == NULL)
  168859. return;
  168860. switch (bit_depth)
  168861. {
  168862. case 1:
  168863. num_palette = 2;
  168864. color_inc = 0xff;
  168865. break;
  168866. case 2:
  168867. num_palette = 4;
  168868. color_inc = 0x55;
  168869. break;
  168870. case 4:
  168871. num_palette = 16;
  168872. color_inc = 0x11;
  168873. break;
  168874. case 8:
  168875. num_palette = 256;
  168876. color_inc = 1;
  168877. break;
  168878. default:
  168879. num_palette = 0;
  168880. color_inc = 0;
  168881. break;
  168882. }
  168883. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  168884. {
  168885. palette[i].red = (png_byte)v;
  168886. palette[i].green = (png_byte)v;
  168887. palette[i].blue = (png_byte)v;
  168888. }
  168889. }
  168890. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  168891. void /* PRIVATE */
  168892. png_correct_palette(png_structp png_ptr, png_colorp palette,
  168893. int num_palette)
  168894. {
  168895. png_debug(1, "in png_correct_palette\n");
  168896. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  168897. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  168898. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  168899. {
  168900. png_color back, back_1;
  168901. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168902. {
  168903. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168904. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168905. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168906. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168907. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168908. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168909. }
  168910. else
  168911. {
  168912. double g;
  168913. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  168914. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  168915. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  168916. {
  168917. back.red = png_ptr->background.red;
  168918. back.green = png_ptr->background.green;
  168919. back.blue = png_ptr->background.blue;
  168920. }
  168921. else
  168922. {
  168923. back.red =
  168924. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  168925. 255.0 + 0.5);
  168926. back.green =
  168927. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  168928. 255.0 + 0.5);
  168929. back.blue =
  168930. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  168931. 255.0 + 0.5);
  168932. }
  168933. g = 1.0 / png_ptr->background_gamma;
  168934. back_1.red =
  168935. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  168936. 255.0 + 0.5);
  168937. back_1.green =
  168938. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  168939. 255.0 + 0.5);
  168940. back_1.blue =
  168941. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  168942. 255.0 + 0.5);
  168943. }
  168944. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168945. {
  168946. png_uint_32 i;
  168947. for (i = 0; i < (png_uint_32)num_palette; i++)
  168948. {
  168949. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  168950. {
  168951. palette[i] = back;
  168952. }
  168953. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168954. {
  168955. png_byte v, w;
  168956. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  168957. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168958. palette[i].red = png_ptr->gamma_from_1[w];
  168959. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  168960. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168961. palette[i].green = png_ptr->gamma_from_1[w];
  168962. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  168963. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168964. palette[i].blue = png_ptr->gamma_from_1[w];
  168965. }
  168966. else
  168967. {
  168968. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168969. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168970. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168971. }
  168972. }
  168973. }
  168974. else
  168975. {
  168976. int i;
  168977. for (i = 0; i < num_palette; i++)
  168978. {
  168979. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  168980. {
  168981. palette[i] = back;
  168982. }
  168983. else
  168984. {
  168985. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168986. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168987. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168988. }
  168989. }
  168990. }
  168991. }
  168992. else
  168993. #endif
  168994. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168995. if (png_ptr->transformations & PNG_GAMMA)
  168996. {
  168997. int i;
  168998. for (i = 0; i < num_palette; i++)
  168999. {
  169000. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169001. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169002. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169003. }
  169004. }
  169005. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169006. else
  169007. #endif
  169008. #endif
  169009. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169010. if (png_ptr->transformations & PNG_BACKGROUND)
  169011. {
  169012. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169013. {
  169014. png_color back;
  169015. back.red = (png_byte)png_ptr->background.red;
  169016. back.green = (png_byte)png_ptr->background.green;
  169017. back.blue = (png_byte)png_ptr->background.blue;
  169018. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169019. {
  169020. if (png_ptr->trans[i] == 0)
  169021. {
  169022. palette[i].red = back.red;
  169023. palette[i].green = back.green;
  169024. palette[i].blue = back.blue;
  169025. }
  169026. else if (png_ptr->trans[i] != 0xff)
  169027. {
  169028. png_composite(palette[i].red, png_ptr->palette[i].red,
  169029. png_ptr->trans[i], back.red);
  169030. png_composite(palette[i].green, png_ptr->palette[i].green,
  169031. png_ptr->trans[i], back.green);
  169032. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169033. png_ptr->trans[i], back.blue);
  169034. }
  169035. }
  169036. }
  169037. else /* assume grayscale palette (what else could it be?) */
  169038. {
  169039. int i;
  169040. for (i = 0; i < num_palette; i++)
  169041. {
  169042. if (i == (png_byte)png_ptr->trans_values.gray)
  169043. {
  169044. palette[i].red = (png_byte)png_ptr->background.red;
  169045. palette[i].green = (png_byte)png_ptr->background.green;
  169046. palette[i].blue = (png_byte)png_ptr->background.blue;
  169047. }
  169048. }
  169049. }
  169050. }
  169051. #endif
  169052. }
  169053. #endif
  169054. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169055. void /* PRIVATE */
  169056. png_do_background(png_row_infop row_info, png_bytep row,
  169057. png_color_16p trans_values, png_color_16p background
  169058. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169059. , png_color_16p background_1,
  169060. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169061. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169062. png_uint_16pp gamma_16_to_1, int gamma_shift
  169063. #endif
  169064. )
  169065. {
  169066. png_bytep sp, dp;
  169067. png_uint_32 i;
  169068. png_uint_32 row_width=row_info->width;
  169069. int shift;
  169070. png_debug(1, "in png_do_background\n");
  169071. if (background != NULL &&
  169072. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169073. row != NULL && row_info != NULL &&
  169074. #endif
  169075. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169076. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169077. {
  169078. switch (row_info->color_type)
  169079. {
  169080. case PNG_COLOR_TYPE_GRAY:
  169081. {
  169082. switch (row_info->bit_depth)
  169083. {
  169084. case 1:
  169085. {
  169086. sp = row;
  169087. shift = 7;
  169088. for (i = 0; i < row_width; i++)
  169089. {
  169090. if ((png_uint_16)((*sp >> shift) & 0x01)
  169091. == trans_values->gray)
  169092. {
  169093. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169094. *sp |= (png_byte)(background->gray << shift);
  169095. }
  169096. if (!shift)
  169097. {
  169098. shift = 7;
  169099. sp++;
  169100. }
  169101. else
  169102. shift--;
  169103. }
  169104. break;
  169105. }
  169106. case 2:
  169107. {
  169108. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169109. if (gamma_table != NULL)
  169110. {
  169111. sp = row;
  169112. shift = 6;
  169113. for (i = 0; i < row_width; i++)
  169114. {
  169115. if ((png_uint_16)((*sp >> shift) & 0x03)
  169116. == trans_values->gray)
  169117. {
  169118. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169119. *sp |= (png_byte)(background->gray << shift);
  169120. }
  169121. else
  169122. {
  169123. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169124. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169125. (p << 4) | (p << 6)] >> 6) & 0x03);
  169126. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169127. *sp |= (png_byte)(g << shift);
  169128. }
  169129. if (!shift)
  169130. {
  169131. shift = 6;
  169132. sp++;
  169133. }
  169134. else
  169135. shift -= 2;
  169136. }
  169137. }
  169138. else
  169139. #endif
  169140. {
  169141. sp = row;
  169142. shift = 6;
  169143. for (i = 0; i < row_width; i++)
  169144. {
  169145. if ((png_uint_16)((*sp >> shift) & 0x03)
  169146. == trans_values->gray)
  169147. {
  169148. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169149. *sp |= (png_byte)(background->gray << shift);
  169150. }
  169151. if (!shift)
  169152. {
  169153. shift = 6;
  169154. sp++;
  169155. }
  169156. else
  169157. shift -= 2;
  169158. }
  169159. }
  169160. break;
  169161. }
  169162. case 4:
  169163. {
  169164. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169165. if (gamma_table != NULL)
  169166. {
  169167. sp = row;
  169168. shift = 4;
  169169. for (i = 0; i < row_width; i++)
  169170. {
  169171. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169172. == trans_values->gray)
  169173. {
  169174. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169175. *sp |= (png_byte)(background->gray << shift);
  169176. }
  169177. else
  169178. {
  169179. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169180. png_byte g = (png_byte)((gamma_table[p |
  169181. (p << 4)] >> 4) & 0x0f);
  169182. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169183. *sp |= (png_byte)(g << shift);
  169184. }
  169185. if (!shift)
  169186. {
  169187. shift = 4;
  169188. sp++;
  169189. }
  169190. else
  169191. shift -= 4;
  169192. }
  169193. }
  169194. else
  169195. #endif
  169196. {
  169197. sp = row;
  169198. shift = 4;
  169199. for (i = 0; i < row_width; i++)
  169200. {
  169201. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169202. == trans_values->gray)
  169203. {
  169204. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169205. *sp |= (png_byte)(background->gray << shift);
  169206. }
  169207. if (!shift)
  169208. {
  169209. shift = 4;
  169210. sp++;
  169211. }
  169212. else
  169213. shift -= 4;
  169214. }
  169215. }
  169216. break;
  169217. }
  169218. case 8:
  169219. {
  169220. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169221. if (gamma_table != NULL)
  169222. {
  169223. sp = row;
  169224. for (i = 0; i < row_width; i++, sp++)
  169225. {
  169226. if (*sp == trans_values->gray)
  169227. {
  169228. *sp = (png_byte)background->gray;
  169229. }
  169230. else
  169231. {
  169232. *sp = gamma_table[*sp];
  169233. }
  169234. }
  169235. }
  169236. else
  169237. #endif
  169238. {
  169239. sp = row;
  169240. for (i = 0; i < row_width; i++, sp++)
  169241. {
  169242. if (*sp == trans_values->gray)
  169243. {
  169244. *sp = (png_byte)background->gray;
  169245. }
  169246. }
  169247. }
  169248. break;
  169249. }
  169250. case 16:
  169251. {
  169252. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169253. if (gamma_16 != NULL)
  169254. {
  169255. sp = row;
  169256. for (i = 0; i < row_width; i++, sp += 2)
  169257. {
  169258. png_uint_16 v;
  169259. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169260. if (v == trans_values->gray)
  169261. {
  169262. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169263. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169264. }
  169265. else
  169266. {
  169267. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169268. *sp = (png_byte)((v >> 8) & 0xff);
  169269. *(sp + 1) = (png_byte)(v & 0xff);
  169270. }
  169271. }
  169272. }
  169273. else
  169274. #endif
  169275. {
  169276. sp = row;
  169277. for (i = 0; i < row_width; i++, sp += 2)
  169278. {
  169279. png_uint_16 v;
  169280. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169281. if (v == trans_values->gray)
  169282. {
  169283. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169284. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169285. }
  169286. }
  169287. }
  169288. break;
  169289. }
  169290. }
  169291. break;
  169292. }
  169293. case PNG_COLOR_TYPE_RGB:
  169294. {
  169295. if (row_info->bit_depth == 8)
  169296. {
  169297. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169298. if (gamma_table != NULL)
  169299. {
  169300. sp = row;
  169301. for (i = 0; i < row_width; i++, sp += 3)
  169302. {
  169303. if (*sp == trans_values->red &&
  169304. *(sp + 1) == trans_values->green &&
  169305. *(sp + 2) == trans_values->blue)
  169306. {
  169307. *sp = (png_byte)background->red;
  169308. *(sp + 1) = (png_byte)background->green;
  169309. *(sp + 2) = (png_byte)background->blue;
  169310. }
  169311. else
  169312. {
  169313. *sp = gamma_table[*sp];
  169314. *(sp + 1) = gamma_table[*(sp + 1)];
  169315. *(sp + 2) = gamma_table[*(sp + 2)];
  169316. }
  169317. }
  169318. }
  169319. else
  169320. #endif
  169321. {
  169322. sp = row;
  169323. for (i = 0; i < row_width; i++, sp += 3)
  169324. {
  169325. if (*sp == trans_values->red &&
  169326. *(sp + 1) == trans_values->green &&
  169327. *(sp + 2) == trans_values->blue)
  169328. {
  169329. *sp = (png_byte)background->red;
  169330. *(sp + 1) = (png_byte)background->green;
  169331. *(sp + 2) = (png_byte)background->blue;
  169332. }
  169333. }
  169334. }
  169335. }
  169336. else /* if (row_info->bit_depth == 16) */
  169337. {
  169338. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169339. if (gamma_16 != NULL)
  169340. {
  169341. sp = row;
  169342. for (i = 0; i < row_width; i++, sp += 6)
  169343. {
  169344. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169345. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169346. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169347. if (r == trans_values->red && g == trans_values->green &&
  169348. b == trans_values->blue)
  169349. {
  169350. *sp = (png_byte)((background->red >> 8) & 0xff);
  169351. *(sp + 1) = (png_byte)(background->red & 0xff);
  169352. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169353. *(sp + 3) = (png_byte)(background->green & 0xff);
  169354. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169355. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169356. }
  169357. else
  169358. {
  169359. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169360. *sp = (png_byte)((v >> 8) & 0xff);
  169361. *(sp + 1) = (png_byte)(v & 0xff);
  169362. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169363. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169364. *(sp + 3) = (png_byte)(v & 0xff);
  169365. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169366. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169367. *(sp + 5) = (png_byte)(v & 0xff);
  169368. }
  169369. }
  169370. }
  169371. else
  169372. #endif
  169373. {
  169374. sp = row;
  169375. for (i = 0; i < row_width; i++, sp += 6)
  169376. {
  169377. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169378. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169379. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169380. if (r == trans_values->red && g == trans_values->green &&
  169381. b == trans_values->blue)
  169382. {
  169383. *sp = (png_byte)((background->red >> 8) & 0xff);
  169384. *(sp + 1) = (png_byte)(background->red & 0xff);
  169385. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169386. *(sp + 3) = (png_byte)(background->green & 0xff);
  169387. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169388. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169389. }
  169390. }
  169391. }
  169392. }
  169393. break;
  169394. }
  169395. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169396. {
  169397. if (row_info->bit_depth == 8)
  169398. {
  169399. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169400. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169401. gamma_table != NULL)
  169402. {
  169403. sp = row;
  169404. dp = row;
  169405. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169406. {
  169407. png_uint_16 a = *(sp + 1);
  169408. if (a == 0xff)
  169409. {
  169410. *dp = gamma_table[*sp];
  169411. }
  169412. else if (a == 0)
  169413. {
  169414. *dp = (png_byte)background->gray;
  169415. }
  169416. else
  169417. {
  169418. png_byte v, w;
  169419. v = gamma_to_1[*sp];
  169420. png_composite(w, v, a, background_1->gray);
  169421. *dp = gamma_from_1[w];
  169422. }
  169423. }
  169424. }
  169425. else
  169426. #endif
  169427. {
  169428. sp = row;
  169429. dp = row;
  169430. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169431. {
  169432. png_byte a = *(sp + 1);
  169433. if (a == 0xff)
  169434. {
  169435. *dp = *sp;
  169436. }
  169437. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169438. else if (a == 0)
  169439. {
  169440. *dp = (png_byte)background->gray;
  169441. }
  169442. else
  169443. {
  169444. png_composite(*dp, *sp, a, background_1->gray);
  169445. }
  169446. #else
  169447. *dp = (png_byte)background->gray;
  169448. #endif
  169449. }
  169450. }
  169451. }
  169452. else /* if (png_ptr->bit_depth == 16) */
  169453. {
  169454. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169455. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169456. gamma_16_to_1 != NULL)
  169457. {
  169458. sp = row;
  169459. dp = row;
  169460. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169461. {
  169462. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169463. if (a == (png_uint_16)0xffff)
  169464. {
  169465. png_uint_16 v;
  169466. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169467. *dp = (png_byte)((v >> 8) & 0xff);
  169468. *(dp + 1) = (png_byte)(v & 0xff);
  169469. }
  169470. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169471. else if (a == 0)
  169472. #else
  169473. else
  169474. #endif
  169475. {
  169476. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169477. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169478. }
  169479. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169480. else
  169481. {
  169482. png_uint_16 g, v, w;
  169483. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169484. png_composite_16(v, g, a, background_1->gray);
  169485. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169486. *dp = (png_byte)((w >> 8) & 0xff);
  169487. *(dp + 1) = (png_byte)(w & 0xff);
  169488. }
  169489. #endif
  169490. }
  169491. }
  169492. else
  169493. #endif
  169494. {
  169495. sp = row;
  169496. dp = row;
  169497. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169498. {
  169499. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169500. if (a == (png_uint_16)0xffff)
  169501. {
  169502. png_memcpy(dp, sp, 2);
  169503. }
  169504. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169505. else if (a == 0)
  169506. #else
  169507. else
  169508. #endif
  169509. {
  169510. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169511. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169512. }
  169513. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169514. else
  169515. {
  169516. png_uint_16 g, v;
  169517. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169518. png_composite_16(v, g, a, background_1->gray);
  169519. *dp = (png_byte)((v >> 8) & 0xff);
  169520. *(dp + 1) = (png_byte)(v & 0xff);
  169521. }
  169522. #endif
  169523. }
  169524. }
  169525. }
  169526. break;
  169527. }
  169528. case PNG_COLOR_TYPE_RGB_ALPHA:
  169529. {
  169530. if (row_info->bit_depth == 8)
  169531. {
  169532. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169533. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169534. gamma_table != NULL)
  169535. {
  169536. sp = row;
  169537. dp = row;
  169538. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169539. {
  169540. png_byte a = *(sp + 3);
  169541. if (a == 0xff)
  169542. {
  169543. *dp = gamma_table[*sp];
  169544. *(dp + 1) = gamma_table[*(sp + 1)];
  169545. *(dp + 2) = gamma_table[*(sp + 2)];
  169546. }
  169547. else if (a == 0)
  169548. {
  169549. *dp = (png_byte)background->red;
  169550. *(dp + 1) = (png_byte)background->green;
  169551. *(dp + 2) = (png_byte)background->blue;
  169552. }
  169553. else
  169554. {
  169555. png_byte v, w;
  169556. v = gamma_to_1[*sp];
  169557. png_composite(w, v, a, background_1->red);
  169558. *dp = gamma_from_1[w];
  169559. v = gamma_to_1[*(sp + 1)];
  169560. png_composite(w, v, a, background_1->green);
  169561. *(dp + 1) = gamma_from_1[w];
  169562. v = gamma_to_1[*(sp + 2)];
  169563. png_composite(w, v, a, background_1->blue);
  169564. *(dp + 2) = gamma_from_1[w];
  169565. }
  169566. }
  169567. }
  169568. else
  169569. #endif
  169570. {
  169571. sp = row;
  169572. dp = row;
  169573. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  169574. {
  169575. png_byte a = *(sp + 3);
  169576. if (a == 0xff)
  169577. {
  169578. *dp = *sp;
  169579. *(dp + 1) = *(sp + 1);
  169580. *(dp + 2) = *(sp + 2);
  169581. }
  169582. else if (a == 0)
  169583. {
  169584. *dp = (png_byte)background->red;
  169585. *(dp + 1) = (png_byte)background->green;
  169586. *(dp + 2) = (png_byte)background->blue;
  169587. }
  169588. else
  169589. {
  169590. png_composite(*dp, *sp, a, background->red);
  169591. png_composite(*(dp + 1), *(sp + 1), a,
  169592. background->green);
  169593. png_composite(*(dp + 2), *(sp + 2), a,
  169594. background->blue);
  169595. }
  169596. }
  169597. }
  169598. }
  169599. else /* if (row_info->bit_depth == 16) */
  169600. {
  169601. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169602. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169603. gamma_16_to_1 != NULL)
  169604. {
  169605. sp = row;
  169606. dp = row;
  169607. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169608. {
  169609. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169610. << 8) + (png_uint_16)(*(sp + 7)));
  169611. if (a == (png_uint_16)0xffff)
  169612. {
  169613. png_uint_16 v;
  169614. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169615. *dp = (png_byte)((v >> 8) & 0xff);
  169616. *(dp + 1) = (png_byte)(v & 0xff);
  169617. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169618. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169619. *(dp + 3) = (png_byte)(v & 0xff);
  169620. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169621. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169622. *(dp + 5) = (png_byte)(v & 0xff);
  169623. }
  169624. else if (a == 0)
  169625. {
  169626. *dp = (png_byte)((background->red >> 8) & 0xff);
  169627. *(dp + 1) = (png_byte)(background->red & 0xff);
  169628. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169629. *(dp + 3) = (png_byte)(background->green & 0xff);
  169630. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169631. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169632. }
  169633. else
  169634. {
  169635. png_uint_16 v, w, x;
  169636. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169637. png_composite_16(w, v, a, background_1->red);
  169638. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169639. *dp = (png_byte)((x >> 8) & 0xff);
  169640. *(dp + 1) = (png_byte)(x & 0xff);
  169641. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169642. png_composite_16(w, v, a, background_1->green);
  169643. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  169644. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  169645. *(dp + 3) = (png_byte)(x & 0xff);
  169646. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169647. png_composite_16(w, v, a, background_1->blue);
  169648. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  169649. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  169650. *(dp + 5) = (png_byte)(x & 0xff);
  169651. }
  169652. }
  169653. }
  169654. else
  169655. #endif
  169656. {
  169657. sp = row;
  169658. dp = row;
  169659. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  169660. {
  169661. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  169662. << 8) + (png_uint_16)(*(sp + 7)));
  169663. if (a == (png_uint_16)0xffff)
  169664. {
  169665. png_memcpy(dp, sp, 6);
  169666. }
  169667. else if (a == 0)
  169668. {
  169669. *dp = (png_byte)((background->red >> 8) & 0xff);
  169670. *(dp + 1) = (png_byte)(background->red & 0xff);
  169671. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169672. *(dp + 3) = (png_byte)(background->green & 0xff);
  169673. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169674. *(dp + 5) = (png_byte)(background->blue & 0xff);
  169675. }
  169676. else
  169677. {
  169678. png_uint_16 v;
  169679. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169680. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  169681. + *(sp + 3));
  169682. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  169683. + *(sp + 5));
  169684. png_composite_16(v, r, a, background->red);
  169685. *dp = (png_byte)((v >> 8) & 0xff);
  169686. *(dp + 1) = (png_byte)(v & 0xff);
  169687. png_composite_16(v, g, a, background->green);
  169688. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  169689. *(dp + 3) = (png_byte)(v & 0xff);
  169690. png_composite_16(v, b, a, background->blue);
  169691. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  169692. *(dp + 5) = (png_byte)(v & 0xff);
  169693. }
  169694. }
  169695. }
  169696. }
  169697. break;
  169698. }
  169699. }
  169700. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  169701. {
  169702. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  169703. row_info->channels--;
  169704. row_info->pixel_depth = (png_byte)(row_info->channels *
  169705. row_info->bit_depth);
  169706. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169707. }
  169708. }
  169709. }
  169710. #endif
  169711. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169712. void /* PRIVATE */
  169713. png_do_gamma(png_row_infop row_info, png_bytep row,
  169714. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  169715. int gamma_shift)
  169716. {
  169717. png_bytep sp;
  169718. png_uint_32 i;
  169719. png_uint_32 row_width=row_info->width;
  169720. png_debug(1, "in png_do_gamma\n");
  169721. if (
  169722. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169723. row != NULL && row_info != NULL &&
  169724. #endif
  169725. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  169726. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  169727. {
  169728. switch (row_info->color_type)
  169729. {
  169730. case PNG_COLOR_TYPE_RGB:
  169731. {
  169732. if (row_info->bit_depth == 8)
  169733. {
  169734. sp = row;
  169735. for (i = 0; i < row_width; i++)
  169736. {
  169737. *sp = gamma_table[*sp];
  169738. sp++;
  169739. *sp = gamma_table[*sp];
  169740. sp++;
  169741. *sp = gamma_table[*sp];
  169742. sp++;
  169743. }
  169744. }
  169745. else /* if (row_info->bit_depth == 16) */
  169746. {
  169747. sp = row;
  169748. for (i = 0; i < row_width; i++)
  169749. {
  169750. png_uint_16 v;
  169751. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169752. *sp = (png_byte)((v >> 8) & 0xff);
  169753. *(sp + 1) = (png_byte)(v & 0xff);
  169754. sp += 2;
  169755. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169756. *sp = (png_byte)((v >> 8) & 0xff);
  169757. *(sp + 1) = (png_byte)(v & 0xff);
  169758. sp += 2;
  169759. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169760. *sp = (png_byte)((v >> 8) & 0xff);
  169761. *(sp + 1) = (png_byte)(v & 0xff);
  169762. sp += 2;
  169763. }
  169764. }
  169765. break;
  169766. }
  169767. case PNG_COLOR_TYPE_RGB_ALPHA:
  169768. {
  169769. if (row_info->bit_depth == 8)
  169770. {
  169771. sp = row;
  169772. for (i = 0; i < row_width; i++)
  169773. {
  169774. *sp = gamma_table[*sp];
  169775. sp++;
  169776. *sp = gamma_table[*sp];
  169777. sp++;
  169778. *sp = gamma_table[*sp];
  169779. sp++;
  169780. sp++;
  169781. }
  169782. }
  169783. else /* if (row_info->bit_depth == 16) */
  169784. {
  169785. sp = row;
  169786. for (i = 0; i < row_width; i++)
  169787. {
  169788. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169789. *sp = (png_byte)((v >> 8) & 0xff);
  169790. *(sp + 1) = (png_byte)(v & 0xff);
  169791. sp += 2;
  169792. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169793. *sp = (png_byte)((v >> 8) & 0xff);
  169794. *(sp + 1) = (png_byte)(v & 0xff);
  169795. sp += 2;
  169796. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169797. *sp = (png_byte)((v >> 8) & 0xff);
  169798. *(sp + 1) = (png_byte)(v & 0xff);
  169799. sp += 4;
  169800. }
  169801. }
  169802. break;
  169803. }
  169804. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169805. {
  169806. if (row_info->bit_depth == 8)
  169807. {
  169808. sp = row;
  169809. for (i = 0; i < row_width; i++)
  169810. {
  169811. *sp = gamma_table[*sp];
  169812. sp += 2;
  169813. }
  169814. }
  169815. else /* if (row_info->bit_depth == 16) */
  169816. {
  169817. sp = row;
  169818. for (i = 0; i < row_width; i++)
  169819. {
  169820. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169821. *sp = (png_byte)((v >> 8) & 0xff);
  169822. *(sp + 1) = (png_byte)(v & 0xff);
  169823. sp += 4;
  169824. }
  169825. }
  169826. break;
  169827. }
  169828. case PNG_COLOR_TYPE_GRAY:
  169829. {
  169830. if (row_info->bit_depth == 2)
  169831. {
  169832. sp = row;
  169833. for (i = 0; i < row_width; i += 4)
  169834. {
  169835. int a = *sp & 0xc0;
  169836. int b = *sp & 0x30;
  169837. int c = *sp & 0x0c;
  169838. int d = *sp & 0x03;
  169839. *sp = (png_byte)(
  169840. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  169841. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  169842. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  169843. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  169844. sp++;
  169845. }
  169846. }
  169847. if (row_info->bit_depth == 4)
  169848. {
  169849. sp = row;
  169850. for (i = 0; i < row_width; i += 2)
  169851. {
  169852. int msb = *sp & 0xf0;
  169853. int lsb = *sp & 0x0f;
  169854. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  169855. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  169856. sp++;
  169857. }
  169858. }
  169859. else if (row_info->bit_depth == 8)
  169860. {
  169861. sp = row;
  169862. for (i = 0; i < row_width; i++)
  169863. {
  169864. *sp = gamma_table[*sp];
  169865. sp++;
  169866. }
  169867. }
  169868. else if (row_info->bit_depth == 16)
  169869. {
  169870. sp = row;
  169871. for (i = 0; i < row_width; i++)
  169872. {
  169873. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  169874. *sp = (png_byte)((v >> 8) & 0xff);
  169875. *(sp + 1) = (png_byte)(v & 0xff);
  169876. sp += 2;
  169877. }
  169878. }
  169879. break;
  169880. }
  169881. }
  169882. }
  169883. }
  169884. #endif
  169885. #if defined(PNG_READ_EXPAND_SUPPORTED)
  169886. void /* PRIVATE */
  169887. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  169888. png_colorp palette, png_bytep trans, int num_trans)
  169889. {
  169890. int shift, value;
  169891. png_bytep sp, dp;
  169892. png_uint_32 i;
  169893. png_uint_32 row_width=row_info->width;
  169894. png_debug(1, "in png_do_expand_palette\n");
  169895. if (
  169896. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169897. row != NULL && row_info != NULL &&
  169898. #endif
  169899. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  169900. {
  169901. if (row_info->bit_depth < 8)
  169902. {
  169903. switch (row_info->bit_depth)
  169904. {
  169905. case 1:
  169906. {
  169907. sp = row + (png_size_t)((row_width - 1) >> 3);
  169908. dp = row + (png_size_t)row_width - 1;
  169909. shift = 7 - (int)((row_width + 7) & 0x07);
  169910. for (i = 0; i < row_width; i++)
  169911. {
  169912. if ((*sp >> shift) & 0x01)
  169913. *dp = 1;
  169914. else
  169915. *dp = 0;
  169916. if (shift == 7)
  169917. {
  169918. shift = 0;
  169919. sp--;
  169920. }
  169921. else
  169922. shift++;
  169923. dp--;
  169924. }
  169925. break;
  169926. }
  169927. case 2:
  169928. {
  169929. sp = row + (png_size_t)((row_width - 1) >> 2);
  169930. dp = row + (png_size_t)row_width - 1;
  169931. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  169932. for (i = 0; i < row_width; i++)
  169933. {
  169934. value = (*sp >> shift) & 0x03;
  169935. *dp = (png_byte)value;
  169936. if (shift == 6)
  169937. {
  169938. shift = 0;
  169939. sp--;
  169940. }
  169941. else
  169942. shift += 2;
  169943. dp--;
  169944. }
  169945. break;
  169946. }
  169947. case 4:
  169948. {
  169949. sp = row + (png_size_t)((row_width - 1) >> 1);
  169950. dp = row + (png_size_t)row_width - 1;
  169951. shift = (int)((row_width & 0x01) << 2);
  169952. for (i = 0; i < row_width; i++)
  169953. {
  169954. value = (*sp >> shift) & 0x0f;
  169955. *dp = (png_byte)value;
  169956. if (shift == 4)
  169957. {
  169958. shift = 0;
  169959. sp--;
  169960. }
  169961. else
  169962. shift += 4;
  169963. dp--;
  169964. }
  169965. break;
  169966. }
  169967. }
  169968. row_info->bit_depth = 8;
  169969. row_info->pixel_depth = 8;
  169970. row_info->rowbytes = row_width;
  169971. }
  169972. switch (row_info->bit_depth)
  169973. {
  169974. case 8:
  169975. {
  169976. if (trans != NULL)
  169977. {
  169978. sp = row + (png_size_t)row_width - 1;
  169979. dp = row + (png_size_t)(row_width << 2) - 1;
  169980. for (i = 0; i < row_width; i++)
  169981. {
  169982. if ((int)(*sp) >= num_trans)
  169983. *dp-- = 0xff;
  169984. else
  169985. *dp-- = trans[*sp];
  169986. *dp-- = palette[*sp].blue;
  169987. *dp-- = palette[*sp].green;
  169988. *dp-- = palette[*sp].red;
  169989. sp--;
  169990. }
  169991. row_info->bit_depth = 8;
  169992. row_info->pixel_depth = 32;
  169993. row_info->rowbytes = row_width * 4;
  169994. row_info->color_type = 6;
  169995. row_info->channels = 4;
  169996. }
  169997. else
  169998. {
  169999. sp = row + (png_size_t)row_width - 1;
  170000. dp = row + (png_size_t)(row_width * 3) - 1;
  170001. for (i = 0; i < row_width; i++)
  170002. {
  170003. *dp-- = palette[*sp].blue;
  170004. *dp-- = palette[*sp].green;
  170005. *dp-- = palette[*sp].red;
  170006. sp--;
  170007. }
  170008. row_info->bit_depth = 8;
  170009. row_info->pixel_depth = 24;
  170010. row_info->rowbytes = row_width * 3;
  170011. row_info->color_type = 2;
  170012. row_info->channels = 3;
  170013. }
  170014. break;
  170015. }
  170016. }
  170017. }
  170018. }
  170019. void /* PRIVATE */
  170020. png_do_expand(png_row_infop row_info, png_bytep row,
  170021. png_color_16p trans_value)
  170022. {
  170023. int shift, value;
  170024. png_bytep sp, dp;
  170025. png_uint_32 i;
  170026. png_uint_32 row_width=row_info->width;
  170027. png_debug(1, "in png_do_expand\n");
  170028. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170029. if (row != NULL && row_info != NULL)
  170030. #endif
  170031. {
  170032. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170033. {
  170034. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170035. if (row_info->bit_depth < 8)
  170036. {
  170037. switch (row_info->bit_depth)
  170038. {
  170039. case 1:
  170040. {
  170041. gray = (png_uint_16)((gray&0x01)*0xff);
  170042. sp = row + (png_size_t)((row_width - 1) >> 3);
  170043. dp = row + (png_size_t)row_width - 1;
  170044. shift = 7 - (int)((row_width + 7) & 0x07);
  170045. for (i = 0; i < row_width; i++)
  170046. {
  170047. if ((*sp >> shift) & 0x01)
  170048. *dp = 0xff;
  170049. else
  170050. *dp = 0;
  170051. if (shift == 7)
  170052. {
  170053. shift = 0;
  170054. sp--;
  170055. }
  170056. else
  170057. shift++;
  170058. dp--;
  170059. }
  170060. break;
  170061. }
  170062. case 2:
  170063. {
  170064. gray = (png_uint_16)((gray&0x03)*0x55);
  170065. sp = row + (png_size_t)((row_width - 1) >> 2);
  170066. dp = row + (png_size_t)row_width - 1;
  170067. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170068. for (i = 0; i < row_width; i++)
  170069. {
  170070. value = (*sp >> shift) & 0x03;
  170071. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170072. (value << 6));
  170073. if (shift == 6)
  170074. {
  170075. shift = 0;
  170076. sp--;
  170077. }
  170078. else
  170079. shift += 2;
  170080. dp--;
  170081. }
  170082. break;
  170083. }
  170084. case 4:
  170085. {
  170086. gray = (png_uint_16)((gray&0x0f)*0x11);
  170087. sp = row + (png_size_t)((row_width - 1) >> 1);
  170088. dp = row + (png_size_t)row_width - 1;
  170089. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170090. for (i = 0; i < row_width; i++)
  170091. {
  170092. value = (*sp >> shift) & 0x0f;
  170093. *dp = (png_byte)(value | (value << 4));
  170094. if (shift == 4)
  170095. {
  170096. shift = 0;
  170097. sp--;
  170098. }
  170099. else
  170100. shift = 4;
  170101. dp--;
  170102. }
  170103. break;
  170104. }
  170105. }
  170106. row_info->bit_depth = 8;
  170107. row_info->pixel_depth = 8;
  170108. row_info->rowbytes = row_width;
  170109. }
  170110. if (trans_value != NULL)
  170111. {
  170112. if (row_info->bit_depth == 8)
  170113. {
  170114. gray = gray & 0xff;
  170115. sp = row + (png_size_t)row_width - 1;
  170116. dp = row + (png_size_t)(row_width << 1) - 1;
  170117. for (i = 0; i < row_width; i++)
  170118. {
  170119. if (*sp == gray)
  170120. *dp-- = 0;
  170121. else
  170122. *dp-- = 0xff;
  170123. *dp-- = *sp--;
  170124. }
  170125. }
  170126. else if (row_info->bit_depth == 16)
  170127. {
  170128. png_byte gray_high = (gray >> 8) & 0xff;
  170129. png_byte gray_low = gray & 0xff;
  170130. sp = row + row_info->rowbytes - 1;
  170131. dp = row + (row_info->rowbytes << 1) - 1;
  170132. for (i = 0; i < row_width; i++)
  170133. {
  170134. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170135. {
  170136. *dp-- = 0;
  170137. *dp-- = 0;
  170138. }
  170139. else
  170140. {
  170141. *dp-- = 0xff;
  170142. *dp-- = 0xff;
  170143. }
  170144. *dp-- = *sp--;
  170145. *dp-- = *sp--;
  170146. }
  170147. }
  170148. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170149. row_info->channels = 2;
  170150. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170151. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170152. row_width);
  170153. }
  170154. }
  170155. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170156. {
  170157. if (row_info->bit_depth == 8)
  170158. {
  170159. png_byte red = trans_value->red & 0xff;
  170160. png_byte green = trans_value->green & 0xff;
  170161. png_byte blue = trans_value->blue & 0xff;
  170162. sp = row + (png_size_t)row_info->rowbytes - 1;
  170163. dp = row + (png_size_t)(row_width << 2) - 1;
  170164. for (i = 0; i < row_width; i++)
  170165. {
  170166. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170167. *dp-- = 0;
  170168. else
  170169. *dp-- = 0xff;
  170170. *dp-- = *sp--;
  170171. *dp-- = *sp--;
  170172. *dp-- = *sp--;
  170173. }
  170174. }
  170175. else if (row_info->bit_depth == 16)
  170176. {
  170177. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170178. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170179. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170180. png_byte red_low = trans_value->red & 0xff;
  170181. png_byte green_low = trans_value->green & 0xff;
  170182. png_byte blue_low = trans_value->blue & 0xff;
  170183. sp = row + row_info->rowbytes - 1;
  170184. dp = row + (png_size_t)(row_width << 3) - 1;
  170185. for (i = 0; i < row_width; i++)
  170186. {
  170187. if (*(sp - 5) == red_high &&
  170188. *(sp - 4) == red_low &&
  170189. *(sp - 3) == green_high &&
  170190. *(sp - 2) == green_low &&
  170191. *(sp - 1) == blue_high &&
  170192. *(sp ) == blue_low)
  170193. {
  170194. *dp-- = 0;
  170195. *dp-- = 0;
  170196. }
  170197. else
  170198. {
  170199. *dp-- = 0xff;
  170200. *dp-- = 0xff;
  170201. }
  170202. *dp-- = *sp--;
  170203. *dp-- = *sp--;
  170204. *dp-- = *sp--;
  170205. *dp-- = *sp--;
  170206. *dp-- = *sp--;
  170207. *dp-- = *sp--;
  170208. }
  170209. }
  170210. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170211. row_info->channels = 4;
  170212. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170213. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170214. }
  170215. }
  170216. }
  170217. #endif
  170218. #if defined(PNG_READ_DITHER_SUPPORTED)
  170219. void /* PRIVATE */
  170220. png_do_dither(png_row_infop row_info, png_bytep row,
  170221. png_bytep palette_lookup, png_bytep dither_lookup)
  170222. {
  170223. png_bytep sp, dp;
  170224. png_uint_32 i;
  170225. png_uint_32 row_width=row_info->width;
  170226. png_debug(1, "in png_do_dither\n");
  170227. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170228. if (row != NULL && row_info != NULL)
  170229. #endif
  170230. {
  170231. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170232. palette_lookup && row_info->bit_depth == 8)
  170233. {
  170234. int r, g, b, p;
  170235. sp = row;
  170236. dp = row;
  170237. for (i = 0; i < row_width; i++)
  170238. {
  170239. r = *sp++;
  170240. g = *sp++;
  170241. b = *sp++;
  170242. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170243. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170244. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170245. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170246. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170247. (PNG_DITHER_BLUE_BITS)) |
  170248. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170249. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170250. *dp++ = palette_lookup[p];
  170251. }
  170252. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170253. row_info->channels = 1;
  170254. row_info->pixel_depth = row_info->bit_depth;
  170255. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170256. }
  170257. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170258. palette_lookup != NULL && row_info->bit_depth == 8)
  170259. {
  170260. int r, g, b, p;
  170261. sp = row;
  170262. dp = row;
  170263. for (i = 0; i < row_width; i++)
  170264. {
  170265. r = *sp++;
  170266. g = *sp++;
  170267. b = *sp++;
  170268. sp++;
  170269. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170270. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170271. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170272. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170273. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170274. (PNG_DITHER_BLUE_BITS)) |
  170275. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170276. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170277. *dp++ = palette_lookup[p];
  170278. }
  170279. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170280. row_info->channels = 1;
  170281. row_info->pixel_depth = row_info->bit_depth;
  170282. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170283. }
  170284. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170285. dither_lookup && row_info->bit_depth == 8)
  170286. {
  170287. sp = row;
  170288. for (i = 0; i < row_width; i++, sp++)
  170289. {
  170290. *sp = dither_lookup[*sp];
  170291. }
  170292. }
  170293. }
  170294. }
  170295. #endif
  170296. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170297. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170298. static PNG_CONST int png_gamma_shift[] =
  170299. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170300. void /* PRIVATE */
  170301. png_build_gamma_table(png_structp png_ptr)
  170302. {
  170303. png_debug(1, "in png_build_gamma_table\n");
  170304. if (png_ptr->bit_depth <= 8)
  170305. {
  170306. int i;
  170307. double g;
  170308. if (png_ptr->screen_gamma > .000001)
  170309. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170310. else
  170311. g = 1.0;
  170312. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170313. (png_uint_32)256);
  170314. for (i = 0; i < 256; i++)
  170315. {
  170316. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170317. g) * 255.0 + .5);
  170318. }
  170319. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170320. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170321. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170322. {
  170323. g = 1.0 / (png_ptr->gamma);
  170324. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170325. (png_uint_32)256);
  170326. for (i = 0; i < 256; i++)
  170327. {
  170328. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170329. g) * 255.0 + .5);
  170330. }
  170331. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170332. (png_uint_32)256);
  170333. if(png_ptr->screen_gamma > 0.000001)
  170334. g = 1.0 / png_ptr->screen_gamma;
  170335. else
  170336. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170337. for (i = 0; i < 256; i++)
  170338. {
  170339. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170340. g) * 255.0 + .5);
  170341. }
  170342. }
  170343. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170344. }
  170345. else
  170346. {
  170347. double g;
  170348. int i, j, shift, num;
  170349. int sig_bit;
  170350. png_uint_32 ig;
  170351. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170352. {
  170353. sig_bit = (int)png_ptr->sig_bit.red;
  170354. if ((int)png_ptr->sig_bit.green > sig_bit)
  170355. sig_bit = png_ptr->sig_bit.green;
  170356. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170357. sig_bit = png_ptr->sig_bit.blue;
  170358. }
  170359. else
  170360. {
  170361. sig_bit = (int)png_ptr->sig_bit.gray;
  170362. }
  170363. if (sig_bit > 0)
  170364. shift = 16 - sig_bit;
  170365. else
  170366. shift = 0;
  170367. if (png_ptr->transformations & PNG_16_TO_8)
  170368. {
  170369. if (shift < (16 - PNG_MAX_GAMMA_8))
  170370. shift = (16 - PNG_MAX_GAMMA_8);
  170371. }
  170372. if (shift > 8)
  170373. shift = 8;
  170374. if (shift < 0)
  170375. shift = 0;
  170376. png_ptr->gamma_shift = (png_byte)shift;
  170377. num = (1 << (8 - shift));
  170378. if (png_ptr->screen_gamma > .000001)
  170379. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170380. else
  170381. g = 1.0;
  170382. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170383. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170384. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170385. {
  170386. double fin, fout;
  170387. png_uint_32 last, max;
  170388. for (i = 0; i < num; i++)
  170389. {
  170390. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170391. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170392. }
  170393. g = 1.0 / g;
  170394. last = 0;
  170395. for (i = 0; i < 256; i++)
  170396. {
  170397. fout = ((double)i + 0.5) / 256.0;
  170398. fin = pow(fout, g);
  170399. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170400. while (last <= max)
  170401. {
  170402. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170403. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170404. (png_uint_16)i | ((png_uint_16)i << 8));
  170405. last++;
  170406. }
  170407. }
  170408. while (last < ((png_uint_32)num << 8))
  170409. {
  170410. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170411. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170412. last++;
  170413. }
  170414. }
  170415. else
  170416. {
  170417. for (i = 0; i < num; i++)
  170418. {
  170419. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170420. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170421. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170422. for (j = 0; j < 256; j++)
  170423. {
  170424. png_ptr->gamma_16_table[i][j] =
  170425. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170426. 65535.0, g) * 65535.0 + .5);
  170427. }
  170428. }
  170429. }
  170430. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170431. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170432. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170433. {
  170434. g = 1.0 / (png_ptr->gamma);
  170435. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170436. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170437. for (i = 0; i < num; i++)
  170438. {
  170439. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170440. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170441. ig = (((png_uint_32)i *
  170442. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170443. for (j = 0; j < 256; j++)
  170444. {
  170445. png_ptr->gamma_16_to_1[i][j] =
  170446. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170447. 65535.0, g) * 65535.0 + .5);
  170448. }
  170449. }
  170450. if(png_ptr->screen_gamma > 0.000001)
  170451. g = 1.0 / png_ptr->screen_gamma;
  170452. else
  170453. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170454. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170455. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170456. for (i = 0; i < num; i++)
  170457. {
  170458. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170459. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170460. ig = (((png_uint_32)i *
  170461. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170462. for (j = 0; j < 256; j++)
  170463. {
  170464. png_ptr->gamma_16_from_1[i][j] =
  170465. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170466. 65535.0, g) * 65535.0 + .5);
  170467. }
  170468. }
  170469. }
  170470. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170471. }
  170472. }
  170473. #endif
  170474. #endif
  170475. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170476. void /* PRIVATE */
  170477. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170478. {
  170479. png_debug(1, "in png_do_read_intrapixel\n");
  170480. if (
  170481. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170482. row != NULL && row_info != NULL &&
  170483. #endif
  170484. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170485. {
  170486. int bytes_per_pixel;
  170487. png_uint_32 row_width = row_info->width;
  170488. if (row_info->bit_depth == 8)
  170489. {
  170490. png_bytep rp;
  170491. png_uint_32 i;
  170492. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170493. bytes_per_pixel = 3;
  170494. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170495. bytes_per_pixel = 4;
  170496. else
  170497. return;
  170498. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170499. {
  170500. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170501. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170502. }
  170503. }
  170504. else if (row_info->bit_depth == 16)
  170505. {
  170506. png_bytep rp;
  170507. png_uint_32 i;
  170508. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170509. bytes_per_pixel = 6;
  170510. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170511. bytes_per_pixel = 8;
  170512. else
  170513. return;
  170514. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170515. {
  170516. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170517. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170518. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170519. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170520. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170521. *(rp ) = (png_byte)((red >> 8) & 0xff);
  170522. *(rp+1) = (png_byte)(red & 0xff);
  170523. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  170524. *(rp+5) = (png_byte)(blue & 0xff);
  170525. }
  170526. }
  170527. }
  170528. }
  170529. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  170530. #endif /* PNG_READ_SUPPORTED */
  170531. /*** End of inlined file: pngrtran.c ***/
  170532. /*** Start of inlined file: pngrutil.c ***/
  170533. #define PNG_INTERNAL
  170534. #if defined(PNG_READ_SUPPORTED)
  170535. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  170536. # define WIN32_WCE_OLD
  170537. #endif
  170538. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170539. # if defined(WIN32_WCE_OLD)
  170540. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  170541. {
  170542. double result = 0;
  170543. int len;
  170544. wchar_t *str, *end;
  170545. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  170546. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  170547. if ( NULL != str )
  170548. {
  170549. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  170550. result = wcstod(str, &end);
  170551. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  170552. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  170553. png_free(png_ptr, str);
  170554. }
  170555. return result;
  170556. }
  170557. # else
  170558. # define png_strtod(p,a,b) strtod(a,b)
  170559. # endif
  170560. #endif
  170561. png_uint_32 PNGAPI
  170562. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  170563. {
  170564. png_uint_32 i = png_get_uint_32(buf);
  170565. if (i > PNG_UINT_31_MAX)
  170566. png_error(png_ptr, "PNG unsigned integer out of range.");
  170567. return (i);
  170568. }
  170569. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  170570. png_uint_32 PNGAPI
  170571. png_get_uint_32(png_bytep buf)
  170572. {
  170573. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  170574. ((png_uint_32)(*(buf + 1)) << 16) +
  170575. ((png_uint_32)(*(buf + 2)) << 8) +
  170576. (png_uint_32)(*(buf + 3));
  170577. return (i);
  170578. }
  170579. png_int_32 PNGAPI
  170580. png_get_int_32(png_bytep buf)
  170581. {
  170582. png_int_32 i = ((png_int_32)(*buf) << 24) +
  170583. ((png_int_32)(*(buf + 1)) << 16) +
  170584. ((png_int_32)(*(buf + 2)) << 8) +
  170585. (png_int_32)(*(buf + 3));
  170586. return (i);
  170587. }
  170588. png_uint_16 PNGAPI
  170589. png_get_uint_16(png_bytep buf)
  170590. {
  170591. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  170592. (png_uint_16)(*(buf + 1)));
  170593. return (i);
  170594. }
  170595. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  170596. void /* PRIVATE */
  170597. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  170598. {
  170599. if(png_ptr == NULL) return;
  170600. png_read_data(png_ptr, buf, length);
  170601. png_calculate_crc(png_ptr, buf, length);
  170602. }
  170603. int /* PRIVATE */
  170604. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  170605. {
  170606. png_size_t i;
  170607. png_size_t istop = png_ptr->zbuf_size;
  170608. for (i = (png_size_t)skip; i > istop; i -= istop)
  170609. {
  170610. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  170611. }
  170612. if (i)
  170613. {
  170614. png_crc_read(png_ptr, png_ptr->zbuf, i);
  170615. }
  170616. if (png_crc_error(png_ptr))
  170617. {
  170618. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  170619. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  170620. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  170621. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  170622. {
  170623. png_chunk_warning(png_ptr, "CRC error");
  170624. }
  170625. else
  170626. {
  170627. png_chunk_error(png_ptr, "CRC error");
  170628. }
  170629. return (1);
  170630. }
  170631. return (0);
  170632. }
  170633. int /* PRIVATE */
  170634. png_crc_error(png_structp png_ptr)
  170635. {
  170636. png_byte crc_bytes[4];
  170637. png_uint_32 crc;
  170638. int need_crc = 1;
  170639. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  170640. {
  170641. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  170642. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170643. need_crc = 0;
  170644. }
  170645. else /* critical */
  170646. {
  170647. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  170648. need_crc = 0;
  170649. }
  170650. png_read_data(png_ptr, crc_bytes, 4);
  170651. if (need_crc)
  170652. {
  170653. crc = png_get_uint_32(crc_bytes);
  170654. return ((int)(crc != png_ptr->crc));
  170655. }
  170656. else
  170657. return (0);
  170658. }
  170659. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  170660. defined(PNG_READ_iCCP_SUPPORTED)
  170661. png_charp /* PRIVATE */
  170662. png_decompress_chunk(png_structp png_ptr, int comp_type,
  170663. png_charp chunkdata, png_size_t chunklength,
  170664. png_size_t prefix_size, png_size_t *newlength)
  170665. {
  170666. static PNG_CONST char msg[] = "Error decoding compressed text";
  170667. png_charp text;
  170668. png_size_t text_size;
  170669. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  170670. {
  170671. int ret = Z_OK;
  170672. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  170673. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  170674. png_ptr->zstream.next_out = png_ptr->zbuf;
  170675. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170676. text_size = 0;
  170677. text = NULL;
  170678. while (png_ptr->zstream.avail_in)
  170679. {
  170680. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  170681. if (ret != Z_OK && ret != Z_STREAM_END)
  170682. {
  170683. if (png_ptr->zstream.msg != NULL)
  170684. png_warning(png_ptr, png_ptr->zstream.msg);
  170685. else
  170686. png_warning(png_ptr, msg);
  170687. inflateReset(&png_ptr->zstream);
  170688. png_ptr->zstream.avail_in = 0;
  170689. if (text == NULL)
  170690. {
  170691. text_size = prefix_size + png_sizeof(msg) + 1;
  170692. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  170693. if (text == NULL)
  170694. {
  170695. png_free(png_ptr,chunkdata);
  170696. png_error(png_ptr,"Not enough memory to decompress chunk");
  170697. }
  170698. png_memcpy(text, chunkdata, prefix_size);
  170699. }
  170700. text[text_size - 1] = 0x00;
  170701. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  170702. text_size = png_sizeof(msg) > text_size ? text_size :
  170703. png_sizeof(msg);
  170704. png_memcpy(text + prefix_size, msg, text_size + 1);
  170705. break;
  170706. }
  170707. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  170708. {
  170709. if (text == NULL)
  170710. {
  170711. text_size = prefix_size +
  170712. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170713. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  170714. if (text == NULL)
  170715. {
  170716. png_free(png_ptr,chunkdata);
  170717. png_error(png_ptr,"Not enough memory to decompress chunk.");
  170718. }
  170719. png_memcpy(text + prefix_size, png_ptr->zbuf,
  170720. text_size - prefix_size);
  170721. png_memcpy(text, chunkdata, prefix_size);
  170722. *(text + text_size) = 0x00;
  170723. }
  170724. else
  170725. {
  170726. png_charp tmp;
  170727. tmp = text;
  170728. text = (png_charp)png_malloc_warn(png_ptr,
  170729. (png_uint_32)(text_size +
  170730. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  170731. if (text == NULL)
  170732. {
  170733. png_free(png_ptr, tmp);
  170734. png_free(png_ptr, chunkdata);
  170735. png_error(png_ptr,"Not enough memory to decompress chunk..");
  170736. }
  170737. png_memcpy(text, tmp, text_size);
  170738. png_free(png_ptr, tmp);
  170739. png_memcpy(text + text_size, png_ptr->zbuf,
  170740. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  170741. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  170742. *(text + text_size) = 0x00;
  170743. }
  170744. if (ret == Z_STREAM_END)
  170745. break;
  170746. else
  170747. {
  170748. png_ptr->zstream.next_out = png_ptr->zbuf;
  170749. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  170750. }
  170751. }
  170752. }
  170753. if (ret != Z_STREAM_END)
  170754. {
  170755. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170756. char umsg[52];
  170757. if (ret == Z_BUF_ERROR)
  170758. png_snprintf(umsg, 52,
  170759. "Buffer error in compressed datastream in %s chunk",
  170760. png_ptr->chunk_name);
  170761. else if (ret == Z_DATA_ERROR)
  170762. png_snprintf(umsg, 52,
  170763. "Data error in compressed datastream in %s chunk",
  170764. png_ptr->chunk_name);
  170765. else
  170766. png_snprintf(umsg, 52,
  170767. "Incomplete compressed datastream in %s chunk",
  170768. png_ptr->chunk_name);
  170769. png_warning(png_ptr, umsg);
  170770. #else
  170771. png_warning(png_ptr,
  170772. "Incomplete compressed datastream in chunk other than IDAT");
  170773. #endif
  170774. text_size=prefix_size;
  170775. if (text == NULL)
  170776. {
  170777. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  170778. if (text == NULL)
  170779. {
  170780. png_free(png_ptr, chunkdata);
  170781. png_error(png_ptr,"Not enough memory for text.");
  170782. }
  170783. png_memcpy(text, chunkdata, prefix_size);
  170784. }
  170785. *(text + text_size) = 0x00;
  170786. }
  170787. inflateReset(&png_ptr->zstream);
  170788. png_ptr->zstream.avail_in = 0;
  170789. png_free(png_ptr, chunkdata);
  170790. chunkdata = text;
  170791. *newlength=text_size;
  170792. }
  170793. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  170794. {
  170795. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  170796. char umsg[50];
  170797. png_snprintf(umsg, 50,
  170798. "Unknown zTXt compression type %d", comp_type);
  170799. png_warning(png_ptr, umsg);
  170800. #else
  170801. png_warning(png_ptr, "Unknown zTXt compression type");
  170802. #endif
  170803. *(chunkdata + prefix_size) = 0x00;
  170804. *newlength=prefix_size;
  170805. }
  170806. return chunkdata;
  170807. }
  170808. #endif
  170809. void /* PRIVATE */
  170810. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170811. {
  170812. png_byte buf[13];
  170813. png_uint_32 width, height;
  170814. int bit_depth, color_type, compression_type, filter_type;
  170815. int interlace_type;
  170816. png_debug(1, "in png_handle_IHDR\n");
  170817. if (png_ptr->mode & PNG_HAVE_IHDR)
  170818. png_error(png_ptr, "Out of place IHDR");
  170819. if (length != 13)
  170820. png_error(png_ptr, "Invalid IHDR chunk");
  170821. png_ptr->mode |= PNG_HAVE_IHDR;
  170822. png_crc_read(png_ptr, buf, 13);
  170823. png_crc_finish(png_ptr, 0);
  170824. width = png_get_uint_31(png_ptr, buf);
  170825. height = png_get_uint_31(png_ptr, buf + 4);
  170826. bit_depth = buf[8];
  170827. color_type = buf[9];
  170828. compression_type = buf[10];
  170829. filter_type = buf[11];
  170830. interlace_type = buf[12];
  170831. png_ptr->width = width;
  170832. png_ptr->height = height;
  170833. png_ptr->bit_depth = (png_byte)bit_depth;
  170834. png_ptr->interlaced = (png_byte)interlace_type;
  170835. png_ptr->color_type = (png_byte)color_type;
  170836. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170837. png_ptr->filter_type = (png_byte)filter_type;
  170838. #endif
  170839. png_ptr->compression_type = (png_byte)compression_type;
  170840. switch (png_ptr->color_type)
  170841. {
  170842. case PNG_COLOR_TYPE_GRAY:
  170843. case PNG_COLOR_TYPE_PALETTE:
  170844. png_ptr->channels = 1;
  170845. break;
  170846. case PNG_COLOR_TYPE_RGB:
  170847. png_ptr->channels = 3;
  170848. break;
  170849. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170850. png_ptr->channels = 2;
  170851. break;
  170852. case PNG_COLOR_TYPE_RGB_ALPHA:
  170853. png_ptr->channels = 4;
  170854. break;
  170855. }
  170856. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  170857. png_ptr->channels);
  170858. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  170859. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  170860. png_debug1(3,"channels = %d\n", png_ptr->channels);
  170861. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  170862. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  170863. color_type, interlace_type, compression_type, filter_type);
  170864. }
  170865. void /* PRIVATE */
  170866. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170867. {
  170868. png_color palette[PNG_MAX_PALETTE_LENGTH];
  170869. int num, i;
  170870. #ifndef PNG_NO_POINTER_INDEXING
  170871. png_colorp pal_ptr;
  170872. #endif
  170873. png_debug(1, "in png_handle_PLTE\n");
  170874. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  170875. png_error(png_ptr, "Missing IHDR before PLTE");
  170876. else if (png_ptr->mode & PNG_HAVE_IDAT)
  170877. {
  170878. png_warning(png_ptr, "Invalid PLTE after IDAT");
  170879. png_crc_finish(png_ptr, length);
  170880. return;
  170881. }
  170882. else if (png_ptr->mode & PNG_HAVE_PLTE)
  170883. png_error(png_ptr, "Duplicate PLTE chunk");
  170884. png_ptr->mode |= PNG_HAVE_PLTE;
  170885. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  170886. {
  170887. png_warning(png_ptr,
  170888. "Ignoring PLTE chunk in grayscale PNG");
  170889. png_crc_finish(png_ptr, length);
  170890. return;
  170891. }
  170892. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170893. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170894. {
  170895. png_crc_finish(png_ptr, length);
  170896. return;
  170897. }
  170898. #endif
  170899. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  170900. {
  170901. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  170902. {
  170903. png_warning(png_ptr, "Invalid palette chunk");
  170904. png_crc_finish(png_ptr, length);
  170905. return;
  170906. }
  170907. else
  170908. {
  170909. png_error(png_ptr, "Invalid palette chunk");
  170910. }
  170911. }
  170912. num = (int)length / 3;
  170913. #ifndef PNG_NO_POINTER_INDEXING
  170914. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  170915. {
  170916. png_byte buf[3];
  170917. png_crc_read(png_ptr, buf, 3);
  170918. pal_ptr->red = buf[0];
  170919. pal_ptr->green = buf[1];
  170920. pal_ptr->blue = buf[2];
  170921. }
  170922. #else
  170923. for (i = 0; i < num; i++)
  170924. {
  170925. png_byte buf[3];
  170926. png_crc_read(png_ptr, buf, 3);
  170927. palette[i].red = buf[0];
  170928. palette[i].green = buf[1];
  170929. palette[i].blue = buf[2];
  170930. }
  170931. #endif
  170932. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170933. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  170934. #endif
  170935. {
  170936. png_crc_finish(png_ptr, 0);
  170937. }
  170938. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  170939. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  170940. {
  170941. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  170942. {
  170943. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  170944. {
  170945. png_chunk_error(png_ptr, "CRC error");
  170946. }
  170947. else
  170948. {
  170949. png_chunk_warning(png_ptr, "CRC error");
  170950. return;
  170951. }
  170952. }
  170953. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  170954. {
  170955. png_chunk_warning(png_ptr, "CRC error");
  170956. }
  170957. }
  170958. #endif
  170959. png_set_PLTE(png_ptr, info_ptr, palette, num);
  170960. #if defined(PNG_READ_tRNS_SUPPORTED)
  170961. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  170962. {
  170963. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  170964. {
  170965. if (png_ptr->num_trans > (png_uint_16)num)
  170966. {
  170967. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  170968. png_ptr->num_trans = (png_uint_16)num;
  170969. }
  170970. if (info_ptr->num_trans > (png_uint_16)num)
  170971. {
  170972. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  170973. info_ptr->num_trans = (png_uint_16)num;
  170974. }
  170975. }
  170976. }
  170977. #endif
  170978. }
  170979. void /* PRIVATE */
  170980. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170981. {
  170982. png_debug(1, "in png_handle_IEND\n");
  170983. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  170984. {
  170985. png_error(png_ptr, "No image in file");
  170986. }
  170987. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  170988. if (length != 0)
  170989. {
  170990. png_warning(png_ptr, "Incorrect IEND chunk length");
  170991. }
  170992. png_crc_finish(png_ptr, length);
  170993. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  170994. }
  170995. #if defined(PNG_READ_gAMA_SUPPORTED)
  170996. void /* PRIVATE */
  170997. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  170998. {
  170999. png_fixed_point igamma;
  171000. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171001. float file_gamma;
  171002. #endif
  171003. png_byte buf[4];
  171004. png_debug(1, "in png_handle_gAMA\n");
  171005. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171006. png_error(png_ptr, "Missing IHDR before gAMA");
  171007. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171008. {
  171009. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171010. png_crc_finish(png_ptr, length);
  171011. return;
  171012. }
  171013. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171014. png_warning(png_ptr, "Out of place gAMA chunk");
  171015. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171016. #if defined(PNG_READ_sRGB_SUPPORTED)
  171017. && !(info_ptr->valid & PNG_INFO_sRGB)
  171018. #endif
  171019. )
  171020. {
  171021. png_warning(png_ptr, "Duplicate gAMA chunk");
  171022. png_crc_finish(png_ptr, length);
  171023. return;
  171024. }
  171025. if (length != 4)
  171026. {
  171027. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171028. png_crc_finish(png_ptr, length);
  171029. return;
  171030. }
  171031. png_crc_read(png_ptr, buf, 4);
  171032. if (png_crc_finish(png_ptr, 0))
  171033. return;
  171034. igamma = (png_fixed_point)png_get_uint_32(buf);
  171035. if (igamma == 0)
  171036. {
  171037. png_warning(png_ptr,
  171038. "Ignoring gAMA chunk with gamma=0");
  171039. return;
  171040. }
  171041. #if defined(PNG_READ_sRGB_SUPPORTED)
  171042. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171043. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171044. {
  171045. png_warning(png_ptr,
  171046. "Ignoring incorrect gAMA value when sRGB is also present");
  171047. #ifndef PNG_NO_CONSOLE_IO
  171048. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171049. #endif
  171050. return;
  171051. }
  171052. #endif /* PNG_READ_sRGB_SUPPORTED */
  171053. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171054. file_gamma = (float)igamma / (float)100000.0;
  171055. # ifdef PNG_READ_GAMMA_SUPPORTED
  171056. png_ptr->gamma = file_gamma;
  171057. # endif
  171058. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171059. #endif
  171060. #ifdef PNG_FIXED_POINT_SUPPORTED
  171061. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171062. #endif
  171063. }
  171064. #endif
  171065. #if defined(PNG_READ_sBIT_SUPPORTED)
  171066. void /* PRIVATE */
  171067. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171068. {
  171069. png_size_t truelen;
  171070. png_byte buf[4];
  171071. png_debug(1, "in png_handle_sBIT\n");
  171072. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171073. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171074. png_error(png_ptr, "Missing IHDR before sBIT");
  171075. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171076. {
  171077. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171078. png_crc_finish(png_ptr, length);
  171079. return;
  171080. }
  171081. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171082. {
  171083. png_warning(png_ptr, "Out of place sBIT chunk");
  171084. }
  171085. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171086. {
  171087. png_warning(png_ptr, "Duplicate sBIT chunk");
  171088. png_crc_finish(png_ptr, length);
  171089. return;
  171090. }
  171091. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171092. truelen = 3;
  171093. else
  171094. truelen = (png_size_t)png_ptr->channels;
  171095. if (length != truelen || length > 4)
  171096. {
  171097. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171098. png_crc_finish(png_ptr, length);
  171099. return;
  171100. }
  171101. png_crc_read(png_ptr, buf, truelen);
  171102. if (png_crc_finish(png_ptr, 0))
  171103. return;
  171104. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171105. {
  171106. png_ptr->sig_bit.red = buf[0];
  171107. png_ptr->sig_bit.green = buf[1];
  171108. png_ptr->sig_bit.blue = buf[2];
  171109. png_ptr->sig_bit.alpha = buf[3];
  171110. }
  171111. else
  171112. {
  171113. png_ptr->sig_bit.gray = buf[0];
  171114. png_ptr->sig_bit.red = buf[0];
  171115. png_ptr->sig_bit.green = buf[0];
  171116. png_ptr->sig_bit.blue = buf[0];
  171117. png_ptr->sig_bit.alpha = buf[1];
  171118. }
  171119. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171120. }
  171121. #endif
  171122. #if defined(PNG_READ_cHRM_SUPPORTED)
  171123. void /* PRIVATE */
  171124. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171125. {
  171126. png_byte buf[4];
  171127. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171128. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171129. #endif
  171130. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171131. int_y_green, int_x_blue, int_y_blue;
  171132. png_uint_32 uint_x, uint_y;
  171133. png_debug(1, "in png_handle_cHRM\n");
  171134. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171135. png_error(png_ptr, "Missing IHDR before cHRM");
  171136. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171137. {
  171138. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171139. png_crc_finish(png_ptr, length);
  171140. return;
  171141. }
  171142. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171143. png_warning(png_ptr, "Missing PLTE before cHRM");
  171144. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171145. #if defined(PNG_READ_sRGB_SUPPORTED)
  171146. && !(info_ptr->valid & PNG_INFO_sRGB)
  171147. #endif
  171148. )
  171149. {
  171150. png_warning(png_ptr, "Duplicate cHRM chunk");
  171151. png_crc_finish(png_ptr, length);
  171152. return;
  171153. }
  171154. if (length != 32)
  171155. {
  171156. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171157. png_crc_finish(png_ptr, length);
  171158. return;
  171159. }
  171160. png_crc_read(png_ptr, buf, 4);
  171161. uint_x = png_get_uint_32(buf);
  171162. png_crc_read(png_ptr, buf, 4);
  171163. uint_y = png_get_uint_32(buf);
  171164. if (uint_x > 80000L || uint_y > 80000L ||
  171165. uint_x + uint_y > 100000L)
  171166. {
  171167. png_warning(png_ptr, "Invalid cHRM white point");
  171168. png_crc_finish(png_ptr, 24);
  171169. return;
  171170. }
  171171. int_x_white = (png_fixed_point)uint_x;
  171172. int_y_white = (png_fixed_point)uint_y;
  171173. png_crc_read(png_ptr, buf, 4);
  171174. uint_x = png_get_uint_32(buf);
  171175. png_crc_read(png_ptr, buf, 4);
  171176. uint_y = png_get_uint_32(buf);
  171177. if (uint_x + uint_y > 100000L)
  171178. {
  171179. png_warning(png_ptr, "Invalid cHRM red point");
  171180. png_crc_finish(png_ptr, 16);
  171181. return;
  171182. }
  171183. int_x_red = (png_fixed_point)uint_x;
  171184. int_y_red = (png_fixed_point)uint_y;
  171185. png_crc_read(png_ptr, buf, 4);
  171186. uint_x = png_get_uint_32(buf);
  171187. png_crc_read(png_ptr, buf, 4);
  171188. uint_y = png_get_uint_32(buf);
  171189. if (uint_x + uint_y > 100000L)
  171190. {
  171191. png_warning(png_ptr, "Invalid cHRM green point");
  171192. png_crc_finish(png_ptr, 8);
  171193. return;
  171194. }
  171195. int_x_green = (png_fixed_point)uint_x;
  171196. int_y_green = (png_fixed_point)uint_y;
  171197. png_crc_read(png_ptr, buf, 4);
  171198. uint_x = png_get_uint_32(buf);
  171199. png_crc_read(png_ptr, buf, 4);
  171200. uint_y = png_get_uint_32(buf);
  171201. if (uint_x + uint_y > 100000L)
  171202. {
  171203. png_warning(png_ptr, "Invalid cHRM blue point");
  171204. png_crc_finish(png_ptr, 0);
  171205. return;
  171206. }
  171207. int_x_blue = (png_fixed_point)uint_x;
  171208. int_y_blue = (png_fixed_point)uint_y;
  171209. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171210. white_x = (float)int_x_white / (float)100000.0;
  171211. white_y = (float)int_y_white / (float)100000.0;
  171212. red_x = (float)int_x_red / (float)100000.0;
  171213. red_y = (float)int_y_red / (float)100000.0;
  171214. green_x = (float)int_x_green / (float)100000.0;
  171215. green_y = (float)int_y_green / (float)100000.0;
  171216. blue_x = (float)int_x_blue / (float)100000.0;
  171217. blue_y = (float)int_y_blue / (float)100000.0;
  171218. #endif
  171219. #if defined(PNG_READ_sRGB_SUPPORTED)
  171220. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171221. {
  171222. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171223. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171224. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171225. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171226. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171227. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171228. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171229. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171230. {
  171231. png_warning(png_ptr,
  171232. "Ignoring incorrect cHRM value when sRGB is also present");
  171233. #ifndef PNG_NO_CONSOLE_IO
  171234. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171235. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171236. white_x, white_y, red_x, red_y);
  171237. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171238. green_x, green_y, blue_x, blue_y);
  171239. #else
  171240. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171241. int_x_white, int_y_white, int_x_red, int_y_red);
  171242. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171243. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171244. #endif
  171245. #endif /* PNG_NO_CONSOLE_IO */
  171246. }
  171247. png_crc_finish(png_ptr, 0);
  171248. return;
  171249. }
  171250. #endif /* PNG_READ_sRGB_SUPPORTED */
  171251. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171252. png_set_cHRM(png_ptr, info_ptr,
  171253. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171254. #endif
  171255. #ifdef PNG_FIXED_POINT_SUPPORTED
  171256. png_set_cHRM_fixed(png_ptr, info_ptr,
  171257. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171258. int_y_green, int_x_blue, int_y_blue);
  171259. #endif
  171260. if (png_crc_finish(png_ptr, 0))
  171261. return;
  171262. }
  171263. #endif
  171264. #if defined(PNG_READ_sRGB_SUPPORTED)
  171265. void /* PRIVATE */
  171266. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171267. {
  171268. int intent;
  171269. png_byte buf[1];
  171270. png_debug(1, "in png_handle_sRGB\n");
  171271. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171272. png_error(png_ptr, "Missing IHDR before sRGB");
  171273. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171274. {
  171275. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171276. png_crc_finish(png_ptr, length);
  171277. return;
  171278. }
  171279. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171280. png_warning(png_ptr, "Out of place sRGB chunk");
  171281. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171282. {
  171283. png_warning(png_ptr, "Duplicate sRGB chunk");
  171284. png_crc_finish(png_ptr, length);
  171285. return;
  171286. }
  171287. if (length != 1)
  171288. {
  171289. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171290. png_crc_finish(png_ptr, length);
  171291. return;
  171292. }
  171293. png_crc_read(png_ptr, buf, 1);
  171294. if (png_crc_finish(png_ptr, 0))
  171295. return;
  171296. intent = buf[0];
  171297. if (intent >= PNG_sRGB_INTENT_LAST)
  171298. {
  171299. png_warning(png_ptr, "Unknown sRGB intent");
  171300. return;
  171301. }
  171302. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171303. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171304. {
  171305. png_fixed_point igamma;
  171306. #ifdef PNG_FIXED_POINT_SUPPORTED
  171307. igamma=info_ptr->int_gamma;
  171308. #else
  171309. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171310. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171311. # endif
  171312. #endif
  171313. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171314. {
  171315. png_warning(png_ptr,
  171316. "Ignoring incorrect gAMA value when sRGB is also present");
  171317. #ifndef PNG_NO_CONSOLE_IO
  171318. # ifdef PNG_FIXED_POINT_SUPPORTED
  171319. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171320. # else
  171321. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171322. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171323. # endif
  171324. # endif
  171325. #endif
  171326. }
  171327. }
  171328. #endif /* PNG_READ_gAMA_SUPPORTED */
  171329. #ifdef PNG_READ_cHRM_SUPPORTED
  171330. #ifdef PNG_FIXED_POINT_SUPPORTED
  171331. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171332. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171333. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171334. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171335. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171336. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171337. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171338. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171339. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171340. {
  171341. png_warning(png_ptr,
  171342. "Ignoring incorrect cHRM value when sRGB is also present");
  171343. }
  171344. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171345. #endif /* PNG_READ_cHRM_SUPPORTED */
  171346. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171347. }
  171348. #endif /* PNG_READ_sRGB_SUPPORTED */
  171349. #if defined(PNG_READ_iCCP_SUPPORTED)
  171350. void /* PRIVATE */
  171351. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171352. {
  171353. png_charp chunkdata;
  171354. png_byte compression_type;
  171355. png_bytep pC;
  171356. png_charp profile;
  171357. png_uint_32 skip = 0;
  171358. png_uint_32 profile_size, profile_length;
  171359. png_size_t slength, prefix_length, data_length;
  171360. png_debug(1, "in png_handle_iCCP\n");
  171361. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171362. png_error(png_ptr, "Missing IHDR before iCCP");
  171363. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171364. {
  171365. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171366. png_crc_finish(png_ptr, length);
  171367. return;
  171368. }
  171369. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171370. png_warning(png_ptr, "Out of place iCCP chunk");
  171371. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171372. {
  171373. png_warning(png_ptr, "Duplicate iCCP chunk");
  171374. png_crc_finish(png_ptr, length);
  171375. return;
  171376. }
  171377. #ifdef PNG_MAX_MALLOC_64K
  171378. if (length > (png_uint_32)65535L)
  171379. {
  171380. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171381. skip = length - (png_uint_32)65535L;
  171382. length = (png_uint_32)65535L;
  171383. }
  171384. #endif
  171385. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171386. slength = (png_size_t)length;
  171387. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171388. if (png_crc_finish(png_ptr, skip))
  171389. {
  171390. png_free(png_ptr, chunkdata);
  171391. return;
  171392. }
  171393. chunkdata[slength] = 0x00;
  171394. for (profile = chunkdata; *profile; profile++)
  171395. ;
  171396. ++profile;
  171397. if ( profile >= chunkdata + slength - 1)
  171398. {
  171399. png_free(png_ptr, chunkdata);
  171400. png_warning(png_ptr, "Malformed iCCP chunk");
  171401. return;
  171402. }
  171403. compression_type = *profile++;
  171404. if (compression_type)
  171405. {
  171406. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171407. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171408. wrote nonzero) */
  171409. }
  171410. prefix_length = profile - chunkdata;
  171411. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171412. slength, prefix_length, &data_length);
  171413. profile_length = data_length - prefix_length;
  171414. if ( prefix_length > data_length || profile_length < 4)
  171415. {
  171416. png_free(png_ptr, chunkdata);
  171417. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171418. return;
  171419. }
  171420. pC = (png_bytep)(chunkdata+prefix_length);
  171421. profile_size = ((*(pC ))<<24) |
  171422. ((*(pC+1))<<16) |
  171423. ((*(pC+2))<< 8) |
  171424. ((*(pC+3)) );
  171425. if(profile_size < profile_length)
  171426. profile_length = profile_size;
  171427. if(profile_size > profile_length)
  171428. {
  171429. png_free(png_ptr, chunkdata);
  171430. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171431. return;
  171432. }
  171433. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171434. chunkdata + prefix_length, profile_length);
  171435. png_free(png_ptr, chunkdata);
  171436. }
  171437. #endif /* PNG_READ_iCCP_SUPPORTED */
  171438. #if defined(PNG_READ_sPLT_SUPPORTED)
  171439. void /* PRIVATE */
  171440. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171441. {
  171442. png_bytep chunkdata;
  171443. png_bytep entry_start;
  171444. png_sPLT_t new_palette;
  171445. #ifdef PNG_NO_POINTER_INDEXING
  171446. png_sPLT_entryp pp;
  171447. #endif
  171448. int data_length, entry_size, i;
  171449. png_uint_32 skip = 0;
  171450. png_size_t slength;
  171451. png_debug(1, "in png_handle_sPLT\n");
  171452. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171453. png_error(png_ptr, "Missing IHDR before sPLT");
  171454. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171455. {
  171456. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171457. png_crc_finish(png_ptr, length);
  171458. return;
  171459. }
  171460. #ifdef PNG_MAX_MALLOC_64K
  171461. if (length > (png_uint_32)65535L)
  171462. {
  171463. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171464. skip = length - (png_uint_32)65535L;
  171465. length = (png_uint_32)65535L;
  171466. }
  171467. #endif
  171468. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171469. slength = (png_size_t)length;
  171470. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171471. if (png_crc_finish(png_ptr, skip))
  171472. {
  171473. png_free(png_ptr, chunkdata);
  171474. return;
  171475. }
  171476. chunkdata[slength] = 0x00;
  171477. for (entry_start = chunkdata; *entry_start; entry_start++)
  171478. ;
  171479. ++entry_start;
  171480. if (entry_start > chunkdata + slength - 2)
  171481. {
  171482. png_free(png_ptr, chunkdata);
  171483. png_warning(png_ptr, "malformed sPLT chunk");
  171484. return;
  171485. }
  171486. new_palette.depth = *entry_start++;
  171487. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171488. data_length = (slength - (entry_start - chunkdata));
  171489. if (data_length % entry_size)
  171490. {
  171491. png_free(png_ptr, chunkdata);
  171492. png_warning(png_ptr, "sPLT chunk has bad length");
  171493. return;
  171494. }
  171495. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171496. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171497. png_sizeof(png_sPLT_entry)))
  171498. {
  171499. png_warning(png_ptr, "sPLT chunk too long");
  171500. return;
  171501. }
  171502. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171503. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171504. if (new_palette.entries == NULL)
  171505. {
  171506. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171507. return;
  171508. }
  171509. #ifndef PNG_NO_POINTER_INDEXING
  171510. for (i = 0; i < new_palette.nentries; i++)
  171511. {
  171512. png_sPLT_entryp pp = new_palette.entries + i;
  171513. if (new_palette.depth == 8)
  171514. {
  171515. pp->red = *entry_start++;
  171516. pp->green = *entry_start++;
  171517. pp->blue = *entry_start++;
  171518. pp->alpha = *entry_start++;
  171519. }
  171520. else
  171521. {
  171522. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  171523. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  171524. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  171525. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  171526. }
  171527. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171528. }
  171529. #else
  171530. pp = new_palette.entries;
  171531. for (i = 0; i < new_palette.nentries; i++)
  171532. {
  171533. if (new_palette.depth == 8)
  171534. {
  171535. pp[i].red = *entry_start++;
  171536. pp[i].green = *entry_start++;
  171537. pp[i].blue = *entry_start++;
  171538. pp[i].alpha = *entry_start++;
  171539. }
  171540. else
  171541. {
  171542. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  171543. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  171544. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  171545. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  171546. }
  171547. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  171548. }
  171549. #endif
  171550. new_palette.name = (png_charp)chunkdata;
  171551. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  171552. png_free(png_ptr, chunkdata);
  171553. png_free(png_ptr, new_palette.entries);
  171554. }
  171555. #endif /* PNG_READ_sPLT_SUPPORTED */
  171556. #if defined(PNG_READ_tRNS_SUPPORTED)
  171557. void /* PRIVATE */
  171558. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171559. {
  171560. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  171561. int bit_mask;
  171562. png_debug(1, "in png_handle_tRNS\n");
  171563. bit_mask = (1 << png_ptr->bit_depth) - 1;
  171564. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171565. png_error(png_ptr, "Missing IHDR before tRNS");
  171566. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171567. {
  171568. png_warning(png_ptr, "Invalid tRNS after IDAT");
  171569. png_crc_finish(png_ptr, length);
  171570. return;
  171571. }
  171572. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171573. {
  171574. png_warning(png_ptr, "Duplicate tRNS chunk");
  171575. png_crc_finish(png_ptr, length);
  171576. return;
  171577. }
  171578. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  171579. {
  171580. png_byte buf[2];
  171581. if (length != 2)
  171582. {
  171583. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171584. png_crc_finish(png_ptr, length);
  171585. return;
  171586. }
  171587. png_crc_read(png_ptr, buf, 2);
  171588. png_ptr->num_trans = 1;
  171589. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  171590. }
  171591. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  171592. {
  171593. png_byte buf[6];
  171594. if (length != 6)
  171595. {
  171596. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171597. png_crc_finish(png_ptr, length);
  171598. return;
  171599. }
  171600. png_crc_read(png_ptr, buf, (png_size_t)length);
  171601. png_ptr->num_trans = 1;
  171602. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  171603. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  171604. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  171605. }
  171606. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171607. {
  171608. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171609. {
  171610. png_warning(png_ptr, "Missing PLTE before tRNS");
  171611. }
  171612. if (length > (png_uint_32)png_ptr->num_palette ||
  171613. length > PNG_MAX_PALETTE_LENGTH)
  171614. {
  171615. png_warning(png_ptr, "Incorrect tRNS chunk length");
  171616. png_crc_finish(png_ptr, length);
  171617. return;
  171618. }
  171619. if (length == 0)
  171620. {
  171621. png_warning(png_ptr, "Zero length tRNS chunk");
  171622. png_crc_finish(png_ptr, length);
  171623. return;
  171624. }
  171625. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  171626. png_ptr->num_trans = (png_uint_16)length;
  171627. }
  171628. else
  171629. {
  171630. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  171631. png_crc_finish(png_ptr, length);
  171632. return;
  171633. }
  171634. if (png_crc_finish(png_ptr, 0))
  171635. {
  171636. png_ptr->num_trans = 0;
  171637. return;
  171638. }
  171639. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  171640. &(png_ptr->trans_values));
  171641. }
  171642. #endif
  171643. #if defined(PNG_READ_bKGD_SUPPORTED)
  171644. void /* PRIVATE */
  171645. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171646. {
  171647. png_size_t truelen;
  171648. png_byte buf[6];
  171649. png_debug(1, "in png_handle_bKGD\n");
  171650. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171651. png_error(png_ptr, "Missing IHDR before bKGD");
  171652. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171653. {
  171654. png_warning(png_ptr, "Invalid bKGD after IDAT");
  171655. png_crc_finish(png_ptr, length);
  171656. return;
  171657. }
  171658. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  171659. !(png_ptr->mode & PNG_HAVE_PLTE))
  171660. {
  171661. png_warning(png_ptr, "Missing PLTE before bKGD");
  171662. png_crc_finish(png_ptr, length);
  171663. return;
  171664. }
  171665. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  171666. {
  171667. png_warning(png_ptr, "Duplicate bKGD chunk");
  171668. png_crc_finish(png_ptr, length);
  171669. return;
  171670. }
  171671. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171672. truelen = 1;
  171673. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171674. truelen = 6;
  171675. else
  171676. truelen = 2;
  171677. if (length != truelen)
  171678. {
  171679. png_warning(png_ptr, "Incorrect bKGD chunk length");
  171680. png_crc_finish(png_ptr, length);
  171681. return;
  171682. }
  171683. png_crc_read(png_ptr, buf, truelen);
  171684. if (png_crc_finish(png_ptr, 0))
  171685. return;
  171686. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171687. {
  171688. png_ptr->background.index = buf[0];
  171689. if(info_ptr->num_palette)
  171690. {
  171691. if(buf[0] > info_ptr->num_palette)
  171692. {
  171693. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  171694. return;
  171695. }
  171696. png_ptr->background.red =
  171697. (png_uint_16)png_ptr->palette[buf[0]].red;
  171698. png_ptr->background.green =
  171699. (png_uint_16)png_ptr->palette[buf[0]].green;
  171700. png_ptr->background.blue =
  171701. (png_uint_16)png_ptr->palette[buf[0]].blue;
  171702. }
  171703. }
  171704. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  171705. {
  171706. png_ptr->background.red =
  171707. png_ptr->background.green =
  171708. png_ptr->background.blue =
  171709. png_ptr->background.gray = png_get_uint_16(buf);
  171710. }
  171711. else
  171712. {
  171713. png_ptr->background.red = png_get_uint_16(buf);
  171714. png_ptr->background.green = png_get_uint_16(buf + 2);
  171715. png_ptr->background.blue = png_get_uint_16(buf + 4);
  171716. }
  171717. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  171718. }
  171719. #endif
  171720. #if defined(PNG_READ_hIST_SUPPORTED)
  171721. void /* PRIVATE */
  171722. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171723. {
  171724. unsigned int num, i;
  171725. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  171726. png_debug(1, "in png_handle_hIST\n");
  171727. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171728. png_error(png_ptr, "Missing IHDR before hIST");
  171729. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171730. {
  171731. png_warning(png_ptr, "Invalid hIST after IDAT");
  171732. png_crc_finish(png_ptr, length);
  171733. return;
  171734. }
  171735. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  171736. {
  171737. png_warning(png_ptr, "Missing PLTE before hIST");
  171738. png_crc_finish(png_ptr, length);
  171739. return;
  171740. }
  171741. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  171742. {
  171743. png_warning(png_ptr, "Duplicate hIST chunk");
  171744. png_crc_finish(png_ptr, length);
  171745. return;
  171746. }
  171747. num = length / 2 ;
  171748. if (num != (unsigned int) png_ptr->num_palette || num >
  171749. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  171750. {
  171751. png_warning(png_ptr, "Incorrect hIST chunk length");
  171752. png_crc_finish(png_ptr, length);
  171753. return;
  171754. }
  171755. for (i = 0; i < num; i++)
  171756. {
  171757. png_byte buf[2];
  171758. png_crc_read(png_ptr, buf, 2);
  171759. readbuf[i] = png_get_uint_16(buf);
  171760. }
  171761. if (png_crc_finish(png_ptr, 0))
  171762. return;
  171763. png_set_hIST(png_ptr, info_ptr, readbuf);
  171764. }
  171765. #endif
  171766. #if defined(PNG_READ_pHYs_SUPPORTED)
  171767. void /* PRIVATE */
  171768. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171769. {
  171770. png_byte buf[9];
  171771. png_uint_32 res_x, res_y;
  171772. int unit_type;
  171773. png_debug(1, "in png_handle_pHYs\n");
  171774. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171775. png_error(png_ptr, "Missing IHDR before pHYs");
  171776. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171777. {
  171778. png_warning(png_ptr, "Invalid pHYs after IDAT");
  171779. png_crc_finish(png_ptr, length);
  171780. return;
  171781. }
  171782. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  171783. {
  171784. png_warning(png_ptr, "Duplicate pHYs chunk");
  171785. png_crc_finish(png_ptr, length);
  171786. return;
  171787. }
  171788. if (length != 9)
  171789. {
  171790. png_warning(png_ptr, "Incorrect pHYs chunk length");
  171791. png_crc_finish(png_ptr, length);
  171792. return;
  171793. }
  171794. png_crc_read(png_ptr, buf, 9);
  171795. if (png_crc_finish(png_ptr, 0))
  171796. return;
  171797. res_x = png_get_uint_32(buf);
  171798. res_y = png_get_uint_32(buf + 4);
  171799. unit_type = buf[8];
  171800. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  171801. }
  171802. #endif
  171803. #if defined(PNG_READ_oFFs_SUPPORTED)
  171804. void /* PRIVATE */
  171805. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171806. {
  171807. png_byte buf[9];
  171808. png_int_32 offset_x, offset_y;
  171809. int unit_type;
  171810. png_debug(1, "in png_handle_oFFs\n");
  171811. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171812. png_error(png_ptr, "Missing IHDR before oFFs");
  171813. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171814. {
  171815. png_warning(png_ptr, "Invalid oFFs after IDAT");
  171816. png_crc_finish(png_ptr, length);
  171817. return;
  171818. }
  171819. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  171820. {
  171821. png_warning(png_ptr, "Duplicate oFFs chunk");
  171822. png_crc_finish(png_ptr, length);
  171823. return;
  171824. }
  171825. if (length != 9)
  171826. {
  171827. png_warning(png_ptr, "Incorrect oFFs chunk length");
  171828. png_crc_finish(png_ptr, length);
  171829. return;
  171830. }
  171831. png_crc_read(png_ptr, buf, 9);
  171832. if (png_crc_finish(png_ptr, 0))
  171833. return;
  171834. offset_x = png_get_int_32(buf);
  171835. offset_y = png_get_int_32(buf + 4);
  171836. unit_type = buf[8];
  171837. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  171838. }
  171839. #endif
  171840. #if defined(PNG_READ_pCAL_SUPPORTED)
  171841. void /* PRIVATE */
  171842. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171843. {
  171844. png_charp purpose;
  171845. png_int_32 X0, X1;
  171846. png_byte type, nparams;
  171847. png_charp buf, units, endptr;
  171848. png_charpp params;
  171849. png_size_t slength;
  171850. int i;
  171851. png_debug(1, "in png_handle_pCAL\n");
  171852. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171853. png_error(png_ptr, "Missing IHDR before pCAL");
  171854. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171855. {
  171856. png_warning(png_ptr, "Invalid pCAL after IDAT");
  171857. png_crc_finish(png_ptr, length);
  171858. return;
  171859. }
  171860. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  171861. {
  171862. png_warning(png_ptr, "Duplicate pCAL chunk");
  171863. png_crc_finish(png_ptr, length);
  171864. return;
  171865. }
  171866. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  171867. length + 1);
  171868. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171869. if (purpose == NULL)
  171870. {
  171871. png_warning(png_ptr, "No memory for pCAL purpose.");
  171872. return;
  171873. }
  171874. slength = (png_size_t)length;
  171875. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  171876. if (png_crc_finish(png_ptr, 0))
  171877. {
  171878. png_free(png_ptr, purpose);
  171879. return;
  171880. }
  171881. purpose[slength] = 0x00; /* null terminate the last string */
  171882. png_debug(3, "Finding end of pCAL purpose string\n");
  171883. for (buf = purpose; *buf; buf++)
  171884. ;
  171885. endptr = purpose + slength;
  171886. if (endptr <= buf + 12)
  171887. {
  171888. png_warning(png_ptr, "Invalid pCAL data");
  171889. png_free(png_ptr, purpose);
  171890. return;
  171891. }
  171892. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  171893. X0 = png_get_int_32((png_bytep)buf+1);
  171894. X1 = png_get_int_32((png_bytep)buf+5);
  171895. type = buf[9];
  171896. nparams = buf[10];
  171897. units = buf + 11;
  171898. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  171899. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  171900. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  171901. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  171902. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  171903. {
  171904. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  171905. png_free(png_ptr, purpose);
  171906. return;
  171907. }
  171908. else if (type >= PNG_EQUATION_LAST)
  171909. {
  171910. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  171911. }
  171912. for (buf = units; *buf; buf++)
  171913. ;
  171914. png_debug(3, "Allocating pCAL parameters array\n");
  171915. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  171916. *png_sizeof(png_charp))) ;
  171917. if (params == NULL)
  171918. {
  171919. png_free(png_ptr, purpose);
  171920. png_warning(png_ptr, "No memory for pCAL params.");
  171921. return;
  171922. }
  171923. for (i = 0; i < (int)nparams; i++)
  171924. {
  171925. buf++; /* Skip the null string terminator from previous parameter. */
  171926. png_debug1(3, "Reading pCAL parameter %d\n", i);
  171927. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  171928. ;
  171929. if (buf > endptr)
  171930. {
  171931. png_warning(png_ptr, "Invalid pCAL data");
  171932. png_free(png_ptr, purpose);
  171933. png_free(png_ptr, params);
  171934. return;
  171935. }
  171936. }
  171937. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  171938. units, params);
  171939. png_free(png_ptr, purpose);
  171940. png_free(png_ptr, params);
  171941. }
  171942. #endif
  171943. #if defined(PNG_READ_sCAL_SUPPORTED)
  171944. void /* PRIVATE */
  171945. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171946. {
  171947. png_charp buffer, ep;
  171948. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171949. double width, height;
  171950. png_charp vp;
  171951. #else
  171952. #ifdef PNG_FIXED_POINT_SUPPORTED
  171953. png_charp swidth, sheight;
  171954. #endif
  171955. #endif
  171956. png_size_t slength;
  171957. png_debug(1, "in png_handle_sCAL\n");
  171958. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171959. png_error(png_ptr, "Missing IHDR before sCAL");
  171960. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171961. {
  171962. png_warning(png_ptr, "Invalid sCAL after IDAT");
  171963. png_crc_finish(png_ptr, length);
  171964. return;
  171965. }
  171966. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  171967. {
  171968. png_warning(png_ptr, "Duplicate sCAL chunk");
  171969. png_crc_finish(png_ptr, length);
  171970. return;
  171971. }
  171972. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  171973. length + 1);
  171974. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  171975. if (buffer == NULL)
  171976. {
  171977. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  171978. return;
  171979. }
  171980. slength = (png_size_t)length;
  171981. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  171982. if (png_crc_finish(png_ptr, 0))
  171983. {
  171984. png_free(png_ptr, buffer);
  171985. return;
  171986. }
  171987. buffer[slength] = 0x00; /* null terminate the last string */
  171988. ep = buffer + 1; /* skip unit byte */
  171989. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171990. width = png_strtod(png_ptr, ep, &vp);
  171991. if (*vp)
  171992. {
  171993. png_warning(png_ptr, "malformed width string in sCAL chunk");
  171994. return;
  171995. }
  171996. #else
  171997. #ifdef PNG_FIXED_POINT_SUPPORTED
  171998. swidth = (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 width");
  172002. return;
  172003. }
  172004. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172005. #endif
  172006. #endif
  172007. for (ep = buffer; *ep; ep++)
  172008. ;
  172009. ep++;
  172010. if (buffer + slength < ep)
  172011. {
  172012. png_warning(png_ptr, "Truncated sCAL chunk");
  172013. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172014. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172015. png_free(png_ptr, swidth);
  172016. #endif
  172017. png_free(png_ptr, buffer);
  172018. return;
  172019. }
  172020. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172021. height = png_strtod(png_ptr, ep, &vp);
  172022. if (*vp)
  172023. {
  172024. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172025. return;
  172026. }
  172027. #else
  172028. #ifdef PNG_FIXED_POINT_SUPPORTED
  172029. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172030. if (swidth == NULL)
  172031. {
  172032. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172033. return;
  172034. }
  172035. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172036. #endif
  172037. #endif
  172038. if (buffer + slength < ep
  172039. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172040. || width <= 0. || height <= 0.
  172041. #endif
  172042. )
  172043. {
  172044. png_warning(png_ptr, "Invalid sCAL data");
  172045. png_free(png_ptr, buffer);
  172046. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172047. png_free(png_ptr, swidth);
  172048. png_free(png_ptr, sheight);
  172049. #endif
  172050. return;
  172051. }
  172052. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172053. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172054. #else
  172055. #ifdef PNG_FIXED_POINT_SUPPORTED
  172056. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172057. #endif
  172058. #endif
  172059. png_free(png_ptr, buffer);
  172060. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172061. png_free(png_ptr, swidth);
  172062. png_free(png_ptr, sheight);
  172063. #endif
  172064. }
  172065. #endif
  172066. #if defined(PNG_READ_tIME_SUPPORTED)
  172067. void /* PRIVATE */
  172068. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172069. {
  172070. png_byte buf[7];
  172071. png_time mod_time;
  172072. png_debug(1, "in png_handle_tIME\n");
  172073. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172074. png_error(png_ptr, "Out of place tIME chunk");
  172075. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172076. {
  172077. png_warning(png_ptr, "Duplicate tIME chunk");
  172078. png_crc_finish(png_ptr, length);
  172079. return;
  172080. }
  172081. if (png_ptr->mode & PNG_HAVE_IDAT)
  172082. png_ptr->mode |= PNG_AFTER_IDAT;
  172083. if (length != 7)
  172084. {
  172085. png_warning(png_ptr, "Incorrect tIME chunk length");
  172086. png_crc_finish(png_ptr, length);
  172087. return;
  172088. }
  172089. png_crc_read(png_ptr, buf, 7);
  172090. if (png_crc_finish(png_ptr, 0))
  172091. return;
  172092. mod_time.second = buf[6];
  172093. mod_time.minute = buf[5];
  172094. mod_time.hour = buf[4];
  172095. mod_time.day = buf[3];
  172096. mod_time.month = buf[2];
  172097. mod_time.year = png_get_uint_16(buf);
  172098. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172099. }
  172100. #endif
  172101. #if defined(PNG_READ_tEXt_SUPPORTED)
  172102. void /* PRIVATE */
  172103. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172104. {
  172105. png_textp text_ptr;
  172106. png_charp key;
  172107. png_charp text;
  172108. png_uint_32 skip = 0;
  172109. png_size_t slength;
  172110. int ret;
  172111. png_debug(1, "in png_handle_tEXt\n");
  172112. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172113. png_error(png_ptr, "Missing IHDR before tEXt");
  172114. if (png_ptr->mode & PNG_HAVE_IDAT)
  172115. png_ptr->mode |= PNG_AFTER_IDAT;
  172116. #ifdef PNG_MAX_MALLOC_64K
  172117. if (length > (png_uint_32)65535L)
  172118. {
  172119. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172120. skip = length - (png_uint_32)65535L;
  172121. length = (png_uint_32)65535L;
  172122. }
  172123. #endif
  172124. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172125. if (key == NULL)
  172126. {
  172127. png_warning(png_ptr, "No memory to process text chunk.");
  172128. return;
  172129. }
  172130. slength = (png_size_t)length;
  172131. png_crc_read(png_ptr, (png_bytep)key, slength);
  172132. if (png_crc_finish(png_ptr, skip))
  172133. {
  172134. png_free(png_ptr, key);
  172135. return;
  172136. }
  172137. key[slength] = 0x00;
  172138. for (text = key; *text; text++)
  172139. ;
  172140. if (text != key + slength)
  172141. text++;
  172142. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172143. (png_uint_32)png_sizeof(png_text));
  172144. if (text_ptr == NULL)
  172145. {
  172146. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172147. png_free(png_ptr, key);
  172148. return;
  172149. }
  172150. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172151. text_ptr->key = key;
  172152. #ifdef PNG_iTXt_SUPPORTED
  172153. text_ptr->lang = NULL;
  172154. text_ptr->lang_key = NULL;
  172155. text_ptr->itxt_length = 0;
  172156. #endif
  172157. text_ptr->text = text;
  172158. text_ptr->text_length = png_strlen(text);
  172159. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172160. png_free(png_ptr, key);
  172161. png_free(png_ptr, text_ptr);
  172162. if (ret)
  172163. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172164. }
  172165. #endif
  172166. #if defined(PNG_READ_zTXt_SUPPORTED)
  172167. void /* PRIVATE */
  172168. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172169. {
  172170. png_textp text_ptr;
  172171. png_charp chunkdata;
  172172. png_charp text;
  172173. int comp_type;
  172174. int ret;
  172175. png_size_t slength, prefix_len, data_len;
  172176. png_debug(1, "in png_handle_zTXt\n");
  172177. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172178. png_error(png_ptr, "Missing IHDR before zTXt");
  172179. if (png_ptr->mode & PNG_HAVE_IDAT)
  172180. png_ptr->mode |= PNG_AFTER_IDAT;
  172181. #ifdef PNG_MAX_MALLOC_64K
  172182. if (length > (png_uint_32)65535L)
  172183. {
  172184. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172185. png_crc_finish(png_ptr, length);
  172186. return;
  172187. }
  172188. #endif
  172189. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172190. if (chunkdata == NULL)
  172191. {
  172192. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172193. return;
  172194. }
  172195. slength = (png_size_t)length;
  172196. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172197. if (png_crc_finish(png_ptr, 0))
  172198. {
  172199. png_free(png_ptr, chunkdata);
  172200. return;
  172201. }
  172202. chunkdata[slength] = 0x00;
  172203. for (text = chunkdata; *text; text++)
  172204. ;
  172205. if (text >= chunkdata + slength - 2)
  172206. {
  172207. png_warning(png_ptr, "Truncated zTXt chunk");
  172208. png_free(png_ptr, chunkdata);
  172209. return;
  172210. }
  172211. else
  172212. {
  172213. comp_type = *(++text);
  172214. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172215. {
  172216. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172217. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172218. }
  172219. text++; /* skip the compression_method byte */
  172220. }
  172221. prefix_len = text - chunkdata;
  172222. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172223. (png_size_t)length, prefix_len, &data_len);
  172224. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172225. (png_uint_32)png_sizeof(png_text));
  172226. if (text_ptr == NULL)
  172227. {
  172228. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172229. png_free(png_ptr, chunkdata);
  172230. return;
  172231. }
  172232. text_ptr->compression = comp_type;
  172233. text_ptr->key = chunkdata;
  172234. #ifdef PNG_iTXt_SUPPORTED
  172235. text_ptr->lang = NULL;
  172236. text_ptr->lang_key = NULL;
  172237. text_ptr->itxt_length = 0;
  172238. #endif
  172239. text_ptr->text = chunkdata + prefix_len;
  172240. text_ptr->text_length = data_len;
  172241. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172242. png_free(png_ptr, text_ptr);
  172243. png_free(png_ptr, chunkdata);
  172244. if (ret)
  172245. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172246. }
  172247. #endif
  172248. #if defined(PNG_READ_iTXt_SUPPORTED)
  172249. void /* PRIVATE */
  172250. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172251. {
  172252. png_textp text_ptr;
  172253. png_charp chunkdata;
  172254. png_charp key, lang, text, lang_key;
  172255. int comp_flag;
  172256. int comp_type = 0;
  172257. int ret;
  172258. png_size_t slength, prefix_len, data_len;
  172259. png_debug(1, "in png_handle_iTXt\n");
  172260. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172261. png_error(png_ptr, "Missing IHDR before iTXt");
  172262. if (png_ptr->mode & PNG_HAVE_IDAT)
  172263. png_ptr->mode |= PNG_AFTER_IDAT;
  172264. #ifdef PNG_MAX_MALLOC_64K
  172265. if (length > (png_uint_32)65535L)
  172266. {
  172267. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172268. png_crc_finish(png_ptr, length);
  172269. return;
  172270. }
  172271. #endif
  172272. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172273. if (chunkdata == NULL)
  172274. {
  172275. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172276. return;
  172277. }
  172278. slength = (png_size_t)length;
  172279. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172280. if (png_crc_finish(png_ptr, 0))
  172281. {
  172282. png_free(png_ptr, chunkdata);
  172283. return;
  172284. }
  172285. chunkdata[slength] = 0x00;
  172286. for (lang = chunkdata; *lang; lang++)
  172287. ;
  172288. lang++; /* skip NUL separator */
  172289. if (lang >= chunkdata + slength - 3)
  172290. {
  172291. png_warning(png_ptr, "Truncated iTXt chunk");
  172292. png_free(png_ptr, chunkdata);
  172293. return;
  172294. }
  172295. else
  172296. {
  172297. comp_flag = *lang++;
  172298. comp_type = *lang++;
  172299. }
  172300. for (lang_key = lang; *lang_key; lang_key++)
  172301. ;
  172302. lang_key++; /* skip NUL separator */
  172303. if (lang_key >= chunkdata + slength)
  172304. {
  172305. png_warning(png_ptr, "Truncated iTXt chunk");
  172306. png_free(png_ptr, chunkdata);
  172307. return;
  172308. }
  172309. for (text = lang_key; *text; text++)
  172310. ;
  172311. text++; /* skip NUL separator */
  172312. if (text >= chunkdata + slength)
  172313. {
  172314. png_warning(png_ptr, "Malformed iTXt chunk");
  172315. png_free(png_ptr, chunkdata);
  172316. return;
  172317. }
  172318. prefix_len = text - chunkdata;
  172319. key=chunkdata;
  172320. if (comp_flag)
  172321. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172322. (size_t)length, prefix_len, &data_len);
  172323. else
  172324. data_len=png_strlen(chunkdata + prefix_len);
  172325. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172326. (png_uint_32)png_sizeof(png_text));
  172327. if (text_ptr == NULL)
  172328. {
  172329. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172330. png_free(png_ptr, chunkdata);
  172331. return;
  172332. }
  172333. text_ptr->compression = (int)comp_flag + 1;
  172334. text_ptr->lang_key = chunkdata+(lang_key-key);
  172335. text_ptr->lang = chunkdata+(lang-key);
  172336. text_ptr->itxt_length = data_len;
  172337. text_ptr->text_length = 0;
  172338. text_ptr->key = chunkdata;
  172339. text_ptr->text = chunkdata + prefix_len;
  172340. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172341. png_free(png_ptr, text_ptr);
  172342. png_free(png_ptr, chunkdata);
  172343. if (ret)
  172344. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172345. }
  172346. #endif
  172347. void /* PRIVATE */
  172348. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172349. {
  172350. png_uint_32 skip = 0;
  172351. png_debug(1, "in png_handle_unknown\n");
  172352. if (png_ptr->mode & PNG_HAVE_IDAT)
  172353. {
  172354. #ifdef PNG_USE_LOCAL_ARRAYS
  172355. PNG_CONST PNG_IDAT;
  172356. #endif
  172357. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172358. png_ptr->mode |= PNG_AFTER_IDAT;
  172359. }
  172360. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172361. if (!(png_ptr->chunk_name[0] & 0x20))
  172362. {
  172363. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172364. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172365. PNG_HANDLE_CHUNK_ALWAYS
  172366. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172367. && png_ptr->read_user_chunk_fn == NULL
  172368. #endif
  172369. )
  172370. #endif
  172371. png_chunk_error(png_ptr, "unknown critical chunk");
  172372. }
  172373. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172374. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172375. (png_ptr->read_user_chunk_fn != NULL))
  172376. {
  172377. #ifdef PNG_MAX_MALLOC_64K
  172378. if (length > (png_uint_32)65535L)
  172379. {
  172380. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172381. skip = length - (png_uint_32)65535L;
  172382. length = (png_uint_32)65535L;
  172383. }
  172384. #endif
  172385. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172386. (png_charp)png_ptr->chunk_name, 5);
  172387. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172388. png_ptr->unknown_chunk.size = (png_size_t)length;
  172389. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172390. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172391. if(png_ptr->read_user_chunk_fn != NULL)
  172392. {
  172393. int ret;
  172394. ret = (*(png_ptr->read_user_chunk_fn))
  172395. (png_ptr, &png_ptr->unknown_chunk);
  172396. if (ret < 0)
  172397. png_chunk_error(png_ptr, "error in user chunk");
  172398. if (ret == 0)
  172399. {
  172400. if (!(png_ptr->chunk_name[0] & 0x20))
  172401. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172402. PNG_HANDLE_CHUNK_ALWAYS)
  172403. png_chunk_error(png_ptr, "unknown critical chunk");
  172404. png_set_unknown_chunks(png_ptr, info_ptr,
  172405. &png_ptr->unknown_chunk, 1);
  172406. }
  172407. }
  172408. #else
  172409. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172410. #endif
  172411. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172412. png_ptr->unknown_chunk.data = NULL;
  172413. }
  172414. else
  172415. #endif
  172416. skip = length;
  172417. png_crc_finish(png_ptr, skip);
  172418. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172419. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172420. #endif
  172421. }
  172422. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172423. void /* PRIVATE */
  172424. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172425. {
  172426. png_debug(1, "in png_check_chunk_name\n");
  172427. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172428. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172429. {
  172430. png_chunk_error(png_ptr, "invalid chunk type");
  172431. }
  172432. }
  172433. void /* PRIVATE */
  172434. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172435. {
  172436. png_debug(1,"in png_combine_row\n");
  172437. if (mask == 0xff)
  172438. {
  172439. png_memcpy(row, png_ptr->row_buf + 1,
  172440. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172441. }
  172442. else
  172443. {
  172444. switch (png_ptr->row_info.pixel_depth)
  172445. {
  172446. case 1:
  172447. {
  172448. png_bytep sp = png_ptr->row_buf + 1;
  172449. png_bytep dp = row;
  172450. int s_inc, s_start, s_end;
  172451. int m = 0x80;
  172452. int shift;
  172453. png_uint_32 i;
  172454. png_uint_32 row_width = png_ptr->width;
  172455. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172456. if (png_ptr->transformations & PNG_PACKSWAP)
  172457. {
  172458. s_start = 0;
  172459. s_end = 7;
  172460. s_inc = 1;
  172461. }
  172462. else
  172463. #endif
  172464. {
  172465. s_start = 7;
  172466. s_end = 0;
  172467. s_inc = -1;
  172468. }
  172469. shift = s_start;
  172470. for (i = 0; i < row_width; i++)
  172471. {
  172472. if (m & mask)
  172473. {
  172474. int value;
  172475. value = (*sp >> shift) & 0x01;
  172476. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172477. *dp |= (png_byte)(value << shift);
  172478. }
  172479. if (shift == s_end)
  172480. {
  172481. shift = s_start;
  172482. sp++;
  172483. dp++;
  172484. }
  172485. else
  172486. shift += s_inc;
  172487. if (m == 1)
  172488. m = 0x80;
  172489. else
  172490. m >>= 1;
  172491. }
  172492. break;
  172493. }
  172494. case 2:
  172495. {
  172496. png_bytep sp = png_ptr->row_buf + 1;
  172497. png_bytep dp = row;
  172498. int s_start, s_end, s_inc;
  172499. int m = 0x80;
  172500. int shift;
  172501. png_uint_32 i;
  172502. png_uint_32 row_width = png_ptr->width;
  172503. int value;
  172504. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172505. if (png_ptr->transformations & PNG_PACKSWAP)
  172506. {
  172507. s_start = 0;
  172508. s_end = 6;
  172509. s_inc = 2;
  172510. }
  172511. else
  172512. #endif
  172513. {
  172514. s_start = 6;
  172515. s_end = 0;
  172516. s_inc = -2;
  172517. }
  172518. shift = s_start;
  172519. for (i = 0; i < row_width; i++)
  172520. {
  172521. if (m & mask)
  172522. {
  172523. value = (*sp >> shift) & 0x03;
  172524. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  172525. *dp |= (png_byte)(value << shift);
  172526. }
  172527. if (shift == s_end)
  172528. {
  172529. shift = s_start;
  172530. sp++;
  172531. dp++;
  172532. }
  172533. else
  172534. shift += s_inc;
  172535. if (m == 1)
  172536. m = 0x80;
  172537. else
  172538. m >>= 1;
  172539. }
  172540. break;
  172541. }
  172542. case 4:
  172543. {
  172544. png_bytep sp = png_ptr->row_buf + 1;
  172545. png_bytep dp = row;
  172546. int s_start, s_end, s_inc;
  172547. int m = 0x80;
  172548. int shift;
  172549. png_uint_32 i;
  172550. png_uint_32 row_width = png_ptr->width;
  172551. int value;
  172552. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172553. if (png_ptr->transformations & PNG_PACKSWAP)
  172554. {
  172555. s_start = 0;
  172556. s_end = 4;
  172557. s_inc = 4;
  172558. }
  172559. else
  172560. #endif
  172561. {
  172562. s_start = 4;
  172563. s_end = 0;
  172564. s_inc = -4;
  172565. }
  172566. shift = s_start;
  172567. for (i = 0; i < row_width; i++)
  172568. {
  172569. if (m & mask)
  172570. {
  172571. value = (*sp >> shift) & 0xf;
  172572. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  172573. *dp |= (png_byte)(value << shift);
  172574. }
  172575. if (shift == s_end)
  172576. {
  172577. shift = s_start;
  172578. sp++;
  172579. dp++;
  172580. }
  172581. else
  172582. shift += s_inc;
  172583. if (m == 1)
  172584. m = 0x80;
  172585. else
  172586. m >>= 1;
  172587. }
  172588. break;
  172589. }
  172590. default:
  172591. {
  172592. png_bytep sp = png_ptr->row_buf + 1;
  172593. png_bytep dp = row;
  172594. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  172595. png_uint_32 i;
  172596. png_uint_32 row_width = png_ptr->width;
  172597. png_byte m = 0x80;
  172598. for (i = 0; i < row_width; i++)
  172599. {
  172600. if (m & mask)
  172601. {
  172602. png_memcpy(dp, sp, pixel_bytes);
  172603. }
  172604. sp += pixel_bytes;
  172605. dp += pixel_bytes;
  172606. if (m == 1)
  172607. m = 0x80;
  172608. else
  172609. m >>= 1;
  172610. }
  172611. break;
  172612. }
  172613. }
  172614. }
  172615. }
  172616. #ifdef PNG_READ_INTERLACING_SUPPORTED
  172617. void /* PRIVATE */
  172618. png_do_read_interlace(png_structp png_ptr)
  172619. {
  172620. png_row_infop row_info = &(png_ptr->row_info);
  172621. png_bytep row = png_ptr->row_buf + 1;
  172622. int pass = png_ptr->pass;
  172623. png_uint_32 transformations = png_ptr->transformations;
  172624. #ifdef PNG_USE_LOCAL_ARRAYS
  172625. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172626. #endif
  172627. png_debug(1,"in png_do_read_interlace\n");
  172628. if (row != NULL && row_info != NULL)
  172629. {
  172630. png_uint_32 final_width;
  172631. final_width = row_info->width * png_pass_inc[pass];
  172632. switch (row_info->pixel_depth)
  172633. {
  172634. case 1:
  172635. {
  172636. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  172637. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  172638. int sshift, dshift;
  172639. int s_start, s_end, s_inc;
  172640. int jstop = png_pass_inc[pass];
  172641. png_byte v;
  172642. png_uint_32 i;
  172643. int j;
  172644. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172645. if (transformations & PNG_PACKSWAP)
  172646. {
  172647. sshift = (int)((row_info->width + 7) & 0x07);
  172648. dshift = (int)((final_width + 7) & 0x07);
  172649. s_start = 7;
  172650. s_end = 0;
  172651. s_inc = -1;
  172652. }
  172653. else
  172654. #endif
  172655. {
  172656. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  172657. dshift = 7 - (int)((final_width + 7) & 0x07);
  172658. s_start = 0;
  172659. s_end = 7;
  172660. s_inc = 1;
  172661. }
  172662. for (i = 0; i < row_info->width; i++)
  172663. {
  172664. v = (png_byte)((*sp >> sshift) & 0x01);
  172665. for (j = 0; j < jstop; j++)
  172666. {
  172667. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  172668. *dp |= (png_byte)(v << dshift);
  172669. if (dshift == s_end)
  172670. {
  172671. dshift = s_start;
  172672. dp--;
  172673. }
  172674. else
  172675. dshift += s_inc;
  172676. }
  172677. if (sshift == s_end)
  172678. {
  172679. sshift = s_start;
  172680. sp--;
  172681. }
  172682. else
  172683. sshift += s_inc;
  172684. }
  172685. break;
  172686. }
  172687. case 2:
  172688. {
  172689. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  172690. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  172691. int sshift, dshift;
  172692. int s_start, s_end, s_inc;
  172693. int jstop = png_pass_inc[pass];
  172694. png_uint_32 i;
  172695. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172696. if (transformations & PNG_PACKSWAP)
  172697. {
  172698. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  172699. dshift = (int)(((final_width + 3) & 0x03) << 1);
  172700. s_start = 6;
  172701. s_end = 0;
  172702. s_inc = -2;
  172703. }
  172704. else
  172705. #endif
  172706. {
  172707. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  172708. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  172709. s_start = 0;
  172710. s_end = 6;
  172711. s_inc = 2;
  172712. }
  172713. for (i = 0; i < row_info->width; i++)
  172714. {
  172715. png_byte v;
  172716. int j;
  172717. v = (png_byte)((*sp >> sshift) & 0x03);
  172718. for (j = 0; j < jstop; j++)
  172719. {
  172720. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  172721. *dp |= (png_byte)(v << dshift);
  172722. if (dshift == s_end)
  172723. {
  172724. dshift = s_start;
  172725. dp--;
  172726. }
  172727. else
  172728. dshift += s_inc;
  172729. }
  172730. if (sshift == s_end)
  172731. {
  172732. sshift = s_start;
  172733. sp--;
  172734. }
  172735. else
  172736. sshift += s_inc;
  172737. }
  172738. break;
  172739. }
  172740. case 4:
  172741. {
  172742. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  172743. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  172744. int sshift, dshift;
  172745. int s_start, s_end, s_inc;
  172746. png_uint_32 i;
  172747. int jstop = png_pass_inc[pass];
  172748. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172749. if (transformations & PNG_PACKSWAP)
  172750. {
  172751. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  172752. dshift = (int)(((final_width + 1) & 0x01) << 2);
  172753. s_start = 4;
  172754. s_end = 0;
  172755. s_inc = -4;
  172756. }
  172757. else
  172758. #endif
  172759. {
  172760. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  172761. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  172762. s_start = 0;
  172763. s_end = 4;
  172764. s_inc = 4;
  172765. }
  172766. for (i = 0; i < row_info->width; i++)
  172767. {
  172768. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  172769. int j;
  172770. for (j = 0; j < jstop; j++)
  172771. {
  172772. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  172773. *dp |= (png_byte)(v << dshift);
  172774. if (dshift == s_end)
  172775. {
  172776. dshift = s_start;
  172777. dp--;
  172778. }
  172779. else
  172780. dshift += s_inc;
  172781. }
  172782. if (sshift == s_end)
  172783. {
  172784. sshift = s_start;
  172785. sp--;
  172786. }
  172787. else
  172788. sshift += s_inc;
  172789. }
  172790. break;
  172791. }
  172792. default:
  172793. {
  172794. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  172795. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  172796. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  172797. int jstop = png_pass_inc[pass];
  172798. png_uint_32 i;
  172799. for (i = 0; i < row_info->width; i++)
  172800. {
  172801. png_byte v[8];
  172802. int j;
  172803. png_memcpy(v, sp, pixel_bytes);
  172804. for (j = 0; j < jstop; j++)
  172805. {
  172806. png_memcpy(dp, v, pixel_bytes);
  172807. dp -= pixel_bytes;
  172808. }
  172809. sp -= pixel_bytes;
  172810. }
  172811. break;
  172812. }
  172813. }
  172814. row_info->width = final_width;
  172815. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  172816. }
  172817. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  172818. transformations = transformations; /* silence compiler warning */
  172819. #endif
  172820. }
  172821. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  172822. void /* PRIVATE */
  172823. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  172824. png_bytep prev_row, int filter)
  172825. {
  172826. png_debug(1, "in png_read_filter_row\n");
  172827. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  172828. switch (filter)
  172829. {
  172830. case PNG_FILTER_VALUE_NONE:
  172831. break;
  172832. case PNG_FILTER_VALUE_SUB:
  172833. {
  172834. png_uint_32 i;
  172835. png_uint_32 istop = row_info->rowbytes;
  172836. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172837. png_bytep rp = row + bpp;
  172838. png_bytep lp = row;
  172839. for (i = bpp; i < istop; i++)
  172840. {
  172841. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  172842. rp++;
  172843. }
  172844. break;
  172845. }
  172846. case PNG_FILTER_VALUE_UP:
  172847. {
  172848. png_uint_32 i;
  172849. png_uint_32 istop = row_info->rowbytes;
  172850. png_bytep rp = row;
  172851. png_bytep pp = prev_row;
  172852. for (i = 0; i < istop; i++)
  172853. {
  172854. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172855. rp++;
  172856. }
  172857. break;
  172858. }
  172859. case PNG_FILTER_VALUE_AVG:
  172860. {
  172861. png_uint_32 i;
  172862. png_bytep rp = row;
  172863. png_bytep pp = prev_row;
  172864. png_bytep lp = row;
  172865. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172866. png_uint_32 istop = row_info->rowbytes - bpp;
  172867. for (i = 0; i < bpp; i++)
  172868. {
  172869. *rp = (png_byte)(((int)(*rp) +
  172870. ((int)(*pp++) / 2 )) & 0xff);
  172871. rp++;
  172872. }
  172873. for (i = 0; i < istop; i++)
  172874. {
  172875. *rp = (png_byte)(((int)(*rp) +
  172876. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  172877. rp++;
  172878. }
  172879. break;
  172880. }
  172881. case PNG_FILTER_VALUE_PAETH:
  172882. {
  172883. png_uint_32 i;
  172884. png_bytep rp = row;
  172885. png_bytep pp = prev_row;
  172886. png_bytep lp = row;
  172887. png_bytep cp = prev_row;
  172888. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  172889. png_uint_32 istop=row_info->rowbytes - bpp;
  172890. for (i = 0; i < bpp; i++)
  172891. {
  172892. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  172893. rp++;
  172894. }
  172895. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  172896. {
  172897. int a, b, c, pa, pb, pc, p;
  172898. a = *lp++;
  172899. b = *pp++;
  172900. c = *cp++;
  172901. p = b - c;
  172902. pc = a - c;
  172903. #ifdef PNG_USE_ABS
  172904. pa = abs(p);
  172905. pb = abs(pc);
  172906. pc = abs(p + pc);
  172907. #else
  172908. pa = p < 0 ? -p : p;
  172909. pb = pc < 0 ? -pc : pc;
  172910. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  172911. #endif
  172912. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  172913. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  172914. rp++;
  172915. }
  172916. break;
  172917. }
  172918. default:
  172919. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  172920. *row=0;
  172921. break;
  172922. }
  172923. }
  172924. void /* PRIVATE */
  172925. png_read_finish_row(png_structp png_ptr)
  172926. {
  172927. #ifdef PNG_USE_LOCAL_ARRAYS
  172928. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  172929. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  172930. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  172931. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  172932. #endif
  172933. png_debug(1, "in png_read_finish_row\n");
  172934. png_ptr->row_number++;
  172935. if (png_ptr->row_number < png_ptr->num_rows)
  172936. return;
  172937. if (png_ptr->interlaced)
  172938. {
  172939. png_ptr->row_number = 0;
  172940. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  172941. png_ptr->rowbytes + 1);
  172942. do
  172943. {
  172944. png_ptr->pass++;
  172945. if (png_ptr->pass >= 7)
  172946. break;
  172947. png_ptr->iwidth = (png_ptr->width +
  172948. png_pass_inc[png_ptr->pass] - 1 -
  172949. png_pass_start[png_ptr->pass]) /
  172950. png_pass_inc[png_ptr->pass];
  172951. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  172952. png_ptr->iwidth) + 1;
  172953. if (!(png_ptr->transformations & PNG_INTERLACE))
  172954. {
  172955. png_ptr->num_rows = (png_ptr->height +
  172956. png_pass_yinc[png_ptr->pass] - 1 -
  172957. png_pass_ystart[png_ptr->pass]) /
  172958. png_pass_yinc[png_ptr->pass];
  172959. if (!(png_ptr->num_rows))
  172960. continue;
  172961. }
  172962. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  172963. break;
  172964. } while (png_ptr->iwidth == 0);
  172965. if (png_ptr->pass < 7)
  172966. return;
  172967. }
  172968. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  172969. {
  172970. #ifdef PNG_USE_LOCAL_ARRAYS
  172971. PNG_CONST PNG_IDAT;
  172972. #endif
  172973. char extra;
  172974. int ret;
  172975. png_ptr->zstream.next_out = (Bytef *)&extra;
  172976. png_ptr->zstream.avail_out = (uInt)1;
  172977. for(;;)
  172978. {
  172979. if (!(png_ptr->zstream.avail_in))
  172980. {
  172981. while (!png_ptr->idat_size)
  172982. {
  172983. png_byte chunk_length[4];
  172984. png_crc_finish(png_ptr, 0);
  172985. png_read_data(png_ptr, chunk_length, 4);
  172986. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  172987. png_reset_crc(png_ptr);
  172988. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  172989. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  172990. png_error(png_ptr, "Not enough image data");
  172991. }
  172992. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  172993. png_ptr->zstream.next_in = png_ptr->zbuf;
  172994. if (png_ptr->zbuf_size > png_ptr->idat_size)
  172995. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  172996. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  172997. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  172998. }
  172999. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173000. if (ret == Z_STREAM_END)
  173001. {
  173002. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173003. png_ptr->idat_size)
  173004. png_warning(png_ptr, "Extra compressed data");
  173005. png_ptr->mode |= PNG_AFTER_IDAT;
  173006. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173007. break;
  173008. }
  173009. if (ret != Z_OK)
  173010. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173011. "Decompression Error");
  173012. if (!(png_ptr->zstream.avail_out))
  173013. {
  173014. png_warning(png_ptr, "Extra compressed data.");
  173015. png_ptr->mode |= PNG_AFTER_IDAT;
  173016. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173017. break;
  173018. }
  173019. }
  173020. png_ptr->zstream.avail_out = 0;
  173021. }
  173022. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173023. png_warning(png_ptr, "Extra compression data");
  173024. inflateReset(&png_ptr->zstream);
  173025. png_ptr->mode |= PNG_AFTER_IDAT;
  173026. }
  173027. void /* PRIVATE */
  173028. png_read_start_row(png_structp png_ptr)
  173029. {
  173030. #ifdef PNG_USE_LOCAL_ARRAYS
  173031. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173032. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173033. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173034. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173035. #endif
  173036. int max_pixel_depth;
  173037. png_uint_32 row_bytes;
  173038. png_debug(1, "in png_read_start_row\n");
  173039. png_ptr->zstream.avail_in = 0;
  173040. png_init_read_transformations(png_ptr);
  173041. if (png_ptr->interlaced)
  173042. {
  173043. if (!(png_ptr->transformations & PNG_INTERLACE))
  173044. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173045. png_pass_ystart[0]) / png_pass_yinc[0];
  173046. else
  173047. png_ptr->num_rows = png_ptr->height;
  173048. png_ptr->iwidth = (png_ptr->width +
  173049. png_pass_inc[png_ptr->pass] - 1 -
  173050. png_pass_start[png_ptr->pass]) /
  173051. png_pass_inc[png_ptr->pass];
  173052. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173053. png_ptr->irowbytes = (png_size_t)row_bytes;
  173054. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173055. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173056. }
  173057. else
  173058. {
  173059. png_ptr->num_rows = png_ptr->height;
  173060. png_ptr->iwidth = png_ptr->width;
  173061. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173062. }
  173063. max_pixel_depth = png_ptr->pixel_depth;
  173064. #if defined(PNG_READ_PACK_SUPPORTED)
  173065. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173066. max_pixel_depth = 8;
  173067. #endif
  173068. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173069. if (png_ptr->transformations & PNG_EXPAND)
  173070. {
  173071. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173072. {
  173073. if (png_ptr->num_trans)
  173074. max_pixel_depth = 32;
  173075. else
  173076. max_pixel_depth = 24;
  173077. }
  173078. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173079. {
  173080. if (max_pixel_depth < 8)
  173081. max_pixel_depth = 8;
  173082. if (png_ptr->num_trans)
  173083. max_pixel_depth *= 2;
  173084. }
  173085. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173086. {
  173087. if (png_ptr->num_trans)
  173088. {
  173089. max_pixel_depth *= 4;
  173090. max_pixel_depth /= 3;
  173091. }
  173092. }
  173093. }
  173094. #endif
  173095. #if defined(PNG_READ_FILLER_SUPPORTED)
  173096. if (png_ptr->transformations & (PNG_FILLER))
  173097. {
  173098. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173099. max_pixel_depth = 32;
  173100. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173101. {
  173102. if (max_pixel_depth <= 8)
  173103. max_pixel_depth = 16;
  173104. else
  173105. max_pixel_depth = 32;
  173106. }
  173107. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173108. {
  173109. if (max_pixel_depth <= 32)
  173110. max_pixel_depth = 32;
  173111. else
  173112. max_pixel_depth = 64;
  173113. }
  173114. }
  173115. #endif
  173116. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173117. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173118. {
  173119. if (
  173120. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173121. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173122. #endif
  173123. #if defined(PNG_READ_FILLER_SUPPORTED)
  173124. (png_ptr->transformations & (PNG_FILLER)) ||
  173125. #endif
  173126. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173127. {
  173128. if (max_pixel_depth <= 16)
  173129. max_pixel_depth = 32;
  173130. else
  173131. max_pixel_depth = 64;
  173132. }
  173133. else
  173134. {
  173135. if (max_pixel_depth <= 8)
  173136. {
  173137. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173138. max_pixel_depth = 32;
  173139. else
  173140. max_pixel_depth = 24;
  173141. }
  173142. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173143. max_pixel_depth = 64;
  173144. else
  173145. max_pixel_depth = 48;
  173146. }
  173147. }
  173148. #endif
  173149. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173150. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173151. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173152. {
  173153. int user_pixel_depth=png_ptr->user_transform_depth*
  173154. png_ptr->user_transform_channels;
  173155. if(user_pixel_depth > max_pixel_depth)
  173156. max_pixel_depth=user_pixel_depth;
  173157. }
  173158. #endif
  173159. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173160. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173161. 1 + ((max_pixel_depth + 7) >> 3);
  173162. #ifdef PNG_MAX_MALLOC_64K
  173163. if (row_bytes > (png_uint_32)65536L)
  173164. png_error(png_ptr, "This image requires a row greater than 64KB");
  173165. #endif
  173166. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173167. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173168. #ifdef PNG_MAX_MALLOC_64K
  173169. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173170. png_error(png_ptr, "This image requires a row greater than 64KB");
  173171. #endif
  173172. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173173. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173174. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173175. png_ptr->rowbytes + 1));
  173176. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173177. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173178. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173179. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173180. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173181. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173182. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173183. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173184. }
  173185. #endif /* PNG_READ_SUPPORTED */
  173186. /*** End of inlined file: pngrutil.c ***/
  173187. /*** Start of inlined file: pngset.c ***/
  173188. #define PNG_INTERNAL
  173189. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173190. #if defined(PNG_bKGD_SUPPORTED)
  173191. void PNGAPI
  173192. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173193. {
  173194. png_debug1(1, "in %s storage function\n", "bKGD");
  173195. if (png_ptr == NULL || info_ptr == NULL)
  173196. return;
  173197. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173198. info_ptr->valid |= PNG_INFO_bKGD;
  173199. }
  173200. #endif
  173201. #if defined(PNG_cHRM_SUPPORTED)
  173202. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173203. void PNGAPI
  173204. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173205. double white_x, double white_y, double red_x, double red_y,
  173206. double green_x, double green_y, double blue_x, double blue_y)
  173207. {
  173208. png_debug1(1, "in %s storage function\n", "cHRM");
  173209. if (png_ptr == NULL || info_ptr == NULL)
  173210. return;
  173211. if (white_x < 0.0 || white_y < 0.0 ||
  173212. red_x < 0.0 || red_y < 0.0 ||
  173213. green_x < 0.0 || green_y < 0.0 ||
  173214. blue_x < 0.0 || blue_y < 0.0)
  173215. {
  173216. png_warning(png_ptr,
  173217. "Ignoring attempt to set negative chromaticity value");
  173218. return;
  173219. }
  173220. if (white_x > 21474.83 || white_y > 21474.83 ||
  173221. red_x > 21474.83 || red_y > 21474.83 ||
  173222. green_x > 21474.83 || green_y > 21474.83 ||
  173223. blue_x > 21474.83 || blue_y > 21474.83)
  173224. {
  173225. png_warning(png_ptr,
  173226. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173227. return;
  173228. }
  173229. info_ptr->x_white = (float)white_x;
  173230. info_ptr->y_white = (float)white_y;
  173231. info_ptr->x_red = (float)red_x;
  173232. info_ptr->y_red = (float)red_y;
  173233. info_ptr->x_green = (float)green_x;
  173234. info_ptr->y_green = (float)green_y;
  173235. info_ptr->x_blue = (float)blue_x;
  173236. info_ptr->y_blue = (float)blue_y;
  173237. #ifdef PNG_FIXED_POINT_SUPPORTED
  173238. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173239. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173240. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173241. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173242. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173243. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173244. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173245. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173246. #endif
  173247. info_ptr->valid |= PNG_INFO_cHRM;
  173248. }
  173249. #endif
  173250. #ifdef PNG_FIXED_POINT_SUPPORTED
  173251. void PNGAPI
  173252. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173253. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173254. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173255. png_fixed_point blue_x, png_fixed_point blue_y)
  173256. {
  173257. png_debug1(1, "in %s storage function\n", "cHRM");
  173258. if (png_ptr == NULL || info_ptr == NULL)
  173259. return;
  173260. if (white_x < 0 || white_y < 0 ||
  173261. red_x < 0 || red_y < 0 ||
  173262. green_x < 0 || green_y < 0 ||
  173263. blue_x < 0 || blue_y < 0)
  173264. {
  173265. png_warning(png_ptr,
  173266. "Ignoring attempt to set negative chromaticity value");
  173267. return;
  173268. }
  173269. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173270. if (white_x > (double) PNG_UINT_31_MAX ||
  173271. white_y > (double) PNG_UINT_31_MAX ||
  173272. red_x > (double) PNG_UINT_31_MAX ||
  173273. red_y > (double) PNG_UINT_31_MAX ||
  173274. green_x > (double) PNG_UINT_31_MAX ||
  173275. green_y > (double) PNG_UINT_31_MAX ||
  173276. blue_x > (double) PNG_UINT_31_MAX ||
  173277. blue_y > (double) PNG_UINT_31_MAX)
  173278. #else
  173279. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173280. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173281. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173282. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173283. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173284. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173285. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173286. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173287. #endif
  173288. {
  173289. png_warning(png_ptr,
  173290. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173291. return;
  173292. }
  173293. info_ptr->int_x_white = white_x;
  173294. info_ptr->int_y_white = white_y;
  173295. info_ptr->int_x_red = red_x;
  173296. info_ptr->int_y_red = red_y;
  173297. info_ptr->int_x_green = green_x;
  173298. info_ptr->int_y_green = green_y;
  173299. info_ptr->int_x_blue = blue_x;
  173300. info_ptr->int_y_blue = blue_y;
  173301. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173302. info_ptr->x_white = (float)(white_x/100000.);
  173303. info_ptr->y_white = (float)(white_y/100000.);
  173304. info_ptr->x_red = (float)( red_x/100000.);
  173305. info_ptr->y_red = (float)( red_y/100000.);
  173306. info_ptr->x_green = (float)(green_x/100000.);
  173307. info_ptr->y_green = (float)(green_y/100000.);
  173308. info_ptr->x_blue = (float)( blue_x/100000.);
  173309. info_ptr->y_blue = (float)( blue_y/100000.);
  173310. #endif
  173311. info_ptr->valid |= PNG_INFO_cHRM;
  173312. }
  173313. #endif
  173314. #endif
  173315. #if defined(PNG_gAMA_SUPPORTED)
  173316. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173317. void PNGAPI
  173318. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173319. {
  173320. double gamma;
  173321. png_debug1(1, "in %s storage function\n", "gAMA");
  173322. if (png_ptr == NULL || info_ptr == NULL)
  173323. return;
  173324. if (file_gamma > 21474.83)
  173325. {
  173326. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173327. gamma=21474.83;
  173328. }
  173329. else
  173330. gamma=file_gamma;
  173331. info_ptr->gamma = (float)gamma;
  173332. #ifdef PNG_FIXED_POINT_SUPPORTED
  173333. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173334. #endif
  173335. info_ptr->valid |= PNG_INFO_gAMA;
  173336. if(gamma == 0.0)
  173337. png_warning(png_ptr, "Setting gamma=0");
  173338. }
  173339. #endif
  173340. void PNGAPI
  173341. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173342. int_gamma)
  173343. {
  173344. png_fixed_point gamma;
  173345. png_debug1(1, "in %s storage function\n", "gAMA");
  173346. if (png_ptr == NULL || info_ptr == NULL)
  173347. return;
  173348. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173349. {
  173350. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173351. gamma=PNG_UINT_31_MAX;
  173352. }
  173353. else
  173354. {
  173355. if (int_gamma < 0)
  173356. {
  173357. png_warning(png_ptr, "Setting negative gamma to zero");
  173358. gamma=0;
  173359. }
  173360. else
  173361. gamma=int_gamma;
  173362. }
  173363. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173364. info_ptr->gamma = (float)(gamma/100000.);
  173365. #endif
  173366. #ifdef PNG_FIXED_POINT_SUPPORTED
  173367. info_ptr->int_gamma = gamma;
  173368. #endif
  173369. info_ptr->valid |= PNG_INFO_gAMA;
  173370. if(gamma == 0)
  173371. png_warning(png_ptr, "Setting gamma=0");
  173372. }
  173373. #endif
  173374. #if defined(PNG_hIST_SUPPORTED)
  173375. void PNGAPI
  173376. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173377. {
  173378. int i;
  173379. png_debug1(1, "in %s storage function\n", "hIST");
  173380. if (png_ptr == NULL || info_ptr == NULL)
  173381. return;
  173382. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173383. > PNG_MAX_PALETTE_LENGTH)
  173384. {
  173385. png_warning(png_ptr,
  173386. "Invalid palette size, hIST allocation skipped.");
  173387. return;
  173388. }
  173389. #ifdef PNG_FREE_ME_SUPPORTED
  173390. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173391. #endif
  173392. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173393. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173394. if (png_ptr->hist == NULL)
  173395. {
  173396. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173397. return;
  173398. }
  173399. for (i = 0; i < info_ptr->num_palette; i++)
  173400. png_ptr->hist[i] = hist[i];
  173401. info_ptr->hist = png_ptr->hist;
  173402. info_ptr->valid |= PNG_INFO_hIST;
  173403. #ifdef PNG_FREE_ME_SUPPORTED
  173404. info_ptr->free_me |= PNG_FREE_HIST;
  173405. #else
  173406. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173407. #endif
  173408. }
  173409. #endif
  173410. void PNGAPI
  173411. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173412. png_uint_32 width, png_uint_32 height, int bit_depth,
  173413. int color_type, int interlace_type, int compression_type,
  173414. int filter_type)
  173415. {
  173416. png_debug1(1, "in %s storage function\n", "IHDR");
  173417. if (png_ptr == NULL || info_ptr == NULL)
  173418. return;
  173419. if (width == 0 || height == 0)
  173420. png_error(png_ptr, "Image width or height is zero in IHDR");
  173421. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173422. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173423. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173424. #else
  173425. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173426. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173427. #endif
  173428. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173429. png_error(png_ptr, "Invalid image size in IHDR");
  173430. if ( width > (PNG_UINT_32_MAX
  173431. >> 3) /* 8-byte RGBA pixels */
  173432. - 64 /* bigrowbuf hack */
  173433. - 1 /* filter byte */
  173434. - 7*8 /* rounding of width to multiple of 8 pixels */
  173435. - 8) /* extra max_pixel_depth pad */
  173436. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173437. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173438. bit_depth != 8 && bit_depth != 16)
  173439. png_error(png_ptr, "Invalid bit depth in IHDR");
  173440. if (color_type < 0 || color_type == 1 ||
  173441. color_type == 5 || color_type > 6)
  173442. png_error(png_ptr, "Invalid color type in IHDR");
  173443. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173444. ((color_type == PNG_COLOR_TYPE_RGB ||
  173445. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173446. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173447. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173448. if (interlace_type >= PNG_INTERLACE_LAST)
  173449. png_error(png_ptr, "Unknown interlace method in IHDR");
  173450. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173451. png_error(png_ptr, "Unknown compression method in IHDR");
  173452. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173453. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173454. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173455. if(filter_type != PNG_FILTER_TYPE_BASE)
  173456. {
  173457. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173458. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173459. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173460. (color_type == PNG_COLOR_TYPE_RGB ||
  173461. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173462. png_error(png_ptr, "Unknown filter method in IHDR");
  173463. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173464. png_warning(png_ptr, "Invalid filter method in IHDR");
  173465. }
  173466. #else
  173467. if(filter_type != PNG_FILTER_TYPE_BASE)
  173468. png_error(png_ptr, "Unknown filter method in IHDR");
  173469. #endif
  173470. info_ptr->width = width;
  173471. info_ptr->height = height;
  173472. info_ptr->bit_depth = (png_byte)bit_depth;
  173473. info_ptr->color_type =(png_byte) color_type;
  173474. info_ptr->compression_type = (png_byte)compression_type;
  173475. info_ptr->filter_type = (png_byte)filter_type;
  173476. info_ptr->interlace_type = (png_byte)interlace_type;
  173477. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173478. info_ptr->channels = 1;
  173479. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173480. info_ptr->channels = 3;
  173481. else
  173482. info_ptr->channels = 1;
  173483. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173484. info_ptr->channels++;
  173485. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173486. if (width > (PNG_UINT_32_MAX
  173487. >> 3) /* 8-byte RGBA pixels */
  173488. - 64 /* bigrowbuf hack */
  173489. - 1 /* filter byte */
  173490. - 7*8 /* rounding of width to multiple of 8 pixels */
  173491. - 8) /* extra max_pixel_depth pad */
  173492. info_ptr->rowbytes = (png_size_t)0;
  173493. else
  173494. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173495. }
  173496. #if defined(PNG_oFFs_SUPPORTED)
  173497. void PNGAPI
  173498. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173499. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173500. {
  173501. png_debug1(1, "in %s storage function\n", "oFFs");
  173502. if (png_ptr == NULL || info_ptr == NULL)
  173503. return;
  173504. info_ptr->x_offset = offset_x;
  173505. info_ptr->y_offset = offset_y;
  173506. info_ptr->offset_unit_type = (png_byte)unit_type;
  173507. info_ptr->valid |= PNG_INFO_oFFs;
  173508. }
  173509. #endif
  173510. #if defined(PNG_pCAL_SUPPORTED)
  173511. void PNGAPI
  173512. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173513. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173514. png_charp units, png_charpp params)
  173515. {
  173516. png_uint_32 length;
  173517. int i;
  173518. png_debug1(1, "in %s storage function\n", "pCAL");
  173519. if (png_ptr == NULL || info_ptr == NULL)
  173520. return;
  173521. length = png_strlen(purpose) + 1;
  173522. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  173523. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  173524. if (info_ptr->pcal_purpose == NULL)
  173525. {
  173526. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  173527. return;
  173528. }
  173529. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  173530. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  173531. info_ptr->pcal_X0 = X0;
  173532. info_ptr->pcal_X1 = X1;
  173533. info_ptr->pcal_type = (png_byte)type;
  173534. info_ptr->pcal_nparams = (png_byte)nparams;
  173535. length = png_strlen(units) + 1;
  173536. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  173537. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  173538. if (info_ptr->pcal_units == NULL)
  173539. {
  173540. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  173541. return;
  173542. }
  173543. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  173544. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  173545. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  173546. if (info_ptr->pcal_params == NULL)
  173547. {
  173548. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  173549. return;
  173550. }
  173551. info_ptr->pcal_params[nparams] = NULL;
  173552. for (i = 0; i < nparams; i++)
  173553. {
  173554. length = png_strlen(params[i]) + 1;
  173555. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  173556. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  173557. if (info_ptr->pcal_params[i] == NULL)
  173558. {
  173559. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  173560. return;
  173561. }
  173562. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  173563. }
  173564. info_ptr->valid |= PNG_INFO_pCAL;
  173565. #ifdef PNG_FREE_ME_SUPPORTED
  173566. info_ptr->free_me |= PNG_FREE_PCAL;
  173567. #endif
  173568. }
  173569. #endif
  173570. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  173571. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173572. void PNGAPI
  173573. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  173574. int unit, double width, double height)
  173575. {
  173576. png_debug1(1, "in %s storage function\n", "sCAL");
  173577. if (png_ptr == NULL || info_ptr == NULL)
  173578. return;
  173579. info_ptr->scal_unit = (png_byte)unit;
  173580. info_ptr->scal_pixel_width = width;
  173581. info_ptr->scal_pixel_height = height;
  173582. info_ptr->valid |= PNG_INFO_sCAL;
  173583. }
  173584. #else
  173585. #ifdef PNG_FIXED_POINT_SUPPORTED
  173586. void PNGAPI
  173587. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  173588. int unit, png_charp swidth, png_charp sheight)
  173589. {
  173590. png_uint_32 length;
  173591. png_debug1(1, "in %s storage function\n", "sCAL");
  173592. if (png_ptr == NULL || info_ptr == NULL)
  173593. return;
  173594. info_ptr->scal_unit = (png_byte)unit;
  173595. length = png_strlen(swidth) + 1;
  173596. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173597. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  173598. if (info_ptr->scal_s_width == NULL)
  173599. {
  173600. png_warning(png_ptr,
  173601. "Memory allocation failed while processing sCAL.");
  173602. }
  173603. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  173604. length = png_strlen(sheight) + 1;
  173605. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  173606. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  173607. if (info_ptr->scal_s_height == NULL)
  173608. {
  173609. png_free (png_ptr, info_ptr->scal_s_width);
  173610. png_warning(png_ptr,
  173611. "Memory allocation failed while processing sCAL.");
  173612. }
  173613. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  173614. info_ptr->valid |= PNG_INFO_sCAL;
  173615. #ifdef PNG_FREE_ME_SUPPORTED
  173616. info_ptr->free_me |= PNG_FREE_SCAL;
  173617. #endif
  173618. }
  173619. #endif
  173620. #endif
  173621. #endif
  173622. #if defined(PNG_pHYs_SUPPORTED)
  173623. void PNGAPI
  173624. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  173625. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  173626. {
  173627. png_debug1(1, "in %s storage function\n", "pHYs");
  173628. if (png_ptr == NULL || info_ptr == NULL)
  173629. return;
  173630. info_ptr->x_pixels_per_unit = res_x;
  173631. info_ptr->y_pixels_per_unit = res_y;
  173632. info_ptr->phys_unit_type = (png_byte)unit_type;
  173633. info_ptr->valid |= PNG_INFO_pHYs;
  173634. }
  173635. #endif
  173636. void PNGAPI
  173637. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  173638. png_colorp palette, int num_palette)
  173639. {
  173640. png_debug1(1, "in %s storage function\n", "PLTE");
  173641. if (png_ptr == NULL || info_ptr == NULL)
  173642. return;
  173643. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  173644. {
  173645. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173646. png_error(png_ptr, "Invalid palette length");
  173647. else
  173648. {
  173649. png_warning(png_ptr, "Invalid palette length");
  173650. return;
  173651. }
  173652. }
  173653. #ifdef PNG_FREE_ME_SUPPORTED
  173654. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  173655. #endif
  173656. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  173657. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  173658. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  173659. png_sizeof(png_color));
  173660. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  173661. info_ptr->palette = png_ptr->palette;
  173662. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  173663. #ifdef PNG_FREE_ME_SUPPORTED
  173664. info_ptr->free_me |= PNG_FREE_PLTE;
  173665. #else
  173666. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  173667. #endif
  173668. info_ptr->valid |= PNG_INFO_PLTE;
  173669. }
  173670. #if defined(PNG_sBIT_SUPPORTED)
  173671. void PNGAPI
  173672. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  173673. png_color_8p sig_bit)
  173674. {
  173675. png_debug1(1, "in %s storage function\n", "sBIT");
  173676. if (png_ptr == NULL || info_ptr == NULL)
  173677. return;
  173678. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  173679. info_ptr->valid |= PNG_INFO_sBIT;
  173680. }
  173681. #endif
  173682. #if defined(PNG_sRGB_SUPPORTED)
  173683. void PNGAPI
  173684. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  173685. {
  173686. png_debug1(1, "in %s storage function\n", "sRGB");
  173687. if (png_ptr == NULL || info_ptr == NULL)
  173688. return;
  173689. info_ptr->srgb_intent = (png_byte)intent;
  173690. info_ptr->valid |= PNG_INFO_sRGB;
  173691. }
  173692. void PNGAPI
  173693. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  173694. int intent)
  173695. {
  173696. #if defined(PNG_gAMA_SUPPORTED)
  173697. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173698. float file_gamma;
  173699. #endif
  173700. #ifdef PNG_FIXED_POINT_SUPPORTED
  173701. png_fixed_point int_file_gamma;
  173702. #endif
  173703. #endif
  173704. #if defined(PNG_cHRM_SUPPORTED)
  173705. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173706. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  173707. #endif
  173708. #ifdef PNG_FIXED_POINT_SUPPORTED
  173709. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  173710. int_green_y, int_blue_x, int_blue_y;
  173711. #endif
  173712. #endif
  173713. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  173714. if (png_ptr == NULL || info_ptr == NULL)
  173715. return;
  173716. png_set_sRGB(png_ptr, info_ptr, intent);
  173717. #if defined(PNG_gAMA_SUPPORTED)
  173718. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173719. file_gamma = (float).45455;
  173720. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  173721. #endif
  173722. #ifdef PNG_FIXED_POINT_SUPPORTED
  173723. int_file_gamma = 45455L;
  173724. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  173725. #endif
  173726. #endif
  173727. #if defined(PNG_cHRM_SUPPORTED)
  173728. #ifdef PNG_FIXED_POINT_SUPPORTED
  173729. int_white_x = 31270L;
  173730. int_white_y = 32900L;
  173731. int_red_x = 64000L;
  173732. int_red_y = 33000L;
  173733. int_green_x = 30000L;
  173734. int_green_y = 60000L;
  173735. int_blue_x = 15000L;
  173736. int_blue_y = 6000L;
  173737. png_set_cHRM_fixed(png_ptr, info_ptr,
  173738. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  173739. int_blue_x, int_blue_y);
  173740. #endif
  173741. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173742. white_x = (float).3127;
  173743. white_y = (float).3290;
  173744. red_x = (float).64;
  173745. red_y = (float).33;
  173746. green_x = (float).30;
  173747. green_y = (float).60;
  173748. blue_x = (float).15;
  173749. blue_y = (float).06;
  173750. png_set_cHRM(png_ptr, info_ptr,
  173751. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  173752. #endif
  173753. #endif
  173754. }
  173755. #endif
  173756. #if defined(PNG_iCCP_SUPPORTED)
  173757. void PNGAPI
  173758. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  173759. png_charp name, int compression_type,
  173760. png_charp profile, png_uint_32 proflen)
  173761. {
  173762. png_charp new_iccp_name;
  173763. png_charp new_iccp_profile;
  173764. png_debug1(1, "in %s storage function\n", "iCCP");
  173765. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  173766. return;
  173767. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  173768. if (new_iccp_name == NULL)
  173769. {
  173770. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  173771. return;
  173772. }
  173773. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  173774. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  173775. if (new_iccp_profile == NULL)
  173776. {
  173777. png_free (png_ptr, new_iccp_name);
  173778. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  173779. return;
  173780. }
  173781. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  173782. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  173783. info_ptr->iccp_proflen = proflen;
  173784. info_ptr->iccp_name = new_iccp_name;
  173785. info_ptr->iccp_profile = new_iccp_profile;
  173786. info_ptr->iccp_compression = (png_byte)compression_type;
  173787. #ifdef PNG_FREE_ME_SUPPORTED
  173788. info_ptr->free_me |= PNG_FREE_ICCP;
  173789. #endif
  173790. info_ptr->valid |= PNG_INFO_iCCP;
  173791. }
  173792. #endif
  173793. #if defined(PNG_TEXT_SUPPORTED)
  173794. void PNGAPI
  173795. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173796. int num_text)
  173797. {
  173798. int ret;
  173799. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  173800. if (ret)
  173801. png_error(png_ptr, "Insufficient memory to store text");
  173802. }
  173803. int /* PRIVATE */
  173804. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  173805. int num_text)
  173806. {
  173807. int i;
  173808. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  173809. "text" : (png_const_charp)png_ptr->chunk_name));
  173810. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  173811. return(0);
  173812. if (info_ptr->num_text + num_text > info_ptr->max_text)
  173813. {
  173814. if (info_ptr->text != NULL)
  173815. {
  173816. png_textp old_text;
  173817. int old_max;
  173818. old_max = info_ptr->max_text;
  173819. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  173820. old_text = info_ptr->text;
  173821. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173822. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173823. if (info_ptr->text == NULL)
  173824. {
  173825. png_free(png_ptr, old_text);
  173826. return(1);
  173827. }
  173828. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  173829. png_sizeof(png_text)));
  173830. png_free(png_ptr, old_text);
  173831. }
  173832. else
  173833. {
  173834. info_ptr->max_text = num_text + 8;
  173835. info_ptr->num_text = 0;
  173836. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  173837. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  173838. if (info_ptr->text == NULL)
  173839. return(1);
  173840. #ifdef PNG_FREE_ME_SUPPORTED
  173841. info_ptr->free_me |= PNG_FREE_TEXT;
  173842. #endif
  173843. }
  173844. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  173845. info_ptr->max_text);
  173846. }
  173847. for (i = 0; i < num_text; i++)
  173848. {
  173849. png_size_t text_length,key_len;
  173850. png_size_t lang_len,lang_key_len;
  173851. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  173852. if (text_ptr[i].key == NULL)
  173853. continue;
  173854. key_len = png_strlen(text_ptr[i].key);
  173855. if(text_ptr[i].compression <= 0)
  173856. {
  173857. lang_len = 0;
  173858. lang_key_len = 0;
  173859. }
  173860. else
  173861. #ifdef PNG_iTXt_SUPPORTED
  173862. {
  173863. if (text_ptr[i].lang != NULL)
  173864. lang_len = png_strlen(text_ptr[i].lang);
  173865. else
  173866. lang_len = 0;
  173867. if (text_ptr[i].lang_key != NULL)
  173868. lang_key_len = png_strlen(text_ptr[i].lang_key);
  173869. else
  173870. lang_key_len = 0;
  173871. }
  173872. #else
  173873. {
  173874. png_warning(png_ptr, "iTXt chunk not supported.");
  173875. continue;
  173876. }
  173877. #endif
  173878. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  173879. {
  173880. text_length = 0;
  173881. #ifdef PNG_iTXt_SUPPORTED
  173882. if(text_ptr[i].compression > 0)
  173883. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  173884. else
  173885. #endif
  173886. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  173887. }
  173888. else
  173889. {
  173890. text_length = png_strlen(text_ptr[i].text);
  173891. textp->compression = text_ptr[i].compression;
  173892. }
  173893. textp->key = (png_charp)png_malloc_warn(png_ptr,
  173894. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  173895. if (textp->key == NULL)
  173896. return(1);
  173897. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  173898. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  173899. (int)textp->key);
  173900. png_memcpy(textp->key, text_ptr[i].key,
  173901. (png_size_t)(key_len));
  173902. *(textp->key+key_len) = '\0';
  173903. #ifdef PNG_iTXt_SUPPORTED
  173904. if (text_ptr[i].compression > 0)
  173905. {
  173906. textp->lang=textp->key + key_len + 1;
  173907. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  173908. *(textp->lang+lang_len) = '\0';
  173909. textp->lang_key=textp->lang + lang_len + 1;
  173910. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  173911. *(textp->lang_key+lang_key_len) = '\0';
  173912. textp->text=textp->lang_key + lang_key_len + 1;
  173913. }
  173914. else
  173915. #endif
  173916. {
  173917. #ifdef PNG_iTXt_SUPPORTED
  173918. textp->lang=NULL;
  173919. textp->lang_key=NULL;
  173920. #endif
  173921. textp->text=textp->key + key_len + 1;
  173922. }
  173923. if(text_length)
  173924. png_memcpy(textp->text, text_ptr[i].text,
  173925. (png_size_t)(text_length));
  173926. *(textp->text+text_length) = '\0';
  173927. #ifdef PNG_iTXt_SUPPORTED
  173928. if(textp->compression > 0)
  173929. {
  173930. textp->text_length = 0;
  173931. textp->itxt_length = text_length;
  173932. }
  173933. else
  173934. #endif
  173935. {
  173936. textp->text_length = text_length;
  173937. #ifdef PNG_iTXt_SUPPORTED
  173938. textp->itxt_length = 0;
  173939. #endif
  173940. }
  173941. info_ptr->num_text++;
  173942. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  173943. }
  173944. return(0);
  173945. }
  173946. #endif
  173947. #if defined(PNG_tIME_SUPPORTED)
  173948. void PNGAPI
  173949. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  173950. {
  173951. png_debug1(1, "in %s storage function\n", "tIME");
  173952. if (png_ptr == NULL || info_ptr == NULL ||
  173953. (png_ptr->mode & PNG_WROTE_tIME))
  173954. return;
  173955. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  173956. info_ptr->valid |= PNG_INFO_tIME;
  173957. }
  173958. #endif
  173959. #if defined(PNG_tRNS_SUPPORTED)
  173960. void PNGAPI
  173961. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  173962. png_bytep trans, int num_trans, png_color_16p trans_values)
  173963. {
  173964. png_debug1(1, "in %s storage function\n", "tRNS");
  173965. if (png_ptr == NULL || info_ptr == NULL)
  173966. return;
  173967. if (trans != NULL)
  173968. {
  173969. #ifdef PNG_FREE_ME_SUPPORTED
  173970. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  173971. #endif
  173972. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  173973. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  173974. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  173975. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  173976. #ifdef PNG_FREE_ME_SUPPORTED
  173977. info_ptr->free_me |= PNG_FREE_TRNS;
  173978. #else
  173979. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  173980. #endif
  173981. }
  173982. if (trans_values != NULL)
  173983. {
  173984. png_memcpy(&(info_ptr->trans_values), trans_values,
  173985. png_sizeof(png_color_16));
  173986. if (num_trans == 0)
  173987. num_trans = 1;
  173988. }
  173989. info_ptr->num_trans = (png_uint_16)num_trans;
  173990. info_ptr->valid |= PNG_INFO_tRNS;
  173991. }
  173992. #endif
  173993. #if defined(PNG_sPLT_SUPPORTED)
  173994. void PNGAPI
  173995. png_set_sPLT(png_structp png_ptr,
  173996. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  173997. {
  173998. png_sPLT_tp np;
  173999. int i;
  174000. if (png_ptr == NULL || info_ptr == NULL)
  174001. return;
  174002. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174003. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174004. if (np == NULL)
  174005. {
  174006. png_warning(png_ptr, "No memory for sPLT palettes.");
  174007. return;
  174008. }
  174009. png_memcpy(np, info_ptr->splt_palettes,
  174010. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174011. png_free(png_ptr, info_ptr->splt_palettes);
  174012. info_ptr->splt_palettes=NULL;
  174013. for (i = 0; i < nentries; i++)
  174014. {
  174015. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174016. png_sPLT_tp from = entries + i;
  174017. to->name = (png_charp)png_malloc_warn(png_ptr,
  174018. png_strlen(from->name) + 1);
  174019. if (to->name == NULL)
  174020. {
  174021. png_warning(png_ptr,
  174022. "Out of memory while processing sPLT chunk");
  174023. }
  174024. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174025. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174026. from->nentries * png_sizeof(png_sPLT_entry));
  174027. png_memcpy(to->entries, from->entries,
  174028. from->nentries * png_sizeof(png_sPLT_entry));
  174029. if (to->entries == NULL)
  174030. {
  174031. png_warning(png_ptr,
  174032. "Out of memory while processing sPLT chunk");
  174033. png_free(png_ptr,to->name);
  174034. to->name = NULL;
  174035. }
  174036. to->nentries = from->nentries;
  174037. to->depth = from->depth;
  174038. }
  174039. info_ptr->splt_palettes = np;
  174040. info_ptr->splt_palettes_num += nentries;
  174041. info_ptr->valid |= PNG_INFO_sPLT;
  174042. #ifdef PNG_FREE_ME_SUPPORTED
  174043. info_ptr->free_me |= PNG_FREE_SPLT;
  174044. #endif
  174045. }
  174046. #endif /* PNG_sPLT_SUPPORTED */
  174047. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174048. void PNGAPI
  174049. png_set_unknown_chunks(png_structp png_ptr,
  174050. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174051. {
  174052. png_unknown_chunkp np;
  174053. int i;
  174054. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174055. return;
  174056. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174057. (info_ptr->unknown_chunks_num + num_unknowns) *
  174058. png_sizeof(png_unknown_chunk));
  174059. if (np == NULL)
  174060. {
  174061. png_warning(png_ptr,
  174062. "Out of memory while processing unknown chunk.");
  174063. return;
  174064. }
  174065. png_memcpy(np, info_ptr->unknown_chunks,
  174066. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174067. png_free(png_ptr, info_ptr->unknown_chunks);
  174068. info_ptr->unknown_chunks=NULL;
  174069. for (i = 0; i < num_unknowns; i++)
  174070. {
  174071. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174072. png_unknown_chunkp from = unknowns + i;
  174073. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174074. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174075. if (to->data == NULL)
  174076. {
  174077. png_warning(png_ptr,
  174078. "Out of memory while processing unknown chunk.");
  174079. }
  174080. else
  174081. {
  174082. png_memcpy(to->data, from->data, from->size);
  174083. to->size = from->size;
  174084. to->location = (png_byte)(png_ptr->mode & 0xff);
  174085. }
  174086. }
  174087. info_ptr->unknown_chunks = np;
  174088. info_ptr->unknown_chunks_num += num_unknowns;
  174089. #ifdef PNG_FREE_ME_SUPPORTED
  174090. info_ptr->free_me |= PNG_FREE_UNKN;
  174091. #endif
  174092. }
  174093. void PNGAPI
  174094. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174095. int chunk, int location)
  174096. {
  174097. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174098. (int)info_ptr->unknown_chunks_num)
  174099. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174100. }
  174101. #endif
  174102. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174103. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174104. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174105. void PNGAPI
  174106. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174107. {
  174108. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174109. if (png_ptr == NULL)
  174110. return;
  174111. png_ptr->mng_features_permitted = (png_byte)
  174112. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174113. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174114. }
  174115. #endif
  174116. #endif
  174117. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174118. png_uint_32 PNGAPI
  174119. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174120. {
  174121. png_debug(1, "in png_permit_mng_features\n");
  174122. if (png_ptr == NULL)
  174123. return (png_uint_32)0;
  174124. png_ptr->mng_features_permitted =
  174125. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174126. return (png_uint_32)png_ptr->mng_features_permitted;
  174127. }
  174128. #endif
  174129. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174130. void PNGAPI
  174131. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174132. chunk_list, int num_chunks)
  174133. {
  174134. png_bytep new_list, p;
  174135. int i, old_num_chunks;
  174136. if (png_ptr == NULL)
  174137. return;
  174138. if (num_chunks == 0)
  174139. {
  174140. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174141. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174142. else
  174143. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174144. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174145. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174146. else
  174147. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174148. return;
  174149. }
  174150. if (chunk_list == NULL)
  174151. return;
  174152. old_num_chunks=png_ptr->num_chunk_list;
  174153. new_list=(png_bytep)png_malloc(png_ptr,
  174154. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174155. if(png_ptr->chunk_list != NULL)
  174156. {
  174157. png_memcpy(new_list, png_ptr->chunk_list,
  174158. (png_size_t)(5*old_num_chunks));
  174159. png_free(png_ptr, png_ptr->chunk_list);
  174160. png_ptr->chunk_list=NULL;
  174161. }
  174162. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174163. (png_size_t)(5*num_chunks));
  174164. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174165. *p=(png_byte)keep;
  174166. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174167. png_ptr->chunk_list=new_list;
  174168. #ifdef PNG_FREE_ME_SUPPORTED
  174169. png_ptr->free_me |= PNG_FREE_LIST;
  174170. #endif
  174171. }
  174172. #endif
  174173. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174174. void PNGAPI
  174175. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174176. png_user_chunk_ptr read_user_chunk_fn)
  174177. {
  174178. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174179. if (png_ptr == NULL)
  174180. return;
  174181. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174182. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174183. }
  174184. #endif
  174185. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174186. void PNGAPI
  174187. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174188. {
  174189. png_debug1(1, "in %s storage function\n", "rows");
  174190. if (png_ptr == NULL || info_ptr == NULL)
  174191. return;
  174192. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174193. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174194. info_ptr->row_pointers = row_pointers;
  174195. if(row_pointers)
  174196. info_ptr->valid |= PNG_INFO_IDAT;
  174197. }
  174198. #endif
  174199. #ifdef PNG_WRITE_SUPPORTED
  174200. void PNGAPI
  174201. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174202. {
  174203. if (png_ptr == NULL)
  174204. return;
  174205. if(png_ptr->zbuf)
  174206. png_free(png_ptr, png_ptr->zbuf);
  174207. png_ptr->zbuf_size = (png_size_t)size;
  174208. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174209. png_ptr->zstream.next_out = png_ptr->zbuf;
  174210. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174211. }
  174212. #endif
  174213. void PNGAPI
  174214. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174215. {
  174216. if (png_ptr && info_ptr)
  174217. info_ptr->valid &= ~(mask);
  174218. }
  174219. #ifndef PNG_1_0_X
  174220. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174221. void PNGAPI
  174222. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174223. {
  174224. if (png_ptr != NULL)
  174225. png_ptr->asm_flags = 0;
  174226. }
  174227. void PNGAPI
  174228. png_set_mmx_thresholds (png_structp png_ptr,
  174229. png_byte mmx_bitdepth_threshold,
  174230. png_uint_32 mmx_rowbytes_threshold)
  174231. {
  174232. if (png_ptr == NULL)
  174233. return;
  174234. }
  174235. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174236. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174237. void PNGAPI
  174238. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174239. png_uint_32 user_height_max)
  174240. {
  174241. if(png_ptr == NULL) return;
  174242. png_ptr->user_width_max = user_width_max;
  174243. png_ptr->user_height_max = user_height_max;
  174244. }
  174245. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174246. #endif /* ?PNG_1_0_X */
  174247. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174248. /*** End of inlined file: pngset.c ***/
  174249. /*** Start of inlined file: pngtrans.c ***/
  174250. #define PNG_INTERNAL
  174251. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174252. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174253. void PNGAPI
  174254. png_set_bgr(png_structp png_ptr)
  174255. {
  174256. png_debug(1, "in png_set_bgr\n");
  174257. if(png_ptr == NULL) return;
  174258. png_ptr->transformations |= PNG_BGR;
  174259. }
  174260. #endif
  174261. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174262. void PNGAPI
  174263. png_set_swap(png_structp png_ptr)
  174264. {
  174265. png_debug(1, "in png_set_swap\n");
  174266. if(png_ptr == NULL) return;
  174267. if (png_ptr->bit_depth == 16)
  174268. png_ptr->transformations |= PNG_SWAP_BYTES;
  174269. }
  174270. #endif
  174271. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174272. void PNGAPI
  174273. png_set_packing(png_structp png_ptr)
  174274. {
  174275. png_debug(1, "in png_set_packing\n");
  174276. if(png_ptr == NULL) return;
  174277. if (png_ptr->bit_depth < 8)
  174278. {
  174279. png_ptr->transformations |= PNG_PACK;
  174280. png_ptr->usr_bit_depth = 8;
  174281. }
  174282. }
  174283. #endif
  174284. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174285. void PNGAPI
  174286. png_set_packswap(png_structp png_ptr)
  174287. {
  174288. png_debug(1, "in png_set_packswap\n");
  174289. if(png_ptr == NULL) return;
  174290. if (png_ptr->bit_depth < 8)
  174291. png_ptr->transformations |= PNG_PACKSWAP;
  174292. }
  174293. #endif
  174294. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174295. void PNGAPI
  174296. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174297. {
  174298. png_debug(1, "in png_set_shift\n");
  174299. if(png_ptr == NULL) return;
  174300. png_ptr->transformations |= PNG_SHIFT;
  174301. png_ptr->shift = *true_bits;
  174302. }
  174303. #endif
  174304. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174305. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174306. int PNGAPI
  174307. png_set_interlace_handling(png_structp png_ptr)
  174308. {
  174309. png_debug(1, "in png_set_interlace handling\n");
  174310. if (png_ptr && png_ptr->interlaced)
  174311. {
  174312. png_ptr->transformations |= PNG_INTERLACE;
  174313. return (7);
  174314. }
  174315. return (1);
  174316. }
  174317. #endif
  174318. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174319. void PNGAPI
  174320. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174321. {
  174322. png_debug(1, "in png_set_filler\n");
  174323. if(png_ptr == NULL) return;
  174324. png_ptr->transformations |= PNG_FILLER;
  174325. png_ptr->filler = (png_byte)filler;
  174326. if (filler_loc == PNG_FILLER_AFTER)
  174327. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174328. else
  174329. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174330. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174331. {
  174332. png_ptr->usr_channels = 4;
  174333. }
  174334. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174335. {
  174336. png_ptr->usr_channels = 2;
  174337. }
  174338. }
  174339. #if !defined(PNG_1_0_X)
  174340. void PNGAPI
  174341. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174342. {
  174343. png_debug(1, "in png_set_add_alpha\n");
  174344. if(png_ptr == NULL) return;
  174345. png_set_filler(png_ptr, filler, filler_loc);
  174346. png_ptr->transformations |= PNG_ADD_ALPHA;
  174347. }
  174348. #endif
  174349. #endif
  174350. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174351. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174352. void PNGAPI
  174353. png_set_swap_alpha(png_structp png_ptr)
  174354. {
  174355. png_debug(1, "in png_set_swap_alpha\n");
  174356. if(png_ptr == NULL) return;
  174357. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174358. }
  174359. #endif
  174360. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174361. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174362. void PNGAPI
  174363. png_set_invert_alpha(png_structp png_ptr)
  174364. {
  174365. png_debug(1, "in png_set_invert_alpha\n");
  174366. if(png_ptr == NULL) return;
  174367. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174368. }
  174369. #endif
  174370. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174371. void PNGAPI
  174372. png_set_invert_mono(png_structp png_ptr)
  174373. {
  174374. png_debug(1, "in png_set_invert_mono\n");
  174375. if(png_ptr == NULL) return;
  174376. png_ptr->transformations |= PNG_INVERT_MONO;
  174377. }
  174378. void /* PRIVATE */
  174379. png_do_invert(png_row_infop row_info, png_bytep row)
  174380. {
  174381. png_debug(1, "in png_do_invert\n");
  174382. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174383. if (row == NULL || row_info == NULL)
  174384. return;
  174385. #endif
  174386. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174387. {
  174388. png_bytep rp = row;
  174389. png_uint_32 i;
  174390. png_uint_32 istop = row_info->rowbytes;
  174391. for (i = 0; i < istop; i++)
  174392. {
  174393. *rp = (png_byte)(~(*rp));
  174394. rp++;
  174395. }
  174396. }
  174397. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174398. row_info->bit_depth == 8)
  174399. {
  174400. png_bytep rp = row;
  174401. png_uint_32 i;
  174402. png_uint_32 istop = row_info->rowbytes;
  174403. for (i = 0; i < istop; i+=2)
  174404. {
  174405. *rp = (png_byte)(~(*rp));
  174406. rp+=2;
  174407. }
  174408. }
  174409. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174410. row_info->bit_depth == 16)
  174411. {
  174412. png_bytep rp = row;
  174413. png_uint_32 i;
  174414. png_uint_32 istop = row_info->rowbytes;
  174415. for (i = 0; i < istop; i+=4)
  174416. {
  174417. *rp = (png_byte)(~(*rp));
  174418. *(rp+1) = (png_byte)(~(*(rp+1)));
  174419. rp+=4;
  174420. }
  174421. }
  174422. }
  174423. #endif
  174424. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174425. void /* PRIVATE */
  174426. png_do_swap(png_row_infop row_info, png_bytep row)
  174427. {
  174428. png_debug(1, "in png_do_swap\n");
  174429. if (
  174430. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174431. row != NULL && row_info != NULL &&
  174432. #endif
  174433. row_info->bit_depth == 16)
  174434. {
  174435. png_bytep rp = row;
  174436. png_uint_32 i;
  174437. png_uint_32 istop= row_info->width * row_info->channels;
  174438. for (i = 0; i < istop; i++, rp += 2)
  174439. {
  174440. png_byte t = *rp;
  174441. *rp = *(rp + 1);
  174442. *(rp + 1) = t;
  174443. }
  174444. }
  174445. }
  174446. #endif
  174447. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174448. static PNG_CONST png_byte onebppswaptable[256] = {
  174449. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174450. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174451. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174452. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174453. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174454. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174455. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174456. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174457. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174458. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174459. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174460. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174461. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174462. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174463. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174464. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174465. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174466. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174467. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174468. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174469. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174470. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174471. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174472. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174473. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174474. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174475. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174476. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174477. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174478. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174479. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174480. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174481. };
  174482. static PNG_CONST png_byte twobppswaptable[256] = {
  174483. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174484. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174485. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174486. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174487. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174488. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174489. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174490. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174491. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174492. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174493. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174494. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174495. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174496. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174497. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174498. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174499. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174500. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174501. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174502. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174503. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174504. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174505. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174506. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174507. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174508. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174509. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174510. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174511. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174512. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174513. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174514. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174515. };
  174516. static PNG_CONST png_byte fourbppswaptable[256] = {
  174517. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174518. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174519. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174520. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174521. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  174522. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  174523. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  174524. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  174525. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  174526. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  174527. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  174528. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  174529. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  174530. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  174531. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  174532. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  174533. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  174534. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  174535. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  174536. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  174537. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  174538. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  174539. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  174540. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  174541. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  174542. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  174543. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  174544. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  174545. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  174546. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  174547. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  174548. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  174549. };
  174550. void /* PRIVATE */
  174551. png_do_packswap(png_row_infop row_info, png_bytep row)
  174552. {
  174553. png_debug(1, "in png_do_packswap\n");
  174554. if (
  174555. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174556. row != NULL && row_info != NULL &&
  174557. #endif
  174558. row_info->bit_depth < 8)
  174559. {
  174560. png_bytep rp, end, table;
  174561. end = row + row_info->rowbytes;
  174562. if (row_info->bit_depth == 1)
  174563. table = (png_bytep)onebppswaptable;
  174564. else if (row_info->bit_depth == 2)
  174565. table = (png_bytep)twobppswaptable;
  174566. else if (row_info->bit_depth == 4)
  174567. table = (png_bytep)fourbppswaptable;
  174568. else
  174569. return;
  174570. for (rp = row; rp < end; rp++)
  174571. *rp = table[*rp];
  174572. }
  174573. }
  174574. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  174575. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  174576. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  174577. void /* PRIVATE */
  174578. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  174579. {
  174580. png_debug(1, "in png_do_strip_filler\n");
  174581. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174582. if (row != NULL && row_info != NULL)
  174583. #endif
  174584. {
  174585. png_bytep sp=row;
  174586. png_bytep dp=row;
  174587. png_uint_32 row_width=row_info->width;
  174588. png_uint_32 i;
  174589. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  174590. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  174591. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174592. row_info->channels == 4)
  174593. {
  174594. if (row_info->bit_depth == 8)
  174595. {
  174596. if (flags & PNG_FLAG_FILLER_AFTER)
  174597. {
  174598. dp+=3; sp+=4;
  174599. for (i = 1; i < row_width; i++)
  174600. {
  174601. *dp++ = *sp++;
  174602. *dp++ = *sp++;
  174603. *dp++ = *sp++;
  174604. sp++;
  174605. }
  174606. }
  174607. else
  174608. {
  174609. for (i = 0; i < row_width; i++)
  174610. {
  174611. sp++;
  174612. *dp++ = *sp++;
  174613. *dp++ = *sp++;
  174614. *dp++ = *sp++;
  174615. }
  174616. }
  174617. row_info->pixel_depth = 24;
  174618. row_info->rowbytes = row_width * 3;
  174619. }
  174620. else /* if (row_info->bit_depth == 16) */
  174621. {
  174622. if (flags & PNG_FLAG_FILLER_AFTER)
  174623. {
  174624. sp += 8; dp += 6;
  174625. for (i = 1; i < row_width; i++)
  174626. {
  174627. *dp++ = *sp++;
  174628. *dp++ = *sp++;
  174629. *dp++ = *sp++;
  174630. *dp++ = *sp++;
  174631. *dp++ = *sp++;
  174632. *dp++ = *sp++;
  174633. sp += 2;
  174634. }
  174635. }
  174636. else
  174637. {
  174638. for (i = 0; i < row_width; i++)
  174639. {
  174640. sp+=2;
  174641. *dp++ = *sp++;
  174642. *dp++ = *sp++;
  174643. *dp++ = *sp++;
  174644. *dp++ = *sp++;
  174645. *dp++ = *sp++;
  174646. *dp++ = *sp++;
  174647. }
  174648. }
  174649. row_info->pixel_depth = 48;
  174650. row_info->rowbytes = row_width * 6;
  174651. }
  174652. row_info->channels = 3;
  174653. }
  174654. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  174655. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174656. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  174657. row_info->channels == 2)
  174658. {
  174659. if (row_info->bit_depth == 8)
  174660. {
  174661. if (flags & PNG_FLAG_FILLER_AFTER)
  174662. {
  174663. for (i = 0; i < row_width; i++)
  174664. {
  174665. *dp++ = *sp++;
  174666. sp++;
  174667. }
  174668. }
  174669. else
  174670. {
  174671. for (i = 0; i < row_width; i++)
  174672. {
  174673. sp++;
  174674. *dp++ = *sp++;
  174675. }
  174676. }
  174677. row_info->pixel_depth = 8;
  174678. row_info->rowbytes = row_width;
  174679. }
  174680. else /* if (row_info->bit_depth == 16) */
  174681. {
  174682. if (flags & PNG_FLAG_FILLER_AFTER)
  174683. {
  174684. sp += 4; dp += 2;
  174685. for (i = 1; i < row_width; i++)
  174686. {
  174687. *dp++ = *sp++;
  174688. *dp++ = *sp++;
  174689. sp += 2;
  174690. }
  174691. }
  174692. else
  174693. {
  174694. for (i = 0; i < row_width; i++)
  174695. {
  174696. sp += 2;
  174697. *dp++ = *sp++;
  174698. *dp++ = *sp++;
  174699. }
  174700. }
  174701. row_info->pixel_depth = 16;
  174702. row_info->rowbytes = row_width * 2;
  174703. }
  174704. row_info->channels = 1;
  174705. }
  174706. if (flags & PNG_FLAG_STRIP_ALPHA)
  174707. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  174708. }
  174709. }
  174710. #endif
  174711. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174712. void /* PRIVATE */
  174713. png_do_bgr(png_row_infop row_info, png_bytep row)
  174714. {
  174715. png_debug(1, "in png_do_bgr\n");
  174716. if (
  174717. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174718. row != NULL && row_info != NULL &&
  174719. #endif
  174720. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  174721. {
  174722. png_uint_32 row_width = row_info->width;
  174723. if (row_info->bit_depth == 8)
  174724. {
  174725. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174726. {
  174727. png_bytep rp;
  174728. png_uint_32 i;
  174729. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  174730. {
  174731. png_byte save = *rp;
  174732. *rp = *(rp + 2);
  174733. *(rp + 2) = save;
  174734. }
  174735. }
  174736. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174737. {
  174738. png_bytep rp;
  174739. png_uint_32 i;
  174740. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  174741. {
  174742. png_byte save = *rp;
  174743. *rp = *(rp + 2);
  174744. *(rp + 2) = save;
  174745. }
  174746. }
  174747. }
  174748. else if (row_info->bit_depth == 16)
  174749. {
  174750. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  174751. {
  174752. png_bytep rp;
  174753. png_uint_32 i;
  174754. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  174755. {
  174756. png_byte save = *rp;
  174757. *rp = *(rp + 4);
  174758. *(rp + 4) = save;
  174759. save = *(rp + 1);
  174760. *(rp + 1) = *(rp + 5);
  174761. *(rp + 5) = save;
  174762. }
  174763. }
  174764. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  174765. {
  174766. png_bytep rp;
  174767. png_uint_32 i;
  174768. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  174769. {
  174770. png_byte save = *rp;
  174771. *rp = *(rp + 4);
  174772. *(rp + 4) = save;
  174773. save = *(rp + 1);
  174774. *(rp + 1) = *(rp + 5);
  174775. *(rp + 5) = save;
  174776. }
  174777. }
  174778. }
  174779. }
  174780. }
  174781. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  174782. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  174783. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  174784. defined(PNG_LEGACY_SUPPORTED)
  174785. void PNGAPI
  174786. png_set_user_transform_info(png_structp png_ptr, png_voidp
  174787. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  174788. {
  174789. png_debug(1, "in png_set_user_transform_info\n");
  174790. if(png_ptr == NULL) return;
  174791. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174792. png_ptr->user_transform_ptr = user_transform_ptr;
  174793. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  174794. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  174795. #else
  174796. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  174797. png_warning(png_ptr,
  174798. "This version of libpng does not support user transform info");
  174799. #endif
  174800. }
  174801. #endif
  174802. png_voidp PNGAPI
  174803. png_get_user_transform_ptr(png_structp png_ptr)
  174804. {
  174805. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  174806. if (png_ptr == NULL) return (NULL);
  174807. return ((png_voidp)png_ptr->user_transform_ptr);
  174808. #else
  174809. return (NULL);
  174810. #endif
  174811. }
  174812. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174813. /*** End of inlined file: pngtrans.c ***/
  174814. /*** Start of inlined file: pngwio.c ***/
  174815. #define PNG_INTERNAL
  174816. #ifdef PNG_WRITE_SUPPORTED
  174817. void /* PRIVATE */
  174818. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174819. {
  174820. if (png_ptr->write_data_fn != NULL )
  174821. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  174822. else
  174823. png_error(png_ptr, "Call to NULL write function");
  174824. }
  174825. #if !defined(PNG_NO_STDIO)
  174826. #ifndef USE_FAR_KEYWORD
  174827. void PNGAPI
  174828. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174829. {
  174830. png_uint_32 check;
  174831. if(png_ptr == NULL) return;
  174832. #if defined(_WIN32_WCE)
  174833. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  174834. check = 0;
  174835. #else
  174836. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  174837. #endif
  174838. if (check != length)
  174839. png_error(png_ptr, "Write Error");
  174840. }
  174841. #else
  174842. #define NEAR_BUF_SIZE 1024
  174843. #define MIN(a,b) (a <= b ? a : b)
  174844. void PNGAPI
  174845. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  174846. {
  174847. png_uint_32 check;
  174848. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  174849. png_FILE_p io_ptr;
  174850. if(png_ptr == NULL) return;
  174851. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  174852. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  174853. if ((png_bytep)near_data == data)
  174854. {
  174855. #if defined(_WIN32_WCE)
  174856. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  174857. check = 0;
  174858. #else
  174859. check = fwrite(near_data, 1, length, io_ptr);
  174860. #endif
  174861. }
  174862. else
  174863. {
  174864. png_byte buf[NEAR_BUF_SIZE];
  174865. png_size_t written, remaining, err;
  174866. check = 0;
  174867. remaining = length;
  174868. do
  174869. {
  174870. written = MIN(NEAR_BUF_SIZE, remaining);
  174871. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  174872. #if defined(_WIN32_WCE)
  174873. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  174874. err = 0;
  174875. #else
  174876. err = fwrite(buf, 1, written, io_ptr);
  174877. #endif
  174878. if (err != written)
  174879. break;
  174880. else
  174881. check += err;
  174882. data += written;
  174883. remaining -= written;
  174884. }
  174885. while (remaining != 0);
  174886. }
  174887. if (check != length)
  174888. png_error(png_ptr, "Write Error");
  174889. }
  174890. #endif
  174891. #endif
  174892. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174893. void /* PRIVATE */
  174894. png_flush(png_structp png_ptr)
  174895. {
  174896. if (png_ptr->output_flush_fn != NULL)
  174897. (*(png_ptr->output_flush_fn))(png_ptr);
  174898. }
  174899. #if !defined(PNG_NO_STDIO)
  174900. void PNGAPI
  174901. png_default_flush(png_structp png_ptr)
  174902. {
  174903. #if !defined(_WIN32_WCE)
  174904. png_FILE_p io_ptr;
  174905. #endif
  174906. if(png_ptr == NULL) return;
  174907. #if !defined(_WIN32_WCE)
  174908. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  174909. if (io_ptr != NULL)
  174910. fflush(io_ptr);
  174911. #endif
  174912. }
  174913. #endif
  174914. #endif
  174915. void PNGAPI
  174916. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  174917. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  174918. {
  174919. if(png_ptr == NULL) return;
  174920. png_ptr->io_ptr = io_ptr;
  174921. #if !defined(PNG_NO_STDIO)
  174922. if (write_data_fn != NULL)
  174923. png_ptr->write_data_fn = write_data_fn;
  174924. else
  174925. png_ptr->write_data_fn = png_default_write_data;
  174926. #else
  174927. png_ptr->write_data_fn = write_data_fn;
  174928. #endif
  174929. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  174930. #if !defined(PNG_NO_STDIO)
  174931. if (output_flush_fn != NULL)
  174932. png_ptr->output_flush_fn = output_flush_fn;
  174933. else
  174934. png_ptr->output_flush_fn = png_default_flush;
  174935. #else
  174936. png_ptr->output_flush_fn = output_flush_fn;
  174937. #endif
  174938. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  174939. if (png_ptr->read_data_fn != NULL)
  174940. {
  174941. png_ptr->read_data_fn = NULL;
  174942. png_warning(png_ptr,
  174943. "Attempted to set both read_data_fn and write_data_fn in");
  174944. png_warning(png_ptr,
  174945. "the same structure. Resetting read_data_fn to NULL.");
  174946. }
  174947. }
  174948. #if defined(USE_FAR_KEYWORD)
  174949. #if defined(_MSC_VER)
  174950. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  174951. {
  174952. void *near_ptr;
  174953. void FAR *far_ptr;
  174954. FP_OFF(near_ptr) = FP_OFF(ptr);
  174955. far_ptr = (void FAR *)near_ptr;
  174956. if(check != 0)
  174957. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  174958. png_error(png_ptr,"segment lost in conversion");
  174959. return(near_ptr);
  174960. }
  174961. # else
  174962. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  174963. {
  174964. void *near_ptr;
  174965. void FAR *far_ptr;
  174966. near_ptr = (void FAR *)ptr;
  174967. far_ptr = (void FAR *)near_ptr;
  174968. if(check != 0)
  174969. if(far_ptr != ptr)
  174970. png_error(png_ptr,"segment lost in conversion");
  174971. return(near_ptr);
  174972. }
  174973. # endif
  174974. # endif
  174975. #endif /* PNG_WRITE_SUPPORTED */
  174976. /*** End of inlined file: pngwio.c ***/
  174977. /*** Start of inlined file: pngwrite.c ***/
  174978. #define PNG_INTERNAL
  174979. #ifdef PNG_WRITE_SUPPORTED
  174980. void PNGAPI
  174981. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  174982. {
  174983. png_debug(1, "in png_write_info_before_PLTE\n");
  174984. if (png_ptr == NULL || info_ptr == NULL)
  174985. return;
  174986. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  174987. {
  174988. png_write_sig(png_ptr); /* write PNG signature */
  174989. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174990. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  174991. {
  174992. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  174993. png_ptr->mng_features_permitted=0;
  174994. }
  174995. #endif
  174996. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  174997. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  174998. info_ptr->filter_type,
  174999. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175000. info_ptr->interlace_type);
  175001. #else
  175002. 0);
  175003. #endif
  175004. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175005. if (info_ptr->valid & PNG_INFO_gAMA)
  175006. {
  175007. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175008. png_write_gAMA(png_ptr, info_ptr->gamma);
  175009. #else
  175010. #ifdef PNG_FIXED_POINT_SUPPORTED
  175011. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175012. # endif
  175013. #endif
  175014. }
  175015. #endif
  175016. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175017. if (info_ptr->valid & PNG_INFO_sRGB)
  175018. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175019. #endif
  175020. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175021. if (info_ptr->valid & PNG_INFO_iCCP)
  175022. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175023. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175024. #endif
  175025. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175026. if (info_ptr->valid & PNG_INFO_sBIT)
  175027. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175028. #endif
  175029. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175030. if (info_ptr->valid & PNG_INFO_cHRM)
  175031. {
  175032. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175033. png_write_cHRM(png_ptr,
  175034. info_ptr->x_white, info_ptr->y_white,
  175035. info_ptr->x_red, info_ptr->y_red,
  175036. info_ptr->x_green, info_ptr->y_green,
  175037. info_ptr->x_blue, info_ptr->y_blue);
  175038. #else
  175039. # ifdef PNG_FIXED_POINT_SUPPORTED
  175040. png_write_cHRM_fixed(png_ptr,
  175041. info_ptr->int_x_white, info_ptr->int_y_white,
  175042. info_ptr->int_x_red, info_ptr->int_y_red,
  175043. info_ptr->int_x_green, info_ptr->int_y_green,
  175044. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175045. # endif
  175046. #endif
  175047. }
  175048. #endif
  175049. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175050. if (info_ptr->unknown_chunks_num)
  175051. {
  175052. png_unknown_chunk *up;
  175053. png_debug(5, "writing extra chunks\n");
  175054. for (up = info_ptr->unknown_chunks;
  175055. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175056. up++)
  175057. {
  175058. int keep=png_handle_as_unknown(png_ptr, up->name);
  175059. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175060. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175061. !(up->location & PNG_HAVE_IDAT) &&
  175062. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175063. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175064. {
  175065. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175066. }
  175067. }
  175068. }
  175069. #endif
  175070. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175071. }
  175072. }
  175073. void PNGAPI
  175074. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175075. {
  175076. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175077. int i;
  175078. #endif
  175079. png_debug(1, "in png_write_info\n");
  175080. if (png_ptr == NULL || info_ptr == NULL)
  175081. return;
  175082. png_write_info_before_PLTE(png_ptr, info_ptr);
  175083. if (info_ptr->valid & PNG_INFO_PLTE)
  175084. png_write_PLTE(png_ptr, info_ptr->palette,
  175085. (png_uint_32)info_ptr->num_palette);
  175086. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175087. png_error(png_ptr, "Valid palette required for paletted images");
  175088. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175089. if (info_ptr->valid & PNG_INFO_tRNS)
  175090. {
  175091. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175092. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175093. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175094. {
  175095. int j;
  175096. for (j=0; j<(int)info_ptr->num_trans; j++)
  175097. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175098. }
  175099. #endif
  175100. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175101. info_ptr->num_trans, info_ptr->color_type);
  175102. }
  175103. #endif
  175104. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175105. if (info_ptr->valid & PNG_INFO_bKGD)
  175106. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175107. #endif
  175108. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175109. if (info_ptr->valid & PNG_INFO_hIST)
  175110. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175111. #endif
  175112. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175113. if (info_ptr->valid & PNG_INFO_oFFs)
  175114. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175115. info_ptr->offset_unit_type);
  175116. #endif
  175117. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175118. if (info_ptr->valid & PNG_INFO_pCAL)
  175119. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175120. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175121. info_ptr->pcal_units, info_ptr->pcal_params);
  175122. #endif
  175123. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175124. if (info_ptr->valid & PNG_INFO_sCAL)
  175125. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175126. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175127. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175128. #else
  175129. #ifdef PNG_FIXED_POINT_SUPPORTED
  175130. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175131. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175132. #else
  175133. png_warning(png_ptr,
  175134. "png_write_sCAL not supported; sCAL chunk not written.");
  175135. #endif
  175136. #endif
  175137. #endif
  175138. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175139. if (info_ptr->valid & PNG_INFO_pHYs)
  175140. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175141. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175142. #endif
  175143. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175144. if (info_ptr->valid & PNG_INFO_tIME)
  175145. {
  175146. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175147. png_ptr->mode |= PNG_WROTE_tIME;
  175148. }
  175149. #endif
  175150. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175151. if (info_ptr->valid & PNG_INFO_sPLT)
  175152. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175153. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175154. #endif
  175155. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175156. for (i = 0; i < info_ptr->num_text; i++)
  175157. {
  175158. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175159. info_ptr->text[i].compression);
  175160. if (info_ptr->text[i].compression > 0)
  175161. {
  175162. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175163. png_write_iTXt(png_ptr,
  175164. info_ptr->text[i].compression,
  175165. info_ptr->text[i].key,
  175166. info_ptr->text[i].lang,
  175167. info_ptr->text[i].lang_key,
  175168. info_ptr->text[i].text);
  175169. #else
  175170. png_warning(png_ptr, "Unable to write international text");
  175171. #endif
  175172. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175173. }
  175174. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175175. {
  175176. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175177. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175178. info_ptr->text[i].text, 0,
  175179. info_ptr->text[i].compression);
  175180. #else
  175181. png_warning(png_ptr, "Unable to write compressed text");
  175182. #endif
  175183. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175184. }
  175185. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175186. {
  175187. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175188. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175189. info_ptr->text[i].text,
  175190. 0);
  175191. #else
  175192. png_warning(png_ptr, "Unable to write uncompressed text");
  175193. #endif
  175194. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175195. }
  175196. }
  175197. #endif
  175198. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175199. if (info_ptr->unknown_chunks_num)
  175200. {
  175201. png_unknown_chunk *up;
  175202. png_debug(5, "writing extra chunks\n");
  175203. for (up = info_ptr->unknown_chunks;
  175204. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175205. up++)
  175206. {
  175207. int keep=png_handle_as_unknown(png_ptr, up->name);
  175208. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175209. up->location && (up->location & PNG_HAVE_PLTE) &&
  175210. !(up->location & PNG_HAVE_IDAT) &&
  175211. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175212. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175213. {
  175214. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175215. }
  175216. }
  175217. }
  175218. #endif
  175219. }
  175220. void PNGAPI
  175221. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175222. {
  175223. png_debug(1, "in png_write_end\n");
  175224. if (png_ptr == NULL)
  175225. return;
  175226. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175227. png_error(png_ptr, "No IDATs written into file");
  175228. if (info_ptr != NULL)
  175229. {
  175230. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175231. int i; /* local index variable */
  175232. #endif
  175233. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175234. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175235. !(png_ptr->mode & PNG_WROTE_tIME))
  175236. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175237. #endif
  175238. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175239. for (i = 0; i < info_ptr->num_text; i++)
  175240. {
  175241. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175242. info_ptr->text[i].compression);
  175243. if (info_ptr->text[i].compression > 0)
  175244. {
  175245. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175246. png_write_iTXt(png_ptr,
  175247. info_ptr->text[i].compression,
  175248. info_ptr->text[i].key,
  175249. info_ptr->text[i].lang,
  175250. info_ptr->text[i].lang_key,
  175251. info_ptr->text[i].text);
  175252. #else
  175253. png_warning(png_ptr, "Unable to write international text");
  175254. #endif
  175255. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175256. }
  175257. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175258. {
  175259. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175260. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175261. info_ptr->text[i].text, 0,
  175262. info_ptr->text[i].compression);
  175263. #else
  175264. png_warning(png_ptr, "Unable to write compressed text");
  175265. #endif
  175266. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175267. }
  175268. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175269. {
  175270. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175271. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175272. info_ptr->text[i].text, 0);
  175273. #else
  175274. png_warning(png_ptr, "Unable to write uncompressed text");
  175275. #endif
  175276. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175277. }
  175278. }
  175279. #endif
  175280. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175281. if (info_ptr->unknown_chunks_num)
  175282. {
  175283. png_unknown_chunk *up;
  175284. png_debug(5, "writing extra chunks\n");
  175285. for (up = info_ptr->unknown_chunks;
  175286. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175287. up++)
  175288. {
  175289. int keep=png_handle_as_unknown(png_ptr, up->name);
  175290. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175291. up->location && (up->location & PNG_AFTER_IDAT) &&
  175292. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175293. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175294. {
  175295. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175296. }
  175297. }
  175298. }
  175299. #endif
  175300. }
  175301. png_ptr->mode |= PNG_AFTER_IDAT;
  175302. png_write_IEND(png_ptr);
  175303. }
  175304. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175305. #if !defined(_WIN32_WCE)
  175306. void PNGAPI
  175307. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175308. {
  175309. png_debug(1, "in png_convert_from_struct_tm\n");
  175310. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175311. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175312. ptime->day = (png_byte)ttime->tm_mday;
  175313. ptime->hour = (png_byte)ttime->tm_hour;
  175314. ptime->minute = (png_byte)ttime->tm_min;
  175315. ptime->second = (png_byte)ttime->tm_sec;
  175316. }
  175317. void PNGAPI
  175318. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175319. {
  175320. struct tm *tbuf;
  175321. png_debug(1, "in png_convert_from_time_t\n");
  175322. tbuf = gmtime(&ttime);
  175323. png_convert_from_struct_tm(ptime, tbuf);
  175324. }
  175325. #endif
  175326. #endif
  175327. png_structp PNGAPI
  175328. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175329. png_error_ptr error_fn, png_error_ptr warn_fn)
  175330. {
  175331. #ifdef PNG_USER_MEM_SUPPORTED
  175332. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175333. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175334. }
  175335. png_structp PNGAPI
  175336. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175337. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175338. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175339. {
  175340. #endif /* PNG_USER_MEM_SUPPORTED */
  175341. png_structp png_ptr;
  175342. #ifdef PNG_SETJMP_SUPPORTED
  175343. #ifdef USE_FAR_KEYWORD
  175344. jmp_buf jmpbuf;
  175345. #endif
  175346. #endif
  175347. int i;
  175348. png_debug(1, "in png_create_write_struct\n");
  175349. #ifdef PNG_USER_MEM_SUPPORTED
  175350. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175351. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175352. #else
  175353. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175354. #endif /* PNG_USER_MEM_SUPPORTED */
  175355. if (png_ptr == NULL)
  175356. return (NULL);
  175357. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175358. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175359. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175360. #endif
  175361. #ifdef PNG_SETJMP_SUPPORTED
  175362. #ifdef USE_FAR_KEYWORD
  175363. if (setjmp(jmpbuf))
  175364. #else
  175365. if (setjmp(png_ptr->jmpbuf))
  175366. #endif
  175367. {
  175368. png_free(png_ptr, png_ptr->zbuf);
  175369. png_ptr->zbuf=NULL;
  175370. png_destroy_struct(png_ptr);
  175371. return (NULL);
  175372. }
  175373. #ifdef USE_FAR_KEYWORD
  175374. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175375. #endif
  175376. #endif
  175377. #ifdef PNG_USER_MEM_SUPPORTED
  175378. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175379. #endif /* PNG_USER_MEM_SUPPORTED */
  175380. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175381. i=0;
  175382. do
  175383. {
  175384. if(user_png_ver[i] != png_libpng_ver[i])
  175385. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175386. } while (png_libpng_ver[i++]);
  175387. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175388. {
  175389. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175390. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175391. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175392. {
  175393. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175394. char msg[80];
  175395. if (user_png_ver)
  175396. {
  175397. png_snprintf(msg, 80,
  175398. "Application was compiled with png.h from libpng-%.20s",
  175399. user_png_ver);
  175400. png_warning(png_ptr, msg);
  175401. }
  175402. png_snprintf(msg, 80,
  175403. "Application is running with png.c from libpng-%.20s",
  175404. png_libpng_ver);
  175405. png_warning(png_ptr, msg);
  175406. #endif
  175407. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175408. png_ptr->flags=0;
  175409. #endif
  175410. png_error(png_ptr,
  175411. "Incompatible libpng version in application and library");
  175412. }
  175413. }
  175414. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175415. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175416. (png_uint_32)png_ptr->zbuf_size);
  175417. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175418. png_flush_ptr_NULL);
  175419. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175420. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175421. 1, png_doublep_NULL, png_doublep_NULL);
  175422. #endif
  175423. #ifdef PNG_SETJMP_SUPPORTED
  175424. #ifdef USE_FAR_KEYWORD
  175425. if (setjmp(jmpbuf))
  175426. PNG_ABORT();
  175427. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175428. #else
  175429. if (setjmp(png_ptr->jmpbuf))
  175430. PNG_ABORT();
  175431. #endif
  175432. #endif
  175433. return (png_ptr);
  175434. }
  175435. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175436. #undef png_write_init
  175437. void PNGAPI
  175438. png_write_init(png_structp png_ptr)
  175439. {
  175440. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175441. }
  175442. void PNGAPI
  175443. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175444. png_size_t png_struct_size, png_size_t png_info_size)
  175445. {
  175446. if(png_ptr == NULL) return;
  175447. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175448. if(png_sizeof(png_struct) > png_struct_size ||
  175449. png_sizeof(png_info) > png_info_size)
  175450. {
  175451. char msg[80];
  175452. png_ptr->warning_fn=NULL;
  175453. if (user_png_ver)
  175454. {
  175455. png_snprintf(msg, 80,
  175456. "Application was compiled with png.h from libpng-%.20s",
  175457. user_png_ver);
  175458. png_warning(png_ptr, msg);
  175459. }
  175460. png_snprintf(msg, 80,
  175461. "Application is running with png.c from libpng-%.20s",
  175462. png_libpng_ver);
  175463. png_warning(png_ptr, msg);
  175464. }
  175465. #endif
  175466. if(png_sizeof(png_struct) > png_struct_size)
  175467. {
  175468. png_ptr->error_fn=NULL;
  175469. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175470. png_ptr->flags=0;
  175471. #endif
  175472. png_error(png_ptr,
  175473. "The png struct allocated by the application for writing is too small.");
  175474. }
  175475. if(png_sizeof(png_info) > png_info_size)
  175476. {
  175477. png_ptr->error_fn=NULL;
  175478. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175479. png_ptr->flags=0;
  175480. #endif
  175481. png_error(png_ptr,
  175482. "The info struct allocated by the application for writing is too small.");
  175483. }
  175484. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175485. }
  175486. #endif /* PNG_1_0_X || PNG_1_2_X */
  175487. void PNGAPI
  175488. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175489. png_size_t png_struct_size)
  175490. {
  175491. png_structp png_ptr=*ptr_ptr;
  175492. #ifdef PNG_SETJMP_SUPPORTED
  175493. jmp_buf tmp_jmp; /* to save current jump buffer */
  175494. #endif
  175495. int i = 0;
  175496. if (png_ptr == NULL)
  175497. return;
  175498. do
  175499. {
  175500. if (user_png_ver[i] != png_libpng_ver[i])
  175501. {
  175502. #ifdef PNG_LEGACY_SUPPORTED
  175503. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175504. #else
  175505. png_ptr->warning_fn=NULL;
  175506. png_warning(png_ptr,
  175507. "Application uses deprecated png_write_init() and should be recompiled.");
  175508. break;
  175509. #endif
  175510. }
  175511. } while (png_libpng_ver[i++]);
  175512. png_debug(1, "in png_write_init_3\n");
  175513. #ifdef PNG_SETJMP_SUPPORTED
  175514. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175515. #endif
  175516. if (png_sizeof(png_struct) > png_struct_size)
  175517. {
  175518. png_destroy_struct(png_ptr);
  175519. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175520. *ptr_ptr = png_ptr;
  175521. }
  175522. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175523. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175524. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175525. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175526. #endif
  175527. #ifdef PNG_SETJMP_SUPPORTED
  175528. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175529. #endif
  175530. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175531. png_flush_ptr_NULL);
  175532. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175533. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175534. (png_uint_32)png_ptr->zbuf_size);
  175535. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175536. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175537. 1, png_doublep_NULL, png_doublep_NULL);
  175538. #endif
  175539. }
  175540. void PNGAPI
  175541. png_write_rows(png_structp png_ptr, png_bytepp row,
  175542. png_uint_32 num_rows)
  175543. {
  175544. png_uint_32 i; /* row counter */
  175545. png_bytepp rp; /* row pointer */
  175546. png_debug(1, "in png_write_rows\n");
  175547. if (png_ptr == NULL)
  175548. return;
  175549. for (i = 0, rp = row; i < num_rows; i++, rp++)
  175550. {
  175551. png_write_row(png_ptr, *rp);
  175552. }
  175553. }
  175554. void PNGAPI
  175555. png_write_image(png_structp png_ptr, png_bytepp image)
  175556. {
  175557. png_uint_32 i; /* row index */
  175558. int pass, num_pass; /* pass variables */
  175559. png_bytepp rp; /* points to current row */
  175560. if (png_ptr == NULL)
  175561. return;
  175562. png_debug(1, "in png_write_image\n");
  175563. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175564. num_pass = png_set_interlace_handling(png_ptr);
  175565. #else
  175566. num_pass = 1;
  175567. #endif
  175568. for (pass = 0; pass < num_pass; pass++)
  175569. {
  175570. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  175571. {
  175572. png_write_row(png_ptr, *rp);
  175573. }
  175574. }
  175575. }
  175576. void PNGAPI
  175577. png_write_row(png_structp png_ptr, png_bytep row)
  175578. {
  175579. if (png_ptr == NULL)
  175580. return;
  175581. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  175582. png_ptr->row_number, png_ptr->pass);
  175583. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  175584. {
  175585. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175586. png_error(png_ptr,
  175587. "png_write_info was never called before png_write_row.");
  175588. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  175589. if (png_ptr->transformations & PNG_INVERT_MONO)
  175590. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  175591. #endif
  175592. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  175593. if (png_ptr->transformations & PNG_FILLER)
  175594. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  175595. #endif
  175596. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  175597. if (png_ptr->transformations & PNG_PACKSWAP)
  175598. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  175599. #endif
  175600. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  175601. if (png_ptr->transformations & PNG_PACK)
  175602. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  175603. #endif
  175604. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  175605. if (png_ptr->transformations & PNG_SHIFT)
  175606. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  175607. #endif
  175608. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  175609. if (png_ptr->transformations & PNG_BGR)
  175610. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  175611. #endif
  175612. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  175613. if (png_ptr->transformations & PNG_SWAP_BYTES)
  175614. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  175615. #endif
  175616. png_write_start_row(png_ptr);
  175617. }
  175618. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175619. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  175620. {
  175621. switch (png_ptr->pass)
  175622. {
  175623. case 0:
  175624. if (png_ptr->row_number & 0x07)
  175625. {
  175626. png_write_finish_row(png_ptr);
  175627. return;
  175628. }
  175629. break;
  175630. case 1:
  175631. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  175632. {
  175633. png_write_finish_row(png_ptr);
  175634. return;
  175635. }
  175636. break;
  175637. case 2:
  175638. if ((png_ptr->row_number & 0x07) != 4)
  175639. {
  175640. png_write_finish_row(png_ptr);
  175641. return;
  175642. }
  175643. break;
  175644. case 3:
  175645. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  175646. {
  175647. png_write_finish_row(png_ptr);
  175648. return;
  175649. }
  175650. break;
  175651. case 4:
  175652. if ((png_ptr->row_number & 0x03) != 2)
  175653. {
  175654. png_write_finish_row(png_ptr);
  175655. return;
  175656. }
  175657. break;
  175658. case 5:
  175659. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  175660. {
  175661. png_write_finish_row(png_ptr);
  175662. return;
  175663. }
  175664. break;
  175665. case 6:
  175666. if (!(png_ptr->row_number & 0x01))
  175667. {
  175668. png_write_finish_row(png_ptr);
  175669. return;
  175670. }
  175671. break;
  175672. }
  175673. }
  175674. #endif
  175675. png_ptr->row_info.color_type = png_ptr->color_type;
  175676. png_ptr->row_info.width = png_ptr->usr_width;
  175677. png_ptr->row_info.channels = png_ptr->usr_channels;
  175678. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  175679. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  175680. png_ptr->row_info.channels);
  175681. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  175682. png_ptr->row_info.width);
  175683. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  175684. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  175685. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  175686. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  175687. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  175688. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  175689. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  175690. png_ptr->row_info.rowbytes);
  175691. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175692. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  175693. (png_ptr->transformations & PNG_INTERLACE))
  175694. {
  175695. png_do_write_interlace(&(png_ptr->row_info),
  175696. png_ptr->row_buf + 1, png_ptr->pass);
  175697. if (!(png_ptr->row_info.width))
  175698. {
  175699. png_write_finish_row(png_ptr);
  175700. return;
  175701. }
  175702. }
  175703. #endif
  175704. if (png_ptr->transformations)
  175705. png_do_write_transformations(png_ptr);
  175706. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175707. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175708. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  175709. {
  175710. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  175711. }
  175712. #endif
  175713. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  175714. if (png_ptr->write_row_fn != NULL)
  175715. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  175716. }
  175717. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175718. void PNGAPI
  175719. png_set_flush(png_structp png_ptr, int nrows)
  175720. {
  175721. png_debug(1, "in png_set_flush\n");
  175722. if (png_ptr == NULL)
  175723. return;
  175724. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  175725. }
  175726. void PNGAPI
  175727. png_write_flush(png_structp png_ptr)
  175728. {
  175729. int wrote_IDAT;
  175730. png_debug(1, "in png_write_flush\n");
  175731. if (png_ptr == NULL)
  175732. return;
  175733. if (png_ptr->row_number >= png_ptr->num_rows)
  175734. return;
  175735. do
  175736. {
  175737. int ret;
  175738. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  175739. wrote_IDAT = 0;
  175740. if (ret != Z_OK)
  175741. {
  175742. if (png_ptr->zstream.msg != NULL)
  175743. png_error(png_ptr, png_ptr->zstream.msg);
  175744. else
  175745. png_error(png_ptr, "zlib error");
  175746. }
  175747. if (!(png_ptr->zstream.avail_out))
  175748. {
  175749. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175750. png_ptr->zbuf_size);
  175751. png_ptr->zstream.next_out = png_ptr->zbuf;
  175752. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175753. wrote_IDAT = 1;
  175754. }
  175755. } while(wrote_IDAT == 1);
  175756. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  175757. {
  175758. png_write_IDAT(png_ptr, png_ptr->zbuf,
  175759. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  175760. png_ptr->zstream.next_out = png_ptr->zbuf;
  175761. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  175762. }
  175763. png_ptr->flush_rows = 0;
  175764. png_flush(png_ptr);
  175765. }
  175766. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175767. void PNGAPI
  175768. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  175769. {
  175770. png_structp png_ptr = NULL;
  175771. png_infop info_ptr = NULL;
  175772. #ifdef PNG_USER_MEM_SUPPORTED
  175773. png_free_ptr free_fn = NULL;
  175774. png_voidp mem_ptr = NULL;
  175775. #endif
  175776. png_debug(1, "in png_destroy_write_struct\n");
  175777. if (png_ptr_ptr != NULL)
  175778. {
  175779. png_ptr = *png_ptr_ptr;
  175780. #ifdef PNG_USER_MEM_SUPPORTED
  175781. free_fn = png_ptr->free_fn;
  175782. mem_ptr = png_ptr->mem_ptr;
  175783. #endif
  175784. }
  175785. if (info_ptr_ptr != NULL)
  175786. info_ptr = *info_ptr_ptr;
  175787. if (info_ptr != NULL)
  175788. {
  175789. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  175790. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  175791. if (png_ptr->num_chunk_list)
  175792. {
  175793. png_free(png_ptr, png_ptr->chunk_list);
  175794. png_ptr->chunk_list=NULL;
  175795. png_ptr->num_chunk_list=0;
  175796. }
  175797. #endif
  175798. #ifdef PNG_USER_MEM_SUPPORTED
  175799. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  175800. (png_voidp)mem_ptr);
  175801. #else
  175802. png_destroy_struct((png_voidp)info_ptr);
  175803. #endif
  175804. *info_ptr_ptr = NULL;
  175805. }
  175806. if (png_ptr != NULL)
  175807. {
  175808. png_write_destroy(png_ptr);
  175809. #ifdef PNG_USER_MEM_SUPPORTED
  175810. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  175811. (png_voidp)mem_ptr);
  175812. #else
  175813. png_destroy_struct((png_voidp)png_ptr);
  175814. #endif
  175815. *png_ptr_ptr = NULL;
  175816. }
  175817. }
  175818. void /* PRIVATE */
  175819. png_write_destroy(png_structp png_ptr)
  175820. {
  175821. #ifdef PNG_SETJMP_SUPPORTED
  175822. jmp_buf tmp_jmp; /* save jump buffer */
  175823. #endif
  175824. png_error_ptr error_fn;
  175825. png_error_ptr warning_fn;
  175826. png_voidp error_ptr;
  175827. #ifdef PNG_USER_MEM_SUPPORTED
  175828. png_free_ptr free_fn;
  175829. #endif
  175830. png_debug(1, "in png_write_destroy\n");
  175831. deflateEnd(&png_ptr->zstream);
  175832. png_free(png_ptr, png_ptr->zbuf);
  175833. png_free(png_ptr, png_ptr->row_buf);
  175834. png_free(png_ptr, png_ptr->prev_row);
  175835. png_free(png_ptr, png_ptr->sub_row);
  175836. png_free(png_ptr, png_ptr->up_row);
  175837. png_free(png_ptr, png_ptr->avg_row);
  175838. png_free(png_ptr, png_ptr->paeth_row);
  175839. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  175840. png_free(png_ptr, png_ptr->time_buffer);
  175841. #endif
  175842. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175843. png_free(png_ptr, png_ptr->prev_filters);
  175844. png_free(png_ptr, png_ptr->filter_weights);
  175845. png_free(png_ptr, png_ptr->inv_filter_weights);
  175846. png_free(png_ptr, png_ptr->filter_costs);
  175847. png_free(png_ptr, png_ptr->inv_filter_costs);
  175848. #endif
  175849. #ifdef PNG_SETJMP_SUPPORTED
  175850. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175851. #endif
  175852. error_fn = png_ptr->error_fn;
  175853. warning_fn = png_ptr->warning_fn;
  175854. error_ptr = png_ptr->error_ptr;
  175855. #ifdef PNG_USER_MEM_SUPPORTED
  175856. free_fn = png_ptr->free_fn;
  175857. #endif
  175858. png_memset(png_ptr, 0, png_sizeof (png_struct));
  175859. png_ptr->error_fn = error_fn;
  175860. png_ptr->warning_fn = warning_fn;
  175861. png_ptr->error_ptr = error_ptr;
  175862. #ifdef PNG_USER_MEM_SUPPORTED
  175863. png_ptr->free_fn = free_fn;
  175864. #endif
  175865. #ifdef PNG_SETJMP_SUPPORTED
  175866. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  175867. #endif
  175868. }
  175869. void PNGAPI
  175870. png_set_filter(png_structp png_ptr, int method, int filters)
  175871. {
  175872. png_debug(1, "in png_set_filter\n");
  175873. if (png_ptr == NULL)
  175874. return;
  175875. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175876. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  175877. (method == PNG_INTRAPIXEL_DIFFERENCING))
  175878. method = PNG_FILTER_TYPE_BASE;
  175879. #endif
  175880. if (method == PNG_FILTER_TYPE_BASE)
  175881. {
  175882. switch (filters & (PNG_ALL_FILTERS | 0x07))
  175883. {
  175884. #ifndef PNG_NO_WRITE_FILTER
  175885. case 5:
  175886. case 6:
  175887. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  175888. #endif /* PNG_NO_WRITE_FILTER */
  175889. case PNG_FILTER_VALUE_NONE:
  175890. png_ptr->do_filter=PNG_FILTER_NONE; break;
  175891. #ifndef PNG_NO_WRITE_FILTER
  175892. case PNG_FILTER_VALUE_SUB:
  175893. png_ptr->do_filter=PNG_FILTER_SUB; break;
  175894. case PNG_FILTER_VALUE_UP:
  175895. png_ptr->do_filter=PNG_FILTER_UP; break;
  175896. case PNG_FILTER_VALUE_AVG:
  175897. png_ptr->do_filter=PNG_FILTER_AVG; break;
  175898. case PNG_FILTER_VALUE_PAETH:
  175899. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  175900. default: png_ptr->do_filter = (png_byte)filters; break;
  175901. #else
  175902. default: png_warning(png_ptr, "Unknown row filter for method 0");
  175903. #endif /* PNG_NO_WRITE_FILTER */
  175904. }
  175905. if (png_ptr->row_buf != NULL)
  175906. {
  175907. #ifndef PNG_NO_WRITE_FILTER
  175908. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  175909. {
  175910. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  175911. (png_ptr->rowbytes + 1));
  175912. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  175913. }
  175914. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  175915. {
  175916. if (png_ptr->prev_row == NULL)
  175917. {
  175918. png_warning(png_ptr, "Can't add Up filter after starting");
  175919. png_ptr->do_filter &= ~PNG_FILTER_UP;
  175920. }
  175921. else
  175922. {
  175923. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  175924. (png_ptr->rowbytes + 1));
  175925. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  175926. }
  175927. }
  175928. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  175929. {
  175930. if (png_ptr->prev_row == NULL)
  175931. {
  175932. png_warning(png_ptr, "Can't add Average filter after starting");
  175933. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  175934. }
  175935. else
  175936. {
  175937. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  175938. (png_ptr->rowbytes + 1));
  175939. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  175940. }
  175941. }
  175942. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  175943. png_ptr->paeth_row == NULL)
  175944. {
  175945. if (png_ptr->prev_row == NULL)
  175946. {
  175947. png_warning(png_ptr, "Can't add Paeth filter after starting");
  175948. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  175949. }
  175950. else
  175951. {
  175952. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  175953. (png_ptr->rowbytes + 1));
  175954. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  175955. }
  175956. }
  175957. if (png_ptr->do_filter == PNG_NO_FILTERS)
  175958. #endif /* PNG_NO_WRITE_FILTER */
  175959. png_ptr->do_filter = PNG_FILTER_NONE;
  175960. }
  175961. }
  175962. else
  175963. png_error(png_ptr, "Unknown custom filter method");
  175964. }
  175965. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  175966. void PNGAPI
  175967. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  175968. int num_weights, png_doublep filter_weights,
  175969. png_doublep filter_costs)
  175970. {
  175971. int i;
  175972. png_debug(1, "in png_set_filter_heuristics\n");
  175973. if (png_ptr == NULL)
  175974. return;
  175975. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  175976. {
  175977. png_warning(png_ptr, "Unknown filter heuristic method");
  175978. return;
  175979. }
  175980. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  175981. {
  175982. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  175983. }
  175984. if (num_weights < 0 || filter_weights == NULL ||
  175985. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  175986. {
  175987. num_weights = 0;
  175988. }
  175989. png_ptr->num_prev_filters = (png_byte)num_weights;
  175990. png_ptr->heuristic_method = (png_byte)heuristic_method;
  175991. if (num_weights > 0)
  175992. {
  175993. if (png_ptr->prev_filters == NULL)
  175994. {
  175995. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  175996. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  175997. for (i = 0; i < num_weights; i++)
  175998. {
  175999. png_ptr->prev_filters[i] = 255;
  176000. }
  176001. }
  176002. if (png_ptr->filter_weights == NULL)
  176003. {
  176004. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176005. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176006. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176007. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176008. for (i = 0; i < num_weights; i++)
  176009. {
  176010. png_ptr->inv_filter_weights[i] =
  176011. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176012. }
  176013. }
  176014. for (i = 0; i < num_weights; i++)
  176015. {
  176016. if (filter_weights[i] < 0.0)
  176017. {
  176018. png_ptr->inv_filter_weights[i] =
  176019. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176020. }
  176021. else
  176022. {
  176023. png_ptr->inv_filter_weights[i] =
  176024. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176025. png_ptr->filter_weights[i] =
  176026. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176027. }
  176028. }
  176029. }
  176030. if (png_ptr->filter_costs == NULL)
  176031. {
  176032. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176033. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176034. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176035. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176036. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176037. {
  176038. png_ptr->inv_filter_costs[i] =
  176039. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176040. }
  176041. }
  176042. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176043. {
  176044. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176045. {
  176046. png_ptr->inv_filter_costs[i] =
  176047. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176048. }
  176049. else if (filter_costs[i] >= 1.0)
  176050. {
  176051. png_ptr->inv_filter_costs[i] =
  176052. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176053. png_ptr->filter_costs[i] =
  176054. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176055. }
  176056. }
  176057. }
  176058. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176059. void PNGAPI
  176060. png_set_compression_level(png_structp png_ptr, int level)
  176061. {
  176062. png_debug(1, "in png_set_compression_level\n");
  176063. if (png_ptr == NULL)
  176064. return;
  176065. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176066. png_ptr->zlib_level = level;
  176067. }
  176068. void PNGAPI
  176069. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176070. {
  176071. png_debug(1, "in png_set_compression_mem_level\n");
  176072. if (png_ptr == NULL)
  176073. return;
  176074. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176075. png_ptr->zlib_mem_level = mem_level;
  176076. }
  176077. void PNGAPI
  176078. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176079. {
  176080. png_debug(1, "in png_set_compression_strategy\n");
  176081. if (png_ptr == NULL)
  176082. return;
  176083. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176084. png_ptr->zlib_strategy = strategy;
  176085. }
  176086. void PNGAPI
  176087. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176088. {
  176089. if (png_ptr == NULL)
  176090. return;
  176091. if (window_bits > 15)
  176092. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176093. else if (window_bits < 8)
  176094. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176095. #ifndef WBITS_8_OK
  176096. if (window_bits == 8)
  176097. {
  176098. png_warning(png_ptr, "Compression window is being reset to 512");
  176099. window_bits=9;
  176100. }
  176101. #endif
  176102. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176103. png_ptr->zlib_window_bits = window_bits;
  176104. }
  176105. void PNGAPI
  176106. png_set_compression_method(png_structp png_ptr, int method)
  176107. {
  176108. png_debug(1, "in png_set_compression_method\n");
  176109. if (png_ptr == NULL)
  176110. return;
  176111. if (method != 8)
  176112. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176113. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176114. png_ptr->zlib_method = method;
  176115. }
  176116. void PNGAPI
  176117. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176118. {
  176119. if (png_ptr == NULL)
  176120. return;
  176121. png_ptr->write_row_fn = write_row_fn;
  176122. }
  176123. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176124. void PNGAPI
  176125. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176126. write_user_transform_fn)
  176127. {
  176128. png_debug(1, "in png_set_write_user_transform_fn\n");
  176129. if (png_ptr == NULL)
  176130. return;
  176131. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176132. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176133. }
  176134. #endif
  176135. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176136. void PNGAPI
  176137. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176138. int transforms, voidp params)
  176139. {
  176140. if (png_ptr == NULL || info_ptr == NULL)
  176141. return;
  176142. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176143. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176144. png_set_invert_alpha(png_ptr);
  176145. #endif
  176146. png_write_info(png_ptr, info_ptr);
  176147. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176148. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176149. png_set_invert_mono(png_ptr);
  176150. #endif
  176151. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176152. if ((transforms & PNG_TRANSFORM_SHIFT)
  176153. && (info_ptr->valid & PNG_INFO_sBIT))
  176154. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176155. #endif
  176156. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176157. if (transforms & PNG_TRANSFORM_PACKING)
  176158. png_set_packing(png_ptr);
  176159. #endif
  176160. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176161. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176162. png_set_swap_alpha(png_ptr);
  176163. #endif
  176164. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176165. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176166. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176167. #endif
  176168. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176169. if (transforms & PNG_TRANSFORM_BGR)
  176170. png_set_bgr(png_ptr);
  176171. #endif
  176172. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176173. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176174. png_set_swap(png_ptr);
  176175. #endif
  176176. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176177. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176178. png_set_packswap(png_ptr);
  176179. #endif
  176180. if (info_ptr->valid & PNG_INFO_IDAT)
  176181. png_write_image(png_ptr, info_ptr->row_pointers);
  176182. png_write_end(png_ptr, info_ptr);
  176183. transforms = transforms; /* quiet compiler warnings */
  176184. params = params;
  176185. }
  176186. #endif
  176187. #endif /* PNG_WRITE_SUPPORTED */
  176188. /*** End of inlined file: pngwrite.c ***/
  176189. /*** Start of inlined file: pngwtran.c ***/
  176190. #define PNG_INTERNAL
  176191. #ifdef PNG_WRITE_SUPPORTED
  176192. void /* PRIVATE */
  176193. png_do_write_transformations(png_structp png_ptr)
  176194. {
  176195. png_debug(1, "in png_do_write_transformations\n");
  176196. if (png_ptr == NULL)
  176197. return;
  176198. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176199. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176200. if(png_ptr->write_user_transform_fn != NULL)
  176201. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176202. (png_ptr, /* png_ptr */
  176203. &(png_ptr->row_info), /* row_info: */
  176204. png_ptr->row_buf + 1); /* start of pixel data for row */
  176205. #endif
  176206. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176207. if (png_ptr->transformations & PNG_FILLER)
  176208. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176209. png_ptr->flags);
  176210. #endif
  176211. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176212. if (png_ptr->transformations & PNG_PACKSWAP)
  176213. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176214. #endif
  176215. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176216. if (png_ptr->transformations & PNG_PACK)
  176217. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176218. (png_uint_32)png_ptr->bit_depth);
  176219. #endif
  176220. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176221. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176222. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176223. #endif
  176224. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176225. if (png_ptr->transformations & PNG_SHIFT)
  176226. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176227. &(png_ptr->shift));
  176228. #endif
  176229. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176230. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176231. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176232. #endif
  176233. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176234. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176235. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176236. #endif
  176237. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176238. if (png_ptr->transformations & PNG_BGR)
  176239. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176240. #endif
  176241. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176242. if (png_ptr->transformations & PNG_INVERT_MONO)
  176243. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176244. #endif
  176245. }
  176246. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176247. void /* PRIVATE */
  176248. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176249. {
  176250. png_debug(1, "in png_do_pack\n");
  176251. if (row_info->bit_depth == 8 &&
  176252. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176253. row != NULL && row_info != NULL &&
  176254. #endif
  176255. row_info->channels == 1)
  176256. {
  176257. switch ((int)bit_depth)
  176258. {
  176259. case 1:
  176260. {
  176261. png_bytep sp, dp;
  176262. int mask, v;
  176263. png_uint_32 i;
  176264. png_uint_32 row_width = row_info->width;
  176265. sp = row;
  176266. dp = row;
  176267. mask = 0x80;
  176268. v = 0;
  176269. for (i = 0; i < row_width; i++)
  176270. {
  176271. if (*sp != 0)
  176272. v |= mask;
  176273. sp++;
  176274. if (mask > 1)
  176275. mask >>= 1;
  176276. else
  176277. {
  176278. mask = 0x80;
  176279. *dp = (png_byte)v;
  176280. dp++;
  176281. v = 0;
  176282. }
  176283. }
  176284. if (mask != 0x80)
  176285. *dp = (png_byte)v;
  176286. break;
  176287. }
  176288. case 2:
  176289. {
  176290. png_bytep sp, dp;
  176291. int shift, v;
  176292. png_uint_32 i;
  176293. png_uint_32 row_width = row_info->width;
  176294. sp = row;
  176295. dp = row;
  176296. shift = 6;
  176297. v = 0;
  176298. for (i = 0; i < row_width; i++)
  176299. {
  176300. png_byte value;
  176301. value = (png_byte)(*sp & 0x03);
  176302. v |= (value << shift);
  176303. if (shift == 0)
  176304. {
  176305. shift = 6;
  176306. *dp = (png_byte)v;
  176307. dp++;
  176308. v = 0;
  176309. }
  176310. else
  176311. shift -= 2;
  176312. sp++;
  176313. }
  176314. if (shift != 6)
  176315. *dp = (png_byte)v;
  176316. break;
  176317. }
  176318. case 4:
  176319. {
  176320. png_bytep sp, dp;
  176321. int shift, v;
  176322. png_uint_32 i;
  176323. png_uint_32 row_width = row_info->width;
  176324. sp = row;
  176325. dp = row;
  176326. shift = 4;
  176327. v = 0;
  176328. for (i = 0; i < row_width; i++)
  176329. {
  176330. png_byte value;
  176331. value = (png_byte)(*sp & 0x0f);
  176332. v |= (value << shift);
  176333. if (shift == 0)
  176334. {
  176335. shift = 4;
  176336. *dp = (png_byte)v;
  176337. dp++;
  176338. v = 0;
  176339. }
  176340. else
  176341. shift -= 4;
  176342. sp++;
  176343. }
  176344. if (shift != 4)
  176345. *dp = (png_byte)v;
  176346. break;
  176347. }
  176348. }
  176349. row_info->bit_depth = (png_byte)bit_depth;
  176350. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176351. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176352. row_info->width);
  176353. }
  176354. }
  176355. #endif
  176356. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176357. void /* PRIVATE */
  176358. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176359. {
  176360. png_debug(1, "in png_do_shift\n");
  176361. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176362. if (row != NULL && row_info != NULL &&
  176363. #else
  176364. if (
  176365. #endif
  176366. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176367. {
  176368. int shift_start[4], shift_dec[4];
  176369. int channels = 0;
  176370. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176371. {
  176372. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176373. shift_dec[channels] = bit_depth->red;
  176374. channels++;
  176375. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176376. shift_dec[channels] = bit_depth->green;
  176377. channels++;
  176378. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176379. shift_dec[channels] = bit_depth->blue;
  176380. channels++;
  176381. }
  176382. else
  176383. {
  176384. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176385. shift_dec[channels] = bit_depth->gray;
  176386. channels++;
  176387. }
  176388. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176389. {
  176390. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176391. shift_dec[channels] = bit_depth->alpha;
  176392. channels++;
  176393. }
  176394. if (row_info->bit_depth < 8)
  176395. {
  176396. png_bytep bp = row;
  176397. png_uint_32 i;
  176398. png_byte mask;
  176399. png_uint_32 row_bytes = row_info->rowbytes;
  176400. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176401. mask = 0x55;
  176402. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176403. mask = 0x11;
  176404. else
  176405. mask = 0xff;
  176406. for (i = 0; i < row_bytes; i++, bp++)
  176407. {
  176408. png_uint_16 v;
  176409. int j;
  176410. v = *bp;
  176411. *bp = 0;
  176412. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176413. {
  176414. if (j > 0)
  176415. *bp |= (png_byte)((v << j) & 0xff);
  176416. else
  176417. *bp |= (png_byte)((v >> (-j)) & mask);
  176418. }
  176419. }
  176420. }
  176421. else if (row_info->bit_depth == 8)
  176422. {
  176423. png_bytep bp = row;
  176424. png_uint_32 i;
  176425. png_uint_32 istop = channels * row_info->width;
  176426. for (i = 0; i < istop; i++, bp++)
  176427. {
  176428. png_uint_16 v;
  176429. int j;
  176430. int c = (int)(i%channels);
  176431. v = *bp;
  176432. *bp = 0;
  176433. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176434. {
  176435. if (j > 0)
  176436. *bp |= (png_byte)((v << j) & 0xff);
  176437. else
  176438. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176439. }
  176440. }
  176441. }
  176442. else
  176443. {
  176444. png_bytep bp;
  176445. png_uint_32 i;
  176446. png_uint_32 istop = channels * row_info->width;
  176447. for (bp = row, i = 0; i < istop; i++)
  176448. {
  176449. int c = (int)(i%channels);
  176450. png_uint_16 value, v;
  176451. int j;
  176452. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176453. value = 0;
  176454. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176455. {
  176456. if (j > 0)
  176457. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176458. else
  176459. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176460. }
  176461. *bp++ = (png_byte)(value >> 8);
  176462. *bp++ = (png_byte)(value & 0xff);
  176463. }
  176464. }
  176465. }
  176466. }
  176467. #endif
  176468. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176469. void /* PRIVATE */
  176470. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176471. {
  176472. png_debug(1, "in png_do_write_swap_alpha\n");
  176473. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176474. if (row != NULL && row_info != NULL)
  176475. #endif
  176476. {
  176477. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176478. {
  176479. if (row_info->bit_depth == 8)
  176480. {
  176481. png_bytep sp, dp;
  176482. png_uint_32 i;
  176483. png_uint_32 row_width = row_info->width;
  176484. for (i = 0, sp = dp = row; i < row_width; i++)
  176485. {
  176486. png_byte save = *(sp++);
  176487. *(dp++) = *(sp++);
  176488. *(dp++) = *(sp++);
  176489. *(dp++) = *(sp++);
  176490. *(dp++) = save;
  176491. }
  176492. }
  176493. else
  176494. {
  176495. png_bytep sp, dp;
  176496. png_uint_32 i;
  176497. png_uint_32 row_width = row_info->width;
  176498. for (i = 0, sp = dp = row; i < row_width; i++)
  176499. {
  176500. png_byte save[2];
  176501. save[0] = *(sp++);
  176502. save[1] = *(sp++);
  176503. *(dp++) = *(sp++);
  176504. *(dp++) = *(sp++);
  176505. *(dp++) = *(sp++);
  176506. *(dp++) = *(sp++);
  176507. *(dp++) = *(sp++);
  176508. *(dp++) = *(sp++);
  176509. *(dp++) = save[0];
  176510. *(dp++) = save[1];
  176511. }
  176512. }
  176513. }
  176514. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176515. {
  176516. if (row_info->bit_depth == 8)
  176517. {
  176518. png_bytep sp, dp;
  176519. png_uint_32 i;
  176520. png_uint_32 row_width = row_info->width;
  176521. for (i = 0, sp = dp = row; i < row_width; i++)
  176522. {
  176523. png_byte save = *(sp++);
  176524. *(dp++) = *(sp++);
  176525. *(dp++) = save;
  176526. }
  176527. }
  176528. else
  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. png_byte save[2];
  176536. save[0] = *(sp++);
  176537. save[1] = *(sp++);
  176538. *(dp++) = *(sp++);
  176539. *(dp++) = *(sp++);
  176540. *(dp++) = save[0];
  176541. *(dp++) = save[1];
  176542. }
  176543. }
  176544. }
  176545. }
  176546. }
  176547. #endif
  176548. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176549. void /* PRIVATE */
  176550. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  176551. {
  176552. png_debug(1, "in png_do_write_invert_alpha\n");
  176553. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176554. if (row != NULL && row_info != NULL)
  176555. #endif
  176556. {
  176557. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176558. {
  176559. if (row_info->bit_depth == 8)
  176560. {
  176561. png_bytep sp, dp;
  176562. png_uint_32 i;
  176563. png_uint_32 row_width = row_info->width;
  176564. for (i = 0, sp = dp = row; i < row_width; i++)
  176565. {
  176566. sp+=3; dp = sp;
  176567. *(dp++) = (png_byte)(255 - *(sp++));
  176568. }
  176569. }
  176570. else
  176571. {
  176572. png_bytep sp, dp;
  176573. png_uint_32 i;
  176574. png_uint_32 row_width = row_info->width;
  176575. for (i = 0, sp = dp = row; i < row_width; i++)
  176576. {
  176577. sp+=6; dp = sp;
  176578. *(dp++) = (png_byte)(255 - *(sp++));
  176579. *(dp++) = (png_byte)(255 - *(sp++));
  176580. }
  176581. }
  176582. }
  176583. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176584. {
  176585. if (row_info->bit_depth == 8)
  176586. {
  176587. png_bytep sp, dp;
  176588. png_uint_32 i;
  176589. png_uint_32 row_width = row_info->width;
  176590. for (i = 0, sp = dp = row; i < row_width; i++)
  176591. {
  176592. *(dp++) = *(sp++);
  176593. *(dp++) = (png_byte)(255 - *(sp++));
  176594. }
  176595. }
  176596. else
  176597. {
  176598. png_bytep sp, dp;
  176599. png_uint_32 i;
  176600. png_uint_32 row_width = row_info->width;
  176601. for (i = 0, sp = dp = row; i < row_width; i++)
  176602. {
  176603. sp+=2; dp = sp;
  176604. *(dp++) = (png_byte)(255 - *(sp++));
  176605. *(dp++) = (png_byte)(255 - *(sp++));
  176606. }
  176607. }
  176608. }
  176609. }
  176610. }
  176611. #endif
  176612. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176613. void /* PRIVATE */
  176614. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  176615. {
  176616. png_debug(1, "in png_do_write_intrapixel\n");
  176617. if (
  176618. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176619. row != NULL && row_info != NULL &&
  176620. #endif
  176621. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  176622. {
  176623. int bytes_per_pixel;
  176624. png_uint_32 row_width = row_info->width;
  176625. if (row_info->bit_depth == 8)
  176626. {
  176627. png_bytep rp;
  176628. png_uint_32 i;
  176629. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176630. bytes_per_pixel = 3;
  176631. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176632. bytes_per_pixel = 4;
  176633. else
  176634. return;
  176635. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176636. {
  176637. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  176638. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  176639. }
  176640. }
  176641. else if (row_info->bit_depth == 16)
  176642. {
  176643. png_bytep rp;
  176644. png_uint_32 i;
  176645. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  176646. bytes_per_pixel = 6;
  176647. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176648. bytes_per_pixel = 8;
  176649. else
  176650. return;
  176651. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  176652. {
  176653. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  176654. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  176655. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  176656. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  176657. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  176658. *(rp ) = (png_byte)((red >> 8) & 0xff);
  176659. *(rp+1) = (png_byte)(red & 0xff);
  176660. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  176661. *(rp+5) = (png_byte)(blue & 0xff);
  176662. }
  176663. }
  176664. }
  176665. }
  176666. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  176667. #endif /* PNG_WRITE_SUPPORTED */
  176668. /*** End of inlined file: pngwtran.c ***/
  176669. /*** Start of inlined file: pngwutil.c ***/
  176670. #define PNG_INTERNAL
  176671. #ifdef PNG_WRITE_SUPPORTED
  176672. void PNGAPI
  176673. png_save_uint_32(png_bytep buf, png_uint_32 i)
  176674. {
  176675. buf[0] = (png_byte)((i >> 24) & 0xff);
  176676. buf[1] = (png_byte)((i >> 16) & 0xff);
  176677. buf[2] = (png_byte)((i >> 8) & 0xff);
  176678. buf[3] = (png_byte)(i & 0xff);
  176679. }
  176680. void PNGAPI
  176681. png_save_int_32(png_bytep buf, png_int_32 i)
  176682. {
  176683. buf[0] = (png_byte)((i >> 24) & 0xff);
  176684. buf[1] = (png_byte)((i >> 16) & 0xff);
  176685. buf[2] = (png_byte)((i >> 8) & 0xff);
  176686. buf[3] = (png_byte)(i & 0xff);
  176687. }
  176688. void PNGAPI
  176689. png_save_uint_16(png_bytep buf, unsigned int i)
  176690. {
  176691. buf[0] = (png_byte)((i >> 8) & 0xff);
  176692. buf[1] = (png_byte)(i & 0xff);
  176693. }
  176694. void PNGAPI
  176695. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  176696. png_bytep data, png_size_t length)
  176697. {
  176698. if(png_ptr == NULL) return;
  176699. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  176700. png_write_chunk_data(png_ptr, data, length);
  176701. png_write_chunk_end(png_ptr);
  176702. }
  176703. void PNGAPI
  176704. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  176705. png_uint_32 length)
  176706. {
  176707. png_byte buf[4];
  176708. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  176709. if(png_ptr == NULL) return;
  176710. png_save_uint_32(buf, length);
  176711. png_write_data(png_ptr, buf, (png_size_t)4);
  176712. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  176713. png_reset_crc(png_ptr);
  176714. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  176715. }
  176716. void PNGAPI
  176717. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  176718. {
  176719. if(png_ptr == NULL) return;
  176720. if (data != NULL && length > 0)
  176721. {
  176722. png_calculate_crc(png_ptr, data, length);
  176723. png_write_data(png_ptr, data, length);
  176724. }
  176725. }
  176726. void PNGAPI
  176727. png_write_chunk_end(png_structp png_ptr)
  176728. {
  176729. png_byte buf[4];
  176730. if(png_ptr == NULL) return;
  176731. png_save_uint_32(buf, png_ptr->crc);
  176732. png_write_data(png_ptr, buf, (png_size_t)4);
  176733. }
  176734. void /* PRIVATE */
  176735. png_write_sig(png_structp png_ptr)
  176736. {
  176737. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  176738. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  176739. (png_size_t)8 - png_ptr->sig_bytes);
  176740. if(png_ptr->sig_bytes < 3)
  176741. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  176742. }
  176743. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  176744. typedef struct
  176745. {
  176746. char *input; /* the uncompressed input data */
  176747. int input_len; /* its length */
  176748. int num_output_ptr; /* number of output pointers used */
  176749. int max_output_ptr; /* size of output_ptr */
  176750. png_charpp output_ptr; /* array of pointers to output */
  176751. } compression_state;
  176752. static int /* PRIVATE */
  176753. png_text_compress(png_structp png_ptr,
  176754. png_charp text, png_size_t text_len, int compression,
  176755. compression_state *comp)
  176756. {
  176757. int ret;
  176758. comp->num_output_ptr = 0;
  176759. comp->max_output_ptr = 0;
  176760. comp->output_ptr = NULL;
  176761. comp->input = NULL;
  176762. comp->input_len = 0;
  176763. if (compression == PNG_TEXT_COMPRESSION_NONE)
  176764. {
  176765. comp->input = text;
  176766. comp->input_len = text_len;
  176767. return((int)text_len);
  176768. }
  176769. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  176770. {
  176771. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  176772. char msg[50];
  176773. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  176774. png_warning(png_ptr, msg);
  176775. #else
  176776. png_warning(png_ptr, "Unknown compression type");
  176777. #endif
  176778. }
  176779. png_ptr->zstream.avail_in = (uInt)text_len;
  176780. png_ptr->zstream.next_in = (Bytef *)text;
  176781. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176782. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  176783. do
  176784. {
  176785. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  176786. if (ret != Z_OK)
  176787. {
  176788. if (png_ptr->zstream.msg != NULL)
  176789. png_error(png_ptr, png_ptr->zstream.msg);
  176790. else
  176791. png_error(png_ptr, "zlib error");
  176792. }
  176793. if (!(png_ptr->zstream.avail_out))
  176794. {
  176795. if (comp->num_output_ptr >= comp->max_output_ptr)
  176796. {
  176797. int old_max;
  176798. old_max = comp->max_output_ptr;
  176799. comp->max_output_ptr = comp->num_output_ptr + 4;
  176800. if (comp->output_ptr != NULL)
  176801. {
  176802. png_charpp old_ptr;
  176803. old_ptr = comp->output_ptr;
  176804. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176805. (png_uint_32)(comp->max_output_ptr *
  176806. png_sizeof (png_charpp)));
  176807. png_memcpy(comp->output_ptr, old_ptr, old_max
  176808. * png_sizeof (png_charp));
  176809. png_free(png_ptr, old_ptr);
  176810. }
  176811. else
  176812. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176813. (png_uint_32)(comp->max_output_ptr *
  176814. png_sizeof (png_charp)));
  176815. }
  176816. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  176817. (png_uint_32)png_ptr->zbuf_size);
  176818. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176819. png_ptr->zbuf_size);
  176820. comp->num_output_ptr++;
  176821. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176822. png_ptr->zstream.next_out = png_ptr->zbuf;
  176823. }
  176824. } while (png_ptr->zstream.avail_in);
  176825. do
  176826. {
  176827. ret = deflate(&png_ptr->zstream, Z_FINISH);
  176828. if (ret == Z_OK)
  176829. {
  176830. if (!(png_ptr->zstream.avail_out))
  176831. {
  176832. if (comp->num_output_ptr >= comp->max_output_ptr)
  176833. {
  176834. int old_max;
  176835. old_max = comp->max_output_ptr;
  176836. comp->max_output_ptr = comp->num_output_ptr + 4;
  176837. if (comp->output_ptr != NULL)
  176838. {
  176839. png_charpp old_ptr;
  176840. old_ptr = comp->output_ptr;
  176841. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176842. (png_uint_32)(comp->max_output_ptr *
  176843. png_sizeof (png_charpp)));
  176844. png_memcpy(comp->output_ptr, old_ptr,
  176845. old_max * png_sizeof (png_charp));
  176846. png_free(png_ptr, old_ptr);
  176847. }
  176848. else
  176849. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  176850. (png_uint_32)(comp->max_output_ptr *
  176851. png_sizeof (png_charp)));
  176852. }
  176853. comp->output_ptr[comp->num_output_ptr] =
  176854. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  176855. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  176856. png_ptr->zbuf_size);
  176857. comp->num_output_ptr++;
  176858. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176859. png_ptr->zstream.next_out = png_ptr->zbuf;
  176860. }
  176861. }
  176862. else if (ret != Z_STREAM_END)
  176863. {
  176864. if (png_ptr->zstream.msg != NULL)
  176865. png_error(png_ptr, png_ptr->zstream.msg);
  176866. else
  176867. png_error(png_ptr, "zlib error");
  176868. }
  176869. } while (ret != Z_STREAM_END);
  176870. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  176871. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  176872. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  176873. return((int)text_len);
  176874. }
  176875. static void /* PRIVATE */
  176876. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  176877. {
  176878. int i;
  176879. if (comp->input)
  176880. {
  176881. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  176882. (png_size_t)comp->input_len);
  176883. return;
  176884. }
  176885. for (i = 0; i < comp->num_output_ptr; i++)
  176886. {
  176887. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  176888. png_ptr->zbuf_size);
  176889. png_free(png_ptr, comp->output_ptr[i]);
  176890. comp->output_ptr[i]=NULL;
  176891. }
  176892. if (comp->max_output_ptr != 0)
  176893. png_free(png_ptr, comp->output_ptr);
  176894. comp->output_ptr=NULL;
  176895. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  176896. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  176897. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176898. deflateReset(&png_ptr->zstream);
  176899. png_ptr->zstream.data_type = Z_BINARY;
  176900. }
  176901. #endif
  176902. void /* PRIVATE */
  176903. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  176904. int bit_depth, int color_type, int compression_type, int filter_type,
  176905. int interlace_type)
  176906. {
  176907. #ifdef PNG_USE_LOCAL_ARRAYS
  176908. PNG_IHDR;
  176909. #endif
  176910. png_byte buf[13]; /* buffer to store the IHDR info */
  176911. png_debug(1, "in png_write_IHDR\n");
  176912. switch (color_type)
  176913. {
  176914. case PNG_COLOR_TYPE_GRAY:
  176915. switch (bit_depth)
  176916. {
  176917. case 1:
  176918. case 2:
  176919. case 4:
  176920. case 8:
  176921. case 16: png_ptr->channels = 1; break;
  176922. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  176923. }
  176924. break;
  176925. case PNG_COLOR_TYPE_RGB:
  176926. if (bit_depth != 8 && bit_depth != 16)
  176927. png_error(png_ptr, "Invalid bit depth for RGB image");
  176928. png_ptr->channels = 3;
  176929. break;
  176930. case PNG_COLOR_TYPE_PALETTE:
  176931. switch (bit_depth)
  176932. {
  176933. case 1:
  176934. case 2:
  176935. case 4:
  176936. case 8: png_ptr->channels = 1; break;
  176937. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  176938. }
  176939. break;
  176940. case PNG_COLOR_TYPE_GRAY_ALPHA:
  176941. if (bit_depth != 8 && bit_depth != 16)
  176942. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  176943. png_ptr->channels = 2;
  176944. break;
  176945. case PNG_COLOR_TYPE_RGB_ALPHA:
  176946. if (bit_depth != 8 && bit_depth != 16)
  176947. png_error(png_ptr, "Invalid bit depth for RGBA image");
  176948. png_ptr->channels = 4;
  176949. break;
  176950. default:
  176951. png_error(png_ptr, "Invalid image color type specified");
  176952. }
  176953. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  176954. {
  176955. png_warning(png_ptr, "Invalid compression type specified");
  176956. compression_type = PNG_COMPRESSION_TYPE_BASE;
  176957. }
  176958. if (
  176959. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176960. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176961. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  176962. (color_type == PNG_COLOR_TYPE_RGB ||
  176963. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  176964. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  176965. #endif
  176966. filter_type != PNG_FILTER_TYPE_BASE)
  176967. {
  176968. png_warning(png_ptr, "Invalid filter type specified");
  176969. filter_type = PNG_FILTER_TYPE_BASE;
  176970. }
  176971. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  176972. if (interlace_type != PNG_INTERLACE_NONE &&
  176973. interlace_type != PNG_INTERLACE_ADAM7)
  176974. {
  176975. png_warning(png_ptr, "Invalid interlace type specified");
  176976. interlace_type = PNG_INTERLACE_ADAM7;
  176977. }
  176978. #else
  176979. interlace_type=PNG_INTERLACE_NONE;
  176980. #endif
  176981. png_ptr->bit_depth = (png_byte)bit_depth;
  176982. png_ptr->color_type = (png_byte)color_type;
  176983. png_ptr->interlaced = (png_byte)interlace_type;
  176984. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176985. png_ptr->filter_type = (png_byte)filter_type;
  176986. #endif
  176987. png_ptr->compression_type = (png_byte)compression_type;
  176988. png_ptr->width = width;
  176989. png_ptr->height = height;
  176990. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  176991. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  176992. png_ptr->usr_width = png_ptr->width;
  176993. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  176994. png_ptr->usr_channels = png_ptr->channels;
  176995. png_save_uint_32(buf, width);
  176996. png_save_uint_32(buf + 4, height);
  176997. buf[8] = (png_byte)bit_depth;
  176998. buf[9] = (png_byte)color_type;
  176999. buf[10] = (png_byte)compression_type;
  177000. buf[11] = (png_byte)filter_type;
  177001. buf[12] = (png_byte)interlace_type;
  177002. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177003. png_ptr->zstream.zalloc = png_zalloc;
  177004. png_ptr->zstream.zfree = png_zfree;
  177005. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177006. if (!(png_ptr->do_filter))
  177007. {
  177008. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177009. png_ptr->bit_depth < 8)
  177010. png_ptr->do_filter = PNG_FILTER_NONE;
  177011. else
  177012. png_ptr->do_filter = PNG_ALL_FILTERS;
  177013. }
  177014. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177015. {
  177016. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177017. png_ptr->zlib_strategy = Z_FILTERED;
  177018. else
  177019. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177020. }
  177021. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177022. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177023. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177024. png_ptr->zlib_mem_level = 8;
  177025. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177026. png_ptr->zlib_window_bits = 15;
  177027. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177028. png_ptr->zlib_method = 8;
  177029. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177030. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177031. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177032. png_error(png_ptr, "zlib failed to initialize compressor");
  177033. png_ptr->zstream.next_out = png_ptr->zbuf;
  177034. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177035. png_ptr->zstream.data_type = Z_BINARY;
  177036. png_ptr->mode = PNG_HAVE_IHDR;
  177037. }
  177038. void /* PRIVATE */
  177039. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177040. {
  177041. #ifdef PNG_USE_LOCAL_ARRAYS
  177042. PNG_PLTE;
  177043. #endif
  177044. png_uint_32 i;
  177045. png_colorp pal_ptr;
  177046. png_byte buf[3];
  177047. png_debug(1, "in png_write_PLTE\n");
  177048. if ((
  177049. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177050. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177051. #endif
  177052. num_pal == 0) || num_pal > 256)
  177053. {
  177054. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177055. {
  177056. png_error(png_ptr, "Invalid number of colors in palette");
  177057. }
  177058. else
  177059. {
  177060. png_warning(png_ptr, "Invalid number of colors in palette");
  177061. return;
  177062. }
  177063. }
  177064. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177065. {
  177066. png_warning(png_ptr,
  177067. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177068. return;
  177069. }
  177070. png_ptr->num_palette = (png_uint_16)num_pal;
  177071. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177072. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177073. #ifndef PNG_NO_POINTER_INDEXING
  177074. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177075. {
  177076. buf[0] = pal_ptr->red;
  177077. buf[1] = pal_ptr->green;
  177078. buf[2] = pal_ptr->blue;
  177079. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177080. }
  177081. #else
  177082. pal_ptr=palette;
  177083. for (i = 0; i < num_pal; i++)
  177084. {
  177085. buf[0] = pal_ptr[i].red;
  177086. buf[1] = pal_ptr[i].green;
  177087. buf[2] = pal_ptr[i].blue;
  177088. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177089. }
  177090. #endif
  177091. png_write_chunk_end(png_ptr);
  177092. png_ptr->mode |= PNG_HAVE_PLTE;
  177093. }
  177094. void /* PRIVATE */
  177095. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177096. {
  177097. #ifdef PNG_USE_LOCAL_ARRAYS
  177098. PNG_IDAT;
  177099. #endif
  177100. png_debug(1, "in png_write_IDAT\n");
  177101. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177102. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177103. {
  177104. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177105. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177106. {
  177107. if (length >= 2 &&
  177108. png_ptr->height < 16384 && png_ptr->width < 16384)
  177109. {
  177110. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177111. ((png_ptr->width *
  177112. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177113. unsigned int z_cinfo = z_cmf >> 4;
  177114. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177115. while (uncompressed_idat_size <= half_z_window_size &&
  177116. half_z_window_size >= 256)
  177117. {
  177118. z_cinfo--;
  177119. half_z_window_size >>= 1;
  177120. }
  177121. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177122. if (data[0] != (png_byte)z_cmf)
  177123. {
  177124. data[0] = (png_byte)z_cmf;
  177125. data[1] &= 0xe0;
  177126. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177127. }
  177128. }
  177129. }
  177130. else
  177131. png_error(png_ptr,
  177132. "Invalid zlib compression method or flags in IDAT");
  177133. }
  177134. png_write_chunk(png_ptr, png_IDAT, data, length);
  177135. png_ptr->mode |= PNG_HAVE_IDAT;
  177136. }
  177137. void /* PRIVATE */
  177138. png_write_IEND(png_structp png_ptr)
  177139. {
  177140. #ifdef PNG_USE_LOCAL_ARRAYS
  177141. PNG_IEND;
  177142. #endif
  177143. png_debug(1, "in png_write_IEND\n");
  177144. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177145. (png_size_t)0);
  177146. png_ptr->mode |= PNG_HAVE_IEND;
  177147. }
  177148. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177149. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177150. void /* PRIVATE */
  177151. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177152. {
  177153. #ifdef PNG_USE_LOCAL_ARRAYS
  177154. PNG_gAMA;
  177155. #endif
  177156. png_uint_32 igamma;
  177157. png_byte buf[4];
  177158. png_debug(1, "in png_write_gAMA\n");
  177159. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177160. png_save_uint_32(buf, igamma);
  177161. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177162. }
  177163. #endif
  177164. #ifdef PNG_FIXED_POINT_SUPPORTED
  177165. void /* PRIVATE */
  177166. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177167. {
  177168. #ifdef PNG_USE_LOCAL_ARRAYS
  177169. PNG_gAMA;
  177170. #endif
  177171. png_byte buf[4];
  177172. png_debug(1, "in png_write_gAMA\n");
  177173. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177174. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177175. }
  177176. #endif
  177177. #endif
  177178. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177179. void /* PRIVATE */
  177180. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177181. {
  177182. #ifdef PNG_USE_LOCAL_ARRAYS
  177183. PNG_sRGB;
  177184. #endif
  177185. png_byte buf[1];
  177186. png_debug(1, "in png_write_sRGB\n");
  177187. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177188. png_warning(png_ptr,
  177189. "Invalid sRGB rendering intent specified");
  177190. buf[0]=(png_byte)srgb_intent;
  177191. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177192. }
  177193. #endif
  177194. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177195. void /* PRIVATE */
  177196. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177197. png_charp profile, int profile_len)
  177198. {
  177199. #ifdef PNG_USE_LOCAL_ARRAYS
  177200. PNG_iCCP;
  177201. #endif
  177202. png_size_t name_len;
  177203. png_charp new_name;
  177204. compression_state comp;
  177205. int embedded_profile_len = 0;
  177206. png_debug(1, "in png_write_iCCP\n");
  177207. comp.num_output_ptr = 0;
  177208. comp.max_output_ptr = 0;
  177209. comp.output_ptr = NULL;
  177210. comp.input = NULL;
  177211. comp.input_len = 0;
  177212. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177213. &new_name)) == 0)
  177214. {
  177215. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177216. return;
  177217. }
  177218. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177219. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177220. if (profile == NULL)
  177221. profile_len = 0;
  177222. if (profile_len > 3)
  177223. embedded_profile_len =
  177224. ((*( (png_bytep)profile ))<<24) |
  177225. ((*( (png_bytep)profile+1))<<16) |
  177226. ((*( (png_bytep)profile+2))<< 8) |
  177227. ((*( (png_bytep)profile+3)) );
  177228. if (profile_len < embedded_profile_len)
  177229. {
  177230. png_warning(png_ptr,
  177231. "Embedded profile length too large in iCCP chunk");
  177232. return;
  177233. }
  177234. if (profile_len > embedded_profile_len)
  177235. {
  177236. png_warning(png_ptr,
  177237. "Truncating profile to actual length in iCCP chunk");
  177238. profile_len = embedded_profile_len;
  177239. }
  177240. if (profile_len)
  177241. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177242. PNG_COMPRESSION_TYPE_BASE, &comp);
  177243. png_write_chunk_start(png_ptr, png_iCCP,
  177244. (png_uint_32)name_len+profile_len+2);
  177245. new_name[name_len+1]=0x00;
  177246. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177247. if (profile_len)
  177248. png_write_compressed_data_out(png_ptr, &comp);
  177249. png_write_chunk_end(png_ptr);
  177250. png_free(png_ptr, new_name);
  177251. }
  177252. #endif
  177253. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177254. void /* PRIVATE */
  177255. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177256. {
  177257. #ifdef PNG_USE_LOCAL_ARRAYS
  177258. PNG_sPLT;
  177259. #endif
  177260. png_size_t name_len;
  177261. png_charp new_name;
  177262. png_byte entrybuf[10];
  177263. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177264. int palette_size = entry_size * spalette->nentries;
  177265. png_sPLT_entryp ep;
  177266. #ifdef PNG_NO_POINTER_INDEXING
  177267. int i;
  177268. #endif
  177269. png_debug(1, "in png_write_sPLT\n");
  177270. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177271. spalette->name, &new_name))==0)
  177272. {
  177273. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177274. return;
  177275. }
  177276. png_write_chunk_start(png_ptr, png_sPLT,
  177277. (png_uint_32)(name_len + 2 + palette_size));
  177278. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177279. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177280. #ifndef PNG_NO_POINTER_INDEXING
  177281. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177282. {
  177283. if (spalette->depth == 8)
  177284. {
  177285. entrybuf[0] = (png_byte)ep->red;
  177286. entrybuf[1] = (png_byte)ep->green;
  177287. entrybuf[2] = (png_byte)ep->blue;
  177288. entrybuf[3] = (png_byte)ep->alpha;
  177289. png_save_uint_16(entrybuf + 4, ep->frequency);
  177290. }
  177291. else
  177292. {
  177293. png_save_uint_16(entrybuf + 0, ep->red);
  177294. png_save_uint_16(entrybuf + 2, ep->green);
  177295. png_save_uint_16(entrybuf + 4, ep->blue);
  177296. png_save_uint_16(entrybuf + 6, ep->alpha);
  177297. png_save_uint_16(entrybuf + 8, ep->frequency);
  177298. }
  177299. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177300. }
  177301. #else
  177302. ep=spalette->entries;
  177303. for (i=0; i>spalette->nentries; i++)
  177304. {
  177305. if (spalette->depth == 8)
  177306. {
  177307. entrybuf[0] = (png_byte)ep[i].red;
  177308. entrybuf[1] = (png_byte)ep[i].green;
  177309. entrybuf[2] = (png_byte)ep[i].blue;
  177310. entrybuf[3] = (png_byte)ep[i].alpha;
  177311. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177312. }
  177313. else
  177314. {
  177315. png_save_uint_16(entrybuf + 0, ep[i].red);
  177316. png_save_uint_16(entrybuf + 2, ep[i].green);
  177317. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177318. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177319. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177320. }
  177321. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177322. }
  177323. #endif
  177324. png_write_chunk_end(png_ptr);
  177325. png_free(png_ptr, new_name);
  177326. }
  177327. #endif
  177328. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177329. void /* PRIVATE */
  177330. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177331. {
  177332. #ifdef PNG_USE_LOCAL_ARRAYS
  177333. PNG_sBIT;
  177334. #endif
  177335. png_byte buf[4];
  177336. png_size_t size;
  177337. png_debug(1, "in png_write_sBIT\n");
  177338. if (color_type & PNG_COLOR_MASK_COLOR)
  177339. {
  177340. png_byte maxbits;
  177341. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177342. png_ptr->usr_bit_depth);
  177343. if (sbit->red == 0 || sbit->red > maxbits ||
  177344. sbit->green == 0 || sbit->green > maxbits ||
  177345. sbit->blue == 0 || sbit->blue > maxbits)
  177346. {
  177347. png_warning(png_ptr, "Invalid sBIT depth specified");
  177348. return;
  177349. }
  177350. buf[0] = sbit->red;
  177351. buf[1] = sbit->green;
  177352. buf[2] = sbit->blue;
  177353. size = 3;
  177354. }
  177355. else
  177356. {
  177357. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177358. {
  177359. png_warning(png_ptr, "Invalid sBIT depth specified");
  177360. return;
  177361. }
  177362. buf[0] = sbit->gray;
  177363. size = 1;
  177364. }
  177365. if (color_type & PNG_COLOR_MASK_ALPHA)
  177366. {
  177367. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177368. {
  177369. png_warning(png_ptr, "Invalid sBIT depth specified");
  177370. return;
  177371. }
  177372. buf[size++] = sbit->alpha;
  177373. }
  177374. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177375. }
  177376. #endif
  177377. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177378. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177379. void /* PRIVATE */
  177380. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177381. double red_x, double red_y, double green_x, double green_y,
  177382. double blue_x, double blue_y)
  177383. {
  177384. #ifdef PNG_USE_LOCAL_ARRAYS
  177385. PNG_cHRM;
  177386. #endif
  177387. png_byte buf[32];
  177388. png_uint_32 itemp;
  177389. png_debug(1, "in png_write_cHRM\n");
  177390. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177391. white_x + white_y > 1.0)
  177392. {
  177393. png_warning(png_ptr, "Invalid cHRM white point specified");
  177394. #if !defined(PNG_NO_CONSOLE_IO)
  177395. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177396. #endif
  177397. return;
  177398. }
  177399. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177400. png_save_uint_32(buf, itemp);
  177401. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177402. png_save_uint_32(buf + 4, itemp);
  177403. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177404. {
  177405. png_warning(png_ptr, "Invalid cHRM red point specified");
  177406. return;
  177407. }
  177408. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177409. png_save_uint_32(buf + 8, itemp);
  177410. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177411. png_save_uint_32(buf + 12, itemp);
  177412. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177413. {
  177414. png_warning(png_ptr, "Invalid cHRM green point specified");
  177415. return;
  177416. }
  177417. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177418. png_save_uint_32(buf + 16, itemp);
  177419. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177420. png_save_uint_32(buf + 20, itemp);
  177421. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177422. {
  177423. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177424. return;
  177425. }
  177426. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177427. png_save_uint_32(buf + 24, itemp);
  177428. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177429. png_save_uint_32(buf + 28, itemp);
  177430. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177431. }
  177432. #endif
  177433. #ifdef PNG_FIXED_POINT_SUPPORTED
  177434. void /* PRIVATE */
  177435. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177436. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177437. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177438. png_fixed_point blue_y)
  177439. {
  177440. #ifdef PNG_USE_LOCAL_ARRAYS
  177441. PNG_cHRM;
  177442. #endif
  177443. png_byte buf[32];
  177444. png_debug(1, "in png_write_cHRM\n");
  177445. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177446. {
  177447. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177448. #if !defined(PNG_NO_CONSOLE_IO)
  177449. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177450. #endif
  177451. return;
  177452. }
  177453. png_save_uint_32(buf, (png_uint_32)white_x);
  177454. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177455. if (red_x + red_y > 100000L)
  177456. {
  177457. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177458. return;
  177459. }
  177460. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177461. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177462. if (green_x + green_y > 100000L)
  177463. {
  177464. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177465. return;
  177466. }
  177467. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177468. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177469. if (blue_x + blue_y > 100000L)
  177470. {
  177471. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177472. return;
  177473. }
  177474. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177475. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177476. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177477. }
  177478. #endif
  177479. #endif
  177480. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177481. void /* PRIVATE */
  177482. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177483. int num_trans, int color_type)
  177484. {
  177485. #ifdef PNG_USE_LOCAL_ARRAYS
  177486. PNG_tRNS;
  177487. #endif
  177488. png_byte buf[6];
  177489. png_debug(1, "in png_write_tRNS\n");
  177490. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177491. {
  177492. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177493. {
  177494. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177495. return;
  177496. }
  177497. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177498. }
  177499. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177500. {
  177501. if(tran->gray >= (1 << png_ptr->bit_depth))
  177502. {
  177503. png_warning(png_ptr,
  177504. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177505. return;
  177506. }
  177507. png_save_uint_16(buf, tran->gray);
  177508. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177509. }
  177510. else if (color_type == PNG_COLOR_TYPE_RGB)
  177511. {
  177512. png_save_uint_16(buf, tran->red);
  177513. png_save_uint_16(buf + 2, tran->green);
  177514. png_save_uint_16(buf + 4, tran->blue);
  177515. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177516. {
  177517. png_warning(png_ptr,
  177518. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177519. return;
  177520. }
  177521. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  177522. }
  177523. else
  177524. {
  177525. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  177526. }
  177527. }
  177528. #endif
  177529. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  177530. void /* PRIVATE */
  177531. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  177532. {
  177533. #ifdef PNG_USE_LOCAL_ARRAYS
  177534. PNG_bKGD;
  177535. #endif
  177536. png_byte buf[6];
  177537. png_debug(1, "in png_write_bKGD\n");
  177538. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177539. {
  177540. if (
  177541. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177542. (png_ptr->num_palette ||
  177543. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  177544. #endif
  177545. back->index > png_ptr->num_palette)
  177546. {
  177547. png_warning(png_ptr, "Invalid background palette index");
  177548. return;
  177549. }
  177550. buf[0] = back->index;
  177551. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  177552. }
  177553. else if (color_type & PNG_COLOR_MASK_COLOR)
  177554. {
  177555. png_save_uint_16(buf, back->red);
  177556. png_save_uint_16(buf + 2, back->green);
  177557. png_save_uint_16(buf + 4, back->blue);
  177558. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177559. {
  177560. png_warning(png_ptr,
  177561. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  177562. return;
  177563. }
  177564. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  177565. }
  177566. else
  177567. {
  177568. if(back->gray >= (1 << png_ptr->bit_depth))
  177569. {
  177570. png_warning(png_ptr,
  177571. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  177572. return;
  177573. }
  177574. png_save_uint_16(buf, back->gray);
  177575. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  177576. }
  177577. }
  177578. #endif
  177579. #if defined(PNG_WRITE_hIST_SUPPORTED)
  177580. void /* PRIVATE */
  177581. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  177582. {
  177583. #ifdef PNG_USE_LOCAL_ARRAYS
  177584. PNG_hIST;
  177585. #endif
  177586. int i;
  177587. png_byte buf[3];
  177588. png_debug(1, "in png_write_hIST\n");
  177589. if (num_hist > (int)png_ptr->num_palette)
  177590. {
  177591. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  177592. png_ptr->num_palette);
  177593. png_warning(png_ptr, "Invalid number of histogram entries specified");
  177594. return;
  177595. }
  177596. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  177597. for (i = 0; i < num_hist; i++)
  177598. {
  177599. png_save_uint_16(buf, hist[i]);
  177600. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  177601. }
  177602. png_write_chunk_end(png_ptr);
  177603. }
  177604. #endif
  177605. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  177606. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  177607. png_size_t /* PRIVATE */
  177608. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  177609. {
  177610. png_size_t key_len;
  177611. png_charp kp, dp;
  177612. int kflag;
  177613. int kwarn=0;
  177614. png_debug(1, "in png_check_keyword\n");
  177615. *new_key = NULL;
  177616. if (key == NULL || (key_len = png_strlen(key)) == 0)
  177617. {
  177618. png_warning(png_ptr, "zero length keyword");
  177619. return ((png_size_t)0);
  177620. }
  177621. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  177622. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  177623. if (*new_key == NULL)
  177624. {
  177625. png_warning(png_ptr, "Out of memory while procesing keyword");
  177626. return ((png_size_t)0);
  177627. }
  177628. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  177629. {
  177630. if ((png_byte)*kp < 0x20 ||
  177631. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  177632. {
  177633. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177634. char msg[40];
  177635. png_snprintf(msg, 40,
  177636. "invalid keyword character 0x%02X", (png_byte)*kp);
  177637. png_warning(png_ptr, msg);
  177638. #else
  177639. png_warning(png_ptr, "invalid character in keyword");
  177640. #endif
  177641. *dp = ' ';
  177642. }
  177643. else
  177644. {
  177645. *dp = *kp;
  177646. }
  177647. }
  177648. *dp = '\0';
  177649. kp = *new_key + key_len - 1;
  177650. if (*kp == ' ')
  177651. {
  177652. png_warning(png_ptr, "trailing spaces removed from keyword");
  177653. while (*kp == ' ')
  177654. {
  177655. *(kp--) = '\0';
  177656. key_len--;
  177657. }
  177658. }
  177659. kp = *new_key;
  177660. if (*kp == ' ')
  177661. {
  177662. png_warning(png_ptr, "leading spaces removed from keyword");
  177663. while (*kp == ' ')
  177664. {
  177665. kp++;
  177666. key_len--;
  177667. }
  177668. }
  177669. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  177670. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  177671. {
  177672. if (*kp == ' ' && kflag == 0)
  177673. {
  177674. *(dp++) = *kp;
  177675. kflag = 1;
  177676. }
  177677. else if (*kp == ' ')
  177678. {
  177679. key_len--;
  177680. kwarn=1;
  177681. }
  177682. else
  177683. {
  177684. *(dp++) = *kp;
  177685. kflag = 0;
  177686. }
  177687. }
  177688. *dp = '\0';
  177689. if(kwarn)
  177690. png_warning(png_ptr, "extra interior spaces removed from keyword");
  177691. if (key_len == 0)
  177692. {
  177693. png_free(png_ptr, *new_key);
  177694. *new_key=NULL;
  177695. png_warning(png_ptr, "Zero length keyword");
  177696. }
  177697. if (key_len > 79)
  177698. {
  177699. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  177700. new_key[79] = '\0';
  177701. key_len = 79;
  177702. }
  177703. return (key_len);
  177704. }
  177705. #endif
  177706. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  177707. void /* PRIVATE */
  177708. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  177709. png_size_t text_len)
  177710. {
  177711. #ifdef PNG_USE_LOCAL_ARRAYS
  177712. PNG_tEXt;
  177713. #endif
  177714. png_size_t key_len;
  177715. png_charp new_key;
  177716. png_debug(1, "in png_write_tEXt\n");
  177717. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177718. {
  177719. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  177720. return;
  177721. }
  177722. if (text == NULL || *text == '\0')
  177723. text_len = 0;
  177724. else
  177725. text_len = png_strlen(text);
  177726. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  177727. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177728. if (text_len)
  177729. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  177730. png_write_chunk_end(png_ptr);
  177731. png_free(png_ptr, new_key);
  177732. }
  177733. #endif
  177734. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  177735. void /* PRIVATE */
  177736. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  177737. png_size_t text_len, int compression)
  177738. {
  177739. #ifdef PNG_USE_LOCAL_ARRAYS
  177740. PNG_zTXt;
  177741. #endif
  177742. png_size_t key_len;
  177743. char buf[1];
  177744. png_charp new_key;
  177745. compression_state comp;
  177746. png_debug(1, "in png_write_zTXt\n");
  177747. comp.num_output_ptr = 0;
  177748. comp.max_output_ptr = 0;
  177749. comp.output_ptr = NULL;
  177750. comp.input = NULL;
  177751. comp.input_len = 0;
  177752. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177753. {
  177754. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  177755. return;
  177756. }
  177757. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  177758. {
  177759. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  177760. png_free(png_ptr, new_key);
  177761. return;
  177762. }
  177763. text_len = png_strlen(text);
  177764. text_len = png_text_compress(png_ptr, text, text_len, compression,
  177765. &comp);
  177766. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  177767. (key_len+text_len+2));
  177768. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177769. png_free(png_ptr, new_key);
  177770. buf[0] = (png_byte)compression;
  177771. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  177772. png_write_compressed_data_out(png_ptr, &comp);
  177773. png_write_chunk_end(png_ptr);
  177774. }
  177775. #endif
  177776. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  177777. void /* PRIVATE */
  177778. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  177779. png_charp lang, png_charp lang_key, png_charp text)
  177780. {
  177781. #ifdef PNG_USE_LOCAL_ARRAYS
  177782. PNG_iTXt;
  177783. #endif
  177784. png_size_t lang_len, key_len, lang_key_len, text_len;
  177785. png_charp new_lang, new_key;
  177786. png_byte cbuf[2];
  177787. compression_state comp;
  177788. png_debug(1, "in png_write_iTXt\n");
  177789. comp.num_output_ptr = 0;
  177790. comp.max_output_ptr = 0;
  177791. comp.output_ptr = NULL;
  177792. comp.input = NULL;
  177793. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  177794. {
  177795. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  177796. return;
  177797. }
  177798. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  177799. {
  177800. png_warning(png_ptr, "Empty language field in iTXt chunk");
  177801. new_lang = NULL;
  177802. lang_len = 0;
  177803. }
  177804. if (lang_key == NULL)
  177805. lang_key_len = 0;
  177806. else
  177807. lang_key_len = png_strlen(lang_key);
  177808. if (text == NULL)
  177809. text_len = 0;
  177810. else
  177811. text_len = png_strlen(text);
  177812. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  177813. &comp);
  177814. png_write_chunk_start(png_ptr, png_iTXt,
  177815. (png_uint_32)(
  177816. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  177817. + key_len
  177818. + lang_len
  177819. + lang_key_len
  177820. + text_len));
  177821. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  177822. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  177823. compression == PNG_TEXT_COMPRESSION_NONE)
  177824. cbuf[0] = 0;
  177825. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  177826. cbuf[0] = 1;
  177827. cbuf[1] = 0;
  177828. png_write_chunk_data(png_ptr, cbuf, 2);
  177829. cbuf[0] = 0;
  177830. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  177831. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  177832. png_write_compressed_data_out(png_ptr, &comp);
  177833. png_write_chunk_end(png_ptr);
  177834. png_free(png_ptr, new_key);
  177835. if (new_lang)
  177836. png_free(png_ptr, new_lang);
  177837. }
  177838. #endif
  177839. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  177840. void /* PRIVATE */
  177841. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  177842. int unit_type)
  177843. {
  177844. #ifdef PNG_USE_LOCAL_ARRAYS
  177845. PNG_oFFs;
  177846. #endif
  177847. png_byte buf[9];
  177848. png_debug(1, "in png_write_oFFs\n");
  177849. if (unit_type >= PNG_OFFSET_LAST)
  177850. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  177851. png_save_int_32(buf, x_offset);
  177852. png_save_int_32(buf + 4, y_offset);
  177853. buf[8] = (png_byte)unit_type;
  177854. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  177855. }
  177856. #endif
  177857. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  177858. void /* PRIVATE */
  177859. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  177860. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  177861. {
  177862. #ifdef PNG_USE_LOCAL_ARRAYS
  177863. PNG_pCAL;
  177864. #endif
  177865. png_size_t purpose_len, units_len, total_len;
  177866. png_uint_32p params_len;
  177867. png_byte buf[10];
  177868. png_charp new_purpose;
  177869. int i;
  177870. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  177871. if (type >= PNG_EQUATION_LAST)
  177872. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  177873. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  177874. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  177875. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  177876. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  177877. total_len = purpose_len + units_len + 10;
  177878. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  177879. *png_sizeof(png_uint_32)));
  177880. for (i = 0; i < nparams; i++)
  177881. {
  177882. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  177883. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  177884. total_len += (png_size_t)params_len[i];
  177885. }
  177886. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  177887. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  177888. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  177889. png_save_int_32(buf, X0);
  177890. png_save_int_32(buf + 4, X1);
  177891. buf[8] = (png_byte)type;
  177892. buf[9] = (png_byte)nparams;
  177893. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  177894. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  177895. png_free(png_ptr, new_purpose);
  177896. for (i = 0; i < nparams; i++)
  177897. {
  177898. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  177899. (png_size_t)params_len[i]);
  177900. }
  177901. png_free(png_ptr, params_len);
  177902. png_write_chunk_end(png_ptr);
  177903. }
  177904. #endif
  177905. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  177906. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  177907. void /* PRIVATE */
  177908. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  177909. {
  177910. #ifdef PNG_USE_LOCAL_ARRAYS
  177911. PNG_sCAL;
  177912. #endif
  177913. char buf[64];
  177914. png_size_t total_len;
  177915. png_debug(1, "in png_write_sCAL\n");
  177916. buf[0] = (char)unit;
  177917. #if defined(_WIN32_WCE)
  177918. {
  177919. wchar_t wc_buf[32];
  177920. size_t wc_len;
  177921. swprintf(wc_buf, TEXT("%12.12e"), width);
  177922. wc_len = wcslen(wc_buf);
  177923. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  177924. total_len = wc_len + 2;
  177925. swprintf(wc_buf, TEXT("%12.12e"), height);
  177926. wc_len = wcslen(wc_buf);
  177927. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  177928. NULL, NULL);
  177929. total_len += wc_len;
  177930. }
  177931. #else
  177932. png_snprintf(buf + 1, 63, "%12.12e", width);
  177933. total_len = 1 + png_strlen(buf + 1) + 1;
  177934. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  177935. total_len += png_strlen(buf + total_len);
  177936. #endif
  177937. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  177938. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  177939. }
  177940. #else
  177941. #ifdef PNG_FIXED_POINT_SUPPORTED
  177942. void /* PRIVATE */
  177943. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  177944. png_charp height)
  177945. {
  177946. #ifdef PNG_USE_LOCAL_ARRAYS
  177947. PNG_sCAL;
  177948. #endif
  177949. png_byte buf[64];
  177950. png_size_t wlen, hlen, total_len;
  177951. png_debug(1, "in png_write_sCAL_s\n");
  177952. wlen = png_strlen(width);
  177953. hlen = png_strlen(height);
  177954. total_len = wlen + hlen + 2;
  177955. if (total_len > 64)
  177956. {
  177957. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  177958. return;
  177959. }
  177960. buf[0] = (png_byte)unit;
  177961. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  177962. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  177963. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  177964. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  177965. }
  177966. #endif
  177967. #endif
  177968. #endif
  177969. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  177970. void /* PRIVATE */
  177971. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  177972. png_uint_32 y_pixels_per_unit,
  177973. int unit_type)
  177974. {
  177975. #ifdef PNG_USE_LOCAL_ARRAYS
  177976. PNG_pHYs;
  177977. #endif
  177978. png_byte buf[9];
  177979. png_debug(1, "in png_write_pHYs\n");
  177980. if (unit_type >= PNG_RESOLUTION_LAST)
  177981. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  177982. png_save_uint_32(buf, x_pixels_per_unit);
  177983. png_save_uint_32(buf + 4, y_pixels_per_unit);
  177984. buf[8] = (png_byte)unit_type;
  177985. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  177986. }
  177987. #endif
  177988. #if defined(PNG_WRITE_tIME_SUPPORTED)
  177989. void /* PRIVATE */
  177990. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  177991. {
  177992. #ifdef PNG_USE_LOCAL_ARRAYS
  177993. PNG_tIME;
  177994. #endif
  177995. png_byte buf[7];
  177996. png_debug(1, "in png_write_tIME\n");
  177997. if (mod_time->month > 12 || mod_time->month < 1 ||
  177998. mod_time->day > 31 || mod_time->day < 1 ||
  177999. mod_time->hour > 23 || mod_time->second > 60)
  178000. {
  178001. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178002. return;
  178003. }
  178004. png_save_uint_16(buf, mod_time->year);
  178005. buf[2] = mod_time->month;
  178006. buf[3] = mod_time->day;
  178007. buf[4] = mod_time->hour;
  178008. buf[5] = mod_time->minute;
  178009. buf[6] = mod_time->second;
  178010. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178011. }
  178012. #endif
  178013. void /* PRIVATE */
  178014. png_write_start_row(png_structp png_ptr)
  178015. {
  178016. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178017. #ifdef PNG_USE_LOCAL_ARRAYS
  178018. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178019. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178020. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178021. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178022. #endif
  178023. #endif
  178024. png_size_t buf_size;
  178025. png_debug(1, "in png_write_start_row\n");
  178026. buf_size = (png_size_t)(PNG_ROWBYTES(
  178027. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178028. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178029. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178030. #ifndef PNG_NO_WRITE_FILTERING
  178031. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178032. {
  178033. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178034. (png_ptr->rowbytes + 1));
  178035. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178036. }
  178037. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178038. {
  178039. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178040. png_memset(png_ptr->prev_row, 0, buf_size);
  178041. if (png_ptr->do_filter & PNG_FILTER_UP)
  178042. {
  178043. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178044. (png_ptr->rowbytes + 1));
  178045. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178046. }
  178047. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178048. {
  178049. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178050. (png_ptr->rowbytes + 1));
  178051. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178052. }
  178053. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178054. {
  178055. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178056. (png_ptr->rowbytes + 1));
  178057. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178058. }
  178059. #endif /* PNG_NO_WRITE_FILTERING */
  178060. }
  178061. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178062. if (png_ptr->interlaced)
  178063. {
  178064. if (!(png_ptr->transformations & PNG_INTERLACE))
  178065. {
  178066. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178067. png_pass_ystart[0]) / png_pass_yinc[0];
  178068. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178069. png_pass_start[0]) / png_pass_inc[0];
  178070. }
  178071. else
  178072. {
  178073. png_ptr->num_rows = png_ptr->height;
  178074. png_ptr->usr_width = png_ptr->width;
  178075. }
  178076. }
  178077. else
  178078. #endif
  178079. {
  178080. png_ptr->num_rows = png_ptr->height;
  178081. png_ptr->usr_width = png_ptr->width;
  178082. }
  178083. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178084. png_ptr->zstream.next_out = png_ptr->zbuf;
  178085. }
  178086. void /* PRIVATE */
  178087. png_write_finish_row(png_structp png_ptr)
  178088. {
  178089. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178090. #ifdef PNG_USE_LOCAL_ARRAYS
  178091. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178092. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178093. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178094. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178095. #endif
  178096. #endif
  178097. int ret;
  178098. png_debug(1, "in png_write_finish_row\n");
  178099. png_ptr->row_number++;
  178100. if (png_ptr->row_number < png_ptr->num_rows)
  178101. return;
  178102. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178103. if (png_ptr->interlaced)
  178104. {
  178105. png_ptr->row_number = 0;
  178106. if (png_ptr->transformations & PNG_INTERLACE)
  178107. {
  178108. png_ptr->pass++;
  178109. }
  178110. else
  178111. {
  178112. do
  178113. {
  178114. png_ptr->pass++;
  178115. if (png_ptr->pass >= 7)
  178116. break;
  178117. png_ptr->usr_width = (png_ptr->width +
  178118. png_pass_inc[png_ptr->pass] - 1 -
  178119. png_pass_start[png_ptr->pass]) /
  178120. png_pass_inc[png_ptr->pass];
  178121. png_ptr->num_rows = (png_ptr->height +
  178122. png_pass_yinc[png_ptr->pass] - 1 -
  178123. png_pass_ystart[png_ptr->pass]) /
  178124. png_pass_yinc[png_ptr->pass];
  178125. if (png_ptr->transformations & PNG_INTERLACE)
  178126. break;
  178127. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178128. }
  178129. if (png_ptr->pass < 7)
  178130. {
  178131. if (png_ptr->prev_row != NULL)
  178132. png_memset(png_ptr->prev_row, 0,
  178133. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178134. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178135. return;
  178136. }
  178137. }
  178138. #endif
  178139. do
  178140. {
  178141. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178142. if (ret == Z_OK)
  178143. {
  178144. if (!(png_ptr->zstream.avail_out))
  178145. {
  178146. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178147. png_ptr->zstream.next_out = png_ptr->zbuf;
  178148. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178149. }
  178150. }
  178151. else if (ret != Z_STREAM_END)
  178152. {
  178153. if (png_ptr->zstream.msg != NULL)
  178154. png_error(png_ptr, png_ptr->zstream.msg);
  178155. else
  178156. png_error(png_ptr, "zlib error");
  178157. }
  178158. } while (ret != Z_STREAM_END);
  178159. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178160. {
  178161. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178162. png_ptr->zstream.avail_out);
  178163. }
  178164. deflateReset(&png_ptr->zstream);
  178165. png_ptr->zstream.data_type = Z_BINARY;
  178166. }
  178167. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178168. void /* PRIVATE */
  178169. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178170. {
  178171. #ifdef PNG_USE_LOCAL_ARRAYS
  178172. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178173. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178174. #endif
  178175. png_debug(1, "in png_do_write_interlace\n");
  178176. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178177. if (row != NULL && row_info != NULL && pass < 6)
  178178. #else
  178179. if (pass < 6)
  178180. #endif
  178181. {
  178182. switch (row_info->pixel_depth)
  178183. {
  178184. case 1:
  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. d = 0;
  178195. shift = 7;
  178196. for (i = png_pass_start[pass]; i < row_width;
  178197. i += png_pass_inc[pass])
  178198. {
  178199. sp = row + (png_size_t)(i >> 3);
  178200. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178201. d |= (value << shift);
  178202. if (shift == 0)
  178203. {
  178204. shift = 7;
  178205. *dp++ = (png_byte)d;
  178206. d = 0;
  178207. }
  178208. else
  178209. shift--;
  178210. }
  178211. if (shift != 7)
  178212. *dp = (png_byte)d;
  178213. break;
  178214. }
  178215. case 2:
  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 = 6;
  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 >> 2);
  178231. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178232. d |= (value << shift);
  178233. if (shift == 0)
  178234. {
  178235. shift = 6;
  178236. *dp++ = (png_byte)d;
  178237. d = 0;
  178238. }
  178239. else
  178240. shift -= 2;
  178241. }
  178242. if (shift != 6)
  178243. *dp = (png_byte)d;
  178244. break;
  178245. }
  178246. case 4:
  178247. {
  178248. png_bytep sp;
  178249. png_bytep dp;
  178250. int shift;
  178251. int d;
  178252. int value;
  178253. png_uint_32 i;
  178254. png_uint_32 row_width = row_info->width;
  178255. dp = row;
  178256. shift = 4;
  178257. d = 0;
  178258. for (i = png_pass_start[pass]; i < row_width;
  178259. i += png_pass_inc[pass])
  178260. {
  178261. sp = row + (png_size_t)(i >> 1);
  178262. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178263. d |= (value << shift);
  178264. if (shift == 0)
  178265. {
  178266. shift = 4;
  178267. *dp++ = (png_byte)d;
  178268. d = 0;
  178269. }
  178270. else
  178271. shift -= 4;
  178272. }
  178273. if (shift != 4)
  178274. *dp = (png_byte)d;
  178275. break;
  178276. }
  178277. default:
  178278. {
  178279. png_bytep sp;
  178280. png_bytep dp;
  178281. png_uint_32 i;
  178282. png_uint_32 row_width = row_info->width;
  178283. png_size_t pixel_bytes;
  178284. dp = row;
  178285. pixel_bytes = (row_info->pixel_depth >> 3);
  178286. for (i = png_pass_start[pass]; i < row_width;
  178287. i += png_pass_inc[pass])
  178288. {
  178289. sp = row + (png_size_t)i * pixel_bytes;
  178290. if (dp != sp)
  178291. png_memcpy(dp, sp, pixel_bytes);
  178292. dp += pixel_bytes;
  178293. }
  178294. break;
  178295. }
  178296. }
  178297. row_info->width = (row_info->width +
  178298. png_pass_inc[pass] - 1 -
  178299. png_pass_start[pass]) /
  178300. png_pass_inc[pass];
  178301. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178302. row_info->width);
  178303. }
  178304. }
  178305. #endif
  178306. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178307. #define PNG_HISHIFT 10
  178308. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178309. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178310. void /* PRIVATE */
  178311. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178312. {
  178313. png_bytep best_row;
  178314. #ifndef PNG_NO_WRITE_FILTER
  178315. png_bytep prev_row, row_buf;
  178316. png_uint_32 mins, bpp;
  178317. png_byte filter_to_do = png_ptr->do_filter;
  178318. png_uint_32 row_bytes = row_info->rowbytes;
  178319. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178320. int num_p_filters = (int)png_ptr->num_prev_filters;
  178321. #endif
  178322. png_debug(1, "in png_write_find_filter\n");
  178323. bpp = (row_info->pixel_depth + 7) >> 3;
  178324. prev_row = png_ptr->prev_row;
  178325. #endif
  178326. best_row = png_ptr->row_buf;
  178327. #ifndef PNG_NO_WRITE_FILTER
  178328. row_buf = best_row;
  178329. mins = PNG_MAXSUM;
  178330. if ((filter_to_do & PNG_FILTER_NONE) &&
  178331. filter_to_do != PNG_FILTER_NONE)
  178332. {
  178333. png_bytep rp;
  178334. png_uint_32 sum = 0;
  178335. png_uint_32 i;
  178336. int v;
  178337. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178338. {
  178339. v = *rp;
  178340. sum += (v < 128) ? v : 256 - v;
  178341. }
  178342. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178343. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178344. {
  178345. png_uint_32 sumhi, sumlo;
  178346. int j;
  178347. sumlo = sum & PNG_LOMASK;
  178348. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178349. for (j = 0; j < num_p_filters; j++)
  178350. {
  178351. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178352. {
  178353. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178354. PNG_WEIGHT_SHIFT;
  178355. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178356. PNG_WEIGHT_SHIFT;
  178357. }
  178358. }
  178359. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178360. PNG_COST_SHIFT;
  178361. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178362. PNG_COST_SHIFT;
  178363. if (sumhi > PNG_HIMASK)
  178364. sum = PNG_MAXSUM;
  178365. else
  178366. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178367. }
  178368. #endif
  178369. mins = sum;
  178370. }
  178371. if (filter_to_do == PNG_FILTER_SUB)
  178372. {
  178373. png_bytep rp, lp, dp;
  178374. png_uint_32 i;
  178375. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178376. i++, rp++, dp++)
  178377. {
  178378. *dp = *rp;
  178379. }
  178380. for (lp = row_buf + 1; i < row_bytes;
  178381. i++, rp++, lp++, dp++)
  178382. {
  178383. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178384. }
  178385. best_row = png_ptr->sub_row;
  178386. }
  178387. else if (filter_to_do & PNG_FILTER_SUB)
  178388. {
  178389. png_bytep rp, dp, lp;
  178390. png_uint_32 sum = 0, lmins = mins;
  178391. png_uint_32 i;
  178392. int v;
  178393. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178394. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178395. {
  178396. int j;
  178397. png_uint_32 lmhi, lmlo;
  178398. lmlo = lmins & PNG_LOMASK;
  178399. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178400. for (j = 0; j < num_p_filters; j++)
  178401. {
  178402. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178403. {
  178404. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178405. PNG_WEIGHT_SHIFT;
  178406. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178407. PNG_WEIGHT_SHIFT;
  178408. }
  178409. }
  178410. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178411. PNG_COST_SHIFT;
  178412. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178413. PNG_COST_SHIFT;
  178414. if (lmhi > PNG_HIMASK)
  178415. lmins = PNG_MAXSUM;
  178416. else
  178417. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178418. }
  178419. #endif
  178420. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178421. i++, rp++, dp++)
  178422. {
  178423. v = *dp = *rp;
  178424. sum += (v < 128) ? v : 256 - v;
  178425. }
  178426. for (lp = row_buf + 1; i < row_bytes;
  178427. i++, rp++, lp++, dp++)
  178428. {
  178429. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178430. sum += (v < 128) ? v : 256 - v;
  178431. if (sum > lmins) /* We are already worse, don't continue. */
  178432. break;
  178433. }
  178434. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178435. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178436. {
  178437. int j;
  178438. png_uint_32 sumhi, sumlo;
  178439. sumlo = sum & PNG_LOMASK;
  178440. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178441. for (j = 0; j < num_p_filters; j++)
  178442. {
  178443. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178444. {
  178445. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178446. PNG_WEIGHT_SHIFT;
  178447. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178448. PNG_WEIGHT_SHIFT;
  178449. }
  178450. }
  178451. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178452. PNG_COST_SHIFT;
  178453. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178454. PNG_COST_SHIFT;
  178455. if (sumhi > PNG_HIMASK)
  178456. sum = PNG_MAXSUM;
  178457. else
  178458. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178459. }
  178460. #endif
  178461. if (sum < mins)
  178462. {
  178463. mins = sum;
  178464. best_row = png_ptr->sub_row;
  178465. }
  178466. }
  178467. if (filter_to_do == PNG_FILTER_UP)
  178468. {
  178469. png_bytep rp, dp, pp;
  178470. png_uint_32 i;
  178471. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178472. pp = prev_row + 1; i < row_bytes;
  178473. i++, rp++, pp++, dp++)
  178474. {
  178475. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178476. }
  178477. best_row = png_ptr->up_row;
  178478. }
  178479. else if (filter_to_do & PNG_FILTER_UP)
  178480. {
  178481. png_bytep rp, dp, pp;
  178482. png_uint_32 sum = 0, lmins = mins;
  178483. png_uint_32 i;
  178484. int v;
  178485. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178486. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178487. {
  178488. int j;
  178489. png_uint_32 lmhi, lmlo;
  178490. lmlo = lmins & PNG_LOMASK;
  178491. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178492. for (j = 0; j < num_p_filters; j++)
  178493. {
  178494. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178495. {
  178496. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178497. PNG_WEIGHT_SHIFT;
  178498. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178499. PNG_WEIGHT_SHIFT;
  178500. }
  178501. }
  178502. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178503. PNG_COST_SHIFT;
  178504. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178505. PNG_COST_SHIFT;
  178506. if (lmhi > PNG_HIMASK)
  178507. lmins = PNG_MAXSUM;
  178508. else
  178509. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178510. }
  178511. #endif
  178512. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178513. pp = prev_row + 1; i < row_bytes; i++)
  178514. {
  178515. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178516. sum += (v < 128) ? v : 256 - v;
  178517. if (sum > lmins) /* We are already worse, don't continue. */
  178518. break;
  178519. }
  178520. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178521. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178522. {
  178523. int j;
  178524. png_uint_32 sumhi, sumlo;
  178525. sumlo = sum & PNG_LOMASK;
  178526. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178527. for (j = 0; j < num_p_filters; j++)
  178528. {
  178529. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178530. {
  178531. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178532. PNG_WEIGHT_SHIFT;
  178533. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178534. PNG_WEIGHT_SHIFT;
  178535. }
  178536. }
  178537. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178538. PNG_COST_SHIFT;
  178539. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  178540. PNG_COST_SHIFT;
  178541. if (sumhi > PNG_HIMASK)
  178542. sum = PNG_MAXSUM;
  178543. else
  178544. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178545. }
  178546. #endif
  178547. if (sum < mins)
  178548. {
  178549. mins = sum;
  178550. best_row = png_ptr->up_row;
  178551. }
  178552. }
  178553. if (filter_to_do == PNG_FILTER_AVG)
  178554. {
  178555. png_bytep rp, dp, pp, lp;
  178556. png_uint_32 i;
  178557. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178558. pp = prev_row + 1; i < bpp; i++)
  178559. {
  178560. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178561. }
  178562. for (lp = row_buf + 1; i < row_bytes; i++)
  178563. {
  178564. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  178565. & 0xff);
  178566. }
  178567. best_row = png_ptr->avg_row;
  178568. }
  178569. else if (filter_to_do & PNG_FILTER_AVG)
  178570. {
  178571. png_bytep rp, dp, pp, lp;
  178572. png_uint_32 sum = 0, lmins = mins;
  178573. png_uint_32 i;
  178574. int v;
  178575. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178576. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178577. {
  178578. int j;
  178579. png_uint_32 lmhi, lmlo;
  178580. lmlo = lmins & PNG_LOMASK;
  178581. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178582. for (j = 0; j < num_p_filters; j++)
  178583. {
  178584. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  178585. {
  178586. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178587. PNG_WEIGHT_SHIFT;
  178588. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178589. PNG_WEIGHT_SHIFT;
  178590. }
  178591. }
  178592. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178593. PNG_COST_SHIFT;
  178594. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178595. PNG_COST_SHIFT;
  178596. if (lmhi > PNG_HIMASK)
  178597. lmins = PNG_MAXSUM;
  178598. else
  178599. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178600. }
  178601. #endif
  178602. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  178603. pp = prev_row + 1; i < bpp; i++)
  178604. {
  178605. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  178606. sum += (v < 128) ? v : 256 - v;
  178607. }
  178608. for (lp = row_buf + 1; i < row_bytes; i++)
  178609. {
  178610. v = *dp++ =
  178611. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  178612. sum += (v < 128) ? v : 256 - v;
  178613. if (sum > lmins) /* We are already worse, don't continue. */
  178614. break;
  178615. }
  178616. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178617. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178618. {
  178619. int j;
  178620. png_uint_32 sumhi, sumlo;
  178621. sumlo = sum & PNG_LOMASK;
  178622. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178623. for (j = 0; j < num_p_filters; j++)
  178624. {
  178625. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178626. {
  178627. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178628. PNG_WEIGHT_SHIFT;
  178629. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178630. PNG_WEIGHT_SHIFT;
  178631. }
  178632. }
  178633. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178634. PNG_COST_SHIFT;
  178635. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  178636. PNG_COST_SHIFT;
  178637. if (sumhi > PNG_HIMASK)
  178638. sum = PNG_MAXSUM;
  178639. else
  178640. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178641. }
  178642. #endif
  178643. if (sum < mins)
  178644. {
  178645. mins = sum;
  178646. best_row = png_ptr->avg_row;
  178647. }
  178648. }
  178649. if (filter_to_do == PNG_FILTER_PAETH)
  178650. {
  178651. png_bytep rp, dp, pp, cp, lp;
  178652. png_uint_32 i;
  178653. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178654. pp = prev_row + 1; i < bpp; i++)
  178655. {
  178656. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178657. }
  178658. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178659. {
  178660. int a, b, c, pa, pb, pc, p;
  178661. b = *pp++;
  178662. c = *cp++;
  178663. a = *lp++;
  178664. p = b - c;
  178665. pc = a - c;
  178666. #ifdef PNG_USE_ABS
  178667. pa = abs(p);
  178668. pb = abs(pc);
  178669. pc = abs(p + pc);
  178670. #else
  178671. pa = p < 0 ? -p : p;
  178672. pb = pc < 0 ? -pc : pc;
  178673. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178674. #endif
  178675. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178676. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178677. }
  178678. best_row = png_ptr->paeth_row;
  178679. }
  178680. else if (filter_to_do & PNG_FILTER_PAETH)
  178681. {
  178682. png_bytep rp, dp, pp, cp, lp;
  178683. png_uint_32 sum = 0, lmins = mins;
  178684. png_uint_32 i;
  178685. int v;
  178686. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178687. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178688. {
  178689. int j;
  178690. png_uint_32 lmhi, lmlo;
  178691. lmlo = lmins & PNG_LOMASK;
  178692. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178693. for (j = 0; j < num_p_filters; j++)
  178694. {
  178695. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178696. {
  178697. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178698. PNG_WEIGHT_SHIFT;
  178699. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178700. PNG_WEIGHT_SHIFT;
  178701. }
  178702. }
  178703. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178704. PNG_COST_SHIFT;
  178705. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178706. PNG_COST_SHIFT;
  178707. if (lmhi > PNG_HIMASK)
  178708. lmins = PNG_MAXSUM;
  178709. else
  178710. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178711. }
  178712. #endif
  178713. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  178714. pp = prev_row + 1; i < bpp; i++)
  178715. {
  178716. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178717. sum += (v < 128) ? v : 256 - v;
  178718. }
  178719. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  178720. {
  178721. int a, b, c, pa, pb, pc, p;
  178722. b = *pp++;
  178723. c = *cp++;
  178724. a = *lp++;
  178725. #ifndef PNG_SLOW_PAETH
  178726. p = b - c;
  178727. pc = a - c;
  178728. #ifdef PNG_USE_ABS
  178729. pa = abs(p);
  178730. pb = abs(pc);
  178731. pc = abs(p + pc);
  178732. #else
  178733. pa = p < 0 ? -p : p;
  178734. pb = pc < 0 ? -pc : pc;
  178735. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  178736. #endif
  178737. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  178738. #else /* PNG_SLOW_PAETH */
  178739. p = a + b - c;
  178740. pa = abs(p - a);
  178741. pb = abs(p - b);
  178742. pc = abs(p - c);
  178743. if (pa <= pb && pa <= pc)
  178744. p = a;
  178745. else if (pb <= pc)
  178746. p = b;
  178747. else
  178748. p = c;
  178749. #endif /* PNG_SLOW_PAETH */
  178750. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  178751. sum += (v < 128) ? v : 256 - v;
  178752. if (sum > lmins) /* We are already worse, don't continue. */
  178753. break;
  178754. }
  178755. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178756. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178757. {
  178758. int j;
  178759. png_uint_32 sumhi, sumlo;
  178760. sumlo = sum & PNG_LOMASK;
  178761. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178762. for (j = 0; j < num_p_filters; j++)
  178763. {
  178764. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  178765. {
  178766. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178767. PNG_WEIGHT_SHIFT;
  178768. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178769. PNG_WEIGHT_SHIFT;
  178770. }
  178771. }
  178772. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178773. PNG_COST_SHIFT;
  178774. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  178775. PNG_COST_SHIFT;
  178776. if (sumhi > PNG_HIMASK)
  178777. sum = PNG_MAXSUM;
  178778. else
  178779. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178780. }
  178781. #endif
  178782. if (sum < mins)
  178783. {
  178784. best_row = png_ptr->paeth_row;
  178785. }
  178786. }
  178787. #endif /* PNG_NO_WRITE_FILTER */
  178788. png_write_filtered_row(png_ptr, best_row);
  178789. #ifndef PNG_NO_WRITE_FILTER
  178790. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178791. if (png_ptr->num_prev_filters > 0)
  178792. {
  178793. int j;
  178794. for (j = 1; j < num_p_filters; j++)
  178795. {
  178796. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  178797. }
  178798. png_ptr->prev_filters[j] = best_row[0];
  178799. }
  178800. #endif
  178801. #endif /* PNG_NO_WRITE_FILTER */
  178802. }
  178803. void /* PRIVATE */
  178804. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  178805. {
  178806. png_debug(1, "in png_write_filtered_row\n");
  178807. png_debug1(2, "filter = %d\n", filtered_row[0]);
  178808. png_ptr->zstream.next_in = filtered_row;
  178809. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  178810. do
  178811. {
  178812. int ret; /* return of zlib */
  178813. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  178814. if (ret != Z_OK)
  178815. {
  178816. if (png_ptr->zstream.msg != NULL)
  178817. png_error(png_ptr, png_ptr->zstream.msg);
  178818. else
  178819. png_error(png_ptr, "zlib error");
  178820. }
  178821. if (!(png_ptr->zstream.avail_out))
  178822. {
  178823. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178824. png_ptr->zstream.next_out = png_ptr->zbuf;
  178825. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178826. }
  178827. } while (png_ptr->zstream.avail_in);
  178828. if (png_ptr->prev_row != NULL)
  178829. {
  178830. png_bytep tptr;
  178831. tptr = png_ptr->prev_row;
  178832. png_ptr->prev_row = png_ptr->row_buf;
  178833. png_ptr->row_buf = tptr;
  178834. }
  178835. png_write_finish_row(png_ptr);
  178836. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  178837. png_ptr->flush_rows++;
  178838. if (png_ptr->flush_dist > 0 &&
  178839. png_ptr->flush_rows >= png_ptr->flush_dist)
  178840. {
  178841. png_write_flush(png_ptr);
  178842. }
  178843. #endif
  178844. }
  178845. #endif /* PNG_WRITE_SUPPORTED */
  178846. /*** End of inlined file: pngwutil.c ***/
  178847. }
  178848. #else
  178849. #define PNG_INTERNAL
  178850. #define PNG_SETJMP_NOT_SUPPORTED
  178851. #include <png.h>
  178852. #include <pngconf.h>
  178853. #endif
  178854. }
  178855. #undef max
  178856. #undef min
  178857. #ifdef _MSC_VER
  178858. #pragma warning (pop)
  178859. #endif
  178860. BEGIN_JUCE_NAMESPACE
  178861. using ::calloc;
  178862. using ::malloc;
  178863. using ::free;
  178864. namespace PNGHelpers
  178865. {
  178866. using namespace pnglibNamespace;
  178867. static void readCallback (png_structp png, png_bytep data, png_size_t length)
  178868. {
  178869. static_cast<InputStream*> (png_get_io_ptr (png))->read (data, (int) length);
  178870. }
  178871. static void writeDataCallback (png_structp png, png_bytep data, png_size_t length)
  178872. {
  178873. static_cast<OutputStream*> (png_get_io_ptr (png))->write (data, (int) length);
  178874. }
  178875. struct PNGErrorStruct {};
  178876. static void errorCallback (png_structp, png_const_charp)
  178877. {
  178878. throw PNGErrorStruct();
  178879. }
  178880. }
  178881. Image* juce_loadPNGImageFromStream (InputStream& in)
  178882. {
  178883. using namespace pnglibNamespace;
  178884. Image* image = 0;
  178885. png_structp pngReadStruct;
  178886. png_infop pngInfoStruct;
  178887. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178888. if (pngReadStruct != 0)
  178889. {
  178890. pngInfoStruct = png_create_info_struct (pngReadStruct);
  178891. if (pngInfoStruct == 0)
  178892. {
  178893. png_destroy_read_struct (&pngReadStruct, 0, 0);
  178894. return 0;
  178895. }
  178896. png_set_error_fn (pngReadStruct, 0, PNGHelpers::errorCallback, PNGHelpers::errorCallback );
  178897. // read the header..
  178898. png_set_read_fn (pngReadStruct, &in, PNGHelpers::readCallback);
  178899. png_uint_32 width, height;
  178900. int bitDepth, colorType, interlaceType;
  178901. png_read_info (pngReadStruct, pngInfoStruct);
  178902. png_get_IHDR (pngReadStruct, pngInfoStruct,
  178903. &width, &height,
  178904. &bitDepth, &colorType,
  178905. &interlaceType, 0, 0);
  178906. if (bitDepth == 16)
  178907. png_set_strip_16 (pngReadStruct);
  178908. if (colorType == PNG_COLOR_TYPE_PALETTE)
  178909. png_set_expand (pngReadStruct);
  178910. if (bitDepth < 8)
  178911. png_set_expand (pngReadStruct);
  178912. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  178913. png_set_expand (pngReadStruct);
  178914. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  178915. png_set_gray_to_rgb (pngReadStruct);
  178916. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  178917. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  178918. || pngInfoStruct->num_trans > 0;
  178919. // Load the image into a temp buffer in the pnglib format..
  178920. HeapBlock <uint8> tempBuffer (height * (width << 2));
  178921. {
  178922. HeapBlock <png_bytep> rows (height);
  178923. for (int y = (int) height; --y >= 0;)
  178924. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  178925. png_read_image (pngReadStruct, rows);
  178926. png_read_end (pngReadStruct, pngInfoStruct);
  178927. }
  178928. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  178929. // now convert the data to a juce image format..
  178930. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  178931. (int) width, (int) height, hasAlphaChan);
  178932. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  178933. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  178934. uint8* srcRow = tempBuffer;
  178935. uint8* destRow = destData.data;
  178936. for (int y = 0; y < (int) height; ++y)
  178937. {
  178938. const uint8* src = srcRow;
  178939. srcRow += (width << 2);
  178940. uint8* dest = destRow;
  178941. destRow += destData.lineStride;
  178942. if (hasAlphaChan)
  178943. {
  178944. for (int i = (int) width; --i >= 0;)
  178945. {
  178946. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  178947. ((PixelARGB*) dest)->premultiply();
  178948. dest += destData.pixelStride;
  178949. src += 4;
  178950. }
  178951. }
  178952. else
  178953. {
  178954. for (int i = (int) width; --i >= 0;)
  178955. {
  178956. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  178957. dest += destData.pixelStride;
  178958. src += 4;
  178959. }
  178960. }
  178961. }
  178962. }
  178963. return image;
  178964. }
  178965. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  178966. {
  178967. using namespace pnglibNamespace;
  178968. const int width = image.getWidth();
  178969. const int height = image.getHeight();
  178970. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  178971. if (pngWriteStruct == 0)
  178972. return false;
  178973. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  178974. if (pngInfoStruct == 0)
  178975. {
  178976. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  178977. return false;
  178978. }
  178979. png_set_write_fn (pngWriteStruct, &out, PNGHelpers::writeDataCallback, 0);
  178980. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  178981. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  178982. : PNG_COLOR_TYPE_RGB,
  178983. PNG_INTERLACE_NONE,
  178984. PNG_COMPRESSION_TYPE_BASE,
  178985. PNG_FILTER_TYPE_BASE);
  178986. HeapBlock <uint8> rowData (width * 4);
  178987. png_color_8 sig_bit;
  178988. sig_bit.red = 8;
  178989. sig_bit.green = 8;
  178990. sig_bit.blue = 8;
  178991. sig_bit.alpha = 8;
  178992. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  178993. png_write_info (pngWriteStruct, pngInfoStruct);
  178994. png_set_shift (pngWriteStruct, &sig_bit);
  178995. png_set_packing (pngWriteStruct);
  178996. const Image::BitmapData srcData (image, 0, 0, width, height);
  178997. for (int y = 0; y < height; ++y)
  178998. {
  178999. uint8* dst = rowData;
  179000. const uint8* src = srcData.getLinePointer (y);
  179001. if (image.hasAlphaChannel())
  179002. {
  179003. for (int i = width; --i >= 0;)
  179004. {
  179005. PixelARGB p (*(const PixelARGB*) src);
  179006. p.unpremultiply();
  179007. *dst++ = p.getRed();
  179008. *dst++ = p.getGreen();
  179009. *dst++ = p.getBlue();
  179010. *dst++ = p.getAlpha();
  179011. src += srcData.pixelStride;
  179012. }
  179013. }
  179014. else
  179015. {
  179016. for (int i = width; --i >= 0;)
  179017. {
  179018. *dst++ = ((const PixelRGB*) src)->getRed();
  179019. *dst++ = ((const PixelRGB*) src)->getGreen();
  179020. *dst++ = ((const PixelRGB*) src)->getBlue();
  179021. src += srcData.pixelStride;
  179022. }
  179023. }
  179024. png_write_rows (pngWriteStruct, &rowData, 1);
  179025. }
  179026. png_write_end (pngWriteStruct, pngInfoStruct);
  179027. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179028. out.flush();
  179029. return true;
  179030. }
  179031. END_JUCE_NAMESPACE
  179032. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179033. #endif
  179034. //==============================================================================
  179035. #if JUCE_BUILD_NATIVE
  179036. #if JUCE_WINDOWS
  179037. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179038. #if JUCE_WINDOWS
  179039. BEGIN_JUCE_NAMESPACE
  179040. #define JUCE_INCLUDED_FILE 1
  179041. // Now include the actual code files..
  179042. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179043. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179044. // compiled on its own).
  179045. #if JUCE_INCLUDED_FILE
  179046. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179047. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179048. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179049. #ifndef DOXYGEN
  179050. // use with DynamicLibraryLoader to simplify importing functions
  179051. //
  179052. // functionName: function to import
  179053. // localFunctionName: name you want to use to actually call it (must be different)
  179054. // returnType: the return type
  179055. // object: the DynamicLibraryLoader to use
  179056. // params: list of params (bracketed)
  179057. //
  179058. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179059. typedef returnType (WINAPI *type##localFunctionName) params; \
  179060. type##localFunctionName localFunctionName \
  179061. = (type##localFunctionName)object.findProcAddress (#functionName);
  179062. // loads and unloads a DLL automatically
  179063. class JUCE_API DynamicLibraryLoader
  179064. {
  179065. public:
  179066. DynamicLibraryLoader (const String& name);
  179067. ~DynamicLibraryLoader();
  179068. void* findProcAddress (const String& functionName);
  179069. private:
  179070. void* libHandle;
  179071. };
  179072. #endif
  179073. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179074. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179075. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179076. {
  179077. libHandle = LoadLibrary (name);
  179078. }
  179079. DynamicLibraryLoader::~DynamicLibraryLoader()
  179080. {
  179081. FreeLibrary ((HMODULE) libHandle);
  179082. }
  179083. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179084. {
  179085. return GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179086. }
  179087. #endif
  179088. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179089. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179090. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179091. // compiled on its own).
  179092. #if JUCE_INCLUDED_FILE
  179093. extern void juce_initialiseThreadEvents();
  179094. void Logger::outputDebugString (const String& text) throw()
  179095. {
  179096. OutputDebugString (text + "\n");
  179097. }
  179098. static int64 hiResTicksPerSecond;
  179099. static double hiResTicksScaleFactor;
  179100. #if JUCE_USE_INTRINSICS
  179101. // CPU info functions using intrinsics...
  179102. #pragma intrinsic (__cpuid)
  179103. #pragma intrinsic (__rdtsc)
  179104. const String SystemStats::getCpuVendor() throw()
  179105. {
  179106. int info [4];
  179107. __cpuid (info, 0);
  179108. char v [12];
  179109. memcpy (v, info + 1, 4);
  179110. memcpy (v + 4, info + 3, 4);
  179111. memcpy (v + 8, info + 2, 4);
  179112. return String (v, 12);
  179113. }
  179114. #else
  179115. // CPU info functions using old fashioned inline asm...
  179116. static void juce_getCpuVendor (char* const v)
  179117. {
  179118. int vendor[4];
  179119. zeromem (vendor, 16);
  179120. #ifdef JUCE_64BIT
  179121. #else
  179122. #ifndef __MINGW32__
  179123. __try
  179124. #endif
  179125. {
  179126. #if JUCE_GCC
  179127. unsigned int dummy = 0;
  179128. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179129. #else
  179130. __asm
  179131. {
  179132. mov eax, 0
  179133. cpuid
  179134. mov [vendor], ebx
  179135. mov [vendor + 4], edx
  179136. mov [vendor + 8], ecx
  179137. }
  179138. #endif
  179139. }
  179140. #ifndef __MINGW32__
  179141. __except (EXCEPTION_EXECUTE_HANDLER)
  179142. {
  179143. *v = 0;
  179144. }
  179145. #endif
  179146. #endif
  179147. memcpy (v, vendor, 16);
  179148. }
  179149. const String SystemStats::getCpuVendor() throw()
  179150. {
  179151. char v [16];
  179152. juce_getCpuVendor (v);
  179153. return String (v, 16);
  179154. }
  179155. #endif
  179156. struct CPUFlags
  179157. {
  179158. bool hasMMX : 1;
  179159. bool hasSSE : 1;
  179160. bool hasSSE2 : 1;
  179161. bool has3DNow : 1;
  179162. };
  179163. static CPUFlags cpuFlags;
  179164. bool SystemStats::hasMMX() throw()
  179165. {
  179166. return cpuFlags.hasMMX;
  179167. }
  179168. bool SystemStats::hasSSE() throw()
  179169. {
  179170. return cpuFlags.hasSSE;
  179171. }
  179172. bool SystemStats::hasSSE2() throw()
  179173. {
  179174. return cpuFlags.hasSSE2;
  179175. }
  179176. bool SystemStats::has3DNow() throw()
  179177. {
  179178. return cpuFlags.has3DNow;
  179179. }
  179180. void SystemStats::initialiseStats() throw()
  179181. {
  179182. juce_initialiseThreadEvents();
  179183. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179184. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179185. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179186. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179187. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179188. #else
  179189. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179190. #endif
  179191. LARGE_INTEGER f;
  179192. QueryPerformanceFrequency (&f);
  179193. hiResTicksPerSecond = f.QuadPart;
  179194. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179195. String s (SystemStats::getJUCEVersion());
  179196. #ifdef JUCE_DEBUG
  179197. const MMRESULT res = timeBeginPeriod (1);
  179198. jassert (res == TIMERR_NOERROR);
  179199. #else
  179200. timeBeginPeriod (1);
  179201. #endif
  179202. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179203. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179204. #endif
  179205. }
  179206. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179207. {
  179208. OSVERSIONINFO info;
  179209. info.dwOSVersionInfoSize = sizeof (info);
  179210. GetVersionEx (&info);
  179211. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179212. {
  179213. switch (info.dwMajorVersion)
  179214. {
  179215. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179216. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179217. default: jassertfalse; break; // !! not a supported OS!
  179218. }
  179219. }
  179220. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179221. {
  179222. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179223. return Win98;
  179224. }
  179225. return UnknownOS;
  179226. }
  179227. const String SystemStats::getOperatingSystemName() throw()
  179228. {
  179229. const char* name = "Unknown OS";
  179230. switch (getOperatingSystemType())
  179231. {
  179232. case Windows7: name = "Windows 7"; break;
  179233. case WinVista: name = "Windows Vista"; break;
  179234. case WinXP: name = "Windows XP"; break;
  179235. case Win2000: name = "Windows 2000"; break;
  179236. case Win98: name = "Windows 98"; break;
  179237. default: jassertfalse; break; // !! new type of OS?
  179238. }
  179239. return name;
  179240. }
  179241. bool SystemStats::isOperatingSystem64Bit() throw()
  179242. {
  179243. #ifdef _WIN64
  179244. return true;
  179245. #else
  179246. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179247. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179248. BOOL isWow64 = FALSE;
  179249. return (fnIsWow64Process != 0)
  179250. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179251. && (isWow64 != FALSE);
  179252. #endif
  179253. }
  179254. int SystemStats::getMemorySizeInMegabytes() throw()
  179255. {
  179256. MEMORYSTATUSEX mem;
  179257. mem.dwLength = sizeof (mem);
  179258. GlobalMemoryStatusEx (&mem);
  179259. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179260. }
  179261. int SystemStats::getNumCpus() throw()
  179262. {
  179263. SYSTEM_INFO systemInfo;
  179264. GetSystemInfo (&systemInfo);
  179265. return systemInfo.dwNumberOfProcessors;
  179266. }
  179267. uint32 juce_millisecondsSinceStartup() throw()
  179268. {
  179269. return (uint32) GetTickCount();
  179270. }
  179271. int64 Time::getHighResolutionTicks() throw()
  179272. {
  179273. LARGE_INTEGER ticks;
  179274. QueryPerformanceCounter (&ticks);
  179275. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179276. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179277. // fix for a very obscure PCI hardware bug that can make the counter
  179278. // sometimes jump forwards by a few seconds..
  179279. static int64 hiResTicksOffset = 0;
  179280. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179281. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179282. hiResTicksOffset = newOffset;
  179283. return ticks.QuadPart + hiResTicksOffset;
  179284. }
  179285. double Time::getMillisecondCounterHiRes() throw()
  179286. {
  179287. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179288. }
  179289. int64 Time::getHighResolutionTicksPerSecond() throw()
  179290. {
  179291. return hiResTicksPerSecond;
  179292. }
  179293. int64 SystemStats::getClockCycleCounter() throw()
  179294. {
  179295. #if JUCE_USE_INTRINSICS
  179296. // MS intrinsics version...
  179297. return __rdtsc();
  179298. #elif JUCE_GCC
  179299. // GNU inline asm version...
  179300. unsigned int hi = 0, lo = 0;
  179301. __asm__ __volatile__ (
  179302. "xor %%eax, %%eax \n\
  179303. xor %%edx, %%edx \n\
  179304. rdtsc \n\
  179305. movl %%eax, %[lo] \n\
  179306. movl %%edx, %[hi]"
  179307. :
  179308. : [hi] "m" (hi),
  179309. [lo] "m" (lo)
  179310. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179311. return (int64) ((((uint64) hi) << 32) | lo);
  179312. #else
  179313. // MSVC inline asm version...
  179314. unsigned int hi = 0, lo = 0;
  179315. __asm
  179316. {
  179317. xor eax, eax
  179318. xor edx, edx
  179319. rdtsc
  179320. mov lo, eax
  179321. mov hi, edx
  179322. }
  179323. return (int64) ((((uint64) hi) << 32) | lo);
  179324. #endif
  179325. }
  179326. int SystemStats::getCpuSpeedInMegaherz() throw()
  179327. {
  179328. const int64 cycles = SystemStats::getClockCycleCounter();
  179329. const uint32 millis = Time::getMillisecondCounter();
  179330. int lastResult = 0;
  179331. for (;;)
  179332. {
  179333. int n = 1000000;
  179334. while (--n > 0) {}
  179335. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179336. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179337. if (millisElapsed > 80)
  179338. {
  179339. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179340. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179341. return newResult;
  179342. lastResult = newResult;
  179343. }
  179344. }
  179345. }
  179346. bool Time::setSystemTimeToThisTime() const throw()
  179347. {
  179348. SYSTEMTIME st;
  179349. st.wDayOfWeek = 0;
  179350. st.wYear = (WORD) getYear();
  179351. st.wMonth = (WORD) (getMonth() + 1);
  179352. st.wDay = (WORD) getDayOfMonth();
  179353. st.wHour = (WORD) getHours();
  179354. st.wMinute = (WORD) getMinutes();
  179355. st.wSecond = (WORD) getSeconds();
  179356. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179357. // do this twice because of daylight saving conversion problems - the
  179358. // first one sets it up, the second one kicks it in.
  179359. return SetLocalTime (&st) != 0
  179360. && SetLocalTime (&st) != 0;
  179361. }
  179362. int SystemStats::getPageSize() throw()
  179363. {
  179364. SYSTEM_INFO systemInfo;
  179365. GetSystemInfo (&systemInfo);
  179366. return systemInfo.dwPageSize;
  179367. }
  179368. const String SystemStats::getLogonName()
  179369. {
  179370. TCHAR text [256];
  179371. DWORD len = numElementsInArray (text) - 2;
  179372. zerostruct (text);
  179373. GetUserName (text, &len);
  179374. return String (text, len);
  179375. }
  179376. const String SystemStats::getFullUserName()
  179377. {
  179378. return getLogonName();
  179379. }
  179380. #endif
  179381. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179382. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179383. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179384. // compiled on its own).
  179385. #if JUCE_INCLUDED_FILE
  179386. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179387. extern HWND juce_messageWindowHandle;
  179388. #endif
  179389. #if ! JUCE_USE_INTRINSICS
  179390. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179391. // older ones we have to actually call the ops as win32 functions..
  179392. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179393. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179394. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179395. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179396. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179397. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179398. #endif
  179399. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179400. CriticalSection::CriticalSection() throw()
  179401. {
  179402. // (just to check the MS haven't changed this structure and broken things...)
  179403. #if _MSC_VER >= 1400
  179404. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179405. #else
  179406. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179407. #endif
  179408. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179409. }
  179410. CriticalSection::~CriticalSection() throw()
  179411. {
  179412. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179413. }
  179414. void CriticalSection::enter() const throw()
  179415. {
  179416. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179417. }
  179418. bool CriticalSection::tryEnter() const throw()
  179419. {
  179420. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179421. }
  179422. void CriticalSection::exit() const throw()
  179423. {
  179424. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179425. }
  179426. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  179427. : internal (CreateEvent (0, manualReset ? TRUE : FALSE, FALSE, 0))
  179428. {
  179429. }
  179430. WaitableEvent::~WaitableEvent() throw()
  179431. {
  179432. CloseHandle (internal);
  179433. }
  179434. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179435. {
  179436. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179437. }
  179438. void WaitableEvent::signal() const throw()
  179439. {
  179440. SetEvent (internal);
  179441. }
  179442. void WaitableEvent::reset() const throw()
  179443. {
  179444. ResetEvent (internal);
  179445. }
  179446. void JUCE_API juce_threadEntryPoint (void*);
  179447. static unsigned int __stdcall threadEntryProc (void* userData)
  179448. {
  179449. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179450. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179451. GetCurrentThreadId(), TRUE);
  179452. #endif
  179453. juce_threadEntryPoint (userData);
  179454. _endthreadex (0);
  179455. return 0;
  179456. }
  179457. void juce_CloseThreadHandle (void* handle)
  179458. {
  179459. CloseHandle ((HANDLE) handle);
  179460. }
  179461. void* juce_createThread (void* userData)
  179462. {
  179463. unsigned int threadId;
  179464. return (void*) _beginthreadex (0, 0,
  179465. &threadEntryProc,
  179466. userData,
  179467. 0, &threadId);
  179468. }
  179469. void juce_killThread (void* handle)
  179470. {
  179471. if (handle != 0)
  179472. {
  179473. #ifdef JUCE_DEBUG
  179474. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179475. #endif
  179476. TerminateThread (handle, 0);
  179477. }
  179478. }
  179479. void juce_setCurrentThreadName (const String& name)
  179480. {
  179481. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179482. struct
  179483. {
  179484. DWORD dwType;
  179485. LPCSTR szName;
  179486. DWORD dwThreadID;
  179487. DWORD dwFlags;
  179488. } info;
  179489. info.dwType = 0x1000;
  179490. info.szName = name.toCString();
  179491. info.dwThreadID = GetCurrentThreadId();
  179492. info.dwFlags = 0;
  179493. __try
  179494. {
  179495. RaiseException (0x406d1388 /*MS_VC_EXCEPTION*/, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179496. }
  179497. __except (EXCEPTION_CONTINUE_EXECUTION)
  179498. {}
  179499. #else
  179500. (void) name;
  179501. #endif
  179502. }
  179503. Thread::ThreadID Thread::getCurrentThreadId()
  179504. {
  179505. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179506. }
  179507. // priority 1 to 10 where 5=normal, 1=low
  179508. bool juce_setThreadPriority (void* threadHandle, int priority)
  179509. {
  179510. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179511. if (priority < 1)
  179512. pri = THREAD_PRIORITY_IDLE;
  179513. else if (priority < 2)
  179514. pri = THREAD_PRIORITY_LOWEST;
  179515. else if (priority < 5)
  179516. pri = THREAD_PRIORITY_BELOW_NORMAL;
  179517. else if (priority < 7)
  179518. pri = THREAD_PRIORITY_NORMAL;
  179519. else if (priority < 9)
  179520. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  179521. else if (priority < 10)
  179522. pri = THREAD_PRIORITY_HIGHEST;
  179523. if (threadHandle == 0)
  179524. threadHandle = GetCurrentThread();
  179525. return SetThreadPriority (threadHandle, pri) != FALSE;
  179526. }
  179527. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  179528. {
  179529. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  179530. }
  179531. static HANDLE sleepEvent = 0;
  179532. void juce_initialiseThreadEvents()
  179533. {
  179534. if (sleepEvent == 0)
  179535. #ifdef JUCE_DEBUG
  179536. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  179537. #else
  179538. sleepEvent = CreateEvent (0, 0, 0, 0);
  179539. #endif
  179540. }
  179541. void Thread::yield()
  179542. {
  179543. Sleep (0);
  179544. }
  179545. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  179546. {
  179547. if (millisecs >= 10)
  179548. {
  179549. Sleep (millisecs);
  179550. }
  179551. else
  179552. {
  179553. jassert (sleepEvent != 0);
  179554. // unlike Sleep() this is guaranteed to return to the current thread after
  179555. // the time expires, so we'll use this for short waits, which are more likely
  179556. // to need to be accurate
  179557. WaitForSingleObject (sleepEvent, millisecs);
  179558. }
  179559. }
  179560. static int lastProcessPriority = -1;
  179561. // called by WindowDriver because Windows does wierd things to process priority
  179562. // when you swap apps, and this forces an update when the app is brought to the front.
  179563. void juce_repeatLastProcessPriority()
  179564. {
  179565. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  179566. {
  179567. DWORD p;
  179568. switch (lastProcessPriority)
  179569. {
  179570. case Process::LowPriority: p = IDLE_PRIORITY_CLASS; break;
  179571. case Process::NormalPriority: p = NORMAL_PRIORITY_CLASS; break;
  179572. case Process::HighPriority: p = HIGH_PRIORITY_CLASS; break;
  179573. case Process::RealtimePriority: p = REALTIME_PRIORITY_CLASS; break;
  179574. default: jassertfalse; return; // bad priority value
  179575. }
  179576. SetPriorityClass (GetCurrentProcess(), p);
  179577. }
  179578. }
  179579. void Process::setPriority (ProcessPriority prior)
  179580. {
  179581. if (lastProcessPriority != (int) prior)
  179582. {
  179583. lastProcessPriority = (int) prior;
  179584. juce_repeatLastProcessPriority();
  179585. }
  179586. }
  179587. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  179588. {
  179589. return IsDebuggerPresent() != FALSE;
  179590. }
  179591. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  179592. {
  179593. return juce_isRunningUnderDebugger();
  179594. }
  179595. void Process::raisePrivilege()
  179596. {
  179597. jassertfalse // xxx not implemented
  179598. }
  179599. void Process::lowerPrivilege()
  179600. {
  179601. jassertfalse // xxx not implemented
  179602. }
  179603. void Process::terminate()
  179604. {
  179605. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179606. _CrtDumpMemoryLeaks();
  179607. #endif
  179608. // bullet in the head in case there's a problem shutting down..
  179609. ExitProcess (0);
  179610. }
  179611. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  179612. {
  179613. void* result = 0;
  179614. JUCE_TRY
  179615. {
  179616. result = LoadLibrary (name);
  179617. }
  179618. JUCE_CATCH_ALL
  179619. return result;
  179620. }
  179621. void PlatformUtilities::freeDynamicLibrary (void* h)
  179622. {
  179623. JUCE_TRY
  179624. {
  179625. if (h != 0)
  179626. FreeLibrary ((HMODULE) h);
  179627. }
  179628. JUCE_CATCH_ALL
  179629. }
  179630. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  179631. {
  179632. return (h != 0) ? GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  179633. }
  179634. class InterProcessLock::Pimpl
  179635. {
  179636. public:
  179637. Pimpl (const String& name, const int timeOutMillisecs)
  179638. : handle (0), refCount (1)
  179639. {
  179640. handle = CreateMutex (0, TRUE, "Global\\" + name.replaceCharacter ('\\','/'));
  179641. if (handle != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  179642. {
  179643. if (timeOutMillisecs == 0)
  179644. {
  179645. close();
  179646. return;
  179647. }
  179648. switch (WaitForSingleObject (handle, timeOutMillisecs < 0 ? INFINITE : timeOutMillisecs))
  179649. {
  179650. case WAIT_OBJECT_0:
  179651. case WAIT_ABANDONED:
  179652. break;
  179653. case WAIT_TIMEOUT:
  179654. default:
  179655. close();
  179656. break;
  179657. }
  179658. }
  179659. }
  179660. ~Pimpl()
  179661. {
  179662. close();
  179663. }
  179664. void close()
  179665. {
  179666. if (handle != 0)
  179667. {
  179668. ReleaseMutex (handle);
  179669. CloseHandle (handle);
  179670. handle = 0;
  179671. }
  179672. }
  179673. HANDLE handle;
  179674. int refCount;
  179675. };
  179676. InterProcessLock::InterProcessLock (const String& name_)
  179677. : name (name_)
  179678. {
  179679. }
  179680. InterProcessLock::~InterProcessLock()
  179681. {
  179682. }
  179683. bool InterProcessLock::enter (const int timeOutMillisecs)
  179684. {
  179685. const ScopedLock sl (lock);
  179686. if (pimpl == 0)
  179687. {
  179688. pimpl = new Pimpl (name, timeOutMillisecs);
  179689. if (pimpl->handle == 0)
  179690. pimpl = 0;
  179691. }
  179692. else
  179693. {
  179694. pimpl->refCount++;
  179695. }
  179696. return pimpl != 0;
  179697. }
  179698. void InterProcessLock::exit()
  179699. {
  179700. const ScopedLock sl (lock);
  179701. // Trying to release the lock too many times!
  179702. jassert (pimpl != 0);
  179703. if (pimpl != 0 && --(pimpl->refCount) == 0)
  179704. pimpl = 0;
  179705. }
  179706. #endif
  179707. /*** End of inlined file: juce_win32_Threads.cpp ***/
  179708. /*** Start of inlined file: juce_win32_Files.cpp ***/
  179709. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179710. // compiled on its own).
  179711. #if JUCE_INCLUDED_FILE
  179712. #ifndef CSIDL_MYMUSIC
  179713. #define CSIDL_MYMUSIC 0x000d
  179714. #endif
  179715. #ifndef CSIDL_MYVIDEO
  179716. #define CSIDL_MYVIDEO 0x000e
  179717. #endif
  179718. #ifndef INVALID_FILE_ATTRIBUTES
  179719. #define INVALID_FILE_ATTRIBUTES ((DWORD) -1)
  179720. #endif
  179721. const juce_wchar File::separator = '\\';
  179722. const juce_wchar* File::separatorString = T("\\");
  179723. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  179724. {
  179725. if (fileName.isEmpty())
  179726. return false;
  179727. const DWORD attr = GetFileAttributes (fileName);
  179728. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  179729. : (attr != INVALID_FILE_ATTRIBUTES);
  179730. }
  179731. bool juce_isDirectory (const String& fileName)
  179732. {
  179733. const DWORD attr = GetFileAttributes (fileName);
  179734. return ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) && (attr != INVALID_FILE_ATTRIBUTES);
  179735. }
  179736. bool juce_canWriteToFile (const String& fileName)
  179737. {
  179738. const DWORD attr = GetFileAttributes (fileName);
  179739. return (attr & FILE_ATTRIBUTE_READONLY) == 0;
  179740. }
  179741. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  179742. {
  179743. DWORD attr = GetFileAttributes (fileName);
  179744. if (attr == INVALID_FILE_ATTRIBUTES)
  179745. return false;
  179746. if (isReadOnly != juce_canWriteToFile (fileName))
  179747. return true;
  179748. if (isReadOnly)
  179749. attr |= FILE_ATTRIBUTE_READONLY;
  179750. else
  179751. attr &= ~FILE_ATTRIBUTE_READONLY;
  179752. return SetFileAttributes (fileName, attr) != FALSE;
  179753. }
  179754. bool File::isHidden() const
  179755. {
  179756. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  179757. }
  179758. bool juce_deleteFile (const String& fileName)
  179759. {
  179760. if (juce_isDirectory (fileName))
  179761. return RemoveDirectory (fileName) != 0;
  179762. return DeleteFile (fileName) != 0;
  179763. }
  179764. bool File::moveToTrash() const
  179765. {
  179766. if (! exists())
  179767. return true;
  179768. SHFILEOPSTRUCT fos;
  179769. zerostruct (fos);
  179770. // The string we pass in must be double null terminated..
  179771. String doubleNullTermPath (getFullPathName() + " ");
  179772. TCHAR* const p = const_cast <TCHAR*> (static_cast <const TCHAR*> (doubleNullTermPath));
  179773. p [getFullPathName().length()] = 0;
  179774. fos.wFunc = FO_DELETE;
  179775. fos.pFrom = p;
  179776. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  179777. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  179778. return SHFileOperation (&fos) == 0;
  179779. }
  179780. bool juce_moveFile (const String& source, const String& dest)
  179781. {
  179782. return MoveFile (source, dest) != 0;
  179783. }
  179784. bool juce_copyFile (const String& source, const String& dest)
  179785. {
  179786. return CopyFile (source, dest, false) != 0;
  179787. }
  179788. void juce_createDirectory (const String& fileName)
  179789. {
  179790. if (! juce_fileExists (fileName, true))
  179791. CreateDirectory (fileName, 0);
  179792. }
  179793. // return 0 if not possible
  179794. void* juce_fileOpen (const String& fileName, bool forWriting)
  179795. {
  179796. HANDLE h;
  179797. if (forWriting)
  179798. {
  179799. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  179800. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  179801. if (h != INVALID_HANDLE_VALUE)
  179802. SetFilePointer (h, 0, 0, FILE_END);
  179803. else
  179804. h = 0;
  179805. }
  179806. else
  179807. {
  179808. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  179809. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  179810. if (h == INVALID_HANDLE_VALUE)
  179811. h = 0;
  179812. }
  179813. return h;
  179814. }
  179815. void juce_fileClose (void* handle)
  179816. {
  179817. CloseHandle (handle);
  179818. }
  179819. int juce_fileRead (void* handle, void* buffer, int size)
  179820. {
  179821. DWORD num = 0;
  179822. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  179823. return (int) num;
  179824. }
  179825. int juce_fileWrite (void* handle, const void* buffer, int size)
  179826. {
  179827. DWORD num;
  179828. WriteFile ((HANDLE) handle, buffer, size, &num, 0);
  179829. return (int) num;
  179830. }
  179831. int64 juce_fileSetPosition (void* handle, int64 pos)
  179832. {
  179833. LARGE_INTEGER li;
  179834. li.QuadPart = pos;
  179835. li.LowPart = SetFilePointer ((HANDLE) handle, li.LowPart, &li.HighPart, FILE_BEGIN); // (returns -1 if it fails)
  179836. return li.QuadPart;
  179837. }
  179838. int64 juce_fileGetPosition (void* handle)
  179839. {
  179840. LARGE_INTEGER li;
  179841. li.QuadPart = 0;
  179842. li.LowPart = SetFilePointer ((HANDLE) handle, 0, &li.HighPart, FILE_CURRENT); // (returns -1 if it fails)
  179843. return jmax ((int64) 0, li.QuadPart);
  179844. }
  179845. void juce_fileFlush (void* handle)
  179846. {
  179847. FlushFileBuffers ((HANDLE) handle);
  179848. }
  179849. int64 juce_getFileSize (const String& fileName)
  179850. {
  179851. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179852. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179853. return (((int64) attributes.nFileSizeHigh) << 32) | attributes.nFileSizeLow;
  179854. return 0;
  179855. }
  179856. static int64 fileTimeToTime (const FILETIME* const ft)
  179857. {
  179858. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME)); // tell me if this fails!
  179859. return (reinterpret_cast<const ULARGE_INTEGER*> (ft)->QuadPart - literal64bit (116444736000000000)) / 10000;
  179860. }
  179861. static void timeToFileTime (const int64 time, FILETIME* const ft)
  179862. {
  179863. reinterpret_cast<ULARGE_INTEGER*> (ft)->QuadPart = time * 10000 + literal64bit (116444736000000000);
  179864. }
  179865. void juce_getFileTimes (const String& fileName,
  179866. int64& modificationTime,
  179867. int64& accessTime,
  179868. int64& creationTime)
  179869. {
  179870. WIN32_FILE_ATTRIBUTE_DATA attributes;
  179871. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  179872. {
  179873. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  179874. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  179875. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  179876. }
  179877. else
  179878. {
  179879. creationTime = accessTime = modificationTime = 0;
  179880. }
  179881. }
  179882. bool juce_setFileTimes (const String& fileName,
  179883. int64 modificationTime,
  179884. int64 accessTime,
  179885. int64 creationTime)
  179886. {
  179887. void* const h = juce_fileOpen (fileName, true);
  179888. bool ok = false;
  179889. if (h != 0)
  179890. {
  179891. FILETIME m, a, c;
  179892. timeToFileTime (modificationTime, &m);
  179893. timeToFileTime (accessTime, &a);
  179894. timeToFileTime (creationTime, &c);
  179895. ok = SetFileTime ((HANDLE) h,
  179896. creationTime > 0 ? &c : 0,
  179897. accessTime > 0 ? &a : 0,
  179898. modificationTime > 0 ? &m : 0) != 0;
  179899. juce_fileClose (h);
  179900. }
  179901. return ok;
  179902. }
  179903. // return '\0' separated list of strings
  179904. const StringArray juce_getFileSystemRoots()
  179905. {
  179906. TCHAR buffer [2048];
  179907. buffer[0] = 0;
  179908. buffer[1] = 0;
  179909. GetLogicalDriveStrings (2048, buffer);
  179910. const TCHAR* n = buffer;
  179911. StringArray roots;
  179912. while (*n != 0)
  179913. {
  179914. roots.add (String (n));
  179915. while (*n++ != 0)
  179916. {}
  179917. }
  179918. roots.sort (true);
  179919. return roots;
  179920. }
  179921. static const String getDriveFromPath (const String& path)
  179922. {
  179923. if (path.isNotEmpty() && path[1] == ':')
  179924. return path.substring (0, 2) + '\\';
  179925. return path;
  179926. }
  179927. const String juce_getVolumeLabel (const String& filenameOnVolume,
  179928. int& volumeSerialNumber)
  179929. {
  179930. TCHAR dest[64];
  179931. DWORD serialNum;
  179932. if (! GetVolumeInformation (getDriveFromPath (filenameOnVolume), dest,
  179933. numElementsInArray (dest), &serialNum, 0, 0, 0, 0))
  179934. {
  179935. dest[0] = 0;
  179936. serialNum = 0;
  179937. }
  179938. volumeSerialNumber = serialNum;
  179939. return dest;
  179940. }
  179941. static int64 getDiskSpaceInfo (const String& path, const bool total)
  179942. {
  179943. ULARGE_INTEGER spc, tot, totFree;
  179944. if (GetDiskFreeSpaceEx (getDriveFromPath (path), &spc, &tot, &totFree))
  179945. return total ? (int64) tot.QuadPart
  179946. : (int64) spc.QuadPart;
  179947. return 0;
  179948. }
  179949. int64 File::getBytesFreeOnVolume() const
  179950. {
  179951. return getDiskSpaceInfo (getFullPathName(), false);
  179952. }
  179953. int64 File::getVolumeTotalSize() const
  179954. {
  179955. return getDiskSpaceInfo (getFullPathName(), true);
  179956. }
  179957. static unsigned int getWindowsDriveType (const String& path)
  179958. {
  179959. return GetDriveType (getDriveFromPath (path));
  179960. }
  179961. bool File::isOnCDRomDrive() const
  179962. {
  179963. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  179964. }
  179965. bool File::isOnHardDisk() const
  179966. {
  179967. if (fullPath.isEmpty())
  179968. return false;
  179969. const unsigned int n = getWindowsDriveType (getFullPathName());
  179970. if (fullPath.toLowerCase()[0] <= 'b' && fullPath[1] == ':')
  179971. return n != DRIVE_REMOVABLE;
  179972. else
  179973. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  179974. }
  179975. bool File::isOnRemovableDrive() const
  179976. {
  179977. if (fullPath.isEmpty())
  179978. return false;
  179979. const unsigned int n = getWindowsDriveType (getFullPathName());
  179980. return n == DRIVE_CDROM
  179981. || n == DRIVE_REMOTE
  179982. || n == DRIVE_REMOVABLE
  179983. || n == DRIVE_RAMDISK;
  179984. }
  179985. static const File juce_getSpecialFolderPath (int type)
  179986. {
  179987. WCHAR path [MAX_PATH + 256];
  179988. if (SHGetSpecialFolderPath (0, path, type, FALSE))
  179989. return File (String (path));
  179990. return File::nonexistent;
  179991. }
  179992. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  179993. {
  179994. int csidlType = 0;
  179995. switch (type)
  179996. {
  179997. case userHomeDirectory: csidlType = CSIDL_PROFILE; break;
  179998. case userDocumentsDirectory: csidlType = CSIDL_PERSONAL; break;
  179999. case userDesktopDirectory: csidlType = CSIDL_DESKTOP; break;
  180000. case userApplicationDataDirectory: csidlType = CSIDL_APPDATA; break;
  180001. case commonApplicationDataDirectory: csidlType = CSIDL_COMMON_APPDATA; break;
  180002. case globalApplicationsDirectory: csidlType = CSIDL_PROGRAM_FILES; break;
  180003. case userMusicDirectory: csidlType = CSIDL_MYMUSIC; break;
  180004. case userMoviesDirectory: csidlType = CSIDL_MYVIDEO; break;
  180005. case tempDirectory:
  180006. {
  180007. WCHAR dest [2048];
  180008. dest[0] = 0;
  180009. GetTempPath (numElementsInArray (dest), dest);
  180010. return File (String (dest));
  180011. }
  180012. case invokedExecutableFile:
  180013. case currentExecutableFile:
  180014. case currentApplicationFile:
  180015. {
  180016. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180017. WCHAR dest [MAX_PATH + 256];
  180018. dest[0] = 0;
  180019. GetModuleFileName (moduleHandle, dest, numElementsInArray (dest));
  180020. return File (String (dest));
  180021. }
  180022. break;
  180023. default:
  180024. jassertfalse // unknown type?
  180025. return File::nonexistent;
  180026. }
  180027. return juce_getSpecialFolderPath (csidlType);
  180028. }
  180029. const File File::getCurrentWorkingDirectory()
  180030. {
  180031. WCHAR dest [MAX_PATH + 256];
  180032. dest[0] = 0;
  180033. GetCurrentDirectory (numElementsInArray (dest), dest);
  180034. return File (String (dest));
  180035. }
  180036. bool File::setAsCurrentWorkingDirectory() const
  180037. {
  180038. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180039. }
  180040. const String File::getVersion() const
  180041. {
  180042. String result;
  180043. DWORD handle = 0;
  180044. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180045. HeapBlock<char> buffer;
  180046. buffer.calloc (bufferSize);
  180047. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180048. {
  180049. VS_FIXEDFILEINFO* vffi;
  180050. UINT len = 0;
  180051. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180052. {
  180053. result << (int) HIWORD (vffi->dwFileVersionMS) << '.'
  180054. << (int) LOWORD (vffi->dwFileVersionMS) << '.'
  180055. << (int) HIWORD (vffi->dwFileVersionLS) << '.'
  180056. << (int) LOWORD (vffi->dwFileVersionLS);
  180057. }
  180058. }
  180059. return result;
  180060. }
  180061. const File File::getLinkedTarget() const
  180062. {
  180063. File result (*this);
  180064. String p (getFullPathName());
  180065. if (! exists())
  180066. p += ".lnk";
  180067. else if (getFileExtension() != ".lnk")
  180068. return result;
  180069. ComSmartPtr <IShellLink> shellLink;
  180070. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180071. {
  180072. ComSmartPtr <IPersistFile> persistFile;
  180073. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180074. {
  180075. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180076. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180077. {
  180078. WIN32_FIND_DATA winFindData;
  180079. WCHAR resolvedPath [MAX_PATH];
  180080. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180081. result = File (resolvedPath);
  180082. }
  180083. }
  180084. }
  180085. return result;
  180086. }
  180087. template <class FindDataType>
  180088. static void getFindFileInfo (FindDataType& findData,
  180089. String& filename, bool* const isDir, bool* const isHidden,
  180090. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180091. bool* const isReadOnly)
  180092. {
  180093. filename = findData.cFileName;
  180094. if (isDir != 0)
  180095. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180096. if (isHidden != 0)
  180097. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180098. if (fileSize != 0)
  180099. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180100. if (modTime != 0)
  180101. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180102. if (creationTime != 0)
  180103. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180104. if (isReadOnly != 0)
  180105. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180106. }
  180107. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180108. bool* isDir, bool* isHidden, int64* fileSize,
  180109. Time* modTime, Time* creationTime, bool* isReadOnly)
  180110. {
  180111. String wc (directory);
  180112. if (! wc.endsWithChar (File::separator))
  180113. wc += File::separator;
  180114. wc += wildCard;
  180115. WIN32_FIND_DATA findData;
  180116. HANDLE h = FindFirstFile (wc, &findData);
  180117. if (h != INVALID_HANDLE_VALUE)
  180118. {
  180119. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180120. modTime, creationTime, isReadOnly);
  180121. return h;
  180122. }
  180123. firstResult = String::empty;
  180124. return 0;
  180125. }
  180126. bool juce_findFileNext (void* handle, String& resultFile,
  180127. bool* isDir, bool* isHidden, int64* fileSize,
  180128. Time* modTime, Time* creationTime, bool* isReadOnly)
  180129. {
  180130. WIN32_FIND_DATA findData;
  180131. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180132. {
  180133. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180134. modTime, creationTime, isReadOnly);
  180135. return true;
  180136. }
  180137. resultFile = String::empty;
  180138. return false;
  180139. }
  180140. void juce_findFileClose (void* handle)
  180141. {
  180142. FindClose (handle);
  180143. }
  180144. bool juce_launchFile (const String& fileName, const String& parameters)
  180145. {
  180146. HINSTANCE hInstance = 0;
  180147. JUCE_TRY
  180148. {
  180149. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180150. }
  180151. JUCE_CATCH_ALL
  180152. return hInstance > (HINSTANCE) 32;
  180153. }
  180154. void File::revealToUser() const
  180155. {
  180156. if (isDirectory())
  180157. startAsProcess();
  180158. else if (getParentDirectory().exists())
  180159. getParentDirectory().startAsProcess();
  180160. }
  180161. class NamedPipeInternal
  180162. {
  180163. public:
  180164. NamedPipeInternal (const String& file, const bool isPipe_)
  180165. : pipeH (0),
  180166. cancelEvent (0),
  180167. connected (false),
  180168. isPipe (isPipe_)
  180169. {
  180170. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180171. pipeH = isPipe ? CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180172. PIPE_UNLIMITED_INSTANCES, 4096, 4096, 0, 0)
  180173. : CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0,
  180174. OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
  180175. }
  180176. ~NamedPipeInternal()
  180177. {
  180178. disconnectPipe();
  180179. if (pipeH != 0)
  180180. CloseHandle (pipeH);
  180181. CloseHandle (cancelEvent);
  180182. }
  180183. bool connect (const int timeOutMs)
  180184. {
  180185. if (! isPipe)
  180186. return true;
  180187. if (! connected)
  180188. {
  180189. OVERLAPPED over;
  180190. zerostruct (over);
  180191. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180192. if (ConnectNamedPipe (pipeH, &over))
  180193. {
  180194. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180195. }
  180196. else
  180197. {
  180198. const int err = GetLastError();
  180199. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180200. {
  180201. HANDLE handles[] = { over.hEvent, cancelEvent };
  180202. if (WaitForMultipleObjects (2, handles, FALSE,
  180203. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180204. connected = true;
  180205. }
  180206. else if (err == ERROR_PIPE_CONNECTED)
  180207. {
  180208. connected = true;
  180209. }
  180210. }
  180211. CloseHandle (over.hEvent);
  180212. }
  180213. return connected;
  180214. }
  180215. void disconnectPipe()
  180216. {
  180217. if (connected)
  180218. {
  180219. DisconnectNamedPipe (pipeH);
  180220. connected = false;
  180221. }
  180222. }
  180223. HANDLE pipeH;
  180224. HANDLE cancelEvent;
  180225. bool connected, isPipe;
  180226. };
  180227. void NamedPipe::close()
  180228. {
  180229. cancelPendingReads();
  180230. const ScopedLock sl (lock);
  180231. delete static_cast<NamedPipeInternal*> (internal);
  180232. internal = 0;
  180233. }
  180234. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180235. {
  180236. close();
  180237. ScopedPointer<NamedPipeInternal> intern (new NamedPipeInternal ("\\\\.\\pipe\\" + pipeName, createPipe));
  180238. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180239. {
  180240. internal = intern.release();
  180241. return true;
  180242. }
  180243. return false;
  180244. }
  180245. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180246. {
  180247. const ScopedLock sl (lock);
  180248. int bytesRead = -1;
  180249. bool waitAgain = true;
  180250. while (waitAgain && internal != 0)
  180251. {
  180252. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180253. waitAgain = false;
  180254. if (! intern->connect (timeOutMilliseconds))
  180255. break;
  180256. if (maxBytesToRead <= 0)
  180257. return 0;
  180258. OVERLAPPED over;
  180259. zerostruct (over);
  180260. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180261. unsigned long numRead;
  180262. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180263. {
  180264. bytesRead = (int) numRead;
  180265. }
  180266. else if (GetLastError() == ERROR_IO_PENDING)
  180267. {
  180268. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180269. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180270. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180271. : INFINITE);
  180272. if (waitResult != WAIT_OBJECT_0)
  180273. {
  180274. // if the operation timed out, let's cancel it...
  180275. CancelIo (intern->pipeH);
  180276. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180277. }
  180278. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180279. {
  180280. bytesRead = (int) numRead;
  180281. }
  180282. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180283. {
  180284. intern->disconnectPipe();
  180285. waitAgain = true;
  180286. }
  180287. }
  180288. else
  180289. {
  180290. waitAgain = internal != 0;
  180291. Sleep (5);
  180292. }
  180293. CloseHandle (over.hEvent);
  180294. }
  180295. return bytesRead;
  180296. }
  180297. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180298. {
  180299. int bytesWritten = -1;
  180300. NamedPipeInternal* const intern = static_cast<NamedPipeInternal*> (internal);
  180301. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180302. {
  180303. if (numBytesToWrite <= 0)
  180304. return 0;
  180305. OVERLAPPED over;
  180306. zerostruct (over);
  180307. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180308. unsigned long numWritten;
  180309. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180310. {
  180311. bytesWritten = (int) numWritten;
  180312. }
  180313. else if (GetLastError() == ERROR_IO_PENDING)
  180314. {
  180315. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180316. DWORD waitResult;
  180317. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180318. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180319. : INFINITE);
  180320. if (waitResult != WAIT_OBJECT_0)
  180321. {
  180322. CancelIo (intern->pipeH);
  180323. WaitForSingleObject (over.hEvent, INFINITE);
  180324. }
  180325. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180326. {
  180327. bytesWritten = (int) numWritten;
  180328. }
  180329. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->isPipe)
  180330. {
  180331. intern->disconnectPipe();
  180332. }
  180333. }
  180334. CloseHandle (over.hEvent);
  180335. }
  180336. return bytesWritten;
  180337. }
  180338. void NamedPipe::cancelPendingReads()
  180339. {
  180340. if (internal != 0)
  180341. SetEvent (static_cast<NamedPipeInternal*> (internal)->cancelEvent);
  180342. }
  180343. #endif
  180344. /*** End of inlined file: juce_win32_Files.cpp ***/
  180345. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180346. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180347. // compiled on its own).
  180348. #if JUCE_INCLUDED_FILE
  180349. #ifndef INTERNET_FLAG_NEED_FILE
  180350. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180351. #endif
  180352. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180353. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180354. #endif
  180355. bool juce_isOnLine()
  180356. {
  180357. DWORD connectionType;
  180358. return InternetGetConnectedState (&connectionType, 0) != 0
  180359. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180360. }
  180361. struct ConnectionAndRequestStruct
  180362. {
  180363. HINTERNET connection, request;
  180364. };
  180365. static HINTERNET sessionHandle = 0;
  180366. #ifndef WORKAROUND_TIMEOUT_BUG
  180367. //#define WORKAROUND_TIMEOUT_BUG 1
  180368. #endif
  180369. #if WORKAROUND_TIMEOUT_BUG
  180370. // Required because of a Microsoft bug in setting a timeout
  180371. class InternetConnectThread : public Thread
  180372. {
  180373. public:
  180374. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180375. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180376. {
  180377. startThread();
  180378. }
  180379. ~InternetConnectThread()
  180380. {
  180381. stopThread (60000);
  180382. }
  180383. void run()
  180384. {
  180385. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180386. uc.nPort, _T(""), _T(""),
  180387. isFtp ? INTERNET_SERVICE_FTP
  180388. : INTERNET_SERVICE_HTTP,
  180389. 0, 0);
  180390. notify();
  180391. }
  180392. juce_UseDebuggingNewOperator
  180393. private:
  180394. URL_COMPONENTS& uc;
  180395. HINTERNET& connection;
  180396. const bool isFtp;
  180397. InternetConnectThread (const InternetConnectThread&);
  180398. InternetConnectThread& operator= (const InternetConnectThread&);
  180399. };
  180400. #endif
  180401. void* juce_openInternetFile (const String& url,
  180402. const String& headers,
  180403. const MemoryBlock& postData,
  180404. const bool isPost,
  180405. URL::OpenStreamProgressCallback* callback,
  180406. void* callbackContext,
  180407. int timeOutMs)
  180408. {
  180409. if (sessionHandle == 0)
  180410. sessionHandle = InternetOpen (_T("juce"),
  180411. INTERNET_OPEN_TYPE_PRECONFIG,
  180412. 0, 0, 0);
  180413. if (sessionHandle != 0)
  180414. {
  180415. // break up the url..
  180416. TCHAR file[1024], server[1024];
  180417. URL_COMPONENTS uc;
  180418. zerostruct (uc);
  180419. uc.dwStructSize = sizeof (uc);
  180420. uc.dwUrlPathLength = sizeof (file);
  180421. uc.dwHostNameLength = sizeof (server);
  180422. uc.lpszUrlPath = file;
  180423. uc.lpszHostName = server;
  180424. if (InternetCrackUrl (url, 0, 0, &uc))
  180425. {
  180426. int disable = 1;
  180427. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180428. if (timeOutMs == 0)
  180429. timeOutMs = 30000;
  180430. else if (timeOutMs < 0)
  180431. timeOutMs = -1;
  180432. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180433. const bool isFtp = url.startsWithIgnoreCase ("ftp:");
  180434. #if WORKAROUND_TIMEOUT_BUG
  180435. HINTERNET connection = 0;
  180436. {
  180437. InternetConnectThread connectThread (uc, connection, isFtp);
  180438. connectThread.wait (timeOutMs);
  180439. if (connection == 0)
  180440. {
  180441. InternetCloseHandle (sessionHandle);
  180442. sessionHandle = 0;
  180443. }
  180444. }
  180445. #else
  180446. HINTERNET connection = InternetConnect (sessionHandle,
  180447. uc.lpszHostName,
  180448. uc.nPort,
  180449. _T(""), _T(""),
  180450. isFtp ? INTERNET_SERVICE_FTP
  180451. : INTERNET_SERVICE_HTTP,
  180452. 0, 0);
  180453. #endif
  180454. if (connection != 0)
  180455. {
  180456. if (isFtp)
  180457. {
  180458. HINTERNET request = FtpOpenFile (connection,
  180459. uc.lpszUrlPath,
  180460. GENERIC_READ,
  180461. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180462. 0);
  180463. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180464. result->connection = connection;
  180465. result->request = request;
  180466. return result;
  180467. }
  180468. else
  180469. {
  180470. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180471. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180472. if (url.startsWithIgnoreCase ("https:"))
  180473. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180474. // IE7 seems to automatically work out when it's https)
  180475. HINTERNET request = HttpOpenRequest (connection,
  180476. isPost ? _T("POST")
  180477. : _T("GET"),
  180478. uc.lpszUrlPath,
  180479. 0, 0, mimeTypes, flags, 0);
  180480. if (request != 0)
  180481. {
  180482. INTERNET_BUFFERS buffers;
  180483. zerostruct (buffers);
  180484. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  180485. buffers.lpcszHeader = (LPCTSTR) headers;
  180486. buffers.dwHeadersLength = headers.length();
  180487. buffers.dwBufferTotal = (DWORD) postData.getSize();
  180488. ConnectionAndRequestStruct* result = 0;
  180489. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  180490. {
  180491. int bytesSent = 0;
  180492. for (;;)
  180493. {
  180494. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  180495. DWORD bytesDone = 0;
  180496. if (bytesToDo > 0
  180497. && ! InternetWriteFile (request,
  180498. static_cast <const char*> (postData.getData()) + bytesSent,
  180499. bytesToDo, &bytesDone))
  180500. {
  180501. break;
  180502. }
  180503. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  180504. {
  180505. result = new ConnectionAndRequestStruct();
  180506. result->connection = connection;
  180507. result->request = request;
  180508. HttpEndRequest (request, 0, 0, 0);
  180509. return result;
  180510. }
  180511. bytesSent += bytesDone;
  180512. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  180513. break;
  180514. }
  180515. }
  180516. InternetCloseHandle (request);
  180517. }
  180518. InternetCloseHandle (connection);
  180519. }
  180520. }
  180521. }
  180522. }
  180523. return 0;
  180524. }
  180525. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  180526. {
  180527. DWORD bytesRead = 0;
  180528. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180529. if (crs != 0)
  180530. InternetReadFile (crs->request,
  180531. buffer, bytesToRead,
  180532. &bytesRead);
  180533. return bytesRead;
  180534. }
  180535. int juce_seekInInternetFile (void* handle, int newPosition)
  180536. {
  180537. if (handle != 0)
  180538. {
  180539. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180540. return InternetSetFilePointer (crs->request, newPosition, 0, FILE_BEGIN, 0);
  180541. }
  180542. else
  180543. {
  180544. return -1;
  180545. }
  180546. }
  180547. int64 juce_getInternetFileContentLength (void* handle)
  180548. {
  180549. const ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180550. if (crs != 0)
  180551. {
  180552. DWORD index = 0, result = 0, size = sizeof (result);
  180553. if (HttpQueryInfo (crs->request, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  180554. &result, &size, &index))
  180555. {
  180556. return (int64) result;
  180557. }
  180558. }
  180559. return -1;
  180560. }
  180561. void juce_closeInternetFile (void* handle)
  180562. {
  180563. if (handle != 0)
  180564. {
  180565. ConnectionAndRequestStruct* const crs = static_cast <ConnectionAndRequestStruct*> (handle);
  180566. InternetCloseHandle (crs->request);
  180567. InternetCloseHandle (crs->connection);
  180568. delete crs;
  180569. }
  180570. }
  180571. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  180572. {
  180573. int numFound = 0;
  180574. DynamicLibraryLoader dll ("iphlpapi.dll");
  180575. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  180576. if (getAdaptersInfo != 0)
  180577. {
  180578. ULONG len = sizeof (IP_ADAPTER_INFO);
  180579. MemoryBlock mb;
  180580. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180581. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  180582. {
  180583. mb.setSize (len);
  180584. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  180585. }
  180586. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  180587. {
  180588. PIP_ADAPTER_INFO adapter = adapterInfo;
  180589. while (adapter != 0)
  180590. {
  180591. int64 mac = 0;
  180592. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  180593. mac = (mac << 8) | adapter->Address[i];
  180594. if (littleEndian)
  180595. mac = (int64) ByteOrder::swap ((uint64) mac);
  180596. if (numFound < maxNum && mac != 0)
  180597. addresses [numFound++] = mac;
  180598. adapter = adapter->Next;
  180599. }
  180600. }
  180601. }
  180602. return numFound;
  180603. }
  180604. struct ASTAT
  180605. {
  180606. ADAPTER_STATUS adapt;
  180607. NAME_BUFFER NameBuff [30];
  180608. };
  180609. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  180610. {
  180611. int numFound = 0;
  180612. DynamicLibraryLoader dll ("netapi32.dll");
  180613. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  180614. if (NetbiosCall != 0)
  180615. {
  180616. NCB ncb;
  180617. zerostruct (ncb);
  180618. ASTAT astat;
  180619. zerostruct (astat);
  180620. LANA_ENUM enums;
  180621. zerostruct (enums);
  180622. ncb.ncb_command = NCBENUM;
  180623. ncb.ncb_buffer = (unsigned char*) &enums;
  180624. ncb.ncb_length = sizeof (LANA_ENUM);
  180625. NetbiosCall (&ncb);
  180626. for (int i = 0; i < enums.length; ++i)
  180627. {
  180628. zerostruct (ncb);
  180629. ncb.ncb_command = NCBRESET;
  180630. ncb.ncb_lana_num = enums.lana[i];
  180631. if (NetbiosCall (&ncb) == 0)
  180632. {
  180633. zerostruct (ncb);
  180634. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  180635. ncb.ncb_command = NCBASTAT;
  180636. ncb.ncb_lana_num = enums.lana[i];
  180637. ncb.ncb_buffer = (unsigned char*) &astat;
  180638. ncb.ncb_length = sizeof (ASTAT);
  180639. if (NetbiosCall (&ncb) == 0)
  180640. {
  180641. if (astat.adapt.adapter_type == 0xfe)
  180642. {
  180643. uint64 mac = 0;
  180644. for (int i = 6; --i >= 0;)
  180645. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  180646. if (numFound < maxNum && mac != 0)
  180647. addresses [numFound++] = mac;
  180648. }
  180649. }
  180650. }
  180651. }
  180652. }
  180653. return numFound;
  180654. }
  180655. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  180656. {
  180657. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  180658. if (numFound == 0)
  180659. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  180660. return numFound;
  180661. }
  180662. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  180663. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  180664. const String& emailSubject,
  180665. const String& bodyText,
  180666. const StringArray& filesToAttach)
  180667. {
  180668. HMODULE h = LoadLibraryA ("MAPI32.dll");
  180669. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  180670. bool ok = false;
  180671. if (mapiSendMail != 0)
  180672. {
  180673. MapiMessage message;
  180674. zerostruct (message);
  180675. message.lpszSubject = (LPSTR) emailSubject.toCString();
  180676. message.lpszNoteText = (LPSTR) bodyText.toCString();
  180677. MapiRecipDesc recip;
  180678. zerostruct (recip);
  180679. recip.ulRecipClass = MAPI_TO;
  180680. String targetEmailAddress_ (targetEmailAddress);
  180681. if (targetEmailAddress_.isEmpty())
  180682. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  180683. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  180684. message.nRecipCount = 1;
  180685. message.lpRecips = &recip;
  180686. HeapBlock <MapiFileDesc> files;
  180687. files.calloc (filesToAttach.size());
  180688. message.nFileCount = filesToAttach.size();
  180689. message.lpFiles = files;
  180690. for (int i = 0; i < filesToAttach.size(); ++i)
  180691. {
  180692. files[i].nPosition = (ULONG) -1;
  180693. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  180694. }
  180695. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  180696. }
  180697. FreeLibrary (h);
  180698. return ok;
  180699. }
  180700. #endif
  180701. /*** End of inlined file: juce_win32_Network.cpp ***/
  180702. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  180703. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180704. // compiled on its own).
  180705. #if JUCE_INCLUDED_FILE
  180706. static HKEY findKeyForPath (String name,
  180707. const bool createForWriting,
  180708. String& valueName)
  180709. {
  180710. HKEY rootKey = 0;
  180711. if (name.startsWithIgnoreCase ("HKEY_CURRENT_USER\\"))
  180712. rootKey = HKEY_CURRENT_USER;
  180713. else if (name.startsWithIgnoreCase ("HKEY_LOCAL_MACHINE\\"))
  180714. rootKey = HKEY_LOCAL_MACHINE;
  180715. else if (name.startsWithIgnoreCase ("HKEY_CLASSES_ROOT\\"))
  180716. rootKey = HKEY_CLASSES_ROOT;
  180717. if (rootKey != 0)
  180718. {
  180719. name = name.substring (name.indexOfChar ('\\') + 1);
  180720. const int lastSlash = name.lastIndexOfChar ('\\');
  180721. valueName = name.substring (lastSlash + 1);
  180722. name = name.substring (0, lastSlash);
  180723. HKEY key;
  180724. DWORD result;
  180725. if (createForWriting)
  180726. {
  180727. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  180728. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  180729. return key;
  180730. }
  180731. else
  180732. {
  180733. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  180734. return key;
  180735. }
  180736. }
  180737. return 0;
  180738. }
  180739. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  180740. const String& defaultValue)
  180741. {
  180742. String valueName, result (defaultValue);
  180743. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180744. if (k != 0)
  180745. {
  180746. WCHAR buffer [2048];
  180747. unsigned long bufferSize = sizeof (buffer);
  180748. DWORD type = REG_SZ;
  180749. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  180750. {
  180751. if (type == REG_SZ)
  180752. result = buffer;
  180753. else if (type == REG_DWORD)
  180754. result = String ((int) *(DWORD*) buffer);
  180755. }
  180756. RegCloseKey (k);
  180757. }
  180758. return result;
  180759. }
  180760. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  180761. const String& value)
  180762. {
  180763. String valueName;
  180764. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180765. if (k != 0)
  180766. {
  180767. RegSetValueEx (k, valueName, 0, REG_SZ,
  180768. (const BYTE*) (const WCHAR*) value,
  180769. sizeof (WCHAR) * (value.length() + 1));
  180770. RegCloseKey (k);
  180771. }
  180772. }
  180773. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  180774. {
  180775. bool exists = false;
  180776. String valueName;
  180777. HKEY k = findKeyForPath (regValuePath, false, valueName);
  180778. if (k != 0)
  180779. {
  180780. unsigned char buffer [2048];
  180781. unsigned long bufferSize = sizeof (buffer);
  180782. DWORD type = 0;
  180783. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  180784. exists = true;
  180785. RegCloseKey (k);
  180786. }
  180787. return exists;
  180788. }
  180789. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  180790. {
  180791. String valueName;
  180792. HKEY k = findKeyForPath (regValuePath, true, valueName);
  180793. if (k != 0)
  180794. {
  180795. RegDeleteValue (k, valueName);
  180796. RegCloseKey (k);
  180797. }
  180798. }
  180799. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  180800. {
  180801. String valueName;
  180802. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  180803. if (k != 0)
  180804. {
  180805. RegDeleteKey (k, valueName);
  180806. RegCloseKey (k);
  180807. }
  180808. }
  180809. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  180810. const String& symbolicDescription,
  180811. const String& fullDescription,
  180812. const File& targetExecutable,
  180813. int iconResourceNumber)
  180814. {
  180815. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  180816. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  180817. if (iconResourceNumber != 0)
  180818. setRegistryValue (key + "\\DefaultIcon\\",
  180819. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  180820. setRegistryValue (key + "\\", fullDescription);
  180821. setRegistryValue (key + "\\shell\\open\\command\\",
  180822. targetExecutable.getFullPathName() + " %1");
  180823. }
  180824. bool juce_IsRunningInWine()
  180825. {
  180826. HKEY key;
  180827. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  180828. {
  180829. RegCloseKey (key);
  180830. return true;
  180831. }
  180832. return false;
  180833. }
  180834. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  180835. {
  180836. String s (::GetCommandLineW());
  180837. StringArray tokens;
  180838. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  180839. return tokens.joinIntoString (" ", 1);
  180840. }
  180841. static void* currentModuleHandle = 0;
  180842. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  180843. {
  180844. if (currentModuleHandle == 0)
  180845. currentModuleHandle = GetModuleHandle (0);
  180846. return currentModuleHandle;
  180847. }
  180848. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  180849. {
  180850. currentModuleHandle = newHandle;
  180851. }
  180852. void PlatformUtilities::fpuReset()
  180853. {
  180854. #if JUCE_MSVC
  180855. _clearfp();
  180856. #endif
  180857. }
  180858. void PlatformUtilities::beep()
  180859. {
  180860. MessageBeep (MB_OK);
  180861. }
  180862. #endif
  180863. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  180864. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  180865. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  180866. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180867. // compiled on its own).
  180868. #if JUCE_INCLUDED_FILE
  180869. static const unsigned int specialId = WM_APP + 0x4400;
  180870. static const unsigned int broadcastId = WM_APP + 0x4403;
  180871. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  180872. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  180873. HWND juce_messageWindowHandle = 0;
  180874. extern long improbableWindowNumber; // defined in windowing.cpp
  180875. #ifndef WM_APPCOMMAND
  180876. #define WM_APPCOMMAND 0x0319
  180877. #endif
  180878. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  180879. const UINT message,
  180880. const WPARAM wParam,
  180881. const LPARAM lParam) throw()
  180882. {
  180883. JUCE_TRY
  180884. {
  180885. if (h == juce_messageWindowHandle)
  180886. {
  180887. if (message == specialCallbackId)
  180888. {
  180889. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  180890. return (LRESULT) (*func) ((void*) lParam);
  180891. }
  180892. else if (message == specialId)
  180893. {
  180894. // these are trapped early in the dispatch call, but must also be checked
  180895. // here in case there are windows modal dialog boxes doing their own
  180896. // dispatch loop and not calling our version
  180897. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  180898. return 0;
  180899. }
  180900. else if (message == broadcastId)
  180901. {
  180902. const ScopedPointer <String> messageString ((String*) lParam);
  180903. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  180904. return 0;
  180905. }
  180906. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  180907. {
  180908. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  180909. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  180910. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  180911. return 0;
  180912. }
  180913. }
  180914. }
  180915. JUCE_CATCH_EXCEPTION
  180916. return DefWindowProc (h, message, wParam, lParam);
  180917. }
  180918. static bool isEventBlockedByModalComps (MSG& m)
  180919. {
  180920. if (Component::getNumCurrentlyModalComponents() == 0
  180921. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  180922. return false;
  180923. switch (m.message)
  180924. {
  180925. case WM_MOUSEMOVE:
  180926. case WM_NCMOUSEMOVE:
  180927. case 0x020A: /* WM_MOUSEWHEEL */
  180928. case 0x020E: /* WM_MOUSEHWHEEL */
  180929. case WM_KEYUP:
  180930. case WM_SYSKEYUP:
  180931. case WM_CHAR:
  180932. case WM_APPCOMMAND:
  180933. case WM_LBUTTONUP:
  180934. case WM_MBUTTONUP:
  180935. case WM_RBUTTONUP:
  180936. case WM_MOUSEACTIVATE:
  180937. case WM_NCMOUSEHOVER:
  180938. case WM_MOUSEHOVER:
  180939. return true;
  180940. case WM_NCLBUTTONDOWN:
  180941. case WM_NCLBUTTONDBLCLK:
  180942. case WM_NCRBUTTONDOWN:
  180943. case WM_NCRBUTTONDBLCLK:
  180944. case WM_NCMBUTTONDOWN:
  180945. case WM_NCMBUTTONDBLCLK:
  180946. case WM_LBUTTONDOWN:
  180947. case WM_LBUTTONDBLCLK:
  180948. case WM_MBUTTONDOWN:
  180949. case WM_MBUTTONDBLCLK:
  180950. case WM_RBUTTONDOWN:
  180951. case WM_RBUTTONDBLCLK:
  180952. case WM_KEYDOWN:
  180953. case WM_SYSKEYDOWN:
  180954. {
  180955. Component* const modal = Component::getCurrentlyModalComponent (0);
  180956. if (modal != 0)
  180957. modal->inputAttemptWhenModal();
  180958. return true;
  180959. }
  180960. default:
  180961. break;
  180962. }
  180963. return false;
  180964. }
  180965. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  180966. {
  180967. MSG m;
  180968. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  180969. return false;
  180970. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  180971. {
  180972. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  180973. {
  180974. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  180975. }
  180976. else if (m.message == WM_QUIT)
  180977. {
  180978. if (JUCEApplication::getInstance())
  180979. JUCEApplication::getInstance()->systemRequestedQuit();
  180980. }
  180981. else if (! isEventBlockedByModalComps (m))
  180982. {
  180983. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  180984. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  180985. {
  180986. // if it's someone else's window being clicked on, and the focus is
  180987. // currently on a juce window, pass the kb focus over..
  180988. HWND currentFocus = GetFocus();
  180989. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  180990. SetFocus (m.hwnd);
  180991. }
  180992. TranslateMessage (&m);
  180993. DispatchMessage (&m);
  180994. }
  180995. }
  180996. return true;
  180997. }
  180998. bool juce_postMessageToSystemQueue (void* message)
  180999. {
  181000. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181001. }
  181002. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181003. void* userData)
  181004. {
  181005. if (MessageManager::getInstance()->isThisTheMessageThread())
  181006. {
  181007. return (*callback) (userData);
  181008. }
  181009. else
  181010. {
  181011. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181012. // deadlock because the message manager is blocked from running, and can't
  181013. // call your function..
  181014. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181015. return (void*) SendMessage (juce_messageWindowHandle,
  181016. specialCallbackId,
  181017. (WPARAM) callback,
  181018. (LPARAM) userData);
  181019. }
  181020. }
  181021. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181022. {
  181023. if (hwnd != juce_messageWindowHandle)
  181024. reinterpret_cast <VoidArray*> (lParam)->add ((void*) hwnd);
  181025. return TRUE;
  181026. }
  181027. void MessageManager::broadcastMessage (const String& value) throw()
  181028. {
  181029. VoidArray windows;
  181030. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181031. const String localCopy (value);
  181032. COPYDATASTRUCT data;
  181033. data.dwData = broadcastId;
  181034. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181035. data.lpData = (void*) static_cast <const juce_wchar*> (localCopy);
  181036. for (int i = windows.size(); --i >= 0;)
  181037. {
  181038. HWND hwnd = (HWND) windows.getUnchecked(i);
  181039. TCHAR windowName [64]; // no need to read longer strings than this
  181040. GetWindowText (hwnd, windowName, 64);
  181041. windowName [63] = 0;
  181042. if (String (windowName) == String (messageWindowName))
  181043. {
  181044. DWORD_PTR result;
  181045. SendMessageTimeout (hwnd, WM_COPYDATA,
  181046. (WPARAM) juce_messageWindowHandle,
  181047. (LPARAM) &data,
  181048. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181049. 8000,
  181050. &result);
  181051. }
  181052. }
  181053. }
  181054. static const String getMessageWindowClassName()
  181055. {
  181056. // this name has to be different for each app/dll instance because otherwise
  181057. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181058. // window class).
  181059. static int number = 0;
  181060. if (number == 0)
  181061. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181062. return "JUCEcs_" + String (number);
  181063. }
  181064. void MessageManager::doPlatformSpecificInitialisation()
  181065. {
  181066. OleInitialize (0);
  181067. const String className (getMessageWindowClassName());
  181068. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181069. WNDCLASSEX wc;
  181070. zerostruct (wc);
  181071. wc.cbSize = sizeof (wc);
  181072. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181073. wc.cbWndExtra = 4;
  181074. wc.hInstance = hmod;
  181075. wc.lpszClassName = className;
  181076. RegisterClassEx (&wc);
  181077. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181078. messageWindowName,
  181079. 0, 0, 0, 0, 0, 0, 0,
  181080. hmod, 0);
  181081. }
  181082. void MessageManager::doPlatformSpecificShutdown()
  181083. {
  181084. DestroyWindow (juce_messageWindowHandle);
  181085. UnregisterClass (getMessageWindowClassName(), 0);
  181086. OleUninitialize();
  181087. }
  181088. #endif
  181089. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181090. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181091. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181092. // compiled on its own).
  181093. #if JUCE_INCLUDED_FILE
  181094. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181095. // these are in the windows SDK, but need to be repeated here for GCC..
  181096. #ifndef GET_APPCOMMAND_LPARAM
  181097. #define FAPPCOMMAND_MASK 0xF000
  181098. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181099. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181100. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181101. #define APPCOMMAND_MEDIA_STOP 13
  181102. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181103. #define WM_APPCOMMAND 0x0319
  181104. #endif
  181105. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181106. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181107. extern bool juce_IsRunningInWine();
  181108. #ifndef ULW_ALPHA
  181109. #define ULW_ALPHA 0x00000002
  181110. #endif
  181111. #ifndef AC_SRC_ALPHA
  181112. #define AC_SRC_ALPHA 0x01
  181113. #endif
  181114. static HPALETTE palette = 0;
  181115. static bool createPaletteIfNeeded = true;
  181116. static bool shouldDeactivateTitleBar = true;
  181117. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181118. #define WM_TRAYNOTIFY WM_USER + 100
  181119. using ::abs;
  181120. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181121. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181122. bool Desktop::canUseSemiTransparentWindows() throw()
  181123. {
  181124. if (updateLayeredWindow == 0)
  181125. {
  181126. if (! juce_IsRunningInWine())
  181127. {
  181128. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181129. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181130. }
  181131. }
  181132. return updateLayeredWindow != 0;
  181133. }
  181134. const int extendedKeyModifier = 0x10000;
  181135. const int KeyPress::spaceKey = VK_SPACE;
  181136. const int KeyPress::returnKey = VK_RETURN;
  181137. const int KeyPress::escapeKey = VK_ESCAPE;
  181138. const int KeyPress::backspaceKey = VK_BACK;
  181139. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181140. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181141. const int KeyPress::tabKey = VK_TAB;
  181142. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181143. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181144. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181145. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181146. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181147. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181148. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181149. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181150. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181151. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181152. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181153. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181154. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181155. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181156. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181157. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181158. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181159. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181160. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181161. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181162. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181163. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181164. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181165. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181166. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181167. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181168. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181169. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181170. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181171. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181172. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181173. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181174. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181175. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181176. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181177. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181178. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181179. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181180. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181181. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181182. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181183. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181184. const int KeyPress::playKey = 0x30000;
  181185. const int KeyPress::stopKey = 0x30001;
  181186. const int KeyPress::fastForwardKey = 0x30002;
  181187. const int KeyPress::rewindKey = 0x30003;
  181188. class WindowsBitmapImage : public Image
  181189. {
  181190. public:
  181191. HBITMAP hBitmap;
  181192. BITMAPV4HEADER bitmapInfo;
  181193. HDC hdc;
  181194. unsigned char* bitmapData;
  181195. WindowsBitmapImage (const PixelFormat format_,
  181196. const int w, const int h, const bool clearImage)
  181197. : Image (format_, w, h)
  181198. {
  181199. jassert (format_ == RGB || format_ == ARGB);
  181200. pixelStride = (format_ == RGB) ? 3 : 4;
  181201. zerostruct (bitmapInfo);
  181202. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181203. bitmapInfo.bV4Width = w;
  181204. bitmapInfo.bV4Height = h;
  181205. bitmapInfo.bV4Planes = 1;
  181206. bitmapInfo.bV4CSType = 1;
  181207. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181208. if (format_ == ARGB)
  181209. {
  181210. bitmapInfo.bV4AlphaMask = 0xff000000;
  181211. bitmapInfo.bV4RedMask = 0xff0000;
  181212. bitmapInfo.bV4GreenMask = 0xff00;
  181213. bitmapInfo.bV4BlueMask = 0xff;
  181214. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181215. }
  181216. else
  181217. {
  181218. bitmapInfo.bV4V4Compression = BI_RGB;
  181219. }
  181220. lineStride = -((w * pixelStride + 3) & ~3);
  181221. HDC dc = GetDC (0);
  181222. hdc = CreateCompatibleDC (dc);
  181223. ReleaseDC (0, dc);
  181224. SetMapMode (hdc, MM_TEXT);
  181225. hBitmap = CreateDIBSection (hdc,
  181226. (BITMAPINFO*) &(bitmapInfo),
  181227. DIB_RGB_COLORS,
  181228. (void**) &bitmapData,
  181229. 0, 0);
  181230. SelectObject (hdc, hBitmap);
  181231. if (format_ == ARGB && clearImage)
  181232. zeromem (bitmapData, abs (h * lineStride));
  181233. imageData = bitmapData - (lineStride * (h - 1));
  181234. }
  181235. ~WindowsBitmapImage()
  181236. {
  181237. DeleteDC (hdc);
  181238. DeleteObject (hBitmap);
  181239. }
  181240. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181241. const int x, const int y,
  181242. const RectangleList& maskedRegion) throw()
  181243. {
  181244. static HDRAWDIB hdd = 0;
  181245. static bool needToCreateDrawDib = true;
  181246. if (needToCreateDrawDib)
  181247. {
  181248. needToCreateDrawDib = false;
  181249. HDC dc = GetDC (0);
  181250. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181251. ReleaseDC (0, dc);
  181252. // only open if we're not palettised
  181253. if (n > 8)
  181254. hdd = DrawDibOpen();
  181255. }
  181256. if (createPaletteIfNeeded)
  181257. {
  181258. HDC dc = GetDC (0);
  181259. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181260. ReleaseDC (0, dc);
  181261. if (n <= 8)
  181262. palette = CreateHalftonePalette (dc);
  181263. createPaletteIfNeeded = false;
  181264. }
  181265. if (palette != 0)
  181266. {
  181267. SelectPalette (dc, palette, FALSE);
  181268. RealizePalette (dc);
  181269. SetStretchBltMode (dc, HALFTONE);
  181270. }
  181271. SetMapMode (dc, MM_TEXT);
  181272. if (transparent)
  181273. {
  181274. POINT p, pos;
  181275. SIZE size;
  181276. RECT windowBounds;
  181277. GetWindowRect (hwnd, &windowBounds);
  181278. p.x = -x;
  181279. p.y = -y;
  181280. pos.x = windowBounds.left;
  181281. pos.y = windowBounds.top;
  181282. size.cx = windowBounds.right - windowBounds.left;
  181283. size.cy = windowBounds.bottom - windowBounds.top;
  181284. BLENDFUNCTION bf;
  181285. bf.AlphaFormat = AC_SRC_ALPHA;
  181286. bf.BlendFlags = 0;
  181287. bf.BlendOp = AC_SRC_OVER;
  181288. bf.SourceConstantAlpha = 0xff;
  181289. if (! maskedRegion.isEmpty())
  181290. {
  181291. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181292. {
  181293. const Rectangle<int>& r = *i.getRectangle();
  181294. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181295. }
  181296. }
  181297. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181298. }
  181299. else
  181300. {
  181301. int savedDC = 0;
  181302. if (! maskedRegion.isEmpty())
  181303. {
  181304. savedDC = SaveDC (dc);
  181305. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181306. {
  181307. const Rectangle<int>& r = *i.getRectangle();
  181308. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181309. }
  181310. }
  181311. const int w = getWidth();
  181312. const int h = getHeight();
  181313. if (hdd == 0)
  181314. {
  181315. StretchDIBits (dc,
  181316. x, y, w, h,
  181317. 0, 0, w, h,
  181318. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181319. DIB_RGB_COLORS, SRCCOPY);
  181320. }
  181321. else
  181322. {
  181323. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181324. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181325. 0, 0, w, h, 0);
  181326. }
  181327. if (! maskedRegion.isEmpty())
  181328. RestoreDC (dc, savedDC);
  181329. }
  181330. }
  181331. juce_UseDebuggingNewOperator
  181332. private:
  181333. WindowsBitmapImage (const WindowsBitmapImage&);
  181334. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181335. };
  181336. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181337. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  181338. {
  181339. SHORT k = (SHORT) keyCode;
  181340. if ((keyCode & extendedKeyModifier) == 0
  181341. && (k >= (SHORT) 'a' && k <= (SHORT) 'z'))
  181342. k += (SHORT) 'A' - (SHORT) 'a';
  181343. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181344. (SHORT) '+', VK_OEM_PLUS,
  181345. (SHORT) '-', VK_OEM_MINUS,
  181346. (SHORT) '.', VK_OEM_PERIOD,
  181347. (SHORT) ';', VK_OEM_1,
  181348. (SHORT) ':', VK_OEM_1,
  181349. (SHORT) '/', VK_OEM_2,
  181350. (SHORT) '?', VK_OEM_2,
  181351. (SHORT) '[', VK_OEM_4,
  181352. (SHORT) ']', VK_OEM_6 };
  181353. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181354. if (k == translatedValues [i])
  181355. k = translatedValues [i + 1];
  181356. return (GetKeyState (k) & 0x8000) != 0;
  181357. }
  181358. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181359. {
  181360. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181361. return callback (userData);
  181362. else
  181363. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181364. }
  181365. class Win32ComponentPeer : public ComponentPeer
  181366. {
  181367. public:
  181368. Win32ComponentPeer (Component* const component,
  181369. const int windowStyleFlags)
  181370. : ComponentPeer (component, windowStyleFlags),
  181371. dontRepaint (false),
  181372. fullScreen (false),
  181373. isDragging (false),
  181374. isMouseOver (false),
  181375. hasCreatedCaret (false),
  181376. currentWindowIcon (0),
  181377. taskBarIcon (0),
  181378. dropTarget (0)
  181379. {
  181380. callFunctionIfNotLocked (&createWindowCallback, this);
  181381. setTitle (component->getName());
  181382. if ((windowStyleFlags & windowHasDropShadow) != 0
  181383. && Desktop::canUseSemiTransparentWindows())
  181384. {
  181385. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181386. if (shadower != 0)
  181387. shadower->setOwner (component);
  181388. }
  181389. else
  181390. {
  181391. shadower = 0;
  181392. }
  181393. }
  181394. ~Win32ComponentPeer()
  181395. {
  181396. setTaskBarIcon (0);
  181397. deleteAndZero (shadower);
  181398. // do this before the next bit to avoid messages arriving for this window
  181399. // before it's destroyed
  181400. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181401. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181402. if (currentWindowIcon != 0)
  181403. DestroyIcon (currentWindowIcon);
  181404. if (dropTarget != 0)
  181405. {
  181406. dropTarget->Release();
  181407. dropTarget = 0;
  181408. }
  181409. }
  181410. void* getNativeHandle() const
  181411. {
  181412. return hwnd;
  181413. }
  181414. void setVisible (bool shouldBeVisible)
  181415. {
  181416. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181417. if (shouldBeVisible)
  181418. InvalidateRect (hwnd, 0, 0);
  181419. else
  181420. lastPaintTime = 0;
  181421. }
  181422. void setTitle (const String& title)
  181423. {
  181424. SetWindowText (hwnd, title);
  181425. }
  181426. void setPosition (int x, int y)
  181427. {
  181428. offsetWithinParent (x, y);
  181429. SetWindowPos (hwnd, 0,
  181430. x - windowBorder.getLeft(),
  181431. y - windowBorder.getTop(),
  181432. 0, 0,
  181433. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181434. }
  181435. void repaintNowIfTransparent()
  181436. {
  181437. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  181438. handlePaintMessage();
  181439. }
  181440. void updateBorderSize()
  181441. {
  181442. WINDOWINFO info;
  181443. info.cbSize = sizeof (info);
  181444. if (GetWindowInfo (hwnd, &info))
  181445. {
  181446. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  181447. info.rcClient.left - info.rcWindow.left,
  181448. info.rcWindow.bottom - info.rcClient.bottom,
  181449. info.rcWindow.right - info.rcClient.right);
  181450. }
  181451. }
  181452. void setSize (int w, int h)
  181453. {
  181454. SetWindowPos (hwnd, 0, 0, 0,
  181455. w + windowBorder.getLeftAndRight(),
  181456. h + windowBorder.getTopAndBottom(),
  181457. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181458. updateBorderSize();
  181459. repaintNowIfTransparent();
  181460. }
  181461. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  181462. {
  181463. fullScreen = isNowFullScreen;
  181464. offsetWithinParent (x, y);
  181465. SetWindowPos (hwnd, 0,
  181466. x - windowBorder.getLeft(),
  181467. y - windowBorder.getTop(),
  181468. w + windowBorder.getLeftAndRight(),
  181469. h + windowBorder.getTopAndBottom(),
  181470. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  181471. updateBorderSize();
  181472. repaintNowIfTransparent();
  181473. }
  181474. const Rectangle<int> getBounds() const
  181475. {
  181476. RECT r;
  181477. GetWindowRect (hwnd, &r);
  181478. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  181479. HWND parentH = GetParent (hwnd);
  181480. if (parentH != 0)
  181481. {
  181482. GetWindowRect (parentH, &r);
  181483. bounds.translate (-r.left, -r.top);
  181484. }
  181485. return windowBorder.subtractedFrom (bounds);
  181486. }
  181487. const Point<int> getScreenPosition() const
  181488. {
  181489. RECT r;
  181490. GetWindowRect (hwnd, &r);
  181491. return Point<int> (r.left + windowBorder.getLeft(),
  181492. r.top + windowBorder.getTop());
  181493. }
  181494. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  181495. {
  181496. return relativePosition + getScreenPosition();
  181497. }
  181498. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  181499. {
  181500. return screenPosition - getScreenPosition();
  181501. }
  181502. void setMinimised (bool shouldBeMinimised)
  181503. {
  181504. if (shouldBeMinimised != isMinimised())
  181505. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  181506. }
  181507. bool isMinimised() const
  181508. {
  181509. WINDOWPLACEMENT wp;
  181510. wp.length = sizeof (WINDOWPLACEMENT);
  181511. GetWindowPlacement (hwnd, &wp);
  181512. return wp.showCmd == SW_SHOWMINIMIZED;
  181513. }
  181514. void setFullScreen (bool shouldBeFullScreen)
  181515. {
  181516. setMinimised (false);
  181517. if (fullScreen != shouldBeFullScreen)
  181518. {
  181519. fullScreen = shouldBeFullScreen;
  181520. const Component::SafePointer<Component> deletionChecker (component);
  181521. if (! fullScreen)
  181522. {
  181523. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  181524. if (hasTitleBar())
  181525. ShowWindow (hwnd, SW_SHOWNORMAL);
  181526. if (! boundsCopy.isEmpty())
  181527. {
  181528. setBounds (boundsCopy.getX(),
  181529. boundsCopy.getY(),
  181530. boundsCopy.getWidth(),
  181531. boundsCopy.getHeight(),
  181532. false);
  181533. }
  181534. }
  181535. else
  181536. {
  181537. if (hasTitleBar())
  181538. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  181539. else
  181540. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  181541. }
  181542. if (deletionChecker != 0)
  181543. handleMovedOrResized();
  181544. }
  181545. }
  181546. bool isFullScreen() const
  181547. {
  181548. if (! hasTitleBar())
  181549. return fullScreen;
  181550. WINDOWPLACEMENT wp;
  181551. wp.length = sizeof (wp);
  181552. GetWindowPlacement (hwnd, &wp);
  181553. return wp.showCmd == SW_SHOWMAXIMIZED;
  181554. }
  181555. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  181556. {
  181557. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  181558. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  181559. return false;
  181560. RECT r;
  181561. GetWindowRect (hwnd, &r);
  181562. POINT p;
  181563. p.x = position.getX() + r.left + windowBorder.getLeft();
  181564. p.y = position.getY() + r.top + windowBorder.getTop();
  181565. HWND w = WindowFromPoint (p);
  181566. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  181567. }
  181568. const BorderSize getFrameSize() const
  181569. {
  181570. return windowBorder;
  181571. }
  181572. bool setAlwaysOnTop (bool alwaysOnTop)
  181573. {
  181574. const bool oldDeactivate = shouldDeactivateTitleBar;
  181575. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181576. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  181577. 0, 0, 0, 0,
  181578. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181579. shouldDeactivateTitleBar = oldDeactivate;
  181580. if (shadower != 0)
  181581. shadower->componentBroughtToFront (*component);
  181582. return true;
  181583. }
  181584. void toFront (bool makeActive)
  181585. {
  181586. setMinimised (false);
  181587. const bool oldDeactivate = shouldDeactivateTitleBar;
  181588. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181589. callFunctionIfNotLocked (makeActive ? &toFrontCallback1 : &toFrontCallback2, hwnd);
  181590. shouldDeactivateTitleBar = oldDeactivate;
  181591. if (! makeActive)
  181592. {
  181593. // in this case a broughttofront call won't have occured, so do it now..
  181594. handleBroughtToFront();
  181595. }
  181596. }
  181597. void toBehind (ComponentPeer* other)
  181598. {
  181599. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  181600. jassert (otherPeer != 0); // wrong type of window?
  181601. if (otherPeer != 0)
  181602. {
  181603. setMinimised (false);
  181604. // must be careful not to try to put a topmost window behind a normal one, or win32
  181605. // promotes the normal one to be topmost!
  181606. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  181607. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  181608. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181609. else if (otherPeer->getComponent()->isAlwaysOnTop())
  181610. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  181611. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181612. }
  181613. }
  181614. bool isFocused() const
  181615. {
  181616. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  181617. }
  181618. void grabFocus()
  181619. {
  181620. const bool oldDeactivate = shouldDeactivateTitleBar;
  181621. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  181622. callFunctionIfNotLocked (&setFocusCallback, hwnd);
  181623. shouldDeactivateTitleBar = oldDeactivate;
  181624. }
  181625. void textInputRequired (const Point<int>&)
  181626. {
  181627. if (! hasCreatedCaret)
  181628. {
  181629. hasCreatedCaret = true;
  181630. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  181631. }
  181632. ShowCaret (hwnd);
  181633. SetCaretPos (0, 0);
  181634. }
  181635. void repaint (int x, int y, int w, int h)
  181636. {
  181637. const RECT r = { x, y, x + w, y + h };
  181638. InvalidateRect (hwnd, &r, FALSE);
  181639. }
  181640. void performAnyPendingRepaintsNow()
  181641. {
  181642. MSG m;
  181643. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  181644. DispatchMessage (&m);
  181645. }
  181646. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  181647. {
  181648. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  181649. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  181650. return 0;
  181651. }
  181652. void setTaskBarIcon (const Image* const image)
  181653. {
  181654. if (image != 0)
  181655. {
  181656. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  181657. if (taskBarIcon == 0)
  181658. {
  181659. taskBarIcon = new NOTIFYICONDATA();
  181660. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  181661. taskBarIcon->hWnd = (HWND) hwnd;
  181662. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  181663. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  181664. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  181665. taskBarIcon->hIcon = hicon;
  181666. taskBarIcon->szTip[0] = 0;
  181667. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  181668. }
  181669. else
  181670. {
  181671. HICON oldIcon = taskBarIcon->hIcon;
  181672. taskBarIcon->hIcon = hicon;
  181673. taskBarIcon->uFlags = NIF_ICON;
  181674. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181675. DestroyIcon (oldIcon);
  181676. }
  181677. DestroyIcon (hicon);
  181678. }
  181679. else if (taskBarIcon != 0)
  181680. {
  181681. taskBarIcon->uFlags = 0;
  181682. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  181683. DestroyIcon (taskBarIcon->hIcon);
  181684. deleteAndZero (taskBarIcon);
  181685. }
  181686. }
  181687. void setTaskBarIconToolTip (const String& toolTip) const
  181688. {
  181689. if (taskBarIcon != 0)
  181690. {
  181691. taskBarIcon->uFlags = NIF_TIP;
  181692. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  181693. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  181694. }
  181695. }
  181696. bool isInside (HWND h) const
  181697. {
  181698. return GetAncestor (hwnd, GA_ROOT) == h;
  181699. }
  181700. static void updateKeyModifiers() throw()
  181701. {
  181702. int keyMods = 0;
  181703. if (GetKeyState (VK_SHIFT) & 0x8000) keyMods |= ModifierKeys::shiftModifier;
  181704. if (GetKeyState (VK_CONTROL) & 0x8000) keyMods |= ModifierKeys::ctrlModifier;
  181705. if (GetKeyState (VK_MENU) & 0x8000) keyMods |= ModifierKeys::altModifier;
  181706. if (GetKeyState (VK_RMENU) & 0x8000) keyMods &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181707. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  181708. }
  181709. static void updateModifiersFromWParam (const WPARAM wParam)
  181710. {
  181711. int mouseMods = 0;
  181712. if (wParam & MK_LBUTTON) mouseMods |= ModifierKeys::leftButtonModifier;
  181713. if (wParam & MK_RBUTTON) mouseMods |= ModifierKeys::rightButtonModifier;
  181714. if (wParam & MK_MBUTTON) mouseMods |= ModifierKeys::middleButtonModifier;
  181715. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  181716. updateKeyModifiers();
  181717. }
  181718. static int64 getMouseEventTime()
  181719. {
  181720. static int64 eventTimeOffset = 0;
  181721. static DWORD lastMessageTime = 0;
  181722. const DWORD thisMessageTime = GetMessageTime();
  181723. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181724. {
  181725. lastMessageTime = thisMessageTime;
  181726. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181727. }
  181728. return eventTimeOffset + thisMessageTime;
  181729. }
  181730. juce_UseDebuggingNewOperator
  181731. bool dontRepaint;
  181732. static ModifierKeys currentModifiers;
  181733. static ModifierKeys modifiersAtLastCallback;
  181734. private:
  181735. HWND hwnd;
  181736. DropShadower* shadower;
  181737. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  181738. BorderSize windowBorder;
  181739. HICON currentWindowIcon;
  181740. NOTIFYICONDATA* taskBarIcon;
  181741. IDropTarget* dropTarget;
  181742. class TemporaryImage : public Timer
  181743. {
  181744. public:
  181745. TemporaryImage()
  181746. : image (0)
  181747. {
  181748. }
  181749. ~TemporaryImage()
  181750. {
  181751. delete image;
  181752. }
  181753. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  181754. {
  181755. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  181756. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  181757. {
  181758. delete image;
  181759. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  181760. }
  181761. startTimer (3000);
  181762. return image;
  181763. }
  181764. void timerCallback()
  181765. {
  181766. stopTimer();
  181767. deleteAndZero (image);
  181768. }
  181769. private:
  181770. WindowsBitmapImage* image;
  181771. TemporaryImage (const TemporaryImage&);
  181772. TemporaryImage& operator= (const TemporaryImage&);
  181773. };
  181774. TemporaryImage offscreenImageGenerator;
  181775. class WindowClassHolder : public DeletedAtShutdown
  181776. {
  181777. public:
  181778. WindowClassHolder()
  181779. : windowClassName ("JUCE_")
  181780. {
  181781. // this name has to be different for each app/dll instance because otherwise
  181782. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181783. // window class).
  181784. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  181785. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181786. TCHAR moduleFile [1024];
  181787. moduleFile[0] = 0;
  181788. GetModuleFileName (moduleHandle, moduleFile, 1024);
  181789. WORD iconNum = 0;
  181790. WNDCLASSEX wcex;
  181791. wcex.cbSize = sizeof (wcex);
  181792. wcex.style = CS_OWNDC;
  181793. wcex.lpfnWndProc = (WNDPROC) windowProc;
  181794. wcex.lpszClassName = windowClassName;
  181795. wcex.cbClsExtra = 0;
  181796. wcex.cbWndExtra = 32;
  181797. wcex.hInstance = moduleHandle;
  181798. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181799. iconNum = 1;
  181800. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  181801. wcex.hCursor = 0;
  181802. wcex.hbrBackground = 0;
  181803. wcex.lpszMenuName = 0;
  181804. RegisterClassEx (&wcex);
  181805. }
  181806. ~WindowClassHolder()
  181807. {
  181808. if (ComponentPeer::getNumPeers() == 0)
  181809. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  181810. clearSingletonInstance();
  181811. }
  181812. String windowClassName;
  181813. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  181814. };
  181815. static void* createWindowCallback (void* userData)
  181816. {
  181817. static_cast <Win32ComponentPeer*> (userData)->createWindow();
  181818. return 0;
  181819. }
  181820. void createWindow()
  181821. {
  181822. DWORD exstyle = WS_EX_ACCEPTFILES;
  181823. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  181824. if (hasTitleBar())
  181825. {
  181826. type |= WS_OVERLAPPED;
  181827. exstyle |= WS_EX_APPWINDOW;
  181828. if ((styleFlags & windowHasCloseButton) != 0)
  181829. {
  181830. type |= WS_SYSMENU;
  181831. }
  181832. else
  181833. {
  181834. // annoyingly, windows won't let you have a min/max button without a close button
  181835. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  181836. }
  181837. if ((styleFlags & windowIsResizable) != 0)
  181838. type |= WS_THICKFRAME;
  181839. }
  181840. else
  181841. {
  181842. type |= WS_POPUP | WS_SYSMENU;
  181843. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  181844. exstyle |= WS_EX_TOOLWINDOW;
  181845. else
  181846. exstyle |= WS_EX_APPWINDOW;
  181847. }
  181848. if ((styleFlags & windowHasMinimiseButton) != 0)
  181849. type |= WS_MINIMIZEBOX;
  181850. if ((styleFlags & windowHasMaximiseButton) != 0)
  181851. type |= WS_MAXIMIZEBOX;
  181852. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  181853. exstyle |= WS_EX_TRANSPARENT;
  181854. if ((styleFlags & windowIsSemiTransparent) != 0
  181855. && Desktop::canUseSemiTransparentWindows())
  181856. exstyle |= WS_EX_LAYERED;
  181857. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  181858. if (hwnd != 0)
  181859. {
  181860. SetWindowLongPtr (hwnd, 0, 0);
  181861. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  181862. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  181863. if (dropTarget == 0)
  181864. dropTarget = new JuceDropTarget (this);
  181865. RegisterDragDrop (hwnd, dropTarget);
  181866. updateBorderSize();
  181867. // Calling this function here is (for some reason) necessary to make Windows
  181868. // correctly enable the menu items that we specify in the wm_initmenu message.
  181869. GetSystemMenu (hwnd, false);
  181870. }
  181871. else
  181872. {
  181873. jassertfalse
  181874. }
  181875. }
  181876. static void* destroyWindowCallback (void* handle)
  181877. {
  181878. RevokeDragDrop ((HWND) handle);
  181879. DestroyWindow ((HWND) handle);
  181880. return 0;
  181881. }
  181882. static void* toFrontCallback1 (void* h)
  181883. {
  181884. SetForegroundWindow ((HWND) h);
  181885. return 0;
  181886. }
  181887. static void* toFrontCallback2 (void* h)
  181888. {
  181889. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  181890. return 0;
  181891. }
  181892. static void* setFocusCallback (void* h)
  181893. {
  181894. SetFocus ((HWND) h);
  181895. return 0;
  181896. }
  181897. static void* getFocusCallback (void*)
  181898. {
  181899. return GetFocus();
  181900. }
  181901. void offsetWithinParent (int& x, int& y) const
  181902. {
  181903. if (isTransparent())
  181904. {
  181905. HWND parentHwnd = GetParent (hwnd);
  181906. if (parentHwnd != 0)
  181907. {
  181908. RECT parentRect;
  181909. GetWindowRect (parentHwnd, &parentRect);
  181910. x += parentRect.left;
  181911. y += parentRect.top;
  181912. }
  181913. }
  181914. }
  181915. bool isTransparent() const
  181916. {
  181917. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  181918. }
  181919. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  181920. void setIcon (const Image& newIcon)
  181921. {
  181922. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  181923. if (hicon != 0)
  181924. {
  181925. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  181926. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  181927. if (currentWindowIcon != 0)
  181928. DestroyIcon (currentWindowIcon);
  181929. currentWindowIcon = hicon;
  181930. }
  181931. }
  181932. void handlePaintMessage()
  181933. {
  181934. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  181935. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  181936. PAINTSTRUCT paintStruct;
  181937. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  181938. // message and become re-entrant, but that's OK
  181939. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  181940. // corrupt the image it's using to paint into, so do a check here.
  181941. static bool reentrant = false;
  181942. if (reentrant)
  181943. {
  181944. DeleteObject (rgn);
  181945. EndPaint (hwnd, &paintStruct);
  181946. return;
  181947. }
  181948. reentrant = true;
  181949. // this is the rectangle to update..
  181950. int x = paintStruct.rcPaint.left;
  181951. int y = paintStruct.rcPaint.top;
  181952. int w = paintStruct.rcPaint.right - x;
  181953. int h = paintStruct.rcPaint.bottom - y;
  181954. const bool transparent = isTransparent();
  181955. if (transparent)
  181956. {
  181957. // it's not possible to have a transparent window with a title bar at the moment!
  181958. jassert (! hasTitleBar());
  181959. RECT r;
  181960. GetWindowRect (hwnd, &r);
  181961. x = y = 0;
  181962. w = r.right - r.left;
  181963. h = r.bottom - r.top;
  181964. }
  181965. if (w > 0 && h > 0)
  181966. {
  181967. clearMaskedRegion();
  181968. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  181969. RectangleList contextClip;
  181970. bool needToPaintAll = true;
  181971. if (regionType == COMPLEXREGION && ! transparent)
  181972. {
  181973. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  181974. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  181975. DeleteObject (clipRgn);
  181976. char rgnData [8192];
  181977. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  181978. if (res > 0 && res <= sizeof (rgnData))
  181979. {
  181980. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  181981. if (hdr->iType == RDH_RECTANGLES
  181982. && hdr->rcBound.right - hdr->rcBound.left >= w
  181983. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  181984. {
  181985. needToPaintAll = false;
  181986. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  181987. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  181988. while (--num >= 0)
  181989. {
  181990. // (need to move this one pixel to the left because of a win32 bug)
  181991. const int cx = jmax (x, (int) rects->left - 1);
  181992. const int cy = rects->top;
  181993. const int cw = rects->right - cx;
  181994. const int ch = rects->bottom - rects->top;
  181995. if (cx + cw - x <= w && cy + ch - y <= h)
  181996. {
  181997. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  181998. }
  181999. else
  182000. {
  182001. needToPaintAll = true;
  182002. break;
  182003. }
  182004. ++rects;
  182005. }
  182006. }
  182007. }
  182008. }
  182009. if (needToPaintAll)
  182010. {
  182011. contextClip.clear();
  182012. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182013. }
  182014. if (transparent)
  182015. {
  182016. RectangleList::Iterator i (contextClip);
  182017. while (i.next())
  182018. {
  182019. const Rectangle<int>& r = *i.getRectangle();
  182020. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182021. }
  182022. }
  182023. // if the component's not opaque, this won't draw properly unless the platform can support this
  182024. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182025. updateCurrentModifiers();
  182026. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182027. context.clipToRectangleList (contextClip);
  182028. context.setOrigin (-x, -y);
  182029. handlePaint (context);
  182030. if (! dontRepaint)
  182031. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182032. }
  182033. DeleteObject (rgn);
  182034. EndPaint (hwnd, &paintStruct);
  182035. reentrant = false;
  182036. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182037. _fpreset(); // because some graphics cards can unmask FP exceptions
  182038. #endif
  182039. lastPaintTime = Time::getMillisecondCounter();
  182040. }
  182041. void doMouseEvent (const Point<int>& position)
  182042. {
  182043. handleMouseEvent (0, position, currentModifiers, getMouseEventTime());
  182044. }
  182045. void doMouseMove (const Point<int>& position)
  182046. {
  182047. if (! isMouseOver)
  182048. {
  182049. isMouseOver = true;
  182050. updateKeyModifiers();
  182051. TRACKMOUSEEVENT tme;
  182052. tme.cbSize = sizeof (tme);
  182053. tme.dwFlags = TME_LEAVE;
  182054. tme.hwndTrack = hwnd;
  182055. tme.dwHoverTime = 0;
  182056. if (! TrackMouseEvent (&tme))
  182057. jassertfalse;
  182058. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  182059. }
  182060. else if (! isDragging)
  182061. {
  182062. if (! contains (position, false))
  182063. return;
  182064. }
  182065. // (Throttling the incoming queue of mouse-events seems to still be required in XP..)
  182066. static uint32 lastMouseTime = 0;
  182067. const uint32 now = Time::getMillisecondCounter();
  182068. const int maxMouseMovesPerSecond = 60;
  182069. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182070. {
  182071. lastMouseTime = now;
  182072. doMouseEvent (position);
  182073. }
  182074. }
  182075. void doMouseDown (const Point<int>& position, const WPARAM wParam)
  182076. {
  182077. if (GetCapture() != hwnd)
  182078. SetCapture (hwnd);
  182079. doMouseMove (position);
  182080. updateModifiersFromWParam (wParam);
  182081. isDragging = true;
  182082. doMouseEvent (position);
  182083. }
  182084. void doMouseUp (const Point<int>& position, const WPARAM wParam)
  182085. {
  182086. updateModifiersFromWParam (wParam);
  182087. isDragging = false;
  182088. // release the mouse capture if the user has released all buttons
  182089. if ((wParam & (MK_LBUTTON | MK_RBUTTON | MK_MBUTTON)) == 0 && hwnd == GetCapture())
  182090. ReleaseCapture();
  182091. doMouseEvent (position);
  182092. }
  182093. void doCaptureChanged()
  182094. {
  182095. if (isDragging)
  182096. doMouseUp (getCurrentMousePos(), (WPARAM) 0);
  182097. }
  182098. void doMouseExit()
  182099. {
  182100. isMouseOver = false;
  182101. doMouseEvent (getCurrentMousePos());
  182102. }
  182103. void doMouseWheel (const Point<int>& position, const WPARAM wParam, const bool isVertical)
  182104. {
  182105. updateKeyModifiers();
  182106. const float amount = jlimit (-1000.0f, 1000.0f, 0.75f * (short) HIWORD (wParam));
  182107. handleMouseWheel (0, position, getMouseEventTime(),
  182108. isVertical ? 0.0f : amount,
  182109. isVertical ? amount : 0.0f);
  182110. }
  182111. void sendModifierKeyChangeIfNeeded()
  182112. {
  182113. if (modifiersAtLastCallback != currentModifiers)
  182114. {
  182115. modifiersAtLastCallback = currentModifiers;
  182116. handleModifierKeysChange();
  182117. }
  182118. }
  182119. bool doKeyUp (const WPARAM key)
  182120. {
  182121. updateKeyModifiers();
  182122. switch (key)
  182123. {
  182124. case VK_SHIFT:
  182125. case VK_CONTROL:
  182126. case VK_MENU:
  182127. case VK_CAPITAL:
  182128. case VK_LWIN:
  182129. case VK_RWIN:
  182130. case VK_APPS:
  182131. case VK_NUMLOCK:
  182132. case VK_SCROLL:
  182133. case VK_LSHIFT:
  182134. case VK_RSHIFT:
  182135. case VK_LCONTROL:
  182136. case VK_LMENU:
  182137. case VK_RCONTROL:
  182138. case VK_RMENU:
  182139. sendModifierKeyChangeIfNeeded();
  182140. }
  182141. return handleKeyUpOrDown (false)
  182142. || Component::getCurrentlyModalComponent() != 0;
  182143. }
  182144. bool doKeyDown (const WPARAM key)
  182145. {
  182146. updateKeyModifiers();
  182147. bool used = false;
  182148. switch (key)
  182149. {
  182150. case VK_SHIFT:
  182151. case VK_LSHIFT:
  182152. case VK_RSHIFT:
  182153. case VK_CONTROL:
  182154. case VK_LCONTROL:
  182155. case VK_RCONTROL:
  182156. case VK_MENU:
  182157. case VK_LMENU:
  182158. case VK_RMENU:
  182159. case VK_LWIN:
  182160. case VK_RWIN:
  182161. case VK_CAPITAL:
  182162. case VK_NUMLOCK:
  182163. case VK_SCROLL:
  182164. case VK_APPS:
  182165. sendModifierKeyChangeIfNeeded();
  182166. break;
  182167. case VK_LEFT:
  182168. case VK_RIGHT:
  182169. case VK_UP:
  182170. case VK_DOWN:
  182171. case VK_PRIOR:
  182172. case VK_NEXT:
  182173. case VK_HOME:
  182174. case VK_END:
  182175. case VK_DELETE:
  182176. case VK_INSERT:
  182177. case VK_F1:
  182178. case VK_F2:
  182179. case VK_F3:
  182180. case VK_F4:
  182181. case VK_F5:
  182182. case VK_F6:
  182183. case VK_F7:
  182184. case VK_F8:
  182185. case VK_F9:
  182186. case VK_F10:
  182187. case VK_F11:
  182188. case VK_F12:
  182189. case VK_F13:
  182190. case VK_F14:
  182191. case VK_F15:
  182192. case VK_F16:
  182193. used = handleKeyUpOrDown (true);
  182194. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182195. break;
  182196. case VK_ADD:
  182197. case VK_SUBTRACT:
  182198. case VK_MULTIPLY:
  182199. case VK_DIVIDE:
  182200. case VK_SEPARATOR:
  182201. case VK_DECIMAL:
  182202. used = handleKeyUpOrDown (true);
  182203. break;
  182204. default:
  182205. used = handleKeyUpOrDown (true);
  182206. {
  182207. MSG msg;
  182208. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182209. {
  182210. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182211. // manually generate the key-press event that matches this key-down.
  182212. const UINT keyChar = MapVirtualKey (key, 2);
  182213. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182214. }
  182215. }
  182216. break;
  182217. }
  182218. if (Component::getCurrentlyModalComponent() != 0)
  182219. used = true;
  182220. return used;
  182221. }
  182222. bool doKeyChar (int key, const LPARAM flags)
  182223. {
  182224. updateKeyModifiers();
  182225. juce_wchar textChar = (juce_wchar) key;
  182226. const int virtualScanCode = (flags >> 16) & 0xff;
  182227. if (key >= '0' && key <= '9')
  182228. {
  182229. switch (virtualScanCode) // check for a numeric keypad scan-code
  182230. {
  182231. case 0x52:
  182232. case 0x4f:
  182233. case 0x50:
  182234. case 0x51:
  182235. case 0x4b:
  182236. case 0x4c:
  182237. case 0x4d:
  182238. case 0x47:
  182239. case 0x48:
  182240. case 0x49:
  182241. key = (key - '0') + KeyPress::numberPad0;
  182242. break;
  182243. default:
  182244. break;
  182245. }
  182246. }
  182247. else
  182248. {
  182249. // convert the scan code to an unmodified character code..
  182250. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182251. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182252. keyChar = LOWORD (keyChar);
  182253. if (keyChar != 0)
  182254. key = (int) keyChar;
  182255. // avoid sending junk text characters for some control-key combinations
  182256. if (textChar < ' ' && currentModifiers.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::altModifier))
  182257. textChar = 0;
  182258. }
  182259. return handleKeyPress (key, textChar);
  182260. }
  182261. bool doAppCommand (const LPARAM lParam)
  182262. {
  182263. int key = 0;
  182264. switch (GET_APPCOMMAND_LPARAM (lParam))
  182265. {
  182266. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182267. key = KeyPress::playKey;
  182268. break;
  182269. case APPCOMMAND_MEDIA_STOP:
  182270. key = KeyPress::stopKey;
  182271. break;
  182272. case APPCOMMAND_MEDIA_NEXTTRACK:
  182273. key = KeyPress::fastForwardKey;
  182274. break;
  182275. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182276. key = KeyPress::rewindKey;
  182277. break;
  182278. }
  182279. if (key != 0)
  182280. {
  182281. updateKeyModifiers();
  182282. if (hwnd == GetActiveWindow())
  182283. {
  182284. handleKeyPress (key, 0);
  182285. return true;
  182286. }
  182287. }
  182288. return false;
  182289. }
  182290. class JuceDropTarget : public IDropTarget
  182291. {
  182292. public:
  182293. JuceDropTarget (Win32ComponentPeer* const owner_)
  182294. : owner (owner_),
  182295. refCount (1)
  182296. {
  182297. }
  182298. virtual ~JuceDropTarget()
  182299. {
  182300. jassert (refCount == 0);
  182301. }
  182302. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182303. {
  182304. if (id == IID_IUnknown || id == IID_IDropTarget)
  182305. {
  182306. AddRef();
  182307. *result = this;
  182308. return S_OK;
  182309. }
  182310. *result = 0;
  182311. return E_NOINTERFACE;
  182312. }
  182313. ULONG __stdcall AddRef() { return ++refCount; }
  182314. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182315. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182316. {
  182317. updateFileList (pDataObject);
  182318. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182319. *pdwEffect = DROPEFFECT_COPY;
  182320. return S_OK;
  182321. }
  182322. HRESULT __stdcall DragLeave()
  182323. {
  182324. owner->handleFileDragExit (files);
  182325. return S_OK;
  182326. }
  182327. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182328. {
  182329. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182330. *pdwEffect = DROPEFFECT_COPY;
  182331. return S_OK;
  182332. }
  182333. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182334. {
  182335. updateFileList (pDataObject);
  182336. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182337. *pdwEffect = DROPEFFECT_COPY;
  182338. return S_OK;
  182339. }
  182340. private:
  182341. Win32ComponentPeer* const owner;
  182342. int refCount;
  182343. StringArray files;
  182344. void updateFileList (IDataObject* const pDataObject)
  182345. {
  182346. files.clear();
  182347. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182348. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182349. if (pDataObject->GetData (&format, &medium) == S_OK)
  182350. {
  182351. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182352. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182353. unsigned int i = 0;
  182354. if (pDropFiles->fWide)
  182355. {
  182356. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182357. for (;;)
  182358. {
  182359. unsigned int len = 0;
  182360. while (i + len < totalLen && fname [i + len] != 0)
  182361. ++len;
  182362. if (len == 0)
  182363. break;
  182364. files.add (String (fname + i, len));
  182365. i += len + 1;
  182366. }
  182367. }
  182368. else
  182369. {
  182370. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182371. for (;;)
  182372. {
  182373. unsigned int len = 0;
  182374. while (i + len < totalLen && fname [i + len] != 0)
  182375. ++len;
  182376. if (len == 0)
  182377. break;
  182378. files.add (String (fname + i, len));
  182379. i += len + 1;
  182380. }
  182381. }
  182382. GlobalUnlock (medium.hGlobal);
  182383. }
  182384. }
  182385. JuceDropTarget (const JuceDropTarget&);
  182386. JuceDropTarget& operator= (const JuceDropTarget&);
  182387. };
  182388. void doSettingChange()
  182389. {
  182390. Desktop::getInstance().refreshMonitorSizes();
  182391. if (fullScreen && ! isMinimised())
  182392. {
  182393. const Rectangle<int> r (component->getParentMonitorArea());
  182394. SetWindowPos (hwnd, 0,
  182395. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  182396. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  182397. }
  182398. }
  182399. public:
  182400. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182401. {
  182402. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  182403. if (peer != 0)
  182404. return peer->peerWindowProc (h, message, wParam, lParam);
  182405. return DefWindowProcW (h, message, wParam, lParam);
  182406. }
  182407. private:
  182408. static const Point<int> getPointFromLParam (LPARAM lParam) throw()
  182409. {
  182410. return Point<int> (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  182411. }
  182412. const Point<int> getCurrentMousePos() throw()
  182413. {
  182414. RECT wr;
  182415. GetWindowRect (hwnd, &wr);
  182416. const DWORD mp = GetMessagePos();
  182417. return Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182418. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop());
  182419. }
  182420. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  182421. {
  182422. if (isValidPeer (this))
  182423. {
  182424. switch (message)
  182425. {
  182426. case WM_NCHITTEST:
  182427. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182428. return HTTRANSPARENT;
  182429. if (hasTitleBar())
  182430. break;
  182431. return HTCLIENT;
  182432. case WM_PAINT:
  182433. handlePaintMessage();
  182434. return 0;
  182435. case WM_NCPAINT:
  182436. if (wParam != 1)
  182437. handlePaintMessage();
  182438. if (hasTitleBar())
  182439. break;
  182440. return 0;
  182441. case WM_ERASEBKGND:
  182442. case WM_NCCALCSIZE:
  182443. if (hasTitleBar())
  182444. break;
  182445. return 1;
  182446. case WM_MOUSEMOVE:
  182447. doMouseMove (getPointFromLParam (lParam));
  182448. return 0;
  182449. case WM_MOUSELEAVE:
  182450. doMouseExit();
  182451. return 0;
  182452. case WM_LBUTTONDOWN:
  182453. case WM_MBUTTONDOWN:
  182454. case WM_RBUTTONDOWN:
  182455. doMouseDown (getPointFromLParam (lParam), wParam);
  182456. return 0;
  182457. case WM_LBUTTONUP:
  182458. case WM_MBUTTONUP:
  182459. case WM_RBUTTONUP:
  182460. doMouseUp (getPointFromLParam (lParam), wParam);
  182461. return 0;
  182462. case WM_CAPTURECHANGED:
  182463. doCaptureChanged();
  182464. return 0;
  182465. case WM_NCMOUSEMOVE:
  182466. if (hasTitleBar())
  182467. break;
  182468. return 0;
  182469. case 0x020A: /* WM_MOUSEWHEEL */
  182470. doMouseWheel (getCurrentMousePos(), wParam, true);
  182471. return 0;
  182472. case 0x020E: /* WM_MOUSEHWHEEL */
  182473. doMouseWheel (getCurrentMousePos(), wParam, false);
  182474. return 0;
  182475. case WM_WINDOWPOSCHANGING:
  182476. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  182477. {
  182478. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  182479. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  182480. {
  182481. if (constrainer != 0)
  182482. {
  182483. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  182484. component->getY() - windowBorder.getTop(),
  182485. component->getWidth() + windowBorder.getLeftAndRight(),
  182486. component->getHeight() + windowBorder.getTopAndBottom());
  182487. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  182488. constrainer->checkBounds (pos, current,
  182489. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  182490. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  182491. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  182492. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  182493. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  182494. wp->x = pos.getX();
  182495. wp->y = pos.getY();
  182496. wp->cx = pos.getWidth();
  182497. wp->cy = pos.getHeight();
  182498. }
  182499. }
  182500. }
  182501. return 0;
  182502. case WM_WINDOWPOSCHANGED:
  182503. handleMovedOrResized();
  182504. if (dontRepaint)
  182505. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  182506. return 0;
  182507. case WM_KEYDOWN:
  182508. case WM_SYSKEYDOWN:
  182509. if (doKeyDown (wParam))
  182510. return 0;
  182511. break;
  182512. case WM_KEYUP:
  182513. case WM_SYSKEYUP:
  182514. if (doKeyUp (wParam))
  182515. return 0;
  182516. break;
  182517. case WM_CHAR:
  182518. if (doKeyChar ((int) wParam, lParam))
  182519. return 0;
  182520. break;
  182521. case WM_APPCOMMAND:
  182522. if (doAppCommand (lParam))
  182523. return TRUE;
  182524. break;
  182525. case WM_SETFOCUS:
  182526. updateKeyModifiers();
  182527. handleFocusGain();
  182528. break;
  182529. case WM_KILLFOCUS:
  182530. if (hasCreatedCaret)
  182531. {
  182532. hasCreatedCaret = false;
  182533. DestroyCaret();
  182534. }
  182535. handleFocusLoss();
  182536. break;
  182537. case WM_ACTIVATEAPP:
  182538. // Windows does weird things to process priority when you swap apps,
  182539. // so this forces an update when the app is brought to the front
  182540. if (wParam != FALSE)
  182541. juce_repeatLastProcessPriority();
  182542. else
  182543. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  182544. juce_CheckCurrentlyFocusedTopLevelWindow();
  182545. modifiersAtLastCallback = -1;
  182546. return 0;
  182547. case WM_ACTIVATE:
  182548. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  182549. {
  182550. modifiersAtLastCallback = -1;
  182551. updateKeyModifiers();
  182552. if (isMinimised())
  182553. {
  182554. component->repaint();
  182555. handleMovedOrResized();
  182556. if (! ComponentPeer::isValidPeer (this))
  182557. return 0;
  182558. }
  182559. if (LOWORD (wParam) == WA_CLICKACTIVE
  182560. && component->isCurrentlyBlockedByAnotherModalComponent())
  182561. {
  182562. const Point<int> mousePos (component->getMouseXYRelative());
  182563. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  182564. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  182565. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  182566. return 0;
  182567. }
  182568. handleBroughtToFront();
  182569. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182570. Component::getCurrentlyModalComponent()->toFront (true);
  182571. return 0;
  182572. }
  182573. break;
  182574. case WM_NCACTIVATE:
  182575. // while a temporary window is being shown, prevent Windows from deactivating the
  182576. // title bars of our main windows.
  182577. if (wParam == 0 && ! shouldDeactivateTitleBar)
  182578. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  182579. break;
  182580. case WM_MOUSEACTIVATE:
  182581. if (! component->getMouseClickGrabsKeyboardFocus())
  182582. return MA_NOACTIVATE;
  182583. break;
  182584. case WM_SHOWWINDOW:
  182585. if (wParam != 0)
  182586. handleBroughtToFront();
  182587. break;
  182588. case WM_CLOSE:
  182589. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  182590. handleUserClosingWindow();
  182591. return 0;
  182592. case WM_QUERYENDSESSION:
  182593. if (JUCEApplication::getInstance() != 0)
  182594. {
  182595. JUCEApplication::getInstance()->systemRequestedQuit();
  182596. return MessageManager::getInstance()->hasStopMessageBeenSent();
  182597. }
  182598. return TRUE;
  182599. case WM_TRAYNOTIFY:
  182600. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182601. {
  182602. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  182603. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182604. {
  182605. Component* const current = Component::getCurrentlyModalComponent();
  182606. if (current != 0)
  182607. current->inputAttemptWhenModal();
  182608. }
  182609. }
  182610. else
  182611. {
  182612. ModifierKeys eventMods (ModifierKeys::getCurrentModifiersRealtime());
  182613. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  182614. eventMods = eventMods.withFlags (ModifierKeys::leftButtonModifier);
  182615. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  182616. eventMods = eventMods.withFlags (ModifierKeys::rightButtonModifier);
  182617. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182618. eventMods = eventMods.withoutMouseButtons();
  182619. const MouseEvent e (Desktop::getInstance().getMainMouseSource(),
  182620. Point<int>(), eventMods, component, getMouseEventTime(),
  182621. Point<int>(), getMouseEventTime(), 1, false);
  182622. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  182623. {
  182624. SetFocus (hwnd);
  182625. SetForegroundWindow (hwnd);
  182626. component->mouseDown (e);
  182627. }
  182628. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  182629. {
  182630. component->mouseUp (e);
  182631. }
  182632. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  182633. {
  182634. component->mouseDoubleClick (e);
  182635. }
  182636. else if (lParam == WM_MOUSEMOVE)
  182637. {
  182638. component->mouseMove (e);
  182639. }
  182640. }
  182641. break;
  182642. case WM_SYNCPAINT:
  182643. return 0;
  182644. case WM_PALETTECHANGED:
  182645. InvalidateRect (h, 0, 0);
  182646. break;
  182647. case WM_DISPLAYCHANGE:
  182648. InvalidateRect (h, 0, 0);
  182649. createPaletteIfNeeded = true;
  182650. // intentional fall-through...
  182651. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  182652. doSettingChange();
  182653. break;
  182654. case WM_INITMENU:
  182655. if (! hasTitleBar())
  182656. {
  182657. if (isFullScreen())
  182658. {
  182659. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  182660. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  182661. }
  182662. else if (! isMinimised())
  182663. {
  182664. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  182665. }
  182666. }
  182667. break;
  182668. case WM_SYSCOMMAND:
  182669. switch (wParam & 0xfff0)
  182670. {
  182671. case SC_CLOSE:
  182672. if (sendInputAttemptWhenModalMessage())
  182673. return 0;
  182674. if (hasTitleBar())
  182675. {
  182676. PostMessage (h, WM_CLOSE, 0, 0);
  182677. return 0;
  182678. }
  182679. break;
  182680. case SC_KEYMENU:
  182681. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  182682. // obscure situations that can arise if a modal loop is started from an alt-key
  182683. // keypress).
  182684. if (hasTitleBar() && h == GetCapture())
  182685. ReleaseCapture();
  182686. break;
  182687. case SC_MAXIMIZE:
  182688. if (sendInputAttemptWhenModalMessage())
  182689. return 0;
  182690. setFullScreen (true);
  182691. return 0;
  182692. case SC_MINIMIZE:
  182693. if (sendInputAttemptWhenModalMessage())
  182694. return 0;
  182695. if (! hasTitleBar())
  182696. {
  182697. setMinimised (true);
  182698. return 0;
  182699. }
  182700. break;
  182701. case SC_RESTORE:
  182702. if (sendInputAttemptWhenModalMessage())
  182703. return 0;
  182704. if (hasTitleBar())
  182705. {
  182706. if (isFullScreen())
  182707. {
  182708. setFullScreen (false);
  182709. return 0;
  182710. }
  182711. }
  182712. else
  182713. {
  182714. if (isMinimised())
  182715. setMinimised (false);
  182716. else if (isFullScreen())
  182717. setFullScreen (false);
  182718. return 0;
  182719. }
  182720. break;
  182721. }
  182722. break;
  182723. case WM_NCLBUTTONDOWN:
  182724. case WM_NCRBUTTONDOWN:
  182725. case WM_NCMBUTTONDOWN:
  182726. sendInputAttemptWhenModalMessage();
  182727. break;
  182728. //case WM_IME_STARTCOMPOSITION;
  182729. // return 0;
  182730. case WM_GETDLGCODE:
  182731. return DLGC_WANTALLKEYS;
  182732. default:
  182733. break;
  182734. }
  182735. }
  182736. return DefWindowProcW (h, message, wParam, lParam);
  182737. }
  182738. bool sendInputAttemptWhenModalMessage()
  182739. {
  182740. if (component->isCurrentlyBlockedByAnotherModalComponent())
  182741. {
  182742. Component* const current = Component::getCurrentlyModalComponent();
  182743. if (current != 0)
  182744. current->inputAttemptWhenModal();
  182745. return true;
  182746. }
  182747. return false;
  182748. }
  182749. Win32ComponentPeer (const Win32ComponentPeer&);
  182750. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  182751. };
  182752. ModifierKeys Win32ComponentPeer::currentModifiers;
  182753. ModifierKeys Win32ComponentPeer::modifiersAtLastCallback;
  182754. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  182755. {
  182756. return new Win32ComponentPeer (this, styleFlags);
  182757. }
  182758. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  182759. void ModifierKeys::updateCurrentModifiers() throw()
  182760. {
  182761. currentModifiers = Win32ComponentPeer::currentModifiers;
  182762. }
  182763. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  182764. {
  182765. Win32ComponentPeer::updateKeyModifiers();
  182766. int keyMods = 0;
  182767. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::leftButtonModifier;
  182768. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::rightButtonModifier;
  182769. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0) keyMods |= ModifierKeys::middleButtonModifier;
  182770. Win32ComponentPeer::currentModifiers
  182771. = Win32ComponentPeer::currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  182772. return Win32ComponentPeer::currentModifiers;
  182773. }
  182774. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  182775. {
  182776. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182777. if (wp != 0)
  182778. wp->setTaskBarIcon (&newImage);
  182779. }
  182780. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  182781. {
  182782. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  182783. if (wp != 0)
  182784. wp->setTaskBarIconToolTip (tooltip);
  182785. }
  182786. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  182787. {
  182788. DWORD val = GetWindowLong (h, styleType);
  182789. if (bitIsSet)
  182790. val |= feature;
  182791. else
  182792. val &= ~feature;
  182793. SetWindowLongPtr (h, styleType, val);
  182794. SetWindowPos (h, 0, 0, 0, 0, 0,
  182795. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  182796. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  182797. }
  182798. bool Process::isForegroundProcess()
  182799. {
  182800. HWND fg = GetForegroundWindow();
  182801. if (fg == 0)
  182802. return true;
  182803. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  182804. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  182805. // have to see if any of our windows are children of the foreground window
  182806. fg = GetAncestor (fg, GA_ROOT);
  182807. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  182808. {
  182809. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  182810. if (wp != 0 && wp->isInside (fg))
  182811. return true;
  182812. }
  182813. return false;
  182814. }
  182815. bool AlertWindow::showNativeDialogBox (const String& title,
  182816. const String& bodyText,
  182817. bool isOkCancel)
  182818. {
  182819. return MessageBox (0, bodyText, title,
  182820. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  182821. : MB_OK)) == IDOK;
  182822. }
  182823. void Desktop::createMouseInputSources()
  182824. {
  182825. mouseSources.add (new MouseInputSource (0, true));
  182826. }
  182827. const Point<int> Desktop::getMousePosition()
  182828. {
  182829. POINT mousePos;
  182830. GetCursorPos (&mousePos);
  182831. return Point<int> (mousePos.x, mousePos.y);
  182832. }
  182833. void Desktop::setMousePosition (const Point<int>& newPosition)
  182834. {
  182835. SetCursorPos (newPosition.getX(), newPosition.getY());
  182836. }
  182837. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  182838. {
  182839. return new Image (format, imageWidth, imageHeight, clearImage);
  182840. }
  182841. class ScreenSaverDefeater : public Timer,
  182842. public DeletedAtShutdown
  182843. {
  182844. public:
  182845. ScreenSaverDefeater() throw()
  182846. {
  182847. startTimer (10000);
  182848. timerCallback();
  182849. }
  182850. ~ScreenSaverDefeater() {}
  182851. void timerCallback()
  182852. {
  182853. if (Process::isForegroundProcess())
  182854. {
  182855. // simulate a shift key getting pressed..
  182856. INPUT input[2];
  182857. input[0].type = INPUT_KEYBOARD;
  182858. input[0].ki.wVk = VK_SHIFT;
  182859. input[0].ki.dwFlags = 0;
  182860. input[0].ki.dwExtraInfo = 0;
  182861. input[1].type = INPUT_KEYBOARD;
  182862. input[1].ki.wVk = VK_SHIFT;
  182863. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  182864. input[1].ki.dwExtraInfo = 0;
  182865. SendInput (2, input, sizeof (INPUT));
  182866. }
  182867. }
  182868. };
  182869. static ScreenSaverDefeater* screenSaverDefeater = 0;
  182870. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  182871. {
  182872. if (isEnabled)
  182873. {
  182874. deleteAndZero (screenSaverDefeater);
  182875. }
  182876. else if (screenSaverDefeater == 0)
  182877. {
  182878. screenSaverDefeater = new ScreenSaverDefeater();
  182879. }
  182880. }
  182881. bool Desktop::isScreenSaverEnabled() throw()
  182882. {
  182883. return screenSaverDefeater == 0;
  182884. }
  182885. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  182886. {
  182887. if (enableOrDisable)
  182888. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  182889. }
  182890. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  182891. {
  182892. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  182893. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  182894. return TRUE;
  182895. }
  182896. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  182897. {
  182898. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  182899. // make sure the first in the list is the main monitor
  182900. for (int i = 1; i < monitorCoords.size(); ++i)
  182901. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  182902. monitorCoords.swap (i, 0);
  182903. if (monitorCoords.size() == 0)
  182904. {
  182905. RECT r;
  182906. GetWindowRect (GetDesktopWindow(), &r);
  182907. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  182908. }
  182909. if (clipToWorkArea)
  182910. {
  182911. // clip the main monitor to the active non-taskbar area
  182912. RECT r;
  182913. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  182914. Rectangle<int>& screen = monitorCoords.getReference (0);
  182915. screen.setPosition (jmax (screen.getX(), (int) r.left),
  182916. jmax (screen.getY(), (int) r.top));
  182917. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  182918. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  182919. }
  182920. }
  182921. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  182922. {
  182923. Image* im = 0;
  182924. if (bitmap != 0)
  182925. {
  182926. BITMAP bm;
  182927. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  182928. && bm.bmWidth > 0 && bm.bmHeight > 0)
  182929. {
  182930. HDC tempDC = GetDC (0);
  182931. HDC dc = CreateCompatibleDC (tempDC);
  182932. ReleaseDC (0, tempDC);
  182933. SelectObject (dc, bitmap);
  182934. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  182935. for (int y = bm.bmHeight; --y >= 0;)
  182936. {
  182937. for (int x = bm.bmWidth; --x >= 0;)
  182938. {
  182939. COLORREF col = GetPixel (dc, x, y);
  182940. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  182941. (uint8) GetGValue (col),
  182942. (uint8) GetBValue (col)));
  182943. }
  182944. }
  182945. DeleteDC (dc);
  182946. }
  182947. }
  182948. return im;
  182949. }
  182950. static Image* createImageFromHICON (HICON icon) throw()
  182951. {
  182952. ICONINFO info;
  182953. if (GetIconInfo (icon, &info))
  182954. {
  182955. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  182956. if (mask == 0)
  182957. return 0;
  182958. Image* const image = createImageFromHBITMAP (info.hbmColor);
  182959. if (image == 0)
  182960. return mask;
  182961. for (int y = image->getHeight(); --y >= 0;)
  182962. {
  182963. for (int x = image->getWidth(); --x >= 0;)
  182964. {
  182965. const float brightness = mask->getPixelAt (x, y).getBrightness();
  182966. if (brightness > 0.0f)
  182967. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  182968. }
  182969. }
  182970. delete mask;
  182971. return image;
  182972. }
  182973. return 0;
  182974. }
  182975. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  182976. {
  182977. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  182978. ICONINFO info;
  182979. info.fIcon = isIcon;
  182980. info.xHotspot = hotspotX;
  182981. info.yHotspot = hotspotY;
  182982. info.hbmMask = mask;
  182983. HICON hi = 0;
  182984. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  182985. {
  182986. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  182987. Graphics g (bitmap);
  182988. g.drawImageAt (&image, 0, 0);
  182989. info.hbmColor = bitmap.hBitmap;
  182990. hi = CreateIconIndirect (&info);
  182991. }
  182992. else
  182993. {
  182994. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  182995. HDC colDC = CreateCompatibleDC (GetDC (0));
  182996. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  182997. SelectObject (colDC, colour);
  182998. SelectObject (alphaDC, mask);
  182999. for (int y = image.getHeight(); --y >= 0;)
  183000. {
  183001. for (int x = image.getWidth(); --x >= 0;)
  183002. {
  183003. const Colour c (image.getPixelAt (x, y));
  183004. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183005. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183006. }
  183007. }
  183008. DeleteDC (colDC);
  183009. DeleteDC (alphaDC);
  183010. info.hbmColor = colour;
  183011. hi = CreateIconIndirect (&info);
  183012. DeleteObject (colour);
  183013. }
  183014. DeleteObject (mask);
  183015. return hi;
  183016. }
  183017. Image* juce_createIconForFile (const File& file)
  183018. {
  183019. Image* image = 0;
  183020. WCHAR filename [1024];
  183021. file.getFullPathName().copyToUnicode (filename, 1023);
  183022. WORD iconNum = 0;
  183023. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183024. filename, &iconNum);
  183025. if (icon != 0)
  183026. {
  183027. image = createImageFromHICON (icon);
  183028. DestroyIcon (icon);
  183029. }
  183030. return image;
  183031. }
  183032. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  183033. {
  183034. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183035. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183036. const Image* im = &image;
  183037. Image* newIm = 0;
  183038. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183039. {
  183040. im = newIm = image.createCopy (maxW, maxH);
  183041. hotspotX = (hotspotX * maxW) / image.getWidth();
  183042. hotspotY = (hotspotY * maxH) / image.getHeight();
  183043. }
  183044. void* cursorH = 0;
  183045. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183046. if (os == SystemStats::WinXP)
  183047. {
  183048. cursorH = createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183049. }
  183050. else
  183051. {
  183052. const int stride = (maxW + 7) >> 3;
  183053. HeapBlock <uint8> andPlane, xorPlane;
  183054. andPlane.calloc (stride * maxH);
  183055. xorPlane.calloc (stride * maxH);
  183056. int index = 0;
  183057. for (int y = 0; y < maxH; ++y)
  183058. {
  183059. for (int x = 0; x < maxW; ++x)
  183060. {
  183061. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183062. const Colour pixelColour (im->getPixelAt (x, y));
  183063. if (pixelColour.getAlpha() < 127)
  183064. andPlane [index + (x >> 3)] |= bit;
  183065. else if (pixelColour.getBrightness() >= 0.5f)
  183066. xorPlane [index + (x >> 3)] |= bit;
  183067. }
  183068. index += stride;
  183069. }
  183070. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183071. }
  183072. delete newIm;
  183073. return cursorH;
  183074. }
  183075. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  183076. {
  183077. if (cursorHandle != 0 && ! isStandard)
  183078. DestroyCursor ((HCURSOR) cursorHandle);
  183079. }
  183080. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  183081. {
  183082. LPCTSTR cursorName = IDC_ARROW;
  183083. switch (type)
  183084. {
  183085. case MouseCursor::NormalCursor:
  183086. cursorName = IDC_ARROW;
  183087. break;
  183088. case MouseCursor::NoCursor:
  183089. return 0;
  183090. case MouseCursor::DraggingHandCursor:
  183091. {
  183092. static void* dragHandCursor = 0;
  183093. if (dragHandCursor == 0)
  183094. {
  183095. static const unsigned char dragHandData[] =
  183096. { 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,
  183097. 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,
  183098. 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 };
  183099. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183100. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183101. }
  183102. return dragHandCursor;
  183103. }
  183104. case MouseCursor::WaitCursor:
  183105. cursorName = IDC_WAIT;
  183106. break;
  183107. case MouseCursor::IBeamCursor:
  183108. cursorName = IDC_IBEAM;
  183109. break;
  183110. case MouseCursor::PointingHandCursor:
  183111. cursorName = MAKEINTRESOURCE(32649);
  183112. break;
  183113. case MouseCursor::LeftRightResizeCursor:
  183114. case MouseCursor::LeftEdgeResizeCursor:
  183115. case MouseCursor::RightEdgeResizeCursor:
  183116. cursorName = IDC_SIZEWE;
  183117. break;
  183118. case MouseCursor::UpDownResizeCursor:
  183119. case MouseCursor::TopEdgeResizeCursor:
  183120. case MouseCursor::BottomEdgeResizeCursor:
  183121. cursorName = IDC_SIZENS;
  183122. break;
  183123. case MouseCursor::TopLeftCornerResizeCursor:
  183124. case MouseCursor::BottomRightCornerResizeCursor:
  183125. cursorName = IDC_SIZENWSE;
  183126. break;
  183127. case MouseCursor::TopRightCornerResizeCursor:
  183128. case MouseCursor::BottomLeftCornerResizeCursor:
  183129. cursorName = IDC_SIZENESW;
  183130. break;
  183131. case MouseCursor::UpDownLeftRightResizeCursor:
  183132. cursorName = IDC_SIZEALL;
  183133. break;
  183134. case MouseCursor::CrosshairCursor:
  183135. cursorName = IDC_CROSS;
  183136. break;
  183137. case MouseCursor::CopyingCursor:
  183138. // can't seem to find one of these in the win32 list..
  183139. break;
  183140. }
  183141. HCURSOR cursorH = LoadCursor (0, cursorName);
  183142. if (cursorH == 0)
  183143. cursorH = LoadCursor (0, IDC_ARROW);
  183144. return cursorH;
  183145. }
  183146. void MouseCursor::showInWindow (ComponentPeer*) const
  183147. {
  183148. SetCursor ((HCURSOR) getHandle());
  183149. }
  183150. void MouseCursor::showInAllWindows() const
  183151. {
  183152. showInWindow (0);
  183153. }
  183154. class JuceDropSource : public IDropSource
  183155. {
  183156. int refCount;
  183157. public:
  183158. JuceDropSource()
  183159. : refCount (1)
  183160. {
  183161. }
  183162. virtual ~JuceDropSource()
  183163. {
  183164. jassert (refCount == 0);
  183165. }
  183166. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183167. {
  183168. if (id == IID_IUnknown || id == IID_IDropSource)
  183169. {
  183170. AddRef();
  183171. *result = this;
  183172. return S_OK;
  183173. }
  183174. *result = 0;
  183175. return E_NOINTERFACE;
  183176. }
  183177. ULONG __stdcall AddRef() { return ++refCount; }
  183178. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183179. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183180. {
  183181. if (escapePressed)
  183182. return DRAGDROP_S_CANCEL;
  183183. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183184. return DRAGDROP_S_DROP;
  183185. return S_OK;
  183186. }
  183187. HRESULT __stdcall GiveFeedback (DWORD)
  183188. {
  183189. return DRAGDROP_S_USEDEFAULTCURSORS;
  183190. }
  183191. };
  183192. class JuceEnumFormatEtc : public IEnumFORMATETC
  183193. {
  183194. public:
  183195. JuceEnumFormatEtc (const FORMATETC* const format_)
  183196. : refCount (1),
  183197. format (format_),
  183198. index (0)
  183199. {
  183200. }
  183201. virtual ~JuceEnumFormatEtc()
  183202. {
  183203. jassert (refCount == 0);
  183204. }
  183205. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183206. {
  183207. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183208. {
  183209. AddRef();
  183210. *result = this;
  183211. return S_OK;
  183212. }
  183213. *result = 0;
  183214. return E_NOINTERFACE;
  183215. }
  183216. ULONG __stdcall AddRef() { return ++refCount; }
  183217. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183218. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183219. {
  183220. if (result == 0)
  183221. return E_POINTER;
  183222. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183223. newOne->index = index;
  183224. *result = newOne;
  183225. return S_OK;
  183226. }
  183227. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183228. {
  183229. if (pceltFetched != 0)
  183230. *pceltFetched = 0;
  183231. else if (celt != 1)
  183232. return S_FALSE;
  183233. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183234. {
  183235. copyFormatEtc (lpFormatEtc [0], *format);
  183236. ++index;
  183237. if (pceltFetched != 0)
  183238. *pceltFetched = 1;
  183239. return S_OK;
  183240. }
  183241. return S_FALSE;
  183242. }
  183243. HRESULT __stdcall Skip (ULONG celt)
  183244. {
  183245. if (index + (int) celt >= 1)
  183246. return S_FALSE;
  183247. index += celt;
  183248. return S_OK;
  183249. }
  183250. HRESULT __stdcall Reset()
  183251. {
  183252. index = 0;
  183253. return S_OK;
  183254. }
  183255. private:
  183256. int refCount;
  183257. const FORMATETC* const format;
  183258. int index;
  183259. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183260. {
  183261. dest = source;
  183262. if (source.ptd != 0)
  183263. {
  183264. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183265. *(dest.ptd) = *(source.ptd);
  183266. }
  183267. }
  183268. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183269. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183270. };
  183271. class JuceDataObject : public IDataObject
  183272. {
  183273. JuceDropSource* const dropSource;
  183274. const FORMATETC* const format;
  183275. const STGMEDIUM* const medium;
  183276. int refCount;
  183277. JuceDataObject (const JuceDataObject&);
  183278. JuceDataObject& operator= (const JuceDataObject&);
  183279. public:
  183280. JuceDataObject (JuceDropSource* const dropSource_,
  183281. const FORMATETC* const format_,
  183282. const STGMEDIUM* const medium_)
  183283. : dropSource (dropSource_),
  183284. format (format_),
  183285. medium (medium_),
  183286. refCount (1)
  183287. {
  183288. }
  183289. virtual ~JuceDataObject()
  183290. {
  183291. jassert (refCount == 0);
  183292. }
  183293. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183294. {
  183295. if (id == IID_IUnknown || id == IID_IDataObject)
  183296. {
  183297. AddRef();
  183298. *result = this;
  183299. return S_OK;
  183300. }
  183301. *result = 0;
  183302. return E_NOINTERFACE;
  183303. }
  183304. ULONG __stdcall AddRef() { return ++refCount; }
  183305. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183306. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183307. {
  183308. if ((pFormatEtc->tymed & format->tymed) != 0
  183309. && pFormatEtc->cfFormat == format->cfFormat
  183310. && pFormatEtc->dwAspect == format->dwAspect)
  183311. {
  183312. pMedium->tymed = format->tymed;
  183313. pMedium->pUnkForRelease = 0;
  183314. if (format->tymed == TYMED_HGLOBAL)
  183315. {
  183316. const SIZE_T len = GlobalSize (medium->hGlobal);
  183317. void* const src = GlobalLock (medium->hGlobal);
  183318. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183319. memcpy (dst, src, len);
  183320. GlobalUnlock (medium->hGlobal);
  183321. pMedium->hGlobal = dst;
  183322. return S_OK;
  183323. }
  183324. }
  183325. return DV_E_FORMATETC;
  183326. }
  183327. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183328. {
  183329. if (f == 0)
  183330. return E_INVALIDARG;
  183331. if (f->tymed == format->tymed
  183332. && f->cfFormat == format->cfFormat
  183333. && f->dwAspect == format->dwAspect)
  183334. return S_OK;
  183335. return DV_E_FORMATETC;
  183336. }
  183337. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183338. {
  183339. pFormatEtcOut->ptd = 0;
  183340. return E_NOTIMPL;
  183341. }
  183342. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183343. {
  183344. if (result == 0)
  183345. return E_POINTER;
  183346. if (direction == DATADIR_GET)
  183347. {
  183348. *result = new JuceEnumFormatEtc (format);
  183349. return S_OK;
  183350. }
  183351. *result = 0;
  183352. return E_NOTIMPL;
  183353. }
  183354. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183355. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183356. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183357. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183358. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183359. };
  183360. static HDROP createHDrop (const StringArray& fileNames) throw()
  183361. {
  183362. int totalChars = 0;
  183363. for (int i = fileNames.size(); --i >= 0;)
  183364. totalChars += fileNames[i].length() + 1;
  183365. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183366. sizeof (DROPFILES)
  183367. + sizeof (WCHAR) * (totalChars + 2));
  183368. if (hDrop != 0)
  183369. {
  183370. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183371. pDropFiles->pFiles = sizeof (DROPFILES);
  183372. pDropFiles->fWide = true;
  183373. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183374. for (int i = 0; i < fileNames.size(); ++i)
  183375. {
  183376. fileNames[i].copyToUnicode (fname, 2048);
  183377. fname += fileNames[i].length() + 1;
  183378. }
  183379. *fname = 0;
  183380. GlobalUnlock (hDrop);
  183381. }
  183382. return hDrop;
  183383. }
  183384. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183385. {
  183386. JuceDropSource* const source = new JuceDropSource();
  183387. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183388. DWORD effect;
  183389. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183390. data->Release();
  183391. source->Release();
  183392. return res == DRAGDROP_S_DROP;
  183393. }
  183394. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183395. {
  183396. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183397. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183398. medium.hGlobal = createHDrop (files);
  183399. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183400. : DROPEFFECT_COPY);
  183401. }
  183402. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183403. {
  183404. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183405. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183406. const int numChars = text.length();
  183407. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183408. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (medium.hGlobal));
  183409. text.copyToUnicode (data, numChars + 1);
  183410. format.cfFormat = CF_UNICODETEXT;
  183411. GlobalUnlock (medium.hGlobal);
  183412. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183413. }
  183414. #endif
  183415. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183416. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183417. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183418. // compiled on its own).
  183419. #if JUCE_INCLUDED_FILE
  183420. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183421. NEWTEXTMETRICEXW*,
  183422. int type,
  183423. LPARAM lParam)
  183424. {
  183425. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  183426. {
  183427. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183428. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters ("@"));
  183429. }
  183430. return 1;
  183431. }
  183432. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  183433. NEWTEXTMETRICEXW*,
  183434. int type,
  183435. LPARAM lParam)
  183436. {
  183437. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 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. const String fontName (lpelfe->elfLogFont.lfFaceName);
  183448. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  183449. HDC dc = CreateCompatibleDC (0);
  183450. EnumFontFamiliesEx (dc, &lf,
  183451. (FONTENUMPROCW) &wfontEnum2,
  183452. lParam, 0);
  183453. DeleteDC (dc);
  183454. }
  183455. return 1;
  183456. }
  183457. const StringArray Font::findAllTypefaceNames()
  183458. {
  183459. StringArray results;
  183460. HDC dc = CreateCompatibleDC (0);
  183461. {
  183462. LOGFONTW lf;
  183463. zerostruct (lf);
  183464. lf.lfWeight = FW_DONTCARE;
  183465. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183466. lf.lfQuality = DEFAULT_QUALITY;
  183467. lf.lfCharSet = DEFAULT_CHARSET;
  183468. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183469. lf.lfPitchAndFamily = FF_DONTCARE;
  183470. lf.lfFaceName[0] = 0;
  183471. EnumFontFamiliesEx (dc, &lf,
  183472. (FONTENUMPROCW) &wfontEnum1,
  183473. (LPARAM) &results, 0);
  183474. }
  183475. DeleteDC (dc);
  183476. results.sort (true);
  183477. return results;
  183478. }
  183479. extern bool juce_IsRunningInWine();
  183480. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  183481. {
  183482. if (juce_IsRunningInWine())
  183483. {
  183484. // If we're running in Wine, then use fonts that might be available on Linux..
  183485. defaultSans = "Bitstream Vera Sans";
  183486. defaultSerif = "Bitstream Vera Serif";
  183487. defaultFixed = "Bitstream Vera Sans Mono";
  183488. }
  183489. else
  183490. {
  183491. defaultSans = "Verdana";
  183492. defaultSerif = "Times";
  183493. defaultFixed = "Lucida Console";
  183494. }
  183495. }
  183496. class FontDCHolder : private DeletedAtShutdown
  183497. {
  183498. public:
  183499. FontDCHolder() throw()
  183500. : dc (0), numKPs (0), size (0),
  183501. bold (false), italic (false)
  183502. {
  183503. }
  183504. ~FontDCHolder() throw()
  183505. {
  183506. if (dc != 0)
  183507. {
  183508. DeleteDC (dc);
  183509. DeleteObject (fontH);
  183510. }
  183511. clearSingletonInstance();
  183512. }
  183513. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  183514. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  183515. {
  183516. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  183517. {
  183518. fontName = fontName_;
  183519. bold = bold_;
  183520. italic = italic_;
  183521. size = size_;
  183522. if (dc != 0)
  183523. {
  183524. DeleteDC (dc);
  183525. DeleteObject (fontH);
  183526. kps.free();
  183527. }
  183528. fontH = 0;
  183529. dc = CreateCompatibleDC (0);
  183530. SetMapperFlags (dc, 0);
  183531. SetMapMode (dc, MM_TEXT);
  183532. LOGFONTW lfw;
  183533. zerostruct (lfw);
  183534. lfw.lfCharSet = DEFAULT_CHARSET;
  183535. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  183536. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  183537. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  183538. lfw.lfQuality = PROOF_QUALITY;
  183539. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  183540. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  183541. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  183542. lfw.lfHeight = size > 0 ? size : -256;
  183543. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  183544. if (standardSizedFont != 0)
  183545. {
  183546. if (SelectObject (dc, standardSizedFont) != 0)
  183547. {
  183548. fontH = standardSizedFont;
  183549. if (size == 0)
  183550. {
  183551. OUTLINETEXTMETRIC otm;
  183552. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  183553. {
  183554. lfw.lfHeight = -(int) otm.otmEMSquare;
  183555. fontH = CreateFontIndirect (&lfw);
  183556. SelectObject (dc, fontH);
  183557. DeleteObject (standardSizedFont);
  183558. }
  183559. }
  183560. }
  183561. else
  183562. {
  183563. jassertfalse
  183564. }
  183565. }
  183566. else
  183567. {
  183568. jassertfalse
  183569. }
  183570. }
  183571. return dc;
  183572. }
  183573. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  183574. {
  183575. if (kps == 0)
  183576. {
  183577. numKPs = GetKerningPairs (dc, 0, 0);
  183578. kps.calloc (numKPs);
  183579. GetKerningPairs (dc, numKPs, kps);
  183580. }
  183581. numKPs_ = numKPs;
  183582. return kps;
  183583. }
  183584. private:
  183585. HFONT fontH;
  183586. HDC dc;
  183587. String fontName;
  183588. HeapBlock <KERNINGPAIR> kps;
  183589. int numKPs, size;
  183590. bool bold, italic;
  183591. FontDCHolder (const FontDCHolder&);
  183592. FontDCHolder& operator= (const FontDCHolder&);
  183593. };
  183594. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  183595. class WindowsTypeface : public CustomTypeface
  183596. {
  183597. public:
  183598. WindowsTypeface (const Font& font)
  183599. {
  183600. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  183601. font.isBold(), font.isItalic(), 0);
  183602. TEXTMETRIC tm;
  183603. tm.tmAscent = tm.tmHeight = 1;
  183604. tm.tmDefaultChar = 0;
  183605. GetTextMetrics (dc, &tm);
  183606. setCharacteristics (font.getTypefaceName(),
  183607. tm.tmAscent / (float) tm.tmHeight,
  183608. font.isBold(), font.isItalic(),
  183609. tm.tmDefaultChar);
  183610. }
  183611. bool loadGlyphIfPossible (juce_wchar character)
  183612. {
  183613. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  183614. GLYPHMETRICS gm;
  183615. {
  183616. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  183617. WORD index = 0;
  183618. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  183619. && index == 0xffff)
  183620. {
  183621. return false;
  183622. }
  183623. }
  183624. Path glyphPath;
  183625. TEXTMETRIC tm;
  183626. if (! GetTextMetrics (dc, &tm))
  183627. {
  183628. addGlyph (character, glyphPath, 0);
  183629. return true;
  183630. }
  183631. const float height = (float) tm.tmHeight;
  183632. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  183633. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  183634. &gm, 0, 0, &identityMatrix);
  183635. if (bufSize > 0)
  183636. {
  183637. HeapBlock<char> data (bufSize);
  183638. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  183639. bufSize, data, &identityMatrix);
  183640. const TTPOLYGONHEADER* pheader = reinterpret_cast<TTPOLYGONHEADER*> (data.getData());
  183641. const float scaleX = 1.0f / height;
  183642. const float scaleY = -1.0f / height;
  183643. while ((char*) pheader < data + bufSize)
  183644. {
  183645. float x = scaleX * pheader->pfxStart.x.value;
  183646. float y = scaleY * pheader->pfxStart.y.value;
  183647. glyphPath.startNewSubPath (x, y);
  183648. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  183649. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  183650. while ((const char*) curve < curveEnd)
  183651. {
  183652. if (curve->wType == TT_PRIM_LINE)
  183653. {
  183654. for (int i = 0; i < curve->cpfx; ++i)
  183655. {
  183656. x = scaleX * curve->apfx[i].x.value;
  183657. y = scaleY * curve->apfx[i].y.value;
  183658. glyphPath.lineTo (x, y);
  183659. }
  183660. }
  183661. else if (curve->wType == TT_PRIM_QSPLINE)
  183662. {
  183663. for (int i = 0; i < curve->cpfx - 1; ++i)
  183664. {
  183665. const float x2 = scaleX * curve->apfx[i].x.value;
  183666. const float y2 = scaleY * curve->apfx[i].y.value;
  183667. float x3, y3;
  183668. if (i < curve->cpfx - 2)
  183669. {
  183670. x3 = 0.5f * (x2 + scaleX * curve->apfx[i + 1].x.value);
  183671. y3 = 0.5f * (y2 + scaleY * curve->apfx[i + 1].y.value);
  183672. }
  183673. else
  183674. {
  183675. x3 = scaleX * curve->apfx[i + 1].x.value;
  183676. y3 = scaleY * curve->apfx[i + 1].y.value;
  183677. }
  183678. glyphPath.quadraticTo (x2, y2, x3, y3);
  183679. x = x3;
  183680. y = y3;
  183681. }
  183682. }
  183683. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  183684. }
  183685. pheader = (const TTPOLYGONHEADER*) curve;
  183686. glyphPath.closeSubPath();
  183687. }
  183688. }
  183689. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  183690. int numKPs;
  183691. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  183692. for (int i = 0; i < numKPs; ++i)
  183693. {
  183694. if (kps[i].wFirst == character)
  183695. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  183696. kps[i].iKernAmount / height);
  183697. }
  183698. return true;
  183699. }
  183700. };
  183701. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  183702. {
  183703. return new WindowsTypeface (font);
  183704. }
  183705. #endif
  183706. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  183707. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  183708. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183709. // compiled on its own).
  183710. #if JUCE_INCLUDED_FILE
  183711. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  183712. namespace FileChooserHelpers
  183713. {
  183714. static const void* defaultDirPath = 0;
  183715. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  183716. static Component* currentExtraFileWin = 0;
  183717. static bool areThereAnyAlwaysOnTopWindows()
  183718. {
  183719. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  183720. {
  183721. Component* c = Desktop::getInstance().getComponent (i);
  183722. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  183723. return true;
  183724. }
  183725. return false;
  183726. }
  183727. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  183728. {
  183729. if (msg == BFFM_INITIALIZED)
  183730. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  183731. else if (msg == BFFM_VALIDATEFAILEDW)
  183732. returnedString = (LPCWSTR) lParam;
  183733. else if (msg == BFFM_VALIDATEFAILEDA)
  183734. returnedString = (const char*) lParam;
  183735. return 0;
  183736. }
  183737. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  183738. {
  183739. if (currentExtraFileWin != 0)
  183740. {
  183741. if (uiMsg == WM_INITDIALOG)
  183742. {
  183743. HWND dialogH = GetParent (hdlg);
  183744. jassert (dialogH != 0);
  183745. if (dialogH == 0)
  183746. dialogH = hdlg;
  183747. RECT r, cr;
  183748. GetWindowRect (dialogH, &r);
  183749. GetClientRect (dialogH, &cr);
  183750. SetWindowPos (dialogH, 0,
  183751. r.left, r.top,
  183752. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  183753. jmax (150, (int) (r.bottom - r.top)),
  183754. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  183755. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  183756. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  183757. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  183758. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  183759. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  183760. }
  183761. else if (uiMsg == WM_NOTIFY)
  183762. {
  183763. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  183764. if (ofn->hdr.code == CDN_SELCHANGE)
  183765. {
  183766. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  183767. if (comp != 0)
  183768. {
  183769. TCHAR path [MAX_PATH * 2];
  183770. path[0] = 0;
  183771. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  183772. const String fn ((const WCHAR*) path);
  183773. comp->selectedFileChanged (File (fn));
  183774. }
  183775. }
  183776. }
  183777. }
  183778. return 0;
  183779. }
  183780. class FPComponentHolder : public Component
  183781. {
  183782. public:
  183783. FPComponentHolder()
  183784. {
  183785. setVisible (true);
  183786. setOpaque (true);
  183787. }
  183788. ~FPComponentHolder()
  183789. {
  183790. }
  183791. void paint (Graphics& g)
  183792. {
  183793. g.fillAll (Colours::lightgrey);
  183794. }
  183795. private:
  183796. FPComponentHolder (const FPComponentHolder&);
  183797. FPComponentHolder& operator= (const FPComponentHolder&);
  183798. };
  183799. }
  183800. void FileChooser::showPlatformDialog (Array<File>& results,
  183801. const String& title,
  183802. const File& currentFileOrDirectory,
  183803. const String& filter,
  183804. bool selectsDirectory,
  183805. bool /*selectsFiles*/,
  183806. bool isSaveDialogue,
  183807. bool warnAboutOverwritingExistingFiles,
  183808. bool selectMultipleFiles,
  183809. FilePreviewComponent* extraInfoComponent)
  183810. {
  183811. using namespace FileChooserHelpers;
  183812. const int numCharsAvailable = 32768;
  183813. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  183814. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  183815. int fnameIdx = 0;
  183816. JUCE_TRY
  183817. {
  183818. // use a modal window as the parent for this dialog box
  183819. // to block input from other app windows
  183820. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  183821. Component w (String::empty);
  183822. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  183823. mainMon.getY() + mainMon.getHeight() / 4,
  183824. 0, 0);
  183825. w.setOpaque (true);
  183826. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  183827. w.addToDesktop (0);
  183828. if (extraInfoComponent == 0)
  183829. w.enterModalState();
  183830. String initialDir;
  183831. if (currentFileOrDirectory.isDirectory())
  183832. {
  183833. initialDir = currentFileOrDirectory.getFullPathName();
  183834. }
  183835. else
  183836. {
  183837. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  183838. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  183839. }
  183840. if (currentExtraFileWin->isValidComponent())
  183841. {
  183842. jassertfalse
  183843. return;
  183844. }
  183845. if (selectsDirectory)
  183846. {
  183847. LPITEMIDLIST list = 0;
  183848. filenameSpace.fillWith (0);
  183849. {
  183850. BROWSEINFO bi;
  183851. zerostruct (bi);
  183852. bi.hwndOwner = (HWND) w.getWindowHandle();
  183853. bi.pszDisplayName = fname;
  183854. bi.lpszTitle = title;
  183855. bi.lpfn = browseCallbackProc;
  183856. #ifdef BIF_USENEWUI
  183857. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  183858. #else
  183859. bi.ulFlags = 0x50;
  183860. #endif
  183861. defaultDirPath = (const WCHAR*) initialDir;
  183862. list = SHBrowseForFolder (&bi);
  183863. if (! SHGetPathFromIDListW (list, fname))
  183864. {
  183865. fname[0] = 0;
  183866. returnedString = String::empty;
  183867. }
  183868. }
  183869. LPMALLOC al;
  183870. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  183871. al->Free (list);
  183872. defaultDirPath = 0;
  183873. if (returnedString.isNotEmpty())
  183874. {
  183875. const String stringFName (fname);
  183876. results.add (File (stringFName).getSiblingFile (returnedString));
  183877. returnedString = String::empty;
  183878. return;
  183879. }
  183880. }
  183881. else
  183882. {
  183883. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  183884. if (warnAboutOverwritingExistingFiles)
  183885. flags |= OFN_OVERWRITEPROMPT;
  183886. if (selectMultipleFiles)
  183887. flags |= OFN_ALLOWMULTISELECT;
  183888. if (extraInfoComponent != 0)
  183889. {
  183890. flags |= OFN_ENABLEHOOK;
  183891. currentExtraFileWin = new FPComponentHolder();
  183892. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  183893. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  183894. extraInfoComponent->getHeight());
  183895. currentExtraFileWin->addToDesktop (0);
  183896. currentExtraFileWin->enterModalState();
  183897. }
  183898. {
  183899. WCHAR filters [1024];
  183900. zeromem (filters, sizeof (filters));
  183901. filter.copyToUnicode (filters, 1024);
  183902. filter.copyToUnicode (filters + filter.length() + 1,
  183903. 1022 - filter.length());
  183904. OPENFILENAMEW of;
  183905. zerostruct (of);
  183906. #ifdef OPENFILENAME_SIZE_VERSION_400W
  183907. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  183908. #else
  183909. of.lStructSize = sizeof (of);
  183910. #endif
  183911. of.hwndOwner = (HWND) w.getWindowHandle();
  183912. of.lpstrFilter = filters;
  183913. of.nFilterIndex = 1;
  183914. of.lpstrFile = fname;
  183915. of.nMaxFile = numCharsAvailable;
  183916. of.lpstrInitialDir = initialDir;
  183917. of.lpstrTitle = title;
  183918. of.Flags = flags;
  183919. if (extraInfoComponent != 0)
  183920. of.lpfnHook = &openCallback;
  183921. if (isSaveDialogue)
  183922. {
  183923. if (! GetSaveFileName (&of))
  183924. fname[0] = 0;
  183925. else
  183926. fnameIdx = of.nFileOffset;
  183927. }
  183928. else
  183929. {
  183930. if (! GetOpenFileName (&of))
  183931. fname[0] = 0;
  183932. else
  183933. fnameIdx = of.nFileOffset;
  183934. }
  183935. }
  183936. }
  183937. }
  183938. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  183939. catch (...)
  183940. {
  183941. fname[0] = 0;
  183942. }
  183943. #endif
  183944. deleteAndZero (currentExtraFileWin);
  183945. const WCHAR* const files = fname;
  183946. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  183947. {
  183948. const WCHAR* filename = files + fnameIdx;
  183949. while (*filename != 0)
  183950. {
  183951. const String filepath (String (files) + "\\" + String (filename));
  183952. results.add (File (filepath));
  183953. filename += CharacterFunctions::length (filename) + 1;
  183954. }
  183955. }
  183956. else if (files[0] != 0)
  183957. {
  183958. results.add (File (files));
  183959. }
  183960. }
  183961. #endif
  183962. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  183963. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  183964. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183965. // compiled on its own).
  183966. #if JUCE_INCLUDED_FILE
  183967. void SystemClipboard::copyTextToClipboard (const String& text)
  183968. {
  183969. if (OpenClipboard (0) != 0)
  183970. {
  183971. if (EmptyClipboard() != 0)
  183972. {
  183973. const int len = text.length();
  183974. if (len > 0)
  183975. {
  183976. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  183977. (len + 1) * sizeof (wchar_t));
  183978. if (bufH != 0)
  183979. {
  183980. WCHAR* const data = static_cast <WCHAR*> (GlobalLock (bufH));
  183981. text.copyToUnicode (data, len);
  183982. GlobalUnlock (bufH);
  183983. SetClipboardData (CF_UNICODETEXT, bufH);
  183984. }
  183985. }
  183986. }
  183987. CloseClipboard();
  183988. }
  183989. }
  183990. const String SystemClipboard::getTextFromClipboard()
  183991. {
  183992. String result;
  183993. if (OpenClipboard (0) != 0)
  183994. {
  183995. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  183996. if (bufH != 0)
  183997. {
  183998. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  183999. if (data != 0)
  184000. {
  184001. result = String (data, (int) (GlobalSize (bufH) / sizeof (wchar_t)));
  184002. GlobalUnlock (bufH);
  184003. }
  184004. }
  184005. CloseClipboard();
  184006. }
  184007. return result;
  184008. }
  184009. #endif
  184010. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184011. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184012. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184013. // compiled on its own).
  184014. #if JUCE_INCLUDED_FILE
  184015. namespace ActiveXHelpers
  184016. {
  184017. class JuceIStorage : public IStorage
  184018. {
  184019. int refCount;
  184020. public:
  184021. JuceIStorage() : refCount (1) {}
  184022. virtual ~JuceIStorage()
  184023. {
  184024. jassert (refCount == 0);
  184025. }
  184026. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184027. {
  184028. if (id == IID_IUnknown || id == IID_IStorage)
  184029. {
  184030. AddRef();
  184031. *result = this;
  184032. return S_OK;
  184033. }
  184034. *result = 0;
  184035. return E_NOINTERFACE;
  184036. }
  184037. ULONG __stdcall AddRef() { return ++refCount; }
  184038. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184039. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184040. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184041. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184042. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184043. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184044. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184045. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184046. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184047. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184048. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184049. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184050. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184051. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184052. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184053. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184054. juce_UseDebuggingNewOperator
  184055. };
  184056. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184057. {
  184058. int refCount;
  184059. HWND window;
  184060. public:
  184061. JuceOleInPlaceFrame (HWND window_)
  184062. : refCount (1),
  184063. window (window_)
  184064. {
  184065. }
  184066. virtual ~JuceOleInPlaceFrame()
  184067. {
  184068. jassert (refCount == 0);
  184069. }
  184070. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184071. {
  184072. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184073. {
  184074. AddRef();
  184075. *result = this;
  184076. return S_OK;
  184077. }
  184078. *result = 0;
  184079. return E_NOINTERFACE;
  184080. }
  184081. ULONG __stdcall AddRef() { return ++refCount; }
  184082. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184083. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184084. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184085. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184086. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184087. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184088. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184089. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184090. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184091. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184092. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184093. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184094. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184095. juce_UseDebuggingNewOperator
  184096. };
  184097. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184098. {
  184099. int refCount;
  184100. HWND window;
  184101. JuceOleInPlaceFrame* frame;
  184102. public:
  184103. JuceIOleInPlaceSite (HWND window_)
  184104. : refCount (1),
  184105. window (window_)
  184106. {
  184107. frame = new JuceOleInPlaceFrame (window);
  184108. }
  184109. virtual ~JuceIOleInPlaceSite()
  184110. {
  184111. jassert (refCount == 0);
  184112. frame->Release();
  184113. }
  184114. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184115. {
  184116. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184117. {
  184118. AddRef();
  184119. *result = this;
  184120. return S_OK;
  184121. }
  184122. *result = 0;
  184123. return E_NOINTERFACE;
  184124. }
  184125. ULONG __stdcall AddRef() { return ++refCount; }
  184126. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184127. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184128. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184129. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184130. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184131. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184132. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184133. {
  184134. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184135. *lplpFrame = frame;
  184136. *lplpDoc = 0;
  184137. lpFrameInfo->fMDIApp = FALSE;
  184138. lpFrameInfo->hwndFrame = window;
  184139. lpFrameInfo->haccel = 0;
  184140. lpFrameInfo->cAccelEntries = 0;
  184141. return S_OK;
  184142. }
  184143. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184144. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184145. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184146. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184147. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184148. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184149. juce_UseDebuggingNewOperator
  184150. };
  184151. class JuceIOleClientSite : public IOleClientSite
  184152. {
  184153. int refCount;
  184154. JuceIOleInPlaceSite* inplaceSite;
  184155. public:
  184156. JuceIOleClientSite (HWND window)
  184157. : refCount (1)
  184158. {
  184159. inplaceSite = new JuceIOleInPlaceSite (window);
  184160. }
  184161. virtual ~JuceIOleClientSite()
  184162. {
  184163. jassert (refCount == 0);
  184164. inplaceSite->Release();
  184165. }
  184166. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184167. {
  184168. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184169. {
  184170. AddRef();
  184171. *result = this;
  184172. return S_OK;
  184173. }
  184174. else if (id == IID_IOleInPlaceSite)
  184175. {
  184176. inplaceSite->AddRef();
  184177. *result = inplaceSite;
  184178. return S_OK;
  184179. }
  184180. *result = 0;
  184181. return E_NOINTERFACE;
  184182. }
  184183. ULONG __stdcall AddRef() { return ++refCount; }
  184184. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184185. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184186. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184187. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184188. HRESULT __stdcall ShowObject() { return S_OK; }
  184189. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184190. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184191. juce_UseDebuggingNewOperator
  184192. };
  184193. static VoidArray activeXComps;
  184194. static HWND getHWND (const ActiveXControlComponent* const component)
  184195. {
  184196. HWND hwnd = 0;
  184197. const IID iid = IID_IOleWindow;
  184198. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184199. if (window != 0)
  184200. {
  184201. window->GetWindow (&hwnd);
  184202. window->Release();
  184203. }
  184204. return hwnd;
  184205. }
  184206. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184207. {
  184208. RECT activeXRect, peerRect;
  184209. GetWindowRect (hwnd, &activeXRect);
  184210. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184211. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184212. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184213. const int64 mouseEventTime = Win32ComponentPeer::getMouseEventTime();
  184214. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184215. switch (message)
  184216. {
  184217. case WM_MOUSEMOVE:
  184218. case WM_LBUTTONDOWN:
  184219. case WM_MBUTTONDOWN:
  184220. case WM_RBUTTONDOWN:
  184221. case WM_LBUTTONUP:
  184222. case WM_MBUTTONUP:
  184223. case WM_RBUTTONUP:
  184224. peer->handleMouseEvent (0, mousePos, Win32ComponentPeer::currentModifiers, mouseEventTime);
  184225. break;
  184226. default:
  184227. break;
  184228. }
  184229. }
  184230. }
  184231. class ActiveXControlComponent::ActiveXControlData : public ComponentMovementWatcher
  184232. {
  184233. ActiveXControlComponent* const owner;
  184234. bool wasShowing;
  184235. public:
  184236. HWND controlHWND;
  184237. IStorage* storage;
  184238. IOleClientSite* clientSite;
  184239. IOleObject* control;
  184240. ActiveXControlData (HWND hwnd,
  184241. ActiveXControlComponent* const owner_)
  184242. : ComponentMovementWatcher (owner_),
  184243. owner (owner_),
  184244. wasShowing (owner_ != 0 && owner_->isShowing()),
  184245. controlHWND (0),
  184246. storage (new ActiveXHelpers::JuceIStorage()),
  184247. clientSite (new ActiveXHelpers::JuceIOleClientSite (hwnd)),
  184248. control (0)
  184249. {
  184250. }
  184251. ~ActiveXControlData()
  184252. {
  184253. if (control != 0)
  184254. {
  184255. control->Close (OLECLOSE_NOSAVE);
  184256. control->Release();
  184257. }
  184258. clientSite->Release();
  184259. storage->Release();
  184260. }
  184261. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184262. {
  184263. Component* const topComp = owner->getTopLevelComponent();
  184264. if (topComp->getPeer() != 0)
  184265. {
  184266. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184267. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184268. }
  184269. }
  184270. void componentPeerChanged()
  184271. {
  184272. const bool isShowingNow = owner->isShowing();
  184273. if (wasShowing != isShowingNow)
  184274. {
  184275. wasShowing = isShowingNow;
  184276. owner->setControlVisible (isShowingNow);
  184277. }
  184278. componentMovedOrResized (true, true);
  184279. }
  184280. void componentVisibilityChanged (Component&)
  184281. {
  184282. componentPeerChanged();
  184283. }
  184284. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184285. {
  184286. return ((ActiveXControlData*) ax->control) != 0
  184287. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184288. }
  184289. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184290. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184291. {
  184292. for (int i = ActiveXHelpers::activeXComps.size(); --i >= 0;)
  184293. {
  184294. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) ActiveXHelpers::activeXComps.getUnchecked(i);
  184295. if (doesWindowMatch (ax, hwnd))
  184296. {
  184297. switch (message)
  184298. {
  184299. case WM_MOUSEMOVE:
  184300. case WM_LBUTTONDOWN:
  184301. case WM_MBUTTONDOWN:
  184302. case WM_RBUTTONDOWN:
  184303. case WM_LBUTTONUP:
  184304. case WM_MBUTTONUP:
  184305. case WM_RBUTTONUP:
  184306. case WM_LBUTTONDBLCLK:
  184307. case WM_MBUTTONDBLCLK:
  184308. case WM_RBUTTONDBLCLK:
  184309. if (ax->isShowing())
  184310. {
  184311. ComponentPeer* const peer = ax->getPeer();
  184312. if (peer != 0)
  184313. {
  184314. ActiveXHelpers::offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184315. if (! ax->areMouseEventsAllowed())
  184316. return 0;
  184317. }
  184318. }
  184319. break;
  184320. default:
  184321. break;
  184322. }
  184323. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184324. }
  184325. }
  184326. return DefWindowProc (hwnd, message, wParam, lParam);
  184327. }
  184328. };
  184329. ActiveXControlComponent::ActiveXControlComponent()
  184330. : originalWndProc (0),
  184331. control (0),
  184332. mouseEventsAllowed (true)
  184333. {
  184334. ActiveXHelpers::activeXComps.add (this);
  184335. }
  184336. ActiveXControlComponent::~ActiveXControlComponent()
  184337. {
  184338. deleteControl();
  184339. ActiveXHelpers::activeXComps.removeValue (this);
  184340. }
  184341. void ActiveXControlComponent::paint (Graphics& g)
  184342. {
  184343. if (control == 0)
  184344. g.fillAll (Colours::lightgrey);
  184345. }
  184346. bool ActiveXControlComponent::createControl (const void* controlIID)
  184347. {
  184348. deleteControl();
  184349. ComponentPeer* const peer = getPeer();
  184350. // the component must have already been added to a real window when you call this!
  184351. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184352. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184353. {
  184354. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184355. HWND hwnd = (HWND) peer->getNativeHandle();
  184356. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184357. HRESULT hr;
  184358. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184359. info->clientSite, info->storage,
  184360. (void**) &(info->control))) == S_OK)
  184361. {
  184362. info->control->SetHostNames (L"Juce", 0);
  184363. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184364. {
  184365. RECT rect;
  184366. rect.left = pos.getX();
  184367. rect.top = pos.getY();
  184368. rect.right = pos.getX() + getWidth();
  184369. rect.bottom = pos.getY() + getHeight();
  184370. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184371. {
  184372. control = info.release();
  184373. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184374. ((ActiveXControlData*) control)->controlHWND = ActiveXHelpers::getHWND (this);
  184375. if (((ActiveXControlData*) control)->controlHWND != 0)
  184376. {
  184377. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184378. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) ActiveXControlData::activeXHookWndProc);
  184379. }
  184380. return true;
  184381. }
  184382. }
  184383. }
  184384. }
  184385. return false;
  184386. }
  184387. void ActiveXControlComponent::deleteControl()
  184388. {
  184389. ActiveXControlData* const info = (ActiveXControlData*) control;
  184390. if (info != 0)
  184391. {
  184392. delete info;
  184393. control = 0;
  184394. originalWndProc = 0;
  184395. }
  184396. }
  184397. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184398. {
  184399. ActiveXControlData* const info = (ActiveXControlData*) control;
  184400. void* result = 0;
  184401. if (info != 0 && info->control != 0
  184402. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184403. return result;
  184404. return 0;
  184405. }
  184406. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184407. {
  184408. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184409. if (hwnd != 0)
  184410. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184411. }
  184412. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184413. {
  184414. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184415. if (hwnd != 0)
  184416. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  184417. }
  184418. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  184419. {
  184420. mouseEventsAllowed = eventsCanReachControl;
  184421. }
  184422. #endif
  184423. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184424. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184425. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184426. // compiled on its own).
  184427. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  184428. using namespace QTOLibrary;
  184429. using namespace QTOControlLib;
  184430. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  184431. static bool isQTAvailable = false;
  184432. class QuickTimeMovieComponent::Pimpl
  184433. {
  184434. public:
  184435. Pimpl() : dataHandle (0)
  184436. {
  184437. }
  184438. ~Pimpl()
  184439. {
  184440. clearHandle();
  184441. }
  184442. void clearHandle()
  184443. {
  184444. if (dataHandle != 0)
  184445. {
  184446. DisposeHandle (dataHandle);
  184447. dataHandle = 0;
  184448. }
  184449. }
  184450. IQTControlPtr qtControl;
  184451. IQTMoviePtr qtMovie;
  184452. Handle dataHandle;
  184453. };
  184454. QuickTimeMovieComponent::QuickTimeMovieComponent()
  184455. : movieLoaded (false),
  184456. controllerVisible (true)
  184457. {
  184458. pimpl = new Pimpl();
  184459. setMouseEventsAllowed (false);
  184460. }
  184461. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  184462. {
  184463. closeMovie();
  184464. pimpl->qtControl = 0;
  184465. deleteControl();
  184466. pimpl = 0;
  184467. }
  184468. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  184469. {
  184470. if (! isQTAvailable)
  184471. isQTAvailable = (InitializeQTML (0) == noErr) && (EnterMovies() == noErr);
  184472. return isQTAvailable;
  184473. }
  184474. void QuickTimeMovieComponent::createControlIfNeeded()
  184475. {
  184476. if (isShowing() && ! isControlCreated())
  184477. {
  184478. const IID qtIID = __uuidof (QTControl);
  184479. if (createControl (&qtIID))
  184480. {
  184481. const IID qtInterfaceIID = __uuidof (IQTControl);
  184482. pimpl->qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  184483. if (pimpl->qtControl != 0)
  184484. {
  184485. pimpl->qtControl->Release(); // it has one ref too many at this point
  184486. pimpl->qtControl->QuickTimeInitialize();
  184487. pimpl->qtControl->PutSizing (qtMovieFitsControl);
  184488. if (movieFile != File::nonexistent)
  184489. loadMovie (movieFile, controllerVisible);
  184490. }
  184491. }
  184492. }
  184493. }
  184494. bool QuickTimeMovieComponent::isControlCreated() const
  184495. {
  184496. return isControlOpen();
  184497. }
  184498. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  184499. const bool isControllerVisible)
  184500. {
  184501. const ScopedPointer<InputStream> movieStreamDeleter (movieStream);
  184502. movieFile = File::nonexistent;
  184503. movieLoaded = false;
  184504. pimpl->qtMovie = 0;
  184505. controllerVisible = isControllerVisible;
  184506. createControlIfNeeded();
  184507. if (isControlCreated())
  184508. {
  184509. if (pimpl->qtControl != 0)
  184510. {
  184511. pimpl->qtControl->Put_MovieHandle (0);
  184512. pimpl->clearHandle();
  184513. Movie movie;
  184514. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, pimpl->dataHandle))
  184515. {
  184516. pimpl->qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  184517. pimpl->qtMovie = pimpl->qtControl->GetMovie();
  184518. if (pimpl->qtMovie != 0)
  184519. pimpl->qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  184520. : qtMovieControllerTypeNone);
  184521. }
  184522. if (movie == 0)
  184523. pimpl->clearHandle();
  184524. }
  184525. movieLoaded = (pimpl->qtMovie != 0);
  184526. }
  184527. else
  184528. {
  184529. // You're trying to open a movie when the control hasn't yet been created, probably because
  184530. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  184531. jassertfalse
  184532. }
  184533. return movieLoaded;
  184534. }
  184535. void QuickTimeMovieComponent::closeMovie()
  184536. {
  184537. stop();
  184538. movieFile = File::nonexistent;
  184539. movieLoaded = false;
  184540. pimpl->qtMovie = 0;
  184541. if (pimpl->qtControl != 0)
  184542. pimpl->qtControl->Put_MovieHandle (0);
  184543. pimpl->clearHandle();
  184544. }
  184545. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  184546. {
  184547. return movieFile;
  184548. }
  184549. bool QuickTimeMovieComponent::isMovieOpen() const
  184550. {
  184551. return movieLoaded;
  184552. }
  184553. double QuickTimeMovieComponent::getMovieDuration() const
  184554. {
  184555. if (pimpl->qtMovie != 0)
  184556. return pimpl->qtMovie->GetDuration() / (double) pimpl->qtMovie->GetTimeScale();
  184557. return 0.0;
  184558. }
  184559. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  184560. {
  184561. if (pimpl->qtMovie != 0)
  184562. {
  184563. struct QTRECT r = pimpl->qtMovie->GetNaturalRect();
  184564. width = r.right - r.left;
  184565. height = r.bottom - r.top;
  184566. }
  184567. else
  184568. {
  184569. width = height = 0;
  184570. }
  184571. }
  184572. void QuickTimeMovieComponent::play()
  184573. {
  184574. if (pimpl->qtMovie != 0)
  184575. pimpl->qtMovie->Play();
  184576. }
  184577. void QuickTimeMovieComponent::stop()
  184578. {
  184579. if (pimpl->qtMovie != 0)
  184580. pimpl->qtMovie->Stop();
  184581. }
  184582. bool QuickTimeMovieComponent::isPlaying() const
  184583. {
  184584. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetRate() != 0.0f;
  184585. }
  184586. void QuickTimeMovieComponent::setPosition (const double seconds)
  184587. {
  184588. if (pimpl->qtMovie != 0)
  184589. pimpl->qtMovie->PutTime ((long) (seconds * pimpl->qtMovie->GetTimeScale()));
  184590. }
  184591. double QuickTimeMovieComponent::getPosition() const
  184592. {
  184593. if (pimpl->qtMovie != 0)
  184594. return pimpl->qtMovie->GetTime() / (double) pimpl->qtMovie->GetTimeScale();
  184595. return 0.0;
  184596. }
  184597. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  184598. {
  184599. if (pimpl->qtMovie != 0)
  184600. pimpl->qtMovie->PutRate (newSpeed);
  184601. }
  184602. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  184603. {
  184604. if (pimpl->qtMovie != 0)
  184605. {
  184606. pimpl->qtMovie->PutAudioVolume (newVolume);
  184607. pimpl->qtMovie->PutAudioMute (newVolume <= 0);
  184608. }
  184609. }
  184610. float QuickTimeMovieComponent::getMovieVolume() const
  184611. {
  184612. if (pimpl->qtMovie != 0)
  184613. return pimpl->qtMovie->GetAudioVolume();
  184614. return 0.0f;
  184615. }
  184616. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  184617. {
  184618. if (pimpl->qtMovie != 0)
  184619. pimpl->qtMovie->PutLoop (shouldLoop);
  184620. }
  184621. bool QuickTimeMovieComponent::isLooping() const
  184622. {
  184623. return pimpl->qtMovie != 0 && pimpl->qtMovie->GetLoop();
  184624. }
  184625. bool QuickTimeMovieComponent::isControllerVisible() const
  184626. {
  184627. return controllerVisible;
  184628. }
  184629. void QuickTimeMovieComponent::parentHierarchyChanged()
  184630. {
  184631. createControlIfNeeded();
  184632. QTCompBaseClass::parentHierarchyChanged();
  184633. }
  184634. void QuickTimeMovieComponent::visibilityChanged()
  184635. {
  184636. createControlIfNeeded();
  184637. QTCompBaseClass::visibilityChanged();
  184638. }
  184639. void QuickTimeMovieComponent::paint (Graphics& g)
  184640. {
  184641. if (! isControlCreated())
  184642. g.fillAll (Colours::black);
  184643. }
  184644. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  184645. {
  184646. Handle dataRef = 0;
  184647. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  184648. if (err == noErr)
  184649. {
  184650. Str255 suffix;
  184651. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  184652. StringPtr name = suffix;
  184653. err = PtrAndHand (name, dataRef, name[0] + 1);
  184654. if (err == noErr)
  184655. {
  184656. long atoms[3];
  184657. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  184658. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  184659. atoms[2] = EndianU32_NtoB (MovieFileType);
  184660. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  184661. if (err == noErr)
  184662. return dataRef;
  184663. }
  184664. DisposeHandle (dataRef);
  184665. }
  184666. return 0;
  184667. }
  184668. static CFStringRef juceStringToCFString (const String& s)
  184669. {
  184670. const int len = s.length();
  184671. const juce_wchar* const t = s;
  184672. HeapBlock <UniChar> temp (len + 2);
  184673. for (int i = 0; i <= len; ++i)
  184674. temp[i] = t[i];
  184675. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  184676. }
  184677. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  184678. {
  184679. Boolean trueBool = true;
  184680. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184681. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  184682. props[prop].propValueSize = sizeof (trueBool);
  184683. props[prop].propValueAddress = &trueBool;
  184684. ++prop;
  184685. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  184686. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  184687. props[prop].propValueSize = sizeof (trueBool);
  184688. props[prop].propValueAddress = &trueBool;
  184689. ++prop;
  184690. Boolean isActive = true;
  184691. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  184692. props[prop].propID = kQTNewMoviePropertyID_Active;
  184693. props[prop].propValueSize = sizeof (isActive);
  184694. props[prop].propValueAddress = &isActive;
  184695. ++prop;
  184696. MacSetPort (0);
  184697. jassert (prop <= 5);
  184698. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  184699. return err == noErr;
  184700. }
  184701. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  184702. {
  184703. if (input == 0)
  184704. return false;
  184705. dataHandle = 0;
  184706. bool ok = false;
  184707. QTNewMoviePropertyElement props[5];
  184708. zeromem (props, sizeof (props));
  184709. int prop = 0;
  184710. DataReferenceRecord dr;
  184711. props[prop].propClass = kQTPropertyClass_DataLocation;
  184712. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  184713. props[prop].propValueSize = sizeof (dr);
  184714. props[prop].propValueAddress = &dr;
  184715. ++prop;
  184716. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  184717. if (fin != 0)
  184718. {
  184719. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  184720. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  184721. &dr.dataRef, &dr.dataRefType);
  184722. ok = openMovie (props, prop, movie);
  184723. DisposeHandle (dr.dataRef);
  184724. CFRelease (filePath);
  184725. }
  184726. else
  184727. {
  184728. // sanity-check because this currently needs to load the whole stream into memory..
  184729. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  184730. dataHandle = NewHandle ((Size) input->getTotalLength());
  184731. HLock (dataHandle);
  184732. // read the entire stream into memory - this is a pain, but can't get it to work
  184733. // properly using a custom callback to supply the data.
  184734. input->read (*dataHandle, (int) input->getTotalLength());
  184735. HUnlock (dataHandle);
  184736. // different types to get QT to try. (We should really be a bit smarter here by
  184737. // working out in advance which one the stream contains, rather than just trying
  184738. // each one)
  184739. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  184740. "\04.avi", "\04.m4a" };
  184741. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  184742. {
  184743. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  184744. dr.dataRefType = HandleDataHandlerSubType;
  184745. ok = openMovie (props, prop, movie);
  184746. DisposeHandle (dr.dataRef);
  184747. }
  184748. }
  184749. return ok;
  184750. }
  184751. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  184752. const bool isControllerVisible)
  184753. {
  184754. const bool ok = loadMovie (static_cast <InputStream*> (movieFile_.createInputStream()), isControllerVisible);
  184755. movieFile = movieFile_;
  184756. return ok;
  184757. }
  184758. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  184759. const bool isControllerVisible)
  184760. {
  184761. return loadMovie (static_cast <InputStream*> (movieURL.createInputStream (false)), isControllerVisible);
  184762. }
  184763. void QuickTimeMovieComponent::goToStart()
  184764. {
  184765. setPosition (0.0);
  184766. }
  184767. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  184768. const RectanglePlacement& placement)
  184769. {
  184770. int normalWidth, normalHeight;
  184771. getMovieNormalSize (normalWidth, normalHeight);
  184772. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  184773. {
  184774. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  184775. placement.applyTo (x, y, w, h,
  184776. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  184777. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  184778. if (w > 0 && h > 0)
  184779. {
  184780. setBounds (roundToInt (x), roundToInt (y),
  184781. roundToInt (w), roundToInt (h));
  184782. }
  184783. }
  184784. else
  184785. {
  184786. setBounds (spaceToFitWithin);
  184787. }
  184788. }
  184789. #endif
  184790. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  184791. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  184792. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184793. // compiled on its own).
  184794. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  184795. class WebBrowserComponentInternal : public ActiveXControlComponent
  184796. {
  184797. public:
  184798. WebBrowserComponentInternal()
  184799. : browser (0),
  184800. connectionPoint (0),
  184801. adviseCookie (0)
  184802. {
  184803. }
  184804. ~WebBrowserComponentInternal()
  184805. {
  184806. if (connectionPoint != 0)
  184807. connectionPoint->Unadvise (adviseCookie);
  184808. if (browser != 0)
  184809. browser->Release();
  184810. }
  184811. void createBrowser()
  184812. {
  184813. createControl (&CLSID_WebBrowser);
  184814. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  184815. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  184816. if (connectionPointContainer != 0)
  184817. {
  184818. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  184819. &connectionPoint);
  184820. if (connectionPoint != 0)
  184821. {
  184822. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  184823. jassert (owner != 0);
  184824. EventHandler* handler = new EventHandler (owner);
  184825. connectionPoint->Advise (handler, &adviseCookie);
  184826. }
  184827. }
  184828. }
  184829. void goToURL (const String& url,
  184830. const StringArray* headers,
  184831. const MemoryBlock* postData)
  184832. {
  184833. if (browser != 0)
  184834. {
  184835. LPSAFEARRAY sa = 0;
  184836. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  184837. VariantInit (&flags);
  184838. VariantInit (&frame);
  184839. VariantInit (&postDataVar);
  184840. VariantInit (&headersVar);
  184841. if (headers != 0)
  184842. {
  184843. V_VT (&headersVar) = VT_BSTR;
  184844. V_BSTR (&headersVar) = SysAllocString ((const OLECHAR*) headers->joinIntoString ("\r\n"));
  184845. }
  184846. if (postData != 0 && postData->getSize() > 0)
  184847. {
  184848. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  184849. if (sa != 0)
  184850. {
  184851. void* data = 0;
  184852. SafeArrayAccessData (sa, &data);
  184853. jassert (data != 0);
  184854. if (data != 0)
  184855. {
  184856. postData->copyTo (data, 0, postData->getSize());
  184857. SafeArrayUnaccessData (sa);
  184858. VARIANT postDataVar2;
  184859. VariantInit (&postDataVar2);
  184860. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  184861. V_ARRAY (&postDataVar2) = sa;
  184862. postDataVar = postDataVar2;
  184863. }
  184864. }
  184865. }
  184866. browser->Navigate ((BSTR) (const OLECHAR*) url,
  184867. &flags, &frame,
  184868. &postDataVar, &headersVar);
  184869. if (sa != 0)
  184870. SafeArrayDestroy (sa);
  184871. VariantClear (&flags);
  184872. VariantClear (&frame);
  184873. VariantClear (&postDataVar);
  184874. VariantClear (&headersVar);
  184875. }
  184876. }
  184877. IWebBrowser2* browser;
  184878. juce_UseDebuggingNewOperator
  184879. private:
  184880. IConnectionPoint* connectionPoint;
  184881. DWORD adviseCookie;
  184882. class EventHandler : public IDispatch,
  184883. public ComponentMovementWatcher
  184884. {
  184885. public:
  184886. EventHandler (WebBrowserComponent* owner_)
  184887. : ComponentMovementWatcher (owner_),
  184888. owner (owner_),
  184889. refCount (0)
  184890. {
  184891. }
  184892. ~EventHandler()
  184893. {
  184894. }
  184895. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184896. {
  184897. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  184898. {
  184899. AddRef();
  184900. *result = this;
  184901. return S_OK;
  184902. }
  184903. *result = 0;
  184904. return E_NOINTERFACE;
  184905. }
  184906. ULONG __stdcall AddRef() { return ++refCount; }
  184907. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  184908. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  184909. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  184910. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  184911. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  184912. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  184913. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  184914. UINT __RPC_FAR* /*puArgErr*/)
  184915. {
  184916. switch (dispIdMember)
  184917. {
  184918. case DISPID_BEFORENAVIGATE2:
  184919. {
  184920. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  184921. String url;
  184922. if ((vurl->vt & VT_BYREF) != 0)
  184923. url = *vurl->pbstrVal;
  184924. else
  184925. url = vurl->bstrVal;
  184926. *pDispParams->rgvarg->pboolVal
  184927. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  184928. : VARIANT_TRUE;
  184929. return S_OK;
  184930. }
  184931. default:
  184932. break;
  184933. }
  184934. return E_NOTIMPL;
  184935. }
  184936. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  184937. void componentPeerChanged() {}
  184938. void componentVisibilityChanged (Component&)
  184939. {
  184940. owner->visibilityChanged();
  184941. }
  184942. juce_UseDebuggingNewOperator
  184943. private:
  184944. WebBrowserComponent* const owner;
  184945. int refCount;
  184946. EventHandler (const EventHandler&);
  184947. EventHandler& operator= (const EventHandler&);
  184948. };
  184949. };
  184950. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  184951. : browser (0),
  184952. blankPageShown (false),
  184953. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  184954. {
  184955. setOpaque (true);
  184956. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  184957. }
  184958. WebBrowserComponent::~WebBrowserComponent()
  184959. {
  184960. delete browser;
  184961. }
  184962. void WebBrowserComponent::goToURL (const String& url,
  184963. const StringArray* headers,
  184964. const MemoryBlock* postData)
  184965. {
  184966. lastURL = url;
  184967. lastHeaders.clear();
  184968. if (headers != 0)
  184969. lastHeaders = *headers;
  184970. lastPostData.setSize (0);
  184971. if (postData != 0)
  184972. lastPostData = *postData;
  184973. blankPageShown = false;
  184974. browser->goToURL (url, headers, postData);
  184975. }
  184976. void WebBrowserComponent::stop()
  184977. {
  184978. if (browser->browser != 0)
  184979. browser->browser->Stop();
  184980. }
  184981. void WebBrowserComponent::goBack()
  184982. {
  184983. lastURL = String::empty;
  184984. blankPageShown = false;
  184985. if (browser->browser != 0)
  184986. browser->browser->GoBack();
  184987. }
  184988. void WebBrowserComponent::goForward()
  184989. {
  184990. lastURL = String::empty;
  184991. if (browser->browser != 0)
  184992. browser->browser->GoForward();
  184993. }
  184994. void WebBrowserComponent::refresh()
  184995. {
  184996. if (browser->browser != 0)
  184997. browser->browser->Refresh();
  184998. }
  184999. void WebBrowserComponent::paint (Graphics& g)
  185000. {
  185001. if (browser->browser == 0)
  185002. g.fillAll (Colours::white);
  185003. }
  185004. void WebBrowserComponent::checkWindowAssociation()
  185005. {
  185006. if (isShowing())
  185007. {
  185008. if (browser->browser == 0 && getPeer() != 0)
  185009. {
  185010. browser->createBrowser();
  185011. reloadLastURL();
  185012. }
  185013. else
  185014. {
  185015. if (blankPageShown)
  185016. goBack();
  185017. }
  185018. }
  185019. else
  185020. {
  185021. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185022. {
  185023. // when the component becomes invisible, some stuff like flash
  185024. // carries on playing audio, so we need to force it onto a blank
  185025. // page to avoid this..
  185026. blankPageShown = true;
  185027. browser->goToURL ("about:blank", 0, 0);
  185028. }
  185029. }
  185030. }
  185031. void WebBrowserComponent::reloadLastURL()
  185032. {
  185033. if (lastURL.isNotEmpty())
  185034. {
  185035. goToURL (lastURL, &lastHeaders, &lastPostData);
  185036. lastURL = String::empty;
  185037. }
  185038. }
  185039. void WebBrowserComponent::parentHierarchyChanged()
  185040. {
  185041. checkWindowAssociation();
  185042. }
  185043. void WebBrowserComponent::resized()
  185044. {
  185045. browser->setSize (getWidth(), getHeight());
  185046. }
  185047. void WebBrowserComponent::visibilityChanged()
  185048. {
  185049. checkWindowAssociation();
  185050. }
  185051. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185052. {
  185053. return true;
  185054. }
  185055. #endif
  185056. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185057. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185058. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185059. // compiled on its own).
  185060. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185061. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185062. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185063. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185064. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185065. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185066. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185067. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185068. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185069. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185070. #define WGL_ACCELERATION_ARB 0x2003
  185071. #define WGL_SWAP_METHOD_ARB 0x2007
  185072. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185073. #define WGL_PIXEL_TYPE_ARB 0x2013
  185074. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185075. #define WGL_COLOR_BITS_ARB 0x2014
  185076. #define WGL_RED_BITS_ARB 0x2015
  185077. #define WGL_GREEN_BITS_ARB 0x2017
  185078. #define WGL_BLUE_BITS_ARB 0x2019
  185079. #define WGL_ALPHA_BITS_ARB 0x201B
  185080. #define WGL_DEPTH_BITS_ARB 0x2022
  185081. #define WGL_STENCIL_BITS_ARB 0x2023
  185082. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185083. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185084. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185085. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185086. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185087. #define WGL_STEREO_ARB 0x2012
  185088. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185089. #define WGL_SAMPLES_ARB 0x2042
  185090. #define WGL_TYPE_RGBA_ARB 0x202B
  185091. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185092. {
  185093. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185094. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185095. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185096. else
  185097. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185098. }
  185099. class WindowedGLContext : public OpenGLContext
  185100. {
  185101. public:
  185102. WindowedGLContext (Component* const component_,
  185103. HGLRC contextToShareWith,
  185104. const OpenGLPixelFormat& pixelFormat)
  185105. : renderContext (0),
  185106. nativeWindow (0),
  185107. dc (0),
  185108. component (component_)
  185109. {
  185110. jassert (component != 0);
  185111. createNativeWindow();
  185112. // Use a default pixel format that should be supported everywhere
  185113. PIXELFORMATDESCRIPTOR pfd;
  185114. zerostruct (pfd);
  185115. pfd.nSize = sizeof (pfd);
  185116. pfd.nVersion = 1;
  185117. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185118. pfd.iPixelType = PFD_TYPE_RGBA;
  185119. pfd.cColorBits = 24;
  185120. pfd.cDepthBits = 16;
  185121. const int format = ChoosePixelFormat (dc, &pfd);
  185122. if (format != 0)
  185123. SetPixelFormat (dc, format, &pfd);
  185124. renderContext = wglCreateContext (dc);
  185125. makeActive();
  185126. setPixelFormat (pixelFormat);
  185127. if (contextToShareWith != 0 && renderContext != 0)
  185128. wglShareLists (contextToShareWith, renderContext);
  185129. }
  185130. ~WindowedGLContext()
  185131. {
  185132. makeInactive();
  185133. wglDeleteContext (renderContext);
  185134. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185135. delete nativeWindow;
  185136. }
  185137. bool makeActive() const throw()
  185138. {
  185139. jassert (renderContext != 0);
  185140. return wglMakeCurrent (dc, renderContext) != 0;
  185141. }
  185142. bool makeInactive() const throw()
  185143. {
  185144. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185145. }
  185146. bool isActive() const throw()
  185147. {
  185148. return wglGetCurrentContext() == renderContext;
  185149. }
  185150. const OpenGLPixelFormat getPixelFormat() const
  185151. {
  185152. OpenGLPixelFormat pf;
  185153. makeActive();
  185154. StringArray availableExtensions;
  185155. getWglExtensions (dc, availableExtensions);
  185156. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185157. return pf;
  185158. }
  185159. void* getRawContext() const throw()
  185160. {
  185161. return renderContext;
  185162. }
  185163. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185164. {
  185165. makeActive();
  185166. PIXELFORMATDESCRIPTOR pfd;
  185167. zerostruct (pfd);
  185168. pfd.nSize = sizeof (pfd);
  185169. pfd.nVersion = 1;
  185170. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185171. pfd.iPixelType = PFD_TYPE_RGBA;
  185172. pfd.iLayerType = PFD_MAIN_PLANE;
  185173. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185174. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185175. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185176. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185177. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185178. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185179. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185180. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185181. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185182. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185183. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185184. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185185. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185186. int format = 0;
  185187. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185188. StringArray availableExtensions;
  185189. getWglExtensions (dc, availableExtensions);
  185190. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185191. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185192. {
  185193. int attributes[64];
  185194. int n = 0;
  185195. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185196. attributes[n++] = GL_TRUE;
  185197. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185198. attributes[n++] = GL_TRUE;
  185199. attributes[n++] = WGL_ACCELERATION_ARB;
  185200. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185201. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185202. attributes[n++] = GL_TRUE;
  185203. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185204. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185205. attributes[n++] = WGL_COLOR_BITS_ARB;
  185206. attributes[n++] = pfd.cColorBits;
  185207. attributes[n++] = WGL_RED_BITS_ARB;
  185208. attributes[n++] = pixelFormat.redBits;
  185209. attributes[n++] = WGL_GREEN_BITS_ARB;
  185210. attributes[n++] = pixelFormat.greenBits;
  185211. attributes[n++] = WGL_BLUE_BITS_ARB;
  185212. attributes[n++] = pixelFormat.blueBits;
  185213. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185214. attributes[n++] = pixelFormat.alphaBits;
  185215. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185216. attributes[n++] = pixelFormat.depthBufferBits;
  185217. if (pixelFormat.stencilBufferBits > 0)
  185218. {
  185219. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185220. attributes[n++] = pixelFormat.stencilBufferBits;
  185221. }
  185222. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185223. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185224. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185225. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185226. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185227. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185228. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185229. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185230. if (availableExtensions.contains ("WGL_ARB_multisample")
  185231. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185232. {
  185233. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185234. attributes[n++] = 1;
  185235. attributes[n++] = WGL_SAMPLES_ARB;
  185236. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185237. }
  185238. attributes[n++] = 0;
  185239. UINT formatsCount;
  185240. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185241. (void) ok;
  185242. jassert (ok);
  185243. }
  185244. else
  185245. {
  185246. format = ChoosePixelFormat (dc, &pfd);
  185247. }
  185248. if (format != 0)
  185249. {
  185250. makeInactive();
  185251. // win32 can't change the pixel format of a window, so need to delete the
  185252. // old one and create a new one..
  185253. jassert (nativeWindow != 0);
  185254. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185255. delete nativeWindow;
  185256. createNativeWindow();
  185257. if (SetPixelFormat (dc, format, &pfd))
  185258. {
  185259. wglDeleteContext (renderContext);
  185260. renderContext = wglCreateContext (dc);
  185261. jassert (renderContext != 0);
  185262. return renderContext != 0;
  185263. }
  185264. }
  185265. return false;
  185266. }
  185267. void updateWindowPosition (int x, int y, int w, int h, int)
  185268. {
  185269. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185270. x, y, w, h,
  185271. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185272. }
  185273. void repaint()
  185274. {
  185275. const Rectangle<int> bounds (nativeWindow->getBounds());
  185276. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185277. }
  185278. void swapBuffers()
  185279. {
  185280. SwapBuffers (dc);
  185281. }
  185282. bool setSwapInterval (int numFramesPerSwap)
  185283. {
  185284. makeActive();
  185285. StringArray availableExtensions;
  185286. getWglExtensions (dc, availableExtensions);
  185287. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185288. return availableExtensions.contains ("WGL_EXT_swap_control")
  185289. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185290. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185291. }
  185292. int getSwapInterval() const
  185293. {
  185294. makeActive();
  185295. StringArray availableExtensions;
  185296. getWglExtensions (dc, availableExtensions);
  185297. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185298. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185299. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185300. return wglGetSwapIntervalEXT();
  185301. return 0;
  185302. }
  185303. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185304. {
  185305. jassert (isActive());
  185306. StringArray availableExtensions;
  185307. getWglExtensions (dc, availableExtensions);
  185308. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185309. int numTypes = 0;
  185310. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185311. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185312. {
  185313. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185314. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185315. jassertfalse
  185316. }
  185317. else
  185318. {
  185319. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185320. }
  185321. OpenGLPixelFormat pf;
  185322. for (int i = 0; i < numTypes; ++i)
  185323. {
  185324. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185325. {
  185326. bool alreadyListed = false;
  185327. for (int j = results.size(); --j >= 0;)
  185328. if (pf == *results.getUnchecked(j))
  185329. alreadyListed = true;
  185330. if (! alreadyListed)
  185331. results.add (new OpenGLPixelFormat (pf));
  185332. }
  185333. }
  185334. }
  185335. void* getNativeWindowHandle() const
  185336. {
  185337. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185338. }
  185339. juce_UseDebuggingNewOperator
  185340. HGLRC renderContext;
  185341. private:
  185342. Win32ComponentPeer* nativeWindow;
  185343. Component* const component;
  185344. HDC dc;
  185345. void createNativeWindow()
  185346. {
  185347. nativeWindow = new Win32ComponentPeer (component, 0);
  185348. nativeWindow->dontRepaint = true;
  185349. nativeWindow->setVisible (true);
  185350. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185351. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185352. if (peer != 0)
  185353. {
  185354. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185355. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185356. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185357. }
  185358. dc = GetDC (hwnd);
  185359. }
  185360. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185361. OpenGLPixelFormat& result,
  185362. const StringArray& availableExtensions) const throw()
  185363. {
  185364. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185365. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185366. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185367. {
  185368. int attributes[32];
  185369. int numAttributes = 0;
  185370. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185371. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185372. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185373. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185374. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185375. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185376. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185377. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185378. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185379. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185380. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185381. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185382. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185383. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185384. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185385. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185386. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185387. int values[32];
  185388. zeromem (values, sizeof (values));
  185389. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185390. {
  185391. int n = 0;
  185392. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185393. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185394. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185395. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185396. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185397. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185398. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185399. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185400. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185401. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185402. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185403. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185404. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185405. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185406. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185407. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185408. return isValidFormat;
  185409. }
  185410. else
  185411. {
  185412. jassertfalse
  185413. }
  185414. }
  185415. else
  185416. {
  185417. PIXELFORMATDESCRIPTOR pfd;
  185418. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  185419. {
  185420. result.redBits = pfd.cRedBits;
  185421. result.greenBits = pfd.cGreenBits;
  185422. result.blueBits = pfd.cBlueBits;
  185423. result.alphaBits = pfd.cAlphaBits;
  185424. result.depthBufferBits = pfd.cDepthBits;
  185425. result.stencilBufferBits = pfd.cStencilBits;
  185426. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  185427. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  185428. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  185429. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  185430. result.fullSceneAntiAliasingNumSamples = 0;
  185431. return true;
  185432. }
  185433. else
  185434. {
  185435. jassertfalse
  185436. }
  185437. }
  185438. return false;
  185439. }
  185440. WindowedGLContext (const WindowedGLContext&);
  185441. WindowedGLContext& operator= (const WindowedGLContext&);
  185442. };
  185443. OpenGLContext* OpenGLComponent::createContext()
  185444. {
  185445. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this,
  185446. contextToShareListsWith != 0 ? (HGLRC) contextToShareListsWith->getRawContext() : 0,
  185447. preferredPixelFormat));
  185448. return (c->renderContext != 0) ? c.release() : 0;
  185449. }
  185450. void* OpenGLComponent::getNativeWindowHandle() const
  185451. {
  185452. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle() : 0;
  185453. }
  185454. void juce_glViewport (const int w, const int h)
  185455. {
  185456. glViewport (0, 0, w, h);
  185457. }
  185458. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  185459. OwnedArray <OpenGLPixelFormat>& results)
  185460. {
  185461. Component tempComp;
  185462. {
  185463. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  185464. wc.makeActive();
  185465. wc.findAlternativeOpenGLPixelFormats (results);
  185466. }
  185467. }
  185468. #endif
  185469. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185470. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  185471. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185472. // compiled on its own).
  185473. #if JUCE_INCLUDED_FILE
  185474. #if JUCE_USE_CDREADER
  185475. namespace CDReaderHelpers
  185476. {
  185477. //***************************************************************************
  185478. // %%% TARGET STATUS VALUES %%%
  185479. //***************************************************************************
  185480. #define STATUS_GOOD 0x00 // Status Good
  185481. #define STATUS_CHKCOND 0x02 // Check Condition
  185482. #define STATUS_CONDMET 0x04 // Condition Met
  185483. #define STATUS_BUSY 0x08 // Busy
  185484. #define STATUS_INTERM 0x10 // Intermediate
  185485. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  185486. #define STATUS_RESCONF 0x18 // Reservation conflict
  185487. #define STATUS_COMTERM 0x22 // Command Terminated
  185488. #define STATUS_QFULL 0x28 // Queue full
  185489. //***************************************************************************
  185490. // %%% SCSI MISCELLANEOUS EQUATES %%%
  185491. //***************************************************************************
  185492. #define MAXLUN 7 // Maximum Logical Unit Id
  185493. #define MAXTARG 7 // Maximum Target Id
  185494. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  185495. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  185496. //***************************************************************************
  185497. // %%% Commands for all Device Types %%%
  185498. //***************************************************************************
  185499. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  185500. #define SCSI_COMPARE 0x39 // Compare (O)
  185501. #define SCSI_COPY 0x18 // Copy (O)
  185502. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  185503. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  185504. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  185505. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  185506. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  185507. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  185508. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  185509. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  185510. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  185511. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  185512. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  185513. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  185514. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  185515. //***************************************************************************
  185516. // %%% Commands Unique to Direct Access Devices %%%
  185517. //***************************************************************************
  185518. #define SCSI_COMPARE 0x39 // Compare (O)
  185519. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  185520. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  185521. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  185522. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  185523. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  185524. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  185525. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  185526. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  185527. #define SCSI_READ_LONG 0x3E // Read Long (O)
  185528. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  185529. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  185530. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  185531. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  185532. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  185533. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  185534. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  185535. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  185536. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  185537. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  185538. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  185539. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  185540. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  185541. #define SCSI_VERIFY 0x2F // Verify (O)
  185542. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  185543. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  185544. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  185545. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  185546. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  185547. //***************************************************************************
  185548. // %%% Commands Unique to Sequential Access Devices %%%
  185549. //***************************************************************************
  185550. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  185551. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  185552. #define SCSI_LOCATE 0x2B // Locate (O)
  185553. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  185554. #define SCSI_READ_POS 0x34 // Read Position (O)
  185555. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  185556. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  185557. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  185558. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  185559. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  185560. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  185561. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  185562. //***************************************************************************
  185563. // %%% Commands Unique to Printer Devices %%%
  185564. //***************************************************************************
  185565. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  185566. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  185567. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  185568. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  185569. //***************************************************************************
  185570. // %%% Commands Unique to Processor Devices %%%
  185571. //***************************************************************************
  185572. #define SCSI_RECEIVE 0x08 // Receive (O)
  185573. #define SCSI_SEND 0x0A // Send (O)
  185574. //***************************************************************************
  185575. // %%% Commands Unique to Write-Once Devices %%%
  185576. //***************************************************************************
  185577. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  185578. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  185579. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  185580. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  185581. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  185582. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  185583. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  185584. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  185585. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  185586. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  185587. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  185588. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  185589. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  185590. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  185591. //***************************************************************************
  185592. // %%% Commands Unique to CD-ROM Devices %%%
  185593. //***************************************************************************
  185594. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  185595. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  185596. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  185597. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  185598. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  185599. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  185600. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  185601. #define SCSI_READHEADER 0x44 // Read Header (O)
  185602. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  185603. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  185604. //***************************************************************************
  185605. // %%% Commands Unique to Scanner Devices %%%
  185606. //***************************************************************************
  185607. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  185608. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  185609. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  185610. #define SCSI_SCAN 0x1B // Scan (O)
  185611. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  185612. //***************************************************************************
  185613. // %%% Commands Unique to Optical Memory Devices %%%
  185614. //***************************************************************************
  185615. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  185616. //***************************************************************************
  185617. // %%% Commands Unique to Medium Changer Devices %%%
  185618. //***************************************************************************
  185619. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  185620. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  185621. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  185622. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  185623. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  185624. //***************************************************************************
  185625. // %%% Commands Unique to Communication Devices %%%
  185626. //***************************************************************************
  185627. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  185628. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  185629. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  185630. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  185631. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  185632. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  185633. //***************************************************************************
  185634. // %%% Request Sense Data Format %%%
  185635. //***************************************************************************
  185636. typedef struct {
  185637. BYTE ErrorCode; // Error Code (70H or 71H)
  185638. BYTE SegmentNum; // Number of current segment descriptor
  185639. BYTE SenseKey; // Sense Key(See bit definitions too)
  185640. BYTE InfoByte0; // Information MSB
  185641. BYTE InfoByte1; // Information MID
  185642. BYTE InfoByte2; // Information MID
  185643. BYTE InfoByte3; // Information LSB
  185644. BYTE AddSenLen; // Additional Sense Length
  185645. BYTE ComSpecInf0; // Command Specific Information MSB
  185646. BYTE ComSpecInf1; // Command Specific Information MID
  185647. BYTE ComSpecInf2; // Command Specific Information MID
  185648. BYTE ComSpecInf3; // Command Specific Information LSB
  185649. BYTE AddSenseCode; // Additional Sense Code
  185650. BYTE AddSenQual; // Additional Sense Code Qualifier
  185651. BYTE FieldRepUCode; // Field Replaceable Unit Code
  185652. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  185653. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  185654. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  185655. BYTE AddSenseBytes; // Additional Sense Bytes
  185656. } SENSE_DATA_FMT;
  185657. //***************************************************************************
  185658. // %%% REQUEST SENSE ERROR CODE %%%
  185659. //***************************************************************************
  185660. #define SERROR_CURRENT 0x70 // Current Errors
  185661. #define SERROR_DEFERED 0x71 // Deferred Errors
  185662. //***************************************************************************
  185663. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  185664. //***************************************************************************
  185665. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  185666. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  185667. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  185668. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  185669. //***************************************************************************
  185670. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  185671. //***************************************************************************
  185672. #define KEY_NOSENSE 0x00 // No Sense
  185673. #define KEY_RECERROR 0x01 // Recovered Error
  185674. #define KEY_NOTREADY 0x02 // Not Ready
  185675. #define KEY_MEDIUMERR 0x03 // Medium Error
  185676. #define KEY_HARDERROR 0x04 // Hardware Error
  185677. #define KEY_ILLGLREQ 0x05 // Illegal Request
  185678. #define KEY_UNITATT 0x06 // Unit Attention
  185679. #define KEY_DATAPROT 0x07 // Data Protect
  185680. #define KEY_BLANKCHK 0x08 // Blank Check
  185681. #define KEY_VENDSPEC 0x09 // Vendor Specific
  185682. #define KEY_COPYABORT 0x0A // Copy Abort
  185683. #define KEY_EQUAL 0x0C // Equal (Search)
  185684. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  185685. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  185686. #define KEY_RESERVED 0x0F // Reserved
  185687. //***************************************************************************
  185688. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  185689. //***************************************************************************
  185690. #define DTYPE_DASD 0x00 // Disk Device
  185691. #define DTYPE_SEQD 0x01 // Tape Device
  185692. #define DTYPE_PRNT 0x02 // Printer
  185693. #define DTYPE_PROC 0x03 // Processor
  185694. #define DTYPE_WORM 0x04 // Write-once read-multiple
  185695. #define DTYPE_CROM 0x05 // CD-ROM device
  185696. #define DTYPE_SCAN 0x06 // Scanner device
  185697. #define DTYPE_OPTI 0x07 // Optical memory device
  185698. #define DTYPE_JUKE 0x08 // Medium Changer device
  185699. #define DTYPE_COMM 0x09 // Communications device
  185700. #define DTYPE_RESL 0x0A // Reserved (low)
  185701. #define DTYPE_RESH 0x1E // Reserved (high)
  185702. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  185703. //***************************************************************************
  185704. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  185705. //***************************************************************************
  185706. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  185707. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  185708. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  185709. #define ANSI_RESLO 0x3 // Reserved (low)
  185710. #define ANSI_RESHI 0x7 // Reserved (high)
  185711. typedef struct
  185712. {
  185713. USHORT Length;
  185714. UCHAR ScsiStatus;
  185715. UCHAR PathId;
  185716. UCHAR TargetId;
  185717. UCHAR Lun;
  185718. UCHAR CdbLength;
  185719. UCHAR SenseInfoLength;
  185720. UCHAR DataIn;
  185721. ULONG DataTransferLength;
  185722. ULONG TimeOutValue;
  185723. ULONG DataBufferOffset;
  185724. ULONG SenseInfoOffset;
  185725. UCHAR Cdb[16];
  185726. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  185727. typedef struct
  185728. {
  185729. USHORT Length;
  185730. UCHAR ScsiStatus;
  185731. UCHAR PathId;
  185732. UCHAR TargetId;
  185733. UCHAR Lun;
  185734. UCHAR CdbLength;
  185735. UCHAR SenseInfoLength;
  185736. UCHAR DataIn;
  185737. ULONG DataTransferLength;
  185738. ULONG TimeOutValue;
  185739. PVOID DataBuffer;
  185740. ULONG SenseInfoOffset;
  185741. UCHAR Cdb[16];
  185742. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  185743. typedef struct
  185744. {
  185745. SCSI_PASS_THROUGH_DIRECT spt;
  185746. ULONG Filler;
  185747. UCHAR ucSenseBuf[32];
  185748. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  185749. typedef struct
  185750. {
  185751. ULONG Length;
  185752. UCHAR PortNumber;
  185753. UCHAR PathId;
  185754. UCHAR TargetId;
  185755. UCHAR Lun;
  185756. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  185757. #define METHOD_BUFFERED 0
  185758. #define METHOD_IN_DIRECT 1
  185759. #define METHOD_OUT_DIRECT 2
  185760. #define METHOD_NEITHER 3
  185761. #define FILE_ANY_ACCESS 0
  185762. #ifndef FILE_READ_ACCESS
  185763. #define FILE_READ_ACCESS (0x0001)
  185764. #endif
  185765. #ifndef FILE_WRITE_ACCESS
  185766. #define FILE_WRITE_ACCESS (0x0002)
  185767. #endif
  185768. #define IOCTL_SCSI_BASE 0x00000004
  185769. #define SCSI_IOCTL_DATA_OUT 0
  185770. #define SCSI_IOCTL_DATA_IN 1
  185771. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  185772. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  185773. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  185774. )
  185775. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185776. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  185777. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  185778. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  185779. #define SENSE_LEN 14
  185780. #define SRB_DIR_SCSI 0x00
  185781. #define SRB_POSTING 0x01
  185782. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  185783. #define SRB_DIR_IN 0x08
  185784. #define SRB_DIR_OUT 0x10
  185785. #define SRB_EVENT_NOTIFY 0x40
  185786. #define RESIDUAL_COUNT_SUPPORTED 0x02
  185787. #define MAX_SRB_TIMEOUT 1080001u
  185788. #define DEFAULT_SRB_TIMEOUT 1080001u
  185789. #define SC_HA_INQUIRY 0x00
  185790. #define SC_GET_DEV_TYPE 0x01
  185791. #define SC_EXEC_SCSI_CMD 0x02
  185792. #define SC_ABORT_SRB 0x03
  185793. #define SC_RESET_DEV 0x04
  185794. #define SC_SET_HA_PARMS 0x05
  185795. #define SC_GET_DISK_INFO 0x06
  185796. #define SC_RESCAN_SCSI_BUS 0x07
  185797. #define SC_GETSET_TIMEOUTS 0x08
  185798. #define SS_PENDING 0x00
  185799. #define SS_COMP 0x01
  185800. #define SS_ABORTED 0x02
  185801. #define SS_ABORT_FAIL 0x03
  185802. #define SS_ERR 0x04
  185803. #define SS_INVALID_CMD 0x80
  185804. #define SS_INVALID_HA 0x81
  185805. #define SS_NO_DEVICE 0x82
  185806. #define SS_INVALID_SRB 0xE0
  185807. #define SS_OLD_MANAGER 0xE1
  185808. #define SS_BUFFER_ALIGN 0xE1
  185809. #define SS_ILLEGAL_MODE 0xE2
  185810. #define SS_NO_ASPI 0xE3
  185811. #define SS_FAILED_INIT 0xE4
  185812. #define SS_ASPI_IS_BUSY 0xE5
  185813. #define SS_BUFFER_TO_BIG 0xE6
  185814. #define SS_BUFFER_TOO_BIG 0xE6
  185815. #define SS_MISMATCHED_COMPONENTS 0xE7
  185816. #define SS_NO_ADAPTERS 0xE8
  185817. #define SS_INSUFFICIENT_RESOURCES 0xE9
  185818. #define SS_ASPI_IS_SHUTDOWN 0xEA
  185819. #define SS_BAD_INSTALL 0xEB
  185820. #define HASTAT_OK 0x00
  185821. #define HASTAT_SEL_TO 0x11
  185822. #define HASTAT_DO_DU 0x12
  185823. #define HASTAT_BUS_FREE 0x13
  185824. #define HASTAT_PHASE_ERR 0x14
  185825. #define HASTAT_TIMEOUT 0x09
  185826. #define HASTAT_COMMAND_TIMEOUT 0x0B
  185827. #define HASTAT_MESSAGE_REJECT 0x0D
  185828. #define HASTAT_BUS_RESET 0x0E
  185829. #define HASTAT_PARITY_ERROR 0x0F
  185830. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  185831. #define PACKED
  185832. #pragma pack(1)
  185833. typedef struct
  185834. {
  185835. BYTE SRB_Cmd;
  185836. BYTE SRB_Status;
  185837. BYTE SRB_HaID;
  185838. BYTE SRB_Flags;
  185839. DWORD SRB_Hdr_Rsvd;
  185840. BYTE HA_Count;
  185841. BYTE HA_SCSI_ID;
  185842. BYTE HA_ManagerId[16];
  185843. BYTE HA_Identifier[16];
  185844. BYTE HA_Unique[16];
  185845. WORD HA_Rsvd1;
  185846. BYTE pad[20];
  185847. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  185848. typedef struct
  185849. {
  185850. BYTE SRB_Cmd;
  185851. BYTE SRB_Status;
  185852. BYTE SRB_HaID;
  185853. BYTE SRB_Flags;
  185854. DWORD SRB_Hdr_Rsvd;
  185855. BYTE SRB_Target;
  185856. BYTE SRB_Lun;
  185857. BYTE SRB_DeviceType;
  185858. BYTE SRB_Rsvd1;
  185859. BYTE pad[68];
  185860. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  185861. typedef struct
  185862. {
  185863. BYTE SRB_Cmd;
  185864. BYTE SRB_Status;
  185865. BYTE SRB_HaID;
  185866. BYTE SRB_Flags;
  185867. DWORD SRB_Hdr_Rsvd;
  185868. BYTE SRB_Target;
  185869. BYTE SRB_Lun;
  185870. WORD SRB_Rsvd1;
  185871. DWORD SRB_BufLen;
  185872. BYTE FAR *SRB_BufPointer;
  185873. BYTE SRB_SenseLen;
  185874. BYTE SRB_CDBLen;
  185875. BYTE SRB_HaStat;
  185876. BYTE SRB_TargStat;
  185877. VOID FAR *SRB_PostProc;
  185878. BYTE SRB_Rsvd2[20];
  185879. BYTE CDBByte[16];
  185880. BYTE SenseArea[SENSE_LEN+2];
  185881. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  185882. typedef struct
  185883. {
  185884. BYTE SRB_Cmd;
  185885. BYTE SRB_Status;
  185886. BYTE SRB_HaId;
  185887. BYTE SRB_Flags;
  185888. DWORD SRB_Hdr_Rsvd;
  185889. } PACKED SRB, *PSRB, FAR *LPSRB;
  185890. #pragma pack()
  185891. struct CDDeviceInfo
  185892. {
  185893. char vendor[9];
  185894. char productId[17];
  185895. char rev[5];
  185896. char vendorSpec[21];
  185897. BYTE ha;
  185898. BYTE tgt;
  185899. BYTE lun;
  185900. char scsiDriveLetter; // will be 0 if not using scsi
  185901. };
  185902. class CDReadBuffer
  185903. {
  185904. public:
  185905. int startFrame;
  185906. int numFrames;
  185907. int dataStartOffset;
  185908. int dataLength;
  185909. BYTE* buffer;
  185910. int bufferSize;
  185911. int index;
  185912. bool wantsIndex;
  185913. CDReadBuffer (const int numberOfFrames)
  185914. : startFrame (0),
  185915. numFrames (0),
  185916. dataStartOffset (0),
  185917. dataLength (0),
  185918. index (0),
  185919. wantsIndex (false)
  185920. {
  185921. bufferSize = 2352 * numberOfFrames;
  185922. buffer = (BYTE*) juce_malloc (bufferSize);
  185923. }
  185924. ~CDReadBuffer()
  185925. {
  185926. juce_free (buffer);
  185927. }
  185928. bool isZero() const
  185929. {
  185930. BYTE* p = buffer + dataStartOffset;
  185931. for (int i = dataLength; --i >= 0;)
  185932. if (*p++ != 0)
  185933. return false;
  185934. return true;
  185935. }
  185936. };
  185937. class CDDeviceHandle;
  185938. class CDController
  185939. {
  185940. public:
  185941. CDController();
  185942. virtual ~CDController();
  185943. virtual bool read (CDReadBuffer* t) = 0;
  185944. virtual void shutDown();
  185945. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  185946. int getLastIndex();
  185947. public:
  185948. bool initialised;
  185949. CDDeviceHandle* deviceInfo;
  185950. int framesToCheck, framesOverlap;
  185951. void prepare (SRB_ExecSCSICmd& s);
  185952. void perform (SRB_ExecSCSICmd& s);
  185953. void setPaused (bool paused);
  185954. };
  185955. #pragma pack(1)
  185956. struct TOCTRACK
  185957. {
  185958. BYTE rsvd;
  185959. BYTE ADR;
  185960. BYTE trackNumber;
  185961. BYTE rsvd2;
  185962. BYTE addr[4];
  185963. };
  185964. struct TOC
  185965. {
  185966. WORD tocLen;
  185967. BYTE firstTrack;
  185968. BYTE lastTrack;
  185969. TOCTRACK tracks[100];
  185970. };
  185971. #pragma pack()
  185972. enum
  185973. {
  185974. READTYPE_ANY = 0,
  185975. READTYPE_ATAPI1 = 1,
  185976. READTYPE_ATAPI2 = 2,
  185977. READTYPE_READ6 = 3,
  185978. READTYPE_READ10 = 4,
  185979. READTYPE_READ_D8 = 5,
  185980. READTYPE_READ_D4 = 6,
  185981. READTYPE_READ_D4_1 = 7,
  185982. READTYPE_READ10_2 = 8
  185983. };
  185984. class CDDeviceHandle
  185985. {
  185986. public:
  185987. CDDeviceHandle (const CDDeviceInfo* const device)
  185988. : scsiHandle (0),
  185989. readType (READTYPE_ANY),
  185990. controller (0)
  185991. {
  185992. memcpy (&info, device, sizeof (info));
  185993. }
  185994. ~CDDeviceHandle()
  185995. {
  185996. if (controller != 0)
  185997. {
  185998. controller->shutDown();
  185999. controller = 0;
  186000. }
  186001. if (scsiHandle != 0)
  186002. CloseHandle (scsiHandle);
  186003. }
  186004. bool readTOC (TOC* lpToc, bool useMSF);
  186005. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186006. void openDrawer (bool shouldBeOpen);
  186007. CDDeviceInfo info;
  186008. HANDLE scsiHandle;
  186009. BYTE readType;
  186010. private:
  186011. ScopedPointer<CDController> controller;
  186012. bool testController (const int readType,
  186013. CDController* const newController,
  186014. CDReadBuffer* const bufferToUse);
  186015. };
  186016. DWORD (*fGetASPI32SupportInfo)(void);
  186017. DWORD (*fSendASPI32Command)(LPSRB);
  186018. static HINSTANCE winAspiLib = 0;
  186019. static bool usingScsi = false;
  186020. static bool initialised = false;
  186021. static bool InitialiseCDRipper()
  186022. {
  186023. if (! initialised)
  186024. {
  186025. initialised = true;
  186026. OSVERSIONINFO info;
  186027. info.dwOSVersionInfoSize = sizeof (info);
  186028. GetVersionEx (&info);
  186029. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186030. if (! usingScsi)
  186031. {
  186032. fGetASPI32SupportInfo = 0;
  186033. fSendASPI32Command = 0;
  186034. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186035. if (winAspiLib != 0)
  186036. {
  186037. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186038. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186039. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186040. return false;
  186041. }
  186042. else
  186043. {
  186044. usingScsi = true;
  186045. }
  186046. }
  186047. }
  186048. return true;
  186049. }
  186050. static void DeinitialiseCDRipper()
  186051. {
  186052. if (winAspiLib != 0)
  186053. {
  186054. fGetASPI32SupportInfo = 0;
  186055. fSendASPI32Command = 0;
  186056. FreeLibrary (winAspiLib);
  186057. winAspiLib = 0;
  186058. }
  186059. initialised = false;
  186060. }
  186061. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186062. {
  186063. TCHAR devicePath[] = { '\\', '\\', '.', '\\', driveLetter, ':', 0, 0 };
  186064. OSVERSIONINFO info;
  186065. info.dwOSVersionInfoSize = sizeof (info);
  186066. GetVersionEx (&info);
  186067. DWORD flags = GENERIC_READ;
  186068. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186069. flags = GENERIC_READ | GENERIC_WRITE;
  186070. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186071. if (h == INVALID_HANDLE_VALUE)
  186072. {
  186073. flags ^= GENERIC_WRITE;
  186074. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186075. }
  186076. return h;
  186077. }
  186078. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186079. const char driveLetter,
  186080. HANDLE& deviceHandle,
  186081. const bool retryOnFailure = true)
  186082. {
  186083. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186084. zerostruct (s);
  186085. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186086. s.spt.CdbLength = srb->SRB_CDBLen;
  186087. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186088. ? SCSI_IOCTL_DATA_IN
  186089. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186090. ? SCSI_IOCTL_DATA_OUT
  186091. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186092. s.spt.DataTransferLength = srb->SRB_BufLen;
  186093. s.spt.TimeOutValue = 5;
  186094. s.spt.DataBuffer = srb->SRB_BufPointer;
  186095. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186096. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186097. srb->SRB_Status = SS_ERR;
  186098. srb->SRB_TargStat = 0x0004;
  186099. DWORD bytesReturned = 0;
  186100. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186101. &s, sizeof (s),
  186102. &s, sizeof (s),
  186103. &bytesReturned, 0) != 0)
  186104. {
  186105. srb->SRB_Status = SS_COMP;
  186106. }
  186107. else if (retryOnFailure)
  186108. {
  186109. const DWORD error = GetLastError();
  186110. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186111. {
  186112. if (error != ERROR_INVALID_HANDLE)
  186113. CloseHandle (deviceHandle);
  186114. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186115. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186116. }
  186117. }
  186118. return srb->SRB_Status;
  186119. }
  186120. // Controller types..
  186121. class ControllerType1 : public CDController
  186122. {
  186123. public:
  186124. ControllerType1() {}
  186125. ~ControllerType1() {}
  186126. bool read (CDReadBuffer* rb)
  186127. {
  186128. if (rb->numFrames * 2352 > rb->bufferSize)
  186129. return false;
  186130. SRB_ExecSCSICmd s;
  186131. prepare (s);
  186132. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186133. s.SRB_BufLen = rb->bufferSize;
  186134. s.SRB_BufPointer = rb->buffer;
  186135. s.SRB_CDBLen = 12;
  186136. s.CDBByte[0] = 0xBE;
  186137. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186138. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186139. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186140. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186141. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186142. perform (s);
  186143. if (s.SRB_Status != SS_COMP)
  186144. return false;
  186145. rb->dataLength = rb->numFrames * 2352;
  186146. rb->dataStartOffset = 0;
  186147. return true;
  186148. }
  186149. };
  186150. class ControllerType2 : public CDController
  186151. {
  186152. public:
  186153. ControllerType2() {}
  186154. ~ControllerType2() {}
  186155. void shutDown()
  186156. {
  186157. if (initialised)
  186158. {
  186159. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186160. SRB_ExecSCSICmd s;
  186161. prepare (s);
  186162. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186163. s.SRB_BufLen = 0x0C;
  186164. s.SRB_BufPointer = bufPointer;
  186165. s.SRB_CDBLen = 6;
  186166. s.CDBByte[0] = 0x15;
  186167. s.CDBByte[4] = 0x0C;
  186168. perform (s);
  186169. }
  186170. }
  186171. bool init()
  186172. {
  186173. SRB_ExecSCSICmd s;
  186174. s.SRB_Status = SS_ERR;
  186175. if (deviceInfo->readType == READTYPE_READ10_2)
  186176. {
  186177. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186178. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186179. for (int i = 0; i < 2; ++i)
  186180. {
  186181. prepare (s);
  186182. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186183. s.SRB_BufLen = 0x14;
  186184. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186185. s.SRB_CDBLen = 6;
  186186. s.CDBByte[0] = 0x15;
  186187. s.CDBByte[1] = 0x10;
  186188. s.CDBByte[4] = 0x14;
  186189. perform (s);
  186190. if (s.SRB_Status != SS_COMP)
  186191. return false;
  186192. }
  186193. }
  186194. else
  186195. {
  186196. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186197. prepare (s);
  186198. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186199. s.SRB_BufLen = 0x0C;
  186200. s.SRB_BufPointer = bufPointer;
  186201. s.SRB_CDBLen = 6;
  186202. s.CDBByte[0] = 0x15;
  186203. s.CDBByte[4] = 0x0C;
  186204. perform (s);
  186205. }
  186206. return s.SRB_Status == SS_COMP;
  186207. }
  186208. bool read (CDReadBuffer* rb)
  186209. {
  186210. if (rb->numFrames * 2352 > rb->bufferSize)
  186211. return false;
  186212. if (!initialised)
  186213. {
  186214. initialised = init();
  186215. if (!initialised)
  186216. return false;
  186217. }
  186218. SRB_ExecSCSICmd s;
  186219. prepare (s);
  186220. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186221. s.SRB_BufLen = rb->bufferSize;
  186222. s.SRB_BufPointer = rb->buffer;
  186223. s.SRB_CDBLen = 10;
  186224. s.CDBByte[0] = 0x28;
  186225. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186226. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186227. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186228. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186229. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186230. perform (s);
  186231. if (s.SRB_Status != SS_COMP)
  186232. return false;
  186233. rb->dataLength = rb->numFrames * 2352;
  186234. rb->dataStartOffset = 0;
  186235. return true;
  186236. }
  186237. };
  186238. class ControllerType3 : public CDController
  186239. {
  186240. public:
  186241. ControllerType3() {}
  186242. ~ControllerType3() {}
  186243. bool read (CDReadBuffer* rb)
  186244. {
  186245. if (rb->numFrames * 2352 > rb->bufferSize)
  186246. return false;
  186247. if (!initialised)
  186248. {
  186249. setPaused (false);
  186250. initialised = true;
  186251. }
  186252. SRB_ExecSCSICmd s;
  186253. prepare (s);
  186254. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186255. s.SRB_BufLen = rb->numFrames * 2352;
  186256. s.SRB_BufPointer = rb->buffer;
  186257. s.SRB_CDBLen = 12;
  186258. s.CDBByte[0] = 0xD8;
  186259. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186260. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186261. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186262. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186263. perform (s);
  186264. if (s.SRB_Status != SS_COMP)
  186265. return false;
  186266. rb->dataLength = rb->numFrames * 2352;
  186267. rb->dataStartOffset = 0;
  186268. return true;
  186269. }
  186270. };
  186271. class ControllerType4 : public CDController
  186272. {
  186273. public:
  186274. ControllerType4() {}
  186275. ~ControllerType4() {}
  186276. bool selectD4Mode()
  186277. {
  186278. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186279. SRB_ExecSCSICmd s;
  186280. prepare (s);
  186281. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186282. s.SRB_CDBLen = 6;
  186283. s.SRB_BufLen = 12;
  186284. s.SRB_BufPointer = bufPointer;
  186285. s.CDBByte[0] = 0x15;
  186286. s.CDBByte[1] = 0x10;
  186287. s.CDBByte[4] = 0x08;
  186288. perform (s);
  186289. return s.SRB_Status == SS_COMP;
  186290. }
  186291. bool read (CDReadBuffer* rb)
  186292. {
  186293. if (rb->numFrames * 2352 > rb->bufferSize)
  186294. return false;
  186295. if (!initialised)
  186296. {
  186297. setPaused (true);
  186298. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186299. selectD4Mode();
  186300. initialised = true;
  186301. }
  186302. SRB_ExecSCSICmd s;
  186303. prepare (s);
  186304. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186305. s.SRB_BufLen = rb->bufferSize;
  186306. s.SRB_BufPointer = rb->buffer;
  186307. s.SRB_CDBLen = 10;
  186308. s.CDBByte[0] = 0xD4;
  186309. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186310. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186311. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186312. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186313. perform (s);
  186314. if (s.SRB_Status != SS_COMP)
  186315. return false;
  186316. rb->dataLength = rb->numFrames * 2352;
  186317. rb->dataStartOffset = 0;
  186318. return true;
  186319. }
  186320. };
  186321. CDController::CDController() : initialised (false)
  186322. {
  186323. }
  186324. CDController::~CDController()
  186325. {
  186326. }
  186327. void CDController::prepare (SRB_ExecSCSICmd& s)
  186328. {
  186329. zerostruct (s);
  186330. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186331. s.SRB_HaID = deviceInfo->info.ha;
  186332. s.SRB_Target = deviceInfo->info.tgt;
  186333. s.SRB_Lun = deviceInfo->info.lun;
  186334. s.SRB_SenseLen = SENSE_LEN;
  186335. }
  186336. void CDController::perform (SRB_ExecSCSICmd& s)
  186337. {
  186338. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186339. s.SRB_PostProc = event;
  186340. ResetEvent (event);
  186341. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186342. deviceInfo->info.scsiDriveLetter,
  186343. deviceInfo->scsiHandle)
  186344. : fSendASPI32Command ((LPSRB)&s);
  186345. if (status == SS_PENDING)
  186346. WaitForSingleObject (event, 4000);
  186347. CloseHandle (event);
  186348. }
  186349. void CDController::setPaused (bool paused)
  186350. {
  186351. SRB_ExecSCSICmd s;
  186352. prepare (s);
  186353. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186354. s.SRB_CDBLen = 10;
  186355. s.CDBByte[0] = 0x4B;
  186356. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186357. perform (s);
  186358. }
  186359. void CDController::shutDown()
  186360. {
  186361. }
  186362. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186363. {
  186364. if (overlapBuffer != 0)
  186365. {
  186366. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186367. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186368. if (doJitter
  186369. && overlapBuffer->startFrame > 0
  186370. && overlapBuffer->numFrames > 0
  186371. && overlapBuffer->dataLength > 0)
  186372. {
  186373. const int numFrames = rb->numFrames;
  186374. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186375. {
  186376. rb->startFrame -= framesOverlap;
  186377. if (framesToCheck < framesOverlap
  186378. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186379. rb->numFrames += framesOverlap;
  186380. }
  186381. else
  186382. {
  186383. overlapBuffer->dataLength = 0;
  186384. overlapBuffer->startFrame = 0;
  186385. overlapBuffer->numFrames = 0;
  186386. }
  186387. }
  186388. if (! read (rb))
  186389. return false;
  186390. if (doJitter)
  186391. {
  186392. const int checkLen = framesToCheck * 2352;
  186393. const int maxToCheck = rb->dataLength - checkLen;
  186394. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186395. return true;
  186396. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186397. bool found = false;
  186398. for (int i = 0; i < maxToCheck; ++i)
  186399. {
  186400. if (memcmp (p, rb->buffer + i, checkLen) == 0)
  186401. {
  186402. i += checkLen;
  186403. rb->dataStartOffset = i;
  186404. rb->dataLength -= i;
  186405. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  186406. found = true;
  186407. break;
  186408. }
  186409. }
  186410. rb->numFrames = rb->dataLength / 2352;
  186411. rb->dataLength = 2352 * rb->numFrames;
  186412. if (!found)
  186413. return false;
  186414. }
  186415. if (canDoJitter)
  186416. {
  186417. memcpy (overlapBuffer->buffer,
  186418. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  186419. 2352 * framesToCheck);
  186420. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  186421. overlapBuffer->numFrames = framesToCheck;
  186422. overlapBuffer->dataLength = 2352 * framesToCheck;
  186423. overlapBuffer->dataStartOffset = 0;
  186424. }
  186425. else
  186426. {
  186427. overlapBuffer->startFrame = 0;
  186428. overlapBuffer->numFrames = 0;
  186429. overlapBuffer->dataLength = 0;
  186430. }
  186431. return true;
  186432. }
  186433. else
  186434. {
  186435. return read (rb);
  186436. }
  186437. }
  186438. int CDController::getLastIndex()
  186439. {
  186440. char qdata[100];
  186441. SRB_ExecSCSICmd s;
  186442. prepare (s);
  186443. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186444. s.SRB_BufLen = sizeof (qdata);
  186445. s.SRB_BufPointer = (BYTE*)qdata;
  186446. s.SRB_CDBLen = 12;
  186447. s.CDBByte[0] = 0x42;
  186448. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186449. s.CDBByte[2] = 64;
  186450. s.CDBByte[3] = 1; // get current position
  186451. s.CDBByte[7] = 0;
  186452. s.CDBByte[8] = (BYTE)sizeof (qdata);
  186453. perform (s);
  186454. if (s.SRB_Status == SS_COMP)
  186455. return qdata[7];
  186456. return 0;
  186457. }
  186458. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  186459. {
  186460. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186461. SRB_ExecSCSICmd s;
  186462. zerostruct (s);
  186463. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186464. s.SRB_HaID = info.ha;
  186465. s.SRB_Target = info.tgt;
  186466. s.SRB_Lun = info.lun;
  186467. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186468. s.SRB_BufLen = 0x324;
  186469. s.SRB_BufPointer = (BYTE*)lpToc;
  186470. s.SRB_SenseLen = 0x0E;
  186471. s.SRB_CDBLen = 0x0A;
  186472. s.SRB_PostProc = event;
  186473. s.CDBByte[0] = 0x43;
  186474. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  186475. s.CDBByte[7] = 0x03;
  186476. s.CDBByte[8] = 0x24;
  186477. ResetEvent (event);
  186478. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186479. : fSendASPI32Command ((LPSRB)&s);
  186480. if (status == SS_PENDING)
  186481. WaitForSingleObject (event, 4000);
  186482. CloseHandle (event);
  186483. return (s.SRB_Status == SS_COMP);
  186484. }
  186485. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  186486. CDReadBuffer* const overlapBuffer)
  186487. {
  186488. if (controller == 0)
  186489. {
  186490. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  186491. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  186492. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  186493. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  186494. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  186495. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  186496. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  186497. }
  186498. buffer->index = 0;
  186499. if ((controller != 0)
  186500. && controller->readAudio (buffer, overlapBuffer))
  186501. {
  186502. if (buffer->wantsIndex)
  186503. buffer->index = controller->getLastIndex();
  186504. return true;
  186505. }
  186506. return false;
  186507. }
  186508. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  186509. {
  186510. if (shouldBeOpen)
  186511. {
  186512. if (controller != 0)
  186513. {
  186514. controller->shutDown();
  186515. controller = 0;
  186516. }
  186517. if (scsiHandle != 0)
  186518. {
  186519. CloseHandle (scsiHandle);
  186520. scsiHandle = 0;
  186521. }
  186522. }
  186523. SRB_ExecSCSICmd s;
  186524. zerostruct (s);
  186525. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186526. s.SRB_HaID = info.ha;
  186527. s.SRB_Target = info.tgt;
  186528. s.SRB_Lun = info.lun;
  186529. s.SRB_SenseLen = SENSE_LEN;
  186530. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186531. s.SRB_BufLen = 0;
  186532. s.SRB_BufPointer = 0;
  186533. s.SRB_CDBLen = 12;
  186534. s.CDBByte[0] = 0x1b;
  186535. s.CDBByte[1] = (BYTE)(info.lun << 5);
  186536. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  186537. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186538. s.SRB_PostProc = event;
  186539. ResetEvent (event);
  186540. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  186541. : fSendASPI32Command ((LPSRB)&s);
  186542. if (status == SS_PENDING)
  186543. WaitForSingleObject (event, 4000);
  186544. CloseHandle (event);
  186545. }
  186546. bool CDDeviceHandle::testController (const int type,
  186547. CDController* const newController,
  186548. CDReadBuffer* const rb)
  186549. {
  186550. controller = newController;
  186551. readType = (BYTE)type;
  186552. controller->deviceInfo = this;
  186553. controller->framesToCheck = 1;
  186554. controller->framesOverlap = 3;
  186555. bool passed = false;
  186556. memset (rb->buffer, 0xcd, rb->bufferSize);
  186557. if (controller->read (rb))
  186558. {
  186559. passed = true;
  186560. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  186561. int wrong = 0;
  186562. for (int i = rb->dataLength / 4; --i >= 0;)
  186563. {
  186564. if (*p++ == (int) 0xcdcdcdcd)
  186565. {
  186566. if (++wrong == 4)
  186567. {
  186568. passed = false;
  186569. break;
  186570. }
  186571. }
  186572. else
  186573. {
  186574. wrong = 0;
  186575. }
  186576. }
  186577. }
  186578. if (! passed)
  186579. {
  186580. controller->shutDown();
  186581. controller = 0;
  186582. }
  186583. return passed;
  186584. }
  186585. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  186586. {
  186587. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186588. const int bufSize = 128;
  186589. BYTE buffer[bufSize];
  186590. zeromem (buffer, bufSize);
  186591. SRB_ExecSCSICmd s;
  186592. zerostruct (s);
  186593. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186594. s.SRB_HaID = ha;
  186595. s.SRB_Target = tgt;
  186596. s.SRB_Lun = lun;
  186597. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186598. s.SRB_BufLen = bufSize;
  186599. s.SRB_BufPointer = buffer;
  186600. s.SRB_SenseLen = SENSE_LEN;
  186601. s.SRB_CDBLen = 6;
  186602. s.SRB_PostProc = event;
  186603. s.CDBByte[0] = SCSI_INQUIRY;
  186604. s.CDBByte[4] = 100;
  186605. ResetEvent (event);
  186606. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  186607. WaitForSingleObject (event, 4000);
  186608. CloseHandle (event);
  186609. if (s.SRB_Status == SS_COMP)
  186610. {
  186611. memcpy (dev->vendor, &buffer[8], 8);
  186612. memcpy (dev->productId, &buffer[16], 16);
  186613. memcpy (dev->rev, &buffer[32], 4);
  186614. memcpy (dev->vendorSpec, &buffer[36], 20);
  186615. }
  186616. }
  186617. static int FindCDDevices (CDDeviceInfo* const list,
  186618. int maxItems)
  186619. {
  186620. int count = 0;
  186621. if (usingScsi)
  186622. {
  186623. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  186624. {
  186625. TCHAR drivePath[8];
  186626. drivePath[0] = driveLetter;
  186627. drivePath[1] = ':';
  186628. drivePath[2] = '\\';
  186629. drivePath[3] = 0;
  186630. if (GetDriveType (drivePath) == DRIVE_CDROM)
  186631. {
  186632. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  186633. if (h != INVALID_HANDLE_VALUE)
  186634. {
  186635. BYTE buffer[100], passThroughStruct[1024];
  186636. zeromem (buffer, sizeof (buffer));
  186637. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186638. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  186639. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  186640. p->spt.CdbLength = 6;
  186641. p->spt.SenseInfoLength = 24;
  186642. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  186643. p->spt.DataTransferLength = 100;
  186644. p->spt.TimeOutValue = 2;
  186645. p->spt.DataBuffer = buffer;
  186646. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186647. p->spt.Cdb[0] = 0x12;
  186648. p->spt.Cdb[4] = 100;
  186649. DWORD bytesReturned = 0;
  186650. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186651. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186652. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  186653. &bytesReturned, 0) != 0)
  186654. {
  186655. zeromem (&list[count], sizeof (CDDeviceInfo));
  186656. list[count].scsiDriveLetter = driveLetter;
  186657. memcpy (list[count].vendor, &buffer[8], 8);
  186658. memcpy (list[count].productId, &buffer[16], 16);
  186659. memcpy (list[count].rev, &buffer[32], 4);
  186660. memcpy (list[count].vendorSpec, &buffer[36], 20);
  186661. zeromem (passThroughStruct, sizeof (passThroughStruct));
  186662. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  186663. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  186664. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  186665. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  186666. &bytesReturned, 0) != 0)
  186667. {
  186668. list[count].ha = scsiAddr->PortNumber;
  186669. list[count].tgt = scsiAddr->TargetId;
  186670. list[count].lun = scsiAddr->Lun;
  186671. ++count;
  186672. }
  186673. }
  186674. CloseHandle (h);
  186675. }
  186676. }
  186677. }
  186678. }
  186679. else
  186680. {
  186681. const DWORD d = fGetASPI32SupportInfo();
  186682. BYTE status = HIBYTE (LOWORD (d));
  186683. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  186684. return 0;
  186685. const int numAdapters = LOBYTE (LOWORD (d));
  186686. for (BYTE ha = 0; ha < numAdapters; ++ha)
  186687. {
  186688. SRB_HAInquiry s;
  186689. zerostruct (s);
  186690. s.SRB_Cmd = SC_HA_INQUIRY;
  186691. s.SRB_HaID = ha;
  186692. fSendASPI32Command ((LPSRB)&s);
  186693. if (s.SRB_Status == SS_COMP)
  186694. {
  186695. maxItems = (int)s.HA_Unique[3];
  186696. if (maxItems == 0)
  186697. maxItems = 8;
  186698. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  186699. {
  186700. for (BYTE lun = 0; lun < 8; ++lun)
  186701. {
  186702. SRB_GDEVBlock sb;
  186703. zerostruct (sb);
  186704. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  186705. sb.SRB_HaID = ha;
  186706. sb.SRB_Target = tgt;
  186707. sb.SRB_Lun = lun;
  186708. fSendASPI32Command ((LPSRB) &sb);
  186709. if (sb.SRB_Status == SS_COMP
  186710. && sb.SRB_DeviceType == DTYPE_CROM)
  186711. {
  186712. zeromem (&list[count], sizeof (CDDeviceInfo));
  186713. list[count].ha = ha;
  186714. list[count].tgt = tgt;
  186715. list[count].lun = lun;
  186716. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  186717. ++count;
  186718. }
  186719. }
  186720. }
  186721. }
  186722. }
  186723. }
  186724. return count;
  186725. }
  186726. static int ripperUsers = 0;
  186727. static bool initialisedOk = false;
  186728. class DeinitialiseTimer : private Timer,
  186729. private DeletedAtShutdown
  186730. {
  186731. DeinitialiseTimer (const DeinitialiseTimer&);
  186732. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  186733. public:
  186734. DeinitialiseTimer()
  186735. {
  186736. startTimer (4000);
  186737. }
  186738. ~DeinitialiseTimer()
  186739. {
  186740. if (--ripperUsers == 0)
  186741. DeinitialiseCDRipper();
  186742. }
  186743. void timerCallback()
  186744. {
  186745. delete this;
  186746. }
  186747. juce_UseDebuggingNewOperator
  186748. };
  186749. static void incUserCount()
  186750. {
  186751. if (ripperUsers++ == 0)
  186752. initialisedOk = InitialiseCDRipper();
  186753. }
  186754. static void decUserCount()
  186755. {
  186756. new DeinitialiseTimer();
  186757. }
  186758. struct CDDeviceWrapper
  186759. {
  186760. ScopedPointer<CDDeviceHandle> cdH;
  186761. ScopedPointer<CDReadBuffer> overlapBuffer;
  186762. bool jitter;
  186763. };
  186764. static int getAddressOf (const TOCTRACK* const t)
  186765. {
  186766. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  186767. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  186768. }
  186769. static int getMSFAddressOf (const TOCTRACK* const t)
  186770. {
  186771. return 60 * t->addr[1] + t->addr[2];
  186772. }
  186773. static const int samplesPerFrame = 44100 / 75;
  186774. static const int bytesPerFrame = samplesPerFrame * 4;
  186775. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  186776. {
  186777. SRB_GDEVBlock s;
  186778. zerostruct (s);
  186779. s.SRB_Cmd = SC_GET_DEV_TYPE;
  186780. s.SRB_HaID = device->ha;
  186781. s.SRB_Target = device->tgt;
  186782. s.SRB_Lun = device->lun;
  186783. if (usingScsi)
  186784. {
  186785. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  186786. if (h != INVALID_HANDLE_VALUE)
  186787. {
  186788. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  186789. cdh->scsiHandle = h;
  186790. return cdh;
  186791. }
  186792. }
  186793. else
  186794. {
  186795. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  186796. && s.SRB_DeviceType == DTYPE_CROM)
  186797. {
  186798. return new CDDeviceHandle (device);
  186799. }
  186800. }
  186801. return 0;
  186802. }
  186803. }
  186804. const StringArray AudioCDReader::getAvailableCDNames()
  186805. {
  186806. using namespace CDReaderHelpers;
  186807. StringArray results;
  186808. incUserCount();
  186809. if (initialisedOk)
  186810. {
  186811. CDDeviceInfo list[8];
  186812. const int num = FindCDDevices (list, 8);
  186813. decUserCount();
  186814. for (int i = 0; i < num; ++i)
  186815. {
  186816. String s;
  186817. if (list[i].scsiDriveLetter > 0)
  186818. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << ": ";
  186819. s << String (list[i].vendor).trim()
  186820. << ' ' << String (list[i].productId).trim()
  186821. << ' ' << String (list[i].rev).trim();
  186822. results.add (s);
  186823. }
  186824. }
  186825. return results;
  186826. }
  186827. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  186828. {
  186829. using namespace CDReaderHelpers;
  186830. incUserCount();
  186831. if (initialisedOk)
  186832. {
  186833. CDDeviceInfo list[8];
  186834. const int num = FindCDDevices (list, 8);
  186835. if (((unsigned int) deviceIndex) < (unsigned int) num)
  186836. {
  186837. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  186838. if (handle != 0)
  186839. {
  186840. CDDeviceWrapper* const d = new CDDeviceWrapper();
  186841. d->cdH = handle;
  186842. d->overlapBuffer = new CDReadBuffer(3);
  186843. return new AudioCDReader (d);
  186844. }
  186845. }
  186846. }
  186847. decUserCount();
  186848. return 0;
  186849. }
  186850. AudioCDReader::AudioCDReader (void* handle_)
  186851. : AudioFormatReader (0, "CD Audio"),
  186852. handle (handle_),
  186853. indexingEnabled (false),
  186854. lastIndex (0),
  186855. firstFrameInBuffer (0),
  186856. samplesInBuffer (0)
  186857. {
  186858. using namespace CDReaderHelpers;
  186859. jassert (handle_ != 0);
  186860. refreshTrackLengths();
  186861. sampleRate = 44100.0;
  186862. bitsPerSample = 16;
  186863. lengthInSamples = getPositionOfTrackStart (numTracks);
  186864. numChannels = 2;
  186865. usesFloatingPointData = false;
  186866. buffer.setSize (4 * bytesPerFrame, true);
  186867. }
  186868. AudioCDReader::~AudioCDReader()
  186869. {
  186870. using namespace CDReaderHelpers;
  186871. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186872. delete device;
  186873. decUserCount();
  186874. }
  186875. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  186876. int64 startSampleInFile, int numSamples)
  186877. {
  186878. using namespace CDReaderHelpers;
  186879. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  186880. bool ok = true;
  186881. while (numSamples > 0)
  186882. {
  186883. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  186884. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  186885. if (startSampleInFile >= bufferStartSample
  186886. && startSampleInFile < bufferEndSample)
  186887. {
  186888. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  186889. int* const l = destSamples[0] + startOffsetInDestBuffer;
  186890. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186891. const short* src = (const short*) buffer.getData();
  186892. src += 2 * (startSampleInFile - bufferStartSample);
  186893. for (int i = 0; i < toDo; ++i)
  186894. {
  186895. l[i] = src [i << 1] << 16;
  186896. if (r != 0)
  186897. r[i] = src [(i << 1) + 1] << 16;
  186898. }
  186899. startOffsetInDestBuffer += toDo;
  186900. startSampleInFile += toDo;
  186901. numSamples -= toDo;
  186902. }
  186903. else
  186904. {
  186905. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  186906. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  186907. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  186908. {
  186909. device->overlapBuffer->dataLength = 0;
  186910. device->overlapBuffer->startFrame = 0;
  186911. device->overlapBuffer->numFrames = 0;
  186912. device->jitter = false;
  186913. }
  186914. firstFrameInBuffer = frameNeeded;
  186915. lastIndex = 0;
  186916. CDReadBuffer readBuffer (framesInBuffer + 4);
  186917. readBuffer.wantsIndex = indexingEnabled;
  186918. int i;
  186919. for (i = 5; --i >= 0;)
  186920. {
  186921. readBuffer.startFrame = frameNeeded;
  186922. readBuffer.numFrames = framesInBuffer;
  186923. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  186924. break;
  186925. else
  186926. device->overlapBuffer->dataLength = 0;
  186927. }
  186928. if (i >= 0)
  186929. {
  186930. memcpy ((char*) buffer.getData(),
  186931. readBuffer.buffer + readBuffer.dataStartOffset,
  186932. readBuffer.dataLength);
  186933. samplesInBuffer = readBuffer.dataLength >> 2;
  186934. lastIndex = readBuffer.index;
  186935. }
  186936. else
  186937. {
  186938. int* l = destSamples[0] + startOffsetInDestBuffer;
  186939. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  186940. while (--numSamples >= 0)
  186941. {
  186942. *l++ = 0;
  186943. if (r != 0)
  186944. *r++ = 0;
  186945. }
  186946. // sometimes the read fails for just the very last couple of blocks, so
  186947. // we'll ignore and errors in the last half-second of the disk..
  186948. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  186949. break;
  186950. }
  186951. }
  186952. }
  186953. return ok;
  186954. }
  186955. bool AudioCDReader::isCDStillPresent() const
  186956. {
  186957. using namespace CDReaderHelpers;
  186958. TOC toc;
  186959. zerostruct (toc);
  186960. return ((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, false);
  186961. }
  186962. int AudioCDReader::getNumTracks() const
  186963. {
  186964. return numTracks;
  186965. }
  186966. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  186967. {
  186968. using namespace CDReaderHelpers;
  186969. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  186970. : 0;
  186971. }
  186972. void AudioCDReader::refreshTrackLengths()
  186973. {
  186974. using namespace CDReaderHelpers;
  186975. zeromem (trackStarts, sizeof (trackStarts));
  186976. zeromem (audioTracks, sizeof (audioTracks));
  186977. TOC toc;
  186978. zerostruct (toc);
  186979. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  186980. {
  186981. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  186982. for (int i = 0; i <= numTracks; ++i)
  186983. {
  186984. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  186985. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  186986. }
  186987. }
  186988. else
  186989. {
  186990. numTracks = 0;
  186991. }
  186992. }
  186993. bool AudioCDReader::isTrackAudio (int trackNum) const
  186994. {
  186995. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  186996. : false;
  186997. }
  186998. void AudioCDReader::enableIndexScanning (bool b)
  186999. {
  187000. indexingEnabled = b;
  187001. }
  187002. int AudioCDReader::getLastIndex() const
  187003. {
  187004. return lastIndex;
  187005. }
  187006. const int framesPerIndexRead = 4;
  187007. int AudioCDReader::getIndexAt (int samplePos)
  187008. {
  187009. using namespace CDReaderHelpers;
  187010. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187011. const int frameNeeded = samplePos / samplesPerFrame;
  187012. device->overlapBuffer->dataLength = 0;
  187013. device->overlapBuffer->startFrame = 0;
  187014. device->overlapBuffer->numFrames = 0;
  187015. device->jitter = false;
  187016. firstFrameInBuffer = 0;
  187017. lastIndex = 0;
  187018. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187019. readBuffer.wantsIndex = true;
  187020. int i;
  187021. for (i = 5; --i >= 0;)
  187022. {
  187023. readBuffer.startFrame = frameNeeded;
  187024. readBuffer.numFrames = framesPerIndexRead;
  187025. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187026. break;
  187027. }
  187028. if (i >= 0)
  187029. return readBuffer.index;
  187030. return -1;
  187031. }
  187032. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187033. {
  187034. using namespace CDReaderHelpers;
  187035. Array <int> indexes;
  187036. const int trackStart = getPositionOfTrackStart (trackNumber);
  187037. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187038. bool needToScan = true;
  187039. if (trackEnd - trackStart > 20 * 44100)
  187040. {
  187041. // check the end of the track for indexes before scanning the whole thing
  187042. needToScan = false;
  187043. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187044. bool seenAnIndex = false;
  187045. while (pos <= trackEnd - samplesPerFrame)
  187046. {
  187047. const int index = getIndexAt (pos);
  187048. if (index == 0)
  187049. {
  187050. // lead-out, so skip back a bit if we've not found any indexes yet..
  187051. if (seenAnIndex)
  187052. break;
  187053. pos -= 44100 * 5;
  187054. if (pos < trackStart)
  187055. break;
  187056. }
  187057. else
  187058. {
  187059. if (index > 0)
  187060. seenAnIndex = true;
  187061. if (index > 1)
  187062. {
  187063. needToScan = true;
  187064. break;
  187065. }
  187066. pos += samplesPerFrame * framesPerIndexRead;
  187067. }
  187068. }
  187069. }
  187070. if (needToScan)
  187071. {
  187072. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187073. int pos = trackStart;
  187074. int last = -1;
  187075. while (pos < trackEnd - samplesPerFrame * 10)
  187076. {
  187077. const int frameNeeded = pos / samplesPerFrame;
  187078. device->overlapBuffer->dataLength = 0;
  187079. device->overlapBuffer->startFrame = 0;
  187080. device->overlapBuffer->numFrames = 0;
  187081. device->jitter = false;
  187082. firstFrameInBuffer = 0;
  187083. CDReadBuffer readBuffer (4);
  187084. readBuffer.wantsIndex = true;
  187085. int i;
  187086. for (i = 5; --i >= 0;)
  187087. {
  187088. readBuffer.startFrame = frameNeeded;
  187089. readBuffer.numFrames = framesPerIndexRead;
  187090. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187091. break;
  187092. }
  187093. if (i < 0)
  187094. break;
  187095. if (readBuffer.index > last && readBuffer.index > 1)
  187096. {
  187097. last = readBuffer.index;
  187098. indexes.add (pos);
  187099. }
  187100. pos += samplesPerFrame * framesPerIndexRead;
  187101. }
  187102. indexes.removeValue (trackStart);
  187103. }
  187104. return indexes;
  187105. }
  187106. int AudioCDReader::getCDDBId()
  187107. {
  187108. using namespace CDReaderHelpers;
  187109. refreshTrackLengths();
  187110. if (numTracks > 0)
  187111. {
  187112. TOC toc;
  187113. zerostruct (toc);
  187114. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187115. {
  187116. int n = 0;
  187117. for (int i = numTracks; --i >= 0;)
  187118. {
  187119. int j = getMSFAddressOf (&toc.tracks[i]);
  187120. while (j > 0)
  187121. {
  187122. n += (j % 10);
  187123. j /= 10;
  187124. }
  187125. }
  187126. if (n != 0)
  187127. {
  187128. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187129. - getMSFAddressOf (&toc.tracks[0]);
  187130. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187131. }
  187132. }
  187133. }
  187134. return 0;
  187135. }
  187136. void AudioCDReader::ejectDisk()
  187137. {
  187138. using namespace CDReaderHelpers;
  187139. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187140. }
  187141. #endif
  187142. #if JUCE_USE_CDBURNER
  187143. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187144. {
  187145. CoInitialize (0);
  187146. IDiscMaster* dm;
  187147. IDiscRecorder* result = 0;
  187148. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187149. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187150. IID_IDiscMaster,
  187151. (void**) &dm)))
  187152. {
  187153. if (SUCCEEDED (dm->Open()))
  187154. {
  187155. IEnumDiscRecorders* drEnum = 0;
  187156. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187157. {
  187158. IDiscRecorder* dr = 0;
  187159. DWORD dummy;
  187160. int index = 0;
  187161. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187162. {
  187163. if (indexToOpen == index)
  187164. {
  187165. result = dr;
  187166. break;
  187167. }
  187168. else if (list != 0)
  187169. {
  187170. BSTR path;
  187171. if (SUCCEEDED (dr->GetPath (&path)))
  187172. list->add ((const WCHAR*) path);
  187173. }
  187174. ++index;
  187175. dr->Release();
  187176. }
  187177. drEnum->Release();
  187178. }
  187179. if (master == 0)
  187180. dm->Close();
  187181. }
  187182. if (master != 0)
  187183. *master = dm;
  187184. else
  187185. dm->Release();
  187186. }
  187187. return result;
  187188. }
  187189. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187190. public Timer
  187191. {
  187192. public:
  187193. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187194. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187195. listener (0), progress (0), shouldCancel (false), refCount (1)
  187196. {
  187197. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187198. jassert (SUCCEEDED (hr));
  187199. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187200. //jassert (SUCCEEDED (hr));
  187201. lastState = getDiskState();
  187202. startTimer (2000);
  187203. }
  187204. ~Pimpl() {}
  187205. void releaseObjects()
  187206. {
  187207. discRecorder->Close();
  187208. if (redbook != 0)
  187209. redbook->Release();
  187210. discRecorder->Release();
  187211. discMaster->Release();
  187212. Release();
  187213. }
  187214. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187215. {
  187216. if (result == 0)
  187217. return E_POINTER;
  187218. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187219. {
  187220. AddRef();
  187221. *result = this;
  187222. return S_OK;
  187223. }
  187224. *result = 0;
  187225. return E_NOINTERFACE;
  187226. }
  187227. ULONG __stdcall AddRef() { return ++refCount; }
  187228. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187229. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187230. {
  187231. if (listener != 0 && ! shouldCancel)
  187232. shouldCancel = listener->audioCDBurnProgress (progress);
  187233. *pbCancel = shouldCancel;
  187234. return S_OK;
  187235. }
  187236. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187237. {
  187238. progress = nCompleted / (float) nTotal;
  187239. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187240. return E_NOTIMPL;
  187241. }
  187242. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187243. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187244. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187245. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187246. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187247. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187248. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187249. class ScopedDiscOpener
  187250. {
  187251. public:
  187252. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187253. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187254. private:
  187255. Pimpl& pimpl;
  187256. ScopedDiscOpener (const ScopedDiscOpener&);
  187257. ScopedDiscOpener& operator= (const ScopedDiscOpener&);
  187258. };
  187259. DiskState getDiskState()
  187260. {
  187261. const ScopedDiscOpener opener (*this);
  187262. long type, flags;
  187263. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187264. if (FAILED (hr))
  187265. return unknown;
  187266. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187267. return writableDiskPresent;
  187268. if (type == 0)
  187269. return noDisc;
  187270. else
  187271. return readOnlyDiskPresent;
  187272. }
  187273. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187274. {
  187275. ComSmartPtr<IPropertyStorage> prop;
  187276. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187277. return defaultReturn;
  187278. PROPSPEC iPropSpec;
  187279. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187280. iPropSpec.lpwstr = name;
  187281. PROPVARIANT iPropVariant;
  187282. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187283. ? defaultReturn : (int) iPropVariant.lVal;
  187284. }
  187285. bool setIntProperty (const LPOLESTR name, const int value) const
  187286. {
  187287. ComSmartPtr<IPropertyStorage> prop;
  187288. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187289. return false;
  187290. PROPSPEC iPropSpec;
  187291. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187292. iPropSpec.lpwstr = name;
  187293. PROPVARIANT iPropVariant;
  187294. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187295. return false;
  187296. iPropVariant.lVal = (long) value;
  187297. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187298. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187299. }
  187300. void timerCallback()
  187301. {
  187302. const DiskState state = getDiskState();
  187303. if (state != lastState)
  187304. {
  187305. lastState = state;
  187306. owner.sendChangeMessage (&owner);
  187307. }
  187308. }
  187309. AudioCDBurner& owner;
  187310. DiskState lastState;
  187311. IDiscMaster* discMaster;
  187312. IDiscRecorder* discRecorder;
  187313. IRedbookDiscMaster* redbook;
  187314. AudioCDBurner::BurnProgressListener* listener;
  187315. float progress;
  187316. bool shouldCancel;
  187317. private:
  187318. int refCount;
  187319. };
  187320. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187321. {
  187322. IDiscMaster* discMaster = 0;
  187323. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187324. if (discRecorder != 0)
  187325. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187326. }
  187327. AudioCDBurner::~AudioCDBurner()
  187328. {
  187329. if (pimpl != 0)
  187330. pimpl.release()->releaseObjects();
  187331. }
  187332. const StringArray AudioCDBurner::findAvailableDevices()
  187333. {
  187334. StringArray devs;
  187335. enumCDBurners (&devs, -1, 0);
  187336. return devs;
  187337. }
  187338. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187339. {
  187340. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187341. if (b->pimpl == 0)
  187342. b = 0;
  187343. return b.release();
  187344. }
  187345. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187346. {
  187347. return pimpl->getDiskState();
  187348. }
  187349. bool AudioCDBurner::isDiskPresent() const
  187350. {
  187351. return getDiskState() == writableDiskPresent;
  187352. }
  187353. bool AudioCDBurner::openTray()
  187354. {
  187355. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187356. return SUCCEEDED (pimpl->discRecorder->Eject());
  187357. }
  187358. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187359. {
  187360. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187361. DiskState oldState = getDiskState();
  187362. DiskState newState = oldState;
  187363. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187364. {
  187365. newState = getDiskState();
  187366. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187367. }
  187368. return newState;
  187369. }
  187370. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187371. {
  187372. Array<int> results;
  187373. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187374. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187375. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187376. if (speeds[i] <= maxSpeed)
  187377. results.add (speeds[i]);
  187378. results.addIfNotAlreadyThere (maxSpeed);
  187379. return results;
  187380. }
  187381. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187382. {
  187383. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187384. return false;
  187385. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187386. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187387. }
  187388. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187389. {
  187390. long blocksFree = 0;
  187391. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187392. return blocksFree;
  187393. }
  187394. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187395. bool performFakeBurnForTesting, int writeSpeed)
  187396. {
  187397. pimpl->setIntProperty (L"WriteSpeed", writeSpeed > 0 ? writeSpeed : -1);
  187398. pimpl->listener = listener;
  187399. pimpl->progress = 0;
  187400. pimpl->shouldCancel = false;
  187401. UINT_PTR cookie;
  187402. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187403. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187404. ejectDiscAfterwards);
  187405. String error;
  187406. if (hr != S_OK)
  187407. {
  187408. const char* e = "Couldn't open or write to the CD device";
  187409. if (hr == IMAPI_E_USERABORT)
  187410. e = "User cancelled the write operation";
  187411. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187412. e = "No Disk present";
  187413. error = e;
  187414. }
  187415. pimpl->discMaster->ProgressUnadvise (cookie);
  187416. pimpl->listener = 0;
  187417. return error;
  187418. }
  187419. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  187420. {
  187421. if (audioSource == 0)
  187422. return false;
  187423. ScopedPointer<AudioSource> source (audioSource);
  187424. long bytesPerBlock;
  187425. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  187426. const int samplesPerBlock = bytesPerBlock / 4;
  187427. bool ok = true;
  187428. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  187429. HeapBlock <byte> buffer (bytesPerBlock);
  187430. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  187431. int samplesDone = 0;
  187432. source->prepareToPlay (samplesPerBlock, 44100.0);
  187433. while (ok)
  187434. {
  187435. {
  187436. AudioSourceChannelInfo info;
  187437. info.buffer = &sourceBuffer;
  187438. info.numSamples = samplesPerBlock;
  187439. info.startSample = 0;
  187440. sourceBuffer.clear();
  187441. source->getNextAudioBlock (info);
  187442. }
  187443. zeromem (buffer, bytesPerBlock);
  187444. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  187445. buffer, samplesPerBlock, 4);
  187446. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  187447. buffer + 2, samplesPerBlock, 4);
  187448. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  187449. if (FAILED (hr))
  187450. ok = false;
  187451. samplesDone += samplesPerBlock;
  187452. if (samplesDone >= numSamples)
  187453. break;
  187454. }
  187455. hr = pimpl->redbook->CloseAudioTrack();
  187456. return ok && hr == S_OK;
  187457. }
  187458. #endif
  187459. #endif
  187460. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  187461. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  187462. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187463. // compiled on its own).
  187464. #if JUCE_INCLUDED_FILE
  187465. using ::free;
  187466. namespace MidiConstants
  187467. {
  187468. static const int midiBufferSize = 1024 * 10;
  187469. static const int numInHeaders = 32;
  187470. static const int inBufferSize = 256;
  187471. }
  187472. class MidiInThread : public Thread
  187473. {
  187474. public:
  187475. MidiInThread (MidiInput* const input_,
  187476. MidiInputCallback* const callback_)
  187477. : Thread ("Juce Midi"),
  187478. hIn (0),
  187479. input (input_),
  187480. callback (callback_),
  187481. isStarted (false),
  187482. startTime (0),
  187483. pendingLength(0)
  187484. {
  187485. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187486. {
  187487. zeromem (&hdr[i], sizeof (MIDIHDR));
  187488. hdr[i].lpData = inData[i];
  187489. hdr[i].dwBufferLength = MidiConstants::inBufferSize;
  187490. }
  187491. };
  187492. ~MidiInThread()
  187493. {
  187494. stop();
  187495. if (hIn != 0)
  187496. {
  187497. int count = 5;
  187498. while (--count >= 0)
  187499. {
  187500. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  187501. break;
  187502. Sleep (20);
  187503. }
  187504. }
  187505. }
  187506. void handle (const uint32 message, const uint32 timeStamp) throw()
  187507. {
  187508. const int byte = message & 0xff;
  187509. if (byte < 0x80)
  187510. return;
  187511. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  187512. const double time = timeStampToTime (timeStamp);
  187513. {
  187514. const ScopedLock sl (lock);
  187515. if (pendingLength < MidiConstants::midiBufferSize - 12)
  187516. {
  187517. char* const p = pending + pendingLength;
  187518. *(double*) p = time;
  187519. *(uint32*) (p + 8) = numBytes;
  187520. *(uint32*) (p + 12) = message;
  187521. pendingLength += 12 + numBytes;
  187522. }
  187523. else
  187524. {
  187525. jassertfalse // midi buffer overflow! You might need to increase the size..
  187526. }
  187527. }
  187528. notify();
  187529. }
  187530. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  187531. {
  187532. const int num = hdr->dwBytesRecorded;
  187533. if (num > 0)
  187534. {
  187535. const double time = timeStampToTime (timeStamp);
  187536. {
  187537. const ScopedLock sl (lock);
  187538. if (pendingLength < MidiConstants::midiBufferSize - (8 + num))
  187539. {
  187540. char* const p = pending + pendingLength;
  187541. *(double*) p = time;
  187542. *(uint32*) (p + 8) = num;
  187543. memcpy (p + 12, hdr->lpData, num);
  187544. pendingLength += 12 + num;
  187545. }
  187546. else
  187547. {
  187548. jassertfalse // midi buffer overflow! You might need to increase the size..
  187549. }
  187550. }
  187551. notify();
  187552. }
  187553. }
  187554. void writeBlock (const int i) throw()
  187555. {
  187556. hdr[i].dwBytesRecorded = 0;
  187557. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187558. jassert (res == MMSYSERR_NOERROR);
  187559. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  187560. jassert (res == MMSYSERR_NOERROR);
  187561. }
  187562. void run()
  187563. {
  187564. MemoryBlock pendingCopy (64);
  187565. while (! threadShouldExit())
  187566. {
  187567. for (int i = 0; i < MidiConstants::numInHeaders; ++i)
  187568. {
  187569. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187570. {
  187571. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  187572. (void) res;
  187573. jassert (res == MMSYSERR_NOERROR);
  187574. writeBlock (i);
  187575. }
  187576. }
  187577. int len;
  187578. {
  187579. const ScopedLock sl (lock);
  187580. len = pendingLength;
  187581. if (len > 0)
  187582. {
  187583. pendingCopy.ensureSize (len);
  187584. pendingCopy.copyFrom (pending, 0, len);
  187585. pendingLength = 0;
  187586. }
  187587. }
  187588. //xxx needs to figure out if blocks are broken up or not
  187589. if (len == 0)
  187590. {
  187591. wait (500);
  187592. }
  187593. else
  187594. {
  187595. const char* p = (const char*) pendingCopy.getData();
  187596. while (len > 0)
  187597. {
  187598. const double time = *(const double*) p;
  187599. const int messageLen = *(const int*) (p + 8);
  187600. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  187601. callback->handleIncomingMidiMessage (input, message);
  187602. p += 12 + messageLen;
  187603. len -= 12 + messageLen;
  187604. }
  187605. }
  187606. }
  187607. }
  187608. void start() throw()
  187609. {
  187610. jassert (hIn != 0);
  187611. if (hIn != 0 && ! isStarted)
  187612. {
  187613. stop();
  187614. activeMidiThreads.addIfNotAlreadyThere (this);
  187615. int i;
  187616. for (i = 0; i < MidiConstants::numInHeaders; ++i)
  187617. writeBlock (i);
  187618. startTime = Time::getMillisecondCounter();
  187619. MMRESULT res = midiInStart (hIn);
  187620. jassert (res == MMSYSERR_NOERROR);
  187621. if (res == MMSYSERR_NOERROR)
  187622. {
  187623. isStarted = true;
  187624. pendingLength = 0;
  187625. startThread (6);
  187626. }
  187627. }
  187628. }
  187629. void stop() throw()
  187630. {
  187631. if (isStarted)
  187632. {
  187633. stopThread (5000);
  187634. midiInReset (hIn);
  187635. midiInStop (hIn);
  187636. activeMidiThreads.removeValue (this);
  187637. { const ScopedLock sl (lock); }
  187638. for (int i = MidiConstants::numInHeaders; --i >= 0;)
  187639. {
  187640. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  187641. {
  187642. int c = 10;
  187643. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  187644. Sleep (20);
  187645. jassert (c >= 0);
  187646. }
  187647. }
  187648. isStarted = false;
  187649. pendingLength = 0;
  187650. }
  187651. }
  187652. static void CALLBACK midiInCallback (HMIDIIN, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR midiMessage, DWORD_PTR timeStamp)
  187653. {
  187654. MidiInThread* const thread = reinterpret_cast <MidiInThread*> (dwInstance);
  187655. if (thread != 0 && activeMidiThreads.contains (thread))
  187656. {
  187657. if (uMsg == MIM_DATA)
  187658. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  187659. else if (uMsg == MIM_LONGDATA)
  187660. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  187661. }
  187662. }
  187663. juce_UseDebuggingNewOperator
  187664. HMIDIIN hIn;
  187665. private:
  187666. static Array <void*, CriticalSection> activeMidiThreads;
  187667. MidiInput* input;
  187668. MidiInputCallback* callback;
  187669. bool isStarted;
  187670. uint32 startTime;
  187671. CriticalSection lock;
  187672. MIDIHDR hdr [MidiConstants::numInHeaders];
  187673. char inData [MidiConstants::numInHeaders] [MidiConstants::inBufferSize];
  187674. int pendingLength;
  187675. char pending [MidiConstants::midiBufferSize];
  187676. double timeStampToTime (uint32 timeStamp) throw()
  187677. {
  187678. timeStamp += startTime;
  187679. const uint32 now = Time::getMillisecondCounter();
  187680. if (timeStamp > now)
  187681. {
  187682. if (timeStamp > now + 2)
  187683. --startTime;
  187684. timeStamp = now;
  187685. }
  187686. return 0.001 * timeStamp;
  187687. }
  187688. MidiInThread (const MidiInThread&);
  187689. MidiInThread& operator= (const MidiInThread&);
  187690. };
  187691. Array <void*, CriticalSection> MidiInThread::activeMidiThreads;
  187692. const StringArray MidiInput::getDevices()
  187693. {
  187694. StringArray s;
  187695. const int num = midiInGetNumDevs();
  187696. for (int i = 0; i < num; ++i)
  187697. {
  187698. MIDIINCAPS mc;
  187699. zerostruct (mc);
  187700. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187701. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187702. }
  187703. return s;
  187704. }
  187705. int MidiInput::getDefaultDeviceIndex()
  187706. {
  187707. return 0;
  187708. }
  187709. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  187710. {
  187711. if (callback == 0)
  187712. return 0;
  187713. UINT deviceId = MIDI_MAPPER;
  187714. int n = 0;
  187715. String name;
  187716. const int num = midiInGetNumDevs();
  187717. for (int i = 0; i < num; ++i)
  187718. {
  187719. MIDIINCAPS mc;
  187720. zerostruct (mc);
  187721. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187722. {
  187723. if (index == n)
  187724. {
  187725. deviceId = i;
  187726. name = String (mc.szPname, sizeof (mc.szPname));
  187727. break;
  187728. }
  187729. ++n;
  187730. }
  187731. }
  187732. ScopedPointer <MidiInput> in (new MidiInput (name));
  187733. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  187734. HMIDIIN h;
  187735. HRESULT err = midiInOpen (&h, deviceId,
  187736. (DWORD_PTR) &MidiInThread::midiInCallback,
  187737. (DWORD_PTR) (MidiInThread*) thread,
  187738. CALLBACK_FUNCTION);
  187739. if (err == MMSYSERR_NOERROR)
  187740. {
  187741. thread->hIn = h;
  187742. in->internal = thread.release();
  187743. return in.release();
  187744. }
  187745. return 0;
  187746. }
  187747. MidiInput::MidiInput (const String& name_)
  187748. : name (name_),
  187749. internal (0)
  187750. {
  187751. }
  187752. MidiInput::~MidiInput()
  187753. {
  187754. delete static_cast <MidiInThread*> (internal);
  187755. }
  187756. void MidiInput::start()
  187757. {
  187758. static_cast <MidiInThread*> (internal)->start();
  187759. }
  187760. void MidiInput::stop()
  187761. {
  187762. static_cast <MidiInThread*> (internal)->stop();
  187763. }
  187764. struct MidiOutHandle
  187765. {
  187766. int refCount;
  187767. UINT deviceId;
  187768. HMIDIOUT handle;
  187769. static Array<MidiOutHandle*> activeHandles;
  187770. juce_UseDebuggingNewOperator
  187771. };
  187772. Array<MidiOutHandle*> MidiOutHandle::activeHandles;
  187773. const StringArray MidiOutput::getDevices()
  187774. {
  187775. StringArray s;
  187776. const int num = midiOutGetNumDevs();
  187777. for (int i = 0; i < num; ++i)
  187778. {
  187779. MIDIOUTCAPS mc;
  187780. zerostruct (mc);
  187781. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187782. s.add (String (mc.szPname, sizeof (mc.szPname)));
  187783. }
  187784. return s;
  187785. }
  187786. int MidiOutput::getDefaultDeviceIndex()
  187787. {
  187788. const int num = midiOutGetNumDevs();
  187789. int n = 0;
  187790. for (int i = 0; i < num; ++i)
  187791. {
  187792. MIDIOUTCAPS mc;
  187793. zerostruct (mc);
  187794. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187795. {
  187796. if ((mc.wTechnology & MOD_MAPPER) != 0)
  187797. return n;
  187798. ++n;
  187799. }
  187800. }
  187801. return 0;
  187802. }
  187803. MidiOutput* MidiOutput::openDevice (int index)
  187804. {
  187805. UINT deviceId = MIDI_MAPPER;
  187806. const int num = midiOutGetNumDevs();
  187807. int i, n = 0;
  187808. for (i = 0; i < num; ++i)
  187809. {
  187810. MIDIOUTCAPS mc;
  187811. zerostruct (mc);
  187812. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  187813. {
  187814. // use the microsoft sw synth as a default - best not to allow deviceId
  187815. // to be MIDI_MAPPER, or else device sharing breaks
  187816. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase ("microsoft"))
  187817. deviceId = i;
  187818. if (index == n)
  187819. {
  187820. deviceId = i;
  187821. break;
  187822. }
  187823. ++n;
  187824. }
  187825. }
  187826. for (i = MidiOutHandle::activeHandles.size(); --i >= 0;)
  187827. {
  187828. MidiOutHandle* const han = MidiOutHandle::activeHandles.getUnchecked(i);
  187829. if (han != 0 && han->deviceId == deviceId)
  187830. {
  187831. han->refCount++;
  187832. MidiOutput* const out = new MidiOutput();
  187833. out->internal = han;
  187834. return out;
  187835. }
  187836. }
  187837. for (i = 4; --i >= 0;)
  187838. {
  187839. HMIDIOUT h = 0;
  187840. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  187841. if (res == MMSYSERR_NOERROR)
  187842. {
  187843. MidiOutHandle* const han = new MidiOutHandle();
  187844. han->deviceId = deviceId;
  187845. han->refCount = 1;
  187846. han->handle = h;
  187847. MidiOutHandle::activeHandles.add (han);
  187848. MidiOutput* const out = new MidiOutput();
  187849. out->internal = han;
  187850. return out;
  187851. }
  187852. else if (res == MMSYSERR_ALLOCATED)
  187853. {
  187854. Sleep (100);
  187855. }
  187856. else
  187857. {
  187858. break;
  187859. }
  187860. }
  187861. return 0;
  187862. }
  187863. MidiOutput::~MidiOutput()
  187864. {
  187865. MidiOutHandle* const h = static_cast <MidiOutHandle*> (internal);
  187866. if (MidiOutHandle::activeHandles.contains (h) && --(h->refCount) == 0)
  187867. {
  187868. midiOutClose (h->handle);
  187869. MidiOutHandle::activeHandles.removeValue (h);
  187870. delete h;
  187871. }
  187872. }
  187873. void MidiOutput::reset()
  187874. {
  187875. const MidiOutHandle* const h = static_cast <const MidiOutHandle*> (internal);
  187876. midiOutReset (h->handle);
  187877. }
  187878. bool MidiOutput::getVolume (float& leftVol,
  187879. float& rightVol)
  187880. {
  187881. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187882. DWORD n;
  187883. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  187884. {
  187885. const unsigned short* const nn = (const unsigned short*) &n;
  187886. rightVol = nn[0] / (float) 0xffff;
  187887. leftVol = nn[1] / (float) 0xffff;
  187888. return true;
  187889. }
  187890. else
  187891. {
  187892. rightVol = leftVol = 1.0f;
  187893. return false;
  187894. }
  187895. }
  187896. void MidiOutput::setVolume (float leftVol,
  187897. float rightVol)
  187898. {
  187899. const MidiOutHandle* const handle = static_cast <MidiOutHandle*> (internal);
  187900. DWORD n;
  187901. unsigned short* const nn = (unsigned short*) &n;
  187902. nn[0] = (unsigned short) jlimit (0, 0xffff, (int) (rightVol * 0xffff));
  187903. nn[1] = (unsigned short) jlimit (0, 0xffff, (int) (leftVol * 0xffff));
  187904. midiOutSetVolume (handle->handle, n);
  187905. }
  187906. void MidiOutput::sendMessageNow (const MidiMessage& message)
  187907. {
  187908. const MidiOutHandle* const handle = static_cast <const MidiOutHandle*> (internal);
  187909. if (message.getRawDataSize() > 3
  187910. || message.isSysEx())
  187911. {
  187912. MIDIHDR h;
  187913. zerostruct (h);
  187914. h.lpData = (char*) message.getRawData();
  187915. h.dwBufferLength = message.getRawDataSize();
  187916. h.dwBytesRecorded = message.getRawDataSize();
  187917. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  187918. {
  187919. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  187920. if (res == MMSYSERR_NOERROR)
  187921. {
  187922. while ((h.dwFlags & MHDR_DONE) == 0)
  187923. Sleep (1);
  187924. int count = 500; // 1 sec timeout
  187925. while (--count >= 0)
  187926. {
  187927. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  187928. if (res == MIDIERR_STILLPLAYING)
  187929. Sleep (2);
  187930. else
  187931. break;
  187932. }
  187933. }
  187934. }
  187935. }
  187936. else
  187937. {
  187938. midiOutShortMsg (handle->handle,
  187939. *(unsigned int*) message.getRawData());
  187940. }
  187941. }
  187942. #endif
  187943. /*** End of inlined file: juce_win32_Midi.cpp ***/
  187944. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  187945. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  187946. // compiled on its own).
  187947. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  187948. #undef WINDOWS
  187949. // #define ASIO_DEBUGGING
  187950. #ifdef ASIO_DEBUGGING
  187951. #define log(a) { Logger::writeToLog (a); DBG (a) }
  187952. #else
  187953. #define log(a) {}
  187954. #endif
  187955. #ifdef ASIO_DEBUGGING
  187956. static void logError (const String& context, long error)
  187957. {
  187958. String err ("unknown error");
  187959. if (error == ASE_NotPresent)
  187960. err = "Not Present";
  187961. else if (error == ASE_HWMalfunction)
  187962. err = "Hardware Malfunction";
  187963. else if (error == ASE_InvalidParameter)
  187964. err = "Invalid Parameter";
  187965. else if (error == ASE_InvalidMode)
  187966. err = "Invalid Mode";
  187967. else if (error == ASE_SPNotAdvancing)
  187968. err = "Sample position not advancing";
  187969. else if (error == ASE_NoClock)
  187970. err = "No Clock";
  187971. else if (error == ASE_NoMemory)
  187972. err = "Out of memory";
  187973. log ("!!error: " + context + " - " + err);
  187974. }
  187975. #else
  187976. #define logError(a, b) {}
  187977. #endif
  187978. class ASIOAudioIODevice;
  187979. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  187980. static const int maxASIOChannels = 160;
  187981. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  187982. private Timer
  187983. {
  187984. public:
  187985. Component ourWindow;
  187986. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  187987. const String& optionalDllForDirectLoading_)
  187988. : AudioIODevice (name_, "ASIO"),
  187989. asioObject (0),
  187990. classId (classId_),
  187991. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  187992. currentBitDepth (16),
  187993. currentSampleRate (0),
  187994. isOpen_ (false),
  187995. isStarted (false),
  187996. postOutput (true),
  187997. insideControlPanelModalLoop (false),
  187998. shouldUsePreferredSize (false)
  187999. {
  188000. name = name_;
  188001. ourWindow.addToDesktop (0);
  188002. windowHandle = ourWindow.getWindowHandle();
  188003. jassert (currentASIODev [slotNumber] == 0);
  188004. currentASIODev [slotNumber] = this;
  188005. openDevice();
  188006. }
  188007. ~ASIOAudioIODevice()
  188008. {
  188009. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188010. if (currentASIODev[i] == this)
  188011. currentASIODev[i] = 0;
  188012. close();
  188013. log ("ASIO - exiting");
  188014. removeCurrentDriver();
  188015. }
  188016. void updateSampleRates()
  188017. {
  188018. // find a list of sample rates..
  188019. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188020. sampleRates.clear();
  188021. if (asioObject != 0)
  188022. {
  188023. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188024. {
  188025. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188026. if (err == 0)
  188027. {
  188028. sampleRates.add ((int) possibleSampleRates[index]);
  188029. log ("rate: " + String ((int) possibleSampleRates[index]));
  188030. }
  188031. else if (err != ASE_NoClock)
  188032. {
  188033. logError ("CanSampleRate", err);
  188034. }
  188035. }
  188036. if (sampleRates.size() == 0)
  188037. {
  188038. double cr = 0;
  188039. const long err = asioObject->getSampleRate (&cr);
  188040. log ("No sample rates supported - current rate: " + String ((int) cr));
  188041. if (err == 0)
  188042. sampleRates.add ((int) cr);
  188043. }
  188044. }
  188045. }
  188046. const StringArray getOutputChannelNames()
  188047. {
  188048. return outputChannelNames;
  188049. }
  188050. const StringArray getInputChannelNames()
  188051. {
  188052. return inputChannelNames;
  188053. }
  188054. int getNumSampleRates()
  188055. {
  188056. return sampleRates.size();
  188057. }
  188058. double getSampleRate (int index)
  188059. {
  188060. return sampleRates [index];
  188061. }
  188062. int getNumBufferSizesAvailable()
  188063. {
  188064. return bufferSizes.size();
  188065. }
  188066. int getBufferSizeSamples (int index)
  188067. {
  188068. return bufferSizes [index];
  188069. }
  188070. int getDefaultBufferSize()
  188071. {
  188072. return preferredSize;
  188073. }
  188074. const String open (const BigInteger& inputChannels,
  188075. const BigInteger& outputChannels,
  188076. double sr,
  188077. int bufferSizeSamples)
  188078. {
  188079. close();
  188080. currentCallback = 0;
  188081. if (bufferSizeSamples <= 0)
  188082. shouldUsePreferredSize = true;
  188083. if (asioObject == 0 || ! isASIOOpen)
  188084. {
  188085. log ("Warning: device not open");
  188086. const String err (openDevice());
  188087. if (asioObject == 0 || ! isASIOOpen)
  188088. return err;
  188089. }
  188090. isStarted = false;
  188091. bufferIndex = -1;
  188092. long err = 0;
  188093. long newPreferredSize = 0;
  188094. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188095. minSize = 0;
  188096. maxSize = 0;
  188097. newPreferredSize = 0;
  188098. granularity = 0;
  188099. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188100. {
  188101. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188102. shouldUsePreferredSize = true;
  188103. preferredSize = newPreferredSize;
  188104. }
  188105. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188106. // dynamic changes to the buffer size...
  188107. shouldUsePreferredSize = shouldUsePreferredSize
  188108. || getName().containsIgnoreCase ("Digidesign");
  188109. if (shouldUsePreferredSize)
  188110. {
  188111. log ("Using preferred size for buffer..");
  188112. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188113. {
  188114. bufferSizeSamples = preferredSize;
  188115. }
  188116. else
  188117. {
  188118. bufferSizeSamples = 1024;
  188119. logError ("GetBufferSize1", err);
  188120. }
  188121. shouldUsePreferredSize = false;
  188122. }
  188123. int sampleRate = roundDoubleToInt (sr);
  188124. currentSampleRate = sampleRate;
  188125. currentBlockSizeSamples = bufferSizeSamples;
  188126. currentChansOut.clear();
  188127. currentChansIn.clear();
  188128. zeromem (inBuffers, sizeof (inBuffers));
  188129. zeromem (outBuffers, sizeof (outBuffers));
  188130. updateSampleRates();
  188131. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188132. sampleRate = sampleRates[0];
  188133. jassert (sampleRate != 0);
  188134. if (sampleRate == 0)
  188135. sampleRate = 44100;
  188136. long numSources = 32;
  188137. ASIOClockSource clocks[32];
  188138. zeromem (clocks, sizeof (clocks));
  188139. asioObject->getClockSources (clocks, &numSources);
  188140. bool isSourceSet = false;
  188141. // careful not to remove this loop because it does more than just logging!
  188142. int i;
  188143. for (i = 0; i < numSources; ++i)
  188144. {
  188145. String s ("clock: ");
  188146. s += clocks[i].name;
  188147. if (clocks[i].isCurrentSource)
  188148. {
  188149. isSourceSet = true;
  188150. s << " (cur)";
  188151. }
  188152. log (s);
  188153. }
  188154. if (numSources > 1 && ! isSourceSet)
  188155. {
  188156. log ("setting clock source");
  188157. asioObject->setClockSource (clocks[0].index);
  188158. Thread::sleep (20);
  188159. }
  188160. else
  188161. {
  188162. if (numSources == 0)
  188163. {
  188164. log ("ASIO - no clock sources!");
  188165. }
  188166. }
  188167. double cr = 0;
  188168. err = asioObject->getSampleRate (&cr);
  188169. if (err == 0)
  188170. {
  188171. currentSampleRate = cr;
  188172. }
  188173. else
  188174. {
  188175. logError ("GetSampleRate", err);
  188176. currentSampleRate = 0;
  188177. }
  188178. error = String::empty;
  188179. needToReset = false;
  188180. isReSync = false;
  188181. err = 0;
  188182. bool buffersCreated = false;
  188183. if (currentSampleRate != sampleRate)
  188184. {
  188185. log ("ASIO samplerate: " + String (currentSampleRate) + " to " + String (sampleRate));
  188186. err = asioObject->setSampleRate (sampleRate);
  188187. if (err == ASE_NoClock && numSources > 0)
  188188. {
  188189. log ("trying to set a clock source..");
  188190. Thread::sleep (10);
  188191. err = asioObject->setClockSource (clocks[0].index);
  188192. if (err != 0)
  188193. {
  188194. logError ("SetClock", err);
  188195. }
  188196. Thread::sleep (10);
  188197. err = asioObject->setSampleRate (sampleRate);
  188198. }
  188199. }
  188200. if (err == 0)
  188201. {
  188202. currentSampleRate = sampleRate;
  188203. if (needToReset)
  188204. {
  188205. if (isReSync)
  188206. {
  188207. log ("Resync request");
  188208. }
  188209. log ("! Resetting ASIO after sample rate change");
  188210. removeCurrentDriver();
  188211. loadDriver();
  188212. const String error (initDriver());
  188213. if (error.isNotEmpty())
  188214. {
  188215. log ("ASIOInit: " + error);
  188216. }
  188217. needToReset = false;
  188218. isReSync = false;
  188219. }
  188220. numActiveInputChans = 0;
  188221. numActiveOutputChans = 0;
  188222. ASIOBufferInfo* info = bufferInfos;
  188223. int i;
  188224. for (i = 0; i < totalNumInputChans; ++i)
  188225. {
  188226. if (inputChannels[i])
  188227. {
  188228. currentChansIn.setBit (i);
  188229. info->isInput = 1;
  188230. info->channelNum = i;
  188231. info->buffers[0] = info->buffers[1] = 0;
  188232. ++info;
  188233. ++numActiveInputChans;
  188234. }
  188235. }
  188236. for (i = 0; i < totalNumOutputChans; ++i)
  188237. {
  188238. if (outputChannels[i])
  188239. {
  188240. currentChansOut.setBit (i);
  188241. info->isInput = 0;
  188242. info->channelNum = i;
  188243. info->buffers[0] = info->buffers[1] = 0;
  188244. ++info;
  188245. ++numActiveOutputChans;
  188246. }
  188247. }
  188248. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188249. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188250. if (currentASIODev[0] == this)
  188251. {
  188252. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188253. callbacks.asioMessage = &asioMessagesCallback0;
  188254. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188255. }
  188256. else if (currentASIODev[1] == this)
  188257. {
  188258. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188259. callbacks.asioMessage = &asioMessagesCallback1;
  188260. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188261. }
  188262. else if (currentASIODev[2] == this)
  188263. {
  188264. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188265. callbacks.asioMessage = &asioMessagesCallback2;
  188266. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188267. }
  188268. else
  188269. {
  188270. jassertfalse
  188271. }
  188272. log ("disposing buffers");
  188273. err = asioObject->disposeBuffers();
  188274. log ("creating buffers: " + String (totalBuffers) + ", " + String (currentBlockSizeSamples));
  188275. err = asioObject->createBuffers (bufferInfos,
  188276. totalBuffers,
  188277. currentBlockSizeSamples,
  188278. &callbacks);
  188279. if (err != 0)
  188280. {
  188281. currentBlockSizeSamples = preferredSize;
  188282. logError ("create buffers 2", err);
  188283. asioObject->disposeBuffers();
  188284. err = asioObject->createBuffers (bufferInfos,
  188285. totalBuffers,
  188286. currentBlockSizeSamples,
  188287. &callbacks);
  188288. }
  188289. if (err == 0)
  188290. {
  188291. buffersCreated = true;
  188292. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188293. int n = 0;
  188294. Array <int> types;
  188295. currentBitDepth = 16;
  188296. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188297. {
  188298. if (inputChannels[i])
  188299. {
  188300. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188301. ASIOChannelInfo channelInfo;
  188302. zerostruct (channelInfo);
  188303. channelInfo.channel = i;
  188304. channelInfo.isInput = 1;
  188305. asioObject->getChannelInfo (&channelInfo);
  188306. types.addIfNotAlreadyThere (channelInfo.type);
  188307. typeToFormatParameters (channelInfo.type,
  188308. inputChannelBitDepths[n],
  188309. inputChannelBytesPerSample[n],
  188310. inputChannelIsFloat[n],
  188311. inputChannelLittleEndian[n]);
  188312. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188313. ++n;
  188314. }
  188315. }
  188316. jassert (numActiveInputChans == n);
  188317. n = 0;
  188318. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188319. {
  188320. if (outputChannels[i])
  188321. {
  188322. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188323. ASIOChannelInfo channelInfo;
  188324. zerostruct (channelInfo);
  188325. channelInfo.channel = i;
  188326. channelInfo.isInput = 0;
  188327. asioObject->getChannelInfo (&channelInfo);
  188328. types.addIfNotAlreadyThere (channelInfo.type);
  188329. typeToFormatParameters (channelInfo.type,
  188330. outputChannelBitDepths[n],
  188331. outputChannelBytesPerSample[n],
  188332. outputChannelIsFloat[n],
  188333. outputChannelLittleEndian[n]);
  188334. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188335. ++n;
  188336. }
  188337. }
  188338. jassert (numActiveOutputChans == n);
  188339. for (i = types.size(); --i >= 0;)
  188340. {
  188341. log ("channel format: " + String (types[i]));
  188342. }
  188343. jassert (n <= totalBuffers);
  188344. for (i = 0; i < numActiveOutputChans; ++i)
  188345. {
  188346. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188347. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188348. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188349. {
  188350. log ("!! Null buffers");
  188351. }
  188352. else
  188353. {
  188354. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188355. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188356. }
  188357. }
  188358. inputLatency = outputLatency = 0;
  188359. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188360. {
  188361. log ("ASIO - no latencies");
  188362. }
  188363. else
  188364. {
  188365. log ("ASIO latencies: " + String ((int) outputLatency) + ", " + String ((int) inputLatency));
  188366. }
  188367. isOpen_ = true;
  188368. log ("starting ASIO");
  188369. calledback = false;
  188370. err = asioObject->start();
  188371. if (err != 0)
  188372. {
  188373. isOpen_ = false;
  188374. log ("ASIO - stop on failure");
  188375. Thread::sleep (10);
  188376. asioObject->stop();
  188377. error = "Can't start device";
  188378. Thread::sleep (10);
  188379. }
  188380. else
  188381. {
  188382. int count = 300;
  188383. while (--count > 0 && ! calledback)
  188384. Thread::sleep (10);
  188385. isStarted = true;
  188386. if (! calledback)
  188387. {
  188388. error = "Device didn't start correctly";
  188389. log ("ASIO didn't callback - stopping..");
  188390. asioObject->stop();
  188391. }
  188392. }
  188393. }
  188394. else
  188395. {
  188396. error = "Can't create i/o buffers";
  188397. }
  188398. }
  188399. else
  188400. {
  188401. error = "Can't set sample rate: ";
  188402. error << sampleRate;
  188403. }
  188404. if (error.isNotEmpty())
  188405. {
  188406. logError (error, err);
  188407. if (asioObject != 0 && buffersCreated)
  188408. asioObject->disposeBuffers();
  188409. Thread::sleep (20);
  188410. isStarted = false;
  188411. isOpen_ = false;
  188412. close();
  188413. }
  188414. needToReset = false;
  188415. isReSync = false;
  188416. return error;
  188417. }
  188418. void close()
  188419. {
  188420. error = String::empty;
  188421. stopTimer();
  188422. stop();
  188423. if (isASIOOpen && isOpen_)
  188424. {
  188425. const ScopedLock sl (callbackLock);
  188426. isOpen_ = false;
  188427. isStarted = false;
  188428. needToReset = false;
  188429. isReSync = false;
  188430. log ("ASIO - stopping");
  188431. if (asioObject != 0)
  188432. {
  188433. Thread::sleep (20);
  188434. asioObject->stop();
  188435. Thread::sleep (10);
  188436. asioObject->disposeBuffers();
  188437. }
  188438. Thread::sleep (10);
  188439. }
  188440. }
  188441. bool isOpen()
  188442. {
  188443. return isOpen_ || insideControlPanelModalLoop;
  188444. }
  188445. int getCurrentBufferSizeSamples()
  188446. {
  188447. return currentBlockSizeSamples;
  188448. }
  188449. double getCurrentSampleRate()
  188450. {
  188451. return currentSampleRate;
  188452. }
  188453. const BigInteger getActiveOutputChannels() const
  188454. {
  188455. return currentChansOut;
  188456. }
  188457. const BigInteger getActiveInputChannels() const
  188458. {
  188459. return currentChansIn;
  188460. }
  188461. int getCurrentBitDepth()
  188462. {
  188463. return currentBitDepth;
  188464. }
  188465. int getOutputLatencyInSamples()
  188466. {
  188467. return outputLatency + currentBlockSizeSamples / 4;
  188468. }
  188469. int getInputLatencyInSamples()
  188470. {
  188471. return inputLatency + currentBlockSizeSamples / 4;
  188472. }
  188473. void start (AudioIODeviceCallback* callback)
  188474. {
  188475. if (callback != 0)
  188476. {
  188477. callback->audioDeviceAboutToStart (this);
  188478. const ScopedLock sl (callbackLock);
  188479. currentCallback = callback;
  188480. }
  188481. }
  188482. void stop()
  188483. {
  188484. AudioIODeviceCallback* const lastCallback = currentCallback;
  188485. {
  188486. const ScopedLock sl (callbackLock);
  188487. currentCallback = 0;
  188488. }
  188489. if (lastCallback != 0)
  188490. lastCallback->audioDeviceStopped();
  188491. }
  188492. bool isPlaying()
  188493. {
  188494. return isASIOOpen && (currentCallback != 0);
  188495. }
  188496. const String getLastError()
  188497. {
  188498. return error;
  188499. }
  188500. bool hasControlPanel() const
  188501. {
  188502. return true;
  188503. }
  188504. bool showControlPanel()
  188505. {
  188506. log ("ASIO - showing control panel");
  188507. Component modalWindow (String::empty);
  188508. modalWindow.setOpaque (true);
  188509. modalWindow.addToDesktop (0);
  188510. modalWindow.enterModalState();
  188511. bool done = false;
  188512. JUCE_TRY
  188513. {
  188514. // are there are devices that need to be closed before showing their control panel?
  188515. // close();
  188516. insideControlPanelModalLoop = true;
  188517. const uint32 started = Time::getMillisecondCounter();
  188518. if (asioObject != 0)
  188519. {
  188520. asioObject->controlPanel();
  188521. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  188522. log ("spent: " + String (spent));
  188523. if (spent > 300)
  188524. {
  188525. shouldUsePreferredSize = true;
  188526. done = true;
  188527. }
  188528. }
  188529. }
  188530. JUCE_CATCH_ALL
  188531. insideControlPanelModalLoop = false;
  188532. return done;
  188533. }
  188534. void resetRequest() throw()
  188535. {
  188536. needToReset = true;
  188537. }
  188538. void resyncRequest() throw()
  188539. {
  188540. needToReset = true;
  188541. isReSync = true;
  188542. }
  188543. void timerCallback()
  188544. {
  188545. if (! insideControlPanelModalLoop)
  188546. {
  188547. stopTimer();
  188548. // used to cause a reset
  188549. log ("! ASIO restart request!");
  188550. if (isOpen_)
  188551. {
  188552. AudioIODeviceCallback* const oldCallback = currentCallback;
  188553. close();
  188554. open (BigInteger (currentChansIn), BigInteger (currentChansOut),
  188555. currentSampleRate, currentBlockSizeSamples);
  188556. if (oldCallback != 0)
  188557. start (oldCallback);
  188558. }
  188559. }
  188560. else
  188561. {
  188562. startTimer (100);
  188563. }
  188564. }
  188565. juce_UseDebuggingNewOperator
  188566. private:
  188567. IASIO* volatile asioObject;
  188568. ASIOCallbacks callbacks;
  188569. void* windowHandle;
  188570. CLSID classId;
  188571. const String optionalDllForDirectLoading;
  188572. String error;
  188573. long totalNumInputChans, totalNumOutputChans;
  188574. StringArray inputChannelNames, outputChannelNames;
  188575. Array<int> sampleRates, bufferSizes;
  188576. long inputLatency, outputLatency;
  188577. long minSize, maxSize, preferredSize, granularity;
  188578. int volatile currentBlockSizeSamples;
  188579. int volatile currentBitDepth;
  188580. double volatile currentSampleRate;
  188581. BigInteger currentChansOut, currentChansIn;
  188582. AudioIODeviceCallback* volatile currentCallback;
  188583. CriticalSection callbackLock;
  188584. ASIOBufferInfo bufferInfos [maxASIOChannels];
  188585. float* inBuffers [maxASIOChannels];
  188586. float* outBuffers [maxASIOChannels];
  188587. int inputChannelBitDepths [maxASIOChannels];
  188588. int outputChannelBitDepths [maxASIOChannels];
  188589. int inputChannelBytesPerSample [maxASIOChannels];
  188590. int outputChannelBytesPerSample [maxASIOChannels];
  188591. bool inputChannelIsFloat [maxASIOChannels];
  188592. bool outputChannelIsFloat [maxASIOChannels];
  188593. bool inputChannelLittleEndian [maxASIOChannels];
  188594. bool outputChannelLittleEndian [maxASIOChannels];
  188595. WaitableEvent event1;
  188596. HeapBlock <float> tempBuffer;
  188597. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  188598. bool isOpen_, isStarted;
  188599. bool volatile isASIOOpen;
  188600. bool volatile calledback;
  188601. bool volatile littleEndian, postOutput, needToReset, isReSync;
  188602. bool volatile insideControlPanelModalLoop;
  188603. bool volatile shouldUsePreferredSize;
  188604. void removeCurrentDriver()
  188605. {
  188606. if (asioObject != 0)
  188607. {
  188608. asioObject->Release();
  188609. asioObject = 0;
  188610. }
  188611. }
  188612. bool loadDriver()
  188613. {
  188614. removeCurrentDriver();
  188615. JUCE_TRY
  188616. {
  188617. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  188618. classId, (void**) &asioObject) == S_OK)
  188619. {
  188620. return true;
  188621. }
  188622. // If a class isn't registered but we have a path for it, we can fallback to
  188623. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  188624. if (optionalDllForDirectLoading.isNotEmpty())
  188625. {
  188626. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  188627. if (h != 0)
  188628. {
  188629. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  188630. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  188631. if (dllGetClassObject != 0)
  188632. {
  188633. IClassFactory* classFactory = 0;
  188634. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  188635. if (classFactory != 0)
  188636. {
  188637. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  188638. classFactory->Release();
  188639. }
  188640. return asioObject != 0;
  188641. }
  188642. }
  188643. }
  188644. }
  188645. JUCE_CATCH_ALL
  188646. asioObject = 0;
  188647. return false;
  188648. }
  188649. const String initDriver()
  188650. {
  188651. if (asioObject != 0)
  188652. {
  188653. char buffer [256];
  188654. zeromem (buffer, sizeof (buffer));
  188655. if (! asioObject->init (windowHandle))
  188656. {
  188657. asioObject->getErrorMessage (buffer);
  188658. return String (buffer, sizeof (buffer) - 1);
  188659. }
  188660. // just in case any daft drivers expect this to be called..
  188661. asioObject->getDriverName (buffer);
  188662. return String::empty;
  188663. }
  188664. return "No Driver";
  188665. }
  188666. const String openDevice()
  188667. {
  188668. // use this in case the driver starts opening dialog boxes..
  188669. Component modalWindow (String::empty);
  188670. modalWindow.setOpaque (true);
  188671. modalWindow.addToDesktop (0);
  188672. modalWindow.enterModalState();
  188673. // open the device and get its info..
  188674. log ("opening ASIO device: " + getName());
  188675. needToReset = false;
  188676. isReSync = false;
  188677. outputChannelNames.clear();
  188678. inputChannelNames.clear();
  188679. bufferSizes.clear();
  188680. sampleRates.clear();
  188681. isASIOOpen = false;
  188682. isOpen_ = false;
  188683. totalNumInputChans = 0;
  188684. totalNumOutputChans = 0;
  188685. numActiveInputChans = 0;
  188686. numActiveOutputChans = 0;
  188687. currentCallback = 0;
  188688. error = String::empty;
  188689. if (getName().isEmpty())
  188690. return error;
  188691. long err = 0;
  188692. if (loadDriver())
  188693. {
  188694. if ((error = initDriver()).isEmpty())
  188695. {
  188696. numActiveInputChans = 0;
  188697. numActiveOutputChans = 0;
  188698. totalNumInputChans = 0;
  188699. totalNumOutputChans = 0;
  188700. if (asioObject != 0
  188701. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  188702. {
  188703. log (String ((int) totalNumInputChans) + " in, " + String ((int) totalNumOutputChans) + " out");
  188704. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188705. {
  188706. // find a list of buffer sizes..
  188707. log (String ((int) minSize) + " " + String ((int) maxSize) + " " + String ((int) preferredSize) + " " + String ((int) granularity));
  188708. if (granularity >= 0)
  188709. {
  188710. granularity = jmax (1, (int) granularity);
  188711. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  188712. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  188713. }
  188714. else if (granularity < 0)
  188715. {
  188716. for (int i = 0; i < 18; ++i)
  188717. {
  188718. const int s = (1 << i);
  188719. if (s >= minSize && s <= maxSize)
  188720. bufferSizes.add (s);
  188721. }
  188722. }
  188723. if (! bufferSizes.contains (preferredSize))
  188724. bufferSizes.insert (0, preferredSize);
  188725. double currentRate = 0;
  188726. asioObject->getSampleRate (&currentRate);
  188727. if (currentRate <= 0.0 || currentRate > 192001.0)
  188728. {
  188729. log ("setting sample rate");
  188730. err = asioObject->setSampleRate (44100.0);
  188731. if (err != 0)
  188732. {
  188733. logError ("setting sample rate", err);
  188734. }
  188735. asioObject->getSampleRate (&currentRate);
  188736. }
  188737. currentSampleRate = currentRate;
  188738. postOutput = (asioObject->outputReady() == 0);
  188739. if (postOutput)
  188740. {
  188741. log ("ASIO outputReady = ok");
  188742. }
  188743. updateSampleRates();
  188744. // ..because cubase does it at this point
  188745. inputLatency = outputLatency = 0;
  188746. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188747. {
  188748. log ("ASIO - no latencies");
  188749. }
  188750. log ("latencies: " + String ((int) inputLatency) + ", " + String ((int) outputLatency));
  188751. // create some dummy buffers now.. because cubase does..
  188752. numActiveInputChans = 0;
  188753. numActiveOutputChans = 0;
  188754. ASIOBufferInfo* info = bufferInfos;
  188755. int i, numChans = 0;
  188756. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  188757. {
  188758. info->isInput = 1;
  188759. info->channelNum = i;
  188760. info->buffers[0] = info->buffers[1] = 0;
  188761. ++info;
  188762. ++numChans;
  188763. }
  188764. const int outputBufferIndex = numChans;
  188765. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  188766. {
  188767. info->isInput = 0;
  188768. info->channelNum = i;
  188769. info->buffers[0] = info->buffers[1] = 0;
  188770. ++info;
  188771. ++numChans;
  188772. }
  188773. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188774. if (currentASIODev[0] == this)
  188775. {
  188776. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188777. callbacks.asioMessage = &asioMessagesCallback0;
  188778. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188779. }
  188780. else if (currentASIODev[1] == this)
  188781. {
  188782. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188783. callbacks.asioMessage = &asioMessagesCallback1;
  188784. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188785. }
  188786. else if (currentASIODev[2] == this)
  188787. {
  188788. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188789. callbacks.asioMessage = &asioMessagesCallback2;
  188790. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188791. }
  188792. else
  188793. {
  188794. jassertfalse
  188795. }
  188796. log ("creating buffers (dummy): " + String (numChans) + ", " + String ((int) preferredSize));
  188797. if (preferredSize > 0)
  188798. {
  188799. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  188800. if (err != 0)
  188801. {
  188802. logError ("dummy buffers", err);
  188803. }
  188804. }
  188805. long newInps = 0, newOuts = 0;
  188806. asioObject->getChannels (&newInps, &newOuts);
  188807. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  188808. {
  188809. totalNumInputChans = newInps;
  188810. totalNumOutputChans = newOuts;
  188811. log (String ((int) totalNumInputChans) + " in; " + String ((int) totalNumOutputChans) + " out");
  188812. }
  188813. updateSampleRates();
  188814. ASIOChannelInfo channelInfo;
  188815. channelInfo.type = 0;
  188816. for (i = 0; i < totalNumInputChans; ++i)
  188817. {
  188818. zerostruct (channelInfo);
  188819. channelInfo.channel = i;
  188820. channelInfo.isInput = 1;
  188821. asioObject->getChannelInfo (&channelInfo);
  188822. inputChannelNames.add (String (channelInfo.name));
  188823. }
  188824. for (i = 0; i < totalNumOutputChans; ++i)
  188825. {
  188826. zerostruct (channelInfo);
  188827. channelInfo.channel = i;
  188828. channelInfo.isInput = 0;
  188829. asioObject->getChannelInfo (&channelInfo);
  188830. outputChannelNames.add (String (channelInfo.name));
  188831. typeToFormatParameters (channelInfo.type,
  188832. outputChannelBitDepths[i],
  188833. outputChannelBytesPerSample[i],
  188834. outputChannelIsFloat[i],
  188835. outputChannelLittleEndian[i]);
  188836. if (i < 2)
  188837. {
  188838. // clear the channels that are used with the dummy stuff
  188839. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  188840. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  188841. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  188842. }
  188843. }
  188844. outputChannelNames.trim();
  188845. inputChannelNames.trim();
  188846. outputChannelNames.appendNumbersToDuplicates (false, true);
  188847. inputChannelNames.appendNumbersToDuplicates (false, true);
  188848. // start and stop because cubase does it..
  188849. asioObject->getLatencies (&inputLatency, &outputLatency);
  188850. if ((err = asioObject->start()) != 0)
  188851. {
  188852. // ignore an error here, as it might start later after setting other stuff up
  188853. logError ("ASIO start", err);
  188854. }
  188855. Thread::sleep (100);
  188856. asioObject->stop();
  188857. }
  188858. else
  188859. {
  188860. error = "Can't detect buffer sizes";
  188861. }
  188862. }
  188863. else
  188864. {
  188865. error = "Can't detect asio channels";
  188866. }
  188867. }
  188868. }
  188869. else
  188870. {
  188871. error = "No such device";
  188872. }
  188873. if (error.isNotEmpty())
  188874. {
  188875. logError (error, err);
  188876. if (asioObject != 0)
  188877. asioObject->disposeBuffers();
  188878. removeCurrentDriver();
  188879. isASIOOpen = false;
  188880. }
  188881. else
  188882. {
  188883. isASIOOpen = true;
  188884. log ("ASIO device open");
  188885. }
  188886. isOpen_ = false;
  188887. needToReset = false;
  188888. isReSync = false;
  188889. return error;
  188890. }
  188891. void callback (const long index) throw()
  188892. {
  188893. if (isStarted)
  188894. {
  188895. bufferIndex = index;
  188896. processBuffer();
  188897. }
  188898. else
  188899. {
  188900. if (postOutput && (asioObject != 0))
  188901. asioObject->outputReady();
  188902. }
  188903. calledback = true;
  188904. }
  188905. void processBuffer() throw()
  188906. {
  188907. const ASIOBufferInfo* const infos = bufferInfos;
  188908. const int bi = bufferIndex;
  188909. const ScopedLock sl (callbackLock);
  188910. if (needToReset)
  188911. {
  188912. needToReset = false;
  188913. if (isReSync)
  188914. {
  188915. log ("! ASIO resync");
  188916. isReSync = false;
  188917. }
  188918. else
  188919. {
  188920. startTimer (20);
  188921. }
  188922. }
  188923. if (bi >= 0)
  188924. {
  188925. const int samps = currentBlockSizeSamples;
  188926. if (currentCallback != 0)
  188927. {
  188928. int i;
  188929. for (i = 0; i < numActiveInputChans; ++i)
  188930. {
  188931. float* const dst = inBuffers[i];
  188932. jassert (dst != 0);
  188933. const char* const src = (const char*) (infos[i].buffers[bi]);
  188934. if (inputChannelIsFloat[i])
  188935. {
  188936. memcpy (dst, src, samps * sizeof (float));
  188937. }
  188938. else
  188939. {
  188940. jassert (dst == tempBuffer + (samps * i));
  188941. switch (inputChannelBitDepths[i])
  188942. {
  188943. case 16:
  188944. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  188945. samps, inputChannelLittleEndian[i]);
  188946. break;
  188947. case 24:
  188948. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  188949. samps, inputChannelLittleEndian[i]);
  188950. break;
  188951. case 32:
  188952. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  188953. samps, inputChannelLittleEndian[i]);
  188954. break;
  188955. case 64:
  188956. jassertfalse
  188957. break;
  188958. }
  188959. }
  188960. }
  188961. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  188962. numActiveInputChans,
  188963. outBuffers,
  188964. numActiveOutputChans,
  188965. samps);
  188966. for (i = 0; i < numActiveOutputChans; ++i)
  188967. {
  188968. float* const src = outBuffers[i];
  188969. jassert (src != 0);
  188970. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  188971. if (outputChannelIsFloat[i])
  188972. {
  188973. memcpy (dst, src, samps * sizeof (float));
  188974. }
  188975. else
  188976. {
  188977. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  188978. switch (outputChannelBitDepths[i])
  188979. {
  188980. case 16:
  188981. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  188982. samps, outputChannelLittleEndian[i]);
  188983. break;
  188984. case 24:
  188985. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  188986. samps, outputChannelLittleEndian[i]);
  188987. break;
  188988. case 32:
  188989. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  188990. samps, outputChannelLittleEndian[i]);
  188991. break;
  188992. case 64:
  188993. jassertfalse
  188994. break;
  188995. }
  188996. }
  188997. }
  188998. }
  188999. else
  189000. {
  189001. for (int i = 0; i < numActiveOutputChans; ++i)
  189002. {
  189003. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189004. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189005. }
  189006. }
  189007. }
  189008. if (postOutput)
  189009. asioObject->outputReady();
  189010. }
  189011. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189012. {
  189013. if (currentASIODev[0] != 0)
  189014. currentASIODev[0]->callback (index);
  189015. return 0;
  189016. }
  189017. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189018. {
  189019. if (currentASIODev[1] != 0)
  189020. currentASIODev[1]->callback (index);
  189021. return 0;
  189022. }
  189023. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189024. {
  189025. if (currentASIODev[2] != 0)
  189026. currentASIODev[2]->callback (index);
  189027. return 0;
  189028. }
  189029. static void bufferSwitchCallback0 (long index, long) throw()
  189030. {
  189031. if (currentASIODev[0] != 0)
  189032. currentASIODev[0]->callback (index);
  189033. }
  189034. static void bufferSwitchCallback1 (long index, long) throw()
  189035. {
  189036. if (currentASIODev[1] != 0)
  189037. currentASIODev[1]->callback (index);
  189038. }
  189039. static void bufferSwitchCallback2 (long index, long) throw()
  189040. {
  189041. if (currentASIODev[2] != 0)
  189042. currentASIODev[2]->callback (index);
  189043. }
  189044. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189045. {
  189046. return asioMessagesCallback (selector, value, 0);
  189047. }
  189048. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189049. {
  189050. return asioMessagesCallback (selector, value, 1);
  189051. }
  189052. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189053. {
  189054. return asioMessagesCallback (selector, value, 2);
  189055. }
  189056. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189057. {
  189058. switch (selector)
  189059. {
  189060. case kAsioSelectorSupported:
  189061. if (value == kAsioResetRequest
  189062. || value == kAsioEngineVersion
  189063. || value == kAsioResyncRequest
  189064. || value == kAsioLatenciesChanged
  189065. || value == kAsioSupportsInputMonitor)
  189066. return 1;
  189067. break;
  189068. case kAsioBufferSizeChange:
  189069. break;
  189070. case kAsioResetRequest:
  189071. if (currentASIODev[deviceIndex] != 0)
  189072. currentASIODev[deviceIndex]->resetRequest();
  189073. return 1;
  189074. case kAsioResyncRequest:
  189075. if (currentASIODev[deviceIndex] != 0)
  189076. currentASIODev[deviceIndex]->resyncRequest();
  189077. return 1;
  189078. case kAsioLatenciesChanged:
  189079. return 1;
  189080. case kAsioEngineVersion:
  189081. return 2;
  189082. case kAsioSupportsTimeInfo:
  189083. case kAsioSupportsTimeCode:
  189084. return 0;
  189085. }
  189086. return 0;
  189087. }
  189088. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189089. {
  189090. }
  189091. static void convertInt16ToFloat (const char* src,
  189092. float* dest,
  189093. const int srcStrideBytes,
  189094. int numSamples,
  189095. const bool littleEndian) throw()
  189096. {
  189097. const double g = 1.0 / 32768.0;
  189098. if (littleEndian)
  189099. {
  189100. while (--numSamples >= 0)
  189101. {
  189102. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189103. src += srcStrideBytes;
  189104. }
  189105. }
  189106. else
  189107. {
  189108. while (--numSamples >= 0)
  189109. {
  189110. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189111. src += srcStrideBytes;
  189112. }
  189113. }
  189114. }
  189115. static void convertFloatToInt16 (const float* src,
  189116. char* dest,
  189117. const int dstStrideBytes,
  189118. int numSamples,
  189119. const bool littleEndian) throw()
  189120. {
  189121. const double maxVal = (double) 0x7fff;
  189122. if (littleEndian)
  189123. {
  189124. while (--numSamples >= 0)
  189125. {
  189126. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189127. dest += dstStrideBytes;
  189128. }
  189129. }
  189130. else
  189131. {
  189132. while (--numSamples >= 0)
  189133. {
  189134. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189135. dest += dstStrideBytes;
  189136. }
  189137. }
  189138. }
  189139. static void convertInt24ToFloat (const char* src,
  189140. float* dest,
  189141. const int srcStrideBytes,
  189142. int numSamples,
  189143. const bool littleEndian) throw()
  189144. {
  189145. const double g = 1.0 / 0x7fffff;
  189146. if (littleEndian)
  189147. {
  189148. while (--numSamples >= 0)
  189149. {
  189150. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189151. src += srcStrideBytes;
  189152. }
  189153. }
  189154. else
  189155. {
  189156. while (--numSamples >= 0)
  189157. {
  189158. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189159. src += srcStrideBytes;
  189160. }
  189161. }
  189162. }
  189163. static void convertFloatToInt24 (const float* src,
  189164. char* dest,
  189165. const int dstStrideBytes,
  189166. int numSamples,
  189167. const bool littleEndian) throw()
  189168. {
  189169. const double maxVal = (double) 0x7fffff;
  189170. if (littleEndian)
  189171. {
  189172. while (--numSamples >= 0)
  189173. {
  189174. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189175. dest += dstStrideBytes;
  189176. }
  189177. }
  189178. else
  189179. {
  189180. while (--numSamples >= 0)
  189181. {
  189182. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189183. dest += dstStrideBytes;
  189184. }
  189185. }
  189186. }
  189187. static void convertInt32ToFloat (const char* src,
  189188. float* dest,
  189189. const int srcStrideBytes,
  189190. int numSamples,
  189191. const bool littleEndian) throw()
  189192. {
  189193. const double g = 1.0 / 0x7fffffff;
  189194. if (littleEndian)
  189195. {
  189196. while (--numSamples >= 0)
  189197. {
  189198. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189199. src += srcStrideBytes;
  189200. }
  189201. }
  189202. else
  189203. {
  189204. while (--numSamples >= 0)
  189205. {
  189206. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189207. src += srcStrideBytes;
  189208. }
  189209. }
  189210. }
  189211. static void convertFloatToInt32 (const float* src,
  189212. char* dest,
  189213. const int dstStrideBytes,
  189214. int numSamples,
  189215. const bool littleEndian) throw()
  189216. {
  189217. const double maxVal = (double) 0x7fffffff;
  189218. if (littleEndian)
  189219. {
  189220. while (--numSamples >= 0)
  189221. {
  189222. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189223. dest += dstStrideBytes;
  189224. }
  189225. }
  189226. else
  189227. {
  189228. while (--numSamples >= 0)
  189229. {
  189230. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189231. dest += dstStrideBytes;
  189232. }
  189233. }
  189234. }
  189235. static void typeToFormatParameters (const long type,
  189236. int& bitDepth,
  189237. int& byteStride,
  189238. bool& formatIsFloat,
  189239. bool& littleEndian) throw()
  189240. {
  189241. bitDepth = 0;
  189242. littleEndian = false;
  189243. formatIsFloat = false;
  189244. switch (type)
  189245. {
  189246. case ASIOSTInt16MSB:
  189247. case ASIOSTInt16LSB:
  189248. case ASIOSTInt32MSB16:
  189249. case ASIOSTInt32LSB16:
  189250. bitDepth = 16; break;
  189251. case ASIOSTFloat32MSB:
  189252. case ASIOSTFloat32LSB:
  189253. formatIsFloat = true;
  189254. bitDepth = 32; break;
  189255. case ASIOSTInt32MSB:
  189256. case ASIOSTInt32LSB:
  189257. bitDepth = 32; break;
  189258. case ASIOSTInt24MSB:
  189259. case ASIOSTInt24LSB:
  189260. case ASIOSTInt32MSB24:
  189261. case ASIOSTInt32LSB24:
  189262. case ASIOSTInt32MSB18:
  189263. case ASIOSTInt32MSB20:
  189264. case ASIOSTInt32LSB18:
  189265. case ASIOSTInt32LSB20:
  189266. bitDepth = 24; break;
  189267. case ASIOSTFloat64MSB:
  189268. case ASIOSTFloat64LSB:
  189269. default:
  189270. bitDepth = 64;
  189271. break;
  189272. }
  189273. switch (type)
  189274. {
  189275. case ASIOSTInt16MSB:
  189276. case ASIOSTInt32MSB16:
  189277. case ASIOSTFloat32MSB:
  189278. case ASIOSTFloat64MSB:
  189279. case ASIOSTInt32MSB:
  189280. case ASIOSTInt32MSB18:
  189281. case ASIOSTInt32MSB20:
  189282. case ASIOSTInt32MSB24:
  189283. case ASIOSTInt24MSB:
  189284. littleEndian = false; break;
  189285. case ASIOSTInt16LSB:
  189286. case ASIOSTInt32LSB16:
  189287. case ASIOSTFloat32LSB:
  189288. case ASIOSTFloat64LSB:
  189289. case ASIOSTInt32LSB:
  189290. case ASIOSTInt32LSB18:
  189291. case ASIOSTInt32LSB20:
  189292. case ASIOSTInt32LSB24:
  189293. case ASIOSTInt24LSB:
  189294. littleEndian = true; break;
  189295. default:
  189296. break;
  189297. }
  189298. switch (type)
  189299. {
  189300. case ASIOSTInt16LSB:
  189301. case ASIOSTInt16MSB:
  189302. byteStride = 2; break;
  189303. case ASIOSTInt24LSB:
  189304. case ASIOSTInt24MSB:
  189305. byteStride = 3; break;
  189306. case ASIOSTInt32MSB16:
  189307. case ASIOSTInt32LSB16:
  189308. case ASIOSTInt32MSB:
  189309. case ASIOSTInt32MSB18:
  189310. case ASIOSTInt32MSB20:
  189311. case ASIOSTInt32MSB24:
  189312. case ASIOSTInt32LSB:
  189313. case ASIOSTInt32LSB18:
  189314. case ASIOSTInt32LSB20:
  189315. case ASIOSTInt32LSB24:
  189316. case ASIOSTFloat32LSB:
  189317. case ASIOSTFloat32MSB:
  189318. byteStride = 4; break;
  189319. case ASIOSTFloat64MSB:
  189320. case ASIOSTFloat64LSB:
  189321. byteStride = 8; break;
  189322. default:
  189323. break;
  189324. }
  189325. }
  189326. };
  189327. class ASIOAudioIODeviceType : public AudioIODeviceType
  189328. {
  189329. public:
  189330. ASIOAudioIODeviceType()
  189331. : AudioIODeviceType ("ASIO"),
  189332. hasScanned (false)
  189333. {
  189334. CoInitialize (0);
  189335. }
  189336. ~ASIOAudioIODeviceType()
  189337. {
  189338. }
  189339. void scanForDevices()
  189340. {
  189341. hasScanned = true;
  189342. deviceNames.clear();
  189343. classIds.clear();
  189344. HKEY hk = 0;
  189345. int index = 0;
  189346. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189347. {
  189348. for (;;)
  189349. {
  189350. char name [256];
  189351. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189352. {
  189353. addDriverInfo (name, hk);
  189354. }
  189355. else
  189356. {
  189357. break;
  189358. }
  189359. }
  189360. RegCloseKey (hk);
  189361. }
  189362. }
  189363. const StringArray getDeviceNames (bool /*wantInputNames*/) const
  189364. {
  189365. jassert (hasScanned); // need to call scanForDevices() before doing this
  189366. return deviceNames;
  189367. }
  189368. int getDefaultDeviceIndex (bool) const
  189369. {
  189370. jassert (hasScanned); // need to call scanForDevices() before doing this
  189371. for (int i = deviceNames.size(); --i >= 0;)
  189372. if (deviceNames[i].containsIgnoreCase ("asio4all"))
  189373. return i; // asio4all is a safe choice for a default..
  189374. #if JUCE_DEBUG
  189375. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase ("digidesign"))
  189376. return 1; // (the digi m-box driver crashes the app when you run
  189377. // it in the debugger, which can be a bit annoying)
  189378. #endif
  189379. return 0;
  189380. }
  189381. static int findFreeSlot()
  189382. {
  189383. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189384. if (currentASIODev[i] == 0)
  189385. return i;
  189386. jassertfalse; // unfortunately you can only have a finite number
  189387. // of ASIO devices open at the same time..
  189388. return -1;
  189389. }
  189390. int getIndexOfDevice (AudioIODevice* d, bool /*asInput*/) const
  189391. {
  189392. jassert (hasScanned); // need to call scanForDevices() before doing this
  189393. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189394. }
  189395. bool hasSeparateInputsAndOutputs() const { return false; }
  189396. AudioIODevice* createDevice (const String& outputDeviceName,
  189397. const String& inputDeviceName)
  189398. {
  189399. // ASIO can't open two different devices for input and output - they must be the same one.
  189400. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189401. jassert (hasScanned); // need to call scanForDevices() before doing this
  189402. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  189403. : inputDeviceName);
  189404. if (index >= 0)
  189405. {
  189406. const int freeSlot = findFreeSlot();
  189407. if (freeSlot >= 0)
  189408. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  189409. }
  189410. return 0;
  189411. }
  189412. juce_UseDebuggingNewOperator
  189413. private:
  189414. StringArray deviceNames;
  189415. OwnedArray <CLSID> classIds;
  189416. bool hasScanned;
  189417. static bool checkClassIsOk (const String& classId)
  189418. {
  189419. HKEY hk = 0;
  189420. bool ok = false;
  189421. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  189422. {
  189423. int index = 0;
  189424. for (;;)
  189425. {
  189426. WCHAR buf [512];
  189427. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  189428. {
  189429. if (classId.equalsIgnoreCase (buf))
  189430. {
  189431. HKEY subKey, pathKey;
  189432. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189433. {
  189434. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  189435. {
  189436. WCHAR pathName [1024];
  189437. DWORD dtype = REG_SZ;
  189438. DWORD dsize = sizeof (pathName);
  189439. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  189440. ok = File (pathName).exists();
  189441. RegCloseKey (pathKey);
  189442. }
  189443. RegCloseKey (subKey);
  189444. }
  189445. break;
  189446. }
  189447. }
  189448. else
  189449. {
  189450. break;
  189451. }
  189452. }
  189453. RegCloseKey (hk);
  189454. }
  189455. return ok;
  189456. }
  189457. void addDriverInfo (const String& keyName, HKEY hk)
  189458. {
  189459. HKEY subKey;
  189460. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  189461. {
  189462. WCHAR buf [256];
  189463. zerostruct (buf);
  189464. DWORD dtype = REG_SZ;
  189465. DWORD dsize = sizeof (buf);
  189466. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189467. {
  189468. if (dsize > 0 && checkClassIsOk (buf))
  189469. {
  189470. CLSID classId;
  189471. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  189472. {
  189473. dtype = REG_SZ;
  189474. dsize = sizeof (buf);
  189475. String deviceName;
  189476. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  189477. deviceName = buf;
  189478. else
  189479. deviceName = keyName;
  189480. log ("found " + deviceName);
  189481. deviceNames.add (deviceName);
  189482. classIds.add (new CLSID (classId));
  189483. }
  189484. }
  189485. RegCloseKey (subKey);
  189486. }
  189487. }
  189488. }
  189489. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  189490. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  189491. };
  189492. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  189493. {
  189494. return new ASIOAudioIODeviceType();
  189495. }
  189496. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  189497. void* guid,
  189498. const String& optionalDllForDirectLoading)
  189499. {
  189500. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  189501. if (freeSlot < 0)
  189502. return 0;
  189503. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  189504. }
  189505. #undef log
  189506. #endif
  189507. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  189508. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  189509. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  189510. // compiled on its own).
  189511. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  189512. END_JUCE_NAMESPACE
  189513. extern "C"
  189514. {
  189515. // Declare just the minimum number of interfaces for the DSound objects that we need..
  189516. typedef struct typeDSBUFFERDESC
  189517. {
  189518. DWORD dwSize;
  189519. DWORD dwFlags;
  189520. DWORD dwBufferBytes;
  189521. DWORD dwReserved;
  189522. LPWAVEFORMATEX lpwfxFormat;
  189523. GUID guid3DAlgorithm;
  189524. } DSBUFFERDESC;
  189525. struct IDirectSoundBuffer;
  189526. #undef INTERFACE
  189527. #define INTERFACE IDirectSound
  189528. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  189529. {
  189530. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189531. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189532. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189533. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  189534. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189535. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  189536. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  189537. STDMETHOD(Compact) (THIS) PURE;
  189538. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  189539. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  189540. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189541. };
  189542. #undef INTERFACE
  189543. #define INTERFACE IDirectSoundBuffer
  189544. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  189545. {
  189546. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189547. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189548. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189549. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189550. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189551. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189552. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  189553. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  189554. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  189555. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189556. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  189557. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189558. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  189559. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  189560. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  189561. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  189562. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  189563. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  189564. STDMETHOD(Stop) (THIS) PURE;
  189565. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189566. STDMETHOD(Restore) (THIS) PURE;
  189567. };
  189568. typedef struct typeDSCBUFFERDESC
  189569. {
  189570. DWORD dwSize;
  189571. DWORD dwFlags;
  189572. DWORD dwBufferBytes;
  189573. DWORD dwReserved;
  189574. LPWAVEFORMATEX lpwfxFormat;
  189575. } DSCBUFFERDESC;
  189576. struct IDirectSoundCaptureBuffer;
  189577. #undef INTERFACE
  189578. #define INTERFACE IDirectSoundCapture
  189579. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  189580. {
  189581. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189582. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189583. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189584. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  189585. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189586. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  189587. };
  189588. #undef INTERFACE
  189589. #define INTERFACE IDirectSoundCaptureBuffer
  189590. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  189591. {
  189592. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  189593. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  189594. STDMETHOD_(ULONG,Release) (THIS) PURE;
  189595. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  189596. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  189597. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  189598. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  189599. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  189600. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  189601. STDMETHOD(Start) (THIS_ DWORD) PURE;
  189602. STDMETHOD(Stop) (THIS) PURE;
  189603. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  189604. };
  189605. };
  189606. BEGIN_JUCE_NAMESPACE
  189607. static const String getDSErrorMessage (HRESULT hr)
  189608. {
  189609. const char* result = 0;
  189610. switch (hr)
  189611. {
  189612. case MAKE_HRESULT(1, 0x878, 10):
  189613. result = "Device already allocated";
  189614. break;
  189615. case MAKE_HRESULT(1, 0x878, 30):
  189616. result = "Control unavailable";
  189617. break;
  189618. case E_INVALIDARG:
  189619. result = "Invalid parameter";
  189620. break;
  189621. case MAKE_HRESULT(1, 0x878, 50):
  189622. result = "Invalid call";
  189623. break;
  189624. case E_FAIL:
  189625. result = "Generic error";
  189626. break;
  189627. case MAKE_HRESULT(1, 0x878, 70):
  189628. result = "Priority level error";
  189629. break;
  189630. case E_OUTOFMEMORY:
  189631. result = "Out of memory";
  189632. break;
  189633. case MAKE_HRESULT(1, 0x878, 100):
  189634. result = "Bad format";
  189635. break;
  189636. case E_NOTIMPL:
  189637. result = "Unsupported function";
  189638. break;
  189639. case MAKE_HRESULT(1, 0x878, 120):
  189640. result = "No driver";
  189641. break;
  189642. case MAKE_HRESULT(1, 0x878, 130):
  189643. result = "Already initialised";
  189644. break;
  189645. case CLASS_E_NOAGGREGATION:
  189646. result = "No aggregation";
  189647. break;
  189648. case MAKE_HRESULT(1, 0x878, 150):
  189649. result = "Buffer lost";
  189650. break;
  189651. case MAKE_HRESULT(1, 0x878, 160):
  189652. result = "Another app has priority";
  189653. break;
  189654. case MAKE_HRESULT(1, 0x878, 170):
  189655. result = "Uninitialised";
  189656. break;
  189657. case E_NOINTERFACE:
  189658. result = "No interface";
  189659. break;
  189660. case S_OK:
  189661. result = "No error";
  189662. break;
  189663. default:
  189664. return "Unknown error: " + String ((int) hr);
  189665. }
  189666. return result;
  189667. }
  189668. #define DS_DEBUGGING 1
  189669. #ifdef DS_DEBUGGING
  189670. #define CATCH JUCE_CATCH_EXCEPTION
  189671. #undef log
  189672. #define log(a) Logger::writeToLog(a);
  189673. #undef logError
  189674. #define logError(a) logDSError(a, __LINE__);
  189675. static void logDSError (HRESULT hr, int lineNum)
  189676. {
  189677. if (hr != S_OK)
  189678. {
  189679. String error ("DS error at line ");
  189680. error << lineNum << " - " << getDSErrorMessage (hr);
  189681. log (error);
  189682. }
  189683. }
  189684. #else
  189685. #define CATCH JUCE_CATCH_ALL
  189686. #define log(a)
  189687. #define logError(a)
  189688. #endif
  189689. #define DSOUND_FUNCTION(functionName, params) \
  189690. typedef HRESULT (WINAPI *type##functionName) params; \
  189691. static type##functionName ds##functionName = 0;
  189692. #define DSOUND_FUNCTION_LOAD(functionName) \
  189693. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  189694. jassert (ds##functionName != 0);
  189695. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  189696. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  189697. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  189698. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  189699. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189700. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  189701. static void initialiseDSoundFunctions()
  189702. {
  189703. if (dsDirectSoundCreate == 0)
  189704. {
  189705. HMODULE h = LoadLibraryA ("dsound.dll");
  189706. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  189707. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  189708. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  189709. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  189710. }
  189711. }
  189712. class DSoundInternalOutChannel
  189713. {
  189714. String name;
  189715. LPGUID guid;
  189716. int sampleRate, bufferSizeSamples;
  189717. float* leftBuffer;
  189718. float* rightBuffer;
  189719. IDirectSound* pDirectSound;
  189720. IDirectSoundBuffer* pOutputBuffer;
  189721. DWORD writeOffset;
  189722. int totalBytesPerBuffer;
  189723. int bytesPerBuffer;
  189724. unsigned int lastPlayCursor;
  189725. public:
  189726. int bitDepth;
  189727. bool doneFlag;
  189728. DSoundInternalOutChannel (const String& name_,
  189729. LPGUID guid_,
  189730. int rate,
  189731. int bufferSize,
  189732. float* left,
  189733. float* right)
  189734. : name (name_),
  189735. guid (guid_),
  189736. sampleRate (rate),
  189737. bufferSizeSamples (bufferSize),
  189738. leftBuffer (left),
  189739. rightBuffer (right),
  189740. pDirectSound (0),
  189741. pOutputBuffer (0),
  189742. bitDepth (16)
  189743. {
  189744. }
  189745. ~DSoundInternalOutChannel()
  189746. {
  189747. close();
  189748. }
  189749. void close()
  189750. {
  189751. HRESULT hr;
  189752. if (pOutputBuffer != 0)
  189753. {
  189754. JUCE_TRY
  189755. {
  189756. log ("closing dsound out: " + name);
  189757. hr = pOutputBuffer->Stop();
  189758. logError (hr);
  189759. }
  189760. CATCH
  189761. JUCE_TRY
  189762. {
  189763. hr = pOutputBuffer->Release();
  189764. logError (hr);
  189765. }
  189766. CATCH
  189767. pOutputBuffer = 0;
  189768. }
  189769. if (pDirectSound != 0)
  189770. {
  189771. JUCE_TRY
  189772. {
  189773. hr = pDirectSound->Release();
  189774. logError (hr);
  189775. }
  189776. CATCH
  189777. pDirectSound = 0;
  189778. }
  189779. }
  189780. const String open()
  189781. {
  189782. log ("opening dsound out device: " + name + " rate=" + String (sampleRate)
  189783. + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  189784. pDirectSound = 0;
  189785. pOutputBuffer = 0;
  189786. writeOffset = 0;
  189787. String error;
  189788. HRESULT hr = E_NOINTERFACE;
  189789. if (dsDirectSoundCreate != 0)
  189790. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  189791. if (hr == S_OK)
  189792. {
  189793. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  189794. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  189795. const int numChannels = 2;
  189796. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  189797. logError (hr);
  189798. if (hr == S_OK)
  189799. {
  189800. IDirectSoundBuffer* pPrimaryBuffer;
  189801. DSBUFFERDESC primaryDesc;
  189802. zerostruct (primaryDesc);
  189803. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189804. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  189805. primaryDesc.dwBufferBytes = 0;
  189806. primaryDesc.lpwfxFormat = 0;
  189807. log ("opening dsound out step 2");
  189808. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  189809. logError (hr);
  189810. if (hr == S_OK)
  189811. {
  189812. WAVEFORMATEX wfFormat;
  189813. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  189814. wfFormat.nChannels = (unsigned short) numChannels;
  189815. wfFormat.nSamplesPerSec = sampleRate;
  189816. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  189817. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  189818. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  189819. wfFormat.cbSize = 0;
  189820. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  189821. logError (hr);
  189822. if (hr == S_OK)
  189823. {
  189824. DSBUFFERDESC secondaryDesc;
  189825. zerostruct (secondaryDesc);
  189826. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  189827. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  189828. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  189829. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  189830. secondaryDesc.lpwfxFormat = &wfFormat;
  189831. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  189832. logError (hr);
  189833. if (hr == S_OK)
  189834. {
  189835. log ("opening dsound out step 3");
  189836. DWORD dwDataLen;
  189837. unsigned char* pDSBuffData;
  189838. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  189839. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  189840. logError (hr);
  189841. if (hr == S_OK)
  189842. {
  189843. zeromem (pDSBuffData, dwDataLen);
  189844. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  189845. if (hr == S_OK)
  189846. {
  189847. hr = pOutputBuffer->SetCurrentPosition (0);
  189848. if (hr == S_OK)
  189849. {
  189850. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  189851. if (hr == S_OK)
  189852. return String::empty;
  189853. }
  189854. }
  189855. }
  189856. }
  189857. }
  189858. }
  189859. }
  189860. }
  189861. error = getDSErrorMessage (hr);
  189862. close();
  189863. return error;
  189864. }
  189865. void synchronisePosition()
  189866. {
  189867. if (pOutputBuffer != 0)
  189868. {
  189869. DWORD playCursor;
  189870. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  189871. }
  189872. }
  189873. bool service()
  189874. {
  189875. if (pOutputBuffer == 0)
  189876. return true;
  189877. DWORD playCursor, writeCursor;
  189878. for (;;)
  189879. {
  189880. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  189881. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189882. {
  189883. pOutputBuffer->Restore();
  189884. continue;
  189885. }
  189886. if (hr == S_OK)
  189887. break;
  189888. logError (hr);
  189889. jassertfalse
  189890. return true;
  189891. }
  189892. int playWriteGap = writeCursor - playCursor;
  189893. if (playWriteGap < 0)
  189894. playWriteGap += totalBytesPerBuffer;
  189895. int bytesEmpty = playCursor - writeOffset;
  189896. if (bytesEmpty < 0)
  189897. bytesEmpty += totalBytesPerBuffer;
  189898. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  189899. {
  189900. writeOffset = writeCursor;
  189901. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  189902. }
  189903. if (bytesEmpty >= bytesPerBuffer)
  189904. {
  189905. LPBYTE lpbuf1 = 0;
  189906. LPBYTE lpbuf2 = 0;
  189907. DWORD dwSize1 = 0;
  189908. DWORD dwSize2 = 0;
  189909. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  189910. bytesPerBuffer,
  189911. (void**) &lpbuf1, &dwSize1,
  189912. (void**) &lpbuf2, &dwSize2, 0);
  189913. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  189914. {
  189915. pOutputBuffer->Restore();
  189916. hr = pOutputBuffer->Lock (writeOffset,
  189917. bytesPerBuffer,
  189918. (void**) &lpbuf1, &dwSize1,
  189919. (void**) &lpbuf2, &dwSize2, 0);
  189920. }
  189921. if (hr == S_OK)
  189922. {
  189923. if (bitDepth == 16)
  189924. {
  189925. const float gainL = 32767.0f;
  189926. const float gainR = 32767.0f;
  189927. int* dest = (int*)lpbuf1;
  189928. const float* left = leftBuffer;
  189929. const float* right = rightBuffer;
  189930. int samples1 = dwSize1 >> 2;
  189931. int samples2 = dwSize2 >> 2;
  189932. if (left == 0)
  189933. {
  189934. while (--samples1 >= 0)
  189935. {
  189936. int r = roundToInt (gainR * *right++);
  189937. if (r < -32768)
  189938. r = -32768;
  189939. else if (r > 32767)
  189940. r = 32767;
  189941. *dest++ = (r << 16);
  189942. }
  189943. dest = (int*)lpbuf2;
  189944. while (--samples2 >= 0)
  189945. {
  189946. int r = roundToInt (gainR * *right++);
  189947. if (r < -32768)
  189948. r = -32768;
  189949. else if (r > 32767)
  189950. r = 32767;
  189951. *dest++ = (r << 16);
  189952. }
  189953. }
  189954. else if (right == 0)
  189955. {
  189956. while (--samples1 >= 0)
  189957. {
  189958. int l = roundToInt (gainL * *left++);
  189959. if (l < -32768)
  189960. l = -32768;
  189961. else if (l > 32767)
  189962. l = 32767;
  189963. l &= 0xffff;
  189964. *dest++ = l;
  189965. }
  189966. dest = (int*)lpbuf2;
  189967. while (--samples2 >= 0)
  189968. {
  189969. int l = roundToInt (gainL * *left++);
  189970. if (l < -32768)
  189971. l = -32768;
  189972. else if (l > 32767)
  189973. l = 32767;
  189974. l &= 0xffff;
  189975. *dest++ = l;
  189976. }
  189977. }
  189978. else
  189979. {
  189980. while (--samples1 >= 0)
  189981. {
  189982. int l = roundToInt (gainL * *left++);
  189983. if (l < -32768)
  189984. l = -32768;
  189985. else if (l > 32767)
  189986. l = 32767;
  189987. l &= 0xffff;
  189988. int r = roundToInt (gainR * *right++);
  189989. if (r < -32768)
  189990. r = -32768;
  189991. else if (r > 32767)
  189992. r = 32767;
  189993. *dest++ = (r << 16) | l;
  189994. }
  189995. dest = (int*)lpbuf2;
  189996. while (--samples2 >= 0)
  189997. {
  189998. int l = roundToInt (gainL * *left++);
  189999. if (l < -32768)
  190000. l = -32768;
  190001. else if (l > 32767)
  190002. l = 32767;
  190003. l &= 0xffff;
  190004. int r = roundToInt (gainR * *right++);
  190005. if (r < -32768)
  190006. r = -32768;
  190007. else if (r > 32767)
  190008. r = 32767;
  190009. *dest++ = (r << 16) | l;
  190010. }
  190011. }
  190012. }
  190013. else
  190014. {
  190015. jassertfalse
  190016. }
  190017. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190018. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190019. }
  190020. else
  190021. {
  190022. jassertfalse
  190023. logError (hr);
  190024. }
  190025. bytesEmpty -= bytesPerBuffer;
  190026. return true;
  190027. }
  190028. else
  190029. {
  190030. return false;
  190031. }
  190032. }
  190033. };
  190034. struct DSoundInternalInChannel
  190035. {
  190036. String name;
  190037. LPGUID guid;
  190038. int sampleRate, bufferSizeSamples;
  190039. float* leftBuffer;
  190040. float* rightBuffer;
  190041. IDirectSound* pDirectSound;
  190042. IDirectSoundCapture* pDirectSoundCapture;
  190043. IDirectSoundCaptureBuffer* pInputBuffer;
  190044. public:
  190045. unsigned int readOffset;
  190046. int bytesPerBuffer, totalBytesPerBuffer;
  190047. int bitDepth;
  190048. bool doneFlag;
  190049. DSoundInternalInChannel (const String& name_,
  190050. LPGUID guid_,
  190051. int rate,
  190052. int bufferSize,
  190053. float* left,
  190054. float* right)
  190055. : name (name_),
  190056. guid (guid_),
  190057. sampleRate (rate),
  190058. bufferSizeSamples (bufferSize),
  190059. leftBuffer (left),
  190060. rightBuffer (right),
  190061. pDirectSound (0),
  190062. pDirectSoundCapture (0),
  190063. pInputBuffer (0),
  190064. bitDepth (16)
  190065. {
  190066. }
  190067. ~DSoundInternalInChannel()
  190068. {
  190069. close();
  190070. }
  190071. void close()
  190072. {
  190073. HRESULT hr;
  190074. if (pInputBuffer != 0)
  190075. {
  190076. JUCE_TRY
  190077. {
  190078. log ("closing dsound in: " + name);
  190079. hr = pInputBuffer->Stop();
  190080. logError (hr);
  190081. }
  190082. CATCH
  190083. JUCE_TRY
  190084. {
  190085. hr = pInputBuffer->Release();
  190086. logError (hr);
  190087. }
  190088. CATCH
  190089. pInputBuffer = 0;
  190090. }
  190091. if (pDirectSoundCapture != 0)
  190092. {
  190093. JUCE_TRY
  190094. {
  190095. hr = pDirectSoundCapture->Release();
  190096. logError (hr);
  190097. }
  190098. CATCH
  190099. pDirectSoundCapture = 0;
  190100. }
  190101. if (pDirectSound != 0)
  190102. {
  190103. JUCE_TRY
  190104. {
  190105. hr = pDirectSound->Release();
  190106. logError (hr);
  190107. }
  190108. CATCH
  190109. pDirectSound = 0;
  190110. }
  190111. }
  190112. const String open()
  190113. {
  190114. log ("opening dsound in device: " + name
  190115. + " rate=" + String (sampleRate) + " bits=" + String (bitDepth) + " buf=" + String (bufferSizeSamples));
  190116. pDirectSound = 0;
  190117. pDirectSoundCapture = 0;
  190118. pInputBuffer = 0;
  190119. readOffset = 0;
  190120. totalBytesPerBuffer = 0;
  190121. String error;
  190122. HRESULT hr = E_NOINTERFACE;
  190123. if (dsDirectSoundCaptureCreate != 0)
  190124. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190125. logError (hr);
  190126. if (hr == S_OK)
  190127. {
  190128. const int numChannels = 2;
  190129. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190130. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190131. WAVEFORMATEX wfFormat;
  190132. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190133. wfFormat.nChannels = (unsigned short)numChannels;
  190134. wfFormat.nSamplesPerSec = sampleRate;
  190135. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190136. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190137. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190138. wfFormat.cbSize = 0;
  190139. DSCBUFFERDESC captureDesc;
  190140. zerostruct (captureDesc);
  190141. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190142. captureDesc.dwFlags = 0;
  190143. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190144. captureDesc.lpwfxFormat = &wfFormat;
  190145. log ("opening dsound in step 2");
  190146. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190147. logError (hr);
  190148. if (hr == S_OK)
  190149. {
  190150. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190151. logError (hr);
  190152. if (hr == S_OK)
  190153. return String::empty;
  190154. }
  190155. }
  190156. error = getDSErrorMessage (hr);
  190157. close();
  190158. return error;
  190159. }
  190160. void synchronisePosition()
  190161. {
  190162. if (pInputBuffer != 0)
  190163. {
  190164. DWORD capturePos;
  190165. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190166. }
  190167. }
  190168. bool service()
  190169. {
  190170. if (pInputBuffer == 0)
  190171. return true;
  190172. DWORD capturePos, readPos;
  190173. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190174. logError (hr);
  190175. if (hr != S_OK)
  190176. return true;
  190177. int bytesFilled = readPos - readOffset;
  190178. if (bytesFilled < 0)
  190179. bytesFilled += totalBytesPerBuffer;
  190180. if (bytesFilled >= bytesPerBuffer)
  190181. {
  190182. LPBYTE lpbuf1 = 0;
  190183. LPBYTE lpbuf2 = 0;
  190184. DWORD dwsize1 = 0;
  190185. DWORD dwsize2 = 0;
  190186. HRESULT hr = pInputBuffer->Lock (readOffset,
  190187. bytesPerBuffer,
  190188. (void**) &lpbuf1, &dwsize1,
  190189. (void**) &lpbuf2, &dwsize2, 0);
  190190. if (hr == S_OK)
  190191. {
  190192. if (bitDepth == 16)
  190193. {
  190194. const float g = 1.0f / 32768.0f;
  190195. float* destL = leftBuffer;
  190196. float* destR = rightBuffer;
  190197. int samples1 = dwsize1 >> 2;
  190198. int samples2 = dwsize2 >> 2;
  190199. const short* src = (const short*)lpbuf1;
  190200. if (destL == 0)
  190201. {
  190202. while (--samples1 >= 0)
  190203. {
  190204. ++src;
  190205. *destR++ = *src++ * g;
  190206. }
  190207. src = (const short*)lpbuf2;
  190208. while (--samples2 >= 0)
  190209. {
  190210. ++src;
  190211. *destR++ = *src++ * g;
  190212. }
  190213. }
  190214. else if (destR == 0)
  190215. {
  190216. while (--samples1 >= 0)
  190217. {
  190218. *destL++ = *src++ * g;
  190219. ++src;
  190220. }
  190221. src = (const short*)lpbuf2;
  190222. while (--samples2 >= 0)
  190223. {
  190224. *destL++ = *src++ * g;
  190225. ++src;
  190226. }
  190227. }
  190228. else
  190229. {
  190230. while (--samples1 >= 0)
  190231. {
  190232. *destL++ = *src++ * g;
  190233. *destR++ = *src++ * g;
  190234. }
  190235. src = (const short*)lpbuf2;
  190236. while (--samples2 >= 0)
  190237. {
  190238. *destL++ = *src++ * g;
  190239. *destR++ = *src++ * g;
  190240. }
  190241. }
  190242. }
  190243. else
  190244. {
  190245. jassertfalse
  190246. }
  190247. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190248. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190249. }
  190250. else
  190251. {
  190252. logError (hr);
  190253. jassertfalse
  190254. }
  190255. bytesFilled -= bytesPerBuffer;
  190256. return true;
  190257. }
  190258. else
  190259. {
  190260. return false;
  190261. }
  190262. }
  190263. };
  190264. class DSoundAudioIODevice : public AudioIODevice,
  190265. public Thread
  190266. {
  190267. public:
  190268. DSoundAudioIODevice (const String& deviceName,
  190269. const int outputDeviceIndex_,
  190270. const int inputDeviceIndex_)
  190271. : AudioIODevice (deviceName, "DirectSound"),
  190272. Thread ("Juce DSound"),
  190273. isOpen_ (false),
  190274. isStarted (false),
  190275. outputDeviceIndex (outputDeviceIndex_),
  190276. inputDeviceIndex (inputDeviceIndex_),
  190277. numInputBuffers (0),
  190278. numOutputBuffers (0),
  190279. totalSamplesOut (0),
  190280. sampleRate (0.0),
  190281. inputBuffers (0),
  190282. outputBuffers (0),
  190283. callback (0),
  190284. bufferSizeSamples (0)
  190285. {
  190286. if (outputDeviceIndex_ >= 0)
  190287. {
  190288. outChannels.add (TRANS("Left"));
  190289. outChannels.add (TRANS("Right"));
  190290. }
  190291. if (inputDeviceIndex_ >= 0)
  190292. {
  190293. inChannels.add (TRANS("Left"));
  190294. inChannels.add (TRANS("Right"));
  190295. }
  190296. }
  190297. ~DSoundAudioIODevice()
  190298. {
  190299. close();
  190300. }
  190301. const StringArray getOutputChannelNames()
  190302. {
  190303. return outChannels;
  190304. }
  190305. const StringArray getInputChannelNames()
  190306. {
  190307. return inChannels;
  190308. }
  190309. int getNumSampleRates()
  190310. {
  190311. return 4;
  190312. }
  190313. double getSampleRate (int index)
  190314. {
  190315. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190316. return samps [jlimit (0, 3, index)];
  190317. }
  190318. int getNumBufferSizesAvailable()
  190319. {
  190320. return 50;
  190321. }
  190322. int getBufferSizeSamples (int index)
  190323. {
  190324. int n = 64;
  190325. for (int i = 0; i < index; ++i)
  190326. n += (n < 512) ? 32
  190327. : ((n < 1024) ? 64
  190328. : ((n < 2048) ? 128 : 256));
  190329. return n;
  190330. }
  190331. int getDefaultBufferSize()
  190332. {
  190333. return 2560;
  190334. }
  190335. const String open (const BigInteger& inputChannels,
  190336. const BigInteger& outputChannels,
  190337. double sampleRate,
  190338. int bufferSizeSamples)
  190339. {
  190340. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190341. isOpen_ = lastError.isEmpty();
  190342. return lastError;
  190343. }
  190344. void close()
  190345. {
  190346. stop();
  190347. if (isOpen_)
  190348. {
  190349. closeDevice();
  190350. isOpen_ = false;
  190351. }
  190352. }
  190353. bool isOpen()
  190354. {
  190355. return isOpen_ && isThreadRunning();
  190356. }
  190357. int getCurrentBufferSizeSamples()
  190358. {
  190359. return bufferSizeSamples;
  190360. }
  190361. double getCurrentSampleRate()
  190362. {
  190363. return sampleRate;
  190364. }
  190365. int getCurrentBitDepth()
  190366. {
  190367. int i, bits = 256;
  190368. for (i = inChans.size(); --i >= 0;)
  190369. bits = jmin (bits, inChans[i]->bitDepth);
  190370. for (i = outChans.size(); --i >= 0;)
  190371. bits = jmin (bits, outChans[i]->bitDepth);
  190372. if (bits > 32)
  190373. bits = 16;
  190374. return bits;
  190375. }
  190376. const BigInteger getActiveOutputChannels() const
  190377. {
  190378. return enabledOutputs;
  190379. }
  190380. const BigInteger getActiveInputChannels() const
  190381. {
  190382. return enabledInputs;
  190383. }
  190384. int getOutputLatencyInSamples()
  190385. {
  190386. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190387. }
  190388. int getInputLatencyInSamples()
  190389. {
  190390. return getOutputLatencyInSamples();
  190391. }
  190392. void start (AudioIODeviceCallback* call)
  190393. {
  190394. if (isOpen_ && call != 0 && ! isStarted)
  190395. {
  190396. if (! isThreadRunning())
  190397. {
  190398. // something gone wrong and the thread's stopped..
  190399. isOpen_ = false;
  190400. return;
  190401. }
  190402. call->audioDeviceAboutToStart (this);
  190403. const ScopedLock sl (startStopLock);
  190404. callback = call;
  190405. isStarted = true;
  190406. }
  190407. }
  190408. void stop()
  190409. {
  190410. if (isStarted)
  190411. {
  190412. AudioIODeviceCallback* const callbackLocal = callback;
  190413. {
  190414. const ScopedLock sl (startStopLock);
  190415. isStarted = false;
  190416. }
  190417. if (callbackLocal != 0)
  190418. callbackLocal->audioDeviceStopped();
  190419. }
  190420. }
  190421. bool isPlaying()
  190422. {
  190423. return isStarted && isOpen_ && isThreadRunning();
  190424. }
  190425. const String getLastError()
  190426. {
  190427. return lastError;
  190428. }
  190429. juce_UseDebuggingNewOperator
  190430. StringArray inChannels, outChannels;
  190431. int outputDeviceIndex, inputDeviceIndex;
  190432. private:
  190433. bool isOpen_;
  190434. bool isStarted;
  190435. String lastError;
  190436. OwnedArray <DSoundInternalInChannel> inChans;
  190437. OwnedArray <DSoundInternalOutChannel> outChans;
  190438. WaitableEvent startEvent;
  190439. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  190440. int volatile totalSamplesOut;
  190441. int64 volatile lastBlockTime;
  190442. double sampleRate;
  190443. BigInteger enabledInputs, enabledOutputs;
  190444. HeapBlock <float*> inputBuffers, outputBuffers;
  190445. AudioIODeviceCallback* callback;
  190446. CriticalSection startStopLock;
  190447. DSoundAudioIODevice (const DSoundAudioIODevice&);
  190448. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  190449. const String openDevice (const BigInteger& inputChannels,
  190450. const BigInteger& outputChannels,
  190451. double sampleRate_,
  190452. int bufferSizeSamples_);
  190453. void closeDevice()
  190454. {
  190455. isStarted = false;
  190456. stopThread (5000);
  190457. inChans.clear();
  190458. outChans.clear();
  190459. int i;
  190460. for (i = 0; i < numInputBuffers; ++i)
  190461. juce_free (inputBuffers[i]);
  190462. inputBuffers.free();
  190463. numInputBuffers = 0;
  190464. for (i = 0; i < numOutputBuffers; ++i)
  190465. juce_free (outputBuffers[i]);
  190466. outputBuffers.free();
  190467. numOutputBuffers = 0;
  190468. }
  190469. void resync()
  190470. {
  190471. if (! threadShouldExit())
  190472. {
  190473. sleep (5);
  190474. int i;
  190475. for (i = 0; i < outChans.size(); ++i)
  190476. outChans.getUnchecked(i)->synchronisePosition();
  190477. for (i = 0; i < inChans.size(); ++i)
  190478. inChans.getUnchecked(i)->synchronisePosition();
  190479. }
  190480. }
  190481. public:
  190482. void run()
  190483. {
  190484. while (! threadShouldExit())
  190485. {
  190486. if (wait (100))
  190487. break;
  190488. }
  190489. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  190490. const int maxTimeMS = jmax (5, 3 * latencyMs);
  190491. while (! threadShouldExit())
  190492. {
  190493. int numToDo = 0;
  190494. uint32 startTime = Time::getMillisecondCounter();
  190495. int i;
  190496. for (i = inChans.size(); --i >= 0;)
  190497. {
  190498. inChans.getUnchecked(i)->doneFlag = false;
  190499. ++numToDo;
  190500. }
  190501. for (i = outChans.size(); --i >= 0;)
  190502. {
  190503. outChans.getUnchecked(i)->doneFlag = false;
  190504. ++numToDo;
  190505. }
  190506. if (numToDo > 0)
  190507. {
  190508. const int maxCount = 3;
  190509. int count = maxCount;
  190510. for (;;)
  190511. {
  190512. for (i = inChans.size(); --i >= 0;)
  190513. {
  190514. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  190515. if ((! in->doneFlag) && in->service())
  190516. {
  190517. in->doneFlag = true;
  190518. --numToDo;
  190519. }
  190520. }
  190521. for (i = outChans.size(); --i >= 0;)
  190522. {
  190523. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  190524. if ((! out->doneFlag) && out->service())
  190525. {
  190526. out->doneFlag = true;
  190527. --numToDo;
  190528. }
  190529. }
  190530. if (numToDo <= 0)
  190531. break;
  190532. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  190533. {
  190534. resync();
  190535. break;
  190536. }
  190537. if (--count <= 0)
  190538. {
  190539. Sleep (1);
  190540. count = maxCount;
  190541. }
  190542. if (threadShouldExit())
  190543. return;
  190544. }
  190545. }
  190546. else
  190547. {
  190548. sleep (1);
  190549. }
  190550. const ScopedLock sl (startStopLock);
  190551. if (isStarted)
  190552. {
  190553. JUCE_TRY
  190554. {
  190555. callback->audioDeviceIOCallback (const_cast <const float**> (inputBuffers.getData()),
  190556. numInputBuffers,
  190557. outputBuffers,
  190558. numOutputBuffers,
  190559. bufferSizeSamples);
  190560. }
  190561. JUCE_CATCH_EXCEPTION
  190562. totalSamplesOut += bufferSizeSamples;
  190563. }
  190564. else
  190565. {
  190566. for (i = 0; i < numOutputBuffers; ++i)
  190567. if (outputBuffers[i] != 0)
  190568. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  190569. totalSamplesOut = 0;
  190570. sleep (1);
  190571. }
  190572. }
  190573. }
  190574. };
  190575. class DSoundAudioIODeviceType : public AudioIODeviceType
  190576. {
  190577. public:
  190578. DSoundAudioIODeviceType()
  190579. : AudioIODeviceType ("DirectSound"),
  190580. hasScanned (false)
  190581. {
  190582. initialiseDSoundFunctions();
  190583. }
  190584. ~DSoundAudioIODeviceType()
  190585. {
  190586. }
  190587. void scanForDevices()
  190588. {
  190589. hasScanned = true;
  190590. outputDeviceNames.clear();
  190591. outputGuids.clear();
  190592. inputDeviceNames.clear();
  190593. inputGuids.clear();
  190594. if (dsDirectSoundEnumerateW != 0)
  190595. {
  190596. dsDirectSoundEnumerateW (outputEnumProcW, this);
  190597. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  190598. }
  190599. }
  190600. const StringArray getDeviceNames (bool wantInputNames) const
  190601. {
  190602. jassert (hasScanned); // need to call scanForDevices() before doing this
  190603. return wantInputNames ? inputDeviceNames
  190604. : outputDeviceNames;
  190605. }
  190606. int getDefaultDeviceIndex (bool /*forInput*/) const
  190607. {
  190608. jassert (hasScanned); // need to call scanForDevices() before doing this
  190609. return 0;
  190610. }
  190611. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  190612. {
  190613. jassert (hasScanned); // need to call scanForDevices() before doing this
  190614. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  190615. if (d == 0)
  190616. return -1;
  190617. return asInput ? d->inputDeviceIndex
  190618. : d->outputDeviceIndex;
  190619. }
  190620. bool hasSeparateInputsAndOutputs() const { return true; }
  190621. AudioIODevice* createDevice (const String& outputDeviceName,
  190622. const String& inputDeviceName)
  190623. {
  190624. jassert (hasScanned); // need to call scanForDevices() before doing this
  190625. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  190626. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  190627. if (outputIndex >= 0 || inputIndex >= 0)
  190628. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  190629. : inputDeviceName,
  190630. outputIndex, inputIndex);
  190631. return 0;
  190632. }
  190633. juce_UseDebuggingNewOperator
  190634. StringArray outputDeviceNames;
  190635. OwnedArray <GUID> outputGuids;
  190636. StringArray inputDeviceNames;
  190637. OwnedArray <GUID> inputGuids;
  190638. private:
  190639. bool hasScanned;
  190640. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  190641. {
  190642. desc = desc.trim();
  190643. if (desc.isNotEmpty())
  190644. {
  190645. const String origDesc (desc);
  190646. int n = 2;
  190647. while (outputDeviceNames.contains (desc))
  190648. desc = origDesc + " (" + String (n++) + ")";
  190649. outputDeviceNames.add (desc);
  190650. if (lpGUID != 0)
  190651. outputGuids.add (new GUID (*lpGUID));
  190652. else
  190653. outputGuids.add (0);
  190654. }
  190655. return TRUE;
  190656. }
  190657. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190658. {
  190659. return ((DSoundAudioIODeviceType*) object)
  190660. ->outputEnumProc (lpGUID, String (description));
  190661. }
  190662. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190663. {
  190664. return ((DSoundAudioIODeviceType*) object)
  190665. ->outputEnumProc (lpGUID, String (description));
  190666. }
  190667. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  190668. {
  190669. desc = desc.trim();
  190670. if (desc.isNotEmpty())
  190671. {
  190672. const String origDesc (desc);
  190673. int n = 2;
  190674. while (inputDeviceNames.contains (desc))
  190675. desc = origDesc + " (" + String (n++) + ")";
  190676. inputDeviceNames.add (desc);
  190677. if (lpGUID != 0)
  190678. inputGuids.add (new GUID (*lpGUID));
  190679. else
  190680. inputGuids.add (0);
  190681. }
  190682. return TRUE;
  190683. }
  190684. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  190685. {
  190686. return ((DSoundAudioIODeviceType*) object)
  190687. ->inputEnumProc (lpGUID, String (description));
  190688. }
  190689. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  190690. {
  190691. return ((DSoundAudioIODeviceType*) object)
  190692. ->inputEnumProc (lpGUID, String (description));
  190693. }
  190694. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  190695. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  190696. };
  190697. const String DSoundAudioIODevice::openDevice (const BigInteger& inputChannels,
  190698. const BigInteger& outputChannels,
  190699. double sampleRate_,
  190700. int bufferSizeSamples_)
  190701. {
  190702. closeDevice();
  190703. totalSamplesOut = 0;
  190704. sampleRate = sampleRate_;
  190705. if (bufferSizeSamples_ <= 0)
  190706. bufferSizeSamples_ = 960; // use as a default size if none is set.
  190707. bufferSizeSamples = bufferSizeSamples_ & ~7;
  190708. DSoundAudioIODeviceType dlh;
  190709. dlh.scanForDevices();
  190710. enabledInputs = inputChannels;
  190711. enabledInputs.setRange (inChannels.size(),
  190712. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  190713. false);
  190714. numInputBuffers = enabledInputs.countNumberOfSetBits();
  190715. inputBuffers.calloc (numInputBuffers + 2);
  190716. int i, numIns = 0;
  190717. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  190718. {
  190719. float* left = 0;
  190720. float* right = 0;
  190721. if (enabledInputs[i])
  190722. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190723. if (enabledInputs[i + 1])
  190724. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190725. if (left != 0 || right != 0)
  190726. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  190727. dlh.inputGuids [inputDeviceIndex],
  190728. (int) sampleRate, bufferSizeSamples,
  190729. left, right));
  190730. }
  190731. enabledOutputs = outputChannels;
  190732. enabledOutputs.setRange (outChannels.size(),
  190733. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  190734. false);
  190735. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  190736. outputBuffers.calloc (numOutputBuffers + 2);
  190737. int numOuts = 0;
  190738. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  190739. {
  190740. float* left = 0;
  190741. float* right = 0;
  190742. if (enabledOutputs[i])
  190743. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190744. if (enabledOutputs[i + 1])
  190745. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  190746. if (left != 0 || right != 0)
  190747. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  190748. dlh.outputGuids [outputDeviceIndex],
  190749. (int) sampleRate, bufferSizeSamples,
  190750. left, right));
  190751. }
  190752. String error;
  190753. // boost our priority while opening the devices to try to get better sync between them
  190754. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  190755. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  190756. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  190757. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  190758. for (i = 0; i < outChans.size(); ++i)
  190759. {
  190760. error = outChans[i]->open();
  190761. if (error.isNotEmpty())
  190762. {
  190763. error = "Error opening " + dlh.outputDeviceNames[i] + ": \"" + error + "\"";
  190764. break;
  190765. }
  190766. }
  190767. if (error.isEmpty())
  190768. {
  190769. for (i = 0; i < inChans.size(); ++i)
  190770. {
  190771. error = inChans[i]->open();
  190772. if (error.isNotEmpty())
  190773. {
  190774. error = "Error opening " + dlh.inputDeviceNames[i] + ": \"" + error + "\"";
  190775. break;
  190776. }
  190777. }
  190778. }
  190779. if (error.isEmpty())
  190780. {
  190781. totalSamplesOut = 0;
  190782. for (i = 0; i < outChans.size(); ++i)
  190783. outChans.getUnchecked(i)->synchronisePosition();
  190784. for (i = 0; i < inChans.size(); ++i)
  190785. inChans.getUnchecked(i)->synchronisePosition();
  190786. startThread (9);
  190787. sleep (10);
  190788. notify();
  190789. }
  190790. else
  190791. {
  190792. log (error);
  190793. }
  190794. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  190795. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  190796. return error;
  190797. }
  190798. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  190799. {
  190800. return new DSoundAudioIODeviceType();
  190801. }
  190802. #undef log
  190803. #endif
  190804. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  190805. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  190806. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190807. // compiled on its own).
  190808. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  190809. #if 1
  190810. const String getAudioErrorDesc (HRESULT hr)
  190811. {
  190812. const char* e = 0;
  190813. switch (hr)
  190814. {
  190815. case E_POINTER: e = "E_POINTER"; break;
  190816. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  190817. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  190818. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  190819. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  190820. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  190821. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  190822. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  190823. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  190824. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  190825. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  190826. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  190827. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  190828. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  190829. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  190830. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  190831. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  190832. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  190833. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  190834. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  190835. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  190836. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  190837. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  190838. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  190839. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  190840. default: return String::toHexString ((int) hr);
  190841. }
  190842. return e;
  190843. }
  190844. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  190845. #define OK(a) wasapi_checkResult(a)
  190846. static bool wasapi_checkResult (HRESULT hr)
  190847. {
  190848. logFailure (hr);
  190849. return SUCCEEDED (hr);
  190850. }
  190851. #else
  190852. #define logFailure(hr) {}
  190853. #define OK(a) SUCCEEDED(a)
  190854. #endif
  190855. static const String wasapi_getDeviceID (IMMDevice* const device)
  190856. {
  190857. String s;
  190858. WCHAR* deviceId = 0;
  190859. if (OK (device->GetId (&deviceId)))
  190860. {
  190861. s = String (deviceId);
  190862. CoTaskMemFree (deviceId);
  190863. }
  190864. return s;
  190865. }
  190866. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  190867. {
  190868. EDataFlow flow = eRender;
  190869. ComSmartPtr <IMMEndpoint> endPoint;
  190870. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  190871. (void) OK (endPoint->GetDataFlow (&flow));
  190872. return flow;
  190873. }
  190874. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  190875. {
  190876. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  190877. }
  190878. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  190879. {
  190880. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  190881. : sizeof (WAVEFORMATEX));
  190882. }
  190883. class WASAPIDeviceBase
  190884. {
  190885. public:
  190886. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  190887. : device (device_),
  190888. sampleRate (0),
  190889. numChannels (0),
  190890. actualNumChannels (0),
  190891. defaultSampleRate (0),
  190892. minBufferSize (0),
  190893. defaultBufferSize (0),
  190894. latencySamples (0),
  190895. useExclusiveMode (useExclusiveMode_)
  190896. {
  190897. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  190898. ComSmartPtr <IAudioClient> tempClient (createClient());
  190899. if (tempClient == 0)
  190900. return;
  190901. REFERENCE_TIME defaultPeriod, minPeriod;
  190902. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  190903. return;
  190904. WAVEFORMATEX* mixFormat = 0;
  190905. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  190906. return;
  190907. WAVEFORMATEXTENSIBLE format;
  190908. wasapi_copyWavFormat (format, mixFormat);
  190909. CoTaskMemFree (mixFormat);
  190910. actualNumChannels = numChannels = format.Format.nChannels;
  190911. defaultSampleRate = format.Format.nSamplesPerSec;
  190912. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  190913. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  190914. FloatElementComparator<double> comparator;
  190915. rates.addSorted (comparator, defaultSampleRate);
  190916. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190917. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  190918. {
  190919. if (ratesToTest[i] == defaultSampleRate)
  190920. continue;
  190921. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  190922. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  190923. (WAVEFORMATEX*) &format, 0)))
  190924. if (! rates.contains (ratesToTest[i]))
  190925. rates.addSorted (comparator, ratesToTest[i]);
  190926. }
  190927. }
  190928. ~WASAPIDeviceBase()
  190929. {
  190930. device = 0;
  190931. CloseHandle (clientEvent);
  190932. }
  190933. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  190934. bool openClient (const double newSampleRate, const BigInteger& newChannels)
  190935. {
  190936. sampleRate = newSampleRate;
  190937. channels = newChannels;
  190938. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  190939. numChannels = channels.getHighestBit() + 1;
  190940. if (numChannels == 0)
  190941. return true;
  190942. client = createClient();
  190943. if (client != 0
  190944. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  190945. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  190946. {
  190947. channelMaps.clear();
  190948. for (int i = 0; i <= channels.getHighestBit(); ++i)
  190949. if (channels[i])
  190950. channelMaps.add (i);
  190951. REFERENCE_TIME latency;
  190952. if (OK (client->GetStreamLatency (&latency)))
  190953. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  190954. (void) OK (client->GetBufferSize (&actualBufferSize));
  190955. return OK (client->SetEventHandle (clientEvent));
  190956. }
  190957. return false;
  190958. }
  190959. void closeClient()
  190960. {
  190961. if (client != 0)
  190962. client->Stop();
  190963. client = 0;
  190964. ResetEvent (clientEvent);
  190965. }
  190966. ComSmartPtr <IMMDevice> device;
  190967. ComSmartPtr <IAudioClient> client;
  190968. double sampleRate, defaultSampleRate;
  190969. int numChannels, actualNumChannels;
  190970. int minBufferSize, defaultBufferSize, latencySamples;
  190971. const bool useExclusiveMode;
  190972. Array <double> rates;
  190973. HANDLE clientEvent;
  190974. BigInteger channels;
  190975. AudioDataConverters::DataFormat dataFormat;
  190976. Array <int> channelMaps;
  190977. UINT32 actualBufferSize;
  190978. int bytesPerSample;
  190979. private:
  190980. const ComSmartPtr <IAudioClient> createClient()
  190981. {
  190982. ComSmartPtr <IAudioClient> client;
  190983. if (device != 0)
  190984. {
  190985. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  190986. logFailure (hr);
  190987. }
  190988. return client;
  190989. }
  190990. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  190991. {
  190992. WAVEFORMATEXTENSIBLE format;
  190993. zerostruct (format);
  190994. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  190995. {
  190996. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  190997. }
  190998. else
  190999. {
  191000. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191001. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191002. }
  191003. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191004. format.Format.nChannels = (WORD) numChannels;
  191005. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191006. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191007. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191008. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191009. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191010. switch (numChannels)
  191011. {
  191012. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191013. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191014. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191015. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191016. 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;
  191017. default: break;
  191018. }
  191019. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191020. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191021. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191022. logFailure (hr);
  191023. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191024. {
  191025. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191026. hr = S_OK;
  191027. }
  191028. CoTaskMemFree (nearestFormat);
  191029. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191030. if (useExclusiveMode)
  191031. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191032. GUID session;
  191033. if (hr == S_OK
  191034. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191035. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191036. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191037. {
  191038. actualNumChannels = format.Format.nChannels;
  191039. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191040. bytesPerSample = format.Format.wBitsPerSample / 8;
  191041. dataFormat = isFloat ? AudioDataConverters::float32LE
  191042. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191043. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191044. : AudioDataConverters::int16LE)));
  191045. return true;
  191046. }
  191047. return false;
  191048. }
  191049. };
  191050. class WASAPIInputDevice : public WASAPIDeviceBase
  191051. {
  191052. public:
  191053. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191054. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191055. reservoir (1, 1)
  191056. {
  191057. }
  191058. ~WASAPIInputDevice()
  191059. {
  191060. close();
  191061. }
  191062. bool open (const double newSampleRate, const BigInteger& newChannels)
  191063. {
  191064. reservoirSize = 0;
  191065. reservoirCapacity = 16384;
  191066. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191067. return openClient (newSampleRate, newChannels)
  191068. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191069. }
  191070. void close()
  191071. {
  191072. closeClient();
  191073. captureClient = 0;
  191074. reservoir.setSize (0);
  191075. }
  191076. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191077. {
  191078. if (numChannels <= 0)
  191079. return;
  191080. int offset = 0;
  191081. while (bufferSize > 0)
  191082. {
  191083. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191084. {
  191085. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191086. for (int i = 0; i < numDestBuffers; ++i)
  191087. {
  191088. float* const dest = destBuffers[i] + offset;
  191089. const int srcChan = channelMaps.getUnchecked(i);
  191090. switch (dataFormat)
  191091. {
  191092. case AudioDataConverters::float32LE:
  191093. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191094. break;
  191095. case AudioDataConverters::int32LE:
  191096. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191097. break;
  191098. case AudioDataConverters::int24LE:
  191099. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191100. break;
  191101. case AudioDataConverters::int16LE:
  191102. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191103. break;
  191104. default: jassertfalse; break;
  191105. }
  191106. }
  191107. bufferSize -= samplesToDo;
  191108. offset += samplesToDo;
  191109. reservoirSize -= samplesToDo;
  191110. }
  191111. else
  191112. {
  191113. UINT32 packetLength = 0;
  191114. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191115. break;
  191116. if (packetLength == 0)
  191117. {
  191118. if (thread.threadShouldExit())
  191119. break;
  191120. Thread::sleep (1);
  191121. continue;
  191122. }
  191123. uint8* inputData = 0;
  191124. UINT32 numSamplesAvailable;
  191125. DWORD flags;
  191126. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191127. {
  191128. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191129. for (int i = 0; i < numDestBuffers; ++i)
  191130. {
  191131. float* const dest = destBuffers[i] + offset;
  191132. const int srcChan = channelMaps.getUnchecked(i);
  191133. switch (dataFormat)
  191134. {
  191135. case AudioDataConverters::float32LE:
  191136. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191137. break;
  191138. case AudioDataConverters::int32LE:
  191139. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191140. break;
  191141. case AudioDataConverters::int24LE:
  191142. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191143. break;
  191144. case AudioDataConverters::int16LE:
  191145. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191146. break;
  191147. default: jassertfalse; break;
  191148. }
  191149. }
  191150. bufferSize -= samplesToDo;
  191151. offset += samplesToDo;
  191152. if (samplesToDo < (int) numSamplesAvailable)
  191153. {
  191154. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191155. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191156. bytesPerSample * actualNumChannels * reservoirSize);
  191157. }
  191158. captureClient->ReleaseBuffer (numSamplesAvailable);
  191159. }
  191160. }
  191161. }
  191162. }
  191163. ComSmartPtr <IAudioCaptureClient> captureClient;
  191164. MemoryBlock reservoir;
  191165. int reservoirSize, reservoirCapacity;
  191166. };
  191167. class WASAPIOutputDevice : public WASAPIDeviceBase
  191168. {
  191169. public:
  191170. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191171. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191172. {
  191173. }
  191174. ~WASAPIOutputDevice()
  191175. {
  191176. close();
  191177. }
  191178. bool open (const double newSampleRate, const BigInteger& newChannels)
  191179. {
  191180. return openClient (newSampleRate, newChannels)
  191181. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191182. }
  191183. void close()
  191184. {
  191185. closeClient();
  191186. renderClient = 0;
  191187. }
  191188. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191189. {
  191190. if (numChannels <= 0)
  191191. return;
  191192. int offset = 0;
  191193. while (bufferSize > 0)
  191194. {
  191195. UINT32 padding = 0;
  191196. if (! OK (client->GetCurrentPadding (&padding)))
  191197. return;
  191198. int samplesToDo = useExclusiveMode ? bufferSize
  191199. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191200. if (samplesToDo <= 0)
  191201. {
  191202. if (thread.threadShouldExit())
  191203. break;
  191204. Thread::sleep (0);
  191205. continue;
  191206. }
  191207. uint8* outputData = 0;
  191208. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191209. {
  191210. for (int i = 0; i < numSrcBuffers; ++i)
  191211. {
  191212. const float* const source = srcBuffers[i] + offset;
  191213. const int destChan = channelMaps.getUnchecked(i);
  191214. switch (dataFormat)
  191215. {
  191216. case AudioDataConverters::float32LE:
  191217. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191218. break;
  191219. case AudioDataConverters::int32LE:
  191220. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191221. break;
  191222. case AudioDataConverters::int24LE:
  191223. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191224. break;
  191225. case AudioDataConverters::int16LE:
  191226. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191227. break;
  191228. default: jassertfalse; break;
  191229. }
  191230. }
  191231. renderClient->ReleaseBuffer (samplesToDo, 0);
  191232. offset += samplesToDo;
  191233. bufferSize -= samplesToDo;
  191234. }
  191235. }
  191236. }
  191237. ComSmartPtr <IAudioRenderClient> renderClient;
  191238. };
  191239. class WASAPIAudioIODevice : public AudioIODevice,
  191240. public Thread
  191241. {
  191242. public:
  191243. WASAPIAudioIODevice (const String& deviceName,
  191244. const String& outputDeviceId_,
  191245. const String& inputDeviceId_,
  191246. const bool useExclusiveMode_)
  191247. : AudioIODevice (deviceName, "Windows Audio"),
  191248. Thread ("Juce WASAPI"),
  191249. isOpen_ (false),
  191250. isStarted (false),
  191251. outputDevice (0),
  191252. outputDeviceId (outputDeviceId_),
  191253. inputDevice (0),
  191254. inputDeviceId (inputDeviceId_),
  191255. useExclusiveMode (useExclusiveMode_),
  191256. currentBufferSizeSamples (0),
  191257. currentSampleRate (0),
  191258. callback (0)
  191259. {
  191260. }
  191261. ~WASAPIAudioIODevice()
  191262. {
  191263. close();
  191264. deleteAndZero (inputDevice);
  191265. deleteAndZero (outputDevice);
  191266. }
  191267. bool initialise()
  191268. {
  191269. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191270. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191271. latencyIn = latencyOut = 0;
  191272. Array <double> ratesIn, ratesOut;
  191273. if (createDevices())
  191274. {
  191275. jassert (inputDevice != 0 || outputDevice != 0);
  191276. if (inputDevice != 0 && outputDevice != 0)
  191277. {
  191278. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191279. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191280. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191281. sampleRates = inputDevice->rates;
  191282. sampleRates.removeValuesNotIn (outputDevice->rates);
  191283. }
  191284. else
  191285. {
  191286. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191287. defaultSampleRate = d->defaultSampleRate;
  191288. minBufferSize = d->minBufferSize;
  191289. defaultBufferSize = d->defaultBufferSize;
  191290. sampleRates = d->rates;
  191291. }
  191292. IntegerElementComparator<int> comparator;
  191293. bufferSizes.addSorted (comparator, defaultBufferSize);
  191294. if (minBufferSize != defaultBufferSize)
  191295. bufferSizes.addSorted (comparator, minBufferSize);
  191296. int n = 64;
  191297. for (int i = 0; i < 40; ++i)
  191298. {
  191299. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191300. bufferSizes.addSorted (comparator, n);
  191301. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191302. }
  191303. return true;
  191304. }
  191305. return false;
  191306. }
  191307. const StringArray getOutputChannelNames()
  191308. {
  191309. StringArray outChannels;
  191310. if (outputDevice != 0)
  191311. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191312. outChannels.add ("Output channel " + String (i));
  191313. return outChannels;
  191314. }
  191315. const StringArray getInputChannelNames()
  191316. {
  191317. StringArray inChannels;
  191318. if (inputDevice != 0)
  191319. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191320. inChannels.add ("Input channel " + String (i));
  191321. return inChannels;
  191322. }
  191323. int getNumSampleRates() { return sampleRates.size(); }
  191324. double getSampleRate (int index) { return sampleRates [index]; }
  191325. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191326. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191327. int getDefaultBufferSize() { return defaultBufferSize; }
  191328. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191329. double getCurrentSampleRate() { return currentSampleRate; }
  191330. int getCurrentBitDepth() { return 32; }
  191331. int getOutputLatencyInSamples() { return latencyOut; }
  191332. int getInputLatencyInSamples() { return latencyIn; }
  191333. const BigInteger getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BigInteger(); }
  191334. const BigInteger getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BigInteger(); }
  191335. const String getLastError() { return lastError; }
  191336. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  191337. double sampleRate, int bufferSizeSamples)
  191338. {
  191339. close();
  191340. lastError = String::empty;
  191341. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191342. {
  191343. lastError = "The input and output devices don't share a common sample rate!";
  191344. return lastError;
  191345. }
  191346. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191347. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191348. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191349. {
  191350. lastError = "Couldn't open the input device!";
  191351. return lastError;
  191352. }
  191353. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191354. {
  191355. close();
  191356. lastError = "Couldn't open the output device!";
  191357. return lastError;
  191358. }
  191359. if (inputDevice != 0)
  191360. ResetEvent (inputDevice->clientEvent);
  191361. if (outputDevice != 0)
  191362. ResetEvent (outputDevice->clientEvent);
  191363. startThread (8);
  191364. Thread::sleep (5);
  191365. if (inputDevice != 0 && inputDevice->client != 0)
  191366. {
  191367. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191368. HRESULT hr = inputDevice->client->Start();
  191369. logFailure (hr); //xxx handle this
  191370. }
  191371. if (outputDevice != 0 && outputDevice->client != 0)
  191372. {
  191373. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191374. HRESULT hr = outputDevice->client->Start();
  191375. logFailure (hr); //xxx handle this
  191376. }
  191377. isOpen_ = true;
  191378. return lastError;
  191379. }
  191380. void close()
  191381. {
  191382. stop();
  191383. if (inputDevice != 0)
  191384. SetEvent (inputDevice->clientEvent);
  191385. if (outputDevice != 0)
  191386. SetEvent (outputDevice->clientEvent);
  191387. stopThread (5000);
  191388. if (inputDevice != 0)
  191389. inputDevice->close();
  191390. if (outputDevice != 0)
  191391. outputDevice->close();
  191392. isOpen_ = false;
  191393. }
  191394. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191395. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191396. void start (AudioIODeviceCallback* call)
  191397. {
  191398. if (isOpen_ && call != 0 && ! isStarted)
  191399. {
  191400. if (! isThreadRunning())
  191401. {
  191402. // something's gone wrong and the thread's stopped..
  191403. isOpen_ = false;
  191404. return;
  191405. }
  191406. call->audioDeviceAboutToStart (this);
  191407. const ScopedLock sl (startStopLock);
  191408. callback = call;
  191409. isStarted = true;
  191410. }
  191411. }
  191412. void stop()
  191413. {
  191414. if (isStarted)
  191415. {
  191416. AudioIODeviceCallback* const callbackLocal = callback;
  191417. {
  191418. const ScopedLock sl (startStopLock);
  191419. isStarted = false;
  191420. }
  191421. if (callbackLocal != 0)
  191422. callbackLocal->audioDeviceStopped();
  191423. }
  191424. }
  191425. void setMMThreadPriority()
  191426. {
  191427. DynamicLibraryLoader dll ("avrt.dll");
  191428. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  191429. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  191430. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  191431. {
  191432. DWORD dummy = 0;
  191433. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  191434. if (h != 0)
  191435. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  191436. }
  191437. }
  191438. void run()
  191439. {
  191440. setMMThreadPriority();
  191441. const int bufferSize = currentBufferSizeSamples;
  191442. HANDLE events[2];
  191443. int numEvents = 0;
  191444. if (inputDevice != 0)
  191445. events [numEvents++] = inputDevice->clientEvent;
  191446. if (outputDevice != 0)
  191447. events [numEvents++] = outputDevice->clientEvent;
  191448. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  191449. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  191450. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  191451. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  191452. float** const inputBuffers = ins.getArrayOfChannels();
  191453. float** const outputBuffers = outs.getArrayOfChannels();
  191454. ins.clear();
  191455. while (! threadShouldExit())
  191456. {
  191457. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  191458. : WaitForMultipleObjects (numEvents, events, true, 1000);
  191459. if (result == WAIT_TIMEOUT)
  191460. continue;
  191461. if (threadShouldExit())
  191462. break;
  191463. if (inputDevice != 0)
  191464. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  191465. // Make the callback..
  191466. {
  191467. const ScopedLock sl (startStopLock);
  191468. if (isStarted)
  191469. {
  191470. JUCE_TRY
  191471. {
  191472. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191473. numInputBuffers,
  191474. outputBuffers,
  191475. numOutputBuffers,
  191476. bufferSize);
  191477. }
  191478. JUCE_CATCH_EXCEPTION
  191479. }
  191480. else
  191481. {
  191482. outs.clear();
  191483. }
  191484. }
  191485. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  191486. continue;
  191487. if (outputDevice != 0)
  191488. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  191489. }
  191490. }
  191491. juce_UseDebuggingNewOperator
  191492. String outputDeviceId, inputDeviceId;
  191493. String lastError;
  191494. private:
  191495. // Device stats...
  191496. WASAPIInputDevice* inputDevice;
  191497. WASAPIOutputDevice* outputDevice;
  191498. const bool useExclusiveMode;
  191499. double defaultSampleRate;
  191500. int minBufferSize, defaultBufferSize;
  191501. int latencyIn, latencyOut;
  191502. Array <double> sampleRates;
  191503. Array <int> bufferSizes;
  191504. // Active state...
  191505. bool isOpen_, isStarted;
  191506. int currentBufferSizeSamples;
  191507. double currentSampleRate;
  191508. AudioIODeviceCallback* callback;
  191509. CriticalSection startStopLock;
  191510. bool createDevices()
  191511. {
  191512. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191513. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191514. return false;
  191515. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191516. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  191517. return false;
  191518. UINT32 numDevices = 0;
  191519. if (! OK (deviceCollection->GetCount (&numDevices)))
  191520. return false;
  191521. for (UINT32 i = 0; i < numDevices; ++i)
  191522. {
  191523. ComSmartPtr <IMMDevice> device;
  191524. if (! OK (deviceCollection->Item (i, &device)))
  191525. continue;
  191526. const String deviceId (wasapi_getDeviceID (device));
  191527. if (deviceId.isEmpty())
  191528. continue;
  191529. const EDataFlow flow = wasapi_getDataFlow (device);
  191530. if (deviceId == inputDeviceId && flow == eCapture)
  191531. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  191532. else if (deviceId == outputDeviceId && flow == eRender)
  191533. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  191534. }
  191535. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  191536. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  191537. }
  191538. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  191539. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  191540. };
  191541. class WASAPIAudioIODeviceType : public AudioIODeviceType
  191542. {
  191543. public:
  191544. WASAPIAudioIODeviceType()
  191545. : AudioIODeviceType ("Windows Audio"),
  191546. hasScanned (false)
  191547. {
  191548. }
  191549. ~WASAPIAudioIODeviceType()
  191550. {
  191551. }
  191552. void scanForDevices()
  191553. {
  191554. hasScanned = true;
  191555. outputDeviceNames.clear();
  191556. inputDeviceNames.clear();
  191557. outputDeviceIds.clear();
  191558. inputDeviceIds.clear();
  191559. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  191560. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  191561. return;
  191562. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  191563. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  191564. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  191565. UINT32 numDevices = 0;
  191566. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  191567. && OK (deviceCollection->GetCount (&numDevices))))
  191568. return;
  191569. for (UINT32 i = 0; i < numDevices; ++i)
  191570. {
  191571. ComSmartPtr <IMMDevice> device;
  191572. if (! OK (deviceCollection->Item (i, &device)))
  191573. continue;
  191574. const String deviceId (wasapi_getDeviceID (device));
  191575. DWORD state = 0;
  191576. if (! OK (device->GetState (&state)))
  191577. continue;
  191578. if (state != DEVICE_STATE_ACTIVE)
  191579. continue;
  191580. String name;
  191581. {
  191582. ComSmartPtr <IPropertyStore> properties;
  191583. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  191584. continue;
  191585. PROPVARIANT value;
  191586. PropVariantInit (&value);
  191587. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  191588. name = value.pwszVal;
  191589. PropVariantClear (&value);
  191590. }
  191591. const EDataFlow flow = wasapi_getDataFlow (device);
  191592. if (flow == eRender)
  191593. {
  191594. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  191595. outputDeviceIds.insert (index, deviceId);
  191596. outputDeviceNames.insert (index, name);
  191597. }
  191598. else if (flow == eCapture)
  191599. {
  191600. const int index = (deviceId == defaultCapture) ? 0 : -1;
  191601. inputDeviceIds.insert (index, deviceId);
  191602. inputDeviceNames.insert (index, name);
  191603. }
  191604. }
  191605. inputDeviceNames.appendNumbersToDuplicates (false, false);
  191606. outputDeviceNames.appendNumbersToDuplicates (false, false);
  191607. }
  191608. const StringArray getDeviceNames (bool wantInputNames) const
  191609. {
  191610. jassert (hasScanned); // need to call scanForDevices() before doing this
  191611. return wantInputNames ? inputDeviceNames
  191612. : outputDeviceNames;
  191613. }
  191614. int getDefaultDeviceIndex (bool /*forInput*/) const
  191615. {
  191616. jassert (hasScanned); // need to call scanForDevices() before doing this
  191617. return 0;
  191618. }
  191619. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  191620. {
  191621. jassert (hasScanned); // need to call scanForDevices() before doing this
  191622. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  191623. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  191624. : outputDeviceIds.indexOf (d->outputDeviceId));
  191625. }
  191626. bool hasSeparateInputsAndOutputs() const { return true; }
  191627. AudioIODevice* createDevice (const String& outputDeviceName,
  191628. const String& inputDeviceName)
  191629. {
  191630. jassert (hasScanned); // need to call scanForDevices() before doing this
  191631. const bool useExclusiveMode = false;
  191632. ScopedPointer<WASAPIAudioIODevice> device;
  191633. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191634. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191635. if (outputIndex >= 0 || inputIndex >= 0)
  191636. {
  191637. device = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191638. : inputDeviceName,
  191639. outputDeviceIds [outputIndex],
  191640. inputDeviceIds [inputIndex],
  191641. useExclusiveMode);
  191642. if (! device->initialise())
  191643. device = 0;
  191644. }
  191645. return device.release();
  191646. }
  191647. juce_UseDebuggingNewOperator
  191648. StringArray outputDeviceNames, outputDeviceIds;
  191649. StringArray inputDeviceNames, inputDeviceIds;
  191650. private:
  191651. bool hasScanned;
  191652. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  191653. {
  191654. String s;
  191655. IMMDevice* dev = 0;
  191656. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  191657. eMultimedia, &dev)))
  191658. {
  191659. WCHAR* deviceId = 0;
  191660. if (OK (dev->GetId (&deviceId)))
  191661. {
  191662. s = String (deviceId);
  191663. CoTaskMemFree (deviceId);
  191664. }
  191665. dev->Release();
  191666. }
  191667. return s;
  191668. }
  191669. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  191670. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  191671. };
  191672. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  191673. {
  191674. return new WASAPIAudioIODeviceType();
  191675. }
  191676. #undef logFailure
  191677. #undef OK
  191678. #endif
  191679. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  191680. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  191681. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191682. // compiled on its own).
  191683. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  191684. class DShowCameraDeviceInteral : public ChangeBroadcaster
  191685. {
  191686. public:
  191687. DShowCameraDeviceInteral (CameraDevice* const owner_,
  191688. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  191689. const ComSmartPtr <IBaseFilter>& filter_,
  191690. int minWidth, int minHeight,
  191691. int maxWidth, int maxHeight)
  191692. : owner (owner_),
  191693. captureGraphBuilder (captureGraphBuilder_),
  191694. filter (filter_),
  191695. ok (false),
  191696. imageNeedsFlipping (false),
  191697. width (0),
  191698. height (0),
  191699. activeUsers (0),
  191700. recordNextFrameTime (false),
  191701. activeImage (0),
  191702. loadingImage (0)
  191703. {
  191704. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  191705. if (FAILED (hr))
  191706. return;
  191707. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  191708. if (FAILED (hr))
  191709. return;
  191710. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  191711. if (FAILED (hr))
  191712. return;
  191713. {
  191714. ComSmartPtr <IAMStreamConfig> streamConfig;
  191715. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE, 0, filter,
  191716. IID_IAMStreamConfig, (void**) &streamConfig);
  191717. if (streamConfig != 0)
  191718. {
  191719. getVideoSizes (streamConfig);
  191720. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  191721. return;
  191722. }
  191723. }
  191724. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  191725. if (FAILED (hr))
  191726. return;
  191727. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  191728. if (FAILED (hr))
  191729. return;
  191730. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  191731. if (FAILED (hr))
  191732. return;
  191733. if (! connectFilters (filter, smartTee))
  191734. return;
  191735. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  191736. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  191737. if (FAILED (hr))
  191738. return;
  191739. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  191740. if (FAILED (hr))
  191741. return;
  191742. AM_MEDIA_TYPE mt;
  191743. zerostruct (mt);
  191744. mt.majortype = MEDIATYPE_Video;
  191745. mt.subtype = MEDIASUBTYPE_RGB24;
  191746. mt.formattype = FORMAT_VideoInfo;
  191747. sampleGrabber->SetMediaType (&mt);
  191748. callback = new GrabberCallback (*this);
  191749. sampleGrabber->SetCallback (callback, 1);
  191750. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  191751. if (FAILED (hr))
  191752. return;
  191753. ComSmartPtr <IPin> grabberInputPin;
  191754. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  191755. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  191756. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  191757. return;
  191758. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  191759. if (FAILED (hr))
  191760. return;
  191761. zerostruct (mt);
  191762. hr = sampleGrabber->GetConnectedMediaType (&mt);
  191763. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  191764. width = pVih->bmiHeader.biWidth;
  191765. height = pVih->bmiHeader.biHeight;
  191766. ComSmartPtr <IBaseFilter> nullFilter;
  191767. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  191768. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  191769. if (connectFilters (sampleGrabberBase, nullFilter)
  191770. && addGraphToRot())
  191771. {
  191772. activeImage = new Image (Image::RGB, width, height, true);
  191773. loadingImage = new Image (Image::RGB, width, height, true);
  191774. ok = true;
  191775. }
  191776. }
  191777. ~DShowCameraDeviceInteral()
  191778. {
  191779. if (mediaControl != 0)
  191780. mediaControl->Stop();
  191781. removeGraphFromRot();
  191782. for (int i = viewerComps.size(); --i >= 0;)
  191783. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  191784. callback = 0;
  191785. graphBuilder = 0;
  191786. sampleGrabber = 0;
  191787. mediaControl = 0;
  191788. filter = 0;
  191789. captureGraphBuilder = 0;
  191790. smartTee = 0;
  191791. smartTeePreviewOutputPin = 0;
  191792. smartTeeCaptureOutputPin = 0;
  191793. asfWriter = 0;
  191794. delete activeImage;
  191795. delete loadingImage;
  191796. }
  191797. void addUser()
  191798. {
  191799. if (ok && activeUsers++ == 0)
  191800. mediaControl->Run();
  191801. }
  191802. void removeUser()
  191803. {
  191804. if (ok && --activeUsers == 0)
  191805. mediaControl->Stop();
  191806. }
  191807. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  191808. {
  191809. if (recordNextFrameTime)
  191810. {
  191811. const double defaultCameraLatency = 0.1;
  191812. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  191813. recordNextFrameTime = false;
  191814. ComSmartPtr <IPin> pin;
  191815. if (getPin (filter, PINDIR_OUTPUT, &pin))
  191816. {
  191817. ComSmartPtr <IAMPushSource> pushSource;
  191818. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  191819. if (pushSource != 0)
  191820. {
  191821. REFERENCE_TIME latency = 0;
  191822. hr = pushSource->GetLatency (&latency);
  191823. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  191824. }
  191825. }
  191826. }
  191827. {
  191828. const int lineStride = width * 3;
  191829. const ScopedLock sl (imageSwapLock);
  191830. {
  191831. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  191832. for (int i = 0; i < height; ++i)
  191833. memcpy (destData.getLinePointer ((height - 1) - i),
  191834. buffer + lineStride * i,
  191835. lineStride);
  191836. }
  191837. imageNeedsFlipping = true;
  191838. }
  191839. if (listeners.size() > 0)
  191840. callListeners (*loadingImage);
  191841. sendChangeMessage (this);
  191842. }
  191843. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  191844. {
  191845. if (imageNeedsFlipping)
  191846. {
  191847. const ScopedLock sl (imageSwapLock);
  191848. swapVariables (loadingImage, activeImage);
  191849. imageNeedsFlipping = false;
  191850. }
  191851. RectanglePlacement rp (RectanglePlacement::centred);
  191852. double dx = 0, dy = 0, dw = width, dh = height;
  191853. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  191854. const int rx = roundToInt (dx), ry = roundToInt (dy);
  191855. const int rw = roundToInt (dw), rh = roundToInt (dh);
  191856. g.saveState();
  191857. g.excludeClipRegion (Rectangle<int> (rx, ry, rw, rh));
  191858. g.fillAll (Colours::black);
  191859. g.restoreState();
  191860. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  191861. }
  191862. bool createFileCaptureFilter (const File& file)
  191863. {
  191864. removeFileCaptureFilter();
  191865. file.deleteFile();
  191866. mediaControl->Stop();
  191867. firstRecordedTime = Time();
  191868. recordNextFrameTime = true;
  191869. HRESULT hr = asfWriter.CoCreateInstance (CLSID_WMAsfWriter, CLSCTX_INPROC_SERVER);
  191870. if (SUCCEEDED (hr))
  191871. {
  191872. ComSmartPtr <IFileSinkFilter> fileSink;
  191873. hr = asfWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  191874. if (SUCCEEDED (hr))
  191875. {
  191876. hr = fileSink->SetFileName (file.getFullPathName(), 0);
  191877. if (SUCCEEDED (hr))
  191878. {
  191879. hr = graphBuilder->AddFilter (asfWriter, _T("AsfWriter"));
  191880. if (SUCCEEDED (hr))
  191881. {
  191882. ComSmartPtr <IConfigAsfWriter> asfConfig;
  191883. hr = asfWriter->QueryInterface (IID_IConfigAsfWriter, (void**) &asfConfig);
  191884. asfConfig->SetIndexMode (true);
  191885. ComSmartPtr <IWMProfileManager> profileManager;
  191886. hr = WMCreateProfileManager (&profileManager);
  191887. // This gibberish is the DirectShow profile for a video-only wmv file.
  191888. String prof ("<profile version=\"589824\" storageformat=\"1\" name=\"Quality\" description=\"Quality type for output.\"><streamconfig "
  191889. "majortype=\"{73646976-0000-0010-8000-00AA00389B71}\" streamnumber=\"1\" streamname=\"Video Stream\" inputname=\"Video409\" bitrate=\"894960\" "
  191890. "bufferwindow=\"0\" reliabletransport=\"1\" decodercomplexity=\"AU\" rfc1766langid=\"en-us\"><videomediaprops maxkeyframespacing=\"50000000\" quality=\"90\"/>"
  191891. "<wmmediatype subtype=\"{33564D57-0000-0010-8000-00AA00389B71}\" bfixedsizesamples=\"0\" btemporalcompression=\"1\" lsamplesize=\"0\"> <videoinfoheader "
  191892. "dwbitrate=\"894960\" dwbiterrorrate=\"0\" avgtimeperframe=\"100000\"><rcsource left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <rctarget "
  191893. "left=\"0\" top=\"0\" right=\"$WIDTH\" bottom=\"$HEIGHT\"/> <bitmapinfoheader biwidth=\"$WIDTH\" biheight=\"$HEIGHT\" biplanes=\"1\" bibitcount=\"24\" "
  191894. "bicompression=\"WMV3\" bisizeimage=\"0\" bixpelspermeter=\"0\" biypelspermeter=\"0\" biclrused=\"0\" biclrimportant=\"0\"/> "
  191895. "</videoinfoheader></wmmediatype></streamconfig></profile>");
  191896. prof = prof.replace ("$WIDTH", String (width))
  191897. .replace ("$HEIGHT", String (height));
  191898. ComSmartPtr <IWMProfile> currentProfile;
  191899. hr = profileManager->LoadProfileByData ((const WCHAR*) prof, &currentProfile);
  191900. hr = asfConfig->ConfigureFilterUsingProfile (currentProfile);
  191901. if (SUCCEEDED (hr))
  191902. {
  191903. ComSmartPtr <IPin> asfWriterInputPin;
  191904. if (getPin (asfWriter, PINDIR_INPUT, &asfWriterInputPin, "Video Input 01"))
  191905. {
  191906. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, asfWriterInputPin);
  191907. if (SUCCEEDED (hr)
  191908. && ok && activeUsers > 0
  191909. && SUCCEEDED (mediaControl->Run()))
  191910. {
  191911. return true;
  191912. }
  191913. }
  191914. }
  191915. }
  191916. }
  191917. }
  191918. }
  191919. removeFileCaptureFilter();
  191920. if (ok && activeUsers > 0)
  191921. mediaControl->Run();
  191922. return false;
  191923. }
  191924. void removeFileCaptureFilter()
  191925. {
  191926. mediaControl->Stop();
  191927. if (asfWriter != 0)
  191928. {
  191929. graphBuilder->RemoveFilter (asfWriter);
  191930. asfWriter = 0;
  191931. }
  191932. if (ok && activeUsers > 0)
  191933. mediaControl->Run();
  191934. }
  191935. void addListener (CameraImageListener* listenerToAdd)
  191936. {
  191937. const ScopedLock sl (listenerLock);
  191938. if (listeners.size() == 0)
  191939. addUser();
  191940. listeners.addIfNotAlreadyThere (listenerToAdd);
  191941. }
  191942. void removeListener (CameraImageListener* listenerToRemove)
  191943. {
  191944. const ScopedLock sl (listenerLock);
  191945. listeners.removeValue (listenerToRemove);
  191946. if (listeners.size() == 0)
  191947. removeUser();
  191948. }
  191949. void callListeners (Image& image)
  191950. {
  191951. const ScopedLock sl (listenerLock);
  191952. for (int i = listeners.size(); --i >= 0;)
  191953. {
  191954. CameraImageListener* l = (CameraImageListener*) listeners[i];
  191955. if (l != 0)
  191956. l->imageReceived (image);
  191957. }
  191958. }
  191959. class DShowCaptureViewerComp : public Component,
  191960. public ChangeListener
  191961. {
  191962. public:
  191963. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  191964. : owner (owner_)
  191965. {
  191966. setOpaque (true);
  191967. owner->addChangeListener (this);
  191968. owner->addUser();
  191969. owner->viewerComps.add (this);
  191970. setSize (owner_->width, owner_->height);
  191971. }
  191972. ~DShowCaptureViewerComp()
  191973. {
  191974. if (owner != 0)
  191975. {
  191976. owner->viewerComps.removeValue (this);
  191977. owner->removeUser();
  191978. owner->removeChangeListener (this);
  191979. }
  191980. }
  191981. void ownerDeleted()
  191982. {
  191983. owner = 0;
  191984. }
  191985. void paint (Graphics& g)
  191986. {
  191987. g.setColour (Colours::black);
  191988. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  191989. if (owner != 0)
  191990. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  191991. else
  191992. g.fillAll (Colours::black);
  191993. }
  191994. void changeListenerCallback (void*)
  191995. {
  191996. repaint();
  191997. }
  191998. private:
  191999. DShowCameraDeviceInteral* owner;
  192000. };
  192001. bool ok;
  192002. int width, height;
  192003. Time firstRecordedTime;
  192004. VoidArray viewerComps;
  192005. private:
  192006. CameraDevice* const owner;
  192007. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192008. ComSmartPtr <IBaseFilter> filter;
  192009. ComSmartPtr <IBaseFilter> smartTee;
  192010. ComSmartPtr <IGraphBuilder> graphBuilder;
  192011. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192012. ComSmartPtr <IMediaControl> mediaControl;
  192013. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192014. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192015. ComSmartPtr <IBaseFilter> asfWriter;
  192016. int activeUsers;
  192017. Array <int> widths, heights;
  192018. DWORD graphRegistrationID;
  192019. CriticalSection imageSwapLock;
  192020. bool imageNeedsFlipping;
  192021. Image* loadingImage;
  192022. Image* activeImage;
  192023. bool recordNextFrameTime;
  192024. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192025. {
  192026. widths.clear();
  192027. heights.clear();
  192028. int count = 0, size = 0;
  192029. streamConfig->GetNumberOfCapabilities (&count, &size);
  192030. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192031. {
  192032. for (int i = 0; i < count; ++i)
  192033. {
  192034. VIDEO_STREAM_CONFIG_CAPS scc;
  192035. AM_MEDIA_TYPE* config;
  192036. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192037. if (SUCCEEDED (hr))
  192038. {
  192039. const int w = scc.InputSize.cx;
  192040. const int h = scc.InputSize.cy;
  192041. bool duplicate = false;
  192042. for (int j = widths.size(); --j >= 0;)
  192043. {
  192044. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192045. {
  192046. duplicate = true;
  192047. break;
  192048. }
  192049. }
  192050. if (! duplicate)
  192051. {
  192052. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192053. widths.add (w);
  192054. heights.add (h);
  192055. }
  192056. deleteMediaType (config);
  192057. }
  192058. }
  192059. }
  192060. }
  192061. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192062. const int minWidth, const int minHeight,
  192063. const int maxWidth, const int maxHeight)
  192064. {
  192065. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192066. streamConfig->GetNumberOfCapabilities (&count, &size);
  192067. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192068. {
  192069. AM_MEDIA_TYPE* config;
  192070. VIDEO_STREAM_CONFIG_CAPS scc;
  192071. for (int i = 0; i < count; ++i)
  192072. {
  192073. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192074. if (SUCCEEDED (hr))
  192075. {
  192076. if (scc.InputSize.cx >= minWidth
  192077. && scc.InputSize.cy >= minHeight
  192078. && scc.InputSize.cx <= maxWidth
  192079. && scc.InputSize.cy <= maxHeight)
  192080. {
  192081. int area = scc.InputSize.cx * scc.InputSize.cy;
  192082. if (area > bestArea)
  192083. {
  192084. bestIndex = i;
  192085. bestArea = area;
  192086. }
  192087. }
  192088. deleteMediaType (config);
  192089. }
  192090. }
  192091. if (bestIndex >= 0)
  192092. {
  192093. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192094. hr = streamConfig->SetFormat (config);
  192095. deleteMediaType (config);
  192096. return SUCCEEDED (hr);
  192097. }
  192098. }
  192099. return false;
  192100. }
  192101. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192102. {
  192103. ComSmartPtr <IEnumPins> enumerator;
  192104. ComSmartPtr <IPin> pin;
  192105. filter->EnumPins (&enumerator);
  192106. while (enumerator->Next (1, &pin, 0) == S_OK)
  192107. {
  192108. PIN_DIRECTION dir;
  192109. pin->QueryDirection (&dir);
  192110. if (wantedDirection == dir)
  192111. {
  192112. PIN_INFO info;
  192113. zerostruct (info);
  192114. pin->QueryPinInfo (&info);
  192115. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192116. {
  192117. pin.p->AddRef();
  192118. *result = pin;
  192119. return true;
  192120. }
  192121. }
  192122. }
  192123. return false;
  192124. }
  192125. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192126. {
  192127. ComSmartPtr <IPin> in, out;
  192128. return getPin (first, PINDIR_OUTPUT, &out)
  192129. && getPin (second, PINDIR_INPUT, &in)
  192130. && SUCCEEDED (graphBuilder->Connect (out, in));
  192131. }
  192132. bool addGraphToRot()
  192133. {
  192134. ComSmartPtr <IRunningObjectTable> rot;
  192135. if (FAILED (GetRunningObjectTable (0, &rot)))
  192136. return false;
  192137. ComSmartPtr <IMoniker> moniker;
  192138. WCHAR buffer[128];
  192139. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192140. if (FAILED (hr))
  192141. return false;
  192142. graphRegistrationID = 0;
  192143. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192144. }
  192145. void removeGraphFromRot()
  192146. {
  192147. ComSmartPtr <IRunningObjectTable> rot;
  192148. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192149. rot->Revoke (graphRegistrationID);
  192150. }
  192151. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192152. {
  192153. if (pmt->cbFormat != 0)
  192154. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192155. if (pmt->pUnk != 0)
  192156. pmt->pUnk->Release();
  192157. CoTaskMemFree (pmt);
  192158. }
  192159. class GrabberCallback : public ISampleGrabberCB
  192160. {
  192161. public:
  192162. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192163. : owner (owner_)
  192164. {
  192165. }
  192166. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192167. {
  192168. if (id == IID_IUnknown)
  192169. *result = dynamic_cast <IUnknown*> (this);
  192170. else if (id == IID_ISampleGrabberCB)
  192171. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192172. else
  192173. {
  192174. *result = 0;
  192175. return E_NOINTERFACE;
  192176. }
  192177. AddRef();
  192178. return S_OK;
  192179. }
  192180. ULONG __stdcall AddRef() { return ++refCount; }
  192181. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192182. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192183. {
  192184. return E_FAIL;
  192185. }
  192186. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192187. {
  192188. owner.handleFrame (time, buffer, bufferSize);
  192189. return S_OK;
  192190. }
  192191. private:
  192192. int refCount;
  192193. DShowCameraDeviceInteral& owner;
  192194. GrabberCallback (const GrabberCallback&);
  192195. GrabberCallback& operator= (const GrabberCallback&);
  192196. };
  192197. ComSmartPtr <GrabberCallback> callback;
  192198. VoidArray listeners;
  192199. CriticalSection listenerLock;
  192200. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192201. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192202. };
  192203. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192204. : name (name_)
  192205. {
  192206. isRecording = false;
  192207. }
  192208. CameraDevice::~CameraDevice()
  192209. {
  192210. stopRecording();
  192211. delete (DShowCameraDeviceInteral*) internal;
  192212. internal = 0;
  192213. }
  192214. Component* CameraDevice::createViewerComponent()
  192215. {
  192216. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192217. }
  192218. const String CameraDevice::getFileExtension()
  192219. {
  192220. return ".wmv";
  192221. }
  192222. void CameraDevice::startRecordingToFile (const File& file, int quality)
  192223. {
  192224. stopRecording();
  192225. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192226. d->addUser();
  192227. isRecording = d->createFileCaptureFilter (file);
  192228. }
  192229. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192230. {
  192231. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192232. return d->firstRecordedTime;
  192233. }
  192234. void CameraDevice::stopRecording()
  192235. {
  192236. if (isRecording)
  192237. {
  192238. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192239. d->removeFileCaptureFilter();
  192240. d->removeUser();
  192241. isRecording = false;
  192242. }
  192243. }
  192244. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192245. {
  192246. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192247. if (listenerToAdd != 0)
  192248. d->addListener (listenerToAdd);
  192249. }
  192250. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192251. {
  192252. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192253. if (listenerToRemove != 0)
  192254. d->removeListener (listenerToRemove);
  192255. }
  192256. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192257. const int deviceIndexToOpen,
  192258. String& name)
  192259. {
  192260. int index = 0;
  192261. ComSmartPtr <IBaseFilter> result;
  192262. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192263. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192264. if (SUCCEEDED (hr))
  192265. {
  192266. ComSmartPtr <IEnumMoniker> enumerator;
  192267. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192268. if (SUCCEEDED (hr) && enumerator != 0)
  192269. {
  192270. ComSmartPtr <IBaseFilter> captureFilter;
  192271. ComSmartPtr <IMoniker> moniker;
  192272. ULONG fetched;
  192273. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192274. {
  192275. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192276. if (SUCCEEDED (hr))
  192277. {
  192278. ComSmartPtr <IPropertyBag> propertyBag;
  192279. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192280. if (SUCCEEDED (hr))
  192281. {
  192282. VARIANT var;
  192283. var.vt = VT_BSTR;
  192284. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192285. propertyBag = 0;
  192286. if (SUCCEEDED (hr))
  192287. {
  192288. if (names != 0)
  192289. names->add (var.bstrVal);
  192290. if (index == deviceIndexToOpen)
  192291. {
  192292. name = var.bstrVal;
  192293. result = captureFilter;
  192294. captureFilter = 0;
  192295. break;
  192296. }
  192297. ++index;
  192298. }
  192299. moniker = 0;
  192300. }
  192301. captureFilter = 0;
  192302. }
  192303. }
  192304. }
  192305. }
  192306. return result;
  192307. }
  192308. const StringArray CameraDevice::getAvailableDevices()
  192309. {
  192310. StringArray devs;
  192311. String dummy;
  192312. enumerateCameras (&devs, -1, dummy);
  192313. return devs;
  192314. }
  192315. CameraDevice* CameraDevice::openDevice (int index,
  192316. int minWidth, int minHeight,
  192317. int maxWidth, int maxHeight)
  192318. {
  192319. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192320. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192321. if (SUCCEEDED (hr))
  192322. {
  192323. String name;
  192324. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192325. if (filter != 0)
  192326. {
  192327. CameraDevice* const cam = new CameraDevice (name, index);
  192328. DShowCameraDeviceInteral* const intern
  192329. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192330. minWidth, minHeight, maxWidth, maxHeight);
  192331. cam->internal = intern;
  192332. if (intern->ok)
  192333. return cam;
  192334. else
  192335. delete cam;
  192336. }
  192337. }
  192338. return 0;
  192339. }
  192340. #endif
  192341. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192342. #endif
  192343. // Auto-link the other win32 libs that are needed by library calls..
  192344. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192345. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192346. // Auto-links to various win32 libs that are needed by library calls..
  192347. #pragma comment(lib, "kernel32.lib")
  192348. #pragma comment(lib, "user32.lib")
  192349. #pragma comment(lib, "shell32.lib")
  192350. #pragma comment(lib, "gdi32.lib")
  192351. #pragma comment(lib, "vfw32.lib")
  192352. #pragma comment(lib, "comdlg32.lib")
  192353. #pragma comment(lib, "winmm.lib")
  192354. #pragma comment(lib, "wininet.lib")
  192355. #pragma comment(lib, "ole32.lib")
  192356. #pragma comment(lib, "oleaut32.lib")
  192357. #pragma comment(lib, "advapi32.lib")
  192358. #pragma comment(lib, "ws2_32.lib")
  192359. #pragma comment(lib, "comsupp.lib")
  192360. #pragma comment(lib, "version.lib")
  192361. #if JUCE_OPENGL
  192362. #pragma comment(lib, "OpenGL32.Lib")
  192363. #pragma comment(lib, "GlU32.Lib")
  192364. #endif
  192365. #if JUCE_QUICKTIME
  192366. #pragma comment (lib, "QTMLClient.lib")
  192367. #endif
  192368. #if JUCE_USE_CAMERA
  192369. #pragma comment (lib, "Strmiids.lib")
  192370. #pragma comment (lib, "wmvcore.lib")
  192371. #endif
  192372. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192373. #endif
  192374. END_JUCE_NAMESPACE
  192375. #endif
  192376. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192377. #endif
  192378. #if JUCE_LINUX
  192379. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192380. #if JUCE_LINUX
  192381. BEGIN_JUCE_NAMESPACE
  192382. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192383. #define SUPPORT_AFFINITIES 1
  192384. #endif
  192385. #define JUCE_INCLUDED_FILE 1
  192386. // Now include the actual code files..
  192387. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192388. CriticalSection::CriticalSection() throw()
  192389. {
  192390. pthread_mutexattr_t atts;
  192391. pthread_mutexattr_init (&atts);
  192392. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192393. pthread_mutex_init (&internal, &atts);
  192394. }
  192395. CriticalSection::~CriticalSection() throw()
  192396. {
  192397. pthread_mutex_destroy (&internal);
  192398. }
  192399. void CriticalSection::enter() const throw()
  192400. {
  192401. pthread_mutex_lock (&internal);
  192402. }
  192403. bool CriticalSection::tryEnter() const throw()
  192404. {
  192405. return pthread_mutex_trylock (&internal) == 0;
  192406. }
  192407. void CriticalSection::exit() const throw()
  192408. {
  192409. pthread_mutex_unlock (&internal);
  192410. }
  192411. class WaitableEventImpl
  192412. {
  192413. public:
  192414. WaitableEventImpl (const bool manualReset_)
  192415. : triggered (false),
  192416. manualReset (manualReset_)
  192417. {
  192418. pthread_cond_init (&condition, 0);
  192419. pthread_mutex_init (&mutex, 0);
  192420. }
  192421. ~WaitableEventImpl()
  192422. {
  192423. pthread_cond_destroy (&condition);
  192424. pthread_mutex_destroy (&mutex);
  192425. }
  192426. bool wait (const int timeOutMillisecs) throw()
  192427. {
  192428. pthread_mutex_lock (&mutex);
  192429. if (! triggered)
  192430. {
  192431. if (timeOutMillisecs < 0)
  192432. {
  192433. do
  192434. {
  192435. pthread_cond_wait (&condition, &mutex);
  192436. }
  192437. while (! triggered);
  192438. }
  192439. else
  192440. {
  192441. struct timeval now;
  192442. gettimeofday (&now, 0);
  192443. struct timespec time;
  192444. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  192445. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  192446. if (time.tv_nsec >= 1000000000)
  192447. {
  192448. time.tv_nsec -= 1000000000;
  192449. time.tv_sec++;
  192450. }
  192451. do
  192452. {
  192453. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  192454. {
  192455. pthread_mutex_unlock (&mutex);
  192456. return false;
  192457. }
  192458. }
  192459. while (! triggered);
  192460. }
  192461. }
  192462. if (! manualReset)
  192463. triggered = false;
  192464. pthread_mutex_unlock (&mutex);
  192465. return true;
  192466. }
  192467. void signal() throw()
  192468. {
  192469. pthread_mutex_lock (&mutex);
  192470. triggered = true;
  192471. pthread_cond_broadcast (&condition);
  192472. pthread_mutex_unlock (&mutex);
  192473. }
  192474. void reset() throw()
  192475. {
  192476. pthread_mutex_lock (&mutex);
  192477. triggered = false;
  192478. pthread_mutex_unlock (&mutex);
  192479. }
  192480. private:
  192481. pthread_cond_t condition;
  192482. pthread_mutex_t mutex;
  192483. bool triggered;
  192484. const bool manualReset;
  192485. WaitableEventImpl (const WaitableEventImpl&);
  192486. WaitableEventImpl& operator= (const WaitableEventImpl&);
  192487. };
  192488. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  192489. : internal (new WaitableEventImpl (manualReset))
  192490. {
  192491. }
  192492. WaitableEvent::~WaitableEvent() throw()
  192493. {
  192494. delete static_cast <WaitableEventImpl*> (internal);
  192495. }
  192496. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  192497. {
  192498. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  192499. }
  192500. void WaitableEvent::signal() const throw()
  192501. {
  192502. static_cast <WaitableEventImpl*> (internal)->signal();
  192503. }
  192504. void WaitableEvent::reset() const throw()
  192505. {
  192506. static_cast <WaitableEventImpl*> (internal)->reset();
  192507. }
  192508. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  192509. {
  192510. struct timespec time;
  192511. time.tv_sec = millisecs / 1000;
  192512. time.tv_nsec = (millisecs % 1000) * 1000000;
  192513. nanosleep (&time, 0);
  192514. }
  192515. const juce_wchar File::separator = '/';
  192516. const juce_wchar* File::separatorString = L"/";
  192517. const File File::getCurrentWorkingDirectory()
  192518. {
  192519. HeapBlock<char> heapBuffer;
  192520. char localBuffer [1024];
  192521. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  192522. int bufferSize = 4096;
  192523. while (cwd == 0 && errno == ERANGE)
  192524. {
  192525. heapBuffer.malloc (bufferSize);
  192526. cwd = getcwd (heapBuffer, bufferSize - 1);
  192527. bufferSize += 1024;
  192528. }
  192529. return File (String::fromUTF8 (cwd));
  192530. }
  192531. bool File::setAsCurrentWorkingDirectory() const
  192532. {
  192533. return chdir (getFullPathName().toUTF8()) == 0;
  192534. }
  192535. bool juce_copyFile (const String& s, const String& d);
  192536. static bool juce_stat (const String& fileName, struct stat& info)
  192537. {
  192538. return fileName.isNotEmpty()
  192539. && (stat (fileName.toUTF8(), &info) == 0);
  192540. }
  192541. bool juce_isDirectory (const String& fileName)
  192542. {
  192543. struct stat info;
  192544. return fileName.isEmpty()
  192545. || (juce_stat (fileName, info)
  192546. && ((info.st_mode & S_IFDIR) != 0));
  192547. }
  192548. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  192549. {
  192550. if (fileName.isEmpty())
  192551. return false;
  192552. const char* const fileNameUTF8 = fileName.toUTF8();
  192553. bool exists = access (fileNameUTF8, F_OK) == 0;
  192554. if (exists && dontCountDirectories)
  192555. {
  192556. struct stat info;
  192557. const int res = stat (fileNameUTF8, &info);
  192558. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  192559. exists = false;
  192560. }
  192561. return exists;
  192562. }
  192563. int64 juce_getFileSize (const String& fileName)
  192564. {
  192565. struct stat info;
  192566. return juce_stat (fileName, info) ? info.st_size : 0;
  192567. }
  192568. bool juce_canWriteToFile (const String& fileName)
  192569. {
  192570. return access (fileName.toUTF8(), W_OK) == 0;
  192571. }
  192572. bool juce_deleteFile (const String& fileName)
  192573. {
  192574. if (juce_isDirectory (fileName))
  192575. return rmdir (fileName.toUTF8()) == 0;
  192576. else
  192577. return remove (fileName.toUTF8()) == 0;
  192578. }
  192579. bool juce_moveFile (const String& source, const String& dest)
  192580. {
  192581. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  192582. return true;
  192583. if (juce_canWriteToFile (source)
  192584. && juce_copyFile (source, dest))
  192585. {
  192586. if (juce_deleteFile (source))
  192587. return true;
  192588. juce_deleteFile (dest);
  192589. }
  192590. return false;
  192591. }
  192592. void juce_createDirectory (const String& fileName)
  192593. {
  192594. mkdir (fileName.toUTF8(), 0777);
  192595. }
  192596. void* juce_fileOpen (const String& fileName, bool forWriting)
  192597. {
  192598. int flags = O_RDONLY;
  192599. if (forWriting)
  192600. {
  192601. if (juce_fileExists (fileName, false))
  192602. {
  192603. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  192604. if (f != -1)
  192605. lseek (f, 0, SEEK_END);
  192606. return (void*) f;
  192607. }
  192608. else
  192609. {
  192610. flags = O_RDWR + O_CREAT;
  192611. }
  192612. }
  192613. return (void*) open (fileName.toUTF8(), flags, 00644);
  192614. }
  192615. void juce_fileClose (void* handle)
  192616. {
  192617. if (handle != 0)
  192618. close ((int) (pointer_sized_int) handle);
  192619. }
  192620. int juce_fileRead (void* handle, void* buffer, int size)
  192621. {
  192622. if (handle != 0)
  192623. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  192624. return 0;
  192625. }
  192626. int juce_fileWrite (void* handle, const void* buffer, int size)
  192627. {
  192628. if (handle != 0)
  192629. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  192630. return 0;
  192631. }
  192632. int64 juce_fileSetPosition (void* handle, int64 pos)
  192633. {
  192634. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  192635. return pos;
  192636. return -1;
  192637. }
  192638. int64 juce_fileGetPosition (void* handle)
  192639. {
  192640. if (handle != 0)
  192641. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  192642. return -1;
  192643. }
  192644. void juce_fileFlush (void* handle)
  192645. {
  192646. if (handle != 0)
  192647. fsync ((int) (pointer_sized_int) handle);
  192648. }
  192649. const File juce_getExecutableFile()
  192650. {
  192651. Dl_info exeInfo;
  192652. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  192653. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  192654. }
  192655. // if this file doesn't exist, find a parent of it that does..
  192656. static bool doStatFS (const File* file, struct statfs& result)
  192657. {
  192658. File f (*file);
  192659. for (int i = 5; --i >= 0;)
  192660. {
  192661. if (f.exists())
  192662. break;
  192663. f = f.getParentDirectory();
  192664. }
  192665. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  192666. }
  192667. int64 File::getBytesFreeOnVolume() const
  192668. {
  192669. struct statfs buf;
  192670. if (doStatFS (this, buf))
  192671. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  192672. return 0;
  192673. }
  192674. int64 File::getVolumeTotalSize() const
  192675. {
  192676. struct statfs buf;
  192677. if (doStatFS (this, buf))
  192678. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  192679. return 0;
  192680. }
  192681. const String juce_getVolumeLabel (const String& filenameOnVolume,
  192682. int& volumeSerialNumber)
  192683. {
  192684. volumeSerialNumber = 0;
  192685. #if JUCE_MAC
  192686. struct VolAttrBuf
  192687. {
  192688. u_int32_t length;
  192689. attrreference_t mountPointRef;
  192690. char mountPointSpace [MAXPATHLEN];
  192691. } attrBuf;
  192692. struct attrlist attrList;
  192693. zerostruct (attrList);
  192694. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  192695. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  192696. File f (filenameOnVolume);
  192697. for (;;)
  192698. {
  192699. if (getattrlist (f.getFullPathName().toUTF8(),
  192700. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  192701. {
  192702. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  192703. (int) attrBuf.mountPointRef.attr_length);
  192704. }
  192705. const File parent (f.getParentDirectory());
  192706. if (f == parent)
  192707. break;
  192708. f = parent;
  192709. }
  192710. #endif
  192711. return String::empty;
  192712. }
  192713. void juce_runSystemCommand (const String& command)
  192714. {
  192715. int result = system (command.toUTF8());
  192716. (void) result;
  192717. }
  192718. const String juce_getOutputFromCommand (const String& command)
  192719. {
  192720. // slight bodge here, as we just pipe the output into a temp file and read it...
  192721. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  192722. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  192723. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  192724. String result (tempFile.loadFileAsString());
  192725. tempFile.deleteFile();
  192726. return result;
  192727. }
  192728. class InterProcessLock::Pimpl
  192729. {
  192730. public:
  192731. Pimpl (const String& name, const int timeOutMillisecs)
  192732. : handle (0), refCount (1)
  192733. {
  192734. #if JUCE_MAC
  192735. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  192736. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  192737. #else
  192738. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  192739. #endif
  192740. temp.create();
  192741. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  192742. if (handle != 0)
  192743. {
  192744. struct flock fl;
  192745. zerostruct (fl);
  192746. fl.l_whence = SEEK_SET;
  192747. fl.l_type = F_WRLCK;
  192748. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  192749. for (;;)
  192750. {
  192751. const int result = fcntl (handle, F_SETLK, &fl);
  192752. if (result >= 0)
  192753. return;
  192754. if (errno != EINTR)
  192755. {
  192756. if (timeOutMillisecs == 0
  192757. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  192758. break;
  192759. Thread::sleep (10);
  192760. }
  192761. }
  192762. }
  192763. closeFile();
  192764. }
  192765. ~Pimpl()
  192766. {
  192767. closeFile();
  192768. }
  192769. void closeFile()
  192770. {
  192771. if (handle != 0)
  192772. {
  192773. struct flock fl;
  192774. zerostruct (fl);
  192775. fl.l_whence = SEEK_SET;
  192776. fl.l_type = F_UNLCK;
  192777. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  192778. {}
  192779. close (handle);
  192780. handle = 0;
  192781. }
  192782. }
  192783. int handle, refCount;
  192784. };
  192785. InterProcessLock::InterProcessLock (const String& name_)
  192786. : name (name_)
  192787. {
  192788. }
  192789. InterProcessLock::~InterProcessLock()
  192790. {
  192791. }
  192792. bool InterProcessLock::enter (const int timeOutMillisecs)
  192793. {
  192794. const ScopedLock sl (lock);
  192795. if (pimpl == 0)
  192796. {
  192797. pimpl = new Pimpl (name, timeOutMillisecs);
  192798. if (pimpl->handle == 0)
  192799. pimpl = 0;
  192800. }
  192801. else
  192802. {
  192803. pimpl->refCount++;
  192804. }
  192805. return pimpl != 0;
  192806. }
  192807. void InterProcessLock::exit()
  192808. {
  192809. const ScopedLock sl (lock);
  192810. // Trying to release the lock too many times!
  192811. jassert (pimpl != 0);
  192812. if (pimpl != 0 && --(pimpl->refCount) == 0)
  192813. pimpl = 0;
  192814. }
  192815. /*** End of inlined file: juce_posix_SharedCode.h ***/
  192816. /*** Start of inlined file: juce_linux_Files.cpp ***/
  192817. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  192818. // compiled on its own).
  192819. #if JUCE_INCLUDED_FILE
  192820. static const short U_ISOFS_SUPER_MAGIC = 0x9660; // linux/iso_fs.h
  192821. static const short U_MSDOS_SUPER_MAGIC = 0x4d44; // linux/msdos_fs.h
  192822. static const short U_NFS_SUPER_MAGIC = 0x6969; // linux/nfs_fs.h
  192823. static const short U_SMB_SUPER_MAGIC = 0x517B; // linux/smb_fs.h
  192824. void juce_getFileTimes (const String& fileName,
  192825. int64& modificationTime,
  192826. int64& accessTime,
  192827. int64& creationTime)
  192828. {
  192829. modificationTime = 0;
  192830. accessTime = 0;
  192831. creationTime = 0;
  192832. struct stat info;
  192833. const int res = stat (fileName.toUTF8(), &info);
  192834. if (res == 0)
  192835. {
  192836. modificationTime = (int64) info.st_mtime * 1000;
  192837. accessTime = (int64) info.st_atime * 1000;
  192838. creationTime = (int64) info.st_ctime * 1000;
  192839. }
  192840. }
  192841. bool juce_setFileTimes (const String& fileName,
  192842. int64 modificationTime,
  192843. int64 accessTime,
  192844. int64 creationTime)
  192845. {
  192846. struct utimbuf times;
  192847. times.actime = (time_t) (accessTime / 1000);
  192848. times.modtime = (time_t) (modificationTime / 1000);
  192849. return utime (fileName.toUTF8(), &times) == 0;
  192850. }
  192851. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  192852. {
  192853. struct stat info;
  192854. const int res = stat (fileName.toUTF8(), &info);
  192855. if (res != 0)
  192856. return false;
  192857. info.st_mode &= 0777; // Just permissions
  192858. if( isReadOnly )
  192859. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  192860. else
  192861. // Give everybody write permission?
  192862. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  192863. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  192864. }
  192865. bool juce_copyFile (const String& s, const String& d)
  192866. {
  192867. const File source (s), dest (d);
  192868. FileInputStream* in = source.createInputStream();
  192869. bool ok = false;
  192870. if (in != 0)
  192871. {
  192872. if (dest.deleteFile())
  192873. {
  192874. FileOutputStream* const out = dest.createOutputStream();
  192875. if (out != 0)
  192876. {
  192877. const int bytesCopied = out->writeFromInputStream (*in, -1);
  192878. delete out;
  192879. ok = (bytesCopied == source.getSize());
  192880. if (! ok)
  192881. dest.deleteFile();
  192882. }
  192883. }
  192884. delete in;
  192885. }
  192886. return ok;
  192887. }
  192888. const StringArray juce_getFileSystemRoots()
  192889. {
  192890. StringArray s;
  192891. s.add ("/");
  192892. return s;
  192893. }
  192894. bool File::isOnCDRomDrive() const
  192895. {
  192896. struct statfs buf;
  192897. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192898. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  192899. // Assume not if this fails for some reason
  192900. return false;
  192901. }
  192902. bool File::isOnHardDisk() const
  192903. {
  192904. struct statfs buf;
  192905. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  192906. {
  192907. switch (buf.f_type)
  192908. {
  192909. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  192910. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  192911. case U_NFS_SUPER_MAGIC: // Network NFS
  192912. case U_SMB_SUPER_MAGIC: // Network Samba
  192913. return false;
  192914. default:
  192915. // Assume anything else is a hard-disk (but note it could
  192916. // be a RAM disk. There isn't a good way of determining
  192917. // this for sure)
  192918. return true;
  192919. }
  192920. }
  192921. // Assume so if this fails for some reason
  192922. return true;
  192923. }
  192924. bool File::isOnRemovableDrive() const
  192925. {
  192926. jassertfalse // xxx not implemented for linux!
  192927. return false;
  192928. }
  192929. bool File::isHidden() const
  192930. {
  192931. return getFileName().startsWithChar ('.');
  192932. }
  192933. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  192934. const File File::getSpecialLocation (const SpecialLocationType type)
  192935. {
  192936. switch (type)
  192937. {
  192938. case userHomeDirectory:
  192939. {
  192940. const char* homeDir = getenv ("HOME");
  192941. if (homeDir == 0)
  192942. {
  192943. struct passwd* const pw = getpwuid (getuid());
  192944. if (pw != 0)
  192945. homeDir = pw->pw_dir;
  192946. }
  192947. return File (String::fromUTF8 (homeDir));
  192948. }
  192949. case userDocumentsDirectory:
  192950. case userMusicDirectory:
  192951. case userMoviesDirectory:
  192952. case userApplicationDataDirectory:
  192953. return File ("~");
  192954. case userDesktopDirectory:
  192955. return File ("~/Desktop");
  192956. case commonApplicationDataDirectory:
  192957. return File ("/var");
  192958. case globalApplicationsDirectory:
  192959. return File ("/usr");
  192960. case tempDirectory:
  192961. {
  192962. File tmp ("/var/tmp");
  192963. if (! tmp.isDirectory())
  192964. {
  192965. tmp = "/tmp";
  192966. if (! tmp.isDirectory())
  192967. tmp = File::getCurrentWorkingDirectory();
  192968. }
  192969. return tmp;
  192970. }
  192971. case invokedExecutableFile:
  192972. if (juce_Argv0 != 0)
  192973. return File (String::fromUTF8 (juce_Argv0));
  192974. // deliberate fall-through...
  192975. case currentExecutableFile:
  192976. case currentApplicationFile:
  192977. return juce_getExecutableFile();
  192978. default:
  192979. jassertfalse // unknown type?
  192980. break;
  192981. }
  192982. return File::nonexistent;
  192983. }
  192984. const String File::getVersion() const
  192985. {
  192986. return String::empty; // xxx not yet implemented
  192987. }
  192988. const File File::getLinkedTarget() const
  192989. {
  192990. char buffer [4096];
  192991. size_t numChars = readlink (getFullPathName().toUTF8(),
  192992. buffer, sizeof (buffer));
  192993. if (numChars > 0 && numChars <= sizeof (buffer))
  192994. return File (String::fromUTF8 (buffer, (int) numChars));
  192995. return *this;
  192996. }
  192997. bool File::moveToTrash() const
  192998. {
  192999. if (! exists())
  193000. return true;
  193001. File trashCan ("~/.Trash");
  193002. if (! trashCan.isDirectory())
  193003. trashCan = "~/.local/share/Trash/files";
  193004. if (! trashCan.isDirectory())
  193005. return false;
  193006. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193007. getFileExtension()));
  193008. }
  193009. struct FindFileStruct
  193010. {
  193011. String parentDir, wildCard;
  193012. DIR* dir;
  193013. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193014. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193015. {
  193016. const char* const wildcardUTF8 = wildCard.toUTF8();
  193017. for (;;)
  193018. {
  193019. struct dirent* const de = readdir (dir);
  193020. if (de == 0)
  193021. break;
  193022. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193023. {
  193024. result = String::fromUTF8 (de->d_name);
  193025. const String path (parentDir + result);
  193026. if (isDir != 0 || fileSize != 0)
  193027. {
  193028. struct stat info;
  193029. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193030. if (isDir != 0)
  193031. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193032. if (isHidden != 0)
  193033. *isHidden = (de->d_name[0] == '.');
  193034. if (fileSize != 0)
  193035. *fileSize = statOk ? info.st_size : 0;
  193036. }
  193037. if (modTime != 0 || creationTime != 0)
  193038. {
  193039. int64 m, a, c;
  193040. juce_getFileTimes (path, m, a, c);
  193041. if (modTime != 0)
  193042. *modTime = m;
  193043. if (creationTime != 0)
  193044. *creationTime = c;
  193045. }
  193046. if (isReadOnly != 0)
  193047. *isReadOnly = ! juce_canWriteToFile (path);
  193048. return true;
  193049. }
  193050. }
  193051. return false;
  193052. }
  193053. };
  193054. // returns 0 on failure
  193055. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193056. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193057. Time* creationTime, bool* isReadOnly)
  193058. {
  193059. DIR* d = opendir (directory.toUTF8());
  193060. if (d != 0)
  193061. {
  193062. FindFileStruct* ff = new FindFileStruct();
  193063. ff->parentDir = directory;
  193064. if (!ff->parentDir.endsWithChar (File::separator))
  193065. ff->parentDir += File::separator;
  193066. ff->wildCard = wildCard;
  193067. if (wildCard == "*.*")
  193068. ff->wildCard = "*";
  193069. ff->dir = d;
  193070. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193071. {
  193072. return ff;
  193073. }
  193074. else
  193075. {
  193076. firstResultFile = String::empty;
  193077. isDir = false;
  193078. isHidden = false;
  193079. closedir (d);
  193080. delete ff;
  193081. }
  193082. }
  193083. return 0;
  193084. }
  193085. bool juce_findFileNext (void* handle, String& resultFile,
  193086. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193087. {
  193088. FindFileStruct* const ff = (FindFileStruct*) handle;
  193089. if (ff != 0)
  193090. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193091. return false;
  193092. }
  193093. void juce_findFileClose (void* handle)
  193094. {
  193095. FindFileStruct* const ff = (FindFileStruct*) handle;
  193096. if (ff != 0)
  193097. {
  193098. closedir (ff->dir);
  193099. delete ff;
  193100. }
  193101. }
  193102. bool juce_launchFile (const String& fileName,
  193103. const String& parameters)
  193104. {
  193105. String cmdString (fileName.replace (" ", "\\ ",false));
  193106. cmdString << " " << parameters;
  193107. if (URL::isProbablyAWebsiteURL (fileName)
  193108. || cmdString.startsWithIgnoreCase ("file:")
  193109. || URL::isProbablyAnEmailAddress (fileName))
  193110. {
  193111. // create a command that tries to launch a bunch of likely browsers
  193112. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193113. StringArray cmdLines;
  193114. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193115. cmdLines.add (String (browserNames[i]) + " " + cmdString.trim().quoted());
  193116. cmdString = cmdLines.joinIntoString (" || ");
  193117. }
  193118. const char* const argv[4] = { "/bin/sh", "-c", cmdString.toUTF8(), 0 };
  193119. const int cpid = fork();
  193120. if (cpid == 0)
  193121. {
  193122. setsid();
  193123. // Child process
  193124. execve (argv[0], (char**) argv, environ);
  193125. exit (0);
  193126. }
  193127. return cpid >= 0;
  193128. }
  193129. void File::revealToUser() const
  193130. {
  193131. if (isDirectory())
  193132. startAsProcess();
  193133. else if (getParentDirectory().exists())
  193134. getParentDirectory().startAsProcess();
  193135. }
  193136. #endif
  193137. /*** End of inlined file: juce_linux_Files.cpp ***/
  193138. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193139. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193140. // compiled on its own).
  193141. #if JUCE_INCLUDED_FILE
  193142. struct NamedPipeInternal
  193143. {
  193144. String pipeInName, pipeOutName;
  193145. int pipeIn, pipeOut;
  193146. bool volatile createdPipe, blocked, stopReadOperation;
  193147. static void signalHandler (int) {}
  193148. };
  193149. void NamedPipe::cancelPendingReads()
  193150. {
  193151. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193152. {
  193153. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193154. intern->stopReadOperation = true;
  193155. char buffer [1] = { 0 };
  193156. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193157. (void) bytesWritten;
  193158. int timeout = 2000;
  193159. while (intern->blocked && --timeout >= 0)
  193160. Thread::sleep (2);
  193161. intern->stopReadOperation = false;
  193162. }
  193163. }
  193164. void NamedPipe::close()
  193165. {
  193166. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193167. if (intern != 0)
  193168. {
  193169. internal = 0;
  193170. if (intern->pipeIn != -1)
  193171. ::close (intern->pipeIn);
  193172. if (intern->pipeOut != -1)
  193173. ::close (intern->pipeOut);
  193174. if (intern->createdPipe)
  193175. {
  193176. unlink (intern->pipeInName.toUTF8());
  193177. unlink (intern->pipeOutName.toUTF8());
  193178. }
  193179. delete intern;
  193180. }
  193181. }
  193182. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193183. {
  193184. close();
  193185. NamedPipeInternal* const intern = new NamedPipeInternal();
  193186. internal = intern;
  193187. intern->createdPipe = createPipe;
  193188. intern->blocked = false;
  193189. intern->stopReadOperation = false;
  193190. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193191. siginterrupt (SIGPIPE, 1);
  193192. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  193193. intern->pipeInName = pipePath + "_in";
  193194. intern->pipeOutName = pipePath + "_out";
  193195. intern->pipeIn = -1;
  193196. intern->pipeOut = -1;
  193197. if (createPipe)
  193198. {
  193199. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193200. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193201. {
  193202. delete intern;
  193203. internal = 0;
  193204. return false;
  193205. }
  193206. }
  193207. return true;
  193208. }
  193209. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193210. {
  193211. int bytesRead = -1;
  193212. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193213. if (intern != 0)
  193214. {
  193215. intern->blocked = true;
  193216. if (intern->pipeIn == -1)
  193217. {
  193218. if (intern->createdPipe)
  193219. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193220. else
  193221. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193222. if (intern->pipeIn == -1)
  193223. {
  193224. intern->blocked = false;
  193225. return -1;
  193226. }
  193227. }
  193228. bytesRead = 0;
  193229. char* p = (char*) destBuffer;
  193230. while (bytesRead < maxBytesToRead)
  193231. {
  193232. const int bytesThisTime = maxBytesToRead - bytesRead;
  193233. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193234. if (numRead <= 0 || intern->stopReadOperation)
  193235. {
  193236. bytesRead = -1;
  193237. break;
  193238. }
  193239. bytesRead += numRead;
  193240. p += bytesRead;
  193241. }
  193242. intern->blocked = false;
  193243. }
  193244. return bytesRead;
  193245. }
  193246. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193247. {
  193248. int bytesWritten = -1;
  193249. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193250. if (intern != 0)
  193251. {
  193252. if (intern->pipeOut == -1)
  193253. {
  193254. if (intern->createdPipe)
  193255. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193256. else
  193257. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193258. if (intern->pipeOut == -1)
  193259. {
  193260. return -1;
  193261. }
  193262. }
  193263. const char* p = (const char*) sourceBuffer;
  193264. bytesWritten = 0;
  193265. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193266. while (bytesWritten < numBytesToWrite
  193267. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193268. {
  193269. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193270. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193271. if (numWritten <= 0)
  193272. {
  193273. bytesWritten = -1;
  193274. break;
  193275. }
  193276. bytesWritten += numWritten;
  193277. p += bytesWritten;
  193278. }
  193279. }
  193280. return bytesWritten;
  193281. }
  193282. #endif
  193283. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193284. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193285. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193286. // compiled on its own).
  193287. #if JUCE_INCLUDED_FILE
  193288. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  193289. {
  193290. int numResults = 0;
  193291. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193292. if (s != -1)
  193293. {
  193294. char buf [1024];
  193295. struct ifconf ifc;
  193296. ifc.ifc_len = sizeof (buf);
  193297. ifc.ifc_buf = buf;
  193298. ioctl (s, SIOCGIFCONF, &ifc);
  193299. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193300. {
  193301. struct ifreq ifr;
  193302. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193303. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193304. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193305. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193306. && numResults < maxNum)
  193307. {
  193308. int64 a = 0;
  193309. for (int j = 6; --j >= 0;)
  193310. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193311. *addresses++ = a;
  193312. ++numResults;
  193313. }
  193314. }
  193315. close (s);
  193316. }
  193317. return numResults;
  193318. }
  193319. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193320. const String& emailSubject,
  193321. const String& bodyText,
  193322. const StringArray& filesToAttach)
  193323. {
  193324. jassertfalse // xxx todo
  193325. return false;
  193326. }
  193327. class JUCE_HTTPSocketStream
  193328. {
  193329. public:
  193330. JUCE_HTTPSocketStream()
  193331. : readPosition (0),
  193332. socketHandle (-1),
  193333. levelsOfRedirection (0),
  193334. timeoutSeconds (15)
  193335. {
  193336. }
  193337. ~JUCE_HTTPSocketStream()
  193338. {
  193339. closeSocket();
  193340. }
  193341. bool open (const String& url,
  193342. const String& headers,
  193343. const MemoryBlock& postData,
  193344. const bool isPost,
  193345. URL::OpenStreamProgressCallback* callback,
  193346. void* callbackContext,
  193347. int timeOutMs)
  193348. {
  193349. closeSocket();
  193350. uint32 timeOutTime = Time::getMillisecondCounter();
  193351. if (timeOutMs == 0)
  193352. timeOutTime += 60000;
  193353. else if (timeOutMs < 0)
  193354. timeOutTime = 0xffffffff;
  193355. else
  193356. timeOutTime += timeOutMs;
  193357. String hostName, hostPath;
  193358. int hostPort;
  193359. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193360. return false;
  193361. const struct hostent* host = 0;
  193362. int port = 0;
  193363. String proxyName, proxyPath;
  193364. int proxyPort = 0;
  193365. String proxyURL (getenv ("http_proxy"));
  193366. if (proxyURL.startsWithIgnoreCase ("http://"))
  193367. {
  193368. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193369. return false;
  193370. host = gethostbyname (proxyName.toUTF8());
  193371. port = proxyPort;
  193372. }
  193373. else
  193374. {
  193375. host = gethostbyname (hostName.toUTF8());
  193376. port = hostPort;
  193377. }
  193378. if (host == 0)
  193379. return false;
  193380. struct sockaddr_in address;
  193381. zerostruct (address);
  193382. memcpy (&address.sin_addr, host->h_addr, host->h_length);
  193383. address.sin_family = host->h_addrtype;
  193384. address.sin_port = htons (port);
  193385. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193386. if (socketHandle == -1)
  193387. return false;
  193388. int receiveBufferSize = 16384;
  193389. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193390. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193391. #if JUCE_MAC
  193392. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193393. #endif
  193394. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193395. {
  193396. closeSocket();
  193397. return false;
  193398. }
  193399. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193400. proxyName, proxyPort,
  193401. hostPath, url,
  193402. headers, postData,
  193403. isPost));
  193404. size_t totalHeaderSent = 0;
  193405. while (totalHeaderSent < requestHeader.getSize())
  193406. {
  193407. if (Time::getMillisecondCounter() > timeOutTime)
  193408. {
  193409. closeSocket();
  193410. return false;
  193411. }
  193412. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193413. if (send (socketHandle,
  193414. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193415. numToSend, 0)
  193416. != numToSend)
  193417. {
  193418. closeSocket();
  193419. return false;
  193420. }
  193421. totalHeaderSent += numToSend;
  193422. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193423. {
  193424. closeSocket();
  193425. return false;
  193426. }
  193427. }
  193428. const String responseHeader (readResponse (timeOutTime));
  193429. if (responseHeader.isNotEmpty())
  193430. {
  193431. //DBG (responseHeader);
  193432. StringArray lines;
  193433. lines.addLines (responseHeader);
  193434. const int statusCode = responseHeader.fromFirstOccurrenceOf (" ", false, false)
  193435. .substring (0, 3).getIntValue();
  193436. //int contentLength = findHeaderItem (lines, "Content-Length:").getIntValue();
  193437. //bool isChunked = findHeaderItem (lines, "Transfer-Encoding:").equalsIgnoreCase ("chunked");
  193438. String location (findHeaderItem (lines, "Location:"));
  193439. if (statusCode >= 300 && statusCode < 400
  193440. && location.isNotEmpty())
  193441. {
  193442. if (! location.startsWithIgnoreCase ("http://"))
  193443. location = "http://" + location;
  193444. if (levelsOfRedirection++ < 3)
  193445. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  193446. }
  193447. else
  193448. {
  193449. levelsOfRedirection = 0;
  193450. return true;
  193451. }
  193452. }
  193453. closeSocket();
  193454. return false;
  193455. }
  193456. int read (void* buffer, int bytesToRead)
  193457. {
  193458. fd_set readbits;
  193459. FD_ZERO (&readbits);
  193460. FD_SET (socketHandle, &readbits);
  193461. struct timeval tv;
  193462. tv.tv_sec = timeoutSeconds;
  193463. tv.tv_usec = 0;
  193464. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193465. return 0; // (timeout)
  193466. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  193467. readPosition += bytesRead;
  193468. return bytesRead;
  193469. }
  193470. int readPosition;
  193471. juce_UseDebuggingNewOperator
  193472. private:
  193473. int socketHandle, levelsOfRedirection;
  193474. const int timeoutSeconds;
  193475. void closeSocket()
  193476. {
  193477. if (socketHandle >= 0)
  193478. close (socketHandle);
  193479. socketHandle = -1;
  193480. }
  193481. const MemoryBlock createRequestHeader (const String& hostName,
  193482. const int hostPort,
  193483. const String& proxyName,
  193484. const int proxyPort,
  193485. const String& hostPath,
  193486. const String& originalURL,
  193487. const String& headers,
  193488. const MemoryBlock& postData,
  193489. const bool isPost)
  193490. {
  193491. String header (isPost ? "POST " : "GET ");
  193492. if (proxyName.isEmpty())
  193493. {
  193494. header << hostPath << " HTTP/1.0\r\nHost: "
  193495. << hostName << ':' << hostPort;
  193496. }
  193497. else
  193498. {
  193499. header << originalURL << " HTTP/1.0\r\nHost: "
  193500. << proxyName << ':' << proxyPort;
  193501. }
  193502. header << "\r\nUser-Agent: JUCE/"
  193503. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  193504. << "\r\nConnection: Close\r\nContent-Length: "
  193505. << postData.getSize() << "\r\n"
  193506. << headers << "\r\n";
  193507. MemoryBlock mb;
  193508. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  193509. mb.append (postData.getData(), postData.getSize());
  193510. return mb;
  193511. }
  193512. const String readResponse (const uint32 timeOutTime)
  193513. {
  193514. int bytesRead = 0, numConsecutiveLFs = 0;
  193515. MemoryBlock buffer (1024, true);
  193516. while (numConsecutiveLFs < 2 && bytesRead < 32768
  193517. && Time::getMillisecondCounter() <= timeOutTime)
  193518. {
  193519. fd_set readbits;
  193520. FD_ZERO (&readbits);
  193521. FD_SET (socketHandle, &readbits);
  193522. struct timeval tv;
  193523. tv.tv_sec = timeoutSeconds;
  193524. tv.tv_usec = 0;
  193525. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  193526. return String::empty; // (timeout)
  193527. buffer.ensureSize (bytesRead + 8, true);
  193528. char* const dest = (char*) buffer.getData() + bytesRead;
  193529. if (recv (socketHandle, dest, 1, 0) == -1)
  193530. return String::empty;
  193531. const char lastByte = *dest;
  193532. ++bytesRead;
  193533. if (lastByte == '\n')
  193534. ++numConsecutiveLFs;
  193535. else if (lastByte != '\r')
  193536. numConsecutiveLFs = 0;
  193537. }
  193538. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  193539. if (header.startsWithIgnoreCase ("HTTP/"))
  193540. return header.trimEnd();
  193541. return String::empty;
  193542. }
  193543. static bool decomposeURL (const String& url,
  193544. String& host, String& path, int& port)
  193545. {
  193546. if (! url.startsWithIgnoreCase ("http://"))
  193547. return false;
  193548. const int nextSlash = url.indexOfChar (7, '/');
  193549. int nextColon = url.indexOfChar (7, ':');
  193550. if (nextColon > nextSlash && nextSlash > 0)
  193551. nextColon = -1;
  193552. if (nextColon >= 0)
  193553. {
  193554. host = url.substring (7, nextColon);
  193555. if (nextSlash >= 0)
  193556. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  193557. else
  193558. port = url.substring (nextColon + 1).getIntValue();
  193559. }
  193560. else
  193561. {
  193562. port = 80;
  193563. if (nextSlash >= 0)
  193564. host = url.substring (7, nextSlash);
  193565. else
  193566. host = url.substring (7);
  193567. }
  193568. if (nextSlash >= 0)
  193569. path = url.substring (nextSlash);
  193570. else
  193571. path = "/";
  193572. return true;
  193573. }
  193574. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  193575. {
  193576. for (int i = 0; i < lines.size(); ++i)
  193577. if (lines[i].startsWithIgnoreCase (itemName))
  193578. return lines[i].substring (itemName.length()).trim();
  193579. return String::empty;
  193580. }
  193581. };
  193582. bool juce_isOnLine()
  193583. {
  193584. return true;
  193585. }
  193586. void* juce_openInternetFile (const String& url,
  193587. const String& headers,
  193588. const MemoryBlock& postData,
  193589. const bool isPost,
  193590. URL::OpenStreamProgressCallback* callback,
  193591. void* callbackContext,
  193592. int timeOutMs)
  193593. {
  193594. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  193595. if (s->open (url, headers, postData, isPost,
  193596. callback, callbackContext, timeOutMs))
  193597. return s;
  193598. delete s;
  193599. return 0;
  193600. }
  193601. void juce_closeInternetFile (void* handle)
  193602. {
  193603. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193604. if (s != 0)
  193605. delete s;
  193606. }
  193607. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  193608. {
  193609. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193610. if (s != 0)
  193611. return s->read (buffer, bytesToRead);
  193612. return 0;
  193613. }
  193614. int64 juce_getInternetFileContentLength (void* handle)
  193615. {
  193616. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193617. if (s != 0)
  193618. {
  193619. //xxx todo
  193620. jassertfalse
  193621. }
  193622. return -1;
  193623. }
  193624. int juce_seekInInternetFile (void* handle, int newPosition)
  193625. {
  193626. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  193627. if (s != 0)
  193628. return s->readPosition;
  193629. return 0;
  193630. }
  193631. #endif
  193632. /*** End of inlined file: juce_linux_Network.cpp ***/
  193633. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  193634. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193635. // compiled on its own).
  193636. #if JUCE_INCLUDED_FILE
  193637. void Logger::outputDebugString (const String& text) throw()
  193638. {
  193639. std::cerr << text << std::endl;
  193640. }
  193641. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  193642. {
  193643. return Linux;
  193644. }
  193645. const String SystemStats::getOperatingSystemName() throw()
  193646. {
  193647. return "Linux";
  193648. }
  193649. bool SystemStats::isOperatingSystem64Bit() throw()
  193650. {
  193651. #if JUCE_64BIT
  193652. return true;
  193653. #else
  193654. //xxx not sure how to find this out?..
  193655. return false;
  193656. #endif
  193657. }
  193658. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  193659. {
  193660. String info;
  193661. char buf [256];
  193662. FILE* f = fopen ("/proc/cpuinfo", "r");
  193663. while (f != 0 && fgets (buf, sizeof(buf), f))
  193664. {
  193665. if (strncmp (buf, key, strlen (key)) == 0)
  193666. {
  193667. char* p = buf;
  193668. while (*p && *p != '\n')
  193669. ++p;
  193670. if (*p != 0)
  193671. *p = 0;
  193672. p = buf;
  193673. while (*p != 0 && *p != ':')
  193674. ++p;
  193675. if (*p != 0 && *(p + 1) != 0)
  193676. info = p + 2;
  193677. if (! lastOne)
  193678. break;
  193679. }
  193680. }
  193681. fclose (f);
  193682. return info;
  193683. }
  193684. bool SystemStats::hasMMX() throw()
  193685. {
  193686. return getCpuInfo ("flags").contains ("mmx");
  193687. }
  193688. bool SystemStats::hasSSE() throw()
  193689. {
  193690. return getCpuInfo ("flags").contains ("sse");
  193691. }
  193692. bool SystemStats::hasSSE2() throw()
  193693. {
  193694. return getCpuInfo ("flags").contains ("sse2");
  193695. }
  193696. bool SystemStats::has3DNow() throw()
  193697. {
  193698. return getCpuInfo ("flags").contains ("3dnow");
  193699. }
  193700. const String SystemStats::getCpuVendor() throw()
  193701. {
  193702. return getCpuInfo ("vendor_id");
  193703. }
  193704. int SystemStats::getCpuSpeedInMegaherz() throw()
  193705. {
  193706. const String speed (getCpuInfo ("cpu MHz"));
  193707. return (int) (speed.getFloatValue() + 0.5f);
  193708. }
  193709. int SystemStats::getMemorySizeInMegabytes() throw()
  193710. {
  193711. struct sysinfo sysi;
  193712. if (sysinfo (&sysi) == 0)
  193713. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  193714. return 0;
  193715. }
  193716. uint32 juce_millisecondsSinceStartup() throw()
  193717. {
  193718. static unsigned int calibrate = 0;
  193719. static bool calibrated = false;
  193720. timeval t;
  193721. unsigned int ret = 0;
  193722. if (! gettimeofday (&t, 0))
  193723. {
  193724. if (! calibrated)
  193725. {
  193726. struct sysinfo sysi;
  193727. if (sysinfo (&sysi) == 0)
  193728. // Safe to assume system was not brought up earlier than 1970!
  193729. calibrate = t.tv_sec - sysi.uptime;
  193730. calibrated = true;
  193731. }
  193732. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  193733. }
  193734. return ret;
  193735. }
  193736. double Time::getMillisecondCounterHiRes() throw()
  193737. {
  193738. return getHighResolutionTicks() * 0.001;
  193739. }
  193740. int64 Time::getHighResolutionTicks() throw()
  193741. {
  193742. timeval t;
  193743. if (gettimeofday (&t, 0))
  193744. return 0;
  193745. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  193746. }
  193747. int64 Time::getHighResolutionTicksPerSecond() throw()
  193748. {
  193749. // Microseconds
  193750. return 1000000;
  193751. }
  193752. bool Time::setSystemTimeToThisTime() const throw()
  193753. {
  193754. timeval t;
  193755. t.tv_sec = millisSinceEpoch % 1000000;
  193756. t.tv_usec = millisSinceEpoch - t.tv_sec;
  193757. return settimeofday (&t, NULL) ? false : true;
  193758. }
  193759. int SystemStats::getPageSize() throw()
  193760. {
  193761. static int systemPageSize = 0;
  193762. if (systemPageSize == 0)
  193763. systemPageSize = sysconf (_SC_PAGESIZE);
  193764. return systemPageSize;
  193765. }
  193766. int SystemStats::getNumCpus() throw()
  193767. {
  193768. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  193769. return lastCpu + 1;
  193770. }
  193771. const String SystemStats::getLogonName()
  193772. {
  193773. const char* user = getenv ("USER");
  193774. if (user == 0)
  193775. {
  193776. struct passwd* const pw = getpwuid (getuid());
  193777. if (pw != 0)
  193778. user = pw->pw_name;
  193779. }
  193780. return String::fromUTF8 (user);
  193781. }
  193782. const String SystemStats::getFullUserName()
  193783. {
  193784. return getLogonName();
  193785. }
  193786. void SystemStats::initialiseStats() throw()
  193787. {
  193788. // Process starts off as root when running suid
  193789. Process::lowerPrivilege();
  193790. String s (SystemStats::getJUCEVersion());
  193791. }
  193792. void PlatformUtilities::fpuReset()
  193793. {
  193794. }
  193795. #endif
  193796. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  193797. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  193798. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193799. // compiled on its own).
  193800. #if JUCE_INCLUDED_FILE
  193801. void JUCE_API juce_threadEntryPoint (void*);
  193802. void* threadEntryProc (void* value)
  193803. {
  193804. // New threads start off as root when running suid
  193805. Process::lowerPrivilege();
  193806. juce_threadEntryPoint (value);
  193807. return 0;
  193808. }
  193809. void* juce_createThread (void* userData)
  193810. {
  193811. pthread_t handle = 0;
  193812. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  193813. {
  193814. pthread_detach (handle);
  193815. return (void*) handle;
  193816. }
  193817. return 0;
  193818. }
  193819. void juce_killThread (void* handle)
  193820. {
  193821. if (handle != 0)
  193822. pthread_cancel ((pthread_t)handle);
  193823. }
  193824. void juce_setCurrentThreadName (const String& /*name*/)
  193825. {
  193826. }
  193827. Thread::ThreadID Thread::getCurrentThreadId()
  193828. {
  193829. return (ThreadID) pthread_self();
  193830. }
  193831. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  193832. // priority of the current thread
  193833. bool juce_setThreadPriority (void* handle, int priority)
  193834. {
  193835. struct sched_param param;
  193836. int policy, maxp, minp, pri;
  193837. if (handle == 0)
  193838. handle = (void*) pthread_self();
  193839. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  193840. && policy != SCHED_OTHER)
  193841. {
  193842. minp = sched_get_priority_min(policy);
  193843. maxp = sched_get_priority_max(policy);
  193844. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  193845. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  193846. // Realtime process priority
  193847. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  193848. else
  193849. // High process priority
  193850. param.__sched_priority = minp + pri;
  193851. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  193852. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  193853. }
  193854. return false;
  193855. }
  193856. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  193857. {
  193858. #if SUPPORT_AFFINITIES
  193859. cpu_set_t affinity;
  193860. CPU_ZERO (&affinity);
  193861. for (int i = 0; i < 32; ++i)
  193862. if ((affinityMask & (1 << i)) != 0)
  193863. CPU_SET (i, &affinity);
  193864. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  193865. sched_yield();
  193866. #else
  193867. /* affinities aren't supported because either the appropriate header files weren't found,
  193868. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  193869. */
  193870. jassertfalse
  193871. #endif
  193872. }
  193873. void Thread::yield()
  193874. {
  193875. sched_yield();
  193876. }
  193877. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  193878. void Process::setPriority (ProcessPriority prior)
  193879. {
  193880. struct sched_param param;
  193881. int policy, maxp, minp;
  193882. const int p = (int) prior;
  193883. if (p <= 1)
  193884. policy = SCHED_OTHER;
  193885. else
  193886. policy = SCHED_RR;
  193887. minp = sched_get_priority_min (policy);
  193888. maxp = sched_get_priority_max (policy);
  193889. if (p < 2)
  193890. param.__sched_priority = 0;
  193891. else if (p == 2 )
  193892. // Set to middle of lower realtime priority range
  193893. param.__sched_priority = minp + (maxp - minp) / 4;
  193894. else
  193895. // Set to middle of higher realtime priority range
  193896. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  193897. pthread_setschedparam (pthread_self(), policy, &param);
  193898. }
  193899. void Process::terminate()
  193900. {
  193901. exit (0);
  193902. }
  193903. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  193904. {
  193905. static char testResult = 0;
  193906. if (testResult == 0)
  193907. {
  193908. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  193909. if (testResult >= 0)
  193910. {
  193911. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  193912. testResult = 1;
  193913. }
  193914. }
  193915. return testResult < 0;
  193916. }
  193917. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  193918. {
  193919. return juce_isRunningUnderDebugger();
  193920. }
  193921. void Process::raisePrivilege()
  193922. {
  193923. // If running suid root, change effective user
  193924. // to root
  193925. if (geteuid() != 0 && getuid() == 0)
  193926. {
  193927. setreuid (geteuid(), getuid());
  193928. setregid (getegid(), getgid());
  193929. }
  193930. }
  193931. void Process::lowerPrivilege()
  193932. {
  193933. // If runing suid root, change effective user
  193934. // back to real user
  193935. if (geteuid() == 0 && getuid() != 0)
  193936. {
  193937. setreuid (geteuid(), getuid());
  193938. setregid (getegid(), getgid());
  193939. }
  193940. }
  193941. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  193942. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  193943. {
  193944. return dlopen (name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  193945. }
  193946. void PlatformUtilities::freeDynamicLibrary (void* handle)
  193947. {
  193948. dlclose(handle);
  193949. }
  193950. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  193951. {
  193952. return dlsym (libraryHandle, procedureName.toCString());
  193953. }
  193954. #endif
  193955. #endif
  193956. /*** End of inlined file: juce_linux_Threads.cpp ***/
  193957. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  193958. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  193959. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193960. // compiled on its own).
  193961. #if JUCE_INCLUDED_FILE
  193962. #ifdef JUCE_DEBUG
  193963. #define JUCE_DEBUG_XERRORS 1
  193964. #endif
  193965. extern Display* display;
  193966. extern Window juce_messageWindowHandle;
  193967. static String localClipboardContent;
  193968. static Atom atom_UTF8_STRING;
  193969. static Atom atom_CLIPBOARD;
  193970. static Atom atom_TARGETS;
  193971. static void initSelectionAtoms()
  193972. {
  193973. static bool isInitialised = false;
  193974. if (! isInitialised)
  193975. {
  193976. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  193977. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  193978. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  193979. }
  193980. }
  193981. // Read the content of a window property as either a locale-dependent string or an utf8 string
  193982. // works only for strings shorter than 1000000 bytes
  193983. static String juce_readWindowProperty (Window window, Atom prop,
  193984. Atom fmt, // XA_STRING or UTF8_STRING
  193985. bool deleteAfterReading)
  193986. {
  193987. String returnData;
  193988. char* clipData;
  193989. Atom actualType;
  193990. int actualFormat;
  193991. unsigned long numItems, bytesLeft;
  193992. if (XGetWindowProperty (display, window, prop,
  193993. 0L /* offset */, 1000000 /* length (max) */, False,
  193994. AnyPropertyType /* format */,
  193995. &actualType, &actualFormat, &numItems, &bytesLeft,
  193996. (unsigned char**) &clipData) == Success)
  193997. {
  193998. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  193999. {
  194000. returnData = String::fromUTF8 (clipData, numItems);
  194001. }
  194002. else if (actualType == XA_STRING && actualFormat == 8)
  194003. {
  194004. returnData = String (clipData, numItems);
  194005. }
  194006. if (clipData != 0)
  194007. XFree (clipData);
  194008. jassert (bytesLeft == 0 || numItems == 1000000);
  194009. }
  194010. if (deleteAfterReading)
  194011. XDeleteProperty (display, window, prop);
  194012. return returnData;
  194013. }
  194014. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194015. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194016. {
  194017. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194018. // The selection owner will be asked to set the JUCE_SEL property on the
  194019. // juce_messageWindowHandle with the selection content
  194020. XConvertSelection (display, selection, requested_format, property_name,
  194021. juce_messageWindowHandle, CurrentTime);
  194022. int timeoutMs = 200; // will wait at most for 200 ms
  194023. do
  194024. {
  194025. XEvent event;
  194026. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194027. {
  194028. if (event.xselection.property == property_name)
  194029. {
  194030. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194031. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194032. event.xselection.property,
  194033. requested_format, true);
  194034. return true;
  194035. }
  194036. else
  194037. {
  194038. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194039. }
  194040. }
  194041. // not very elegant.. we could do a select() or something like that...
  194042. // however clipboard content requesting is inherently slow on x11, it
  194043. // often takes 50ms or more so...
  194044. Thread::sleep (4);
  194045. timeoutMs -= 4;
  194046. }
  194047. while (timeoutMs > 0);
  194048. DBG("timeout for juce_requestSelectionContent");
  194049. return false;
  194050. }
  194051. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194052. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194053. {
  194054. initSelectionAtoms();
  194055. // the selection content is sent to the target window as a window property
  194056. XSelectionEvent reply;
  194057. reply.type = SelectionNotify;
  194058. reply.display = evt.display;
  194059. reply.requestor = evt.requestor;
  194060. reply.selection = evt.selection;
  194061. reply.target = evt.target;
  194062. reply.property = None; // == "fail"
  194063. reply.time = evt.time;
  194064. HeapBlock <char> data;
  194065. int propertyFormat = 0, numDataItems = 0;
  194066. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194067. {
  194068. if (evt.target == XA_STRING)
  194069. {
  194070. // format data according to system locale
  194071. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194072. data.calloc (numDataItems + 1);
  194073. localClipboardContent.copyToCString (data, numDataItems);
  194074. propertyFormat = 8; // bits/item
  194075. }
  194076. else if (evt.target == atom_UTF8_STRING)
  194077. {
  194078. // translate to utf8
  194079. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194080. data.calloc (numDataItems + 1);
  194081. localClipboardContent.copyToUTF8 (data, numDataItems);
  194082. propertyFormat = 8; // bits/item
  194083. }
  194084. else if (evt.target == atom_TARGETS)
  194085. {
  194086. // another application wants to know what we are able to send
  194087. numDataItems = 2;
  194088. propertyFormat = 32; // atoms are 32-bit
  194089. data.calloc (numDataItems * 4);
  194090. Atom* atoms = reinterpret_cast<Atom*> (data.getData());
  194091. atoms[0] = atom_UTF8_STRING;
  194092. atoms[1] = XA_STRING;
  194093. }
  194094. }
  194095. else
  194096. {
  194097. DBG ("requested unsupported clipboard");
  194098. }
  194099. if (data != 0)
  194100. {
  194101. const int maxReasonableSelectionSize = 1000000;
  194102. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194103. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194104. {
  194105. XChangeProperty (evt.display, evt.requestor,
  194106. evt.property, evt.target,
  194107. propertyFormat /* 8 or 32 */, PropModeReplace,
  194108. reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
  194109. reply.property = evt.property; // " == success"
  194110. }
  194111. }
  194112. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194113. }
  194114. void SystemClipboard::copyTextToClipboard (const String& clipText)
  194115. {
  194116. initSelectionAtoms();
  194117. localClipboardContent = clipText;
  194118. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194119. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194120. }
  194121. const String SystemClipboard::getTextFromClipboard()
  194122. {
  194123. initSelectionAtoms();
  194124. String content;
  194125. Atom selection = XA_PRIMARY;
  194126. Window selectionOwner = None;
  194127. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194128. {
  194129. selection = atom_CLIPBOARD;
  194130. selectionOwner = XGetSelectionOwner (display, selection);
  194131. }
  194132. if (selectionOwner != None)
  194133. {
  194134. if (selectionOwner == juce_messageWindowHandle)
  194135. {
  194136. content = localClipboardContent;
  194137. }
  194138. else
  194139. {
  194140. // first try: we want an utf8 string
  194141. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194142. if (! ok)
  194143. {
  194144. // second chance, ask for a good old locale-dependent string ..
  194145. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194146. }
  194147. }
  194148. }
  194149. return content;
  194150. }
  194151. #endif
  194152. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194153. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194154. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194155. // compiled on its own).
  194156. #if JUCE_INCLUDED_FILE
  194157. #ifdef JUCE_DEBUG
  194158. #define JUCE_DEBUG_XERRORS 1
  194159. #endif
  194160. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194161. Window juce_messageWindowHandle = None;
  194162. XContext improbableNumber; // This is referenced from Windowing.cpp
  194163. extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp
  194164. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt); // Defined in Clipboard.cpp
  194165. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194166. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194167. class InternalMessageQueue
  194168. {
  194169. public:
  194170. InternalMessageQueue()
  194171. : bytesInSocket (0)
  194172. {
  194173. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194174. (void) ret; jassert (ret == 0);
  194175. //setNonBlocking (fd[0]);
  194176. //setNonBlocking (fd[1]);
  194177. }
  194178. ~InternalMessageQueue()
  194179. {
  194180. close (fd[0]);
  194181. close (fd[1]);
  194182. }
  194183. void postMessage (Message* msg)
  194184. {
  194185. const int maxBytesInSocketQueue = 128;
  194186. ScopedLock sl (lock);
  194187. queue.add (msg);
  194188. if (bytesInSocket < maxBytesInSocketQueue)
  194189. {
  194190. ++bytesInSocket;
  194191. ScopedUnlock ul (lock);
  194192. const unsigned char x = 0xff;
  194193. size_t bytesWritten = write (fd[0], &x, 1);
  194194. (void) bytesWritten;
  194195. }
  194196. }
  194197. bool isEmpty() const
  194198. {
  194199. ScopedLock sl (lock);
  194200. return queue.size() == 0;
  194201. }
  194202. Message* popNextMessage()
  194203. {
  194204. ScopedLock sl (lock);
  194205. if (bytesInSocket > 0)
  194206. {
  194207. --bytesInSocket;
  194208. ScopedUnlock ul (lock);
  194209. unsigned char x;
  194210. size_t numBytes = read (fd[1], &x, 1);
  194211. (void) numBytes;
  194212. }
  194213. Message* m = queue[0];
  194214. queue.remove (0, false /* deleteObject */);
  194215. return m;
  194216. }
  194217. int getWaitHandle() const { return fd[1]; }
  194218. private:
  194219. CriticalSection lock;
  194220. OwnedArray <Message> queue;
  194221. int fd[2];
  194222. int bytesInSocket;
  194223. static bool setNonBlocking (int handle)
  194224. {
  194225. int socketFlags = fcntl (handle, F_GETFL, 0);
  194226. if (socketFlags == -1)
  194227. return false;
  194228. socketFlags |= O_NONBLOCK;
  194229. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194230. }
  194231. };
  194232. struct MessageThreadFuncCall
  194233. {
  194234. enum { uniqueID = 0x73774623 };
  194235. MessageCallbackFunction* func;
  194236. void* parameter;
  194237. void* result;
  194238. CriticalSection lock;
  194239. WaitableEvent event;
  194240. };
  194241. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194242. // error handling in X11
  194243. static bool errorOccurred = false;
  194244. static bool keyboardBreakOccurred = false;
  194245. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194246. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194247. // Usually happens when client-server connection is broken
  194248. static int ioErrorHandler (Display* display)
  194249. {
  194250. DBG ("ERROR: connection to X server broken.. terminating.");
  194251. errorOccurred = true;
  194252. if (JUCEApplication::getInstance() != 0)
  194253. Process::terminate();
  194254. return 0;
  194255. }
  194256. // A protocol error has occurred
  194257. static int errorHandler (Display* display, XErrorEvent* event)
  194258. {
  194259. #ifdef JUCE_DEBUG_XERRORS
  194260. char errorStr[64] = { 0 };
  194261. char requestStr[64] = { 0 };
  194262. XGetErrorText (display, event->error_code, errorStr, 64);
  194263. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194264. "Unknown", requestStr, 64);
  194265. DBG ("ERROR: X returned " + String (errorStr) + " for operation " + String (requestStr));
  194266. #endif
  194267. return 0;
  194268. }
  194269. // Breakin from keyboard
  194270. static void signalHandler (int sig)
  194271. {
  194272. if (sig == SIGINT)
  194273. {
  194274. keyboardBreakOccurred = true;
  194275. return;
  194276. }
  194277. static bool reentrant = false;
  194278. if (! reentrant)
  194279. {
  194280. reentrant = true;
  194281. // Illegal instruction
  194282. fflush (stdout);
  194283. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194284. errorOccurred = true;
  194285. if (JUCEApplication::getInstance() != 0)
  194286. Process::terminate();
  194287. }
  194288. else
  194289. {
  194290. if (JUCEApplication::getInstance() != 0)
  194291. exit(0);
  194292. }
  194293. }
  194294. void MessageManager::doPlatformSpecificInitialisation()
  194295. {
  194296. // Initialise xlib for multiple thread support
  194297. static bool initThreadCalled = false;
  194298. if (! initThreadCalled)
  194299. {
  194300. if (! XInitThreads())
  194301. {
  194302. // This is fatal! Print error and closedown
  194303. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194304. if (JUCEApplication::getInstance() != 0)
  194305. Process::terminate();
  194306. return;
  194307. }
  194308. initThreadCalled = true;
  194309. }
  194310. // This is called if the client/server connection is broken
  194311. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194312. // This is called if a protocol error occurs
  194313. oldErrorHandler = XSetErrorHandler (errorHandler);
  194314. // Install signal handler for break-in
  194315. struct sigaction saction;
  194316. sigset_t maskSet;
  194317. sigemptyset (&maskSet);
  194318. saction.sa_handler = signalHandler;
  194319. saction.sa_mask = maskSet;
  194320. saction.sa_flags = 0;
  194321. sigaction (SIGINT, &saction, NULL);
  194322. #ifndef _DEBUG
  194323. // Setup signal handlers for various fatal errors
  194324. sigaction (SIGILL, &saction, NULL);
  194325. sigaction (SIGBUS, &saction, NULL);
  194326. sigaction (SIGFPE, &saction, NULL);
  194327. sigaction (SIGSEGV, &saction, NULL);
  194328. sigaction (SIGSYS, &saction, NULL);
  194329. #endif
  194330. // Create the internal message queue
  194331. juce_internalMessageQueue = new InternalMessageQueue();
  194332. // Try to connect to a display
  194333. String displayName (getenv ("DISPLAY"));
  194334. if (displayName.isEmpty())
  194335. displayName = ":0.0";
  194336. display = XOpenDisplay (displayName.toCString());
  194337. if (display == 0)
  194338. {
  194339. // This is not fatal! we can run headless.
  194340. return;
  194341. }
  194342. // Get defaults for various properties
  194343. int screen = DefaultScreen (display);
  194344. Window root = RootWindow (display, screen);
  194345. Visual* visual = DefaultVisual (display, screen);
  194346. // Create a context to store user data associated with Windows we
  194347. // create in WindowDriver
  194348. improbableNumber = XUniqueContext();
  194349. // We're only interested in client messages for this window
  194350. // which are always sent
  194351. XSetWindowAttributes swa;
  194352. swa.event_mask = NoEventMask;
  194353. // Create our message window (this will never be mapped)
  194354. juce_messageWindowHandle = XCreateWindow (display, root,
  194355. 0, 0, 1, 1, 0, 0, InputOnly,
  194356. visual, CWEventMask, &swa);
  194357. }
  194358. void MessageManager::doPlatformSpecificShutdown()
  194359. {
  194360. deleteAndZero (juce_internalMessageQueue);
  194361. if (display != 0 && ! errorOccurred)
  194362. {
  194363. XDestroyWindow (display, juce_messageWindowHandle);
  194364. XCloseDisplay (display);
  194365. // reset pointers
  194366. juce_messageWindowHandle = 0;
  194367. display = 0;
  194368. // Restore original error handlers
  194369. XSetIOErrorHandler (oldIOErrorHandler);
  194370. oldIOErrorHandler = 0;
  194371. XSetErrorHandler (oldErrorHandler);
  194372. oldErrorHandler = 0;
  194373. }
  194374. }
  194375. bool juce_postMessageToSystemQueue (void* message)
  194376. {
  194377. if (errorOccurred)
  194378. return false;
  194379. juce_internalMessageQueue->postMessage ((Message*) message);
  194380. return true;
  194381. }
  194382. void MessageManager::broadcastMessage (const String& value) throw()
  194383. {
  194384. }
  194385. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194386. void* parameter)
  194387. {
  194388. if (errorOccurred)
  194389. return 0;
  194390. if (! isThisTheMessageThread())
  194391. {
  194392. MessageThreadFuncCall messageCallContext;
  194393. messageCallContext.func = func;
  194394. messageCallContext.parameter = parameter;
  194395. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194396. 0, 0, &messageCallContext));
  194397. // Wait for it to complete before continuing
  194398. messageCallContext.event.wait();
  194399. return messageCallContext.result;
  194400. }
  194401. else
  194402. {
  194403. // Just call the function directly
  194404. return func (parameter);
  194405. }
  194406. }
  194407. // Wait for an event (either XEvent, or an internal Message)
  194408. static bool juce_sleepUntilEvent (const int timeoutMs)
  194409. {
  194410. if (! juce_internalMessageQueue->isEmpty())
  194411. return true;
  194412. if (display != 0)
  194413. {
  194414. ScopedXLock xlock;
  194415. if (XPending (display))
  194416. return true;
  194417. }
  194418. struct timeval tv;
  194419. tv.tv_sec = 0;
  194420. tv.tv_usec = timeoutMs * 1000;
  194421. int fd0 = juce_internalMessageQueue->getWaitHandle();
  194422. int fdmax = fd0;
  194423. fd_set readset;
  194424. FD_ZERO (&readset);
  194425. FD_SET (fd0, &readset);
  194426. if (display != 0)
  194427. {
  194428. ScopedXLock xlock;
  194429. int fd1 = XConnectionNumber (display);
  194430. FD_SET (fd1, &readset);
  194431. fdmax = jmax (fd0, fd1);
  194432. }
  194433. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  194434. return (ret > 0); // ret <= 0 if error or timeout
  194435. }
  194436. // Handle next XEvent (if any)
  194437. static bool juce_dispatchNextXEvent()
  194438. {
  194439. if (display == 0)
  194440. return false;
  194441. XEvent evt;
  194442. {
  194443. ScopedXLock xlock;
  194444. if (! XPending (display))
  194445. return false;
  194446. XNextEvent (display, &evt);
  194447. }
  194448. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  194449. {
  194450. juce_handleSelectionRequest (evt.xselectionrequest);
  194451. }
  194452. else if (evt.xany.window != juce_messageWindowHandle)
  194453. {
  194454. juce_windowMessageReceive (&evt);
  194455. }
  194456. return true;
  194457. }
  194458. // Handle next internal Message (if any)
  194459. static bool juce_dispatchNextInternalMessage()
  194460. {
  194461. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  194462. if (msg == 0)
  194463. return false;
  194464. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  194465. {
  194466. // Handle callback message
  194467. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  194468. call->result = (*(call->func)) (call->parameter);
  194469. call->event.signal();
  194470. }
  194471. else
  194472. {
  194473. // Handle "normal" messages
  194474. MessageManager::getInstance()->deliverMessage (msg.release());
  194475. }
  194476. return true;
  194477. }
  194478. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  194479. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  194480. {
  194481. for (;;)
  194482. {
  194483. if (errorOccurred)
  194484. break;
  194485. if (keyboardBreakOccurred)
  194486. {
  194487. errorOccurred = true;
  194488. if (JUCEApplication::getInstance() != 0)
  194489. Process::terminate();
  194490. break;
  194491. }
  194492. static int totalEventCount = 0;
  194493. ++totalEventCount;
  194494. // The purpose here is to give either priority to XEvents or
  194495. // to internal messages This is necessary to keep a "good"
  194496. // behaviour when the cpu is overloaded
  194497. if (totalEventCount & 1)
  194498. {
  194499. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  194500. return true;
  194501. }
  194502. else
  194503. {
  194504. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  194505. return true;
  194506. }
  194507. if (returnIfNoPendingMessages) // early exit
  194508. break;
  194509. // the timeout is to be on the safe side, but it does not seem to be useful
  194510. juce_sleepUntilEvent (2000);
  194511. }
  194512. return false;
  194513. }
  194514. #endif
  194515. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  194516. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  194517. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194518. // compiled on its own).
  194519. #if JUCE_INCLUDED_FILE
  194520. class FreeTypeFontFace
  194521. {
  194522. public:
  194523. enum FontStyle
  194524. {
  194525. Plain = 0,
  194526. Bold = 1,
  194527. Italic = 2
  194528. };
  194529. struct FontNameIndex
  194530. {
  194531. String fileName;
  194532. int faceIndex;
  194533. };
  194534. FreeTypeFontFace (const String& familyName)
  194535. : hasSerif (false),
  194536. monospaced (false)
  194537. {
  194538. family = familyName;
  194539. }
  194540. void setFileName (const String& name, const int faceIndex, FontStyle style)
  194541. {
  194542. if (names [(int) style].fileName.isEmpty())
  194543. {
  194544. names [(int) style].fileName = name;
  194545. names [(int) style].faceIndex = faceIndex;
  194546. }
  194547. }
  194548. const String& getFamilyName() const throw() { return family; }
  194549. const String& getFileName (const int style, int& faceIndex) const throw()
  194550. {
  194551. faceIndex = names[style].faceIndex;
  194552. return names[style].fileName;
  194553. }
  194554. void setMonospaced (bool mono) throw() { monospaced = mono; }
  194555. bool getMonospaced() const throw() { return monospaced; }
  194556. void setSerif (const bool serif) throw() { hasSerif = serif; }
  194557. bool getSerif() const throw() { return hasSerif; }
  194558. private:
  194559. String family;
  194560. FontNameIndex names[4];
  194561. bool hasSerif, monospaced;
  194562. };
  194563. class FreeTypeInterface : public DeletedAtShutdown
  194564. {
  194565. public:
  194566. FreeTypeInterface()
  194567. : ftLib (0),
  194568. lastFace (0),
  194569. lastBold (false),
  194570. lastItalic (false)
  194571. {
  194572. if (FT_Init_FreeType (&ftLib) != 0)
  194573. {
  194574. ftLib = 0;
  194575. DBG ("Failed to initialize FreeType");
  194576. }
  194577. StringArray fontDirs;
  194578. fontDirs.addTokens (String::fromUTF8 (getenv ("JUCE_FONT_PATH")), ";,", String::empty);
  194579. fontDirs.removeEmptyStrings (true);
  194580. if (fontDirs.size() == 0)
  194581. {
  194582. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  194583. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  194584. if (fontsInfo != 0)
  194585. {
  194586. forEachXmlChildElementWithTagName (*fontsInfo, e, "dir")
  194587. {
  194588. fontDirs.add (e->getAllSubText().trim());
  194589. }
  194590. delete fontsInfo;
  194591. }
  194592. }
  194593. if (fontDirs.size() == 0)
  194594. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  194595. for (int i = 0; i < fontDirs.size(); ++i)
  194596. enumerateFaces (fontDirs[i]);
  194597. }
  194598. ~FreeTypeInterface()
  194599. {
  194600. if (lastFace != 0)
  194601. FT_Done_Face (lastFace);
  194602. if (ftLib != 0)
  194603. FT_Done_FreeType (ftLib);
  194604. clearSingletonInstance();
  194605. }
  194606. FreeTypeFontFace* findOrCreate (const String& familyName, const bool create = false)
  194607. {
  194608. for (int i = 0; i < faces.size(); i++)
  194609. if (faces[i]->getFamilyName() == familyName)
  194610. return faces[i];
  194611. if (! create)
  194612. return NULL;
  194613. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  194614. faces.add (newFace);
  194615. return newFace;
  194616. }
  194617. // Enumerate all font faces available in a given directory
  194618. void enumerateFaces (const String& path)
  194619. {
  194620. File dirPath (path);
  194621. if (path.isEmpty() || ! dirPath.isDirectory())
  194622. return;
  194623. DirectoryIterator di (dirPath, true);
  194624. while (di.next())
  194625. {
  194626. File possible (di.getFile());
  194627. if (possible.hasFileExtension ("ttf")
  194628. || possible.hasFileExtension ("pfb")
  194629. || possible.hasFileExtension ("pcf"))
  194630. {
  194631. FT_Face face;
  194632. int faceIndex = 0;
  194633. int numFaces = 0;
  194634. do
  194635. {
  194636. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  194637. faceIndex, &face) == 0)
  194638. {
  194639. if (faceIndex == 0)
  194640. numFaces = face->num_faces;
  194641. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  194642. {
  194643. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  194644. int style = (int) FreeTypeFontFace::Plain;
  194645. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  194646. style |= (int) FreeTypeFontFace::Bold;
  194647. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  194648. style |= (int) FreeTypeFontFace::Italic;
  194649. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  194650. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  194651. // Surely there must be a better way to do this?
  194652. const String name (face->family_name);
  194653. newFace->setSerif (! (name.containsIgnoreCase ("Sans")
  194654. || name.containsIgnoreCase ("Verdana")
  194655. || name.containsIgnoreCase ("Arial")));
  194656. }
  194657. FT_Done_Face (face);
  194658. }
  194659. ++faceIndex;
  194660. }
  194661. while (faceIndex < numFaces);
  194662. }
  194663. }
  194664. }
  194665. // Create a FreeType face object for a given font
  194666. FT_Face createFT_Face (const String& fontName, const bool bold, const bool italic)
  194667. {
  194668. FT_Face face = 0;
  194669. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  194670. {
  194671. face = lastFace;
  194672. }
  194673. else
  194674. {
  194675. if (lastFace != 0)
  194676. {
  194677. FT_Done_Face (lastFace);
  194678. lastFace = 0;
  194679. }
  194680. lastFontName = fontName;
  194681. lastBold = bold;
  194682. lastItalic = italic;
  194683. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  194684. if (ftFace != 0)
  194685. {
  194686. int style = (int) FreeTypeFontFace::Plain;
  194687. if (bold)
  194688. style |= (int) FreeTypeFontFace::Bold;
  194689. if (italic)
  194690. style |= (int) FreeTypeFontFace::Italic;
  194691. int faceIndex;
  194692. String fileName (ftFace->getFileName (style, faceIndex));
  194693. if (fileName.isEmpty())
  194694. {
  194695. style ^= (int) FreeTypeFontFace::Bold;
  194696. fileName = ftFace->getFileName (style, faceIndex);
  194697. if (fileName.isEmpty())
  194698. {
  194699. style ^= (int) FreeTypeFontFace::Bold;
  194700. style ^= (int) FreeTypeFontFace::Italic;
  194701. fileName = ftFace->getFileName (style, faceIndex);
  194702. if (! fileName.length())
  194703. {
  194704. style ^= (int) FreeTypeFontFace::Bold;
  194705. fileName = ftFace->getFileName (style, faceIndex);
  194706. }
  194707. }
  194708. }
  194709. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  194710. {
  194711. face = lastFace;
  194712. // If there isn't a unicode charmap then select the first one.
  194713. if (FT_Select_Charmap (face, ft_encoding_unicode))
  194714. FT_Set_Charmap (face, face->charmaps[0]);
  194715. }
  194716. }
  194717. }
  194718. return face;
  194719. }
  194720. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character)
  194721. {
  194722. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  194723. const float height = (float) (face->ascender - face->descender);
  194724. const float scaleX = 1.0f / height;
  194725. const float scaleY = -1.0f / height;
  194726. Path destShape;
  194727. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  194728. || face->glyph->format != ft_glyph_format_outline)
  194729. {
  194730. return false;
  194731. }
  194732. const FT_Outline* const outline = &face->glyph->outline;
  194733. const short* const contours = outline->contours;
  194734. const char* const tags = outline->tags;
  194735. FT_Vector* const points = outline->points;
  194736. for (int c = 0; c < outline->n_contours; c++)
  194737. {
  194738. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  194739. const int endPoint = contours[c];
  194740. for (int p = startPoint; p <= endPoint; p++)
  194741. {
  194742. const float x = scaleX * points[p].x;
  194743. const float y = scaleY * points[p].y;
  194744. if (p == startPoint)
  194745. {
  194746. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194747. {
  194748. float x2 = scaleX * points [endPoint].x;
  194749. float y2 = scaleY * points [endPoint].y;
  194750. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  194751. {
  194752. x2 = (x + x2) * 0.5f;
  194753. y2 = (y + y2) * 0.5f;
  194754. }
  194755. destShape.startNewSubPath (x2, y2);
  194756. }
  194757. else
  194758. {
  194759. destShape.startNewSubPath (x, y);
  194760. }
  194761. }
  194762. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  194763. {
  194764. if (p != startPoint)
  194765. destShape.lineTo (x, y);
  194766. }
  194767. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  194768. {
  194769. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  194770. float x2 = scaleX * points [nextIndex].x;
  194771. float y2 = scaleY * points [nextIndex].y;
  194772. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  194773. {
  194774. x2 = (x + x2) * 0.5f;
  194775. y2 = (y + y2) * 0.5f;
  194776. }
  194777. else
  194778. {
  194779. ++p;
  194780. }
  194781. destShape.quadraticTo (x, y, x2, y2);
  194782. }
  194783. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  194784. {
  194785. if (p >= endPoint)
  194786. return false;
  194787. const int next1 = p + 1;
  194788. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  194789. const float x2 = scaleX * points [next1].x;
  194790. const float y2 = scaleY * points [next1].y;
  194791. const float x3 = scaleX * points [next2].x;
  194792. const float y3 = scaleY * points [next2].y;
  194793. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  194794. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  194795. return false;
  194796. destShape.cubicTo (x, y, x2, y2, x3, y3);
  194797. p += 2;
  194798. }
  194799. }
  194800. destShape.closeSubPath();
  194801. }
  194802. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  194803. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  194804. addKerning (face, dest, character, glyphIndex);
  194805. return true;
  194806. }
  194807. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex)
  194808. {
  194809. const float height = (float) (face->ascender - face->descender);
  194810. uint32 rightGlyphIndex;
  194811. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  194812. while (rightGlyphIndex != 0)
  194813. {
  194814. FT_Vector kerning;
  194815. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  194816. {
  194817. if (kerning.x != 0)
  194818. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  194819. }
  194820. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  194821. }
  194822. }
  194823. // Add a glyph to a font
  194824. bool addGlyphToFont (const uint32 character, const String& fontName,
  194825. bool bold, bool italic, CustomTypeface& dest)
  194826. {
  194827. FT_Face face = createFT_Face (fontName, bold, italic);
  194828. return face != 0 && addGlyph (face, dest, character);
  194829. }
  194830. void getFamilyNames (StringArray& familyNames) const
  194831. {
  194832. for (int i = 0; i < faces.size(); i++)
  194833. familyNames.add (faces[i]->getFamilyName());
  194834. }
  194835. void getMonospacedNames (StringArray& monoSpaced) const
  194836. {
  194837. for (int i = 0; i < faces.size(); i++)
  194838. if (faces[i]->getMonospaced())
  194839. monoSpaced.add (faces[i]->getFamilyName());
  194840. }
  194841. void getSerifNames (StringArray& serif) const
  194842. {
  194843. for (int i = 0; i < faces.size(); i++)
  194844. if (faces[i]->getSerif())
  194845. serif.add (faces[i]->getFamilyName());
  194846. }
  194847. void getSansSerifNames (StringArray& sansSerif) const
  194848. {
  194849. for (int i = 0; i < faces.size(); i++)
  194850. if (! faces[i]->getSerif())
  194851. sansSerif.add (faces[i]->getFamilyName());
  194852. }
  194853. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  194854. private:
  194855. FT_Library ftLib;
  194856. FT_Face lastFace;
  194857. String lastFontName;
  194858. bool lastBold, lastItalic;
  194859. OwnedArray<FreeTypeFontFace> faces;
  194860. };
  194861. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  194862. class FreetypeTypeface : public CustomTypeface
  194863. {
  194864. public:
  194865. FreetypeTypeface (const Font& font)
  194866. {
  194867. FT_Face face = FreeTypeInterface::getInstance()
  194868. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  194869. if (face == 0)
  194870. {
  194871. #ifdef JUCE_DEBUG
  194872. String msg ("Failed to create typeface: ");
  194873. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  194874. DBG (msg);
  194875. #endif
  194876. }
  194877. else
  194878. {
  194879. setCharacteristics (font.getTypefaceName(),
  194880. face->ascender / (float) (face->ascender - face->descender),
  194881. font.isBold(), font.isItalic(),
  194882. L' ');
  194883. }
  194884. }
  194885. bool loadGlyphIfPossible (juce_wchar character)
  194886. {
  194887. return FreeTypeInterface::getInstance()
  194888. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  194889. }
  194890. };
  194891. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  194892. {
  194893. return new FreetypeTypeface (font);
  194894. }
  194895. const StringArray Font::findAllTypefaceNames()
  194896. {
  194897. StringArray s;
  194898. FreeTypeInterface::getInstance()->getFamilyNames (s);
  194899. s.sort (true);
  194900. return s;
  194901. }
  194902. static const String pickBestFont (const StringArray& names,
  194903. const char* const choicesString)
  194904. {
  194905. StringArray choices;
  194906. choices.addTokens (String (choicesString), ",", String::empty);
  194907. choices.trim();
  194908. choices.removeEmptyStrings();
  194909. int i, j;
  194910. for (j = 0; j < choices.size(); ++j)
  194911. if (names.contains (choices[j], true))
  194912. return choices[j];
  194913. for (j = 0; j < choices.size(); ++j)
  194914. for (i = 0; i < names.size(); i++)
  194915. if (names[i].startsWithIgnoreCase (choices[j]))
  194916. return names[i];
  194917. for (j = 0; j < choices.size(); ++j)
  194918. for (i = 0; i < names.size(); i++)
  194919. if (names[i].containsIgnoreCase (choices[j]))
  194920. return names[i];
  194921. return names[0];
  194922. }
  194923. static const String linux_getDefaultSansSerifFontName()
  194924. {
  194925. StringArray allFonts;
  194926. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  194927. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  194928. }
  194929. static const String linux_getDefaultSerifFontName()
  194930. {
  194931. StringArray allFonts;
  194932. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  194933. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  194934. }
  194935. static const String linux_getDefaultMonospacedFontName()
  194936. {
  194937. StringArray allFonts;
  194938. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  194939. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  194940. }
  194941. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  194942. {
  194943. defaultSans = linux_getDefaultSansSerifFontName();
  194944. defaultSerif = linux_getDefaultSerifFontName();
  194945. defaultFixed = linux_getDefaultMonospacedFontName();
  194946. }
  194947. #endif
  194948. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  194949. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  194950. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194951. // compiled on its own).
  194952. #if JUCE_INCLUDED_FILE
  194953. // These are defined in juce_linux_Messaging.cpp
  194954. extern Display* display;
  194955. extern XContext improbableNumber;
  194956. namespace Atoms
  194957. {
  194958. enum ProtocolItems
  194959. {
  194960. TAKE_FOCUS = 0,
  194961. DELETE_WINDOW = 1,
  194962. PING = 2
  194963. };
  194964. static Atom Protocols, ProtocolList[3], ChangeState, State,
  194965. ActiveWin, Pid, WindowType, WindowState,
  194966. XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus,
  194967. XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList,
  194968. XdndActionDescription, XdndActionCopy,
  194969. allowedActions[5],
  194970. allowedMimeTypes[2];
  194971. const unsigned long DndVersion = 3;
  194972. static void initialiseAtoms()
  194973. {
  194974. static bool atomsInitialised = false;
  194975. if (! atomsInitialised)
  194976. {
  194977. atomsInitialised = true;
  194978. Protocols = XInternAtom (display, "WM_PROTOCOLS", True);
  194979. ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", True);
  194980. ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", True);
  194981. ProtocolList [PING] = XInternAtom (display, "_NET_WM_PING", True);
  194982. ChangeState = XInternAtom (display, "WM_CHANGE_STATE", True);
  194983. State = XInternAtom (display, "WM_STATE", True);
  194984. ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  194985. Pid = XInternAtom (display, "_NET_WM_PID", False);
  194986. WindowType = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  194987. WindowState = XInternAtom (display, "_NET_WM_STATE", True);
  194988. XdndAware = XInternAtom (display, "XdndAware", False);
  194989. XdndEnter = XInternAtom (display, "XdndEnter", False);
  194990. XdndLeave = XInternAtom (display, "XdndLeave", False);
  194991. XdndPosition = XInternAtom (display, "XdndPosition", False);
  194992. XdndStatus = XInternAtom (display, "XdndStatus", False);
  194993. XdndDrop = XInternAtom (display, "XdndDrop", False);
  194994. XdndFinished = XInternAtom (display, "XdndFinished", False);
  194995. XdndSelection = XInternAtom (display, "XdndSelection", False);
  194996. XdndTypeList = XInternAtom (display, "XdndTypeList", False);
  194997. XdndActionList = XInternAtom (display, "XdndActionList", False);
  194998. XdndActionCopy = XInternAtom (display, "XdndActionCopy", False);
  194999. XdndActionDescription = XInternAtom (display, "XdndActionDescription", False);
  195000. allowedMimeTypes[0] = XInternAtom (display, "text/plain", False);
  195001. allowedMimeTypes[1] = XInternAtom (display, "text/uri-list", False);
  195002. allowedActions[0] = XInternAtom (display, "XdndActionMove", False);
  195003. allowedActions[1] = XdndActionCopy;
  195004. allowedActions[2] = XInternAtom (display, "XdndActionLink", False);
  195005. allowedActions[3] = XInternAtom (display, "XdndActionAsk", False);
  195006. allowedActions[4] = XInternAtom (display, "XdndActionPrivate", False);
  195007. }
  195008. }
  195009. }
  195010. namespace Keys
  195011. {
  195012. enum MouseButtons
  195013. {
  195014. NoButton = 0,
  195015. LeftButton = 1,
  195016. MiddleButton = 2,
  195017. RightButton = 3,
  195018. WheelUp = 4,
  195019. WheelDown = 5
  195020. };
  195021. static int AltMask = 0;
  195022. static int NumLockMask = 0;
  195023. static bool numLock = false;
  195024. static bool capsLock = false;
  195025. static char keyStates [32];
  195026. static const int extendedKeyModifier = 0x10000000;
  195027. }
  195028. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  195029. {
  195030. int keysym;
  195031. if (keyCode & Keys::extendedKeyModifier)
  195032. {
  195033. keysym = 0xff00 | (keyCode & 0xff);
  195034. }
  195035. else
  195036. {
  195037. keysym = keyCode;
  195038. if (keysym == (XK_Tab & 0xff)
  195039. || keysym == (XK_Return & 0xff)
  195040. || keysym == (XK_Escape & 0xff)
  195041. || keysym == (XK_BackSpace & 0xff))
  195042. {
  195043. keysym |= 0xff00;
  195044. }
  195045. }
  195046. ScopedXLock xlock;
  195047. const int keycode = XKeysymToKeycode (display, keysym);
  195048. const int keybyte = keycode >> 3;
  195049. const int keybit = (1 << (keycode & 7));
  195050. return (Keys::keyStates [keybyte] & keybit) != 0;
  195051. }
  195052. #if JUCE_USE_XSHM
  195053. namespace XSHMHelpers
  195054. {
  195055. static int trappedErrorCode = 0;
  195056. extern "C" int errorTrapHandler (Display*, XErrorEvent* err)
  195057. {
  195058. trappedErrorCode = err->error_code;
  195059. return 0;
  195060. }
  195061. static bool isShmAvailable() throw()
  195062. {
  195063. static bool isChecked = false;
  195064. static bool isAvailable = false;
  195065. if (! isChecked)
  195066. {
  195067. isChecked = true;
  195068. int major, minor;
  195069. Bool pixmaps;
  195070. ScopedXLock xlock;
  195071. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195072. {
  195073. trappedErrorCode = 0;
  195074. XErrorHandler oldHandler = XSetErrorHandler (errorTrapHandler);
  195075. XShmSegmentInfo segmentInfo;
  195076. zerostruct (segmentInfo);
  195077. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195078. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195079. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195080. xImage->bytes_per_line * xImage->height,
  195081. IPC_CREAT | 0777)) >= 0)
  195082. {
  195083. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195084. if (segmentInfo.shmaddr != (void*) -1)
  195085. {
  195086. segmentInfo.readOnly = False;
  195087. xImage->data = segmentInfo.shmaddr;
  195088. XSync (display, False);
  195089. if (XShmAttach (display, &segmentInfo) != 0)
  195090. {
  195091. XSync (display, False);
  195092. XShmDetach (display, &segmentInfo);
  195093. isAvailable = true;
  195094. }
  195095. }
  195096. XFlush (display);
  195097. XDestroyImage (xImage);
  195098. shmdt (segmentInfo.shmaddr);
  195099. }
  195100. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195101. XSetErrorHandler (oldHandler);
  195102. if (trappedErrorCode != 0)
  195103. isAvailable = false;
  195104. }
  195105. }
  195106. return isAvailable;
  195107. }
  195108. }
  195109. #endif
  195110. #if JUCE_USE_XRENDER
  195111. namespace XRender
  195112. {
  195113. typedef Status (*tXRenderQueryVersion) (Display*, int*, int*);
  195114. typedef XRenderPictFormat* (*tXrenderFindStandardFormat) (Display*, int);
  195115. typedef XRenderPictFormat* (*tXRenderFindFormat) (Display*, unsigned long, XRenderPictFormat*, int);
  195116. typedef XRenderPictFormat* (*tXRenderFindVisualFormat) (Display*, Visual*);
  195117. static tXRenderQueryVersion xRenderQueryVersion = 0;
  195118. static tXrenderFindStandardFormat xRenderFindStandardFormat = 0;
  195119. static tXRenderFindFormat xRenderFindFormat = 0;
  195120. static tXRenderFindVisualFormat xRenderFindVisualFormat = 0;
  195121. static bool isAvailable()
  195122. {
  195123. static bool hasLoaded = false;
  195124. if (! hasLoaded)
  195125. {
  195126. ScopedXLock xlock;
  195127. hasLoaded = true;
  195128. void* h = dlopen ("libXrender.so", RTLD_GLOBAL | RTLD_NOW);
  195129. if (h != 0)
  195130. {
  195131. xRenderQueryVersion = (tXRenderQueryVersion) dlsym (h, "XRenderQueryVersion");
  195132. xRenderFindStandardFormat = (tXrenderFindStandardFormat) dlsym (h, "XrenderFindStandardFormat");
  195133. xRenderFindFormat = (tXRenderFindFormat) dlsym (h, "XRenderFindFormat");
  195134. xRenderFindVisualFormat = (tXRenderFindVisualFormat) dlsym (h, "XRenderFindVisualFormat");
  195135. }
  195136. if (xRenderQueryVersion != 0
  195137. && xRenderFindStandardFormat != 0
  195138. && xRenderFindFormat != 0
  195139. && xRenderFindVisualFormat != 0)
  195140. {
  195141. int major, minor;
  195142. if (xRenderQueryVersion (display, &major, &minor))
  195143. return true;
  195144. }
  195145. xRenderQueryVersion = 0;
  195146. }
  195147. return xRenderQueryVersion != 0;
  195148. }
  195149. static XRenderPictFormat* findPictureFormat()
  195150. {
  195151. ScopedXLock xlock;
  195152. XRenderPictFormat* pictFormat = 0;
  195153. if (isAvailable())
  195154. {
  195155. pictFormat = xRenderFindStandardFormat (display, PictStandardARGB32);
  195156. if (pictFormat == 0)
  195157. {
  195158. XRenderPictFormat desiredFormat;
  195159. desiredFormat.type = PictTypeDirect;
  195160. desiredFormat.depth = 32;
  195161. desiredFormat.direct.alphaMask = 0xff;
  195162. desiredFormat.direct.redMask = 0xff;
  195163. desiredFormat.direct.greenMask = 0xff;
  195164. desiredFormat.direct.blueMask = 0xff;
  195165. desiredFormat.direct.alpha = 24;
  195166. desiredFormat.direct.red = 16;
  195167. desiredFormat.direct.green = 8;
  195168. desiredFormat.direct.blue = 0;
  195169. pictFormat = xRenderFindFormat (display,
  195170. PictFormatType | PictFormatDepth
  195171. | PictFormatRedMask | PictFormatRed
  195172. | PictFormatGreenMask | PictFormatGreen
  195173. | PictFormatBlueMask | PictFormatBlue
  195174. | PictFormatAlphaMask | PictFormatAlpha,
  195175. &desiredFormat,
  195176. 0);
  195177. }
  195178. }
  195179. return pictFormat;
  195180. }
  195181. }
  195182. #endif
  195183. namespace Visuals
  195184. {
  195185. static Visual* findVisualWithDepth (const int desiredDepth) throw()
  195186. {
  195187. ScopedXLock xlock;
  195188. Visual* visual = 0;
  195189. int numVisuals = 0;
  195190. long desiredMask = VisualNoMask;
  195191. XVisualInfo desiredVisual;
  195192. desiredVisual.screen = DefaultScreen (display);
  195193. desiredVisual.depth = desiredDepth;
  195194. desiredMask = VisualScreenMask | VisualDepthMask;
  195195. if (desiredDepth == 32)
  195196. {
  195197. desiredVisual.c_class = TrueColor;
  195198. desiredVisual.red_mask = 0x00FF0000;
  195199. desiredVisual.green_mask = 0x0000FF00;
  195200. desiredVisual.blue_mask = 0x000000FF;
  195201. desiredVisual.bits_per_rgb = 8;
  195202. desiredMask |= VisualClassMask;
  195203. desiredMask |= VisualRedMaskMask;
  195204. desiredMask |= VisualGreenMaskMask;
  195205. desiredMask |= VisualBlueMaskMask;
  195206. desiredMask |= VisualBitsPerRGBMask;
  195207. }
  195208. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195209. desiredMask,
  195210. &desiredVisual,
  195211. &numVisuals);
  195212. if (xvinfos != 0)
  195213. {
  195214. for (int i = 0; i < numVisuals; i++)
  195215. {
  195216. if (xvinfos[i].depth == desiredDepth)
  195217. {
  195218. visual = xvinfos[i].visual;
  195219. break;
  195220. }
  195221. }
  195222. XFree (xvinfos);
  195223. }
  195224. return visual;
  195225. }
  195226. static Visual* findVisualFormat (const int desiredDepth, int& matchedDepth) throw()
  195227. {
  195228. Visual* visual = 0;
  195229. if (desiredDepth == 32)
  195230. {
  195231. #if JUCE_USE_XSHM
  195232. if (XSHMHelpers::isShmAvailable())
  195233. {
  195234. #if JUCE_USE_XRENDER
  195235. if (XRender::isAvailable())
  195236. {
  195237. XRenderPictFormat* pictFormat = XRender::findPictureFormat();
  195238. if (pictFormat != 0)
  195239. {
  195240. int numVisuals = 0;
  195241. XVisualInfo desiredVisual;
  195242. desiredVisual.screen = DefaultScreen (display);
  195243. desiredVisual.depth = 32;
  195244. desiredVisual.bits_per_rgb = 8;
  195245. XVisualInfo* xvinfos = XGetVisualInfo (display,
  195246. VisualScreenMask | VisualDepthMask | VisualBitsPerRGBMask,
  195247. &desiredVisual, &numVisuals);
  195248. if (xvinfos != 0)
  195249. {
  195250. for (int i = 0; i < numVisuals; ++i)
  195251. {
  195252. XRenderPictFormat* pictVisualFormat = XRender::xRenderFindVisualFormat (display, xvinfos[i].visual);
  195253. if (pictVisualFormat != 0
  195254. && pictVisualFormat->type == PictTypeDirect
  195255. && pictVisualFormat->direct.alphaMask)
  195256. {
  195257. visual = xvinfos[i].visual;
  195258. matchedDepth = 32;
  195259. break;
  195260. }
  195261. }
  195262. XFree (xvinfos);
  195263. }
  195264. }
  195265. }
  195266. #endif
  195267. if (visual == 0)
  195268. {
  195269. visual = findVisualWithDepth (32);
  195270. if (visual != 0)
  195271. matchedDepth = 32;
  195272. }
  195273. }
  195274. #endif
  195275. }
  195276. if (visual == 0 && desiredDepth >= 24)
  195277. {
  195278. visual = findVisualWithDepth (24);
  195279. if (visual != 0)
  195280. matchedDepth = 24;
  195281. }
  195282. if (visual == 0 && desiredDepth >= 16)
  195283. {
  195284. visual = findVisualWithDepth (16);
  195285. if (visual != 0)
  195286. matchedDepth = 16;
  195287. }
  195288. return visual;
  195289. }
  195290. }
  195291. class XBitmapImage : public Image
  195292. {
  195293. public:
  195294. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195295. const bool clearImage, const int imageDepth_, Visual* visual)
  195296. : Image (format_, w, h),
  195297. imageDepth (imageDepth_),
  195298. gc (None)
  195299. {
  195300. jassert (format_ == RGB || format_ == ARGB);
  195301. pixelStride = (format_ == RGB) ? 3 : 4;
  195302. lineStride = ((w * pixelStride + 3) & ~3);
  195303. ScopedXLock xlock;
  195304. #if JUCE_USE_XSHM
  195305. usingXShm = false;
  195306. if ((imageDepth > 16) && XSHMHelpers::isShmAvailable())
  195307. {
  195308. zerostruct (segmentInfo);
  195309. segmentInfo.shmid = -1;
  195310. segmentInfo.shmaddr = (char *) -1;
  195311. segmentInfo.readOnly = False;
  195312. xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
  195313. if (xImage != 0)
  195314. {
  195315. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195316. xImage->bytes_per_line * xImage->height,
  195317. IPC_CREAT | 0777)) >= 0)
  195318. {
  195319. if (segmentInfo.shmid != -1)
  195320. {
  195321. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195322. if (segmentInfo.shmaddr != (void*) -1)
  195323. {
  195324. segmentInfo.readOnly = False;
  195325. xImage->data = segmentInfo.shmaddr;
  195326. imageData = (uint8*) segmentInfo.shmaddr;
  195327. if (XShmAttach (display, &segmentInfo) != 0)
  195328. {
  195329. usingXShm = true;
  195330. }
  195331. else
  195332. {
  195333. jassertfalse
  195334. }
  195335. }
  195336. else
  195337. {
  195338. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195339. }
  195340. }
  195341. }
  195342. }
  195343. }
  195344. if (! usingXShm)
  195345. #endif
  195346. {
  195347. imageDataAllocated.malloc (lineStride * h);
  195348. imageData = imageDataAllocated;
  195349. if (format_ == ARGB && clearImage)
  195350. zeromem (imageData, h * lineStride);
  195351. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195352. xImage->width = w;
  195353. xImage->height = h;
  195354. xImage->xoffset = 0;
  195355. xImage->format = ZPixmap;
  195356. xImage->data = (char*) imageData;
  195357. xImage->byte_order = ImageByteOrder (display);
  195358. xImage->bitmap_unit = BitmapUnit (display);
  195359. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195360. xImage->bitmap_pad = 32;
  195361. xImage->depth = pixelStride * 8;
  195362. xImage->bytes_per_line = lineStride;
  195363. xImage->bits_per_pixel = pixelStride * 8;
  195364. xImage->red_mask = 0x00FF0000;
  195365. xImage->green_mask = 0x0000FF00;
  195366. xImage->blue_mask = 0x000000FF;
  195367. if (imageDepth == 16)
  195368. {
  195369. const int pixelStride = 2;
  195370. const int lineStride = ((w * pixelStride + 3) & ~3);
  195371. imageData16Bit.malloc (lineStride * h);
  195372. xImage->data = imageData16Bit;
  195373. xImage->bitmap_pad = 16;
  195374. xImage->depth = pixelStride * 8;
  195375. xImage->bytes_per_line = lineStride;
  195376. xImage->bits_per_pixel = pixelStride * 8;
  195377. xImage->red_mask = visual->red_mask;
  195378. xImage->green_mask = visual->green_mask;
  195379. xImage->blue_mask = visual->blue_mask;
  195380. }
  195381. if (! XInitImage (xImage))
  195382. {
  195383. jassertfalse
  195384. }
  195385. }
  195386. }
  195387. ~XBitmapImage()
  195388. {
  195389. ScopedXLock xlock;
  195390. if (gc != None)
  195391. XFreeGC (display, gc);
  195392. #if JUCE_USE_XSHM
  195393. if (usingXShm)
  195394. {
  195395. XShmDetach (display, &segmentInfo);
  195396. XFlush (display);
  195397. XDestroyImage (xImage);
  195398. shmdt (segmentInfo.shmaddr);
  195399. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195400. }
  195401. else
  195402. #endif
  195403. {
  195404. xImage->data = 0;
  195405. XDestroyImage (xImage);
  195406. }
  195407. }
  195408. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195409. {
  195410. ScopedXLock xlock;
  195411. if (gc == None)
  195412. {
  195413. XGCValues gcvalues;
  195414. gcvalues.foreground = None;
  195415. gcvalues.background = None;
  195416. gcvalues.function = GXcopy;
  195417. gcvalues.plane_mask = AllPlanes;
  195418. gcvalues.clip_mask = None;
  195419. gcvalues.graphics_exposures = False;
  195420. gc = XCreateGC (display, window,
  195421. GCBackground | GCForeground | GCFunction | GCPlaneMask | GCClipMask | GCGraphicsExposures,
  195422. &gcvalues);
  195423. }
  195424. if (imageDepth == 16)
  195425. {
  195426. const uint32 rMask = xImage->red_mask;
  195427. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195428. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195429. const uint32 gMask = xImage->green_mask;
  195430. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195431. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195432. const uint32 bMask = xImage->blue_mask;
  195433. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195434. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195435. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195436. for (int y = sy; y < sy + dh; ++y)
  195437. {
  195438. const uint8* p = srcData.getPixelPointer (sx, y);
  195439. for (int x = sx; x < sx + dw; ++x)
  195440. {
  195441. const PixelRGB* const pixel = (const PixelRGB*) p;
  195442. p += srcData.pixelStride;
  195443. XPutPixel (xImage, x, y,
  195444. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195445. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195446. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195447. }
  195448. }
  195449. }
  195450. // blit results to screen.
  195451. #if JUCE_USE_XSHM
  195452. if (usingXShm)
  195453. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195454. else
  195455. #endif
  195456. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195457. }
  195458. juce_UseDebuggingNewOperator
  195459. private:
  195460. XImage* xImage;
  195461. const int imageDepth;
  195462. HeapBlock <char> imageData16Bit;
  195463. GC gc;
  195464. #if JUCE_USE_XSHM
  195465. XShmSegmentInfo segmentInfo;
  195466. bool usingXShm;
  195467. #endif
  195468. static int getShiftNeeded (const uint32 mask) throw()
  195469. {
  195470. for (int i = 32; --i >= 0;)
  195471. if (((mask >> i) & 1) != 0)
  195472. return i - 7;
  195473. jassertfalse
  195474. return 0;
  195475. }
  195476. };
  195477. class LinuxComponentPeer : public ComponentPeer
  195478. {
  195479. public:
  195480. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195481. : ComponentPeer (component, windowStyleFlags),
  195482. windowH (0),
  195483. parentWindow (0),
  195484. wx (0),
  195485. wy (0),
  195486. ww (0),
  195487. wh (0),
  195488. fullScreen (false),
  195489. mapped (false),
  195490. visual (0),
  195491. depth (0)
  195492. {
  195493. // it's dangerous to create a window on a thread other than the message thread..
  195494. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195495. repainter = new LinuxRepaintManager (this);
  195496. createWindow();
  195497. setTitle (component->getName());
  195498. }
  195499. ~LinuxComponentPeer()
  195500. {
  195501. // it's dangerous to delete a window on a thread other than the message thread..
  195502. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195503. deleteIconPixmaps();
  195504. destroyWindow();
  195505. windowH = 0;
  195506. }
  195507. void* getNativeHandle() const
  195508. {
  195509. return (void*) windowH;
  195510. }
  195511. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  195512. {
  195513. XPointer peer = 0;
  195514. ScopedXLock xlock;
  195515. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  195516. {
  195517. if (peer != 0 && ! ComponentPeer::isValidPeer ((LinuxComponentPeer*) peer))
  195518. peer = 0;
  195519. }
  195520. return (LinuxComponentPeer*) peer;
  195521. }
  195522. void setVisible (bool shouldBeVisible)
  195523. {
  195524. ScopedXLock xlock;
  195525. if (shouldBeVisible)
  195526. XMapWindow (display, windowH);
  195527. else
  195528. XUnmapWindow (display, windowH);
  195529. }
  195530. void setTitle (const String& title)
  195531. {
  195532. setWindowTitle (windowH, title);
  195533. }
  195534. void setPosition (int x, int y)
  195535. {
  195536. setBounds (x, y, ww, wh, false);
  195537. }
  195538. void setSize (int w, int h)
  195539. {
  195540. setBounds (wx, wy, w, h, false);
  195541. }
  195542. void setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  195543. {
  195544. fullScreen = isNowFullScreen;
  195545. if (windowH != 0)
  195546. {
  195547. Component::SafePointer<Component> deletionChecker (component);
  195548. wx = x;
  195549. wy = y;
  195550. ww = jmax (1, w);
  195551. wh = jmax (1, h);
  195552. ScopedXLock xlock;
  195553. // Make sure the Window manager does what we want
  195554. XSizeHints* hints = XAllocSizeHints();
  195555. hints->flags = USSize | USPosition;
  195556. hints->width = ww;
  195557. hints->height = wh;
  195558. hints->x = wx;
  195559. hints->y = wy;
  195560. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  195561. {
  195562. hints->min_width = hints->max_width = hints->width;
  195563. hints->min_height = hints->max_height = hints->height;
  195564. hints->flags |= PMinSize | PMaxSize;
  195565. }
  195566. XSetWMNormalHints (display, windowH, hints);
  195567. XFree (hints);
  195568. XMoveResizeWindow (display, windowH,
  195569. wx - windowBorder.getLeft(),
  195570. wy - windowBorder.getTop(), ww, wh);
  195571. if (deletionChecker != 0)
  195572. {
  195573. updateBorderSize();
  195574. handleMovedOrResized();
  195575. }
  195576. }
  195577. }
  195578. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  195579. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  195580. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  195581. {
  195582. return relativePosition + getScreenPosition();
  195583. }
  195584. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  195585. {
  195586. return screenPosition - getScreenPosition();
  195587. }
  195588. void setMinimised (bool shouldBeMinimised)
  195589. {
  195590. if (shouldBeMinimised)
  195591. {
  195592. Window root = RootWindow (display, DefaultScreen (display));
  195593. XClientMessageEvent clientMsg;
  195594. clientMsg.display = display;
  195595. clientMsg.window = windowH;
  195596. clientMsg.type = ClientMessage;
  195597. clientMsg.format = 32;
  195598. clientMsg.message_type = Atoms::ChangeState;
  195599. clientMsg.data.l[0] = IconicState;
  195600. ScopedXLock xlock;
  195601. XSendEvent (display, root, false,
  195602. SubstructureRedirectMask | SubstructureNotifyMask,
  195603. (XEvent*) &clientMsg);
  195604. }
  195605. else
  195606. {
  195607. setVisible (true);
  195608. }
  195609. }
  195610. bool isMinimised() const
  195611. {
  195612. bool minimised = false;
  195613. unsigned char* stateProp;
  195614. unsigned long nitems, bytesLeft;
  195615. Atom actualType;
  195616. int actualFormat;
  195617. ScopedXLock xlock;
  195618. if (XGetWindowProperty (display, windowH, Atoms::State, 0, 64, False,
  195619. Atoms::State, &actualType, &actualFormat, &nitems, &bytesLeft,
  195620. &stateProp) == Success
  195621. && actualType == Atoms::State
  195622. && actualFormat == 32
  195623. && nitems > 0)
  195624. {
  195625. if (((unsigned long*) stateProp)[0] == IconicState)
  195626. minimised = true;
  195627. XFree (stateProp);
  195628. }
  195629. return minimised;
  195630. }
  195631. void setFullScreen (const bool shouldBeFullScreen)
  195632. {
  195633. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  195634. setMinimised (false);
  195635. if (fullScreen != shouldBeFullScreen)
  195636. {
  195637. if (shouldBeFullScreen)
  195638. r = Desktop::getInstance().getMainMonitorArea();
  195639. if (! r.isEmpty())
  195640. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  195641. getComponent()->repaint();
  195642. }
  195643. }
  195644. bool isFullScreen() const
  195645. {
  195646. return fullScreen;
  195647. }
  195648. bool isChildWindowOf (Window possibleParent) const
  195649. {
  195650. Window* windowList = 0;
  195651. uint32 windowListSize = 0;
  195652. Window parent, root;
  195653. ScopedXLock xlock;
  195654. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  195655. {
  195656. if (windowList != 0)
  195657. XFree (windowList);
  195658. return parent == possibleParent;
  195659. }
  195660. return false;
  195661. }
  195662. bool isFrontWindow() const
  195663. {
  195664. Window* windowList = 0;
  195665. uint32 windowListSize = 0;
  195666. bool result = false;
  195667. ScopedXLock xlock;
  195668. Window parent, root = RootWindow (display, DefaultScreen (display));
  195669. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  195670. {
  195671. for (int i = windowListSize; --i >= 0;)
  195672. {
  195673. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  195674. if (peer != 0)
  195675. {
  195676. result = (peer == this);
  195677. break;
  195678. }
  195679. }
  195680. }
  195681. if (windowList != 0)
  195682. XFree (windowList);
  195683. return result;
  195684. }
  195685. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
  195686. {
  195687. int x = position.getX();
  195688. int y = position.getY();
  195689. if (((unsigned int) x) >= (unsigned int) ww
  195690. || ((unsigned int) y) >= (unsigned int) wh)
  195691. return false;
  195692. bool inFront = false;
  195693. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  195694. {
  195695. Component* const c = Desktop::getInstance().getComponent (i);
  195696. if (inFront)
  195697. {
  195698. if (c->contains (x + wx - c->getScreenX(),
  195699. y + wy - c->getScreenY()))
  195700. {
  195701. return false;
  195702. }
  195703. }
  195704. else if (c == getComponent())
  195705. {
  195706. inFront = true;
  195707. }
  195708. }
  195709. if (trueIfInAChildWindow)
  195710. return true;
  195711. ::Window root, child;
  195712. unsigned int bw, depth;
  195713. int wx, wy, w, h;
  195714. ScopedXLock xlock;
  195715. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  195716. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  195717. &bw, &depth))
  195718. {
  195719. return false;
  195720. }
  195721. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  195722. return false;
  195723. return child == None;
  195724. }
  195725. const BorderSize getFrameSize() const
  195726. {
  195727. return BorderSize();
  195728. }
  195729. bool setAlwaysOnTop (bool alwaysOnTop)
  195730. {
  195731. if (windowH != 0)
  195732. {
  195733. const bool wasVisible = component->isVisible();
  195734. if (wasVisible)
  195735. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  195736. {
  195737. ScopedXLock xlock;
  195738. XSetWindowAttributes swa;
  195739. swa.override_redirect = alwaysOnTop ? True : False;
  195740. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  195741. }
  195742. if (wasVisible)
  195743. setVisible (true);
  195744. }
  195745. return true;
  195746. }
  195747. void toFront (bool makeActive)
  195748. {
  195749. if (makeActive)
  195750. {
  195751. setVisible (true);
  195752. grabFocus();
  195753. }
  195754. XEvent ev;
  195755. ev.xclient.type = ClientMessage;
  195756. ev.xclient.serial = 0;
  195757. ev.xclient.send_event = True;
  195758. ev.xclient.message_type = Atoms::ActiveWin;
  195759. ev.xclient.window = windowH;
  195760. ev.xclient.format = 32;
  195761. ev.xclient.data.l[0] = 2;
  195762. ev.xclient.data.l[1] = CurrentTime;
  195763. ev.xclient.data.l[2] = 0;
  195764. ev.xclient.data.l[3] = 0;
  195765. ev.xclient.data.l[4] = 0;
  195766. {
  195767. ScopedXLock xlock;
  195768. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  195769. False,
  195770. SubstructureRedirectMask | SubstructureNotifyMask,
  195771. &ev);
  195772. XWindowAttributes attr;
  195773. XGetWindowAttributes (display, windowH, &attr);
  195774. if (attr.override_redirect)
  195775. XRaiseWindow (display, windowH);
  195776. XSync (display, False);
  195777. }
  195778. handleBroughtToFront();
  195779. }
  195780. void toBehind (ComponentPeer* other)
  195781. {
  195782. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  195783. jassert (otherPeer != 0); // wrong type of window?
  195784. if (otherPeer != 0)
  195785. {
  195786. setMinimised (false);
  195787. Window newStack[] = { otherPeer->windowH, windowH };
  195788. ScopedXLock xlock;
  195789. XRestackWindows (display, newStack, 2);
  195790. }
  195791. }
  195792. bool isFocused() const
  195793. {
  195794. int revert;
  195795. Window focusedWindow = 0;
  195796. ScopedXLock xlock;
  195797. XGetInputFocus (display, &focusedWindow, &revert);
  195798. return focusedWindow == windowH;
  195799. }
  195800. void grabFocus()
  195801. {
  195802. XWindowAttributes atts;
  195803. ScopedXLock xlock;
  195804. if (windowH != 0
  195805. && XGetWindowAttributes (display, windowH, &atts)
  195806. && atts.map_state == IsViewable
  195807. && ! isFocused())
  195808. {
  195809. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  195810. isActiveApplication = true;
  195811. }
  195812. }
  195813. void textInputRequired (const Point<int>&)
  195814. {
  195815. }
  195816. void repaint (int x, int y, int w, int h)
  195817. {
  195818. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  195819. 0, 0,
  195820. getComponent()->getWidth(),
  195821. getComponent()->getHeight()))
  195822. {
  195823. repainter->repaint (x, y, w, h);
  195824. }
  195825. }
  195826. void performAnyPendingRepaintsNow()
  195827. {
  195828. repainter->performAnyPendingRepaintsNow();
  195829. }
  195830. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  195831. {
  195832. ScopedXLock xlock;
  195833. const int width = image.getWidth();
  195834. const int height = image.getHeight();
  195835. HeapBlock <char> colour (width * height);
  195836. int index = 0;
  195837. for (int y = 0; y < height; ++y)
  195838. for (int x = 0; x < width; ++x)
  195839. colour[index++] = static_cast<char> (image.getPixelAt (x, y).getARGB());
  195840. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  195841. 0, colour.getData(),
  195842. width, height, 32, 0);
  195843. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  195844. width, height, 24);
  195845. GC gc = XCreateGC (display, pixmap, 0, 0);
  195846. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  195847. XFreeGC (display, gc);
  195848. return pixmap;
  195849. }
  195850. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  195851. {
  195852. ScopedXLock xlock;
  195853. const int width = image.getWidth();
  195854. const int height = image.getHeight();
  195855. const int stride = (width + 7) >> 3;
  195856. HeapBlock <char> mask;
  195857. mask.calloc (stride * height);
  195858. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  195859. for (int y = 0; y < height; ++y)
  195860. {
  195861. for (int x = 0; x < width; ++x)
  195862. {
  195863. const char bit = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  195864. const int offset = y * stride + (x >> 3);
  195865. if (image.getPixelAt (x, y).getAlpha() >= 128)
  195866. mask[offset] |= bit;
  195867. }
  195868. }
  195869. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  195870. mask.getData(), width, height, 1, 0, 1);
  195871. }
  195872. void setIcon (const Image& newIcon)
  195873. {
  195874. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  195875. HeapBlock <unsigned long> data (dataSize);
  195876. int index = 0;
  195877. data[index++] = newIcon.getWidth();
  195878. data[index++] = newIcon.getHeight();
  195879. for (int y = 0; y < newIcon.getHeight(); ++y)
  195880. for (int x = 0; x < newIcon.getWidth(); ++x)
  195881. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  195882. ScopedXLock xlock;
  195883. XChangeProperty (display, windowH,
  195884. XInternAtom (display, "_NET_WM_ICON", False),
  195885. XA_CARDINAL, 32, PropModeReplace,
  195886. reinterpret_cast<unsigned char*> (data.getData()), dataSize);
  195887. deleteIconPixmaps();
  195888. XWMHints* wmHints = XGetWMHints (display, windowH);
  195889. if (wmHints == 0)
  195890. wmHints = XAllocWMHints();
  195891. wmHints->flags |= IconPixmapHint | IconMaskHint;
  195892. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  195893. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  195894. XSetWMHints (display, windowH, wmHints);
  195895. XFree (wmHints);
  195896. XSync (display, False);
  195897. }
  195898. void deleteIconPixmaps()
  195899. {
  195900. ScopedXLock xlock;
  195901. XWMHints* wmHints = XGetWMHints (display, windowH);
  195902. if (wmHints != 0)
  195903. {
  195904. if ((wmHints->flags & IconPixmapHint) != 0)
  195905. {
  195906. wmHints->flags &= ~IconPixmapHint;
  195907. XFreePixmap (display, wmHints->icon_pixmap);
  195908. }
  195909. if ((wmHints->flags & IconMaskHint) != 0)
  195910. {
  195911. wmHints->flags &= ~IconMaskHint;
  195912. XFreePixmap (display, wmHints->icon_mask);
  195913. }
  195914. XSetWMHints (display, windowH, wmHints);
  195915. XFree (wmHints);
  195916. }
  195917. }
  195918. void handleWindowMessage (XEvent* event)
  195919. {
  195920. switch (event->xany.type)
  195921. {
  195922. case 2: // 'KeyPress'
  195923. {
  195924. ScopedXLock xlock;
  195925. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  195926. updateKeyStates (keyEvent->keycode, true);
  195927. char utf8 [64];
  195928. zeromem (utf8, sizeof (utf8));
  195929. KeySym sym;
  195930. {
  195931. const char* oldLocale = ::setlocale (LC_ALL, 0);
  195932. ::setlocale (LC_ALL, "");
  195933. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  195934. ::setlocale (LC_ALL, oldLocale);
  195935. }
  195936. const juce_wchar unicodeChar = String::fromUTF8 (utf8, sizeof (utf8) - 1) [0];
  195937. int keyCode = (int) unicodeChar;
  195938. if (keyCode < 0x20)
  195939. keyCode = XKeycodeToKeysym (display, keyEvent->keycode, currentModifiers.isShiftDown() ? 1 : 0);
  195940. const ModifierKeys oldMods (currentModifiers);
  195941. bool keyPressed = false;
  195942. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  195943. if ((sym & 0xff00) == 0xff00)
  195944. {
  195945. // Translate keypad
  195946. if (sym == XK_KP_Divide)
  195947. keyCode = XK_slash;
  195948. else if (sym == XK_KP_Multiply)
  195949. keyCode = XK_asterisk;
  195950. else if (sym == XK_KP_Subtract)
  195951. keyCode = XK_hyphen;
  195952. else if (sym == XK_KP_Add)
  195953. keyCode = XK_plus;
  195954. else if (sym == XK_KP_Enter)
  195955. keyCode = XK_Return;
  195956. else if (sym == XK_KP_Decimal)
  195957. keyCode = Keys::numLock ? XK_period : XK_Delete;
  195958. else if (sym == XK_KP_0)
  195959. keyCode = Keys::numLock ? XK_0 : XK_Insert;
  195960. else if (sym == XK_KP_1)
  195961. keyCode = Keys::numLock ? XK_1 : XK_End;
  195962. else if (sym == XK_KP_2)
  195963. keyCode = Keys::numLock ? XK_2 : XK_Down;
  195964. else if (sym == XK_KP_3)
  195965. keyCode = Keys::numLock ? XK_3 : XK_Page_Down;
  195966. else if (sym == XK_KP_4)
  195967. keyCode = Keys::numLock ? XK_4 : XK_Left;
  195968. else if (sym == XK_KP_5)
  195969. keyCode = XK_5;
  195970. else if (sym == XK_KP_6)
  195971. keyCode = Keys::numLock ? XK_6 : XK_Right;
  195972. else if (sym == XK_KP_7)
  195973. keyCode = Keys::numLock ? XK_7 : XK_Home;
  195974. else if (sym == XK_KP_8)
  195975. keyCode = Keys::numLock ? XK_8 : XK_Up;
  195976. else if (sym == XK_KP_9)
  195977. keyCode = Keys::numLock ? XK_9 : XK_Page_Up;
  195978. switch (sym)
  195979. {
  195980. case XK_Left:
  195981. case XK_Right:
  195982. case XK_Up:
  195983. case XK_Down:
  195984. case XK_Page_Up:
  195985. case XK_Page_Down:
  195986. case XK_End:
  195987. case XK_Home:
  195988. case XK_Delete:
  195989. case XK_Insert:
  195990. keyPressed = true;
  195991. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  195992. break;
  195993. case XK_Tab:
  195994. case XK_Return:
  195995. case XK_Escape:
  195996. case XK_BackSpace:
  195997. keyPressed = true;
  195998. keyCode &= 0xff;
  195999. break;
  196000. default:
  196001. {
  196002. if (sym >= XK_F1 && sym <= XK_F16)
  196003. {
  196004. keyPressed = true;
  196005. keyCode = (sym & 0xff) | Keys::extendedKeyModifier;
  196006. }
  196007. break;
  196008. }
  196009. }
  196010. }
  196011. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196012. keyPressed = true;
  196013. if (oldMods != currentModifiers)
  196014. handleModifierKeysChange();
  196015. if (keyDownChange)
  196016. handleKeyUpOrDown (true);
  196017. if (keyPressed)
  196018. handleKeyPress (keyCode, unicodeChar);
  196019. break;
  196020. }
  196021. case KeyRelease:
  196022. {
  196023. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196024. updateKeyStates (keyEvent->keycode, false);
  196025. ScopedXLock xlock;
  196026. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196027. const ModifierKeys oldMods (currentModifiers);
  196028. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196029. if (oldMods != currentModifiers)
  196030. handleModifierKeysChange();
  196031. if (keyDownChange)
  196032. handleKeyUpOrDown (false);
  196033. break;
  196034. }
  196035. case ButtonPress:
  196036. {
  196037. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196038. updateKeyModifiers (buttonPressEvent->state);
  196039. bool buttonMsg = false;
  196040. const int map = pointerMap [buttonPressEvent->button - Button1];
  196041. if (map == Keys::WheelUp || map == Keys::WheelDown)
  196042. {
  196043. handleMouseWheel (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196044. getEventTime (buttonPressEvent->time), 0, map == Keys::WheelDown ? -84.0f : 84.0f);
  196045. }
  196046. if (map == Keys::LeftButton)
  196047. {
  196048. currentModifiers = currentModifiers.withFlags (ModifierKeys::leftButtonModifier);
  196049. buttonMsg = true;
  196050. }
  196051. else if (map == Keys::RightButton)
  196052. {
  196053. currentModifiers = currentModifiers.withFlags (ModifierKeys::rightButtonModifier);
  196054. buttonMsg = true;
  196055. }
  196056. else if (map == Keys::MiddleButton)
  196057. {
  196058. currentModifiers = currentModifiers.withFlags (ModifierKeys::middleButtonModifier);
  196059. buttonMsg = true;
  196060. }
  196061. if (buttonMsg)
  196062. {
  196063. toFront (true);
  196064. handleMouseEvent (0, Point<int> (buttonPressEvent->x, buttonPressEvent->y), currentModifiers,
  196065. getEventTime (buttonPressEvent->time));
  196066. }
  196067. clearLastMousePos();
  196068. break;
  196069. }
  196070. case ButtonRelease:
  196071. {
  196072. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196073. updateKeyModifiers (buttonRelEvent->state);
  196074. const int map = pointerMap [buttonRelEvent->button - Button1];
  196075. if (map == Keys::LeftButton)
  196076. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::leftButtonModifier);
  196077. else if (map == Keys::RightButton)
  196078. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::rightButtonModifier);
  196079. else if (map == Keys::MiddleButton)
  196080. currentModifiers = currentModifiers.withoutFlags (ModifierKeys::middleButtonModifier);
  196081. handleMouseEvent (0, Point<int> (buttonRelEvent->x, buttonRelEvent->y), currentModifiers,
  196082. getEventTime (buttonRelEvent->time));
  196083. clearLastMousePos();
  196084. break;
  196085. }
  196086. case MotionNotify:
  196087. {
  196088. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196089. updateKeyModifiers (movedEvent->state);
  196090. const Point<int> mousePos (Desktop::getMousePosition());
  196091. if (lastMousePos != mousePos)
  196092. {
  196093. lastMousePos = mousePos;
  196094. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196095. {
  196096. Window wRoot = 0, wParent = 0;
  196097. {
  196098. ScopedXLock xlock;
  196099. unsigned int numChildren;
  196100. Window* wChild = 0;
  196101. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196102. }
  196103. if (wParent != 0
  196104. && wParent != windowH
  196105. && wParent != wRoot)
  196106. {
  196107. parentWindow = wParent;
  196108. updateBounds();
  196109. }
  196110. else
  196111. {
  196112. parentWindow = 0;
  196113. }
  196114. }
  196115. handleMouseEvent (0, mousePos - getScreenPosition(), currentModifiers, getEventTime (movedEvent->time));
  196116. }
  196117. break;
  196118. }
  196119. case EnterNotify:
  196120. {
  196121. clearLastMousePos();
  196122. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196123. if (! currentModifiers.isAnyMouseButtonDown())
  196124. {
  196125. updateKeyModifiers (enterEvent->state);
  196126. handleMouseEvent (0, Point<int> (enterEvent->x, enterEvent->y), currentModifiers, getEventTime (enterEvent->time));
  196127. }
  196128. break;
  196129. }
  196130. case LeaveNotify:
  196131. {
  196132. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196133. // Suppress the normal leave if we've got a pointer grab, or if
  196134. // it's a bogus one caused by clicking a mouse button when running
  196135. // in a Window manager
  196136. if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent->mode == NotifyNormal)
  196137. || leaveEvent->mode == NotifyUngrab)
  196138. {
  196139. updateKeyModifiers (leaveEvent->state);
  196140. handleMouseEvent (0, Point<int> (leaveEvent->x, leaveEvent->y), currentModifiers, getEventTime (leaveEvent->time));
  196141. }
  196142. break;
  196143. }
  196144. case FocusIn:
  196145. {
  196146. isActiveApplication = true;
  196147. if (isFocused())
  196148. handleFocusGain();
  196149. break;
  196150. }
  196151. case FocusOut:
  196152. {
  196153. isActiveApplication = false;
  196154. if (! isFocused())
  196155. handleFocusLoss();
  196156. break;
  196157. }
  196158. case Expose:
  196159. {
  196160. // Batch together all pending expose events
  196161. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196162. XEvent nextEvent;
  196163. ScopedXLock xlock;
  196164. if (exposeEvent->window != windowH)
  196165. {
  196166. Window child;
  196167. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196168. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196169. &child);
  196170. }
  196171. repaint (exposeEvent->x, exposeEvent->y,
  196172. exposeEvent->width, exposeEvent->height);
  196173. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196174. {
  196175. XPeekEvent (display, (XEvent*) &nextEvent);
  196176. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196177. break;
  196178. XNextEvent (display, (XEvent*) &nextEvent);
  196179. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196180. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196181. nextExposeEvent->width, nextExposeEvent->height);
  196182. }
  196183. break;
  196184. }
  196185. case CirculateNotify:
  196186. case CreateNotify:
  196187. case DestroyNotify:
  196188. // Think we can ignore these
  196189. break;
  196190. case ConfigureNotify:
  196191. {
  196192. updateBounds();
  196193. updateBorderSize();
  196194. handleMovedOrResized();
  196195. // if the native title bar is dragged, need to tell any active menus, etc.
  196196. if ((styleFlags & windowHasTitleBar) != 0
  196197. && component->isCurrentlyBlockedByAnotherModalComponent())
  196198. {
  196199. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196200. if (currentModalComp != 0)
  196201. currentModalComp->inputAttemptWhenModal();
  196202. }
  196203. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196204. if (confEvent->window == windowH
  196205. && confEvent->above != 0
  196206. && isFrontWindow())
  196207. {
  196208. handleBroughtToFront();
  196209. }
  196210. break;
  196211. }
  196212. case ReparentNotify:
  196213. {
  196214. parentWindow = 0;
  196215. Window wRoot = 0;
  196216. Window* wChild = 0;
  196217. unsigned int numChildren;
  196218. {
  196219. ScopedXLock xlock;
  196220. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196221. }
  196222. if (parentWindow == windowH || parentWindow == wRoot)
  196223. parentWindow = 0;
  196224. updateBounds();
  196225. updateBorderSize();
  196226. handleMovedOrResized();
  196227. break;
  196228. }
  196229. case GravityNotify:
  196230. {
  196231. updateBounds();
  196232. updateBorderSize();
  196233. handleMovedOrResized();
  196234. break;
  196235. }
  196236. case MapNotify:
  196237. mapped = true;
  196238. handleBroughtToFront();
  196239. break;
  196240. case UnmapNotify:
  196241. mapped = false;
  196242. break;
  196243. case MappingNotify:
  196244. {
  196245. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196246. if (mappingEvent->request != MappingPointer)
  196247. {
  196248. // Deal with modifier/keyboard mapping
  196249. ScopedXLock xlock;
  196250. XRefreshKeyboardMapping (mappingEvent);
  196251. updateModifierMappings();
  196252. }
  196253. break;
  196254. }
  196255. case ClientMessage:
  196256. {
  196257. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196258. if (clientMsg->message_type == Atoms::Protocols && clientMsg->format == 32)
  196259. {
  196260. const Atom atom = (Atom) clientMsg->data.l[0];
  196261. if (atom == Atoms::ProtocolList [Atoms::PING])
  196262. {
  196263. Window root = RootWindow (display, DefaultScreen (display));
  196264. event->xclient.window = root;
  196265. XSendEvent (display, root, False, NoEventMask, event);
  196266. XFlush (display);
  196267. }
  196268. else if (atom == Atoms::ProtocolList [Atoms::TAKE_FOCUS])
  196269. {
  196270. XWindowAttributes atts;
  196271. ScopedXLock xlock;
  196272. if (clientMsg->window != 0
  196273. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196274. {
  196275. if (atts.map_state == IsViewable)
  196276. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196277. }
  196278. }
  196279. else if (atom == Atoms::ProtocolList [Atoms::DELETE_WINDOW])
  196280. {
  196281. handleUserClosingWindow();
  196282. }
  196283. }
  196284. else if (clientMsg->message_type == Atoms::XdndEnter)
  196285. {
  196286. handleDragAndDropEnter (clientMsg);
  196287. }
  196288. else if (clientMsg->message_type == Atoms::XdndLeave)
  196289. {
  196290. resetDragAndDrop();
  196291. }
  196292. else if (clientMsg->message_type == Atoms::XdndPosition)
  196293. {
  196294. handleDragAndDropPosition (clientMsg);
  196295. }
  196296. else if (clientMsg->message_type == Atoms::XdndDrop)
  196297. {
  196298. handleDragAndDropDrop (clientMsg);
  196299. }
  196300. else if (clientMsg->message_type == Atoms::XdndStatus)
  196301. {
  196302. handleDragAndDropStatus (clientMsg);
  196303. }
  196304. else if (clientMsg->message_type == Atoms::XdndFinished)
  196305. {
  196306. resetDragAndDrop();
  196307. }
  196308. break;
  196309. }
  196310. case SelectionNotify:
  196311. handleDragAndDropSelection (event);
  196312. break;
  196313. case SelectionClear:
  196314. case SelectionRequest:
  196315. break;
  196316. default:
  196317. #if JUCE_USE_XSHM
  196318. {
  196319. ScopedXLock xlock;
  196320. if (event->xany.type == XShmGetEventBase (display))
  196321. repainter->notifyPaintCompleted();
  196322. }
  196323. #endif
  196324. break;
  196325. }
  196326. }
  196327. void showMouseCursor (Cursor cursor) throw()
  196328. {
  196329. ScopedXLock xlock;
  196330. XDefineCursor (display, windowH, cursor);
  196331. }
  196332. void setTaskBarIcon (const Image& image)
  196333. {
  196334. ScopedXLock xlock;
  196335. taskbarImage = image.createCopy();
  196336. Screen* const screen = XDefaultScreenOfDisplay (display);
  196337. const int screenNumber = XScreenNumberOfScreen (screen);
  196338. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196339. screenAtom << screenNumber;
  196340. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196341. XGrabServer (display);
  196342. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196343. if (managerWin != None)
  196344. XSelectInput (display, managerWin, StructureNotifyMask);
  196345. XUngrabServer (display);
  196346. XFlush (display);
  196347. if (managerWin != None)
  196348. {
  196349. XEvent ev;
  196350. zerostruct (ev);
  196351. ev.xclient.type = ClientMessage;
  196352. ev.xclient.window = managerWin;
  196353. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196354. ev.xclient.format = 32;
  196355. ev.xclient.data.l[0] = CurrentTime;
  196356. ev.xclient.data.l[1] = 0 /*SYSTEM_TRAY_REQUEST_DOCK*/;
  196357. ev.xclient.data.l[2] = windowH;
  196358. ev.xclient.data.l[3] = 0;
  196359. ev.xclient.data.l[4] = 0;
  196360. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196361. XSync (display, False);
  196362. }
  196363. // For older KDE's ...
  196364. long atomData = 1;
  196365. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196366. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196367. // For more recent KDE's...
  196368. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196369. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196370. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196371. XSizeHints* hints = XAllocSizeHints();
  196372. hints->flags = PMinSize;
  196373. hints->min_width = 22;
  196374. hints->min_height = 22;
  196375. XSetWMNormalHints (display, windowH, hints);
  196376. XFree (hints);
  196377. }
  196378. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196379. juce_UseDebuggingNewOperator
  196380. bool dontRepaint;
  196381. static ModifierKeys currentModifiers;
  196382. static bool isActiveApplication;
  196383. private:
  196384. class LinuxRepaintManager : public Timer
  196385. {
  196386. public:
  196387. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196388. : peer (peer_),
  196389. lastTimeImageUsed (0)
  196390. {
  196391. #if JUCE_USE_XSHM
  196392. shmCompletedDrawing = true;
  196393. useARGBImagesForRendering = XSHMHelpers::isShmAvailable();
  196394. if (useARGBImagesForRendering)
  196395. {
  196396. ScopedXLock xlock;
  196397. XShmSegmentInfo segmentinfo;
  196398. XImage* const testImage
  196399. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196400. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196401. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196402. XDestroyImage (testImage);
  196403. }
  196404. #endif
  196405. }
  196406. ~LinuxRepaintManager()
  196407. {
  196408. }
  196409. void timerCallback()
  196410. {
  196411. #if JUCE_USE_XSHM
  196412. if (! shmCompletedDrawing)
  196413. return;
  196414. #endif
  196415. if (! regionsNeedingRepaint.isEmpty())
  196416. {
  196417. stopTimer();
  196418. performAnyPendingRepaintsNow();
  196419. }
  196420. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196421. {
  196422. stopTimer();
  196423. image = 0;
  196424. }
  196425. }
  196426. void repaint (int x, int y, int w, int h)
  196427. {
  196428. if (! isTimerRunning())
  196429. startTimer (repaintTimerPeriod);
  196430. regionsNeedingRepaint.add (x, y, w, h);
  196431. }
  196432. void performAnyPendingRepaintsNow()
  196433. {
  196434. #if JUCE_USE_XSHM
  196435. if (! shmCompletedDrawing)
  196436. {
  196437. startTimer (repaintTimerPeriod);
  196438. return;
  196439. }
  196440. #endif
  196441. peer->clearMaskedRegion();
  196442. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196443. regionsNeedingRepaint.clear();
  196444. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196445. if (! totalArea.isEmpty())
  196446. {
  196447. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196448. || image->getHeight() < totalArea.getHeight())
  196449. {
  196450. #if JUCE_USE_XSHM
  196451. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196452. : Image::RGB,
  196453. #else
  196454. image = new XBitmapImage (Image::RGB,
  196455. #endif
  196456. (totalArea.getWidth() + 31) & ~31,
  196457. (totalArea.getHeight() + 31) & ~31,
  196458. false,
  196459. peer->depth,
  196460. peer->visual);
  196461. }
  196462. startTimer (repaintTimerPeriod);
  196463. LowLevelGraphicsSoftwareRenderer context (*image);
  196464. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196465. if (context.clipToRectangleList (originalRepaintRegion))
  196466. {
  196467. if (peer->depth == 32)
  196468. {
  196469. RectangleList::Iterator i (originalRepaintRegion);
  196470. while (i.next())
  196471. {
  196472. const Rectangle<int>& r = *i.getRectangle();
  196473. image->clear (r.getX() - totalArea.getX(), r.getY() - totalArea.getY(), r.getWidth(), r.getHeight());
  196474. }
  196475. }
  196476. peer->handlePaint (context);
  196477. }
  196478. if (! peer->maskedRegion.isEmpty())
  196479. originalRepaintRegion.subtract (peer->maskedRegion);
  196480. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196481. {
  196482. #if JUCE_USE_XSHM
  196483. shmCompletedDrawing = false;
  196484. #endif
  196485. const Rectangle<int>& r = *i.getRectangle();
  196486. image->blitToWindow (peer->windowH,
  196487. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196488. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196489. }
  196490. }
  196491. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196492. startTimer (repaintTimerPeriod);
  196493. }
  196494. #if JUCE_USE_XSHM
  196495. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196496. #endif
  196497. private:
  196498. enum { repaintTimerPeriod = 1000 / 100 };
  196499. LinuxComponentPeer* const peer;
  196500. ScopedPointer <XBitmapImage> image;
  196501. uint32 lastTimeImageUsed;
  196502. RectangleList regionsNeedingRepaint;
  196503. #if JUCE_USE_XSHM
  196504. bool useARGBImagesForRendering, shmCompletedDrawing;
  196505. #endif
  196506. LinuxRepaintManager (const LinuxRepaintManager&);
  196507. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  196508. };
  196509. ScopedPointer <LinuxRepaintManager> repainter;
  196510. friend class LinuxRepaintManager;
  196511. Window windowH, parentWindow;
  196512. int wx, wy, ww, wh;
  196513. ScopedPointer<Image> taskbarImage;
  196514. bool fullScreen, mapped;
  196515. Visual* visual;
  196516. int depth;
  196517. BorderSize windowBorder;
  196518. struct MotifWmHints
  196519. {
  196520. unsigned long flags;
  196521. unsigned long functions;
  196522. unsigned long decorations;
  196523. long input_mode;
  196524. unsigned long status;
  196525. };
  196526. static void updateKeyStates (const int keycode, const bool press) throw()
  196527. {
  196528. const int keybyte = keycode >> 3;
  196529. const int keybit = (1 << (keycode & 7));
  196530. if (press)
  196531. Keys::keyStates [keybyte] |= keybit;
  196532. else
  196533. Keys::keyStates [keybyte] &= ~keybit;
  196534. }
  196535. static void updateKeyModifiers (const int status) throw()
  196536. {
  196537. int keyMods = 0;
  196538. if (status & ShiftMask) keyMods |= ModifierKeys::shiftModifier;
  196539. if (status & ControlMask) keyMods |= ModifierKeys::ctrlModifier;
  196540. if (status & Keys::AltMask) keyMods |= ModifierKeys::altModifier;
  196541. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (keyMods);
  196542. Keys::numLock = ((status & Keys::NumLockMask) != 0);
  196543. Keys::capsLock = ((status & LockMask) != 0);
  196544. }
  196545. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  196546. {
  196547. int modifier = 0;
  196548. bool isModifier = true;
  196549. switch (sym)
  196550. {
  196551. case XK_Shift_L:
  196552. case XK_Shift_R:
  196553. modifier = ModifierKeys::shiftModifier;
  196554. break;
  196555. case XK_Control_L:
  196556. case XK_Control_R:
  196557. modifier = ModifierKeys::ctrlModifier;
  196558. break;
  196559. case XK_Alt_L:
  196560. case XK_Alt_R:
  196561. modifier = ModifierKeys::altModifier;
  196562. break;
  196563. case XK_Num_Lock:
  196564. if (press)
  196565. Keys::numLock = ! Keys::numLock;
  196566. break;
  196567. case XK_Caps_Lock:
  196568. if (press)
  196569. Keys::capsLock = ! Keys::capsLock;
  196570. break;
  196571. case XK_Scroll_Lock:
  196572. break;
  196573. default:
  196574. isModifier = false;
  196575. break;
  196576. }
  196577. if (modifier != 0)
  196578. {
  196579. if (press)
  196580. currentModifiers = currentModifiers.withFlags (modifier);
  196581. else
  196582. currentModifiers = currentModifiers.withoutFlags (modifier);
  196583. }
  196584. return isModifier;
  196585. }
  196586. // Alt and Num lock are not defined by standard X
  196587. // modifier constants: check what they're mapped to
  196588. static void updateModifierMappings() throw()
  196589. {
  196590. ScopedXLock xlock;
  196591. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  196592. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  196593. Keys::AltMask = 0;
  196594. Keys::NumLockMask = 0;
  196595. XModifierKeymap* mapping = XGetModifierMapping (display);
  196596. if (mapping)
  196597. {
  196598. for (int i = 0; i < 8; i++)
  196599. {
  196600. if (mapping->modifiermap [i << 1] == altLeftCode)
  196601. Keys::AltMask = 1 << i;
  196602. else if (mapping->modifiermap [i << 1] == numLockCode)
  196603. Keys::NumLockMask = 1 << i;
  196604. }
  196605. XFreeModifiermap (mapping);
  196606. }
  196607. }
  196608. void removeWindowDecorations (Window wndH)
  196609. {
  196610. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196611. if (hints != None)
  196612. {
  196613. MotifWmHints motifHints;
  196614. zerostruct (motifHints);
  196615. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  196616. motifHints.decorations = 0;
  196617. ScopedXLock xlock;
  196618. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196619. (unsigned char*) &motifHints, 4);
  196620. }
  196621. hints = XInternAtom (display, "_WIN_HINTS", True);
  196622. if (hints != None)
  196623. {
  196624. long gnomeHints = 0;
  196625. ScopedXLock xlock;
  196626. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196627. (unsigned char*) &gnomeHints, 1);
  196628. }
  196629. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  196630. if (hints != None)
  196631. {
  196632. long kwmHints = 2; /*KDE_tinyDecoration*/
  196633. ScopedXLock xlock;
  196634. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  196635. (unsigned char*) &kwmHints, 1);
  196636. }
  196637. }
  196638. void addWindowButtons (Window wndH)
  196639. {
  196640. ScopedXLock xlock;
  196641. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  196642. if (hints != None)
  196643. {
  196644. MotifWmHints motifHints;
  196645. zerostruct (motifHints);
  196646. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  196647. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  196648. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  196649. if ((styleFlags & windowHasCloseButton) != 0)
  196650. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  196651. if ((styleFlags & windowHasMinimiseButton) != 0)
  196652. {
  196653. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  196654. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  196655. }
  196656. if ((styleFlags & windowHasMaximiseButton) != 0)
  196657. {
  196658. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  196659. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  196660. }
  196661. if ((styleFlags & windowIsResizable) != 0)
  196662. {
  196663. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  196664. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  196665. }
  196666. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  196667. }
  196668. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  196669. if (hints != None)
  196670. {
  196671. int netHints [6];
  196672. int num = 0;
  196673. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  196674. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  196675. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  196676. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  196677. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  196678. (unsigned char*) &netHints, num);
  196679. }
  196680. }
  196681. void setWindowType (Window wndH)
  196682. {
  196683. int netHints [2];
  196684. int numHints = 0;
  196685. if ((styleFlags & windowIsTemporary) != 0
  196686. || ((styleFlags & windowHasDropShadow) == 0 && Desktop::canUseSemiTransparentWindows()))
  196687. {
  196688. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_COMBO", True);
  196689. }
  196690. else
  196691. {
  196692. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  196693. }
  196694. if (netHints [numHints] != 0)
  196695. ++numHints;
  196696. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  196697. if (netHints [numHints] != 0)
  196698. ++numHints;
  196699. XChangeProperty (display, wndH, Atoms::WindowType, XA_ATOM, 32, PropModeReplace,
  196700. (unsigned char*) &netHints, numHints);
  196701. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  196702. {
  196703. Atom skipTaskbar = XInternAtom (display, "_NET_WM_STATE_SKIP_TASKBAR", False);
  196704. XChangeProperty (display, wndH, Atoms::WindowState, XA_ATOM, 32, PropModeReplace,
  196705. (unsigned char*) &skipTaskbar, 1);
  196706. }
  196707. }
  196708. void createWindow()
  196709. {
  196710. ScopedXLock xlock;
  196711. Atoms::initialiseAtoms();
  196712. resetDragAndDrop();
  196713. // Get defaults for various properties
  196714. const int screen = DefaultScreen (display);
  196715. Window root = RootWindow (display, screen);
  196716. // Try to obtain a 32-bit visual or fallback to 24 or 16
  196717. visual = Visuals::findVisualFormat ((styleFlags & windowIsSemiTransparent) ? 32 : 24, depth);
  196718. if (visual == 0)
  196719. {
  196720. Logger::outputDebugString ("ERROR: System doesn't support 32, 24 or 16 bit RGB display.\n");
  196721. Process::terminate();
  196722. }
  196723. // Create and install a colormap suitable fr our visual
  196724. Colormap colormap = XCreateColormap (display, root, visual, AllocNone);
  196725. XInstallColormap (display, colormap);
  196726. // Set up the window attributes
  196727. XSetWindowAttributes swa;
  196728. swa.border_pixel = 0;
  196729. swa.background_pixmap = None;
  196730. swa.colormap = colormap;
  196731. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  196732. swa.event_mask = getAllEventsMask();
  196733. Window wndH = XCreateWindow (display, root,
  196734. 0, 0, 1, 1,
  196735. 0, depth, InputOutput, visual,
  196736. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  196737. &swa);
  196738. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  196739. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  196740. GrabModeAsync, GrabModeAsync, None, None);
  196741. // Set the window context to identify the window handle object
  196742. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  196743. {
  196744. // Failed
  196745. jassertfalse
  196746. Logger::outputDebugString ("Failed to create context information for window.\n");
  196747. XDestroyWindow (display, wndH);
  196748. wndH = 0;
  196749. }
  196750. // Set window manager hints
  196751. XWMHints* wmHints = XAllocWMHints();
  196752. wmHints->flags = InputHint | StateHint;
  196753. wmHints->input = True; // Locally active input model
  196754. wmHints->initial_state = NormalState;
  196755. XSetWMHints (display, wndH, wmHints);
  196756. XFree (wmHints);
  196757. // Set the window type
  196758. setWindowType (wndH);
  196759. // Define decoration
  196760. if ((styleFlags & windowHasTitleBar) == 0)
  196761. removeWindowDecorations (wndH);
  196762. else
  196763. addWindowButtons (wndH);
  196764. // Set window name
  196765. setWindowTitle (wndH, getComponent()->getName());
  196766. // Associate the PID, allowing to be shut down when something goes wrong
  196767. unsigned long pid = getpid();
  196768. XChangeProperty (display, wndH, Atoms::Pid, XA_CARDINAL, 32, PropModeReplace,
  196769. (unsigned char*) &pid, 1);
  196770. // Set window manager protocols
  196771. XChangeProperty (display, wndH, Atoms::Protocols, XA_ATOM, 32, PropModeReplace,
  196772. (unsigned char*) Atoms::ProtocolList, 2);
  196773. // Set drag and drop flags
  196774. XChangeProperty (display, wndH, Atoms::XdndTypeList, XA_ATOM, 32, PropModeReplace,
  196775. (const unsigned char*) Atoms::allowedMimeTypes, numElementsInArray (Atoms::allowedMimeTypes));
  196776. XChangeProperty (display, wndH, Atoms::XdndActionList, XA_ATOM, 32, PropModeReplace,
  196777. (const unsigned char*) Atoms::allowedActions, numElementsInArray (Atoms::allowedActions));
  196778. XChangeProperty (display, wndH, Atoms::XdndActionDescription, XA_STRING, 8, PropModeReplace,
  196779. (const unsigned char*) "", 0);
  196780. unsigned long dndVersion = Atoms::DndVersion;
  196781. XChangeProperty (display, wndH, Atoms::XdndAware, XA_ATOM, 32, PropModeReplace,
  196782. (const unsigned char*) &dndVersion, 1);
  196783. // Initialise the pointer and keyboard mapping
  196784. // This is not the same as the logical pointer mapping the X server uses:
  196785. // we don't mess with this.
  196786. static bool mappingInitialised = false;
  196787. if (! mappingInitialised)
  196788. {
  196789. mappingInitialised = true;
  196790. const int numButtons = XGetPointerMapping (display, 0, 0);
  196791. if (numButtons == 2)
  196792. {
  196793. pointerMap[0] = Keys::LeftButton;
  196794. pointerMap[1] = Keys::RightButton;
  196795. pointerMap[2] = pointerMap[3] = pointerMap[4] = Keys::NoButton;
  196796. }
  196797. else if (numButtons >= 3)
  196798. {
  196799. pointerMap[0] = Keys::LeftButton;
  196800. pointerMap[1] = Keys::MiddleButton;
  196801. pointerMap[2] = Keys::RightButton;
  196802. if (numButtons >= 5)
  196803. {
  196804. pointerMap[3] = Keys::WheelUp;
  196805. pointerMap[4] = Keys::WheelDown;
  196806. }
  196807. }
  196808. updateModifierMappings();
  196809. }
  196810. windowH = wndH;
  196811. }
  196812. void destroyWindow()
  196813. {
  196814. ScopedXLock xlock;
  196815. XPointer handlePointer;
  196816. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  196817. XDeleteContext (display, (XID) windowH, improbableNumber);
  196818. XDestroyWindow (display, windowH);
  196819. // Wait for it to complete and then remove any events for this
  196820. // window from the event queue.
  196821. XSync (display, false);
  196822. XEvent event;
  196823. while (XCheckWindowEvent (display, windowH, getAllEventsMask(), &event) == True)
  196824. {}
  196825. }
  196826. static int getAllEventsMask() throw()
  196827. {
  196828. return NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  196829. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  196830. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  196831. }
  196832. static int64 getEventTime (::Time t)
  196833. {
  196834. static int64 eventTimeOffset = 0x12345678;
  196835. const int64 thisMessageTime = t;
  196836. if (eventTimeOffset == 0x12345678)
  196837. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  196838. return eventTimeOffset + thisMessageTime;
  196839. }
  196840. static void setWindowTitle (Window xwin, const String& title)
  196841. {
  196842. XTextProperty nameProperty;
  196843. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  196844. ScopedXLock xlock;
  196845. if (XStringListToTextProperty (strings, 1, &nameProperty))
  196846. {
  196847. XSetWMName (display, xwin, &nameProperty);
  196848. XSetWMIconName (display, xwin, &nameProperty);
  196849. XFree (nameProperty.value);
  196850. }
  196851. }
  196852. void updateBorderSize()
  196853. {
  196854. if ((styleFlags & windowHasTitleBar) == 0)
  196855. {
  196856. windowBorder = BorderSize (0);
  196857. }
  196858. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  196859. {
  196860. ScopedXLock xlock;
  196861. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  196862. if (hints != None)
  196863. {
  196864. unsigned char* data = 0;
  196865. unsigned long nitems, bytesLeft;
  196866. Atom actualType;
  196867. int actualFormat;
  196868. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  196869. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  196870. &data) == Success)
  196871. {
  196872. const unsigned long* const sizes = (const unsigned long*) data;
  196873. if (actualFormat == 32)
  196874. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  196875. (int) sizes[3], (int) sizes[1]);
  196876. XFree (data);
  196877. }
  196878. }
  196879. }
  196880. }
  196881. void updateBounds()
  196882. {
  196883. jassert (windowH != 0);
  196884. if (windowH != 0)
  196885. {
  196886. Window root, child;
  196887. unsigned int bw, depth;
  196888. ScopedXLock xlock;
  196889. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196890. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  196891. &bw, &depth))
  196892. {
  196893. wx = wy = ww = wh = 0;
  196894. }
  196895. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  196896. {
  196897. wx = wy = 0;
  196898. }
  196899. }
  196900. }
  196901. void resetDragAndDrop()
  196902. {
  196903. dragAndDropFiles.clear();
  196904. lastDropPos = Point<int> (-1, -1);
  196905. dragAndDropCurrentMimeType = 0;
  196906. dragAndDropSourceWindow = 0;
  196907. srcMimeTypeAtomList.clear();
  196908. }
  196909. void sendDragAndDropMessage (XClientMessageEvent& msg)
  196910. {
  196911. msg.type = ClientMessage;
  196912. msg.display = display;
  196913. msg.window = dragAndDropSourceWindow;
  196914. msg.format = 32;
  196915. msg.data.l[0] = windowH;
  196916. ScopedXLock xlock;
  196917. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  196918. }
  196919. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  196920. {
  196921. XClientMessageEvent msg;
  196922. zerostruct (msg);
  196923. msg.message_type = Atoms::XdndStatus;
  196924. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  196925. msg.data.l[4] = dropAction;
  196926. sendDragAndDropMessage (msg);
  196927. }
  196928. void sendDragAndDropLeave()
  196929. {
  196930. XClientMessageEvent msg;
  196931. zerostruct (msg);
  196932. msg.message_type = Atoms::XdndLeave;
  196933. sendDragAndDropMessage (msg);
  196934. }
  196935. void sendDragAndDropFinish()
  196936. {
  196937. XClientMessageEvent msg;
  196938. zerostruct (msg);
  196939. msg.message_type = Atoms::XdndFinished;
  196940. sendDragAndDropMessage (msg);
  196941. }
  196942. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  196943. {
  196944. if ((clientMsg->data.l[1] & 1) == 0)
  196945. {
  196946. sendDragAndDropLeave();
  196947. if (dragAndDropFiles.size() > 0)
  196948. handleFileDragExit (dragAndDropFiles);
  196949. dragAndDropFiles.clear();
  196950. }
  196951. }
  196952. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  196953. {
  196954. if (dragAndDropSourceWindow == 0)
  196955. return;
  196956. dragAndDropSourceWindow = clientMsg->data.l[0];
  196957. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  196958. (int) clientMsg->data.l[2] & 0xffff);
  196959. dropPos -= getScreenPosition();
  196960. if (lastDropPos != dropPos)
  196961. {
  196962. lastDropPos = dropPos;
  196963. dragAndDropTimestamp = clientMsg->data.l[3];
  196964. Atom targetAction = Atoms::XdndActionCopy;
  196965. for (int i = numElementsInArray (Atoms::allowedActions); --i >= 0;)
  196966. {
  196967. if ((Atom) clientMsg->data.l[4] == Atoms::allowedActions[i])
  196968. {
  196969. targetAction = Atoms::allowedActions[i];
  196970. break;
  196971. }
  196972. }
  196973. sendDragAndDropStatus (true, targetAction);
  196974. if (dragAndDropFiles.size() == 0)
  196975. updateDraggedFileList (clientMsg);
  196976. if (dragAndDropFiles.size() > 0)
  196977. handleFileDragMove (dragAndDropFiles, dropPos);
  196978. }
  196979. }
  196980. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  196981. {
  196982. if (dragAndDropFiles.size() == 0)
  196983. updateDraggedFileList (clientMsg);
  196984. const StringArray files (dragAndDropFiles);
  196985. const Point<int> lastPos (lastDropPos);
  196986. sendDragAndDropFinish();
  196987. resetDragAndDrop();
  196988. if (files.size() > 0)
  196989. handleFileDragDrop (files, lastPos);
  196990. }
  196991. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  196992. {
  196993. dragAndDropFiles.clear();
  196994. srcMimeTypeAtomList.clear();
  196995. dragAndDropCurrentMimeType = 0;
  196996. const unsigned long dndCurrentVersion = static_cast <unsigned long> (clientMsg->data.l[1] & 0xff000000) >> 24;
  196997. if (dndCurrentVersion < 3 || dndCurrentVersion > Atoms::DndVersion)
  196998. {
  196999. dragAndDropSourceWindow = 0;
  197000. return;
  197001. }
  197002. dragAndDropSourceWindow = clientMsg->data.l[0];
  197003. if ((clientMsg->data.l[1] & 1) != 0)
  197004. {
  197005. Atom actual;
  197006. int format;
  197007. unsigned long count = 0, remaining = 0;
  197008. unsigned char* data = 0;
  197009. ScopedXLock xlock;
  197010. XGetWindowProperty (display, dragAndDropSourceWindow, Atoms::XdndTypeList,
  197011. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197012. &count, &remaining, &data);
  197013. if (data != 0)
  197014. {
  197015. if (actual == XA_ATOM && format == 32 && count != 0)
  197016. {
  197017. const unsigned long* const types = (const unsigned long*) data;
  197018. for (unsigned int i = 0; i < count; ++i)
  197019. if (types[i] != None)
  197020. srcMimeTypeAtomList.add (types[i]);
  197021. }
  197022. XFree (data);
  197023. }
  197024. }
  197025. if (srcMimeTypeAtomList.size() == 0)
  197026. {
  197027. for (int i = 2; i < 5; ++i)
  197028. if (clientMsg->data.l[i] != None)
  197029. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197030. if (srcMimeTypeAtomList.size() == 0)
  197031. {
  197032. dragAndDropSourceWindow = 0;
  197033. return;
  197034. }
  197035. }
  197036. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197037. for (int j = 0; j < numElementsInArray (Atoms::allowedMimeTypes); ++j)
  197038. if (srcMimeTypeAtomList[i] == Atoms::allowedMimeTypes[j])
  197039. dragAndDropCurrentMimeType = Atoms::allowedMimeTypes[j];
  197040. handleDragAndDropPosition (clientMsg);
  197041. }
  197042. void handleDragAndDropSelection (const XEvent* const evt)
  197043. {
  197044. dragAndDropFiles.clear();
  197045. if (evt->xselection.property != 0)
  197046. {
  197047. StringArray lines;
  197048. {
  197049. MemoryBlock dropData;
  197050. for (;;)
  197051. {
  197052. Atom actual;
  197053. uint8* data = 0;
  197054. unsigned long count = 0, remaining = 0;
  197055. int format = 0;
  197056. ScopedXLock xlock;
  197057. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197058. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197059. &format, &count, &remaining, &data) == Success)
  197060. {
  197061. dropData.append (data, count * format / 8);
  197062. XFree (data);
  197063. if (remaining == 0)
  197064. break;
  197065. }
  197066. else
  197067. {
  197068. XFree (data);
  197069. break;
  197070. }
  197071. }
  197072. lines.addLines (dropData.toString());
  197073. }
  197074. for (int i = 0; i < lines.size(); ++i)
  197075. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf ("file://", false, true)));
  197076. dragAndDropFiles.trim();
  197077. dragAndDropFiles.removeEmptyStrings();
  197078. }
  197079. }
  197080. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197081. {
  197082. dragAndDropFiles.clear();
  197083. if (dragAndDropSourceWindow != None
  197084. && dragAndDropCurrentMimeType != 0)
  197085. {
  197086. dragAndDropTimestamp = clientMsg->data.l[2];
  197087. ScopedXLock xlock;
  197088. XConvertSelection (display,
  197089. Atoms::XdndSelection,
  197090. dragAndDropCurrentMimeType,
  197091. XInternAtom (display, "JXSelectionWindowProperty", 0),
  197092. windowH,
  197093. dragAndDropTimestamp);
  197094. }
  197095. }
  197096. StringArray dragAndDropFiles;
  197097. int dragAndDropTimestamp;
  197098. Point<int> lastDropPos;
  197099. Atom dragAndDropCurrentMimeType;
  197100. Window dragAndDropSourceWindow;
  197101. Array <Atom> srcMimeTypeAtomList;
  197102. static int pointerMap[5];
  197103. static Point<int> lastMousePos;
  197104. static void clearLastMousePos() throw()
  197105. {
  197106. lastMousePos = Point<int> (0x100000, 0x100000);
  197107. }
  197108. };
  197109. ModifierKeys LinuxComponentPeer::currentModifiers;
  197110. bool LinuxComponentPeer::isActiveApplication = false;
  197111. int LinuxComponentPeer::pointerMap[5];
  197112. Point<int> LinuxComponentPeer::lastMousePos;
  197113. bool Process::isForegroundProcess()
  197114. {
  197115. return LinuxComponentPeer::isActiveApplication;
  197116. }
  197117. void ModifierKeys::updateCurrentModifiers() throw()
  197118. {
  197119. currentModifiers = LinuxComponentPeer::currentModifiers;
  197120. }
  197121. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  197122. {
  197123. Window root, child;
  197124. int x, y, winx, winy;
  197125. unsigned int mask;
  197126. int mouseMods = 0;
  197127. ScopedXLock xlock;
  197128. if (XQueryPointer (display, RootWindow (display, DefaultScreen (display)),
  197129. &root, &child, &x, &y, &winx, &winy, &mask) != False)
  197130. {
  197131. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  197132. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  197133. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  197134. }
  197135. LinuxComponentPeer::currentModifiers = LinuxComponentPeer::currentModifiers.withoutMouseButtons().withFlags (mouseMods);
  197136. return LinuxComponentPeer::currentModifiers;
  197137. }
  197138. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197139. {
  197140. if (enableOrDisable)
  197141. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197142. }
  197143. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197144. {
  197145. return new LinuxComponentPeer (this, styleFlags);
  197146. }
  197147. // (this callback is hooked up in the messaging code)
  197148. void juce_windowMessageReceive (XEvent* event)
  197149. {
  197150. if (event->xany.window != None)
  197151. {
  197152. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197153. if (ComponentPeer::isValidPeer (peer))
  197154. peer->handleWindowMessage (event);
  197155. }
  197156. else
  197157. {
  197158. switch (event->xany.type)
  197159. {
  197160. case KeymapNotify:
  197161. {
  197162. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197163. memcpy (Keys::keyStates, keymapEvent->key_vector, 32);
  197164. break;
  197165. }
  197166. default:
  197167. break;
  197168. }
  197169. }
  197170. }
  197171. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197172. {
  197173. if (display == 0)
  197174. return;
  197175. #if JUCE_USE_XINERAMA
  197176. int major_opcode, first_event, first_error;
  197177. ScopedXLock xlock;
  197178. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197179. {
  197180. typedef Bool (*tXineramaIsActive) (Display*);
  197181. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197182. static tXineramaIsActive xXineramaIsActive = 0;
  197183. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197184. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197185. {
  197186. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197187. if (h != 0)
  197188. {
  197189. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197190. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197191. }
  197192. }
  197193. if (xXineramaIsActive != 0
  197194. && xXineramaQueryScreens != 0
  197195. && xXineramaIsActive (display))
  197196. {
  197197. int numMonitors = 0;
  197198. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197199. if (screens != 0)
  197200. {
  197201. for (int i = numMonitors; --i >= 0;)
  197202. {
  197203. int index = screens[i].screen_number;
  197204. if (index >= 0)
  197205. {
  197206. while (monitorCoords.size() < index)
  197207. monitorCoords.add (Rectangle<int>());
  197208. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197209. screens[i].y_org,
  197210. screens[i].width,
  197211. screens[i].height));
  197212. }
  197213. }
  197214. XFree (screens);
  197215. }
  197216. }
  197217. }
  197218. if (monitorCoords.size() == 0)
  197219. #endif
  197220. {
  197221. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197222. if (hints != None)
  197223. {
  197224. const int numMonitors = ScreenCount (display);
  197225. for (int i = 0; i < numMonitors; ++i)
  197226. {
  197227. Window root = RootWindow (display, i);
  197228. unsigned long nitems, bytesLeft;
  197229. Atom actualType;
  197230. int actualFormat;
  197231. unsigned char* data = 0;
  197232. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197233. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197234. &data) == Success)
  197235. {
  197236. const long* const position = (const long*) data;
  197237. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197238. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197239. position[2], position[3]));
  197240. XFree (data);
  197241. }
  197242. }
  197243. }
  197244. if (monitorCoords.size() == 0)
  197245. {
  197246. monitorCoords.add (Rectangle<int> (0, 0,
  197247. DisplayWidth (display, DefaultScreen (display)),
  197248. DisplayHeight (display, DefaultScreen (display))));
  197249. }
  197250. }
  197251. }
  197252. void Desktop::createMouseInputSources()
  197253. {
  197254. mouseSources.add (new MouseInputSource (0, true));
  197255. }
  197256. bool Desktop::canUseSemiTransparentWindows() throw()
  197257. {
  197258. int matchedDepth = 0;
  197259. const int desiredDepth = 32;
  197260. return Visuals::findVisualFormat (desiredDepth, matchedDepth) != 0
  197261. && (matchedDepth == desiredDepth);
  197262. }
  197263. const Point<int> Desktop::getMousePosition()
  197264. {
  197265. Window root, child;
  197266. int x, y, winx, winy;
  197267. unsigned int mask;
  197268. ScopedXLock xlock;
  197269. if (XQueryPointer (display,
  197270. RootWindow (display, DefaultScreen (display)),
  197271. &root, &child,
  197272. &x, &y, &winx, &winy, &mask) == False)
  197273. {
  197274. // Pointer not on the default screen
  197275. x = y = -1;
  197276. }
  197277. return Point<int> (x, y);
  197278. }
  197279. void Desktop::setMousePosition (const Point<int>& newPosition)
  197280. {
  197281. ScopedXLock xlock;
  197282. Window root = RootWindow (display, DefaultScreen (display));
  197283. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197284. }
  197285. static bool screenSaverAllowed = true;
  197286. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197287. {
  197288. if (screenSaverAllowed != isEnabled)
  197289. {
  197290. screenSaverAllowed = isEnabled;
  197291. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197292. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197293. if (xScreenSaverSuspend == 0)
  197294. {
  197295. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197296. if (h != 0)
  197297. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197298. }
  197299. ScopedXLock xlock;
  197300. if (xScreenSaverSuspend != 0)
  197301. xScreenSaverSuspend (display, ! isEnabled);
  197302. }
  197303. }
  197304. bool Desktop::isScreenSaverEnabled() throw()
  197305. {
  197306. return screenSaverAllowed;
  197307. }
  197308. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  197309. {
  197310. ScopedXLock xlock;
  197311. const unsigned int imageW = image.getWidth();
  197312. const unsigned int imageH = image.getHeight();
  197313. #if JUCE_USE_XCURSOR
  197314. {
  197315. typedef XcursorBool (*tXcursorSupportsARGB) (Display*);
  197316. typedef XcursorImage* (*tXcursorImageCreate) (int, int);
  197317. typedef void (*tXcursorImageDestroy) (XcursorImage*);
  197318. typedef Cursor (*tXcursorImageLoadCursor) (Display*, const XcursorImage*);
  197319. static tXcursorSupportsARGB xXcursorSupportsARGB = 0;
  197320. static tXcursorImageCreate xXcursorImageCreate = 0;
  197321. static tXcursorImageDestroy xXcursorImageDestroy = 0;
  197322. static tXcursorImageLoadCursor xXcursorImageLoadCursor = 0;
  197323. static bool hasBeenLoaded = false;
  197324. if (! hasBeenLoaded)
  197325. {
  197326. hasBeenLoaded = true;
  197327. void* h = dlopen ("libXcursor.so", RTLD_GLOBAL | RTLD_NOW);
  197328. if (h != 0)
  197329. {
  197330. xXcursorSupportsARGB = (tXcursorSupportsARGB) dlsym (h, "XcursorSupportsARGB");
  197331. xXcursorImageCreate = (tXcursorImageCreate) dlsym (h, "XcursorImageCreate");
  197332. xXcursorImageLoadCursor = (tXcursorImageLoadCursor) dlsym (h, "XcursorImageLoadCursor");
  197333. xXcursorImageDestroy = (tXcursorImageDestroy) dlsym (h, "XcursorImageDestroy");
  197334. if (xXcursorSupportsARGB == 0 || xXcursorImageCreate == 0
  197335. || xXcursorImageLoadCursor == 0 || xXcursorImageDestroy == 0
  197336. || ! xXcursorSupportsARGB (display))
  197337. xXcursorSupportsARGB = 0;
  197338. }
  197339. }
  197340. if (xXcursorSupportsARGB != 0)
  197341. {
  197342. XcursorImage* xcImage = xXcursorImageCreate (imageW, imageH);
  197343. if (xcImage != 0)
  197344. {
  197345. xcImage->xhot = hotspotX;
  197346. xcImage->yhot = hotspotY;
  197347. XcursorPixel* dest = xcImage->pixels;
  197348. for (int y = 0; y < (int) imageH; ++y)
  197349. for (int x = 0; x < (int) imageW; ++x)
  197350. *dest++ = image.getPixelAt (x, y).getARGB();
  197351. void* result = (void*) xXcursorImageLoadCursor (display, xcImage);
  197352. xXcursorImageDestroy (xcImage);
  197353. if (result != 0)
  197354. return result;
  197355. }
  197356. }
  197357. }
  197358. #endif
  197359. Window root = RootWindow (display, DefaultScreen (display));
  197360. unsigned int cursorW, cursorH;
  197361. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197362. return 0;
  197363. Image im (Image::ARGB, cursorW, cursorH, true);
  197364. {
  197365. Graphics g (im);
  197366. if (imageW > cursorW || imageH > cursorH)
  197367. {
  197368. hotspotX = (hotspotX * cursorW) / imageW;
  197369. hotspotY = (hotspotY * cursorH) / imageH;
  197370. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197371. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197372. false);
  197373. }
  197374. else
  197375. {
  197376. g.drawImageAt (&image, 0, 0);
  197377. }
  197378. }
  197379. const int stride = (cursorW + 7) >> 3;
  197380. HeapBlock <char> maskPlane, sourcePlane;
  197381. maskPlane.calloc (stride * cursorH);
  197382. sourcePlane.calloc (stride * cursorH);
  197383. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197384. for (int y = cursorH; --y >= 0;)
  197385. {
  197386. for (int x = cursorW; --x >= 0;)
  197387. {
  197388. const char mask = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197389. const int offset = y * stride + (x >> 3);
  197390. const Colour c (im.getPixelAt (x, y));
  197391. if (c.getAlpha() >= 128)
  197392. maskPlane[offset] |= mask;
  197393. if (c.getBrightness() >= 0.5f)
  197394. sourcePlane[offset] |= mask;
  197395. }
  197396. }
  197397. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, sourcePlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197398. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, maskPlane.getData(), cursorW, cursorH, 0xffff, 0, 1);
  197399. XColor white, black;
  197400. black.red = black.green = black.blue = 0;
  197401. white.red = white.green = white.blue = 0xffff;
  197402. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197403. XFreePixmap (display, sourcePixmap);
  197404. XFreePixmap (display, maskPixmap);
  197405. return result;
  197406. }
  197407. void juce_deleteMouseCursor (void* const cursorHandle, const bool)
  197408. {
  197409. ScopedXLock xlock;
  197410. if (cursorHandle != 0)
  197411. XFreeCursor (display, (Cursor) cursorHandle);
  197412. }
  197413. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  197414. {
  197415. unsigned int shape;
  197416. switch (type)
  197417. {
  197418. case MouseCursor::NoCursor:
  197419. {
  197420. const Image im (Image::ARGB, 16, 16, true);
  197421. return juce_createMouseCursorFromImage (im, 0, 0);
  197422. }
  197423. case MouseCursor::NormalCursor:
  197424. return (void*) None; // Use parent cursor
  197425. case MouseCursor::DraggingHandCursor:
  197426. {
  197427. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197428. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197429. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197430. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197431. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197432. const int dragHandDataSize = 99;
  197433. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (dragHandData, dragHandDataSize));
  197434. return juce_createMouseCursorFromImage (*im, 8, 7);
  197435. }
  197436. case MouseCursor::CopyingCursor:
  197437. {
  197438. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197439. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197440. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197441. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197442. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197443. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197444. const int copyCursorSize = 119;
  197445. const ScopedPointer <Image> im (ImageFileFormat::loadFrom (copyCursorData, copyCursorSize));
  197446. return juce_createMouseCursorFromImage (*im, 1, 3);
  197447. }
  197448. case MouseCursor::WaitCursor:
  197449. shape = XC_watch;
  197450. break;
  197451. case MouseCursor::IBeamCursor:
  197452. shape = XC_xterm;
  197453. break;
  197454. case MouseCursor::PointingHandCursor:
  197455. shape = XC_hand2;
  197456. break;
  197457. case MouseCursor::LeftRightResizeCursor:
  197458. shape = XC_sb_h_double_arrow;
  197459. break;
  197460. case MouseCursor::UpDownResizeCursor:
  197461. shape = XC_sb_v_double_arrow;
  197462. break;
  197463. case MouseCursor::UpDownLeftRightResizeCursor:
  197464. shape = XC_fleur;
  197465. break;
  197466. case MouseCursor::TopEdgeResizeCursor:
  197467. shape = XC_top_side;
  197468. break;
  197469. case MouseCursor::BottomEdgeResizeCursor:
  197470. shape = XC_bottom_side;
  197471. break;
  197472. case MouseCursor::LeftEdgeResizeCursor:
  197473. shape = XC_left_side;
  197474. break;
  197475. case MouseCursor::RightEdgeResizeCursor:
  197476. shape = XC_right_side;
  197477. break;
  197478. case MouseCursor::TopLeftCornerResizeCursor:
  197479. shape = XC_top_left_corner;
  197480. break;
  197481. case MouseCursor::TopRightCornerResizeCursor:
  197482. shape = XC_top_right_corner;
  197483. break;
  197484. case MouseCursor::BottomLeftCornerResizeCursor:
  197485. shape = XC_bottom_left_corner;
  197486. break;
  197487. case MouseCursor::BottomRightCornerResizeCursor:
  197488. shape = XC_bottom_right_corner;
  197489. break;
  197490. case MouseCursor::CrosshairCursor:
  197491. shape = XC_crosshair;
  197492. break;
  197493. default:
  197494. return (void*) None; // Use parent cursor
  197495. }
  197496. ScopedXLock xlock;
  197497. return (void*) XCreateFontCursor (display, shape);
  197498. }
  197499. void MouseCursor::showInWindow (ComponentPeer* peer) const
  197500. {
  197501. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197502. if (lp != 0)
  197503. lp->showMouseCursor ((Cursor) getHandle());
  197504. }
  197505. void MouseCursor::showInAllWindows() const
  197506. {
  197507. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197508. showInWindow (ComponentPeer::getPeer (i));
  197509. }
  197510. Image* juce_createIconForFile (const File& file)
  197511. {
  197512. return 0;
  197513. }
  197514. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197515. {
  197516. return new Image (format, imageWidth, imageHeight, clearImage);
  197517. }
  197518. #if JUCE_OPENGL
  197519. class WindowedGLContext : public OpenGLContext
  197520. {
  197521. public:
  197522. WindowedGLContext (Component* const component,
  197523. const OpenGLPixelFormat& pixelFormat_,
  197524. GLXContext sharedContext)
  197525. : renderContext (0),
  197526. embeddedWindow (0),
  197527. pixelFormat (pixelFormat_)
  197528. {
  197529. jassert (component != 0);
  197530. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197531. if (peer == 0)
  197532. return;
  197533. ScopedXLock xlock;
  197534. XSync (display, False);
  197535. GLint attribs [64];
  197536. int n = 0;
  197537. attribs[n++] = GLX_RGBA;
  197538. attribs[n++] = GLX_DOUBLEBUFFER;
  197539. attribs[n++] = GLX_RED_SIZE;
  197540. attribs[n++] = pixelFormat.redBits;
  197541. attribs[n++] = GLX_GREEN_SIZE;
  197542. attribs[n++] = pixelFormat.greenBits;
  197543. attribs[n++] = GLX_BLUE_SIZE;
  197544. attribs[n++] = pixelFormat.blueBits;
  197545. attribs[n++] = GLX_ALPHA_SIZE;
  197546. attribs[n++] = pixelFormat.alphaBits;
  197547. attribs[n++] = GLX_DEPTH_SIZE;
  197548. attribs[n++] = pixelFormat.depthBufferBits;
  197549. attribs[n++] = GLX_STENCIL_SIZE;
  197550. attribs[n++] = pixelFormat.stencilBufferBits;
  197551. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197552. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197553. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197554. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197555. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197556. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197557. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197558. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197559. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197560. attribs[n++] = None;
  197561. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197562. if (bestVisual == 0)
  197563. return;
  197564. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197565. Window windowH = (Window) peer->getNativeHandle();
  197566. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197567. XSetWindowAttributes swa;
  197568. swa.colormap = colourMap;
  197569. swa.border_pixel = 0;
  197570. swa.event_mask = ExposureMask | StructureNotifyMask;
  197571. embeddedWindow = XCreateWindow (display, windowH,
  197572. 0, 0, 1, 1, 0,
  197573. bestVisual->depth,
  197574. InputOutput,
  197575. bestVisual->visual,
  197576. CWBorderPixel | CWColormap | CWEventMask,
  197577. &swa);
  197578. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197579. XMapWindow (display, embeddedWindow);
  197580. XFreeColormap (display, colourMap);
  197581. XFree (bestVisual);
  197582. XSync (display, False);
  197583. }
  197584. ~WindowedGLContext()
  197585. {
  197586. makeInactive();
  197587. ScopedXLock xlock;
  197588. glXDestroyContext (display, renderContext);
  197589. XUnmapWindow (display, embeddedWindow);
  197590. XDestroyWindow (display, embeddedWindow);
  197591. }
  197592. bool makeActive() const throw()
  197593. {
  197594. jassert (renderContext != 0);
  197595. ScopedXLock xlock;
  197596. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197597. && XSync (display, False);
  197598. }
  197599. bool makeInactive() const throw()
  197600. {
  197601. ScopedXLock xlock;
  197602. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197603. }
  197604. bool isActive() const throw()
  197605. {
  197606. ScopedXLock xlock;
  197607. return glXGetCurrentContext() == renderContext;
  197608. }
  197609. const OpenGLPixelFormat getPixelFormat() const
  197610. {
  197611. return pixelFormat;
  197612. }
  197613. void* getRawContext() const throw()
  197614. {
  197615. return renderContext;
  197616. }
  197617. void updateWindowPosition (int x, int y, int w, int h, int)
  197618. {
  197619. ScopedXLock xlock;
  197620. XMoveResizeWindow (display, embeddedWindow,
  197621. x, y, jmax (1, w), jmax (1, h));
  197622. }
  197623. void swapBuffers()
  197624. {
  197625. ScopedXLock xlock;
  197626. glXSwapBuffers (display, embeddedWindow);
  197627. }
  197628. bool setSwapInterval (const int numFramesPerSwap)
  197629. {
  197630. // xxx needs doing..
  197631. return false;
  197632. }
  197633. int getSwapInterval() const
  197634. {
  197635. // xxx needs doing..
  197636. return 0;
  197637. }
  197638. void repaint()
  197639. {
  197640. }
  197641. juce_UseDebuggingNewOperator
  197642. GLXContext renderContext;
  197643. private:
  197644. Window embeddedWindow;
  197645. OpenGLPixelFormat pixelFormat;
  197646. WindowedGLContext (const WindowedGLContext&);
  197647. WindowedGLContext& operator= (const WindowedGLContext&);
  197648. };
  197649. OpenGLContext* OpenGLComponent::createContext()
  197650. {
  197651. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  197652. contextToShareListsWith != 0 ? (GLXContext) contextToShareListsWith->getRawContext() : 0));
  197653. return (c->renderContext != 0) ? c.release() : 0;
  197654. }
  197655. void juce_glViewport (const int w, const int h)
  197656. {
  197657. glViewport (0, 0, w, h);
  197658. }
  197659. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  197660. OwnedArray <OpenGLPixelFormat>& results)
  197661. {
  197662. results.add (new OpenGLPixelFormat()); // xxx
  197663. }
  197664. #endif
  197665. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  197666. {
  197667. jassertfalse // not implemented!
  197668. return false;
  197669. }
  197670. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  197671. {
  197672. jassertfalse // not implemented!
  197673. return false;
  197674. }
  197675. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  197676. {
  197677. if (! isOnDesktop ())
  197678. addToDesktop (0);
  197679. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197680. if (wp != 0)
  197681. {
  197682. wp->setTaskBarIcon (newImage);
  197683. setVisible (true);
  197684. toFront (false);
  197685. repaint();
  197686. }
  197687. }
  197688. void SystemTrayIconComponent::paint (Graphics& g)
  197689. {
  197690. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  197691. if (wp != 0)
  197692. {
  197693. const Image* const image = wp->getTaskbarIcon();
  197694. if (image != 0)
  197695. {
  197696. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  197697. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197698. false);
  197699. }
  197700. }
  197701. }
  197702. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  197703. {
  197704. // xxx not yet implemented!
  197705. }
  197706. void PlatformUtilities::beep()
  197707. {
  197708. std::cout << "\a" << std::flush;
  197709. }
  197710. bool AlertWindow::showNativeDialogBox (const String& title,
  197711. const String& bodyText,
  197712. bool isOkCancel)
  197713. {
  197714. // use a non-native one for the time being..
  197715. if (isOkCancel)
  197716. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  197717. else
  197718. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  197719. return true;
  197720. }
  197721. const int KeyPress::spaceKey = XK_space & 0xff;
  197722. const int KeyPress::returnKey = XK_Return & 0xff;
  197723. const int KeyPress::escapeKey = XK_Escape & 0xff;
  197724. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  197725. const int KeyPress::leftKey = (XK_Left & 0xff) | Keys::extendedKeyModifier;
  197726. const int KeyPress::rightKey = (XK_Right & 0xff) | Keys::extendedKeyModifier;
  197727. const int KeyPress::upKey = (XK_Up & 0xff) | Keys::extendedKeyModifier;
  197728. const int KeyPress::downKey = (XK_Down & 0xff) | Keys::extendedKeyModifier;
  197729. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | Keys::extendedKeyModifier;
  197730. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | Keys::extendedKeyModifier;
  197731. const int KeyPress::endKey = (XK_End & 0xff) | Keys::extendedKeyModifier;
  197732. const int KeyPress::homeKey = (XK_Home & 0xff) | Keys::extendedKeyModifier;
  197733. const int KeyPress::insertKey = (XK_Insert & 0xff) | Keys::extendedKeyModifier;
  197734. const int KeyPress::deleteKey = (XK_Delete & 0xff) | Keys::extendedKeyModifier;
  197735. const int KeyPress::tabKey = XK_Tab & 0xff;
  197736. const int KeyPress::F1Key = (XK_F1 & 0xff) | Keys::extendedKeyModifier;
  197737. const int KeyPress::F2Key = (XK_F2 & 0xff) | Keys::extendedKeyModifier;
  197738. const int KeyPress::F3Key = (XK_F3 & 0xff) | Keys::extendedKeyModifier;
  197739. const int KeyPress::F4Key = (XK_F4 & 0xff) | Keys::extendedKeyModifier;
  197740. const int KeyPress::F5Key = (XK_F5 & 0xff) | Keys::extendedKeyModifier;
  197741. const int KeyPress::F6Key = (XK_F6 & 0xff) | Keys::extendedKeyModifier;
  197742. const int KeyPress::F7Key = (XK_F7 & 0xff) | Keys::extendedKeyModifier;
  197743. const int KeyPress::F8Key = (XK_F8 & 0xff) | Keys::extendedKeyModifier;
  197744. const int KeyPress::F9Key = (XK_F9 & 0xff) | Keys::extendedKeyModifier;
  197745. const int KeyPress::F10Key = (XK_F10 & 0xff) | Keys::extendedKeyModifier;
  197746. const int KeyPress::F11Key = (XK_F11 & 0xff) | Keys::extendedKeyModifier;
  197747. const int KeyPress::F12Key = (XK_F12 & 0xff) | Keys::extendedKeyModifier;
  197748. const int KeyPress::F13Key = (XK_F13 & 0xff) | Keys::extendedKeyModifier;
  197749. const int KeyPress::F14Key = (XK_F14 & 0xff) | Keys::extendedKeyModifier;
  197750. const int KeyPress::F15Key = (XK_F15 & 0xff) | Keys::extendedKeyModifier;
  197751. const int KeyPress::F16Key = (XK_F16 & 0xff) | Keys::extendedKeyModifier;
  197752. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | Keys::extendedKeyModifier;
  197753. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | Keys::extendedKeyModifier;
  197754. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | Keys::extendedKeyModifier;
  197755. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | Keys::extendedKeyModifier;
  197756. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | Keys::extendedKeyModifier;
  197757. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | Keys::extendedKeyModifier;
  197758. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | Keys::extendedKeyModifier;
  197759. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| Keys::extendedKeyModifier;
  197760. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| Keys::extendedKeyModifier;
  197761. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| Keys::extendedKeyModifier;
  197762. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| Keys::extendedKeyModifier;
  197763. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| Keys::extendedKeyModifier;
  197764. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| Keys::extendedKeyModifier;
  197765. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| Keys::extendedKeyModifier;
  197766. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::extendedKeyModifier;
  197767. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
  197768. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
  197769. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
  197770. const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
  197771. const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
  197772. const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
  197773. const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
  197774. #endif
  197775. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  197776. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  197777. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  197778. // compiled on its own).
  197779. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  197780. static const int maxNumChans = 64;
  197781. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  197782. {
  197783. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  197784. snd_pcm_hw_params_t* hwParams;
  197785. snd_pcm_hw_params_alloca (&hwParams);
  197786. for (int i = 0; ratesToTry[i] != 0; ++i)
  197787. {
  197788. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  197789. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  197790. {
  197791. rates.addIfNotAlreadyThere (ratesToTry[i]);
  197792. }
  197793. }
  197794. }
  197795. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  197796. {
  197797. snd_pcm_hw_params_t *params;
  197798. snd_pcm_hw_params_alloca (&params);
  197799. if (snd_pcm_hw_params_any (handle, params) >= 0)
  197800. {
  197801. snd_pcm_hw_params_get_channels_min (params, minChans);
  197802. snd_pcm_hw_params_get_channels_max (params, maxChans);
  197803. }
  197804. }
  197805. static void getDeviceProperties (const String& deviceID,
  197806. unsigned int& minChansOut,
  197807. unsigned int& maxChansOut,
  197808. unsigned int& minChansIn,
  197809. unsigned int& maxChansIn,
  197810. Array <int>& rates)
  197811. {
  197812. if (deviceID.isEmpty())
  197813. return;
  197814. snd_ctl_t* handle;
  197815. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (",", false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  197816. {
  197817. snd_pcm_info_t* info;
  197818. snd_pcm_info_alloca (&info);
  197819. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  197820. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (",", false, false).getIntValue());
  197821. snd_pcm_info_set_subdevice (info, 0);
  197822. if (snd_ctl_pcm_info (handle, info) >= 0)
  197823. {
  197824. snd_pcm_t* pcmHandle;
  197825. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197826. {
  197827. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  197828. getDeviceSampleRates (pcmHandle, rates);
  197829. snd_pcm_close (pcmHandle);
  197830. }
  197831. }
  197832. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  197833. if (snd_ctl_pcm_info (handle, info) >= 0)
  197834. {
  197835. snd_pcm_t* pcmHandle;
  197836. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  197837. {
  197838. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  197839. if (rates.size() == 0)
  197840. getDeviceSampleRates (pcmHandle, rates);
  197841. snd_pcm_close (pcmHandle);
  197842. }
  197843. }
  197844. snd_ctl_close (handle);
  197845. }
  197846. }
  197847. class ALSADevice
  197848. {
  197849. public:
  197850. ALSADevice (const String& deviceID,
  197851. const bool forInput)
  197852. : handle (0),
  197853. bitDepth (16),
  197854. numChannelsRunning (0),
  197855. isInput (forInput),
  197856. sampleFormat (AudioDataConverters::int16LE)
  197857. {
  197858. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  197859. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  197860. SND_PCM_ASYNC));
  197861. }
  197862. ~ALSADevice()
  197863. {
  197864. if (handle != 0)
  197865. snd_pcm_close (handle);
  197866. }
  197867. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  197868. {
  197869. if (handle == 0)
  197870. return false;
  197871. snd_pcm_hw_params_t* hwParams;
  197872. snd_pcm_hw_params_alloca (&hwParams);
  197873. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  197874. return false;
  197875. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  197876. isInterleaved = false;
  197877. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  197878. isInterleaved = true;
  197879. else
  197880. {
  197881. jassertfalse
  197882. return false;
  197883. }
  197884. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  197885. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  197886. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  197887. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  197888. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  197889. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  197890. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  197891. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  197892. bitDepth = 0;
  197893. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  197894. {
  197895. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  197896. {
  197897. bitDepth = formatsToTry [i + 1];
  197898. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  197899. break;
  197900. }
  197901. }
  197902. if (bitDepth == 0)
  197903. {
  197904. error = "device doesn't support a compatible PCM format";
  197905. DBG ("ALSA error: " + error + "\n");
  197906. return false;
  197907. }
  197908. int dir = 0;
  197909. unsigned int periods = 4;
  197910. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  197911. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  197912. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  197913. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  197914. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  197915. || failed (snd_pcm_hw_params (handle, hwParams)))
  197916. {
  197917. return false;
  197918. }
  197919. snd_pcm_sw_params_t* swParams;
  197920. snd_pcm_sw_params_alloca (&swParams);
  197921. snd_pcm_uframes_t boundary;
  197922. if (failed (snd_pcm_sw_params_current (handle, swParams))
  197923. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  197924. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  197925. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  197926. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  197927. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  197928. || failed (snd_pcm_sw_params (handle, swParams)))
  197929. {
  197930. return false;
  197931. }
  197932. numChannelsRunning = numChannels;
  197933. return true;
  197934. }
  197935. bool write (float** const data, const int numSamples)
  197936. {
  197937. if (isInterleaved)
  197938. {
  197939. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197940. float* interleaved = static_cast <float*> (scratch.getData());
  197941. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  197942. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  197943. snd_pcm_sframes_t num = snd_pcm_writei (handle, interleaved, numSamples);
  197944. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  197945. return false;
  197946. }
  197947. else
  197948. {
  197949. for (int i = 0; i < numChannelsRunning; ++i)
  197950. if (data[i] != 0)
  197951. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  197952. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  197953. if (failed (num))
  197954. {
  197955. if (num == -EPIPE)
  197956. {
  197957. if (failed (snd_pcm_prepare (handle)))
  197958. return false;
  197959. }
  197960. else if (num != -ESTRPIPE)
  197961. return false;
  197962. }
  197963. }
  197964. return true;
  197965. }
  197966. bool read (float** const data, const int numSamples)
  197967. {
  197968. if (isInterleaved)
  197969. {
  197970. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  197971. float* interleaved = static_cast <float*> (scratch.getData());
  197972. snd_pcm_sframes_t num = snd_pcm_readi (handle, interleaved, numSamples);
  197973. if (failed (num))
  197974. {
  197975. if (num == -EPIPE)
  197976. {
  197977. if (failed (snd_pcm_prepare (handle)))
  197978. return false;
  197979. }
  197980. else if (num != -ESTRPIPE)
  197981. return false;
  197982. }
  197983. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  197984. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  197985. }
  197986. else
  197987. {
  197988. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  197989. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  197990. return false;
  197991. for (int i = 0; i < numChannelsRunning; ++i)
  197992. if (data[i] != 0)
  197993. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  197994. }
  197995. return true;
  197996. }
  197997. juce_UseDebuggingNewOperator
  197998. snd_pcm_t* handle;
  197999. String error;
  198000. int bitDepth, numChannelsRunning;
  198001. private:
  198002. const bool isInput;
  198003. bool isInterleaved;
  198004. MemoryBlock scratch;
  198005. AudioDataConverters::DataFormat sampleFormat;
  198006. bool failed (const int errorNum)
  198007. {
  198008. if (errorNum >= 0)
  198009. return false;
  198010. error = snd_strerror (errorNum);
  198011. DBG ("ALSA error: " + error + "\n");
  198012. return true;
  198013. }
  198014. };
  198015. class ALSAThread : public Thread
  198016. {
  198017. public:
  198018. ALSAThread (const String& inputId_,
  198019. const String& outputId_)
  198020. : Thread ("Juce ALSA"),
  198021. sampleRate (0),
  198022. bufferSize (0),
  198023. callback (0),
  198024. inputId (inputId_),
  198025. outputId (outputId_),
  198026. outputDevice (0),
  198027. inputDevice (0),
  198028. numCallbacks (0),
  198029. totalNumInputChannels (0),
  198030. totalNumOutputChannels (0)
  198031. {
  198032. zeromem (outputChannelData, sizeof (outputChannelData));
  198033. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198034. zeromem (inputChannelData, sizeof (inputChannelData));
  198035. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198036. initialiseRatesAndChannels();
  198037. }
  198038. ~ALSAThread()
  198039. {
  198040. close();
  198041. }
  198042. void open (BigInteger inputChannels,
  198043. BigInteger outputChannels,
  198044. const double sampleRate_,
  198045. const int bufferSize_)
  198046. {
  198047. close();
  198048. error = String::empty;
  198049. sampleRate = sampleRate_;
  198050. bufferSize = bufferSize_;
  198051. currentInputChans.clear();
  198052. currentOutputChans.clear();
  198053. if (inputChannels.getHighestBit() >= 0)
  198054. {
  198055. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198056. {
  198057. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198058. if (inputChannels[i])
  198059. {
  198060. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198061. currentInputChans.setBit (i);
  198062. }
  198063. }
  198064. }
  198065. if (outputChannels.getHighestBit() >= 0)
  198066. {
  198067. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198068. {
  198069. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198070. if (outputChannels[i])
  198071. {
  198072. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198073. currentOutputChans.setBit (i);
  198074. }
  198075. }
  198076. }
  198077. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198078. {
  198079. outputDevice = new ALSADevice (outputId, false);
  198080. if (outputDevice->error.isNotEmpty())
  198081. {
  198082. error = outputDevice->error;
  198083. deleteAndZero (outputDevice);
  198084. return;
  198085. }
  198086. currentOutputChans.setRange (0, minChansOut, true);
  198087. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198088. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198089. bufferSize))
  198090. {
  198091. error = outputDevice->error;
  198092. deleteAndZero (outputDevice);
  198093. return;
  198094. }
  198095. }
  198096. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198097. {
  198098. inputDevice = new ALSADevice (inputId, true);
  198099. if (inputDevice->error.isNotEmpty())
  198100. {
  198101. error = inputDevice->error;
  198102. deleteAndZero (inputDevice);
  198103. return;
  198104. }
  198105. currentInputChans.setRange (0, minChansIn, true);
  198106. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198107. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198108. bufferSize))
  198109. {
  198110. error = inputDevice->error;
  198111. deleteAndZero (inputDevice);
  198112. return;
  198113. }
  198114. }
  198115. if (outputDevice == 0 && inputDevice == 0)
  198116. {
  198117. error = "no channels";
  198118. return;
  198119. }
  198120. if (outputDevice != 0 && inputDevice != 0)
  198121. {
  198122. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198123. }
  198124. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198125. return;
  198126. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198127. return;
  198128. startThread (9);
  198129. int count = 1000;
  198130. while (numCallbacks == 0)
  198131. {
  198132. sleep (5);
  198133. if (--count < 0 || ! isThreadRunning())
  198134. {
  198135. error = "device didn't start";
  198136. break;
  198137. }
  198138. }
  198139. }
  198140. void close()
  198141. {
  198142. stopThread (6000);
  198143. deleteAndZero (inputDevice);
  198144. deleteAndZero (outputDevice);
  198145. for (int i = 0; i < maxNumChans; ++i)
  198146. {
  198147. juce_free (inputChannelData [i]);
  198148. juce_free (outputChannelData [i]);
  198149. }
  198150. zeromem (outputChannelData, sizeof (outputChannelData));
  198151. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198152. zeromem (inputChannelData, sizeof (inputChannelData));
  198153. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198154. totalNumOutputChannels = 0;
  198155. totalNumInputChannels = 0;
  198156. numCallbacks = 0;
  198157. }
  198158. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198159. {
  198160. const ScopedLock sl (callbackLock);
  198161. callback = newCallback;
  198162. }
  198163. void run()
  198164. {
  198165. while (! threadShouldExit())
  198166. {
  198167. if (inputDevice != 0)
  198168. {
  198169. if (! inputDevice->read (inputChannelData, bufferSize))
  198170. {
  198171. DBG ("ALSA: read failure");
  198172. break;
  198173. }
  198174. }
  198175. if (threadShouldExit())
  198176. break;
  198177. {
  198178. const ScopedLock sl (callbackLock);
  198179. ++numCallbacks;
  198180. if (callback != 0)
  198181. {
  198182. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198183. totalNumInputChannels,
  198184. outputChannelDataForCallback,
  198185. totalNumOutputChannels,
  198186. bufferSize);
  198187. }
  198188. else
  198189. {
  198190. for (int i = 0; i < totalNumOutputChannels; ++i)
  198191. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198192. }
  198193. }
  198194. if (outputDevice != 0)
  198195. {
  198196. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198197. if (threadShouldExit())
  198198. break;
  198199. failed (snd_pcm_avail_update (outputDevice->handle));
  198200. if (! outputDevice->write (outputChannelData, bufferSize))
  198201. {
  198202. DBG ("ALSA: write failure");
  198203. break;
  198204. }
  198205. }
  198206. }
  198207. }
  198208. int getBitDepth() const throw()
  198209. {
  198210. if (outputDevice != 0)
  198211. return outputDevice->bitDepth;
  198212. if (inputDevice != 0)
  198213. return inputDevice->bitDepth;
  198214. return 16;
  198215. }
  198216. juce_UseDebuggingNewOperator
  198217. String error;
  198218. double sampleRate;
  198219. int bufferSize;
  198220. BigInteger currentInputChans, currentOutputChans;
  198221. Array <int> sampleRates;
  198222. StringArray channelNamesOut, channelNamesIn;
  198223. AudioIODeviceCallback* callback;
  198224. private:
  198225. const String inputId, outputId;
  198226. ALSADevice* outputDevice;
  198227. ALSADevice* inputDevice;
  198228. int numCallbacks;
  198229. CriticalSection callbackLock;
  198230. float* outputChannelData [maxNumChans];
  198231. float* outputChannelDataForCallback [maxNumChans];
  198232. int totalNumInputChannels;
  198233. float* inputChannelData [maxNumChans];
  198234. float* inputChannelDataForCallback [maxNumChans];
  198235. int totalNumOutputChannels;
  198236. unsigned int minChansOut, maxChansOut;
  198237. unsigned int minChansIn, maxChansIn;
  198238. bool failed (const int errorNum) throw()
  198239. {
  198240. if (errorNum >= 0)
  198241. return false;
  198242. error = snd_strerror (errorNum);
  198243. DBG ("ALSA error: " + error + "\n");
  198244. return true;
  198245. }
  198246. void initialiseRatesAndChannels() throw()
  198247. {
  198248. sampleRates.clear();
  198249. channelNamesOut.clear();
  198250. channelNamesIn.clear();
  198251. minChansOut = 0;
  198252. maxChansOut = 0;
  198253. minChansIn = 0;
  198254. maxChansIn = 0;
  198255. unsigned int dummy = 0;
  198256. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198257. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198258. unsigned int i;
  198259. for (i = 0; i < maxChansOut; ++i)
  198260. channelNamesOut.add ("channel " + String ((int) i + 1));
  198261. for (i = 0; i < maxChansIn; ++i)
  198262. channelNamesIn.add ("channel " + String ((int) i + 1));
  198263. }
  198264. };
  198265. class ALSAAudioIODevice : public AudioIODevice
  198266. {
  198267. public:
  198268. ALSAAudioIODevice (const String& deviceName,
  198269. const String& inputId_,
  198270. const String& outputId_)
  198271. : AudioIODevice (deviceName, "ALSA"),
  198272. inputId (inputId_),
  198273. outputId (outputId_),
  198274. isOpen_ (false),
  198275. isStarted (false),
  198276. internal (0)
  198277. {
  198278. internal = new ALSAThread (inputId, outputId);
  198279. }
  198280. ~ALSAAudioIODevice()
  198281. {
  198282. delete internal;
  198283. }
  198284. const StringArray getOutputChannelNames()
  198285. {
  198286. return internal->channelNamesOut;
  198287. }
  198288. const StringArray getInputChannelNames()
  198289. {
  198290. return internal->channelNamesIn;
  198291. }
  198292. int getNumSampleRates()
  198293. {
  198294. return internal->sampleRates.size();
  198295. }
  198296. double getSampleRate (int index)
  198297. {
  198298. return internal->sampleRates [index];
  198299. }
  198300. int getNumBufferSizesAvailable()
  198301. {
  198302. return 50;
  198303. }
  198304. int getBufferSizeSamples (int index)
  198305. {
  198306. int n = 16;
  198307. for (int i = 0; i < index; ++i)
  198308. n += n < 64 ? 16
  198309. : (n < 512 ? 32
  198310. : (n < 1024 ? 64
  198311. : (n < 2048 ? 128 : 256)));
  198312. return n;
  198313. }
  198314. int getDefaultBufferSize()
  198315. {
  198316. return 512;
  198317. }
  198318. const String open (const BigInteger& inputChannels,
  198319. const BigInteger& outputChannels,
  198320. double sampleRate,
  198321. int bufferSizeSamples)
  198322. {
  198323. close();
  198324. if (bufferSizeSamples <= 0)
  198325. bufferSizeSamples = getDefaultBufferSize();
  198326. if (sampleRate <= 0)
  198327. {
  198328. for (int i = 0; i < getNumSampleRates(); ++i)
  198329. {
  198330. if (getSampleRate (i) >= 44100)
  198331. {
  198332. sampleRate = getSampleRate (i);
  198333. break;
  198334. }
  198335. }
  198336. }
  198337. internal->open (inputChannels, outputChannels,
  198338. sampleRate, bufferSizeSamples);
  198339. isOpen_ = internal->error.isEmpty();
  198340. return internal->error;
  198341. }
  198342. void close()
  198343. {
  198344. stop();
  198345. internal->close();
  198346. isOpen_ = false;
  198347. }
  198348. bool isOpen()
  198349. {
  198350. return isOpen_;
  198351. }
  198352. int getCurrentBufferSizeSamples()
  198353. {
  198354. return internal->bufferSize;
  198355. }
  198356. double getCurrentSampleRate()
  198357. {
  198358. return internal->sampleRate;
  198359. }
  198360. int getCurrentBitDepth()
  198361. {
  198362. return internal->getBitDepth();
  198363. }
  198364. const BigInteger getActiveOutputChannels() const
  198365. {
  198366. return internal->currentOutputChans;
  198367. }
  198368. const BigInteger getActiveInputChannels() const
  198369. {
  198370. return internal->currentInputChans;
  198371. }
  198372. int getOutputLatencyInSamples()
  198373. {
  198374. return 0;
  198375. }
  198376. int getInputLatencyInSamples()
  198377. {
  198378. return 0;
  198379. }
  198380. void start (AudioIODeviceCallback* callback)
  198381. {
  198382. if (! isOpen_)
  198383. callback = 0;
  198384. internal->setCallback (callback);
  198385. if (callback != 0)
  198386. callback->audioDeviceAboutToStart (this);
  198387. isStarted = (callback != 0);
  198388. }
  198389. void stop()
  198390. {
  198391. AudioIODeviceCallback* const oldCallback = internal->callback;
  198392. start (0);
  198393. if (oldCallback != 0)
  198394. oldCallback->audioDeviceStopped();
  198395. }
  198396. bool isPlaying()
  198397. {
  198398. return isStarted && internal->error.isEmpty();
  198399. }
  198400. const String getLastError()
  198401. {
  198402. return internal->error;
  198403. }
  198404. String inputId, outputId;
  198405. private:
  198406. bool isOpen_, isStarted;
  198407. ALSAThread* internal;
  198408. };
  198409. class ALSAAudioIODeviceType : public AudioIODeviceType
  198410. {
  198411. public:
  198412. ALSAAudioIODeviceType()
  198413. : AudioIODeviceType ("ALSA"),
  198414. hasScanned (false)
  198415. {
  198416. }
  198417. ~ALSAAudioIODeviceType()
  198418. {
  198419. }
  198420. void scanForDevices()
  198421. {
  198422. if (hasScanned)
  198423. return;
  198424. hasScanned = true;
  198425. inputNames.clear();
  198426. inputIds.clear();
  198427. outputNames.clear();
  198428. outputIds.clear();
  198429. snd_ctl_t* handle;
  198430. snd_ctl_card_info_t* info;
  198431. snd_ctl_card_info_alloca (&info);
  198432. int cardNum = -1;
  198433. while (outputIds.size() + inputIds.size() <= 32)
  198434. {
  198435. snd_card_next (&cardNum);
  198436. if (cardNum < 0)
  198437. break;
  198438. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198439. {
  198440. if (snd_ctl_card_info (handle, info) >= 0)
  198441. {
  198442. String cardId (snd_ctl_card_info_get_id (info));
  198443. if (cardId.removeCharacters ("0123456789").isEmpty())
  198444. cardId = String (cardNum);
  198445. int device = -1;
  198446. for (;;)
  198447. {
  198448. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198449. break;
  198450. String id, name;
  198451. id << "hw:" << cardId << ',' << device;
  198452. bool isInput, isOutput;
  198453. if (testDevice (id, isInput, isOutput))
  198454. {
  198455. name << snd_ctl_card_info_get_name (info);
  198456. if (name.isEmpty())
  198457. name = id;
  198458. if (isInput)
  198459. {
  198460. inputNames.add (name);
  198461. inputIds.add (id);
  198462. }
  198463. if (isOutput)
  198464. {
  198465. outputNames.add (name);
  198466. outputIds.add (id);
  198467. }
  198468. }
  198469. }
  198470. }
  198471. snd_ctl_close (handle);
  198472. }
  198473. }
  198474. inputNames.appendNumbersToDuplicates (false, true);
  198475. outputNames.appendNumbersToDuplicates (false, true);
  198476. }
  198477. const StringArray getDeviceNames (bool wantInputNames) const
  198478. {
  198479. jassert (hasScanned); // need to call scanForDevices() before doing this
  198480. return wantInputNames ? inputNames : outputNames;
  198481. }
  198482. int getDefaultDeviceIndex (bool forInput) const
  198483. {
  198484. jassert (hasScanned); // need to call scanForDevices() before doing this
  198485. return 0;
  198486. }
  198487. bool hasSeparateInputsAndOutputs() const { return true; }
  198488. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198489. {
  198490. jassert (hasScanned); // need to call scanForDevices() before doing this
  198491. ALSAAudioIODevice* d = dynamic_cast <ALSAAudioIODevice*> (device);
  198492. if (d == 0)
  198493. return -1;
  198494. return asInput ? inputIds.indexOf (d->inputId)
  198495. : outputIds.indexOf (d->outputId);
  198496. }
  198497. AudioIODevice* createDevice (const String& outputDeviceName,
  198498. const String& inputDeviceName)
  198499. {
  198500. jassert (hasScanned); // need to call scanForDevices() before doing this
  198501. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198502. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198503. String deviceName (outputIndex >= 0 ? outputDeviceName
  198504. : inputDeviceName);
  198505. if (inputIndex >= 0 || outputIndex >= 0)
  198506. return new ALSAAudioIODevice (deviceName,
  198507. inputIds [inputIndex],
  198508. outputIds [outputIndex]);
  198509. return 0;
  198510. }
  198511. juce_UseDebuggingNewOperator
  198512. private:
  198513. StringArray inputNames, outputNames, inputIds, outputIds;
  198514. bool hasScanned;
  198515. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198516. {
  198517. unsigned int minChansOut = 0, maxChansOut = 0;
  198518. unsigned int minChansIn = 0, maxChansIn = 0;
  198519. Array <int> rates;
  198520. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198521. DBG ("ALSA device: " + id
  198522. + " outs=" + String ((int) minChansOut) + "-" + String ((int) maxChansOut)
  198523. + " ins=" + String ((int) minChansIn) + "-" + String ((int) maxChansIn)
  198524. + " rates=" + String (rates.size()));
  198525. isInput = maxChansIn > 0;
  198526. isOutput = maxChansOut > 0;
  198527. return (isInput || isOutput) && rates.size() > 0;
  198528. }
  198529. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198530. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198531. };
  198532. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198533. {
  198534. return new ALSAAudioIODeviceType();
  198535. }
  198536. #endif
  198537. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198538. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198539. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198540. // compiled on its own).
  198541. #ifdef JUCE_INCLUDED_FILE
  198542. #if JUCE_JACK
  198543. static void* juce_libjack_handle = 0;
  198544. void* juce_load_jack_function (const char* const name)
  198545. {
  198546. if (juce_libjack_handle == 0)
  198547. return 0;
  198548. return dlsym (juce_libjack_handle, name);
  198549. }
  198550. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198551. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198552. return_type fn_name argument_types { \
  198553. static fn_name##_ptr_t fn = 0; \
  198554. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198555. if (fn) return (*fn)arguments; \
  198556. else return 0; \
  198557. }
  198558. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198559. typedef void (*fn_name##_ptr_t)argument_types; \
  198560. void fn_name argument_types { \
  198561. static fn_name##_ptr_t fn = 0; \
  198562. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198563. if (fn) (*fn)arguments; \
  198564. }
  198565. 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));
  198566. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198567. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198568. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198569. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198570. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198571. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198572. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198573. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198574. 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));
  198575. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198576. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198577. 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));
  198578. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198579. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198580. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198581. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198582. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198583. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198584. #if JUCE_DEBUG
  198585. #define JACK_LOGGING_ENABLED 1
  198586. #endif
  198587. #if JACK_LOGGING_ENABLED
  198588. static void jack_Log (const String& s)
  198589. {
  198590. std::cerr << s << std::endl;
  198591. }
  198592. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198593. {
  198594. if (status & JackServerFailed || status & JackServerError)
  198595. jack_Log ("Unable to connect to JACK server");
  198596. if (status & JackVersionError)
  198597. jack_Log ("Client's protocol version does not match");
  198598. if (status & JackInvalidOption)
  198599. jack_Log ("The operation contained an invalid or unsupported option");
  198600. if (status & JackNameNotUnique)
  198601. jack_Log ("The desired client name was not unique");
  198602. if (status & JackNoSuchClient)
  198603. jack_Log ("Requested client does not exist");
  198604. if (status & JackInitFailure)
  198605. jack_Log ("Unable to initialize client");
  198606. }
  198607. #else
  198608. #define dumpJackErrorMessage(a) {}
  198609. #define jack_Log(...) {}
  198610. #endif
  198611. #ifndef JUCE_JACK_CLIENT_NAME
  198612. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198613. #endif
  198614. class JackAudioIODevice : public AudioIODevice
  198615. {
  198616. public:
  198617. JackAudioIODevice (const String& deviceName,
  198618. const String& inputId_,
  198619. const String& outputId_)
  198620. : AudioIODevice (deviceName, "JACK"),
  198621. inputId (inputId_),
  198622. outputId (outputId_),
  198623. isOpen_ (false),
  198624. callback (0),
  198625. totalNumberOfInputChannels (0),
  198626. totalNumberOfOutputChannels (0)
  198627. {
  198628. jassert (deviceName.isNotEmpty());
  198629. jack_status_t status;
  198630. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  198631. if (client == 0)
  198632. {
  198633. dumpJackErrorMessage (status);
  198634. }
  198635. else
  198636. {
  198637. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  198638. // open input ports
  198639. const StringArray inputChannels (getInputChannelNames());
  198640. for (int i = 0; i < inputChannels.size(); i++)
  198641. {
  198642. String inputName;
  198643. inputName << "in_" << ++totalNumberOfInputChannels;
  198644. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  198645. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  198646. }
  198647. // open output ports
  198648. const StringArray outputChannels (getOutputChannelNames());
  198649. for (int i = 0; i < outputChannels.size (); i++)
  198650. {
  198651. String outputName;
  198652. outputName << "out_" << ++totalNumberOfOutputChannels;
  198653. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  198654. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  198655. }
  198656. inChans.calloc (totalNumberOfInputChannels + 2);
  198657. outChans.calloc (totalNumberOfOutputChannels + 2);
  198658. }
  198659. }
  198660. ~JackAudioIODevice()
  198661. {
  198662. close();
  198663. if (client != 0)
  198664. {
  198665. JUCE_NAMESPACE::jack_client_close (client);
  198666. client = 0;
  198667. }
  198668. }
  198669. const StringArray getChannelNames (bool forInput) const
  198670. {
  198671. StringArray names;
  198672. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  198673. forInput ? JackPortIsInput : JackPortIsOutput);
  198674. if (ports != 0)
  198675. {
  198676. int j = 0;
  198677. while (ports[j] != 0)
  198678. {
  198679. const String portName (ports [j++]);
  198680. if (portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198681. names.add (portName.fromFirstOccurrenceOf (":", false, false));
  198682. }
  198683. free (ports);
  198684. }
  198685. return names;
  198686. }
  198687. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  198688. const StringArray getInputChannelNames() { return getChannelNames (true); }
  198689. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  198690. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  198691. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  198692. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  198693. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  198694. const String open (const BigInteger& inputChannels, const BigInteger& outputChannels,
  198695. double sampleRate, int bufferSizeSamples)
  198696. {
  198697. if (client == 0)
  198698. {
  198699. lastError = "No JACK client running";
  198700. return lastError;
  198701. }
  198702. lastError = String::empty;
  198703. close();
  198704. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  198705. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  198706. JUCE_NAMESPACE::jack_activate (client);
  198707. isOpen_ = true;
  198708. if (! inputChannels.isZero())
  198709. {
  198710. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198711. if (ports != 0)
  198712. {
  198713. const int numInputChannels = inputChannels.getHighestBit() + 1;
  198714. for (int i = 0; i < numInputChannels; ++i)
  198715. {
  198716. const String portName (ports[i]);
  198717. if (inputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198718. {
  198719. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  198720. if (error != 0)
  198721. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198722. }
  198723. }
  198724. free (ports);
  198725. }
  198726. }
  198727. if (! outputChannels.isZero())
  198728. {
  198729. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198730. if (ports != 0)
  198731. {
  198732. const int numOutputChannels = outputChannels.getHighestBit() + 1;
  198733. for (int i = 0; i < numOutputChannels; ++i)
  198734. {
  198735. const String portName (ports[i]);
  198736. if (outputChannels[i] && portName.upToFirstOccurrenceOf (":", false, false) == getName())
  198737. {
  198738. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  198739. if (error != 0)
  198740. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  198741. }
  198742. }
  198743. free (ports);
  198744. }
  198745. }
  198746. return lastError;
  198747. }
  198748. void close()
  198749. {
  198750. stop();
  198751. if (client != 0)
  198752. {
  198753. JUCE_NAMESPACE::jack_deactivate (client);
  198754. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  198755. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  198756. }
  198757. isOpen_ = false;
  198758. }
  198759. void start (AudioIODeviceCallback* newCallback)
  198760. {
  198761. if (isOpen_ && newCallback != callback)
  198762. {
  198763. if (newCallback != 0)
  198764. newCallback->audioDeviceAboutToStart (this);
  198765. AudioIODeviceCallback* const oldCallback = callback;
  198766. {
  198767. const ScopedLock sl (callbackLock);
  198768. callback = newCallback;
  198769. }
  198770. if (oldCallback != 0)
  198771. oldCallback->audioDeviceStopped();
  198772. }
  198773. }
  198774. void stop()
  198775. {
  198776. start (0);
  198777. }
  198778. bool isOpen() { return isOpen_; }
  198779. bool isPlaying() { return callback != 0; }
  198780. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  198781. double getCurrentSampleRate() { return getSampleRate (0); }
  198782. int getCurrentBitDepth() { return 32; }
  198783. const String getLastError() { return lastError; }
  198784. const BigInteger getActiveOutputChannels() const
  198785. {
  198786. BigInteger outputBits;
  198787. for (int i = 0; i < outputPorts.size(); i++)
  198788. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  198789. outputBits.setBit (i);
  198790. return outputBits;
  198791. }
  198792. const BigInteger getActiveInputChannels() const
  198793. {
  198794. BigInteger inputBits;
  198795. for (int i = 0; i < inputPorts.size(); i++)
  198796. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  198797. inputBits.setBit (i);
  198798. return inputBits;
  198799. }
  198800. int getOutputLatencyInSamples()
  198801. {
  198802. int latency = 0;
  198803. for (int i = 0; i < outputPorts.size(); i++)
  198804. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  198805. return latency;
  198806. }
  198807. int getInputLatencyInSamples()
  198808. {
  198809. int latency = 0;
  198810. for (int i = 0; i < inputPorts.size(); i++)
  198811. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  198812. return latency;
  198813. }
  198814. String inputId, outputId;
  198815. private:
  198816. void process (const int numSamples)
  198817. {
  198818. int i, numActiveInChans = 0, numActiveOutChans = 0;
  198819. for (i = 0; i < totalNumberOfInputChannels; ++i)
  198820. {
  198821. jack_default_audio_sample_t* in
  198822. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  198823. if (in != 0)
  198824. inChans [numActiveInChans++] = (float*) in;
  198825. }
  198826. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  198827. {
  198828. jack_default_audio_sample_t* out
  198829. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  198830. if (out != 0)
  198831. outChans [numActiveOutChans++] = (float*) out;
  198832. }
  198833. const ScopedLock sl (callbackLock);
  198834. if (callback != 0)
  198835. {
  198836. callback->audioDeviceIOCallback (const_cast<const float**> (inChans.getData()), numActiveInChans,
  198837. outChans, numActiveOutChans, numSamples);
  198838. }
  198839. else
  198840. {
  198841. for (i = 0; i < numActiveOutChans; ++i)
  198842. zeromem (outChans[i], sizeof (float) * numSamples);
  198843. }
  198844. }
  198845. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  198846. {
  198847. if (callbackArgument != 0)
  198848. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  198849. return 0;
  198850. }
  198851. static void threadInitCallback (void* callbackArgument)
  198852. {
  198853. jack_Log ("JackAudioIODevice::initialise");
  198854. }
  198855. static void shutdownCallback (void* callbackArgument)
  198856. {
  198857. jack_Log ("JackAudioIODevice::shutdown");
  198858. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  198859. if (device != 0)
  198860. {
  198861. device->client = 0;
  198862. device->close();
  198863. }
  198864. }
  198865. static void errorCallback (const char* msg)
  198866. {
  198867. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  198868. }
  198869. bool isOpen_;
  198870. jack_client_t* client;
  198871. String lastError;
  198872. AudioIODeviceCallback* callback;
  198873. CriticalSection callbackLock;
  198874. HeapBlock <float*> inChans, outChans;
  198875. int totalNumberOfInputChannels;
  198876. int totalNumberOfOutputChannels;
  198877. VoidArray inputPorts, outputPorts;
  198878. };
  198879. class JackAudioIODeviceType : public AudioIODeviceType
  198880. {
  198881. public:
  198882. JackAudioIODeviceType()
  198883. : AudioIODeviceType ("JACK"),
  198884. hasScanned (false)
  198885. {
  198886. }
  198887. ~JackAudioIODeviceType()
  198888. {
  198889. }
  198890. void scanForDevices()
  198891. {
  198892. hasScanned = true;
  198893. inputNames.clear();
  198894. inputIds.clear();
  198895. outputNames.clear();
  198896. outputIds.clear();
  198897. if (juce_libjack_handle == 0)
  198898. {
  198899. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  198900. if (juce_libjack_handle == 0)
  198901. return;
  198902. }
  198903. // open a dummy client
  198904. jack_status_t status;
  198905. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  198906. if (client == 0)
  198907. {
  198908. dumpJackErrorMessage (status);
  198909. }
  198910. else
  198911. {
  198912. // scan for output devices
  198913. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  198914. if (ports != 0)
  198915. {
  198916. int j = 0;
  198917. while (ports[j] != 0)
  198918. {
  198919. String clientName (ports[j]);
  198920. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198921. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198922. && ! inputNames.contains (clientName))
  198923. {
  198924. inputNames.add (clientName);
  198925. inputIds.add (ports [j]);
  198926. }
  198927. ++j;
  198928. }
  198929. free (ports);
  198930. }
  198931. // scan for input devices
  198932. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  198933. if (ports != 0)
  198934. {
  198935. int j = 0;
  198936. while (ports[j] != 0)
  198937. {
  198938. String clientName (ports[j]);
  198939. clientName = clientName.upToFirstOccurrenceOf (":", false, false);
  198940. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  198941. && ! outputNames.contains (clientName))
  198942. {
  198943. outputNames.add (clientName);
  198944. outputIds.add (ports [j]);
  198945. }
  198946. ++j;
  198947. }
  198948. free (ports);
  198949. }
  198950. JUCE_NAMESPACE::jack_client_close (client);
  198951. }
  198952. }
  198953. const StringArray getDeviceNames (bool wantInputNames) const
  198954. {
  198955. jassert (hasScanned); // need to call scanForDevices() before doing this
  198956. return wantInputNames ? inputNames : outputNames;
  198957. }
  198958. int getDefaultDeviceIndex (bool forInput) const
  198959. {
  198960. jassert (hasScanned); // need to call scanForDevices() before doing this
  198961. return 0;
  198962. }
  198963. bool hasSeparateInputsAndOutputs() const { return true; }
  198964. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  198965. {
  198966. jassert (hasScanned); // need to call scanForDevices() before doing this
  198967. JackAudioIODevice* d = dynamic_cast <JackAudioIODevice*> (device);
  198968. if (d == 0)
  198969. return -1;
  198970. return asInput ? inputIds.indexOf (d->inputId)
  198971. : outputIds.indexOf (d->outputId);
  198972. }
  198973. AudioIODevice* createDevice (const String& outputDeviceName,
  198974. const String& inputDeviceName)
  198975. {
  198976. jassert (hasScanned); // need to call scanForDevices() before doing this
  198977. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198978. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198979. if (inputIndex >= 0 || outputIndex >= 0)
  198980. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  198981. : inputDeviceName,
  198982. inputIds [inputIndex],
  198983. outputIds [outputIndex]);
  198984. return 0;
  198985. }
  198986. juce_UseDebuggingNewOperator
  198987. private:
  198988. StringArray inputNames, outputNames, inputIds, outputIds;
  198989. bool hasScanned;
  198990. JackAudioIODeviceType (const JackAudioIODeviceType&);
  198991. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  198992. };
  198993. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  198994. {
  198995. return new JackAudioIODeviceType();
  198996. }
  198997. #else // if JACK is turned off..
  198998. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  198999. #endif
  199000. #endif
  199001. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199002. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199003. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199004. // compiled on its own).
  199005. #if JUCE_INCLUDED_FILE
  199006. #if JUCE_ALSA
  199007. static snd_seq_t* iterateDevices (const bool forInput,
  199008. StringArray& deviceNamesFound,
  199009. const int deviceIndexToOpen)
  199010. {
  199011. snd_seq_t* returnedHandle = 0;
  199012. snd_seq_t* seqHandle;
  199013. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199014. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199015. {
  199016. snd_seq_system_info_t* systemInfo;
  199017. snd_seq_client_info_t* clientInfo;
  199018. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199019. {
  199020. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199021. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199022. {
  199023. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199024. while (--numClients >= 0 && returnedHandle == 0)
  199025. {
  199026. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199027. {
  199028. snd_seq_port_info_t* portInfo;
  199029. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199030. {
  199031. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199032. const int client = snd_seq_client_info_get_client (clientInfo);
  199033. snd_seq_port_info_set_client (portInfo, client);
  199034. snd_seq_port_info_set_port (portInfo, -1);
  199035. while (--numPorts >= 0)
  199036. {
  199037. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199038. && (snd_seq_port_info_get_capability (portInfo)
  199039. & (forInput ? SND_SEQ_PORT_CAP_READ
  199040. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199041. {
  199042. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199043. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199044. {
  199045. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199046. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199047. if (sourcePort != -1)
  199048. {
  199049. snd_seq_set_client_name (seqHandle,
  199050. forInput ? "Juce Midi Input"
  199051. : "Juce Midi Output");
  199052. const int portId
  199053. = snd_seq_create_simple_port (seqHandle,
  199054. forInput ? "Juce Midi In Port"
  199055. : "Juce Midi Out Port",
  199056. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199057. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199058. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199059. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199060. returnedHandle = seqHandle;
  199061. }
  199062. }
  199063. }
  199064. }
  199065. snd_seq_port_info_free (portInfo);
  199066. }
  199067. }
  199068. }
  199069. snd_seq_client_info_free (clientInfo);
  199070. }
  199071. snd_seq_system_info_free (systemInfo);
  199072. }
  199073. if (returnedHandle == 0)
  199074. snd_seq_close (seqHandle);
  199075. }
  199076. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199077. return returnedHandle;
  199078. }
  199079. static snd_seq_t* createDevice (const bool forInput,
  199080. const String& deviceNameToOpen)
  199081. {
  199082. snd_seq_t* seqHandle = 0;
  199083. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199084. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199085. {
  199086. snd_seq_set_client_name (seqHandle,
  199087. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199088. const int portId
  199089. = snd_seq_create_simple_port (seqHandle,
  199090. forInput ? "in"
  199091. : "out",
  199092. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199093. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199094. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199095. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199096. if (portId < 0)
  199097. {
  199098. snd_seq_close (seqHandle);
  199099. seqHandle = 0;
  199100. }
  199101. }
  199102. return seqHandle;
  199103. }
  199104. class MidiOutputDevice
  199105. {
  199106. public:
  199107. MidiOutputDevice (MidiOutput* const midiOutput_,
  199108. snd_seq_t* const seqHandle_)
  199109. :
  199110. midiOutput (midiOutput_),
  199111. seqHandle (seqHandle_),
  199112. maxEventSize (16 * 1024)
  199113. {
  199114. jassert (seqHandle != 0 && midiOutput != 0);
  199115. snd_midi_event_new (maxEventSize, &midiParser);
  199116. }
  199117. ~MidiOutputDevice()
  199118. {
  199119. snd_midi_event_free (midiParser);
  199120. snd_seq_close (seqHandle);
  199121. }
  199122. void sendMessageNow (const MidiMessage& message)
  199123. {
  199124. if (message.getRawDataSize() > maxEventSize)
  199125. {
  199126. maxEventSize = message.getRawDataSize();
  199127. snd_midi_event_free (midiParser);
  199128. snd_midi_event_new (maxEventSize, &midiParser);
  199129. }
  199130. snd_seq_event_t event;
  199131. snd_seq_ev_clear (&event);
  199132. snd_midi_event_encode (midiParser,
  199133. message.getRawData(),
  199134. message.getRawDataSize(),
  199135. &event);
  199136. snd_midi_event_reset_encode (midiParser);
  199137. snd_seq_ev_set_source (&event, 0);
  199138. snd_seq_ev_set_subs (&event);
  199139. snd_seq_ev_set_direct (&event);
  199140. snd_seq_event_output (seqHandle, &event);
  199141. snd_seq_drain_output (seqHandle);
  199142. }
  199143. juce_UseDebuggingNewOperator
  199144. private:
  199145. MidiOutput* const midiOutput;
  199146. snd_seq_t* const seqHandle;
  199147. snd_midi_event_t* midiParser;
  199148. int maxEventSize;
  199149. };
  199150. const StringArray MidiOutput::getDevices()
  199151. {
  199152. StringArray devices;
  199153. iterateDevices (false, devices, -1);
  199154. return devices;
  199155. }
  199156. int MidiOutput::getDefaultDeviceIndex()
  199157. {
  199158. return 0;
  199159. }
  199160. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199161. {
  199162. MidiOutput* newDevice = 0;
  199163. StringArray devices;
  199164. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199165. if (handle != 0)
  199166. {
  199167. newDevice = new MidiOutput();
  199168. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199169. }
  199170. return newDevice;
  199171. }
  199172. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199173. {
  199174. MidiOutput* newDevice = 0;
  199175. snd_seq_t* const handle = createDevice (false, deviceName);
  199176. if (handle != 0)
  199177. {
  199178. newDevice = new MidiOutput();
  199179. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199180. }
  199181. return newDevice;
  199182. }
  199183. MidiOutput::~MidiOutput()
  199184. {
  199185. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199186. delete device;
  199187. }
  199188. void MidiOutput::reset()
  199189. {
  199190. }
  199191. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199192. {
  199193. return false;
  199194. }
  199195. void MidiOutput::setVolume (float leftVol, float rightVol)
  199196. {
  199197. }
  199198. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199199. {
  199200. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199201. }
  199202. class MidiInputThread : public Thread
  199203. {
  199204. public:
  199205. MidiInputThread (MidiInput* const midiInput_,
  199206. snd_seq_t* const seqHandle_,
  199207. MidiInputCallback* const callback_)
  199208. : Thread ("Juce MIDI Input"),
  199209. midiInput (midiInput_),
  199210. seqHandle (seqHandle_),
  199211. callback (callback_)
  199212. {
  199213. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199214. }
  199215. ~MidiInputThread()
  199216. {
  199217. snd_seq_close (seqHandle);
  199218. }
  199219. void run()
  199220. {
  199221. const int maxEventSize = 16 * 1024;
  199222. snd_midi_event_t* midiParser;
  199223. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199224. {
  199225. HeapBlock <uint8> buffer (maxEventSize);
  199226. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199227. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199228. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199229. while (! threadShouldExit())
  199230. {
  199231. if (poll (pfd, numPfds, 500) > 0)
  199232. {
  199233. snd_seq_event_t* inputEvent = 0;
  199234. snd_seq_nonblock (seqHandle, 1);
  199235. do
  199236. {
  199237. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199238. {
  199239. // xxx what about SYSEXes that are too big for the buffer?
  199240. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199241. snd_midi_event_reset_decode (midiParser);
  199242. if (numBytes > 0)
  199243. {
  199244. const MidiMessage message ((const uint8*) buffer,
  199245. numBytes,
  199246. Time::getMillisecondCounter() * 0.001);
  199247. callback->handleIncomingMidiMessage (midiInput, message);
  199248. }
  199249. snd_seq_free_event (inputEvent);
  199250. }
  199251. }
  199252. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199253. snd_seq_free_event (inputEvent);
  199254. }
  199255. }
  199256. snd_midi_event_free (midiParser);
  199257. }
  199258. };
  199259. juce_UseDebuggingNewOperator
  199260. private:
  199261. MidiInput* const midiInput;
  199262. snd_seq_t* const seqHandle;
  199263. MidiInputCallback* const callback;
  199264. };
  199265. MidiInput::MidiInput (const String& name_)
  199266. : name (name_),
  199267. internal (0)
  199268. {
  199269. }
  199270. MidiInput::~MidiInput()
  199271. {
  199272. stop();
  199273. MidiInputThread* const thread = (MidiInputThread*) internal;
  199274. delete thread;
  199275. }
  199276. void MidiInput::start()
  199277. {
  199278. ((MidiInputThread*) internal)->startThread();
  199279. }
  199280. void MidiInput::stop()
  199281. {
  199282. ((MidiInputThread*) internal)->stopThread (3000);
  199283. }
  199284. int MidiInput::getDefaultDeviceIndex()
  199285. {
  199286. return 0;
  199287. }
  199288. const StringArray MidiInput::getDevices()
  199289. {
  199290. StringArray devices;
  199291. iterateDevices (true, devices, -1);
  199292. return devices;
  199293. }
  199294. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199295. {
  199296. MidiInput* newDevice = 0;
  199297. StringArray devices;
  199298. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199299. if (handle != 0)
  199300. {
  199301. newDevice = new MidiInput (devices [deviceIndex]);
  199302. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199303. }
  199304. return newDevice;
  199305. }
  199306. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199307. {
  199308. MidiInput* newDevice = 0;
  199309. snd_seq_t* const handle = createDevice (true, deviceName);
  199310. if (handle != 0)
  199311. {
  199312. newDevice = new MidiInput (deviceName);
  199313. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199314. }
  199315. return newDevice;
  199316. }
  199317. #else
  199318. // (These are just stub functions if ALSA is unavailable...)
  199319. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199320. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199321. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199322. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199323. MidiOutput::~MidiOutput() {}
  199324. void MidiOutput::reset() {}
  199325. bool MidiOutput::getVolume (float&, float&) { return false; }
  199326. void MidiOutput::setVolume (float, float) {}
  199327. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199328. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199329. MidiInput::~MidiInput() {}
  199330. void MidiInput::start() {}
  199331. void MidiInput::stop() {}
  199332. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199333. const StringArray MidiInput::getDevices() { return StringArray(); }
  199334. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199335. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199336. #endif
  199337. #endif
  199338. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199339. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199340. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199341. // compiled on its own).
  199342. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199343. AudioCDReader::AudioCDReader()
  199344. : AudioFormatReader (0, "CD Audio")
  199345. {
  199346. }
  199347. const StringArray AudioCDReader::getAvailableCDNames()
  199348. {
  199349. StringArray names;
  199350. return names;
  199351. }
  199352. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199353. {
  199354. return 0;
  199355. }
  199356. AudioCDReader::~AudioCDReader()
  199357. {
  199358. }
  199359. void AudioCDReader::refreshTrackLengths()
  199360. {
  199361. }
  199362. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199363. int64 startSampleInFile, int numSamples)
  199364. {
  199365. return false;
  199366. }
  199367. bool AudioCDReader::isCDStillPresent() const
  199368. {
  199369. return false;
  199370. }
  199371. int AudioCDReader::getNumTracks() const
  199372. {
  199373. return 0;
  199374. }
  199375. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199376. {
  199377. return 0;
  199378. }
  199379. bool AudioCDReader::isTrackAudio (int trackNum) const
  199380. {
  199381. return false;
  199382. }
  199383. void AudioCDReader::enableIndexScanning (bool b)
  199384. {
  199385. }
  199386. int AudioCDReader::getLastIndex() const
  199387. {
  199388. return 0;
  199389. }
  199390. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199391. {
  199392. return Array<int>();
  199393. }
  199394. int AudioCDReader::getCDDBId()
  199395. {
  199396. return 0;
  199397. }
  199398. #endif
  199399. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199400. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199401. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199402. // compiled on its own).
  199403. #if JUCE_INCLUDED_FILE
  199404. void FileChooser::showPlatformDialog (Array<File>& results,
  199405. const String& title,
  199406. const File& file,
  199407. const String& filters,
  199408. bool isDirectory,
  199409. bool selectsFiles,
  199410. bool isSave,
  199411. bool warnAboutOverwritingExistingFiles,
  199412. bool selectMultipleFiles,
  199413. FilePreviewComponent* previewComponent)
  199414. {
  199415. const String separator (":");
  199416. String command ("zenity --file-selection");
  199417. if (title.isNotEmpty())
  199418. command << " --title=\"" << title << "\"";
  199419. if (file != File::nonexistent)
  199420. command << " --filename=\"" << file.getFullPathName () << "\"";
  199421. if (isDirectory)
  199422. command << " --directory";
  199423. if (isSave)
  199424. command << " --save";
  199425. if (selectMultipleFiles)
  199426. command << " --multiple --separator=\"" << separator << "\"";
  199427. command << " 2>&1";
  199428. MemoryOutputStream result;
  199429. int status = -1;
  199430. FILE* stream = popen (command.toUTF8(), "r");
  199431. if (stream != 0)
  199432. {
  199433. for (;;)
  199434. {
  199435. char buffer [1024];
  199436. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199437. if (bytesRead <= 0)
  199438. break;
  199439. result.write (buffer, bytesRead);
  199440. }
  199441. status = pclose (stream);
  199442. }
  199443. if (status == 0)
  199444. {
  199445. StringArray tokens;
  199446. if (selectMultipleFiles)
  199447. tokens.addTokens (result.toUTF8(), separator, String::empty);
  199448. else
  199449. tokens.add (result.toUTF8());
  199450. for (int i = 0; i < tokens.size(); i++)
  199451. results.add (File (tokens[i]));
  199452. return;
  199453. }
  199454. //xxx ain't got one!
  199455. jassertfalse
  199456. }
  199457. #endif
  199458. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199459. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199460. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199461. // compiled on its own).
  199462. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199463. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199464. : browser (0),
  199465. blankPageShown (false),
  199466. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199467. {
  199468. setOpaque (true);
  199469. }
  199470. WebBrowserComponent::~WebBrowserComponent()
  199471. {
  199472. }
  199473. void WebBrowserComponent::goToURL (const String& url,
  199474. const StringArray* headers,
  199475. const MemoryBlock* postData)
  199476. {
  199477. lastURL = url;
  199478. lastHeaders.clear();
  199479. if (headers != 0)
  199480. lastHeaders = *headers;
  199481. lastPostData.setSize (0);
  199482. if (postData != 0)
  199483. lastPostData = *postData;
  199484. blankPageShown = false;
  199485. }
  199486. void WebBrowserComponent::stop()
  199487. {
  199488. }
  199489. void WebBrowserComponent::goBack()
  199490. {
  199491. lastURL = String::empty;
  199492. blankPageShown = false;
  199493. }
  199494. void WebBrowserComponent::goForward()
  199495. {
  199496. lastURL = String::empty;
  199497. }
  199498. void WebBrowserComponent::refresh()
  199499. {
  199500. }
  199501. void WebBrowserComponent::paint (Graphics& g)
  199502. {
  199503. g.fillAll (Colours::white);
  199504. }
  199505. void WebBrowserComponent::checkWindowAssociation()
  199506. {
  199507. }
  199508. void WebBrowserComponent::reloadLastURL()
  199509. {
  199510. if (lastURL.isNotEmpty())
  199511. {
  199512. goToURL (lastURL, &lastHeaders, &lastPostData);
  199513. lastURL = String::empty;
  199514. }
  199515. }
  199516. void WebBrowserComponent::parentHierarchyChanged()
  199517. {
  199518. checkWindowAssociation();
  199519. }
  199520. void WebBrowserComponent::resized()
  199521. {
  199522. }
  199523. void WebBrowserComponent::visibilityChanged()
  199524. {
  199525. checkWindowAssociation();
  199526. }
  199527. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199528. {
  199529. return true;
  199530. }
  199531. #endif
  199532. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199533. #endif
  199534. END_JUCE_NAMESPACE
  199535. #endif
  199536. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199537. #endif
  199538. #if JUCE_MAC || JUCE_IPHONE
  199539. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199540. #if JUCE_MAC || JUCE_IPHONE
  199541. BEGIN_JUCE_NAMESPACE
  199542. #undef Point
  199543. #define JUCE_INCLUDED_FILE 1
  199544. // Now include the actual code files..
  199545. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199546. #ifndef JUCE_ObjCExtraSuffix
  199547. #define JUCE_ObjCExtraSuffix 3
  199548. #endif
  199549. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199550. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199551. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199552. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199553. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199554. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199555. // compiled on its own).
  199556. #if JUCE_INCLUDED_FILE
  199557. static const String nsStringToJuce (NSString* s)
  199558. {
  199559. return String::fromUTF8 ([s UTF8String]);
  199560. }
  199561. static NSString* juceStringToNS (const String& s)
  199562. {
  199563. return [NSString stringWithUTF8String: s.toUTF8()];
  199564. }
  199565. static const String convertUTF16ToString (const UniChar* utf16)
  199566. {
  199567. String s;
  199568. while (*utf16 != 0)
  199569. s += (juce_wchar) *utf16++;
  199570. return s;
  199571. }
  199572. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199573. {
  199574. String result;
  199575. if (cfString != 0)
  199576. {
  199577. CFRange range = { 0, CFStringGetLength (cfString) };
  199578. HeapBlock <UniChar> u (range.length + 1);
  199579. CFStringGetCharacters (cfString, range, u);
  199580. u[range.length] = 0;
  199581. result = convertUTF16ToString (u);
  199582. }
  199583. return result;
  199584. }
  199585. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199586. {
  199587. const int len = s.length();
  199588. HeapBlock <UniChar> temp (len + 2);
  199589. for (int i = 0; i <= len; ++i)
  199590. temp[i] = s[i];
  199591. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199592. }
  199593. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199594. {
  199595. #if JUCE_IPHONE
  199596. const ScopedAutoReleasePool pool;
  199597. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199598. #else
  199599. UnicodeMapping map;
  199600. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199601. kUnicodeNoSubset,
  199602. kTextEncodingDefaultFormat);
  199603. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199604. kUnicodeCanonicalCompVariant,
  199605. kTextEncodingDefaultFormat);
  199606. map.mappingVersion = kUnicodeUseLatestMapping;
  199607. UnicodeToTextInfo conversionInfo = 0;
  199608. String result;
  199609. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199610. {
  199611. const int len = s.length();
  199612. HeapBlock <UniChar> tempIn, tempOut;
  199613. tempIn.calloc (len + 2);
  199614. tempOut.calloc (len + 2);
  199615. for (int i = 0; i <= len; ++i)
  199616. tempIn[i] = s[i];
  199617. ByteCount bytesRead = 0;
  199618. ByteCount outputBufferSize = 0;
  199619. if (ConvertFromUnicodeToText (conversionInfo,
  199620. len * sizeof (UniChar), tempIn,
  199621. kUnicodeDefaultDirectionMask,
  199622. 0, 0, 0, 0,
  199623. len * sizeof (UniChar), &bytesRead,
  199624. &outputBufferSize, tempOut) == noErr)
  199625. {
  199626. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199627. juce_wchar* t = result;
  199628. unsigned int i;
  199629. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  199630. t[i] = (juce_wchar) tempOut[i];
  199631. t[i] = 0;
  199632. }
  199633. DisposeUnicodeToTextInfo (&conversionInfo);
  199634. }
  199635. return result;
  199636. #endif
  199637. }
  199638. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  199639. void SystemClipboard::copyTextToClipboard (const String& text)
  199640. {
  199641. #if JUCE_IPHONE
  199642. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  199643. forPasteboardType: @"public.text"];
  199644. #else
  199645. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  199646. owner: nil];
  199647. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  199648. forType: NSStringPboardType];
  199649. #endif
  199650. }
  199651. const String SystemClipboard::getTextFromClipboard()
  199652. {
  199653. #if JUCE_IPHONE
  199654. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  199655. #else
  199656. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  199657. #endif
  199658. return text == 0 ? String::empty
  199659. : nsStringToJuce (text);
  199660. }
  199661. #endif
  199662. #endif
  199663. /*** End of inlined file: juce_mac_Strings.mm ***/
  199664. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  199665. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199666. // compiled on its own).
  199667. #if JUCE_INCLUDED_FILE
  199668. namespace SystemStatsHelpers
  199669. {
  199670. static int64 highResTimerFrequency = 0;
  199671. static double highResTimerToMillisecRatio = 0;
  199672. #if JUCE_INTEL
  199673. static void juce_getCpuVendor (char* const v) throw()
  199674. {
  199675. int vendor[4];
  199676. zerostruct (vendor);
  199677. int dummy = 0;
  199678. asm ("mov %%ebx, %%esi \n\t"
  199679. "cpuid \n\t"
  199680. "xchg %%esi, %%ebx"
  199681. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  199682. memcpy (v, vendor, 16);
  199683. }
  199684. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  199685. {
  199686. unsigned int cpu = 0;
  199687. unsigned int ext = 0;
  199688. unsigned int family = 0;
  199689. unsigned int dummy = 0;
  199690. asm ("mov %%ebx, %%esi \n\t"
  199691. "cpuid \n\t"
  199692. "xchg %%esi, %%ebx"
  199693. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  199694. familyModel = family;
  199695. extFeatures = ext;
  199696. return cpu;
  199697. }
  199698. struct CPUFlags
  199699. {
  199700. bool hasMMX : 1;
  199701. bool hasSSE : 1;
  199702. bool hasSSE2 : 1;
  199703. bool has3DNow : 1;
  199704. };
  199705. static CPUFlags cpuFlags;
  199706. #endif
  199707. }
  199708. void SystemStats::initialiseStats() throw()
  199709. {
  199710. using namespace SystemStatsHelpers;
  199711. static bool initialised = false;
  199712. if (! initialised)
  199713. {
  199714. initialised = true;
  199715. #if JUCE_MAC
  199716. // extremely annoying: adding this line stops the apple menu items from working. Of
  199717. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  199718. // any events.
  199719. //NSApplicationLoad();
  199720. [NSApplication sharedApplication];
  199721. #endif
  199722. #if JUCE_INTEL
  199723. {
  199724. unsigned int familyModel, extFeatures;
  199725. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  199726. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  199727. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  199728. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  199729. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  199730. }
  199731. #endif
  199732. mach_timebase_info_data_t timebase;
  199733. (void) mach_timebase_info (&timebase);
  199734. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  199735. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  199736. String s (SystemStats::getJUCEVersion());
  199737. rlimit lim;
  199738. getrlimit (RLIMIT_NOFILE, &lim);
  199739. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  199740. setrlimit (RLIMIT_NOFILE, &lim);
  199741. }
  199742. }
  199743. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  199744. {
  199745. return MacOSX;
  199746. }
  199747. const String SystemStats::getOperatingSystemName() throw()
  199748. {
  199749. return "Mac OS X";
  199750. }
  199751. bool SystemStats::isOperatingSystem64Bit() throw()
  199752. {
  199753. #if JUCE_64BIT
  199754. return true;
  199755. #else
  199756. //xxx not sure how to find this out?..
  199757. return false;
  199758. #endif
  199759. }
  199760. int SystemStats::getMemorySizeInMegabytes() throw()
  199761. {
  199762. uint64 mem = 0;
  199763. size_t memSize = sizeof (mem);
  199764. int mib[] = { CTL_HW, HW_MEMSIZE };
  199765. sysctl (mib, 2, &mem, &memSize, 0, 0);
  199766. return (int) (mem / (1024 * 1024));
  199767. }
  199768. bool SystemStats::hasMMX() throw()
  199769. {
  199770. #if JUCE_INTEL
  199771. return SystemStatsHelpers::cpuFlags.hasMMX;
  199772. #else
  199773. return false;
  199774. #endif
  199775. }
  199776. bool SystemStats::hasSSE() throw()
  199777. {
  199778. #if JUCE_INTEL
  199779. return SystemStatsHelpers::cpuFlags.hasSSE;
  199780. #else
  199781. return false;
  199782. #endif
  199783. }
  199784. bool SystemStats::hasSSE2() throw()
  199785. {
  199786. #if JUCE_INTEL
  199787. return SystemStatsHelpers::cpuFlags.hasSSE2;
  199788. #else
  199789. return false;
  199790. #endif
  199791. }
  199792. bool SystemStats::has3DNow() throw()
  199793. {
  199794. #if JUCE_INTEL
  199795. return SystemStatsHelpers::cpuFlags.has3DNow;
  199796. #else
  199797. return false;
  199798. #endif
  199799. }
  199800. const String SystemStats::getCpuVendor() throw()
  199801. {
  199802. #if JUCE_INTEL
  199803. char v [16];
  199804. SystemStatsHelpers::juce_getCpuVendor (v);
  199805. return String (v, 16);
  199806. #else
  199807. return String::empty;
  199808. #endif
  199809. }
  199810. int SystemStats::getCpuSpeedInMegaherz() throw()
  199811. {
  199812. uint64 speedHz = 0;
  199813. size_t speedSize = sizeof (speedHz);
  199814. int mib[] = { CTL_HW, HW_CPU_FREQ };
  199815. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  199816. #if JUCE_BIG_ENDIAN
  199817. if (speedSize == 4)
  199818. speedHz >>= 32;
  199819. #endif
  199820. return (int) (speedHz / 1000000);
  199821. }
  199822. int SystemStats::getNumCpus() throw()
  199823. {
  199824. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  199825. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  199826. #else
  199827. return MPProcessors();
  199828. #endif
  199829. }
  199830. const String SystemStats::getLogonName()
  199831. {
  199832. return nsStringToJuce (NSUserName());
  199833. }
  199834. const String SystemStats::getFullUserName()
  199835. {
  199836. return nsStringToJuce (NSFullUserName());
  199837. }
  199838. uint32 juce_millisecondsSinceStartup() throw()
  199839. {
  199840. return (uint32) (mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio);
  199841. }
  199842. double Time::getMillisecondCounterHiRes() throw()
  199843. {
  199844. return mach_absolute_time() * SystemStatsHelpers::highResTimerToMillisecRatio;
  199845. }
  199846. int64 Time::getHighResolutionTicks() throw()
  199847. {
  199848. return (int64) mach_absolute_time();
  199849. }
  199850. int64 Time::getHighResolutionTicksPerSecond() throw()
  199851. {
  199852. return SystemStatsHelpers::highResTimerFrequency;
  199853. }
  199854. int64 SystemStats::getClockCycleCounter() throw()
  199855. {
  199856. return (int64) mach_absolute_time();
  199857. }
  199858. bool Time::setSystemTimeToThisTime() const throw()
  199859. {
  199860. jassertfalse
  199861. return false;
  199862. }
  199863. int SystemStats::getPageSize() throw()
  199864. {
  199865. return (int) NSPageSize();
  199866. }
  199867. void PlatformUtilities::fpuReset()
  199868. {
  199869. }
  199870. #endif
  199871. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  199872. /*** Start of inlined file: juce_mac_Network.mm ***/
  199873. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199874. // compiled on its own).
  199875. #if JUCE_INCLUDED_FILE
  199876. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian)
  199877. {
  199878. #ifndef IFT_ETHER
  199879. #define IFT_ETHER 6
  199880. #endif
  199881. ifaddrs* addrs = 0;
  199882. int numResults = 0;
  199883. if (getifaddrs (&addrs) == 0)
  199884. {
  199885. const ifaddrs* cursor = addrs;
  199886. while (cursor != 0 && numResults < maxNum)
  199887. {
  199888. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  199889. if (sto->ss_family == AF_LINK)
  199890. {
  199891. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  199892. if (sadd->sdl_type == IFT_ETHER)
  199893. {
  199894. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  199895. uint64 a = 0;
  199896. for (int i = 6; --i >= 0;)
  199897. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  199898. *addresses++ = (int64) a;
  199899. ++numResults;
  199900. }
  199901. }
  199902. cursor = cursor->ifa_next;
  199903. }
  199904. freeifaddrs (addrs);
  199905. }
  199906. return numResults;
  199907. }
  199908. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  199909. const String& emailSubject,
  199910. const String& bodyText,
  199911. const StringArray& filesToAttach)
  199912. {
  199913. #if JUCE_IPHONE
  199914. //xxx probably need to use MFMailComposeViewController
  199915. jassertfalse
  199916. return false;
  199917. #else
  199918. const ScopedAutoReleasePool pool;
  199919. String script;
  199920. script << "tell application \"Mail\"\r\n"
  199921. "set newMessage to make new outgoing message with properties {subject:\""
  199922. << emailSubject.replace ("\"", "\\\"")
  199923. << "\", content:\""
  199924. << bodyText.replace ("\"", "\\\"")
  199925. << "\" & return & return}\r\n"
  199926. "tell newMessage\r\n"
  199927. "set visible to true\r\n"
  199928. "set sender to \"sdfsdfsdfewf\"\r\n"
  199929. "make new to recipient at end of to recipients with properties {address:\""
  199930. << targetEmailAddress
  199931. << "\"}\r\n";
  199932. for (int i = 0; i < filesToAttach.size(); ++i)
  199933. {
  199934. script << "tell content\r\n"
  199935. "make new attachment with properties {file name:\""
  199936. << filesToAttach[i].replace ("\"", "\\\"")
  199937. << "\"} at after the last paragraph\r\n"
  199938. "end tell\r\n";
  199939. }
  199940. script << "end tell\r\n"
  199941. "end tell\r\n";
  199942. NSAppleScript* s = [[NSAppleScript alloc]
  199943. initWithSource: juceStringToNS (script)];
  199944. NSDictionary* error = 0;
  199945. const bool ok = [s executeAndReturnError: &error] != nil;
  199946. [s release];
  199947. return ok;
  199948. #endif
  199949. }
  199950. END_JUCE_NAMESPACE
  199951. using namespace JUCE_NAMESPACE;
  199952. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  199953. @interface JuceURLConnection : NSObject
  199954. {
  199955. @public
  199956. NSURLRequest* request;
  199957. NSURLConnection* connection;
  199958. NSMutableData* data;
  199959. Thread* runLoopThread;
  199960. bool initialised, hasFailed, hasFinished;
  199961. int position;
  199962. int64 contentLength;
  199963. NSLock* dataLock;
  199964. }
  199965. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  199966. - (void) dealloc;
  199967. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  199968. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  199969. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  199970. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  199971. - (BOOL) isOpen;
  199972. - (int) read: (char*) dest numBytes: (int) num;
  199973. - (int) readPosition;
  199974. - (void) stop;
  199975. - (void) createConnection;
  199976. @end
  199977. class JuceURLConnectionMessageThread : public Thread
  199978. {
  199979. JuceURLConnection* owner;
  199980. public:
  199981. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  199982. : Thread ("http connection"),
  199983. owner (owner_)
  199984. {
  199985. }
  199986. ~JuceURLConnectionMessageThread()
  199987. {
  199988. stopThread (10000);
  199989. }
  199990. void run()
  199991. {
  199992. [owner createConnection];
  199993. while (! threadShouldExit())
  199994. {
  199995. const ScopedAutoReleasePool pool;
  199996. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  199997. }
  199998. }
  199999. };
  200000. @implementation JuceURLConnection
  200001. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200002. withCallback: (URL::OpenStreamProgressCallback*) callback
  200003. withContext: (void*) context;
  200004. {
  200005. [super init];
  200006. request = req;
  200007. [request retain];
  200008. data = [[NSMutableData data] retain];
  200009. dataLock = [[NSLock alloc] init];
  200010. connection = 0;
  200011. initialised = false;
  200012. hasFailed = false;
  200013. hasFinished = false;
  200014. contentLength = -1;
  200015. runLoopThread = new JuceURLConnectionMessageThread (self);
  200016. runLoopThread->startThread();
  200017. while (runLoopThread->isThreadRunning() && ! initialised)
  200018. {
  200019. if (callback != 0)
  200020. callback (context, -1, (int) [[request HTTPBody] length]);
  200021. Thread::sleep (1);
  200022. }
  200023. return self;
  200024. }
  200025. - (void) dealloc
  200026. {
  200027. [self stop];
  200028. deleteAndZero (runLoopThread);
  200029. [connection release];
  200030. [data release];
  200031. [dataLock release];
  200032. [request release];
  200033. [super dealloc];
  200034. }
  200035. - (void) createConnection
  200036. {
  200037. connection = [[NSURLConnection alloc] initWithRequest: request
  200038. delegate: [self retain]];
  200039. if (connection == nil)
  200040. runLoopThread->signalThreadShouldExit();
  200041. }
  200042. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200043. {
  200044. [dataLock lock];
  200045. [data setLength: 0];
  200046. [dataLock unlock];
  200047. initialised = true;
  200048. contentLength = [response expectedContentLength];
  200049. }
  200050. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200051. {
  200052. DBG (nsStringToJuce ([error description]));
  200053. hasFailed = true;
  200054. initialised = true;
  200055. if (runLoopThread != 0)
  200056. runLoopThread->signalThreadShouldExit();
  200057. }
  200058. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200059. {
  200060. [dataLock lock];
  200061. [data appendData: newData];
  200062. [dataLock unlock];
  200063. initialised = true;
  200064. }
  200065. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200066. {
  200067. hasFinished = true;
  200068. initialised = true;
  200069. if (runLoopThread != 0)
  200070. runLoopThread->signalThreadShouldExit();
  200071. }
  200072. - (BOOL) isOpen
  200073. {
  200074. return connection != 0 && ! hasFailed;
  200075. }
  200076. - (int) readPosition
  200077. {
  200078. return position;
  200079. }
  200080. - (int) read: (char*) dest numBytes: (int) numNeeded
  200081. {
  200082. int numDone = 0;
  200083. while (numNeeded > 0)
  200084. {
  200085. int available = jmin (numNeeded, (int) [data length]);
  200086. if (available > 0)
  200087. {
  200088. [dataLock lock];
  200089. [data getBytes: dest length: available];
  200090. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200091. [dataLock unlock];
  200092. numDone += available;
  200093. numNeeded -= available;
  200094. dest += available;
  200095. }
  200096. else
  200097. {
  200098. if (hasFailed || hasFinished)
  200099. break;
  200100. Thread::sleep (1);
  200101. }
  200102. }
  200103. position += numDone;
  200104. return numDone;
  200105. }
  200106. - (void) stop
  200107. {
  200108. [connection cancel];
  200109. if (runLoopThread != 0)
  200110. runLoopThread->stopThread (10000);
  200111. }
  200112. @end
  200113. BEGIN_JUCE_NAMESPACE
  200114. bool juce_isOnLine()
  200115. {
  200116. return true;
  200117. }
  200118. void* juce_openInternetFile (const String& url,
  200119. const String& headers,
  200120. const MemoryBlock& postData,
  200121. const bool isPost,
  200122. URL::OpenStreamProgressCallback* callback,
  200123. void* callbackContext,
  200124. int timeOutMs)
  200125. {
  200126. const ScopedAutoReleasePool pool;
  200127. NSMutableURLRequest* req = [NSMutableURLRequest
  200128. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200129. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200130. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200131. if (req == nil)
  200132. return 0;
  200133. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200134. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200135. StringArray headerLines;
  200136. headerLines.addLines (headers);
  200137. headerLines.removeEmptyStrings (true);
  200138. for (int i = 0; i < headerLines.size(); ++i)
  200139. {
  200140. const String key (headerLines[i].upToFirstOccurrenceOf (":", false, false).trim());
  200141. const String value (headerLines[i].fromFirstOccurrenceOf (":", false, false).trim());
  200142. if (key.isNotEmpty() && value.isNotEmpty())
  200143. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200144. }
  200145. if (isPost && postData.getSize() > 0)
  200146. {
  200147. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200148. length: postData.getSize()]];
  200149. }
  200150. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200151. withCallback: callback
  200152. withContext: callbackContext];
  200153. if ([s isOpen])
  200154. return s;
  200155. [s release];
  200156. return 0;
  200157. }
  200158. void juce_closeInternetFile (void* handle)
  200159. {
  200160. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200161. if (s != 0)
  200162. {
  200163. const ScopedAutoReleasePool pool;
  200164. [s stop];
  200165. [s release];
  200166. }
  200167. }
  200168. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200169. {
  200170. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200171. if (s != 0)
  200172. {
  200173. const ScopedAutoReleasePool pool;
  200174. return [s read: (char*) buffer numBytes: bytesToRead];
  200175. }
  200176. return 0;
  200177. }
  200178. int64 juce_getInternetFileContentLength (void* handle)
  200179. {
  200180. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200181. if (s != 0)
  200182. return s->contentLength;
  200183. return -1;
  200184. }
  200185. int juce_seekInInternetFile (void* handle, int newPosition)
  200186. {
  200187. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200188. if (s != 0)
  200189. return [s readPosition];
  200190. return 0;
  200191. }
  200192. #endif
  200193. /*** End of inlined file: juce_mac_Network.mm ***/
  200194. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200195. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200196. // compiled on its own).
  200197. #if JUCE_INCLUDED_FILE
  200198. struct NamedPipeInternal
  200199. {
  200200. String pipeInName, pipeOutName;
  200201. int pipeIn, pipeOut;
  200202. bool volatile createdPipe, blocked, stopReadOperation;
  200203. static void signalHandler (int) {}
  200204. };
  200205. void NamedPipe::cancelPendingReads()
  200206. {
  200207. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200208. {
  200209. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200210. intern->stopReadOperation = true;
  200211. char buffer [1] = { 0 };
  200212. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200213. (void) bytesWritten;
  200214. int timeout = 2000;
  200215. while (intern->blocked && --timeout >= 0)
  200216. Thread::sleep (2);
  200217. intern->stopReadOperation = false;
  200218. }
  200219. }
  200220. void NamedPipe::close()
  200221. {
  200222. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200223. if (intern != 0)
  200224. {
  200225. internal = 0;
  200226. if (intern->pipeIn != -1)
  200227. ::close (intern->pipeIn);
  200228. if (intern->pipeOut != -1)
  200229. ::close (intern->pipeOut);
  200230. if (intern->createdPipe)
  200231. {
  200232. unlink (intern->pipeInName.toUTF8());
  200233. unlink (intern->pipeOutName.toUTF8());
  200234. }
  200235. delete intern;
  200236. }
  200237. }
  200238. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200239. {
  200240. close();
  200241. NamedPipeInternal* const intern = new NamedPipeInternal();
  200242. internal = intern;
  200243. intern->createdPipe = createPipe;
  200244. intern->blocked = false;
  200245. intern->stopReadOperation = false;
  200246. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200247. siginterrupt (SIGPIPE, 1);
  200248. const String pipePath ("/tmp/" + File::createLegalFileName (pipeName));
  200249. intern->pipeInName = pipePath + "_in";
  200250. intern->pipeOutName = pipePath + "_out";
  200251. intern->pipeIn = -1;
  200252. intern->pipeOut = -1;
  200253. if (createPipe)
  200254. {
  200255. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200256. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200257. {
  200258. delete intern;
  200259. internal = 0;
  200260. return false;
  200261. }
  200262. }
  200263. return true;
  200264. }
  200265. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200266. {
  200267. int bytesRead = -1;
  200268. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200269. if (intern != 0)
  200270. {
  200271. intern->blocked = true;
  200272. if (intern->pipeIn == -1)
  200273. {
  200274. if (intern->createdPipe)
  200275. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200276. else
  200277. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200278. if (intern->pipeIn == -1)
  200279. {
  200280. intern->blocked = false;
  200281. return -1;
  200282. }
  200283. }
  200284. bytesRead = 0;
  200285. char* p = (char*) destBuffer;
  200286. while (bytesRead < maxBytesToRead)
  200287. {
  200288. const int bytesThisTime = maxBytesToRead - bytesRead;
  200289. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200290. if (numRead <= 0 || intern->stopReadOperation)
  200291. {
  200292. bytesRead = -1;
  200293. break;
  200294. }
  200295. bytesRead += numRead;
  200296. p += bytesRead;
  200297. }
  200298. intern->blocked = false;
  200299. }
  200300. return bytesRead;
  200301. }
  200302. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200303. {
  200304. int bytesWritten = -1;
  200305. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200306. if (intern != 0)
  200307. {
  200308. if (intern->pipeOut == -1)
  200309. {
  200310. if (intern->createdPipe)
  200311. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200312. else
  200313. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200314. if (intern->pipeOut == -1)
  200315. {
  200316. return -1;
  200317. }
  200318. }
  200319. const char* p = (const char*) sourceBuffer;
  200320. bytesWritten = 0;
  200321. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200322. while (bytesWritten < numBytesToWrite
  200323. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200324. {
  200325. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200326. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200327. if (numWritten <= 0)
  200328. {
  200329. bytesWritten = -1;
  200330. break;
  200331. }
  200332. bytesWritten += numWritten;
  200333. p += bytesWritten;
  200334. }
  200335. }
  200336. return bytesWritten;
  200337. }
  200338. #endif
  200339. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200340. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200341. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200342. // compiled on its own).
  200343. #if JUCE_INCLUDED_FILE
  200344. void JUCE_API juce_threadEntryPoint (void*);
  200345. void* threadEntryProc (void* userData)
  200346. {
  200347. const ScopedAutoReleasePool pool;
  200348. juce_threadEntryPoint (userData);
  200349. return 0;
  200350. }
  200351. void* juce_createThread (void* userData)
  200352. {
  200353. pthread_t handle = 0;
  200354. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200355. {
  200356. pthread_detach (handle);
  200357. return (void*) handle;
  200358. }
  200359. return 0;
  200360. }
  200361. void juce_killThread (void* handle)
  200362. {
  200363. if (handle != 0)
  200364. pthread_cancel ((pthread_t) handle);
  200365. }
  200366. void juce_setCurrentThreadName (const String& /*name*/)
  200367. {
  200368. }
  200369. bool juce_setThreadPriority (void* handle, int priority)
  200370. {
  200371. if (handle == 0)
  200372. handle = (void*) pthread_self();
  200373. struct sched_param param;
  200374. int policy;
  200375. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200376. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200377. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200378. }
  200379. Thread::ThreadID Thread::getCurrentThreadId()
  200380. {
  200381. return static_cast <ThreadID> (pthread_self());
  200382. }
  200383. void Thread::yield()
  200384. {
  200385. sched_yield();
  200386. }
  200387. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200388. {
  200389. // xxx
  200390. jassertfalse
  200391. }
  200392. bool Process::isForegroundProcess()
  200393. {
  200394. #if JUCE_MAC
  200395. return [NSApp isActive];
  200396. #else
  200397. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200398. #endif
  200399. }
  200400. void Process::raisePrivilege()
  200401. {
  200402. jassertfalse
  200403. }
  200404. void Process::lowerPrivilege()
  200405. {
  200406. jassertfalse
  200407. }
  200408. void Process::terminate()
  200409. {
  200410. exit (0);
  200411. }
  200412. void Process::setPriority (ProcessPriority p)
  200413. {
  200414. // xxx
  200415. }
  200416. #endif
  200417. /*** End of inlined file: juce_mac_Threads.mm ***/
  200418. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200419. CriticalSection::CriticalSection() throw()
  200420. {
  200421. pthread_mutexattr_t atts;
  200422. pthread_mutexattr_init (&atts);
  200423. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200424. pthread_mutex_init (&internal, &atts);
  200425. }
  200426. CriticalSection::~CriticalSection() throw()
  200427. {
  200428. pthread_mutex_destroy (&internal);
  200429. }
  200430. void CriticalSection::enter() const throw()
  200431. {
  200432. pthread_mutex_lock (&internal);
  200433. }
  200434. bool CriticalSection::tryEnter() const throw()
  200435. {
  200436. return pthread_mutex_trylock (&internal) == 0;
  200437. }
  200438. void CriticalSection::exit() const throw()
  200439. {
  200440. pthread_mutex_unlock (&internal);
  200441. }
  200442. class WaitableEventImpl
  200443. {
  200444. public:
  200445. WaitableEventImpl (const bool manualReset_)
  200446. : triggered (false),
  200447. manualReset (manualReset_)
  200448. {
  200449. pthread_cond_init (&condition, 0);
  200450. pthread_mutex_init (&mutex, 0);
  200451. }
  200452. ~WaitableEventImpl()
  200453. {
  200454. pthread_cond_destroy (&condition);
  200455. pthread_mutex_destroy (&mutex);
  200456. }
  200457. bool wait (const int timeOutMillisecs) throw()
  200458. {
  200459. pthread_mutex_lock (&mutex);
  200460. if (! triggered)
  200461. {
  200462. if (timeOutMillisecs < 0)
  200463. {
  200464. do
  200465. {
  200466. pthread_cond_wait (&condition, &mutex);
  200467. }
  200468. while (! triggered);
  200469. }
  200470. else
  200471. {
  200472. struct timeval now;
  200473. gettimeofday (&now, 0);
  200474. struct timespec time;
  200475. time.tv_sec = now.tv_sec + (timeOutMillisecs / 1000);
  200476. time.tv_nsec = (now.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200477. if (time.tv_nsec >= 1000000000)
  200478. {
  200479. time.tv_nsec -= 1000000000;
  200480. time.tv_sec++;
  200481. }
  200482. do
  200483. {
  200484. if (pthread_cond_timedwait (&condition, &mutex, &time) == ETIMEDOUT)
  200485. {
  200486. pthread_mutex_unlock (&mutex);
  200487. return false;
  200488. }
  200489. }
  200490. while (! triggered);
  200491. }
  200492. }
  200493. if (! manualReset)
  200494. triggered = false;
  200495. pthread_mutex_unlock (&mutex);
  200496. return true;
  200497. }
  200498. void signal() throw()
  200499. {
  200500. pthread_mutex_lock (&mutex);
  200501. triggered = true;
  200502. pthread_cond_broadcast (&condition);
  200503. pthread_mutex_unlock (&mutex);
  200504. }
  200505. void reset() throw()
  200506. {
  200507. pthread_mutex_lock (&mutex);
  200508. triggered = false;
  200509. pthread_mutex_unlock (&mutex);
  200510. }
  200511. private:
  200512. pthread_cond_t condition;
  200513. pthread_mutex_t mutex;
  200514. bool triggered;
  200515. const bool manualReset;
  200516. WaitableEventImpl (const WaitableEventImpl&);
  200517. WaitableEventImpl& operator= (const WaitableEventImpl&);
  200518. };
  200519. WaitableEvent::WaitableEvent (const bool manualReset) throw()
  200520. : internal (new WaitableEventImpl (manualReset))
  200521. {
  200522. }
  200523. WaitableEvent::~WaitableEvent() throw()
  200524. {
  200525. delete static_cast <WaitableEventImpl*> (internal);
  200526. }
  200527. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200528. {
  200529. return static_cast <WaitableEventImpl*> (internal)->wait (timeOutMillisecs);
  200530. }
  200531. void WaitableEvent::signal() const throw()
  200532. {
  200533. static_cast <WaitableEventImpl*> (internal)->signal();
  200534. }
  200535. void WaitableEvent::reset() const throw()
  200536. {
  200537. static_cast <WaitableEventImpl*> (internal)->reset();
  200538. }
  200539. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200540. {
  200541. struct timespec time;
  200542. time.tv_sec = millisecs / 1000;
  200543. time.tv_nsec = (millisecs % 1000) * 1000000;
  200544. nanosleep (&time, 0);
  200545. }
  200546. const juce_wchar File::separator = '/';
  200547. const juce_wchar* File::separatorString = L"/";
  200548. const File File::getCurrentWorkingDirectory()
  200549. {
  200550. HeapBlock<char> heapBuffer;
  200551. char localBuffer [1024];
  200552. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200553. int bufferSize = 4096;
  200554. while (cwd == 0 && errno == ERANGE)
  200555. {
  200556. heapBuffer.malloc (bufferSize);
  200557. cwd = getcwd (heapBuffer, bufferSize - 1);
  200558. bufferSize += 1024;
  200559. }
  200560. return File (String::fromUTF8 (cwd));
  200561. }
  200562. bool File::setAsCurrentWorkingDirectory() const
  200563. {
  200564. return chdir (getFullPathName().toUTF8()) == 0;
  200565. }
  200566. bool juce_copyFile (const String& s, const String& d);
  200567. static bool juce_stat (const String& fileName, struct stat& info)
  200568. {
  200569. return fileName.isNotEmpty()
  200570. && (stat (fileName.toUTF8(), &info) == 0);
  200571. }
  200572. bool juce_isDirectory (const String& fileName)
  200573. {
  200574. struct stat info;
  200575. return fileName.isEmpty()
  200576. || (juce_stat (fileName, info)
  200577. && ((info.st_mode & S_IFDIR) != 0));
  200578. }
  200579. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200580. {
  200581. if (fileName.isEmpty())
  200582. return false;
  200583. const char* const fileNameUTF8 = fileName.toUTF8();
  200584. bool exists = access (fileNameUTF8, F_OK) == 0;
  200585. if (exists && dontCountDirectories)
  200586. {
  200587. struct stat info;
  200588. const int res = stat (fileNameUTF8, &info);
  200589. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200590. exists = false;
  200591. }
  200592. return exists;
  200593. }
  200594. int64 juce_getFileSize (const String& fileName)
  200595. {
  200596. struct stat info;
  200597. return juce_stat (fileName, info) ? info.st_size : 0;
  200598. }
  200599. bool juce_canWriteToFile (const String& fileName)
  200600. {
  200601. return access (fileName.toUTF8(), W_OK) == 0;
  200602. }
  200603. bool juce_deleteFile (const String& fileName)
  200604. {
  200605. if (juce_isDirectory (fileName))
  200606. return rmdir (fileName.toUTF8()) == 0;
  200607. else
  200608. return remove (fileName.toUTF8()) == 0;
  200609. }
  200610. bool juce_moveFile (const String& source, const String& dest)
  200611. {
  200612. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200613. return true;
  200614. if (juce_canWriteToFile (source)
  200615. && juce_copyFile (source, dest))
  200616. {
  200617. if (juce_deleteFile (source))
  200618. return true;
  200619. juce_deleteFile (dest);
  200620. }
  200621. return false;
  200622. }
  200623. void juce_createDirectory (const String& fileName)
  200624. {
  200625. mkdir (fileName.toUTF8(), 0777);
  200626. }
  200627. void* juce_fileOpen (const String& fileName, bool forWriting)
  200628. {
  200629. int flags = O_RDONLY;
  200630. if (forWriting)
  200631. {
  200632. if (juce_fileExists (fileName, false))
  200633. {
  200634. const int f = open (fileName.toUTF8(), O_RDWR, 00644);
  200635. if (f != -1)
  200636. lseek (f, 0, SEEK_END);
  200637. return (void*) f;
  200638. }
  200639. else
  200640. {
  200641. flags = O_RDWR + O_CREAT;
  200642. }
  200643. }
  200644. return (void*) open (fileName.toUTF8(), flags, 00644);
  200645. }
  200646. void juce_fileClose (void* handle)
  200647. {
  200648. if (handle != 0)
  200649. close ((int) (pointer_sized_int) handle);
  200650. }
  200651. int juce_fileRead (void* handle, void* buffer, int size)
  200652. {
  200653. if (handle != 0)
  200654. return jmax (0, (int) read ((int) (pointer_sized_int) handle, buffer, size));
  200655. return 0;
  200656. }
  200657. int juce_fileWrite (void* handle, const void* buffer, int size)
  200658. {
  200659. if (handle != 0)
  200660. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200661. return 0;
  200662. }
  200663. int64 juce_fileSetPosition (void* handle, int64 pos)
  200664. {
  200665. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  200666. return pos;
  200667. return -1;
  200668. }
  200669. int64 juce_fileGetPosition (void* handle)
  200670. {
  200671. if (handle != 0)
  200672. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  200673. return -1;
  200674. }
  200675. void juce_fileFlush (void* handle)
  200676. {
  200677. if (handle != 0)
  200678. fsync ((int) (pointer_sized_int) handle);
  200679. }
  200680. const File juce_getExecutableFile()
  200681. {
  200682. Dl_info exeInfo;
  200683. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  200684. return File::getCurrentWorkingDirectory().getChildFile (String::fromUTF8 (exeInfo.dli_fname));
  200685. }
  200686. // if this file doesn't exist, find a parent of it that does..
  200687. static bool doStatFS (const File* file, struct statfs& result)
  200688. {
  200689. File f (*file);
  200690. for (int i = 5; --i >= 0;)
  200691. {
  200692. if (f.exists())
  200693. break;
  200694. f = f.getParentDirectory();
  200695. }
  200696. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  200697. }
  200698. int64 File::getBytesFreeOnVolume() const
  200699. {
  200700. struct statfs buf;
  200701. if (doStatFS (this, buf))
  200702. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  200703. return 0;
  200704. }
  200705. int64 File::getVolumeTotalSize() const
  200706. {
  200707. struct statfs buf;
  200708. if (doStatFS (this, buf))
  200709. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  200710. return 0;
  200711. }
  200712. const String juce_getVolumeLabel (const String& filenameOnVolume,
  200713. int& volumeSerialNumber)
  200714. {
  200715. volumeSerialNumber = 0;
  200716. #if JUCE_MAC
  200717. struct VolAttrBuf
  200718. {
  200719. u_int32_t length;
  200720. attrreference_t mountPointRef;
  200721. char mountPointSpace [MAXPATHLEN];
  200722. } attrBuf;
  200723. struct attrlist attrList;
  200724. zerostruct (attrList);
  200725. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  200726. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  200727. File f (filenameOnVolume);
  200728. for (;;)
  200729. {
  200730. if (getattrlist (f.getFullPathName().toUTF8(),
  200731. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  200732. {
  200733. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  200734. (int) attrBuf.mountPointRef.attr_length);
  200735. }
  200736. const File parent (f.getParentDirectory());
  200737. if (f == parent)
  200738. break;
  200739. f = parent;
  200740. }
  200741. #endif
  200742. return String::empty;
  200743. }
  200744. void juce_runSystemCommand (const String& command)
  200745. {
  200746. int result = system (command.toUTF8());
  200747. (void) result;
  200748. }
  200749. const String juce_getOutputFromCommand (const String& command)
  200750. {
  200751. // slight bodge here, as we just pipe the output into a temp file and read it...
  200752. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  200753. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  200754. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  200755. String result (tempFile.loadFileAsString());
  200756. tempFile.deleteFile();
  200757. return result;
  200758. }
  200759. class InterProcessLock::Pimpl
  200760. {
  200761. public:
  200762. Pimpl (const String& name, const int timeOutMillisecs)
  200763. : handle (0), refCount (1)
  200764. {
  200765. #if JUCE_MAC
  200766. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  200767. const File temp (File ("~/Library/Caches/Juce").getChildFile (name));
  200768. #else
  200769. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  200770. #endif
  200771. temp.create();
  200772. handle = open (temp.getFullPathName().toUTF8(), O_RDWR);
  200773. if (handle != 0)
  200774. {
  200775. struct flock fl;
  200776. zerostruct (fl);
  200777. fl.l_whence = SEEK_SET;
  200778. fl.l_type = F_WRLCK;
  200779. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  200780. for (;;)
  200781. {
  200782. const int result = fcntl (handle, F_SETLK, &fl);
  200783. if (result >= 0)
  200784. return;
  200785. if (errno != EINTR)
  200786. {
  200787. if (timeOutMillisecs == 0
  200788. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  200789. break;
  200790. Thread::sleep (10);
  200791. }
  200792. }
  200793. }
  200794. closeFile();
  200795. }
  200796. ~Pimpl()
  200797. {
  200798. closeFile();
  200799. }
  200800. void closeFile()
  200801. {
  200802. if (handle != 0)
  200803. {
  200804. struct flock fl;
  200805. zerostruct (fl);
  200806. fl.l_whence = SEEK_SET;
  200807. fl.l_type = F_UNLCK;
  200808. while (! (fcntl (handle, F_SETLKW, &fl) >= 0 || errno != EINTR))
  200809. {}
  200810. close (handle);
  200811. handle = 0;
  200812. }
  200813. }
  200814. int handle, refCount;
  200815. };
  200816. InterProcessLock::InterProcessLock (const String& name_)
  200817. : name (name_)
  200818. {
  200819. }
  200820. InterProcessLock::~InterProcessLock()
  200821. {
  200822. }
  200823. bool InterProcessLock::enter (const int timeOutMillisecs)
  200824. {
  200825. const ScopedLock sl (lock);
  200826. if (pimpl == 0)
  200827. {
  200828. pimpl = new Pimpl (name, timeOutMillisecs);
  200829. if (pimpl->handle == 0)
  200830. pimpl = 0;
  200831. }
  200832. else
  200833. {
  200834. pimpl->refCount++;
  200835. }
  200836. return pimpl != 0;
  200837. }
  200838. void InterProcessLock::exit()
  200839. {
  200840. const ScopedLock sl (lock);
  200841. // Trying to release the lock too many times!
  200842. jassert (pimpl != 0);
  200843. if (pimpl != 0 && --(pimpl->refCount) == 0)
  200844. pimpl = 0;
  200845. }
  200846. /*** End of inlined file: juce_posix_SharedCode.h ***/
  200847. /*** Start of inlined file: juce_mac_Files.mm ***/
  200848. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200849. // compiled on its own).
  200850. #if JUCE_INCLUDED_FILE
  200851. void juce_getFileTimes (const String& fileName,
  200852. int64& modificationTime,
  200853. int64& accessTime,
  200854. int64& creationTime)
  200855. {
  200856. modificationTime = 0;
  200857. accessTime = 0;
  200858. creationTime = 0;
  200859. struct stat info;
  200860. const int res = stat (fileName.toUTF8(), &info);
  200861. if (res == 0)
  200862. {
  200863. modificationTime = (int64) info.st_mtime * 1000;
  200864. accessTime = (int64) info.st_atime * 1000;
  200865. creationTime = (int64) info.st_ctime * 1000;
  200866. }
  200867. }
  200868. bool juce_setFileTimes (const String& fileName,
  200869. int64 modificationTime,
  200870. int64 accessTime,
  200871. int64 creationTime)
  200872. {
  200873. struct utimbuf times;
  200874. times.actime = (time_t) (accessTime / 1000);
  200875. times.modtime = (time_t) (modificationTime / 1000);
  200876. return utime (fileName.toUTF8(), &times) == 0;
  200877. }
  200878. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  200879. {
  200880. struct stat info;
  200881. const int res = stat (fileName.toUTF8(), &info);
  200882. if (res != 0)
  200883. return false;
  200884. info.st_mode &= 0777; // Just permissions
  200885. if (isReadOnly)
  200886. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  200887. else
  200888. // Give everybody write permission?
  200889. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  200890. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  200891. }
  200892. bool juce_copyFile (const String& src, const String& dst)
  200893. {
  200894. const ScopedAutoReleasePool pool;
  200895. NSFileManager* fm = [NSFileManager defaultManager];
  200896. return [fm fileExistsAtPath: juceStringToNS (src)]
  200897. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  200898. && [fm copyItemAtPath: juceStringToNS (src)
  200899. toPath: juceStringToNS (dst)
  200900. error: nil];
  200901. #else
  200902. && [fm copyPath: juceStringToNS (src)
  200903. toPath: juceStringToNS (dst)
  200904. handler: nil];
  200905. #endif
  200906. }
  200907. const StringArray juce_getFileSystemRoots()
  200908. {
  200909. StringArray s;
  200910. s.add ("/");
  200911. return s;
  200912. }
  200913. static bool isFileOnDriveType (const File* const f, const char** types)
  200914. {
  200915. struct statfs buf;
  200916. if (doStatFS (f, buf))
  200917. {
  200918. const String type (buf.f_fstypename);
  200919. while (*types != 0)
  200920. if (type.equalsIgnoreCase (*types++))
  200921. return true;
  200922. }
  200923. return false;
  200924. }
  200925. bool File::isOnCDRomDrive() const
  200926. {
  200927. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  200928. return isFileOnDriveType (this, (const char**) cdTypes);
  200929. }
  200930. bool File::isOnHardDisk() const
  200931. {
  200932. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  200933. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  200934. }
  200935. bool File::isOnRemovableDrive() const
  200936. {
  200937. #if JUCE_IPHONE
  200938. return false; // xxx is this possible?
  200939. #else
  200940. const ScopedAutoReleasePool pool;
  200941. BOOL removable = false;
  200942. [[NSWorkspace sharedWorkspace]
  200943. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  200944. isRemovable: &removable
  200945. isWritable: nil
  200946. isUnmountable: nil
  200947. description: nil
  200948. type: nil];
  200949. return removable;
  200950. #endif
  200951. }
  200952. static bool juce_isHiddenFile (const String& path)
  200953. {
  200954. #if JUCE_IPHONE
  200955. return File (path).getFileName().startsWithChar ('.');
  200956. #else
  200957. FSRef ref;
  200958. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  200959. return false;
  200960. FSCatalogInfo info;
  200961. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  200962. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  200963. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200964. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  200965. #endif
  200966. }
  200967. bool File::isHidden() const
  200968. {
  200969. return juce_isHiddenFile (getFullPathName());
  200970. }
  200971. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  200972. const File File::getSpecialLocation (const SpecialLocationType type)
  200973. {
  200974. const ScopedAutoReleasePool pool;
  200975. String resultPath;
  200976. switch (type)
  200977. {
  200978. case userHomeDirectory:
  200979. resultPath = nsStringToJuce (NSHomeDirectory());
  200980. break;
  200981. case userDocumentsDirectory:
  200982. resultPath = "~/Documents";
  200983. break;
  200984. case userDesktopDirectory:
  200985. resultPath = "~/Desktop";
  200986. break;
  200987. case userApplicationDataDirectory:
  200988. resultPath = "~/Library";
  200989. break;
  200990. case commonApplicationDataDirectory:
  200991. resultPath = "/Library";
  200992. break;
  200993. case globalApplicationsDirectory:
  200994. resultPath = "/Applications";
  200995. break;
  200996. case userMusicDirectory:
  200997. resultPath = "~/Music";
  200998. break;
  200999. case userMoviesDirectory:
  201000. resultPath = "~/Movies";
  201001. break;
  201002. case tempDirectory:
  201003. {
  201004. File tmp ("~/Library/Caches/" + juce_getExecutableFile().getFileNameWithoutExtension());
  201005. tmp.createDirectory();
  201006. return tmp.getFullPathName();
  201007. }
  201008. case invokedExecutableFile:
  201009. if (juce_Argv0 != 0)
  201010. return File (String::fromUTF8 (juce_Argv0));
  201011. // deliberate fall-through...
  201012. case currentExecutableFile:
  201013. return juce_getExecutableFile();
  201014. case currentApplicationFile:
  201015. {
  201016. const File exe (juce_getExecutableFile());
  201017. const File parent (exe.getParentDirectory());
  201018. return parent.getFullPathName().endsWithIgnoreCase ("Contents/MacOS")
  201019. ? parent.getParentDirectory().getParentDirectory()
  201020. : exe;
  201021. }
  201022. default:
  201023. jassertfalse // unknown type?
  201024. break;
  201025. }
  201026. if (resultPath.isNotEmpty())
  201027. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201028. return File::nonexistent;
  201029. }
  201030. const String File::getVersion() const
  201031. {
  201032. const ScopedAutoReleasePool pool;
  201033. String result;
  201034. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201035. if (bundle != 0)
  201036. {
  201037. NSDictionary* info = [bundle infoDictionary];
  201038. if (info != 0)
  201039. {
  201040. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201041. if (name != nil)
  201042. result = nsStringToJuce (name);
  201043. }
  201044. }
  201045. return result;
  201046. }
  201047. const File File::getLinkedTarget() const
  201048. {
  201049. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201050. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201051. #else
  201052. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201053. #endif
  201054. if (dest != nil)
  201055. return File (nsStringToJuce (dest));
  201056. return *this;
  201057. }
  201058. bool File::moveToTrash() const
  201059. {
  201060. if (! exists())
  201061. return true;
  201062. #if JUCE_IPHONE
  201063. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201064. #else
  201065. const ScopedAutoReleasePool pool;
  201066. NSString* p = juceStringToNS (getFullPathName());
  201067. return [[NSWorkspace sharedWorkspace]
  201068. performFileOperation: NSWorkspaceRecycleOperation
  201069. source: [p stringByDeletingLastPathComponent]
  201070. destination: @""
  201071. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201072. tag: nil ];
  201073. #endif
  201074. }
  201075. struct FindFileStruct
  201076. {
  201077. NSDirectoryEnumerator* enumerator;
  201078. String parentDir, wildCard;
  201079. };
  201080. bool juce_findFileNext (void* handle, String& resultFile,
  201081. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201082. {
  201083. ScopedAutoReleasePool pool;
  201084. FindFileStruct* ff = (FindFileStruct*) handle;
  201085. NSString* file;
  201086. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201087. for (;;)
  201088. {
  201089. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201090. return false;
  201091. [ff->enumerator skipDescendents];
  201092. resultFile = nsStringToJuce (file);
  201093. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201094. continue;
  201095. const String path (ff->parentDir + resultFile);
  201096. if (isDir != 0 || fileSize != 0)
  201097. {
  201098. struct stat info;
  201099. const bool statOk = juce_stat (path, info);
  201100. if (isDir != 0)
  201101. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201102. if (isHidden != 0)
  201103. *isHidden = juce_isHiddenFile (path);
  201104. if (fileSize != 0)
  201105. *fileSize = statOk ? info.st_size : 0;
  201106. }
  201107. if (modTime != 0 || creationTime != 0)
  201108. {
  201109. int64 m, a, c;
  201110. juce_getFileTimes (path, m, a, c);
  201111. if (modTime != 0)
  201112. *modTime = m;
  201113. if (creationTime != 0)
  201114. *creationTime = c;
  201115. }
  201116. if (isReadOnly != 0)
  201117. *isReadOnly = ! juce_canWriteToFile (path);
  201118. return true;
  201119. }
  201120. }
  201121. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201122. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201123. Time* creationTime, bool* isReadOnly)
  201124. {
  201125. ScopedAutoReleasePool pool;
  201126. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201127. if (e != 0)
  201128. {
  201129. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201130. ff->enumerator = [e retain];
  201131. ff->parentDir = directory;
  201132. ff->wildCard = wildCard;
  201133. if (! ff->parentDir.endsWithChar (File::separator))
  201134. ff->parentDir += File::separator;
  201135. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201136. return ff.release();
  201137. [e release];
  201138. }
  201139. return 0;
  201140. }
  201141. void juce_findFileClose (void* handle)
  201142. {
  201143. ScopedAutoReleasePool pool;
  201144. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201145. [ff->enumerator release];
  201146. }
  201147. bool juce_launchExecutable (const String& pathAndArguments)
  201148. {
  201149. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201150. const int cpid = fork();
  201151. if (cpid == 0)
  201152. {
  201153. // Child process
  201154. if (execve (argv[0], (char**) argv, 0) < 0)
  201155. exit (0);
  201156. }
  201157. else
  201158. {
  201159. if (cpid < 0)
  201160. return false;
  201161. }
  201162. return true;
  201163. }
  201164. bool juce_launchFile (const String& fileName, const String& parameters)
  201165. {
  201166. #if JUCE_IPHONE
  201167. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201168. #else
  201169. const ScopedAutoReleasePool pool;
  201170. if (parameters.isEmpty())
  201171. {
  201172. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201173. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201174. }
  201175. bool ok = false;
  201176. FSRef ref;
  201177. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201178. {
  201179. if (PlatformUtilities::isBundle (fileName))
  201180. {
  201181. NSMutableArray* urls = [NSMutableArray array];
  201182. StringArray docs;
  201183. docs.addTokens (parameters, true);
  201184. for (int i = 0; i < docs.size(); ++i)
  201185. [urls addObject: juceStringToNS (docs[i])];
  201186. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201187. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201188. options: 0
  201189. additionalEventParamDescriptor: nil
  201190. launchIdentifiers: nil];
  201191. }
  201192. else
  201193. {
  201194. ok = juce_launchExecutable ("\"" + fileName + "\" " + parameters);
  201195. }
  201196. }
  201197. return ok;
  201198. #endif
  201199. }
  201200. void File::revealToUser() const
  201201. {
  201202. #if ! JUCE_IPHONE
  201203. if (exists())
  201204. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201205. else if (getParentDirectory().exists())
  201206. getParentDirectory().revealToUser();
  201207. #endif
  201208. }
  201209. #if ! JUCE_IPHONE
  201210. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201211. {
  201212. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201213. }
  201214. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201215. {
  201216. char path [2048];
  201217. zerostruct (path);
  201218. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201219. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201220. return String::empty;
  201221. }
  201222. #endif
  201223. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201224. {
  201225. const ScopedAutoReleasePool pool;
  201226. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201227. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201228. #else
  201229. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201230. #endif
  201231. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201232. return [fileDict fileHFSTypeCode];
  201233. }
  201234. bool PlatformUtilities::isBundle (const String& filename)
  201235. {
  201236. #if JUCE_IPHONE
  201237. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201238. #else
  201239. const ScopedAutoReleasePool pool;
  201240. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201241. #endif
  201242. }
  201243. #endif
  201244. /*** End of inlined file: juce_mac_Files.mm ***/
  201245. #if JUCE_IPHONE
  201246. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201247. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201248. // compiled on its own).
  201249. #if JUCE_INCLUDED_FILE
  201250. static JUCEApplication* juce_intialisingApp;
  201251. END_JUCE_NAMESPACE
  201252. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201253. {
  201254. }
  201255. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201256. - (void) applicationWillResignActive: (UIApplication*) application;
  201257. @end
  201258. @implementation JuceAppStartupDelegate
  201259. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201260. {
  201261. String dummy;
  201262. if (! juce_intialisingApp->initialiseApp (dummy))
  201263. exit (0);
  201264. }
  201265. - (void) applicationWillResignActive: (UIApplication*) application
  201266. {
  201267. JUCEApplication::shutdownAppAndClearUp();
  201268. }
  201269. @end
  201270. BEGIN_JUCE_NAMESPACE
  201271. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201272. {
  201273. juce_intialisingApp = app;
  201274. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201275. }
  201276. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201277. {
  201278. pool = [[NSAutoreleasePool alloc] init];
  201279. }
  201280. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201281. {
  201282. [((NSAutoreleasePool*) pool) release];
  201283. }
  201284. void PlatformUtilities::beep()
  201285. {
  201286. //xxx
  201287. //AudioServicesPlaySystemSound ();
  201288. }
  201289. void PlatformUtilities::addItemToDock (const File& file)
  201290. {
  201291. }
  201292. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201293. END_JUCE_NAMESPACE
  201294. @interface JuceAlertBoxDelegate : NSObject
  201295. {
  201296. @public
  201297. bool clickedOk;
  201298. }
  201299. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201300. @end
  201301. @implementation JuceAlertBoxDelegate
  201302. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201303. {
  201304. clickedOk = (buttonIndex == 0);
  201305. alertView.hidden = true;
  201306. }
  201307. @end
  201308. BEGIN_JUCE_NAMESPACE
  201309. // (This function is used directly by other bits of code)
  201310. bool juce_iPhoneShowModalAlert (const String& title,
  201311. const String& bodyText,
  201312. NSString* okButtonText,
  201313. NSString* cancelButtonText)
  201314. {
  201315. const ScopedAutoReleasePool pool;
  201316. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201317. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201318. message: juceStringToNS (bodyText)
  201319. delegate: callback
  201320. cancelButtonTitle: okButtonText
  201321. otherButtonTitles: cancelButtonText, nil];
  201322. [alert retain];
  201323. [alert show];
  201324. while (! alert.hidden && alert.superview != nil)
  201325. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201326. const bool result = callback->clickedOk;
  201327. [alert release];
  201328. [callback release];
  201329. return result;
  201330. }
  201331. bool AlertWindow::showNativeDialogBox (const String& title,
  201332. const String& bodyText,
  201333. bool isOkCancel)
  201334. {
  201335. return juce_iPhoneShowModalAlert (title, bodyText,
  201336. @"OK",
  201337. isOkCancel ? @"Cancel" : nil);
  201338. }
  201339. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201340. {
  201341. jassertfalse // no such thing on the iphone!
  201342. return false;
  201343. }
  201344. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201345. {
  201346. jassertfalse // no such thing on the iphone!
  201347. return false;
  201348. }
  201349. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201350. {
  201351. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201352. }
  201353. bool Desktop::isScreenSaverEnabled() throw()
  201354. {
  201355. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201356. }
  201357. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201358. {
  201359. const ScopedAutoReleasePool pool;
  201360. monitorCoords.clear();
  201361. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201362. : [[UIScreen mainScreen] bounds];
  201363. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201364. (int) r.origin.y,
  201365. (int) r.size.width,
  201366. (int) r.size.height));
  201367. }
  201368. #endif
  201369. #endif
  201370. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201371. #else
  201372. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201373. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201374. // compiled on its own).
  201375. #if JUCE_INCLUDED_FILE
  201376. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201377. {
  201378. pool = [[NSAutoreleasePool alloc] init];
  201379. }
  201380. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201381. {
  201382. [((NSAutoreleasePool*) pool) release];
  201383. }
  201384. void PlatformUtilities::beep()
  201385. {
  201386. NSBeep();
  201387. }
  201388. void PlatformUtilities::addItemToDock (const File& file)
  201389. {
  201390. // check that it's not already there...
  201391. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201392. .containsIgnoreCase (file.getFullPathName()))
  201393. {
  201394. 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>"
  201395. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201396. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201397. }
  201398. }
  201399. int PlatformUtilities::getOSXMinorVersionNumber()
  201400. {
  201401. SInt32 versionMinor = 0;
  201402. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201403. (void) err;
  201404. jassert (err == noErr);
  201405. return (int) versionMinor;
  201406. }
  201407. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201408. bool AlertWindow::showNativeDialogBox (const String& title,
  201409. const String& bodyText,
  201410. bool isOkCancel)
  201411. {
  201412. const ScopedAutoReleasePool pool;
  201413. return NSRunAlertPanel (juceStringToNS (title),
  201414. juceStringToNS (bodyText),
  201415. @"Ok",
  201416. isOkCancel ? @"Cancel" : nil,
  201417. nil) == NSAlertDefaultReturn;
  201418. }
  201419. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201420. {
  201421. if (files.size() == 0)
  201422. return false;
  201423. MouseInputSource* draggingSource = Desktop::getInstance().getDraggingMouseSource(0);
  201424. if (draggingSource == 0)
  201425. {
  201426. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201427. return false;
  201428. }
  201429. Component* sourceComp = draggingSource->getComponentUnderMouse();
  201430. if (sourceComp == 0)
  201431. {
  201432. jassertfalse // This method must be called in response to a component's mouseDown or mouseDrag event!
  201433. return false;
  201434. }
  201435. const ScopedAutoReleasePool pool;
  201436. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201437. if (view == 0)
  201438. return false;
  201439. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201440. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201441. owner: nil];
  201442. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201443. for (int i = 0; i < files.size(); ++i)
  201444. [filesArray addObject: juceStringToNS (files[i])];
  201445. [pboard setPropertyList: filesArray
  201446. forType: NSFilenamesPboardType];
  201447. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201448. fromView: nil];
  201449. dragPosition.x -= 16;
  201450. dragPosition.y -= 16;
  201451. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201452. at: dragPosition
  201453. offset: NSMakeSize (0, 0)
  201454. event: [[view window] currentEvent]
  201455. pasteboard: pboard
  201456. source: view
  201457. slideBack: YES];
  201458. return true;
  201459. }
  201460. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201461. {
  201462. jassertfalse // not implemented!
  201463. return false;
  201464. }
  201465. bool Desktop::canUseSemiTransparentWindows() throw()
  201466. {
  201467. return true;
  201468. }
  201469. const Point<int> Desktop::getMousePosition()
  201470. {
  201471. const ScopedAutoReleasePool pool;
  201472. const NSPoint p ([NSEvent mouseLocation]);
  201473. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201474. }
  201475. void Desktop::setMousePosition (const Point<int>& newPosition)
  201476. {
  201477. // this rubbish needs to be done around the warp call, to avoid causing a
  201478. // bizarre glitch..
  201479. CGAssociateMouseAndMouseCursorPosition (false);
  201480. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201481. CGAssociateMouseAndMouseCursorPosition (true);
  201482. }
  201483. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201484. class ScreenSaverDefeater : public Timer,
  201485. public DeletedAtShutdown
  201486. {
  201487. public:
  201488. ScreenSaverDefeater() throw()
  201489. {
  201490. startTimer (10000);
  201491. timerCallback();
  201492. }
  201493. ~ScreenSaverDefeater() {}
  201494. void timerCallback()
  201495. {
  201496. if (Process::isForegroundProcess())
  201497. UpdateSystemActivity (UsrActivity);
  201498. }
  201499. };
  201500. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201501. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201502. {
  201503. if (isEnabled)
  201504. {
  201505. deleteAndZero (screenSaverDefeater);
  201506. }
  201507. else if (screenSaverDefeater == 0)
  201508. {
  201509. screenSaverDefeater = new ScreenSaverDefeater();
  201510. }
  201511. }
  201512. bool Desktop::isScreenSaverEnabled() throw()
  201513. {
  201514. return screenSaverDefeater == 0;
  201515. }
  201516. #else
  201517. static IOPMAssertionID screenSaverDisablerID = 0;
  201518. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201519. {
  201520. if (isEnabled)
  201521. {
  201522. if (screenSaverDisablerID != 0)
  201523. {
  201524. IOPMAssertionRelease (screenSaverDisablerID);
  201525. screenSaverDisablerID = 0;
  201526. }
  201527. }
  201528. else
  201529. {
  201530. if (screenSaverDisablerID == 0)
  201531. {
  201532. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201533. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201534. CFSTR ("Juce"), &screenSaverDisablerID);
  201535. #else
  201536. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201537. &screenSaverDisablerID);
  201538. #endif
  201539. }
  201540. }
  201541. }
  201542. bool Desktop::isScreenSaverEnabled() throw()
  201543. {
  201544. return screenSaverDisablerID == 0;
  201545. }
  201546. #endif
  201547. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201548. {
  201549. const ScopedAutoReleasePool pool;
  201550. monitorCoords.clear();
  201551. NSArray* screens = [NSScreen screens];
  201552. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201553. for (unsigned int i = 0; i < [screens count]; ++i)
  201554. {
  201555. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201556. NSRect r = clipToWorkArea ? [s visibleFrame]
  201557. : [s frame];
  201558. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201559. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201560. (int) r.size.width,
  201561. (int) r.size.height));
  201562. }
  201563. jassert (monitorCoords.size() > 0);
  201564. }
  201565. #endif
  201566. #endif
  201567. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201568. #endif
  201569. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201570. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201571. // compiled on its own).
  201572. #if JUCE_INCLUDED_FILE
  201573. void Logger::outputDebugString (const String& text) throw()
  201574. {
  201575. std::cerr << text << std::endl;
  201576. }
  201577. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201578. {
  201579. static char testResult = 0;
  201580. if (testResult == 0)
  201581. {
  201582. struct kinfo_proc info;
  201583. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201584. size_t sz = sizeof (info);
  201585. sysctl (m, 4, &info, &sz, 0, 0);
  201586. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201587. }
  201588. return testResult > 0;
  201589. }
  201590. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201591. {
  201592. return juce_isRunningUnderDebugger();
  201593. }
  201594. #endif
  201595. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201596. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201597. #if JUCE_IPHONE
  201598. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201599. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201600. // compiled on its own).
  201601. #if JUCE_INCLUDED_FILE
  201602. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201603. #define SUPPORT_10_4_FONTS 1
  201604. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201605. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201606. #define SUPPORT_ONLY_10_4_FONTS 1
  201607. #endif
  201608. END_JUCE_NAMESPACE
  201609. @interface NSFont (PrivateHack)
  201610. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201611. @end
  201612. BEGIN_JUCE_NAMESPACE
  201613. #endif
  201614. class MacTypeface : public Typeface
  201615. {
  201616. public:
  201617. MacTypeface (const Font& font)
  201618. : Typeface (font.getTypefaceName())
  201619. {
  201620. const ScopedAutoReleasePool pool;
  201621. renderingTransform = CGAffineTransformIdentity;
  201622. bool needsItalicTransform = false;
  201623. #if JUCE_IPHONE
  201624. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201625. if (font.isItalic() || font.isBold())
  201626. {
  201627. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201628. for (NSString* i in familyFonts)
  201629. {
  201630. const String fn (nsStringToJuce (i));
  201631. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  201632. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  201633. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  201634. || afterDash.containsIgnoreCase ("italic")
  201635. || fn.endsWithIgnoreCase ("oblique")
  201636. || fn.endsWithIgnoreCase ("italic");
  201637. if (probablyBold == font.isBold()
  201638. && probablyItalic == font.isItalic())
  201639. {
  201640. fontName = i;
  201641. needsItalicTransform = false;
  201642. break;
  201643. }
  201644. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201645. {
  201646. fontName = i;
  201647. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201648. }
  201649. }
  201650. if (needsItalicTransform)
  201651. renderingTransform.c = 0.15f;
  201652. }
  201653. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201654. const int ascender = abs (CGFontGetAscent (fontRef));
  201655. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201656. ascent = ascender / totalHeight;
  201657. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201658. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201659. #else
  201660. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201661. if (font.isItalic())
  201662. {
  201663. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201664. toHaveTrait: NSItalicFontMask];
  201665. if (newFont == nsFont)
  201666. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201667. nsFont = newFont;
  201668. }
  201669. if (font.isBold())
  201670. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201671. [nsFont retain];
  201672. ascent = fabsf ((float) [nsFont ascender]);
  201673. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201674. ascent /= totalSize;
  201675. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201676. if (needsItalicTransform)
  201677. {
  201678. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  201679. renderingTransform.c = 0.15f;
  201680. }
  201681. #if SUPPORT_ONLY_10_4_FONTS
  201682. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201683. if (atsFont == 0)
  201684. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201685. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  201686. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201687. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201688. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201689. #else
  201690. #if SUPPORT_10_4_FONTS
  201691. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201692. {
  201693. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201694. if (atsFont == 0)
  201695. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  201696. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  201697. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  201698. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201699. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  201700. }
  201701. else
  201702. #endif
  201703. {
  201704. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  201705. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  201706. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201707. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  201708. }
  201709. #endif
  201710. #endif
  201711. }
  201712. ~MacTypeface()
  201713. {
  201714. #if ! JUCE_IPHONE
  201715. [nsFont release];
  201716. #endif
  201717. if (fontRef != 0)
  201718. CGFontRelease (fontRef);
  201719. }
  201720. float getAscent() const
  201721. {
  201722. return ascent;
  201723. }
  201724. float getDescent() const
  201725. {
  201726. return 1.0f - ascent;
  201727. }
  201728. float getStringWidth (const String& text)
  201729. {
  201730. if (fontRef == 0 || text.isEmpty())
  201731. return 0;
  201732. const int length = text.length();
  201733. HeapBlock <CGGlyph> glyphs;
  201734. createGlyphsForString (text, length, glyphs);
  201735. float x = 0;
  201736. #if SUPPORT_ONLY_10_4_FONTS
  201737. HeapBlock <NSSize> advances (length);
  201738. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201739. for (int i = 0; i < length; ++i)
  201740. x += advances[i].width;
  201741. #else
  201742. #if SUPPORT_10_4_FONTS
  201743. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201744. {
  201745. HeapBlock <NSSize> advances (length);
  201746. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  201747. for (int i = 0; i < length; ++i)
  201748. x += advances[i].width;
  201749. }
  201750. else
  201751. #endif
  201752. {
  201753. HeapBlock <int> advances (length);
  201754. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201755. for (int i = 0; i < length; ++i)
  201756. x += advances[i];
  201757. }
  201758. #endif
  201759. return x * unitsToHeightScaleFactor;
  201760. }
  201761. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  201762. {
  201763. xOffsets.add (0);
  201764. if (fontRef == 0 || text.isEmpty())
  201765. return;
  201766. const int length = text.length();
  201767. HeapBlock <CGGlyph> glyphs;
  201768. createGlyphsForString (text, length, glyphs);
  201769. #if SUPPORT_ONLY_10_4_FONTS
  201770. HeapBlock <NSSize> advances (length);
  201771. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  201772. int x = 0;
  201773. for (int i = 0; i < length; ++i)
  201774. {
  201775. x += advances[i].width;
  201776. xOffsets.add (x * unitsToHeightScaleFactor);
  201777. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  201778. }
  201779. #else
  201780. #if SUPPORT_10_4_FONTS
  201781. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201782. {
  201783. HeapBlock <NSSize> advances (length);
  201784. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201785. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  201786. float x = 0;
  201787. for (int i = 0; i < length; ++i)
  201788. {
  201789. x += advances[i].width;
  201790. xOffsets.add (x * unitsToHeightScaleFactor);
  201791. resultGlyphs.add (nsGlyphs[i]);
  201792. }
  201793. }
  201794. else
  201795. #endif
  201796. {
  201797. HeapBlock <int> advances (length);
  201798. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  201799. {
  201800. int x = 0;
  201801. for (int i = 0; i < length; ++i)
  201802. {
  201803. x += advances [i];
  201804. xOffsets.add (x * unitsToHeightScaleFactor);
  201805. resultGlyphs.add (glyphs[i]);
  201806. }
  201807. }
  201808. }
  201809. #endif
  201810. }
  201811. bool getOutlineForGlyph (int glyphNumber, Path& path)
  201812. {
  201813. #if JUCE_IPHONE
  201814. return false;
  201815. #else
  201816. if (nsFont == 0)
  201817. return false;
  201818. // we might need to apply a transform to the path, so it mustn't have anything else in it
  201819. jassert (path.isEmpty());
  201820. const ScopedAutoReleasePool pool;
  201821. NSBezierPath* bez = [NSBezierPath bezierPath];
  201822. [bez moveToPoint: NSMakePoint (0, 0)];
  201823. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  201824. inFont: nsFont];
  201825. for (int i = 0; i < [bez elementCount]; ++i)
  201826. {
  201827. NSPoint p[3];
  201828. switch ([bez elementAtIndex: i associatedPoints: p])
  201829. {
  201830. case NSMoveToBezierPathElement:
  201831. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  201832. break;
  201833. case NSLineToBezierPathElement:
  201834. path.lineTo ((float) p[0].x, (float) -p[0].y);
  201835. break;
  201836. case NSCurveToBezierPathElement:
  201837. 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);
  201838. break;
  201839. case NSClosePathBezierPathElement:
  201840. path.closeSubPath();
  201841. break;
  201842. default:
  201843. jassertfalse
  201844. break;
  201845. }
  201846. }
  201847. path.applyTransform (pathTransform);
  201848. return true;
  201849. #endif
  201850. }
  201851. juce_UseDebuggingNewOperator
  201852. CGFontRef fontRef;
  201853. float fontHeightToCGSizeFactor;
  201854. CGAffineTransform renderingTransform;
  201855. private:
  201856. float ascent, unitsToHeightScaleFactor;
  201857. #if JUCE_IPHONE
  201858. #else
  201859. NSFont* nsFont;
  201860. AffineTransform pathTransform;
  201861. #endif
  201862. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  201863. {
  201864. #if SUPPORT_10_4_FONTS
  201865. #if ! SUPPORT_ONLY_10_4_FONTS
  201866. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  201867. #endif
  201868. {
  201869. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  201870. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  201871. for (int i = 0; i < length; ++i)
  201872. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  201873. return;
  201874. }
  201875. #endif
  201876. #if ! SUPPORT_ONLY_10_4_FONTS
  201877. if (charToGlyphMapper == 0)
  201878. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  201879. glyphs.malloc (length);
  201880. for (int i = 0; i < length; ++i)
  201881. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  201882. #endif
  201883. }
  201884. #if ! SUPPORT_ONLY_10_4_FONTS
  201885. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  201886. class CharToGlyphMapper
  201887. {
  201888. public:
  201889. CharToGlyphMapper (CGFontRef fontRef)
  201890. : segCount (0), endCode (0), startCode (0), idDelta (0),
  201891. idRangeOffset (0), glyphIndexes (0)
  201892. {
  201893. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  201894. if (cmapTable != 0)
  201895. {
  201896. const int numSubtables = getValue16 (cmapTable, 2);
  201897. for (int i = 0; i < numSubtables; ++i)
  201898. {
  201899. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  201900. {
  201901. const int offset = getValue32 (cmapTable, i * 8 + 8);
  201902. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  201903. {
  201904. const int length = getValue16 (cmapTable, offset + 2);
  201905. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  201906. segCount = segCountX2 / 2;
  201907. const int endCodeOffset = offset + 14;
  201908. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  201909. const int idDeltaOffset = startCodeOffset + segCountX2;
  201910. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  201911. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  201912. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  201913. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  201914. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  201915. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  201916. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  201917. }
  201918. break;
  201919. }
  201920. }
  201921. CFRelease (cmapTable);
  201922. }
  201923. }
  201924. ~CharToGlyphMapper()
  201925. {
  201926. if (endCode != 0)
  201927. {
  201928. CFRelease (endCode);
  201929. CFRelease (startCode);
  201930. CFRelease (idDelta);
  201931. CFRelease (idRangeOffset);
  201932. CFRelease (glyphIndexes);
  201933. }
  201934. }
  201935. int getGlyphForCharacter (const juce_wchar c) const
  201936. {
  201937. for (int i = 0; i < segCount; ++i)
  201938. {
  201939. if (getValue16 (endCode, i * 2) >= c)
  201940. {
  201941. const int start = getValue16 (startCode, i * 2);
  201942. if (start > c)
  201943. break;
  201944. const int delta = getValue16 (idDelta, i * 2);
  201945. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  201946. if (rangeOffset == 0)
  201947. return delta + c;
  201948. else
  201949. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  201950. }
  201951. }
  201952. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  201953. return jmax (-1, c - 29);
  201954. }
  201955. private:
  201956. int segCount;
  201957. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  201958. static uint16 getValue16 (CFDataRef data, const int index)
  201959. {
  201960. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  201961. }
  201962. static uint32 getValue32 (CFDataRef data, const int index)
  201963. {
  201964. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  201965. }
  201966. };
  201967. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  201968. #endif
  201969. MacTypeface (const MacTypeface&);
  201970. MacTypeface& operator= (const MacTypeface&);
  201971. };
  201972. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  201973. {
  201974. return new MacTypeface (font);
  201975. }
  201976. const StringArray Font::findAllTypefaceNames()
  201977. {
  201978. StringArray names;
  201979. const ScopedAutoReleasePool pool;
  201980. #if JUCE_IPHONE
  201981. NSArray* fonts = [UIFont familyNames];
  201982. #else
  201983. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  201984. #endif
  201985. for (unsigned int i = 0; i < [fonts count]; ++i)
  201986. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  201987. names.sort (true);
  201988. return names;
  201989. }
  201990. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  201991. {
  201992. #if JUCE_IPHONE
  201993. defaultSans = "Helvetica";
  201994. defaultSerif = "Times New Roman";
  201995. defaultFixed = "Courier New";
  201996. #else
  201997. defaultSans = "Lucida Grande";
  201998. defaultSerif = "Times New Roman";
  201999. defaultFixed = "Monaco";
  202000. #endif
  202001. }
  202002. #endif
  202003. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202004. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202005. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202006. // compiled on its own).
  202007. #if JUCE_INCLUDED_FILE
  202008. class CoreGraphicsImage : public Image
  202009. {
  202010. public:
  202011. CoreGraphicsImage (const PixelFormat format_,
  202012. const int imageWidth_,
  202013. const int imageHeight_,
  202014. const bool clearImage)
  202015. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202016. {
  202017. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  202018. : CGColorSpaceCreateDeviceRGB();
  202019. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202020. colourSpace, getCGImageFlags (*this));
  202021. CGColorSpaceRelease (colourSpace);
  202022. }
  202023. ~CoreGraphicsImage()
  202024. {
  202025. CGContextRelease (context);
  202026. }
  202027. LowLevelGraphicsContext* createLowLevelContext();
  202028. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202029. {
  202030. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202031. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202032. {
  202033. return CGBitmapContextCreateImage (nativeImage->context);
  202034. }
  202035. else
  202036. {
  202037. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202038. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202039. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202040. 8, srcData.pixelStride * 8, srcData.lineStride,
  202041. colourSpace, getCGImageFlags (juceImage), provider,
  202042. 0, true, kCGRenderingIntentDefault);
  202043. CGDataProviderRelease (provider);
  202044. return imageRef;
  202045. }
  202046. }
  202047. #if JUCE_MAC
  202048. static NSImage* createNSImage (const Image& image)
  202049. {
  202050. const ScopedAutoReleasePool pool;
  202051. NSImage* im = [[NSImage alloc] init];
  202052. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202053. [im lockFocus];
  202054. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202055. CGImageRef imageRef = createImage (image, false, colourSpace);
  202056. CGColorSpaceRelease (colourSpace);
  202057. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202058. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202059. CGImageRelease (imageRef);
  202060. [im unlockFocus];
  202061. return im;
  202062. }
  202063. #endif
  202064. CGContextRef context;
  202065. private:
  202066. static CGBitmapInfo getCGImageFlags (const Image& image)
  202067. {
  202068. #if JUCE_BIG_ENDIAN
  202069. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202070. #else
  202071. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202072. #endif
  202073. }
  202074. };
  202075. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202076. {
  202077. #if USE_COREGRAPHICS_RENDERING
  202078. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202079. #else
  202080. return new Image (format, imageWidth, imageHeight, clearImage);
  202081. #endif
  202082. }
  202083. class CoreGraphicsContext : public LowLevelGraphicsContext
  202084. {
  202085. public:
  202086. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202087. : context (context_),
  202088. flipHeight (flipHeight_),
  202089. state (new SavedState()),
  202090. numGradientLookupEntries (0)
  202091. {
  202092. CGContextRetain (context);
  202093. CGContextSaveGState(context);
  202094. CGContextSetShouldSmoothFonts (context, true);
  202095. CGContextSetShouldAntialias (context, true);
  202096. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202097. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202098. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202099. gradientCallbacks.version = 0;
  202100. gradientCallbacks.evaluate = gradientCallback;
  202101. gradientCallbacks.releaseInfo = 0;
  202102. setFont (Font());
  202103. }
  202104. ~CoreGraphicsContext()
  202105. {
  202106. CGContextRestoreGState (context);
  202107. CGContextRelease (context);
  202108. CGColorSpaceRelease (rgbColourSpace);
  202109. CGColorSpaceRelease (greyColourSpace);
  202110. }
  202111. bool isVectorDevice() const { return false; }
  202112. void setOrigin (int x, int y)
  202113. {
  202114. CGContextTranslateCTM (context, x, -y);
  202115. }
  202116. bool clipToRectangle (const Rectangle<int>& r)
  202117. {
  202118. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202119. return ! isClipEmpty();
  202120. }
  202121. bool clipToRectangleList (const RectangleList& clipRegion)
  202122. {
  202123. if (clipRegion.isEmpty())
  202124. {
  202125. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202126. return false;
  202127. }
  202128. else
  202129. {
  202130. const int numRects = clipRegion.getNumRectangles();
  202131. HeapBlock <CGRect> rects (numRects);
  202132. for (int i = 0; i < numRects; ++i)
  202133. {
  202134. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202135. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202136. }
  202137. CGContextClipToRects (context, rects, numRects);
  202138. return ! isClipEmpty();
  202139. }
  202140. }
  202141. void excludeClipRectangle (const Rectangle<int>& r)
  202142. {
  202143. RectangleList remaining (getClipBounds());
  202144. remaining.subtract (r);
  202145. clipToRectangleList (remaining);
  202146. }
  202147. void clipToPath (const Path& path, const AffineTransform& transform)
  202148. {
  202149. createPath (path, transform);
  202150. CGContextClip (context);
  202151. }
  202152. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202153. {
  202154. if (! transform.isSingularity())
  202155. {
  202156. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202157. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202158. flip();
  202159. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202160. applyTransform (t);
  202161. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202162. CGContextClipToMask (context, r, image);
  202163. applyTransform (t.inverted());
  202164. flip();
  202165. CGImageRelease (image);
  202166. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202167. }
  202168. }
  202169. bool clipRegionIntersects (const Rectangle<int>& r)
  202170. {
  202171. return getClipBounds().intersects (r);
  202172. }
  202173. const Rectangle<int> getClipBounds() const
  202174. {
  202175. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202176. return Rectangle<int> (roundToInt (bounds.origin.x),
  202177. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202178. roundToInt (bounds.size.width),
  202179. roundToInt (bounds.size.height));
  202180. }
  202181. bool isClipEmpty() const
  202182. {
  202183. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202184. }
  202185. void saveState()
  202186. {
  202187. CGContextSaveGState (context);
  202188. stateStack.add (new SavedState (*state));
  202189. }
  202190. void restoreState()
  202191. {
  202192. CGContextRestoreGState (context);
  202193. SavedState* const top = stateStack.getLast();
  202194. if (top != 0)
  202195. {
  202196. state = top;
  202197. stateStack.removeLast (1, false);
  202198. }
  202199. else
  202200. {
  202201. jassertfalse // trying to pop with an empty stack!
  202202. }
  202203. }
  202204. void setFill (const FillType& fillType)
  202205. {
  202206. state->fillType = fillType;
  202207. if (fillType.isColour())
  202208. {
  202209. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202210. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202211. CGContextSetAlpha (context, 1.0f);
  202212. }
  202213. }
  202214. void setOpacity (float newOpacity)
  202215. {
  202216. state->fillType.setOpacity (newOpacity);
  202217. setFill (state->fillType);
  202218. }
  202219. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202220. {
  202221. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202222. ? kCGInterpolationLow
  202223. : kCGInterpolationHigh);
  202224. }
  202225. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202226. {
  202227. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202228. if (replaceExistingContents)
  202229. {
  202230. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202231. CGContextClearRect (context, cgRect);
  202232. #else
  202233. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202234. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202235. CGContextClearRect (context, cgRect);
  202236. else
  202237. #endif
  202238. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202239. #endif
  202240. fillRect (r, false);
  202241. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202242. }
  202243. else
  202244. {
  202245. if (state->fillType.isColour())
  202246. {
  202247. CGContextFillRect (context, cgRect);
  202248. }
  202249. else if (state->fillType.isGradient())
  202250. {
  202251. CGContextSaveGState (context);
  202252. CGContextClipToRect (context, cgRect);
  202253. drawGradient();
  202254. CGContextRestoreGState (context);
  202255. }
  202256. else
  202257. {
  202258. CGContextSaveGState (context);
  202259. CGContextClipToRect (context, cgRect);
  202260. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202261. CGContextRestoreGState (context);
  202262. }
  202263. }
  202264. }
  202265. void fillPath (const Path& path, const AffineTransform& transform)
  202266. {
  202267. CGContextSaveGState (context);
  202268. if (state->fillType.isColour())
  202269. {
  202270. flip();
  202271. applyTransform (transform);
  202272. createPath (path);
  202273. if (path.isUsingNonZeroWinding())
  202274. CGContextFillPath (context);
  202275. else
  202276. CGContextEOFillPath (context);
  202277. }
  202278. else
  202279. {
  202280. createPath (path, transform);
  202281. if (path.isUsingNonZeroWinding())
  202282. CGContextClip (context);
  202283. else
  202284. CGContextEOClip (context);
  202285. if (state->fillType.isGradient())
  202286. drawGradient();
  202287. else
  202288. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202289. }
  202290. CGContextRestoreGState (context);
  202291. }
  202292. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202293. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202294. {
  202295. jassert (sourceImage.getBounds().contains (srcClip));
  202296. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202297. CGImageRef image = fullImage;
  202298. if (srcClip != sourceImage.getBounds())
  202299. {
  202300. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202301. srcClip.getWidth(), srcClip.getHeight()));
  202302. CGImageRelease (fullImage);
  202303. }
  202304. CGContextSaveGState (context);
  202305. CGContextSetAlpha (context, state->fillType.getOpacity());
  202306. flip();
  202307. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202308. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202309. if (fillEntireClipAsTiles)
  202310. {
  202311. #if JUCE_IPHONE
  202312. CGContextDrawTiledImage (context, imageRect, image);
  202313. #else
  202314. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202315. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202316. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202317. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202318. CGContextDrawTiledImage (context, imageRect, image);
  202319. else
  202320. #endif
  202321. {
  202322. // Fallback to manually doing a tiled fill on 10.4
  202323. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202324. const int iw = srcClip.getWidth();
  202325. const int ih = srcClip.getHeight();
  202326. int x = 0, y = 0;
  202327. while (x > clip.origin.x) x -= iw;
  202328. while (y > clip.origin.y) y -= ih;
  202329. const int right = (int) (clip.origin.x + clip.size.width);
  202330. const int bottom = (int) (clip.origin.y + clip.size.height);
  202331. while (y < bottom)
  202332. {
  202333. for (int x2 = x; x2 < right; x2 += iw)
  202334. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202335. y += ih;
  202336. }
  202337. }
  202338. #endif
  202339. }
  202340. else
  202341. {
  202342. CGContextDrawImage (context, imageRect, image);
  202343. }
  202344. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202345. CGContextRestoreGState (context);
  202346. }
  202347. void drawLine (double x1, double y1, double x2, double y2)
  202348. {
  202349. CGContextSetLineCap (context, kCGLineCapSquare);
  202350. CGContextSetLineWidth (context, 1.0f);
  202351. CGContextSetRGBStrokeColor (context,
  202352. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202353. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202354. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  202355. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  202356. CGContextStrokeLineSegments (context, line, 1);
  202357. }
  202358. void drawVerticalLine (const int x, double top, double bottom)
  202359. {
  202360. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202361. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202362. #else
  202363. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202364. // the x co-ord slightly to trick it..
  202365. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202366. #endif
  202367. }
  202368. void drawHorizontalLine (const int y, double left, double right)
  202369. {
  202370. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202371. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202372. #else
  202373. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202374. // the x co-ord slightly to trick it..
  202375. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202376. #endif
  202377. }
  202378. void setFont (const Font& newFont)
  202379. {
  202380. if (state->font != newFont)
  202381. {
  202382. state->fontRef = 0;
  202383. state->font = newFont;
  202384. MacTypeface* mf = dynamic_cast <MacTypeface*> (state->font.getTypeface());
  202385. if (mf != 0)
  202386. {
  202387. state->fontRef = mf->fontRef;
  202388. CGContextSetFont (context, state->fontRef);
  202389. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202390. state->fontTransform = mf->renderingTransform;
  202391. state->fontTransform.a *= state->font.getHorizontalScale();
  202392. CGContextSetTextMatrix (context, state->fontTransform);
  202393. }
  202394. }
  202395. }
  202396. const Font getFont()
  202397. {
  202398. return state->font;
  202399. }
  202400. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202401. {
  202402. if (state->fontRef != 0 && state->fillType.isColour())
  202403. {
  202404. if (transform.isOnlyTranslation())
  202405. {
  202406. CGGlyph g = glyphNumber;
  202407. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202408. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202409. }
  202410. else
  202411. {
  202412. CGContextSaveGState (context);
  202413. flip();
  202414. applyTransform (transform);
  202415. CGAffineTransform t = state->fontTransform;
  202416. t.d = -t.d;
  202417. CGContextSetTextMatrix (context, t);
  202418. CGGlyph g = glyphNumber;
  202419. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202420. CGContextSetTextMatrix (context, state->fontTransform);
  202421. CGContextRestoreGState (context);
  202422. }
  202423. }
  202424. else
  202425. {
  202426. Path p;
  202427. Font& f = state->font;
  202428. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202429. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202430. .followedBy (transform));
  202431. }
  202432. }
  202433. private:
  202434. CGContextRef context;
  202435. const CGFloat flipHeight;
  202436. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202437. CGFunctionCallbacks gradientCallbacks;
  202438. struct SavedState
  202439. {
  202440. SavedState()
  202441. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202442. {
  202443. }
  202444. SavedState (const SavedState& other)
  202445. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202446. fontTransform (other.fontTransform)
  202447. {
  202448. }
  202449. ~SavedState()
  202450. {
  202451. }
  202452. FillType fillType;
  202453. Font font;
  202454. CGFontRef fontRef;
  202455. CGAffineTransform fontTransform;
  202456. };
  202457. ScopedPointer <SavedState> state;
  202458. OwnedArray <SavedState> stateStack;
  202459. HeapBlock <PixelARGB> gradientLookupTable;
  202460. int numGradientLookupEntries;
  202461. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202462. {
  202463. const CoreGraphicsContext* const g = static_cast <const CoreGraphicsContext*> (info);
  202464. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202465. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202466. colour.unpremultiply();
  202467. outData[0] = colour.getRed() / 255.0f;
  202468. outData[1] = colour.getGreen() / 255.0f;
  202469. outData[2] = colour.getBlue() / 255.0f;
  202470. outData[3] = colour.getAlpha() / 255.0f;
  202471. }
  202472. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202473. {
  202474. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202475. --numGradientLookupEntries;
  202476. CGShadingRef result = 0;
  202477. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  202478. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202479. if (gradient.isRadial)
  202480. {
  202481. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202482. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202483. function, true, true);
  202484. }
  202485. else
  202486. {
  202487. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202488. CGPointMake (gradient.x2, gradient.y2),
  202489. function, true, true);
  202490. }
  202491. CGFunctionRelease (function);
  202492. return result;
  202493. }
  202494. void drawGradient()
  202495. {
  202496. flip();
  202497. applyTransform (state->fillType.transform);
  202498. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202499. // you draw a gradient with high quality interp enabled).
  202500. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202501. CGContextSetAlpha (context, state->fillType.getOpacity());
  202502. CGContextDrawShading (context, shading);
  202503. CGShadingRelease (shading);
  202504. }
  202505. void createPath (const Path& path) const
  202506. {
  202507. CGContextBeginPath (context);
  202508. Path::Iterator i (path);
  202509. while (i.next())
  202510. {
  202511. switch (i.elementType)
  202512. {
  202513. case Path::Iterator::startNewSubPath:
  202514. CGContextMoveToPoint (context, i.x1, i.y1);
  202515. break;
  202516. case Path::Iterator::lineTo:
  202517. CGContextAddLineToPoint (context, i.x1, i.y1);
  202518. break;
  202519. case Path::Iterator::quadraticTo:
  202520. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202521. break;
  202522. case Path::Iterator::cubicTo:
  202523. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202524. break;
  202525. case Path::Iterator::closePath:
  202526. CGContextClosePath (context); break;
  202527. default:
  202528. jassertfalse
  202529. break;
  202530. }
  202531. }
  202532. }
  202533. void createPath (const Path& path, const AffineTransform& transform) const
  202534. {
  202535. CGContextBeginPath (context);
  202536. Path::Iterator i (path);
  202537. while (i.next())
  202538. {
  202539. switch (i.elementType)
  202540. {
  202541. case Path::Iterator::startNewSubPath:
  202542. transform.transformPoint (i.x1, i.y1);
  202543. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202544. break;
  202545. case Path::Iterator::lineTo:
  202546. transform.transformPoint (i.x1, i.y1);
  202547. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202548. break;
  202549. case Path::Iterator::quadraticTo:
  202550. transform.transformPoint (i.x1, i.y1);
  202551. transform.transformPoint (i.x2, i.y2);
  202552. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202553. break;
  202554. case Path::Iterator::cubicTo:
  202555. transform.transformPoint (i.x1, i.y1);
  202556. transform.transformPoint (i.x2, i.y2);
  202557. transform.transformPoint (i.x3, i.y3);
  202558. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202559. break;
  202560. case Path::Iterator::closePath:
  202561. CGContextClosePath (context); break;
  202562. default:
  202563. jassertfalse
  202564. break;
  202565. }
  202566. }
  202567. }
  202568. static Image* createAlphaChannelImage (const Image& im)
  202569. {
  202570. if (im.getFormat() == Image::SingleChannel)
  202571. return const_cast <Image*> (&im);
  202572. return im.createCopyOfAlphaChannel();
  202573. }
  202574. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202575. {
  202576. if (im.getFormat() != Image::SingleChannel)
  202577. delete alphaIm;
  202578. }
  202579. void flip() const
  202580. {
  202581. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202582. }
  202583. void applyTransform (const AffineTransform& transform) const
  202584. {
  202585. CGAffineTransform t;
  202586. t.a = transform.mat00;
  202587. t.b = transform.mat10;
  202588. t.c = transform.mat01;
  202589. t.d = transform.mat11;
  202590. t.tx = transform.mat02;
  202591. t.ty = transform.mat12;
  202592. CGContextConcatCTM (context, t);
  202593. }
  202594. CoreGraphicsContext (const CoreGraphicsContext&);
  202595. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  202596. };
  202597. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202598. {
  202599. return new CoreGraphicsContext (context, imageHeight);
  202600. }
  202601. #endif
  202602. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202603. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202604. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202605. // compiled on its own).
  202606. #if JUCE_INCLUDED_FILE
  202607. class UIViewComponentPeer;
  202608. END_JUCE_NAMESPACE
  202609. #define JuceUIView MakeObjCClassName(JuceUIView)
  202610. @interface JuceUIView : UIView <UITextFieldDelegate>
  202611. {
  202612. @public
  202613. UIViewComponentPeer* owner;
  202614. UITextField *hiddenTextField;
  202615. }
  202616. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202617. - (void) dealloc;
  202618. - (void) drawRect: (CGRect) r;
  202619. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202620. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202621. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202622. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202623. - (BOOL) becomeFirstResponder;
  202624. - (BOOL) resignFirstResponder;
  202625. - (BOOL) canBecomeFirstResponder;
  202626. - (void) asyncRepaint: (id) rect;
  202627. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) string;
  202628. - (BOOL) textFieldShouldClear: (UITextField*) textField;
  202629. - (BOOL) textFieldShouldReturn: (UITextField*) textField;
  202630. @end
  202631. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202632. @interface JuceUIWindow : UIWindow
  202633. {
  202634. @private
  202635. UIViewComponentPeer* owner;
  202636. bool isZooming;
  202637. }
  202638. - (void) setOwner: (UIViewComponentPeer*) owner;
  202639. - (void) becomeKeyWindow;
  202640. @end
  202641. BEGIN_JUCE_NAMESPACE
  202642. class UIViewComponentPeer : public ComponentPeer,
  202643. public FocusChangeListener
  202644. {
  202645. public:
  202646. UIViewComponentPeer (Component* const component,
  202647. const int windowStyleFlags,
  202648. UIView* viewToAttachTo);
  202649. ~UIViewComponentPeer();
  202650. void* getNativeHandle() const;
  202651. void setVisible (bool shouldBeVisible);
  202652. void setTitle (const String& title);
  202653. void setPosition (int x, int y);
  202654. void setSize (int w, int h);
  202655. void setBounds (int x, int y, int w, int h, bool isNowFullScreen);
  202656. const Rectangle<int> getBounds() const;
  202657. const Rectangle<int> getBounds (const bool global) const;
  202658. const Point<int> getScreenPosition() const;
  202659. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202660. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202661. void setMinimised (bool shouldBeMinimised);
  202662. bool isMinimised() const;
  202663. void setFullScreen (bool shouldBeFullScreen);
  202664. bool isFullScreen() const;
  202665. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  202666. const BorderSize getFrameSize() const;
  202667. bool setAlwaysOnTop (bool alwaysOnTop);
  202668. void toFront (bool makeActiveWindow);
  202669. void toBehind (ComponentPeer* other);
  202670. void setIcon (const Image& newIcon);
  202671. virtual void drawRect (CGRect r);
  202672. virtual bool canBecomeKeyWindow();
  202673. virtual bool windowShouldClose();
  202674. virtual void redirectMovedOrResized();
  202675. virtual CGRect constrainRect (CGRect r);
  202676. virtual void viewFocusGain();
  202677. virtual void viewFocusLoss();
  202678. bool isFocused() const;
  202679. void grabFocus();
  202680. void textInputRequired (const Point<int>& position);
  202681. virtual BOOL textFieldReplaceCharacters (const Range<int>& range, const String& text);
  202682. virtual BOOL textFieldShouldClear();
  202683. virtual BOOL textFieldShouldReturn();
  202684. void updateHiddenTextContent (TextInputTarget* target);
  202685. void globalFocusChanged (Component*);
  202686. void handleTouches (UIEvent* e, bool isDown, bool isUp, bool isCancel);
  202687. void repaint (int x, int y, int w, int h);
  202688. void performAnyPendingRepaintsNow();
  202689. juce_UseDebuggingNewOperator
  202690. UIWindow* window;
  202691. JuceUIView* view;
  202692. bool isSharedWindow, fullScreen, insideDrawRect;
  202693. static ModifierKeys currentModifiers;
  202694. static int64 getMouseTime (UIEvent* e)
  202695. {
  202696. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  202697. + (int64) ([e timestamp] * 1000.0);
  202698. }
  202699. Array <UITouch*> currentTouches;
  202700. };
  202701. END_JUCE_NAMESPACE
  202702. @implementation JuceUIView
  202703. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  202704. withFrame: (CGRect) frame
  202705. {
  202706. [super initWithFrame: frame];
  202707. owner = owner_;
  202708. hiddenTextField = [[UITextField alloc] initWithFrame: CGRectMake (0, 0, 0, 0)];
  202709. [self addSubview: hiddenTextField];
  202710. hiddenTextField.delegate = self;
  202711. return self;
  202712. }
  202713. - (void) dealloc
  202714. {
  202715. [hiddenTextField removeFromSuperview];
  202716. [hiddenTextField release];
  202717. [super dealloc];
  202718. }
  202719. - (void) drawRect: (CGRect) r
  202720. {
  202721. if (owner != 0)
  202722. owner->drawRect (r);
  202723. }
  202724. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  202725. {
  202726. return false;
  202727. }
  202728. ModifierKeys UIViewComponentPeer::currentModifiers;
  202729. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  202730. {
  202731. return UIViewComponentPeer::currentModifiers;
  202732. }
  202733. void ModifierKeys::updateCurrentModifiers() throw()
  202734. {
  202735. currentModifiers = UIViewComponentPeer::currentModifiers;
  202736. }
  202737. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  202738. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  202739. {
  202740. if (owner != 0)
  202741. owner->handleTouches (event, true, false, false);
  202742. }
  202743. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  202744. {
  202745. if (owner != 0)
  202746. owner->handleTouches (event, false, false, false);
  202747. }
  202748. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  202749. {
  202750. if (owner != 0)
  202751. owner->handleTouches (event, false, true, false);
  202752. }
  202753. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  202754. {
  202755. if (owner != 0)
  202756. owner->handleTouches (event, false, true, true);
  202757. [self touchesEnded: touches withEvent: event];
  202758. }
  202759. - (BOOL) becomeFirstResponder
  202760. {
  202761. if (owner != 0)
  202762. owner->viewFocusGain();
  202763. return true;
  202764. }
  202765. - (BOOL) resignFirstResponder
  202766. {
  202767. if (owner != 0)
  202768. owner->viewFocusLoss();
  202769. return true;
  202770. }
  202771. - (BOOL) canBecomeFirstResponder
  202772. {
  202773. return owner != 0 && owner->canBecomeKeyWindow();
  202774. }
  202775. - (void) asyncRepaint: (id) rect
  202776. {
  202777. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  202778. [self setNeedsDisplayInRect: *r];
  202779. }
  202780. - (BOOL) textField: (UITextField*) textField shouldChangeCharactersInRange: (NSRange) range replacementString: (NSString*) text
  202781. {
  202782. return owner->textFieldReplaceCharacters (Range<int> (range.location, range.location + range.length),
  202783. nsStringToJuce (text));
  202784. }
  202785. - (BOOL) textFieldShouldClear: (UITextField*) textField
  202786. {
  202787. return owner->textFieldShouldClear();
  202788. }
  202789. - (BOOL) textFieldShouldReturn: (UITextField*) textField
  202790. {
  202791. return owner->textFieldShouldReturn();
  202792. }
  202793. @end
  202794. @implementation JuceUIWindow
  202795. - (void) setOwner: (UIViewComponentPeer*) owner_
  202796. {
  202797. owner = owner_;
  202798. isZooming = false;
  202799. }
  202800. - (void) becomeKeyWindow
  202801. {
  202802. [super becomeKeyWindow];
  202803. if (owner != 0)
  202804. owner->grabFocus();
  202805. }
  202806. @end
  202807. BEGIN_JUCE_NAMESPACE
  202808. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  202809. const int windowStyleFlags,
  202810. UIView* viewToAttachTo)
  202811. : ComponentPeer (component, windowStyleFlags),
  202812. window (0),
  202813. view (0),
  202814. isSharedWindow (viewToAttachTo != 0),
  202815. fullScreen (false),
  202816. insideDrawRect (false)
  202817. {
  202818. CGRect r = CGRectMake (0, 0, (float) component->getWidth(), (float) component->getHeight());
  202819. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  202820. if (isSharedWindow)
  202821. {
  202822. window = [viewToAttachTo window];
  202823. [viewToAttachTo addSubview: view];
  202824. setVisible (component->isVisible());
  202825. }
  202826. else
  202827. {
  202828. r.origin.x = (float) component->getX();
  202829. r.origin.y = (float) component->getY();
  202830. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  202831. window = [[JuceUIWindow alloc] init];
  202832. window.frame = r;
  202833. window.opaque = component->isOpaque();
  202834. view.opaque = component->isOpaque();
  202835. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202836. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  202837. [((JuceUIWindow*) window) setOwner: this];
  202838. if (component->isAlwaysOnTop())
  202839. window.windowLevel = UIWindowLevelAlert;
  202840. [window addSubview: view];
  202841. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202842. view.hidden = ! component->isVisible();
  202843. window.hidden = ! component->isVisible();
  202844. view.multipleTouchEnabled = YES;
  202845. }
  202846. setTitle (component->getName());
  202847. Desktop::getInstance().addFocusChangeListener (this);
  202848. }
  202849. UIViewComponentPeer::~UIViewComponentPeer()
  202850. {
  202851. Desktop::getInstance().removeFocusChangeListener (this);
  202852. view->owner = 0;
  202853. [view removeFromSuperview];
  202854. [view release];
  202855. if (! isSharedWindow)
  202856. {
  202857. [((JuceUIWindow*) window) setOwner: 0];
  202858. [window release];
  202859. }
  202860. }
  202861. void* UIViewComponentPeer::getNativeHandle() const
  202862. {
  202863. return view;
  202864. }
  202865. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  202866. {
  202867. view.hidden = ! shouldBeVisible;
  202868. if (! isSharedWindow)
  202869. window.hidden = ! shouldBeVisible;
  202870. }
  202871. void UIViewComponentPeer::setTitle (const String& title)
  202872. {
  202873. // xxx is this possible?
  202874. }
  202875. void UIViewComponentPeer::setPosition (int x, int y)
  202876. {
  202877. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  202878. }
  202879. void UIViewComponentPeer::setSize (int w, int h)
  202880. {
  202881. setBounds (component->getX(), component->getY(), w, h, false);
  202882. }
  202883. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  202884. {
  202885. fullScreen = isNowFullScreen;
  202886. w = jmax (0, w);
  202887. h = jmax (0, h);
  202888. CGRect r;
  202889. r.origin.x = (float) x;
  202890. r.origin.y = (float) y;
  202891. r.size.width = (float) w;
  202892. r.size.height = (float) h;
  202893. if (isSharedWindow)
  202894. {
  202895. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  202896. if ([view frame].size.width != r.size.width
  202897. || [view frame].size.height != r.size.height)
  202898. [view setNeedsDisplay];
  202899. view.frame = r;
  202900. }
  202901. else
  202902. {
  202903. window.frame = r;
  202904. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  202905. }
  202906. }
  202907. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  202908. {
  202909. CGRect r = [view frame];
  202910. if (global && [view window] != 0)
  202911. {
  202912. r = [view convertRect: r toView: nil];
  202913. CGRect wr = [[view window] frame];
  202914. r.origin.x += wr.origin.x;
  202915. r.origin.y += wr.origin.y;
  202916. }
  202917. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  202918. (int) r.size.width, (int) r.size.height);
  202919. }
  202920. const Rectangle<int> UIViewComponentPeer::getBounds() const
  202921. {
  202922. return getBounds (! isSharedWindow);
  202923. }
  202924. const Point<int> UIViewComponentPeer::getScreenPosition() const
  202925. {
  202926. return getBounds (true).getPosition();
  202927. }
  202928. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  202929. {
  202930. return relativePosition + getScreenPosition();
  202931. }
  202932. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  202933. {
  202934. return screenPosition - getScreenPosition();
  202935. }
  202936. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  202937. {
  202938. if (constrainer != 0)
  202939. {
  202940. CGRect current = [window frame];
  202941. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  202942. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  202943. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  202944. (int) r.size.width, (int) r.size.height);
  202945. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  202946. (int) current.size.width, (int) current.size.height);
  202947. constrainer->checkBounds (pos, original,
  202948. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  202949. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  202950. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  202951. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  202952. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  202953. r.origin.x = pos.getX();
  202954. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  202955. r.size.width = pos.getWidth();
  202956. r.size.height = pos.getHeight();
  202957. }
  202958. return r;
  202959. }
  202960. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  202961. {
  202962. // xxx
  202963. }
  202964. bool UIViewComponentPeer::isMinimised() const
  202965. {
  202966. return false;
  202967. }
  202968. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  202969. {
  202970. if (! isSharedWindow)
  202971. {
  202972. Rectangle<int> r (lastNonFullscreenBounds);
  202973. setMinimised (false);
  202974. if (fullScreen != shouldBeFullScreen)
  202975. {
  202976. if (shouldBeFullScreen)
  202977. r = Desktop::getInstance().getMainMonitorArea();
  202978. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  202979. if (r != getComponent()->getBounds() && ! r.isEmpty())
  202980. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  202981. }
  202982. }
  202983. }
  202984. bool UIViewComponentPeer::isFullScreen() const
  202985. {
  202986. return fullScreen;
  202987. }
  202988. bool UIViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  202989. {
  202990. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  202991. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  202992. return false;
  202993. CGPoint p;
  202994. p.x = (float) position.getX();
  202995. p.y = (float) position.getY();
  202996. UIView* v = [view hitTest: p withEvent: nil];
  202997. if (trueIfInAChildWindow)
  202998. return v != nil;
  202999. return v == view;
  203000. }
  203001. const BorderSize UIViewComponentPeer::getFrameSize() const
  203002. {
  203003. BorderSize b;
  203004. if (! isSharedWindow)
  203005. {
  203006. CGRect v = [view convertRect: [view frame] toView: nil];
  203007. CGRect w = [window frame];
  203008. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203009. b.setBottom ((int) v.origin.y);
  203010. b.setLeft ((int) v.origin.x);
  203011. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203012. }
  203013. return b;
  203014. }
  203015. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203016. {
  203017. if (! isSharedWindow)
  203018. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203019. return true;
  203020. }
  203021. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203022. {
  203023. if (isSharedWindow)
  203024. [[view superview] bringSubviewToFront: view];
  203025. if (window != 0 && component->isVisible())
  203026. [window makeKeyAndVisible];
  203027. }
  203028. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203029. {
  203030. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203031. if (isSharedWindow)
  203032. {
  203033. [[view superview] insertSubview: view belowSubview: o->view];
  203034. }
  203035. else
  203036. {
  203037. jassertfalse // don't know how to do this
  203038. }
  203039. }
  203040. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203041. {
  203042. // to do..
  203043. }
  203044. void UIViewComponentPeer::handleTouches (UIEvent* event, const bool isDown, const bool isUp, bool isCancel)
  203045. {
  203046. NSArray* touches = [[event touchesForView: view] allObjects];
  203047. for (unsigned int i = 0; i < [touches count]; ++i)
  203048. {
  203049. UITouch* touch = [touches objectAtIndex: i];
  203050. CGPoint p = [touch locationInView: view];
  203051. const Point<int> pos ((int) p.x, (int) p.y);
  203052. juce_lastMousePos = pos + getScreenPosition();
  203053. const int64 time = getMouseTime (event);
  203054. int touchIndex = currentTouches.indexOf (touch);
  203055. if (touchIndex < 0)
  203056. {
  203057. touchIndex = currentTouches.size();
  203058. currentTouches.add (touch);
  203059. }
  203060. if (isDown)
  203061. {
  203062. currentModifiers = currentModifiers.withoutMouseButtons();
  203063. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203064. currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
  203065. }
  203066. else if (isUp)
  203067. {
  203068. currentModifiers = currentModifiers.withoutMouseButtons();
  203069. currentTouches.remove (touchIndex);
  203070. }
  203071. if (isCancel)
  203072. currentTouches.clear();
  203073. handleMouseEvent (touchIndex, pos, currentModifiers, time);
  203074. }
  203075. }
  203076. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203077. void UIViewComponentPeer::viewFocusGain()
  203078. {
  203079. if (currentlyFocusedPeer != this)
  203080. {
  203081. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203082. currentlyFocusedPeer->handleFocusLoss();
  203083. currentlyFocusedPeer = this;
  203084. handleFocusGain();
  203085. }
  203086. }
  203087. void UIViewComponentPeer::viewFocusLoss()
  203088. {
  203089. if (currentlyFocusedPeer == this)
  203090. {
  203091. currentlyFocusedPeer = 0;
  203092. handleFocusLoss();
  203093. }
  203094. }
  203095. void juce_HandleProcessFocusChange()
  203096. {
  203097. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203098. {
  203099. if (Process::isForegroundProcess())
  203100. {
  203101. currentlyFocusedPeer->handleFocusGain();
  203102. ComponentPeer::bringModalComponentToFront();
  203103. }
  203104. else
  203105. {
  203106. currentlyFocusedPeer->handleFocusLoss();
  203107. // turn kiosk mode off if we lose focus..
  203108. Desktop::getInstance().setKioskModeComponent (0);
  203109. }
  203110. }
  203111. }
  203112. bool UIViewComponentPeer::isFocused() const
  203113. {
  203114. return isSharedWindow ? this == currentlyFocusedPeer
  203115. : (window != 0 && [window isKeyWindow]);
  203116. }
  203117. void UIViewComponentPeer::grabFocus()
  203118. {
  203119. if (window != 0)
  203120. {
  203121. [window makeKeyWindow];
  203122. viewFocusGain();
  203123. }
  203124. }
  203125. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203126. {
  203127. }
  203128. void UIViewComponentPeer::updateHiddenTextContent (TextInputTarget* target)
  203129. {
  203130. view->hiddenTextField.text = juceStringToNS (target->getTextInRange (Range<int> (0, target->getHighlightedRegion().getStart())));
  203131. }
  203132. BOOL UIViewComponentPeer::textFieldReplaceCharacters (const Range<int>& range, const String& text)
  203133. {
  203134. TextInputTarget* const target = findCurrentTextInputTarget();
  203135. if (target != 0)
  203136. {
  203137. const Range<int> currentSelection (target->getHighlightedRegion());
  203138. if (range.getLength() == 1 && text.isEmpty()) // (detect backspace)
  203139. if (currentSelection.isEmpty())
  203140. target->setHighlightedRegion (currentSelection.withStart (currentSelection.getStart() - 1));
  203141. target->insertTextAtCaret (text);
  203142. updateHiddenTextContent (target);
  203143. }
  203144. return NO;
  203145. }
  203146. BOOL UIViewComponentPeer::textFieldShouldClear()
  203147. {
  203148. TextInputTarget* const target = findCurrentTextInputTarget();
  203149. if (target != 0)
  203150. {
  203151. target->setHighlightedRegion (Range<int> (0, std::numeric_limits<int>::max()));
  203152. target->insertTextAtCaret (String::empty);
  203153. updateHiddenTextContent (target);
  203154. }
  203155. return YES;
  203156. }
  203157. BOOL UIViewComponentPeer::textFieldShouldReturn()
  203158. {
  203159. TextInputTarget* const target = findCurrentTextInputTarget();
  203160. if (target != 0)
  203161. {
  203162. target->insertTextAtCaret ("\n");
  203163. updateHiddenTextContent (target);
  203164. }
  203165. return YES;
  203166. }
  203167. void UIViewComponentPeer::globalFocusChanged (Component*)
  203168. {
  203169. TextInputTarget* const target = findCurrentTextInputTarget();
  203170. if (target != 0)
  203171. {
  203172. Component* comp = dynamic_cast<Component*> (target);
  203173. Point<int> pos (comp->relativePositionToOtherComponent (component, Point<int>()));
  203174. view->hiddenTextField.frame = CGRectMake (pos.getX(), pos.getY(), 0, 0);
  203175. updateHiddenTextContent (target);
  203176. [view->hiddenTextField becomeFirstResponder];
  203177. }
  203178. else
  203179. {
  203180. [view->hiddenTextField resignFirstResponder];
  203181. }
  203182. }
  203183. void UIViewComponentPeer::drawRect (CGRect r)
  203184. {
  203185. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203186. return;
  203187. CGContextRef cg = UIGraphicsGetCurrentContext();
  203188. if (! component->isOpaque())
  203189. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203190. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203191. CoreGraphicsContext g (cg, view.bounds.size.height);
  203192. insideDrawRect = true;
  203193. handlePaint (g);
  203194. insideDrawRect = false;
  203195. }
  203196. bool UIViewComponentPeer::canBecomeKeyWindow()
  203197. {
  203198. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203199. }
  203200. bool UIViewComponentPeer::windowShouldClose()
  203201. {
  203202. if (! isValidPeer (this))
  203203. return YES;
  203204. handleUserClosingWindow();
  203205. return NO;
  203206. }
  203207. void UIViewComponentPeer::redirectMovedOrResized()
  203208. {
  203209. handleMovedOrResized();
  203210. }
  203211. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203212. {
  203213. }
  203214. class AsyncRepaintMessage : public CallbackMessage
  203215. {
  203216. public:
  203217. UIViewComponentPeer* const peer;
  203218. const Rectangle<int> rect;
  203219. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203220. : peer (peer_), rect (rect_)
  203221. {
  203222. }
  203223. void messageCallback()
  203224. {
  203225. if (ComponentPeer::isValidPeer (peer))
  203226. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203227. }
  203228. };
  203229. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203230. {
  203231. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203232. {
  203233. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203234. }
  203235. else
  203236. {
  203237. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203238. }
  203239. }
  203240. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203241. {
  203242. }
  203243. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203244. {
  203245. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203246. }
  203247. Image* juce_createIconForFile (const File& file)
  203248. {
  203249. return 0;
  203250. }
  203251. void Desktop::createMouseInputSources()
  203252. {
  203253. for (int i = 0; i < 10; ++i)
  203254. mouseSources.add (new MouseInputSource (i, false));
  203255. }
  203256. bool Desktop::canUseSemiTransparentWindows() throw()
  203257. {
  203258. return true;
  203259. }
  203260. const Point<int> Desktop::getMousePosition()
  203261. {
  203262. return juce_lastMousePos;
  203263. }
  203264. void Desktop::setMousePosition (const Point<int>&)
  203265. {
  203266. }
  203267. const int KeyPress::spaceKey = ' ';
  203268. const int KeyPress::returnKey = 0x0d;
  203269. const int KeyPress::escapeKey = 0x1b;
  203270. const int KeyPress::backspaceKey = 0x7f;
  203271. const int KeyPress::leftKey = 0x1000;
  203272. const int KeyPress::rightKey = 0x1001;
  203273. const int KeyPress::upKey = 0x1002;
  203274. const int KeyPress::downKey = 0x1003;
  203275. const int KeyPress::pageUpKey = 0x1004;
  203276. const int KeyPress::pageDownKey = 0x1005;
  203277. const int KeyPress::endKey = 0x1006;
  203278. const int KeyPress::homeKey = 0x1007;
  203279. const int KeyPress::deleteKey = 0x1008;
  203280. const int KeyPress::insertKey = -1;
  203281. const int KeyPress::tabKey = 9;
  203282. const int KeyPress::F1Key = 0x2001;
  203283. const int KeyPress::F2Key = 0x2002;
  203284. const int KeyPress::F3Key = 0x2003;
  203285. const int KeyPress::F4Key = 0x2004;
  203286. const int KeyPress::F5Key = 0x2005;
  203287. const int KeyPress::F6Key = 0x2006;
  203288. const int KeyPress::F7Key = 0x2007;
  203289. const int KeyPress::F8Key = 0x2008;
  203290. const int KeyPress::F9Key = 0x2009;
  203291. const int KeyPress::F10Key = 0x200a;
  203292. const int KeyPress::F11Key = 0x200b;
  203293. const int KeyPress::F12Key = 0x200c;
  203294. const int KeyPress::F13Key = 0x200d;
  203295. const int KeyPress::F14Key = 0x200e;
  203296. const int KeyPress::F15Key = 0x200f;
  203297. const int KeyPress::F16Key = 0x2010;
  203298. const int KeyPress::numberPad0 = 0x30020;
  203299. const int KeyPress::numberPad1 = 0x30021;
  203300. const int KeyPress::numberPad2 = 0x30022;
  203301. const int KeyPress::numberPad3 = 0x30023;
  203302. const int KeyPress::numberPad4 = 0x30024;
  203303. const int KeyPress::numberPad5 = 0x30025;
  203304. const int KeyPress::numberPad6 = 0x30026;
  203305. const int KeyPress::numberPad7 = 0x30027;
  203306. const int KeyPress::numberPad8 = 0x30028;
  203307. const int KeyPress::numberPad9 = 0x30029;
  203308. const int KeyPress::numberPadAdd = 0x3002a;
  203309. const int KeyPress::numberPadSubtract = 0x3002b;
  203310. const int KeyPress::numberPadMultiply = 0x3002c;
  203311. const int KeyPress::numberPadDivide = 0x3002d;
  203312. const int KeyPress::numberPadSeparator = 0x3002e;
  203313. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203314. const int KeyPress::numberPadEquals = 0x30030;
  203315. const int KeyPress::numberPadDelete = 0x30031;
  203316. const int KeyPress::playKey = 0x30000;
  203317. const int KeyPress::stopKey = 0x30001;
  203318. const int KeyPress::fastForwardKey = 0x30002;
  203319. const int KeyPress::rewindKey = 0x30003;
  203320. #endif
  203321. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203322. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203323. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203324. // compiled on its own).
  203325. #if JUCE_INCLUDED_FILE
  203326. struct CallbackMessagePayload
  203327. {
  203328. MessageCallbackFunction* function;
  203329. void* parameter;
  203330. void* volatile result;
  203331. bool volatile hasBeenExecuted;
  203332. };
  203333. END_JUCE_NAMESPACE
  203334. using namespace JUCE_NAMESPACE;
  203335. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203336. {
  203337. }
  203338. - (JuceAppDelegate*) init;
  203339. - (void) dealloc;
  203340. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203341. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203342. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203343. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203344. - (void) customEvent: (id) data;
  203345. - (void) performCallback: (id) info;
  203346. @end
  203347. @implementation JuceAppDelegate
  203348. - (JuceAppDelegate*) init
  203349. {
  203350. [super init];
  203351. [[UIApplication sharedApplication] setDelegate: self];
  203352. return self;
  203353. }
  203354. - (void) dealloc
  203355. {
  203356. [[UIApplication sharedApplication] setDelegate: nil];
  203357. [super dealloc];
  203358. }
  203359. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203360. {
  203361. if (JUCEApplication::getInstance() != 0)
  203362. {
  203363. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203364. return YES;
  203365. }
  203366. return NO;
  203367. }
  203368. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203369. {
  203370. juce_HandleProcessFocusChange();
  203371. }
  203372. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203373. {
  203374. juce_HandleProcessFocusChange();
  203375. }
  203376. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203377. {
  203378. juce_HandleProcessFocusChange();
  203379. }
  203380. - (void) customEvent: (id) n
  203381. {
  203382. NSData* data = (NSData*) n;
  203383. void* message = 0;
  203384. [data getBytes: &message length: sizeof (message)];
  203385. [data release];
  203386. if (message != 0)
  203387. MessageManager::getInstance()->deliverMessage (message);
  203388. }
  203389. - (void) performCallback: (id) info
  203390. {
  203391. if ([info isKindOfClass: [NSData class]])
  203392. {
  203393. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203394. if (pl != 0)
  203395. {
  203396. pl->result = (*pl->function) (pl->parameter);
  203397. pl->hasBeenExecuted = true;
  203398. }
  203399. }
  203400. else
  203401. {
  203402. jassertfalse // should never get here!
  203403. }
  203404. }
  203405. @end
  203406. BEGIN_JUCE_NAMESPACE
  203407. static JuceAppDelegate* juceAppDelegate = 0;
  203408. void MessageManager::runDispatchLoop()
  203409. {
  203410. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203411. runDispatchLoopUntil (-1);
  203412. }
  203413. void MessageManager::stopDispatchLoop()
  203414. {
  203415. exit (0); // iPhone apps get no mercy..
  203416. }
  203417. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203418. {
  203419. const ScopedAutoReleasePool pool;
  203420. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203421. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203422. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203423. while (! quitMessagePosted)
  203424. {
  203425. const ScopedAutoReleasePool pool;
  203426. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203427. beforeDate: endDate];
  203428. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203429. break;
  203430. }
  203431. return ! quitMessagePosted;
  203432. }
  203433. static CFRunLoopRef runLoop = 0;
  203434. static CFRunLoopSourceRef runLoopSource = 0;
  203435. static Array <void*, CriticalSection>* pendingMessages = 0;
  203436. static void runLoopSourceCallback (void*)
  203437. {
  203438. if (pendingMessages != 0)
  203439. {
  203440. int numDispatched = 0;
  203441. do
  203442. {
  203443. void* const nextMessage = pendingMessages->remove (0);
  203444. if (nextMessage == 0)
  203445. return;
  203446. const ScopedAutoReleasePool pool;
  203447. MessageManager::getInstance()->deliverMessage (nextMessage);
  203448. } while (++numDispatched <= 4);
  203449. CFRunLoopSourceSignal (runLoopSource);
  203450. CFRunLoopWakeUp (runLoop);
  203451. }
  203452. }
  203453. void MessageManager::doPlatformSpecificInitialisation()
  203454. {
  203455. pendingMessages = new Array <void*, CriticalSection>();
  203456. runLoop = CFRunLoopGetCurrent();
  203457. CFRunLoopSourceContext sourceContext;
  203458. zerostruct (sourceContext);
  203459. sourceContext.perform = runLoopSourceCallback;
  203460. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203461. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203462. if (juceAppDelegate == 0)
  203463. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203464. }
  203465. void MessageManager::doPlatformSpecificShutdown()
  203466. {
  203467. CFRunLoopSourceInvalidate (runLoopSource);
  203468. CFRelease (runLoopSource);
  203469. runLoopSource = 0;
  203470. if (pendingMessages != 0)
  203471. {
  203472. while (pendingMessages->size() > 0)
  203473. delete ((Message*) pendingMessages->remove(0));
  203474. deleteAndZero (pendingMessages);
  203475. }
  203476. if (juceAppDelegate != 0)
  203477. {
  203478. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203479. [juceAppDelegate release];
  203480. juceAppDelegate = 0;
  203481. }
  203482. }
  203483. bool juce_postMessageToSystemQueue (void* message)
  203484. {
  203485. if (pendingMessages != 0)
  203486. {
  203487. pendingMessages->add (message);
  203488. CFRunLoopSourceSignal (runLoopSource);
  203489. CFRunLoopWakeUp (runLoop);
  203490. }
  203491. return true;
  203492. }
  203493. void MessageManager::broadcastMessage (const String& value) throw()
  203494. {
  203495. }
  203496. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203497. void* data)
  203498. {
  203499. if (isThisTheMessageThread())
  203500. {
  203501. return (*callback) (data);
  203502. }
  203503. else
  203504. {
  203505. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203506. // deadlock because the message manager is blocked from running, so can never
  203507. // call your function..
  203508. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203509. const ScopedAutoReleasePool pool;
  203510. CallbackMessagePayload cmp;
  203511. cmp.function = callback;
  203512. cmp.parameter = data;
  203513. cmp.result = 0;
  203514. cmp.hasBeenExecuted = false;
  203515. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203516. withObject: [NSData dataWithBytesNoCopy: &cmp
  203517. length: sizeof (cmp)
  203518. freeWhenDone: NO]
  203519. waitUntilDone: YES];
  203520. return cmp.result;
  203521. }
  203522. }
  203523. #endif
  203524. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203525. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203526. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203527. // compiled on its own).
  203528. #if JUCE_INCLUDED_FILE
  203529. #if JUCE_MAC
  203530. END_JUCE_NAMESPACE
  203531. using namespace JUCE_NAMESPACE;
  203532. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203533. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203534. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203535. #else
  203536. @interface JuceFileChooserDelegate : NSObject
  203537. #endif
  203538. {
  203539. StringArray* filters;
  203540. }
  203541. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203542. - (void) dealloc;
  203543. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203544. @end
  203545. @implementation JuceFileChooserDelegate
  203546. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203547. {
  203548. [super init];
  203549. filters = filters_;
  203550. return self;
  203551. }
  203552. - (void) dealloc
  203553. {
  203554. delete filters;
  203555. [super dealloc];
  203556. }
  203557. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203558. {
  203559. const File f (nsStringToJuce (filename));
  203560. for (int i = filters->size(); --i >= 0;)
  203561. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203562. return true;
  203563. return f.isDirectory();
  203564. }
  203565. @end
  203566. BEGIN_JUCE_NAMESPACE
  203567. void FileChooser::showPlatformDialog (Array<File>& results,
  203568. const String& title,
  203569. const File& currentFileOrDirectory,
  203570. const String& filter,
  203571. bool selectsDirectory,
  203572. bool selectsFiles,
  203573. bool isSaveDialogue,
  203574. bool warnAboutOverwritingExistingFiles,
  203575. bool selectMultipleFiles,
  203576. FilePreviewComponent* extraInfoComponent)
  203577. {
  203578. const ScopedAutoReleasePool pool;
  203579. StringArray* filters = new StringArray();
  203580. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  203581. filters->trim();
  203582. filters->removeEmptyStrings();
  203583. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203584. [delegate autorelease];
  203585. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203586. : [NSOpenPanel openPanel];
  203587. [panel setTitle: juceStringToNS (title)];
  203588. if (! isSaveDialogue)
  203589. {
  203590. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203591. [openPanel setCanChooseDirectories: selectsDirectory];
  203592. [openPanel setCanChooseFiles: selectsFiles];
  203593. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203594. }
  203595. [panel setDelegate: delegate];
  203596. if (isSaveDialogue || selectsDirectory)
  203597. [panel setCanCreateDirectories: YES];
  203598. String directory, filename;
  203599. if (currentFileOrDirectory.isDirectory())
  203600. {
  203601. directory = currentFileOrDirectory.getFullPathName();
  203602. }
  203603. else
  203604. {
  203605. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203606. filename = currentFileOrDirectory.getFileName();
  203607. }
  203608. if ([panel runModalForDirectory: juceStringToNS (directory)
  203609. file: juceStringToNS (filename)]
  203610. == NSOKButton)
  203611. {
  203612. if (isSaveDialogue)
  203613. {
  203614. results.add (File (nsStringToJuce ([panel filename])));
  203615. }
  203616. else
  203617. {
  203618. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203619. NSArray* urls = [openPanel filenames];
  203620. for (unsigned int i = 0; i < [urls count]; ++i)
  203621. {
  203622. NSString* f = [urls objectAtIndex: i];
  203623. results.add (File (nsStringToJuce (f)));
  203624. }
  203625. }
  203626. }
  203627. [panel setDelegate: nil];
  203628. }
  203629. #else
  203630. void FileChooser::showPlatformDialog (Array<File>& results,
  203631. const String& title,
  203632. const File& currentFileOrDirectory,
  203633. const String& filter,
  203634. bool selectsDirectory,
  203635. bool selectsFiles,
  203636. bool isSaveDialogue,
  203637. bool warnAboutOverwritingExistingFiles,
  203638. bool selectMultipleFiles,
  203639. FilePreviewComponent* extraInfoComponent)
  203640. {
  203641. const ScopedAutoReleasePool pool;
  203642. jassertfalse //xxx to do
  203643. }
  203644. #endif
  203645. #endif
  203646. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203647. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203648. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203649. // compiled on its own).
  203650. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203651. #if JUCE_MAC
  203652. END_JUCE_NAMESPACE
  203653. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203654. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203655. {
  203656. CriticalSection* contextLock;
  203657. bool needsUpdate;
  203658. }
  203659. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203660. - (bool) makeActive;
  203661. - (void) makeInactive;
  203662. - (void) reshape;
  203663. @end
  203664. @implementation ThreadSafeNSOpenGLView
  203665. - (id) initWithFrame: (NSRect) frameRect
  203666. pixelFormat: (NSOpenGLPixelFormat*) format
  203667. {
  203668. contextLock = new CriticalSection();
  203669. self = [super initWithFrame: frameRect pixelFormat: format];
  203670. if (self != nil)
  203671. [[NSNotificationCenter defaultCenter] addObserver: self
  203672. selector: @selector (_surfaceNeedsUpdate:)
  203673. name: NSViewGlobalFrameDidChangeNotification
  203674. object: self];
  203675. return self;
  203676. }
  203677. - (void) dealloc
  203678. {
  203679. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203680. delete contextLock;
  203681. [super dealloc];
  203682. }
  203683. - (bool) makeActive
  203684. {
  203685. const ScopedLock sl (*contextLock);
  203686. if ([self openGLContext] == 0)
  203687. return false;
  203688. [[self openGLContext] makeCurrentContext];
  203689. if (needsUpdate)
  203690. {
  203691. [super update];
  203692. needsUpdate = false;
  203693. }
  203694. return true;
  203695. }
  203696. - (void) makeInactive
  203697. {
  203698. const ScopedLock sl (*contextLock);
  203699. [NSOpenGLContext clearCurrentContext];
  203700. }
  203701. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203702. {
  203703. const ScopedLock sl (*contextLock);
  203704. needsUpdate = true;
  203705. }
  203706. - (void) update
  203707. {
  203708. const ScopedLock sl (*contextLock);
  203709. needsUpdate = true;
  203710. }
  203711. - (void) reshape
  203712. {
  203713. const ScopedLock sl (*contextLock);
  203714. needsUpdate = true;
  203715. }
  203716. @end
  203717. BEGIN_JUCE_NAMESPACE
  203718. class WindowedGLContext : public OpenGLContext
  203719. {
  203720. public:
  203721. WindowedGLContext (Component* const component,
  203722. const OpenGLPixelFormat& pixelFormat_,
  203723. NSOpenGLContext* sharedContext)
  203724. : renderContext (0),
  203725. pixelFormat (pixelFormat_)
  203726. {
  203727. jassert (component != 0);
  203728. NSOpenGLPixelFormatAttribute attribs [64];
  203729. int n = 0;
  203730. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203731. attribs[n++] = NSOpenGLPFAAccelerated;
  203732. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203733. attribs[n++] = NSOpenGLPFAColorSize;
  203734. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203735. pixelFormat.greenBits,
  203736. pixelFormat.blueBits);
  203737. attribs[n++] = NSOpenGLPFAAlphaSize;
  203738. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203739. attribs[n++] = NSOpenGLPFADepthSize;
  203740. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203741. attribs[n++] = NSOpenGLPFAStencilSize;
  203742. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203743. attribs[n++] = NSOpenGLPFAAccumSize;
  203744. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203745. pixelFormat.accumulationBufferGreenBits,
  203746. pixelFormat.accumulationBufferBlueBits,
  203747. pixelFormat.accumulationBufferAlphaBits);
  203748. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203749. attribs[n++] = NSOpenGLPFASampleBuffers;
  203750. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203751. attribs[n++] = NSOpenGLPFAClosestPolicy;
  203752. attribs[n++] = NSOpenGLPFANoRecovery;
  203753. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  203754. NSOpenGLPixelFormat* format
  203755. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  203756. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  203757. pixelFormat: format];
  203758. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  203759. shareContext: sharedContext] autorelease];
  203760. const GLint swapInterval = 1;
  203761. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  203762. [view setOpenGLContext: renderContext];
  203763. [renderContext setView: view];
  203764. [format release];
  203765. viewHolder = new NSViewComponentInternal (view, component);
  203766. }
  203767. ~WindowedGLContext()
  203768. {
  203769. makeInactive();
  203770. [renderContext clearDrawable];
  203771. viewHolder = 0;
  203772. }
  203773. bool makeActive() const throw()
  203774. {
  203775. jassert (renderContext != 0);
  203776. [view makeActive];
  203777. return isActive();
  203778. }
  203779. bool makeInactive() const throw()
  203780. {
  203781. [view makeInactive];
  203782. return true;
  203783. }
  203784. bool isActive() const throw()
  203785. {
  203786. return [NSOpenGLContext currentContext] == renderContext;
  203787. }
  203788. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203789. void* getRawContext() const throw() { return renderContext; }
  203790. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203791. {
  203792. }
  203793. void swapBuffers()
  203794. {
  203795. [renderContext flushBuffer];
  203796. }
  203797. bool setSwapInterval (const int numFramesPerSwap)
  203798. {
  203799. [renderContext setValues: (const GLint*) &numFramesPerSwap
  203800. forParameter: NSOpenGLCPSwapInterval];
  203801. return true;
  203802. }
  203803. int getSwapInterval() const
  203804. {
  203805. GLint numFrames = 0;
  203806. [renderContext getValues: &numFrames
  203807. forParameter: NSOpenGLCPSwapInterval];
  203808. return numFrames;
  203809. }
  203810. void repaint()
  203811. {
  203812. // we need to invalidate the juce view that holds this gl view, to make it
  203813. // cause a repaint callback
  203814. NSView* v = (NSView*) viewHolder->view;
  203815. NSRect r = [v frame];
  203816. // bit of a bodge here.. if we only invalidate the area of the gl component,
  203817. // it's completely covered by the NSOpenGLView, so the OS throws away the
  203818. // repaint message, thus never causing our paint() callback, and never repainting
  203819. // the comp. So invalidating just a little bit around the edge helps..
  203820. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  203821. }
  203822. void* getNativeWindowHandle() const { return viewHolder->view; }
  203823. juce_UseDebuggingNewOperator
  203824. NSOpenGLContext* renderContext;
  203825. ThreadSafeNSOpenGLView* view;
  203826. private:
  203827. OpenGLPixelFormat pixelFormat;
  203828. ScopedPointer <NSViewComponentInternal> viewHolder;
  203829. WindowedGLContext (const WindowedGLContext&);
  203830. WindowedGLContext& operator= (const WindowedGLContext&);
  203831. };
  203832. OpenGLContext* OpenGLComponent::createContext()
  203833. {
  203834. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  203835. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  203836. return (c->renderContext != 0) ? c.release() : 0;
  203837. }
  203838. void* OpenGLComponent::getNativeWindowHandle() const
  203839. {
  203840. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  203841. : 0;
  203842. }
  203843. void juce_glViewport (const int w, const int h)
  203844. {
  203845. glViewport (0, 0, w, h);
  203846. }
  203847. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  203848. OwnedArray <OpenGLPixelFormat>& results)
  203849. {
  203850. /* GLint attribs [64];
  203851. int n = 0;
  203852. attribs[n++] = AGL_RGBA;
  203853. attribs[n++] = AGL_DOUBLEBUFFER;
  203854. attribs[n++] = AGL_ACCELERATED;
  203855. attribs[n++] = AGL_NO_RECOVERY;
  203856. attribs[n++] = AGL_NONE;
  203857. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  203858. while (p != 0)
  203859. {
  203860. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  203861. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  203862. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  203863. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  203864. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  203865. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  203866. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  203867. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  203868. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  203869. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  203870. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  203871. results.add (pf);
  203872. p = aglNextPixelFormat (p);
  203873. }*/
  203874. //jassertfalse //xxx can't see how you do this in cocoa!
  203875. }
  203876. #else
  203877. END_JUCE_NAMESPACE
  203878. @interface JuceGLView : UIView
  203879. {
  203880. }
  203881. + (Class) layerClass;
  203882. @end
  203883. @implementation JuceGLView
  203884. + (Class) layerClass
  203885. {
  203886. return [CAEAGLLayer class];
  203887. }
  203888. @end
  203889. BEGIN_JUCE_NAMESPACE
  203890. class GLESContext : public OpenGLContext
  203891. {
  203892. public:
  203893. GLESContext (UIViewComponentPeer* peer,
  203894. Component* const component_,
  203895. const OpenGLPixelFormat& pixelFormat_,
  203896. const GLESContext* const sharedContext,
  203897. NSUInteger apiType)
  203898. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  203899. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  203900. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  203901. {
  203902. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  203903. view.opaque = YES;
  203904. view.hidden = NO;
  203905. view.backgroundColor = [UIColor blackColor];
  203906. view.userInteractionEnabled = NO;
  203907. glLayer = (CAEAGLLayer*) [view layer];
  203908. [peer->view addSubview: view];
  203909. if (sharedContext != 0)
  203910. context = [[EAGLContext alloc] initWithAPI: apiType
  203911. sharegroup: [sharedContext->context sharegroup]];
  203912. else
  203913. context = [[EAGLContext alloc] initWithAPI: apiType];
  203914. createGLBuffers();
  203915. }
  203916. ~GLESContext()
  203917. {
  203918. makeInactive();
  203919. [context release];
  203920. [view removeFromSuperview];
  203921. [view release];
  203922. freeGLBuffers();
  203923. }
  203924. bool makeActive() const throw()
  203925. {
  203926. jassert (context != 0);
  203927. [EAGLContext setCurrentContext: context];
  203928. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203929. return true;
  203930. }
  203931. void swapBuffers()
  203932. {
  203933. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203934. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  203935. }
  203936. bool makeInactive() const throw()
  203937. {
  203938. return [EAGLContext setCurrentContext: nil];
  203939. }
  203940. bool isActive() const throw()
  203941. {
  203942. return [EAGLContext currentContext] == context;
  203943. }
  203944. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  203945. void* getRawContext() const throw() { return glLayer; }
  203946. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  203947. {
  203948. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  203949. if (lastWidth != w || lastHeight != h)
  203950. {
  203951. lastWidth = w;
  203952. lastHeight = h;
  203953. freeGLBuffers();
  203954. createGLBuffers();
  203955. }
  203956. }
  203957. bool setSwapInterval (const int numFramesPerSwap)
  203958. {
  203959. numFrames = numFramesPerSwap;
  203960. return true;
  203961. }
  203962. int getSwapInterval() const
  203963. {
  203964. return numFrames;
  203965. }
  203966. void repaint()
  203967. {
  203968. }
  203969. void createGLBuffers()
  203970. {
  203971. makeActive();
  203972. glGenFramebuffersOES (1, &frameBufferHandle);
  203973. glGenRenderbuffersOES (1, &colorBufferHandle);
  203974. glGenRenderbuffersOES (1, &depthBufferHandle);
  203975. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203976. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  203977. GLint width, height;
  203978. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  203979. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  203980. if (useDepthBuffer)
  203981. {
  203982. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  203983. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  203984. }
  203985. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  203986. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  203987. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  203988. if (useDepthBuffer)
  203989. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  203990. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  203991. }
  203992. void freeGLBuffers()
  203993. {
  203994. if (frameBufferHandle != 0)
  203995. {
  203996. glDeleteFramebuffersOES (1, &frameBufferHandle);
  203997. frameBufferHandle = 0;
  203998. }
  203999. if (colorBufferHandle != 0)
  204000. {
  204001. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  204002. colorBufferHandle = 0;
  204003. }
  204004. if (depthBufferHandle != 0)
  204005. {
  204006. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  204007. depthBufferHandle = 0;
  204008. }
  204009. }
  204010. juce_UseDebuggingNewOperator
  204011. private:
  204012. Component::SafePointer<Component> component;
  204013. OpenGLPixelFormat pixelFormat;
  204014. JuceGLView* view;
  204015. CAEAGLLayer* glLayer;
  204016. EAGLContext* context;
  204017. bool useDepthBuffer;
  204018. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  204019. int numFrames;
  204020. int lastWidth, lastHeight;
  204021. GLESContext (const GLESContext&);
  204022. GLESContext& operator= (const GLESContext&);
  204023. };
  204024. OpenGLContext* OpenGLComponent::createContext()
  204025. {
  204026. ScopedAutoReleasePool pool;
  204027. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  204028. if (peer != 0)
  204029. return new GLESContext (peer, this, preferredPixelFormat,
  204030. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  204031. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  204032. return 0;
  204033. }
  204034. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204035. OwnedArray <OpenGLPixelFormat>& /*results*/)
  204036. {
  204037. }
  204038. void juce_glViewport (const int w, const int h)
  204039. {
  204040. glViewport (0, 0, w, h);
  204041. }
  204042. #endif
  204043. #endif
  204044. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204045. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204046. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204047. // compiled on its own).
  204048. #if JUCE_INCLUDED_FILE
  204049. #if JUCE_MAC
  204050. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  204051. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  204052. {
  204053. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204054. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204055. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204056. [im release];
  204057. return c;
  204058. }
  204059. static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy)
  204060. {
  204061. MemoryInputStream stream (data, false);
  204062. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  204063. jassert (im != 0);
  204064. if (im == 0)
  204065. return 0;
  204066. return juce_createMouseCursorFromImage (*im,
  204067. (int) (hx * im->getWidth()),
  204068. (int) (hy * im->getHeight()));
  204069. }
  204070. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204071. {
  204072. const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204073. MemoryBlock mb;
  204074. if (f.getChildFile (filename).loadFileAsData (mb))
  204075. return juce_cursorFromData (mb, hx, hy);
  204076. return 0;
  204077. }
  204078. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  204079. {
  204080. const ScopedAutoReleasePool pool;
  204081. NSCursor* c = 0;
  204082. switch (type)
  204083. {
  204084. case MouseCursor::NormalCursor:
  204085. c = [NSCursor arrowCursor];
  204086. break;
  204087. case MouseCursor::NoCursor:
  204088. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  204089. case MouseCursor::DraggingHandCursor:
  204090. c = [NSCursor openHandCursor];
  204091. break;
  204092. case MouseCursor::CopyingCursor:
  204093. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204094. case MouseCursor::WaitCursor:
  204095. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204096. break;
  204097. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204098. case MouseCursor::IBeamCursor:
  204099. c = [NSCursor IBeamCursor];
  204100. break;
  204101. case MouseCursor::PointingHandCursor:
  204102. c = [NSCursor pointingHandCursor];
  204103. break;
  204104. case MouseCursor::LeftRightResizeCursor:
  204105. c = [NSCursor resizeLeftRightCursor];
  204106. break;
  204107. case MouseCursor::LeftEdgeResizeCursor:
  204108. c = [NSCursor resizeLeftCursor];
  204109. break;
  204110. case MouseCursor::RightEdgeResizeCursor:
  204111. c = [NSCursor resizeRightCursor];
  204112. break;
  204113. case MouseCursor::UpDownResizeCursor:
  204114. case MouseCursor::TopEdgeResizeCursor:
  204115. case MouseCursor::BottomEdgeResizeCursor:
  204116. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204117. case MouseCursor::TopLeftCornerResizeCursor:
  204118. case MouseCursor::BottomRightCornerResizeCursor:
  204119. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204120. case MouseCursor::TopRightCornerResizeCursor:
  204121. case MouseCursor::BottomLeftCornerResizeCursor:
  204122. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204123. case MouseCursor::UpDownLeftRightResizeCursor:
  204124. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204125. case MouseCursor::CrosshairCursor:
  204126. c = [NSCursor crosshairCursor];
  204127. break;
  204128. }
  204129. [c retain];
  204130. return c;
  204131. }
  204132. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  204133. {
  204134. NSCursor* c = (NSCursor*) cursorHandle;
  204135. [c release];
  204136. }
  204137. void MouseCursor::showInAllWindows() const
  204138. {
  204139. showInWindow (0);
  204140. }
  204141. void MouseCursor::showInWindow (ComponentPeer*) const
  204142. {
  204143. NSCursor* const c = (NSCursor*) getHandle();
  204144. [c set];
  204145. }
  204146. #else
  204147. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; }
  204148. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; }
  204149. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {}
  204150. void MouseCursor::showInAllWindows() const {}
  204151. void MouseCursor::showInWindow (ComponentPeer*) const {}
  204152. #endif
  204153. #endif
  204154. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204155. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204156. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204157. // compiled on its own).
  204158. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204159. #if JUCE_MAC
  204160. END_JUCE_NAMESPACE
  204161. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204162. @interface DownloadClickDetector : NSObject
  204163. {
  204164. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204165. }
  204166. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204167. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204168. request: (NSURLRequest*) request
  204169. frame: (WebFrame*) frame
  204170. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204171. @end
  204172. @implementation DownloadClickDetector
  204173. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204174. {
  204175. [super init];
  204176. ownerComponent = ownerComponent_;
  204177. return self;
  204178. }
  204179. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204180. request: (NSURLRequest*) request
  204181. frame: (WebFrame*) frame
  204182. decisionListener: (id <WebPolicyDecisionListener>) listener
  204183. {
  204184. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204185. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204186. [listener use];
  204187. else
  204188. [listener ignore];
  204189. }
  204190. @end
  204191. BEGIN_JUCE_NAMESPACE
  204192. class WebBrowserComponentInternal : public NSViewComponent
  204193. {
  204194. public:
  204195. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204196. {
  204197. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204198. frameName: @""
  204199. groupName: @""];
  204200. setView (webView);
  204201. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204202. [webView setPolicyDelegate: clickListener];
  204203. }
  204204. ~WebBrowserComponentInternal()
  204205. {
  204206. [webView setPolicyDelegate: nil];
  204207. [clickListener release];
  204208. setView (0);
  204209. }
  204210. void goToURL (const String& url,
  204211. const StringArray* headers,
  204212. const MemoryBlock* postData)
  204213. {
  204214. NSMutableURLRequest* r
  204215. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204216. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204217. timeoutInterval: 30.0];
  204218. if (postData != 0 && postData->getSize() > 0)
  204219. {
  204220. [r setHTTPMethod: @"POST"];
  204221. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204222. length: postData->getSize()]];
  204223. }
  204224. if (headers != 0)
  204225. {
  204226. for (int i = 0; i < headers->size(); ++i)
  204227. {
  204228. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  204229. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  204230. [r setValue: juceStringToNS (headerValue)
  204231. forHTTPHeaderField: juceStringToNS (headerName)];
  204232. }
  204233. }
  204234. stop();
  204235. [[webView mainFrame] loadRequest: r];
  204236. }
  204237. void goBack()
  204238. {
  204239. [webView goBack];
  204240. }
  204241. void goForward()
  204242. {
  204243. [webView goForward];
  204244. }
  204245. void stop()
  204246. {
  204247. [webView stopLoading: nil];
  204248. }
  204249. void refresh()
  204250. {
  204251. [webView reload: nil];
  204252. }
  204253. private:
  204254. WebView* webView;
  204255. DownloadClickDetector* clickListener;
  204256. };
  204257. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204258. : browser (0),
  204259. blankPageShown (false),
  204260. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204261. {
  204262. setOpaque (true);
  204263. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204264. }
  204265. WebBrowserComponent::~WebBrowserComponent()
  204266. {
  204267. deleteAndZero (browser);
  204268. }
  204269. void WebBrowserComponent::goToURL (const String& url,
  204270. const StringArray* headers,
  204271. const MemoryBlock* postData)
  204272. {
  204273. lastURL = url;
  204274. lastHeaders.clear();
  204275. if (headers != 0)
  204276. lastHeaders = *headers;
  204277. lastPostData.setSize (0);
  204278. if (postData != 0)
  204279. lastPostData = *postData;
  204280. blankPageShown = false;
  204281. browser->goToURL (url, headers, postData);
  204282. }
  204283. void WebBrowserComponent::stop()
  204284. {
  204285. browser->stop();
  204286. }
  204287. void WebBrowserComponent::goBack()
  204288. {
  204289. lastURL = String::empty;
  204290. blankPageShown = false;
  204291. browser->goBack();
  204292. }
  204293. void WebBrowserComponent::goForward()
  204294. {
  204295. lastURL = String::empty;
  204296. browser->goForward();
  204297. }
  204298. void WebBrowserComponent::refresh()
  204299. {
  204300. browser->refresh();
  204301. }
  204302. void WebBrowserComponent::paint (Graphics& g)
  204303. {
  204304. }
  204305. void WebBrowserComponent::checkWindowAssociation()
  204306. {
  204307. if (isShowing())
  204308. {
  204309. if (blankPageShown)
  204310. goBack();
  204311. }
  204312. else
  204313. {
  204314. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204315. {
  204316. // when the component becomes invisible, some stuff like flash
  204317. // carries on playing audio, so we need to force it onto a blank
  204318. // page to avoid this, (and send it back when it's made visible again).
  204319. blankPageShown = true;
  204320. browser->goToURL ("about:blank", 0, 0);
  204321. }
  204322. }
  204323. }
  204324. void WebBrowserComponent::reloadLastURL()
  204325. {
  204326. if (lastURL.isNotEmpty())
  204327. {
  204328. goToURL (lastURL, &lastHeaders, &lastPostData);
  204329. lastURL = String::empty;
  204330. }
  204331. }
  204332. void WebBrowserComponent::parentHierarchyChanged()
  204333. {
  204334. checkWindowAssociation();
  204335. }
  204336. void WebBrowserComponent::resized()
  204337. {
  204338. browser->setSize (getWidth(), getHeight());
  204339. }
  204340. void WebBrowserComponent::visibilityChanged()
  204341. {
  204342. checkWindowAssociation();
  204343. }
  204344. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204345. {
  204346. return true;
  204347. }
  204348. #else
  204349. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204350. {
  204351. }
  204352. WebBrowserComponent::~WebBrowserComponent()
  204353. {
  204354. }
  204355. void WebBrowserComponent::goToURL (const String& url,
  204356. const StringArray* headers,
  204357. const MemoryBlock* postData)
  204358. {
  204359. }
  204360. void WebBrowserComponent::stop()
  204361. {
  204362. }
  204363. void WebBrowserComponent::goBack()
  204364. {
  204365. }
  204366. void WebBrowserComponent::goForward()
  204367. {
  204368. }
  204369. void WebBrowserComponent::refresh()
  204370. {
  204371. }
  204372. void WebBrowserComponent::paint (Graphics& g)
  204373. {
  204374. }
  204375. void WebBrowserComponent::checkWindowAssociation()
  204376. {
  204377. }
  204378. void WebBrowserComponent::reloadLastURL()
  204379. {
  204380. }
  204381. void WebBrowserComponent::parentHierarchyChanged()
  204382. {
  204383. }
  204384. void WebBrowserComponent::resized()
  204385. {
  204386. }
  204387. void WebBrowserComponent::visibilityChanged()
  204388. {
  204389. }
  204390. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204391. {
  204392. return true;
  204393. }
  204394. #endif
  204395. #endif
  204396. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204397. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204398. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204399. // compiled on its own).
  204400. #if JUCE_INCLUDED_FILE
  204401. class IPhoneAudioIODevice : public AudioIODevice
  204402. {
  204403. public:
  204404. IPhoneAudioIODevice (const String& deviceName)
  204405. : AudioIODevice (deviceName, "Audio"),
  204406. audioUnit (0),
  204407. isRunning (false),
  204408. callback (0),
  204409. actualBufferSize (0),
  204410. floatData (1, 2)
  204411. {
  204412. numInputChannels = 2;
  204413. numOutputChannels = 2;
  204414. preferredBufferSize = 0;
  204415. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204416. updateDeviceInfo();
  204417. }
  204418. ~IPhoneAudioIODevice()
  204419. {
  204420. close();
  204421. }
  204422. const StringArray getOutputChannelNames()
  204423. {
  204424. StringArray s;
  204425. s.add ("Left");
  204426. s.add ("Right");
  204427. return s;
  204428. }
  204429. const StringArray getInputChannelNames()
  204430. {
  204431. StringArray s;
  204432. if (audioInputIsAvailable)
  204433. {
  204434. s.add ("Left");
  204435. s.add ("Right");
  204436. }
  204437. return s;
  204438. }
  204439. int getNumSampleRates()
  204440. {
  204441. return 1;
  204442. }
  204443. double getSampleRate (int index)
  204444. {
  204445. return sampleRate;
  204446. }
  204447. int getNumBufferSizesAvailable()
  204448. {
  204449. return 1;
  204450. }
  204451. int getBufferSizeSamples (int index)
  204452. {
  204453. return getDefaultBufferSize();
  204454. }
  204455. int getDefaultBufferSize()
  204456. {
  204457. return 1024;
  204458. }
  204459. const String open (const BigInteger& inputChannels,
  204460. const BigInteger& outputChannels,
  204461. double sampleRate,
  204462. int bufferSize)
  204463. {
  204464. close();
  204465. lastError = String::empty;
  204466. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204467. // xxx set up channel mapping
  204468. activeOutputChans = outputChannels;
  204469. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204470. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204471. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204472. activeInputChans = inputChannels;
  204473. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204474. numInputChannels = activeInputChans.countNumberOfSetBits();
  204475. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204476. AudioSessionSetActive (true);
  204477. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204478. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204479. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204480. fixAudioRouteIfSetToReceiver();
  204481. updateDeviceInfo();
  204482. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204483. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204484. actualBufferSize = preferredBufferSize;
  204485. prepareFloatBuffers();
  204486. isRunning = true;
  204487. propertyChanged (0, 0, 0); // creates and starts the AU
  204488. lastError = audioUnit != 0 ? "" : "Couldn't open the device";
  204489. return lastError;
  204490. }
  204491. void close()
  204492. {
  204493. if (isRunning)
  204494. {
  204495. isRunning = false;
  204496. AudioSessionSetActive (false);
  204497. if (audioUnit != 0)
  204498. {
  204499. AudioComponentInstanceDispose (audioUnit);
  204500. audioUnit = 0;
  204501. }
  204502. }
  204503. }
  204504. bool isOpen()
  204505. {
  204506. return isRunning;
  204507. }
  204508. int getCurrentBufferSizeSamples()
  204509. {
  204510. return actualBufferSize;
  204511. }
  204512. double getCurrentSampleRate()
  204513. {
  204514. return sampleRate;
  204515. }
  204516. int getCurrentBitDepth()
  204517. {
  204518. return 16;
  204519. }
  204520. const BigInteger getActiveOutputChannels() const
  204521. {
  204522. return activeOutputChans;
  204523. }
  204524. const BigInteger getActiveInputChannels() const
  204525. {
  204526. return activeInputChans;
  204527. }
  204528. int getOutputLatencyInSamples()
  204529. {
  204530. return 0; //xxx
  204531. }
  204532. int getInputLatencyInSamples()
  204533. {
  204534. return 0; //xxx
  204535. }
  204536. void start (AudioIODeviceCallback* callback_)
  204537. {
  204538. if (isRunning && callback != callback_)
  204539. {
  204540. if (callback_ != 0)
  204541. callback_->audioDeviceAboutToStart (this);
  204542. const ScopedLock sl (callbackLock);
  204543. callback = callback_;
  204544. }
  204545. }
  204546. void stop()
  204547. {
  204548. if (isRunning)
  204549. {
  204550. AudioIODeviceCallback* lastCallback;
  204551. {
  204552. const ScopedLock sl (callbackLock);
  204553. lastCallback = callback;
  204554. callback = 0;
  204555. }
  204556. if (lastCallback != 0)
  204557. lastCallback->audioDeviceStopped();
  204558. }
  204559. }
  204560. bool isPlaying()
  204561. {
  204562. return isRunning && callback != 0;
  204563. }
  204564. const String getLastError()
  204565. {
  204566. return lastError;
  204567. }
  204568. private:
  204569. CriticalSection callbackLock;
  204570. Float64 sampleRate;
  204571. int numInputChannels, numOutputChannels;
  204572. int preferredBufferSize;
  204573. int actualBufferSize;
  204574. bool isRunning;
  204575. String lastError;
  204576. AudioStreamBasicDescription format;
  204577. AudioUnit audioUnit;
  204578. UInt32 audioInputIsAvailable;
  204579. AudioIODeviceCallback* callback;
  204580. BigInteger activeOutputChans, activeInputChans;
  204581. AudioSampleBuffer floatData;
  204582. float* inputChannels[3];
  204583. float* outputChannels[3];
  204584. bool monoInputChannelNumber, monoOutputChannelNumber;
  204585. void prepareFloatBuffers()
  204586. {
  204587. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204588. zerostruct (inputChannels);
  204589. zerostruct (outputChannels);
  204590. for (int i = 0; i < numInputChannels; ++i)
  204591. inputChannels[i] = floatData.getSampleData (i);
  204592. for (int i = 0; i < numOutputChannels; ++i)
  204593. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204594. }
  204595. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204596. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204597. {
  204598. OSStatus err = noErr;
  204599. if (audioInputIsAvailable)
  204600. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204601. const ScopedLock sl (callbackLock);
  204602. if (callback != 0)
  204603. {
  204604. if (audioInputIsAvailable && numInputChannels > 0)
  204605. {
  204606. short* shortData = (short*) ioData->mBuffers[0].mData;
  204607. if (numInputChannels >= 2)
  204608. {
  204609. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204610. {
  204611. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204612. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204613. }
  204614. }
  204615. else
  204616. {
  204617. if (monoInputChannelNumber > 0)
  204618. ++shortData;
  204619. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204620. {
  204621. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204622. ++shortData;
  204623. }
  204624. }
  204625. }
  204626. else
  204627. {
  204628. for (int i = numInputChannels; --i >= 0;)
  204629. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204630. }
  204631. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204632. outputChannels, numOutputChannels,
  204633. (int) inNumberFrames);
  204634. short* shortData = (short*) ioData->mBuffers[0].mData;
  204635. int n = 0;
  204636. if (numOutputChannels >= 2)
  204637. {
  204638. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204639. {
  204640. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204641. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204642. }
  204643. }
  204644. else if (numOutputChannels == 1)
  204645. {
  204646. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204647. {
  204648. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204649. shortData [n++] = s;
  204650. shortData [n++] = s;
  204651. }
  204652. }
  204653. else
  204654. {
  204655. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204656. }
  204657. }
  204658. else
  204659. {
  204660. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204661. }
  204662. return err;
  204663. }
  204664. void updateDeviceInfo()
  204665. {
  204666. UInt32 size = sizeof (sampleRate);
  204667. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204668. size = sizeof (audioInputIsAvailable);
  204669. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204670. }
  204671. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204672. {
  204673. if (! isRunning)
  204674. return;
  204675. if (inPropertyValue != 0)
  204676. {
  204677. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204678. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204679. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204680. SInt32 routeChangeReason;
  204681. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204682. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204683. fixAudioRouteIfSetToReceiver();
  204684. }
  204685. updateDeviceInfo();
  204686. createAudioUnit();
  204687. AudioSessionSetActive (true);
  204688. if (audioUnit != 0)
  204689. {
  204690. UInt32 formatSize = sizeof (format);
  204691. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204692. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204693. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204694. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204695. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204696. AudioOutputUnitStart (audioUnit);
  204697. }
  204698. }
  204699. void interruptionListener (UInt32 inInterruption)
  204700. {
  204701. if (inInterruption == kAudioSessionEndInterruption)
  204702. {
  204703. isRunning = true;
  204704. AudioSessionSetActive (true);
  204705. AudioOutputUnitStart (audioUnit);
  204706. }
  204707. }
  204708. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204709. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204710. {
  204711. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204712. }
  204713. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204714. {
  204715. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204716. }
  204717. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204718. {
  204719. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204720. }
  204721. void resetFormat (const int numChannels)
  204722. {
  204723. memset (&format, 0, sizeof (format));
  204724. format.mFormatID = kAudioFormatLinearPCM;
  204725. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204726. format.mBitsPerChannel = 8 * sizeof (short);
  204727. format.mChannelsPerFrame = 2;
  204728. format.mFramesPerPacket = 1;
  204729. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204730. }
  204731. bool createAudioUnit()
  204732. {
  204733. if (audioUnit != 0)
  204734. {
  204735. AudioComponentInstanceDispose (audioUnit);
  204736. audioUnit = 0;
  204737. }
  204738. resetFormat (2);
  204739. AudioComponentDescription desc;
  204740. desc.componentType = kAudioUnitType_Output;
  204741. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204742. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204743. desc.componentFlags = 0;
  204744. desc.componentFlagsMask = 0;
  204745. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204746. AudioComponentInstanceNew (comp, &audioUnit);
  204747. if (audioUnit == 0)
  204748. return false;
  204749. const UInt32 one = 1;
  204750. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204751. AudioChannelLayout layout;
  204752. layout.mChannelBitmap = 0;
  204753. layout.mNumberChannelDescriptions = 0;
  204754. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204755. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204756. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204757. AURenderCallbackStruct inputProc;
  204758. inputProc.inputProc = processStatic;
  204759. inputProc.inputProcRefCon = this;
  204760. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204761. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204762. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204763. AudioUnitInitialize (audioUnit);
  204764. return true;
  204765. }
  204766. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204767. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204768. static void fixAudioRouteIfSetToReceiver()
  204769. {
  204770. CFStringRef audioRoute = 0;
  204771. UInt32 propertySize = sizeof (audioRoute);
  204772. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204773. {
  204774. NSString* route = (NSString*) audioRoute;
  204775. //DBG ("audio route: " + nsStringToJuce (route));
  204776. if ([route hasPrefix: @"Receiver"])
  204777. {
  204778. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204779. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204780. }
  204781. CFRelease (audioRoute);
  204782. }
  204783. }
  204784. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204785. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204786. };
  204787. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204788. {
  204789. public:
  204790. IPhoneAudioIODeviceType()
  204791. : AudioIODeviceType ("iPhone Audio")
  204792. {
  204793. }
  204794. ~IPhoneAudioIODeviceType()
  204795. {
  204796. }
  204797. void scanForDevices()
  204798. {
  204799. }
  204800. const StringArray getDeviceNames (bool wantInputNames) const
  204801. {
  204802. StringArray s;
  204803. s.add ("iPhone Audio");
  204804. return s;
  204805. }
  204806. int getDefaultDeviceIndex (bool forInput) const
  204807. {
  204808. return 0;
  204809. }
  204810. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  204811. {
  204812. return device != 0 ? 0 : -1;
  204813. }
  204814. bool hasSeparateInputsAndOutputs() const { return false; }
  204815. AudioIODevice* createDevice (const String& outputDeviceName,
  204816. const String& inputDeviceName)
  204817. {
  204818. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204819. {
  204820. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204821. : inputDeviceName);
  204822. }
  204823. return 0;
  204824. }
  204825. juce_UseDebuggingNewOperator
  204826. private:
  204827. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204828. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204829. };
  204830. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204831. {
  204832. return new IPhoneAudioIODeviceType();
  204833. }
  204834. #endif
  204835. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204836. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204837. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204838. // compiled on its own).
  204839. #if JUCE_INCLUDED_FILE
  204840. #if JUCE_MAC
  204841. #undef log
  204842. #define log(a) Logger::writeToLog(a)
  204843. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204844. {
  204845. if (err == noErr)
  204846. return true;
  204847. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  204848. jassertfalse
  204849. return false;
  204850. }
  204851. #undef OK
  204852. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204853. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204854. {
  204855. String result;
  204856. CFStringRef str = 0;
  204857. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204858. if (str != 0)
  204859. {
  204860. result = PlatformUtilities::cfStringToJuceString (str);
  204861. CFRelease (str);
  204862. str = 0;
  204863. }
  204864. MIDIEntityRef entity = 0;
  204865. MIDIEndpointGetEntity (endpoint, &entity);
  204866. if (entity == 0)
  204867. return result; // probably virtual
  204868. if (result.isEmpty())
  204869. {
  204870. // endpoint name has zero length - try the entity
  204871. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204872. if (str != 0)
  204873. {
  204874. result += PlatformUtilities::cfStringToJuceString (str);
  204875. CFRelease (str);
  204876. str = 0;
  204877. }
  204878. }
  204879. // now consider the device's name
  204880. MIDIDeviceRef device = 0;
  204881. MIDIEntityGetDevice (entity, &device);
  204882. if (device == 0)
  204883. return result;
  204884. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204885. if (str != 0)
  204886. {
  204887. const String s (PlatformUtilities::cfStringToJuceString (str));
  204888. CFRelease (str);
  204889. // if an external device has only one entity, throw away
  204890. // the endpoint name and just use the device name
  204891. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204892. {
  204893. result = s;
  204894. }
  204895. else if (! result.startsWithIgnoreCase (s))
  204896. {
  204897. // prepend the device name to the entity name
  204898. result = (s + " " + result).trimEnd();
  204899. }
  204900. }
  204901. return result;
  204902. }
  204903. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  204904. {
  204905. String result;
  204906. // Does the endpoint have connections?
  204907. CFDataRef connections = 0;
  204908. int numConnections = 0;
  204909. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  204910. if (connections != 0)
  204911. {
  204912. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  204913. if (numConnections > 0)
  204914. {
  204915. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  204916. for (int i = 0; i < numConnections; ++i, ++pid)
  204917. {
  204918. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  204919. MIDIObjectRef connObject;
  204920. MIDIObjectType connObjectType;
  204921. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  204922. if (err == noErr)
  204923. {
  204924. String s;
  204925. if (connObjectType == kMIDIObjectType_ExternalSource
  204926. || connObjectType == kMIDIObjectType_ExternalDestination)
  204927. {
  204928. // Connected to an external device's endpoint (10.3 and later).
  204929. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  204930. }
  204931. else
  204932. {
  204933. // Connected to an external device (10.2) (or something else, catch-all)
  204934. CFStringRef str = 0;
  204935. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  204936. if (str != 0)
  204937. {
  204938. s = PlatformUtilities::cfStringToJuceString (str);
  204939. CFRelease (str);
  204940. }
  204941. }
  204942. if (s.isNotEmpty())
  204943. {
  204944. if (result.isNotEmpty())
  204945. result += ", ";
  204946. result += s;
  204947. }
  204948. }
  204949. }
  204950. }
  204951. CFRelease (connections);
  204952. }
  204953. if (result.isNotEmpty())
  204954. return result;
  204955. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  204956. return getEndpointName (endpoint, false);
  204957. }
  204958. const StringArray MidiOutput::getDevices()
  204959. {
  204960. StringArray s;
  204961. const ItemCount num = MIDIGetNumberOfDestinations();
  204962. for (ItemCount i = 0; i < num; ++i)
  204963. {
  204964. MIDIEndpointRef dest = MIDIGetDestination (i);
  204965. if (dest != 0)
  204966. {
  204967. String name (getConnectedEndpointName (dest));
  204968. if (name.isEmpty())
  204969. name = "<error>";
  204970. s.add (name);
  204971. }
  204972. else
  204973. {
  204974. s.add ("<error>");
  204975. }
  204976. }
  204977. return s;
  204978. }
  204979. int MidiOutput::getDefaultDeviceIndex()
  204980. {
  204981. return 0;
  204982. }
  204983. static MIDIClientRef globalMidiClient;
  204984. static bool hasGlobalClientBeenCreated = false;
  204985. static bool makeSureClientExists()
  204986. {
  204987. if (! hasGlobalClientBeenCreated)
  204988. {
  204989. String name ("JUCE");
  204990. if (JUCEApplication::getInstance() != 0)
  204991. name = JUCEApplication::getInstance()->getApplicationName();
  204992. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  204993. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  204994. CFRelease (appName);
  204995. }
  204996. return hasGlobalClientBeenCreated;
  204997. }
  204998. class MidiPortAndEndpoint
  204999. {
  205000. public:
  205001. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205002. : port (port_), endPoint (endPoint_)
  205003. {
  205004. }
  205005. ~MidiPortAndEndpoint()
  205006. {
  205007. if (port != 0)
  205008. MIDIPortDispose (port);
  205009. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205010. MIDIEndpointDispose (endPoint);
  205011. }
  205012. MIDIPortRef port;
  205013. MIDIEndpointRef endPoint;
  205014. };
  205015. MidiOutput* MidiOutput::openDevice (int index)
  205016. {
  205017. MidiOutput* mo = 0;
  205018. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205019. {
  205020. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205021. CFStringRef pname;
  205022. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205023. {
  205024. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  205025. if (makeSureClientExists())
  205026. {
  205027. MIDIPortRef port;
  205028. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205029. {
  205030. mo = new MidiOutput();
  205031. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  205032. }
  205033. }
  205034. CFRelease (pname);
  205035. }
  205036. }
  205037. return mo;
  205038. }
  205039. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205040. {
  205041. MidiOutput* mo = 0;
  205042. if (makeSureClientExists())
  205043. {
  205044. MIDIEndpointRef endPoint;
  205045. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205046. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205047. {
  205048. mo = new MidiOutput();
  205049. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  205050. }
  205051. CFRelease (name);
  205052. }
  205053. return mo;
  205054. }
  205055. MidiOutput::~MidiOutput()
  205056. {
  205057. delete (MidiPortAndEndpoint*) internal;
  205058. }
  205059. void MidiOutput::reset()
  205060. {
  205061. }
  205062. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205063. {
  205064. return false;
  205065. }
  205066. void MidiOutput::setVolume (float leftVol, float rightVol)
  205067. {
  205068. }
  205069. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205070. {
  205071. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205072. if (message.isSysEx())
  205073. {
  205074. const int maxPacketSize = 256;
  205075. int pos = 0, bytesLeft = message.getRawDataSize();
  205076. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205077. HeapBlock <MIDIPacketList> packets;
  205078. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205079. packets->numPackets = numPackets;
  205080. MIDIPacket* p = packets->packet;
  205081. for (int i = 0; i < numPackets; ++i)
  205082. {
  205083. p->timeStamp = 0;
  205084. p->length = jmin (maxPacketSize, bytesLeft);
  205085. memcpy (p->data, message.getRawData() + pos, p->length);
  205086. pos += p->length;
  205087. bytesLeft -= p->length;
  205088. p = MIDIPacketNext (p);
  205089. }
  205090. if (mpe->port != 0)
  205091. MIDISend (mpe->port, mpe->endPoint, packets);
  205092. else
  205093. MIDIReceived (mpe->endPoint, packets);
  205094. }
  205095. else
  205096. {
  205097. MIDIPacketList packets;
  205098. packets.numPackets = 1;
  205099. packets.packet[0].timeStamp = 0;
  205100. packets.packet[0].length = message.getRawDataSize();
  205101. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205102. if (mpe->port != 0)
  205103. MIDISend (mpe->port, mpe->endPoint, &packets);
  205104. else
  205105. MIDIReceived (mpe->endPoint, &packets);
  205106. }
  205107. }
  205108. const StringArray MidiInput::getDevices()
  205109. {
  205110. StringArray s;
  205111. const ItemCount num = MIDIGetNumberOfSources();
  205112. for (ItemCount i = 0; i < num; ++i)
  205113. {
  205114. MIDIEndpointRef source = MIDIGetSource (i);
  205115. if (source != 0)
  205116. {
  205117. String name (getConnectedEndpointName (source));
  205118. if (name.isEmpty())
  205119. name = "<error>";
  205120. s.add (name);
  205121. }
  205122. else
  205123. {
  205124. s.add ("<error>");
  205125. }
  205126. }
  205127. return s;
  205128. }
  205129. int MidiInput::getDefaultDeviceIndex()
  205130. {
  205131. return 0;
  205132. }
  205133. struct MidiPortAndCallback
  205134. {
  205135. MidiInput* input;
  205136. MidiPortAndEndpoint* portAndEndpoint;
  205137. MidiInputCallback* callback;
  205138. MemoryBlock pendingData;
  205139. int pendingBytes;
  205140. double pendingDataTime;
  205141. bool active;
  205142. void processSysex (const uint8*& d, int& size, const double time)
  205143. {
  205144. if (*d == 0xf0)
  205145. {
  205146. pendingBytes = 0;
  205147. pendingDataTime = time;
  205148. }
  205149. pendingData.ensureSize (pendingBytes + size, false);
  205150. uint8* totalMessage = (uint8*) pendingData.getData();
  205151. uint8* dest = totalMessage + pendingBytes;
  205152. while (size > 0)
  205153. {
  205154. if (pendingBytes > 0 && *d >= 0x80)
  205155. {
  205156. if (*d >= 0xfa || *d == 0xf8)
  205157. {
  205158. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205159. ++d;
  205160. --size;
  205161. }
  205162. else
  205163. {
  205164. if (*d == 0xf7)
  205165. {
  205166. *dest++ = *d++;
  205167. pendingBytes++;
  205168. --size;
  205169. }
  205170. break;
  205171. }
  205172. }
  205173. else
  205174. {
  205175. *dest++ = *d++;
  205176. pendingBytes++;
  205177. --size;
  205178. }
  205179. }
  205180. if (totalMessage [pendingBytes - 1] == 0xf7)
  205181. {
  205182. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205183. pendingBytes = 0;
  205184. }
  205185. else
  205186. {
  205187. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205188. }
  205189. }
  205190. };
  205191. namespace CoreMidiCallbacks
  205192. {
  205193. static CriticalSection callbackLock;
  205194. static VoidArray activeCallbacks;
  205195. }
  205196. static void midiInputProc (const MIDIPacketList* pktlist,
  205197. void* readProcRefCon,
  205198. void* srcConnRefCon)
  205199. {
  205200. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205201. const double originalTime = time;
  205202. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205203. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205204. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205205. {
  205206. const MIDIPacket* packet = &pktlist->packet[0];
  205207. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205208. {
  205209. const uint8* d = (const uint8*) (packet->data);
  205210. int size = packet->length;
  205211. while (size > 0)
  205212. {
  205213. time = originalTime;
  205214. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205215. {
  205216. mpc->processSysex (d, size, time);
  205217. }
  205218. else
  205219. {
  205220. int used = 0;
  205221. const MidiMessage m (d, size, used, 0, time);
  205222. if (used <= 0)
  205223. {
  205224. jassertfalse // malformed midi message
  205225. break;
  205226. }
  205227. else
  205228. {
  205229. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205230. }
  205231. size -= used;
  205232. d += used;
  205233. }
  205234. }
  205235. packet = MIDIPacketNext (packet);
  205236. }
  205237. }
  205238. }
  205239. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205240. {
  205241. MidiInput* mi = 0;
  205242. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205243. {
  205244. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205245. if (endPoint != 0)
  205246. {
  205247. CFStringRef pname;
  205248. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205249. {
  205250. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  205251. if (makeSureClientExists())
  205252. {
  205253. MIDIPortRef port;
  205254. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205255. mpc->active = false;
  205256. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205257. {
  205258. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205259. {
  205260. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205261. mpc->callback = callback;
  205262. mpc->pendingBytes = 0;
  205263. mpc->pendingData.ensureSize (128);
  205264. mi = new MidiInput (getDevices() [index]);
  205265. mpc->input = mi;
  205266. mi->internal = mpc;
  205267. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205268. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205269. }
  205270. else
  205271. {
  205272. OK (MIDIPortDispose (port));
  205273. }
  205274. }
  205275. }
  205276. }
  205277. CFRelease (pname);
  205278. }
  205279. }
  205280. return mi;
  205281. }
  205282. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205283. {
  205284. MidiInput* mi = 0;
  205285. if (makeSureClientExists())
  205286. {
  205287. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205288. mpc->active = false;
  205289. MIDIEndpointRef endPoint;
  205290. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205291. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205292. {
  205293. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205294. mpc->callback = callback;
  205295. mpc->pendingBytes = 0;
  205296. mpc->pendingData.ensureSize (128);
  205297. mi = new MidiInput (deviceName);
  205298. mpc->input = mi;
  205299. mi->internal = mpc;
  205300. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205301. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205302. }
  205303. CFRelease (name);
  205304. }
  205305. return mi;
  205306. }
  205307. MidiInput::MidiInput (const String& name_)
  205308. : name (name_)
  205309. {
  205310. }
  205311. MidiInput::~MidiInput()
  205312. {
  205313. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205314. mpc->active = false;
  205315. {
  205316. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205317. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205318. }
  205319. if (mpc->portAndEndpoint->port != 0)
  205320. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205321. delete mpc->portAndEndpoint;
  205322. delete mpc;
  205323. }
  205324. void MidiInput::start()
  205325. {
  205326. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205327. ((MidiPortAndCallback*) internal)->active = true;
  205328. }
  205329. void MidiInput::stop()
  205330. {
  205331. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205332. ((MidiPortAndCallback*) internal)->active = false;
  205333. }
  205334. #undef log
  205335. #else
  205336. MidiOutput::~MidiOutput()
  205337. {
  205338. }
  205339. void MidiOutput::reset()
  205340. {
  205341. }
  205342. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205343. {
  205344. return false;
  205345. }
  205346. void MidiOutput::setVolume (float leftVol, float rightVol)
  205347. {
  205348. }
  205349. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205350. {
  205351. }
  205352. const StringArray MidiOutput::getDevices()
  205353. {
  205354. return StringArray();
  205355. }
  205356. MidiOutput* MidiOutput::openDevice (int index)
  205357. {
  205358. return 0;
  205359. }
  205360. const StringArray MidiInput::getDevices()
  205361. {
  205362. return StringArray();
  205363. }
  205364. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205365. {
  205366. return 0;
  205367. }
  205368. #endif
  205369. #endif
  205370. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205371. #else
  205372. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205373. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205374. // compiled on its own).
  205375. #if JUCE_INCLUDED_FILE
  205376. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205377. #define SUPPORT_10_4_FONTS 1
  205378. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205379. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205380. #define SUPPORT_ONLY_10_4_FONTS 1
  205381. #endif
  205382. END_JUCE_NAMESPACE
  205383. @interface NSFont (PrivateHack)
  205384. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205385. @end
  205386. BEGIN_JUCE_NAMESPACE
  205387. #endif
  205388. class MacTypeface : public Typeface
  205389. {
  205390. public:
  205391. MacTypeface (const Font& font)
  205392. : Typeface (font.getTypefaceName())
  205393. {
  205394. const ScopedAutoReleasePool pool;
  205395. renderingTransform = CGAffineTransformIdentity;
  205396. bool needsItalicTransform = false;
  205397. #if JUCE_IPHONE
  205398. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205399. if (font.isItalic() || font.isBold())
  205400. {
  205401. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205402. for (NSString* i in familyFonts)
  205403. {
  205404. const String fn (nsStringToJuce (i));
  205405. const String afterDash (fn.fromFirstOccurrenceOf ("-", false, false));
  205406. const bool probablyBold = afterDash.containsIgnoreCase ("bold") || fn.endsWithIgnoreCase ("bold");
  205407. const bool probablyItalic = afterDash.containsIgnoreCase ("oblique")
  205408. || afterDash.containsIgnoreCase ("italic")
  205409. || fn.endsWithIgnoreCase ("oblique")
  205410. || fn.endsWithIgnoreCase ("italic");
  205411. if (probablyBold == font.isBold()
  205412. && probablyItalic == font.isItalic())
  205413. {
  205414. fontName = i;
  205415. needsItalicTransform = false;
  205416. break;
  205417. }
  205418. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205419. {
  205420. fontName = i;
  205421. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205422. }
  205423. }
  205424. if (needsItalicTransform)
  205425. renderingTransform.c = 0.15f;
  205426. }
  205427. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205428. const int ascender = abs (CGFontGetAscent (fontRef));
  205429. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205430. ascent = ascender / totalHeight;
  205431. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205432. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205433. #else
  205434. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205435. if (font.isItalic())
  205436. {
  205437. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205438. toHaveTrait: NSItalicFontMask];
  205439. if (newFont == nsFont)
  205440. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205441. nsFont = newFont;
  205442. }
  205443. if (font.isBold())
  205444. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205445. [nsFont retain];
  205446. ascent = fabsf ((float) [nsFont ascender]);
  205447. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205448. ascent /= totalSize;
  205449. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205450. if (needsItalicTransform)
  205451. {
  205452. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205453. renderingTransform.c = 0.15f;
  205454. }
  205455. #if SUPPORT_ONLY_10_4_FONTS
  205456. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205457. if (atsFont == 0)
  205458. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205459. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  205460. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205461. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205462. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205463. #else
  205464. #if SUPPORT_10_4_FONTS
  205465. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205466. {
  205467. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205468. if (atsFont == 0)
  205469. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205470. fontRef = CGFontCreateWithPlatformFont (&atsFont);
  205471. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205472. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205473. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205474. }
  205475. else
  205476. #endif
  205477. {
  205478. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205479. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205480. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205481. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205482. }
  205483. #endif
  205484. #endif
  205485. }
  205486. ~MacTypeface()
  205487. {
  205488. #if ! JUCE_IPHONE
  205489. [nsFont release];
  205490. #endif
  205491. if (fontRef != 0)
  205492. CGFontRelease (fontRef);
  205493. }
  205494. float getAscent() const
  205495. {
  205496. return ascent;
  205497. }
  205498. float getDescent() const
  205499. {
  205500. return 1.0f - ascent;
  205501. }
  205502. float getStringWidth (const String& text)
  205503. {
  205504. if (fontRef == 0 || text.isEmpty())
  205505. return 0;
  205506. const int length = text.length();
  205507. HeapBlock <CGGlyph> glyphs;
  205508. createGlyphsForString (text, length, glyphs);
  205509. float x = 0;
  205510. #if SUPPORT_ONLY_10_4_FONTS
  205511. HeapBlock <NSSize> advances (length);
  205512. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205513. for (int i = 0; i < length; ++i)
  205514. x += advances[i].width;
  205515. #else
  205516. #if SUPPORT_10_4_FONTS
  205517. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205518. {
  205519. HeapBlock <NSSize> advances (length);
  205520. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast<NSGlyph*> (glyphs.getData()) count: length];
  205521. for (int i = 0; i < length; ++i)
  205522. x += advances[i].width;
  205523. }
  205524. else
  205525. #endif
  205526. {
  205527. HeapBlock <int> advances (length);
  205528. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205529. for (int i = 0; i < length; ++i)
  205530. x += advances[i];
  205531. }
  205532. #endif
  205533. return x * unitsToHeightScaleFactor;
  205534. }
  205535. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205536. {
  205537. xOffsets.add (0);
  205538. if (fontRef == 0 || text.isEmpty())
  205539. return;
  205540. const int length = text.length();
  205541. HeapBlock <CGGlyph> glyphs;
  205542. createGlyphsForString (text, length, glyphs);
  205543. #if SUPPORT_ONLY_10_4_FONTS
  205544. HeapBlock <NSSize> advances (length);
  205545. [nsFont getAdvancements: advances forGlyphs: reinterpret_cast <NSGlyph*> (glyphs.getData()) count: length];
  205546. int x = 0;
  205547. for (int i = 0; i < length; ++i)
  205548. {
  205549. x += advances[i].width;
  205550. xOffsets.add (x * unitsToHeightScaleFactor);
  205551. resultGlyphs.add (reinterpret_cast <NSGlyph*> (glyphs.getData())[i]);
  205552. }
  205553. #else
  205554. #if SUPPORT_10_4_FONTS
  205555. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205556. {
  205557. HeapBlock <NSSize> advances (length);
  205558. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205559. [nsFont getAdvancements: advances forGlyphs: nsGlyphs count: length];
  205560. float x = 0;
  205561. for (int i = 0; i < length; ++i)
  205562. {
  205563. x += advances[i].width;
  205564. xOffsets.add (x * unitsToHeightScaleFactor);
  205565. resultGlyphs.add (nsGlyphs[i]);
  205566. }
  205567. }
  205568. else
  205569. #endif
  205570. {
  205571. HeapBlock <int> advances (length);
  205572. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205573. {
  205574. int x = 0;
  205575. for (int i = 0; i < length; ++i)
  205576. {
  205577. x += advances [i];
  205578. xOffsets.add (x * unitsToHeightScaleFactor);
  205579. resultGlyphs.add (glyphs[i]);
  205580. }
  205581. }
  205582. }
  205583. #endif
  205584. }
  205585. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205586. {
  205587. #if JUCE_IPHONE
  205588. return false;
  205589. #else
  205590. if (nsFont == 0)
  205591. return false;
  205592. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205593. jassert (path.isEmpty());
  205594. const ScopedAutoReleasePool pool;
  205595. NSBezierPath* bez = [NSBezierPath bezierPath];
  205596. [bez moveToPoint: NSMakePoint (0, 0)];
  205597. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205598. inFont: nsFont];
  205599. for (int i = 0; i < [bez elementCount]; ++i)
  205600. {
  205601. NSPoint p[3];
  205602. switch ([bez elementAtIndex: i associatedPoints: p])
  205603. {
  205604. case NSMoveToBezierPathElement:
  205605. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205606. break;
  205607. case NSLineToBezierPathElement:
  205608. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205609. break;
  205610. case NSCurveToBezierPathElement:
  205611. 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);
  205612. break;
  205613. case NSClosePathBezierPathElement:
  205614. path.closeSubPath();
  205615. break;
  205616. default:
  205617. jassertfalse
  205618. break;
  205619. }
  205620. }
  205621. path.applyTransform (pathTransform);
  205622. return true;
  205623. #endif
  205624. }
  205625. juce_UseDebuggingNewOperator
  205626. CGFontRef fontRef;
  205627. float fontHeightToCGSizeFactor;
  205628. CGAffineTransform renderingTransform;
  205629. private:
  205630. float ascent, unitsToHeightScaleFactor;
  205631. #if JUCE_IPHONE
  205632. #else
  205633. NSFont* nsFont;
  205634. AffineTransform pathTransform;
  205635. #endif
  205636. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205637. {
  205638. #if SUPPORT_10_4_FONTS
  205639. #if ! SUPPORT_ONLY_10_4_FONTS
  205640. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205641. #endif
  205642. {
  205643. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205644. NSGlyph* const nsGlyphs = reinterpret_cast<NSGlyph*> (glyphs.getData());
  205645. for (int i = 0; i < length; ++i)
  205646. nsGlyphs[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205647. return;
  205648. }
  205649. #endif
  205650. #if ! SUPPORT_ONLY_10_4_FONTS
  205651. if (charToGlyphMapper == 0)
  205652. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205653. glyphs.malloc (length);
  205654. for (int i = 0; i < length; ++i)
  205655. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205656. #endif
  205657. }
  205658. #if ! SUPPORT_ONLY_10_4_FONTS
  205659. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205660. class CharToGlyphMapper
  205661. {
  205662. public:
  205663. CharToGlyphMapper (CGFontRef fontRef)
  205664. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205665. idRangeOffset (0), glyphIndexes (0)
  205666. {
  205667. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205668. if (cmapTable != 0)
  205669. {
  205670. const int numSubtables = getValue16 (cmapTable, 2);
  205671. for (int i = 0; i < numSubtables; ++i)
  205672. {
  205673. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205674. {
  205675. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205676. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205677. {
  205678. const int length = getValue16 (cmapTable, offset + 2);
  205679. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205680. segCount = segCountX2 / 2;
  205681. const int endCodeOffset = offset + 14;
  205682. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205683. const int idDeltaOffset = startCodeOffset + segCountX2;
  205684. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205685. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205686. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205687. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205688. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205689. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205690. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205691. }
  205692. break;
  205693. }
  205694. }
  205695. CFRelease (cmapTable);
  205696. }
  205697. }
  205698. ~CharToGlyphMapper()
  205699. {
  205700. if (endCode != 0)
  205701. {
  205702. CFRelease (endCode);
  205703. CFRelease (startCode);
  205704. CFRelease (idDelta);
  205705. CFRelease (idRangeOffset);
  205706. CFRelease (glyphIndexes);
  205707. }
  205708. }
  205709. int getGlyphForCharacter (const juce_wchar c) const
  205710. {
  205711. for (int i = 0; i < segCount; ++i)
  205712. {
  205713. if (getValue16 (endCode, i * 2) >= c)
  205714. {
  205715. const int start = getValue16 (startCode, i * 2);
  205716. if (start > c)
  205717. break;
  205718. const int delta = getValue16 (idDelta, i * 2);
  205719. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205720. if (rangeOffset == 0)
  205721. return delta + c;
  205722. else
  205723. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205724. }
  205725. }
  205726. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205727. return jmax (-1, c - 29);
  205728. }
  205729. private:
  205730. int segCount;
  205731. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205732. static uint16 getValue16 (CFDataRef data, const int index)
  205733. {
  205734. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205735. }
  205736. static uint32 getValue32 (CFDataRef data, const int index)
  205737. {
  205738. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205739. }
  205740. };
  205741. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205742. #endif
  205743. MacTypeface (const MacTypeface&);
  205744. MacTypeface& operator= (const MacTypeface&);
  205745. };
  205746. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205747. {
  205748. return new MacTypeface (font);
  205749. }
  205750. const StringArray Font::findAllTypefaceNames()
  205751. {
  205752. StringArray names;
  205753. const ScopedAutoReleasePool pool;
  205754. #if JUCE_IPHONE
  205755. NSArray* fonts = [UIFont familyNames];
  205756. #else
  205757. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205758. #endif
  205759. for (unsigned int i = 0; i < [fonts count]; ++i)
  205760. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205761. names.sort (true);
  205762. return names;
  205763. }
  205764. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed)
  205765. {
  205766. #if JUCE_IPHONE
  205767. defaultSans = "Helvetica";
  205768. defaultSerif = "Times New Roman";
  205769. defaultFixed = "Courier New";
  205770. #else
  205771. defaultSans = "Lucida Grande";
  205772. defaultSerif = "Times New Roman";
  205773. defaultFixed = "Monaco";
  205774. #endif
  205775. }
  205776. #endif
  205777. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205778. // (must go before juce_mac_CoreGraphicsContext.mm)
  205779. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205780. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205781. // compiled on its own).
  205782. #if JUCE_INCLUDED_FILE
  205783. class CoreGraphicsImage : public Image
  205784. {
  205785. public:
  205786. CoreGraphicsImage (const PixelFormat format_,
  205787. const int imageWidth_,
  205788. const int imageHeight_,
  205789. const bool clearImage)
  205790. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205791. {
  205792. CGColorSpaceRef colourSpace = (format == Image::SingleChannel) ? CGColorSpaceCreateDeviceGray()
  205793. : CGColorSpaceCreateDeviceRGB();
  205794. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205795. colourSpace, getCGImageFlags (*this));
  205796. CGColorSpaceRelease (colourSpace);
  205797. }
  205798. ~CoreGraphicsImage()
  205799. {
  205800. CGContextRelease (context);
  205801. }
  205802. LowLevelGraphicsContext* createLowLevelContext();
  205803. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205804. {
  205805. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205806. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205807. {
  205808. return CGBitmapContextCreateImage (nativeImage->context);
  205809. }
  205810. else
  205811. {
  205812. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205813. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205814. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205815. 8, srcData.pixelStride * 8, srcData.lineStride,
  205816. colourSpace, getCGImageFlags (juceImage), provider,
  205817. 0, true, kCGRenderingIntentDefault);
  205818. CGDataProviderRelease (provider);
  205819. return imageRef;
  205820. }
  205821. }
  205822. #if JUCE_MAC
  205823. static NSImage* createNSImage (const Image& image)
  205824. {
  205825. const ScopedAutoReleasePool pool;
  205826. NSImage* im = [[NSImage alloc] init];
  205827. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205828. [im lockFocus];
  205829. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205830. CGImageRef imageRef = createImage (image, false, colourSpace);
  205831. CGColorSpaceRelease (colourSpace);
  205832. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205833. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205834. CGImageRelease (imageRef);
  205835. [im unlockFocus];
  205836. return im;
  205837. }
  205838. #endif
  205839. CGContextRef context;
  205840. private:
  205841. static CGBitmapInfo getCGImageFlags (const Image& image)
  205842. {
  205843. #if JUCE_BIG_ENDIAN
  205844. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205845. #else
  205846. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205847. #endif
  205848. }
  205849. };
  205850. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205851. {
  205852. #if USE_COREGRAPHICS_RENDERING
  205853. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205854. #else
  205855. return new Image (format, imageWidth, imageHeight, clearImage);
  205856. #endif
  205857. }
  205858. class CoreGraphicsContext : public LowLevelGraphicsContext
  205859. {
  205860. public:
  205861. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205862. : context (context_),
  205863. flipHeight (flipHeight_),
  205864. state (new SavedState()),
  205865. numGradientLookupEntries (0)
  205866. {
  205867. CGContextRetain (context);
  205868. CGContextSaveGState(context);
  205869. CGContextSetShouldSmoothFonts (context, true);
  205870. CGContextSetShouldAntialias (context, true);
  205871. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205872. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205873. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205874. gradientCallbacks.version = 0;
  205875. gradientCallbacks.evaluate = gradientCallback;
  205876. gradientCallbacks.releaseInfo = 0;
  205877. setFont (Font());
  205878. }
  205879. ~CoreGraphicsContext()
  205880. {
  205881. CGContextRestoreGState (context);
  205882. CGContextRelease (context);
  205883. CGColorSpaceRelease (rgbColourSpace);
  205884. CGColorSpaceRelease (greyColourSpace);
  205885. }
  205886. bool isVectorDevice() const { return false; }
  205887. void setOrigin (int x, int y)
  205888. {
  205889. CGContextTranslateCTM (context, x, -y);
  205890. }
  205891. bool clipToRectangle (const Rectangle<int>& r)
  205892. {
  205893. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205894. return ! isClipEmpty();
  205895. }
  205896. bool clipToRectangleList (const RectangleList& clipRegion)
  205897. {
  205898. if (clipRegion.isEmpty())
  205899. {
  205900. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205901. return false;
  205902. }
  205903. else
  205904. {
  205905. const int numRects = clipRegion.getNumRectangles();
  205906. HeapBlock <CGRect> rects (numRects);
  205907. for (int i = 0; i < numRects; ++i)
  205908. {
  205909. const Rectangle<int>& r = clipRegion.getRectangle(i);
  205910. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  205911. }
  205912. CGContextClipToRects (context, rects, numRects);
  205913. return ! isClipEmpty();
  205914. }
  205915. }
  205916. void excludeClipRectangle (const Rectangle<int>& r)
  205917. {
  205918. RectangleList remaining (getClipBounds());
  205919. remaining.subtract (r);
  205920. clipToRectangleList (remaining);
  205921. }
  205922. void clipToPath (const Path& path, const AffineTransform& transform)
  205923. {
  205924. createPath (path, transform);
  205925. CGContextClip (context);
  205926. }
  205927. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  205928. {
  205929. if (! transform.isSingularity())
  205930. {
  205931. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  205932. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  205933. flip();
  205934. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  205935. applyTransform (t);
  205936. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  205937. CGContextClipToMask (context, r, image);
  205938. applyTransform (t.inverted());
  205939. flip();
  205940. CGImageRelease (image);
  205941. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  205942. }
  205943. }
  205944. bool clipRegionIntersects (const Rectangle<int>& r)
  205945. {
  205946. return getClipBounds().intersects (r);
  205947. }
  205948. const Rectangle<int> getClipBounds() const
  205949. {
  205950. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  205951. return Rectangle<int> (roundToInt (bounds.origin.x),
  205952. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  205953. roundToInt (bounds.size.width),
  205954. roundToInt (bounds.size.height));
  205955. }
  205956. bool isClipEmpty() const
  205957. {
  205958. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  205959. }
  205960. void saveState()
  205961. {
  205962. CGContextSaveGState (context);
  205963. stateStack.add (new SavedState (*state));
  205964. }
  205965. void restoreState()
  205966. {
  205967. CGContextRestoreGState (context);
  205968. SavedState* const top = stateStack.getLast();
  205969. if (top != 0)
  205970. {
  205971. state = top;
  205972. stateStack.removeLast (1, false);
  205973. }
  205974. else
  205975. {
  205976. jassertfalse // trying to pop with an empty stack!
  205977. }
  205978. }
  205979. void setFill (const FillType& fillType)
  205980. {
  205981. state->fillType = fillType;
  205982. if (fillType.isColour())
  205983. {
  205984. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  205985. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  205986. CGContextSetAlpha (context, 1.0f);
  205987. }
  205988. }
  205989. void setOpacity (float newOpacity)
  205990. {
  205991. state->fillType.setOpacity (newOpacity);
  205992. setFill (state->fillType);
  205993. }
  205994. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  205995. {
  205996. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  205997. ? kCGInterpolationLow
  205998. : kCGInterpolationHigh);
  205999. }
  206000. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206001. {
  206002. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206003. if (replaceExistingContents)
  206004. {
  206005. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206006. CGContextClearRect (context, cgRect);
  206007. #else
  206008. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206009. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206010. CGContextClearRect (context, cgRect);
  206011. else
  206012. #endif
  206013. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206014. #endif
  206015. fillRect (r, false);
  206016. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206017. }
  206018. else
  206019. {
  206020. if (state->fillType.isColour())
  206021. {
  206022. CGContextFillRect (context, cgRect);
  206023. }
  206024. else if (state->fillType.isGradient())
  206025. {
  206026. CGContextSaveGState (context);
  206027. CGContextClipToRect (context, cgRect);
  206028. drawGradient();
  206029. CGContextRestoreGState (context);
  206030. }
  206031. else
  206032. {
  206033. CGContextSaveGState (context);
  206034. CGContextClipToRect (context, cgRect);
  206035. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206036. CGContextRestoreGState (context);
  206037. }
  206038. }
  206039. }
  206040. void fillPath (const Path& path, const AffineTransform& transform)
  206041. {
  206042. CGContextSaveGState (context);
  206043. if (state->fillType.isColour())
  206044. {
  206045. flip();
  206046. applyTransform (transform);
  206047. createPath (path);
  206048. if (path.isUsingNonZeroWinding())
  206049. CGContextFillPath (context);
  206050. else
  206051. CGContextEOFillPath (context);
  206052. }
  206053. else
  206054. {
  206055. createPath (path, transform);
  206056. if (path.isUsingNonZeroWinding())
  206057. CGContextClip (context);
  206058. else
  206059. CGContextEOClip (context);
  206060. if (state->fillType.isGradient())
  206061. drawGradient();
  206062. else
  206063. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206064. }
  206065. CGContextRestoreGState (context);
  206066. }
  206067. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206068. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206069. {
  206070. jassert (sourceImage.getBounds().contains (srcClip));
  206071. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206072. CGImageRef image = fullImage;
  206073. if (srcClip != sourceImage.getBounds())
  206074. {
  206075. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206076. srcClip.getWidth(), srcClip.getHeight()));
  206077. CGImageRelease (fullImage);
  206078. }
  206079. CGContextSaveGState (context);
  206080. CGContextSetAlpha (context, state->fillType.getOpacity());
  206081. flip();
  206082. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206083. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206084. if (fillEntireClipAsTiles)
  206085. {
  206086. #if JUCE_IPHONE
  206087. CGContextDrawTiledImage (context, imageRect, image);
  206088. #else
  206089. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206090. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206091. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206092. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206093. CGContextDrawTiledImage (context, imageRect, image);
  206094. else
  206095. #endif
  206096. {
  206097. // Fallback to manually doing a tiled fill on 10.4
  206098. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206099. const int iw = srcClip.getWidth();
  206100. const int ih = srcClip.getHeight();
  206101. int x = 0, y = 0;
  206102. while (x > clip.origin.x) x -= iw;
  206103. while (y > clip.origin.y) y -= ih;
  206104. const int right = (int) (clip.origin.x + clip.size.width);
  206105. const int bottom = (int) (clip.origin.y + clip.size.height);
  206106. while (y < bottom)
  206107. {
  206108. for (int x2 = x; x2 < right; x2 += iw)
  206109. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206110. y += ih;
  206111. }
  206112. }
  206113. #endif
  206114. }
  206115. else
  206116. {
  206117. CGContextDrawImage (context, imageRect, image);
  206118. }
  206119. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206120. CGContextRestoreGState (context);
  206121. }
  206122. void drawLine (double x1, double y1, double x2, double y2)
  206123. {
  206124. CGContextSetLineCap (context, kCGLineCapSquare);
  206125. CGContextSetLineWidth (context, 1.0f);
  206126. CGContextSetRGBStrokeColor (context,
  206127. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206128. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206129. CGPoint line[] = { { (CGFloat) x1, flipHeight - (CGFloat) y1 },
  206130. { (CGFloat) x2, flipHeight - (CGFloat) y2 } };
  206131. CGContextStrokeLineSegments (context, line, 1);
  206132. }
  206133. void drawVerticalLine (const int x, double top, double bottom)
  206134. {
  206135. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206136. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206137. #else
  206138. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206139. // the x co-ord slightly to trick it..
  206140. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206141. #endif
  206142. }
  206143. void drawHorizontalLine (const int y, double left, double right)
  206144. {
  206145. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206146. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206147. #else
  206148. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206149. // the x co-ord slightly to trick it..
  206150. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206151. #endif
  206152. }
  206153. void setFont (const Font& newFont)
  206154. {
  206155. if (state->font != newFont)
  206156. {
  206157. state->fontRef = 0;
  206158. state->font = newFont;
  206159. MacTypeface* mf = dynamic_cast <MacTypeface*> (state->font.getTypeface());
  206160. if (mf != 0)
  206161. {
  206162. state->fontRef = mf->fontRef;
  206163. CGContextSetFont (context, state->fontRef);
  206164. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206165. state->fontTransform = mf->renderingTransform;
  206166. state->fontTransform.a *= state->font.getHorizontalScale();
  206167. CGContextSetTextMatrix (context, state->fontTransform);
  206168. }
  206169. }
  206170. }
  206171. const Font getFont()
  206172. {
  206173. return state->font;
  206174. }
  206175. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206176. {
  206177. if (state->fontRef != 0 && state->fillType.isColour())
  206178. {
  206179. if (transform.isOnlyTranslation())
  206180. {
  206181. CGGlyph g = glyphNumber;
  206182. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206183. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206184. }
  206185. else
  206186. {
  206187. CGContextSaveGState (context);
  206188. flip();
  206189. applyTransform (transform);
  206190. CGAffineTransform t = state->fontTransform;
  206191. t.d = -t.d;
  206192. CGContextSetTextMatrix (context, t);
  206193. CGGlyph g = glyphNumber;
  206194. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206195. CGContextSetTextMatrix (context, state->fontTransform);
  206196. CGContextRestoreGState (context);
  206197. }
  206198. }
  206199. else
  206200. {
  206201. Path p;
  206202. Font& f = state->font;
  206203. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206204. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206205. .followedBy (transform));
  206206. }
  206207. }
  206208. private:
  206209. CGContextRef context;
  206210. const CGFloat flipHeight;
  206211. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206212. CGFunctionCallbacks gradientCallbacks;
  206213. struct SavedState
  206214. {
  206215. SavedState()
  206216. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206217. {
  206218. }
  206219. SavedState (const SavedState& other)
  206220. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206221. fontTransform (other.fontTransform)
  206222. {
  206223. }
  206224. ~SavedState()
  206225. {
  206226. }
  206227. FillType fillType;
  206228. Font font;
  206229. CGFontRef fontRef;
  206230. CGAffineTransform fontTransform;
  206231. };
  206232. ScopedPointer <SavedState> state;
  206233. OwnedArray <SavedState> stateStack;
  206234. HeapBlock <PixelARGB> gradientLookupTable;
  206235. int numGradientLookupEntries;
  206236. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206237. {
  206238. const CoreGraphicsContext* const g = static_cast <const CoreGraphicsContext*> (info);
  206239. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206240. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206241. colour.unpremultiply();
  206242. outData[0] = colour.getRed() / 255.0f;
  206243. outData[1] = colour.getGreen() / 255.0f;
  206244. outData[2] = colour.getBlue() / 255.0f;
  206245. outData[3] = colour.getAlpha() / 255.0f;
  206246. }
  206247. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206248. {
  206249. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206250. --numGradientLookupEntries;
  206251. CGShadingRef result = 0;
  206252. CGFunctionRef function = CGFunctionCreate (this, 1, 0, 4, 0, &gradientCallbacks);
  206253. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206254. if (gradient.isRadial)
  206255. {
  206256. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206257. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206258. function, true, true);
  206259. }
  206260. else
  206261. {
  206262. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206263. CGPointMake (gradient.x2, gradient.y2),
  206264. function, true, true);
  206265. }
  206266. CGFunctionRelease (function);
  206267. return result;
  206268. }
  206269. void drawGradient()
  206270. {
  206271. flip();
  206272. applyTransform (state->fillType.transform);
  206273. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206274. // you draw a gradient with high quality interp enabled).
  206275. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206276. CGContextSetAlpha (context, state->fillType.getOpacity());
  206277. CGContextDrawShading (context, shading);
  206278. CGShadingRelease (shading);
  206279. }
  206280. void createPath (const Path& path) const
  206281. {
  206282. CGContextBeginPath (context);
  206283. Path::Iterator i (path);
  206284. while (i.next())
  206285. {
  206286. switch (i.elementType)
  206287. {
  206288. case Path::Iterator::startNewSubPath:
  206289. CGContextMoveToPoint (context, i.x1, i.y1);
  206290. break;
  206291. case Path::Iterator::lineTo:
  206292. CGContextAddLineToPoint (context, i.x1, i.y1);
  206293. break;
  206294. case Path::Iterator::quadraticTo:
  206295. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206296. break;
  206297. case Path::Iterator::cubicTo:
  206298. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206299. break;
  206300. case Path::Iterator::closePath:
  206301. CGContextClosePath (context); break;
  206302. default:
  206303. jassertfalse
  206304. break;
  206305. }
  206306. }
  206307. }
  206308. void createPath (const Path& path, const AffineTransform& transform) const
  206309. {
  206310. CGContextBeginPath (context);
  206311. Path::Iterator i (path);
  206312. while (i.next())
  206313. {
  206314. switch (i.elementType)
  206315. {
  206316. case Path::Iterator::startNewSubPath:
  206317. transform.transformPoint (i.x1, i.y1);
  206318. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206319. break;
  206320. case Path::Iterator::lineTo:
  206321. transform.transformPoint (i.x1, i.y1);
  206322. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206323. break;
  206324. case Path::Iterator::quadraticTo:
  206325. transform.transformPoint (i.x1, i.y1);
  206326. transform.transformPoint (i.x2, i.y2);
  206327. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206328. break;
  206329. case Path::Iterator::cubicTo:
  206330. transform.transformPoint (i.x1, i.y1);
  206331. transform.transformPoint (i.x2, i.y2);
  206332. transform.transformPoint (i.x3, i.y3);
  206333. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206334. break;
  206335. case Path::Iterator::closePath:
  206336. CGContextClosePath (context); break;
  206337. default:
  206338. jassertfalse
  206339. break;
  206340. }
  206341. }
  206342. }
  206343. static Image* createAlphaChannelImage (const Image& im)
  206344. {
  206345. if (im.getFormat() == Image::SingleChannel)
  206346. return const_cast <Image*> (&im);
  206347. return im.createCopyOfAlphaChannel();
  206348. }
  206349. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206350. {
  206351. if (im.getFormat() != Image::SingleChannel)
  206352. delete alphaIm;
  206353. }
  206354. void flip() const
  206355. {
  206356. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206357. }
  206358. void applyTransform (const AffineTransform& transform) const
  206359. {
  206360. CGAffineTransform t;
  206361. t.a = transform.mat00;
  206362. t.b = transform.mat10;
  206363. t.c = transform.mat01;
  206364. t.d = transform.mat11;
  206365. t.tx = transform.mat02;
  206366. t.ty = transform.mat12;
  206367. CGContextConcatCTM (context, t);
  206368. }
  206369. CoreGraphicsContext (const CoreGraphicsContext&);
  206370. CoreGraphicsContext& operator= (const CoreGraphicsContext&);
  206371. };
  206372. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206373. {
  206374. return new CoreGraphicsContext (context, imageHeight);
  206375. }
  206376. #endif
  206377. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206378. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206379. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206380. // compiled on its own).
  206381. #if JUCE_INCLUDED_FILE
  206382. class NSViewComponentPeer;
  206383. END_JUCE_NAMESPACE
  206384. #define JuceNSView MakeObjCClassName(JuceNSView)
  206385. @interface JuceNSView : NSView<NSTextInput>
  206386. {
  206387. @public
  206388. NSViewComponentPeer* owner;
  206389. NSNotificationCenter* notificationCenter;
  206390. String* stringBeingComposed;
  206391. bool textWasInserted;
  206392. }
  206393. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206394. - (void) dealloc;
  206395. - (BOOL) isOpaque;
  206396. - (void) drawRect: (NSRect) r;
  206397. - (void) mouseDown: (NSEvent*) ev;
  206398. - (void) asyncMouseDown: (NSEvent*) ev;
  206399. - (void) mouseUp: (NSEvent*) ev;
  206400. - (void) asyncMouseUp: (NSEvent*) ev;
  206401. - (void) mouseDragged: (NSEvent*) ev;
  206402. - (void) mouseMoved: (NSEvent*) ev;
  206403. - (void) mouseEntered: (NSEvent*) ev;
  206404. - (void) mouseExited: (NSEvent*) ev;
  206405. - (void) rightMouseDown: (NSEvent*) ev;
  206406. - (void) rightMouseDragged: (NSEvent*) ev;
  206407. - (void) rightMouseUp: (NSEvent*) ev;
  206408. - (void) otherMouseDown: (NSEvent*) ev;
  206409. - (void) otherMouseDragged: (NSEvent*) ev;
  206410. - (void) otherMouseUp: (NSEvent*) ev;
  206411. - (void) scrollWheel: (NSEvent*) ev;
  206412. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206413. - (void) frameChanged: (NSNotification*) n;
  206414. - (void) viewDidMoveToWindow;
  206415. - (void) keyDown: (NSEvent*) ev;
  206416. - (void) keyUp: (NSEvent*) ev;
  206417. // NSTextInput Methods
  206418. - (void) insertText: (id) aString;
  206419. - (void) doCommandBySelector: (SEL) aSelector;
  206420. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206421. - (void) unmarkText;
  206422. - (BOOL) hasMarkedText;
  206423. - (long) conversationIdentifier;
  206424. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206425. - (NSRange) markedRange;
  206426. - (NSRange) selectedRange;
  206427. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206428. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206429. - (NSArray*) validAttributesForMarkedText;
  206430. - (void) flagsChanged: (NSEvent*) ev;
  206431. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206432. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206433. #endif
  206434. - (BOOL) becomeFirstResponder;
  206435. - (BOOL) resignFirstResponder;
  206436. - (BOOL) acceptsFirstResponder;
  206437. - (void) asyncRepaint: (id) rect;
  206438. - (NSArray*) getSupportedDragTypes;
  206439. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206440. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206441. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206442. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206443. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206444. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206445. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206446. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206447. @end
  206448. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206449. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206450. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206451. #else
  206452. @interface JuceNSWindow : NSWindow
  206453. #endif
  206454. {
  206455. @private
  206456. NSViewComponentPeer* owner;
  206457. bool isZooming;
  206458. }
  206459. - (void) setOwner: (NSViewComponentPeer*) owner;
  206460. - (BOOL) canBecomeKeyWindow;
  206461. - (void) becomeKeyWindow;
  206462. - (BOOL) windowShouldClose: (id) window;
  206463. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206464. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206465. - (void) zoom: (id) sender;
  206466. @end
  206467. BEGIN_JUCE_NAMESPACE
  206468. class NSViewComponentPeer : public ComponentPeer
  206469. {
  206470. public:
  206471. NSViewComponentPeer (Component* const component,
  206472. const int windowStyleFlags,
  206473. NSView* viewToAttachTo);
  206474. ~NSViewComponentPeer();
  206475. void* getNativeHandle() const;
  206476. void setVisible (bool shouldBeVisible);
  206477. void setTitle (const String& title);
  206478. void setPosition (int x, int y);
  206479. void setSize (int w, int h);
  206480. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206481. const Rectangle<int> getBounds (const bool global) const;
  206482. const Rectangle<int> getBounds() const;
  206483. const Point<int> getScreenPosition() const;
  206484. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206485. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206486. void setMinimised (bool shouldBeMinimised);
  206487. bool isMinimised() const;
  206488. void setFullScreen (bool shouldBeFullScreen);
  206489. bool isFullScreen() const;
  206490. bool contains (const Point<int>& position, bool trueIfInAChildWindow) const;
  206491. const BorderSize getFrameSize() const;
  206492. bool setAlwaysOnTop (bool alwaysOnTop);
  206493. void toFront (bool makeActiveWindow);
  206494. void toBehind (ComponentPeer* other);
  206495. void setIcon (const Image& newIcon);
  206496. const StringArray getAvailableRenderingEngines() throw();
  206497. int getCurrentRenderingEngine() throw();
  206498. void setCurrentRenderingEngine (int index) throw();
  206499. virtual void redirectMouseDown (NSEvent* ev);
  206500. virtual void redirectMouseUp (NSEvent* ev);
  206501. virtual void redirectMouseDrag (NSEvent* ev);
  206502. virtual void redirectMouseMove (NSEvent* ev);
  206503. virtual void redirectMouseEnter (NSEvent* ev);
  206504. virtual void redirectMouseExit (NSEvent* ev);
  206505. virtual void redirectMouseWheel (NSEvent* ev);
  206506. void sendMouseEvent (NSEvent* ev);
  206507. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206508. virtual bool redirectKeyDown (NSEvent* ev);
  206509. virtual bool redirectKeyUp (NSEvent* ev);
  206510. virtual void redirectModKeyChange (NSEvent* ev);
  206511. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206512. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206513. #endif
  206514. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206515. virtual bool isOpaque();
  206516. virtual void drawRect (NSRect r);
  206517. virtual bool canBecomeKeyWindow();
  206518. virtual bool windowShouldClose();
  206519. virtual void redirectMovedOrResized();
  206520. virtual void viewMovedToWindow();
  206521. virtual NSRect constrainRect (NSRect r);
  206522. static void showArrowCursorIfNeeded();
  206523. static void updateModifiers (NSEvent* e);
  206524. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206525. static int getKeyCodeFromEvent (NSEvent* ev)
  206526. {
  206527. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206528. int keyCode = unmodified[0];
  206529. if (keyCode == 0x19) // (backwards-tab)
  206530. keyCode = '\t';
  206531. else if (keyCode == 0x03) // (enter)
  206532. keyCode = '\r';
  206533. return keyCode;
  206534. }
  206535. static int64 getMouseTime (NSEvent* e)
  206536. {
  206537. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206538. + (int64) ([e timestamp] * 1000.0);
  206539. }
  206540. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206541. {
  206542. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206543. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206544. }
  206545. static int getModifierForButtonNumber (const NSInteger num)
  206546. {
  206547. return num == 0 ? ModifierKeys::leftButtonModifier
  206548. : (num == 1 ? ModifierKeys::rightButtonModifier
  206549. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206550. }
  206551. virtual void viewFocusGain();
  206552. virtual void viewFocusLoss();
  206553. bool isFocused() const;
  206554. void grabFocus();
  206555. void textInputRequired (const Point<int>& position);
  206556. void repaint (int x, int y, int w, int h);
  206557. void performAnyPendingRepaintsNow();
  206558. juce_UseDebuggingNewOperator
  206559. NSWindow* window;
  206560. JuceNSView* view;
  206561. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206562. static ModifierKeys currentModifiers;
  206563. static ComponentPeer* currentlyFocusedPeer;
  206564. static Array<int> keysCurrentlyDown;
  206565. };
  206566. END_JUCE_NAMESPACE
  206567. @implementation JuceNSView
  206568. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206569. withFrame: (NSRect) frame
  206570. {
  206571. [super initWithFrame: frame];
  206572. owner = owner_;
  206573. stringBeingComposed = 0;
  206574. textWasInserted = false;
  206575. notificationCenter = [NSNotificationCenter defaultCenter];
  206576. [notificationCenter addObserver: self
  206577. selector: @selector (frameChanged:)
  206578. name: NSViewFrameDidChangeNotification
  206579. object: self];
  206580. if (! owner_->isSharedWindow)
  206581. {
  206582. [notificationCenter addObserver: self
  206583. selector: @selector (frameChanged:)
  206584. name: NSWindowDidMoveNotification
  206585. object: owner_->window];
  206586. }
  206587. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206588. return self;
  206589. }
  206590. - (void) dealloc
  206591. {
  206592. [notificationCenter removeObserver: self];
  206593. delete stringBeingComposed;
  206594. [super dealloc];
  206595. }
  206596. - (void) drawRect: (NSRect) r
  206597. {
  206598. if (owner != 0)
  206599. owner->drawRect (r);
  206600. }
  206601. - (BOOL) isOpaque
  206602. {
  206603. return owner == 0 || owner->isOpaque();
  206604. }
  206605. - (void) mouseDown: (NSEvent*) ev
  206606. {
  206607. // In some host situations, the host will stop modal loops from working
  206608. // correctly if they're called from a mouse event, so we'll trigger
  206609. // the event asynchronously..
  206610. if (JUCEApplication::getInstance() == 0)
  206611. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206612. withObject: ev
  206613. waitUntilDone: NO];
  206614. else
  206615. [self asyncMouseDown: ev];
  206616. }
  206617. - (void) asyncMouseDown: (NSEvent*) ev
  206618. {
  206619. if (owner != 0)
  206620. owner->redirectMouseDown (ev);
  206621. }
  206622. - (void) mouseUp: (NSEvent*) ev
  206623. {
  206624. // In some host situations, the host will stop modal loops from working
  206625. // correctly if they're called from a mouse event, so we'll trigger
  206626. // the event asynchronously..
  206627. if (JUCEApplication::getInstance() == 0)
  206628. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206629. withObject: ev
  206630. waitUntilDone: NO];
  206631. else
  206632. [self asyncMouseUp: ev];
  206633. }
  206634. - (void) asyncMouseUp: (NSEvent*) ev
  206635. {
  206636. if (owner != 0)
  206637. owner->redirectMouseUp (ev);
  206638. }
  206639. - (void) mouseDragged: (NSEvent*) ev
  206640. {
  206641. if (owner != 0)
  206642. owner->redirectMouseDrag (ev);
  206643. }
  206644. - (void) mouseMoved: (NSEvent*) ev
  206645. {
  206646. if (owner != 0)
  206647. owner->redirectMouseMove (ev);
  206648. }
  206649. - (void) mouseEntered: (NSEvent*) ev
  206650. {
  206651. if (owner != 0)
  206652. owner->redirectMouseEnter (ev);
  206653. }
  206654. - (void) mouseExited: (NSEvent*) ev
  206655. {
  206656. if (owner != 0)
  206657. owner->redirectMouseExit (ev);
  206658. }
  206659. - (void) rightMouseDown: (NSEvent*) ev
  206660. {
  206661. [self mouseDown: ev];
  206662. }
  206663. - (void) rightMouseDragged: (NSEvent*) ev
  206664. {
  206665. [self mouseDragged: ev];
  206666. }
  206667. - (void) rightMouseUp: (NSEvent*) ev
  206668. {
  206669. [self mouseUp: ev];
  206670. }
  206671. - (void) otherMouseDown: (NSEvent*) ev
  206672. {
  206673. [self mouseDown: ev];
  206674. }
  206675. - (void) otherMouseDragged: (NSEvent*) ev
  206676. {
  206677. [self mouseDragged: ev];
  206678. }
  206679. - (void) otherMouseUp: (NSEvent*) ev
  206680. {
  206681. [self mouseUp: ev];
  206682. }
  206683. - (void) scrollWheel: (NSEvent*) ev
  206684. {
  206685. if (owner != 0)
  206686. owner->redirectMouseWheel (ev);
  206687. }
  206688. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206689. {
  206690. return YES;
  206691. }
  206692. - (void) frameChanged: (NSNotification*) n
  206693. {
  206694. if (owner != 0)
  206695. owner->redirectMovedOrResized();
  206696. }
  206697. - (void) viewDidMoveToWindow
  206698. {
  206699. if (owner != 0)
  206700. owner->viewMovedToWindow();
  206701. }
  206702. - (void) asyncRepaint: (id) rect
  206703. {
  206704. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206705. [self setNeedsDisplayInRect: *r];
  206706. }
  206707. - (void) keyDown: (NSEvent*) ev
  206708. {
  206709. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206710. textWasInserted = false;
  206711. if (target != 0)
  206712. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206713. else
  206714. deleteAndZero (stringBeingComposed);
  206715. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206716. [super keyDown: ev];
  206717. }
  206718. - (void) keyUp: (NSEvent*) ev
  206719. {
  206720. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206721. [super keyUp: ev];
  206722. }
  206723. - (void) insertText: (id) aString
  206724. {
  206725. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206726. if ([aString length] > 0)
  206727. {
  206728. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206729. if (target != 0)
  206730. {
  206731. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206732. textWasInserted = true;
  206733. }
  206734. }
  206735. deleteAndZero (stringBeingComposed);
  206736. }
  206737. - (void) doCommandBySelector: (SEL) aSelector
  206738. {
  206739. }
  206740. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206741. {
  206742. if (stringBeingComposed == 0)
  206743. stringBeingComposed = new String();
  206744. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206745. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206746. if (target != 0)
  206747. {
  206748. const Range<int> currentHighlight (target->getHighlightedRegion());
  206749. target->insertTextAtCaret (*stringBeingComposed);
  206750. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206751. textWasInserted = true;
  206752. }
  206753. }
  206754. - (void) unmarkText
  206755. {
  206756. if (stringBeingComposed != 0)
  206757. {
  206758. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206759. if (target != 0)
  206760. {
  206761. target->insertTextAtCaret (*stringBeingComposed);
  206762. textWasInserted = true;
  206763. }
  206764. }
  206765. deleteAndZero (stringBeingComposed);
  206766. }
  206767. - (BOOL) hasMarkedText
  206768. {
  206769. return stringBeingComposed != 0;
  206770. }
  206771. - (long) conversationIdentifier
  206772. {
  206773. return (long) (pointer_sized_int) self;
  206774. }
  206775. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206776. {
  206777. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206778. if (target != 0)
  206779. {
  206780. const Range<int> r ((int) theRange.location,
  206781. (int) (theRange.location + theRange.length));
  206782. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206783. }
  206784. return nil;
  206785. }
  206786. - (NSRange) markedRange
  206787. {
  206788. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206789. : NSMakeRange (NSNotFound, 0);
  206790. }
  206791. - (NSRange) selectedRange
  206792. {
  206793. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206794. if (target != 0)
  206795. {
  206796. const Range<int> highlight (target->getHighlightedRegion());
  206797. if (! highlight.isEmpty())
  206798. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206799. }
  206800. return NSMakeRange (NSNotFound, 0);
  206801. }
  206802. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206803. {
  206804. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206805. if (comp == 0)
  206806. return NSMakeRect (0, 0, 0, 0);
  206807. const Rectangle<int> bounds (comp->getScreenBounds());
  206808. return NSMakeRect (bounds.getX(),
  206809. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206810. bounds.getWidth(),
  206811. bounds.getHeight());
  206812. }
  206813. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206814. {
  206815. return NSNotFound;
  206816. }
  206817. - (NSArray*) validAttributesForMarkedText
  206818. {
  206819. return [NSArray array];
  206820. }
  206821. - (void) flagsChanged: (NSEvent*) ev
  206822. {
  206823. if (owner != 0)
  206824. owner->redirectModKeyChange (ev);
  206825. }
  206826. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206827. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206828. {
  206829. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206830. return true;
  206831. return [super performKeyEquivalent: ev];
  206832. }
  206833. #endif
  206834. - (BOOL) becomeFirstResponder
  206835. {
  206836. if (owner != 0)
  206837. owner->viewFocusGain();
  206838. return true;
  206839. }
  206840. - (BOOL) resignFirstResponder
  206841. {
  206842. if (owner != 0)
  206843. owner->viewFocusLoss();
  206844. return true;
  206845. }
  206846. - (BOOL) acceptsFirstResponder
  206847. {
  206848. return owner != 0 && owner->canBecomeKeyWindow();
  206849. }
  206850. - (NSArray*) getSupportedDragTypes
  206851. {
  206852. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206853. }
  206854. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206855. {
  206856. return owner != 0 && owner->sendDragCallback (type, sender);
  206857. }
  206858. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206859. {
  206860. if ([self sendDragCallback: 0 sender: sender])
  206861. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206862. else
  206863. return NSDragOperationNone;
  206864. }
  206865. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206866. {
  206867. if ([self sendDragCallback: 0 sender: sender])
  206868. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206869. else
  206870. return NSDragOperationNone;
  206871. }
  206872. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206873. {
  206874. [self sendDragCallback: 1 sender: sender];
  206875. }
  206876. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206877. {
  206878. [self sendDragCallback: 1 sender: sender];
  206879. }
  206880. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206881. {
  206882. return YES;
  206883. }
  206884. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206885. {
  206886. return [self sendDragCallback: 2 sender: sender];
  206887. }
  206888. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206889. {
  206890. }
  206891. @end
  206892. @implementation JuceNSWindow
  206893. - (void) setOwner: (NSViewComponentPeer*) owner_
  206894. {
  206895. owner = owner_;
  206896. isZooming = false;
  206897. }
  206898. - (BOOL) canBecomeKeyWindow
  206899. {
  206900. return owner != 0 && owner->canBecomeKeyWindow();
  206901. }
  206902. - (void) becomeKeyWindow
  206903. {
  206904. [super becomeKeyWindow];
  206905. if (owner != 0)
  206906. owner->grabFocus();
  206907. }
  206908. - (BOOL) windowShouldClose: (id) window
  206909. {
  206910. return owner == 0 || owner->windowShouldClose();
  206911. }
  206912. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  206913. {
  206914. if (owner != 0)
  206915. frameRect = owner->constrainRect (frameRect);
  206916. return frameRect;
  206917. }
  206918. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  206919. {
  206920. if (isZooming)
  206921. return proposedFrameSize;
  206922. NSRect frameRect = [self frame];
  206923. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  206924. frameRect.size = proposedFrameSize;
  206925. if (owner != 0)
  206926. frameRect = owner->constrainRect (frameRect);
  206927. return frameRect.size;
  206928. }
  206929. - (void) zoom: (id) sender
  206930. {
  206931. isZooming = true;
  206932. [super zoom: sender];
  206933. isZooming = false;
  206934. }
  206935. - (void) windowWillMove: (NSNotification*) notification
  206936. {
  206937. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  206938. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  206939. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  206940. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  206941. }
  206942. @end
  206943. BEGIN_JUCE_NAMESPACE
  206944. ModifierKeys NSViewComponentPeer::currentModifiers;
  206945. ComponentPeer* NSViewComponentPeer::currentlyFocusedPeer = 0;
  206946. Array<int> NSViewComponentPeer::keysCurrentlyDown;
  206947. bool KeyPress::isKeyCurrentlyDown (const int keyCode)
  206948. {
  206949. if (NSViewComponentPeer::keysCurrentlyDown.contains (keyCode))
  206950. return true;
  206951. if (keyCode >= 'A' && keyCode <= 'Z'
  206952. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toLowerCase ((juce_wchar) keyCode)))
  206953. return true;
  206954. if (keyCode >= 'a' && keyCode <= 'z'
  206955. && NSViewComponentPeer::keysCurrentlyDown.contains ((int) CharacterFunctions::toUpperCase ((juce_wchar) keyCode)))
  206956. return true;
  206957. return false;
  206958. }
  206959. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  206960. {
  206961. int m = 0;
  206962. if (([e modifierFlags] & NSShiftKeyMask) != 0) m |= ModifierKeys::shiftModifier;
  206963. if (([e modifierFlags] & NSControlKeyMask) != 0) m |= ModifierKeys::ctrlModifier;
  206964. if (([e modifierFlags] & NSAlternateKeyMask) != 0) m |= ModifierKeys::altModifier;
  206965. if (([e modifierFlags] & NSCommandKeyMask) != 0) m |= ModifierKeys::commandModifier;
  206966. currentModifiers = currentModifiers.withOnlyMouseButtons().withFlags (m);
  206967. }
  206968. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  206969. {
  206970. updateModifiers (ev);
  206971. int keyCode = getKeyCodeFromEvent (ev);
  206972. if (keyCode != 0)
  206973. {
  206974. if (isKeyDown)
  206975. keysCurrentlyDown.addIfNotAlreadyThere (keyCode);
  206976. else
  206977. keysCurrentlyDown.removeValue (keyCode);
  206978. }
  206979. }
  206980. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  206981. {
  206982. return NSViewComponentPeer::currentModifiers;
  206983. }
  206984. void ModifierKeys::updateCurrentModifiers() throw()
  206985. {
  206986. currentModifiers = NSViewComponentPeer::currentModifiers;
  206987. }
  206988. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  206989. const int windowStyleFlags,
  206990. NSView* viewToAttachTo)
  206991. : ComponentPeer (component_, windowStyleFlags),
  206992. window (0),
  206993. view (0),
  206994. isSharedWindow (viewToAttachTo != 0),
  206995. fullScreen (false),
  206996. insideDrawRect (false),
  206997. #if USE_COREGRAPHICS_RENDERING
  206998. usingCoreGraphics (true),
  206999. #else
  207000. usingCoreGraphics (false),
  207001. #endif
  207002. recursiveToFrontCall (false)
  207003. {
  207004. NSRect r;
  207005. r.origin.x = 0;
  207006. r.origin.y = 0;
  207007. r.size.width = (float) component->getWidth();
  207008. r.size.height = (float) component->getHeight();
  207009. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207010. [view setPostsFrameChangedNotifications: YES];
  207011. if (isSharedWindow)
  207012. {
  207013. window = [viewToAttachTo window];
  207014. [viewToAttachTo addSubview: view];
  207015. setVisible (component->isVisible());
  207016. }
  207017. else
  207018. {
  207019. r.origin.x = (float) component->getX();
  207020. r.origin.y = (float) component->getY();
  207021. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207022. unsigned int style = 0;
  207023. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207024. style = NSBorderlessWindowMask;
  207025. else
  207026. style = NSTitledWindowMask;
  207027. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207028. style |= NSMiniaturizableWindowMask;
  207029. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207030. style |= NSClosableWindowMask;
  207031. if ((windowStyleFlags & windowIsResizable) != 0)
  207032. style |= NSResizableWindowMask;
  207033. window = [[JuceNSWindow alloc] initWithContentRect: r
  207034. styleMask: style
  207035. backing: NSBackingStoreBuffered
  207036. defer: YES];
  207037. [((JuceNSWindow*) window) setOwner: this];
  207038. [window orderOut: nil];
  207039. [window setDelegate: (JuceNSWindow*) window];
  207040. [window setOpaque: component->isOpaque()];
  207041. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207042. if (component->isAlwaysOnTop())
  207043. [window setLevel: NSFloatingWindowLevel];
  207044. [window setContentView: view];
  207045. [window setAutodisplay: YES];
  207046. [window setAcceptsMouseMovedEvents: YES];
  207047. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207048. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207049. [window setReleasedWhenClosed: YES];
  207050. [window retain];
  207051. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207052. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207053. }
  207054. setTitle (component->getName());
  207055. }
  207056. NSViewComponentPeer::~NSViewComponentPeer()
  207057. {
  207058. view->owner = 0;
  207059. [view removeFromSuperview];
  207060. [view release];
  207061. if (! isSharedWindow)
  207062. {
  207063. [((JuceNSWindow*) window) setOwner: 0];
  207064. [window close];
  207065. [window release];
  207066. }
  207067. }
  207068. void* NSViewComponentPeer::getNativeHandle() const
  207069. {
  207070. return view;
  207071. }
  207072. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207073. {
  207074. if (isSharedWindow)
  207075. {
  207076. [view setHidden: ! shouldBeVisible];
  207077. }
  207078. else
  207079. {
  207080. if (shouldBeVisible)
  207081. {
  207082. [window orderFront: nil];
  207083. handleBroughtToFront();
  207084. }
  207085. else
  207086. {
  207087. [window orderOut: nil];
  207088. }
  207089. }
  207090. }
  207091. void NSViewComponentPeer::setTitle (const String& title)
  207092. {
  207093. const ScopedAutoReleasePool pool;
  207094. if (! isSharedWindow)
  207095. [window setTitle: juceStringToNS (title)];
  207096. }
  207097. void NSViewComponentPeer::setPosition (int x, int y)
  207098. {
  207099. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207100. }
  207101. void NSViewComponentPeer::setSize (int w, int h)
  207102. {
  207103. setBounds (component->getX(), component->getY(), w, h, false);
  207104. }
  207105. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, bool isNowFullScreen)
  207106. {
  207107. fullScreen = isNowFullScreen;
  207108. w = jmax (0, w);
  207109. h = jmax (0, h);
  207110. NSRect r;
  207111. r.origin.x = (float) x;
  207112. r.origin.y = (float) y;
  207113. r.size.width = (float) w;
  207114. r.size.height = (float) h;
  207115. if (isSharedWindow)
  207116. {
  207117. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207118. if ([view frame].size.width != r.size.width
  207119. || [view frame].size.height != r.size.height)
  207120. [view setNeedsDisplay: true];
  207121. [view setFrame: r];
  207122. }
  207123. else
  207124. {
  207125. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207126. [window setFrame: [window frameRectForContentRect: r]
  207127. display: true];
  207128. }
  207129. }
  207130. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207131. {
  207132. NSRect r = [view frame];
  207133. if (global && [view window] != 0)
  207134. {
  207135. r = [view convertRect: r toView: nil];
  207136. NSRect wr = [[view window] frame];
  207137. r.origin.x += wr.origin.x;
  207138. r.origin.y += wr.origin.y;
  207139. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207140. }
  207141. else
  207142. {
  207143. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207144. }
  207145. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207146. }
  207147. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207148. {
  207149. return getBounds (! isSharedWindow);
  207150. }
  207151. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207152. {
  207153. return getBounds (true).getPosition();
  207154. }
  207155. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207156. {
  207157. return relativePosition + getScreenPosition();
  207158. }
  207159. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207160. {
  207161. return screenPosition - getScreenPosition();
  207162. }
  207163. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207164. {
  207165. if (constrainer != 0)
  207166. {
  207167. NSRect current = [window frame];
  207168. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207169. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207170. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207171. (int) r.size.width, (int) r.size.height);
  207172. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207173. (int) current.size.width, (int) current.size.height);
  207174. constrainer->checkBounds (pos, original,
  207175. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207176. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207177. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207178. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207179. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207180. r.origin.x = pos.getX();
  207181. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207182. r.size.width = pos.getWidth();
  207183. r.size.height = pos.getHeight();
  207184. }
  207185. return r;
  207186. }
  207187. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207188. {
  207189. if (! isSharedWindow)
  207190. {
  207191. if (shouldBeMinimised)
  207192. [window miniaturize: nil];
  207193. else
  207194. [window deminiaturize: nil];
  207195. }
  207196. }
  207197. bool NSViewComponentPeer::isMinimised() const
  207198. {
  207199. return window != 0 && [window isMiniaturized];
  207200. }
  207201. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207202. {
  207203. if (! isSharedWindow)
  207204. {
  207205. Rectangle<int> r (lastNonFullscreenBounds);
  207206. setMinimised (false);
  207207. if (fullScreen != shouldBeFullScreen)
  207208. {
  207209. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207210. {
  207211. fullScreen = true;
  207212. [window performZoom: nil];
  207213. }
  207214. else
  207215. {
  207216. if (shouldBeFullScreen)
  207217. r = Desktop::getInstance().getMainMonitorArea();
  207218. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207219. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207220. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207221. }
  207222. }
  207223. }
  207224. }
  207225. bool NSViewComponentPeer::isFullScreen() const
  207226. {
  207227. return fullScreen;
  207228. }
  207229. bool NSViewComponentPeer::contains (const Point<int>& position, bool trueIfInAChildWindow) const
  207230. {
  207231. if (((unsigned int) position.getX()) >= (unsigned int) component->getWidth()
  207232. || ((unsigned int) position.getY()) >= (unsigned int) component->getHeight())
  207233. return false;
  207234. NSPoint p;
  207235. p.x = (float) position.getX();
  207236. p.y = (float) position.getY();
  207237. NSView* v = [view hitTest: p];
  207238. if (trueIfInAChildWindow)
  207239. return v != nil;
  207240. return v == view;
  207241. }
  207242. const BorderSize NSViewComponentPeer::getFrameSize() const
  207243. {
  207244. BorderSize b;
  207245. if (! isSharedWindow)
  207246. {
  207247. NSRect v = [view convertRect: [view frame] toView: nil];
  207248. NSRect w = [window frame];
  207249. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207250. b.setBottom ((int) v.origin.y);
  207251. b.setLeft ((int) v.origin.x);
  207252. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207253. }
  207254. return b;
  207255. }
  207256. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207257. {
  207258. if (! isSharedWindow)
  207259. {
  207260. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207261. : NSNormalWindowLevel];
  207262. }
  207263. return true;
  207264. }
  207265. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207266. {
  207267. if (isSharedWindow)
  207268. {
  207269. [[view superview] addSubview: view
  207270. positioned: NSWindowAbove
  207271. relativeTo: nil];
  207272. }
  207273. if (window != 0 && component->isVisible())
  207274. {
  207275. if (makeActiveWindow)
  207276. [window makeKeyAndOrderFront: nil];
  207277. else
  207278. [window orderFront: nil];
  207279. if (! recursiveToFrontCall)
  207280. {
  207281. recursiveToFrontCall = true;
  207282. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207283. handleBroughtToFront();
  207284. recursiveToFrontCall = false;
  207285. }
  207286. }
  207287. }
  207288. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207289. {
  207290. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207291. if (isSharedWindow)
  207292. {
  207293. [[view superview] addSubview: view
  207294. positioned: NSWindowBelow
  207295. relativeTo: o->view];
  207296. }
  207297. else
  207298. {
  207299. [window orderWindow: NSWindowBelow
  207300. relativeTo: o->window != 0 ? [o->window windowNumber]
  207301. : nil ];
  207302. }
  207303. }
  207304. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207305. {
  207306. // to do..
  207307. }
  207308. void NSViewComponentPeer::viewFocusGain()
  207309. {
  207310. if (currentlyFocusedPeer != this)
  207311. {
  207312. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207313. currentlyFocusedPeer->handleFocusLoss();
  207314. currentlyFocusedPeer = this;
  207315. handleFocusGain();
  207316. }
  207317. }
  207318. void NSViewComponentPeer::viewFocusLoss()
  207319. {
  207320. if (currentlyFocusedPeer == this)
  207321. {
  207322. currentlyFocusedPeer = 0;
  207323. handleFocusLoss();
  207324. }
  207325. }
  207326. void juce_HandleProcessFocusChange()
  207327. {
  207328. NSViewComponentPeer::keysCurrentlyDown.clear();
  207329. if (NSViewComponentPeer::isValidPeer (NSViewComponentPeer::currentlyFocusedPeer))
  207330. {
  207331. if (Process::isForegroundProcess())
  207332. {
  207333. NSViewComponentPeer::currentlyFocusedPeer->handleFocusGain();
  207334. ComponentPeer::bringModalComponentToFront();
  207335. }
  207336. else
  207337. {
  207338. NSViewComponentPeer::currentlyFocusedPeer->handleFocusLoss();
  207339. // turn kiosk mode off if we lose focus..
  207340. Desktop::getInstance().setKioskModeComponent (0);
  207341. }
  207342. }
  207343. }
  207344. bool NSViewComponentPeer::isFocused() const
  207345. {
  207346. return isSharedWindow ? this == currentlyFocusedPeer
  207347. : (window != 0 && [window isKeyWindow]);
  207348. }
  207349. void NSViewComponentPeer::grabFocus()
  207350. {
  207351. if (window != 0)
  207352. {
  207353. [window makeKeyWindow];
  207354. [window makeFirstResponder: view];
  207355. viewFocusGain();
  207356. }
  207357. }
  207358. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207359. {
  207360. }
  207361. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207362. {
  207363. String unicode (nsStringToJuce ([ev characters]));
  207364. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207365. int keyCode = getKeyCodeFromEvent (ev);
  207366. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207367. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207368. if (unicode.isNotEmpty() || keyCode != 0)
  207369. {
  207370. if (isKeyDown)
  207371. {
  207372. bool used = false;
  207373. while (unicode.length() > 0)
  207374. {
  207375. juce_wchar textCharacter = unicode[0];
  207376. unicode = unicode.substring (1);
  207377. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207378. textCharacter = 0;
  207379. used = handleKeyUpOrDown (true) || used;
  207380. used = handleKeyPress (keyCode, textCharacter) || used;
  207381. }
  207382. return used;
  207383. }
  207384. else
  207385. {
  207386. if (handleKeyUpOrDown (false))
  207387. return true;
  207388. }
  207389. }
  207390. return false;
  207391. }
  207392. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207393. {
  207394. updateKeysDown (ev, true);
  207395. bool used = handleKeyEvent (ev, true);
  207396. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207397. {
  207398. // for command keys, the key-up event is thrown away, so simulate one..
  207399. updateKeysDown (ev, false);
  207400. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207401. }
  207402. // (If we're running modally, don't allow unused keystrokes to be passed
  207403. // along to other blocked views..)
  207404. if (Component::getCurrentlyModalComponent() != 0)
  207405. used = true;
  207406. return used;
  207407. }
  207408. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207409. {
  207410. updateKeysDown (ev, false);
  207411. return handleKeyEvent (ev, false)
  207412. || Component::getCurrentlyModalComponent() != 0;
  207413. }
  207414. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207415. {
  207416. keysCurrentlyDown.clear();
  207417. handleKeyUpOrDown (true);
  207418. updateModifiers (ev);
  207419. handleModifierKeysChange();
  207420. }
  207421. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207422. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207423. {
  207424. if ([ev type] == NSKeyDown)
  207425. return redirectKeyDown (ev);
  207426. else if ([ev type] == NSKeyUp)
  207427. return redirectKeyUp (ev);
  207428. return false;
  207429. }
  207430. #endif
  207431. void NSViewComponentPeer::sendMouseEvent (NSEvent* ev)
  207432. {
  207433. updateModifiers (ev);
  207434. handleMouseEvent (0, getMousePos (ev, view), currentModifiers, getMouseTime (ev));
  207435. }
  207436. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207437. {
  207438. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207439. sendMouseEvent (ev);
  207440. }
  207441. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207442. {
  207443. currentModifiers = currentModifiers.withoutFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207444. sendMouseEvent (ev);
  207445. showArrowCursorIfNeeded();
  207446. }
  207447. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207448. {
  207449. currentModifiers = currentModifiers.withFlags (getModifierForButtonNumber ([ev buttonNumber]));
  207450. sendMouseEvent (ev);
  207451. }
  207452. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207453. {
  207454. currentModifiers = currentModifiers.withoutMouseButtons();
  207455. sendMouseEvent (ev);
  207456. showArrowCursorIfNeeded();
  207457. }
  207458. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207459. {
  207460. Desktop::getInstance().getMainMouseSource().forceMouseCursorUpdate();
  207461. currentModifiers = currentModifiers.withoutMouseButtons();
  207462. sendMouseEvent (ev);
  207463. }
  207464. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207465. {
  207466. currentModifiers = currentModifiers.withoutMouseButtons();
  207467. sendMouseEvent (ev);
  207468. }
  207469. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207470. {
  207471. updateModifiers (ev);
  207472. handleMouseWheel (0, getMousePos (ev, view), getMouseTime (ev),
  207473. [ev deltaX] * 10.0f, [ev deltaY] * 10.0f);
  207474. }
  207475. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207476. {
  207477. MouseInputSource& mouse = Desktop::getInstance().getMainMouseSource();
  207478. if (mouse.getComponentUnderMouse() == 0
  207479. && Desktop::getInstance().findComponentAt (mouse.getScreenPosition()) == 0)
  207480. {
  207481. [[NSCursor arrowCursor] set];
  207482. }
  207483. }
  207484. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207485. {
  207486. NSString* bestType
  207487. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207488. if (bestType == nil)
  207489. return false;
  207490. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207491. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207492. StringArray files;
  207493. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207494. if (list == nil)
  207495. return false;
  207496. if ([list isKindOfClass: [NSArray class]])
  207497. {
  207498. NSArray* items = (NSArray*) list;
  207499. for (unsigned int i = 0; i < [items count]; ++i)
  207500. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207501. }
  207502. if (files.size() == 0)
  207503. return false;
  207504. if (type == 0)
  207505. handleFileDragMove (files, pos);
  207506. else if (type == 1)
  207507. handleFileDragExit (files);
  207508. else if (type == 2)
  207509. handleFileDragDrop (files, pos);
  207510. return true;
  207511. }
  207512. bool NSViewComponentPeer::isOpaque()
  207513. {
  207514. return component == 0 || component->isOpaque();
  207515. }
  207516. void NSViewComponentPeer::drawRect (NSRect r)
  207517. {
  207518. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207519. return;
  207520. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207521. if (! component->isOpaque())
  207522. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207523. #if USE_COREGRAPHICS_RENDERING
  207524. if (usingCoreGraphics)
  207525. {
  207526. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207527. insideDrawRect = true;
  207528. handlePaint (context);
  207529. insideDrawRect = false;
  207530. }
  207531. else
  207532. #endif
  207533. {
  207534. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207535. (int) (r.size.width + 0.5f),
  207536. (int) (r.size.height + 0.5f),
  207537. ! getComponent()->isOpaque());
  207538. LowLevelGraphicsSoftwareRenderer context (temp);
  207539. context.setOrigin (-roundToInt (r.origin.x),
  207540. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207541. const NSRect* rects = 0;
  207542. NSInteger numRects = 0;
  207543. [view getRectsBeingDrawn: &rects count: &numRects];
  207544. RectangleList clip;
  207545. for (int i = 0; i < numRects; ++i)
  207546. {
  207547. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207548. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207549. roundToInt (rects[i].size.width),
  207550. roundToInt (rects[i].size.height)));
  207551. }
  207552. if (context.clipToRectangleList (clip))
  207553. {
  207554. insideDrawRect = true;
  207555. handlePaint (context);
  207556. insideDrawRect = false;
  207557. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207558. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207559. CGColorSpaceRelease (colourSpace);
  207560. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207561. CGImageRelease (image);
  207562. }
  207563. }
  207564. }
  207565. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207566. {
  207567. StringArray s;
  207568. s.add ("Software Renderer");
  207569. #if USE_COREGRAPHICS_RENDERING
  207570. s.add ("CoreGraphics Renderer");
  207571. #endif
  207572. return s;
  207573. }
  207574. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207575. {
  207576. return usingCoreGraphics ? 1 : 0;
  207577. }
  207578. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207579. {
  207580. #if USE_COREGRAPHICS_RENDERING
  207581. if (usingCoreGraphics != (index > 0))
  207582. {
  207583. usingCoreGraphics = index > 0;
  207584. [view setNeedsDisplay: true];
  207585. }
  207586. #endif
  207587. }
  207588. bool NSViewComponentPeer::canBecomeKeyWindow()
  207589. {
  207590. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207591. }
  207592. bool NSViewComponentPeer::windowShouldClose()
  207593. {
  207594. if (! isValidPeer (this))
  207595. return YES;
  207596. handleUserClosingWindow();
  207597. return NO;
  207598. }
  207599. void NSViewComponentPeer::redirectMovedOrResized()
  207600. {
  207601. handleMovedOrResized();
  207602. }
  207603. void NSViewComponentPeer::viewMovedToWindow()
  207604. {
  207605. if (isSharedWindow)
  207606. window = [view window];
  207607. }
  207608. void Desktop::createMouseInputSources()
  207609. {
  207610. mouseSources.add (new MouseInputSource (0, true));
  207611. }
  207612. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207613. {
  207614. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207615. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207616. // is apparently still available in 64-bit apps..
  207617. if (enableOrDisable)
  207618. {
  207619. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207620. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207621. }
  207622. else
  207623. {
  207624. SetSystemUIMode (kUIModeNormal, 0);
  207625. }
  207626. }
  207627. class AsyncRepaintMessage : public CallbackMessage
  207628. {
  207629. public:
  207630. NSViewComponentPeer* const peer;
  207631. const Rectangle<int> rect;
  207632. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207633. : peer (peer_), rect (rect_)
  207634. {
  207635. }
  207636. void messageCallback()
  207637. {
  207638. if (ComponentPeer::isValidPeer (peer))
  207639. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207640. }
  207641. };
  207642. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207643. {
  207644. if (insideDrawRect)
  207645. {
  207646. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207647. }
  207648. else
  207649. {
  207650. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207651. (float) w, (float) h)];
  207652. }
  207653. }
  207654. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207655. {
  207656. [view displayIfNeeded];
  207657. }
  207658. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207659. {
  207660. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207661. }
  207662. Image* juce_createIconForFile (const File& file)
  207663. {
  207664. const ScopedAutoReleasePool pool;
  207665. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207666. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207667. [NSGraphicsContext saveGraphicsState];
  207668. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207669. [image drawAtPoint: NSMakePoint (0, 0)
  207670. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207671. operation: NSCompositeSourceOver fraction: 1.0f];
  207672. [[NSGraphicsContext currentContext] flushGraphics];
  207673. [NSGraphicsContext restoreGraphicsState];
  207674. return result;
  207675. }
  207676. const int KeyPress::spaceKey = ' ';
  207677. const int KeyPress::returnKey = 0x0d;
  207678. const int KeyPress::escapeKey = 0x1b;
  207679. const int KeyPress::backspaceKey = 0x7f;
  207680. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207681. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207682. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207683. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207684. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207685. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207686. const int KeyPress::endKey = NSEndFunctionKey;
  207687. const int KeyPress::homeKey = NSHomeFunctionKey;
  207688. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207689. const int KeyPress::insertKey = -1;
  207690. const int KeyPress::tabKey = 9;
  207691. const int KeyPress::F1Key = NSF1FunctionKey;
  207692. const int KeyPress::F2Key = NSF2FunctionKey;
  207693. const int KeyPress::F3Key = NSF3FunctionKey;
  207694. const int KeyPress::F4Key = NSF4FunctionKey;
  207695. const int KeyPress::F5Key = NSF5FunctionKey;
  207696. const int KeyPress::F6Key = NSF6FunctionKey;
  207697. const int KeyPress::F7Key = NSF7FunctionKey;
  207698. const int KeyPress::F8Key = NSF8FunctionKey;
  207699. const int KeyPress::F9Key = NSF9FunctionKey;
  207700. const int KeyPress::F10Key = NSF10FunctionKey;
  207701. const int KeyPress::F11Key = NSF1FunctionKey;
  207702. const int KeyPress::F12Key = NSF12FunctionKey;
  207703. const int KeyPress::F13Key = NSF13FunctionKey;
  207704. const int KeyPress::F14Key = NSF14FunctionKey;
  207705. const int KeyPress::F15Key = NSF15FunctionKey;
  207706. const int KeyPress::F16Key = NSF16FunctionKey;
  207707. const int KeyPress::numberPad0 = 0x30020;
  207708. const int KeyPress::numberPad1 = 0x30021;
  207709. const int KeyPress::numberPad2 = 0x30022;
  207710. const int KeyPress::numberPad3 = 0x30023;
  207711. const int KeyPress::numberPad4 = 0x30024;
  207712. const int KeyPress::numberPad5 = 0x30025;
  207713. const int KeyPress::numberPad6 = 0x30026;
  207714. const int KeyPress::numberPad7 = 0x30027;
  207715. const int KeyPress::numberPad8 = 0x30028;
  207716. const int KeyPress::numberPad9 = 0x30029;
  207717. const int KeyPress::numberPadAdd = 0x3002a;
  207718. const int KeyPress::numberPadSubtract = 0x3002b;
  207719. const int KeyPress::numberPadMultiply = 0x3002c;
  207720. const int KeyPress::numberPadDivide = 0x3002d;
  207721. const int KeyPress::numberPadSeparator = 0x3002e;
  207722. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207723. const int KeyPress::numberPadEquals = 0x30030;
  207724. const int KeyPress::numberPadDelete = 0x30031;
  207725. const int KeyPress::playKey = 0x30000;
  207726. const int KeyPress::stopKey = 0x30001;
  207727. const int KeyPress::fastForwardKey = 0x30002;
  207728. const int KeyPress::rewindKey = 0x30003;
  207729. #endif
  207730. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207731. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207732. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207733. // compiled on its own).
  207734. #if JUCE_INCLUDED_FILE
  207735. #if JUCE_MAC
  207736. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  207737. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY)
  207738. {
  207739. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207740. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207741. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207742. [im release];
  207743. return c;
  207744. }
  207745. static void* juce_cursorFromData (const MemoryBlock& data, const float hx, const float hy)
  207746. {
  207747. MemoryInputStream stream (data, false);
  207748. ScopedPointer <Image> im (juce_loadPNGImageFromStream (stream));
  207749. jassert (im != 0);
  207750. if (im == 0)
  207751. return 0;
  207752. return juce_createMouseCursorFromImage (*im,
  207753. (int) (hx * im->getWidth()),
  207754. (int) (hy * im->getHeight()));
  207755. }
  207756. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207757. {
  207758. const File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207759. MemoryBlock mb;
  207760. if (f.getChildFile (filename).loadFileAsData (mb))
  207761. return juce_cursorFromData (mb, hx, hy);
  207762. return 0;
  207763. }
  207764. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type)
  207765. {
  207766. const ScopedAutoReleasePool pool;
  207767. NSCursor* c = 0;
  207768. switch (type)
  207769. {
  207770. case MouseCursor::NormalCursor:
  207771. c = [NSCursor arrowCursor];
  207772. break;
  207773. case MouseCursor::NoCursor:
  207774. return juce_createMouseCursorFromImage (Image (Image::ARGB, 8, 8, true), 0, 0);
  207775. case MouseCursor::DraggingHandCursor:
  207776. c = [NSCursor openHandCursor];
  207777. break;
  207778. case MouseCursor::CopyingCursor:
  207779. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207780. case MouseCursor::WaitCursor:
  207781. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207782. break;
  207783. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207784. case MouseCursor::IBeamCursor:
  207785. c = [NSCursor IBeamCursor];
  207786. break;
  207787. case MouseCursor::PointingHandCursor:
  207788. c = [NSCursor pointingHandCursor];
  207789. break;
  207790. case MouseCursor::LeftRightResizeCursor:
  207791. c = [NSCursor resizeLeftRightCursor];
  207792. break;
  207793. case MouseCursor::LeftEdgeResizeCursor:
  207794. c = [NSCursor resizeLeftCursor];
  207795. break;
  207796. case MouseCursor::RightEdgeResizeCursor:
  207797. c = [NSCursor resizeRightCursor];
  207798. break;
  207799. case MouseCursor::UpDownResizeCursor:
  207800. case MouseCursor::TopEdgeResizeCursor:
  207801. case MouseCursor::BottomEdgeResizeCursor:
  207802. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207803. case MouseCursor::TopLeftCornerResizeCursor:
  207804. case MouseCursor::BottomRightCornerResizeCursor:
  207805. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207806. case MouseCursor::TopRightCornerResizeCursor:
  207807. case MouseCursor::BottomLeftCornerResizeCursor:
  207808. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207809. case MouseCursor::UpDownLeftRightResizeCursor:
  207810. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207811. case MouseCursor::CrosshairCursor:
  207812. c = [NSCursor crosshairCursor];
  207813. break;
  207814. }
  207815. [c retain];
  207816. return c;
  207817. }
  207818. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard)
  207819. {
  207820. NSCursor* c = (NSCursor*) cursorHandle;
  207821. [c release];
  207822. }
  207823. void MouseCursor::showInAllWindows() const
  207824. {
  207825. showInWindow (0);
  207826. }
  207827. void MouseCursor::showInWindow (ComponentPeer*) const
  207828. {
  207829. NSCursor* const c = (NSCursor*) getHandle();
  207830. [c set];
  207831. }
  207832. #else
  207833. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) { return 0; }
  207834. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) { return 0; }
  207835. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) {}
  207836. void MouseCursor::showInAllWindows() const {}
  207837. void MouseCursor::showInWindow (ComponentPeer*) const {}
  207838. #endif
  207839. #endif
  207840. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207841. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207842. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207843. // compiled on its own).
  207844. #if JUCE_INCLUDED_FILE
  207845. class NSViewComponentInternal : public ComponentMovementWatcher
  207846. {
  207847. Component* const owner;
  207848. NSViewComponentPeer* currentPeer;
  207849. bool wasShowing;
  207850. public:
  207851. NSView* const view;
  207852. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207853. : ComponentMovementWatcher (owner_),
  207854. owner (owner_),
  207855. currentPeer (0),
  207856. wasShowing (false),
  207857. view (view_)
  207858. {
  207859. [view_ retain];
  207860. if (owner_->isShowing())
  207861. componentPeerChanged();
  207862. }
  207863. ~NSViewComponentInternal()
  207864. {
  207865. [view removeFromSuperview];
  207866. [view release];
  207867. }
  207868. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207869. {
  207870. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207871. // The ComponentMovementWatcher version of this method avoids calling
  207872. // us when the top-level comp is resized, but for an NSView we need to know this
  207873. // because with inverted co-ords, we need to update the position even if the
  207874. // top-left pos hasn't changed
  207875. if (comp.isOnDesktop() && wasResized)
  207876. componentMovedOrResized (wasMoved, wasResized);
  207877. }
  207878. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207879. {
  207880. Component* const topComp = owner->getTopLevelComponent();
  207881. if (topComp->getPeer() != 0)
  207882. {
  207883. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207884. NSRect r;
  207885. r.origin.x = (float) pos.getX();
  207886. r.origin.y = (float) pos.getY();
  207887. r.size.width = (float) owner->getWidth();
  207888. r.size.height = (float) owner->getHeight();
  207889. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207890. [view setFrame: r];
  207891. }
  207892. }
  207893. void componentPeerChanged()
  207894. {
  207895. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207896. if (currentPeer != peer)
  207897. {
  207898. [view removeFromSuperview];
  207899. currentPeer = peer;
  207900. if (peer != 0)
  207901. {
  207902. [peer->view addSubview: view];
  207903. componentMovedOrResized (false, false);
  207904. }
  207905. }
  207906. [view setHidden: ! owner->isShowing()];
  207907. }
  207908. void componentVisibilityChanged (Component&)
  207909. {
  207910. componentPeerChanged();
  207911. }
  207912. juce_UseDebuggingNewOperator
  207913. private:
  207914. NSViewComponentInternal (const NSViewComponentInternal&);
  207915. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  207916. };
  207917. NSViewComponent::NSViewComponent()
  207918. {
  207919. }
  207920. NSViewComponent::~NSViewComponent()
  207921. {
  207922. }
  207923. void NSViewComponent::setView (void* view)
  207924. {
  207925. if (view != getView())
  207926. {
  207927. if (view != 0)
  207928. info = new NSViewComponentInternal ((NSView*) view, this);
  207929. else
  207930. info = 0;
  207931. }
  207932. }
  207933. void* NSViewComponent::getView() const
  207934. {
  207935. return info == 0 ? 0 : info->view;
  207936. }
  207937. void NSViewComponent::paint (Graphics& g)
  207938. {
  207939. }
  207940. #endif
  207941. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  207942. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  207943. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207944. // compiled on its own).
  207945. #if JUCE_INCLUDED_FILE
  207946. AppleRemoteDevice::AppleRemoteDevice()
  207947. : device (0),
  207948. queue (0),
  207949. remoteId (0)
  207950. {
  207951. }
  207952. AppleRemoteDevice::~AppleRemoteDevice()
  207953. {
  207954. stop();
  207955. }
  207956. static io_object_t getAppleRemoteDevice()
  207957. {
  207958. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  207959. io_iterator_t iter = 0;
  207960. io_object_t iod = 0;
  207961. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  207962. && iter != 0)
  207963. {
  207964. iod = IOIteratorNext (iter);
  207965. }
  207966. IOObjectRelease (iter);
  207967. return iod;
  207968. }
  207969. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  207970. {
  207971. jassert (*device == 0);
  207972. io_name_t classname;
  207973. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  207974. {
  207975. IOCFPlugInInterface** cfPlugInInterface = 0;
  207976. SInt32 score = 0;
  207977. if (IOCreatePlugInInterfaceForService (iod,
  207978. kIOHIDDeviceUserClientTypeID,
  207979. kIOCFPlugInInterfaceID,
  207980. &cfPlugInInterface,
  207981. &score) == kIOReturnSuccess)
  207982. {
  207983. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  207984. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  207985. device);
  207986. (void) hr;
  207987. (*cfPlugInInterface)->Release (cfPlugInInterface);
  207988. }
  207989. }
  207990. return *device != 0;
  207991. }
  207992. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  207993. {
  207994. if (queue != 0)
  207995. return true;
  207996. stop();
  207997. bool result = false;
  207998. io_object_t iod = getAppleRemoteDevice();
  207999. if (iod != 0)
  208000. {
  208001. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208002. result = true;
  208003. else
  208004. stop();
  208005. IOObjectRelease (iod);
  208006. }
  208007. return result;
  208008. }
  208009. void AppleRemoteDevice::stop()
  208010. {
  208011. if (queue != 0)
  208012. {
  208013. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208014. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208015. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208016. queue = 0;
  208017. }
  208018. if (device != 0)
  208019. {
  208020. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208021. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208022. device = 0;
  208023. }
  208024. }
  208025. bool AppleRemoteDevice::isActive() const
  208026. {
  208027. return queue != 0;
  208028. }
  208029. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208030. {
  208031. if (result == kIOReturnSuccess)
  208032. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208033. }
  208034. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208035. {
  208036. Array <int> cookies;
  208037. CFArrayRef elements;
  208038. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208039. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208040. return false;
  208041. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208042. {
  208043. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208044. // get the cookie
  208045. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208046. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208047. continue;
  208048. long number;
  208049. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208050. continue;
  208051. cookies.add ((int) number);
  208052. }
  208053. CFRelease (elements);
  208054. if ((*(IOHIDDeviceInterface**) device)
  208055. ->open ((IOHIDDeviceInterface**) device,
  208056. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208057. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208058. {
  208059. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208060. if (queue != 0)
  208061. {
  208062. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208063. for (int i = 0; i < cookies.size(); ++i)
  208064. {
  208065. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208066. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208067. }
  208068. CFRunLoopSourceRef eventSource;
  208069. if ((*(IOHIDQueueInterface**) queue)
  208070. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208071. {
  208072. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208073. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208074. {
  208075. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208076. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208077. return true;
  208078. }
  208079. }
  208080. }
  208081. }
  208082. return false;
  208083. }
  208084. void AppleRemoteDevice::handleCallbackInternal()
  208085. {
  208086. int totalValues = 0;
  208087. AbsoluteTime nullTime = { 0, 0 };
  208088. char cookies [12];
  208089. int numCookies = 0;
  208090. while (numCookies < numElementsInArray (cookies))
  208091. {
  208092. IOHIDEventStruct e;
  208093. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208094. break;
  208095. if ((int) e.elementCookie == 19)
  208096. {
  208097. remoteId = e.value;
  208098. buttonPressed (switched, false);
  208099. }
  208100. else
  208101. {
  208102. totalValues += e.value;
  208103. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208104. }
  208105. }
  208106. cookies [numCookies++] = 0;
  208107. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208108. static const char buttonPatterns[] =
  208109. {
  208110. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208111. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208112. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208113. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208114. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208115. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208116. 0x1f, 0x12, 0x04, 0x02, 0,
  208117. 0x1f, 0x12, 0x03, 0x02, 0,
  208118. 0x1f, 0x12, 0x1f, 0x12, 0,
  208119. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208120. 19, 0
  208121. };
  208122. int buttonNum = (int) menuButton;
  208123. int i = 0;
  208124. while (i < numElementsInArray (buttonPatterns))
  208125. {
  208126. if (strcmp (cookies, buttonPatterns + i) == 0)
  208127. {
  208128. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208129. break;
  208130. }
  208131. i += (int) strlen (buttonPatterns + i) + 1;
  208132. ++buttonNum;
  208133. }
  208134. }
  208135. #endif
  208136. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208137. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208138. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208139. // compiled on its own).
  208140. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208141. #if JUCE_MAC
  208142. END_JUCE_NAMESPACE
  208143. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208144. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208145. {
  208146. CriticalSection* contextLock;
  208147. bool needsUpdate;
  208148. }
  208149. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208150. - (bool) makeActive;
  208151. - (void) makeInactive;
  208152. - (void) reshape;
  208153. @end
  208154. @implementation ThreadSafeNSOpenGLView
  208155. - (id) initWithFrame: (NSRect) frameRect
  208156. pixelFormat: (NSOpenGLPixelFormat*) format
  208157. {
  208158. contextLock = new CriticalSection();
  208159. self = [super initWithFrame: frameRect pixelFormat: format];
  208160. if (self != nil)
  208161. [[NSNotificationCenter defaultCenter] addObserver: self
  208162. selector: @selector (_surfaceNeedsUpdate:)
  208163. name: NSViewGlobalFrameDidChangeNotification
  208164. object: self];
  208165. return self;
  208166. }
  208167. - (void) dealloc
  208168. {
  208169. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208170. delete contextLock;
  208171. [super dealloc];
  208172. }
  208173. - (bool) makeActive
  208174. {
  208175. const ScopedLock sl (*contextLock);
  208176. if ([self openGLContext] == 0)
  208177. return false;
  208178. [[self openGLContext] makeCurrentContext];
  208179. if (needsUpdate)
  208180. {
  208181. [super update];
  208182. needsUpdate = false;
  208183. }
  208184. return true;
  208185. }
  208186. - (void) makeInactive
  208187. {
  208188. const ScopedLock sl (*contextLock);
  208189. [NSOpenGLContext clearCurrentContext];
  208190. }
  208191. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208192. {
  208193. const ScopedLock sl (*contextLock);
  208194. needsUpdate = true;
  208195. }
  208196. - (void) update
  208197. {
  208198. const ScopedLock sl (*contextLock);
  208199. needsUpdate = true;
  208200. }
  208201. - (void) reshape
  208202. {
  208203. const ScopedLock sl (*contextLock);
  208204. needsUpdate = true;
  208205. }
  208206. @end
  208207. BEGIN_JUCE_NAMESPACE
  208208. class WindowedGLContext : public OpenGLContext
  208209. {
  208210. public:
  208211. WindowedGLContext (Component* const component,
  208212. const OpenGLPixelFormat& pixelFormat_,
  208213. NSOpenGLContext* sharedContext)
  208214. : renderContext (0),
  208215. pixelFormat (pixelFormat_)
  208216. {
  208217. jassert (component != 0);
  208218. NSOpenGLPixelFormatAttribute attribs [64];
  208219. int n = 0;
  208220. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208221. attribs[n++] = NSOpenGLPFAAccelerated;
  208222. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208223. attribs[n++] = NSOpenGLPFAColorSize;
  208224. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208225. pixelFormat.greenBits,
  208226. pixelFormat.blueBits);
  208227. attribs[n++] = NSOpenGLPFAAlphaSize;
  208228. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208229. attribs[n++] = NSOpenGLPFADepthSize;
  208230. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208231. attribs[n++] = NSOpenGLPFAStencilSize;
  208232. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208233. attribs[n++] = NSOpenGLPFAAccumSize;
  208234. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208235. pixelFormat.accumulationBufferGreenBits,
  208236. pixelFormat.accumulationBufferBlueBits,
  208237. pixelFormat.accumulationBufferAlphaBits);
  208238. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208239. attribs[n++] = NSOpenGLPFASampleBuffers;
  208240. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208241. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208242. attribs[n++] = NSOpenGLPFANoRecovery;
  208243. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208244. NSOpenGLPixelFormat* format
  208245. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208246. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208247. pixelFormat: format];
  208248. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208249. shareContext: sharedContext] autorelease];
  208250. const GLint swapInterval = 1;
  208251. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208252. [view setOpenGLContext: renderContext];
  208253. [renderContext setView: view];
  208254. [format release];
  208255. viewHolder = new NSViewComponentInternal (view, component);
  208256. }
  208257. ~WindowedGLContext()
  208258. {
  208259. makeInactive();
  208260. [renderContext clearDrawable];
  208261. viewHolder = 0;
  208262. }
  208263. bool makeActive() const throw()
  208264. {
  208265. jassert (renderContext != 0);
  208266. [view makeActive];
  208267. return isActive();
  208268. }
  208269. bool makeInactive() const throw()
  208270. {
  208271. [view makeInactive];
  208272. return true;
  208273. }
  208274. bool isActive() const throw()
  208275. {
  208276. return [NSOpenGLContext currentContext] == renderContext;
  208277. }
  208278. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208279. void* getRawContext() const throw() { return renderContext; }
  208280. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208281. {
  208282. }
  208283. void swapBuffers()
  208284. {
  208285. [renderContext flushBuffer];
  208286. }
  208287. bool setSwapInterval (const int numFramesPerSwap)
  208288. {
  208289. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208290. forParameter: NSOpenGLCPSwapInterval];
  208291. return true;
  208292. }
  208293. int getSwapInterval() const
  208294. {
  208295. GLint numFrames = 0;
  208296. [renderContext getValues: &numFrames
  208297. forParameter: NSOpenGLCPSwapInterval];
  208298. return numFrames;
  208299. }
  208300. void repaint()
  208301. {
  208302. // we need to invalidate the juce view that holds this gl view, to make it
  208303. // cause a repaint callback
  208304. NSView* v = (NSView*) viewHolder->view;
  208305. NSRect r = [v frame];
  208306. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208307. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208308. // repaint message, thus never causing our paint() callback, and never repainting
  208309. // the comp. So invalidating just a little bit around the edge helps..
  208310. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208311. }
  208312. void* getNativeWindowHandle() const { return viewHolder->view; }
  208313. juce_UseDebuggingNewOperator
  208314. NSOpenGLContext* renderContext;
  208315. ThreadSafeNSOpenGLView* view;
  208316. private:
  208317. OpenGLPixelFormat pixelFormat;
  208318. ScopedPointer <NSViewComponentInternal> viewHolder;
  208319. WindowedGLContext (const WindowedGLContext&);
  208320. WindowedGLContext& operator= (const WindowedGLContext&);
  208321. };
  208322. OpenGLContext* OpenGLComponent::createContext()
  208323. {
  208324. ScopedPointer<WindowedGLContext> c (new WindowedGLContext (this, preferredPixelFormat,
  208325. contextToShareListsWith != 0 ? (NSOpenGLContext*) contextToShareListsWith->getRawContext() : 0));
  208326. return (c->renderContext != 0) ? c.release() : 0;
  208327. }
  208328. void* OpenGLComponent::getNativeWindowHandle() const
  208329. {
  208330. return context != 0 ? static_cast<WindowedGLContext*> (static_cast<OpenGLContext*> (context))->getNativeWindowHandle()
  208331. : 0;
  208332. }
  208333. void juce_glViewport (const int w, const int h)
  208334. {
  208335. glViewport (0, 0, w, h);
  208336. }
  208337. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208338. OwnedArray <OpenGLPixelFormat>& results)
  208339. {
  208340. /* GLint attribs [64];
  208341. int n = 0;
  208342. attribs[n++] = AGL_RGBA;
  208343. attribs[n++] = AGL_DOUBLEBUFFER;
  208344. attribs[n++] = AGL_ACCELERATED;
  208345. attribs[n++] = AGL_NO_RECOVERY;
  208346. attribs[n++] = AGL_NONE;
  208347. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208348. while (p != 0)
  208349. {
  208350. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208351. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208352. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208353. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208354. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208355. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208356. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208357. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208358. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208359. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208360. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208361. results.add (pf);
  208362. p = aglNextPixelFormat (p);
  208363. }*/
  208364. //jassertfalse //xxx can't see how you do this in cocoa!
  208365. }
  208366. #else
  208367. END_JUCE_NAMESPACE
  208368. @interface JuceGLView : UIView
  208369. {
  208370. }
  208371. + (Class) layerClass;
  208372. @end
  208373. @implementation JuceGLView
  208374. + (Class) layerClass
  208375. {
  208376. return [CAEAGLLayer class];
  208377. }
  208378. @end
  208379. BEGIN_JUCE_NAMESPACE
  208380. class GLESContext : public OpenGLContext
  208381. {
  208382. public:
  208383. GLESContext (UIViewComponentPeer* peer,
  208384. Component* const component_,
  208385. const OpenGLPixelFormat& pixelFormat_,
  208386. const GLESContext* const sharedContext,
  208387. NSUInteger apiType)
  208388. : component (component_), pixelFormat (pixelFormat_), glLayer (0), context (0),
  208389. useDepthBuffer (pixelFormat_.depthBufferBits > 0), frameBufferHandle (0), colorBufferHandle (0),
  208390. depthBufferHandle (0), lastWidth (0), lastHeight (0)
  208391. {
  208392. view = [[JuceGLView alloc] initWithFrame: CGRectMake (0, 0, 64, 64)];
  208393. view.opaque = YES;
  208394. view.hidden = NO;
  208395. view.backgroundColor = [UIColor blackColor];
  208396. view.userInteractionEnabled = NO;
  208397. glLayer = (CAEAGLLayer*) [view layer];
  208398. [peer->view addSubview: view];
  208399. if (sharedContext != 0)
  208400. context = [[EAGLContext alloc] initWithAPI: apiType
  208401. sharegroup: [sharedContext->context sharegroup]];
  208402. else
  208403. context = [[EAGLContext alloc] initWithAPI: apiType];
  208404. createGLBuffers();
  208405. }
  208406. ~GLESContext()
  208407. {
  208408. makeInactive();
  208409. [context release];
  208410. [view removeFromSuperview];
  208411. [view release];
  208412. freeGLBuffers();
  208413. }
  208414. bool makeActive() const throw()
  208415. {
  208416. jassert (context != 0);
  208417. [EAGLContext setCurrentContext: context];
  208418. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208419. return true;
  208420. }
  208421. void swapBuffers()
  208422. {
  208423. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208424. [context presentRenderbuffer: GL_RENDERBUFFER_OES];
  208425. }
  208426. bool makeInactive() const throw()
  208427. {
  208428. return [EAGLContext setCurrentContext: nil];
  208429. }
  208430. bool isActive() const throw()
  208431. {
  208432. return [EAGLContext currentContext] == context;
  208433. }
  208434. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208435. void* getRawContext() const throw() { return glLayer; }
  208436. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208437. {
  208438. view.frame = CGRectMake ((CGFloat) x, (CGFloat) y, (CGFloat) w, (CGFloat) h);
  208439. if (lastWidth != w || lastHeight != h)
  208440. {
  208441. lastWidth = w;
  208442. lastHeight = h;
  208443. freeGLBuffers();
  208444. createGLBuffers();
  208445. }
  208446. }
  208447. bool setSwapInterval (const int numFramesPerSwap)
  208448. {
  208449. numFrames = numFramesPerSwap;
  208450. return true;
  208451. }
  208452. int getSwapInterval() const
  208453. {
  208454. return numFrames;
  208455. }
  208456. void repaint()
  208457. {
  208458. }
  208459. void createGLBuffers()
  208460. {
  208461. makeActive();
  208462. glGenFramebuffersOES (1, &frameBufferHandle);
  208463. glGenRenderbuffersOES (1, &colorBufferHandle);
  208464. glGenRenderbuffersOES (1, &depthBufferHandle);
  208465. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208466. [context renderbufferStorage: GL_RENDERBUFFER_OES fromDrawable: glLayer];
  208467. GLint width, height;
  208468. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &width);
  208469. glGetRenderbufferParameterivOES (GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &height);
  208470. if (useDepthBuffer)
  208471. {
  208472. glBindRenderbufferOES (GL_RENDERBUFFER_OES, depthBufferHandle);
  208473. glRenderbufferStorageOES (GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, width, height);
  208474. }
  208475. glBindRenderbufferOES (GL_RENDERBUFFER_OES, colorBufferHandle);
  208476. glBindFramebufferOES (GL_FRAMEBUFFER_OES, frameBufferHandle);
  208477. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorBufferHandle);
  208478. if (useDepthBuffer)
  208479. glFramebufferRenderbufferOES (GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthBufferHandle);
  208480. jassert (glCheckFramebufferStatusOES (GL_FRAMEBUFFER_OES) == GL_FRAMEBUFFER_COMPLETE_OES);
  208481. }
  208482. void freeGLBuffers()
  208483. {
  208484. if (frameBufferHandle != 0)
  208485. {
  208486. glDeleteFramebuffersOES (1, &frameBufferHandle);
  208487. frameBufferHandle = 0;
  208488. }
  208489. if (colorBufferHandle != 0)
  208490. {
  208491. glDeleteRenderbuffersOES (1, &colorBufferHandle);
  208492. colorBufferHandle = 0;
  208493. }
  208494. if (depthBufferHandle != 0)
  208495. {
  208496. glDeleteRenderbuffersOES (1, &depthBufferHandle);
  208497. depthBufferHandle = 0;
  208498. }
  208499. }
  208500. juce_UseDebuggingNewOperator
  208501. private:
  208502. Component::SafePointer<Component> component;
  208503. OpenGLPixelFormat pixelFormat;
  208504. JuceGLView* view;
  208505. CAEAGLLayer* glLayer;
  208506. EAGLContext* context;
  208507. bool useDepthBuffer;
  208508. GLuint frameBufferHandle, colorBufferHandle, depthBufferHandle;
  208509. int numFrames;
  208510. int lastWidth, lastHeight;
  208511. GLESContext (const GLESContext&);
  208512. GLESContext& operator= (const GLESContext&);
  208513. };
  208514. OpenGLContext* OpenGLComponent::createContext()
  208515. {
  208516. ScopedAutoReleasePool pool;
  208517. UIViewComponentPeer* peer = dynamic_cast <UIViewComponentPeer*> (getPeer());
  208518. if (peer != 0)
  208519. return new GLESContext (peer, this, preferredPixelFormat,
  208520. dynamic_cast <const GLESContext*> (contextToShareListsWith),
  208521. type == openGLES2 ? kEAGLRenderingAPIOpenGLES2 : kEAGLRenderingAPIOpenGLES1);
  208522. return 0;
  208523. }
  208524. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208525. OwnedArray <OpenGLPixelFormat>& /*results*/)
  208526. {
  208527. }
  208528. void juce_glViewport (const int w, const int h)
  208529. {
  208530. glViewport (0, 0, w, h);
  208531. }
  208532. #endif
  208533. #endif
  208534. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208535. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208536. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208537. // compiled on its own).
  208538. #if JUCE_INCLUDED_FILE
  208539. class JuceMainMenuHandler;
  208540. END_JUCE_NAMESPACE
  208541. using namespace JUCE_NAMESPACE;
  208542. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208543. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208544. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208545. #else
  208546. @interface JuceMenuCallback : NSObject
  208547. #endif
  208548. {
  208549. JuceMainMenuHandler* owner;
  208550. }
  208551. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208552. - (void) dealloc;
  208553. - (void) menuItemInvoked: (id) menu;
  208554. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208555. @end
  208556. BEGIN_JUCE_NAMESPACE
  208557. class JuceMainMenuHandler : private MenuBarModelListener,
  208558. private DeletedAtShutdown
  208559. {
  208560. public:
  208561. static JuceMainMenuHandler* instance;
  208562. JuceMainMenuHandler()
  208563. : currentModel (0),
  208564. lastUpdateTime (0)
  208565. {
  208566. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208567. }
  208568. ~JuceMainMenuHandler()
  208569. {
  208570. setMenu (0);
  208571. jassert (instance == this);
  208572. instance = 0;
  208573. [callback release];
  208574. }
  208575. void setMenu (MenuBarModel* const newMenuBarModel)
  208576. {
  208577. if (currentModel != newMenuBarModel)
  208578. {
  208579. if (currentModel != 0)
  208580. currentModel->removeListener (this);
  208581. currentModel = newMenuBarModel;
  208582. if (currentModel != 0)
  208583. currentModel->addListener (this);
  208584. menuBarItemsChanged (0);
  208585. }
  208586. }
  208587. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208588. const String& name, const int menuId, const int tag)
  208589. {
  208590. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208591. action: nil
  208592. keyEquivalent: @""];
  208593. [item setTag: tag];
  208594. NSMenu* sub = createMenu (child, name, menuId, tag);
  208595. [parent setSubmenu: sub forItem: item];
  208596. [sub setAutoenablesItems: false];
  208597. [sub release];
  208598. }
  208599. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208600. const String& name, const int menuId, const int tag)
  208601. {
  208602. [parentItem setTag: tag];
  208603. NSMenu* menu = [parentItem submenu];
  208604. [menu setTitle: juceStringToNS (name)];
  208605. while ([menu numberOfItems] > 0)
  208606. [menu removeItemAtIndex: 0];
  208607. PopupMenu::MenuItemIterator iter (menuToCopy);
  208608. while (iter.next())
  208609. addMenuItem (iter, menu, menuId, tag);
  208610. [menu setAutoenablesItems: false];
  208611. [menu update];
  208612. }
  208613. void menuBarItemsChanged (MenuBarModel*)
  208614. {
  208615. lastUpdateTime = Time::getMillisecondCounter();
  208616. StringArray menuNames;
  208617. if (currentModel != 0)
  208618. menuNames = currentModel->getMenuBarNames();
  208619. NSMenu* menuBar = [NSApp mainMenu];
  208620. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208621. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208622. int menuId = 1;
  208623. for (int i = 0; i < menuNames.size(); ++i)
  208624. {
  208625. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208626. if (i >= [menuBar numberOfItems] - 1)
  208627. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208628. else
  208629. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208630. }
  208631. }
  208632. static void flashMenuBar (NSMenu* menu)
  208633. {
  208634. if ([[menu title] isEqualToString: @"Apple"])
  208635. return;
  208636. [menu retain];
  208637. const unichar f35Key = NSF35FunctionKey;
  208638. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208639. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208640. action: nil
  208641. keyEquivalent: f35String];
  208642. [item setTarget: nil];
  208643. [menu insertItem: item atIndex: [menu numberOfItems]];
  208644. [item release];
  208645. if ([menu indexOfItem: item] >= 0)
  208646. {
  208647. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208648. location: NSZeroPoint
  208649. modifierFlags: NSCommandKeyMask
  208650. timestamp: 0
  208651. windowNumber: 0
  208652. context: [NSGraphicsContext currentContext]
  208653. characters: f35String
  208654. charactersIgnoringModifiers: f35String
  208655. isARepeat: NO
  208656. keyCode: 0];
  208657. [menu performKeyEquivalent: f35Event];
  208658. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208659. }
  208660. [menu release];
  208661. }
  208662. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208663. {
  208664. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208665. {
  208666. NSMenuItem* m = [menu itemAtIndex: i];
  208667. if ([m tag] == info.commandID)
  208668. return m;
  208669. if ([m submenu] != 0)
  208670. {
  208671. NSMenuItem* found = findMenuItem ([m submenu], info);
  208672. if (found != 0)
  208673. return found;
  208674. }
  208675. }
  208676. return 0;
  208677. }
  208678. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208679. {
  208680. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208681. if (item != 0)
  208682. flashMenuBar ([item menu]);
  208683. }
  208684. void updateMenus()
  208685. {
  208686. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208687. menuBarItemsChanged (0);
  208688. }
  208689. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208690. {
  208691. if (currentModel != 0)
  208692. {
  208693. if (commandManager != 0)
  208694. {
  208695. ApplicationCommandTarget::InvocationInfo info (commandId);
  208696. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208697. commandManager->invoke (info, true);
  208698. }
  208699. currentModel->menuItemSelected (commandId, topLevelIndex);
  208700. }
  208701. }
  208702. MenuBarModel* currentModel;
  208703. uint32 lastUpdateTime;
  208704. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208705. const int topLevelMenuId, const int topLevelIndex)
  208706. {
  208707. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf ("<end>", false, true));
  208708. if (text == 0)
  208709. text = @"";
  208710. if (iter.isSeparator)
  208711. {
  208712. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208713. }
  208714. else if (iter.isSectionHeader)
  208715. {
  208716. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208717. action: nil
  208718. keyEquivalent: @""];
  208719. [item setEnabled: false];
  208720. }
  208721. else if (iter.subMenu != 0)
  208722. {
  208723. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208724. action: nil
  208725. keyEquivalent: @""];
  208726. [item setTag: iter.itemId];
  208727. [item setEnabled: iter.isEnabled];
  208728. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208729. [sub setDelegate: nil];
  208730. [menuToAddTo setSubmenu: sub forItem: item];
  208731. [sub release];
  208732. }
  208733. else
  208734. {
  208735. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208736. action: @selector (menuItemInvoked:)
  208737. keyEquivalent: @""];
  208738. [item setTag: iter.itemId];
  208739. [item setEnabled: iter.isEnabled];
  208740. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208741. [item setTarget: (id) callback];
  208742. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208743. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208744. [item setRepresentedObject: info];
  208745. if (iter.commandManager != 0)
  208746. {
  208747. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208748. ->getKeyPressesAssignedToCommand (iter.itemId));
  208749. if (keyPresses.size() > 0)
  208750. {
  208751. const KeyPress& kp = keyPresses.getReference(0);
  208752. juce_wchar key = kp.getTextCharacter();
  208753. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208754. key = NSBackspaceCharacter;
  208755. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208756. key = NSDeleteCharacter;
  208757. else if (key == 0)
  208758. key = (juce_wchar) kp.getKeyCode();
  208759. unsigned int mods = 0;
  208760. if (kp.getModifiers().isShiftDown())
  208761. mods |= NSShiftKeyMask;
  208762. if (kp.getModifiers().isCtrlDown())
  208763. mods |= NSControlKeyMask;
  208764. if (kp.getModifiers().isAltDown())
  208765. mods |= NSAlternateKeyMask;
  208766. if (kp.getModifiers().isCommandDown())
  208767. mods |= NSCommandKeyMask;
  208768. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208769. [item setKeyEquivalentModifierMask: mods];
  208770. }
  208771. }
  208772. }
  208773. }
  208774. JuceMenuCallback* callback;
  208775. private:
  208776. NSMenu* createMenu (const PopupMenu menu,
  208777. const String& menuName,
  208778. const int topLevelMenuId,
  208779. const int topLevelIndex)
  208780. {
  208781. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208782. [m setAutoenablesItems: false];
  208783. [m setDelegate: callback];
  208784. PopupMenu::MenuItemIterator iter (menu);
  208785. while (iter.next())
  208786. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208787. [m update];
  208788. return m;
  208789. }
  208790. };
  208791. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208792. END_JUCE_NAMESPACE
  208793. @implementation JuceMenuCallback
  208794. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208795. {
  208796. [super init];
  208797. owner = owner_;
  208798. return self;
  208799. }
  208800. - (void) dealloc
  208801. {
  208802. [super dealloc];
  208803. }
  208804. - (void) menuItemInvoked: (id) menu
  208805. {
  208806. NSMenuItem* item = (NSMenuItem*) menu;
  208807. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208808. {
  208809. // 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
  208810. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208811. // into the focused component and let it trigger the menu item indirectly.
  208812. NSEvent* e = [NSApp currentEvent];
  208813. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208814. {
  208815. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent() != 0)
  208816. {
  208817. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208818. if (peer != 0)
  208819. {
  208820. if ([e type] == NSKeyDown)
  208821. peer->redirectKeyDown (e);
  208822. else
  208823. peer->redirectKeyUp (e);
  208824. return;
  208825. }
  208826. }
  208827. }
  208828. NSArray* info = (NSArray*) [item representedObject];
  208829. owner->invoke ((int) [item tag],
  208830. (ApplicationCommandManager*) (pointer_sized_int)
  208831. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208832. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208833. }
  208834. }
  208835. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208836. {
  208837. if (JuceMainMenuHandler::instance != 0)
  208838. JuceMainMenuHandler::instance->updateMenus();
  208839. }
  208840. @end
  208841. BEGIN_JUCE_NAMESPACE
  208842. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208843. const PopupMenu* extraItems)
  208844. {
  208845. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208846. {
  208847. PopupMenu::MenuItemIterator iter (*extraItems);
  208848. while (iter.next())
  208849. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208850. [menu addItem: [NSMenuItem separatorItem]];
  208851. }
  208852. NSMenuItem* item;
  208853. // Services...
  208854. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208855. action: nil keyEquivalent: @""];
  208856. [menu addItem: item];
  208857. [item release];
  208858. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208859. [menu setSubmenu: servicesMenu forItem: item];
  208860. [NSApp setServicesMenu: servicesMenu];
  208861. [servicesMenu release];
  208862. [menu addItem: [NSMenuItem separatorItem]];
  208863. // Hide + Show stuff...
  208864. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208865. action: @selector (hide:) keyEquivalent: @"h"];
  208866. [item setTarget: NSApp];
  208867. [menu addItem: item];
  208868. [item release];
  208869. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208870. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208871. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208872. [item setTarget: NSApp];
  208873. [menu addItem: item];
  208874. [item release];
  208875. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208876. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208877. [item setTarget: NSApp];
  208878. [menu addItem: item];
  208879. [item release];
  208880. [menu addItem: [NSMenuItem separatorItem]];
  208881. // Quit item....
  208882. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208883. action: @selector (terminate:) keyEquivalent: @"q"];
  208884. [item setTarget: NSApp];
  208885. [menu addItem: item];
  208886. [item release];
  208887. return menu;
  208888. }
  208889. // Since our app has no NIB, this initialises a standard app menu...
  208890. static void rebuildMainMenu (const PopupMenu* extraItems)
  208891. {
  208892. // this can't be used in a plugin!
  208893. jassert (JUCEApplication::getInstance() != 0);
  208894. if (JUCEApplication::getInstance() != 0)
  208895. {
  208896. const ScopedAutoReleasePool pool;
  208897. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208898. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208899. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208900. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208901. [mainMenu setSubmenu: appMenu forItem: item];
  208902. [NSApp setMainMenu: mainMenu];
  208903. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208904. [appMenu release];
  208905. [mainMenu release];
  208906. }
  208907. }
  208908. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208909. const PopupMenu* extraAppleMenuItems)
  208910. {
  208911. if (getMacMainMenu() != newMenuBarModel)
  208912. {
  208913. const ScopedAutoReleasePool pool;
  208914. if (newMenuBarModel == 0)
  208915. {
  208916. delete JuceMainMenuHandler::instance;
  208917. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208918. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208919. extraAppleMenuItems = 0;
  208920. }
  208921. else
  208922. {
  208923. if (JuceMainMenuHandler::instance == 0)
  208924. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208925. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208926. }
  208927. }
  208928. rebuildMainMenu (extraAppleMenuItems);
  208929. if (newMenuBarModel != 0)
  208930. newMenuBarModel->menuItemsChanged();
  208931. }
  208932. MenuBarModel* MenuBarModel::getMacMainMenu()
  208933. {
  208934. return JuceMainMenuHandler::instance != 0
  208935. ? JuceMainMenuHandler::instance->currentModel : 0;
  208936. }
  208937. void initialiseMainMenu()
  208938. {
  208939. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208940. rebuildMainMenu (0);
  208941. }
  208942. #endif
  208943. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208944. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208945. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208946. // compiled on its own).
  208947. #if JUCE_INCLUDED_FILE
  208948. #if JUCE_MAC
  208949. END_JUCE_NAMESPACE
  208950. using namespace JUCE_NAMESPACE;
  208951. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208952. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208953. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208954. #else
  208955. @interface JuceFileChooserDelegate : NSObject
  208956. #endif
  208957. {
  208958. StringArray* filters;
  208959. }
  208960. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208961. - (void) dealloc;
  208962. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208963. @end
  208964. @implementation JuceFileChooserDelegate
  208965. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208966. {
  208967. [super init];
  208968. filters = filters_;
  208969. return self;
  208970. }
  208971. - (void) dealloc
  208972. {
  208973. delete filters;
  208974. [super dealloc];
  208975. }
  208976. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208977. {
  208978. const File f (nsStringToJuce (filename));
  208979. for (int i = filters->size(); --i >= 0;)
  208980. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208981. return true;
  208982. return f.isDirectory();
  208983. }
  208984. @end
  208985. BEGIN_JUCE_NAMESPACE
  208986. void FileChooser::showPlatformDialog (Array<File>& results,
  208987. const String& title,
  208988. const File& currentFileOrDirectory,
  208989. const String& filter,
  208990. bool selectsDirectory,
  208991. bool selectsFiles,
  208992. bool isSaveDialogue,
  208993. bool warnAboutOverwritingExistingFiles,
  208994. bool selectMultipleFiles,
  208995. FilePreviewComponent* extraInfoComponent)
  208996. {
  208997. const ScopedAutoReleasePool pool;
  208998. StringArray* filters = new StringArray();
  208999. filters->addTokens (filter.replaceCharacters (",:", ";;"), ";", String::empty);
  209000. filters->trim();
  209001. filters->removeEmptyStrings();
  209002. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  209003. [delegate autorelease];
  209004. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  209005. : [NSOpenPanel openPanel];
  209006. [panel setTitle: juceStringToNS (title)];
  209007. if (! isSaveDialogue)
  209008. {
  209009. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209010. [openPanel setCanChooseDirectories: selectsDirectory];
  209011. [openPanel setCanChooseFiles: selectsFiles];
  209012. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  209013. }
  209014. [panel setDelegate: delegate];
  209015. if (isSaveDialogue || selectsDirectory)
  209016. [panel setCanCreateDirectories: YES];
  209017. String directory, filename;
  209018. if (currentFileOrDirectory.isDirectory())
  209019. {
  209020. directory = currentFileOrDirectory.getFullPathName();
  209021. }
  209022. else
  209023. {
  209024. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  209025. filename = currentFileOrDirectory.getFileName();
  209026. }
  209027. if ([panel runModalForDirectory: juceStringToNS (directory)
  209028. file: juceStringToNS (filename)]
  209029. == NSOKButton)
  209030. {
  209031. if (isSaveDialogue)
  209032. {
  209033. results.add (File (nsStringToJuce ([panel filename])));
  209034. }
  209035. else
  209036. {
  209037. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  209038. NSArray* urls = [openPanel filenames];
  209039. for (unsigned int i = 0; i < [urls count]; ++i)
  209040. {
  209041. NSString* f = [urls objectAtIndex: i];
  209042. results.add (File (nsStringToJuce (f)));
  209043. }
  209044. }
  209045. }
  209046. [panel setDelegate: nil];
  209047. }
  209048. #else
  209049. void FileChooser::showPlatformDialog (Array<File>& results,
  209050. const String& title,
  209051. const File& currentFileOrDirectory,
  209052. const String& filter,
  209053. bool selectsDirectory,
  209054. bool selectsFiles,
  209055. bool isSaveDialogue,
  209056. bool warnAboutOverwritingExistingFiles,
  209057. bool selectMultipleFiles,
  209058. FilePreviewComponent* extraInfoComponent)
  209059. {
  209060. const ScopedAutoReleasePool pool;
  209061. jassertfalse //xxx to do
  209062. }
  209063. #endif
  209064. #endif
  209065. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209066. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209067. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209068. // compiled on its own).
  209069. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209070. END_JUCE_NAMESPACE
  209071. #define NonInterceptingQTMovieView MakeObjCClassName(NonInterceptingQTMovieView)
  209072. @interface NonInterceptingQTMovieView : QTMovieView
  209073. {
  209074. }
  209075. - (id) initWithFrame: (NSRect) frame;
  209076. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent;
  209077. - (NSView*) hitTest: (NSPoint) p;
  209078. @end
  209079. @implementation NonInterceptingQTMovieView
  209080. - (id) initWithFrame: (NSRect) frame
  209081. {
  209082. self = [super initWithFrame: frame];
  209083. [self setNextResponder: [self superview]];
  209084. return self;
  209085. }
  209086. - (void) dealloc
  209087. {
  209088. [super dealloc];
  209089. }
  209090. - (NSView*) hitTest: (NSPoint) point
  209091. {
  209092. return [self isControllerVisible] ? [super hitTest: point] : nil;
  209093. }
  209094. - (BOOL) acceptsFirstMouse: (NSEvent*) theEvent
  209095. {
  209096. return YES;
  209097. }
  209098. @end
  209099. BEGIN_JUCE_NAMESPACE
  209100. #define theMovie (static_cast <QTMovie*> (movie))
  209101. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209102. : movie (0)
  209103. {
  209104. setOpaque (true);
  209105. setVisible (true);
  209106. QTMovieView* view = [[NonInterceptingQTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209107. setView (view);
  209108. [view release];
  209109. }
  209110. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209111. {
  209112. closeMovie();
  209113. setView (0);
  209114. }
  209115. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209116. {
  209117. return true;
  209118. }
  209119. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209120. {
  209121. // unfortunately, QTMovie objects can only be created on the main thread..
  209122. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209123. QTMovie* movie = 0;
  209124. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209125. if (fin != 0)
  209126. {
  209127. movieFile = fin->getFile();
  209128. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209129. error: nil];
  209130. }
  209131. else
  209132. {
  209133. MemoryBlock temp;
  209134. movieStream->readIntoMemoryBlock (temp);
  209135. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209136. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209137. {
  209138. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209139. length: temp.getSize()]
  209140. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209141. MIMEType: @""]
  209142. error: nil];
  209143. if (movie != 0)
  209144. break;
  209145. }
  209146. }
  209147. return movie;
  209148. }
  209149. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209150. const bool isControllerVisible_)
  209151. {
  209152. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209153. }
  209154. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209155. const bool controllerVisible_)
  209156. {
  209157. closeMovie();
  209158. if (getPeer() == 0)
  209159. {
  209160. // To open a movie, this component must be visible inside a functioning window, so that
  209161. // the QT control can be assigned to the window.
  209162. jassertfalse
  209163. return false;
  209164. }
  209165. movie = openMovieFromStream (movieStream, movieFile);
  209166. [theMovie retain];
  209167. QTMovieView* view = (QTMovieView*) getView();
  209168. [view setMovie: theMovie];
  209169. [view setControllerVisible: controllerVisible_];
  209170. setLooping (looping);
  209171. return movie != nil;
  209172. }
  209173. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209174. const bool isControllerVisible_)
  209175. {
  209176. // unfortunately, QTMovie objects can only be created on the main thread..
  209177. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209178. closeMovie();
  209179. if (getPeer() == 0)
  209180. {
  209181. // To open a movie, this component must be visible inside a functioning window, so that
  209182. // the QT control can be assigned to the window.
  209183. jassertfalse
  209184. return false;
  209185. }
  209186. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209187. NSError* err;
  209188. if ([QTMovie canInitWithURL: url])
  209189. movie = [QTMovie movieWithURL: url error: &err];
  209190. [theMovie retain];
  209191. QTMovieView* view = (QTMovieView*) getView();
  209192. [view setMovie: theMovie];
  209193. [view setControllerVisible: controllerVisible];
  209194. setLooping (looping);
  209195. return movie != nil;
  209196. }
  209197. void QuickTimeMovieComponent::closeMovie()
  209198. {
  209199. stop();
  209200. QTMovieView* view = (QTMovieView*) getView();
  209201. [view setMovie: nil];
  209202. [theMovie release];
  209203. movie = 0;
  209204. movieFile = File::nonexistent;
  209205. }
  209206. bool QuickTimeMovieComponent::isMovieOpen() const
  209207. {
  209208. return movie != nil;
  209209. }
  209210. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209211. {
  209212. return movieFile;
  209213. }
  209214. void QuickTimeMovieComponent::play()
  209215. {
  209216. [theMovie play];
  209217. }
  209218. void QuickTimeMovieComponent::stop()
  209219. {
  209220. [theMovie stop];
  209221. }
  209222. bool QuickTimeMovieComponent::isPlaying() const
  209223. {
  209224. return movie != 0 && [theMovie rate] != 0;
  209225. }
  209226. void QuickTimeMovieComponent::setPosition (const double seconds)
  209227. {
  209228. if (movie != 0)
  209229. {
  209230. QTTime t;
  209231. t.timeValue = (uint64) (100000.0 * seconds);
  209232. t.timeScale = 100000;
  209233. t.flags = 0;
  209234. [theMovie setCurrentTime: t];
  209235. }
  209236. }
  209237. double QuickTimeMovieComponent::getPosition() const
  209238. {
  209239. if (movie == 0)
  209240. return 0.0;
  209241. QTTime t = [theMovie currentTime];
  209242. return t.timeValue / (double) t.timeScale;
  209243. }
  209244. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209245. {
  209246. [theMovie setRate: newSpeed];
  209247. }
  209248. double QuickTimeMovieComponent::getMovieDuration() const
  209249. {
  209250. if (movie == 0)
  209251. return 0.0;
  209252. QTTime t = [theMovie duration];
  209253. return t.timeValue / (double) t.timeScale;
  209254. }
  209255. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209256. {
  209257. looping = shouldLoop;
  209258. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209259. forKey: QTMovieLoopsAttribute];
  209260. }
  209261. bool QuickTimeMovieComponent::isLooping() const
  209262. {
  209263. return looping;
  209264. }
  209265. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209266. {
  209267. [theMovie setVolume: newVolume];
  209268. }
  209269. float QuickTimeMovieComponent::getMovieVolume() const
  209270. {
  209271. return movie != 0 ? [theMovie volume] : 0.0f;
  209272. }
  209273. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209274. {
  209275. width = 0;
  209276. height = 0;
  209277. if (movie != 0)
  209278. {
  209279. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209280. width = (int) s.width;
  209281. height = (int) s.height;
  209282. }
  209283. }
  209284. void QuickTimeMovieComponent::paint (Graphics& g)
  209285. {
  209286. if (movie == 0)
  209287. g.fillAll (Colours::black);
  209288. }
  209289. bool QuickTimeMovieComponent::isControllerVisible() const
  209290. {
  209291. return controllerVisible;
  209292. }
  209293. void QuickTimeMovieComponent::goToStart()
  209294. {
  209295. setPosition (0.0);
  209296. }
  209297. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209298. const RectanglePlacement& placement)
  209299. {
  209300. int normalWidth, normalHeight;
  209301. getMovieNormalSize (normalWidth, normalHeight);
  209302. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209303. {
  209304. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209305. placement.applyTo (x, y, w, h,
  209306. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209307. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209308. if (w > 0 && h > 0)
  209309. {
  209310. setBounds (roundToInt (x), roundToInt (y),
  209311. roundToInt (w), roundToInt (h));
  209312. }
  209313. }
  209314. else
  209315. {
  209316. setBounds (spaceToFitWithin);
  209317. }
  209318. }
  209319. #if ! (JUCE_MAC && JUCE_64BIT)
  209320. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209321. {
  209322. if (movieStream == 0)
  209323. return false;
  209324. File file;
  209325. QTMovie* movie = openMovieFromStream (movieStream, file);
  209326. if (movie != nil)
  209327. result = [movie quickTimeMovie];
  209328. return movie != nil;
  209329. }
  209330. #endif
  209331. #endif
  209332. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209333. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209334. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209335. // compiled on its own).
  209336. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209337. const int kilobytesPerSecond1x = 176;
  209338. END_JUCE_NAMESPACE
  209339. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209340. @interface OpenDiskDevice : NSObject
  209341. {
  209342. @public
  209343. DRDevice* device;
  209344. NSMutableArray* tracks;
  209345. bool underrunProtection;
  209346. }
  209347. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209348. - (void) dealloc;
  209349. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209350. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209351. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209352. @end
  209353. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209354. @interface AudioTrackProducer : NSObject
  209355. {
  209356. JUCE_NAMESPACE::AudioSource* source;
  209357. int readPosition, lengthInFrames;
  209358. }
  209359. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209360. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209361. - (void) dealloc;
  209362. - (void) setupTrackProperties: (DRTrack*) track;
  209363. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209364. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209365. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209366. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209367. toMedia:(NSDictionary*)mediaInfo;
  209368. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209369. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209370. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209371. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209372. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209373. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209374. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209375. ioFlags:(uint32_t*)flags;
  209376. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209377. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209378. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209379. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209380. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209381. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209382. ioFlags:(uint32_t*)flags;
  209383. @end
  209384. @implementation OpenDiskDevice
  209385. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209386. {
  209387. [super init];
  209388. device = device_;
  209389. tracks = [[NSMutableArray alloc] init];
  209390. underrunProtection = true;
  209391. return self;
  209392. }
  209393. - (void) dealloc
  209394. {
  209395. [tracks release];
  209396. [super dealloc];
  209397. }
  209398. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209399. {
  209400. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209401. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209402. [p setupTrackProperties: t];
  209403. [tracks addObject: t];
  209404. [t release];
  209405. [p release];
  209406. }
  209407. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209408. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209409. {
  209410. DRBurn* burn = [DRBurn burnForDevice: device];
  209411. if (! [device acquireExclusiveAccess])
  209412. {
  209413. *error = "Couldn't open or write to the CD device";
  209414. return;
  209415. }
  209416. [device acquireMediaReservation];
  209417. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209418. [d autorelease];
  209419. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209420. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209421. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209422. if (burnSpeed > 0)
  209423. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209424. if (! underrunProtection)
  209425. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209426. [burn setProperties: d];
  209427. [burn writeLayout: tracks];
  209428. for (;;)
  209429. {
  209430. JUCE_NAMESPACE::Thread::sleep (300);
  209431. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209432. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209433. {
  209434. [burn abort];
  209435. *error = "User cancelled the write operation";
  209436. break;
  209437. }
  209438. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209439. {
  209440. *error = "Write operation failed";
  209441. break;
  209442. }
  209443. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209444. {
  209445. break;
  209446. }
  209447. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209448. objectForKey: DRErrorStatusErrorStringKey];
  209449. if ([err length] > 0)
  209450. {
  209451. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209452. break;
  209453. }
  209454. }
  209455. [device releaseMediaReservation];
  209456. [device releaseExclusiveAccess];
  209457. }
  209458. @end
  209459. @implementation AudioTrackProducer
  209460. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209461. {
  209462. lengthInFrames = lengthInFrames_;
  209463. readPosition = 0;
  209464. return self;
  209465. }
  209466. - (void) setupTrackProperties: (DRTrack*) track
  209467. {
  209468. NSMutableDictionary* p = [[track properties] mutableCopy];
  209469. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209470. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209471. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209472. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209473. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209474. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209475. [track setProperties: p];
  209476. [p release];
  209477. }
  209478. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209479. {
  209480. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209481. if (s != nil)
  209482. s->source = source_;
  209483. return s;
  209484. }
  209485. - (void) dealloc
  209486. {
  209487. if (source != 0)
  209488. {
  209489. source->releaseResources();
  209490. delete source;
  209491. }
  209492. [super dealloc];
  209493. }
  209494. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209495. {
  209496. }
  209497. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209498. {
  209499. return true;
  209500. }
  209501. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209502. {
  209503. return lengthInFrames;
  209504. }
  209505. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209506. toMedia: (NSDictionary*) mediaInfo
  209507. {
  209508. if (source != 0)
  209509. source->prepareToPlay (44100 / 75, 44100);
  209510. readPosition = 0;
  209511. return true;
  209512. }
  209513. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209514. {
  209515. if (source != 0)
  209516. source->prepareToPlay (44100 / 75, 44100);
  209517. return true;
  209518. }
  209519. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209520. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209521. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209522. {
  209523. if (source != 0)
  209524. {
  209525. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209526. if (numSamples > 0)
  209527. {
  209528. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209529. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209530. info.buffer = &tempBuffer;
  209531. info.startSample = 0;
  209532. info.numSamples = numSamples;
  209533. source->getNextAudioBlock (info);
  209534. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209535. buffer, numSamples, 4);
  209536. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209537. buffer + 2, numSamples, 4);
  209538. readPosition += numSamples;
  209539. }
  209540. return numSamples * 4;
  209541. }
  209542. return 0;
  209543. }
  209544. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209545. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209546. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209547. ioFlags: (uint32_t*) flags
  209548. {
  209549. zeromem (buffer, bufferLength);
  209550. return bufferLength;
  209551. }
  209552. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209553. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209554. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209555. {
  209556. return true;
  209557. }
  209558. @end
  209559. BEGIN_JUCE_NAMESPACE
  209560. class AudioCDBurner::Pimpl : public Timer
  209561. {
  209562. public:
  209563. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209564. : device (0), owner (owner_)
  209565. {
  209566. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209567. if (dev != 0)
  209568. {
  209569. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209570. lastState = getDiskState();
  209571. startTimer (1000);
  209572. }
  209573. }
  209574. ~Pimpl()
  209575. {
  209576. stopTimer();
  209577. [device release];
  209578. }
  209579. void timerCallback()
  209580. {
  209581. const DiskState state = getDiskState();
  209582. if (state != lastState)
  209583. {
  209584. lastState = state;
  209585. owner.sendChangeMessage (&owner);
  209586. }
  209587. }
  209588. DiskState getDiskState() const
  209589. {
  209590. if ([device->device isValid])
  209591. {
  209592. NSDictionary* status = [device->device status];
  209593. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209594. if ([state isEqualTo: DRDeviceMediaStateNone])
  209595. {
  209596. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209597. return trayOpen;
  209598. return noDisc;
  209599. }
  209600. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209601. {
  209602. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209603. return writableDiskPresent;
  209604. else
  209605. return readOnlyDiskPresent;
  209606. }
  209607. }
  209608. return unknown;
  209609. }
  209610. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209611. const Array<int> getAvailableWriteSpeeds() const
  209612. {
  209613. Array<int> results;
  209614. if ([device->device isValid])
  209615. {
  209616. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209617. for (unsigned int i = 0; i < [speeds count]; ++i)
  209618. {
  209619. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209620. results.add (kbPerSec / kilobytesPerSecond1x);
  209621. }
  209622. }
  209623. return results;
  209624. }
  209625. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209626. {
  209627. if ([device->device isValid])
  209628. {
  209629. device->underrunProtection = shouldBeEnabled;
  209630. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209631. }
  209632. return false;
  209633. }
  209634. int getNumAvailableAudioBlocks() const
  209635. {
  209636. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209637. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209638. }
  209639. OpenDiskDevice* device;
  209640. private:
  209641. DiskState lastState;
  209642. AudioCDBurner& owner;
  209643. };
  209644. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209645. {
  209646. pimpl = new Pimpl (*this, deviceIndex);
  209647. }
  209648. AudioCDBurner::~AudioCDBurner()
  209649. {
  209650. }
  209651. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209652. {
  209653. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209654. if (b->pimpl->device == 0)
  209655. b = 0;
  209656. return b.release();
  209657. }
  209658. static NSArray* findDiskBurnerDevices()
  209659. {
  209660. NSMutableArray* results = [NSMutableArray array];
  209661. NSArray* devs = [DRDevice devices];
  209662. if (devs != 0)
  209663. {
  209664. int num = [devs count];
  209665. int i;
  209666. for (i = 0; i < num; ++i)
  209667. {
  209668. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209669. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209670. if (name != nil)
  209671. [results addObject: name];
  209672. }
  209673. }
  209674. return results;
  209675. }
  209676. const StringArray AudioCDBurner::findAvailableDevices()
  209677. {
  209678. NSArray* names = findDiskBurnerDevices();
  209679. StringArray s;
  209680. for (unsigned int i = 0; i < [names count]; ++i)
  209681. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209682. return s;
  209683. }
  209684. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209685. {
  209686. return pimpl->getDiskState();
  209687. }
  209688. bool AudioCDBurner::isDiskPresent() const
  209689. {
  209690. return getDiskState() == writableDiskPresent;
  209691. }
  209692. bool AudioCDBurner::openTray()
  209693. {
  209694. return pimpl->openTray();
  209695. }
  209696. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209697. {
  209698. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209699. DiskState oldState = getDiskState();
  209700. DiskState newState = oldState;
  209701. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209702. {
  209703. newState = getDiskState();
  209704. Thread::sleep (100);
  209705. }
  209706. return newState;
  209707. }
  209708. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209709. {
  209710. return pimpl->getAvailableWriteSpeeds();
  209711. }
  209712. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209713. {
  209714. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209715. }
  209716. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209717. {
  209718. return pimpl->getNumAvailableAudioBlocks();
  209719. }
  209720. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209721. {
  209722. if ([pimpl->device->device isValid])
  209723. {
  209724. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209725. return true;
  209726. }
  209727. return false;
  209728. }
  209729. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209730. bool ejectDiscAfterwards,
  209731. bool performFakeBurnForTesting,
  209732. int writeSpeed)
  209733. {
  209734. String error ("Couldn't open or write to the CD device");
  209735. if ([pimpl->device->device isValid])
  209736. {
  209737. error = String::empty;
  209738. [pimpl->device burn: listener
  209739. errorString: &error
  209740. ejectAfterwards: ejectDiscAfterwards
  209741. isFake: performFakeBurnForTesting
  209742. speed: writeSpeed];
  209743. }
  209744. return error;
  209745. }
  209746. #endif
  209747. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209748. void AudioCDReader::ejectDisk()
  209749. {
  209750. const ScopedAutoReleasePool p;
  209751. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209752. }
  209753. #endif
  209754. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209755. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209756. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209757. // compiled on its own).
  209758. #if JUCE_INCLUDED_FILE
  209759. class AppDelegateRedirector
  209760. {
  209761. public:
  209762. AppDelegateRedirector()
  209763. {
  209764. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209765. runLoop = CFRunLoopGetMain();
  209766. #else
  209767. runLoop = CFRunLoopGetCurrent();
  209768. #endif
  209769. CFRunLoopSourceContext sourceContext;
  209770. zerostruct (sourceContext);
  209771. sourceContext.info = this;
  209772. sourceContext.perform = runLoopSourceCallback;
  209773. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209774. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209775. }
  209776. virtual ~AppDelegateRedirector()
  209777. {
  209778. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209779. CFRunLoopSourceInvalidate (runLoopSource);
  209780. CFRelease (runLoopSource);
  209781. while (messages.size() > 0)
  209782. delete static_cast <Message*> (messages.remove(0));
  209783. }
  209784. virtual NSApplicationTerminateReply shouldTerminate()
  209785. {
  209786. if (JUCEApplication::getInstance() != 0)
  209787. {
  209788. JUCEApplication::getInstance()->systemRequestedQuit();
  209789. return NSTerminateCancel;
  209790. }
  209791. return NSTerminateNow;
  209792. }
  209793. virtual BOOL openFile (const NSString* filename)
  209794. {
  209795. if (JUCEApplication::getInstance() != 0)
  209796. {
  209797. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209798. return YES;
  209799. }
  209800. return NO;
  209801. }
  209802. virtual void openFiles (NSArray* filenames)
  209803. {
  209804. StringArray files;
  209805. for (unsigned int i = 0; i < [filenames count]; ++i)
  209806. {
  209807. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209808. if (filename.containsChar (' '))
  209809. filename = filename.quoted('"');
  209810. files.add (filename);
  209811. }
  209812. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209813. {
  209814. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (" "));
  209815. }
  209816. }
  209817. virtual void focusChanged()
  209818. {
  209819. juce_HandleProcessFocusChange();
  209820. }
  209821. struct CallbackMessagePayload
  209822. {
  209823. MessageCallbackFunction* function;
  209824. void* parameter;
  209825. void* volatile result;
  209826. bool volatile hasBeenExecuted;
  209827. };
  209828. virtual void performCallback (CallbackMessagePayload* pl)
  209829. {
  209830. pl->result = (*pl->function) (pl->parameter);
  209831. pl->hasBeenExecuted = true;
  209832. }
  209833. virtual void deleteSelf()
  209834. {
  209835. delete this;
  209836. }
  209837. void postMessage (void* m)
  209838. {
  209839. messages.add (m);
  209840. CFRunLoopSourceSignal (runLoopSource);
  209841. CFRunLoopWakeUp (runLoop);
  209842. }
  209843. private:
  209844. CFRunLoopRef runLoop;
  209845. CFRunLoopSourceRef runLoopSource;
  209846. Array <void*, CriticalSection> messages;
  209847. void runLoopCallback()
  209848. {
  209849. int numDispatched = 0;
  209850. do
  209851. {
  209852. void* const nextMessage = messages.remove (0);
  209853. if (nextMessage == 0)
  209854. return;
  209855. const ScopedAutoReleasePool pool;
  209856. MessageManager::getInstance()->deliverMessage (nextMessage);
  209857. } while (++numDispatched <= 4);
  209858. CFRunLoopSourceSignal (runLoopSource);
  209859. CFRunLoopWakeUp (runLoop);
  209860. }
  209861. static void runLoopSourceCallback (void* info)
  209862. {
  209863. static_cast <AppDelegateRedirector*> (info)->runLoopCallback();
  209864. }
  209865. };
  209866. END_JUCE_NAMESPACE
  209867. using namespace JUCE_NAMESPACE;
  209868. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209869. @interface JuceAppDelegate : NSObject
  209870. {
  209871. @private
  209872. id oldDelegate;
  209873. @public
  209874. AppDelegateRedirector* redirector;
  209875. }
  209876. - (JuceAppDelegate*) init;
  209877. - (void) dealloc;
  209878. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209879. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209880. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209881. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209882. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209883. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209884. - (void) performCallback: (id) info;
  209885. - (void) dummyMethod;
  209886. @end
  209887. @implementation JuceAppDelegate
  209888. - (JuceAppDelegate*) init
  209889. {
  209890. [super init];
  209891. redirector = new AppDelegateRedirector();
  209892. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209893. if (JUCEApplication::getInstance() != 0)
  209894. {
  209895. oldDelegate = [NSApp delegate];
  209896. [NSApp setDelegate: self];
  209897. }
  209898. else
  209899. {
  209900. oldDelegate = 0;
  209901. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209902. name: NSApplicationDidResignActiveNotification object: NSApp];
  209903. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209904. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209905. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209906. name: NSApplicationWillUnhideNotification object: NSApp];
  209907. }
  209908. return self;
  209909. }
  209910. - (void) dealloc
  209911. {
  209912. if (oldDelegate != 0)
  209913. [NSApp setDelegate: oldDelegate];
  209914. redirector->deleteSelf();
  209915. [super dealloc];
  209916. }
  209917. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209918. {
  209919. return redirector->shouldTerminate();
  209920. }
  209921. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209922. {
  209923. return redirector->openFile (filename);
  209924. }
  209925. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209926. {
  209927. return redirector->openFiles (filenames);
  209928. }
  209929. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209930. {
  209931. redirector->focusChanged();
  209932. }
  209933. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209934. {
  209935. redirector->focusChanged();
  209936. }
  209937. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209938. {
  209939. redirector->focusChanged();
  209940. }
  209941. - (void) performCallback: (id) info
  209942. {
  209943. if ([info isKindOfClass: [NSData class]])
  209944. {
  209945. AppDelegateRedirector::CallbackMessagePayload* pl
  209946. = (AppDelegateRedirector::CallbackMessagePayload*) [((NSData*) info) bytes];
  209947. if (pl != 0)
  209948. redirector->performCallback (pl);
  209949. }
  209950. else
  209951. {
  209952. jassertfalse // should never get here!
  209953. }
  209954. }
  209955. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209956. @end
  209957. BEGIN_JUCE_NAMESPACE
  209958. static JuceAppDelegate* juceAppDelegate = 0;
  209959. void MessageManager::runDispatchLoop()
  209960. {
  209961. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209962. {
  209963. const ScopedAutoReleasePool pool;
  209964. // must only be called by the message thread!
  209965. jassert (isThisTheMessageThread());
  209966. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209967. @try
  209968. {
  209969. [NSApp run];
  209970. }
  209971. @catch (NSException* e)
  209972. {
  209973. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209974. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209975. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209976. }
  209977. @finally
  209978. {
  209979. }
  209980. #else
  209981. [NSApp run];
  209982. #endif
  209983. }
  209984. }
  209985. void MessageManager::stopDispatchLoop()
  209986. {
  209987. quitMessagePosted = true;
  209988. [NSApp stop: nil];
  209989. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209990. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209991. }
  209992. static bool isEventBlockedByModalComps (NSEvent* e)
  209993. {
  209994. if (Component::getNumCurrentlyModalComponents() == 0)
  209995. return false;
  209996. NSWindow* const w = [e window];
  209997. if (w == 0 || [w worksWhenModal])
  209998. return false;
  209999. bool isKey = false, isInputAttempt = false;
  210000. switch ([e type])
  210001. {
  210002. case NSKeyDown:
  210003. case NSKeyUp:
  210004. isKey = isInputAttempt = true;
  210005. break;
  210006. case NSLeftMouseDown:
  210007. case NSRightMouseDown:
  210008. case NSOtherMouseDown:
  210009. isInputAttempt = true;
  210010. break;
  210011. case NSLeftMouseDragged:
  210012. case NSRightMouseDragged:
  210013. case NSLeftMouseUp:
  210014. case NSRightMouseUp:
  210015. case NSOtherMouseUp:
  210016. case NSOtherMouseDragged:
  210017. if (Desktop::getInstance().getDraggingMouseSource(0) != 0)
  210018. return false;
  210019. break;
  210020. case NSMouseMoved:
  210021. case NSMouseEntered:
  210022. case NSMouseExited:
  210023. case NSCursorUpdate:
  210024. case NSScrollWheel:
  210025. case NSTabletPoint:
  210026. case NSTabletProximity:
  210027. break;
  210028. default:
  210029. return false;
  210030. }
  210031. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  210032. {
  210033. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  210034. NSView* const compView = (NSView*) peer->getNativeHandle();
  210035. if ([compView window] == w)
  210036. {
  210037. if (isKey)
  210038. {
  210039. if (compView == [w firstResponder])
  210040. return false;
  210041. }
  210042. else
  210043. {
  210044. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  210045. [compView bounds]))
  210046. return false;
  210047. }
  210048. }
  210049. }
  210050. if (isInputAttempt)
  210051. {
  210052. if (! [NSApp isActive])
  210053. [NSApp activateIgnoringOtherApps: YES];
  210054. Component* const modal = Component::getCurrentlyModalComponent (0);
  210055. if (modal != 0)
  210056. modal->inputAttemptWhenModal();
  210057. }
  210058. return true;
  210059. }
  210060. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  210061. {
  210062. const ScopedAutoReleasePool pool;
  210063. jassert (isThisTheMessageThread()); // must only be called by the message thread
  210064. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  210065. while (! quitMessagePosted)
  210066. {
  210067. const ScopedAutoReleasePool pool2;
  210068. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  210069. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  210070. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  210071. inMode: NSDefaultRunLoopMode
  210072. dequeue: YES];
  210073. if (e != 0 && ! isEventBlockedByModalComps (e))
  210074. [NSApp sendEvent: e];
  210075. if (Time::getMillisecondCounter() >= endTime)
  210076. break;
  210077. }
  210078. return ! quitMessagePosted;
  210079. }
  210080. void MessageManager::doPlatformSpecificInitialisation()
  210081. {
  210082. if (juceAppDelegate == 0)
  210083. juceAppDelegate = [[JuceAppDelegate alloc] init];
  210084. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  210085. // correctly (needed prior to 10.5)
  210086. if (! [NSThread isMultiThreaded])
  210087. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  210088. toTarget: juceAppDelegate
  210089. withObject: nil];
  210090. initialiseMainMenu();
  210091. }
  210092. void MessageManager::doPlatformSpecificShutdown()
  210093. {
  210094. if (juceAppDelegate != 0)
  210095. {
  210096. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210097. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210098. [juceAppDelegate release];
  210099. juceAppDelegate = 0;
  210100. }
  210101. }
  210102. bool juce_postMessageToSystemQueue (void* message)
  210103. {
  210104. juceAppDelegate->redirector->postMessage (message);
  210105. return true;
  210106. }
  210107. void MessageManager::broadcastMessage (const String& value) throw()
  210108. {
  210109. }
  210110. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210111. void* data)
  210112. {
  210113. if (isThisTheMessageThread())
  210114. {
  210115. return (*callback) (data);
  210116. }
  210117. else
  210118. {
  210119. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210120. // deadlock because the message manager is blocked from running, so can never
  210121. // call your function..
  210122. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210123. const ScopedAutoReleasePool pool;
  210124. AppDelegateRedirector::CallbackMessagePayload cmp;
  210125. cmp.function = callback;
  210126. cmp.parameter = data;
  210127. cmp.result = 0;
  210128. cmp.hasBeenExecuted = false;
  210129. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210130. withObject: [NSData dataWithBytesNoCopy: &cmp
  210131. length: sizeof (cmp)
  210132. freeWhenDone: NO]
  210133. waitUntilDone: YES];
  210134. return cmp.result;
  210135. }
  210136. }
  210137. #endif
  210138. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210139. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210140. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210141. // compiled on its own).
  210142. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210143. #if JUCE_MAC
  210144. END_JUCE_NAMESPACE
  210145. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210146. @interface DownloadClickDetector : NSObject
  210147. {
  210148. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210149. }
  210150. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210151. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210152. request: (NSURLRequest*) request
  210153. frame: (WebFrame*) frame
  210154. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210155. @end
  210156. @implementation DownloadClickDetector
  210157. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210158. {
  210159. [super init];
  210160. ownerComponent = ownerComponent_;
  210161. return self;
  210162. }
  210163. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210164. request: (NSURLRequest*) request
  210165. frame: (WebFrame*) frame
  210166. decisionListener: (id <WebPolicyDecisionListener>) listener
  210167. {
  210168. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210169. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210170. [listener use];
  210171. else
  210172. [listener ignore];
  210173. }
  210174. @end
  210175. BEGIN_JUCE_NAMESPACE
  210176. class WebBrowserComponentInternal : public NSViewComponent
  210177. {
  210178. public:
  210179. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210180. {
  210181. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210182. frameName: @""
  210183. groupName: @""];
  210184. setView (webView);
  210185. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210186. [webView setPolicyDelegate: clickListener];
  210187. }
  210188. ~WebBrowserComponentInternal()
  210189. {
  210190. [webView setPolicyDelegate: nil];
  210191. [clickListener release];
  210192. setView (0);
  210193. }
  210194. void goToURL (const String& url,
  210195. const StringArray* headers,
  210196. const MemoryBlock* postData)
  210197. {
  210198. NSMutableURLRequest* r
  210199. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210200. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210201. timeoutInterval: 30.0];
  210202. if (postData != 0 && postData->getSize() > 0)
  210203. {
  210204. [r setHTTPMethod: @"POST"];
  210205. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210206. length: postData->getSize()]];
  210207. }
  210208. if (headers != 0)
  210209. {
  210210. for (int i = 0; i < headers->size(); ++i)
  210211. {
  210212. const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
  210213. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
  210214. [r setValue: juceStringToNS (headerValue)
  210215. forHTTPHeaderField: juceStringToNS (headerName)];
  210216. }
  210217. }
  210218. stop();
  210219. [[webView mainFrame] loadRequest: r];
  210220. }
  210221. void goBack()
  210222. {
  210223. [webView goBack];
  210224. }
  210225. void goForward()
  210226. {
  210227. [webView goForward];
  210228. }
  210229. void stop()
  210230. {
  210231. [webView stopLoading: nil];
  210232. }
  210233. void refresh()
  210234. {
  210235. [webView reload: nil];
  210236. }
  210237. private:
  210238. WebView* webView;
  210239. DownloadClickDetector* clickListener;
  210240. };
  210241. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210242. : browser (0),
  210243. blankPageShown (false),
  210244. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210245. {
  210246. setOpaque (true);
  210247. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210248. }
  210249. WebBrowserComponent::~WebBrowserComponent()
  210250. {
  210251. deleteAndZero (browser);
  210252. }
  210253. void WebBrowserComponent::goToURL (const String& url,
  210254. const StringArray* headers,
  210255. const MemoryBlock* postData)
  210256. {
  210257. lastURL = url;
  210258. lastHeaders.clear();
  210259. if (headers != 0)
  210260. lastHeaders = *headers;
  210261. lastPostData.setSize (0);
  210262. if (postData != 0)
  210263. lastPostData = *postData;
  210264. blankPageShown = false;
  210265. browser->goToURL (url, headers, postData);
  210266. }
  210267. void WebBrowserComponent::stop()
  210268. {
  210269. browser->stop();
  210270. }
  210271. void WebBrowserComponent::goBack()
  210272. {
  210273. lastURL = String::empty;
  210274. blankPageShown = false;
  210275. browser->goBack();
  210276. }
  210277. void WebBrowserComponent::goForward()
  210278. {
  210279. lastURL = String::empty;
  210280. browser->goForward();
  210281. }
  210282. void WebBrowserComponent::refresh()
  210283. {
  210284. browser->refresh();
  210285. }
  210286. void WebBrowserComponent::paint (Graphics& g)
  210287. {
  210288. }
  210289. void WebBrowserComponent::checkWindowAssociation()
  210290. {
  210291. if (isShowing())
  210292. {
  210293. if (blankPageShown)
  210294. goBack();
  210295. }
  210296. else
  210297. {
  210298. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210299. {
  210300. // when the component becomes invisible, some stuff like flash
  210301. // carries on playing audio, so we need to force it onto a blank
  210302. // page to avoid this, (and send it back when it's made visible again).
  210303. blankPageShown = true;
  210304. browser->goToURL ("about:blank", 0, 0);
  210305. }
  210306. }
  210307. }
  210308. void WebBrowserComponent::reloadLastURL()
  210309. {
  210310. if (lastURL.isNotEmpty())
  210311. {
  210312. goToURL (lastURL, &lastHeaders, &lastPostData);
  210313. lastURL = String::empty;
  210314. }
  210315. }
  210316. void WebBrowserComponent::parentHierarchyChanged()
  210317. {
  210318. checkWindowAssociation();
  210319. }
  210320. void WebBrowserComponent::resized()
  210321. {
  210322. browser->setSize (getWidth(), getHeight());
  210323. }
  210324. void WebBrowserComponent::visibilityChanged()
  210325. {
  210326. checkWindowAssociation();
  210327. }
  210328. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210329. {
  210330. return true;
  210331. }
  210332. #else
  210333. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210334. {
  210335. }
  210336. WebBrowserComponent::~WebBrowserComponent()
  210337. {
  210338. }
  210339. void WebBrowserComponent::goToURL (const String& url,
  210340. const StringArray* headers,
  210341. const MemoryBlock* postData)
  210342. {
  210343. }
  210344. void WebBrowserComponent::stop()
  210345. {
  210346. }
  210347. void WebBrowserComponent::goBack()
  210348. {
  210349. }
  210350. void WebBrowserComponent::goForward()
  210351. {
  210352. }
  210353. void WebBrowserComponent::refresh()
  210354. {
  210355. }
  210356. void WebBrowserComponent::paint (Graphics& g)
  210357. {
  210358. }
  210359. void WebBrowserComponent::checkWindowAssociation()
  210360. {
  210361. }
  210362. void WebBrowserComponent::reloadLastURL()
  210363. {
  210364. }
  210365. void WebBrowserComponent::parentHierarchyChanged()
  210366. {
  210367. }
  210368. void WebBrowserComponent::resized()
  210369. {
  210370. }
  210371. void WebBrowserComponent::visibilityChanged()
  210372. {
  210373. }
  210374. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210375. {
  210376. return true;
  210377. }
  210378. #endif
  210379. #endif
  210380. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210381. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210382. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210383. // compiled on its own).
  210384. #if JUCE_INCLUDED_FILE
  210385. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210386. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210387. #endif
  210388. #undef log
  210389. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210390. #define log(a) Logger::writeToLog (a)
  210391. #else
  210392. #define log(a)
  210393. #endif
  210394. #undef OK
  210395. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210396. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210397. {
  210398. if (err == noErr)
  210399. return true;
  210400. Logger::writeToLog ("CoreAudio error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  210401. jassertfalse
  210402. return false;
  210403. }
  210404. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210405. #else
  210406. #define OK(a) (a == noErr)
  210407. #endif
  210408. class CoreAudioInternal : public Timer
  210409. {
  210410. public:
  210411. CoreAudioInternal (AudioDeviceID id)
  210412. : inputLatency (0),
  210413. outputLatency (0),
  210414. callback (0),
  210415. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210416. audioProcID (0),
  210417. #endif
  210418. inputDevice (0),
  210419. isSlaveDevice (false),
  210420. deviceID (id),
  210421. started (false),
  210422. sampleRate (0),
  210423. bufferSize (512),
  210424. numInputChans (0),
  210425. numOutputChans (0),
  210426. callbacksAllowed (true),
  210427. numInputChannelInfos (0),
  210428. numOutputChannelInfos (0)
  210429. {
  210430. jassert (deviceID != 0);
  210431. updateDetailsFromDevice();
  210432. AudioObjectPropertyAddress pa;
  210433. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210434. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210435. pa.mElement = kAudioObjectPropertyElementWildcard;
  210436. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210437. }
  210438. ~CoreAudioInternal()
  210439. {
  210440. AudioObjectPropertyAddress pa;
  210441. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210442. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210443. pa.mElement = kAudioObjectPropertyElementWildcard;
  210444. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210445. stop (false);
  210446. delete inputDevice;
  210447. }
  210448. void allocateTempBuffers()
  210449. {
  210450. const int tempBufSize = bufferSize + 4;
  210451. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210452. tempInputBuffers.calloc (numInputChans + 2);
  210453. tempOutputBuffers.calloc (numOutputChans + 2);
  210454. int i, count = 0;
  210455. for (i = 0; i < numInputChans; ++i)
  210456. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210457. for (i = 0; i < numOutputChans; ++i)
  210458. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210459. }
  210460. // returns the number of actual available channels
  210461. void fillInChannelInfo (const bool input)
  210462. {
  210463. int chanNum = 0;
  210464. UInt32 size;
  210465. AudioObjectPropertyAddress pa;
  210466. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210467. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210468. pa.mElement = kAudioObjectPropertyElementMaster;
  210469. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210470. {
  210471. HeapBlock <AudioBufferList> bufList;
  210472. bufList.calloc (size, 1);
  210473. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210474. {
  210475. const int numStreams = bufList->mNumberBuffers;
  210476. for (int i = 0; i < numStreams; ++i)
  210477. {
  210478. const AudioBuffer& b = bufList->mBuffers[i];
  210479. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210480. {
  210481. String name;
  210482. {
  210483. char channelName [256];
  210484. zerostruct (channelName);
  210485. UInt32 nameSize = sizeof (channelName);
  210486. UInt32 channelNum = chanNum + 1;
  210487. pa.mSelector = kAudioDevicePropertyChannelName;
  210488. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210489. name = String::fromUTF8 (channelName, nameSize);
  210490. }
  210491. if (input)
  210492. {
  210493. if (activeInputChans[chanNum])
  210494. {
  210495. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210496. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210497. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210498. ++numInputChannelInfos;
  210499. }
  210500. if (name.isEmpty())
  210501. name << "Input " << (chanNum + 1);
  210502. inChanNames.add (name);
  210503. }
  210504. else
  210505. {
  210506. if (activeOutputChans[chanNum])
  210507. {
  210508. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210509. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210510. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210511. ++numOutputChannelInfos;
  210512. }
  210513. if (name.isEmpty())
  210514. name << "Output " << (chanNum + 1);
  210515. outChanNames.add (name);
  210516. }
  210517. ++chanNum;
  210518. }
  210519. }
  210520. }
  210521. }
  210522. }
  210523. void updateDetailsFromDevice()
  210524. {
  210525. stopTimer();
  210526. if (deviceID == 0)
  210527. return;
  210528. const ScopedLock sl (callbackLock);
  210529. Float64 sr;
  210530. UInt32 size = sizeof (Float64);
  210531. AudioObjectPropertyAddress pa;
  210532. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210533. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210534. pa.mElement = kAudioObjectPropertyElementMaster;
  210535. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210536. sampleRate = sr;
  210537. UInt32 framesPerBuf;
  210538. size = sizeof (framesPerBuf);
  210539. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210540. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210541. {
  210542. bufferSize = framesPerBuf;
  210543. allocateTempBuffers();
  210544. }
  210545. bufferSizes.clear();
  210546. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210547. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210548. {
  210549. HeapBlock <AudioValueRange> ranges;
  210550. ranges.calloc (size, 1);
  210551. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210552. {
  210553. bufferSizes.add ((int) ranges[0].mMinimum);
  210554. for (int i = 32; i < 2048; i += 32)
  210555. {
  210556. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210557. {
  210558. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210559. {
  210560. bufferSizes.addIfNotAlreadyThere (i);
  210561. break;
  210562. }
  210563. }
  210564. }
  210565. if (bufferSize > 0)
  210566. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210567. }
  210568. }
  210569. if (bufferSizes.size() == 0 && bufferSize > 0)
  210570. bufferSizes.add (bufferSize);
  210571. sampleRates.clear();
  210572. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210573. String rates;
  210574. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210575. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210576. {
  210577. HeapBlock <AudioValueRange> ranges;
  210578. ranges.calloc (size, 1);
  210579. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210580. {
  210581. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210582. {
  210583. bool ok = false;
  210584. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210585. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210586. ok = true;
  210587. if (ok)
  210588. {
  210589. sampleRates.add (possibleRates[i]);
  210590. rates << possibleRates[i] << ' ';
  210591. }
  210592. }
  210593. }
  210594. }
  210595. if (sampleRates.size() == 0 && sampleRate > 0)
  210596. {
  210597. sampleRates.add (sampleRate);
  210598. rates << sampleRate;
  210599. }
  210600. log ("sr: " + rates);
  210601. inputLatency = 0;
  210602. outputLatency = 0;
  210603. UInt32 lat;
  210604. size = sizeof (lat);
  210605. pa.mSelector = kAudioDevicePropertyLatency;
  210606. pa.mScope = kAudioDevicePropertyScopeInput;
  210607. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210608. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210609. inputLatency = (int) lat;
  210610. pa.mScope = kAudioDevicePropertyScopeOutput;
  210611. size = sizeof (lat);
  210612. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210613. outputLatency = (int) lat;
  210614. log ("lat: " + String (inputLatency) + " " + String (outputLatency));
  210615. inChanNames.clear();
  210616. outChanNames.clear();
  210617. inputChannelInfo.calloc (numInputChans + 2);
  210618. numInputChannelInfos = 0;
  210619. outputChannelInfo.calloc (numOutputChans + 2);
  210620. numOutputChannelInfos = 0;
  210621. fillInChannelInfo (true);
  210622. fillInChannelInfo (false);
  210623. }
  210624. const StringArray getSources (bool input)
  210625. {
  210626. StringArray s;
  210627. HeapBlock <OSType> types;
  210628. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210629. for (int i = 0; i < num; ++i)
  210630. {
  210631. AudioValueTranslation avt;
  210632. char buffer[256];
  210633. avt.mInputData = &(types[i]);
  210634. avt.mInputDataSize = sizeof (UInt32);
  210635. avt.mOutputData = buffer;
  210636. avt.mOutputDataSize = 256;
  210637. UInt32 transSize = sizeof (avt);
  210638. AudioObjectPropertyAddress pa;
  210639. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210640. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210641. pa.mElement = kAudioObjectPropertyElementMaster;
  210642. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210643. {
  210644. DBG (buffer);
  210645. s.add (buffer);
  210646. }
  210647. }
  210648. return s;
  210649. }
  210650. int getCurrentSourceIndex (bool input) const
  210651. {
  210652. OSType currentSourceID = 0;
  210653. UInt32 size = sizeof (currentSourceID);
  210654. int result = -1;
  210655. AudioObjectPropertyAddress pa;
  210656. pa.mSelector = kAudioDevicePropertyDataSource;
  210657. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210658. pa.mElement = kAudioObjectPropertyElementMaster;
  210659. if (deviceID != 0)
  210660. {
  210661. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210662. {
  210663. HeapBlock <OSType> types;
  210664. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210665. for (int i = 0; i < num; ++i)
  210666. {
  210667. if (types[num] == currentSourceID)
  210668. {
  210669. result = i;
  210670. break;
  210671. }
  210672. }
  210673. }
  210674. }
  210675. return result;
  210676. }
  210677. void setCurrentSourceIndex (int index, bool input)
  210678. {
  210679. if (deviceID != 0)
  210680. {
  210681. HeapBlock <OSType> types;
  210682. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210683. if (((unsigned int) index) < (unsigned int) num)
  210684. {
  210685. AudioObjectPropertyAddress pa;
  210686. pa.mSelector = kAudioDevicePropertyDataSource;
  210687. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210688. pa.mElement = kAudioObjectPropertyElementMaster;
  210689. OSType typeId = types[index];
  210690. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210691. }
  210692. }
  210693. }
  210694. const String reopen (const BigInteger& inputChannels,
  210695. const BigInteger& outputChannels,
  210696. double newSampleRate,
  210697. int bufferSizeSamples)
  210698. {
  210699. String error;
  210700. log ("CoreAudio reopen");
  210701. callbacksAllowed = false;
  210702. stopTimer();
  210703. stop (false);
  210704. activeInputChans = inputChannels;
  210705. activeInputChans.setRange (inChanNames.size(),
  210706. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210707. false);
  210708. activeOutputChans = outputChannels;
  210709. activeOutputChans.setRange (outChanNames.size(),
  210710. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210711. false);
  210712. numInputChans = activeInputChans.countNumberOfSetBits();
  210713. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210714. // set sample rate
  210715. AudioObjectPropertyAddress pa;
  210716. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210717. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210718. pa.mElement = kAudioObjectPropertyElementMaster;
  210719. Float64 sr = newSampleRate;
  210720. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210721. {
  210722. error = "Couldn't change sample rate";
  210723. }
  210724. else
  210725. {
  210726. // change buffer size
  210727. UInt32 framesPerBuf = bufferSizeSamples;
  210728. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210729. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210730. {
  210731. error = "Couldn't change buffer size";
  210732. }
  210733. else
  210734. {
  210735. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210736. // correctly report their new settings until some random time in the future, so
  210737. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210738. // to make sure we're using the correct numbers..
  210739. updateDetailsFromDevice();
  210740. sampleRate = newSampleRate;
  210741. bufferSize = bufferSizeSamples;
  210742. if (sampleRates.size() == 0)
  210743. error = "Device has no available sample-rates";
  210744. else if (bufferSizes.size() == 0)
  210745. error = "Device has no available buffer-sizes";
  210746. else if (inputDevice != 0)
  210747. error = inputDevice->reopen (inputChannels,
  210748. outputChannels,
  210749. newSampleRate,
  210750. bufferSizeSamples);
  210751. }
  210752. }
  210753. callbacksAllowed = true;
  210754. return error;
  210755. }
  210756. bool start (AudioIODeviceCallback* cb)
  210757. {
  210758. if (! started)
  210759. {
  210760. callback = 0;
  210761. if (deviceID != 0)
  210762. {
  210763. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210764. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, this)))
  210765. #else
  210766. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, this, &audioProcID)))
  210767. #endif
  210768. {
  210769. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210770. {
  210771. started = true;
  210772. }
  210773. else
  210774. {
  210775. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210776. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210777. #else
  210778. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210779. audioProcID = 0;
  210780. #endif
  210781. }
  210782. }
  210783. }
  210784. }
  210785. if (started)
  210786. {
  210787. const ScopedLock sl (callbackLock);
  210788. callback = cb;
  210789. }
  210790. if (inputDevice != 0)
  210791. return started && inputDevice->start (cb);
  210792. else
  210793. return started;
  210794. }
  210795. void stop (bool leaveInterruptRunning)
  210796. {
  210797. {
  210798. const ScopedLock sl (callbackLock);
  210799. callback = 0;
  210800. }
  210801. if (started
  210802. && (deviceID != 0)
  210803. && ! leaveInterruptRunning)
  210804. {
  210805. OK (AudioDeviceStop (deviceID, audioIOProc));
  210806. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210807. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210808. #else
  210809. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210810. audioProcID = 0;
  210811. #endif
  210812. started = false;
  210813. { const ScopedLock sl (callbackLock); }
  210814. // wait until it's definately stopped calling back..
  210815. for (int i = 40; --i >= 0;)
  210816. {
  210817. Thread::sleep (50);
  210818. UInt32 running = 0;
  210819. UInt32 size = sizeof (running);
  210820. AudioObjectPropertyAddress pa;
  210821. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210822. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210823. pa.mElement = kAudioObjectPropertyElementMaster;
  210824. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210825. if (running == 0)
  210826. break;
  210827. }
  210828. const ScopedLock sl (callbackLock);
  210829. }
  210830. if (inputDevice != 0)
  210831. inputDevice->stop (leaveInterruptRunning);
  210832. }
  210833. double getSampleRate() const
  210834. {
  210835. return sampleRate;
  210836. }
  210837. int getBufferSize() const
  210838. {
  210839. return bufferSize;
  210840. }
  210841. void audioCallback (const AudioBufferList* inInputData,
  210842. AudioBufferList* outOutputData)
  210843. {
  210844. int i;
  210845. const ScopedLock sl (callbackLock);
  210846. if (callback != 0)
  210847. {
  210848. if (inputDevice == 0)
  210849. {
  210850. for (i = numInputChans; --i >= 0;)
  210851. {
  210852. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210853. float* dest = tempInputBuffers [i];
  210854. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210855. + info.dataOffsetSamples;
  210856. const int stride = info.dataStrideSamples;
  210857. if (stride != 0) // if this is zero, info is invalid
  210858. {
  210859. for (int j = bufferSize; --j >= 0;)
  210860. {
  210861. *dest++ = *src;
  210862. src += stride;
  210863. }
  210864. }
  210865. }
  210866. }
  210867. if (! isSlaveDevice)
  210868. {
  210869. if (inputDevice == 0)
  210870. {
  210871. callback->audioDeviceIOCallback (const_cast<const float**> (tempInputBuffers.getData()),
  210872. numInputChans,
  210873. tempOutputBuffers,
  210874. numOutputChans,
  210875. bufferSize);
  210876. }
  210877. else
  210878. {
  210879. jassert (inputDevice->bufferSize == bufferSize);
  210880. // Sometimes the two linked devices seem to get their callbacks in
  210881. // parallel, so we need to lock both devices to stop the input data being
  210882. // changed while inside our callback..
  210883. const ScopedLock sl2 (inputDevice->callbackLock);
  210884. callback->audioDeviceIOCallback (const_cast<const float**> (inputDevice->tempInputBuffers.getData()),
  210885. inputDevice->numInputChans,
  210886. tempOutputBuffers,
  210887. numOutputChans,
  210888. bufferSize);
  210889. }
  210890. for (i = numOutputChans; --i >= 0;)
  210891. {
  210892. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210893. const float* src = tempOutputBuffers [i];
  210894. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210895. + info.dataOffsetSamples;
  210896. const int stride = info.dataStrideSamples;
  210897. if (stride != 0) // if this is zero, info is invalid
  210898. {
  210899. for (int j = bufferSize; --j >= 0;)
  210900. {
  210901. *dest = *src++;
  210902. dest += stride;
  210903. }
  210904. }
  210905. }
  210906. }
  210907. }
  210908. else
  210909. {
  210910. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210911. {
  210912. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210913. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210914. + info.dataOffsetSamples;
  210915. const int stride = info.dataStrideSamples;
  210916. if (stride != 0) // if this is zero, info is invalid
  210917. {
  210918. for (int j = bufferSize; --j >= 0;)
  210919. {
  210920. *dest = 0.0f;
  210921. dest += stride;
  210922. }
  210923. }
  210924. }
  210925. }
  210926. }
  210927. // called by callbacks
  210928. void deviceDetailsChanged()
  210929. {
  210930. if (callbacksAllowed)
  210931. startTimer (100);
  210932. }
  210933. void timerCallback()
  210934. {
  210935. stopTimer();
  210936. log ("CoreAudio device changed callback");
  210937. const double oldSampleRate = sampleRate;
  210938. const int oldBufferSize = bufferSize;
  210939. updateDetailsFromDevice();
  210940. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210941. {
  210942. callbacksAllowed = false;
  210943. stop (false);
  210944. updateDetailsFromDevice();
  210945. callbacksAllowed = true;
  210946. }
  210947. }
  210948. CoreAudioInternal* getRelatedDevice() const
  210949. {
  210950. UInt32 size = 0;
  210951. ScopedPointer <CoreAudioInternal> result;
  210952. AudioObjectPropertyAddress pa;
  210953. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210954. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210955. pa.mElement = kAudioObjectPropertyElementMaster;
  210956. if (deviceID != 0
  210957. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210958. && size > 0)
  210959. {
  210960. HeapBlock <AudioDeviceID> devs;
  210961. devs.calloc (size, 1);
  210962. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210963. {
  210964. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210965. {
  210966. if (devs[i] != deviceID && devs[i] != 0)
  210967. {
  210968. result = new CoreAudioInternal (devs[i]);
  210969. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210970. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210971. if (thisIsInput != otherIsInput
  210972. || (inChanNames.size() + outChanNames.size() == 0)
  210973. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210974. break;
  210975. result = 0;
  210976. }
  210977. }
  210978. }
  210979. }
  210980. return result.release();
  210981. }
  210982. juce_UseDebuggingNewOperator
  210983. int inputLatency, outputLatency;
  210984. BigInteger activeInputChans, activeOutputChans;
  210985. StringArray inChanNames, outChanNames;
  210986. Array <double> sampleRates;
  210987. Array <int> bufferSizes;
  210988. AudioIODeviceCallback* callback;
  210989. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210990. AudioDeviceIOProcID audioProcID;
  210991. #endif
  210992. CoreAudioInternal* inputDevice;
  210993. bool isSlaveDevice;
  210994. private:
  210995. CriticalSection callbackLock;
  210996. AudioDeviceID deviceID;
  210997. bool started;
  210998. double sampleRate;
  210999. int bufferSize;
  211000. HeapBlock <float> audioBuffer;
  211001. int numInputChans, numOutputChans;
  211002. bool callbacksAllowed;
  211003. struct CallbackDetailsForChannel
  211004. {
  211005. int streamNum;
  211006. int dataOffsetSamples;
  211007. int dataStrideSamples;
  211008. };
  211009. int numInputChannelInfos, numOutputChannelInfos;
  211010. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  211011. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  211012. CoreAudioInternal (const CoreAudioInternal&);
  211013. CoreAudioInternal& operator= (const CoreAudioInternal&);
  211014. static OSStatus audioIOProc (AudioDeviceID inDevice,
  211015. const AudioTimeStamp* inNow,
  211016. const AudioBufferList* inInputData,
  211017. const AudioTimeStamp* inInputTime,
  211018. AudioBufferList* outOutputData,
  211019. const AudioTimeStamp* inOutputTime,
  211020. void* device)
  211021. {
  211022. static_cast <CoreAudioInternal*> (device)->audioCallback (inInputData, outOutputData);
  211023. return noErr;
  211024. }
  211025. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211026. {
  211027. CoreAudioInternal* const intern = static_cast <CoreAudioInternal*> (inClientData);
  211028. switch (pa->mSelector)
  211029. {
  211030. case kAudioDevicePropertyBufferSize:
  211031. case kAudioDevicePropertyBufferFrameSize:
  211032. case kAudioDevicePropertyNominalSampleRate:
  211033. case kAudioDevicePropertyStreamFormat:
  211034. case kAudioDevicePropertyDeviceIsAlive:
  211035. intern->deviceDetailsChanged();
  211036. break;
  211037. case kAudioDevicePropertyBufferSizeRange:
  211038. case kAudioDevicePropertyVolumeScalar:
  211039. case kAudioDevicePropertyMute:
  211040. case kAudioDevicePropertyPlayThru:
  211041. case kAudioDevicePropertyDataSource:
  211042. case kAudioDevicePropertyDeviceIsRunning:
  211043. break;
  211044. }
  211045. return noErr;
  211046. }
  211047. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  211048. {
  211049. AudioObjectPropertyAddress pa;
  211050. pa.mSelector = kAudioDevicePropertyDataSources;
  211051. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211052. pa.mElement = kAudioObjectPropertyElementMaster;
  211053. UInt32 size = 0;
  211054. if (deviceID != 0
  211055. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211056. {
  211057. types.calloc (size, 1);
  211058. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  211059. return size / (int) sizeof (OSType);
  211060. }
  211061. return 0;
  211062. }
  211063. };
  211064. class CoreAudioIODevice : public AudioIODevice
  211065. {
  211066. public:
  211067. CoreAudioIODevice (const String& deviceName,
  211068. AudioDeviceID inputDeviceId,
  211069. const int inputIndex_,
  211070. AudioDeviceID outputDeviceId,
  211071. const int outputIndex_)
  211072. : AudioIODevice (deviceName, "CoreAudio"),
  211073. inputIndex (inputIndex_),
  211074. outputIndex (outputIndex_),
  211075. isOpen_ (false),
  211076. isStarted (false)
  211077. {
  211078. internal = 0;
  211079. CoreAudioInternal* device = 0;
  211080. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  211081. {
  211082. jassert (inputDeviceId != 0);
  211083. device = new CoreAudioInternal (inputDeviceId);
  211084. }
  211085. else
  211086. {
  211087. device = new CoreAudioInternal (outputDeviceId);
  211088. if (inputDeviceId != 0)
  211089. {
  211090. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  211091. device->inputDevice = secondDevice;
  211092. secondDevice->isSlaveDevice = true;
  211093. }
  211094. }
  211095. internal = device;
  211096. AudioObjectPropertyAddress pa;
  211097. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211098. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211099. pa.mElement = kAudioObjectPropertyElementWildcard;
  211100. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211101. }
  211102. ~CoreAudioIODevice()
  211103. {
  211104. AudioObjectPropertyAddress pa;
  211105. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211106. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211107. pa.mElement = kAudioObjectPropertyElementWildcard;
  211108. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211109. delete internal;
  211110. }
  211111. const StringArray getOutputChannelNames()
  211112. {
  211113. return internal->outChanNames;
  211114. }
  211115. const StringArray getInputChannelNames()
  211116. {
  211117. if (internal->inputDevice != 0)
  211118. return internal->inputDevice->inChanNames;
  211119. else
  211120. return internal->inChanNames;
  211121. }
  211122. int getNumSampleRates()
  211123. {
  211124. return internal->sampleRates.size();
  211125. }
  211126. double getSampleRate (int index)
  211127. {
  211128. return internal->sampleRates [index];
  211129. }
  211130. int getNumBufferSizesAvailable()
  211131. {
  211132. return internal->bufferSizes.size();
  211133. }
  211134. int getBufferSizeSamples (int index)
  211135. {
  211136. return internal->bufferSizes [index];
  211137. }
  211138. int getDefaultBufferSize()
  211139. {
  211140. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211141. if (getBufferSizeSamples(i) >= 512)
  211142. return getBufferSizeSamples(i);
  211143. return 512;
  211144. }
  211145. const String open (const BigInteger& inputChannels,
  211146. const BigInteger& outputChannels,
  211147. double sampleRate,
  211148. int bufferSizeSamples)
  211149. {
  211150. isOpen_ = true;
  211151. if (bufferSizeSamples <= 0)
  211152. bufferSizeSamples = getDefaultBufferSize();
  211153. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211154. isOpen_ = lastError.isEmpty();
  211155. return lastError;
  211156. }
  211157. void close()
  211158. {
  211159. isOpen_ = false;
  211160. internal->stop (false);
  211161. }
  211162. bool isOpen()
  211163. {
  211164. return isOpen_;
  211165. }
  211166. int getCurrentBufferSizeSamples()
  211167. {
  211168. return internal != 0 ? internal->getBufferSize() : 512;
  211169. }
  211170. double getCurrentSampleRate()
  211171. {
  211172. return internal != 0 ? internal->getSampleRate() : 0;
  211173. }
  211174. int getCurrentBitDepth()
  211175. {
  211176. return 32; // no way to find out, so just assume it's high..
  211177. }
  211178. const BigInteger getActiveOutputChannels() const
  211179. {
  211180. return internal != 0 ? internal->activeOutputChans : BigInteger();
  211181. }
  211182. const BigInteger getActiveInputChannels() const
  211183. {
  211184. BigInteger chans;
  211185. if (internal != 0)
  211186. {
  211187. chans = internal->activeInputChans;
  211188. if (internal->inputDevice != 0)
  211189. chans |= internal->inputDevice->activeInputChans;
  211190. }
  211191. return chans;
  211192. }
  211193. int getOutputLatencyInSamples()
  211194. {
  211195. if (internal == 0)
  211196. return 0;
  211197. // this seems like a good guess at getting the latency right - comparing
  211198. // this with a round-trip measurement, it gets it to within a few millisecs
  211199. // for the built-in mac soundcard
  211200. return internal->outputLatency + internal->getBufferSize() * 2;
  211201. }
  211202. int getInputLatencyInSamples()
  211203. {
  211204. if (internal == 0)
  211205. return 0;
  211206. return internal->inputLatency + internal->getBufferSize() * 2;
  211207. }
  211208. void start (AudioIODeviceCallback* callback)
  211209. {
  211210. if (internal != 0 && ! isStarted)
  211211. {
  211212. if (callback != 0)
  211213. callback->audioDeviceAboutToStart (this);
  211214. isStarted = true;
  211215. internal->start (callback);
  211216. }
  211217. }
  211218. void stop()
  211219. {
  211220. if (isStarted && internal != 0)
  211221. {
  211222. AudioIODeviceCallback* const lastCallback = internal->callback;
  211223. isStarted = false;
  211224. internal->stop (true);
  211225. if (lastCallback != 0)
  211226. lastCallback->audioDeviceStopped();
  211227. }
  211228. }
  211229. bool isPlaying()
  211230. {
  211231. if (internal->callback == 0)
  211232. isStarted = false;
  211233. return isStarted;
  211234. }
  211235. const String getLastError()
  211236. {
  211237. return lastError;
  211238. }
  211239. int inputIndex, outputIndex;
  211240. juce_UseDebuggingNewOperator
  211241. private:
  211242. CoreAudioInternal* internal;
  211243. bool isOpen_, isStarted;
  211244. String lastError;
  211245. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211246. {
  211247. CoreAudioInternal* const intern = static_cast <CoreAudioInternal*> (inClientData);
  211248. switch (pa->mSelector)
  211249. {
  211250. case kAudioHardwarePropertyDevices:
  211251. intern->deviceDetailsChanged();
  211252. break;
  211253. case kAudioHardwarePropertyDefaultOutputDevice:
  211254. case kAudioHardwarePropertyDefaultInputDevice:
  211255. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211256. break;
  211257. }
  211258. return noErr;
  211259. }
  211260. CoreAudioIODevice (const CoreAudioIODevice&);
  211261. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211262. };
  211263. class CoreAudioIODeviceType : public AudioIODeviceType
  211264. {
  211265. public:
  211266. CoreAudioIODeviceType()
  211267. : AudioIODeviceType ("CoreAudio"),
  211268. hasScanned (false)
  211269. {
  211270. }
  211271. ~CoreAudioIODeviceType()
  211272. {
  211273. }
  211274. void scanForDevices()
  211275. {
  211276. hasScanned = true;
  211277. inputDeviceNames.clear();
  211278. outputDeviceNames.clear();
  211279. inputIds.clear();
  211280. outputIds.clear();
  211281. UInt32 size;
  211282. AudioObjectPropertyAddress pa;
  211283. pa.mSelector = kAudioHardwarePropertyDevices;
  211284. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211285. pa.mElement = kAudioObjectPropertyElementMaster;
  211286. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211287. {
  211288. HeapBlock <AudioDeviceID> devs;
  211289. devs.calloc (size, 1);
  211290. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211291. {
  211292. static bool alreadyLogged = false;
  211293. const int num = size / (int) sizeof (AudioDeviceID);
  211294. for (int i = 0; i < num; ++i)
  211295. {
  211296. char name [1024];
  211297. size = sizeof (name);
  211298. pa.mSelector = kAudioDevicePropertyDeviceName;
  211299. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211300. {
  211301. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211302. if (! alreadyLogged)
  211303. log ("CoreAudio device: " + nameString);
  211304. const int numIns = getNumChannels (devs[i], true);
  211305. const int numOuts = getNumChannels (devs[i], false);
  211306. if (numIns > 0)
  211307. {
  211308. inputDeviceNames.add (nameString);
  211309. inputIds.add (devs[i]);
  211310. }
  211311. if (numOuts > 0)
  211312. {
  211313. outputDeviceNames.add (nameString);
  211314. outputIds.add (devs[i]);
  211315. }
  211316. }
  211317. }
  211318. alreadyLogged = true;
  211319. }
  211320. }
  211321. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211322. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211323. }
  211324. const StringArray getDeviceNames (bool wantInputNames) const
  211325. {
  211326. jassert (hasScanned); // need to call scanForDevices() before doing this
  211327. if (wantInputNames)
  211328. return inputDeviceNames;
  211329. else
  211330. return outputDeviceNames;
  211331. }
  211332. int getDefaultDeviceIndex (bool forInput) const
  211333. {
  211334. jassert (hasScanned); // need to call scanForDevices() before doing this
  211335. AudioDeviceID deviceID;
  211336. UInt32 size = sizeof (deviceID);
  211337. // if they're asking for any input channels at all, use the default input, so we
  211338. // get the built-in mic rather than the built-in output with no inputs..
  211339. AudioObjectPropertyAddress pa;
  211340. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211341. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211342. pa.mElement = kAudioObjectPropertyElementMaster;
  211343. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211344. {
  211345. if (forInput)
  211346. {
  211347. for (int i = inputIds.size(); --i >= 0;)
  211348. if (inputIds[i] == deviceID)
  211349. return i;
  211350. }
  211351. else
  211352. {
  211353. for (int i = outputIds.size(); --i >= 0;)
  211354. if (outputIds[i] == deviceID)
  211355. return i;
  211356. }
  211357. }
  211358. return 0;
  211359. }
  211360. int getIndexOfDevice (AudioIODevice* device, bool asInput) const
  211361. {
  211362. jassert (hasScanned); // need to call scanForDevices() before doing this
  211363. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211364. if (d == 0)
  211365. return -1;
  211366. return asInput ? d->inputIndex
  211367. : d->outputIndex;
  211368. }
  211369. bool hasSeparateInputsAndOutputs() const { return true; }
  211370. AudioIODevice* createDevice (const String& outputDeviceName,
  211371. const String& inputDeviceName)
  211372. {
  211373. jassert (hasScanned); // need to call scanForDevices() before doing this
  211374. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211375. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211376. String deviceName (outputDeviceName);
  211377. if (deviceName.isEmpty())
  211378. deviceName = inputDeviceName;
  211379. if (index >= 0)
  211380. return new CoreAudioIODevice (deviceName,
  211381. inputIds [inputIndex],
  211382. inputIndex,
  211383. outputIds [outputIndex],
  211384. outputIndex);
  211385. return 0;
  211386. }
  211387. juce_UseDebuggingNewOperator
  211388. private:
  211389. StringArray inputDeviceNames, outputDeviceNames;
  211390. Array <AudioDeviceID> inputIds, outputIds;
  211391. bool hasScanned;
  211392. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211393. {
  211394. int total = 0;
  211395. UInt32 size;
  211396. AudioObjectPropertyAddress pa;
  211397. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211398. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211399. pa.mElement = kAudioObjectPropertyElementMaster;
  211400. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211401. {
  211402. HeapBlock <AudioBufferList> bufList;
  211403. bufList.calloc (size, 1);
  211404. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211405. {
  211406. const int numStreams = bufList->mNumberBuffers;
  211407. for (int i = 0; i < numStreams; ++i)
  211408. {
  211409. const AudioBuffer& b = bufList->mBuffers[i];
  211410. total += b.mNumberChannels;
  211411. }
  211412. }
  211413. }
  211414. return total;
  211415. }
  211416. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211417. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211418. };
  211419. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211420. {
  211421. return new CoreAudioIODeviceType();
  211422. }
  211423. #undef log
  211424. #endif
  211425. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211426. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211427. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211428. // compiled on its own).
  211429. #if JUCE_INCLUDED_FILE
  211430. #if JUCE_MAC
  211431. #undef log
  211432. #define log(a) Logger::writeToLog(a)
  211433. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211434. {
  211435. if (err == noErr)
  211436. return true;
  211437. log ("CoreMidi error: " + String (lineNum) + " - " + String::toHexString ((int) err));
  211438. jassertfalse
  211439. return false;
  211440. }
  211441. #undef OK
  211442. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211443. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211444. {
  211445. String result;
  211446. CFStringRef str = 0;
  211447. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211448. if (str != 0)
  211449. {
  211450. result = PlatformUtilities::cfStringToJuceString (str);
  211451. CFRelease (str);
  211452. str = 0;
  211453. }
  211454. MIDIEntityRef entity = 0;
  211455. MIDIEndpointGetEntity (endpoint, &entity);
  211456. if (entity == 0)
  211457. return result; // probably virtual
  211458. if (result.isEmpty())
  211459. {
  211460. // endpoint name has zero length - try the entity
  211461. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211462. if (str != 0)
  211463. {
  211464. result += PlatformUtilities::cfStringToJuceString (str);
  211465. CFRelease (str);
  211466. str = 0;
  211467. }
  211468. }
  211469. // now consider the device's name
  211470. MIDIDeviceRef device = 0;
  211471. MIDIEntityGetDevice (entity, &device);
  211472. if (device == 0)
  211473. return result;
  211474. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211475. if (str != 0)
  211476. {
  211477. const String s (PlatformUtilities::cfStringToJuceString (str));
  211478. CFRelease (str);
  211479. // if an external device has only one entity, throw away
  211480. // the endpoint name and just use the device name
  211481. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211482. {
  211483. result = s;
  211484. }
  211485. else if (! result.startsWithIgnoreCase (s))
  211486. {
  211487. // prepend the device name to the entity name
  211488. result = (s + " " + result).trimEnd();
  211489. }
  211490. }
  211491. return result;
  211492. }
  211493. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211494. {
  211495. String result;
  211496. // Does the endpoint have connections?
  211497. CFDataRef connections = 0;
  211498. int numConnections = 0;
  211499. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211500. if (connections != 0)
  211501. {
  211502. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211503. if (numConnections > 0)
  211504. {
  211505. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211506. for (int i = 0; i < numConnections; ++i, ++pid)
  211507. {
  211508. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211509. MIDIObjectRef connObject;
  211510. MIDIObjectType connObjectType;
  211511. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211512. if (err == noErr)
  211513. {
  211514. String s;
  211515. if (connObjectType == kMIDIObjectType_ExternalSource
  211516. || connObjectType == kMIDIObjectType_ExternalDestination)
  211517. {
  211518. // Connected to an external device's endpoint (10.3 and later).
  211519. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211520. }
  211521. else
  211522. {
  211523. // Connected to an external device (10.2) (or something else, catch-all)
  211524. CFStringRef str = 0;
  211525. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211526. if (str != 0)
  211527. {
  211528. s = PlatformUtilities::cfStringToJuceString (str);
  211529. CFRelease (str);
  211530. }
  211531. }
  211532. if (s.isNotEmpty())
  211533. {
  211534. if (result.isNotEmpty())
  211535. result += ", ";
  211536. result += s;
  211537. }
  211538. }
  211539. }
  211540. }
  211541. CFRelease (connections);
  211542. }
  211543. if (result.isNotEmpty())
  211544. return result;
  211545. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211546. return getEndpointName (endpoint, false);
  211547. }
  211548. const StringArray MidiOutput::getDevices()
  211549. {
  211550. StringArray s;
  211551. const ItemCount num = MIDIGetNumberOfDestinations();
  211552. for (ItemCount i = 0; i < num; ++i)
  211553. {
  211554. MIDIEndpointRef dest = MIDIGetDestination (i);
  211555. if (dest != 0)
  211556. {
  211557. String name (getConnectedEndpointName (dest));
  211558. if (name.isEmpty())
  211559. name = "<error>";
  211560. s.add (name);
  211561. }
  211562. else
  211563. {
  211564. s.add ("<error>");
  211565. }
  211566. }
  211567. return s;
  211568. }
  211569. int MidiOutput::getDefaultDeviceIndex()
  211570. {
  211571. return 0;
  211572. }
  211573. static MIDIClientRef globalMidiClient;
  211574. static bool hasGlobalClientBeenCreated = false;
  211575. static bool makeSureClientExists()
  211576. {
  211577. if (! hasGlobalClientBeenCreated)
  211578. {
  211579. String name ("JUCE");
  211580. if (JUCEApplication::getInstance() != 0)
  211581. name = JUCEApplication::getInstance()->getApplicationName();
  211582. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211583. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211584. CFRelease (appName);
  211585. }
  211586. return hasGlobalClientBeenCreated;
  211587. }
  211588. class MidiPortAndEndpoint
  211589. {
  211590. public:
  211591. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211592. : port (port_), endPoint (endPoint_)
  211593. {
  211594. }
  211595. ~MidiPortAndEndpoint()
  211596. {
  211597. if (port != 0)
  211598. MIDIPortDispose (port);
  211599. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211600. MIDIEndpointDispose (endPoint);
  211601. }
  211602. MIDIPortRef port;
  211603. MIDIEndpointRef endPoint;
  211604. };
  211605. MidiOutput* MidiOutput::openDevice (int index)
  211606. {
  211607. MidiOutput* mo = 0;
  211608. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211609. {
  211610. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211611. CFStringRef pname;
  211612. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211613. {
  211614. log ("CoreMidi - opening out: " + PlatformUtilities::cfStringToJuceString (pname));
  211615. if (makeSureClientExists())
  211616. {
  211617. MIDIPortRef port;
  211618. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211619. {
  211620. mo = new MidiOutput();
  211621. mo->internal = new MidiPortAndEndpoint (port, endPoint);
  211622. }
  211623. }
  211624. CFRelease (pname);
  211625. }
  211626. }
  211627. return mo;
  211628. }
  211629. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211630. {
  211631. MidiOutput* mo = 0;
  211632. if (makeSureClientExists())
  211633. {
  211634. MIDIEndpointRef endPoint;
  211635. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211636. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211637. {
  211638. mo = new MidiOutput();
  211639. mo->internal = new MidiPortAndEndpoint (0, endPoint);
  211640. }
  211641. CFRelease (name);
  211642. }
  211643. return mo;
  211644. }
  211645. MidiOutput::~MidiOutput()
  211646. {
  211647. delete (MidiPortAndEndpoint*) internal;
  211648. }
  211649. void MidiOutput::reset()
  211650. {
  211651. }
  211652. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211653. {
  211654. return false;
  211655. }
  211656. void MidiOutput::setVolume (float leftVol, float rightVol)
  211657. {
  211658. }
  211659. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211660. {
  211661. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211662. if (message.isSysEx())
  211663. {
  211664. const int maxPacketSize = 256;
  211665. int pos = 0, bytesLeft = message.getRawDataSize();
  211666. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211667. HeapBlock <MIDIPacketList> packets;
  211668. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211669. packets->numPackets = numPackets;
  211670. MIDIPacket* p = packets->packet;
  211671. for (int i = 0; i < numPackets; ++i)
  211672. {
  211673. p->timeStamp = 0;
  211674. p->length = jmin (maxPacketSize, bytesLeft);
  211675. memcpy (p->data, message.getRawData() + pos, p->length);
  211676. pos += p->length;
  211677. bytesLeft -= p->length;
  211678. p = MIDIPacketNext (p);
  211679. }
  211680. if (mpe->port != 0)
  211681. MIDISend (mpe->port, mpe->endPoint, packets);
  211682. else
  211683. MIDIReceived (mpe->endPoint, packets);
  211684. }
  211685. else
  211686. {
  211687. MIDIPacketList packets;
  211688. packets.numPackets = 1;
  211689. packets.packet[0].timeStamp = 0;
  211690. packets.packet[0].length = message.getRawDataSize();
  211691. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211692. if (mpe->port != 0)
  211693. MIDISend (mpe->port, mpe->endPoint, &packets);
  211694. else
  211695. MIDIReceived (mpe->endPoint, &packets);
  211696. }
  211697. }
  211698. const StringArray MidiInput::getDevices()
  211699. {
  211700. StringArray s;
  211701. const ItemCount num = MIDIGetNumberOfSources();
  211702. for (ItemCount i = 0; i < num; ++i)
  211703. {
  211704. MIDIEndpointRef source = MIDIGetSource (i);
  211705. if (source != 0)
  211706. {
  211707. String name (getConnectedEndpointName (source));
  211708. if (name.isEmpty())
  211709. name = "<error>";
  211710. s.add (name);
  211711. }
  211712. else
  211713. {
  211714. s.add ("<error>");
  211715. }
  211716. }
  211717. return s;
  211718. }
  211719. int MidiInput::getDefaultDeviceIndex()
  211720. {
  211721. return 0;
  211722. }
  211723. struct MidiPortAndCallback
  211724. {
  211725. MidiInput* input;
  211726. MidiPortAndEndpoint* portAndEndpoint;
  211727. MidiInputCallback* callback;
  211728. MemoryBlock pendingData;
  211729. int pendingBytes;
  211730. double pendingDataTime;
  211731. bool active;
  211732. void processSysex (const uint8*& d, int& size, const double time)
  211733. {
  211734. if (*d == 0xf0)
  211735. {
  211736. pendingBytes = 0;
  211737. pendingDataTime = time;
  211738. }
  211739. pendingData.ensureSize (pendingBytes + size, false);
  211740. uint8* totalMessage = (uint8*) pendingData.getData();
  211741. uint8* dest = totalMessage + pendingBytes;
  211742. while (size > 0)
  211743. {
  211744. if (pendingBytes > 0 && *d >= 0x80)
  211745. {
  211746. if (*d >= 0xfa || *d == 0xf8)
  211747. {
  211748. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211749. ++d;
  211750. --size;
  211751. }
  211752. else
  211753. {
  211754. if (*d == 0xf7)
  211755. {
  211756. *dest++ = *d++;
  211757. pendingBytes++;
  211758. --size;
  211759. }
  211760. break;
  211761. }
  211762. }
  211763. else
  211764. {
  211765. *dest++ = *d++;
  211766. pendingBytes++;
  211767. --size;
  211768. }
  211769. }
  211770. if (totalMessage [pendingBytes - 1] == 0xf7)
  211771. {
  211772. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211773. pendingBytes = 0;
  211774. }
  211775. else
  211776. {
  211777. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211778. }
  211779. }
  211780. };
  211781. namespace CoreMidiCallbacks
  211782. {
  211783. static CriticalSection callbackLock;
  211784. static VoidArray activeCallbacks;
  211785. }
  211786. static void midiInputProc (const MIDIPacketList* pktlist,
  211787. void* readProcRefCon,
  211788. void* srcConnRefCon)
  211789. {
  211790. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211791. const double originalTime = time;
  211792. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211793. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211794. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211795. {
  211796. const MIDIPacket* packet = &pktlist->packet[0];
  211797. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211798. {
  211799. const uint8* d = (const uint8*) (packet->data);
  211800. int size = packet->length;
  211801. while (size > 0)
  211802. {
  211803. time = originalTime;
  211804. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211805. {
  211806. mpc->processSysex (d, size, time);
  211807. }
  211808. else
  211809. {
  211810. int used = 0;
  211811. const MidiMessage m (d, size, used, 0, time);
  211812. if (used <= 0)
  211813. {
  211814. jassertfalse // malformed midi message
  211815. break;
  211816. }
  211817. else
  211818. {
  211819. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211820. }
  211821. size -= used;
  211822. d += used;
  211823. }
  211824. }
  211825. packet = MIDIPacketNext (packet);
  211826. }
  211827. }
  211828. }
  211829. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211830. {
  211831. MidiInput* mi = 0;
  211832. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211833. {
  211834. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211835. if (endPoint != 0)
  211836. {
  211837. CFStringRef pname;
  211838. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211839. {
  211840. log ("CoreMidi - opening inp: " + PlatformUtilities::cfStringToJuceString (pname));
  211841. if (makeSureClientExists())
  211842. {
  211843. MIDIPortRef port;
  211844. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211845. mpc->active = false;
  211846. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211847. {
  211848. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211849. {
  211850. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211851. mpc->callback = callback;
  211852. mpc->pendingBytes = 0;
  211853. mpc->pendingData.ensureSize (128);
  211854. mi = new MidiInput (getDevices() [index]);
  211855. mpc->input = mi;
  211856. mi->internal = mpc;
  211857. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211858. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211859. }
  211860. else
  211861. {
  211862. OK (MIDIPortDispose (port));
  211863. }
  211864. }
  211865. }
  211866. }
  211867. CFRelease (pname);
  211868. }
  211869. }
  211870. return mi;
  211871. }
  211872. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211873. {
  211874. MidiInput* mi = 0;
  211875. if (makeSureClientExists())
  211876. {
  211877. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211878. mpc->active = false;
  211879. MIDIEndpointRef endPoint;
  211880. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211881. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211882. {
  211883. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211884. mpc->callback = callback;
  211885. mpc->pendingBytes = 0;
  211886. mpc->pendingData.ensureSize (128);
  211887. mi = new MidiInput (deviceName);
  211888. mpc->input = mi;
  211889. mi->internal = mpc;
  211890. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211891. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211892. }
  211893. CFRelease (name);
  211894. }
  211895. return mi;
  211896. }
  211897. MidiInput::MidiInput (const String& name_)
  211898. : name (name_)
  211899. {
  211900. }
  211901. MidiInput::~MidiInput()
  211902. {
  211903. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211904. mpc->active = false;
  211905. {
  211906. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211907. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211908. }
  211909. if (mpc->portAndEndpoint->port != 0)
  211910. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211911. delete mpc->portAndEndpoint;
  211912. delete mpc;
  211913. }
  211914. void MidiInput::start()
  211915. {
  211916. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211917. ((MidiPortAndCallback*) internal)->active = true;
  211918. }
  211919. void MidiInput::stop()
  211920. {
  211921. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211922. ((MidiPortAndCallback*) internal)->active = false;
  211923. }
  211924. #undef log
  211925. #else
  211926. MidiOutput::~MidiOutput()
  211927. {
  211928. }
  211929. void MidiOutput::reset()
  211930. {
  211931. }
  211932. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211933. {
  211934. return false;
  211935. }
  211936. void MidiOutput::setVolume (float leftVol, float rightVol)
  211937. {
  211938. }
  211939. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211940. {
  211941. }
  211942. const StringArray MidiOutput::getDevices()
  211943. {
  211944. return StringArray();
  211945. }
  211946. MidiOutput* MidiOutput::openDevice (int index)
  211947. {
  211948. return 0;
  211949. }
  211950. const StringArray MidiInput::getDevices()
  211951. {
  211952. return StringArray();
  211953. }
  211954. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211955. {
  211956. return 0;
  211957. }
  211958. #endif
  211959. #endif
  211960. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211961. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211962. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211963. // compiled on its own).
  211964. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  211965. #if ! JUCE_QUICKTIME
  211966. #error "On the Mac, cameras use Quicktime, so if you turn on JUCE_USE_CAMERA, you also need to enable JUCE_QUICKTIME"
  211967. #endif
  211968. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211969. class QTCameraDeviceInteral;
  211970. END_JUCE_NAMESPACE
  211971. @interface QTCaptureCallbackDelegate : NSObject
  211972. {
  211973. @public
  211974. CameraDevice* owner;
  211975. QTCameraDeviceInteral* internal;
  211976. int64 firstPresentationTime;
  211977. int64 averageTimeOffset;
  211978. }
  211979. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211980. - (void) dealloc;
  211981. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211982. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211983. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211984. fromConnection: (QTCaptureConnection*) connection;
  211985. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211986. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211987. fromConnection: (QTCaptureConnection*) connection;
  211988. @end
  211989. BEGIN_JUCE_NAMESPACE
  211990. class QTCameraDeviceInteral
  211991. {
  211992. public:
  211993. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211994. {
  211995. const ScopedAutoReleasePool pool;
  211996. session = [[QTCaptureSession alloc] init];
  211997. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211998. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211999. input = 0;
  212000. audioInput = 0;
  212001. audioDevice = 0;
  212002. fileOutput = 0;
  212003. imageOutput = 0;
  212004. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  212005. internalDev: this];
  212006. NSError* err = 0;
  212007. [device retain];
  212008. [device open: &err];
  212009. if (err == 0)
  212010. {
  212011. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212012. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  212013. [session addInput: input error: &err];
  212014. if (err == 0)
  212015. {
  212016. resetFile();
  212017. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  212018. [imageOutput setDelegate: callbackDelegate];
  212019. if (err == 0)
  212020. {
  212021. [session startRunning];
  212022. return;
  212023. }
  212024. }
  212025. }
  212026. openingError = nsStringToJuce ([err description]);
  212027. DBG (openingError);
  212028. }
  212029. ~QTCameraDeviceInteral()
  212030. {
  212031. [session stopRunning];
  212032. [session removeOutput: imageOutput];
  212033. [session release];
  212034. [input release];
  212035. [device release];
  212036. [audioDevice release];
  212037. [audioInput release];
  212038. [fileOutput release];
  212039. [imageOutput release];
  212040. [callbackDelegate release];
  212041. }
  212042. void resetFile()
  212043. {
  212044. [fileOutput recordToOutputFileURL: nil];
  212045. [session removeOutput: fileOutput];
  212046. [fileOutput release];
  212047. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  212048. [session removeInput: audioInput];
  212049. [audioInput release];
  212050. audioInput = 0;
  212051. [audioDevice release];
  212052. audioDevice = 0;
  212053. [fileOutput setDelegate: callbackDelegate];
  212054. }
  212055. void addDefaultAudioInput()
  212056. {
  212057. NSError* err = nil;
  212058. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  212059. if ([audioDevice open: &err])
  212060. [audioDevice retain];
  212061. else
  212062. audioDevice = nil;
  212063. if (audioDevice != 0)
  212064. {
  212065. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  212066. [session addInput: audioInput error: &err];
  212067. }
  212068. }
  212069. void addListener (CameraImageListener* listenerToAdd)
  212070. {
  212071. const ScopedLock sl (listenerLock);
  212072. if (listeners.size() == 0)
  212073. [session addOutput: imageOutput error: nil];
  212074. listeners.addIfNotAlreadyThere (listenerToAdd);
  212075. }
  212076. void removeListener (CameraImageListener* listenerToRemove)
  212077. {
  212078. const ScopedLock sl (listenerLock);
  212079. listeners.removeValue (listenerToRemove);
  212080. if (listeners.size() == 0)
  212081. [session removeOutput: imageOutput];
  212082. }
  212083. void callListeners (CIImage* frame, int w, int h)
  212084. {
  212085. CoreGraphicsImage image (Image::ARGB, w, h, false);
  212086. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  212087. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  212088. CGContextFlush (image.context);
  212089. const ScopedLock sl (listenerLock);
  212090. for (int i = listeners.size(); --i >= 0;)
  212091. {
  212092. CameraImageListener* l = (CameraImageListener*) listeners[i];
  212093. if (l != 0)
  212094. l->imageReceived (image);
  212095. }
  212096. }
  212097. QTCaptureDevice* device;
  212098. QTCaptureDeviceInput* input;
  212099. QTCaptureDevice* audioDevice;
  212100. QTCaptureDeviceInput* audioInput;
  212101. QTCaptureSession* session;
  212102. QTCaptureMovieFileOutput* fileOutput;
  212103. QTCaptureDecompressedVideoOutput* imageOutput;
  212104. QTCaptureCallbackDelegate* callbackDelegate;
  212105. String openingError;
  212106. VoidArray listeners;
  212107. CriticalSection listenerLock;
  212108. };
  212109. END_JUCE_NAMESPACE
  212110. @implementation QTCaptureCallbackDelegate
  212111. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212112. internalDev: (QTCameraDeviceInteral*) d
  212113. {
  212114. [super init];
  212115. owner = owner_;
  212116. internal = d;
  212117. firstPresentationTime = 0;
  212118. averageTimeOffset = 0;
  212119. return self;
  212120. }
  212121. - (void) dealloc
  212122. {
  212123. [super dealloc];
  212124. }
  212125. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212126. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212127. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212128. fromConnection: (QTCaptureConnection*) connection
  212129. {
  212130. if (internal->listeners.size() > 0)
  212131. {
  212132. const ScopedAutoReleasePool pool;
  212133. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212134. CVPixelBufferGetWidth (videoFrame),
  212135. CVPixelBufferGetHeight (videoFrame));
  212136. }
  212137. }
  212138. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212139. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212140. fromConnection: (QTCaptureConnection*) connection
  212141. {
  212142. const Time now (Time::getCurrentTime());
  212143. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212144. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212145. #else
  212146. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212147. #endif
  212148. int64 presentationTime = (hosttime != nil)
  212149. ? ((int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000 + 40)
  212150. : (([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale + 50);
  212151. const int64 timeDiff = now.toMilliseconds() - presentationTime;
  212152. if (firstPresentationTime == 0)
  212153. {
  212154. firstPresentationTime = presentationTime;
  212155. averageTimeOffset = timeDiff;
  212156. }
  212157. else
  212158. {
  212159. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212160. }
  212161. }
  212162. @end
  212163. BEGIN_JUCE_NAMESPACE
  212164. class QTCaptureViewerComp : public NSViewComponent
  212165. {
  212166. public:
  212167. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212168. {
  212169. const ScopedAutoReleasePool pool;
  212170. captureView = [[QTCaptureView alloc] init];
  212171. [captureView setCaptureSession: internal->session];
  212172. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212173. setView (captureView);
  212174. }
  212175. ~QTCaptureViewerComp()
  212176. {
  212177. setView (0);
  212178. [captureView setCaptureSession: nil];
  212179. [captureView release];
  212180. }
  212181. QTCaptureView* captureView;
  212182. };
  212183. CameraDevice::CameraDevice (const String& name_, int index)
  212184. : name (name_)
  212185. {
  212186. isRecording = false;
  212187. internal = new QTCameraDeviceInteral (this, index);
  212188. }
  212189. CameraDevice::~CameraDevice()
  212190. {
  212191. stopRecording();
  212192. delete static_cast <QTCameraDeviceInteral*> (internal);
  212193. internal = 0;
  212194. }
  212195. Component* CameraDevice::createViewerComponent()
  212196. {
  212197. return new QTCaptureViewerComp (this, static_cast <QTCameraDeviceInteral*> (internal));
  212198. }
  212199. const String CameraDevice::getFileExtension()
  212200. {
  212201. return ".mov";
  212202. }
  212203. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212204. {
  212205. stopRecording();
  212206. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212207. d->callbackDelegate->firstPresentationTime = 0;
  212208. file.deleteFile();
  212209. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212210. // out wrong, so we'll put some audio in there too..,
  212211. d->addDefaultAudioInput();
  212212. [d->session addOutput: d->fileOutput error: nil];
  212213. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212214. for (;;)
  212215. {
  212216. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212217. if (connection == 0)
  212218. break;
  212219. QTCompressionOptions* options = 0;
  212220. NSString* mediaType = [connection mediaType];
  212221. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212222. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212223. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212224. : @"QTCompressionOptions240SizeH264Video"];
  212225. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212226. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212227. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212228. }
  212229. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212230. isRecording = true;
  212231. }
  212232. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212233. {
  212234. QTCameraDeviceInteral* const d = static_cast <QTCameraDeviceInteral*> (internal);
  212235. if (d->callbackDelegate->firstPresentationTime != 0)
  212236. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212237. return Time();
  212238. }
  212239. void CameraDevice::stopRecording()
  212240. {
  212241. if (isRecording)
  212242. {
  212243. static_cast <QTCameraDeviceInteral*> (internal)->resetFile();
  212244. isRecording = false;
  212245. }
  212246. }
  212247. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212248. {
  212249. if (listenerToAdd != 0)
  212250. static_cast <QTCameraDeviceInteral*> (internal)->addListener (listenerToAdd);
  212251. }
  212252. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212253. {
  212254. if (listenerToRemove != 0)
  212255. static_cast <QTCameraDeviceInteral*> (internal)->removeListener (listenerToRemove);
  212256. }
  212257. const StringArray CameraDevice::getAvailableDevices()
  212258. {
  212259. const ScopedAutoReleasePool pool;
  212260. StringArray results;
  212261. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212262. for (int i = 0; i < (int) [devs count]; ++i)
  212263. {
  212264. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212265. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212266. }
  212267. return results;
  212268. }
  212269. CameraDevice* CameraDevice::openDevice (int index,
  212270. int minWidth, int minHeight,
  212271. int maxWidth, int maxHeight)
  212272. {
  212273. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212274. if (static_cast <QTCameraDeviceInteral*> (d->internal)->openingError.isEmpty())
  212275. return d.release();
  212276. return 0;
  212277. }
  212278. #endif
  212279. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212280. #endif
  212281. #endif
  212282. END_JUCE_NAMESPACE
  212283. #endif
  212284. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212285. #endif
  212286. #endif